Outils pour utilisateurs

Outils du site


lumo:creation_complete_du_plugin_dokuwiki:accueil

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
lumo:creation_complete_du_plugin_dokuwiki:accueil [2026/03/12 10:49] estrolumo:creation_complete_du_plugin_dokuwiki:accueil [2026/03/12 11:11] (Version actuelle) estro
Ligne 2: Ligne 2:
 [[./|retour]] [[./|retour]]
 ---- ----
-===== Structure du Plugin =====+<adm example Structure du Plugin> 
 +==== Structure du Plugin ====
 <code> <code>
 /lib/plugins/bashexec/ /lib/plugins/bashexec/
Ligne 11: Ligne 12:
 └── manifest.ini        # Métadonnées du plugin └── manifest.ini        # Métadonnées du plugin
 </code> </code>
 +</adm>
 {{page>1. manifest.ini}} {{page>1. manifest.ini}}
 {{page>2. helper.php (Fonctions utilitaires)}} {{page>2. helper.php (Fonctions utilitaires)}}
-<adm information 3. syntax.php (Syntaxe dans les pages wiki)+{{page>3. syntax.php (Syntaxe dans les pages wiki)}} 
-++++code php| +{{page>4. action.php (Actions via URL)}} 
-<code php> +{{page>5Exemple de Script Bash Sécurisé}
-<?php +{{page>6. Configuration Nginx Complète}} 
-/** +{{page>7Installation et Permissions }} 
- * Syntax Plugin for Bash Exec +{{page>8. Utilisation dans DokuWiki }
- */ +{{page>9Fichier de Configuration (conf/default.php) }}
-class syntax_plugin_bashexec extends DokuWiki_Plugin_Syntax { +
-     +
-    public function getType() { +
-        return 'substition'; +
-    } +
-     +
-    public function getPType() { +
-        return 'normal'; +
-    +
-     +
-    public function getSort() { +
-        return 150; +
-    } +
-     +
-    public function connectTo($mode) { +
-        $this->Lexer->addSpecialPattern('%%bashexec\{[^}]+\}%%', $mode, 'plugin_bashexec')+
-    } +
-     +
-    public function handle($match, $state, $pos, Doku_Handler $handler) { +
-        preg_match('/%%bashexec\{([^}]+)\}%%/', $match, $matches); +
-        $params = trim($matches[1]); +
-         +
-        // Parse: script.sh arg1 arg2 +
-        $parts = preg_split('/\s+/', $params); +
-        $script = array_shift($parts); +
-        $args = $parts; +
-         +
-        return array($script, $args); +
-    } +
-     +
-    public function render($format, Doku_Renderer $renderer, $data) { +
-        if ($format != 'xhtml'{ +
-            return false; +
-        } +
-         +
-        list($script, $args) = $data; +
-        $helper = plugin_load('helper', 'bashexec'); +
-         +
-        // Vérifier les permissions +
-        if (!$helper->checkPermissions()) { +
-            $renderer->cdata('Accès refusé'); +
-            return true; +
-        } +
-         +
-        // Valider le script +
-        if (!$helper->validateScriptPath(DOKU_PLUGIN 'bashexec/scripts/' . $script)) { +
-            $renderer->cdata('Script non autorisé'); +
-            return true; +
-        +
-         +
-        // Valider tous les arguments +
-        foreach ($args as $arg) { +
-            if (!$helper->validateArgument($arg)) { +
-                $renderer->cdata('Argument invalide'); +
-                return true; +
-            } +
-        +
-         +
-        // Exécuter le script +
-        $fullScript = DOKU_PLUGIN . 'bashexec/scripts/' . $script; +
-        $cmd = escapeshellcmd($fullScript); +
-        $escapedArgs = array_map('escapeshellarg', $args); +
-        $command = $cmd . ' ' . implode(' ', $escapedArgs); +
-         +
-        exec($command, $output, $returnCode); +
-         +
-        // Journaliser +
-        global $INPUT; +
-        $helper->logExecution($script, $args, $returnCode, $INPUT->server->str('REMOTE_USER')); +
-         +
-        // Afficher le résultat +
-        if ($returnCode === 0) { +
-            $renderer->cdata(implode("\n", $output)); +
-        } else { +
-            $renderer->cdata('Erreur d\'exécution (code: ' $returnCode . ')'); +
-        } +
-         +
-        return true; +
-    +
-+
-</code> +
-++++ +
-</adm> +
-<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('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleScriptRequest'); +
-        $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, 'renderOutput'); +
-    +
-     +
-    public function handleScriptRequest(Doku_Event $event, $param) { +
-        if ($event->data !== 'script'{ +
-            return; +
-        } +
-         +
-        $helper = plugin_load('helper', 'bashexec'); +
-         +
-        // Vérifier les permissions +
-        if (!$helper->checkPermissions()) { +
-            http_response_code(403); +
-            print json_encode(['error' => 'Accès refusé']); +
-            exit; +
-        } +
-         +
-        // Récupérer les paramètres +
-        $script = $this->getInput('script'); +
-        $arg1 = $this->getInput('arg1'); +
-        $arg2 = $this->getInput('arg2'); +
-         +
-        // Valider le script +
-        if (!$helper->validateScriptPath(DOKU_PLUGIN 'bashexec/scripts/' . $script)) { +
-            http_response_code(400); +
-            print json_encode(['error' => 'Script non autorisé']); +
-            exit; +
-        } +
-         +
-        // Valider les arguments +
-        $args = array_filter([$arg1, $arg2]); +
-        foreach ($args as $arg) { +
-            if (!$helper->validateArgument($arg)) { +
-                http_response_code(400); +
-                print json_encode(['error' => 'Argument invalide']); +
-                exit; +
-            } +
-        } +
-         +
-        // Exécuter +
-        $fullScript = DOKU_PLUGIN 'bashexec/scripts/' . $script; +
-        $escapedArgs = array_map('escapeshellarg', $args)+
-        $command = escapeshellcmd($fullScript) . ' ' . implode(' ', $escapedArgs); +
-         +
-        exec($command, $output, $returnCode); +
-         +
-        // Journaliser +
-        global $INPUT; +
-        $helper->logExecution($script, $args, $returnCode, $INPUT->server->str('REMOTE_USER')); +
-         +
-        // Répondre +
-        header('Content-Type: application/json'); +
-        print json_encode([ +
-            'success' => $returnCode === 0, +
-            'output' => $output, +
-            'return_code' => $returnCode +
-        ]); +
-        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 +
-    } +
-+
-</code> +
-+++++
  
-</adm> 
-<adm warning 5. Exemple de Script Bash Sécurisé> 
-++++code bash| 
-<code bash> 
-#!/bin/bash 
-# /lib/plugins/bashexec/scripts/status.sh 
- 
-# Vérifier les permissions du script 
-if [ "$(id -u)" -eq 0 ]; then 
-    echo "Erreur: Le script ne doit pas être exécuté en root" >&2 
-    exit 1 
-fi 
- 
-# Arguments attendus 
-ARG1="${1:-}" 
-ARG2="${2:-}" 
- 
-# Validation côté script (défense en profondeur) 
-if [[ ! "$ARG1" =~ ^[a-zA-Z0-9_-]{1,50}$ ]]; then 
-    echo "Erreur: Argument 1 invalide" >&2 
-    exit 1 
-fi 
- 
-# Exemple d'exécution 
-case "$ARG1" in 
-    "status") 
-        echo "Statut: OK" 
-        echo "Paramètre: $ARG2" 
-        ;; 
-    "info") 
-        echo "Informations système" 
-        uname -a 
-        ;; 
-    *) 
-        echo "Commande inconnue: $ARG1" >&2 
-        exit 1 
-        ;; 
-esac 
- 
-exit 0 
-</code> 
-++++ 
-</adm> 
-<adm achievement 6. Configuration Nginx Complète> 
-++++code php| 
-<code php> 
-server { 
-    listen 80; 
-    server_name wiki.votre-domaine.com; 
-    root /var/www/dokuwiki; 
-    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:/var/run/php/php-fpm.sock; 
-        include fastcgi_params; 
-        fastcgi_param SCRIPT_FILENAME $document_root/index.php; 
-        fastcgi_param HTTPS off; 
-    } 
-     
-    # Protection des fichiers sensibles 
-    location ~* ^/(conf|inc|lib|data)/.*$ { 
-        deny all; 
-        return 403; 
-    } 
-     
-    # Protection des scripts bash 
-    location ~* \.sh$ { 
-        deny all; 
-        return 403; 
-    } 
-     
-    # Rate limiting pour l'exécution de scripts 
-    limit_req_zone $binary_remote_addr zone=bashexec:10m rate=5r/m; 
-     
-    location /lib/plugins/bashexec/ { 
-        limit_req zone=bashexec burst=2 nodelay; 
-        fastcgi_pass unix:/var/run/php/php-fpm.sock; 
-        include fastcgi_params; 
-        fastcgi_param SCRIPT_FILENAME $document_root/index.php; 
-    } 
-     
-    # Logs spécifiques 
-    access_log /var/log/nginx/dokuwiki-bashexec.log; 
-} 
-</code> 
-++++ 
-</adm> 
-<adm achievement> 
-++++code conf| 
-<code conf> 
- 
-</code> 
-++++ 
-</adm> 
lumo/creation_complete_du_plugin_dokuwiki/accueil.1773312592.txt.gz · Dernière modification : de estro

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki