/**
  * Parses users configuration and stores it in a structured array.
  *
  * @since 5.1
  * @return void
  */
 public function parseConfig()
 {
     $context = \Innomatic\Module\Server\ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext');
     $xmldoc = simplexml_load_file($context->getHome() . 'core/conf/modules-users.xml');
     $this->structure = array();
     foreach ($xmldoc->user as $user) {
         $userStr = "{$user->username}";
         $this->structure[$userStr]['password'] = "******";
         // Give admin user access to all Modules.
         // Admin user has no DASN.
         if ($userStr == 'admin') {
             foreach ($context->getModuleList() as $module) {
                 $this->structure[$userStr]['modules'][$module] = '';
             }
         } else {
             foreach ($user->allowedmodules as $allowedmodules) {
                 foreach ($allowedmodules->allowedmodule as $allowedmodule) {
                     $this->structure[$userStr]['modules']["{$allowedmodule->modulelocation}"] = "{$allowedmodule->moduledasn}";
                 }
             }
         }
         foreach ($user->allowedactions as $allowedactions) {
             foreach ($allowedactions->allowedaction as $allowedaction) {
                 $this->structure[$userStr]['actions']["{$allowedaction}"] = 1;
             }
         }
     }
 }
 /**
  * Undeploys a Module in the Module server.
  *
  * @param string $location Module name.
  * @return boolean
  * @since 5.1
  */
 public function undeploy($location)
 {
     // Checks if the specified Module exists.
     $context = \Innomatic\Module\Server\ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext');
     if (!is_dir($context->getHome() . 'core/modules' . DIRECTORY_SEPARATOR . $location)) {
         throw new \Innomatic\Module\ModuleException('No such Module');
     }
     // Executes Module undeploy hooked actions.
     $auth = \Innomatic\Module\Server\ModuleServerAuthenticator::instance('ModuleServerAuthenticator');
     $module = \Innomatic\Module\ModuleFactory::getModule(new ModuleLocator('module://*****:*****@/' . $location));
     $module->undeploy();
     // Removes Module.
     \Innomatic\Io\Filesystem\DirectoryUtils::unlinkTree($context->getHome() . 'core/modules' . DIRECTORY_SEPARATOR . $location);
     // Logs undeployment.
     if ($context->getConfig()->getKey('log_deployer_events') == 1 or $context->getConfig()->useDefaults()) {
         $logger = new \Innomatic\Module\Server\ModuleServerLogger($context->getHome() . 'core/log/module-deployer.log');
         $logger->logEvent($location . ' undeployed');
     }
     return true;
 }
 /**
  * Parses Module registry configuration from an XML file downloaded from a remote server;
  * then stores it in a structured array.
  *
  * @param string $host the host from which the registry has to be loaded
  * @param string $port the port on the remote host
  * @since 5.1
  * @return void
  */
 private function downloadRemoteRegistry($address, $port)
 {
     print "downloadRemoteRegistry: inizio\r\n";
     $result = '';
     try {
         $auth = \Innomatic\Module\Server\ModuleServerAuthenticator::instance('ModuleServerAuthenticator');
         $socket = new \Innomatic\Net\Socket\Socket();
         $socket->connect($address, $port);
         $request = 'GET_REGISTRY Module/1.1' . "\r\n";
         $request .= 'User: admin' . "\r\n";
         $request .= 'Password: '******'admin') . "\r\n";
         print "Request content:\r\n" . $request . "\n";
         $socket->write($request);
         $result = trim($socket->readAll());
         print "Result content:\r\n" . $result . "\n";
         $socket->disconnect();
     } catch (\Innomatic\Net\Socket\SocketException $e) {
         $result = "Module: services-extension cannot download up-to-date registry from {$address}:{$port}";
     }
     $context = \Innomatic\Module\Server\ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext');
     $file_registry = fopen($context->getHome() . 'core/conf/modules-netregistry-remote.xml', 'x');
     if ($file_registry == false) {
         unlink($context->getHome() . 'core/conf/modules-netregistry-remote.xml');
         $file_registry = fopen($context->getHome() . 'core/conf/modules-netregistry-remote.xml', 'x');
     }
     fwrite($file_registry, $result);
     fclose($file_registry);
 }
 /**
  * Object constructor.
  *
  * @param string $location Module name.
  * @since 5.1
  */
 public function __construct($location)
 {
     $serverContext = \Innomatic\Module\Server\ModuleServerContext::instance('moduleservercontext');
     $this->location = $location;
     $this->home = $serverContext->getHome() . 'modules' . DIRECTORY_SEPARATOR . $location . DIRECTORY_SEPARATOR;
 }
 /**
  * force the ModuleServiceSocketHandler to refresh the registry
  *
  * @since 5.1
  */
 protected function force_refresh()
 {
     print "force_refresh" . "\n";
     $request = '';
     $address = '127.0.0.1';
     $context = \Innomatic\Module\Server\ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext');
     try {
         $port = $context->getConfig()->getKey('service_port');
         $this->socket->connect($address, $port);
         $request = 'REFRESH Module/1.1' . "\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) {
         print "Cannot refresh: server " . $address . ":" . $port . " down!" . "\n";
     }
     print $result;
 }