From 027d0c8846615019dafb59440f7245aab0ada28d Mon Sep 17 00:00:00 2001 From: rub Date: Thu, 19 Jul 2007 20:03:17 +0000 Subject: 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. Merge BSF 2064:2066 into branch-1_7 git-svn-id: http://piwigo.org/svn/branches/branch-1_7@2067 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin.php | 13 +- admin/include/functions.php | 36 --- admin/include/functions_check_integrity.inc.php | 405 ++++++++++++++++++++++++ admin/intro.php | 2 + language/en_UK.iso-8859-1/admin.lang.php | 28 +- language/fr_FR.iso-8859-1/admin.lang.php | 28 +- template/yoga/admin/check_integrity.tpl | 49 +++ 7 files changed, 517 insertions(+), 44 deletions(-) create mode 100644 admin/include/functions_check_integrity.inc.php create mode 100644 template/yoga/admin/check_integrity.tpl diff --git a/admin.php b/admin.php index dc848ab49..004bac218 100644 --- a/admin.php +++ b/admin.php @@ -43,12 +43,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 @@ -1951,42 +1951,6 @@ SELECT id, fclose($fp); } -/** - * 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 = '%s'; - $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) * 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 @@ + 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 = '%s'; + 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.'\']') + .'
'. + 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 d7eabccb4..cab5c4646 100644 --- a/language/en_UK.iso-8859-1/admin.lang.php +++ b/language/en_UK.iso-8859-1/admin.lang.php @@ -607,9 +607,35 @@ $lang['Hour'] = 'Hour'; $lang['is_the_guest'] = 'guest'; $lang['is_the_default'] = 'default values'; $lang['High filesize'] = 'High filesize'; -// --------- Starting below: New or revised $lang ---- from Butterfly (1.7.1) +// --------- Starting below: New or revised $lang ---- from version 1.7.1 $lang['Guest cannot be deleted'] = 'Guest cannot be deleted'; $lang['Default user cannot be deleted'] = 'Default user cannot be deleted'; $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 063fd1250..748d722f1 100644 --- a/language/fr_FR.iso-8859-1/admin.lang.php +++ b/language/fr_FR.iso-8859-1/admin.lang.php @@ -608,9 +608,35 @@ $lang['Hour'] = 'Heure'; $lang['is_the_guest'] = 'invité'; $lang['is_the_default'] = 'valeurs par défaut'; $lang['High filesize'] = 'Taille du fichier HR'; -// --------- Starting below: New or revised $lang ---- from Butterfly (1.7.1) +// --------- Starting below: New or revised $lang ---- from version 1.7.1 $lang['Guest cannot be deleted'] = 'L\'invité ne peut pas être supprimé'; $lang['Default user cannot be deleted'] = 'L\'utilisateur par défaut ne peut pas être supprimé'; $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 @@ + +
+
{lang:c13y_title}
+
+
    +
    +
    + + + + + + + + + + + +
    {lang:c13y_Anomaly}{lang:c13y_Correction}
    + + + + + {lang:c13y_Impossible_automatic_correction} + + + {lang:c13y_Correction_applied_success} + + + {lang:c13y_Correction_applied_error} +
    + {c13y.correction_error_fct.WIKI_FOROM_LINKS} + + +
    + + + {c13y.correction_msg.DATA} + +
    + +

    + +

    + +
    +
    +
+
-- cgit v1.2.3