function server_http_headers($host, $ip, $port) { global $timeout; // first check if server is http. otherwise long timeout. $ch = curl_init("https://" . $ip . ":" . $port); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: {$host}")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); if (curl_exec($ch) === false) { curl_close($ch); return false; } curl_close($ch); stream_context_set_default(array("ssl" => array("verify_peer" => false, "capture_session_meta" => true, "verify_peer_name" => false, "peer_name" => $host, "allow_self_signed" => true, "sni_enabled" => true), 'http' => array('method' => 'GET', 'max_redirects' => 1, 'header' => 'Host: ' . $host, 'timeout' => $timeout))); $headers = get_headers("https://{$ip}:{$port}", 1); if (!empty($headers)) { $headers = array_change_key_case($headers, CASE_LOWER); return $headers; } }
public static function applyInitPathHook($url, $context = 'core') { $params = []; $parts = AJXP_Utils::safeParseUrl($url); if (!($params = self::getLocalParams(self::CACHE_KEY . $url))) { // Nothing in cache $repositoryId = $parts["host"]; $repository = ConfService::getRepositoryById($parts["host"]); if ($repository == null) { throw new \Exception("Cannot find repository"); } $configHost = $repository->getOption('HOST'); $configPath = $repository->getOption('PATH'); $params['path'] = $parts['path']; $params['basepath'] = $configPath; $params['itemname'] = basename($params['path']); // Special case for root dir if (empty($params['path']) || $params['path'] == '/') { $params['path'] = '/'; } $params['path'] = dirname($params['path']); $params['fullpath'] = rtrim($params['path'], '/') . '/' . $params['itemname']; $params['base_url'] = $configHost; $params['keybase'] = $repositoryId . $params['fullpath']; $params['key'] = md5($params['keybase']); self::addLocalParams(self::CACHE_KEY . $url, $params); } $repoData = self::actualRepositoryWrapperData($parts["host"]); $repoProtocol = $repoData['protocol']; $default = stream_context_get_options(stream_context_get_default()); $default[$repoProtocol]['path'] = $params; $default[$repoProtocol]['client']->setDefaultUrl($configHost); stream_context_set_default($default); }
/** * Pydio authentication * * @param int $userId ftp username * @return bool FALSE on failure */ function client_pydioAuth($userId) { if (file_exists(GUI_ROOT_DIR . '/data/tmp/failedAJXP.log')) { @unlink(GUI_ROOT_DIR . '/data/tmp/failedAJXP.log'); } $credentials = _client_pydioGetLoginCredentials($userId); if (!$credentials) { set_page_message(tr('Unknown FTP user.'), 'error'); return false; } $contextOptions = array(); // Prepares Pydio absolute Uri to use if (isSecureRequest()) { $contextOptions = array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true)); } $pydioBaseUrl = getBaseUrl() . '/ftp/'; $port = getUriPort(); // Pydio authentication $context = stream_context_create(array_merge($contextOptions, array('http' => array('method' => 'GET', 'protocol_version' => '1.1', 'header' => array('Host: ' . $_SERVER['SERVER_NAME'] . ($port ? ':' . $port : ''), 'User-Agent: i-MSCP', 'Connection: close'))))); # Getting secure token $secureToken = file_get_contents("{$pydioBaseUrl}/index.php?action=get_secure_token", false, $context); $postData = http_build_query(array('get_action' => 'login', 'userid' => $credentials[0], 'login_seed' => '-1', "remember_me" => 'false', 'password' => stripcslashes($credentials[1]), '_method' => 'put')); $contextOptions = array_merge($contextOptions, array('http' => array('method' => 'POST', 'protocol_version' => '1.1', 'header' => array('Host: ' . $_SERVER['SERVER_NAME'] . ($port ? ':' . $port : ''), 'Content-Type: application/x-www-form-urlencoded', 'X-Requested-With: XMLHttpRequest', 'Content-Length: ' . strlen($postData), 'User-Agent: i-MSCP', 'Connection: close'), 'content' => $postData))); stream_context_set_default($contextOptions); # TODO Parse the full response and display error message on authentication failure $headers = get_headers("{$pydioBaseUrl}?secure_token={$secureToken}", true); _client_pydioCreateCookies($headers['Set-Cookie']); redirectTo($pydioBaseUrl); exit; }
public static function updateRegistry() { // WPN-XM Software Registry - Latest Version @ GitHub $url = 'https://raw.githubusercontent.com/WPN-XM/registry/master/wpnxm-software-registry.php'; // fetch date header (doing a simple HEAD request) stream_context_set_default(array('http' => array('method' => 'HEAD'))); // silenced: throws warning, if offline $headers = @get_headers($url, 1); // we are offline if (empty($headers) === true) { return false; } $file = WPNXM_DATA_DIR . 'wpnxm-software-registry.php'; // parse header date $date = \DateTime::createFromFormat('D, d M Y H:i:s O', $headers['Date']); $last_modified = filemtime($file); // update condition, older than 1 week $needsUpdate = $date->getTimestamp() >= $last_modified + 7 * 24 * 60 * 60; // do update $updated = false; if ($needsUpdate === true) { // set request method back to GET, to fetch the file stream_context_set_default(array('http' => array('method' => 'GET'))); $updated = file_put_contents($file, file_get_contents($url)); } return $updated; }
/** * GET an HTTP URL to retrieve its content * * @param string $url URL to get (http://...) * @param int $timeout network timeout (in seconds) * @param int $maxBytes maximum downloaded bytes (default: 4 MiB) * * @return array HTTP response headers, downloaded content * * Output format: * [0] = associative array containing HTTP response headers * [1] = URL content (downloaded data) * * Example: * list($headers, $data) = get_http_response('http://sebauvage.net/'); * if (strpos($headers[0], '200 OK') !== false) { * echo 'Data type: '.htmlspecialchars($headers['Content-Type']); * } else { * echo 'There was an error: '.htmlspecialchars($headers[0]); * } * * @see http://php.net/manual/en/function.file-get-contents.php * @see http://php.net/manual/en/function.stream-context-create.php * @see http://php.net/manual/en/function.get-headers.php */ function get_http_response($url, $timeout = 30, $maxBytes = 4194304) { $urlObj = new Url($url); $cleanUrl = $urlObj->idnToAscii(); if (!filter_var($cleanUrl, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) { return array(array(0 => 'Invalid HTTP Url'), false); } $options = array('http' => array('method' => 'GET', 'timeout' => $timeout, 'user_agent' => 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:45.0)' . ' Gecko/20100101 Firefox/45.0', 'accept_language' => substr(setlocale(LC_COLLATE, 0), 0, 2) . ',en-US;q=0.7,en;q=0.3')); stream_context_set_default($options); list($headers, $finalUrl) = get_redirected_headers($cleanUrl); if (!$headers || strpos($headers[0], '200 OK') === false) { $options['http']['request_fulluri'] = true; stream_context_set_default($options); list($headers, $finalUrl) = get_redirected_headers($cleanUrl); } if (!$headers || strpos($headers[0], '200 OK') === false) { return array($headers, false); } try { // TODO: catch Exception in calling code (thumbnailer) $context = stream_context_create($options); $content = file_get_contents($finalUrl, false, $context, -1, $maxBytes); } catch (Exception $exc) { return array(array(0 => 'HTTP Error'), $exc->getMessage()); } return array($headers, $content); }
function github($format) { // location of cached file $file = 'assets/cache/contributors.json'; // whatever this does, but it works stream_context_set_default(array("http" => array("header" => "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9"))); // update cached file if it's older than half a day if (time() - filemtime($file) > 3600 * 12) { // || $_GET['forcerefresh']) { // get most recent json data $url = 'https://api.github.com/repos/thm/uinames/contributors?per_page=100'; // check status if (getStatus($url) == 200) { // update cached file $data = file_get_contents($url); file_put_contents($file, $data, LOCK_EX); } else { $data = file_get_contents($file); } // prepare fresh data for implementation $data = json_decode($data, true); } else { // prepare cached data for implementation $data = json_decode(file_get_contents($file), true); } // shuffle people up so they're in a different spot every time shuffle($data); // loop: render faces for ($i = 0; $i < count($data); $i++) { $needles = ['$href', '$img', '$user', '$contributions']; $details = [$data[$i]['html_url'], $data[$i]['avatar_url'], $data[$i]['login'], $data[$i]['contributions']]; echo str_replace($needles, $details, $format); } }
function getMp3StreamTitle($steam_url) { $result = false; $icy_metaint = -1; $needle = 'StreamTitle='; $ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36'; $opts = array('http' => array('method' => 'GET', 'header' => 'Icy-MetaData: 1', 'user_agent' => $ua)); $default = stream_context_set_default($opts); $stream = fopen($steam_url, 'r'); if ($stream && ($meta_data = stream_get_meta_data($stream)) && isset($meta_data['wrapper_data'])) { foreach ($meta_data['wrapper_data'] as $header) { if (strpos(strtolower($header), 'icy-metaint') !== false) { $tmp = explode(":", $header); $icy_metaint = trim($tmp[1]); break; } } } if ($icy_metaint != -1) { $buffer = stream_get_contents($stream, 300, $icy_metaint); if (strpos($buffer, $needle) !== false) { $title = explode($needle, $buffer); $title = trim($title[1]); $result = substr($title, 1, strpos($title, ';') - 2); } } if ($stream) { fclose($stream); } return $result; }
function jsonrequest($url, $ip = NULL) { $iptouse = is_null($ip) ? randomip() : $ip; $opts = array('socket' => array('bindto' => $iptouse . ':' . rand(49152, 65534))); stream_context_set_default($opts); $result = file_get_contents($url); return json_decode($result); }
public function testContainerIsReturnedFromContext() { stream_context_set_default(array('contextContainerTest' => array('Container' => 'test'))); $c = new Wrapper(); $this->assertEquals('test', $c->getContainerFromContext('contextContainerTest://file')); $this->assertEquals('test', $c->getContainerFromContext('contextContainerTest://')); $this->assertEquals('test', $c->getContainerFromContext('contextContainerTest:///file')); }
/** * {@inheritDoc} */ public function exists() { // temporarily set context to use head request stream_context_set_default(['http' => ['method' => 'HEAD']]); $headers = get_headers($this->getUrl(), 1); // set context method back to get stream_context_set_default(['http' => ['method' => 'GET']]); return stristr($headers[0], '200'); }
/** * @param string $prefix */ public function __construct(S3Client $client) { $protocol = 'dspace'; $this->client = $client; $default = stream_context_get_options(stream_context_get_default()); $default[$protocol]['client'] = $client; if (!isset($default[$protocol]['cache'])) { // Set a default cache adapter. $default[$protocol]['cache'] = new LruArrayCache(); } stream_context_set_default($default); }
/** * Get response code for REST API * - get_headers seems to be faster than wp_remote_request * - however, get_headers has no timeout * - seeing false positives from some servers * @param $url * @param $method * @return bool|int */ private function http_status($url, $method = 'GET') { // try get_headers first stream_context_set_default(array('http' => array('method' => $method))); $headers = get_headers($url); if (isset($headers[0])) { return substr($headers[0], 9, 3) === '200'; } // if get_headers fails, try wp_remote_request $args = array('method' => $method); $response = wp_remote_request($url, $args); return wp_remote_retrieve_response_code($response) === 200; }
public function testDefaultContextOptionsAreRemoved() { return; $this->markTestSkipped('Skipped until I find a way to remove eys from default context options'); stream_context_set_default(array('someContext' => array('a' => 'b'))); $fs = new FileSystem(); $scheme = $fs->scheme(); unset($fs); //provoking __destruct $options = stream_context_get_options(stream_context_get_default()); $this->assertArrayNotHasKey($scheme, $options, 'FS Context option present'); $this->assertArrayHasKey('someContext', $options, 'Previously existing context option present'); }
public function setInformation() { //Reasoning: faster, returns full headers // useful for obtaining metadata without response body //Warning: Some servers do not allow HTTP Head requests stream_context_set_default(array('http' => array('method' => 'HEAD'))); $this->information = get_headers($this->getLocation(), 1); //We need to download webpage data later on so change back to default stream_context_set_default(array('http' => array('method' => 'GET'))); if ($this->getInformation() === false) { throw new \Exception("Either url does not exist or not url, or server disabled HEAD Requests"); } }
/** * Fetch ETag. * * @return string ETag or false. */ public function get_etag() { if ($this->user != null && $this->pass != null) { stream_context_set_default(array('http' => array('header' => "Authorization: Basic " . base64_encode("{$this->user}:{$this->pass}") . "\r\n" . "User-Agent: PHP/" . PHP_VERSION))); } $headers = get_headers($this->url, 1); foreach ($headers as $key => $val) { $headers[strtolower($key)] = $val; } if (isset($headers['etag'])) { return str_replace(array("'", '"'), '', $headers['etag']); } return false; }
/** * Registers the dspace scheme */ protected function register() { if (in_array(self::PROTOCOL, stream_get_wrappers())) { stream_wrapper_unregister(self::PROTOCOL); } stream_wrapper_register(self::PROTOCOL, '\\Dspacelabs\\Component\\Filesystem\\StreamWrapper', STREAM_IS_URL); $default = stream_context_get_options(stream_context_get_default()); $default[self::PROTOCOL]['adapter'] = $this->adapter; $default[self::PROTOCOL]['logger'] = $this->logger; /** * It might be worth putting a caching layer in */ //$default[self::PROTOCOL]['cache'] = $this->cache; stream_context_set_default($default); }
/** * Tests links for twitter/url */ protected function testLink($url) { stream_context_set_default(["http" => ["method" => "HEAD"]]); try { $headers = get_headers($url); } catch (Exception $e) { return false; } foreach ($headers as $header) { if (stristr($header, "200 OK")) { return $url; } } return false; }
/** * Url Exists * * Tests whether or not a URL is legitimate by looking up the * URL headers. * * Uses error silencing on get_headers(). PHP issues warning * php_network_getaddresses: getaddrinfo on some invalid URL's * * @param string $url Url to lookup * @return Returns TRUE if the URL exists or FALSE if not. */ public static function exists($url) { if (!UrlValidator::validate($url)) { return false; } try { // Change default stream context. get_headers uses GET by default. stream_context_set_default(array('http' => array('method' => 'HEAD'))); $headers = @get_headers($url); if (!$headers || preg_match('/404/', $headers[0]) === 1) { return false; } } catch (Exception $e) { return false; } return true; }
public function __construct($environment = null, $debug = null) { // determine the environment / debug configuration based on whether or not this is running // in App Engine's Dev App Server, or in production if (is_null($debug)) { $debug = !Environment::onAppEngine(); } if (is_null($environment)) { $environment = $debug ? 'dev' : 'prod'; } parent::__construct($environment, $debug); // Symfony console requires timezone to be set manually. if (!ini_get('date.timezone')) { date_default_timezone_set('UTC'); } // Enable optimistic caching for GCS. $options = ['gs' => ['enable_cache' => true, 'enable_optimistic_cache' => true, 'read_cache_expiry_seconds' => 300]]; stream_context_set_default($options); $this->gcsBucketName = getenv('GCS_BUCKET_NAME'); }
function oldEggs() { global $dbconn; global $conf; stream_context_set_default(array('http' => array('method' => 'HEAD', 'header' => "X-ApiKey: " . $conf["apikey"]))); $result = pg_query($dbconn, 'SELECT eggid, cosmid FROM eggs WHERE cosmid < 1000000'); if (!$result) { die('SQL Error'); } while ($row = pg_fetch_assoc($result)) { $f = @get_headers("http://api.cosm.com/v2/feeds/" . urlencode($row['cosmid'])); if ($f[0] == "HTTP/1.1 404 Not Found") { $query_params = array($row['eggid']); if ($result = pg_query_params($dbconn, 'UPDATE eggs SET active = false WHERE eggid=$1', $query_params)) { echo "Cosm id " . $row["cosmid"] . " was set inactive for being deleted<br>"; } else { echo pg_last_error() . "<br>"; } } } }
public static function applyInitPathHook($url, $context = 'core') { $urlParts = AJXP_Utils::safeParseUrl($url); $repository = ConfService::getRepositoryById($urlParts["host"]); if ($repository == null) { throw new Exception("Cannot find repository"); } $credentials = AJXP_Safe::tryLoadingCredentialsFromSources($urlParts, $repository); $user = $credentials["user"]; $password = $credentials["password"]; if ($user == "") { throw new Exception("Cannot find user/pass for Remote Access!"); } $repoData = self::actualRepositoryWrapperData($urlParts["host"]); $repoProtocol = $repoData['protocol']; $default = stream_context_get_options(stream_context_get_default()); $auth = ['user' => $user, 'password' => $password]; $default[$repoProtocol]['auth'] = $auth; $default[$repoProtocol]['client']->setAuth($auth); stream_context_set_default($default); }
/** * GET an HTTP URL to retrieve its content * * @param string $url URL to get (http://...) * @param int $timeout network timeout (in seconds) * @param int $maxBytes maximum downloaded bytes (default: 4 MiB) * * @return array HTTP response headers, downloaded content * * Output format: * [0] = associative array containing HTTP response headers * [1] = URL content (downloaded data) * * Example: * list($headers, $data) = get_http_response('http://sebauvage.net/'); * if (strpos($headers[0], '200 OK') !== false) { * echo 'Data type: '.htmlspecialchars($headers['Content-Type']); * } else { * echo 'There was an error: '.htmlspecialchars($headers[0]); * } * * @see http://php.net/manual/en/function.file-get-contents.php * @see http://php.net/manual/en/function.stream-context-create.php * @see http://php.net/manual/en/function.get-headers.php */ function get_http_response($url, $timeout = 30, $maxBytes = 4194304) { $urlObj = new Url($url); if (!filter_var($url, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) { return array(array(0 => 'Invalid HTTP Url'), false); } $options = array('http' => array('method' => 'GET', 'timeout' => $timeout, 'user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:23.0)' . ' Gecko/20100101 Firefox/23.0', 'request_fulluri' => true)); $context = stream_context_create($options); stream_context_set_default($options); list($headers, $finalUrl) = get_redirected_headers($urlObj->cleanup()); if (!$headers || strpos($headers[0], '200 OK') === false) { return array($headers, false); } try { // TODO: catch Exception in calling code (thumbnailer) $content = file_get_contents($finalUrl, false, $context, -1, $maxBytes); } catch (Exception $exc) { return array(array(0 => 'HTTP Error'), $exc->getMessage()); } return array($headers, $content); }
public function createConnection($dbParams) { if (isset($dbParams['ssl']['weak'])) { stream_context_set_default(array('ssl' => array('peer_name' => 'generic-server', 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true))); } // convert errors to PDOExceptions $options = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]; // check params foreach (['host', 'database', 'user', 'password'] as $r) { if (!isset($dbParams[$r])) { throw new UserException(sprintf("Parameter %s is missing.", $r)); } } $port = isset($dbParams['port']) ? $dbParams['port'] : '3306'; $dsn = sprintf("mysql:host=%s;port=%s;dbname=%s;charset=utf8", $dbParams['host'], $port, $dbParams['database']); // SSL support $isSsl = false; if (isset($dbParams['ssl'])) { if (!empty($dbParams['ssl']['key'])) { $options[\PDO::MYSQL_ATTR_SSL_KEY] = $this->createSSLFile($dbParams['ssl']['key']); $isSsl = true; } if (!empty($dbParams['ssl']['cert'])) { $options[\PDO::MYSQL_ATTR_SSL_CERT] = $this->createSSLFile($dbParams['ssl']['cert']); $isSsl = true; } if (!empty($dbParams['ssl']['ca'])) { $options[\PDO::MYSQL_ATTR_SSL_CA] = $this->createSSLFile($dbParams['ssl']['ca']); $isSsl = true; } if (!empty($dbParams['ssl']['cipher'])) { $options[\PDO::MYSQL_ATTR_SSL_CIPHER] = $dbParams['ssl']['cipher']; } } $this->logger->info("Connecting to DSN '" . $dsn . "' " . ($isSsl ? 'Using SSL' : ''), ['options' => $options]); $pdo = new \PDO($dsn, $dbParams['user'], $dbParams['password'], $options); $pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); $pdo->exec("SET NAMES utf8;"); return $pdo; }
function curl_get_contents($url) { stream_context_set_default(array('http' => array('method' => 'HEAD'))); //var_dump($headers); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); //设置访问的url地址 //curl_setopt($ch,CURLOPT_HEADER,1); //是否显示头部信息 curl_setopt($ch, CURLOPT_TIMEOUT, 5); //设置超时 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 9.11; Windows NT'); //用户访问代理 User-Agent curl_setopt($ch, CURLOPT_REFERER, ''); //设置 referer curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //跟踪301 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回结果 $r = curl_exec($ch); curl_close($ch); return $r; }
function _request_timeout($timeout) { stream_context_set_default(array('http' => array('timeout' => (int) $timeout))); }
/** * Register the 's3://' stream wrapper * * @param S3Client $client Client to use with the stream wrapper * @param string $protocol Protocol to register as. * @param CacheInterface $cache Default cache for the protocol. */ public static function register(S3Client $client, $protocol = 's3', CacheInterface $cache = null) { if (in_array($protocol, stream_get_wrappers())) { stream_wrapper_unregister($protocol); } // Set the client passed in as the default stream context client stream_wrapper_register($protocol, get_called_class(), STREAM_IS_URL); $default = stream_context_get_options(stream_context_get_default()); $default[$protocol]['client'] = $client; if ($cache) { $default[$protocol]['cache'] = $cache; } elseif (!isset($default[$protocol]['cache'])) { // Set a default cache adapter. $default[$protocol]['cache'] = new LruArrayCache(); } stream_context_set_default($default); }
* Google MAPs API key for locations to display map * * Obtain key: Go to your Google Console (https://console.developers.google.com) and enable "Google Maps JavaScript API" * from overview tab, so go to Credentials tab and make an API key for your project. */ $gmaps_api_key = ""; /* proxy connection details ******************************/ $proxy_enabled = false; # Enable/Disable usage of the Proxy server $proxy_server = "myproxy.something.com"; # Proxy server FQDN or IP $proxy_port = "8080"; # Proxy server port $proxy_user = "******"; # Proxy Username $proxy_pass = "******"; # Proxy Password $proxy_use_auth = false; # Enable/Disable Proxy authentication /** * proxy to use for every internet access like update check */ $proxy_auth = base64_encode("{$proxy_user}:{$proxy_pass}"); if ($proxy_enabled == true && $proxy_use_auth == false) { stream_context_set_default(array('http' => array('proxy' => 'tcp://' . $proxy_server . ':' . $proxy_port))); } elseif ($proxy_enabled == true && $proxy_use_auth == true) { stream_context_set_default(array('http' => array('proxy' => "tcp://{$proxy_server}:{$proxy_port}", 'request_fulluri' => true, 'header' => "Proxy-Authorization: Basic {$proxy_auth}"))); } /* for debugging proxy config uncomment next line */ #var_dump(stream_context_get_options(stream_context_get_default()));
/** * Establece directivas y rutinas de proteccion contra ataques * [USADA POR EL SISTEMA] */ public static function directives() { $options = \Raptor\Raptor::getInstance()->getConfigurationLoader()->getConfOption(); if (isset($options['raptor']['session_expire'])) { ini_set('session.cookie_lifetime', intval($options['raptor']['session_expire'])); } else { ini_set('session.cookie_lifetime', 0); } ini_set('session.cookie_httponly', true); ini_set('session.use_only_cookies', true); $savePath = \Raptor\Core\Location::get(\Raptor\Core\Location::APP) . '/Sessions'; if (!file_exists($savePath)) { @mkdir($savePath); } session_save_path($savePath); if (isset($options['raptor']['proxy'])) { $parts = explode('@', $options['raptor']['proxy']); $header = array(); $proxy = ''; if (count($parts) == 2) { $auth = base64_encode($parts[0]); $header[] = "Proxy-Authorization: Basic {$auth}"; $proxy = $parts[1]; } else { $proxy = $parts[0]; } stream_context_set_default(array('http' => array('proxy' => "tcp://{$proxy}", 'request_fulluri' => true, 'method' => "GET", 'user_agent' => 'Mozilla/5.0', 'header' => $header))); } }
/** * Either calls editor's save function or handles file as a stream. * * @since 3.5.0 * @access protected * * @param string|stream $filename * @param callable $function * @param array $arguments * @return boolean */ protected function make_image($filename, $function, $arguments) { // Setup the stream wrapper context $default = stream_context_get_options(stream_context_get_default()); $gcs_opts = ['gs' => ['acl' => 'public-read']]; switch ($function) { case 'imagepng': $gcs_opts['gs']['Content-Type'] = 'image/png'; break; case 'imagejpeg': $gcs_opts['gs']['Content-Type'] = 'image/jpeg'; break; case 'imagegif': $gcs_opts['gs']['Content-Type'] = 'image/gif'; break; } $context = array_merge($default, $gcs_opts); stream_context_set_default($context); // Work around bug in core WordPress // http://core.trac.wordpress.org/ticket/24459 $arguments[1] = null; $result = parent::make_image($filename, $function, $arguments); // Restore the default wrapper context stream_context_set_default($default); return $result; }
function getRedirectUrl($url) { stream_context_set_default(array('http' => array('method' => 'HEAD'))); $headers = get_headers($url, 1); if ($headers !== false && isset($headers['Location'])) { return $headers['Location']; } return false; }