1<?php 2/** 3* Execute command given by runcommand plugin 4* 5* @author Alessandro Celli <aelsantex@gmail.com> 6* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7* @ChangeLog: 8* 2014/03/20: Added rcObjectId argument as command and outputType selector 9*/ 10 11//---- CONSTANT and INCLUSION ------------------------------------------------------------------------------------------ 12// must be run within Dokuwiki 13if(!defined('DOKU_INC')) { 14 define('DOKU_INC',realpath(dirname(__FILE__).'/../../..').'/'); 15} 16 17function debug($msg,$msgLevel,$rcDebugLevel) { // DEBUG 18 // Write log on data/cache/debug.log 19 if ($rcDebugLevel >= $msgLevel) { 20 file_put_contents(DOKU_INC."data/cache/debug.log", print_r($msg,TRUE) . "\n", FILE_APPEND); 21 } 22} 23 24$rcDebugLevel=0; 25 26if ($rcDebugLevel > 0) { 27 //require_once '/usr/lib/php/PEAR/file_put_contents.php'; //DEBUG SOLARIS 28 require_once '/usr/share/php/./PHP/Compat/Function/file_put_contents.php'; //DEBUG UBUNTU 29}; 30 31debug($_POST, 2, $rcDebugLevel); 32 33// Parse arguments 34$arrayKey = array_keys($_POST); 35$rcObjectId=$_POST['rcObjectId']; 36 37$command=$_POST['command'.$rcObjectId]; 38$outputType=$_POST['outputType'.$rcObjectId]; 39foreach ($arrayKey as $element) { 40 if ($element == 'command'.$rcObjectId) continue; 41 if ($element == 'outputType'.$rcObjectId) continue; 42 if ($element == 'rcObjectId') continue; 43 44 $baseElement = preg_replace('/'.$rcObjectId.'$/', '', $element); 45 $command=str_replace("$".$baseElement,$_POST[$element],$command); 46 debug("Replace: ".$baseElement." -> ".$_POST[$element]." | ".$command, 3, $rcDebugLevel); 47} 48$command=stripslashes($command); 49 50unset($outputValue); 51// Eseguo lo script 52$lastLine = exec($command, $outputValue, $retVal); 53 54$result = ""; 55switch ($outputType) { 56 case 'text': 57 $result .= "<pre>\n"; 58 foreach ($outputValue as $row){ 59 $result .= $row."\n"; 60 }; 61 $result .= "</pre>\n"; 62 break; 63 case 'html': 64 $result .= "<p>\n"; 65 foreach ($outputValue as $row){ 66 $result .= $row."\n"; 67 }; 68 $result .= "</p>\n"; 69 break; 70 case 'wiki': 71 //define('DOKU_INC','/var/opt/webstack/apache2/2.2/htdocs/dokuwiki/'); 72 require_once(DOKU_INC.'inc/init.php'); 73 require_once(DOKU_INC.'inc/parserutils.php'); 74 75 $info=null; 76 $parsedOutput=p_get_instructions(implode("\n", $outputValue)); 77 $result .= p_render('xhtml',$parsedOutput, $info); 78 break; 79 case 'binary': 80 81 break; 82}; 83debug("RESULT=\n".$result, 2, $rcDebugLevel); 84print $result; 85?> 86