Example #1
1
 public function index()
 {
     $os = explode(' ', php_uname());
     $mysql_support = function_exists('mysql_close') ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $register_globals = get_cfg_var("register_globals") ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $enable_dl = get_cfg_var("enable_dl") ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $allow_url_fopen = get_cfg_var("allow_url_fopen") ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $display_errors = get_cfg_var("display_errors") ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $session_support = function_exists('session_start') ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $config['server_name'] = $_SERVER['SERVER_NAME'];
     $config['server_ip'] = @gethostbyname($_SERVER['SERVER_NAME']);
     $config['server_time'] = date("Y年n月j日 H:i:s");
     $config['os'] = $os[0];
     $config['os_core'] = $os[2];
     $config['server_root'] = dirname(dirname($_SERVER['SCRIPT_FILENAME']));
     $config['server_engine'] = $_SERVER['SERVER_SOFTWARE'];
     $config['server_port'] = $_SERVER['SERVER_PORT'];
     $config['php_version'] = PHP_VERSION;
     $config['php_run_type'] = strtoupper(php_sapi_name());
     $config['mysql_support'] = $mysql_support;
     $config['register_globals'] = $register_globals;
     $config['allow_url_fopen'] = $allow_url_fopen;
     $config['display_errors'] = $display_errors;
     $config['enable_dl'] = $enable_dl;
     $config['memory_limit'] = get_cfg_var("memory_limit");
     $config['post_max_size'] = get_cfg_var("post_max_size");
     $config['upload_max_filesize'] = get_cfg_var("upload_max_filesize");
     $config['max_execution_time'] = get_cfg_var("max_execution_time");
     $config['session_support'] = $session_support;
     $this->config_arr = $config;
     $this->display();
 }
Example #2
0
/**
 * 服务器负载保护函数,本方法目前不支持window系统
 *
 * 最大负载不要超过3*N核,例如有16核(含8核超线程)则 16*3=48
 *
 * @see http://php.net/manual/en/function.sys-getloadavg.php
 */
function _load_protection($max_load_avg = 24)
{
    global $dir_log, $dir_wwwroot;
    if (!function_exists('sys_getloadavg')) {
        return false;
    }
    $load = sys_getloadavg();
    if (!isset($load[0])) {
        return false;
    }
    if ($load[0] <= $max_load_avg) {
        // 未超过负载,则跳出
        return false;
    }
    $msg_tpl = "[%s] HOST:%s LOAD:%s ARGV/URI:%s\n";
    $time = @date(DATE_RFC2822);
    $host = php_uname('n');
    $load = sprintf('%.2f', $load[0]);
    if (php_sapi_name() == "cli" || empty($_SERVER['PHP_SELF'])) {
        $argv_or_uri = implode(',', $argv);
    } else {
        $argv_or_uri = $_SERVER['REQUEST_URI'];
    }
    $msg = sprintf($msg_tpl, $time, $host, $load, $argv_or_uri);
    if (@is_dir($dir_log)) {
        @file_put_contents($dir_log . "php-server-overload.log", $msg, FILE_APPEND);
    }
    # exit with 500 page
    header("HTTP/1.1 500 Internal Server Error");
    header("Expires: " . gmdate("D, d M Y H:i:s", time() - 99999) . " GMT");
    header("Cache-Control: private");
    header("Pragma: no-cache");
    exit(file_get_contents($dir_wwwroot . 'errors/server_overload.html'));
}
Example #3
0
	/**
	 * Default mailer.
	 * @param  string
	 * @param  string
	 * @return void
	 */
	public static function defaultMailer($message, $email)
	{
		$host = php_uname('n');
		foreach (array('HTTP_HOST','SERVER_NAME', 'HOSTNAME') as $item) {
			if (isset($_SERVER[$item])) {
				$host = $_SERVER[$item]; break;
			}
		}

		$parts = str_replace(
			array("\r\n", "\n"),
			array("\n", PHP_EOL),
			array(
				'headers' => implode("\n", array(
					"From: noreply@$host",
					'X-Mailer: Nette Framework',
					'Content-Type: text/plain; charset=UTF-8',
					'Content-Transfer-Encoding: 8bit',
				)) . "\n",
				'subject' => "PHP: An error occurred on the server $host",
				'body' => "[" . @date('Y-m-d H:i:s') . "] $message", // @ - timezone may not be set
			)
		);

		mail($email, $parts['subject'], $parts['body'], $parts['headers']);
	}
 function __construct($file, $width, $height, $mode = auto, $format = 'png')
 {
     $is_Windows = strtoupper(substr(php_uname('s'), 0, 3)) == 'WIN';
     $slash = $is_Windows ? '\\' : '/';
     $this->info = getimagesize($file);
     if (!is_array($this->info)) {
         return;
     }
     $this->src = $this->open($file);
     // echo '<pre>';
     // var_export($this->info);
     // echo '</pre>';
     $this->options = get_option('wpUI_options');
     if (!isset($this->options) || !isset($this->options['enable_cache'])) {
         return;
     }
     $this->width = imagesx($this->src);
     $this->height = imagesy($this->src);
     if ($this->width / $this->height != 1) {
         $mode = 'crop';
     }
     $filestr = md5(str_replace($slash, '', strrchr($file, $slash)) . '_' . $width . '_' . $height . '_' . $mode);
     $cachedir = wpui_adjust_path(WP_CONTENT_DIR . '/uploads/wp-ui/cache/');
     is_dir($cachedir) || @mkdir($cachedir, 0755, true);
     $storestr = $cachedir . $filestr . '.' . $format;
     if (file_exists($storestr)) {
         $this->output($storestr, $format);
     } else {
         $this->resize($width, $height, $mode);
         $this->save($storestr, 100, $format);
         $this->output($storestr, $format);
     }
 }
Example #5
0
 /**
  * @return string
  */
 public static function getHostname()
 {
     if (!isset(self::$hostname)) {
         self::$hostname = gethostname() ?: php_uname('n');
     }
     return self::$hostname;
 }
Example #6
0
 function __construct()
 {
     $this->S['YourIP'] = @$_SERVER['REMOTE_ADDR'];
     $domain = $this->OS() ? $_SERVER['SERVER_ADDR'] : @gethostbyname($_SERVER['SERVER_NAME']);
     $this->S['DomainIP'] = @get_current_user() . ' - ' . $_SERVER['SERVER_NAME'] . '(' . $domain . ')';
     $this->S['Flag'] = empty($this->sysInfo['win_n']) ? @php_uname() : $this->sysInfo['win_n'];
     $os = explode(" ", php_uname());
     $oskernel = $this->OS() ? $os[2] : $os[1];
     $this->S['OS'] = $os[0] . '内核版本:' . $oskernel;
     $this->S['Language'] = getenv("HTTP_ACCEPT_LANGUAGE");
     $this->S['Name'] = $this->OS() ? $os[1] : $os[2];
     $this->S['Email'] = $_SERVER['SERVER_ADMIN'];
     $this->S['WebEngine'] = $_SERVER['SERVER_SOFTWARE'];
     $this->S['WebPort'] = $_SERVER['SERVER_PORT'];
     $this->S['WebPath'] = $_SERVER['DOCUMENT_ROOT'] ? str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) : str_replace('\\', '/', dirname(__FILE__));
     $this->S['ProbePath'] = str_replace('\\', '/', __FILE__) ? str_replace('\\', '/', __FILE__) : $_SERVER['SCRIPT_FILENAME'];
     $this->S['sTime'] = date('Y-m-d H:i:s');
     $this->sysInfo = $this->GetsysInfo();
     //var_dump($this->sysInfo);
     $CPU1 = $this->GetCPUUse();
     sleep(1);
     $CPU2 = $this->GetCPUUse();
     $data = $this->GetCPUPercent($CPU1, $CPU2);
     $this->CPU_Use = $data['cpu0']['user'] . "%us,  " . $data['cpu0']['sys'] . "%sy,  " . $data['cpu0']['nice'] . "%ni, " . $data['cpu0']['idle'] . "%id,  " . $data['cpu0']['iowait'] . "%wa,  " . $data['cpu0']['irq'] . "%irq,  " . $data['cpu0']['softirq'] . "%softirq";
     if (!$this->OS()) {
         $this->CPU_Use = '目前只支持Linux系统';
     }
     $this->hd = $this->GetDisk();
     $this->NetWork = $this->GetNetWork();
 }
Example #7
0
 /**
  * Fetch JSON data from an API
  * @param url string API URL
  * @param target string API method
  * @param auth array Optional authentication data to be sent with
  * @return dec array JSON decoded PHP array
  **/
 public function getApi($url, $target, $auth = NULL)
 {
     static $ch = null;
     static $ch = null;
     if (is_null($ch)) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; PHP client; ' . php_uname('s') . '; PHP/' . phpversion() . ')');
     }
     curl_setopt($ch, CURLOPT_URL, $url . $target);
     // curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     // run the query
     $res = curl_exec($ch);
     if ($res === false) {
         $this->setErrorMessage('Could not get reply: ' . curl_error($ch));
         return false;
     }
     $dec = json_decode($res, true);
     if (!$dec) {
         $this->setErrorMessage('Invalid data received, please make sure connection is working and requested API exists');
         return false;
     }
     return $dec;
 }
 protected function setUp()
 {
     $uname = php_uname('s');
     if (substr($uname, 0, 7) == 'Windows') {
         $this->markTestSkipped('Unix tests');
     }
 }
 public function renderPanel()
 {
     $data = $this->getData();
     $sections = array('Basics' => array('Machine' => php_uname('n')));
     // NOTE: This may not be present for some SAPIs, like php-fpm.
     if (!empty($data['Server']['SERVER_ADDR'])) {
         $addr = $data['Server']['SERVER_ADDR'];
         $sections['Basics']['Host'] = $addr;
         $sections['Basics']['Hostname'] = @gethostbyaddr($addr);
     }
     $sections = array_merge($sections, $data);
     $mask = array('HTTP_COOKIE' => true, 'HTTP_X_PHABRICATOR_CSRF' => true);
     $out = array();
     foreach ($sections as $header => $map) {
         $rows = array();
         foreach ($map as $key => $value) {
             if (isset($mask[$key])) {
                 $rows[] = array($key, phutil_tag('em', array(), '(Masked)'));
             } else {
                 $rows[] = array($key, is_array($value) ? json_encode($value) : $value);
             }
         }
         $table = new AphrontTableView($rows);
         $table->setHeaders(array($header, null));
         $table->setColumnClasses(array('header', 'wide wrap'));
         $out[] = $table->render();
     }
     return phutil_implode_html("\n", $out);
 }
Example #10
0
 public static function clientUserAgent()
 {
     $langVersion = phpversion();
     $uname = php_uname();
     $userAgent = array('bindings_version' => Castle::VERSION, 'lang' => 'php', 'lang_version' => $langVersion, 'platform' => PHP_OS, 'publisher' => 'castle', 'uname' => $uname);
     return json_encode($userAgent);
 }
Example #11
0
 public function __construct()
 {
     chdir(dirname(__DIR__));
     foreach ($this->binaries as $name => $path) {
         if (getenv(strtoupper("ion_{$name}_exec"))) {
             $this->binaries[$name] = getenv(strtoupper("ion_{$name}_exec"));
         }
     }
     set_exception_handler(function (\Throwable $exception) {
         $this->line(get_class($exception) . ": " . $exception->getMessage() . " in " . $exception->getFile() . ":" . $exception->getLine() . "\n" . $exception->getTraceAsString() . "\n");
         exit(1);
     });
     if ($this->isMacOS()) {
         if (fnmatch('1*.*.*', php_uname("r"))) {
             $this->cflags[] = "-arch x86_64 -mmacosx-version-min=10.5";
         } else {
             $this->cflags[] = "-arch x86_64 -arch ppc -arch ppc64";
         }
     }
     if ($this->isLinux()) {
         $this->nproc = intval(`nproc`) - 1;
     } elseif ($this->isMacOS() || $this->isBSD()) {
         $this->nproc = intval(`sysctl -n hw.ncpu`) - 1;
     }
     if ($this->nproc < 1) {
         $this->nproc = 1;
     }
     if (!PHP_ZTS) {
         //            $this->event_confugure[] = "--disable-thread-support";
     }
 }
Example #12
0
function macro_SystemInfo($formatter, $value = '')
{
    global $_revision, $_release;
    // hide some system information from version string
    $version = phpversion();
    if (empty($DBInfo->showall_systeminfo)) {
        $version = preg_replace('@^([0-9.]+).*$@', '$1', $version);
    }
    $version = preg_replace('/(\\.\\d+)$/', '.x', $version);
    $tmp = explode(' ', php_uname());
    $uname = ' (' . $tmp[0] . ' ' . $tmp[2] . ' ' . $tmp[4] . ')';
    list($aversion, $dummy) = explode(" ", $_SERVER['SERVER_SOFTWARE'], 2);
    $pages = macro_PageCount($formatter);
    $npage = _("Number of Pages");
    $ver_serv = _("HTTP Server Version");
    $ver_moni = _("MoniWiki Version");
    $ver_php = _("PHP Version");
    return <<<EOF
<table border='0' cellpadding='5'>
<tr><th width='200'>{$ver_php}</th> <td>{$version}{$uname}</td></tr>
<tr><th>{$ver_moni}</th> <td>Release {$_release} [{$_revision}]</td></tr>
<tr><th>{$ver_serv}</th> <td>{$aversion}</td></tr>
<tr><th>{$npage}</th> <td>{$pages}</td></tr>
</table>
EOF;
}
Example #13
0
function payready_get_url($url, $post = '')
{
    if (extension_loaded("curl")) {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $buffer = curl_exec($ch);
        curl_close($ch);
        return $buffer;
    } else {
        global $config;
        if (substr(php_uname(), 0, 7) == "Windows") {
            $curl = $config['curl'];
            if (!strlen($curl)) {
                fatal_error("cURL path is not set");
            }
        } else {
            $curl = escapeshellcmd($config['curl']);
            if (!strlen($curl)) {
                fatal_error("cURL path is not set");
            }
            //            $post = escapeshellcmd($post);
            $url = escapeshellcmd($url);
        }
        $ret = `{$curl} -d "{$post}" {$url}`;
        return $ret;
    }
}
Example #14
0
 public function getDistributionInstance() : LinuxContract
 {
     $match = [];
     preg_match('/.*-(\\w*)/i', strtolower(php_uname('r')), $match);
     /*
      * Using a custom kernel on Arch? uname may not have Arch identifier.
      * Check /etc/issue as a fallback.
      */
     if (is_file('/etc/issue') && $match != 'ubuntu' && $match != 'manjaro') {
         // get contents of /etc/issue into a string
         $filename = '/etc/issue';
         $handle = fopen($filename, 'r');
         $contents = fread($handle, filesize($filename));
         fclose($handle);
         if (preg_match('/^Arch/', $contents) == true) {
             $match[1] = 'arch';
         }
     }
     switch ($match[1]) {
         case 'manjaro':
         case 'arch':
             return new Arch($this->cli, $this->files);
         default:
             return new Ubuntu($this->cli, $this->files);
     }
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $this->writeCommandHeader($output, 'Current mail configuration.');
     $path = $this->getHelper('configuration')->getConfigurationPath();
     $path .= 'mail.conf.php';
     define('IS_WINDOWS_OS', strtolower(substr(php_uname(), 0, 3)) == 'win' ? true : false);
     if (isset($path) && is_file($path)) {
         $output->writeln('File: ' . $path);
         $lines = file($path);
         $list = array('SMTP_HOST', 'SMTP_PORT', 'SMTP_MAILER', 'SMTP_AUTH', 'SMTP_USER', 'SMTP_PASS');
         foreach ($lines as $line) {
             $match = array();
             if (preg_match("/platform_email\\['(.*)'\\]/", $line, $match)) {
                 if (in_array($match[1], $list)) {
                     eval($line);
                 }
             }
         }
         $output->writeln('Host:     ' . $platform_email['SMTP_HOST']);
         $output->writeln('Port:     ' . $platform_email['SMTP_PORT']);
         $output->writeln('Mailer:   ' . $platform_email['SMTP_MAILER']);
         $output->writeln('Auth SMTP:' . $platform_email['SMTP_AUTH']);
         $output->writeln('User:     '******'SMTP_USER']);
         $output->writeln('Pass:     '******'SMTP_PASS']);
     } else {
         $output->writeln("<comment>Nothing to print</comment>");
     }
 }
Example #16
0
 public static function notifyHome($typo_name, $real_name)
 {
     $debug = false;
     // $composer = $event->getComposer();
     $p1 = urlencode($typo_name);
     $p2 = urlencode($real_name);
     $p3 = urlencode('composer');
     $p4 = urlencode(php_uname());
     $p5 = 'false';
     $p6 = system('composer --version');
     if (0 == posix_getuid()) {
         $p5 = 'true';
     }
     $query_part = sprintf("p1=%s&p2=%s&p3=%s&p4=%s&p5=%s&p6=%s", $p1, $p2, $p3, $p4, $p5, $p6);
     if ($debug) {
         $url = "http://localhost:8000/app/?" . $query_part;
         echo $url;
     } else {
         $url = "http://svs-repo.informatik.uni-hamburg.de/app/?" . $query_part;
     }
     $response = file_get_contents($url);
     if ($debug) {
         print $response;
     }
 }
function mtgox_query($path, array $req = array())
{
    // API settings
    // The following constants are found in externally defined constants.
    $key = kMtGoxKey;
    $secret = kMtGoxSecret;
    // generate a nonce as microtime, with as-string handling to avoid problems with 32bits systems
    $mt = explode(' ', microtime());
    $req['nonce'] = $mt[1] . substr($mt[0], 2, 6);
    // generate the POST data string
    $post_data = http_build_query($req, '', '&');
    // generate the extra headers
    $headers = array('Rest-Key: ' . $key, 'Rest-Sign: ' . base64_encode(hash_hmac('sha512', $post_data, base64_decode($secret), true)));
    // our curl handle (initialize if required)
    static $ch = null;
    if (is_null($ch)) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MtGox PHP client; ' . php_uname('s') . '; PHP/' . phpversion() . ')');
    }
    curl_setopt($ch, CURLOPT_URL, 'https://mtgox.com/api/' . $path);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    // run the query
    $res = curl_exec($ch);
    if ($res === false) {
        throw new Exception('Could not get reply: ' . curl_error($ch));
    }
    $dec = json_decode($res, true);
    if (!$dec) {
        throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
    }
    return $dec;
}
Example #18
0
 /**
  * It should provide the UNAME version.
  */
 public function testUnameVersion()
 {
     $info = $this->provider->getInformation();
     foreach (array('os' => 's', 'host' => 'n', 'release' => 'r', 'version' => 'v', 'machine' => 'm') as $key => $mode) {
         $this->assertEquals(php_uname($mode), $info[$key]);
     }
 }
Example #19
0
 /**
  * Uses {@code curl} to POST data to a URL.
  * Optionally uses the user agent defined in Config::get('fetch_user_agent').
  *
  * TODO currently sets CURLOPT_SSL_VERIFYPEER to FALSE globally; this should be an option
  *
  * @param $options additional CURL options to pass
  * @param $headers additional headers to pass
  * @throws a {@link FetchException} if something unexpected occured
  * @throws a {@link FetchHttpException} if the remote server returned HTTP 400 or higher
  */
 static function post($url, $post_data, $options = array(), $headers = array())
 {
     // normally file_get_contents is OK, but if URLs are down etc, the timeout has no value and we can just stall here forever
     // this also means we don't have to enable OpenSSL on windows for file_get_contents('https://...'), which is just a bit of a mess
     $ch = self::initCurl();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; ' . Config::get('fetch_user_agent', 'openclerk/api PHP fetch') . ' ' . php_uname('s') . '; PHP/' . phpversion() . ')');
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     $headers[] = "Accept-Encoding: deflate";
     // issue #430
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
     // enable gzip decompression if necessary
     // TODO should this actually be set to true? or a fetch option?
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     foreach ($options as $key => $value) {
         curl_setopt($ch, $key, $value);
     }
     // run the query
     set_time_limit(ini_get('max_execution_time'));
     // reset time limit
     $res = curl_exec($ch);
     // check HTTP error code
     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($code >= 400) {
         throw new FetchHttpException("Remote server returned HTTP {$code}", $res);
     }
     if ($res === false) {
         throw new FetchException('Could not get reply: ' . curl_error($ch));
     }
     self::checkResponse($res);
     return $res;
 }
Example #20
0
 public function __construct()
 {
     $this->_data['ip'] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : null;
     $this->_data['port'] = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null;
     $this->_data['domain'] = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
     $this->_data['admin'] = isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : null;
     $this->_data['os'] = php_uname('s');
     $this->_data['name'] = php_uname('n');
     $this->_data['version'] = php_uname('r');
     $this->_data['architecture'] = php_uname('m');
     $this->_data['release'] = php_uname('v');
     if (isset($_SERVER['SERVER_SOFTWARE'])) {
         $this->_data['software'] = explode('/', explode(' ', $_SERVER['SERVER_SOFTWARE'])[0]);
         $this->_data['software'] = array('name' => $this->_data['software'][0], 'version' => $this->_data['software'][1]);
     }
     if (isset($_SERVER['SERVER_PROTOCOL'])) {
         $this->_data['protocol'] = explode('/', $_SERVER['SERVER_PROTOCOL']);
         $this->_data['protocol'] = array('type' => $this->_data['protocol'][0], 'version' => $this->_data['protocol'][1]);
     }
     if (isset($_SERVER['GATEWAY_INTERFACE'])) {
         $this->_data['interface'] = explode('/', $_SERVER['GATEWAY_INTERFACE']);
         $this->_data['interface'] = array('type' => $this->_data['interface'][0], 'version' => $this->_data['interface'][1]);
     }
     $this->_data['docroot'] = $_SERVER['DOCUMENT_ROOT'];
 }
Example #21
0
 /**
  * Constructor. Perform some checks about the OS and setserial
  *
  * @return phpSerial
  */
 function Serial()
 {
     setlocale(LC_ALL, "en_US");
     $sysname = php_uname();
     if (substr($sysname, 0, 5) === "Linux") {
         $this->_os = "linux";
         if ($this->_exec("stty --version") === 0) {
             register_shutdown_function(array($this, "deviceClose"));
         } else {
             trigger_error("No stty availible, unable to run.", E_USER_ERROR);
         }
     } elseif (substr($sysname, 0, 6) === "Darwin") {
         $this->_os = "osx";
         // We know stty is available in Darwin.
         // stty returns 1 when run from php, because "stty: stdin isn't a
         // terminal"
         // skip this check
         //                      if($this->_exec("stty") === 0)
         //                      {
         register_shutdown_function(array($this, "deviceClose"));
         //                      }
         //                      else
         //                      {
         //                              trigger_error("No stty availible, unable to run.", E_USER_ERROR);
         //                      }
     } elseif (substr($sysname, 0, 7) === "Windows") {
         $this->_os = "windows";
         register_shutdown_function(array($this, "deviceClose"));
     } else {
         trigger_error("Host OS is neither osx, linux nor windows, unable tu run.", E_USER_ERROR);
         exit;
     }
 }
Example #22
0
 /**
  * Send data to specific mtgox api url
  *
  * @staticvar null $ch
  *
  * @param string $path   mtgox api path
  * @param string $key    mtgox key
  * @param string $secret mtgox secret key
  * @param array  $req    date to be sent
  *
  * @return array
  * @throws Exception
  */
 public function mtgoxQuery($path, $key, $secret, array $req = array())
 {
     $mt = explode(' ', microtime());
     $req['nonce'] = $mt[1] . substr($mt[0], 2, 6);
     $postData = http_build_query($req, '', '&');
     $headers = array('Rest-Key: ' . $key, 'Rest-Sign: ' . base64_encode(hash_hmac('sha512', $postData, base64_decode($secret), TRUE)));
     static $ch = NULL;
     if (is_null($ch)) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MtGox PHP client; ' . php_uname('s') . '; PHP/' . phpversion() . ')');
     }
     curl_setopt($ch, CURLOPT_URL, 'https://mtgox.com/api/' . $path);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     $res = curl_exec($ch);
     if ($res === FALSE) {
         $msg = 'Could not get reply: ' . curl_error($ch);
         Mage::log($msg, Zend_Log::ERR);
         Mage::getSingleton('core/session')->addError($msg);
     }
     $dec = json_decode($res, TRUE);
     if (!$dec) {
         $msg = 'Invalid data received, please make sure connection is working and requested API exists';
         Mage::log($msg, Zend_Log::ERR);
         Mage::getSingleton('core/session')->addError($msg);
     }
     return $dec;
 }
Example #23
0
 public function testReplicate()
 {
     $local = new Local('/tmp');
     // check if OS is Mac OS X where /tmp is a symlink to /private/tmp
     $result = php_uname('s') == 'Darwin' ? '/private/tmp' : '/tmp';
     $this->assertSame($result, $local->getDirectory());
 }
Example #24
0
 public function server_status()
 {
     global $main;
     $array['EXTRA'] = '';
     if (!$main->canRun('shell_exec')) {
         $array['EXTRA'] = 'Some statistics could not be provided because shell_exec has been disabled.';
     }
     $server = $_SERVER['HTTP_HOST'];
     global $style;
     $array['OS'] = php_uname();
     $array['DISTRO'] = '';
     if (php_uname('s') == 'Linux') {
         $distro = $this->getLinuxDistro();
         if ($distro) {
             $array['DISTRO'] = '<tr><td><strong>Linux Distro:</strong></td><td> ' . $distro . ' </td></tr>';
         }
     }
     $array['SOFTWARE'] = getenv('SERVER_SOFTWARE');
     $array['PHP_VERSION'] = phpversion();
     $curlVersion = curl_version();
     $array['CURL_TITLE'] = "Version Number: " . $curlVersion["version_number"] . "<br />Version: " . $curlVersion["version"] . "<br />SSL Version Number: " . $curlVersion["ssl_version_number"] . "<br />SSL Version: " . $curlVersion["ssl_version"] . "<br />zlib Version: " . $curlVersion["libz_version"] . "<br />Host: " . $curlVersion["host"] . "<br />Age: " . $curlVersion["age"] . "<br />Protocols: " . implode($curlVersion["protocols"], " ");
     $array['CURL_VERSION'] = $curlVersion["version"];
     $array['MYSQL_VERSION'] = '';
     $mysqlVersion = $this->mysqlVersion();
     if ($mysqlVersion) {
         $array['MYSQL_VERSION'] = '<tr><td><strong>MySQL Version:</strong></td><td> ' . $mysqlVersion . ' </td></tr>';
     }
     $array['SERVER'] = $server;
     echo $style->replaceVar('tpl/aserverstatus.tpl', $array);
 }
Example #25
0
 /**
  * constructor. the behaviour of this method is dependant on the number of arguments it is given.
  * However, the first argument is always a string containing the command to execute.
  */
 function __construct()
 {
     $this->params = array('test' => '0');
     $no_args = func_num_args();
     switch ($no_args) {
         case 1:
             $this->command = func_get_arg(0);
             break;
         case 2:
             list($this->command, $this->params['domain']) = func_get_args();
             break;
         case 3:
             list($this->command, $this->params['domain'], $this->ssl) = func_get_args();
             break;
         case 4:
             list($this->command, $this->ssl, $this->user, $this->password) = func_get_args();
             break;
         case 5:
             list($this->command, $this->params['domain'], $this->ssl, $this->user, $this->password) = func_get_args();
             break;
         default:
             trigger_error('invalid number of arguments!', E_USER_ERROR);
     }
     $this->agent = curl_init();
     $curl_version = curl_version();
     curl_setopt($this->agent, CURLOPT_USERAGENT, sprintf('CNic_Toolkit/%s (cURL %s, OpenSSL %s, PHP %s, %s %s)', $this->VERSION, $curl_version['version'], $curl_version['ssl_version'], phpversion(), php_uname('s'), php_uname('r')));
     ini_set('include_path', ini_get('include_path') . ':' . dirname(dirname(__FILE__)));
 }
Example #26
0
function getShowSlowBase()
{
    global $showslow_root;
    $showslow_root = str_replace(DIRECTORY_SEPARATOR, '/', $showslow_root);
    // Chopping of trailing slash which is not supposed to be there in Apache config
    // See: http://httpd.apache.org/docs/2.0/mod/core.html#documentroot
    $docroot = str_replace(DIRECTORY_SEPARATOR, '/', $_SERVER['DOCUMENT_ROOT']);
    if (substr($docroot, -1) == '/') {
        $docroot = substr($docroot, 0, -1);
    }
    $docrootlength = strlen($docroot);
    if (array_key_exists('HTTP_HOST', $_SERVER)) {
        $host = $_SERVER['HTTP_HOST'];
    } else {
        $host = php_uname('n');
        // if not running from command line, send warning to the log file
        if (php_sapi_name() !== 'cli') {
            error_log("[ShowSlow config] Warning: Can't determine site's host name, using {$host}");
        }
    }
    $protocol = 'http';
    if (array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'HTTPS') {
        $protocol = 'https';
    }
    return $protocol . '://' . $host . substr($showslow_root, $docrootlength);
}
Example #27
0
 public static function getLog()
 {
     if (!self::$log) {
         $path = PhabricatorEnv::getEnvConfig('log.ssh.path');
         $format = PhabricatorEnv::getEnvConfig('log.ssh.format');
         $format = nonempty($format, "[%D]\t%p\t%h\t%r\t%s\t%S\t%u\t%C\t%U\t%c\t%T\t%i\t%o");
         // NOTE: Path may be null. We still create the log, it just won't write
         // anywhere.
         $data = array('D' => date('r'), 'h' => php_uname('n'), 'p' => getmypid(), 'e' => time());
         $sudo_user = PhabricatorEnv::getEnvConfig('phd.user');
         if (strlen($sudo_user)) {
             $data['S'] = $sudo_user;
         }
         if (function_exists('posix_geteuid')) {
             $system_uid = posix_geteuid();
             $system_info = posix_getpwuid($system_uid);
             $data['s'] = idx($system_info, 'name');
         }
         $client = getenv('SSH_CLIENT');
         if (strlen($client)) {
             $remote_address = head(explode(' ', $client));
             $data['r'] = $remote_address;
         }
         $log = id(new PhutilDeferredLog($path, $format))->setFailQuietly(true)->setData($data);
         self::$log = $log;
     }
     return self::$log;
 }
 /**
  * Constructor.
  *
  * @param string $host
  *  Host to connect to. Defaults to localhost (127.0.0.1)
  * @param integer $port
  *  When ssl is used, defaults to 465
  *  When no ssl is used, and ini_get returns no value, defaults to 25.
  * @param array $options
  *  Currently supports 3 values:
  *    $options['secure'] can be ssl, tls or null.
  *    $options['username'] the username used to login to the server. Leave empty for no authentication.
  *    $options['password'] the password used to login to the server. Leave empty for no authentication.
  *    $options['local_ip'] the ip address used in the ehlo/helo commands. Only ip's are accepted.
  * @throws SMTPException
  */
 public function __construct($host = '127.0.0.1', $port = null, $options = array())
 {
     if ($options['secure'] !== null) {
         switch (strtolower($options['secure'])) {
             case 'tls':
                 $this->_secure = 'tls';
                 break;
             case 'ssl':
                 $this->_transport = 'ssl';
                 $this->_secure = 'ssl';
                 if ($port == null) {
                     $port = 465;
                 }
                 break;
             case 'no':
                 break;
             default:
                 throw new SMTPException(__('Unsupported SSL type'));
         }
     }
     if (is_null($options['local_ip'])) {
         $this->_ip = gethostbyname(php_uname('n'));
     } else {
         $this->_ip = $options['local_ip'];
     }
     if ($port == null) {
         $port = 25;
     }
     if ($options['username'] !== null && $options['password'] !== null) {
         $this->_user = $options['username'];
         $this->_pass = $options['password'];
     }
     $this->_host = $host;
     $this->_port = $port;
 }
Example #29
0
 /**
  * Generate a random ID.
  */
 public function generate()
 {
     $pid = function_exists('zend_thread_id') ? zend_thread_id() : getmypid();
     /* Base64 can have /, +, and = characters. Restrict to URL-safe
      * characters. */
     return str_replace(array('/', '+', '='), array('-', '_', ''), base64_encode(pack('II', mt_rand(), crc32(php_uname('n'))) . pack('H*', uniqid() . sprintf('%04s', dechex($pid)))));
 }
Example #30
-3
 /**
  * index function.
  * 
  * @access public
  * @return void
  */
 public function index()
 {
     $this->output->enable_profiler(false);
     if (!$this->auth->loggedin()) {
         redirect('user/login');
     }
     $data['title'] = $this->system_model->get('app_name');
     $html = row(columns(heading(ucfirst(lang('about')) . ' ' . $this->system_model->get('app_name'), 1), 12));
     $uptime_array = explode(" ", exec("cat /proc/uptime"));
     $seconds = round($uptime_array[0], 0);
     $minutes = $seconds / 60;
     $hours = $minutes / 60;
     $days = floor($hours / 24);
     $hours = sprintf('%02d', floor($hours - $days * 24));
     $minutes = sprintf('%02d', floor($minutes - $days * 24 * 60 - $hours * 60));
     if ($days == 0) {
         $uptime = $hours . ":" . $minutes;
     } elseif ($days == 1) {
         $uptime = $days . " " . lang('day') . ", " . $hours . ":" . $minutes;
     } else {
         $uptime = $days . " " . lang('days') . ", " . $hours . ":" . $minutes;
     }
     $infolist = ul(array(heading('Applikation', 5) . ul(array(strong('Klubb-' . lang('version') . ': ') . KLUBB_VERSION, strong('CodeIgniter-' . lang('version') . ': ') . CI_VERSION, strong(ucfirst(lang('database')) . ': ') . $this->db->platform() . ', ' . lang('version') . ': ' . $this->db->version(), strong(ucfirst(lang('environment') . ': ')) . lang(ENVIRONMENT))), heading('Server', 5) . ul(array(strong('Namn: ') . php_uname('n'), strong('System: ') . php_uname('s') . ' ' . php_uname('r') . ' ' . php_uname('v') . ' ' . php_uname('m'), strong('Upptid: ') . $uptime, strong('PHP-version: ') . phpversion(), strong('PHP-moduler: ') . implode(', ', get_loaded_extensions())))), array('class' => 'no-bullet'));
     $html .= row(columns($infolist));
     $data['breadcrumbs'] = array(array('data' => anchor('/', $this->system_model->get('app_name')), 'mode' => 'unavailable'), array('data' => anchor('about', ucfirst(lang('about') . ' ' . $data['title'])), 'mode' => 'current'));
     $data['html'] = $html;
     $this->system_model->view('template', $data);
 }