]> git.p6c8.net - jirafeau.git/blob - admin.php
afcccb512708bfdd15549df10d8aababbaafa92e
[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/config.original.php');
23 require (JIRAFEAU_ROOT . 'lib/settings.php');
24 require (JIRAFEAU_ROOT . 'lib/functions.php');
25 require (JIRAFEAU_ROOT . 'lib/lang.php');
26
27 /* Check if installation is OK. */
28 if (file_exists (JIRAFEAU_ROOT . 'install.php')
29 && !file_exists (JIRAFEAU_ROOT . 'lib/config.local.php'))
30 {
31 header('Location: install.php');
32 exit;
33 }
34
35 /* Disable admin interface if we have a empty admin password. */
36 if (empty($cfg['admin_password']))
37 {
38 require (JIRAFEAU_ROOT . 'lib/template/header.php');
39 echo '<div class="error"><p>'.
40 t('Sorry, the admin interface is not enabled.') .
41 '</p></div>';
42 require (JIRAFEAU_ROOT.'lib/template/footer.php');
43 exit;
44 }
45
46 /* Check session. */
47 session_start();
48
49 /* Unlog if asked. */
50 if (isset ($_POST['action']) && (strcmp ($_POST['action'], 'logout') == 0))
51 $_SESSION['admin_auth'] = false;
52
53 /* Check password. */
54 if (isset ($_POST['admin_password']))
55 {
56 if (strcmp ($cfg['admin_password'], $_POST['admin_password']) == 0)
57 $_SESSION['admin_auth'] = true;
58 else
59 {
60 $_SESSION['admin_auth'] = false;
61 require (JIRAFEAU_ROOT . 'lib/template/header.php');
62 echo '<div class="error"><p>'.
63 t('Wrong password.') . '</p></div>';
64 require (JIRAFEAU_ROOT.'lib/template/footer.php');
65 exit;
66 }
67 }
68 /* Ask for password. */
69 elseif (!isset ($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true)
70 {
71 require (JIRAFEAU_ROOT . 'lib/template/header.php'); ?>
72 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
73 <fieldset>
74 <table>
75 <tr>
76 <td class = "label"><label for = "enter_password">
77 <?php echo t('Administration password') . ':';?></label>
78 </td>
79 <td class = "field"><input type = "password"
80 name = "admin_password" id = "admin_password"
81 size = "40" />
82 </td>
83 </tr>
84 <tr class = "nav">
85 <td></td>
86 <td class = "nav next">
87 <input type = "submit" name = "key" value =
88 "<?php echo t('Login'); ?>" />
89 </td>
90 </tr>
91 </table>
92 </fieldset>
93 </form>
94 <?php
95 require (JIRAFEAU_ROOT.'lib/template/footer.php');
96 exit;
97 }
98
99 /* Operations may take a long time.
100 * Be sure PHP's safe mode is off.
101 */
102 @set_time_limit(0);
103 /* Remove errors. */
104 @error_reporting(0);
105
106 /* Admin interface. */
107 require (JIRAFEAU_ROOT . 'lib/template/header.php');
108 ?><h2><?php echo t('Admin interface'); ?></h2><?php
109
110 /* Show admin interface. */
111 {
112 ?><div id = "install">
113 <fieldset><legend><?php echo t('Actions');?></legend>
114 <table>
115 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
116 <tr>
117 <input type = "hidden" name = "action" value = "clean"/>
118 <td class = "info">
119 <?php echo t('Clean expired files'); ?>
120 </td>
121 <td></td>
122 <td>
123 <input type = "submit" value = "<?php echo t('Clean'); ?>" />
124 </td>
125 </tr>
126 </form>
127 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
128 <tr>
129 <input type = "hidden" name = "action" value = "clean_async"/>
130 <td class = "info">
131 <?php echo t('Clean old unfinished transferts'); ?>
132 </td>
133 <td></td>
134 <td>
135 <input type = "submit" value = "<?php echo t('Clean'); ?>" />
136 </td>
137 </tr>
138 </form>
139 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
140 <tr>
141 <input type = "hidden" name = "action" value = "list"/>
142 <td class = "info">
143 <?php echo t('List all files'); ?>
144 </td>
145 <td></td>
146 <td>
147 <input type = "submit" value = "<?php echo t('List'); ?>" />
148 </td>
149 </tr>
150 </form>
151 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
152 <tr>
153 <input type = "hidden" name = "action" value = "search_by_name"/>
154 <td class = "info">
155 <?php echo t('Search files by name'); ?>
156 </td>
157 <td>
158 <input type = "text" name = "name" id = "name"/>
159 </td>
160 <td>
161 <input type = "submit" value = "<?php echo t('Search'); ?>" />
162 </td>
163 </tr>
164 </form>
165 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
166 <tr>
167 <input type = "hidden" name = "action" value = "search_by_file_hash"/>
168 <td class = "info">
169 <?php echo t('Search files by file hash'); ?>
170 </td>
171 <td>
172 <input type = "text" name = "hash" id = "hash"/>
173 </td>
174 <td>
175 <input type = "submit" value = "<?php echo t('Search'); ?>" />
176 </td>
177 </tr>
178 </form>
179 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
180 <tr>
181 <input type = "hidden" name = "action" value = "search_link"/>
182 <td class = "info">
183 <?php echo t('Search a specific link'); ?>
184 </td>
185 <td>
186 <input type = "text" name = "link" id = "link"/>
187 </td>
188 <td>
189 <input type = "submit" value = "<?php echo t('Search'); ?>" />
190 </td>
191 </tr>
192 </form>
193 </table>
194 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
195 <input type = "hidden" name = "action" value = "logout"/>
196 <input type = "submit" value = "<?php echo t('Logout'); ?>" />
197 </form>
198 </fieldset></div><?php
199 }
200
201 /* Check for actions */
202 if (isset ($_POST['action']))
203 {
204 if (strcmp ($_POST['action'], 'clean') == 0)
205 {
206 $total = jirafeau_admin_clean ();
207 echo '<div class="message">' . NL;
208 echo '<p>';
209 echo t('Number of cleaned files') . ' : ' . $total;
210 echo '</p></div>';
211 }
212 elseif (strcmp ($_POST['action'], 'clean_async') == 0)
213 {
214 $total = jirafeau_admin_clean_async ();
215 echo '<div class="message">' . NL;
216 echo '<p>';
217 echo t('Number of cleaned files') . ' : ' . $total;
218 echo '</p></div>';
219 }
220 elseif (strcmp ($_POST['action'], 'list') == 0)
221 {
222 jirafeau_admin_list ("", "", "");
223 }
224 elseif (strcmp ($_POST['action'], 'search_by_name') == 0)
225 {
226 jirafeau_admin_list ($_POST['name'], "", "");
227 }
228 elseif (strcmp ($_POST['action'], 'search_by_file_hash') == 0)
229 {
230 jirafeau_admin_list ("", $_POST['hash'], "");
231 }
232 elseif (strcmp ($_POST['action'], 'search_link') == 0)
233 {
234 jirafeau_admin_list ("", "", $_POST['link']);
235 }
236 elseif (strcmp ($_POST['action'], 'delete_link') == 0)
237 {
238 jirafeau_delete_link ($_POST['link']);
239 echo '<div class="message">' . NL;
240 echo '<p>' . t('Link deleted') . '</p></div>';
241 }
242 elseif (strcmp ($_POST['action'], 'delete_file') == 0)
243 {
244 $count = jirafeau_delete_file ($_POST['md5']);
245 echo '<div class="message">' . NL;
246 echo '<p>' . t('Deleted links') . ' : ' . $count . '</p></div>';
247 }
248 elseif (strcmp ($_POST['action'], 'download') == 0)
249 {
250 $l = jirafeau_get_link ($_POST['link']);
251 if (!count ($l))
252 return;
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 }
262
263 require (JIRAFEAU_ROOT.'lib/template/footer.php');
264
265 ?>

patrick-canterino.de