try { $config->set('nom_asso', Utils::post('nom_asso')); $config->set('email_asso', Utils::post('email_asso')); $config->set('adresse_asso', Utils::post('adresse_asso')); $config->set('site_asso', Utils::post('site_asso')); $config->set('email_envoi_automatique', Utils::post('email_envoi_automatique')); $config->set('accueil_wiki', Utils::post('accueil_wiki')); $config->set('accueil_connexion', Utils::post('accueil_connexion')); $config->set('categorie_membres', Utils::post('categorie_membres')); $config->set('champ_identite', Utils::post('champ_identite')); $config->set('champ_identifiant', Utils::post('champ_identifiant')); $config->set('pays', Utils::post('pays')); $config->set('monnaie', Utils::post('monnaie')); $config->save(); Utils::redirect('/admin/config/?ok'); } catch (UserException $e) { $error = $e->getMessage(); } } } $tpl->assign('error', $error); $tpl->assign('garradin_version', garradin_version() . ' [' . (garradin_manifest() ?: 'release') . ']'); $tpl->assign('php_version', phpversion()); $v = \SQLite3::version(); $tpl->assign('sqlite_version', $v['versionString']); $tpl->assign('pays', Utils::getCountryList()); $cats = new Membres\Categories(); $tpl->assign('membres_cats', $cats->listSimple()); $champs_liste = array_merge(['id' => ['title' => 'Numéro unique', 'type' => 'number']], $config->get('champs_membres')->getList()); $tpl->assign('champs', $champs_liste); $tpl->display('admin/config/index.tpl');
function exception_handler($e) { if ($e instanceof UserException || $e instanceof \KD2\MiniSkelMarkupException) { try { if (PHP_SAPI == 'cli') { echo $e->getMessage(); } else { $tpl = Template::getInstance(); $tpl->assign('error', $e->getMessage()); $tpl->display('error.tpl'); } exit; } catch (Exception $e) { } } $file = str_replace(ROOT, '', $e->getFile()); $error = "Exception of type " . get_class($e) . " happened !\n\n" . $e->getCode() . " - " . $e->getMessage() . "\n\nIn: " . $file . ":" . $e->getLine() . "\n\n"; if (!empty($_SERVER['HTTP_HOST']) && !empty($_SERVER['REQUEST_URI'])) { $error .= 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\n\n"; } $error .= $e->getTraceAsString(); $error .= "\n-------------\n"; $error .= 'Garradin version: ' . garradin_version() . "\n"; $error .= 'Garradin manifest: ' . garradin_manifest() . "\n"; $error .= 'PHP version: ' . phpversion() . "\n"; foreach ($_SERVER as $key => $value) { if (is_array($value)) { $value = json_encode($value); } $error .= $key . ': ' . $value . "\n"; } $error = str_replace("\r", '', $error); error_log($error); if (MAIL_ERRORS) { mail(MAIL_ERRORS, '[Garradin] Erreur d\'exécution', $error, 'From: "' . WWW_URL . '" <*****@*****.**>'); } if (PHP_SAPI == 'cli') { echo $error; } else { echo '<!DOCTYPE html><meta charset="utf-8" /><style type="text/css">body { font-family: sans-serif; } h3 { color: darkred; } pre { text-shadow: 2px 2px 5px black; color: darkgreen; font-size: 2em; float: left; margin: 0 1em 0 0; padding: 1em; background: #cfc; border-radius: 50px; }</style> <pre> \\__/<br /> (xx)<br />//||\\\\</pre> <h1>Erreur d\'exécution</h1>'; if (SHOW_ERRORS) { echo '<p>Une erreur s\'est produite à l\'exécution de Garradin. Pour rapporter ce bug merci d\'inclure le message suivant :</p> <textarea cols="70" rows="' . substr_count($error, "\n") . '">' . htmlspecialchars($error, ENT_QUOTES, 'UTF-8') . '</textarea> <hr /> <p><a href="http://dev.kd2.org/garradin/Rapporter%20un%20bug">Comment rapporter un bug</a></p>'; } else { echo '<p>Une erreur s\'est produite à l\'exécution de Garradin.</p> <p>Le webmaster a été prévenu.</p>'; } } exit; }
/** * Restauration de base de données, la fonction qui le fait vraiment * @param string $file Chemin absolu vers la base de données à utiliser * @return mixed true si rien ne va plus, ou self::NEED_UPGRADE si la version de la DB * ne correspond pas à la version de Garradin (mise à jour nécessaire). */ protected function restoreDB($file) { // Essayons déjà d'ouvrir la base de données à restaurer en lecture try { $db = new \SQLite3($file, SQLITE3_OPEN_READONLY); } catch (\Exception $e) { throw new UserException('Le fichier fourni n\'est pas une base de données valide. ' . 'Message d\'erreur de SQLite : ' . $e->getMessage()); } // Regardons ensuite si la base de données n'est pas corrompue $check = $db->querySingle('PRAGMA integrity_check;'); if (strtolower(trim($check)) != 'ok') { throw new UserException('Le fichier fourni est corrompu. SQLite a trouvé ' . $check . ' erreurs.'); } // On ne peut pas faire de vérifications très poussées sur la structure de la base de données, // celle-ci pouvant changer d'une version à l'autre et on peut vouloir importer une base // un peu vieille, mais on vérifie quand même que ça ressemble un minimum à une base garradin $table = $db->querySingle('SELECT 1 FROM sqlite_master WHERE type=\'table\' AND tbl_name=\'config\';'); if (!$table) { throw new UserException('Le fichier fourni ne semble pas contenir de données liées à Garradin.'); } // On récupère la version pour plus tard $version = $db->querySingle('SELECT valeur FROM config WHERE cle=\'version\';'); $db->close(); $backup = str_replace('.sqlite', date('.Y-m-d-His') . '.avant_restauration.sqlite', DB_FILE); if (!rename(DB_FILE, $backup)) { throw new \RuntimeException('Unable to backup current DB file.'); } if (!copy($file, DB_FILE)) { rename($backup, DB_FILE); throw new \RuntimeException('Unable to copy backup DB to main location.'); } if ($version != garradin_version()) { return self::NEED_UPGRADE; } return true; }
try { $db = DB::getInstance(true); // Création de la base de données $db->exec('BEGIN;'); $db->exec(file_get_contents(DB_SCHEMA)); $db->exec('END;'); // Configuration de base $config = Config::getInstance(); $config->set('nom_asso', Utils::post('nom_asso')); $config->set('adresse_asso', Utils::post('adresse_asso')); $config->set('email_asso', Utils::post('email_asso')); $config->set('site_asso', WWW_URL); $config->set('monnaie', '€'); $config->set('pays', 'FR'); $config->set('email_envoi_automatique', Utils::post('email_asso')); $config->setVersion(garradin_version()); $champs = Membres\Champs::importInstall(); $champs->save(false); // Pas de copie car pas de table membres existante $config->set('champ_identifiant', 'email'); $config->set('champ_identite', 'nom'); // Création catégories $cats = new Membres\Categories(); $id = $cats->add(['nom' => 'Membres actifs']); $config->set('categorie_membres', $id); $id = $cats->add(['nom' => 'Anciens membres', 'droit_inscription' => Membres::DROIT_AUCUN, 'droit_wiki' => Membres::DROIT_AUCUN, 'droit_membres' => Membres::DROIT_AUCUN, 'droit_compta' => Membres::DROIT_AUCUN, 'droit_config' => Membres::DROIT_AUCUN, 'droit_connexion' => Membres::DROIT_AUCUN, 'cacher' => 1]); $id = $cats->add(['nom' => ucfirst(Utils::post('cat_membre')), 'droit_inscription' => Membres::DROIT_AUCUN, 'droit_wiki' => Membres::DROIT_ADMIN, 'droit_membres' => Membres::DROIT_ADMIN, 'droit_compta' => Membres::DROIT_ADMIN, 'droit_config' => Membres::DROIT_ADMIN]); // Création premier membre $membres = new Membres(); $id_membre = $membres->add(['id_categorie' => $id, 'nom' => Utils::post('nom_membre'), 'email' => Utils::post('email_membre'), 'passe' => Utils::post('passe_membre'), 'pays' => 'FR']); // Création wiki
/** * Installer un plugin * @param string $id Identifiant du plugin * @param boolean $official TRUE si le plugin est officiel * @return boolean TRUE si tout a fonctionné */ public static function install($id, $official = false) { if (!file_exists('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz')) { throw new \RuntimeException('Le plugin ' . $id . ' ne semble pas exister et ne peut donc être installé.'); } if (!file_exists('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/garradin_plugin.ini')) { throw new UserException('L\'archive ' . $id . '.tar.gz n\'est pas une extension Garradin : fichier garradin_plugin.ini manquant.'); } $infos = parse_ini_file('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/garradin_plugin.ini', false); $required = ['nom', 'description', 'auteur', 'url', 'version', 'menu', 'config']; foreach ($required as $key) { if (!array_key_exists($key, $infos)) { throw new \RuntimeException('Le fichier garradin_plugin.ini ne contient pas d\'entrée "' . $key . '".'); } } if (!empty($infos['min_version']) && !version_compare(garradin_version(), $infos['min_version'], '>=')) { throw new \RuntimeException('Le plugin ' . $id . ' nécessite Garradin version ' . $infos['min_version'] . ' ou supérieure.'); } if (!empty($infos['menu']) && !file_exists('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/www/admin/index.php')) { throw new \RuntimeException('Le plugin ' . $id . ' ne comporte pas de fichier www/admin/index.php alors qu\'il demande à figurer au menu.'); } $config = ''; if ((bool) $infos['config']) { if (!file_exists('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/config.json')) { throw new \RuntimeException('L\'archive ' . $id . '.tar.gz ne comporte pas de fichier config.json alors que le plugin nécessite le stockage d\'une configuration.'); } if (!file_exists('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/www/admin/config.php')) { throw new \RuntimeException('L\'archive ' . $id . '.tar.gz ne comporte pas de fichier www/admin/config.php alors que le plugin nécessite le stockage d\'une configuration.'); } $config = json_decode(file_get_contents('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/config.json'), true); if (is_null($config)) { throw new \RuntimeException('config.json invalide. Code erreur JSON: ' . json_last_error()); } $config = json_encode($config); } $db = DB::getInstance(); $db->simpleInsert('plugins', ['id' => $id, 'officiel' => (int) (bool) $official, 'nom' => $infos['nom'], 'description' => $infos['description'], 'auteur' => $infos['auteur'], 'url' => $infos['url'], 'version' => $infos['version'], 'menu' => (int) (bool) $infos['menu'], 'config' => $config]); if (file_exists('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/install.php')) { $plugin = new Plugin($id); include 'phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/install.php'; } return true; }