function testPage() { $url = DATAFACE_SITE_URL . '/tests/testsites/site1/index.html'; $site = new Dataface_Record('websites', array()); $site->setValues(array('website_url' => df_absolute_url(DATAFACE_SITE_URL . '/tests/testsites/site1/'), 'source_language' => 'en', 'target_language' => 'fr', 'website_name' => 'Site 1 French', 'active' => 1, 'base_path' => DATAFACE_SITE_URL . '/proxies/site1/', 'host' => $_SERVER['HTTP_HOST'])); $site->save(); df_q("delete from site_text_filters where website_id='" . addslashes($site->val('website_id')) . "'"); $server = new ProxyServer(); $server->site = SweteSite::loadSiteById($site->val('website_id')); $server->SERVER = array('REQUEST_METHOD' => 'get'); $server->URL = df_absolute_url(DATAFACE_SITE_URL . '/proxies/site1/index.html'); $server->buffer = true; $server->handleRequest(); $doc = new DOMDocument(); $doc->loadHtml(file_get_contents('tests/testsites/site1_output/index.out.html')); $expected = $doc->saveHtml(); //echo $server->contentBuffer; $doc2 = new DOMDocument(); $doc2->loadHtml($server->contentBuffer); $actual = $doc2->saveHtml(); //$this->assertEquals(trim($expected), trim($actual)); // Cancelled this test because WTF!!!! Even if I print the actual output, copy it to the file // and compare it to itself, it still fails!!!! WTF!!!! }
public function run() { //内网api调用 if ($this->_checkInnerApi()) { //如果有其他调试输出忽略 ob_start(); define("USE_INNER_API", 1); Pi::inc(PI_CORE . 'Proxy.php'); ProxyServer::Server(); } else { //初始化pipe $default_pipe = array('ApiReqPipe' => 'default', 'ApiHttpRouterPipe' => 'default'); $pipes = Pi::get('global.pipes', array()); if (empty($pipes)) { $pipes = $default_pipe; } $this->pipeLoadContainer = $pipes; parent::run(); } }
} function onShutdown($serv) { echo "Server: onShutdown\n"; } function onClose($serv, $fd, $from_id) { } function onConnect($serv, $fd, $from_id) { } function onReceive($serv, $fd, $from_id, $data) { $socket = new swoole_client(SWOOLE_SOCK_TCP); echo "send data:\n" . $data . "\n"; if ($socket->connect('www.baidu.com', 80, 1)) { $socket->send($data); while (1) { $recv = $socket->recv(8000, 0); echo "recv data:\n" . $recv . "\n"; if (strlen($recv) > 0) { $serv->send($fd, $recv); } } } // unset($socket); // $serv->close($fd); } } $serv = new ProxyServer(); $serv->run();
function createLiveJobWithTranslationMisses() { $siteRec = $this->liveSite; $job = SweteJob::createJob($this->liveSite); $this->assertFalse($job->getRecord()->val('compiled'), 'Job is not compiled yet but has compiled flag set.'); // Create a translation miss $server = new ProxyServer(); $server->logger->saveBodies = true; $server->site = $this->liveSite; $server->SERVER = array('REQUEST_METHOD' => 'get'); $server->URL = $server->site->getProxyUrl() . 'index.html'; $server->buffer = true; $server->logTranslationMisses = true; SweteDb::q('commit'); $server->handleRequest(); // We should have some misses: $res = SweteDb::q("select count(*) from translation_miss_log where website_id='" . addslashes($siteRec->getRecord()->val('website_id')) . "'"); list($num) = mysql_fetch_row($res); @mysql_free_result($res); $this->assertEquals(13, $num, 'There should be 13 misses in our translation log.'); $misses = df_get_records_array('translation_miss_log', array('website_id' => '=' . $siteRec->getRecord()->val('website_id'))); foreach ($misses as $miss) { $job->addTranslationMiss($miss->val('translation_miss_log_id')); } return $job; }
function handle($params) { global $ORIG_POST, $ORIG_REQUEST, $ORIG_GET; $_GET = $ORIG_GET; $_POST = $ORIG_POST; $_REQUEST = $ORIG_REQUEST; @session_write_close(); $app = Dataface_Application::getInstance(); $query = $app->getQuery(); //print_r($_SERVER); $url = implode('/', array_map('rawurlencode', explode('/', $_SERVER['REDIRECT_URL']))); $url = str_replace("%3A", ":", $url); if (isset($_SERVER['REQUEST_URI'])) { if (strpos($_SERVER['REQUEST_URI'], '?') !== false) { list($junk, $_SERVER['REDIRECT_QUERY_STRING']) = explode('?', $_SERVER['REQUEST_URI']); } else { $_SERVER['REDIRECT_QUERY_STRING'] = ''; } } $sweteDirectives = array(); if (@$_SERVER['REDIRECT_QUERY_STRING']) { $qstr = $_SERVER['REDIRECT_QUERY_STRING']; $parts = explode('&', $qstr); $qstrout = array(); foreach ($parts as $pt) { if (preg_match('/^swete\\:/', $pt)) { list($d1, $d2) = explode('=', $pt); $sweteDirectives[urldecode($d1)] = urldecode($d2); } else { $qstrout[] = $pt; } } $url .= '?' . implode('&', $qstrout); } $url = df_absolute_url($url); //echo "The URL: ".$url; //echo "$url";exit; $site = SweteSite::loadSiteByUrl($url); if (!$site and $url and $url[strlen($url) - 1] != '/') { $url .= '/'; $site = SweteSite::loadSiteByUrl($url); if ($site) { header('Location: ' . $url); exit; } } if (!$site) { die("[ERROR] No site found"); } $server = new ProxyServer(); if (defined('SWETE_USE_HTML5_PARSER') and SWETE_USE_HTML5_PARSER) { $server->useHtml5Parser = true; } if (@$_POST['swete:input']) { if (@$_POST['swete:key'] and @$_POST['swete:salt']) { if (is_numeric($_POST['swete:salt'])) { $salt = intval($_POST['swete:salt']); if (abs($salt - time()) < 3600) { $password = $site->getRecord()->val('webservice_secret_key'); if ($password) { $key = sha1($_POST['swete:salt'] . $password); //if ( $key === $_POST['swete:key'] ){ if (strcasecmp($key, $_POST['swete:key']) === 0) { $server->inputContent = $_POST['swete:input']; if (@$_POST['swete:content-type']) { $server->inputContentType = $_POST['swete:content-type']; } } else { die("[ERROR] Incorrect Key"); } } else { die("[ERROR] No secret key set in the website settings."); } } else { die("[ERROR] Invalid salt value"); } } else { die("[ERROR] Invalid salt value. Salt must be an integer"); } } else { die("[ERROR] Both swete:key and swete:salt must be provided"); } } //$server->buffer = true; $server->logTranslationMisses = true; $server->site = $site; if ($site->getRecord()->val('log_requests')) { if (isset($server->logger)) { $server->logger->requestLoggingEnabled = true; } } else { if (isset($server->logger)) { $server->logger->requestLoggingEnabled = false; } } if ($site->getRecord()->val('log_translation_misses')) { $server->logTranslationMisses = true; if (isset($server->logger)) { // If we are logging translation misses we also need to log requests $server->logger->requestLoggingEnabled = true; } } else { $server->logTranslationMisses = false; } $server->URL = $url; // Deal with live cache // The first time a page is requested, it won't yet have a livecache // descriptor, so we needed to wait until we had loaded the // site so we can calculate the unproxified url. // Then we will try to flush it again. $isPost = strtolower($server->SERVER['REQUEST_METHOD']) === 'post'; if (class_exists('LiveCache')) { $server->liveCache = LiveCache::getCurrentPage(); if (!$isPost and !isset($server->liveCache->unproxifiedUrl)) { $server->liveCache->unproxifiedUrl = $server->site->getProxyWriter()->unproxifyUrl($server->URL); $server->liveCache->logger = $server->logger; $server->liveCache->flush(); } } // $server->handleRequest(); //print_r($server->headerBuffer); //$site = SweteSite::loadSiteByUrl( }