]> git.p6c8.net - jirafeau.git/blob - admin.php
[FEATURE] Show readable date format
[jirafeau.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
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('Sorry, the admin interface is not enabled.') .
50 '</p></div>';
51 require(JIRAFEAU_ROOT.'lib/template/footer.php');
52 exit;
53 }
54
55 /* Check session. */
56 session_start();
57
58 /* Unlog if asked. */
59 if (isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
60 $_SESSION['admin_auth'] = false;
61 }
62
63 /* Check classic admin password authentification. */
64 if (isset($_POST['admin_password']) && empty($cfg['admin_http_auth_user'])) {
65 if ($cfg['admin_password'] === $_POST['admin_password'] ||
66 $cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) {
67 $_SESSION['admin_auth'] = true;
68 } else {
69 $_SESSION['admin_auth'] = false;
70 require(JIRAFEAU_ROOT . 'lib/template/header.php');
71 echo '<div class="error"><p>'.
72 t('Wrong password.') . '</p></div>';
73 require(JIRAFEAU_ROOT.'lib/template/footer.php');
74 exit;
75 }
76 }
77 /* Ask for classic admin password authentification. */
78 elseif ((!isset($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true)
79 && empty($cfg['admin_http_auth_user'])) {
80 require(JIRAFEAU_ROOT . 'lib/template/header.php'); ?>
81 <form method="post">
82 <fieldset>
83 <table>
84 <tr>
85 <td class = "label"><label for = "enter_password">
86 <?php echo t('Administration password') . ':'; ?></label>
87 </td>
88 <td class = "field"><input type = "password"
89 name = "admin_password" id = "admin_password"
90 size = "40" />
91 </td>
92 </tr>
93 <tr class = "nav">
94 <td></td>
95 <td class = "nav next">
96 <input type = "submit" name = "key" value =
97 "<?php echo t('Login'); ?>" />
98 </td>
99 </tr>
100 </table>
101 </fieldset>
102 </form>
103 <?php
104 require(JIRAFEAU_ROOT.'lib/template/footer.php');
105 exit;
106 }
107 /* Check authenticated user if HTTP authentification is enable. */
108 elseif ((!isset($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true)
109 && !empty($cfg['admin_http_auth_user'])) {
110 if ($cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER']) {
111 $_SESSION['admin_auth'] = true;
112 }
113 }
114
115 /* Be sure that no one can access further without admin_auth. */
116 if (!isset($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true) {
117 $_SESSION['admin_auth'] = false;
118 require(JIRAFEAU_ROOT . 'lib/template/header.php');
119 echo '<div class="error"><p>'.
120 t('Sorry, you are not authenticated on admin interface.') .
121 '</p></div>';
122 require(JIRAFEAU_ROOT.'lib/template/footer.php');
123 exit;
124 }
125
126 /* Operations may take a long time.
127 * Be sure PHP's safe mode is off.
128 */
129 @set_time_limit(0);
130 /* Remove errors. */
131 @error_reporting(0);
132
133 /* Show admin interface if not downloading a file. */
134 if (!(isset($_POST['action']) && strcmp($_POST['action'], 'download') == 0)) {
135 require(JIRAFEAU_ROOT . 'lib/template/header.php'); ?><h2><?php echo t('Admin interface'); ?></h2><?php
136 ?><h2>(version <?php echo JIRAFEAU_VERSION ?>)</h2><?php
137
138 ?><div id = "admin">
139 <fieldset><legend><?php echo t('Actions'); ?></legend>
140 <table>
141 <form method="post">
142 <tr>
143 <input type = "hidden" name = "action" value = "clean"/>
144 <td class = "info">
145 <?php echo t('Clean expired files'); ?>
146 </td>
147 <td></td>
148 <td>
149 <input type = "submit" value = "<?php echo t('Clean'); ?>" />
150 </td>
151 </tr>
152 </form>
153 <form method="post">
154 <tr>
155 <input type = "hidden" name = "action" value = "clean_async"/>
156 <td class = "info">
157 <?php echo t('Clean old unfinished transfers'); ?>
158 </td>
159 <td></td>
160 <td>
161 <input type = "submit" value = "<?php echo t('Clean'); ?>" />
162 </td>
163 </tr>
164 </form>
165 <form method="post">
166 <tr>
167 <input type = "hidden" name = "action" value = "list"/>
168 <td class = "info">
169 <?php echo t('List all files'); ?>
170 </td>
171 <td></td>
172 <td>
173 <input type = "submit" value = "<?php echo t('List'); ?>" />
174 </td>
175 </tr>
176 </form>
177 <form method="post">
178 <tr>
179 <input type = "hidden" name = "action" value = "search_by_name"/>
180 <td class = "info">
181 <?php echo t('Search files by name'); ?>
182 </td>
183 <td>
184 <input type = "text" name = "name" id = "name"/>
185 </td>
186 <td>
187 <input type = "submit" value = "<?php echo t('Search'); ?>" />
188 </td>
189 </tr>
190 </form>
191 <form method="post">
192 <tr>
193 <input type = "hidden" name = "action" value = "search_by_file_hash"/>
194 <td class = "info">
195 <?php echo t('Search files by file hash'); ?>
196 </td>
197 <td>
198 <input type = "text" name = "hash" id = "hash"/>
199 </td>
200 <td>
201 <input type = "submit" value = "<?php echo t('Search'); ?>" />
202 </td>
203 </tr>
204 </form>
205 <form method="post">
206 <tr>
207 <input type = "hidden" name = "action" value = "search_link"/>
208 <td class = "info">
209 <?php echo t('Search a specific link'); ?>
210 </td>
211 <td>
212 <input type = "text" name = "link" id = "link"/>
213 </td>
214 <td>
215 <input type = "submit" value = "<?php echo t('Search'); ?>" />
216 </td>
217 </tr>
218 </form>
219 </table>
220 <form method="post">
221 <input type = "hidden" name = "action" value = "logout" />
222 <input type = "submit" value = "<?php echo t('Logout'); ?>" />
223 </form>
224 </fieldset></div><?php
225
226 }
227
228 /* Check for actions */
229 if (isset($_POST['action'])) {
230 if (strcmp($_POST['action'], 'clean') == 0) {
231 $total = jirafeau_admin_clean();
232 echo '<div class="message">' . NL;
233 echo '<p>';
234 echo t('Number of cleaned files') . ' : ' . $total;
235 echo '</p></div>';
236 } elseif (strcmp($_POST['action'], 'clean_async') == 0) {
237 $total = jirafeau_admin_clean_async();
238 echo '<div class="message">' . NL;
239 echo '<p>';
240 echo t('Number of cleaned files') . ' : ' . $total;
241 echo '</p></div>';
242 } elseif (strcmp($_POST['action'], 'list') == 0) {
243 jirafeau_admin_list("", "", "");
244 } elseif (strcmp($_POST['action'], 'search_by_name') == 0) {
245 jirafeau_admin_list($_POST['name'], "", "");
246 } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) {
247 jirafeau_admin_list("", $_POST['hash'], "");
248 } elseif (strcmp($_POST['action'], 'search_link') == 0) {
249 jirafeau_admin_list("", "", $_POST['link']);
250 } elseif (strcmp($_POST['action'], 'delete_link') == 0) {
251 jirafeau_delete_link($_POST['link']);
252 echo '<div class="message">' . NL;
253 echo '<p>' . t('Link deleted') . '</p></div>';
254 } elseif (strcmp($_POST['action'], 'delete_file') == 0) {
255 $count = jirafeau_delete_file($_POST['md5']);
256 echo '<div class="message">' . NL;
257 echo '<p>' . t('Deleted links') . ' : ' . $count . '</p></div>';
258 } elseif (strcmp($_POST['action'], 'download') == 0) {
259 $l = jirafeau_get_link($_POST['link']);
260 if (!count($l)) {
261 return;
262 }
263 $p = s2p($l['md5']);
264 header('Content-Length: ' . $l['file_size']);
265 header('Content-Type: ' . $l['mime_type']);
266 header('Content-Disposition: attachment; filename="' .
267 $l['file_name'] . '"');
268 if (file_exists(VAR_FILES . $p . $l['md5'])) {
269 readfile(VAR_FILES . $p . $l['md5']);
270 }
271 exit;
272 }
273 }
274
275 require(JIRAFEAU_ROOT.'lib/template/footer.php');
276 }
277 ?>

patrick-canterino.de