function start($args) { print_r($args); list($cmd, $this->repos, $this->rev, $this->email) = $args; if ($this->repos[0] == '/') { $this->repos = $this->repos = 'file://' . $this->repos; } $this->rev = (int) $this->rev; $last = $this->rev - 1; // techncially where the diff is!? require_once 'System.php'; $svn = System::which('svn', '/usr/bin/svn'); $cmd = "{$svn} diff -r{$last}:{$this->rev} {$this->repos}"; $this->log = svn_log($this->repos, $this->rev, $this->rev - 1, 0, SVN_DISCOVER_CHANGED_PATHS); $syntax = $this->checkSyntax(); //echo $cmd; $diff = `{$cmd}`; $diff = $this->log[0]['msg'] . "\n\n" . $diff; if ($syntax) { $diff = $syntax . "\n\n" . $diff; } $bits = explode('@', $this->email); $headers['From'] = "{$this->log[0]['author']} <{$this->log[0]['author']}@{$bits[1]}>"; $headers['To'] = $this->email; $headers['Subject'] = "[SVN {$bits[1]}] " . ($syntax ? "ERROR!" : "") . $this->getFilenames() . " ({$this->rev})"; $headers['Date'] = date('r'); $headers['X-Mailer'] = 'svn hook'; // Create the mail object using the Mail::factory method require_once 'Mail.php'; $mail_object =& Mail::factory('smtp', $params); $mail_object->send($this->email, $headers, $diff); $this->sendPopup($syntax); }
function EventGenerator_xte() { $xte = System::which('xte'); if ($xte !== false) { $this->xte = $xte; } else { echo "Couldn't find xte program!\r\nTests won't run!\r\n"; } }
/** * Constructor which tries to guess the paths of the tools */ function Net_Wifi() { //try to find the paths $iwconfig = System::which('iwconfig'); if ($iwconfig !== false) { $this->setPathIwconfig($iwconfig); } else { if (file_exists('/sbin/iwconfig')) { $this->setPathIwconfig('/sbin/iwconfig'); } } $iwlist = System::which('iwlist'); if ($iwlist !== false) { $this->setPathIwlist($iwlist); } else { if (file_exists('/sbin/iwlist')) { $this->setPathIwlist('/sbin/iwlist'); } } }
function start($cli = false, $mods = '', $overwrite = array()) { $ff = HTML_Flexyframework::get(); $this->scanModules(); //echo '<PRE>'; print_r($this->modtables); exit; $options =& PEAR::getStaticProperty('DB_DataObject', 'options'); $proj = 'pman'; //ucfirst(basename($options['database'])); // we are going to generate all of the code into a temporay foldler.. $user = posix_getpwuid(posix_getuid()); $options['rootDir'] = ini_get('session.save_path') . '/temp_' . $proj . '_' . $user['name']; $options['cli'] = $cli; $options['mods'] = empty($mods) ? array() : explode('/', $mods); if (!file_exists($options['rootDir'])) { mkdir($options['rootDir'], 0775, true); } $this->rootDir = $options['rootDir']; $options['schema_location'] = $this->rootDir . '/' . $proj . '/DataObjects'; $options['class_location'] = $this->rootDir . '/' . $proj . '/DataObjects'; $options['require_prefix'] = $proj . '/DataObjects/'; $options['class_prefix'] = $proj . '_DataObjects_'; $this->debug(print_r($options, true)); // print_r($this);exit; $standard_database = $options['database']; parent::start(); $this->scanModules(); require_once 'System.php'; $diff = System::which('diff'); // now for each of the directories copy/show diffs.. echo $cli ? '' : '<PRE>'; $flist = $overwrite; foreach ($this->modtables as $m => $ar) { if ($options['database'] != $standard_database) { $options['database'] = $standard_database; parent::start(); } $options['database'] = $standard_database; if (isset($options['database_' . $m])) { $options['database'] = $options['database_' . $m]; //var_dump($url);exit; // start again? parent::start(); } if (!empty($options['mods']) && !in_array($m, $options['mods'])) { continue; } // this happens when we have no database tables from a module, // but module code has been defined. if (!file_exists($options['rootDir'] . '/' . $m)) { continue; } foreach (scandir($options['rootDir'] . '/' . $m) as $f) { echo "SCAN {$options['rootDir']} {$f}\n"; if (!strlen($f) || $f[0] == '.') { continue; } // does it exist!!! $src = $options['rootDir'] . "/{$m}/{$f}"; $tg = $ff->page->rootDir . "/Pman/{$m}/DataObjects/{$f}"; if (preg_match('/\\.js$/', $f)) { $tg = $ff->page->rootDir . "/Pman/{$m}/{$f}"; } if (!file_exists($tg) || !filesize($tg)) { if ($cli && file_exists($tg) || in_array($f, $flist) || in_array('_all_', $flist)) { echo "COPY {$src} {$tg}" . ($cli ? "\n" : "<BR>"); copy($src, $tg); continue; } echo "!!!!MISSING!!! {$tg}" . ($cli ? "\n" : "<BR>"); continue; } // always copy readers and ini file.= nope - not on live.. if ($cli && in_array($f, $flist) || in_array('_all_', $flist)) { //|| $f=='pman.ini' || preg_match('/\.js$/', $f))) { echo "COPY {$src} {$tg}" . ($cli ? "\n" : "<BR>"); copy($src, $tg); continue; } // diff the two.. $cmd = "{$diff} -u -w " . escapeshellarg($tg) . ' ' . escapeshellarg($src); $out = array(); $ret = 0; exec($cmd, $out, $ret); if ($ret == 0) { // files match.. continue; } // var_dump($ret); echo "\n" . implode("\n", $out) . "\n"; } } }
public function testExecuteWithShortFormatOption() { $git = new VersionControl_Git('./fixtures/001_VersionControl_Git'); $i1 = new DummyGitCommand($git); $result = $i1->setSubCommand('log')->setOption('n', '1')->setOption('pretty', 'oneline')->setOption('grep', 'initial')->execute(); $this->assertEquals($i1->getCommandString(), @System::which('git') . ' log -n\'1\' --pretty=\'oneline\' --grep=\'initial\''); $this->assertEquals(trim($result), 'b8adc7214881bb71b9741b5d8228ebf346197d47 initial commit'); }
if (getenv('PHP_PEAR_CACHE_TTL')) { define('PEAR_CONFIG_DEFAULT_CACHE_TTL', getenv('PHP_PEAR_CACHE_TTL')); } else { define('PEAR_CONFIG_DEFAULT_CACHE_TTL', 3600); } // Default for sig_type if (getenv('PHP_PEAR_SIG_TYPE')) { define('PEAR_CONFIG_DEFAULT_SIG_TYPE', getenv('PHP_PEAR_SIG_TYPE')); } else { define('PEAR_CONFIG_DEFAULT_SIG_TYPE', 'gpg'); } // Default for sig_bin if (getenv('PHP_PEAR_SIG_BIN')) { define('PEAR_CONFIG_DEFAULT_SIG_BIN', getenv('PHP_PEAR_SIG_BIN')); } else { define('PEAR_CONFIG_DEFAULT_SIG_BIN', System::which('gpg', OS_WINDOWS ? 'c:\\gnupg\\gpg.exe' : '/usr/local/bin/gpg')); } // Default for sig_keydir if (getenv('PHP_PEAR_SIG_KEYDIR')) { define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR', getenv('PHP_PEAR_SIG_KEYDIR')); } else { define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR', PEAR_CONFIG_SYSCONFDIR . DIRECTORY_SEPARATOR . 'pearkeys'); } /** * This is a class for storing configuration data, keeping track of * which are system-defined, user-defined or defaulted. */ class PEAR_Config extends PEAR { // {{{ properties /**
/** * Image_Transform_Driver_NetPBM::_postProcess() * * @param $type * @param $quality * @return string A chain of shell command * @link http://netpbm.sourceforge.net/doc/directory.html */ function _postProcess($type, $quality) { array_unshift($this->command, $this->_prepare_cmd(IMAGE_TRANSFORM_NETPBM_PATH, strtolower($this->type) . 'topnm', escapeshellarg($this->image))); $arg = ''; $type = strtolower($type); $program = ''; switch ($type) { // ppmto* converters case 'gif': if (!System::which(IMAGE_TRANSFORM_NETPBM_PATH . 'ppmquant' . (OS_WINDOWS ? '.exe' : ''))) { return PEAR::raiseError('Couldn\'t find "ppmquant" binary', IMAGE_TRANSFORM_ERROR_UNSUPPORTED); } $this->command[] = $this->_prepare_cmd(IMAGE_TRANSFORM_NETPBM_PATH, 'ppmquant', 256); case 'acad': case 'bmp': case 'eyuv': case 'ilbm': case 'leaf': case 'lj': case 'mitsu': case 'mpeg': case 'neo': case 'pcx': case 'pi1': case 'pict': case 'pj': case 'pjxl': case 'puzz': case 'sixel': case 'tga': case 'uil': case 'xpm': case 'yuv': $program = 'ppmto' . $type; break; // Windows icon // Windows icon case 'winicon': case 'ico': $type = 'winicon'; $program = 'ppmto' . $type; break; // pbmto* converters // pbmto* converters case 'ascii': case 'text': case 'txt': $type = 'ascii'; case 'atk': case 'bbubg': case 'epsi': case 'epson': case 'escp2': case 'icon': // Sun icon // Sun icon case 'gem': case 'go': case 'lj': case 'ln03': case 'lps': case 'macp': case 'mda': case 'mgr': case 'pi3': case 'pk': case 'plot': case 'ptx': case 'wbp': case 'xbm': case 'x10bm': case 'ybm': case 'zinc': case '10x': $program = 'pbmto' . $type; break; // pamto* converters // pamto* converters case 'jpc': $type = 'jpeg2k'; case 'html': case 'pfm': case 'tga': $program = 'pamto' . $type; break; // pnmto* converters // pnmto* converters case 'jpc': $type = 'jpeg2k'; break; case 'wfa': $type = 'fiasco'; break; case 'jpg': $type = 'jpeg'; case 'jpeg': $arg = '--quality=' . $quality; case 'jbig': case 'fits': case 'palm': case 'pclxl': case 'png': case 'ps': case 'rast': case 'rle': case 'sgi': case 'sir': case 'tiff': case 'xwd': $program = 'pnmto' . $type; break; } // switch if ($program == '') { $program = 'pnmto' . $type; } if (!System::which(IMAGE_TRANSFORM_NETPBM_PATH . $program . (OS_WINDOWS ? '.exe' : ''))) { return PEAR::raiseError("Couldn't find \"{$program}\" binary", IMAGE_TRANSFORM_ERROR_UNSUPPORTED); } $this->command[] = $this->_prepare_cmd(IMAGE_TRANSFORM_NETPBM_PATH, $program); return implode('|', $this->command); }
/** * Functionality similiar to unix 'which'. Searches the path * for the specified program. * * @param $cmd name of the executable to search for * * @access private * @return string returns the full path if found, false if not */ function which($in_cmd) { // only pass non-empty strings to System::which() if (!is_string($in_cmd) || '' === $in_cmd) { return false; } // explicitly pass false as fallback value return System::which($in_cmd, false); }
/** * Image_Transform_Driver_IM::_get_image_details() * * @param string $image the path and name of the image file * @return none */ function _get_image_details($image) { $retval = Image_Transform::_get_image_details($image); if (PEAR::isError($retval)) { unset($retval); if (!System::which(IMAGE_TRANSFORM_IM_PATH . 'identify' . (OS_WINDOWS ? '.exe' : ''))) { $this->isError(PEAR::raiseError('Couldn\'t find "identify" binary', IMAGE_TRANSFORM_ERROR_UNSUPPORTED)); } $cmd = $this->_prepare_cmd(IMAGE_TRANSFORM_IM_PATH, 'identify', '-format %w:%h:%m ' . escapeshellarg($image)); exec($cmd, $res, $exit); if ($exit == 0) { $data = explode(':', $res[0]); $this->img_x = $data[0]; $this->img_y = $data[1]; $this->type = strtolower($data[2]); $retval = true; } else { return PEAR::raiseError("Cannot fetch image or images details.", true); } } return $retval; }
if (getenv('PHP_PEAR_CACHE_TTL')) { define('PEAR_CONFIG_DEFAULT_CACHE_TTL', getenv('PHP_PEAR_CACHE_TTL')); } else { define('PEAR_CONFIG_DEFAULT_CACHE_TTL', 3600); } // Default for sig_type if (getenv('PHP_PEAR_SIG_TYPE')) { define('PEAR_CONFIG_DEFAULT_SIG_TYPE', getenv('PHP_PEAR_SIG_TYPE')); } else { define('PEAR_CONFIG_DEFAULT_SIG_TYPE', 'gpg'); } // Default for sig_bin if (getenv('PHP_PEAR_SIG_BIN')) { define('PEAR_CONFIG_DEFAULT_SIG_BIN', getenv('PHP_PEAR_SIG_BIN')); } else { define('PEAR_CONFIG_DEFAULT_SIG_BIN', System::which('gpg', OS_WINDOWS ? 'c:\\apache2triadpath\\php\\bin\\gpg.exe' : '/usr/local/bin/gpg')); } // Default for sig_keydir if (getenv('PHP_PEAR_SIG_KEYDIR')) { define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR', getenv('PHP_PEAR_SIG_KEYDIR')); } else { define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR', PEAR_CONFIG_SYSCONFDIR . DIRECTORY_SEPARATOR . 'pearkeys'); } /** * This is a class for storing configuration data, keeping track of * which are system-defined, user-defined or defaulted. */ class PEAR_Config extends PEAR { // {{{ properties /**
function build($proj) { echo "Building {$proj}\n"; // var_dump($proj); if (empty($proj)) { $this->err = "no project"; if ($this->cli) { echo $this->err; } return; } // first item in path is always the app start directory.. $src = array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) . '/Pman/' . $proj; //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src); require_once 'System.php'; $seed = System::which('seed'); if (!$seed) { $this->err = "no seed installed"; if ($this->cli) { echo $this->err; } return false; } $o = HTML_FlexyFramework::get()->Pman_Core; if (empty($o['packseed']) || !file_exists($o['packseed'] . '/pack.js')) { $this->err = "no jstoolkit path set [Pman_Core][packseed] to the\n introspection documentation directory where pack.js is located."; if ($this->cli) { echo $this->err; } return false; } // should we be more specirfic!??!?!? $cmd = "{$seed} {$o['packseed']}/pack.js -m {$proj} -a {$src}/*.js"; echo "{$cmd}\n"; passthru($cmd); // technically we should trash old compiled files.. // or we move towards a 'cache in session directory model..' /* $ret = $tmp . '/'. $proj . '.js'; if ($this->cli) { echo "BUILT: $ret \n"; exit; } return $ret; */ }
/** * Get the location to git binary * * @return string */ public function getGitCommandPath() { // Guess path to git binary if (!$this->gitCommandPath) { $this->gitCommandPath = @System::which('git'); if (!$this->gitCommandPath) { $message = 'Guessing path to git binary is failed.' . ' You must specify path to git binary yourself.'; throw new VersionControl_Git_Exception($message); } } return $this->gitCommandPath; }
public function testSetGitCommandPath() { $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git'); $this->assertEquals($instance->getGitCommandPath(), @System::which('git')); $instance->setGitCommandPath('/usr/local/bin/git'); $this->assertEquals($instance->getGitCommandPath(), '/usr/local/bin/git'); }
define('PEAR_CONFIG_DEFAULT_CACHE_TTL', 3600); } // Default for sig_type if (getenv('PHP_PEAR_SIG_TYPE')) { define('PEAR_CONFIG_DEFAULT_SIG_TYPE', getenv('PHP_PEAR_SIG_TYPE')); } else { define('PEAR_CONFIG_DEFAULT_SIG_TYPE', 'gpg'); } // Default for sig_bin if (getenv('PHP_PEAR_SIG_BIN')) { define('PEAR_CONFIG_DEFAULT_SIG_BIN', getenv('PHP_PEAR_SIG_BIN')); } else { define('PEAR_CONFIG_DEFAULT_SIG_BIN', System::which( 'gpg', OS_WINDOWS ? 'c:\gnupg\gpg.exe' : '/usr/local/bin/gpg')); } // Default for sig_keydir if (getenv('PHP_PEAR_SIG_KEYDIR')) { define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR', getenv('PHP_PEAR_SIG_KEYDIR')); } else { define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR', PEAR_CONFIG_SYSCONFDIR . DIRECTORY_SEPARATOR . 'pearkeys'); } /** * This is a class for storing configuration data, keeping track of * which are system-defined, user-defined or defaulted. * @category pear * @package PEAR
function createBase() { require_once 'System.php'; $iptables = System::which('iptables', '/sbin/iptables'); if (!$iptables || !file_exists($iptables)) { $this->jerr("iptables could not be found."); } //$this->exec("{$iptables} -F postgres"); // flush old $this->exec("{$iptables} -X postgres"); // flush old $this->exec("{$iptables} -N postgres"); // create new.. $this->exec($iptables . ' -A postgres -m limit --limit 2/min -j LOG ' . '--log-prefix "IPTables-Dropped: " --log-level 4'); $this->exec("{$iptables} -A postgres -j DROP"); }
/** * Run the command with the defined switches. * * @param array $args Arguments to pass to Subversion * @param array $switches Switches to pass to Subversion * * @return mixed $fetchmode specified output on success. * @throws VersionControl_SVN_Exception If command failed. */ public function run($args = array(), $switches = array()) { if ($this->svn_path != '') { $this->binaryPath = $this->svn_path; } if (!file_exists($this->binaryPath)) { $system = new System(); $this->binaryPath = $system->which('svn'); } if (sizeof($switches) > 0) { $this->switches = $switches; } if (sizeof($args) > 0) { foreach (array_keys($args) as $k) { $this->args[$k] = escapeshellarg($args[$k]); } } // Always prepare, allows for obj re-use. (Request #5021) $this->prepare(); $out = array(); // @var integer $returnVar Return number from shell execution. $returnVar = null; $cmd = $this->preparedCmd; // On Windows, don't use escapeshellcmd, and double-quote $cmd // so it's executed as // cmd /c ""C:\Program Files\SVN\bin\svn.exe" info "C:\Program Files\dev\trunk"" if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $cmd = str_replace($this->binaryPath, escapeshellarg(str_replace('/', '\\', $this->binaryPath)), $cmd); if (!$this->passthru) { exec("cmd /c \"{$cmd} 2>&1\"", $out, $returnVar); } else { passthru("cmd /c \"{$cmd} 2>&1\"", $returnVar); } } else { if ($this->useEscapeshellcmd) { $cmd = escapeshellcmd($cmd); } if (!$this->passthru) { exec("{$this->prependCmd}{$cmd} 2>&1", $out, $returnVar); } else { passthru("{$this->prependCmd}{$cmd} 2>&1", $returnVar); } } if ($returnVar > 0) { throw new VersionControl_SVN_Exception('Execution of command failed returning: ' . $returnVar . "\n" . implode("\n", $out), VersionControl_SVN_Exception::EXEC); } return $this->parseOutput($out); }
function finishInstall() { $sep = OS_WINDOWS ? ';' : ':'; $include_path = explode($sep, ini_get('include_path')); if (OS_WINDOWS) { $found = false; $t = strtolower($this->php_dir); foreach ($include_path as $path) { if ($t == strtolower($path)) { $found = true; break; } } } else { $found = in_array($this->php_dir, $include_path); } if (!$found) { print "\r\n******************************************************************************\r\nWARNING! The include_path defined in the currently used php.ini does not\r\ncontain the PEAR PHP directory you just specified:\r\n<{$this->php_dir}>\r\nIf the specified directory is also not in the include_path used by\r\nyour scripts, you will have problems getting any PEAR packages working.\r\n"; if ($php_ini = $this->getPhpiniPath()) { print "\n\nWould you like to alter php.ini <{$php_ini}>? [Y/n] : "; $alter_phpini = !stristr(fgets($this->tty, 1024), "n"); if ($alter_phpini) { $this->alterPhpIni($php_ini); } else { if (OS_WINDOWS) { print "\r\nPlease look over your php.ini file to make sure\r\n{$this->php_dir} is in your include_path."; } else { print "\r\nI will add a workaround for this in the 'pear' command to make sure\r\nthe installer works, but please look over your php.ini or Apache\r\nconfiguration to make sure {$this->php_dir} is in your include_path.\r\n"; } } } print "\r\nCurrent include path : " . ini_get('include_path') . "\r\nConfigured directory : {$this->php_dir}\r\nCurrently used php.ini (guess) : {$php_ini}\r\n"; print "Press Enter to continue: "; fgets($this->tty, 1024); } $pear_cmd = $this->bin_dir . DIRECTORY_SEPARATOR . 'pear'; $pear_cmd = OS_WINDOWS ? strtolower($pear_cmd) . '.bat' : $pear_cmd; // check that the installed pear and the one in the path are the same (if any) $pear_old = System::which(OS_WINDOWS ? 'pear.bat' : 'pear', $this->bin_dir); if ($pear_old && $pear_old != $pear_cmd) { // check if it is a link or symlink $islink = OS_WINDOWS ? false : is_link($pear_old); if ($islink && readlink($pear_old) != $pear_cmd) { print "\n** WARNING! The link {$pear_old} does not point to the " . "installed {$pear_cmd}\n"; } elseif (!$this->localInstall && is_writable($pear_old) && !is_dir($pear_old)) { rename($pear_old, "{$pear_old}_old"); print "\n** WARNING! Backed up old pear to {$pear_old}_old\n"; } else { print "\n** WARNING! Old version found at {$pear_old}, please remove it or " . "be sure to use the new {$pear_cmd} command\n"; } } print "\nThe 'pear' command is now at your service at {$pear_cmd}\n"; // Alert the user if the pear cmd is not in PATH $old_dir = $pear_old ? dirname($pear_old) : false; if (!$this->which('pear', $old_dir)) { print "\r\n** The 'pear' command is not currently in your PATH, so you need to\r\n** use '{$pear_cmd}' until you have added\r\n** '{$this->bin_dir}' to your PATH environment variable.\r\n\r\n"; print "Run it without parameters to see the available actions, try 'pear list'\r\nto see what packages are installed, or 'pear help' for help.\r\n\r\nFor more information about PEAR, see:\r\n\r\n http://pear.php.net/faq.php\r\n http://pear.php.net/manual/\r\n\r\nThanks for using go-pear!\r\n\r\n"; } if (OS_WINDOWS && !$this->localInstall) { $this->win32CreateRegEnv(); } }
function gitCommitDelete($file) { $gd = $this->gitDir(); if (!$gd) { return false; } $working = $this->gitWorking($gd['url']); $path = strlen($gd['path']) ? $gd['path'] . '/' : ''; $target = $working . '/' . $path . $file; //var_dump($target);exit; if (!file_exists($target)) { return; // no need to do anything.. } require_once 'System.php'; $git = System::which('git'); chdir($working); `{$git} rm {$path}{$file}`; $cmd = "{$git} commit -m '{$path}{$file} - Commit (DELETE) from online editor' "; `{$cmd}`; `git push`; }
function convertStyle($url, $file, $is_url = true) { $inLineCss = true; if ($is_url && !empty($url)) { $host = parse_url($url); require_once 'System.php'; $wget = System::which('wget'); if (!$wget) { $this->jerr("no wget"); } $cmd = $wget . ' -q -O - ' . escapeshellarg($url); //echo $cmd; exit; $data = `{$cmd}`; if (!trim(strlen($data))) { $this->jerr("url returned an empty string"); } } if (!$is_url) { $data = file_get_contents($file); } if (preg_match('/^\\s*<!--\\s*NOT CONVERT STYLE\\s*-->\\s*/', $data)) { $inLineCss = false; } libxml_use_internal_errors(true); $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadHTML('<?xml encoding="UTF-8">' . $data); $doc->formatOutput = true; $xpath = new DOMXpath($doc); foreach ($xpath->query('//img[@src]') as $img) { $href = $img->getAttribute('src'); if (!preg_match("/^http(.*)\$/", $href, $matches)) { if (!empty($url)) { $img->setAttribute('src', $this->relPath($url, $href)); continue; } $this->jerr('Please use the absolutely url for image src!'); } } foreach ($xpath->query('//a[@href]') as $a) { $href = $a->getAttribute('href'); if (!preg_match("/^http|mailto|#(.*)\$/", $href, $matches)) { if (!empty($url)) { $a->setAttribute('href', $this->relPath($url, $href)); continue; } $this->jerr('Please use the absolutely url for a href!'); } } foreach ($xpath->query('//link[@href]') as $l) { if ($l->getAttribute('rel') == 'stylesheet') { $href = $l->getAttribute('href'); if (!preg_match("/^http(.*)\$/", $href, $matches)) { if (empty($url)) { $this->jerr('Please use the absolutely url for link href!'); } $href = $this->relPath($url, $href); } $this->styleSheets[$href] = $this->replaceImageUrl(file_get_contents($href), $href); } } foreach ($xpath->query('//style') as $s) { $this->styleSheets[] = $this->replaceImageUrl($s->nodeValue, $url); } $data = $doc->saveHTML(); if (!$inLineCss) { return $data; } $htmldoc = new HTML_CSS_InlineStyle($data); if (count($this->styleSheets) > 0) { foreach ($this->styleSheets as $styleSheet) { $htmldoc->applyStylesheet($styleSheet); } } $html = $htmldoc->getHTML(); libxml_use_internal_errors(false); if (!function_exists('tidy_repair_string')) { return "INSTALL TIDY ON SERVER " . $html; } $html = tidy_repair_string($html, array('indent' => TRUE, 'output-xhtml' => TRUE, 'wrap' => 120), 'UTF8'); return $html; }
function checkSystem() { // most of these are from File_Convert... // these are required - and have simple dependancies. require_once 'System.php'; $req = array('convert', 'grep', 'pdfinfo', 'pdftoppm', 'rsvg-convert', 'strings'); // these are prefered - but may have complicated depenacies $pref = array('abiword', 'faad', 'ffmpeg', 'html2text', 'pdftocairo', 'lame', 'ssconvert', 'unoconv', 'wkhtmltopdf', 'xvfb-run'); $res = array(); $fail = false; foreach ($req as $r) { if (!System::which($r)) { $res[] = $r; } $fail = true; } if ($res) { $this->jerr("Missing these programs - need installing\n" . implode("\n", $res)); } foreach ($pref as $r) { if (!System::which($r)) { $res[] = $r; } $fail = true; } if ($res) { echo "WARNING: Missing these programs - they may need installing\n" . implode("\n", $res); sleep(5); } }
/** * Checks if the specified tool binary exists and returns the full path. * * @param string $file Binary file to check. * * @throws Net_SSH2_Exception If the specified SSH2 binary tool was not found. * @return void */ private function _getBinaryPath($file) { //Check for ssh binary if (array_key_exists('ssh2_binary_path', $this->options)) { $ssh2_binary = escapeshellarg(File::buildpath(array($options['ssh2_binary_path'], $file))); } else { $ssh2_binary = System::which($file); } if (!is_file($ssh2_binary)) { throw new Net_SSH2_Exception(Net_SSH2::getMessage(SSH2_BINARY_NOT_FOUND, $file)); } return $ssh2_binary; }
/** * Load the paths of required tools: rst2confluence and confluence-cli * * @return void * * @throws Exception When one of the tools cannot be found */ public function loadTools() { error_reporting(error_reporting() & ~E_STRICT); include_once 'System.php'; if (!class_exists('System')) { throw new Exception('Could not find PEAR\'s "System" class', 10); } $this->cmd['rst2c'] = \System::which('rst2confluence'); if ($this->cmd['rst2c'] === false) { throw new Exception('rst2confluence not found', 11); } $this->cmd['cflcli'] = \System::which('confluence-cli'); if ($this->cmd['cflcli'] === false) { throw new Exception('confluence-cli not found', 12); } }
function importSQL() { $options =& PEAR::getStaticProperty('DB_DataObject', 'options'); $ff = HTML_Flexyframework::get(); $url = parse_url($options['database']); // hide stuff for web.. $cli = $options['cli']; if (!$cli) { $url['pass'] = '******'; $url['user'] = '******'; $url['host'] = '*****'; } require_once 'System.php'; $cat = System::which('cat'); $mysql = System::which('mysql'); //print_r($ff); //print_r($options['mods'] ); foreach ($this->modsql as $m => $fl) { if ($cli && isset($options['database_' . $m])) { $url = parse_url($options['database_' . $m]); } $mysql_cmd = $mysql . ' -h ' . $url['host'] . ' -u' . escapeshellarg($url['user']) . (!empty($url['pass']) ? ' -p' . escapeshellarg($url['pass']) : '') . ' ' . basename($url['path']); echo $mysql_cmd . "\n"; if (!empty($options['mods']) && !in_array($m, $options['mods'])) { continue; } foreach ($fl as $f) { $fn = $ff->page->rootDir . "/Pman/{$m}/DataObjects/{$f}"; $cmd = $cat . ' ' . escapeshellarg($fn) . " | {$mysql_cmd} -f "; echo $cmd . ($cli ? "\n" : "<BR>\n"); if ($cli) { passthru($cmd); } } } }
/** * Creates a new Nmap object * * Available options are: * * - string nmap_binary: The location of the Nmap binary. * If not specified, defaults to '/usr/bin/nmap'. * * - string output_file: Path to store the Nmap XML output file. * If not specified, a temporary file is created. * * @param array $options optional. An array of options used to create the * Nmap object. All options must be optional and are * represented as key-value pairs. */ public function __construct(array $options = array()) { if (array_key_exists('nmap_binary', $options)) { $this->_nmap_binary = (string) $options['nmap_binary']; } else { $this->_nmap_binary = System::which('nmap'); } if (array_key_exists('output_file', $options)) { $this->_output_file = (string) $options['output_file']; } }
/** * Check the list of required files * * @return string The HTML output. */ public function requiredFileCheck() { $php = System::which('php', null); $output = is_null($php) ? '<p style="color:orange">Cannot find PHP command-line binary on your system. Syntax checking of configuration files is disabled.</p>' : ''; ksort($this->_fileList); return $output . $this->_requiredFileCheck($this->_fileList, $php); }
/** * Our main execution of the task. * * @throws BuildException * @throws Exception * * @access public * @return void */ public function main() { if ($this->useSass) { if (strlen($this->executable) < 0) { throw new BuildException("'executable' must be defined."); } } if (empty($this->filesets) && $this->file === null) { throw new BuildException("Missing either a nested fileset or attribute 'file'"); } // If both are set to be used, prefer sass over scssphp. $lUseScssphp = false; if ($this->useSass && $this->useScssphp) { if (System::which($this->executable) === false) { if ($this->loadScssphp() === false) { $msg = sprintf("%s not found. Install sass or leafo scssphp.", $this->executable); if ($this->failonerror) { throw new BuildException($msg); } else { $this->log($msg, Project::MSG_ERR); return; } } else { $lUseScssphp = true; $this->scssCompiler = $this->initialiseScssphp(); } } } elseif (!$this->useSass && !$this->useScssphp) { $this->log("Neither sass nor scssphp are to be used.", Project::MSG_ERR); return; } elseif ($this->useSass) { if (System::which($this->executable) === false) { $msg = sprintf("%s not found. Install sass.", $this->executable); if ($this->failonerror) { throw new BuildException($msg); } else { $this->log($msg, Project::MSG_ERR); return; } } } elseif ($this->useScssphp) { if ($this->loadScssphp() === false) { $msg = sprintf("Install leafo scssphp."); if ($this->failonerror) { throw new BuildException($msg); } else { $this->log($msg, Project::MSG_ERR); return; } } else { $lUseScssphp = true; $this->scssCompiler = $this->initialiseScssphp(); } } if (count($this->filesets) > 0) { $this->processFilesets($lUseScssphp); } elseif ($this->file !== null) { $this->processFile($lUseScssphp); } }
function build($proj) { echo "Building {$proj}\n"; // var_dump($proj); if (empty($proj)) { $this->err = "no project"; if ($this->cli) { echo $this->err; } return; } $src = realpath(dirname(__FILE__) . '/../' . $proj); if (!file_exists(dirname(__FILE__) . '/../../_compiled_tmp_/' . $proj)) { mkdir(dirname(__FILE__) . '/../../_compiled_tmp_/' . $proj, 0755, true); } $tmp = realpath(dirname(__FILE__) . '/../../_compiled_tmp_'); //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src); require_once 'System.php'; $roolite = System::which('roolite'); $svn = System::which('svn'); if (!$roolite) { $this->err = "no roolite"; if ($this->cli) { echo $this->err; } return false; } $o = PEAR::getStaticProperty('Pman_Builder', 'options'); if (empty($o['jstoolkit'])) { $this->err = "no jstoolkit path"; if ($this->cli) { echo $this->err; } return false; } // should we be more specirfic!??!?!? $buildjs = realpath(dirname(__FILE__) . '/jsbuilder/build.js'); $cmd = "{$roolite} {$buildjs} -L{$o['jstoolkit']} -- " . escapeshellarg($src) . " " . escapeshellarg($tmp); passthru($cmd); // copy into the revision controlled area. $src = realpath(dirname(__FILE__) . '/../../_compiled_tmp_/' . $proj . '.js'); if (!$src) { return; } $pdir = realpath(dirname(__FILE__) . '/../' . $proj); if (!file_exists($pdir . '/compiled')) { mkdir($pdir . '/compiled', 0755, true); } copy($src, $pdir . '/compiled/' . $proj . '.js'); // copy the translation strings. $src = realpath(dirname(__FILE__) . '/../../_compiled_tmp_/' . $proj . '/build/_translation_.js'); // var_dump($src); $pdir = realpath(dirname(__FILE__) . '/../' . $proj); copy($src, $pdir . '/compiled/_translation_.js'); if ($svn) { $base = getcwd(); chdir($pdir); $cmd = "{$svn} add compiled"; `{$cmd}`; $cmd = "{$svn} add " . escapeshellarg('compiled/' . $proj . '.js'); $cmd = "{$svn} add " . escapeshellarg('compiled/_translation_.js'); `{$cmd}`; `{$svn} commit -m 'update compiled version'`; chdir($base); } /* $ret = $tmp . '/'. $proj . '.js'; if ($this->cli) { echo "BUILT: $ret \n"; exit; } return $ret; */ }
function __construct() { parent::__construct(); if (OS_WINDOWS) { $this->configPrompt['php_bin'] = 'Path to CLI php.exe'; $this->config[] = 'php_bin'; $this->prefix = getcwd(); if (!@is_dir($this->prefix)) { if (@is_dir('c:\\php5')) { $this->prefix = 'c:\\php5'; } elseif (@is_dir('c:\\php4')) { $this->prefix = 'c:\\php4'; } elseif (@is_dir('c:\\php')) { $this->prefix = 'c:\\php'; } } $slash = "\\"; if (strrpos($this->prefix, '\\') === strlen($this->prefix) - 1) { $slash = ''; } $this->localInstall = false; $this->bin_dir = '$prefix'; $this->temp_dir = '$prefix' . $slash . 'tmp'; $this->download_dir = '$prefix' . $slash . 'tmp'; $this->php_dir = '$prefix' . $slash . 'pear'; $this->doc_dir = '$prefix' . $slash . 'docs'; $this->data_dir = '$prefix' . $slash . 'data'; $this->test_dir = '$prefix' . $slash . 'tests'; $this->www_dir = '$prefix' . $slash . 'www'; $this->man_dir = '$prefix' . $slash . 'man'; $this->cfg_dir = '$prefix' . $slash . 'cfg'; $this->pear_conf = PEAR_CONFIG_SYSCONFDIR . '\\pear.ini'; /* * Detects php.exe */ $this->validPHPBin = true; if ($t = $this->safeGetenv('PHP_PEAR_PHP_BIN')) { $this->php_bin = dirname($t); } elseif ($t = $this->safeGetenv('PHP_BIN')) { $this->php_bin = dirname($t); } elseif ($t = System::which('php')) { $this->php_bin = dirname($t); } elseif (is_file($this->prefix . '\\cli\\php.exe')) { $this->php_bin = $this->prefix . '\\cli'; } elseif (is_file($this->prefix . '\\php.exe')) { $this->php_bin = $this->prefix; } $phpexe = OS_WINDOWS ? '\\php.exe' : '/php'; if ($this->php_bin && !is_file($this->php_bin . $phpexe)) { $this->php_bin = ''; } else { if (strpos($this->php_bin, ':') === 0) { $this->php_bin = getcwd() . DIRECTORY_SEPARATOR . $this->php_bin; } } if (!is_file($this->php_bin . $phpexe)) { if (is_file('c:/php/cli/php.exe')) { $this->php_bin = 'c"\\php\\cli'; } elseif (is_file('c:/php5/php.exe')) { $this->php_bin = 'c:\\php5'; } elseif (is_file('c:/php4/cli/php.exe')) { $this->php_bin = 'c:\\php4\\cli'; } else { $this->validPHPBin = false; } } } else { $this->prefix = dirname(PHP_BINDIR); $this->pear_conf = PEAR_CONFIG_SYSCONFDIR . '/pear.conf'; if ($this->getCurrentUser() != 'root') { $this->prefix = $this->safeGetenv('HOME') . '/pear'; $this->pear_conf = $this->safeGetenv('HOME') . '.pearrc'; } $this->bin_dir = '$prefix/bin'; $this->php_dir = '$prefix/share/pear'; $this->temp_dir = '/tmp/pear/install'; $this->download_dir = '/tmp/pear/install'; $this->doc_dir = '$prefix/docs'; $this->www_dir = '$prefix/www'; $this->cfg_dir = '$prefix/cfg'; $this->data_dir = '$prefix/data'; $this->test_dir = '$prefix/tests'; $this->man_dir = '$prefix/man'; // check if the user has installed PHP with PHP or GNU layout if (@is_dir("{$this->prefix}/lib/php/.registry")) { $this->php_dir = '$prefix/lib/php'; } elseif (@is_dir("{$this->prefix}/share/pear/lib/.registry")) { $this->php_dir = '$prefix/share/pear/lib'; $this->doc_dir = '$prefix/share/pear/docs'; $this->data_dir = '$prefix/share/pear/data'; $this->test_dir = '$prefix/share/pear/tests'; } elseif (@is_dir("{$this->prefix}/share/php/.registry")) { $this->php_dir = '$prefix/share/php'; } } }
/** * The setter for the attribute "toolpath" * * @param $path * * @throws BuildException * @internal param string $param Full path to tool path, i.e. /usr/local/bin/rst2html * * @return void * */ public function setToolpath($path) { if (!file_exists($path)) { $fullpath = System::which($path); if ($fullpath === false) { throw new BuildException('Tool does not exist. Path: ' . $path); } $path = $fullpath; } if (!is_executable($path)) { throw new BuildException('Tool not executable. Path: ' . $path); } $this->toolPath = $path; }
/** * Functionality similiar to unix 'which'. Searches the path * for the specified program. * * @param $cmd name of the executable to search for * * @access private * @return string returns the full path if found, false if not */ function which($in_cmd) { return System::which($in_cmd); }