]>
git.p6c8.net - jirafeau.git/blob - admin.php
3 * Jirafeau, your web file repository
4 * Copyright (C) 2015 Jerome Jutteau <jerome@jutteau.fr>
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 ($cfg['installation_done'] == false) {
36 die("Installation not completed yet.\n");
38 if ((count($argv)>1) && $argv[1]=="clean_expired") {
39 $total = jirafeau_admin_clean();
40 echo "$total expired files deleted.\n";
41 } elseif ((count($argv)>1) && $argv[1]=="clean_async") {
42 $total = jirafeau_admin_clean_async();
43 echo "$total old unfinished transfers deleted.\n";
45 die("No command found. Should be admin.php <clean_expired|clean_async>.\n");
47 // Second check: Challenge by IP
48 } elseif (true === jirafeau_challenge_admin_ip($cfg, get_ip_address($cfg))) {
49 /* Disable admin interface if we have a empty admin password. */
50 if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user'])) {
51 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
52 echo '<div class="error"><p>'.
55 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
59 /* Logout if requested. */
60 if (jirafeau_admin_session_logged() && isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
61 jirafeau_session_end();
64 if (!jirafeau_admin_session_logged()) {
65 /* Test HTTP authentication. */
66 if (!empty($cfg['admin_http_auth_user']) &&
67 $cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER']) {
68 jirafeau_admin_session_start();
70 /* Test web password authentication. */
71 elseif (!empty($cfg['admin_password']) && isset($_POST['admin_password'])) {
72 if ($cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) {
73 jirafeau_admin_session_start();
75 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
76 echo '<div class="error"><p>'. t('BAD_PSW') . '</p></div>';
77 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
81 /* Admin password prompt form. */
83 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
>
84 <form method
="post" class="form login">
88 <td
class = "label"><label
for = "enter_password">
89 <?php
echo t('ADMIN_PSW') . ':'; ?
></label
>
93 <td
class = "field"><input type
= "password"
94 name
= "admin_password" id
= "admin_password"
95 size
= "40" autocomplete
= "current-password" />
99 <td
class = "nav next">
100 <input type
= "submit" name
= "key" value
=
101 "<?php echo t('LOGIN'); ?>" />
108 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
113 /* Operations may take a long time.
114 * Be sure PHP's safe mode is off.
118 /* Show admin interface if not downloading a file. */
119 if (!(isset($_POST['action']) && strcmp($_POST['action'], 'download') == 0)) {
120 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
><h2
><?php
echo t('ADMIN_INTERFACE'); ?
></h2
><?php
121 ?
><h2
>(version
<?php
echo JIRAFEAU_VERSION ?
>)</h2
><?php
124 <fieldset
><legend
><?php
echo t('ACTIONS'); ?
></legend
>
128 <input type
= "hidden" name
= "action" value
= "clean"/>
129 <?php
echo jirafeau_admin_csrf_field() ?
>
131 <?php
echo t('CLEAN_EXPIRED'); ?
>
135 <input type
= "submit" value
= "<?php echo t('CLEAN'); ?>" />
141 <input type
= "hidden" name
= "action" value
= "clean_async"/>
142 <?php
echo jirafeau_admin_csrf_field() ?
>
144 <?php
echo t('CLEAN_INCOMPLETE'); ?
>
148 <input type
= "submit" value
= "<?php echo t('CLEAN'); ?>" />
154 <input type
= "hidden" name
= "action" value
= "list"/>
155 <?php
echo jirafeau_admin_csrf_field() ?
>
157 <?php
echo t('LS_FILES'); ?
>
161 <input type
= "submit" value
= "<?php echo t('LIST'); ?>" />
167 <input type
= "hidden" name
= "action" value
= "size"/>
168 <?php
echo jirafeau_admin_csrf_field() ?
>
170 <?php
echo t('SIZE_DATA'); ?
>
174 <input type
= "submit" value
= "<?php echo t('SIZE'); ?>" />
180 <input type
= "hidden" name
= "action" value
= "search_by_name"/>
181 <?php
echo jirafeau_admin_csrf_field() ?
>
183 <?php
echo t('SEARCH_NAME'); ?
>
186 <input type
= "text" name
= "name" id
= "name"/>
189 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
195 <input type
= "hidden" name
= "action" value
= "search_by_file_hash"/>
196 <?php
echo jirafeau_admin_csrf_field() ?
>
198 <?php
echo t('SEARH_BY_HASH'); ?
>
201 <input type
= "text" name
= "hash" id
= "hash"/>
204 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
210 <input type
= "hidden" name
= "action" value
= "search_link"/>
211 <?php
echo jirafeau_admin_csrf_field() ?
>
213 <?php
echo t('SEARCH_LINK'); ?
>
216 <input type
= "text" name
= "link" id
= "link"/>
219 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
225 <input type
= "hidden" name
= "action" value
= "bug_report_info"/>
226 <?php
echo jirafeau_admin_csrf_field() ?
>
228 <?php
echo t('REPORTING_AN_ISSUE'); ?
>
232 <input type
= "submit" value
= "<?php echo t('INFO'); ?>" />
238 <input type
= "hidden" name
= "action" value
= "logout" />
239 <?php
echo jirafeau_admin_csrf_field() ?
>
240 <input type
= "submit" value
= "<?php echo t('LOGOUT'); ?>" />
242 </fieldset
></div
><?php
245 /* Check for actions */
246 if (isset($_POST['action'])) {
247 if (strcmp($_POST['action'], 'clean') == 0) {
248 $total = jirafeau_admin_clean();
249 echo '<div class="message">' . NL
;
251 echo t('CLEANED_FILES_CNT') . ' : ' . $total;
253 } elseif (strcmp($_POST['action'], 'clean_async') == 0) {
254 $total = jirafeau_admin_clean_async();
255 echo '<div class="message">' . NL
;
257 echo t('CLEANED_FILES_CNT') . ' : ' . $total;
259 } elseif (strcmp($_POST['action'], 'size') == 0) {
260 $size = jirafeau_dir_size($cfg['var_root']);
261 $human_size = jirafeau_human_size($size);
262 echo '<div class="message">' . NL
;
263 echo '<p>' . t('SIZE_DATA') . ': ' . $human_size .'</p>';
265 } elseif (strcmp($_POST['action'], 'list') == 0) {
266 jirafeau_admin_list("", "", "");
267 } elseif (strcmp($_POST['action'], 'search_by_name') == 0) {
268 jirafeau_admin_list($_POST['name'], "", "");
269 } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) {
270 jirafeau_admin_list("", $_POST['hash'], "");
271 } elseif (strcmp($_POST['action'], 'search_link') == 0) {
272 jirafeau_admin_list("", "", $_POST['link']);
273 } elseif (strcmp($_POST['action'], 'delete_link') == 0) {
274 jirafeau_delete_link($_POST['link']);
275 echo '<div class="message">' . NL
;
276 echo '<p>' . t('LINK_DELETED') . '</p></div>';
277 } elseif (strcmp($_POST['action'], 'delete_file') == 0) {
278 $count = jirafeau_delete_file($_POST['hash']);
279 echo '<div class="message">' . NL
;
280 echo '<p>' . t('DELETED_LINKS') . ' : ' . $count . '</p></div>';
281 } elseif (strcmp($_POST['action'], 'download') == 0) {
282 $l = jirafeau_get_link($_POST['link']);
286 $p = s2p($l['hash']);
287 header('Content-Length: ' . $l['file_size']);
288 header('Content-Type: ' . $l['mime_type']);
289 header('Content-Disposition: attachment; filename="' .
290 $l['file_name'] . '"');
291 if (file_exists(VAR_FILES
. $p . $l['hash'])) {
292 $r = fopen(VAR_FILES
. $p . $l['hash'], 'r');
294 print fread($r, 1024);
299 } elseif (strcmp($_POST['action'], 'bug_report_info') == 0) {
300 echo jirafeau_admin_bug_report($cfg);
304 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
306 jirafeau_fatal_error(t('ACCESS_KO'), $cfg);
patrick-canterino.de