1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | file : $Id: functions_check_integrity.inc.php 2104 2007-09-21 21:23:09Z rub $ |
---|
8 | // | last update : $Date: 2007-09-21 21:23:09 +0000 (Fri, 21 Sep 2007) $ |
---|
9 | // | last modifier : $Author: rub $ |
---|
10 | // | revision : $Revision: 2104 $ |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | This program is free software; you can redistribute it and/or modify | |
---|
13 | // | it under the terms of the GNU General Public License as published by | |
---|
14 | // | the Free Software Foundation | |
---|
15 | // | | |
---|
16 | // | This program is distributed in the hope that it will be useful, but | |
---|
17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
19 | // | General Public License for more details. | |
---|
20 | // | | |
---|
21 | // | You should have received a copy of the GNU General Public License | |
---|
22 | // | along with this program; if not, write to the Free Software | |
---|
23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
24 | // | USA. | |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | |
---|
27 | /** |
---|
28 | * Check integrity |
---|
29 | * |
---|
30 | * @param void |
---|
31 | * @return void |
---|
32 | */ |
---|
33 | function check_integrity() |
---|
34 | { |
---|
35 | global $page, $header_notes; |
---|
36 | |
---|
37 | add_event_handler('get_check_integrity', 'c13y_exif'); |
---|
38 | add_event_handler('get_check_integrity', 'c13y_user'); |
---|
39 | |
---|
40 | $page['check_integrity'] = array(); |
---|
41 | $page['check_integrity'] = trigger_event('get_check_integrity', |
---|
42 | $page['check_integrity']); |
---|
43 | |
---|
44 | if (count($page['check_integrity']) > 0) |
---|
45 | { |
---|
46 | $header_notes[] = |
---|
47 | l10n_dec('c13y_anomaly_count', 'c13y_anomalies_count', |
---|
48 | count($page['check_integrity'])); |
---|
49 | } |
---|
50 | |
---|
51 | if (!is_adviser()) |
---|
52 | { |
---|
53 | if (isset($_POST['c13y_submit']) and isset($_POST['c13y_selection'])) |
---|
54 | { |
---|
55 | $corrected_count = 0; |
---|
56 | $not_corrected_count = 0; |
---|
57 | |
---|
58 | foreach ($page['check_integrity'] as $i => $c13y) |
---|
59 | { |
---|
60 | if (!empty($c13y['correction_fct']) and |
---|
61 | $c13y['is_callable'] and |
---|
62 | in_array($c13y['id'], $_POST['c13y_selection'])) |
---|
63 | { |
---|
64 | if (is_array($c13y['correction_fct_args'])) |
---|
65 | { |
---|
66 | $args = $c13y['correction_fct_args']; |
---|
67 | } |
---|
68 | else |
---|
69 | if (!is_null($c13y['correction_fct_args'])) |
---|
70 | { |
---|
71 | $args = array($c13y['correction_fct_args']); |
---|
72 | } |
---|
73 | else |
---|
74 | { |
---|
75 | $args = array(); |
---|
76 | } |
---|
77 | $page['check_integrity'][$i]['corrected'] = call_user_func_array($c13y['correction_fct'], $args); |
---|
78 | |
---|
79 | if ($page['check_integrity'][$i]['corrected']) |
---|
80 | { |
---|
81 | $corrected_count += 1; |
---|
82 | } |
---|
83 | else |
---|
84 | { |
---|
85 | $not_corrected_count += 1; |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | if ($corrected_count > 0) |
---|
91 | { |
---|
92 | $page['infos'][] = |
---|
93 | l10n_dec('c13y_anomaly_corrected_count', 'c13y_anomalies_corrected_count', |
---|
94 | $corrected_count); |
---|
95 | } |
---|
96 | if ($not_corrected_count > 0) |
---|
97 | { |
---|
98 | $page['errors'][] = |
---|
99 | l10n_dec('c13y_anomaly_not_corrected_count', 'c13y_anomalies_not_corrected_count', |
---|
100 | $not_corrected_count); |
---|
101 | } |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * Display anomalies list |
---|
108 | * |
---|
109 | * @param void |
---|
110 | * @return void |
---|
111 | */ |
---|
112 | function display_check_integrity() |
---|
113 | { |
---|
114 | global $template, $page; |
---|
115 | |
---|
116 | $show_submit = false; |
---|
117 | |
---|
118 | if (isset($page['check_integrity']) and count($page['check_integrity']) > 0) |
---|
119 | { |
---|
120 | $template->set_filenames(array('check_integrity' => 'admin/check_integrity.tpl')); |
---|
121 | |
---|
122 | foreach ($page['check_integrity'] as $i => $c13y) |
---|
123 | { |
---|
124 | $template->assign_block_vars('c13y', |
---|
125 | array( |
---|
126 | 'CLASS' => ($i % 2 == 1) ? 'row2' : 'row1', |
---|
127 | 'ID' => $c13y['id'], |
---|
128 | 'ANOMALY' => $c13y['anomaly'] |
---|
129 | )); |
---|
130 | |
---|
131 | if (!empty($c13y['correction_fct'])) |
---|
132 | { |
---|
133 | if (isset($c13y['corrected'])) |
---|
134 | { |
---|
135 | if ($c13y['corrected']) |
---|
136 | { |
---|
137 | $template->assign_block_vars('c13y.correction_success_fct', array()); |
---|
138 | } |
---|
139 | else |
---|
140 | { |
---|
141 | $template->assign_block_vars('c13y.correction_error_fct', |
---|
142 | array('WIKI_FOROM_LINKS' => get_htlm_links_more_info())); |
---|
143 | } |
---|
144 | } |
---|
145 | else if ($c13y['is_callable']) |
---|
146 | { |
---|
147 | $template->assign_block_vars('c13y.correction_fct', array()); |
---|
148 | $show_submit = true; |
---|
149 | } |
---|
150 | else |
---|
151 | { |
---|
152 | $template->assign_block_vars('c13y.correction_bad_fct', array()); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | if (!empty($c13y['correction_fct']) and !empty($c13y['correction_msg'])) |
---|
157 | { |
---|
158 | $template->assign_block_vars('c13y.br', array()); |
---|
159 | } |
---|
160 | |
---|
161 | if (!empty($c13y['correction_msg']) and !isset($c13y['corrected'])) |
---|
162 | { |
---|
163 | $template->assign_block_vars('c13y.correction_msg', |
---|
164 | array( |
---|
165 | 'DATA' => nl2br($c13y['correction_msg']) |
---|
166 | )); |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | if ($show_submit) |
---|
171 | { |
---|
172 | $template->assign_block_vars('c13y_submit', array()); |
---|
173 | } |
---|
174 | |
---|
175 | $template->concat_var_from_handle('ADMIN_CONTENT', 'check_integrity'); |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | /** |
---|
180 | * Returns structured anomaly data |
---|
181 | * |
---|
182 | * @param anomaly arguments |
---|
183 | * @return c13y anomaly array |
---|
184 | */ |
---|
185 | function get_c13y($anomaly, $correction_fct = null, $correction_fct_args = null, $correction_msg = null) |
---|
186 | { |
---|
187 | return |
---|
188 | array( |
---|
189 | 'id' => md5($anomaly.$correction_fct.serialize($correction_fct_args).$correction_msg), |
---|
190 | 'anomaly' => $anomaly, |
---|
191 | 'correction_fct' => $correction_fct, |
---|
192 | 'correction_fct_args' => $correction_fct_args, |
---|
193 | 'correction_msg' => $correction_msg, |
---|
194 | 'is_callable' => is_callable($correction_fct)); |
---|
195 | } |
---|
196 | |
---|
197 | /** |
---|
198 | * Returns links more informations |
---|
199 | * |
---|
200 | * @param void |
---|
201 | * @return html links |
---|
202 | */ |
---|
203 | function get_htlm_links_more_info() |
---|
204 | { |
---|
205 | $pwg_links = pwg_URL(); |
---|
206 | $link_fmt = '<a href="%s" onclick="window.open(this.href, \'\'); return false;">%s</a>'; |
---|
207 | return |
---|
208 | sprintf |
---|
209 | ( |
---|
210 | l10n('c13y_more_info'), |
---|
211 | sprintf($link_fmt, $pwg_links['FORUM'], l10n('c13y_more_info_forum')), |
---|
212 | sprintf($link_fmt, $pwg_links['WIKI'], l10n('c13y_more_info_wiki')) |
---|
213 | ); |
---|
214 | } |
---|
215 | |
---|
216 | /** |
---|
217 | * Check exif |
---|
218 | * |
---|
219 | * @param c13y anomalies array |
---|
220 | * @return c13y anomalies array |
---|
221 | */ |
---|
222 | function c13y_exif($c13y_array) |
---|
223 | { |
---|
224 | global $conf; |
---|
225 | |
---|
226 | foreach (array('show_exif', 'use_exif') as $value) |
---|
227 | { |
---|
228 | if (($conf[$value]) and (!function_exists('read_exif_data'))) |
---|
229 | { |
---|
230 | $c13y_array[] = get_c13y( |
---|
231 | sprintf(l10n('c13y_exif_anomaly'), '$conf[\''.$value.'\']'), |
---|
232 | null, |
---|
233 | null, |
---|
234 | sprintf(l10n('c13y_exif_correction'), '$conf[\''.$value.'\']') |
---|
235 | .'<BR />'. |
---|
236 | get_htlm_links_more_info()); |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|
240 | return $c13y_array; |
---|
241 | } |
---|
242 | |
---|
243 | /** |
---|
244 | * Check user |
---|
245 | * |
---|
246 | * @param c13y anomalies array |
---|
247 | * @return c13y anomalies array |
---|
248 | */ |
---|
249 | function c13y_user($c13y_array) |
---|
250 | { |
---|
251 | global $conf; |
---|
252 | |
---|
253 | $c13y_users = array(); |
---|
254 | $c13y_users[$conf['guest_id']] = array( |
---|
255 | 'status' => 'guest', |
---|
256 | 'l10n_non_existent' => 'c13y_guest_non_existent', |
---|
257 | 'l10n_bad_status' => 'c13y_bad_guest_status'); |
---|
258 | |
---|
259 | if ($conf['guest_id'] != $conf['default_user_id']) |
---|
260 | { |
---|
261 | $c13y_users[$conf['default_user_id']] = array( |
---|
262 | 'password' => null, |
---|
263 | 'l10n_non_existent' => 'c13y_default_non_existent'); |
---|
264 | } |
---|
265 | |
---|
266 | $c13y_users[$conf['webmaster_id']] = array( |
---|
267 | 'status' => 'webmaster', |
---|
268 | 'l10n_non_existent' => 'c13y_webmaster_non_existent', |
---|
269 | 'l10n_bad_status' => 'c13y_bad_webmaster_status'); |
---|
270 | |
---|
271 | $query = ' |
---|
272 | select u.'.$conf['user_fields']['id'].' as id, ui.status |
---|
273 | from '.USERS_TABLE.' as u |
---|
274 | left join '.USER_INFOS_TABLE.' as ui |
---|
275 | on u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
276 | where |
---|
277 | u.'.$conf['user_fields']['id'].' in ('.implode(',', array_keys($c13y_users)).') |
---|
278 | ;'; |
---|
279 | |
---|
280 | |
---|
281 | $status = array(); |
---|
282 | |
---|
283 | $result = pwg_query($query); |
---|
284 | while ($row = mysql_fetch_array($result)) |
---|
285 | { |
---|
286 | $status[$row['id']] = $row['status']; |
---|
287 | } |
---|
288 | |
---|
289 | foreach ($c13y_users as $id => $data) |
---|
290 | { |
---|
291 | if (!array_key_exists($id, $status)) |
---|
292 | { |
---|
293 | $c13y_array[] = get_c13y(l10n($data['l10n_non_existent']), 'c13y_correction_user', |
---|
294 | array('id' => $id, 'action' => 'creation')); |
---|
295 | } |
---|
296 | else |
---|
297 | if (!empty($data['status']) and $status[$id] != $data['status']) |
---|
298 | { |
---|
299 | $c13y_array[] = get_c13y(l10n($data['l10n_bad_status']), 'c13y_correction_user', |
---|
300 | array('id' => $id, 'action' => 'status')); |
---|
301 | } |
---|
302 | } |
---|
303 | |
---|
304 | return $c13y_array; |
---|
305 | } |
---|
306 | |
---|
307 | /** |
---|
308 | * Do correction user |
---|
309 | * |
---|
310 | * @param user_id, action |
---|
311 | * @return boolean true if ok else false |
---|
312 | */ |
---|
313 | function c13y_correction_user($id, $action) |
---|
314 | { |
---|
315 | global $conf, $page; |
---|
316 | |
---|
317 | $result = false; |
---|
318 | |
---|
319 | if (!empty($id)) |
---|
320 | { |
---|
321 | switch ($action) |
---|
322 | { |
---|
323 | case 'creation': |
---|
324 | if ($id == $conf['guest_id']) |
---|
325 | { |
---|
326 | $name = 'guest'; |
---|
327 | $password = null; |
---|
328 | } |
---|
329 | else if ($id == $conf['default_user_id']) |
---|
330 | { |
---|
331 | $name = 'guest'; |
---|
332 | $password = null; |
---|
333 | } |
---|
334 | else if ($id == $conf['webmaster_id']) |
---|
335 | { |
---|
336 | $name = 'webmaster'; |
---|
337 | $password = generate_key(6); |
---|
338 | } |
---|
339 | |
---|
340 | if (isset($name)) |
---|
341 | { |
---|
342 | $name_ok = false; |
---|
343 | while (!$name_ok) |
---|
344 | { |
---|
345 | $name_ok = (get_userid($name) === false); |
---|
346 | if (!$name_ok) |
---|
347 | { |
---|
348 | $name .= generate_key(1); |
---|
349 | } |
---|
350 | } |
---|
351 | |
---|
352 | $inserts = array( |
---|
353 | array( |
---|
354 | 'id' => $id, |
---|
355 | 'username' => $name, |
---|
356 | 'password' => $password |
---|
357 | ), |
---|
358 | ); |
---|
359 | mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts); |
---|
360 | |
---|
361 | create_user_infos($id); |
---|
362 | |
---|
363 | $page['infos'][] = sprintf(l10n('c13y_user_created'), $name, $password); |
---|
364 | |
---|
365 | $result = true; |
---|
366 | } |
---|
367 | break; |
---|
368 | case 'status': |
---|
369 | if ($id == $conf['guest_id']) |
---|
370 | { |
---|
371 | $status = 'guest'; |
---|
372 | } |
---|
373 | else if ($id == $conf['default_user_id']) |
---|
374 | { |
---|
375 | $status = 'guest'; |
---|
376 | } |
---|
377 | else if ($id == $conf['webmaster_id']) |
---|
378 | { |
---|
379 | $status = 'webmaster'; |
---|
380 | } |
---|
381 | |
---|
382 | if (isset($status)) |
---|
383 | { |
---|
384 | $updates = array( |
---|
385 | array( |
---|
386 | 'user_id' => $id, |
---|
387 | 'status' => $status |
---|
388 | ), |
---|
389 | ); |
---|
390 | mass_updates(USER_INFOS_TABLE, |
---|
391 | array('primary' => array('user_id'),'update' => array('status')), |
---|
392 | $updates); |
---|
393 | |
---|
394 | $page['infos'][] = sprintf(l10n('c13y_user_status_updated'), get_username($id)); |
---|
395 | |
---|
396 | $result = true; |
---|
397 | } |
---|
398 | break; |
---|
399 | } |
---|
400 | } |
---|
401 | |
---|
402 | return $result; |
---|
403 | } |
---|
404 | |
---|
405 | ?> |
---|