lumo:creation_complete_du_plugin_dokuwiki:accueil
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:accueil [2026/03/12 10:49] – estro | lumo:creation_complete_du_plugin_dokuwiki:accueil [2026/03/12 11:11] (Version actuelle) – estro | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| [[./ | [[./ | ||
| ---- | ---- | ||
| - | ===== Structure du Plugin | + | <adm example Structure du Plugin> |
| + | ==== Structure du Plugin ==== | ||
| < | < | ||
| / | / | ||
| Ligne 11: | Ligne 12: | ||
| └── manifest.ini | └── manifest.ini | ||
| </ | </ | ||
| + | </ | ||
| {{page> | {{page> | ||
| {{page> | {{page> | ||
| - | <adm information | + | {{page>3. syntax.php (Syntaxe dans les pages wiki)}} |
| - | ++++code php| | + | {{page>4. action.php |
| - | <code php> | + | {{page>5. Exemple de Script |
| - | <?php | + | {{page>6. Configuration Nginx Complète}} |
| - | /** | + | {{page>7. Installation et Permissions |
| - | * Syntax Plugin for Bash Exec | + | {{page>8. Utilisation dans DokuWiki }} |
| - | */ | + | {{page>9. Fichier de Configuration |
| - | 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->Lexer-> | + | |
| - | | + | |
| - | + | ||
| - | public function handle($match, | + | |
| - | preg_match('/ | + | |
| - | | + | |
| - | + | ||
| - | // 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->checkPermissions()) { | + | |
| - | $renderer-> | + | |
| - | return true; | + | |
| - | } | + | |
| - | + | ||
| - | // Valider le script | + | |
| - | if (!$helper-> | + | |
| - | $renderer-> | + | |
| - | return true; | + | |
| - | | + | |
| - | + | ||
| - | // Valider tous les arguments | + | |
| - | foreach ($args as $arg) { | + | |
| - | if (!$helper-> | + | |
| - | $renderer->cdata(' | + | |
| - | 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->cdata(' | + | |
| - | | + | |
| - | + | ||
| - | 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->register_hook(' | + | |
| - | $controller-> | + | |
| - | | + | |
| - | + | ||
| - | public function handleScriptRequest(Doku_Event $event, $param) | + | |
| - | if ($event-> | + | |
| - | return; | + | |
| - | } | + | |
| - | + | ||
| - | $helper = plugin_load(' | + | |
| - | + | ||
| - | // Vérifier les permissions | + | |
| - | if (!$helper->checkPermissions()) { | + | |
| - | 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; | + | |
| - | } | + | |
| - | + | ||
| - | | + | |
| - | $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/accueil.1773312592.txt.gz · Dernière modification : de estro
