]> git.p6c8.net - jirafeau_mojo42.git/blob - admin.php
[FEATURE] Add new option: upload_ip_nopassword
[jirafeau_mojo42.git] / admin.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2015 Jerome Jutteau <j.jutteau@gmail.com>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19 session_start();
20 define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
21
22 require(JIRAFEAU_ROOT . 'lib/settings.php');
23 require(JIRAFEAU_ROOT . 'lib/functions.php');
24 require(JIRAFEAU_ROOT . 'lib/lang.php');
25
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');
30 exit;
31 }
32
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.";
41 } else {
42 die("No command found. Should be admin.php <clean_expired|clean_async>.");
43 }
44 } else {
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>'.
49 t('NO_ADMIN') .
50 '</p></div>';
51 require(JIRAFEAU_ROOT.'lib/template/footer.php');
52 exit;
53 }
54
55 /* Unlog if asked. */
56 if (jirafeau_admin_session_logged() && isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
57 jirafeau_admin_session_end();
58 }
59
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();
65 }
66 /* Test web password authentification. */
67 else if (!empty($cfg['admin_password']) && isset($_POST['admin_password'])) {
68 if ($cfg['admin_password'] === $_POST['admin_password'] ||
69 $cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) {
70 jirafeau_admin_session_start();
71 } else {
72 require(JIRAFEAU_ROOT . 'lib/template/header.php');
73 echo '<div class="error"><p>'. t('BAD_PSW') . '</p></div>';
74 require(JIRAFEAU_ROOT.'lib/template/footer.php');
75 exit;
76 }
77 }
78 /* Admin password prompt form. */
79 else {
80 require(JIRAFEAU_ROOT . 'lib/template/header.php'); ?>
81 <form method="post" class="form login">
82 <fieldset>
83 <table>
84 <tr>
85 <td class = "label"><label for = "enter_password">
86 <?php echo t('ADMIN_PSW') . ':'; ?></label>
87 </td>
88 </tr>
89 <tr>
90 <td class = "field"><input type = "password"
91 name = "admin_password" id = "admin_password"
92 size = "40" />
93 </td>
94 </tr>
95 <tr class = "nav">
96 <td class = "nav next">
97 <input type = "submit" name = "key" value =
98 "<?php echo t('LOGIN'); ?>" />
99 </td>
100 </tr>
101 </table>
102 </fieldset>
103 </form>
104 <?php
105 require(JIRAFEAU_ROOT.'lib/template/footer.php');
106 exit;
107 }
108 }
109
110 /* Operations may take a long time.
111 * Be sure PHP's safe mode is off.
112 */
113 @set_time_limit(0);
114 /* Remove errors. */
115 @error_reporting(0);
116
117 /* Show admin interface if not downloading a file. */
118 if (!(isset($_POST['action']) && strcmp($_POST['action'], 'download') == 0)) {
119 require(JIRAFEAU_ROOT . 'lib/template/header.php'); ?><h2><?php echo t('ADMIN_INTERFACE'); ?></h2><?php
120 ?><h2>(version <?php echo JIRAFEAU_VERSION ?>)</h2><?php
121
122 ?><div id = "admin">
123 <fieldset><legend><?php echo t('ACTIONS'); ?></legend>
124 <table>
125 <form method="post">
126 <tr>
127 <input type = "hidden" name = "action" value = "clean"/>
128 <?php echo jirafeau_admin_csrf_field() ?>
129 <td class = "info">
130 <?php echo t('CLEAN_EXPIRED'); ?>
131 </td>
132 <td></td>
133 <td>
134 <input type = "submit" value = "<?php echo t('CLEAN'); ?>" />
135 </td>
136 </tr>
137 </form>
138 <form method="post">
139 <tr>
140 <input type = "hidden" name = "action" value = "clean_async"/>
141 <?php echo jirafeau_admin_csrf_field() ?>
142 <td class = "info">
143 <?php echo t('CLEAN_INCOMPLETE'); ?>
144 </td>
145 <td></td>
146 <td>
147 <input type = "submit" value = "<?php echo t('CLEAN'); ?>" />
148 </td>
149 </tr>
150 </form>
151 <form method="post">
152 <tr>
153 <input type = "hidden" name = "action" value = "list"/>
154 <?php echo jirafeau_admin_csrf_field() ?>
155 <td class = "info">
156 <?php echo t('LS_FILES'); ?>
157 </td>
158 <td></td>
159 <td>
160 <input type = "submit" value = "<?php echo t('LIST'); ?>" />
161 </td>
162 </tr>
163 </form>
164 <form method="post">
165 <tr>
166 <input type = "hidden" name = "action" value = "search_by_name"/>
167 <?php echo jirafeau_admin_csrf_field() ?>
168 <td class = "info">
169 <?php echo t('SEARCH_NAME'); ?>
170 </td>
171 <td>
172 <input type = "text" name = "name" id = "name"/>
173 </td>
174 <td>
175 <input type = "submit" value = "<?php echo t('SEARCH'); ?>" />
176 </td>
177 </tr>
178 </form>
179 <form method="post">
180 <tr>
181 <input type = "hidden" name = "action" value = "search_by_file_hash"/>
182 <?php echo jirafeau_admin_csrf_field() ?>
183 <td class = "info">
184 <?php echo t('SEARH_BY_HASH'); ?>
185 </td>
186 <td>
187 <input type = "text" name = "hash" id = "hash"/>
188 </td>
189 <td>
190 <input type = "submit" value = "<?php echo t('SEARCH'); ?>" />
191 </td>
192 </tr>
193 </form>
194 <form method="post">
195 <tr>
196 <input type = "hidden" name = "action" value = "search_link"/>
197 <?php echo jirafeau_admin_csrf_field() ?>
198 <td class = "info">
199 <?php echo t('SEARCH_LINK'); ?>
200 </td>
201 <td>
202 <input type = "text" name = "link" id = "link"/>
203 </td>
204 <td>
205 <input type = "submit" value = "<?php echo t('SEARCH'); ?>" />
206 </td>
207 </tr>
208 </form>
209 </table>
210 <form method="post">
211 <input type = "hidden" name = "action" value = "logout" />
212 <?php echo jirafeau_admin_csrf_field() ?>
213 <input type = "submit" value = "<?php echo t('LOGOUT'); ?>" />
214 </form>
215 </fieldset></div><?php
216 }
217
218 /* Check for actions */
219 if (isset($_POST['action'])) {
220 if (strcmp($_POST['action'], 'clean') == 0) {
221 $total = jirafeau_admin_clean();
222 echo '<div class="message">' . NL;
223 echo '<p>';
224 echo t('CLEANED_FILES_CNT') . ' : ' . $total;
225 echo '</p></div>';
226 } elseif (strcmp($_POST['action'], 'clean_async') == 0) {
227 $total = jirafeau_admin_clean_async();
228 echo '<div class="message">' . NL;
229 echo '<p>';
230 echo t('CLEANED_FILES_CNT') . ' : ' . $total;
231 echo '</p></div>';
232 } elseif (strcmp($_POST['action'], 'list') == 0) {
233 jirafeau_admin_list("", "", "");
234 } elseif (strcmp($_POST['action'], 'search_by_name') == 0) {
235 jirafeau_admin_list($_POST['name'], "", "");
236 } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) {
237 jirafeau_admin_list("", $_POST['hash'], "");
238 } elseif (strcmp($_POST['action'], 'search_link') == 0) {
239 jirafeau_admin_list("", "", $_POST['link']);
240 } elseif (strcmp($_POST['action'], 'delete_link') == 0) {
241 jirafeau_delete_link($_POST['link']);
242 echo '<div class="message">' . NL;
243 echo '<p>' . t('LINK_DELETED') . '</p></div>';
244 } elseif (strcmp($_POST['action'], 'delete_file') == 0) {
245 $count = jirafeau_delete_file($_POST['md5']);
246 echo '<div class="message">' . NL;
247 echo '<p>' . t('DELETED_LINKS') . ' : ' . $count . '</p></div>';
248 } elseif (strcmp($_POST['action'], 'download') == 0) {
249 $l = jirafeau_get_link($_POST['link']);
250 if (!count($l)) {
251 return;
252 }
253 $p = s2p($l['md5']);
254 header('Content-Length: ' . $l['file_size']);
255 header('Content-Type: ' . $l['mime_type']);
256 header('Content-Disposition: attachment; filename="' .
257 $l['file_name'] . '"');
258 if (file_exists(VAR_FILES . $p . $l['md5'])) {
259 readfile(VAR_FILES . $p . $l['md5']);
260 }
261 exit;
262 }
263 }
264
265 require(JIRAFEAU_ROOT.'lib/template/footer.php');
266 }
267 ?>

patrick-canterino.de