/** * Actions executed at socket server startup. * * During this method execution, loggers are started and garbage collecting * process is launched. * * @since 5.1 */ public function onStart() { $context = ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext'); if ($context->getConfig()->getKey('log_server_events') == 1 or $context->getConfig()->useDefaults()) { $this->serverLogEnabled = true; $this->serverLogger = new ModuleServerLogger($context->getHome() . 'core/log' . DIRECTORY_SEPARATOR . 'module-server.log'); } if ($context->getConfig()->getKey('log_access_events') == 1) { $this->accessLogEnabled = true; $this->accessLogger = new ModuleServerLogger($context->getHome() . 'core/log' . DIRECTORY_SEPARATOR . 'module-access.log'); } \Innomatic\Module\Session\ModuleSessionGarbageCollector::clean(); $this->authenticator = ModuleServerAuthenticator::instance('ModuleServerAuthenticator'); if ($this->serverLogEnabled) { $this->serverLogger->logEvent('Start'); } register_shutdown_function(array($this, 'onHalt')); print 'Module server started and listening at port ' . $this->serversocket->getPort() . "\n"; }
/** * Gets an instance of a local Module object. * * This static method retrieves a Module located in local context, without * using the Module server. Module authentication is needed anyway. * * The method also builds the configuration for the Module. * * @since 5.1 * @param ModuleLocator $locator Module locator object. * @return ModuleObject The Module object. */ public static function getLocalModule(ModuleLocator $locator) { $location = $locator->getLocation(); // Authenticates $authenticator = ModuleServerAuthenticator::instance('ModuleServerAuthenticator'); if (!$authenticator->authenticate($locator->getUsername(), $locator->getPassword())) { throw new ModuleException('Not authorized'); } $context = ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext'); // Checks if Module exists $classes_dir = $context->getHome() . 'core/modules/' . $location . '/classes/'; if (!is_dir($classes_dir)) { throw new ModuleException('Module does not exists'); } // Checks if configuration file exists $moduleXml = $context->getHome() . 'core/modules/' . $location . '/setup/module.xml'; if (!file_exists($moduleXml)) { throw new ModuleException('Missing module.xml configuration file'); } $cfg = \Innomatic\Module\Util\ModuleXmlConfig::getInstance($moduleXml); $fqcn = $cfg->getFQCN(); // Builds Module Data Access Source Name $dasn_string = $authenticator->getDASN($locator->getUsername(), $locator->getLocation()); if (strpos($dasn_string, 'context:')) { $module_context = new ModuleContext($location); $dasn_string = str_replace('context:', $module_context->getHome(), $dasn_string); } $cfg->setDASN(new DataAccessSourceName($dasn_string)); // Adds Module classes directory to classpath // TODO: Should add include path only if not already available set_include_path($classes_dir . PATH_SEPARATOR . get_include_path()); require_once $fqcn . '.php'; // Retrieves class name from Fully Qualified Class Name $class = strpos($fqcn, '/') ? substr($fqcn, strrpos($fqcn, '/') + 1) : $fqcn; // Instantiates the new class and returns it return new $class($cfg); }
/** * stops the pinger * (starts the pinger shuting down sequence) * * @see ModulePinger.php * @since 5.1 * @return string Server result string. */ private function stopPinger() { $result = ''; $auth = ModuleServerAuthenticator::instance('ModuleServerAuthenticator'); $context = ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext'); $this->socket->connect('127.0.0.1', $context->getConfig()->getKey('pinger_port')); $request = 'SHUTDOWN Module/1.0' . "\r\n"; $request .= 'User: admin' . "\r\n"; $request .= 'Password: '******'admin') . "\r\n"; $this->socket->write($request); $result = $this->socket->readAll(); $this->socket->disconnect(); }
/** * Forces the server to refresh its configuration. * * @since 5.1 * @return string Server result string. */ public function refresh() { try { $result = ''; $auth = ModuleServerAuthenticator::instance('ModuleServerAuthenticator'); $this->socket->connect($this->host, $this->port); $request = 'REFRESH Module/1.0' . "\r\n"; $request .= 'User: admin' . "\r\n"; $request .= 'Password: '******'admin') . "\r\n"; $this->socket->write($request); $result = $this->socket->readAll(); $this->socket->disconnect(); } catch (\Innomatic\Net\Socket\SocketException $e) { $result = 'Module server is down.' . "\n"; } return $result; }
/** * Actions executed at socket server startup. * * During this method execution, loggers are started and garbage collecting * process is launched. * * @since 5.1 */ public function onStart() { //OK $context = ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext'); if ($context->getConfig()->getKey('log_server_events') == 1 or $context->getConfig()->useDefaults()) { $this->serverLogEnabled = true; $this->serverLogger = new ModuleServerLogger($context->getHome() . 'core/log/module-services.log'); } if ($context->getConfig()->getKey('log_access_events') == 1) { $this->accessLogEnabled = true; $this->accessLogger = new ModuleServerLogger($context->getHome() . 'core/log/module-access.log'); } \Innomatic\Module\Session\ModuleSessionGarbageCollector::clean(); $this->authenticator = ModuleServerAuthenticator::instance('ModuleServerAuthenticator'); if ($this->serverLogEnabled) { $this->serverLogger->logEvent('Start'); } //loading net-registry $this->registryHandler = new ModuleRegistryHandler(); $this->registryHandler->parseRegistry(); Runtime::getInstance()->addShutdownHook($this, 'onHalt'); print 'Module: services-extension started and listening at port ' . $this->serversocket->getPort() . "\n"; }