Esempio n. 1
0
 public function sendBuffer($id)
 {
     if (!isset($this->buffers[$id])) {
         return FALSE;
     }
     if (!isset($this->buffers[$id]['raw'])) {
         $this->addAutomaticHeaders($id);
         NginyUS::message('Reply code : $0', array($this->buffers[$id]['code']), E_DEBUG);
         $text = 'HTTP/1.1 ' . $this->buffers[$id]['code'] . " " . $this->replyStr[$this->buffers[$id]['code']] . "\n";
         foreach ($this->buffers[$id]['headers'] as $ref => $header) {
             $text .= $ref . ': ' . $header . "\r\n";
         }
         $text .= "\r\n" . $this->buffers[$id]['data'];
     } else {
         $text = $this->buffers[$id]['raw'];
     }
     $this->sendData($id, $text);
     unset($this->buffers[$id]);
     //$this->closeConnection($id);
 }
Esempio n. 2
0
 public function addClasses($classes)
 {
     NginyUS::message('Adding classes $0', array(join(', ', $classes)), E_DEBUG);
     $this->classList = array_merge($this->classList, $classes);
 }
Esempio n. 3
0
        }
        echo date("m/d/Y h:i:s A") . ' -- ' . $prefix . ' -- ' . $message . PHP_EOL;
    }
}
//Basic replacement for Storage
class Storage
{
    public function __construct($array)
    {
        foreach ($array as $name => $value) {
            $this->{$name} = $value;
        }
    }
}
chdir('../../');
include 'lib/nginyus/nginyus.php';
include 'lib/moap/moapserver.php';
NginyUS_load('lib/nginyus');
$server = new NginyUS();
$server->setAddress('0.0.0.0', 3000);
$manager = $server->manageSites();
$manager->newSite('admin');
$manager->loadConfig('admin', array('SiteRoot' => '127.0.0.1/admin', 'Alias' => 'bender.koinko.in/admin, bender.nyan.at/admin', 'DocumentRoot' => 'web', 'ProcessFiles' => 'local.php'));
$manager->newSite('webservice');
$manager->loadConfig('webservice', array('SiteRoot' => '127.0.0.1/api', 'Alias' => 'bender.koinko.in/api, bender.nyan.at/api', 'DocumentRoot' => 'web', 'ProcessFiles' => 'webservice.php'));
pcntl_signal(SIGTERM, array($server, 'stop'));
$server->connect();
while (1) {
    $server->process();
    usleep(1000);
}
Esempio n. 4
0
 public function setSiteRoot($root)
 {
     NginyUS::message('[$0] New SiteRoot $1', array($this->name, $root), E_DEBUG);
     $this->siteRoot = $root;
 }
Esempio n. 5
0
 public function parseQuery($id, $query)
 {
     NginyUS::message("New query from \$0", array($id), E_DEBUG);
     if (!$query) {
         return FALSE;
     }
     $data = array();
     socket_getpeername($this->clients[$id], $data['addr']);
     $data['raw'] = $query;
     $query = explode("\r\n\r\n", $query);
     $metadata = explode("\r\n", $query[0]);
     $_POST = array();
     $data['query'] = 'GET';
     $_SERVER = array();
     foreach ($metadata as $row) {
         $row = explode(' ', $row, 2);
         switch ($row[0]) {
             case 'POST':
                 parse_str($query[1], $_POST);
                 if (is_array($_POST)) {
                     NginyUS::message("Received POST data : \$0", array($this->dumpArray($_POST)), E_DEBUG);
                 } else {
                     NginyUS::message("Received POST data : \$0", array($data['rawPOST']), E_DEBUG);
                 }
                 $data['rawPOST'] = $query[1];
             case 'OPTIONS':
             case 'GET':
                 //It's a GET request (main parameter)
                 $_SERVER['REQUEST_METHOD'] = $data['query'] = $row[0];
                 $data['page'] = explode(' ', $row[1]);
                 $data['page'] = $data['page'][0];
                 NginyUS::message('Requested page : $0', array($data['page']), E_DEBUG);
                 break;
             case 'Host:':
                 $host = explode(':', $row[1], 2);
                 $data['host'] = $host[0];
                 $data['port'] = isset($host[1]) ? $host[1] : NULL;
                 break;
             case 'Connection:':
                 if ($row[1] == 'keep-alive') {
                     $data['keep-alive'] = TRUE;
                 }
                 break;
             case 'User-Agent:':
                 array_shift($row);
                 $data['user-agent'] = join(' ', $row);
                 break;
             default:
                 $data[substr($row[0], 0, -1)] = $row[1];
                 break;
         }
         if (isset($row[1])) {
             $_SERVER[substr($row[0], 0, -1)] = $row[1];
         }
     }
     $data['url'] = $data['host'] . $data['page'];
     $this->siteManager->pageCall($id, $data);
 }