public function init() { $server = Abstract_Server::load($this->server); if (!is_object($server)) { Logger::error('apt-get', 'TASK::init for task ' . $this->id . ' returned an error (unknown server ' . $this->server . ')'); return false; } $dom = new DomDocument('1.0', 'utf-8'); $node = $dom->createElement('debian'); $node->setAttribute('request', $this->getRequest()); foreach ($this->getPackages() as $package) { $buf = $dom->createElement('package'); $buf->setAttribute('name', $package); $node->appendChild($buf); } $dom->appendChild($node); $xml = $dom->saveXML(); $xml = query_url_post_xml($server->getBaseURL() . '/aps/debian', $xml); if (!$xml) { ErrorManager::report('Unable to submit Task to server "' . $server->fqdn . '"'); return false; } $dom = new DomDocument('1.0', 'utf-8'); $buf = @$dom->loadXML($xml); if (!$buf) { return false; } if (!$dom->hasChildNodes()) { return false; } $node = $dom->getElementsByTagname('debian_request')->item(0); if (is_null($node)) { return false; } $this->job_id = $node->getAttribute('id'); $this->status = $node->getAttribute('status'); return true; }
$applications_node = $dom->createElement('applications'); foreach ($session->getPublishedApplications() as $application) { if ($application->getAttribute('type') != 'webapp') { continue; } $application_node = $dom->createElement('application'); $application_node->setAttribute('id', $application->getAttribute('id')); $application_node->setAttribute('type', 'webapp'); $application_node->setAttribute('name', $application->getAttribute('name')); $applications_node->appendChild($application_node); } $session_node->appendChild($applications_node); $dom->appendChild($session_node); $sessionManagement->appendToSessionCreateXML($dom); $xml = $dom->saveXML(); $ret_xml = query_url_post_xml($server->getBaseURL() . '/webapps/session/create', $xml); $ret = $sessionManagement->parseSessionCreate($ret_xml); if (!$ret) { Logger::critical('main', '(client/start) Unable to create Session \'' . $session->id . '\' for User \'' . $session->user_login . '\' on Server \'' . $server->fqdn . '\', aborting'); $session->orderDeletion(true, Session::SESSION_END_STATUS_ERROR); throw_response(INTERNAL_ERROR); } $ret_dom = new DomDocument('1.0', 'utf-8'); $ret_buf = @$ret_dom->loadXML($ret_xml); $node = $ret_dom->getElementsByTagname('session')->item(0); $webapps_url = $node->getAttribute('webapps-scheme') . '://' . $server->getExternalName() . ':' . $node->getAttribute('webapps-port'); $session->settings['webapps-url'] = $webapps_url; } // $session->setStatus(Session::SESSION_STATUS_READY); Logger::info('main', '(client/start) Resuming session for ' . $user->getAttribute('login') . ' (' . $old_session_id . ' => ' . $session->server . ')');
if (isset($start_apps) && is_array($start_apps)) { $start_node = $dom->createElement('start'); foreach ($start_apps as $start_app) { $application_node = $dom->createElement('application'); $application_node->setAttribute('id', $start_app['id']); if (array_key_exists('arg', $start_app) && !is_null($start_app['arg'])) { $application_node->setAttribute('arg', $start_app['arg']); } $start_node->appendChild($application_node); } $session_node->appendChild($start_node); } $dom->appendChild($session_node); $sessionManagement->appendToSessionCreateXML($dom); $xml = $dom->saveXML(); $session_create_xml = query_url_post_xml($server->getBaseURL() . '/aps/session/create', $xml); $ret = $sessionManagement->parseSessionCreate($session_create_xml); if (!$ret) { Logger::critical('main', '(client/start) Unable to create Session \'' . $session->id . '\' for User \'' . $session->user_login . '\' on Server \'' . $server->fqdn . '\', aborting'); $session->orderDeletion(true, Session::SESSION_END_STATUS_ERROR); throw_response(INTERNAL_ERROR); } } } $_SESSION['session_id'] = $session->id; $sessionManagement->end(); header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8'); $session_node = $dom->createElement('session'); $session_node->setAttribute('id', $session->id); $session_node->setAttribute('mode', $session->mode);
public function orderAction($action_) { $server = Abstract_Server::load($this->server); if (!$server) { Logger::error('main', 'VDI_VM::orderAction unable to load Server \'' . $this->server . '\''); return false; } $dom = new DomDocument('1.0', 'utf-8'); $node = $dom->createElement('vm'); $node->setAttribute('id', $this->id); $node->setAttribute('action', $action_); $dom->appendChild($node); $xml = $dom->saveXML(); $xml = query_url_post_xml($server->getBaseURL() . '/hypervisor/vm/manage', $xml); if (!$xml) { $server->isUnreachable(); Logger::error('main', 'VDI_VM::orderAction server \'' . $server->fqdn . '\' is unreachable'); return false; } $dom = new DomDocument('1.0', 'utf-8'); $buf = @$dom->loadXML($xml); if (!$buf) { return false; } if (!$dom->hasChildNodes()) { return false; } $node = $dom->getElementsByTagname('vm')->item(0); if (is_null($node)) { return false; } $status = $node->getAttribute('status'); if ($status != 'OK') { Logger::error('main', 'VDI_VM::orderAction failed'); return false; } return true; }
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; }
public function prepareAPSAccess($session_) { $remote_desktop_settings = $this->user->getSessionSettings('remote_desktop_settings'); $default_settings = $this->user->getSessionSettings('session_settings_defaults'); $prepare_servers = array(); # No_desktop option management if (isset($this->no_desktop) && $this->no_desktop === true) { if ($authorize_no_desktop === true) { $no_desktop_process = 1; } else { Logger::warning('main', 'SessionManagement::prepareAPSAccess - Cannot apply no_desktop parameter because policy forbid it'); } } if ($default_settings['use_known_drives'] == 1) { $use_known_drives = 'true'; } $profile_mode = $default_settings['profile_mode']; $use_local_ime = $session_->settings['use_local_ime']; $desktop_icons = $remote_desktop_settings['desktop_icons']; $need_valid_profile = $default_settings['start_without_profile'] == 0; $user_login_aps = $session_->settings['aps_access_login']; $user_password_aps = $session_->settings['aps_access_password']; $user_login_fs = $session_->settings['fs_access_login']; $user_password_fs = $session_->settings['fs_access_password']; $remote_desktop_settings = $this->user->getSessionSettings('remote_desktop_settings'); $allow_external_applications = array_key_exists('allow_external_applications', $remote_desktop_settings) && $remote_desktop_settings['allow_external_applications'] == 1; if (isset($this->language)) { $locale = locale2unix($this->language); } else { $locale = $this->user->getLocale(); } if (isset($this->timezone) && $this->timezone != '') { $timezone = $this->timezone; } if ($session_->mode == Session::MODE_DESKTOP) { $have_external_apps = false; if (array_key_exists(Server::SERVER_ROLE_APS, $session_->servers)) { $have_external_apps |= count($session_->servers[Server::SERVER_ROLE_APS]) > 1; } if (array_key_exists(Server::SERVER_ROLE_WEBAPPS, $session_->servers)) { $have_external_apps |= count($session_->servers[Server::SERVER_ROLE_WEBAPPS]) > 0; } if ($session_->mode == Session::MODE_DESKTOP && $allow_external_applications && $have_external_apps) { $external_apps_token = new Token(gen_unique_string()); $external_apps_token->type = 'external_apps'; $external_apps_token->link_to = $session_->id; $external_apps_token->valid_until = 0; Abstract_Token::save($external_apps_token); } $prepare_servers[] = $session_->server; } if ($session_->mode == Session::MODE_APPLICATIONS || $session_->mode == Session::MODE_DESKTOP && $allow_external_applications) { foreach ($session_->servers[Server::SERVER_ROLE_APS] as $server_id => $data) { if ($session_->mode == Session::MODE_DESKTOP && $allow_external_applications && $server_id == $session_->server) { continue; } $prepare_servers[] = $server_id; } } $count_prepare_servers = 0; foreach ($prepare_servers as $prepare_server) { $count_prepare_servers++; $server = Abstract_Server::load($prepare_server); if (!$server) { continue; } if (!array_key_exists(Server::SERVER_ROLE_APS, $server->getRoles())) { continue; } $server_applications = $server->getApplications(); if (!is_array($server_applications)) { $server_applications = array(); } $available_applications = array(); foreach ($server_applications as $server_application) { $available_applications[] = $server_application->getAttribute('id'); } $dom = new DomDocument('1.0', 'utf-8'); $session_node = $dom->createElement('session'); $session_node->setAttribute('id', $session_->id); $session_node->setAttribute('mode', $session_->mode == Session::MODE_DESKTOP && $count_prepare_servers == 1 ? Session::MODE_DESKTOP : Session::MODE_APPLICATIONS); // OvdShell Configuration $shell_node = $dom->createElement('shell'); $session_node->appendChild($shell_node); if (isset($external_apps_token)) { $setting_node = $dom->createElement('setting'); $setting_node->setAttribute('name', 'external_apps_token'); $setting_node->setAttribute('value', $external_apps_token->id); $shell_node->appendChild($setting_node); } if (isset($this->start_apps) && is_array($this->start_apps)) { $start_apps = $this->start_apps; $applicationDB = ApplicationDB::getInstance(); foreach ($start_apps as $start_app) { $app = $applicationDB->import($start_app['id']); if (!is_object($app)) { Logger::error('main', 'SessionManagement::prepareAPSAccess - No such application for id \'' . $start_app['id'] . '\''); throw_response(SERVICE_NOT_AVAILABLE); } $apps = $session_->getPublishedApplications(); $ok = false; foreach ($apps as $user_app) { if ($user_app->getAttribute('id') == $start_app['id']) { $ok = true; break; } } if ($ok === false) { Logger::error('main', 'SessionManagement::prepareAPSAccess - Application not available for user \'' . $user->getAttribute('login') . '\' id \'' . $start_app['id'] . '\''); return false; } } } foreach (array('no_desktop_process', 'use_known_drives', 'profile_mode', 'use_local_ime') as $parameter) { if (!isset(${$parameter})) { continue; } $setting_node = $dom->createElement('setting'); $setting_node->setAttribute('name', $parameter); $setting_node->setAttribute('value', ${$parameter}); $shell_node->appendChild($setting_node); } foreach (array('desktop_icons', 'locale', 'timezone', 'need_valid_profile') as $parameter) { if (!isset(${$parameter})) { continue; } $parameter_node = $dom->createElement('parameter'); $parameter_node->setAttribute('name', $parameter); $parameter_node->setAttribute('value', ${$parameter}); $session_node->appendChild($parameter_node); } $scripts = $this->user->scripts(); if (is_array($scripts)) { $scripts_node = $dom->createElement('scripts'); foreach ($scripts as $script) { $script_node = $dom->createElement('script'); $script_node->setAttribute('id', $script->getAttribute('id')); $script_node->setAttribute('type', $script->getAttribute('type')); $script_node->setAttribute('name', $script->getAttribute('name')); $scripts_node->appendChild($script_node); } $shell_node->appendChild($scripts_node); } $user_node = $dom->createElement('user'); $user_node->setAttribute('login', $user_login_aps); $user_node->setAttribute('password', $user_password_aps); $user_node->setAttribute('displayName', $this->user->getAttribute('displayname')); $session_node->appendChild($user_node); if (array_key_exists(Server::SERVER_ROLE_FS, $session_->servers)) { foreach ($session_->servers[Server::SERVER_ROLE_FS] as $server_id => $netfolders) { $fs_server = Abstract_Server::load($server_id); foreach ($netfolders as $netfolder) { $uri = 'cifs://' . $fs_server->getExternalName() . '/' . $netfolder['dir']; $netfolder_node = $dom->createElement($netfolder['type']); $netfolder_node->setAttribute('rid', $netfolder['rid']); $netfolder_node->setAttribute('uri', $uri); if ($netfolder['type'] == 'profile') { $netfolder_node->setAttribute('profile_mode', $profile_mode); } if ($netfolder['type'] == 'sharedfolder') { $netfolder_node->setAttribute('name', $netfolder['name']); $netfolder_node->setAttribute('mode', $netfolder['mode']); } $netfolder_node->setAttribute('login', $user_login_fs); $netfolder_node->setAttribute('password', $user_password_fs); $session_node->appendChild($netfolder_node); } } } foreach ($this->forced_sharedfolders as $share) { $sharedfolder_node = $dom->createElement('sharedfolder'); $sharedfolder_node->setAttribute('rid', $share['rid']); $sharedfolder_node->setAttribute('uri', $share['uri']); $sharedfolder_node->setAttribute('name', $share['name']); if (array_key_exists('login', $share) && array_key_exists('password', $share)) { $sharedfolder_node->setAttribute('login', $share['login']); $sharedfolder_node->setAttribute('password', $share['password']); } $session_node->appendChild($sharedfolder_node); } // Pass custom shared folders to the server foreach (Plugin::dispatch('getSharedFolders', $server) as $plugin => $results) { foreach ($results as $sharedfolder) { $sharedfolder_ok = true; $sharedfolder_node = $dom->createElement('sharedfolder'); foreach (array('uri', 'name', 'rid') as $key) { if (array_key_exists($key, $sharedfolder)) { $sharedfolder_node->setAttribute($key, $sharedfolder[$key]); } else { Logger::error('main', 'SharedFolder is missing ' . $key . ' parameter in ' . $plugin); $sharedfolder_ok = false; } } foreach (array('login', 'password') as $key) { if (array_key_exists($key, $sharedfolder)) { $sharedfolder_node->setAttribute($key, $sharedfolder[$key]); } } if (($have_login = array_key_exists('login', $sharedfolder)) != array_key_exists('password', $sharedfolder) && $have_login) { Logger::error('main', 'SharedFolder login and password are both required if one is present in ' . $plugin); $sharedfolder_ok = false; } if ($sharedfolder_ok) { $session_node->appendChild($sharedfolder_node); } } } foreach ($session_->getPublishedApplications() as $application) { if ($application->getAttribute('type') != $server->getAttribute('type')) { continue; } if (!in_array($application->getAttribute('id'), $available_applications)) { continue; } $application_node = $dom->createElement('application'); $application_node->setAttribute('id', $application->getAttribute('id')); $application_node->setAttribute('name', $application->getAttribute('name')); if (!$application->getAttribute('static')) { $application_node->setAttribute('mode', 'local'); } else { $application_node->setAttribute('mode', 'static'); } $session_node->appendChild($application_node); } if (isset($start_apps) && is_array($start_apps)) { $start_node = $dom->createElement('start'); foreach ($start_apps as $start_app) { $application_node = $dom->createElement('application'); $application_node->setAttribute('app_id', $start_app['id']); if (array_key_exists('arg', $start_app) && !is_null($start_app['arg'])) { $application_node->setAttribute('arg', $start_app['arg']); } if (array_key_exists('file', $start_app)) { $file_node = $dom->createElement('file'); $file_node->setAttribute('type', $start_app['file']['type']); $file_node->setAttribute('location', $start_app['file']['location']); $file_node->setAttribute('path', $start_app['file']['path']); $application_node->appendChild($file_node); } $start_node->appendChild($application_node); } $session_node->appendChild($start_node); } $dom->appendChild($session_node); $this->appendToSessionCreateXML($dom); $xml = $dom->saveXML(); $session_create_xml = query_url_post_xml($server->getBaseURL() . '/aps/session/create', $xml); $ret = $this->parseSessionCreate($session_create_xml); if (!$ret) { Logger::critical('main', 'SessionManagement::prepareAPSAccess - Unable to create Session \'' . $session->id . '\' for User \'' . $session->user_login . '\' on Server \'' . $server->fqdn . '\', aborting'); $session->orderDeletion(true, Session::SESSION_END_STATUS_ERROR); return false; } } return true; }