function do_exec_system($username, $dir, $cmd, &$out, &$err, &$ret, $input) { global $gbl, $sgbl, $login, $ghtml; global $global_shell_out, $global_shell_error, $global_shell_ret; dprint("<hr> {$dir} <br> {$cmd} <hr> "); $path = "{$sgbl->__path_lxmisc}"; $fename = tempnam($sgbl->__path_tmp, "system_errr"); $execcmd = null; /* if ($username !== '__system__') { $execcmd = "$path -u $username"; } */ os_set_path(); $sh = new COM("Wscript.shell"); if ($dir) { if (!csa($dir, ':')) { $dir = getcwd() . "/{$dir}"; } $sh->currentDirectory = $dir; } $out = null; $ret = 0; $err = null; dprint("\n ** mmmmmm {$dir} {$cmd} **\n"); $cmdobject = $sh->Exec($cmd); if ($input) { $cmdobject->StdIn->Write($input); } $out = $cmdobject->StdOut->ReadAll(); $err = $cmdobject->StdErr->ReadAll(); $ret = 0; $sh->currentDirectory = $sgbl->__path_program_htmlbase; /* function ReadAllFromAny($ret) { if (!($ret->StdOut->AtEndOfStream)){ $Ret=$ret->StdOut->ReadAll(); return $Ret; } if (!($ret->StdErr->AtEndOfStream)){ $Ret="STDERR: ".$ret->StdErr->ReadAll(); return $Ret; } return -1; }*/ if ($ret) { log_shell_error("{$err}: [({$username}:{$dir}) {$cmd}]"); } log_shell("{$ret}: {$err} [({$username}:{$dir}) {$cmd}]"); $global_shell_ret = $ret; $global_shell_out = $out; $global_shell_error = $err; }
/** * The actual renderingfunction for handling all the stuff */ function renderEngine($timelinesrc, $args = null, $parser = null) { global $wgTitle, $wgUploadDirectory, $wgUploadPath, $wgGraphVizSettings, $info; // some html-output for retracing what we did $info = "<h1>Graphviz Information</h1>"; $info .= "<h2>Called render</h2>"; /* Prepare Directories */ $dest = $wgUploadDirectory . "/graphviz/"; if (stristr(PHP_OS, 'WIN') && !stristr(PHP_OS, 'Darwin')) { $dest = str_replace("/", '\\', $dest); // switch the slashes for windows $isWindows = true; } else { $isWindows = false; } if (!is_dir($dest)) { mkdir($dest, 0777); } // create directory if it isn't there /* Start pruning (if enabled) - use directory generated before * prune before creating a new image so that it won't be pruned right after creation */ if ($wgGraphVizSettings->pruneEnabled) { prune($dest, $wgGraphVizSettings->pruneStrategy, $wgGraphVizSettings->pruneValue, $wgGraphVizSettings->pruneAmount); // prune the collection first } /* Check renderer - renderer should be set at least in renderMscgen or renderGraphviz but for security we check agaion and set some additional params */ if (isset($args['renderer'])) { $renderer = $args['renderer']; } else { $renderer = 'dot'; } switch ($renderer) { case 'circo': case 'dot': case 'fdp': case 'sfdp': case 'neato': case 'twopi': $mapDashTOption = ' -Tcmapx '; $inputOption = ''; break; case 'mscgen': if ($wgGraphVizSettings->mscgenPath != null) { // check if path to mscgen is set - if not use agaion graphviz with dot $inputOption = '-i '; $mapDashTOption = ' -T ismap '; $wgGraphVizSettings->execPath = $wgGraphVizSettings->mscgenPath; // not that nice but functional: overwrite execPath with the path to mscgen } else { $renderer = 'dot'; $mapDashTOption = ' -Tcmapx '; $inputOption = ''; } break; default: $renderer = 'dot'; $mapDashTOption = ' -Tcmapx '; $inputOption = ''; } /* create the command for graphviz or mscgen */ $cmd = $renderer; $cmd = $wgGraphVizSettings->execPath . $cmd; // example: /user/bin/dot if ($isWindows) { $cmd = $cmd . '.exe'; // executables in windows } $info .= "<pre>Dir={$dest}</pre>"; $info .= "<pre>execPath=" . $wgGraphVizSettings->execPath . "</pre>"; $info .= "<pre>named=" . $wgGraphVizSettings->named . "</pre>"; /* create actual storagename */ $wgGraphVizSettings->named = strtolower($wgGraphVizSettings->named); // avoid problems with upper/lowercase /* get title name from parser. If parser not set, use $wgTitle instead */ if ($parser != null) { $title = $parser->getTitle()->getFulltext(); } else { $title = $wgTitle->getFulltext(); } $storagename = str_replace("%", '_perc_', urlencode($title)) . '---'; // clean up pagename (special chars etc) if ($wgGraphVizSettings->named == 'md5') { $storagename = md5($storagename . $timelinesrc); // produce md5-hash out of the storagename !can be duplicate! } elseif ($wgGraphVizSettings->named == 'sha1') { $storagename = sha1($storagename . $timelinesrc); // produce sha1-hash } else { // named == 'named' $storagename .= str_replace("%", '_perc_', urlencode(trim(str_replace(array("\n", "\\"), array('', '/'), substr($timelinesrc, 0, strpos($timelinesrc, '{')))))); } $info .= "<pre>storagename=" . $storagename . "</pre>"; /* check if some outputtype is specified in the wikipage - else use the default value */ if (isset($args['format'])) { $outputType = $args['format']; } else { $outputType = $wgGraphVizSettings->outputType; } /* inputcheck of supported image types */ if ($renderer != 'mscgen') { // see supported types by graphviz itself (here only those that seem to be kind of useful) - http://www.graphviz.org/doc/info/output.html switch ($outputType) { case 'bmp': case 'gif': case 'jpg': case 'jpeg': case 'png': case 'svg': // for svg you need extra MediaWiki configuration // for svg you need extra MediaWiki configuration case 'svgz': // same as for svg // case 'tif': // case 'tiff': break; default: $outputType = 'png'; } } else { // mscgen does only support png, svg and eps switch ($outputType) { case 'png': case 'svg': break; default: $outputType = 'png'; } } $info .= "<pre>outputType=" . $outputType . "</pre>"; /* prepare the actual files */ $src = $dest . $storagename; // the raw input code - needed for the renderers - e.g. /graphviz/imagename (will be deleted later on) $imgn = $src . '.' . $outputType; // the whole image name - e.g. /graphviz/imagename.png $mapn = $src . '.map'; // the whole map name - e.g. /graphviz/imagename.map $info .= '<pre>Src=' . $src . '</pre>'; $info .= '<pre>imgn=' . $imgn . '</pre>'; $info .= '<pre>mapn=' . $mapn . '</pre>'; /* The actual commands for the rendering * check first if we have to overwrite the file (if we don't use hashes) or if it already exists */ if ($wgGraphVizSettings->named == 'named' || !(file_exists($imgn) || file_exists($src . ".err"))) { $timelinesrc = rewriteWikiUrls($timelinesrc); // if we use wiki-links we transform them to real urls // write the given dot-commands into a textfile $handle = fopen($src, "w"); if (!$handle) { return 'Error writing graphviz file to disk.'; } $ret2 = fwrite($handle, $timelinesrc); $ret3 = fclose($handle); $info .= '<pre>Opened and closed $src, handle=' . $handle . ', timeelinesrc=' . $timelinesrc . ', ret2=' . $ret2 . ', ret3=' . $ret3 . '</pre>'; // prepare the whole commands for image and map $cmdline = wfEscapeShellArg($cmd) . ' -T ' . $outputType . ' -o ' . wfEscapeShellArg($imgn) . ' ' . $inputOption . wfEscapeShellArg($src); $cmdlinemap = wfEscapeShellArg($cmd) . $mapDashTOption . '-o ' . wfEscapeShellArg($mapn) . ' ' . $inputOption . wfEscapeShellArg($src); // run the commands if ($isWindows) { $WshShell = new COM("WScript.Shell"); $ret = $WshShell->Exec($cmdline); $retmap = $WshShell->Exec($cmdlinemap); } else { $ret = shell_exec($cmdline); $retmap = shell_exec($cmdlinemap); } $info .= '<pre>Ran cmd line (image). ret=$ret cmdline=' . $cmdline . '</pre>'; $info .= '<pre>Ran cmd line (map). ret=$ret cmdlinemap=' . $cmdlinemap . '</pre>'; // Error messages for image-creation if ($wgGraphVizSettings->install && $ret == "") { echo '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdline . '</tt></div>'; $info .= '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdline . '</tt></div>'; exit; } // Error messages for map-creation if ($wgGraphVizSettings->install && $retmap == "") { echo '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdlinemap . '</tt></div>'; $info .= '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdlinemap . '</tt></div>'; exit; } // let some other programs do their stuff if ($isWindows) { while ($ret->Status == 0 || $retmap->Status == 0) { usleep(100); } } unlink($src); // delete the src right away } /* put the produced into the website */ @($err = file_get_contents($src . ".err")); // not really used if ($err != "") { $info .= '<div id="toc"><tt>' . $err . '</tt></div>'; // print error message } else { if (false == ($map = file_get_contents($mapn))) { if ($wgGraphVizSettings->install) { echo '<div id="toc"><tt>File: ' . $mapn . ' is missing or empty.</tt></div>'; $info .= '<div id="toc"><tt>File: ' . $mapn . ' is missing or empty.</tt></div>'; } } // clean up map-name $map = preg_replace('#<ma(.*)>#', ' ', $map); $map = str_replace('</map>', '', $map); if ($renderer == 'mscgen') { $mapbefore = $map; $map = preg_replace('/(\\w+)\\s([_:%#/\\w]+)\\s(\\d+,\\d+)\\s(\\d+,\\d+)/', '<area shape="$1" href="$2" title="$2" alt="$2" coords="$3,$4" />', $map); } /* Procduce html */ if ($wgGraphVizSettings->imageFormatting) { $txt = imageAtrributes($args, $storagename, $map, $outputType, $wgUploadPath); // if we want borders/position/... } else { $txt = '<map name="' . $storagename . '">' . $map . '</map>' . '<img src="' . $wgUploadPath . '/graphviz/' . $storagename . '.' . $outputType . '"' . ' usemap="#' . $storagename . '" />'; } } /* give it back to your wiki */ if ($wgGraphVizSettings->info) { $txt .= $info; } // do we want the information snipptes? return $txt; }
<?php /* * This file is part of Workflow. * * (c) sysatom <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ $url = $argv[1]; $path = urldecode($url); $path = trim(str_replace('workflow://', '', $path), '/'); //exec($path); // extension=php_com_dotnet.dll $pCOM = new COM("WScript.Shell"); $pShell = $pCOM->Exec($path);