public function update($session_node_) { $sessid = $session_node_->getAttribute('id'); $buf = Abstract_Session::exists($sessid); if (!$buf) { return; } $session = Abstract_Session::load($sessid); if (!$session) { return; } //$apps_link = application_desktops_to_ids(); /* reset the current apps data */ $this->current_apps = array(); /* get the running apps for a start */ $tmp = array(); foreach ($session_node_->childNodes as $instance_node) { if ($instance_node->tagName != 'instance') { continue; } $app_pid = $instance_node->getAttribute('id'); $app_id = $instance_node->getAttribute('application'); $this->current_apps[$sessid] = $app_id; $tmp[$app_pid] = $app_id; } /* for each app that was already active, we check if it's still there * and: - if yes, drop it from $tmp - if no, regeister the end of the application */ foreach ($this->apps_raw_data as $app) { $app_pid = $app['pid']; $app_id = $app['id']; $app_running = $app['running']; if ($app_running->isDone()) { /* already ended, we don't care */ continue; } if (array_key_exists($app_pid, $tmp) && $app_id == $tmp[$app_pid]) { unset($tmp[$app_pid]); } else { $app_running->stop(); } } /* now register each remaining item in $tmp */ foreach ($tmp as $app_pid => $app_id) { $this->apps_raw_data[] = array('pid' => $app_pid, 'id' => $app_id, 'running' => new ReportRunningItem()); } }
public function run() { switch ($this->ev->status) { /* session created */ case Session::SESSION_STATUS_CREATED: $token = $this->ev->id; if (!Abstract_ReportSession::exists($token)) { if (!Abstract_Session::exists($token)) { Logger::error('main', "SessionStatusChangedReport::run failed session '{$token}' does not exist"); return false; } $session = Abstract_Session::load($token); $sessitem = new SessionReportItem($session->id, $session->user_login, $session->server, $session->start_time); $ret = Abstract_ReportSession::create($sessitem); if (!$ret) { Logger::error('main', "SessionStatusChangedReport::run failed to save SessionReportItem({$token})"); return false; } } return true; break; /* session ended */ /* session ended */ case Session::SESSION_STATUS_WAIT_DESTROY: case Session::SESSION_STATUS_DESTROYED: $token = $this->ev->id; if (!Abstract_Session::exists($token)) { Logger::error('main', "SessionStatusChangedReport::run failed session '{$token}' does not exist"); return false; } $session = Abstract_Session::load($token); $sessitem = Abstract_ReportSession::load($token); if (!is_object($sessitem)) { Logger::error('main', "SessionStatusChangedReport::run failed to load SessionReportItem({$token})"); return false; } $sessitem->end($session); Abstract_ReportSession::update_on_session_end($sessitem); return true; break; default: return true; break; } }
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; }
$user_password_aps = $session->settings['aps_access_password']; if (array_key_exists('fs_access_login', $session->settings) && array_key_exists('fs_access_password', $session->settings)) { $user_login_fs = $session->settings['fs_access_login']; $user_password_fs = $session->settings['fs_access_password']; } if (array_key_exists('webapps_access_login', $session->settings) && array_key_exists('webapps_access_password', $session->settings)) { $user_login_webapps = $session->settings['webapps_access_login']; $user_password_webapps = $session->settings['webapps_access_password']; } if (array_key_exists('webapps-url', $session->settings)) { $webapps_url = $session->settings['webapps-url']; } } } if (isset($old_session_id)) { $session = Abstract_Session::load($old_session_id); $session_type = 'resume'; // $prepare_servers = array(); if ($session->mode == Session::MODE_APPLICATIONS) { if (array_key_exists(Server::SERVER_ROLE_WEBAPPS, $session->servers)) { foreach ($session->servers[Server::SERVER_ROLE_WEBAPPS] as $server_id => $data) { $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) {
$ret['reason'] = $node->getAttribute('reason'); } if ($node->hasAttribute('role')) { $ret['role'] = $node->getAttribute('role'); } return $ret; } $ret = parse_session_status_XML(@file_get_contents('php://input')); if (!$ret) { Logger::error('main', '(webservices/session/status) 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 (is_null($server)) { Logger::error('main', '(webservices/session/status) Server does not exist (error_code: 2)'); webservices_return_error(2, 'Server does not exist'); } $session = Abstract_Session::load($ret['id']); if (!$session) { Logger::error('main', '(webservices/session/status) Session does not exist (error_code: 2)'); webservices_return_error(2, 'Session does not exist'); } $session->setServerStatus($server->id, $ret['status'], $ret['reason'], $ret['role']); header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8'); $node = $dom->createElement('session'); $node->setAttribute('id', $session->id); $node->setAttribute('status', $session->status); $dom->appendChild($node); echo $dom->saveXML(); exit(0);
$node->setAttribute('id', $errno_); $node->setAttribute('message', $errstr_); $dom->appendChild($node); Logger::error('main', "(client/mimetype-icon) return_error({$errno_}, {$errstr_})"); return $dom->saveXML(); } if (!array_key_exists('id', $_GET)) { echo return_error(1, 'Usage: missing "id" $_GET parameter'); die; } $prefs = Preferences::getInstance(); $web_interface_settings = $prefs->get('general', 'web_interface_settings'); if (array_key_exists('public_webservices_access', $web_interface_settings) && $web_interface_settings['public_webservices_access'] == 1) { // ok } elseif (array_key_exists('session_id', $_SESSION)) { $session = Abstract_Session::load($_SESSION['session_id']); if (!$session) { echo return_error(3, 'No such session "' . $_SESSION['session_id'] . '"'); die; } /*if (! in_array($_GET['id'], $session->applications)) { echo return_error(4, 'Unauthorized application'); die(); }*/ } else { Logger::debug('main', '(client/applications) No Session id nor public_webservices_access'); echo return_error(7, 'No Session id nor public_webservices_access'); die; } $applicationDB = ApplicationDB::getInstance(); $applications = $applicationDB->getApplicationsWithMimetype($_GET['id']);
* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ require_once dirname(__FILE__) . '/includes/core.inc.php'; require_once dirname(__FILE__) . '/includes/page_template.php'; if (!checkAuthorization('viewStatus')) { redirect('index.php'); } if (isset($_GET['info'])) { $session = Abstract_Session::load($_GET['info']); if (!$session) { redirect('sessions.php'); } $prefs = Preferences::getInstance(); if (!$prefs) { die_error('get Preferences failed', __FILE__, __LINE__); } $mods_enable = $prefs->get('general', 'module_enable'); if (!in_array('ApplicationDB', $mods_enable)) { $show_apps = false; } else { $show_apps = true; $applicationDB = ApplicationDB::getInstance(); } //FIX ME?
redirect('configuration-sumup.php'); } else { popup_error(_('Password not changed')); } } } } } redirect(); } } if ($_REQUEST['name'] == 'Session') { if ($_REQUEST['action'] == 'del') { if (isset($_REQUEST['selected_session']) && is_array($_REQUEST['selected_session'])) { foreach ($_POST['selected_session'] as $session) { $session = Abstract_Session::load($session); if (is_object($session)) { if (!$session->orderDeletion(true, Session::SESSION_END_STATUS_ADMINKILL)) { Logger::error('main', 'Unable to order deletion of session \'' . $session->id . '\': purging'); Abstract_Session::delete($session->id); popup_error(sprintf(_("Unable to delete session '%s'"), $session->id)); continue; } else { popup_info(sprintf(_("Session '%s' successfully deleted"), $session->id)); } } } redirect('sessions.php'); } } }
if ($slaveserver_settings['auto_recover'] == 1) { if (!$server->isOnline()) { $server->setAttribute('status', Server::SERVER_STATUS_ONLINE); $server->getStatus(); } } Abstract_Server::save($server); //update Server cache timestamp if (array_key_exists('sessions', $ret) && is_array($ret['sessions'])) { $monitored_session = array(); foreach ($ret['sessions'] as $session) { $buf = Abstract_Session::exists($session['id']); if (!$buf) { continue; } $buf = Abstract_Session::load($session['id']); if (!$buf) { continue; } $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']);
} $ret['dump'][$name] = trim($textNode->wholeText); } return $ret; } $infos = parse_session_dump_XML(@file_get_contents('php://input')); 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');
return $dom->saveXML(); } if (!array_key_exists('token', $_REQUEST)) { echo return_error(1, 'Usage: missing "token" $_REQUEST parameter'); die; } $token = Abstract_Token::load($_REQUEST['token']); if (!$token) { echo return_error(2, 'No such token: ' . $_REQUEST['token']); die; } if ($token->type != 'external_apps') { echo return_error(3, 'Token "' . $_REQUEST['token'] . '" is invalid'); die; } $session = Abstract_Session::load($token->link_to); if (!$session) { echo return_error(4, 'No such session: ' . $token->link_to); die; } $userDB = UserDB::getInstance(); $user = $userDB->import($session->user_login); if (!is_object($user)) { echo return_error(5, 'No such user: '******'session_id', $_SESSION)) { $_SESSION['session_id'] = $session->id; } header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8');
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; }
function checkup_liaison($type_, $element_, $group_) { switch ($type_) { case 'ApplicationServer': $applicationDB = ApplicationDB::getInstance(); $buf = $applicationDB->import($element_); if (!is_object($buf)) { return 'Application "' . $element_ . '" does not exist'; } $buf = Abstract_Server::load($group_); if (!$buf) { return 'Server "' . $group_ . '" does not exist'; } break; case 'AppsGroup': $applicationDB = ApplicationDB::getInstance(); $buf = $applicationDB->import($element_); if (!is_object($buf)) { return 'Application "' . $element_ . '" does not exist'; } $applicationsGroupDB = ApplicationsGroupDB::getInstance(); $buf = $applicationsGroupDB->import($group_); if (!is_object($buf)) { return 'ApplicationsGroup "' . $group_ . '" does not exist'; } break; case 'ApplicationMimeType': $applicationDB = ApplicationDB::getInstance(); $buf = $applicationDB->import($element_); if (!is_object($buf)) { return 'Application "' . $element_ . '" does not exist'; } break; case 'ServerSession': $buf = Abstract_Server::load($element_); if (!$buf) { return 'Server "' . $element_ . '" does not exist'; } $buf = Abstract_Session::load($group_); if (!$buf) { return 'Session "' . $group_ . '" does not exist'; } break; case 'UserGroupSharedFolder': $sharedfolderdb = SharedFolderDB::getInstance(); $userGroupDB = UserGroupDB::getInstance(); $buf = $userGroupDB->import($element_); if (!is_object($buf)) { return 'UserGroup "' . $element_ . '" does not exist'; } $buf = $sharedfolderdb->import($group_); if (!$buf) { return 'SharedFolder "' . $group_ . '" does not exist'; } break; case 'UserProfile': $profiledb = ProfileDB::getInstance(); $userDB = UserDB::getInstance(); $buf = $userDB->import($element_); if (!is_object($buf)) { return 'User "' . $element_ . '" does not exist'; } $buf = $profiledb->import($group_); if (!$buf) { return 'Profile "' . $group_ . '" does not exist'; } break; case 'UsersGroup': $userDB = UserDB::getInstance(); $buf = $userDB->import($element_); if (!is_object($buf)) { return 'User "' . $element_ . '" does not exist'; } $userGroupDB = UserGroupDB::getInstance(); $buf = $userGroupDB->import($group_); if (!is_object($buf)) { return 'UserGroup "' . $group_ . '" does not exist'; } break; case 'UsersGroupApplicationsGroup': $userGroupDB = UserGroupDB::getInstance(); $buf = $userGroupDB->import($element_); if (!is_object($buf)) { return 'UserGroup "' . $element_ . '" does not exist'; } $applicationsGroupDB = ApplicationsGroupDB::getInstance(); $buf = $applicationsGroupDB->import($group_); if (!is_object($buf)) { return 'ApplicationsGroup "' . $group_ . '" does not exist'; } break; case 'UsersGroupCached': $userDB = UserDB::getInstance(); $buf = $userDB->import($element_); if (!is_object($buf)) { return 'User "' . $element_ . '" does not exist'; } $userGroupDB = UserGroupDB::getInstance(); $buf = $userGroupDB->import($group_); if (!is_object($buf)) { return 'UserGroup "' . $group_ . '" does not exist'; } break; } return true; }
public static function delete($fqdn_) { Logger::debug('main', 'Starting Abstract_Server::delete for \'' . $fqdn_ . '\''); if (substr($fqdn_, -1) == '.') { $fqdn_ = substr($fqdn_, 0, strlen($fqdn_) - 1); } $SQL = SQL::getInstance(); $fqdn = $fqdn_; $SQL->DoQuery('SELECT 1 FROM @1 WHERE @2 = %3 LIMIT 1', $SQL->prefix . 'servers', 'fqdn', $fqdn); $total = $SQL->NumRows(); if ($total == 0) { Logger::error('main', "Abstract_Server::delete({$server_}) server does not exist (NumRows == 0)"); return false; } $sessions_liaisons = Abstract_Liaison::load('ServerSession', $fqdn_, NULL); foreach ($sessions_liaisons as $sessions_liaison) { $session = Abstract_Session::load($sessions_liaison->group); if (!$session) { continue; } $session->orderDeletion(true, Session::SESSION_END_STATUS_SERVER_DELETED); } Abstract_Liaison::delete('ServerSession', $fqdn_, NULL); $a_server = Abstract_Server::load($fqdn_); $roles = $a_server->getAttribute('roles'); if (is_array($roles)) { foreach ($roles as $a_role) { Abstract_Server::removeRole($fqdn_, $a_role); } } $SQL->DoQuery('DELETE FROM @1 WHERE @2 = %3', $SQL->prefix . 'servers_properties', 'fqdn', $fqdn); $SQL->DoQuery('DELETE FROM @1 WHERE @2 = %3 LIMIT 1', $SQL->prefix . 'servers', 'fqdn', $fqdn); return true; }
public static function delete($id_) { Logger::debug('main', 'Starting Abstract_Server::delete for \'' . $id_ . '\''); $SQL = SQL::getInstance(); $SQL->DoQuery('SELECT 1 FROM #1 WHERE @2 = %3 LIMIT 1', self::table, 'id', $id_); $total = $SQL->NumRows(); if ($total == 0) { Logger::error('main', "Abstract_Server::delete({$id_}) server does not exist (NumRows == 0)"); return false; } $sessions_liaisons = Abstract_Liaison::load('ServerSession', $id_, NULL); foreach ($sessions_liaisons as $sessions_liaison) { $session = Abstract_Session::load($sessions_liaison->group); if (!$session) { continue; } $session->orderDeletion(true, Session::SESSION_END_STATUS_SERVER_DELETED); } Abstract_Liaison::delete('ServerSession', $id_, NULL); $a_server = Abstract_Server::load($id_); $roles = $a_server->getAttribute('roles'); if (is_array($roles)) { foreach ($roles as $a_role => $role_enabled) { Abstract_Server::removeRole($id_, $a_role); } } $SQL->DoQuery('DELETE FROM #1 WHERE @2 = %3', self::table_properties, 'server', $id_); $SQL->DoQuery('DELETE FROM #1 WHERE @2 = %3 LIMIT 1', self::table, 'id', $id_); return true; }