Overview
Comment: | Suppression de plugin + vérifications |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
1cb7db96ca91286fc52ab5b63448f7c4 |
User & Date: | bohwaz on 2014-03-20 19:39:24 |
Other Links: | manifest | tags |
Context
2014-03-20
| ||
20:06 | Documentation et lecture simple des fichiers non-PHP plutôt qu'inclusion check-in: 9577053997 user: bohwaz tags: trunk | |
19:39 | Suppression de plugin + vérifications check-in: 1cb7db96ca user: bohwaz tags: trunk | |
18:30 | Début d'intégration des plugins check-in: d239c2525e user: bohwaz tags: trunk | |
Changes
Modified src/include/class.plugin.php from [b491bcdea6] to [f5203581aa].
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 ... 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 ... 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 ... 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 ... 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 ... 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
public function id() { return $this->id; } public function call($file) { $forbidden = ['install.php', 'infos.ini', 'upgrade.php', 'uninstall.php', 'signals.php']; if (in_array($file, $forbidden)) { throw new UserException('Le fichier ' . $file . ' ne peut être appelé par cette méthode.'); } if (!file_exists('phar://' . PLUGINS_PATH . '/' . $this->id . '.phar/' . $file)) ................................................................................ $db = DB::getInstance(); return $db->simpleExec('DELETE FROM plugins WHERE id = ?;', $this->id); } public function needUpgrade() { $infos = parse_ini_file('phar://' . PLUGINS_PATH . '/' . $this->id . '.phar/infos.ini', false); if (version_compare($this->plugin['version'], $infos['version'], '!=')) return true; return false; } ................................................................................ if (!preg_match('!^([a-z0-9_-]+)\.phar$!', $file, $match)) continue; if (array_key_exists($match[1], $installed)) continue; $list[$match[1]] = parse_ini_file('phar://' . PLUGINS_PATH . '/' . $match[1] . '.phar/infos.ini', false); } $dir->close(); return $list; } ................................................................................ $context = stream_context_create($context_options); try { copy($list[$id]['phar'], PLUGINS_PATH . '/' . $id . '.phar', $context); } catch (\Exception $e) { throw new \RuntimeException('Le téléchargement du plugin '.$id.' a échoué : ' . $e->getMessage()); } if (!self::checkHash($id)) { unlink(PLUGINS_PATH . '/' . $id . '.phar'); throw new \RuntimeException('L\'archive du plugin '.$id.' est corrompue (le hash SHA1 ne correspond pas).'); } ................................................................................ } if ($official && !self::checkHash($id)) { throw new \RuntimeException('L\'archive du plugin '.$id.' est corrompue (le hash SHA1 ne correspond pas).'); } if (!file_exists('phar://' . PLUGINS_PATH . '/' . $id . '.phar/infos.ini')) { throw new \RuntimeException('L\'archive '.$id.'.phar ne comporte pas de fichier infos.ini : est-ce un plugin Garradin ?'); } if (!file_exists('phar://' . PLUGINS_PATH . '/' . $id . '.phar/index.php')) { throw new \RuntimeException('L\'archive '.$id.'.phar ne comporte pas de fichier index.php : est-ce un plugin Garradin ?'); } $infos = parse_ini_file('phar://' . PLUGINS_PATH . '/' . $id . '.phar/infos.ini', false); if ((bool)$infos['config']) { if (!file_exists('phar://' . PLUGINS_PATH . '/' . $id . '.phar/config.json')) { throw new \RuntimeException('L\'archive '.$id.'.phar ne comporte pas de fichier config.json alors que le plugin nécessite le stockage d\'une configuration.'); ................................................................................ } if (!file_exists('phar://' . PLUGINS_PATH . '/' . $id . '.phar/config.php')) { throw new \RuntimeException('L\'archive '.$id.'.phar ne comporte pas de fichier config.php alors que le plugin nécessite le stockage d\'une configuration.'); } } $db = DB::getInstance(); $db->simpleInsert('plugins', [ 'id' => $id, 'officiel' => (int)(bool)$official, 'nom' => $infos['nom'], |
| | | | | | | > > > > > > > > > > > > > > |
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 ... 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 ... 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 ... 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 ... 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 ... 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
public function id() { return $this->id; } public function call($file) { $forbidden = ['install.php', 'garradin_plugin.ini', 'upgrade.php', 'uninstall.php', 'signals.php']; if (in_array($file, $forbidden)) { throw new UserException('Le fichier ' . $file . ' ne peut être appelé par cette méthode.'); } if (!file_exists('phar://' . PLUGINS_PATH . '/' . $this->id . '.phar/' . $file)) ................................................................................ $db = DB::getInstance(); return $db->simpleExec('DELETE FROM plugins WHERE id = ?;', $this->id); } public function needUpgrade() { $infos = parse_ini_file('phar://' . PLUGINS_PATH . '/' . $this->id . '.phar/garradin_plugin.ini', false); if (version_compare($this->plugin['version'], $infos['version'], '!=')) return true; return false; } ................................................................................ if (!preg_match('!^([a-z0-9_-]+)\.phar$!', $file, $match)) continue; if (array_key_exists($match[1], $installed)) continue; $list[$match[1]] = parse_ini_file('phar://' . PLUGINS_PATH . '/' . $match[1] . '.phar/garradin_plugin.ini', false); } $dir->close(); return $list; } ................................................................................ $context = stream_context_create($context_options); try { copy($list[$id]['phar'], PLUGINS_PATH . '/' . $id . '.phar', $context); } catch (\Exception $e) { throw new UserException('Le téléchargement du plugin '.$id.' a échoué : ' . $e->getMessage()); } if (!self::checkHash($id)) { unlink(PLUGINS_PATH . '/' . $id . '.phar'); throw new \RuntimeException('L\'archive du plugin '.$id.' est corrompue (le hash SHA1 ne correspond pas).'); } ................................................................................ } if ($official && !self::checkHash($id)) { throw new \RuntimeException('L\'archive du plugin '.$id.' est corrompue (le hash SHA1 ne correspond pas).'); } if (!file_exists('phar://' . PLUGINS_PATH . '/' . $id . '.phar/garradin_plugin.ini')) { throw new UserException('L\'archive '.$id.'.phar n\'est pas une extension Garradin : fichier garradin_plugin.ini manquant.'); } if (!file_exists('phar://' . PLUGINS_PATH . '/' . $id . '.phar/index.php')) { throw new \RuntimeException('L\'archive '.$id.'.phar ne comporte pas de fichier index.php : est-ce un plugin Garradin ?'); } $infos = parse_ini_file('phar://' . PLUGINS_PATH . '/' . $id . '.phar/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.'".'); } } $config = ''; if ((bool)$infos['config']) { if (!file_exists('phar://' . PLUGINS_PATH . '/' . $id . '.phar/config.json')) { throw new \RuntimeException('L\'archive '.$id.'.phar ne comporte pas de fichier config.json alors que le plugin nécessite le stockage d\'une configuration.'); ................................................................................ } if (!file_exists('phar://' . PLUGINS_PATH . '/' . $id . '.phar/config.php')) { throw new \RuntimeException('L\'archive '.$id.'.phar ne comporte pas de fichier config.php alors que le plugin nécessite le stockage d\'une configuration.'); } $config = json_encode(file_get_contents('phar://' . PLUGINS_PATH . '/' . $id . '.phar/config.json')); } $db = DB::getInstance(); $db->simpleInsert('plugins', [ 'id' => $id, 'officiel' => (int)(bool)$official, 'nom' => $infos['nom'], |
Modified src/templates/admin/config/plugins.tpl from [0d772933a3] to [b4a685b843].
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
{if $error} <p class="error"> {$error|escape} </p> {/if} {if !empty($liste_installes)} <table class="list"> <thead> <tr> <th>Extension</th> <td>Auteur</td> <td>Version installée</td> <td></td> </tr> </thead> <tbody> {foreach from=$liste_installes item="plugin"} <tr> <th> <h4>{$plugin.nom|escape}</h4> <small>{$plugin.description|escape}</small> </th> <td> <a href="{$plugin.url|escape}" onclick="return !window.open(this.href);">{$plugin.auteur|escape}</a> </td> <td> {$plugin.version|escape} </td> <td class="actions"> <a href="{$admin_url}config/plugins.php?delete={$plugin.id|escape}">Désinstaller</a> {if !empty($plugin.config)} | <a href="{$admin_url}plugin.php?id={$plugin.id|escape}&page=config.php">Configurer</a> {/if} </td> </tr> {/foreach} </tbody> </table> {else} <p class="help"> Aucune extension n'est installée. Vous pouvez consulter <a href="{Garradin\WEBSITE}">le site de Garradin</a> pour obtenir des extensions à télécharger. </p> {/if} {if !empty($liste_telecharges)} <form method="post" action="{$self_url|escape}"> <fieldset> <legend>Extensions téléchargées</legend> <dl> {foreach from=$liste_telecharges item="plugin" key="id"} <dt> <label> <input type="radio" name="to_install" value="{$id|escape}" /> {$plugin.nom|escape} </label> (version {$plugin.version|escape}) </dt> <dd>[<a href="{$plugin.url|escape}" onclick="return !window.open(this.href);">{$plugin.auteur|escape}</a>] {$plugin.description|escape}</dd> {/foreach} </dl> </fieldset> <p class="help"> Attention : installer une extension non officielle peut présenter des risques de sécurité et de stabilité. </p> <p class="submit"> {csrf_field key="install"} <input type="submit" name="install" value="Installer →" /> </p> </form> {/if} {include file="admin/_foot.tpl"} |
> > > > > > > > > > > > > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > |
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
{if $error} <p class="error"> {$error|escape} </p> {/if} {if !empty($delete)} <form method="post" action="{$self_url|escape}"> <fieldset> <legend>Désinstaller une extension</legend> <h3 class="warning"> Êtes-vous sûr de vouloir supprimer l'extension « {$plugin.nom|escape} » ? </h3> <p class="alert"> <strong>Attention</strong> : cette action est irréversible et effacera toutes les données associées à l'extension. </p> </fieldset> <p class="submit"> {csrf_field key="delete_plugin_`$plugin.id`"} <input type="submit" name="delete" value="Désinstaller →" /> </p> </form> {else} {if !empty($liste_installes)} <table class="list"> <thead> <tr> <th>Extension</th> <td>Auteur</td> <td>Version installée</td> <td></td> </tr> </thead> <tbody> {foreach from=$liste_installes item="plugin"} <tr> <th> <h4>{$plugin.nom|escape}</h4> <small>{$plugin.description|escape}</small> </th> <td> <a href="{$plugin.url|escape}" onclick="return !window.open(this.href);">{$plugin.auteur|escape}</a> </td> <td> {$plugin.version|escape} </td> <td class="actions"> <a href="{$admin_url}config/plugins.php?delete={$plugin.id|escape}">Désinstaller</a> {if !empty($plugin.config)} | <a href="{$admin_url}plugin.php?id={$plugin.id|escape}&page=config.php">Configurer</a> {/if} </td> </tr> {/foreach} </tbody> </table> {else} <p class="help"> Aucune extension n'est installée. Vous pouvez consulter <a href="{Garradin\WEBSITE}">le site de Garradin</a> pour obtenir des extensions à télécharger. </p> {/if} {if !empty($liste_telecharges)} <form method="post" action="{$self_url|escape}"> <fieldset> <legend>Extensions téléchargées</legend> <dl> {foreach from=$liste_telecharges item="plugin" key="id"} <dt> <label> <input type="radio" name="to_install" value="{$id|escape}" /> {$plugin.nom|escape} </label> (version {$plugin.version|escape}) </dt> <dd>[<a href="{$plugin.url|escape}" onclick="return !window.open(this.href);">{$plugin.auteur|escape}</a>] {$plugin.description|escape}</dd> {/foreach} </dl> </fieldset> <p class="help"> Attention : installer une extension non officielle peut présenter des risques de sécurité et de stabilité. </p> <p class="submit"> {csrf_field key="install_plugin"} <input type="submit" name="install" value="Installer →" /> </p> </form> {/if} {/if} {include file="admin/_foot.tpl"} |
Modified src/www/admin/config/plugins.php from [7c4827277c] to [7c4b62c1ef].
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
require_once __DIR__ . '/_inc.php';
$error = false;
if (!empty($_POST['install']))
{
if (!utils::CSRF_check('install'))
{
$error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
}
else
{
try {
Plugin::install(utils::post('to_install'), false);
utils::redirect('/admin/config/plugins.php');
}
catch (\Exception $e)
{
$error = $e->getMessage();
}
}
}
$tpl->assign('error', $error);
$tpl->assign('liste_telecharges', Plugin::listDownloaded());
$tpl->assign('liste_installes', Plugin::listInstalled());
$tpl->display('admin/config/plugins.tpl');
?>
|
| | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | > |
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
require_once __DIR__ . '/_inc.php'; $error = false; if (!empty($_POST['install'])) { if (!utils::CSRF_check('install_plugin')) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } else { try { Plugin::install(utils::post('to_install'), false); utils::redirect('/admin/config/plugins.php'); } catch (UserException $e) { $error = $e->getMessage(); } } } if (utils::post('delete')) { if (!utils::CSRF_check('delete_plugin_' . utils::get('delete'))) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } else { try { $plugin = new Plugin(utils::get('delete')); $plugin->uninstall(); utils::redirect('/admin/config/plugins.php'); } catch (UserException $e) { $error = $e->getMessage(); } } } $tpl->assign('error', $error); if (utils::get('delete')) { $plugin = new Plugin(utils::get('delete')); $tpl->assign('plugin', $plugin->getInfos()); $tpl->assign('delete', true); } else { $tpl->assign('liste_telecharges', Plugin::listDownloaded()); $tpl->assign('liste_installes', Plugin::listInstalled()); } $tpl->display('admin/config/plugins.tpl'); ?> |
Modified tools/make_plugin.php from [6aa347bed8] to [91ec357448].
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
if (empty($argv[1]) || empty($argv[2]))
{
die("Usage : " . basename(__FILE__) . " plugin.phar /path/to/plugin\n");
}
$phar_file = $argv[1];
$phar_name = basename($phar_file);
@unlink($phar_file);
@unlink($phar_file . '.gz');
$target = realpath($argv[2]);
$p = new Phar($phar_file);
$p->buildFromDirectory($target);
$p->compress(Phar::GZ);
rename($phar_file . '.gz', __DIR__ . '/../src/plugins/' . $phar_name);
|
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < |
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
if (empty($argv[1]) || empty($argv[2])) { die("Usage : " . basename(__FILE__) . " plugin.phar /path/to/plugin\n"); } $phar_file = $argv[1]; $phar_name = basename($phar_file); $target = realpath($argv[2]); if (!file_exists($target . '/index.php')) { die("ERREUR : Le fichier garradin_plugin.ini est obligatoire.\n"); } $infos = parse_ini_file($target . '/garradin_plugin.ini'); if (!empty($infos['config'])) { if (!file_exists($target . '/config.json')) { die("ERREUR : Le fichier config.json est obligatoire si config=1 dans garradin_plugin.ini.\n"); } if (!file_exists($target . '/config.php')) { die("ERREUR : Le fichier config.php est obligatoire si config=1 dans garradin_plugin.ini.\n"); } } $required = ['nom', 'description', 'auteur', 'url', 'version', 'menu', 'config']; foreach ($required as $key) { if (!array_key_exists($key, $infos)) { die('ERREUR : Le fichier garradin_plugin.ini ne contient pas d\'entrée "'.$key.'".' . "\n"); } } if (!file_exists($target . '/index.php')) { die("ERREUR : Le fichier index.php est obligatoire.\n"); } @unlink($phar_file); @unlink($phar_file . '.gz'); $p = new Phar($phar_file); $p->buildFromDirectory($target); $p->compress(Phar::GZ); rename($phar_file . '.gz', __DIR__ . '/../src/plugins/' . $phar_name); |