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

patrick-canterino.de