$data[$k] = $v; } $session->setAttribute('settings', $data); $session->setAttribute('start_time', time()); $session->settings['aps_access_login'] = $user_login_aps; $session->settings['aps_access_password'] = $user_password_aps; if (isset($user_login_fs) && isset($user_password_fs)) { $session->settings['fs_access_login'] = $user_login_fs; $session->settings['fs_access_password'] = $user_password_fs; } if (isset($user_login_webapps) && isset($user_password_webapps)) { $session->settings['webapps_access_login'] = $user_login_webapps; $session->settings['webapps_access_password'] = $user_password_webapps; } $session->client_id = $client_id; $save_session = Abstract_Session::save($session); if (!$save_session) { Logger::error('main', '(client/start) failed to save session \'' . $session->id . '\' for user \'' . $user->getAttribute('login') . '\''); throw_response(INTERNAL_ERROR); } $ev->setAttributes(array('ok' => true, 'server' => $session->server, 'resume' => $session->isSuspended(), 'sessid' => $session->id)); $ev->emit(); if (!isset($old_session_id)) { if ($createNow == false) { $session->need_creation = true; } else { if (!$sessionManagement->prepareSession($session)) { throw_response(INTERNAL_ERROR); } } }
} $modified = false; array_push($monitored_session, $session['id']); if (!array_key_exists($session['server'], $buf->servers[Server::SERVER_ROLE_APS])) { continue; } if ($session['status'] != $buf->servers[Server::SERVER_ROLE_APS][$session['server']]['status']) { $modified = true; $buf->setServerStatus($session['server'], $session['status']); } if ($session['status'] == Session::SESSION_STATUS_ACTIVE) { $modified = true; $buf->reportRunningApplicationsOnServer($ret['server'], $session['instances']); } if ($modified === true) { Abstract_Session::save($buf); } //update Session cache timestamp } // Check state of sessions not present in xml Logger::debug('main', "Checking session from " . $server->fqdn); $sessions = Abstract_Session::getByServer($server->id); foreach ($sessions as $session) { Logger::debug('main', "Inspecting session " . $session->id); if (!array_key_exists($server->id, $session->servers[Server::SERVER_ROLE_APS])) { Logger::debug('main', "Session " . $session->id . " on " . $server->fqdn . " is not an APS session"); continue; } // Check if the session id unknown by the APS if (!in_array($session->id, $monitored_session)) { $serverStatus = $session->servers[Server::SERVER_ROLE_APS][$server->id]['status'];
if (!$infos) { Logger::error('main', '(webservices/session/dump) Server does not send a valid XML (error_code: 1)'); webservices_return_error(1, 'Server does not send a valid XML'); } $server = webservices_load_server($_SERVER['REMOTE_ADDR']); if (!$server) { Logger::error('main', '(webservices/session/dump) Server does not exist (error_code: 2)'); webservices_return_error(2, 'Server does not exist'); } $session = Abstract_Session::load($infos['id']); if (!$session) { Logger::error('main', '(webservices/session/dump) Session does not exist (error_code: 2)'); webservices_return_error(2, 'Session does not exist'); } $ret = $session->setServerDump($server->id, $infos['dump']); if ($ret === false) { Logger::error('main', '(webservices/session/dump) Server is not used for this session (error_code: 1)'); webservices_return_error(1, 'Server is not used for this session'); } $ret = Abstract_Session::save($session); if ($ret === false) { Logger::error('main', '(webservices/session/dump) Unable to save session with these information (error_code: 1)'); webservices_return_error(1, 'Unable to save session with these information'); } header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8'); $node = $dom->createElement('session'); $node->setAttribute('id', $session->id); $dom->appendChild($node); echo $dom->saveXML(); exit(0);
public function prepareWebappsAccess($session_) { if (!array_key_exists(Server::SERVER_ROLE_WEBAPPS, $session_->servers)) { return true; } $prepare_servers = array(); foreach ($session_->servers[Server::SERVER_ROLE_WEBAPPS] as $server_id => $data) { $prepare_servers[] = $server_id; } $user_login_webapps = $session_->settings['webapps_access_login']; $user_password_webapps = $session_->settings['webapps_access_password']; $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_WEBAPPS, $server->getRoles())) { continue; } $dom = new DomDocument('1.0', 'utf-8'); $session_node = $dom->createElement('session'); $session_node->setAttribute('id', $session_->id); $session_node->setAttribute('mode', Session::MODE_APPLICATIONS); $user_node = $dom->createElement('user'); $user_node->setAttribute('login', $user_login_webapps); $user_node->setAttribute('password', $user_password_webapps); $user_node->setAttribute('USER_LOGIN', $_POST['login']); $user_node->setAttribute('USER_PASSWD', $_POST['password']); $user_node->setAttribute('displayName', $this->user->getAttribute('displayname')); $session_node->appendChild($user_node); $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); $this->appendToSessionCreateXML($dom); $xml = $dom->saveXML(); $ret_xml = query_url_post_xml($server->getBaseURL() . '/webapps/session/create', $xml); $ret = $this->parseSessionCreate($ret_xml); if (!$ret) { Logger::critical('main', 'SessionManagement::prepareWebappsAccess - 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; } $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; // Make sure that session object is uptodate $buf = Abstract_Session::load($session_->id); $buf->setServerStatus($server->id, Session::SESSION_STATUS_READY, NULL, Server::SERVER_ROLE_WEBAPPS); $buf->settings['webapps-url'] = $webapps_url; Abstract_Session::save($buf); } return true; }
public function setStatus($status_, $reason_ = NULL) { if ($status_ == $this->getAttribute('status')) { return false; } // status is already the same... $states = array(Session::SESSION_STATUS_CREATING => -1, Session::SESSION_STATUS_CREATED => 0, Session::SESSION_STATUS_INIT => 1, Session::SESSION_STATUS_READY => 2, Session::SESSION_STATUS_ACTIVE => 3, Session::SESSION_STATUS_INACTIVE => 3, Session::SESSION_STATUS_WAIT_DESTROY => 4, Session::SESSION_STATUS_DESTROYING => 5, Session::SESSION_STATUS_DESTROYED => 6, Session::SESSION_STATUS_ERROR => 6, Session::SESSION_STATUS_UNKNOWN => 6); if (array_key_exists($status_, $states) && array_key_exists($this->getAttribute('status'), $states)) { if ($states[$status_] < $states[$this->getAttribute('status')] && !$this->canSwitchToPreviousStatus($status_)) { return false; } // avoid switching Session to a previous status... } Logger::debug('main', 'Starting Session::setStatus for \'' . $this->id . '\''); $ev = new SessionStatusChanged(array('id' => $this->id, 'status' => $status_)); if ($status_ == Session::SESSION_STATUS_READY) { Logger::info('main', 'Session start : \'' . $this->id . '\''); $this->setAttribute('start_time', time()); } elseif ($status_ == Session::SESSION_STATUS_INACTIVE) { if (!array_key_exists('persistent', $this->settings) || $this->settings['persistent'] == 0) { return $this->setStatus(Session::SESSION_STATUS_WAIT_DESTROY, Session::SESSION_END_STATUS_LOGOUT); } // We prevent switch from READY to INACTIVE if ($this->getAttribute('status') == Session::SESSION_STATUS_READY) { return true; } } elseif ($status_ == Session::SESSION_STATUS_WAIT_DESTROY) { Logger::info('main', 'Session end : \'' . $this->id . '\' (reason: \'' . $reason_ . '\')'); if (!array_key_exists('stop_time', $this->settings)) { $this->settings["stop_time"] = time(); } if ($status_ == Session::SESSION_STATUS_WAIT_DESTROY && !is_null($reason_)) { $report_session = Abstract_ReportSession::load($this->id); if (is_object($report_session)) { $report_session->setStopWhy($reason_); Abstract_ReportSession::update($report_session); } } if (!$this->orderDeletion()) { Logger::error('main', 'Unable to order session deletion for session \'' . $this->id . '\''); } else { $ev->emit(); return false; } } elseif ($status_ == Session::SESSION_STATUS_DESTROYED) { Logger::info('main', 'Session purge : \'' . $this->id . '\' (reason: \'' . $reason_ . '\')'); if (array_key_exists(Server::SERVER_ROLE_FS, $this->servers)) { foreach ($this->servers[Server::SERVER_ROLE_FS] as $server_id => $data) { $session_server = Abstract_Server::load($server_id); if (!$session_server) { Logger::error('main', 'Session::orderDeletion Unable to load server \'' . $server_id . '\''); return false; } if (is_array($session_server->roles)) { if (array_key_exists(Server::SERVER_ROLE_FS, $session_server->roles)) { $buf = $session_server->orderFSAccessDisable($this->settings['fs_access_login']); if (!$buf) { Logger::warning('main', 'Session::orderDeletion User \'' . $this->settings['fs_access_login'] . '\' already logged out of server \'' . $session_server->fqdn . '\''); } } } } } if ($status_ == Session::SESSION_STATUS_DESTROYED && !is_null($reason_)) { $report_session = Abstract_ReportSession::load($this->id); if (is_object($report_session)) { $report_session->setStopWhy($reason_); Abstract_ReportSession::update($report_session); } } $ev->emit(); Abstract_Session::delete($this->id); return false; } Logger::debug('main', 'Status set to "' . $status_ . '" (' . $this->textStatus($status_) . ') for session \'' . $this->id . '\''); $this->setAttribute('status', $status_); $ev->emit(); Abstract_Session::save($this); return true; }
public function checkPendingSession($session_) { $sessions = Abstract_Session::getByUser($session_->user_login); foreach ($sessions as $i => $session) { if ($session->id == $session_->id) { unset($sessions[$i]); continue; } } if (count($sessions) != 1) { return true; } $session = reset($sessions); if ($session->need_creation == 0) { return true; } // Start the creation try { $sessionManagement = SessionManagement::getInstance(); } catch (Exception $err) { Logger::error('main', "SessionStatusChangedPendingSessionCreation:: Failed to get SessionManagement instance"); return false; } if (!$sessionManagement->initialize()) { Logger::error('main', "SessionStatusChangedPendingSessionCreation:: SessionManagement initialization failed"); return false; } $userDB = UserDB::getInstance(); $user = $userDB->import($session->user_login); if (!is_object($user)) { Logger::error('main', 'SessionStatusChangedPendingSessionCreation:: Unable to import a valid user with login "' . $session->user_login . '"'); return false; } $sessionManagement->user = $user; if (!$sessionManagement->prepareSession($session)) { Logger::error('main', "SessionStatusChangedPendingSessionCreation:: SessionManagement initialization failed"); return false; } // prepareSession can take some time $session = Abstract_Session::load($session->id); $session->need_creation = 0; Abstract_Session::save($session); return true; }