Example #1
0
    echo '	<input type="hidden" name="selected_session[]" value="' . $session->id . '" />';
    echo '	<input type="submit" value="' . _('Kill this session') . '" />';
    echo '</form>';
    echo '</div>';
    page_footer();
} else {
    page_header();
    $total = Abstract_Session::countByStatus();
    echo '<h1>' . sprintf(_('Sessions (total: %s)'), $total) . '</h1>';
    if ($total > $prefs->get('general', 'max_items_per_page')) {
        if (!isset($_GET['start']) || (!is_numeric($_GET['start']) || $_GET['start'] >= $total)) {
            $start = 0;
        } else {
            $start = $_GET['start'];
        }
        $pagechanger = get_pagechanger('sessions.php?', $prefs->get('general', 'max_items_per_page'), $total);
        $sessions = Abstract_Session::load_partial($prefs->get('general', 'max_items_per_page'), $start);
    } else {
        $sessions = Abstract_Session::load_all();
    }
    if (is_array($sessions) && count($sessions) > 0) {
        $buf = array();
        foreach ($sessions as $session) {
            $buf[$session->getAttribute('user_login')] = $session;
        }
        ksort($buf);
        $sessions = $buf;
        echo '<div>';
        if (isset($pagechanger)) {
            echo $pagechanger;
        }
Example #2
0
} else {
    page_header();
    $nb_session_by_status = $_SESSION['service']->sessions_count();
    if (is_null($nb_session_by_status)) {
        $nb_session_by_status = array('total' => 0);
    }
    $total = $nb_session_by_status['total'];
    $max_items_per_page = $_SESSION['configuration']['max_items_per_page'];
    echo '<h1>' . sprintf(_('Sessions (total: %s)'), $total) . '</h1>';
    if ($total > $max_items_per_page) {
        if (!isset($_GET['start']) || (!is_numeric($_GET['start']) || $_GET['start'] >= $total)) {
            $start = 0;
        } else {
            $start = $_GET['start'];
        }
        $pagechanger = get_pagechanger('sessions.php?', $max_items_per_page, $total);
        $sessions = $_SESSION['service']->sessions_list($start);
    } else {
        $sessions = $_SESSION['service']->sessions_list();
    }
    if (is_array($sessions) && count($sessions) > 0) {
        $buf = array();
        foreach ($sessions as $session) {
            $buf[$session->getAttribute('user_login')] = $session;
        }
        ksort($buf);
        $sessions = $buf;
        echo '<div>';
        if (isset($pagechanger)) {
            echo $pagechanger;
        }
function server_display_role_preparation_aps($server)
{
    $ret = array();
    $server_online = $server->isOnline();
    $applications_all = $_SESSION['service']->applications_list();
    $applications = array();
    foreach ($server->applications as $application_id => $application_name) {
        if (array_key_exists($application_id, $applications_all)) {
            $applications[] = $applications_all[$application_id];
        }
    }
    uasort($applications, 'application_cmp');
    $applications_available = array();
    $static_applications_available = array();
    if (!$server_online && count($applications) == 0) {
        $applications_all = array();
    }
    $servers_replication = $_SESSION['service']->servers_list('online');
    if (is_null($servers_replication)) {
        $servers_replication = array();
    }
    foreach ($servers_replication as $k => $v) {
        if ($v->id == $server->id) {
            unset($servers_replication[$k]);
        }
        if ($v->type != $server->getAttribute('type')) {
            unset($servers_replication[$k]);
        }
        if (!array_key_exists(Server::SERVER_ROLE_APS, $v->roles)) {
            unset($servers_replication[$k]);
        }
        if ($server->hasAttribute('ulteo_system') == false || $server->getAttribute('ulteo_system') == 0) {
            unset($servers_replication[$k]);
        }
    }
    $sessions = array();
    $total = 0;
    if ($server->hasAttribute('sessions_number')) {
        $total = $server->getAttribute('sessions_number');
    }
    if ($total > 0) {
        $has_sessions = true;
        $search_limit = $_SESSION['configuration']['max_items_per_page'];
        if ($total > $search_limit) {
            if (!isset($_GET['start']) || (!is_numeric($_GET['start']) || $_GET['start'] >= $total)) {
                $start = 0;
            } else {
                $start = $_GET['start'];
            }
            $pagechanger = get_pagechanger('servers.php?action=manage&id=' . $server->id . '&', $search_limit, $total);
            $sessions = $_SESSION['service']->sessions_list_by_server($server->id, $start);
        } else {
            $sessions = $_SESSION['service']->sessions_list_by_server($server->id);
        }
    } else {
        $has_sessions = false;
    }
    $external_name_checklist = array('localhost', '127.0.0.1');
    if (in_array($server->getExternalName(), $external_name_checklist)) {
        popup_error(sprintf(_('Server "%s": redirection name may be invalid!'), $server->getDisplayName()));
    }
    if ($server_online) {
        $apps_in_remove = array();
        $apps_in_install = array();
        $tasks = array();
        if ($server_online) {
            $all_tasks = $_SESSION['service']->tasks_list();
            if (is_null($all_tasks)) {
                $all_tasks = array();
            }
            foreach ($all_tasks as $task) {
                if ($task->getAttribute('server') != $server->id) {
                    continue;
                }
                if (!$task->succeed()) {
                    $tasks[] = $task;
                }
            }
            foreach ($tasks as $task) {
                if ($task->hasAttribute('applications')) {
                    continue;
                }
                if ($task->getAttribute('type') == 'Task_install') {
                    foreach ($task->getAttribute('applications') as $app) {
                        if (!in_array($app, $apps_in_install)) {
                            $apps_in_install[] = $app;
                        }
                    }
                }
                if ($task->getAttribute('type') == 'Task_remove') {
                    foreach ($task->getAttribute('applications') as $app) {
                        if (!in_array($app, $apps_in_remove)) {
                            $apps_in_remove[] = $app;
                        }
                    }
                }
            }
            foreach ($applications_all as $app) {
                if (in_array($app, $applications)) {
                    continue;
                }
                if (in_array($app, $apps_in_install)) {
                    continue;
                }
                if ($app->getAttribute('type') != $server->getAttribute('type')) {
                    continue;
                }
                if ($app->getAttribute('static') == 1) {
                    $static_applications_available[] = $app;
                } else {
                    $applications_available[] = $app;
                }
            }
        }
        $ret['tasks'] = $tasks;
        $ret['apps_in_install'] = $apps_in_install;
        $ret['apps_in_remove'] = $apps_in_remove;
    }
    $ret['can_do_action'] = isAuthorized('manageServers');
    $ret['web_port'] = $server->getAttribute('web_port');
    $ret['can_use_apt'] = isset($server->ulteo_system) && $server->ulteo_system == 1 ? true : false;
    $ret['server_online'] = $server_online;
    $ret['sessions'] = $sessions;
    $ret['has_sessions'] = $has_sessions;
    $ret['total_sessions'] = $total;
    if (isset($pagechanger)) {
        $ret['pagechanger'] = $pagechanger;
    }
    $ret['applications'] = $applications;
    $ret['applications_available'] = $applications_available;
    $ret['static_applications_available'] = $static_applications_available;
    $ret['applications_all'] = $applications_all;
    $ret['servers_replication'] = $servers_replication;
    return $ret;
}
Example #4
0
function server_display_role_preparation_aps($server)
{
    $ret = array();
    $server_online = $server->isOnline();
    if ($server_online) {
        $buf = $server->updateApplications();
        if (!$buf) {
            popup_error(_('Cannot list available applications'));
        }
    }
    $applicationDB = ApplicationDB::getInstance();
    $applications_all = $applicationDB->getList(true);
    $applications = $server->getApplications();
    if (!is_array($applications)) {
        $applications = array();
    }
    usort($applications, 'application_cmp');
    $applications_available = array();
    $static_applications_available = array();
    if (!$server_online && count($applications) == 0) {
        $applications_all = array();
    }
    $servers_all = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE);
    foreach ($servers_all as $k => $v) {
        if ($v->fqdn == $server->fqdn) {
            unset($servers_all[$k]);
        }
    }
    $servers_replication = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE);
    foreach ($servers_replication as $k => $v) {
        if ($v->fqdn == $server->fqdn) {
            unset($servers_replication[$k]);
        }
        if ($v->type != $server->getAttribute('type')) {
            unset($servers_replication[$k]);
        }
        if (!array_key_exists('aps', $v->roles) || $v->roles['aps'] !== true) {
            unset($servers_replication[$k]);
        }
        if ($server->hasAttribute('ulteo_system') == false || $server->getAttribute('ulteo_system') == 0) {
            unset($servers_replication[$k]);
        }
    }
    $sessions = array();
    $total = Abstract_Session::countByServer($_GET['fqdn']);
    if ($total > 0) {
        $has_sessions = true;
        $prefs = Preferences::getInstance();
        if (!$prefs) {
            die_error('get Preferences failed', __FILE__, __LINE__);
        }
        if ($total > $prefs->get('general', 'max_items_per_page')) {
            if (!isset($_GET['start']) || (!is_numeric($_GET['start']) || $_GET['start'] >= $total)) {
                $start = 0;
            } else {
                $start = $_GET['start'];
            }
            $pagechanger = get_pagechanger('servers.php?action=manage&fqdn=' . $_GET['fqdn'] . '&', $prefs->get('general', 'max_items_per_page'), $total);
            $sessions = Abstract_Session::getByServer($_GET['fqdn'], $prefs->get('general', 'max_items_per_page'), $start);
        } else {
            $sessions = Abstract_Session::getByServer($_GET['fqdn']);
        }
    } else {
        $has_sessions = false;
    }
    $external_name_checklist = array('localhost', '127.0.0.1');
    if (in_array($server->fqdn, $external_name_checklist) && in_array($server->getAttribute('external_name'), $external_name_checklist)) {
        popup_error(sprintf(_('Server "%s": redirection name may be invalid!'), $server->fqdn));
    }
    if ($server->getAttribute('external_name') == '') {
        popup_error(sprintf(_('Server "%s": redirection name cannot be empty!'), $server->fqdn));
    }
    if ($server_online) {
        //FIX ME ?
        $tm = new Tasks_Manager();
        $tm->load_from_server($server->fqdn);
        $tm->refresh_all();
        $apps_in_remove = array();
        $apps_in_install = array();
        $tasks = array();
        if ($server_online) {
            foreach ($tm->tasks as $task) {
                if (!$task->succeed()) {
                    $tasks[] = $task;
                }
            }
            foreach ($tasks as $task) {
                if (get_class($task) == 'Task_install') {
                    foreach ($task->applications as $app) {
                        if (!in_array($app, $apps_in_install)) {
                            $apps_in_install[] = $app;
                        }
                    }
                }
                if (get_class($task) == 'Task_remove') {
                    foreach ($task->applications as $app) {
                        if (!in_array($app, $apps_in_remove)) {
                            $apps_in_remove[] = $app;
                        }
                    }
                }
            }
            foreach ($applications_all as $app) {
                if (in_array($app, $applications)) {
                    continue;
                }
                if (in_array($app, $apps_in_install)) {
                    continue;
                }
                if ($app->getAttribute('type') != $server->getAttribute('type')) {
                    continue;
                }
                $applications_available[] = $app;
            }
        }
        $ret['tasks'] = $tasks;
        $ret['apps_in_install'] = $apps_in_install;
        $ret['apps_in_remove'] = $apps_in_remove;
    }
    $ret['can_do_action'] = isAuthorized('manageServers');
    $ret['web_port'] = $server->getAttribute('web_port');
    $ret['can_use_apt'] = isset($server->ulteo_system) && $server->ulteo_system == 1 ? true : false;
    $ret['server_online'] = $server_online;
    $ret['sessions'] = $sessions;
    $ret['has_sessions'] = $has_sessions;
    $ret['total_sessions'] = $total;
    if (isset($pagechanger)) {
        $ret['pagechanger'] = $pagechanger;
    }
    $ret['applications'] = $applications;
    $ret['applications_available'] = $applications_available;
    $ret['applications_all'] = $applications_all;
    $ret['servers_all'] = $servers_all;
    $ret['servers_replication'] = $servers_replication;
    return $ret;
}