]>
git.p6c8.net - jirafeau_mojo42.git/blob - admin.php
54fcde135df8c5ae21fd0d170598b2131d85ff82
3 * Jirafeau, your web file repository
4 * Copyright (C) 2015 Jerome Jutteau <j.jutteau@gmail.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 define('JIRAFEAU_ROOT', dirname(__FILE__
) . '/');
22 require(JIRAFEAU_ROOT
. 'lib/settings.php');
23 require(JIRAFEAU_ROOT
. 'lib/functions.php');
24 require(JIRAFEAU_ROOT
. 'lib/lang.php');
26 /* Check if installation is OK. */
27 if (file_exists(JIRAFEAU_ROOT
. 'install.php')
28 && !file_exists(JIRAFEAU_ROOT
. 'lib/config.local.php')) {
29 header('Location: install.php');
33 /* If called from CLI, no password or graphical interface */
34 if (php_sapi_name() == "cli") {
35 if ((count($argv)>1) && $argv[1]=="clean_expired") {
36 $total = jirafeau_admin_clean();
37 echo "$total expired files deleted.";
38 } elseif ((count($argv)>1) && $argv[1]=="clean_async") {
39 $total = jirafeau_admin_clean_async();
40 echo "$total old unfinished transfers deleted.";
42 die("No command found. Should be admin.php <clean_expired|clean_async>.");
45 /* Disable admin interface if we have a empty admin password. */
46 if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user'])) {
47 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
48 echo '<div class="error"><p>'.
51 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
56 if (jirafeau_admin_session_logged() && isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
57 jirafeau_admin_session_end();
60 if (!jirafeau_admin_session_logged()) {
61 /* Test HTTP authentification. */
62 if (!empty($cfg['admin_http_auth_user']) &&
63 $cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER']) {
64 jirafeau_admin_session_start();
66 /* Test web password authentification. */
67 else if (!empty($cfg['admin_password']) && isset($_POST['admin_password'])) {
68 if ($cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) {
69 jirafeau_admin_session_start();
71 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
72 echo '<div class="error"><p>'. t('BAD_PSW') . '</p></div>';
73 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
77 /* Admin password prompt form. */
79 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
>
80 <form method
="post" class="form login">
84 <td
class = "label"><label
for = "enter_password">
85 <?php
echo t('ADMIN_PSW') . ':'; ?
></label
>
89 <td
class = "field"><input type
= "password"
90 name
= "admin_password" id
= "admin_password"
95 <td
class = "nav next">
96 <input type
= "submit" name
= "key" value
=
97 "<?php echo t('LOGIN'); ?>" />
104 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
109 /* Operations may take a long time.
110 * Be sure PHP's safe mode is off.
116 /* Show admin interface if not downloading a file. */
117 if (!(isset($_POST['action']) && strcmp($_POST['action'], 'download') == 0)) {
118 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
><h2
><?php
echo t('ADMIN_INTERFACE'); ?
></h2
><?php
119 ?
><h2
>(version
<?php
echo JIRAFEAU_VERSION ?
>)</h2
><?php
122 <fieldset
><legend
><?php
echo t('ACTIONS'); ?
></legend
>
126 <input type
= "hidden" name
= "action" value
= "clean"/>
127 <?php
echo jirafeau_admin_csrf_field() ?
>
129 <?php
echo t('CLEAN_EXPIRED'); ?
>
133 <input type
= "submit" value
= "<?php echo t('CLEAN'); ?>" />
139 <input type
= "hidden" name
= "action" value
= "clean_async"/>
140 <?php
echo jirafeau_admin_csrf_field() ?
>
142 <?php
echo t('CLEAN_INCOMPLETE'); ?
>
146 <input type
= "submit" value
= "<?php echo t('CLEAN'); ?>" />
152 <input type
= "hidden" name
= "action" value
= "list"/>
153 <?php
echo jirafeau_admin_csrf_field() ?
>
155 <?php
echo t('LS_FILES'); ?
>
159 <input type
= "submit" value
= "<?php echo t('LIST'); ?>" />
165 <input type
= "hidden" name
= "action" value
= "size"/>
166 <?php
echo jirafeau_admin_csrf_field() ?
>
168 <?php
echo t('SIZE_DATA'); ?
>
172 <input type
= "submit" value
= "<?php echo t('SIZE'); ?>" />
178 <input type
= "hidden" name
= "action" value
= "search_by_name"/>
179 <?php
echo jirafeau_admin_csrf_field() ?
>
181 <?php
echo t('SEARCH_NAME'); ?
>
184 <input type
= "text" name
= "name" id
= "name"/>
187 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
193 <input type
= "hidden" name
= "action" value
= "search_by_file_hash"/>
194 <?php
echo jirafeau_admin_csrf_field() ?
>
196 <?php
echo t('SEARH_BY_HASH'); ?
>
199 <input type
= "text" name
= "hash" id
= "hash"/>
202 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
208 <input type
= "hidden" name
= "action" value
= "search_link"/>
209 <?php
echo jirafeau_admin_csrf_field() ?
>
211 <?php
echo t('SEARCH_LINK'); ?
>
214 <input type
= "text" name
= "link" id
= "link"/>
217 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
223 <input type
= "hidden" name
= "action" value
= "logout" />
224 <?php
echo jirafeau_admin_csrf_field() ?
>
225 <input type
= "submit" value
= "<?php echo t('LOGOUT'); ?>" />
227 </fieldset
></div
><?php
230 /* Check for actions */
231 if (isset($_POST['action'])) {
232 if (strcmp($_POST['action'], 'clean') == 0) {
233 $total = jirafeau_admin_clean();
234 echo '<div class="message">' . NL
;
236 echo t('CLEANED_FILES_CNT') . ' : ' . $total;
238 } elseif (strcmp($_POST['action'], 'clean_async') == 0) {
239 $total = jirafeau_admin_clean_async();
240 echo '<div class="message">' . NL
;
242 echo t('CLEANED_FILES_CNT') . ' : ' . $total;
244 } elseif (strcmp($_POST['action'], 'size') == 0) {
245 $size = jirafeau_dir_size($cfg['var_root']);
246 $human_size = jirafeau_human_size($size);
247 echo '<div class="message">' . NL
;
248 echo '<p>' . t('SIZE_DATA') . ': ' . $human_size .'</p>';
250 } elseif (strcmp($_POST['action'], 'list') == 0) {
251 jirafeau_admin_list("", "", "");
252 } elseif (strcmp($_POST['action'], 'search_by_name') == 0) {
253 jirafeau_admin_list($_POST['name'], "", "");
254 } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) {
255 jirafeau_admin_list("", $_POST['hash'], "");
256 } elseif (strcmp($_POST['action'], 'search_link') == 0) {
257 jirafeau_admin_list("", "", $_POST['link']);
258 } elseif (strcmp($_POST['action'], 'delete_link') == 0) {
259 jirafeau_delete_link($_POST['link']);
260 echo '<div class="message">' . NL
;
261 echo '<p>' . t('LINK_DELETED') . '</p></div>';
262 } elseif (strcmp($_POST['action'], 'delete_file') == 0) {
263 $count = jirafeau_delete_file($_POST['hash']);
264 echo '<div class="message">' . NL
;
265 echo '<p>' . t('DELETED_LINKS') . ' : ' . $count . '</p></div>';
266 } elseif (strcmp($_POST['action'], 'download') == 0) {
267 $l = jirafeau_get_link($_POST['link']);
271 $p = s2p($l['hash']);
272 header('Content-Length: ' . $l['file_size']);
273 header('Content-Type: ' . $l['mime_type']);
274 header('Content-Disposition: attachment; filename="' .
275 $l['file_name'] . '"');
276 if (file_exists(VAR_FILES
. $p . $l['hash'])) {
277 $r = fopen(VAR_FILES
. $p . $l['hash'], 'r');
279 print fread($r, 1024);
288 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
patrick-canterino.de