本文整理汇总了PHP中KTUtil::findCommand方法的典型用法代码示例。如果您正苦于以下问题:PHP KTUtil::findCommand方法的具体用法?PHP KTUtil::findCommand怎么用?PHP KTUtil::findCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KTUtil
的用法示例。
在下文中一共展示了KTUtil::findCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDiskUsageStats
public static function getDiskUsageStats($update = true)
{
$config = KTConfig::getSingleton();
$cmd = KTUtil::findCommand('externalBinary/df', 'df');
if ($cmd === false) {
if ($update) {
KTUtil::setSystemSetting('DiskUsage', 'n/a');
}
return false;
}
$warningPercent = $config->get('DiskUsage/warningThreshold', 15);
$urgentPercent = $config->get('DiskUsage/urgentThreshold', 5);
if (OS_WINDOWS) {
$cmd = str_replace('/', '\\', $cmd);
$res = KTUtil::pexec("\"{$cmd}\" -B 1 2>&1");
$result = implode("\r\n", $res['out']);
} else {
if (strtolower(PHP_OS) == 'darwin') {
$result = shell_exec($cmd . " -k 2>&1");
} else {
$result = shell_exec($cmd . " -B 1 2>&1");
}
}
if (strpos($result, 'cannot read table of mounted file systems') !== false) {
if ($update) {
KTUtil::setSystemSetting('DiskUsage', 'n/a');
}
return false;
}
$result = explode("\n", $result);
unset($result[0]);
// gets rid of headings
$usage = array();
foreach ($result as $line) {
if (empty($line)) {
continue;
}
preg_match('/(.*)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\%\\s+(.*)/', $line, $matches);
list($line, $filesystem, $size, $used, $avail, $usedp, $mount) = $matches;
if ($size === 0 || empty($size)) {
continue;
}
if (strtolower(PHP_OS) == 'darwin') {
$size = $size * 1024;
$used = $used * 1024;
$avail = $avail * 1024;
}
$colour = '';
if ($usedp >= 100 - $urgentPercent) {
$colour = 'red';
} elseif ($usedp >= 100 - $warningPercent) {
$colour = 'orange';
}
$usage[] = array('filesystem' => trim($filesystem), 'size' => KTUtil::filesizeToString($size), 'used' => KTUtil::filesizeToString($used), 'available' => KTUtil::filesizeToString($avail), 'usage' => $usedp . '%', 'mounted' => trim($mount), 'colour' => $colour);
}
if ($update) {
KTUtil::setSystemSetting('DiskUsage', serialize($usage));
}
return $usage;
}
示例2: checkDF
function checkDF()
{
$df = KTUtil::findCommand('externalBinary/df', 'df');
if (false === $df) {
$this->addIssue('Storage Utilization', 'Could not locate the <i>df</i> binary.');
}
}
示例3: __construct
public function __construct()
{
$config = KTConfig::getSingleton();
$this->unzip = KTUtil::findCommand("import/unzip", 'unzip');
$this->unzip = str_replace('\\', '/', $this->unzip);
$this->unzip_params = $config->get('extractorParameters/unzip', '"{source}" "{part}" -d "{target_dir}"');
parent::__construct();
}
示例4: findLocalCommand
function findLocalCommand()
{
if (OS_WINDOWS) {
$this->command = 'c:\\antiword\\antiword.exe';
$this->commandconfig = 'indexer/antiword';
$this->args = array();
}
$sCommand = KTUtil::findCommand($this->commandconfig, $this->command);
return $sCommand;
}
示例5: __construct
public function __construct($targetExtension = 'html')
{
parent::__construct();
$this->targetExtension = $targetExtension;
$config =& KTConfig::getSingleton();
$this->useOO = $config->get('indexer/useOpenOffice', true);
$this->python = KTUtil::findCommand('externalBinary/python');
$this->ooHost = $config->get('openoffice/host');
$this->ooPort = $config->get('openoffice/port');
$this->documentConverter = KT_DIR . '/bin/openoffice/DocumentConverter.py';
if (!is_file($this->documentConverter)) {
$this->documentConverter = false;
}
}
示例6: findLocalCommand
function findLocalCommand()
{
$sCommand = KTUtil::findCommand($this->commandconfig, $this->command);
return $sCommand;
}
示例7: capture_df
/**
* Get disk usage
*
* @param string $path
*/
private function capture_df($path)
{
$df = KTUtil::findCommand('externalBinary/df', 'df');
if (!file_exists($df) || !is_executable($df)) {
return;
}
$df = popen($df, 'r');
$content = fread($df, 10240);
pclose($df);
file_put_contents($path . '/df.txt', $content);
}
示例8: init
function init()
{
$oKTConfig =& KTConfig::getSingleton();
$sBasedir = $oKTConfig->get("urls/tmpDirectory");
$sTmpPath = tempnam($sBasedir, 'archiveimportstorage');
if ($sTmpPath === false) {
return PEAR::raiseError(_kt("Could not create temporary directory for archive storage"));
}
if (!file_exists($this->sZipPath)) {
return PEAR::raiseError(_kt("Archive file given does not exist"));
}
unlink($sTmpPath);
mkdir($sTmpPath, 0700);
$this->sBasePath = $sTmpPath;
// Set environment language to output character encoding
$sOutputEncoding = $oKTConfig->get('export/encoding', 'UTF-8');
$loc = $sOutputEncoding;
putenv("LANG={$loc}");
putenv("LANGUAGE={$loc}");
$loc = setlocale(LC_ALL, $loc);
// File Archive doesn't unzip properly so sticking to the original unzip functionality
if ($this->sExtension == 'zip') {
// ** Original zip functionality
$sUnzipCommand = KTUtil::findCommand("import/unzip", "unzip");
if (empty($sUnzipCommand)) {
return PEAR::raiseError(_kt("unzip command not found on system"));
}
$aArgs = array($sUnzipCommand, "-q", "-n", "-d", $sTmpPath, $this->sZipPath);
$aRes = KTUtil::pexec($aArgs);
if ($aRes['ret'] !== 0) {
return PEAR::raiseError(_kt("Could not retrieve contents from zip storage"));
}
} else {
File_Archive::extract(File_Archive::readArchive($this->sExtension, File_Archive::readUploadedFile('file')), $dst = $sTmpPath);
}
}
示例9: createZipFile
/**
* Zip the temp folder
*/
function createZipFile($bEchoStatus = FALSE)
{
if (empty($this->aPaths)) {
return PEAR::raiseError(_kt("No folders or documents found to compress"));
}
// Set environment language to output character encoding
$loc = $this->sOutputEncoding;
putenv("LANG={$loc}");
putenv("LANGUAGE={$loc}");
$loc = setlocale(LC_ALL, $loc);
$sManifest = sprintf("%s/%s", $this->sTmpPath, "MANIFEST");
file_put_contents($sManifest, join("\n", $this->aPaths));
$sZipFile = sprintf("%s/%s.zip", $this->sTmpPath, $this->sZipFileName);
$sZipFile = str_replace('<', '', str_replace('</', '', str_replace('>', '', $sZipFile)));
$sZipCommand = KTUtil::findCommand("export/zip", "zip");
$aCmd = array($sZipCommand, "-r", $sZipFile, ".", "-i@MANIFEST");
$sOldPath = getcwd();
chdir($this->sTmpPath);
// Note that the popen means that pexec will return a file descriptor
$aOptions = array('popen' => 'r');
$fh = KTUtil::pexec($aCmd, $aOptions);
if ($bEchoStatus) {
$last_beat = time();
while (!feof($fh)) {
if ($i % 1000 == 0) {
$this_beat = time();
if ($last_beat + 1 < $this_beat) {
$last_beat = $this_beat;
print " ";
}
}
$contents = fread($fh, 4096);
if ($contents) {
print nl2br($this->_convertEncoding($contents, false));
}
$i++;
}
}
pclose($fh);
// Save the zip file and path into session
$_SESSION['zipcompression'] = KTUtil::arrayGet($_SESSION, 'zipcompression', array());
$sExportCode = KTUtil::randomString();
$_SESSION['zipcompression'][$sExportCode] = array('file' => $sZipFile, 'dir' => $this->sTmpPath);
$_SESSION['zipcompression']['exportcode'] = $sExportCode;
$this->sZipFile = $sZipFile;
return $sExportCode;
}
示例10: extract_contents
function extract_contents($sFilename, $sTempFilename)
{
$sCommand = KTUtil::findCommand($this->commandconfig, $this->command);
if (empty($sCommand)) {
return false;
}
$cmdline = array($sCommand);
$cmdline = kt_array_merge($cmdline, $this->args);
$cmdline[] = $sFilename;
$aOptions = array();
$aOptions['exec_wait'] = 'true';
if ($this->use_pipes) {
$aOptions["append"] = $sTempFilename;
} else {
$cmdline[] = $sTempFilename;
}
$aRet = KTUtil::pexec($cmdline, $aOptions);
$this->aCommandOutput = $aRet['out'];
$contents = file_get_contents($sTempFilename);
return $contents;
}
示例11: do_pdfdownload_deprecated
/**
* Method for downloading the document as a pdf.
*
* @deprecated
* @return true on success else false
*/
function do_pdfdownload_deprecated()
{
$oDocument = $this->oDocument;
$oStorage =& KTStorageManagerUtil::getSingleton();
$oConfig =& KTConfig::getSingleton();
$default = realpath(str_replace('\\', '/', KT_DIR . '/../openoffice/program'));
putenv('ooProgramPath=' . $oConfig->get('openoffice/programPath', $default));
$cmdpath = KTUtil::findCommand('externalBinary/python');
// Check if openoffice and python are available
if ($cmdpath == false || !file_exists($cmdpath) || empty($cmdpath)) {
// Set the error messsage and redirect to view document
$this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. Python binary not found.'));
redirect(generateControllerLink('viewDocument', sprintf('fDocumentId=%d', $oDocument->getId())));
exit(0);
}
//get the actual path to the document on the server
$sPath = sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $oStorage->getPath($oDocument));
if (file_exists($sPath)) {
// Get a tmp file
$sTempFilename = tempnam('/tmp', 'ktpdf');
// We need to handle Windows differently - as usual ;)
if (substr(PHP_OS, 0, 3) == 'WIN') {
$cmd = "\"" . $cmdpath . "\" \"" . KT_DIR . "/bin/openoffice/pdfgen.py\" \"" . $sPath . "\" \"" . $sTempFilename . "\"";
$cmd = str_replace('/', '\\', $cmd);
// TODO: Check for more errors here
// SECURTIY: Ensure $sPath and $sTempFilename are safe or they could be used to excecute arbitrary commands!
// Excecute the python script. TODO: Check this works with Windows
$res = `"{$cmd}" 2>&1`;
//print($res);
//print($cmd);
//exit;
} else {
// TODO: Check for more errors here
// SECURTIY: Ensure $sPath and $sTempFilename are safe or they could be used to excecute arbitrary commands!
// Excecute the python script.
$cmd = $cmdpath . ' ' . KT_DIR . '/bin/openoffice/pdfgen.py ' . escapeshellcmd($sPath) . ' ' . escapeshellcmd($sTempFilename);
$res = shell_exec($cmd . " 2>&1");
//print($res);
//print($cmd);
//exit;
}
// Check the tempfile exists and the python script did not return anything (which would indicate an error)
if (file_exists($sTempFilename) && $res == '') {
$mimetype = 'application/pdf';
$size = filesize($sTempFilename);
$name = substr($oDocument->getFileName(), 0, strrpos($oDocument->getFileName(), '.')) . '.pdf';
KTUtil::download($sTempFilename, $mimetype, $size, $name);
// Remove the tempfile
unlink($sTempFilename);
// Create the document transaction
$oDocumentTransaction =& new DocumentTransaction($oDocument, 'Document downloaded as PDF', 'ktcore.transactions.download', $aOptions);
$oDocumentTransaction->create();
// Just stop here - the content has already been sent.
exit(0);
} else {
// Set the error messsage and redirect to view document
$this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. ' . $res));
redirect(generateControllerLink('viewDocument', sprintf('fDocumentId=%d', $oDocument->getId())));
exit(0);
}
} else {
// Set the error messsage and redirect to view document
$this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. The path to the document did not exist.'));
redirect(generateControllerLink('viewDocument', sprintf('fDocumentId=%d', $oDocument->getId())));
exit(0);
}
}
示例12: realpath
if (!is_executable(KT_DIR . '/' . $script) && $ext != 'php') {
$default->log->error("Scheduler: The script '{$sTaskUrl}' is not executable.");
continue;
}
}
$file = realpath(KT_DIR . '/' . $sTaskUrl);
if ($file === false) {
$default->log->error("Scheduler: The script '{$sTaskUrl}' cannot be resolved.");
continue;
}
$iTime = time();
$iStart = KTUtil::getBenchmarkTime();
// Run the script
$cmd = "\"{$file}\" {$sParameters}";
if ($ext == 'php') {
$phpPath = KTUtil::findCommand('externalBinary/php');
// being protective as some scripts work on relative paths
$dirname = dirname($file);
chdir($dirname);
$cmd = "\"{$phpPath}\" {$cmd}";
}
if (OS_WINDOWS) {
$default->log->debug("Scheduler - dirname: {$dirname} cmd: {$cmd}");
//$WshShell = new COM("WScript.Shell");
//$res = $WshShell->Run($cmd, 0, true);
KTUtil::pexec($cmd);
} else {
$res = shell_exec($cmd . " 2>&1");
}
// On completion - reset run time
$iEnd = KTUtil::getBenchmarkTime();
示例13: findLocalCommand
function findLocalCommand()
{
putenv('LANG=en_US.UTF-8');
$sCommand = KTUtil::findCommand($this->commandconfig, $this->command);
return $sCommand;
}
示例14: extract_contents
function extract_contents($sFilename, $sTmpFilename)
{
$sUnzipCommand = KTUtil::findCommand("import/unzip", "unzip");
if (empty($sUnzipCommand)) {
return;
}
$oKTConfig =& KTConfig::getSingleton();
$sBasedir = $oKTConfig->get("urls/tmpDirectory");
$this->sTmpPath = tempnam($sBasedir, 'opendocumentextract');
if ($this->sTmpPath === false) {
return;
}
unlink($this->sTmpPath);
mkdir($this->sTmpPath, 0700);
$sCmd = array($sUnzipCommand, "-q", "-n", "-d", $this->sTmpPath, $sFilename);
KTUtil::pexec($sCmd, array('exec_wait' => 'true'));
$sManifest = sprintf("%s/%s", $this->sTmpPath, "META-INF/manifest.xml");
if (OS_WINDOWS) {
$sManifest = str_replace('/', '\\', $sManifest);
}
if (!file_exists($sManifest)) {
$this->cleanup();
return;
}
$sContentFile = sprintf("%s/%s", $this->sTmpPath, "content.xml");
if (OS_WINDOWS) {
$sContentFile = str_replace('/', '\\', $sContentFile);
}
if (!file_exists($sContentFile)) {
$this->cleanup();
return;
}
$sContent = file_get_contents($sContentFile);
$sContent = preg_replace("@(</?[^>]*>)+@", " ", $sContent);
$this->cleanup();
return $sContent;
}
示例15: __construct
/**
* Initialise the extractor.
*
* @param string $section The section in the config file.
* @param string $appname The application name in the config file.
* @param string $command The command that can be run.
* @param string $displayname
* @param string $params
*/
public function __construct($section, $appname, $command, $displayname, $params)
{
parent::__construct();
$this->application = KTUtil::findCommand("{$section}/{$appname}", $command);
$this->command = $command;
$this->displayname = $displayname;
$this->params = $params;
}