Example #1
0
 function setupOpenOfficeOrgServer()
 {
     $operatingSystemFamily = getOperatingSystemFamily();
     if (!$this->allowedAdminAccess || $operatingSystemFamily != 'Unix') {
         return;
     }
     $hideOpenOfficeOrgServerOption = getGlobalConfigItem('hideAdminOptionOpenOfficeOrgServer');
     if ($hideOpenOfficeOrgServerOption == "true") {
         return;
     }
     $userMessage = null;
     $pidFile = '/tmp/openoffice.org-server.pid';
     $output = '';
     if (isset($_REQUEST['openofficeorg-server-on']) || isset($_REQUEST['openofficeorg-server-off'])) {
         $unixConfigPath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'unix-specific' . DIRECTORY_SEPARATOR;
         $startStopBashScript = $unixConfigPath . 'openoffice.org-server-init.sh';
         $startOrStop = null;
         if (isset($_REQUEST['openofficeorg-server-on'])) {
             if (file_exists($pidFile) && filesize($pidFile) > 0) {
                 $userMessage = 'existing-pid';
             } else {
                 $startOrStop = 'start';
             }
         } elseif (isset($_REQUEST['openofficeorg-server-off'])) {
             if (file_exists($pidFile) && filesize($pidFile) > 0) {
                 $startOrStop = 'stop';
             } else {
                 $userMessage = 'no-existing-pid';
             }
         }
         if ($startOrStop) {
             include_once dirname(__FILE__) . '/config.php';
             $runAsUser = '';
             $sudo = '';
             $startTime = 8;
             $stopTime = 3;
             $customUser = getGlobalConfigItem('runExternalApplicationAsUser');
             if ($customUser) {
                 $runAsUser = $customUser;
             }
             $startStopScript = null;
             $superUserPreference = getSuperUserPreference();
             if ($superUserPreference == 'sudo') {
                 $startStopScript = $startStopBashScript;
                 $sudo = 'sudo -u {runAsUser}';
             } elseif ($superUserPreference == 'nothing') {
                 $startStopScript = $startStopBashScript;
                 $sudo = '';
             }
             $commandTemplate = '{sudo} {startStopScript} {startOrStop} {runAsUser}';
             $commandTemplate = str_replace('{sudo}', $sudo, $commandTemplate);
             $commandTemplate = str_replace('{startStopScript}', $startStopScript, $commandTemplate);
             $commandTemplate = str_replace('{startOrStop}', $startOrStop, $commandTemplate);
             $commandTemplate = str_replace('{runAsUser}', $runAsUser, $commandTemplate);
             $commandTemplate = trim($commandTemplate);
             $output = shellCommand($commandTemplate, 0);
             switch ($startOrStop) {
                 // due to OOo delay in startup/shutdown we'll just twiddle our thumbs for a bit
                 case 'start':
                     sleep($startTime);
                     break;
                 case 'stop':
                     sleep($stopTime);
                     break;
             }
             if (isset($_REQUEST['openofficeorg-server-on']) || isset($_REQUEST['openofficeorg-server-off'])) {
                 $output = '<blockquote><tt>' . revealXml($commandTemplate) . '</tt></blockquote><blockquote><tt>' . revealXml($output) . '</tt></blockquote>';
                 if (isset($_REQUEST['openofficeorg-server-on']) && !file_exists($pidFile)) {
                     webServiceError('&error-unable-to-start-ooo-server; ' . $output . ' ');
                 } elseif (isset($_REQUEST['openofficeorg-server-off']) && file_exists($pidFile)) {
                     webServiceError('&error-unable-to-stop-ooo-server; ' . $output . ' ');
                 }
             }
         }
     }
     if (!is_readable($pidFile)) {
         $response = $this->getThemeFragment('admin-setupopenofficeorg-server-button-unknown.htmlf');
     } elseif (file_exists($pidFile) && filesize($pidFile) > 0) {
         $response = $this->getThemeFragment('admin-setupopenofficeorg-server-button-disabled.htmlf');
     } else {
         $response = $this->getThemeFragment('admin-setupopenofficeorg-server-button-enabled.htmlf');
     }
     //if($userMessage)
     //	{
     //	$response = $response.$this->getThemeFragment('error-setupopenofficeorg-server-'.$userMessage.'.htmlf');
     //	}
     if ($output) {
         $response = $response . '<p>Output:</p><pre style="padding:0px 0.5em;font-size:small;background:#cccccc">' . $output . '</pre>';
     }
     return $response;
 }
Example #2
0
 function svgToPng($svgPath, $widthInPixels, $heightInPixels, $deleteOriginal = false)
 {
     $svgToPngConverterPath = DOCVERT_DIR . 'core' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR;
     $operatingSystemFamily = getOperatingSystemFamily();
     if ($operatingSystemFamily == 'Windows') {
         $svgToPngConverterPath .= 'windows-specific' . DIRECTORY_SEPARATOR . 'convert-using-svg2png.bat';
     } elseif ($operatingSystemFamily == 'Unix') {
         $svgToPngConverterPath .= 'unix-specific' . DIRECTORY_SEPARATOR . 'convert-using-svg2png.sh';
     }
     if (!file_exists($svgToPngConverterPath)) {
         webServiceError('&error-process-convertimages-no-converter;', 500, array('path' => $svgToPngConverterPath));
     }
     $svgPathInfo = pathinfo($svgPath);
     $pngPath = dirname($svgPath) . DIRECTORY_SEPARATOR . basename($svgPath, '.' . $svgPathInfo['extension']) . '.png';
     $command = escapeshellarg($svgToPngConverterPath) . ' ' . escapeshellarg($svgPath) . ' ' . escapeshellarg($pngPath) . ' ' . escapeshellarg($widthInPixels) . ' ' . escapeshellarg($heightInPixels);
     shellCommand($command);
     if (!file_exists($pngPath)) {
         webServiceError('&error-process-convertimages-no-png;', 500, array('command' => $command));
     }
     if ($deleteOriginal) {
         silentlyUnlink($svgPath);
     }
     return $pngPath;
 }
Example #3
0
function deleteDirectoryRecursively($directoryPath)
{
    $directoryPath = convertPathSlashesForCurrentOperatingSystem($directoryPath);
    if ($files = glob($directoryPath . DIRECTORY_SEPARATOR . '*')) {
        foreach ($files as $file) {
            if (is_dir($file)) {
                deleteDirectoryRecursively($file);
            } else {
                silentlyUnlink($file);
            }
        }
    }
    $operatingSystemFamily = getOperatingSystemFamily();
    $detailedError = '';
    if ($operatingSystemFamily == 'Windows') {
        $rmdirCommand = 'rmdir /s /q ' . $directoryPath;
        $response = shellCommand($rmdirCommand);
        $response = trim($response);
        //file_put_contents('c:\\results.txt', "\r\n".$response."\r\n", FILE_APPEND);
        if (stripos($response, 'process cannot access the file') !== false) {
            $detailedError .= '. Reason: ' . $response;
        } else {
            $detailedError .= '. Running command "' . $rmdirCommand . '" ' . $response;
        }
    }
    if (@(!rmdir($directoryPath))) {
        $detailedError = null;
        $contentsOfDirectory = implode(glob($directoryPath . DIRECTORY_SEPARATOR . '*'), ', ');
        $contentsOfDirectory = substr($contentsOfDirectory, 0, strlen($contentsOfDirectory) - 1);
        if (trim($contentsOfDirectory)) {
            $detailedError .= 'Directory contains ' . $contentsOfDirectory . '. ';
        }
        if (file_exists($directoryPath)) {
            silentlyAppendLineToLog('Unable to delete directory ' . $directoryPath . $detailedError, 'error');
        }
    }
}