<td style="padding-right: 20px; text-align: left; vertical-align: top;"> <div class="container rounded" style="background: #eee; width: 99%; margin-left: auto; margin-right: auto;"> <div> <h2><?php echo _('Status'); ?> </h2> <?php if ($show_status) { echo '<ul>'; $count_active_sessions = Abstract_Session::countByStatus(Session::SESSION_STATUS_ACTIVE); $online_servers = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE); $count_online_servers = count($online_servers); $offline_servers = Abstract_Server::load_by_status(Server::SERVER_STATUS_OFFLINE); $count_offline_servers = count($offline_servers); $broken_servers = Abstract_Server::load_by_status(Server::SERVER_STATUS_BROKEN); $count_broken_servers = count($broken_servers); echo '<li>'; echo $count_active_sessions . ' '; echo '<a href="sessions.php">'; if ($count_active_sessions > 1) { echo _('active sessions'); } else { echo _('active session'); } echo '</a>'; echo '</li>'; echo '<li>'; echo $count_online_servers . ' '; echo '<a href="servers.php">'; if ($count_online_servers > 1) {
public function servers_list($filter = null) { $this->check_authorized('viewServers'); if ($filter == 'online') { $servers = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE); } else { if ($filter == 'unregistered') { $servers = Abstract_Server::load_registered(false); } else { if ($filter == 'role_aps') { $servers = Abstract_Server::load_available_by_role(Server::SERVER_ROLE_APS, true); } else { $servers = Abstract_Server::load_registered(true); } } } $ret = array(); foreach ($servers as $server) { if (!$server->getAttribute('registered')) { if ($server->getAttribute('type') == '') { $server->isOK(); } if ($server->getAttribute('cpu_model') == '') { $server->getMonitoring(); } Abstract_Server::save($server); } $s = array('id' => $server->id, 'fqdn' => $server->fqdn, 'status' => $server->getAttribute('status'), 'registered' => $server->getAttribute('registered'), 'locked' => $server->getAttribute('locked'), 'type' => $server->getAttribute('type'), 'version' => $server->getAttribute('version'), 'cpu_model' => $server->getAttribute('cpu_model'), 'cpu_nb_cores' => $server->getAttribute('cpu_nb_cores'), 'ram_total' => $server->getAttribute('ram_total'), 'cpu_load' => $server->getAttribute('cpu_load'), 'ram_used' => $server->getAttribute('ram_used'), 'timestamp' => $server->getAttribute('timestamp')); if (!$server->getAttribute('registered')) { $s['can_register'] = $server->isOK(); } foreach (array('roles', 'roles_disabled', 'display_name', 'external_name', 'rdp_port', 'max_sessions', 'ulteo_system', 'windows_domain', 'disk_total', 'disk_free') as $key) { if ($server->hasAttribute($key)) { $s[$key] = $server->getAttribute($key); } } $ret[$s['id']] = $s; } return $ret; }
function show_default($tm) { $servers_ = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE); $servers = array(); foreach ($servers_ as $server) { if (isset($server->ulteo_system) && $server->ulteo_system == 1) { $servers[] = $server; } } $can_do_action = isAuthorized('manageServers'); page_header(); echo '<div id="tasks_div">'; echo '<h1>' . _('Tasks') . '</h1>'; if (count($tm->tasks) > 0) { echo '<div id="tasks_list_div">'; echo '<h2>' . _('List of tasks') . '</h2>'; echo '<table class="main_sub sortable" id="tasks_list_table" border="0" cellspacing="1" cellpadding="5">'; echo '<thead>'; echo '<tr class="title">'; echo '<th>' . _('ID') . '</th>'; echo '<th>' . _('Creation time') . '</th>'; echo '<th>' . _('Type') . '</th>'; echo '<th>' . _('Server') . '</th>'; echo '<th>' . _('Status') . '</th>'; echo '<th>' . _('Details') . '</th>'; echo '</tr>'; echo '</thead>'; echo '<tbody>'; $count = 0; foreach ($tm->tasks as $task) { $content = 'content' . ($count++ % 2 == 0 ? 1 : 2); $can_remove = $task->succeed() || $task->failed(); if ($task->succeed()) { $status = '<span class="msg_ok">' . _('Finished') . '</span>'; } elseif ($task->failed()) { $status = '<span class="msg_error">' . _('Error') . '</span>'; } elseif ($task->status == 'in progress') { $status = '<span class="msg_warn">' . _('In progress') . '</span>'; } else { $status = $task->status; } echo '<tr class="' . $content . '">'; echo '<td><a href="?action=manage&id=' . $task->id . '">' . $task->id . '</a></td>'; echo '<td>' . date('Y-m-d H:i:s', $task->t_begin) . '</td>'; echo '<td>' . get_class($task) . '</td>'; echo '<td><a href="servers.php?action=manage&fqdn=' . $task->server . '">' . $task->server . '</a></td>'; echo '<td>' . $status . '</td>'; echo '<td>' . $task->getRequest() . '</td>'; if ($can_do_action) { echo '<td>'; if ($can_remove) { echo '<form action="actions.php" method="post">'; echo '<input type="hidden" name="name" value="Task" />'; echo '<input type="hidden" name="action" value="del" />'; echo '<input type="hidden" name="checked_tasks[]" value="' . $task->id . '" />'; echo '<input type="submit" value="' . _('Delete') . '" />'; echo '</form>'; } echo '</td>'; } echo '</tr>'; } echo '</tbody>'; echo '</table>'; echo '</div>'; } if (count($servers) > 0 && $can_do_action) { echo '<h2>' . _('Install an application from a package name') . '</h2>'; echo '<form action="actions.php" method="post">'; echo '<input type="hidden" name="name" value="Task" />'; echo '<input type="hidden" name="action" value="add" />'; echo '<select name="server">'; foreach ($servers as $server) { echo '<option value="' . $server->fqdn . '">' . $server->fqdn . '</option>'; } echo '</select> '; echo '<input type="text" name="request" value="" /> '; echo '<input type="hidden" name="type" value="install_from_line" />'; echo '<input type="submit" name="submit" value="' . _('Install') . '" />'; echo '</form>'; echo '<h2>' . _('Upgrade the internal system and applications') . '</h2>'; echo '<form action="actions.php" method="post">'; echo '<input type="hidden" name="name" value="Task" />'; echo '<input type="hidden" name="action" value="add" />'; echo '<input type="hidden" name="type" value="upgrade" />'; echo '<input type="hidden" name="request" value="" />'; // hack for the task creation echo '<select name="server">'; foreach ($servers as $server) { echo '<option value="' . $server->fqdn . '">' . $server->fqdn . '</option>'; } echo '</select> '; echo '<input type="submit" name="submit" value="' . _('Upgrade') . '" />'; echo '</form>'; } echo '</div>'; page_footer(); die; }
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; }