/** Loads the webserver and configures it. * This function loads the webserver and configures it from the data given in argument. * * \param $config Configuration data * * \return TRUE if server loaded successfully, FALSE otherwise. */ public function load($config) { Leelabot::message('Loading OuterAPI...'); include 'lib/nginyus/nginyus.php'; NginyUS_load('lib/nginyus/'); $this->_server = new NginyUS(); //Checking validity of the IP/Port couple if (!isset($config['BindAddress']) || !isset($config['BindPort']) || !in_array($config['BindPort'], range(0, 65535)) || !filter_var($config['BindAddress'], FILTER_VALIDATE_IP)) { Leelabot::message('Bind address/port not found or incorrect', array(), E_WARNING); return FALSE; } $this->_server->setAddress($config['BindAddress'], $config['BindPort']); //Getting the SiteManager $this->_manager = $this->_server->manageSites(); //Loading the webservice if (isset($config['Webservice']) && (!isset($config['Webservice']['Enable']) || Leelabot::parseBool($config['Webservice']['Enable']))) { Leelabot::message('Loading Webservice...'); $this->_WSEnabled = TRUE; $WSConfig = $config['Webservice']; //Including the MLPFIM Webservice class include 'lib/mlpfim/mlpfimserver.php'; //If there is aliases, we update them to add the API path to them if (!empty($WSConfig['Aliases'])) { $newAliases = array(); foreach (explode(',', $WSConfig['Aliases']) as $alias) { $newAliases[] = trim($alias) . '/api'; } $WSConfig['Aliases'] = join(', ', $newAliases); } else { $WSConfig['Aliases'] = ''; } //Creating site for that $this->_manager->newSite('webservice'); $site = $this->_manager->getSite('webservice'); $this->_manager->loadConfig('webservice', array('SiteRoot' => $config['BindAddress'] . '/api', 'Alias' => $WSConfig['Aliases'], 'DocumentRoot' => '.', 'ProcessFiles' => 'core/webservice.class.php')); if (isset($WSConfig['Authentication']) && Leelabot::parseBool($WSConfig['Authentication']) == TRUE && isset($WSConfig['AuthFile']) && is_file(Leelabot::$instance->getConfigLocation() . '/' . $WSConfig['AuthFile'])) { $this->_WSAuth = TRUE; $WSConfig['AuthFile'] = Leelabot::$instance->getConfigLocation() . '/' . $WSConfig['AuthFile']; $this->_WSAuthFile = $WSConfig['AuthFile']; } else { Leelabot::message('Using Webservice without authentication is not secure !', array(), E_WARNING, TRUE); } } //Loading the webadmin if (isset($config['Webadmin']) && (!isset($config['Webadmin']['Enable']) || Leelabot::parseBool($config['Webadmin']['Enable']))) { Leelabot::message('Loading Webadmin...'); $this->_WAEnabled = TRUE; $WAConfig = $config['Webadmin']; //If there is aliases, we update them to add the admin path to them if (!empty($WAConfig['Aliases'])) { $newAliases = array(); foreach (explode(',', $WAConfig['Aliases']) as $alias) { $newAliases[] = trim($alias) . '/admin'; } $WAConfig['Aliases'] = join(', ', $newAliases); } else { $WAConfig['Aliases'] = ''; } //Creating the site in the webserver $this->_manager->newSite('webadmin'); $site = $this->_manager->getSite('webadmin'); $this->_manager->loadConfig('webadmin', array('SiteRoot' => $config['BindAddress'] . '/admin', 'Alias' => $WAConfig['Aliases'], 'DocumentRoot' => '.', 'ProcessFiles' => 'web/controllers/dispatcher.class.php')); if (isset($WAConfig['Authentication']) && Leelabot::parseBool($WAConfig['Authentication']) == TRUE && isset($WAConfig['AuthFile']) && is_file(Leelabot::$instance->getConfigLocation() . '/' . $WAConfig['AuthFile'])) { $this->_WAAuth = TRUE; $WAConfig['AuthFile'] = Leelabot::$instance->getConfigLocation() . '/' . $WAConfig['AuthFile']; $this->_WAAuthFile = $WAConfig['AuthFile']; } else { Leelabot::message('Using Webadmin without authentication is not secure !', array(), E_WARNING, TRUE); } } $this->_server->connect(); //Setting InnerAPI classes if (!empty($this->_manager->getSite('webadmin')->classes['LeelabotAdmin'])) { Webadmin::setWAObject($this->_manager->getSite('webadmin')->classes['LeelabotAdmin']); } if (!empty($this->_manager->getSite('webadmin')->classes['LeelabotAdmin'])) { $this->_manager->getSite('webadmin')->classes['LeelabotAdmin']->setAuthentication($this->_WAAuth, $this->_WAAuthFile); } if (!empty($this->_manager->getSite('webadmin')->classes['LeelabotAdmin'])) { $this->_manager->getSite('webservice')->classes['LeelabotWebservice']->setAuthentication($this->_WSAuth, $this->_WSAuthFile); } }
} 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); }