public function chooseWebAppServers() { if (!$this->user) { Logger::error('main', 'SessionManagement::chooseWebAppServers - User is not authenticated, aborting'); return false; } $applications = array(); $all_applications = $this->user->applications(); // Filter applications by type foreach ($all_applications as $application) { if ($application->getAttribute('type') == 'webapp') { $applications[] = $application; } } if (count($applications) == 0) { $event = new SessionStart(array('user' => $this->user)); $event->setAttribute('ok', false); $event->setAttribute('error', _('No available application')); $event->emit(); Logger::info('main', 'No webapp published for User "' . $this->user->getAttribute('login') . '"'); return false; } else { Logger::debug('main', 'SessionManagement::chooseWebAppServers - found ' . count($applications) . ' webapp(s)'); } foreach ($applications as $application) { $this->applications[$application->getAttribute('id')] = $application; } $servers = Abstract_Server::load_available_by_role(Server::SERVER_ROLE_WEBAPPS); return $servers; }
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); } } } $_SESSION['session_id'] = $session->id; $_SESSION['client_id'] = $client_id; $sessionManagement->end(); header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8'); $session_node = $dom->createElement('session');
public function buildServersList() { if (!$this->user) { Logger::error('main', 'SessionManagement::buildServersList - User is not authenticated, aborting'); throw_response(AUTH_FAILED); } $serverRoles = $this->getServerRoles(); $this->servers = array(); foreach ($serverRoles as $role) { if (!array_key_exists($role, $this->servers)) { $this->servers[$role] = array(); } switch ($role) { case Server::SERVER_ROLE_APS: $applicationServerTypes = $this->getApplicationServerTypes(); $servers = array(); foreach ($applicationServerTypes as $type) { $buf = $this->user->getAvailableServers($type); if (is_null($buf) || !is_array($buf)) { return false; } $servers = array_merge($servers, $buf); } $slave_server_settings = $this->prefs->get('general', 'slave_server_settings'); if (is_array($slave_server_settings) && array_key_exists('use_max_sessions_limit', $slave_server_settings) && $slave_server_settings['use_max_sessions_limit'] == 1) { foreach ($servers as $k => $server) { if (!isset($server->max_sessions) || $server->max_sessions == 0) { continue; } $total = Abstract_Session::countByServer($server->fqdn); if ($total >= $server->max_sessions) { Logger::warning('main', 'SessionManagement::buildServersList - Server \'' . $server->fqdn . '\' has reached its "max sessions" limit, sessions cannot be launched on it anymore'); unset($servers[$k]); } } } if (count($servers) == 0) { $event = new SessionStart(array('user' => $this->user)); $event->setAttribute('ok', false); $event->setAttribute('error', _('No available server')); $event->emit(); Logger::error('main', 'SessionManagement::buildServersList - No "' . $role . '" server found for User "' . $this->user->getAttribute('login') . '", aborting'); return false; } foreach ($servers as $server) { $this->servers[Server::SERVER_ROLE_APS][$server->fqdn] = array('status' => Session::SESSION_STATUS_CREATED); } break; case Server::SERVER_ROLE_FS: if (get_class($this) != 'SessionManagement_internal') { Logger::error('main', 'SessionManagement::buildServersList - Role "' . $role . '" is not compatible with the current integration mode (' . substr(get_class($this), strlen('SessionManagement_')) . '), aborting'); return false; } $default_settings = $this->user->getSessionSettings('session_settings_defaults'); $enable_profiles = $default_settings['enable_profiles'] == 1 ? true : false; $auto_create_profile = $default_settings['auto_create_profile'] == 1 ? true : false; $start_without_profile = $default_settings['start_without_profile'] == 1 ? true : false; $enable_sharedfolders = $default_settings['enable_sharedfolders'] == 1 ? true : false; $start_without_all_sharedfolders = $default_settings['start_without_all_sharedfolders'] == 1 ? true : false; if ($enable_profiles) { $fileservers = Abstract_Server::load_available_by_role(Server::SERVER_ROLE_FS); if (count($fileservers) > 0) { $profiles = $this->user->getProfiles(); if (!is_array($profiles)) { Logger::error('main', 'SessionManagement::buildServersList - getProfiles() failed for User "' . $this->user->getAttribute('login') . '", aborting'); return false; } if (count($profiles) == 1) { Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" already have a Profile, using it'); $profile = array_pop($profiles); foreach ($fileservers as $fileserver) { if ($fileserver->fqdn != $profile->server) { continue; } if (!array_key_exists($fileserver->fqdn, $this->servers[Server::SERVER_ROLE_FS])) { $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn] = array(); } $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn][] = array('type' => 'profile', 'server' => $fileserver, 'dir' => $profile->id); break; } } else { Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" does not have a Profile for now, checking for auto-creation'); if ($auto_create_profile) { Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" Profile will be auto-created and used'); $profileDB = ProfileDB::getInstance(); $fileserver = $profileDB->chooseFileServer(); if (!is_object($fileserver)) { Logger::error('main', 'SessionManagement::buildServersList - Auto-creation of Profile for User "' . $this->user->getAttribute('login') . '" failed (unable to get a valid FileServer)'); return false; } $profile = new Profile(); $profile->server = $fileserver->getAttribute('fqdn'); if (!$profileDB->addToServer($profile, $fileserver)) { Logger::error('main', 'SessionManagement::buildServersList - Auto-creation of Profile for User "' . $this->user->getAttribute('login') . '" failed (unable to add the Profile to the FileServer)'); return false; } if (!$profile->addUser($this->user)) { Logger::error('main', 'SessionManagement::buildServersList - Auto-creation of Profile for User "' . $this->user->getAttribute('login') . '" failed (unable to associate the User to the Profile)'); return false; } if (!array_key_exists($fileserver->fqdn, $this->servers[Server::SERVER_ROLE_FS])) { $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn] = array(); } $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn][] = array('type' => 'profile', 'server' => $fileserver, 'dir' => $profile->id); } else { Logger::debug('main', 'SessionManagement::buildServersList - Auto-creation of Profile for User "' . $this->user->getAttribute('login') . '" disabled, checking for session without Profile'); if (!$start_without_profile) { Logger::error('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" does not have a valid Profile, aborting'); return false; } Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" can start a session without a valid Profile, proceeding'); } } } else { Logger::debug('main', 'SessionManagement::buildServersList - No "' . $role . '" server found for User "' . $this->user->getAttribute('login') . '", checking for session without Profile'); if (!$start_without_profile) { Logger::error('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" does not have a valid Profile, aborting'); return false; } Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" can start a session without a valid Profile, proceeding'); } } if ($enable_sharedfolders) { $sharedfolders = $this->user->getSharedFolders(); if (!is_array($sharedfolders)) { Logger::error('main', 'SessionManagement::buildServersList - getSharedFolders() failed for User "' . $this->user->getAttribute('login') . '", aborting'); return false; } if (count($sharedfolders) > 0) { foreach ($sharedfolders as $sharedfolder) { $fileserver = Abstract_Server::load($sharedfolder->server); if (!$fileserver || !$fileserver->isOnline() || $fileserver->getAttribute('locked')) { Logger::warning('main', 'SessionManagement::buildServersList - Server "' . $sharedfolder->server . '" for SharedFolder "' . $sharedfolder->id . '" is not available'); if (!$start_without_all_sharedfolders) { Logger::error('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" does not have all SharedFolders available, aborting'); return false; } else { Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" can start a session without all SharedFolders available, proceeding'); continue; } } if (!array_key_exists($fileserver->fqdn, $this->servers[Server::SERVER_ROLE_FS])) { $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn] = array(); } $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn][] = array('type' => 'sharedfolder', 'server' => $fileserver, 'dir' => $sharedfolder->id, 'name' => $sharedfolder->name); } } } break; } } return true; }