Example #1
0
 public function generateApplicationFromRow($row)
 {
     if (!isset($row['id']) || !isset($row['name']) || !isset($row['type']) || !isset($row['executable_path']) || !isset($row['published'])) {
         // no right attribute, we do nothing
         Logger::info('main', 'ApplicationDB_sql::getList app not insert');
         // todo right the content
         return NULL;
     } else {
         if (!isset($row['package'])) {
             $row['package'] = NULL;
         }
         if ($row['type'] == 'weblink') {
             $r = new Application_weblink($row['id'], $row['name'], $row['description'], $row['executable_path']);
             unset($row['id']);
             unset($row['name']);
             unset($row['description']);
             unset($row['type']);
             unset($row['executable_path']);
             unset($row['package']);
             unset($row['desktopfile']);
         } elseif ($row['type'] == 'webapp') {
             $r = new Application_webapp($row['id'], $row['name'], $row['description']);
             unset($row['id']);
             unset($row['name']);
             unset($row['description']);
             unset($row['type']);
             unset($row['executable_path']);
             unset($row['package']);
             unset($row['desktopfile']);
         } else {
             $r = new Application($row['id'], $row['name'], $row['description'], $row['type'], $row['executable_path'], $row['package'], $row['published']);
             Logger::debug('main', 'ApplicationDB::load_mimetypes');
             $liaisons = Abstract_Liaison::load('ApplicationMimeType', $r->getAttribute('id'), NULL);
             if (is_array($liaisons)) {
                 $mimetypes = array();
                 foreach ($liaisons as $group => $liaison) {
                     $mimetypes[] = $group;
                 }
                 $r->setMimeTypes($mimetypes);
             }
         }
         foreach ($row as $key => $value) {
             $r->setAttribute($key, $value);
         }
         return $r;
     }
 }
Example #2
0
 public function updateApplications()
 {
     Logger::debug('main', 'Server::updateApplications');
     if (!is_array($this->roles) || !array_key_exists(Server::SERVER_ROLE_APS, $this->roles)) {
         Logger::critical('main', 'SERVER::updateApplications - Not an ApS');
         return false;
     }
     if (!$this->isOnline()) {
         Logger::debug('main', 'Server::updateApplications server "' . $this->fqdn . ':' . $this->web_port . '" is not online');
         return false;
     }
     $applicationDB = ApplicationDB::getInstance();
     $xml = query_url($this->getBaseURL() . '/aps/applications');
     if (!$xml) {
         $this->isUnreachable();
         Logger::error('main', 'Server::updateApplications server \'' . $this->fqdn . '\' is unreachable');
         return false;
     }
     if (!is_string($xml)) {
         Logger::error('main', 'Server::updateApplications invalid xml1');
         return false;
     }
     if (substr($xml, 0, 5) == 'ERROR') {
         $this->returnedError();
         Logger::error('main', 'Server::updateApplications invalid xml2');
         return false;
     }
     if ($xml == '') {
         Logger::error('main', 'Server::updateApplications invalid xml3');
         return false;
     }
     $dom = new DomDocument('1.0', 'utf-8');
     @$dom->loadXML($xml);
     $root = $dom->documentElement;
     // before adding application, we remove all previous applications
     $previous_liaison = Abstract_Liaison::load('ApplicationServer', NULL, $this->fqdn);
     // see end of function
     $current_liaison_key = array();
     $application_node = $dom->getElementsByTagName("application");
     $sync_apps = array();
     foreach ($application_node as $app_node) {
         $app_name = '';
         $app_description = '';
         $app_path_exe = '';
         $app_path_args = NULL;
         $app_package = NULL;
         $app_desktopfile = NULL;
         if ($app_node->hasAttribute("name")) {
             $app_name = $app_node->getAttribute("name");
         }
         if ($app_node->hasAttribute("description")) {
             $app_description = $app_node->getAttribute("description");
         }
         if ($app_node->hasAttribute("package")) {
             $app_package = $app_node->getAttribute("package");
         }
         if ($app_node->hasAttribute("desktopfile")) {
             $app_desktopfile = $app_node->getAttribute("desktopfile");
         }
         $local_id = $app_node->getAttribute("id");
         $exe_node = $app_node->getElementsByTagName('executable')->item(0);
         if ($exe_node->hasAttribute("command")) {
             $command = $exe_node->getAttribute("command");
             $command = str_replace(array("%U", "%u", "%c", "%i", "%f", "%m"), "", $command);
             $app_path_exe = trim($command);
         }
         $mimetypes = array();
         $mime_nodes = $app_node->getElementsByTagName('mime');
         foreach ($mime_nodes as $mime_node) {
             if (!$mime_node->hasAttribute("type")) {
                 continue;
             }
             $mimetypes[] = $mime_node->getAttribute("type");
         }
         $a = new Application(NULL, $app_name, $app_description, $this->getAttribute('type'), $app_path_exe, $app_package, true, $app_desktopfile);
         $a->setMimeTypes($mimetypes);
         $a_search = $applicationDB->search($app_name, $app_description, $this->getAttribute('type'), $app_path_exe);
         if (is_object($a_search)) {
             //already in DB
             // echo $app_name." already in DB\n";
             $a = $a_search;
         } else {
             // echo $app_name." NOT in DB\n";
             if ($applicationDB->isWriteable() == false) {
                 Logger::debug('main', 'Server::updateApplications applicationDB is not writeable');
             } else {
                 if ($applicationDB->add($a) == false) {
                     //echo 'app '.$app_name." not insert<br>\n";
                     return false;
                 }
             }
         }
         if ($applicationDB->isWriteable() == true) {
             if ($applicationDB->isOK($a) == true) {
                 // we add the app to the server
                 if (!is_object(Abstract_Liaison::load('ApplicationServer', $a->getAttribute('id'), $this->fqdn))) {
                     $ret = Abstract_Liaison::save('ApplicationServer', $a->getAttribute('id'), $this->fqdn);
                     if ($ret === false) {
                         Logger::error('main', 'Server::updateApplications failed to save application');
                         return $ret;
                     }
                 }
                 $current_liaison_key[] = $a->getAttribute('id');
             } else {
                 //echo "Application not ok<br>\n";
             }
         }
         $sync_apps[$local_id] = $a->getAttribute('id');
     }
     $previous_liaison_key = array_keys($previous_liaison);
     foreach ($previous_liaison_key as $key) {
         if (in_array($key, $current_liaison_key) == false) {
             $a = $applicationDB->import($key);
             if (is_null($a) || $a->getAttribute('static') == false) {
                 Abstract_Liaison::delete('ApplicationServer', $key, $this->fqdn);
             }
         }
     }
     if (count($sync_apps) > 0) {
         $dom = new DomDocument('1.0', 'utf-8');
         $applications_node = $dom->createElement('applications');
         foreach ($sync_apps as $local_id => $id) {
             $application_node = $dom->createElement('application');
             $application_node->setAttribute('id', $id);
             $application_node->setAttribute('local_id', $local_id);
             $applications_node->appendChild($application_node);
         }
         $dom->appendChild($applications_node);
         $xml = $dom->saveXML();
         query_url_post_xml($this->getBaseURL() . '/aps/applications/ids', $xml);
         foreach ($sync_apps as $local_id => $id) {
             $a = $applicationDB->import($id);
             if (!is_object($a)) {
                 continue;
             }
             if (!file_exists($a->getIconPathRW())) {
                 $this->getApplicationIcon($a->getAttribute('id'));
             }
         }
     }
     return true;
 }