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édente | |||
| lumo:creation_complete_du_plugin_dokuwiki [2026/03/12 10:42] – 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; | ||
| - | } | ||
| - | } | ||
| - | </ | ||
| - | ++++ | ||
| - | </ | ||
| - | <adm bug 4. action.php (Actions via URL)> | ||
| - | ++++code php| | ||
| - | <code php> | ||
| - | <?php | ||
| - | /** | ||
| - | * Action Plugin for Bash Exec | ||
| - | */ | ||
| - | class action_plugin_bashexec extends DokuWiki_Action_Plugin { | ||
| - | | ||
| - | public function register(Doku_Event_Handler $controller) { | ||
| - | $controller-> | ||
| - | $controller-> | ||
| - | } | ||
| - | | ||
| - | public function handleScriptRequest(Doku_Event $event, $param) { | ||
| - | if ($event-> | ||
| - | return; | ||
| - | } | ||
| - | | ||
| - | $helper = plugin_load(' | ||
| - | | ||
| - | // Vérifier les permissions | ||
| - | if (!$helper-> | ||
| - | http_response_code(403); | ||
| - | print json_encode([' | ||
| - | exit; | ||
| - | } | ||
| - | | ||
| - | // Récupérer les paramètres | ||
| - | $script = $this-> | ||
| - | $arg1 = $this-> | ||
| - | $arg2 = $this-> | ||
| - | | ||
| - | // Valider le script | ||
| - | if (!$helper-> | ||
| - | http_response_code(400); | ||
| - | print json_encode([' | ||
| - | exit; | ||
| - | } | ||
| - | | ||
| - | // Valider les arguments | ||
| - | $args = array_filter([$arg1, | ||
| - | foreach ($args as $arg) { | ||
| - | if (!$helper-> | ||
| - | http_response_code(400); | ||
| - | print json_encode([' | ||
| - | exit; | ||
| - | } | ||
| - | } | ||
| - | | ||
| - | // Exécuter | ||
| - | $fullScript = DOKU_PLUGIN . ' | ||
| - | $escapedArgs = array_map(' | ||
| - | $command = escapeshellcmd($fullScript) . ' ' . implode(' | ||
| - | | ||
| - | exec($command, | ||
| - | | ||
| - | // Journaliser | ||
| - | global $INPUT; | ||
| - | $helper-> | ||
| - | | ||
| - | // Répondre | ||
| - | header(' | ||
| - | print json_encode([ | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ]); | ||
| - | exit; | ||
| - | } | ||
| - | | ||
| - | private function getInput($key) { | ||
| - | return isset($_GET[$key]) ? $_GET[$key] : (isset($_POST[$key]) ? $_POST[$key] : '' | ||
| - | } | ||
| - | | ||
| - | public function renderOutput(Doku_Event $event, $param) { | ||
| - | // Peut être utilisé pour afficher des résultats après exécution | ||
| - | } | ||
| - | } | ||
| - | </ | ||
| - | ++++ | ||
| - | </ | ||
| - | <adm warning 5. Exemple de Script Bash Sécurisé> | ||
| - | ++++code bash| | ||
| - | <code bash> | ||
| - | #!/bin/bash | ||
| - | # / | ||
| - | |||
| - | # Vérifier les permissions du script | ||
| - | if [ "$(id -u)" -eq 0 ]; then | ||
| - | echo " | ||
| - | exit 1 | ||
| - | fi | ||
| - | |||
| - | # Arguments attendus | ||
| - | ARG1=" | ||
| - | ARG2=" | ||
| - | |||
| - | # Validation côté script (défense en profondeur) | ||
| - | if [[ ! " | ||
| - | echo " | ||
| - | exit 1 | ||
| - | fi | ||
| - | |||
| - | # Exemple d' | ||
| - | case " | ||
| - | " | ||
| - | echo " | ||
| - | echo " | ||
| - | ;; | ||
| - | " | ||
| - | echo " | ||
| - | uname -a | ||
| - | ;; | ||
| - | *) | ||
| - | echo " | ||
| - | exit 1 | ||
| - | ;; | ||
| - | esac | ||
| - | |||
| - | exit 0 | ||
| - | </ | ||
| - | ++++ | ||
| - | </ | ||
| - | <adm achievement 6. Configuration Nginx Complète> | ||
| - | ++++code php| | ||
| - | <code php> | ||
| - | server { | ||
| - | listen 80; | ||
| - | server_name wiki.votre-domaine.com; | ||
| - | root / | ||
| - | index index.php; | ||
| - | | ||
| - | # Sécurité générale | ||
| - | add_header X-Content-Type-Options nosniff; | ||
| - | add_header X-Frame-Options SAMEORIGIN; | ||
| - | add_header X-XSS-Protection "1; mode=block"; | ||
| - | | ||
| - | # DokuWiki principal | ||
| - | location / { | ||
| - | try_files $uri $uri/ @dokuwiki; | ||
| - | } | ||
| - | | ||
| - | location @dokuwiki { | ||
| - | fastcgi_pass unix:/ | ||
| - | include fastcgi_params; | ||
| - | fastcgi_param SCRIPT_FILENAME $document_root/ | ||
| - | fastcgi_param HTTPS off; | ||
| - | } | ||
| - | | ||
| - | # Protection des fichiers sensibles | ||
| - | location ~* ^/ | ||
| - | deny all; | ||
| - | return 403; | ||
| - | } | ||
| - | | ||
| - | # Protection des scripts bash | ||
| - | location ~* \.sh$ { | ||
| - | deny all; | ||
| - | return 403; | ||
| - | } | ||
| - | | ||
| - | # Rate limiting pour l' | ||
| - | limit_req_zone $binary_remote_addr zone=bashexec: | ||
| - | | ||
| - | location / | ||
| - | limit_req zone=bashexec burst=2 nodelay; | ||
| - | fastcgi_pass unix:/ | ||
| - | include fastcgi_params; | ||
| - | fastcgi_param SCRIPT_FILENAME $document_root/ | ||
| - | } | ||
| - | | ||
| - | # Logs spécifiques | ||
| - | access_log / | ||
| - | } | ||
| - | </ | ||
| - | ++++ | ||
| - | </ | ||
| - | <adm achievement> | ||
| - | ++++code conf| | ||
| - | <code conf> | ||
| - | |||
| - | </ | ||
| - | ++++ | ||
| - | </ | ||
lumo/creation_complete_du_plugin_dokuwiki.1773312158.txt.gz · Dernière modification : de estro
