/** * This function will be called when the script terminates */ function onScriptShutDown() { global $apiKey; $error = error_get_last(); $error = is_array($error) ? $error : array('type' => -1); // check to see if an error actually occurred if (in_array($error['type'], array(E_PARSE, E_ERROR))) { // get the error message $message = $error['message']; // I'm simulating the backtrace because we are in the context of a shutdown handler. // If we were in the context of a script that had not terminated (say, in the catch // block of a try/catch control structure), then we could use PHP's built-in // debug_backtrace. See http://php.net/manual/en/function.debug-backtrace.php $backtrace = array(array('line' => $error['line'], 'file' => $error['file'], 'class' => 'example.php', 'function' => 'onScriptShutDown')); // We may also add session specific information in our tracking call. // This info is optional, but encouraged. $session = array('user' => get_current_user(), 'title' => 'Running the Airbrake PHP client', 'date' => date('Y-m-d H:i:s')); // Create a new tracker, bound to the passed-in API key $notifier = new AirbrakeNotifier($apiKey); // Track the error. Note that this call will log messages // to the error console if AirbrakeNotifier::$debugMode is true $noticeId = $notifier->notify($message, 'ShutdownError', $backtrace, $session); if ($noticeId) { die("Your error has been successfully logged, verify by visiting your Airbrake dashboard. Notice ID {$noticeId}\r\n"); } } }
private function getUser() { if (extension_loaded("posix") && function_exists("posix_getpwuid")) { return posix_getpwuid(posix_getuid())["name"]; } return trim(`whoami 2>/dev/null`) ?: trim(`id -nu 2>/dev/null`) ?: getenv("USER") ?: get_current_user(); }
function removeMenuItems() { $current_user = get_current_user(); if ($current_user != 2 || $current_user != 1) { //something to hide here } }
public function testAdapterConfig() { $config = new Config(array('database' => $GLOBALS['dbname'], 'driver' => 'pgsql'), $this->basePath, 2); $config = $config->getAdapterConfig(); $strAuthor = $config->author; $this->assertTrue($strAuthor == ucfirst(get_current_user())); }
/** * Constructs storage object and creates storage directory * * @param string $dir directory name to store data files in * @throws Zend_OpenId_Exception */ public function __construct($dir = null) { if ($dir === null) { $tmp = getenv('TMP'); if (empty($tmp)) { $tmp = getenv('TEMP'); if (empty($tmp)) { $tmp = "/tmp"; } } $user = get_current_user(); if (is_string($user) && !empty($user)) { $tmp .= '/' . $user; } $dir = $tmp . '/openid/provider'; } $this->_dir = $dir; if (!is_dir($this->_dir)) { if (!@mkdir($this->_dir, 0700, 1)) { throw new Zend_OpenId_Exception("Cannot access storage directory {$dir}", Zend_OpenId_Exception::ERROR_STORAGE); } } if (($f = fopen($this->_dir . '/assoc.lock', 'w+')) === null) { throw new Zend_OpenId_Exception('Cannot create a lock file in the directory ' . $dir, Zend_OpenId_Exception::ERROR_STORAGE); } fclose($f); if (($f = fopen($this->_dir . '/user.lock', 'w+')) === null) { throw new Zend_OpenId_Exception('Cannot create a lock file in the directory ' . $dir, Zend_OpenId_Exception::ERROR_STORAGE); } fclose($f); }
function index() { require APP . 'webroot/configuration.php'; //get CURRENT SpaceBukkit version $c_sb = $sbconf['app_version']; $app = $sbconf['app']; //get LATEST SpaceBukkit version $filename = 'http://dl.nope.bz/sb/build/build.xml'; $l_sb = simplexml_load_file($filename); $json = json_encode($l_sb); $l_sb = json_decode($json, TRUE); //Redirect if no new version is avaible if ($app >= $l_sb["BUILD"]["APP"]) { $this->redirect(array('controller' => 'Dash', 'action' => 'index')); } $this->set('title_for_layout', __('Updating SpaceBukkit')); $this->set('current', $c_sb); $this->set('latest', $l_sb["BUILD"]["VERSION"]); $this->set('changelog', $l_sb["BUILD"]["CHANGELOG"]); $command = ''; if (PHP_OS !== 'WINNT') { $user = exec('whoami'); if (get_current_user() == $user) { $chown = true; } else { $chown = false; $command = 'chown -R ' . $user . ' ' . ROOT; } } else { $chown = true; } $this->set('owner', array($chown, $command)); $this->layout = 'update'; }
/** * A normal Unix pathname contains no duplicate slashes and does not end * with a slash. It may be the empty string. * * Check that the given pathname is normal. If not, invoke the real * normalizer on the part of the pathname that requires normalization. * This way we iterate through the whole pathname string only once. */ function normalize($strPathname) { if (!strlen($strPathname)) { return; } // Resolve home directories. We assume /home is where all home // directories reside, b/c there is no other way to do this with // PHP AFAIK. if ($strPathname[0] === "~") { if ($strPathname[1] === "/") { // like ~/foo => /home/user/foo $strPathname = "/home/" . get_current_user() . substr($strPathname, 1); } else { // like ~foo => /home/foo $pos = strpos($strPathname, "/"); $name = substr($strPathname, 1, $pos - 2); $strPathname = "/home/" . $name . substr($strPathname, $pos); } } $n = strlen($strPathname); $prevChar = 0; for ($i = 0; $i < $n; $i++) { $c = $strPathname[$i]; if ($prevChar === '/' && $c === '/') { return self::normalizer($strPathname, $n, $i - 1); } $prevChar = $c; } if ($prevChar === '/') { return self::normalizer($strPathname, $n, $n - 1); } return $strPathname; }
/** * Constructs storage object and creates storage directory * * @param string $dir directory name to store data files in * @throws Zend_OpenId_Exception */ public function __construct($dir = null) { if (is_null($dir)) { $tmp = getenv('TMP'); if (empty($tmp)) { $tmp = getenv('TEMP'); if (empty($tmp)) { $tmp = "/tmp"; } } $user = get_current_user(); if (is_string($user) && !empty($user)) { $tmp .= '/' . $user; } $dir = $tmp . '/openid/provider'; } $this->_dir = $dir; if (!is_dir($this->_dir)) { if (!@mkdir($this->_dir, 0700, 1)) { throw new Zend_OpenId_Exception( "Cannot access storage directory $dir", Zend_OpenId_Exception::ERROR_STORAGE); } } }
/** * Setup the current role, and (if set) setup the new role and capabilities. * * @since 0.2.0 * @access private */ function setup_roles() { global $current_user; if (!$current_user) { $current_user = get_current_user(); } if (!$this->current_role) { $this->current_role = array_shift($current_user->roles); } if (!$this->new_role) { // If this POST variable exists, the current user just changed the drop-down if (isset($_POST['rqc'])) { // If the POST value is "default", then just turn it off if ($_POST['rqc'] == 'default') { $this->new_role = false; delete_user_meta($current_user->ID, 'rqc_current_role'); return; } // Set the new role to the POST value and update the meta $this->new_role = $_POST['rqc']; update_user_meta($current_user->ID, 'rqc_current_role', $this->new_role); } // Otherwise, grab the role from the current user meta $role = get_user_meta($current_user->ID, 'rqc_current_role', true); $this->new_role = $role; if ($role = get_role($this->new_role)) { $this->new_role_caps = $role->capabilities; } } }
/** * Dump live informations from extender process (if in daemon mode and pcntl installed) * * @param int $timestamp_absolute * @param itn $parent_pid * @param int $completed_processes * @param itn $failed_processes */ public static final function dump($timestamp_absolute, $parent_pid, $completed_processes, $failed_processes, $paused) { $statusfile = EXTENDER_CACHE_FOLDER . self::$statusfile; $data = array("RUNNING" => $paused ? 0 : 1, "STARTED" => $timestamp_absolute, "TIME" => microtime(true) - $timestamp_absolute, "PARENTPID" => $parent_pid, "COMPLETED" => $completed_processes, "FAILED" => $failed_processes, "CPUAVG" => sys_getloadavg(), "MEM" => memory_get_usage(true), "MEMPEAK" => memory_get_peak_usage(true), "USER" => get_current_user(), "NICENESS" => function_exists('pcntl_getpriority') ? pcntl_getpriority() : "UNDEFINED"); $content = serialize($data); return file_put_contents($statusfile, $content); }
private function remove_ENGR_dirs($path) { $pattern = '/\\/nfs.*public_html(.*)/'; preg_match($pattern, $path, $matches); $user = get_current_user(); return '/~' . $user . $matches[1]; }
/** * Constructor * * @param string nick * @param string realname default NULL (defaults to nickname) * @param string username default NULL (defaults to current username) * @param string hostname default 'localhost' */ public function __construct($nick, $realname = NULL, $username = NULL, $hostname = 'localhost') { $this->nick = $nick; $this->realname = $realname ? $realname : $nick; $this->username = $username ? $username : get_current_user(); $this->hostname = $hostname; }
/** * Allows you to do things before any output has been sent to the browser. * This means you can redirect to a remote site, another page etc if need be. */ function verify_token() { // Generate a fake token and store it for this example $token = sha1(time() . mt_rand(0, 1000) . time()); $meta = array('time' => time(), 'user' => get_current_user()); $this->store_token($token, $meta); }
public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('transporter'); $rootNode->isRequired()->children()->scalarNode('host')->isRequired()->end()->scalarNode('path')->isRequired()->end()->scalarNode('port')->defaultNull()->end()->scalarNode('user')->defaultValue(get_current_user())->end()->scalarNode('pass')->defaultNull()->end()->end(); return $treeBuilder; }
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(); }
public function __construct($argv) { $this->verbose = $this->verbose == true ? true : false; $argv[] = '-clean'; $argv[] = ''; $this->args = $argv; // get the systems username and set the home dir. $this->user = get_current_user(); $this->home = '/home/' . $this->user . '/'; foreach ($this->args as $location => $args) { $chars = str_split($args); if ($chars[0] === '-') { $tmp = explode('-', $args); $function = end($tmp); unset($tmp); // this does a check to make sure we can only // run public functions via this constructor. $check = new ReflectionMethod($this, $function); if (!$check->isPublic()) { continue; } $this->{$function}($argv[++$location]); } } }
/** * Formats the events title with variables as stated in the src/config/config.php * * @param string $branchName * @param string $applicationName * @param string $connectionName * @param string $eventTitle * @return string */ private function formatEventTitle($branchName, $applicationName, $connectionName, $eventTitle) { $pattern = ['(:user)', '(:branch)', '(:repo)', '(:conn)']; $replacements = [':user' => get_current_user(), ':branch' => $branchName, ':repo' => $applicationName, ':conn' => $connectionName]; $eventTitle = preg_replace($pattern, $replacements, $eventTitle); return $eventTitle; }
/** * Constructs storage object and creates storage directory * * @param string $dir directory name to store data files in * @throws Zend_OpenId_Exception */ public function __construct($dir = null) { if ($dir === null) { $tmp = getenv('TMP'); if (empty($tmp)) { $tmp = getenv('TEMP'); if (empty($tmp)) { $tmp = "/tmp"; } } $user = get_current_user(); if (is_string($user) && !empty($user)) { $tmp .= '/' . $user; } $dir = $tmp . '/openid/consumer'; } $this->_dir = $dir; if (!is_dir($this->_dir)) { if (!@mkdir($this->_dir, 0700, 1)) { /** * @see Zend_OpenId_Exception */ require_once 'Zend/OpenId/Exception.php'; throw new Zend_OpenId_Exception( 'Cannot access storage directory ' . $dir, Zend_OpenId_Exception::ERROR_STORAGE); } } if (($f = fopen($this->_dir.'/assoc.lock', 'w+')) === null) { /** * @see Zend_OpenId_Exception */ require_once 'Zend/OpenId/Exception.php'; throw new Zend_OpenId_Exception( 'Cannot create a lock file in the directory ' . $dir, Zend_OpenId_Exception::ERROR_STORAGE); } fclose($f); if (($f = fopen($this->_dir.'/discovery.lock', 'w+')) === null) { /** * @see Zend_OpenId_Exception */ require_once 'Zend/OpenId/Exception.php'; throw new Zend_OpenId_Exception( 'Cannot create a lock file in the directory ' . $dir, Zend_OpenId_Exception::ERROR_STORAGE); } fclose($f); if (($f = fopen($this->_dir.'/nonce.lock', 'w+')) === null) { /** * @see Zend_OpenId_Exception */ require_once 'Zend/OpenId/Exception.php'; throw new Zend_OpenId_Exception( 'Cannot create a lock file in the directory ' . $dir, Zend_OpenId_Exception::ERROR_STORAGE); } fclose($f); }
/** * Create unique run ID * * @return string */ public static function createRunId() { $random = uniqid(true) . mt_rand(); if (function_exists('openssl_random_pseudo_bytes')) { $random .= openssl_random_pseudo_bytes(1024); } return hash('sha512', $random . microtime(true) . getmypid() . get_current_user()); }
/** * Get Current User * * @return string */ public static function getCurrentUser() { $processUser = posix_getpwuid(posix_geteuid()); if (true === isset($processUser['name'])) { return $processUser['name']; } return get_current_user(); }
public function startMyCommandWithOptionAndConfigurationAtNewPlace(CliGuy $I) { $myname = get_current_user(); $I->amInPath('tests/data/register_command'); $I->executeCommand('myProject:myCommand --config standard/codeception.yml --friendly'); $I->seeInShellOutput("Hello {$myname},"); $I->seeInShellOutput("how are you?"); }
/** * Reaturn all handins that an user is responsible from * * @param User $user default value is current user * @return array */ static function getPendingHandinsByUser($user = null) { if (!$user) { $user = get_current_user(); } return self::findAll(array('conditions' => array('`responsible_user_id` = ? and (completed_on IS NULL or completed_on = 0) ', $user->getId()))); // findAll }
/** * 构造函数 * * @access public * @return void */ public function __construct($option) { if (!empty($option['query'])) { parse_str($option['query'], $query); $this->option = (array) $option + (array) $query; } $this->option = (array) $option + array('user' => get_current_user()); }
/** * Sets the URL to https or http, depending on availability and related WP config settings/APIs. * * @since 4.2 * * @param $url string * * @return string */ public function set_url_scheme($url) { $current_user = get_current_user(); if (function_exists('force_ssl_admin') && force_ssl_admin() || function_exists('force_ssl_login') && force_ssl_login() || function_exists('force_ssl_content') && force_ssl_content() || function_exists('is_ssl') && is_ssl() || !empty($current_user->use_ssl)) { return set_url_scheme($url, 'https'); } return set_url_scheme($url, 'http'); }
public function __construct($args = array()) { $host = $args['host'] ? $args['host'] : 'localhost'; $user = $args['user'] ? $args['user'] : get_current_user(); $pass = $args['pass'] ? $args['pass'] : ''; $this->_connect($host, $user, $pass); $args['db'] && ($this->db = $args['db']); $this->_load_migrations(); }
public static function whoami() { if (function_exists('posix_getpwuid')) { $chk = posix_getpwuid(posix_getuid()); return $chk['name']; } else { return get_current_user(); } }
/** * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @codingStandardsIgnoreStart */ public function authenticate($username, $password, $options = []) { $system_username = get_current_user(); $role_map = $this->config->get('role_map'); if (isset($role_map[$system_username])) { return new AuthResponse(AuthResponse::STATE_AUTHORIZED, 'authenticaton success', ['login' => $system_username, 'acl_role' => $role_map[$system_username]]); } return new AuthResponse(AuthResponse::STATE_UNAUTHORIZED, 'authentication failed', [], ['Unable to map system user to honeybee role.']); }
public function mycred_edit_profile_actions() { global $wpdb; // Check nonce value $nonce = isset($_POST['dln_hire']['token']) ? $_POST['dln_hire']['token'] : ''; if (!wp_verify_nonce($nonce, 'dln-adjust-hire-day')) { return; } extract($_POST['dln_hire']); $redirect_url = admin_url('users.php?page=mycred-edit-balance&user_id=' . $user_id . '&ctype=' . self::$ctype); if (isset($_POST['dln_add_hire_day']) && isset($_POST['dln_add_hire_day'])) { if ($user_id && $cost && $start_time && $day_limit) { $cost = $cost * 1000; $day_limit = (int) $day_limit; $days = strtotime($start_time) + $day_limit * 24 * 60 * 60; $user = get_current_user(); $mycred = mycred(self::$ctype); $args = array('user_id' => $user_id, 'start_time' => date('Y-m-d H:i:s', strtotime($start_time)), 'day_limit' => $day_limit, 'end_time' => date('Y-m-d H:i:s', $days), 'cost' => $cost, 'active' => 1, 'type' => 'silver'); $data = serialize($args); $log = ''; if (!empty($hire_day_id)) { $result = $wpdb->update($wpdb->dln_hire, $args, array('id' => $hire_day_id)); } else { $result = $wpdb->insert($wpdb->dln_hire, $args); $log = sprintf(__('User %s inserted silver for hire id %d', DLN_ABE), $user, $result); } if (!is_wp_error($result)) { if ($log) { // Run $mycred->add_creds('manual', $user_id, 0 - $cost, $log, get_current_user_id(), $data, self::$ctype); } wp_redirect($redirect_url); exit; } else { var_dump($result); } } } if (!current_user_can('edit_users')) { return false; } if (isset($_POST['dln_delete_hire_day']) && isset($_POST['dln_delete_hire_day'])) { if (isset($_POST['dln_action']) && $_POST['dln_action'] == 'delete') { $hire_day_id = isset($_POST['hire_day_id']) ? (int) $_POST['hire_day_id'] : ''; if (!empty($hire_day_id)) { $result = $wpdb->delete($wpdb->dln_hire, array('id' => $hire_day_id)); if (!is_wp_error($result)) { wp_redirect($redirect_url); exit; } else { var_dump($result); } } } } }
function randomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0) { static $lastRandom = ""; $output = ""; $length = abs((int) $length); $secureValue = ""; $rounds = 0; $drop = 0; while (!isset($output[$length - 1])) { //some entropy, but works ^^ $weakEntropy = array(is_array($startEntropy) ? implode($startEntropy) : $startEntropy, serialize(stat(__FILE__)), __DIR__, PHP_OS, microtime(), (string) lcg_value(), (string) PHP_MAXPATHLEN, PHP_SAPI, (string) PHP_INT_MAX . "." . PHP_INT_SIZE, serialize($_SERVER), serialize(get_defined_constants()), get_current_user(), serialize(ini_get_all()), (string) memory_get_usage() . "." . memory_get_peak_usage(), php_uname(), phpversion(), extension_loaded("gmp") ? gmp_strval(gmp_random(4)) : microtime(), zend_version(), (string) getmypid(), (string) getmyuid(), (string) mt_rand(), (string) getmyinode(), (string) getmygid(), (string) rand(), function_exists("zend_thread_id") ? (string) zend_thread_id() : microtime(), var_export(@get_browser(), true), function_exists("getrusage") ? @implode(getrusage()) : microtime(), function_exists("sys_getloadavg") ? @implode(sys_getloadavg()) : microtime(), serialize(get_loaded_extensions()), sys_get_temp_dir(), (string) disk_free_space("."), (string) disk_total_space("."), uniqid(microtime(), true), file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : microtime()); shuffle($weakEntropy); $value = hash("sha512", implode($weakEntropy), true); $lastRandom .= $value; foreach ($weakEntropy as $k => $c) { //mixing entropy values with XOR and hash randomness extractor $value ^= hash("sha256", $c . microtime() . $k, true) . hash("sha256", mt_rand() . microtime() . $k . $c, true); $value ^= hash("sha512", (string) lcg_value() . $c . microtime() . $k, true); } unset($weakEntropy); if ($secure === true) { $strongEntropyValues = array(is_array($startEntropy) ? hash("sha512", $startEntropy[($rounds + $drop) % count($startEntropy)], true) : hash("sha512", $startEntropy, true), file_exists("/dev/urandom") ? fread(fopen("/dev/urandom", "rb"), 64) : str_repeat("", 64), (function_exists("openssl_random_pseudo_bytes") and version_compare(PHP_VERSION, "5.3.4", ">=")) ? openssl_random_pseudo_bytes(64) : str_repeat("", 64), function_exists("mcrypt_create_iv") ? mcrypt_create_iv(64, MCRYPT_DEV_URANDOM) : str_repeat("", 64), $value); $strongEntropy = array_pop($strongEntropyValues); foreach ($strongEntropyValues as $value) { $strongEntropy = $strongEntropy ^ $value; } $value = ""; //Von Neumann randomness extractor, increases entropy $bitcnt = 0; for ($j = 0; $j < 64; ++$j) { $a = ord($strongEntropy[$j]); for ($i = 0; $i < 8; $i += 2) { $b = ($a & 1 << $i) > 0 ? 1 : 0; if ($b != (($a & 1 << $i + 1) > 0 ? 1 : 0)) { $secureValue |= $b << $bitcnt; if ($bitcnt == 7) { $value .= chr($secureValue); $secureValue = 0; $bitcnt = 0; } else { ++$bitcnt; } ++$drop; } else { $drop += 2; } } } } $output .= substr($value, 0, min($length - strlen($output), $length)); unset($value); ++$rounds; } $lastRandom = hash("sha512", $lastRandom, true); return $raw === false ? bin2hex($output) : $output; }
protected function getVirtualMemory() { $file = sprintf("/sys/fs/cgroup/tornado/%s/1073741824", get_current_user()); if (is_readable($file)) { return (int) file_get_contents($file); } else { $command = $this->command = 'getPhysicalMemory'; return $this->{$command}(); } }