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

patrick-canterino.de