diff options
author | rub <rub@piwigo.org> | 2007-07-18 22:48:50 +0000 |
---|---|---|
committer | rub <rub@piwigo.org> | 2007-07-18 22:48:50 +0000 |
commit | b879e1742485db53da3edad98be036791bfd1bbf (patch) | |
tree | e056e514016bec1c2b23911b05c5cc54e8580821 | |
parent | ec6395c91169af249bd31d8eb06e103413cff749 (diff) |
Resolved issue 0000725: Check integrity
Replace actual test (exif) by a new dynamic system of check integrity.
Anomalies are listed with automatic correction if it's possible.
It's a proposition of new feature!
git-svn-id: http://piwigo.org/svn/trunk@2065 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | admin.php | 13 | ||||
-rw-r--r-- | admin/include/functions.php | 36 | ||||
-rw-r--r-- | admin/include/functions_check_integrity.inc.php | 405 | ||||
-rw-r--r-- | admin/intro.php | 2 | ||||
-rw-r--r-- | language/en_UK.iso-8859-1/admin.lang.php | 30 | ||||
-rw-r--r-- | language/fr_FR.iso-8859-1/admin.lang.php | 30 | ||||
-rw-r--r-- | template/yoga/admin/check_integrity.tpl | 49 |
7 files changed, 515 insertions, 50 deletions
@@ -44,12 +44,6 @@ check_status(ACCESS_ADMINISTRATOR); sync_users(); // +-----------------------------------------------------------------------+ -// | Check configuration and add notes on problem | -// +-----------------------------------------------------------------------+ - -check_conf(); - -// +-----------------------------------------------------------------------+ // | variables init | // +-----------------------------------------------------------------------+ @@ -67,6 +61,13 @@ else $page['errors'] = array(); $page['infos'] = array(); + +if ($page['page'] == 'intro') +{ + include_once(PHPWG_ROOT_PATH.'admin/include/functions_check_integrity.inc.php'); + check_integrity(); +} + $link_start = PHPWG_ROOT_PATH.'admin.php?page='; $conf_link = $link_start.'configuration&section='; //----------------------------------------------------- template initialization diff --git a/admin/include/functions.php b/admin/include/functions.php index 66deb5777..3614c0904 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -1952,42 +1952,6 @@ SELECT id, } /** - * Check configuration and add notes on problem - * - * @param void - * @return void - */ -function check_conf() -{ - global $conf, $header_notes; - $count = 0; - - if (($conf['show_exif']) and (!function_exists('read_exif_data'))) - { - $header_notes[] = sprintf(l10n('note_check_exif'), '$conf[\'show_exif\']'); - $count++; - } - - if (($conf['use_exif']) and (!function_exists('read_exif_data'))) - { - $header_notes[] = sprintf(l10n('note_check_exif'), '$conf[\'use_exif\']'); - $count++; - } - - if ($count != 0) - { - $pwg_links = pwg_URL(); - $link_fmt = '<a href="%s" onclick="window.open(this.href, \'\'); return false;">%s</a>'; - $header_notes[] = - sprintf - ( - l10n('note_check_more_info'), - sprintf($link_fmt, $pwg_links['FORUM'], l10n('note_check_more_info_forum')), - sprintf($link_fmt, $pwg_links['WIKI'], l10n('note_check_more_info_wiki')) - ); - } -} -/** * Refer main PhpWebGallery URLs (currently PHPWG_DOMAIN domain) * * @param void diff --git a/admin/include/functions_check_integrity.inc.php b/admin/include/functions_check_integrity.inc.php new file mode 100644 index 000000000..65b7aa2b0 --- /dev/null +++ b/admin/include/functions_check_integrity.inc.php @@ -0,0 +1,405 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | file : $Id$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +/** + * Check integrity + * + * @param void + * @return void + */ +function check_integrity() +{ + global $page, $header_notes; + + add_event_handler('get_check_integrity', 'c13y_exif'); + add_event_handler('get_check_integrity', 'c13y_user'); + + $page['check_integrity'] = array(); + $page['check_integrity'] = trigger_event('get_check_integrity', + $page['check_integrity']); + + if (count($page['check_integrity']) > 0) + { + $header_notes[] = + l10n_dec('c13y_anomaly_count', 'c13y_anomalies_count', + count($page['check_integrity'])); + } + + if (!is_adviser()) + { + if (isset($_POST['c13y_submit']) and isset($_POST['c13y_selection'])) + { + $corrected_count = 0; + $not_corrected_count = 0; + + foreach ($page['check_integrity'] as $i => $c13y) + { + if (!empty($c13y['correction_fct']) and + $c13y['is_callable'] and + in_array($c13y['id'], $_POST['c13y_selection'])) + { + if (is_array($c13y['correction_fct_args'])) + { + $args = $c13y['correction_fct_args']; + } + else + if (!is_null($c13y['correction_fct_args'])) + { + $args = array($c13y['correction_fct_args']); + } + else + { + $args = array(); + } + $page['check_integrity'][$i]['corrected'] = call_user_func_array($c13y['correction_fct'], $args); + + if ($page['check_integrity'][$i]['corrected']) + { + $corrected_count += 1; + } + else + { + $not_corrected_count += 1; + } + } + } + + if ($corrected_count > 0) + { + $page['infos'][] = + l10n_dec('c13y_anomaly_corrected_count', 'c13y_anomalies_corrected_count', + $corrected_count); + } + if ($not_corrected_count > 0) + { + $page['errors'][] = + l10n_dec('c13y_anomaly_not_corrected_count', 'c13y_anomalies_not_corrected_count', + $not_corrected_count); + } + } + } +} + +/** + * Display anomalies list + * + * @param void + * @return void + */ +function display_check_integrity() +{ + global $template, $page; + + $show_submit = false; + + if (isset($page['check_integrity']) and count($page['check_integrity']) > 0) + { + $template->set_filenames(array('check_integrity' => 'admin/check_integrity.tpl')); + + foreach ($page['check_integrity'] as $i => $c13y) + { + $template->assign_block_vars('c13y', + array( + 'CLASS' => ($i % 2 == 1) ? 'row2' : 'row1', + 'ID' => $c13y['id'], + 'ANOMALY' => $c13y['anomaly'] + )); + + if (!empty($c13y['correction_fct'])) + { + if (isset($c13y['corrected'])) + { + if ($c13y['corrected']) + { + $template->assign_block_vars('c13y.correction_success_fct', array()); + } + else + { + $template->assign_block_vars('c13y.correction_error_fct', + array('WIKI_FOROM_LINKS' => get_htlm_links_more_info())); + } + } + else if ($c13y['is_callable']) + { + $template->assign_block_vars('c13y.correction_fct', array()); + $show_submit = true; + } + else + { + $template->assign_block_vars('c13y.correction_bad_fct', array()); + } + } + + if (!empty($c13y['correction_fct']) and !empty($c13y['correction_msg'])) + { + $template->assign_block_vars('c13y.br', array()); + } + + if (!empty($c13y['correction_msg']) and !isset($c13y['corrected'])) + { + $template->assign_block_vars('c13y.correction_msg', + array( + 'DATA' => nl2br($c13y['correction_msg']) + )); + } + } + + if ($show_submit) + { + $template->assign_block_vars('c13y_submit', array()); + } + + $template->concat_var_from_handle('ADMIN_CONTENT', 'check_integrity'); + } +} + +/** + * Returns structured anomaly data + * + * @param anomaly arguments + * @return c13y anomaly array + */ +function get_c13y($anomaly, $correction_fct = null, $correction_fct_args = null, $correction_msg = null) +{ + return + array( + 'id' => md5($anomaly.$correction_fct.serialize($correction_fct_args).$correction_msg), + 'anomaly' => $anomaly, + 'correction_fct' => $correction_fct, + 'correction_fct_args' => $correction_fct_args, + 'correction_msg' => $correction_msg, + 'is_callable' => is_callable($correction_fct)); +} + +/** + * Returns links more informations + * + * @param void + * @return html links + */ +function get_htlm_links_more_info() +{ + $pwg_links = pwg_URL(); + $link_fmt = '<a href="%s" onclick="window.open(this.href, \'\'); return false;">%s</a>'; + return + sprintf + ( + l10n('c13y_more_info'), + sprintf($link_fmt, $pwg_links['FORUM'], l10n('c13y_more_info_forum')), + sprintf($link_fmt, $pwg_links['WIKI'], l10n('c13y_more_info_wiki')) + ); +} + +/** + * Check exif + * + * @param c13y anomalies array + * @return c13y anomalies array + */ +function c13y_exif($c13y_array) +{ + global $conf; + + foreach (array('show_exif', 'use_exif') as $value) + { + if (($conf[$value]) and (!function_exists('read_exif_data'))) + { + $c13y_array[] = get_c13y( + sprintf(l10n('c13y_exif_anomaly'), '$conf[\''.$value.'\']'), + null, + null, + sprintf(l10n('c13y_exif_correction'), '$conf[\''.$value.'\']') + .'<BR />'. + get_htlm_links_more_info()); + } + } + + return $c13y_array; +} + +/** + * Check user + * + * @param c13y anomalies array + * @return c13y anomalies array + */ +function c13y_user($c13y_array) +{ + global $conf; + + $c13y_users = array(); + $c13y_users[$conf['guest_id']] = array( + 'status' => 'guest', + 'l10n_non_existent' => 'c13y_guest_non_existent', + 'l10n_bad_status' => 'c13y_bad_guest_status'); + + if ($conf['guest_id'] != $conf['default_user_id']) + { + $c13y_users[$conf['default_user_id']] = array( + 'password' => null, + 'l10n_non_existent' => 'c13y_default_non_existent'); + } + + $c13y_users[$conf['webmaster_id']] = array( + 'status' => 'webmaster', + 'l10n_non_existent' => 'c13y_webmaster_non_existent', + 'l10n_bad_status' => 'c13y_bad_webmaster_status'); + + $query = ' +select u.'.$conf['user_fields']['id'].' as id, ui.status +from '.USERS_TABLE.' as u + left join '.USER_INFOS_TABLE.' as ui + on u.'.$conf['user_fields']['id'].' = ui.user_id +where + u.'.$conf['user_fields']['id'].' in ('.implode(',', array_keys($c13y_users)).') +;'; + + + $status = array(); + + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + $status[$row['id']] = $row['status']; + } + + foreach ($c13y_users as $id => $data) + { + if (!array_key_exists($id, $status)) + { + $c13y_array[] = get_c13y(l10n($data['l10n_non_existent']), 'c13y_correction_user', + array('id' => $id, 'action' => 'creation')); + } + else + if (!empty($data['status']) and $status[$id] != $data['status']) + { + $c13y_array[] = get_c13y(l10n($data['l10n_bad_status']), 'c13y_correction_user', + array('id' => $id, 'action' => 'status')); + } + } + + return $c13y_array; +} + +/** + * Check exif + * + * @param user_id, action + * @return boolean true if ok else false + */ +function c13y_correction_user($id, $action) +{ + global $conf, $page; + + $result = false; + + if (!empty($id)) + { + switch ($action) + { + case 'creation': + if ($id == $conf['guest_id']) + { + $name = 'guest'; + $password = null; + } + else if ($id == $conf['default_user_id']) + { + $name = 'guest'; + $password = null; + } + else if ($id == $conf['webmaster_id']) + { + $name = 'webmaster'; + $password = generate_key(6); + } + + if (isset($name)) + { + $name_ok = false; + while (!$name_ok) + { + $name_ok = (get_userid($name) === false); + if (!$name_ok) + { + $name .= generate_key(1); + } + } + + $inserts = array( + array( + 'id' => $id, + 'username' => $name, + 'password' => $password + ), + ); + mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts); + + create_user_infos($id); + + $page['infos'][] = sprintf(l10n('c13y_user_created'), $name, $password); + + $result = true; + } + break; + case 'status': + if ($id == $conf['guest_id']) + { + $status = 'guest'; + } + else if ($id == $conf['default_user_id']) + { + $status = 'guest'; + } + else if ($id == $conf['webmaster_id']) + { + $status = 'webmaster'; + } + + if (isset($status)) + { + $updates = array( + array( + 'user_id' => $id, + 'status' => $status + ), + ); + mass_updates(USER_INFOS_TABLE, + array('primary' => array('user_id'),'update' => array('status')), + $updates); + + $page['infos'][] = sprintf(l10n('c13y_user_status_updated'), get_username($id)); + + $result = true; + } + break; + } + } + + return $result; +} + +?> diff --git a/admin/intro.php b/admin/intro.php index 7c50ce2ce..6014b2d19 100644 --- a/admin/intro.php +++ b/admin/intro.php @@ -278,4 +278,6 @@ if ($nb_comments > 0) $template->assign_var_from_handle('ADMIN_CONTENT', 'intro'); +display_check_integrity(); + ?> diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php index 067a49330..7a313118f 100644 --- a/language/en_UK.iso-8859-1/admin.lang.php +++ b/language/en_UK.iso-8859-1/admin.lang.php @@ -554,10 +554,6 @@ $lang['Web Services availability duration in days'] = 'Web Services availability $lang['Web Services under control'] = 'PhpWebGallery Web Services are fully operationals and all requests are under control.'; $lang['special_admin_menu'] = 'Specials'; $lang['pictures_menu'] = 'Pictures'; -$lang['note_check_exif'] = '%s must be to set to false in your config_local.inc.php file because exif are not supported.'; -$lang['note_check_more_info'] = 'Go to %s or %s for more informations.'; -$lang['note_check_more_info_forum'] = 'the forum'; -$lang['note_check_more_info_wiki'] = 'the wiki'; $lang['Duplicates'] = 'Files with same name in more than one physical category'; $lang['DEMO'] = 'DEMO'; $lang['HOME'] = 'HOME'; @@ -618,4 +614,30 @@ $lang['Default user cannot be deleted'] = 'Default user cannot be deleted'; $lang['obligatory_user_mail_address'] = 'Mail address is obligatory for all users'; $lang['purge history detail'] = 'purge history detail'; $lang['purge history summary'] = 'purge history summary'; +$lang['c13y_title'] = 'Check integrity'; +$lang['c13y_Anomaly'] = 'Anomaly'; +$lang['c13y_Correction'] = 'Correction'; +$lang['c13y_Automatic_correction'] = 'Automatic correction'; +$lang['c13y_Impossible_automatic_correction'] = 'Impossible automatic correction'; +$lang['c13y_Correction_applied_success'] = 'Correction applied with success'; +$lang['c13y_Correction_applied_error'] = 'Correction applied with error'; +$lang['c13y_Apply_selected_corrections'] = 'Apply selected corrections'; +$lang['c13y_anomaly_count'] = '%d anomaly has been detected.'; +$lang['c13y_anomalies_count'] = '%d anomalies has been detected.'; +$lang['c13y_anomaly_corrected_count'] = '%d anomaly has been corrected.'; +$lang['c13y_anomalies_corrected_count'] = '%d anomalies has been detected corrected.'; +$lang['c13y_anomaly_not_corrected_count'] = '%d anomaly hasn\'t been corrected.'; +$lang['c13y_anomalies_not_corrected_count'] = '%d anomalies hasn\'t been corrected.'; +$lang['c13y_more_info'] = 'Go to %s or %s for more informations'; +$lang['c13y_more_info_forum'] = 'the forum'; +$lang['c13y_more_info_wiki'] = 'the wiki'; +$lang['c13y_exif_anomaly'] = '%s value is not correct file because exif are not supported'; +$lang['c13y_exif_correction'] = '%s must be to set to false in your config_local.inc.php file'; +$lang['c13y_guest_non_existent'] = 'Main "guest" user don\'t exist any more'; +$lang['c13y_bad_guest_status'] = 'Main "guest" user status is incorrect'; +$lang['c13y_default_non_existent'] = 'Default user don\'t exist any more'; +$lang['c13y_webmaster_non_existent'] = 'Main "webmaster" user don\'t exist any more'; +$lang['c13y_bad_webmaster_status'] = 'Main "webmaster" user status is incorrect'; +$lang['c13y_user_created'] = 'User "%s" created with "%s" like password'; +$lang['c13y_user_status_updated'] = 'Status of user "%s" updated'; ?> diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php index afcb77c81..c84ac748e 100644 --- a/language/fr_FR.iso-8859-1/admin.lang.php +++ b/language/fr_FR.iso-8859-1/admin.lang.php @@ -553,10 +553,6 @@ $lang['Web Services availability duration in days'] = 'Durée d\'ouverture des Se $lang['Web Services under control'] = 'Les Services Web de PhpWebGallery sont totalement operationnels et toutes les requêtes sont contrôlées.'; $lang['special_admin_menu'] = 'Spéciales'; $lang['pictures_menu'] = 'Images'; -$lang['note_check_exif'] = '%s doit être mis à "false" dans votre fichier config_local.inc.php parce que l\'exif n\'est pas supporté.'; -$lang['note_check_more_info'] = 'Allez sur %s ou %s pour plus d\'informations.'; -$lang['note_check_more_info_forum'] = 'le forum'; -$lang['note_check_more_info_wiki'] = 'le wiki'; $lang['Duplicates'] = 'Fichiers portant le même nom dans plusieurs catégories physiques'; $lang['DEMO'] = 'DÉMO'; $lang['HOME'] = 'ACCUEIL PWG'; @@ -619,4 +615,30 @@ $lang['Default user cannot be deleted'] = 'L\'utilisateur par défaut ne peut pas $lang['obligatory_user_mail_address'] = 'L\'adresse mail est obligatoire pour tous les utilisateurs'; $lang['purge history detail'] = 'purger le detail de l\'historique'; $lang['purge history summary'] = 'purger le sommaire de l\'historique'; +$lang['c13y_title'] = 'Contrôle d\'intégrité'; +$lang['c13y_Anomaly'] = 'Anomalie'; +$lang['c13y_Correction'] = 'Correction'; +$lang['c13y_Automatic_correction'] = 'Correction automatique'; +$lang['c13y_Impossible_automatic_correction'] = 'Correction automatique impossible'; +$lang['c13y_Correction_applied_success'] = 'Correction appliquée avec succés'; +$lang['c13y_Correction_applied_error'] = 'Correction appliquée avec erreur'; +$lang['c13y_Apply_selected_corrections'] = 'Appliquer les corrections sélectionnées'; +$lang['c13y_anomaly_count'] = '%d anomalie a été détecté.'; +$lang['c13y_anomalies_count'] = '%d anomalies ont été détectées.'; +$lang['c13y_anomaly_corrected_count'] = '%d anomalie a été corrigée.'; +$lang['c13y_anomalies_corrected_count'] = '%d anomalies ont été corrigées.'; +$lang['c13y_anomaly_not_corrected_count'] = '%d anomalie n\'a pas pu être corrigée.'; +$lang['c13y_anomalies_not_corrected_count'] = '%d anomalies n\'ont pu être corrigées.'; +$lang['c13y_more_info'] = 'Allez sur %s ou %s pour plus d\'informations'; +$lang['c13y_more_info_forum'] = 'le forum'; +$lang['c13y_more_info_wiki'] = 'le wiki'; +$lang['c13y_exif_anomaly'] = 'La valeur de %s n\'est pas correcte parce que l\'exif n\'est pas supporté'; +$lang['c13y_exif_correction'] = '%s doit être mis à "false" dans votre fichier config_local.inc.php'; +$lang['c13y_guest_non_existent'] = 'L\'utilisateur "invité" principal n\'existe plus'; +$lang['c13y_bad_guest_status'] = 'Le statut de l\'utilisateur "invité" principal est incorrect'; +$lang['c13y_default_non_existent'] = 'L\'utilisateur par défaut n\'existe plus'; +$lang['c13y_webmaster_non_existent'] = 'L\'utilisateur "webmestre" principal n\'existe plus'; +$lang['c13y_bad_webmaster_status'] = 'Le statut de l\'utilisateur "webmestre" principal est incorrect'; +$lang['c13y_user_created'] = 'Utilisateur "%s" créé avec comme mot de passe "%s"'; +$lang['c13y_user_status_updated'] = 'Statut de l\'utilisateur "%s" mis à jour'; ?> diff --git a/template/yoga/admin/check_integrity.tpl b/template/yoga/admin/check_integrity.tpl new file mode 100644 index 000000000..5523d0364 --- /dev/null +++ b/template/yoga/admin/check_integrity.tpl @@ -0,0 +1,49 @@ +<!-- $Id$ --> +<dl> + <dt>{lang:c13y_title}</dt> + <dd> + <ul> + <form method="post" name="preferences" action="{F_c13y_ACTION}"> + <fieldset> + <table class="table2"> + <tr class="throw"> + <th>{lang:c13y_Anomaly}</th> + <th>{lang:c13y_Correction}</th> + </tr> + <!-- BEGIN c13y --> + <tr class="{c13y.CLASS}"> + <td><label for="c13y_selection-{c13y.ID}">{c13y.ANOMALY}</label></td> + <td> + <!-- BEGIN correction_fct --> + <input type="checkbox" name="c13y_selection[]" value="{c13y.ID}" {c13y.CHECKED} id="c13y_selection-{c13y.ID}" /><label for="c13y_selection-{c13y.ID}"> {lang:c13y_Automatic_correction}</label> + <!-- END correction_fct --> + <!-- BEGIN correction_bad_fct --> + {lang:c13y_Impossible_automatic_correction} + <!-- END correction_bad_fct --> + <!-- BEGIN correction_success_fct --> + {lang:c13y_Correction_applied_success} + <!-- END correction_success_fct --> + <!-- BEGIN correction_error_fct --> + {lang:c13y_Correction_applied_error} + <BR /> + {c13y.correction_error_fct.WIKI_FOROM_LINKS} + <!-- END correction_error_fct --> + <!-- BEGIN br --> + <br /> + <!-- END br --> + <!-- BEGIN correction_msg --> + {c13y.correction_msg.DATA} + <!-- END correction_msg --> + </td> + </tr> + <!-- END c13y --> + </table> + <!-- BEGIN c13y_submit --> + <p> + <input class="submit" type="submit" value="{lang:c13y_Apply_selected_corrections}" name="c13y_submit" {TAG_INPUT_ENABLED} /> + </p> + <!-- END c13y_submit --> + </fieldset> + </form> + </ul> + </dd> |