Пример #1
0
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         $prefs = Preferences::getInstance();
         if (!$prefs) {
             die_error('get Preferences failed', __FILE__, __LINE__);
         }
         $enabled_modules = $prefs->get('general', 'module_enable');
         if (!in_array('SessionManagement', $enabled_modules)) {
             die_error('SessionManagement module must be enabled', __FILE__, __LINE__);
         }
         $SessionManagement_module_name = 'SessionManagement_' . $prefs->get('SessionManagement', 'enable');
         self::$instance = new $SessionManagement_module_name();
     }
     return self::$instance;
 }
 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;
 }
Пример #3
0
define('SERVICE_NOT_AVAILABLE', 'service_not_available');
define('UNAUTHORIZED_SESSION_MODE', 'unauthorized_session_mode');
define('USER_WITH_ACTIVE_SESSION', 'user_with_active_session');
function throw_response($response_code_)
{
    Logger::error('main', '(client/start) throw_response(\'' . $response_code_ . '\')');
    header('Content-Type: text/xml; charset=utf-8');
    $dom = new DomDocument('1.0', 'utf-8');
    $response_node = $dom->createElement('response');
    $response_node->setAttribute('code', $response_code_);
    $dom->appendChild($response_node);
    echo $dom->saveXML();
    die;
}
try {
    $sessionManagement = SessionManagement::getInstance();
} catch (Exception $err) {
    throw_response(INTERNAL_ERROR);
}
if (!$sessionManagement->initialize()) {
    Logger::error('main', '(client/auth) SessionManagement initialization failed');
    throw_response(INTERNAL_ERROR);
}
if (!$sessionManagement->parseClientRequest(@file_get_contents('php://input'))) {
    Logger::error('main', '(client/auth) Client does not send a valid XML');
    throw_response(INTERNAL_ERROR);
}
if (!$sessionManagement->authenticate()) {
    Logger::error('main', '(client/auth) Authentication failed');
    throw_response(AUTH_FAILED);
}
Пример #4
0
function show_default()
{
    $userDB = UserDB::getInstance();
    $userGroupDB = UserGroupDB::getInstance();
    $applicationsGroupDB = ApplicationsGroupDB::getInstance();
    $sessionmanagement = SessionManagement::getInstance();
    $usersList = new UsersList($_REQUEST);
    $us = $usersList->search();
    $searchDiv = $usersList->getForm();
    page_header();
    echo '<h2>' . _('List of users') . '</h2>';
    echo $searchDiv;
    if (count($us) == 0) {
        echo _('No available user') . '<br />';
    } else {
        echo '<table id="users_table" class="main_sub sortable" border="0" cellspacing="1" cellpadding="3">';
        echo '<thead>';
        echo '<tr class="title2">';
        echo '<th class="unsortable" colspan="3">' . _('Users') . '</th>';
        echo '<th colspan="2">' . _('Applications') . '</th>';
        echo '<th>' . _('Folders') . '</th>';
        echo '<th>' . _('Session') . '</th>';
        echo '</tr>';
        echo '<tr class="title">';
        echo '<th>' . _('Login') . '</th>';
        echo '<th>' . _('Name') . '</th>';
        echo '<th>' . _('In these users groups') . '</th>';
        echo '<th>' . _('Published applications groups') . '</th>';
        echo '<th>' . _('Access to these applications') . '</th>';
        echo '<th>' . _('Access to these folders') . '</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
        $count = 0;
        foreach ($us as $u) {
            $session_settings_defaults = $u->getSessionSettings('session_settings_defaults');
            echo '<tr class="content';
            if ($count % 2 == 0) {
                echo '1';
            } else {
                echo '2';
            }
            echo '">';
            echo '<td><a href="users.php?action=manage&id=' . $u->getAttribute('login') . '">' . $u->getAttribute('login') . '</a></td>';
            // login
            echo '<td><a href="users.php?action=manage&id=' . $u->getAttribute('login') . '">' . $u->getAttribute('displayname') . '</a></td>';
            //nam
            $users_grps = $u->usersGroups();
            // in user group
            echo '<td>';
            if (count($users_grps) == 0) {
                echo '<em>' . _('Not in any users group') . '</em>';
            } else {
                echo '<table border="0" cellspacing="1" cellpadding="3">';
                foreach ($users_grps as $ugrp) {
                    echo '<tr>';
                    echo '<td><a href="usersgroup.php?action=manage&id=' . $ugrp->getUniqueID() . '">' . $ugrp->name . '</a></td>';
                    echo '</tr>';
                }
                echo '</table>';
            }
            echo '</td>';
            $apps_grps = $u->appsGroups();
            if (count($apps_grps) == 0) {
                echo '<td colspan="2">';
                echo '<em>' . _('No publication') . '</em>';
                echo '</td>';
            } else {
                echo '<td>';
                echo '<table border="0" cellspacing="1" cellpadding="3">';
                foreach ($apps_grps as $agrp_id) {
                    $agrp = $applicationsGroupDB->import($agrp_id);
                    if (is_object($agrp)) {
                        echo '<tr>';
                        echo '<td><a href="appsgroup.php?action=manage&id=' . $agrp->id . '">' . $agrp->name . '</a></td>';
                        echo '</tr>';
                    }
                }
                echo '</table>';
                echo '</td>';
                echo '<td>';
                // in app
                $apps_s = $u->applications();
                if (count($apps_s) == 0) {
                    echo '<em>' . _('No applications in these groups') . '</em>';
                } else {
                    echo '<table border="0" cellspacing="1" cellpadding="3">';
                    foreach ($apps_s as $aaa) {
                        echo '<tr>';
                        echo '<td><img src="media/image/cache.php?id=' . $aaa->getAttribute('id') . '" alt="" title="" /></td>';
                        echo '<td><a href="applications.php?action=manage&id=' . $aaa->getAttribute('id') . '">' . $aaa->getAttribute('name') . '</a></td>';
                        echo '<td style="text-align: center;"><img src="media/image/server-' . $aaa->getAttribute('type') . '.png" width="16" height="16" alt="' . $aaa->getAttribute('type') . '" title="' . $aaa->getAttribute('type') . '" /></td>';
                        echo '</tr>';
                    }
                    echo '</table>';
                }
                echo '</td>';
            }
            echo '<td>';
            $folders = array();
            if (array_key_exists('enable_sharedfolders', $session_settings_defaults) && $session_settings_defaults['enable_sharedfolders'] == 1) {
                $folders = $u->getSharedFolders();
            }
            $profiles = array();
            if (array_key_exists('enable_profiles', $session_settings_defaults) && $session_settings_defaults['enable_profiles'] == 1) {
                $profiles = $u->getProfiles();
            }
            $networkfolder_s = array_merge($folders, $profiles);
            if (count($networkfolder_s) > 0) {
                echo '<table border="0" cellspacing="1" cellpadding="3">';
                foreach ($networkfolder_s as $a_networkfolder) {
                    echo '<tr>';
                    echo '<td>' . $a_networkfolder->prettyName() . '</td>';
                    if (isset($a_networkfolder->name) && $a_networkfolder->name !== '') {
                        $name = $a_networkfolder->name;
                    } else {
                        $name = $a_networkfolder->id;
                    }
                    echo '<td>';
                    if (isset($a_networkfolder->name)) {
                        $page = 'sharedfolders';
                    } else {
                        $page = 'profiles';
                    }
                    echo '<a href="' . $page . '.php?action=manage&id=' . $a_networkfolder->id . '">' . $name . '</a></td>';
                    echo '</tr>';
                }
                echo '</table>';
            }
            echo '</td>';
            echo '<td style="text-align: center;">';
            // server
            $sessionmanagement2 = clone $sessionmanagement;
            $sessionmanagement2->user = $u;
            $can_start_session = $sessionmanagement2->buildServersList();
            if ($can_start_session === true) {
                echo '<img src="media/image/ok.png" alt="" title="" />';
            } else {
                echo '<img src="media/image/cancel.png" alt="" title="" />';
            }
            echo '</td>';
            echo '</tr>';
            $count++;
        }
        echo '</tbody>';
        echo '</table>';
    }
    page_footer();
}
Пример #5
0
 public function session_simulate($user_login_)
 {
     $this->check_authorized('viewSummary');
     $userDB = UserDB::getInstance();
     $user = $userDB->import($user_login_);
     if (!$user) {
         return null;
     }
     $userGroupDB = UserGroupDB::getInstance();
     $applicationsGroupDB = ApplicationsGroupDB::getInstance();
     try {
         $sessionmanagement = SessionManagement::getInstance();
     } catch (Exception $err) {
         die_error('Unable to instanciate SessionManagement: ' . $err->getMessage(), __FILE__, __LINE__);
     }
     $info = array();
     // Should only request SessionManagement instance to catch all these information ...
     $info['settings'] = $user->getSessionSettings('session_settings_defaults');
     $search_limit = $this->prefs->get('general', 'max_items_per_page');
     $usergroupDB = UserGroupDB::getInstance();
     list($groups, $sizelimit_exceeded) = $usergroupDB->getGroupsContains('', array(), $search_limit, $user);
     $info['user_grps'] = array();
     $info['groups_partial_list'] = $sizelimit_exceeded;
     foreach ($groups as $group_id => $group) {
         $info['user_grps'][$group_id] = $group->name;
     }
     $info['apps_grps'] = array();
     $apps_grps = $user->appsGroups();
     foreach ($apps_grps as $agrp_id) {
         $agrp = $applicationsGroupDB->import($agrp_id);
         if (!is_object($agrp)) {
             continue;
         }
         $info['apps_grps'][$agrp_id] = $agrp->name;
     }
     $info['apps'] = array();
     $applications = $user->applications();
     foreach ($applications as $application) {
         $a = array('id' => $application->getAttribute('id'), 'name' => $application->getAttribute('name'), 'type' => $application->getAttribute('type'));
         $info['apps'][$a['id']] = $a;
     }
     $info['shared_folders'] = array();
     if (array_key_exists('enable_sharedfolders', $info['settings']) && $info['settings']['enable_sharedfolders'] == 1) {
         $shared_folders = $user->getSharedFolders();
         foreach ($shared_folders as $shared_folder_id => $infos) {
             $info['shared_folders'][$shared_folder_id] = array('share_name' => $infos['share']->name, 'mode' => $infos['mode']);
         }
     }
     $info['profiles'] = array();
     if (array_key_exists('enable_profiles', $info['settings']) && $info['settings']['enable_profiles'] == 1) {
         $profiles = $user->getProfiles();
         foreach ($profiles as $profile) {
             $info['profiles'][$profile->id] = $profile->id;
         }
     }
     $can_start_session = $user->can_use_session();
     $remote_desktop_settings = $user->getSessionSettings('remote_desktop_settings');
     $remote_desktop_enabled = $remote_desktop_settings['enabled'] == 1;
     $remote_applications_settings = $user->getSessionSettings('remote_applications_settings');
     $remote_applications_enabled = $remote_applications_settings['enabled'] == 1;
     $bypass_servers_restrictions = $info['settings']['bypass_servers_restrictions'] == 1;
     $sessionmanagement2 = clone $sessionmanagement;
     $sessionmanagement2->user = $user;
     $info['can_start_session_desktop'] = $can_start_session && $remote_desktop_enabled && $sessionmanagement2->getDesktopServer($bypass_servers_restrictions) && $sessionmanagement2->buildServersList(true);
     $sessionmanagement2 = clone $sessionmanagement;
     $sessionmanagement2->user = $user;
     $info['can_start_session_applications'] = $can_start_session && $remote_applications_enabled && $sessionmanagement2->buildServersList(true);
     if ($info['can_start_session_desktop'] || $info['can_start_session_applications']) {
         $sessionmanagement2 = clone $sessionmanagement;
         $sessionmanagement2->user = $user;
         $servers = $sessionmanagement2->chooseApplicationServers($bypass_servers_restrictions);
         $info['servers'] = array();
         if (is_array($servers)) {
             foreach ($servers as $server) {
                 $s = array('id' => $server->id, 'name' => $server->getDisplayName(), 'type' => $server->getAttribute('type'));
                 $info['servers'][$s['id']] = $s;
             }
         }
     }
     if (!$info['can_start_session_desktop'] || !$info['can_start_session_applications']) {
         if (!$can_start_session) {
             $info['cannot_start_session_reason'] = 'time_restriction';
         } else {
             if (!$remote_desktop_enabled || !$remote_applications_enabled) {
                 $info['cannot_start_session_reason'] = 'unauthorized_session_mode';
             } else {
                 $info['cannot_start_session_reason'] = 'invalid_publications';
             }
         }
     }
     return $info;
 }