lumo:creation_complete_du_plugin_dokuwiki
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| lumo:creation_complete_du_plugin_dokuwiki [2026/03/12 10:32] – estro | lumo:creation_complete_du_plugin_dokuwiki [2026/03/12 10:45] (Version actuelle) – supprimée estro | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== Création complète du plugin DokuWiki ====== | + | |
| - | [[./ | + | |
| - | ---- | + | |
| - | ===== Structure du Plugin ===== | + | |
| - | < | + | |
| - | / | + | |
| - | ├── action.php | + | |
| - | ├── syntax.php | + | |
| - | ├── helper.php | + | |
| - | ├── script.sh | + | |
| - | └── manifest.ini | + | |
| - | </ | + | |
| - | <adm note 1. manifest.ini> | + | |
| - | ++++code ini| | + | |
| - | <code ini> | + | |
| - | [plugin] | + | |
| - | name=Bash Exec Plugin | + | |
| - | desc=Exécute des scripts bash avec validation sécurisée | + | |
| - | author=Votre Nom | + | |
| - | email=votre@email.com | + | |
| - | url=https:// | + | |
| - | date=2026-03-12 | + | |
| - | version=1.0.0 | + | |
| - | </ | + | |
| - | ++++ | + | |
| - | </ | + | |
| - | <adm danger 2. helper.php (Fonctions utilitaires)> | + | |
| - | ++++code php| | + | |
| - | <code php> | + | |
| - | <?php | + | |
| - | /** | + | |
| - | * Helper class for Bash Exec Plugin | + | |
| - | */ | + | |
| - | class helper_plugin_bashexec extends DokuWiki_Plugin { | + | |
| - | + | ||
| - | /** | + | |
| - | * Validation stricte des arguments | + | |
| - | */ | + | |
| - | public function validateArgument($arg) { | + | |
| - | // Autorise uniquement alphanumérique, | + | |
| - | if (!preg_match('/ | + | |
| - | return false; | + | |
| - | } | + | |
| - | return true; | + | |
| - | } | + | |
| - | + | ||
| - | /** | + | |
| - | * Validation du chemin du script | + | |
| - | */ | + | |
| - | public function validateScriptPath($path) { | + | |
| - | $allowedPaths = array( | + | |
| - | DOKU_PLUGIN . ' | + | |
| - | '/ | + | |
| - | ); | + | |
| - | + | ||
| - | foreach ($allowedPaths as $allowed) { | + | |
| - | if (strpos($path, | + | |
| - | return true; | + | |
| - | } | + | |
| - | } | + | |
| - | return false; | + | |
| - | } | + | |
| - | + | ||
| - | /** | + | |
| - | * Journalisation des exécutions | + | |
| - | */ | + | |
| - | public function logExecution($script, | + | |
| - | $logFile = DOKU_LOG . '/ | + | |
| - | $timestamp = date(' | + | |
| - | $entry = sprintf( | + | |
| - | "[%s] User: %s | Script: %s | Args: %s | Return: %d\n", | + | |
| - | $timestamp, | + | |
| - | $user, | + | |
| - | basename($script), | + | |
| - | implode(' | + | |
| - | $returnCode | + | |
| - | ); | + | |
| - | file_put_contents($logFile, | + | |
| - | } | + | |
| - | + | ||
| - | /** | + | |
| - | * Vérification des permissions | + | |
| - | */ | + | |
| - | public function checkPermissions() { | + | |
| - | global $USERINFO; | + | |
| - | + | ||
| - | // Vérifie si l' | + | |
| - | if (!isset($USERINFO[' | + | |
| - | return false; | + | |
| - | } | + | |
| - | + | ||
| - | // Optionnel : Restreindre à certains groupes | + | |
| - | $allowedGroups = $this-> | + | |
| - | if ($allowedGroups) { | + | |
| - | $userGroups = explode(',', | + | |
| - | foreach ($userGroups as $group) { | + | |
| - | if (in_array(trim($group), | + | |
| - | return true; | + | |
| - | } | + | |
| - | } | + | |
| - | return false; | + | |
| - | } | + | |
| - | + | ||
| - | return true; | + | |
| - | } | + | |
| - | } | + | |
| - | </ | + | |
| - | ++++ | + | |
| - | </ | + | |
| - | <adm information 3. syntax.php (Syntaxe dans les pages wiki)> | + | |
| - | ++++code php| | + | |
| - | <code php> | + | |
| - | <?php | + | |
| - | /** | + | |
| - | * Syntax Plugin for Bash Exec | + | |
| - | */ | + | |
| - | class syntax_plugin_bashexec extends DokuWiki_Plugin_Syntax { | + | |
| - | + | ||
| - | public function getType() { | + | |
| - | return ' | + | |
| - | } | + | |
| - | + | ||
| - | public function getPType() { | + | |
| - | return ' | + | |
| - | } | + | |
| - | + | ||
| - | public function getSort() { | + | |
| - | return 150; | + | |
| - | } | + | |
| - | + | ||
| - | public function connectTo($mode) { | + | |
| - | $this-> | + | |
| - | } | + | |
| - | + | ||
| - | public function handle($match, | + | |
| - | preg_match('/ | + | |
| - | $params = trim($matches[1]); | + | |
| - | + | ||
| - | // Parse: script.sh arg1 arg2 | + | |
| - | $parts = preg_split('/ | + | |
| - | $script = array_shift($parts); | + | |
| - | $args = $parts; | + | |
| - | + | ||
| - | return array($script, | + | |
| - | } | + | |
| - | + | ||
| - | public function render($format, | + | |
| - | if ($format != ' | + | |
| - | return false; | + | |
| - | } | + | |
| - | + | ||
| - | list($script, | + | |
| - | $helper = plugin_load(' | + | |
| - | + | ||
| - | // Vérifier les permissions | + | |
| - | if (!$helper-> | + | |
| - | $renderer-> | + | |
| - | return true; | + | |
| - | } | + | |
| - | + | ||
| - | // Valider le script | + | |
| - | if (!$helper-> | + | |
| - | $renderer-> | + | |
| - | return true; | + | |
| - | } | + | |
| - | + | ||
| - | // Valider tous les arguments | + | |
| - | foreach ($args as $arg) { | + | |
| - | if (!$helper-> | + | |
| - | $renderer-> | + | |
| - | return true; | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | // Exécuter le script | + | |
| - | $fullScript = DOKU_PLUGIN . ' | + | |
| - | $cmd = escapeshellcmd($fullScript); | + | |
| - | $escapedArgs = array_map(' | + | |
| - | $command = $cmd . ' ' . implode(' | + | |
| - | + | ||
| - | exec($command, | + | |
| - | + | ||
| - | // Journaliser | + | |
| - | global $INPUT; | + | |
| - | $helper-> | + | |
| - | + | ||
| - | // Afficher le résultat | + | |
| - | if ($returnCode === 0) { | + | |
| - | $renderer-> | + | |
| - | } else { | + | |
| - | $renderer-> | + | |
| - | } | + | |
| - | + | ||
| - | return true; | + | |
| - | } | + | |
| - | } | + | |
| - | </ | + | |
| - | ++++ | + | |
| - | </ | + | |
lumo/creation_complete_du_plugin_dokuwiki.1773311546.txt.gz · Dernière modification : de estro
