public function find() { if (defined('HHVM_VERSION') && false !== ($hhvm = getenv('PHP_BINARY'))) { return $hhvm; } if (defined('PHP_BINARY') && PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server')) && is_file(PHP_BINARY)) { return PHP_BINARY; } if ($php = getenv('PHP_PATH')) { if (!is_executable($php)) { return false; } return $php; } if ($php = getenv('PHP_PEAR_PHP_BIN')) { if (is_executable($php)) { return $php; } } $dirs = array(PHP_BINDIR); if (defined('PHP_WINDOWS_VERSION_BUILD')) { $dirs[] = 'C:\\xampp\\php\\'; } return $this->executableFinder->find('php', false, $dirs); }
/** * Checks permissions of files and directories. * @param sFileName - file's name. */ function checkPermissions($sFileName) { $sPermissions = ""; $sFilePath = trim($sFileName); clearstatcache(); if (!file_exists($sFilePath)) { $sResult = ""; } else { clearstatcache(); $iPermissions = fileperms($sFilePath); for ($i = 0, $offset = 0; $i < 3; $i++, $offset += 3) { $iPerm = 0; for ($j = 0; $j < 3; $j++) { $iPermissions >> $j + $offset & 1 ? $iPerm += pow(2, $j) : ""; } $sPermissions = $iPerm . $sPermissions; } $sResult = $sPermissions; } $sResult = ""; $bDir = is_dir($sFilePath); if (is_readable($sFilePath)) { $sResult = $bDir ? "755" : "644"; } if (is_writable($sFilePath)) { $sResult = $bDir ? "777" : "666"; } if (!$bDir && is_executable($sFilePath)) { $sResult = "777"; } return $sResult; }
protected function findPhpBinary() { if (defined('PHP_BINARY') && PHP_BINARY) { return PHP_BINARY; } if (false !== strpos(basename($php = $_SERVER['_']), 'php')) { return $php; } // from https://github.com/symfony/Process/blob/379b35a41a2749cf7361dda0f03e04410daaca4c/PhpExecutableFinder.php $suffixes = DIRECTORY_SEPARATOR == '\\' ? (getenv('PATHEXT') ? explode(PATH_SEPARATOR, getenv('PATHEXT')) : array('.exe', '.bat', '.cmd', '.com')) : array(''); foreach ($suffixes as $suffix) { if (is_executable($php = PHP_BINDIR.DIRECTORY_SEPARATOR.'php'.$suffix)) { return $php; } } if ($php = getenv('PHP_PEAR_PHP_BIN')) { if (is_executable($php)) { return $php; } } return sfToolkit::getPhpCli(); }
/** * Find a system program, do also path checking when not running on WINNT * on WINNT we simply return the name with the exe extension to the program name * * @param string $strProgram name of the program * * @return string complete path and name of the program */ private static function _findProgram($strProgram) { $arrPath = array(); if (PHP_OS == 'WINNT') { $strProgram .= '.exe'; $arrPath = preg_split('/;/', getenv("Path"), -1, PREG_SPLIT_NO_EMPTY); } else { $arrPath = preg_split('/:/', getenv("PATH"), -1, PREG_SPLIT_NO_EMPTY); } if (PSI_ADD_PATHS !== false) { $addpaths = preg_split('/,/', PSI_ADD_PATHS, -1, PREG_SPLIT_NO_EMPTY); $arrPath = array_merge($addpaths, $arrPath); // In this order so $addpaths is before $arrPath when looking for a program } //add some default paths if we still have no paths here if (empty($arrPath) && PHP_OS != 'WINNT') { array_push($arrPath, '/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin'); } // If open_basedir defined, fill the $open_basedir array with authorized paths,. (Not tested when no open_basedir restriction) if ((bool) ini_get('open_basedir')) { $open_basedir = preg_split('/:/', ini_get('open_basedir'), -1, PREG_SPLIT_NO_EMPTY); } foreach ($arrPath as $strPath) { // To avoid "open_basedir restriction in effect" error when testing paths if restriction is enabled if (isset($open_basedir) && !in_array($strPath, $open_basedir) || !is_dir($strPath)) { continue; } $strProgrammpath = $strPath . "/" . $strProgram; if (is_executable($strProgrammpath)) { return $strProgrammpath; } } }
/** */ public function minify() { if (!is_executable($this->_opts['java']) || !is_readable($this->_opts['closure'])) { $this->_opts['logger']->log('The java path or Closure location can not be accessed.', Horde_Log::ERR); return parent::minify(); } /* --warning_level QUIET - closure default is "DEFAULT" which will * cause code with compiler warnings to output bad js (see Bug * #13789) */ $cmd = trim(escapeshellcmd($this->_opts['java']) . ' -jar ' . escapeshellarg($this->_opts['closure']) . ' --warning_level QUIET'); if (isset($this->_opts['sourcemap']) && is_array($this->_data)) { $this->_sourcemap = Horde_Util::getTempFile(); $cmd .= ' --create_source_map ' . escapeshellarg($this->_sourcemap) . ' --source_map_format=V3'; $suffix = "\n//# sourceMappingURL=" . $this->_opts['sourcemap']; } else { $suffix = ''; } if (isset($this->_opts['cmdline'])) { $cmd .= ' ' . trim($this->_opts['cmdline']); } if (is_array($this->_data)) { $js = ''; foreach ($this->_data as $val) { $cmd .= ' ' . $val; } } else { $js = $this->_data; } $cmdline = new Horde_JavascriptMinify_Util_Cmdline(); return $cmdline->runCmd($js, $cmd, $this->_opts['logger']) . $suffix . $this->_sourceUrls(); }
function init_convert_options() { global $config, $lang; $convert_options = array("convert_error" => 0, "convert_tool" => $config['convert_tool'], "convert_path" => preg_replace("/\\/\$/", "", $config['convert_tool_path'])); switch ($config['convert_tool']) { case "im": $exec = check_executable("convert"); $convert_options['convert_path'] = preg_replace("/\\/?(" . check_executable("mogrify") . "|{$exec})+\$/i", '', $convert_options['convert_path']); $convert_options['convert_path'] = $convert_options['convert_path'] . '/' . $exec; if (!@is_executable($convert_options['convert_path'])) { $convert_options['convert_error'] = "<b class=\"marktext\">" . $lang['im_error'] . "</b><br />\n" . $lang['check_module_settings']; } break; case "gd": $convert_options['convert_gd2'] = false; if (defined('CONVERT_IS_GD2')) { $convert_options['convert_gd2'] = CONVERT_IS_GD2 == 0 ? false : true; } elseif (function_exists("imagecreatetruecolor") && function_exists("imagecopyresampled")) { $convert_options['convert_gd2'] = true; } if (!function_exists("imagetypes")) { $convert_options['convert_error'] = defined("IN_CP") ? "<b class=\"marktext\">" . $lang['gd_error'] . "</b><br />\n" . $lang['check_module_settings'] : 1; } break; case "netpbm": if (!@is_executable($convert_options['convert_path'] . "/" . check_executable("pnmscale"))) { $convert_options['convert_error'] = defined("IN_CP") ? "<b class=\"marktext\">" . $lang['netpbm_error'] . "</b><br />\n" . $lang['check_module_settings'] : 1; } break; default: $convert_options['convert_error'] = defined("IN_CP") ? "<b class=\"marktext\">" . $lang['no_convert_module'] . "</b><br />\n" . $lang['check_module_settings'] : 1; } return $convert_options; }
/** * Returns the path to a specific executable * * @param string $command Name or path of the command * @return mixed */ public static function realpath($command) { // check if everything we need is available if (!static::available()) { throw new Exception('The exec() function is not available on this system. Probably, safe_mode is on (shame!).'); } // if this is actually a file, we don't need to search for it any longer if (file_exists($command)) { return is_executable($command) ? realpath($command) : false; } // let the shell search for it // depends on the operating system $exists = false; // does the command exist? $result = ''; // where is it located? if (strtolower(substr(PHP_OS, 0, 3)) === 'win') { // Windows // run the "where" command $result = `where {$command}`; // everything besides "Could not find files" would be OK $exists = !preg_match('/Could not find files/', $result); } else { // Unix // run the "which" command $result = `which {$command}`; // an empty output means there is no path $exists = !empty($result); } return $exists ? trim($result) : false; }
/** * Finds an executable by name. * * @param string $name The executable name (without the extension) * @param string $default The default to return if no executable is found * @param array $extraDirs Additional dirs to check into * * @return string The executable path or default value */ public function find($name, $default = null, array $extraDirs = array()) { if (ini_get('open_basedir')) { $searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir')); $dirs = array(); foreach ($searchPath as $path) { // Silencing against https://bugs.php.net/69240 if (@is_dir($path)) { $dirs[] = $path; } else { if (basename($path) == $name && @is_executable($path)) { return $path; } } } } else { $dirs = array_merge(explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')), $extraDirs); } $suffixes = array(''); if ('\\' === DIRECTORY_SEPARATOR) { $pathExt = getenv('PATHEXT'); $suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes; } foreach ($suffixes as $suffix) { foreach ($dirs as $dir) { if (is_file($file = $dir . DIRECTORY_SEPARATOR . $name . $suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) { return $file; } } } return $default; }
function system_check_find_path($command) { $is_windows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; if (!defined('PATH_SEPARATOR')) { $path_sep = $is_windows ? ':' : ';'; } else { $path_sep = PATH_SEPARATOR; } $path = getenv('PATH'); $path_array = explode($path_sep, $path); $pathext = $is_windows ? strtolower($_SERVER['PATHEXT']) : ''; $ext_array = explode(';', $pathext); $file_sep = $is_windows ? '\\' : '/'; $found = false; clearstatcache(); foreach ($path_array as $p) { if (substr($p, -1) === $file_sep) { $p = substr($p, 0, strlen($p) - 1); } foreach ($ext_array as $e) { $full_path = $p . $file_sep . $command . $e; if (file_exists($full_path)) { if (is_file($full_path) && ($is_windows || is_executable($full_path))) { $found = $full_path; break; } } } } return $found; }
/** * Set Container Defaults * * This is where we set all our defaults. If you need to customise this * container this is a good place to look to see what can be configured * and how to configure it. */ protected function setDefaults() { $this->binary = function () { if (is_dir(__DIR__ . '/../../../vendor')) { $bin = __DIR__ . '/../../../vendor/bin/phantomjs'; } else { $bin = __DIR__ . '/../../../../bin/phantomjs'; } if (!is_executable($bin)) { throw new RuntimeException('The phantomjs command ("' . $bin . '") ' . 'was not found or is not executable by the current user! '); } return realpath($bin); }; $this->runner = __DIR__ . '/Phantom.js'; $this->process = $this->protect(function ($cmd) { return new Process($cmd); }); $this->tempFile = $this->protect(function () { return new TempFile('GearsPdf', 'pdf'); }); $this->printFramework = function () { return ' <style>' . file_get_contents(__DIR__ . '/Print.css') . '</style> <script>' . file_get_contents(__DIR__ . '/isVisible.js') . '</script> <script>' . file_get_contents(__DIR__ . '/jQuery.js') . '</script> <script>' . file_get_contents(__DIR__ . '/Print.js') . '</script> '; }; }
/** * Displays information about the system configuration. */ public function status() { $this->set('core', array('debug' => Configure::read('debug'), 'database' => @ConnectionManager::getDataSource('default'))); $uploads_path = Configure::read('uploads.path'); $this->set('uploads', array('url' => Configure::read('uploads.url'), 'path' => $uploads_path, 'exists' => is_dir($uploads_path), 'writable' => is_writable($uploads_path), 'executable' => is_executable($uploads_path))); $this->set('dependencies', array('Ghostscript' => is_executable('ghostscript'), 'Imagemagick' => class_exists('Imagick'))); }
function doRepositoryTest($repo) { if ($repo->accessType != "ssh") { return -1; } $basePath = "../../../plugins/access.ssh/"; // Check file exists if (!file_exists($basePath . "class.sshAccessDriver.php") || !file_exists($basePath . "class.SSHOperations.php") || !file_exists($basePath . "manifest.xml") || !file_exists($basePath . "showPass.php") || !file_exists($basePath . "sshActions.xml")) { $this->failedInfo .= "Missing at least one of the plugin files (class.sshDriver.php, class.SSHOperations.php, manifest.xml, showPass.php, sshActions.xml).\nPlease reinstall from lastest release."; return FALSE; } // Check if showPass is executable from ssh $stat = stat($basePath . "showPass.php"); $mode = $stat['mode'] & 0x7fff; // We don't care about the type if (!is_executable($basePath . 'showPass.php') && ($mode & 0x40 && $stat['uid'] == posix_getuid()) && ($mode & 0x8 && $stat['gid'] == posix_getgid()) && $mode & 0x1) { chmod($basePath . 'showPass.php', 0555); if (!is_executable($basePath . 'showPass.php')) { $this->failedInfo .= "showPass.php must be executable. Please log in on your server and set showPass.php as executable (chmod u+x showPass.php)."; return FALSE; } } // Check if ssh is accessible $handle = popen("ssh 2>&1", "r"); $usage = fread($handle, 30); pclose($handle); if (strpos($usage, "usage") === FALSE) { $this->failedInfo .= "Couldn't find or execute 'ssh' on your system. Please install latest SSH client."; return FALSE; } return TRUE; }
protected function execute($arguments = array(), $options = array()) { $app = $arguments['application']; $env = $options['env']; if (!is_executable($options['java'])) { throw new sfException('Please provide a valid java executable file'); } $this->java = $options['java']; if (!is_executable($options['nohup'])) { throw new sfException('Please provide a valid nohup executable file'); } $this->nohup = $options['nohup']; $action = $arguments['action']; switch ($action) { case 'start': $this->start($app, $env, $options); break; case 'stop': $this->stop($app, $env, $options); break; case 'restart': $this->stop($app, $env, $options); $this->start($app, $env, $options); break; case 'status': $this->status($app, $env, $options); break; } }
public function __construct($gnokiiPath) { if (!is_executable($this->gnokiiPath)) { throw new \Exception('Specified Gnokii executable is not executable by me!'); } $this->gnokiiPath = $gnokiiPath; }
function tex_filter_get_executable($debug = false) { global $CFG; $error_message1 = "Your system is not configured to run mimeTeX. You need to download the appropriate<br />" . "executable for you " . PHP_OS . " platform from <a href=\"http://moodle.org/download/mimetex/\">" . "http://moodle.org/download/mimetex/</a>, or obtain the C source<br /> " . "from <a href=\"http://www.forkosh.com/mimetex.zip\">" . "http://www.forkosh.com/mimetex.zip</a>, compile it and " . "put the executable into your<br /> moodle/filter/tex/ directory."; $error_message2 = "Custom mimetex is not executable!<br /><br />"; if (PHP_OS == "WINNT" || PHP_OS == "WIN32" || PHP_OS == "Windows") { return "{$CFG->dirroot}/filter/tex/mimetex.exe"; } $custom_commandpath = "{$CFG->dirroot}/filter/tex/mimetex"; if (file_exists($custom_commandpath)) { if (is_executable($custom_commandpath)) { return $custom_commandpath; } else { error($error_message2 . $error_message1); } } switch (PHP_OS) { case "Linux": return "{$CFG->dirroot}/filter/tex/mimetex.linux"; case "Darwin": return "{$CFG->dirroot}/filter/tex/mimetex.darwin"; case "FreeBSD": return "{$CFG->dirroot}/filter/tex/mimetex.freebsd"; } error($error_message1); }
public static function checkWriteExcute($path) { if (is_executable($path) && is_writable($path)) { return true; } return false; }
/** * Return the path to an executable version of the named binary, or null. * The paths are traversed in the following order: * 1. $priority_path (if specified) * 2. Gallery's own bin directory (DOCROOT . "bin") * 3. PATH environment variable * 4. extra_binary_paths Gallery variable (if specified) * In addition, if the file is found inside Gallery's bin directory but * it's not executable, we try to change its permissions to 0755. * * @param string $binary * @param string $priority_path (optional) * @return string path to binary if found; null if not found */ static function find_binary($binary, $priority_path = null) { $bin_path = DOCROOT . "bin"; if ($priority_path) { $paths = array($priority_path, $bin_path); } else { $paths = array($bin_path); } $paths = array_merge($paths, explode(":", getenv("PATH")), explode(":", module::get_var("gallery", "extra_binary_paths"))); foreach ($paths as $path) { $path = rtrim($path, "/"); $candidate = "{$path}/{$binary}"; // @suppress errors below to avoid open_basedir issues if (@file_exists($candidate)) { if (!@is_executable($candidate) && substr_compare($bin_path, $candidate, 0, strlen($bin_path)) == 0) { // Binary isn't executable but is in Gallery's bin directory - try fixing permissions. @chmod($candidate, 0755); } if (@is_executable($candidate)) { return $candidate; } } } return null; }
function checkByCrackLib($password) { $cl = $this->api->getConfig('cracklib', null); if ($cl === null) { if (is_executable($t = '/usr/sbin/cracklib-check')) { $cl = $t; } elseif (is_executable($t = '/usr/local/sbin/cracklib-check')) { $cl = $t; } else { $cl = false; } } $password = str_replace("\r", "", $password); $password = str_replace("\n", "", $password); if ($cl && file_exists($cl) && is_executable($cl)) { $cl = $this->add('System_ProcessIO')->exec($cl)->write_all($password); $out = trim($cl->read_all()); $out = str_replace($password, '', $out); $out = preg_replace('/^:\\s*/', '', $out); if ($out == 'OK') { return true; } return $out; } else { if (strlen($password) < 4) { return "it is WAY too short"; } if (strlen($password) < 6) { return "it is too short"; } return true; } }
public function __construct() { parent::__construct(); // check pwauth executable $this->pwauth_path = $this->getConf('pwauth_path'); $this->passwd_path = $this->getConf('passwd_path'); $this->shells_path = $this->getConf('shells_path'); $this->email_domain_name = $this->getConf('email_domain_name'); if (is_executable($this->pwauth_path)) { $this->cando['addUser'] = false; $this->cando['delUser'] = false; $this->cando['modLogin'] = false; $this->cando['modPass'] = false; $this->cando['modName'] = false; $this->cando['modMail'] = false; $this->cando['modGroups'] = false; if (is_readable($this->passwd_path)) { $this->cando['getUsers'] = true; $this->cando['getUserCount'] = true; } else { $this->cando['getUsers'] = false; $this->cando['getUserCount'] = false; } $this->cando['getGroups'] = false; $this->cando['external'] = false; $this->cando['logout'] = true; $this->success = true; } else { $this->success = false; echo "pwauth not found!"; } }
/** * Returns an array of found directories * * This function checks every found directory if they match either $uid or $gid, if they do * the found directory is valid. It uses recursive function calls to find subdirectories. Due * to the recursive behauviour this function may consume much memory. * * @param string path The path to start searching in * @param integer uid The uid which must match the found directories * @param integer gid The gid which must match the found direcotries * @param array _fileList recursive transport array !for internal use only! * @return array Array of found valid pathes * * @author Martin Burchert <*****@*****.**> * @author Manuel Bernhardt <*****@*****.**> */ function findDirs($path, $uid, $gid) { $list = array($path); $_fileList = array(); while (sizeof($list) > 0) { $path = array_pop($list); $path = makeCorrectDir($path); if (!is_readable($path) || !is_executable($path)) { //return $_fileList; // only 'skip' this directory, #611 continue; } $dh = opendir($path); if ($dh === false) { /* * this should never be called because we checked * 'is_readable' before...but we never know what might happen */ standard_error('cannotreaddir', $path); return null; } else { while (false !== ($file = @readdir($dh))) { if ($file == '.' && (fileowner($path . '/' . $file) == $uid || filegroup($path . '/' . $file) == $gid)) { $_fileList[] = makeCorrectDir($path); } if (is_dir($path . '/' . $file) && $file != '..' && $file != '.') { array_push($list, $path . '/' . $file); } } @closedir($dh); } } return $_fileList; }
protected function __construct() { $idFile = wfTempDir() . '/mw-' . __CLASS__ . '-UID-nodeid'; $nodeId = is_file( $idFile ) ? file_get_contents( $idFile ) : ''; // Try to get some ID that uniquely identifies this machine (RFC 4122)... if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) { wfSuppressWarnings(); if ( wfIsWindows() ) { // http://technet.microsoft.com/en-us/library/bb490913.aspx $csv = trim( wfShellExec( 'getmac /NH /FO CSV' ) ); $line = substr( $csv, 0, strcspn( $csv, "\n" ) ); $info = str_getcsv( $line ); $nodeId = isset( $info[0] ) ? str_replace( '-', '', $info[0] ) : ''; } elseif ( is_executable( '/sbin/ifconfig' ) ) { // Linux/BSD/Solaris/OS X // See http://linux.die.net/man/8/ifconfig $m = array(); preg_match( '/\s([0-9a-f]{2}(:[0-9a-f]{2}){5})\s/', wfShellExec( '/sbin/ifconfig -a' ), $m ); $nodeId = isset( $m[1] ) ? str_replace( ':', '', $m[1] ) : ''; } wfRestoreWarnings(); if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) { $nodeId = MWCryptRand::generateHex( 12, true ); $nodeId[1] = dechex( hexdec( $nodeId[1] ) | 0x1 ); // set multicast bit } file_put_contents( $idFile, $nodeId ); // cache } $this->nodeId32 = wfBaseConvert( substr( sha1( $nodeId ), 0, 8 ), 16, 2, 32 ); $this->nodeId48 = wfBaseConvert( $nodeId, 16, 2, 48 ); // If different processes run as different users, they may have different temp dirs. // This is dealt with by initializing the clock sequence number and counters randomly. $this->lockFile88 = wfTempDir() . '/mw-' . __CLASS__ . '-UID-88'; $this->lockFile128 = wfTempDir() . '/mw-' . __CLASS__ . '-UID-128'; }
/** * Finds an executable by name. * * @param string $name The executable name (without the extension) * @param string $default The default to return if no executable is found * @param array $extraDirs Additional dirs to check into * * @return string The executable path or default value */ public function find($name, $default = null, array $extraDirs = array()) { if (ini_get('open_basedir')) { $searchPath = explode(PATH_SEPARATOR, getenv('open_basedir')); $dirs = array(); foreach ($searchPath as $path) { if (is_dir($path)) { $dirs[] = $path; } else { $file = str_replace(dirname($path), '', $path); if ($file == $name && is_executable($path)) { return $path; } } } } else { $dirs = array_merge(explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')), $extraDirs); } $suffixes = array(''); if (defined('PHP_WINDOWS_VERSION_BUILD')) { $pathExt = getenv('PATHEXT'); $suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes; } foreach ($suffixes as $suffix) { foreach ($dirs as $dir) { if (is_file($file = $dir . DIRECTORY_SEPARATOR . $name . $suffix) && (defined('PHP_WINDOWS_VERSION_BUILD') || is_executable($file))) { return $file; } } } return $default; }
public static function read_cpuz($section, $name, $match_multiple = false) { $return = $match_multiple ? array() : false; if (is_executable('C:\\Program Files\\CPUID\\CPU-Z\\cpuz.exe')) { static $cpuz_log = null; if ($cpuz_log == null) { shell_exec('"C:\\Program Files\\CPUID\\CPU-Z\\cpuz.exe" -txt=' . PTS_USER_PATH . 'cpuz'); if (is_file(PTS_USER_PATH . 'cpuz.txt')) { $cpuz_log = file_get_contents(PTS_USER_PATH . 'cpuz.txt'); unlink(PTS_USER_PATH . 'cpuz.txt'); } } $s = 0; while (($match_multiple || $s == 0) && isset($cpuz_log[$s + 1]) && ($s = strpos($cpuz_log, "\n" . $section, $s + 1)) !== false) { $cpuz_section = substr($cpuz_log, $s); if ($name != null && ($c = strpos($cpuz_section, ' ' . $name)) !== false || ($c = 0) == 0) { if ($name == null) { $name = $section; } $cpuz_section = substr($cpuz_section, $c, strpos($cpuz_section, "\r\n", $c) - $c); $return_match = substr($cpuz_section, strpos($cpuz_section, $name) + strlen($name)); if (($e = strpos($return_match, '(')) !== false) { $return_match = substr($return_match, 0, $e); } $return_match = trim($return_match); if ($match_multiple) { array_push($return, $return_match); } else { $return = $return_match; } } } } return $return; }
function isExecutable($sFile) { clearstatcache(); $aPathInfo = pathinfo(__FILE__); $sFile = $aPathInfo['dirname'] . '/../../' . $sFile; return is_file($sFile) && is_executable($sFile); }
public function find($includeArgs = true) { if (defined('HHVM_VERSION')) { return (false !== ($hhvm = getenv('PHP_BINARY')) ? $hhvm : PHP_BINARY) . ($includeArgs ? ' ' . implode(' ', $this->findArguments()) : ''); } if (defined('PHP_BINARY') && PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server')) && is_file(PHP_BINARY)) { return PHP_BINARY; } if ($php = getenv('PHP_PATH')) { if (!is_executable($php)) { return false; } return $php; } if ($php = getenv('PHP_PEAR_PHP_BIN')) { if (is_executable($php)) { return $php; } } $dirs = array(PHP_BINDIR); if ('\\' === DIRECTORY_SEPARATOR) { $dirs[] = 'C:\\xampp\\php\\'; } return $this->executableFinder->find('php', false, $dirs); }
public function __construct($tool = null) { $this->tool = $tool ?: $this->tool; if (!is_file($this->tool) || !is_executable($this->tool)) { throw new ErrorException("Invalid ffmpeg tool location: {$this->tool}"); } }
protected function setUp() { parent::setUp(); if (!isset($_ENV['imagemagickConvertPath']) || !is_executable($_ENV['imagemagickConvertPath'])) { $this->markTestSkipped('Missing or mis-configured Imagemagick convert path.'); } }
/** * Try to locate the program * @param string $program * @return string * * @access protected */ function __exec($program) { // safe mode ? // if (!ini_get('safe_mode') || !($path = ini_get('safe_mode_exec_dir'))) { ($path = getenv('PATH')) || ($path = getenv('Path')); } $executable = false; $p = explode(PATH_SEPARATOR, $path); $p[] = getcwd(); $ext = array(); if (OS_WINDOWS) { $ext = getenv('PATHEXT') ? explode(PATH_SEPARATOR, getenv('PATHEXT')) : array('.exe', '.bat', '.cmd', '.com'); // extension ? // array_unshift($ext, ''); } // walk the variants // foreach ($ext as $e) { foreach ($p as $dir) { $exe = $dir . DIRECTORY_SEPARATOR . $program . $e; // *nix only implementation // if (OS_WINDOWS ? is_file($exe) : is_executable($exe)) { $executable = $exe; break; } } } return $executable; }
public function validate($input) { if ($input instanceof \SplFileInfo) { return $input->isExecutable(); } return is_string($input) && is_executable($input); }
/** * Constructor * * @param string command default NULL * @param string[] arguments default [] * @param string cwd default NULL the working directory * @param [:string] default NULL the environment * @throws io.IOException in case the command could not be executed */ public function __construct($command = NULL, $arguments = array(), $cwd = NULL, $env = NULL) { static $spec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')); // For `new self()` used in getProcessById() if (NULL === $command) { return; } // Check whether the given command is executable. $binary = self::resolve($command); if (!is_file($binary) || !is_executable($binary)) { throw new IOException('Command "' . $binary . '" is not an executable file'); } // Open process $cmd = CommandLine::forName(PHP_OS)->compose($binary, $arguments); if (!is_resource($this->_proc = proc_open($cmd, $spec, $pipes, $cwd, $env, array('bypass_shell' => TRUE)))) { throw new IOException('Could not execute "' . $cmd . '"'); } $this->status = proc_get_status($this->_proc); $this->status['exe'] = $binary; $this->status['arguments'] = $arguments; $this->status['owner'] = TRUE; // Assign in, out and err members $this->in = new File($pipes[0]); $this->out = new File($pipes[1]); $this->err = new File($pipes[2]); }