Esempio n. 1
0
                    $tm->add($t);
                    popup_info(_('Task successfully added'));
                }
            }
            redirect();
        }
    }
}
if ($_REQUEST['name'] == 'Task') {
    // it is the rigth place ? (see similar block on name=server action=install_line
    if (!checkAuthorization('manageServers')) {
        redirect();
    }
    $tm = new Tasks_Manager();
    $tm->load_all();
    $tm->refresh_all();
    if ($_REQUEST['action'] == 'add') {
        if (isset($_POST['type'])) {
            $type_task = 'Task_' . $_POST['type'];
            try {
                $task = new $type_task(0, $_POST['server'], $_POST['request']);
                $tm->add($task);
                popup_info(_("Task successfully added"));
            } catch (Exception $e) {
                Logger::error('main', 'tasks.php error create task (type=\'' . $type_task . '\')');
                popup_error("error create task (type='{$type_task}')");
            }
        }
        redirect('tasks.php');
    }
    if ($_REQUEST['action'] == 'del') {
Esempio n. 2
0
function show_manage($id, $applicationDB)
{
    $applicationsGroupDB = ApplicationsGroupDB::getInstance();
    $app = $applicationDB->import($id);
    if (!is_object($app)) {
        return false;
    }
    //     die_error('Unable to import application "'.$id.'"',__FILE__,__LINE__);
    if ($app->getAttribute('static')) {
        redirect('applications_static.php?action=manage&id=' . $app->getAttribute('id'));
    }
    $is_rw = $applicationDB->isWriteable();
    if ($app->getAttribute('published')) {
        $status = '<span class="msg_ok">' . _('Available') . '</span>';
        $status_change = _('Block');
        $status_change_value = 0;
    } else {
        $status = '<span class="msg_error">' . _('Blocked') . '</span>';
        $status_change = _('Unblock');
        $status_change_value = 1;
    }
    // Tasks
    $tm = new Tasks_Manager();
    $tm->load_from_application($id);
    $tm->refresh_all();
    $servers_in_install = array();
    $servers_in_remove = array();
    $tasks = array();
    foreach ($tm->tasks as $task) {
        if ($task->succeed()) {
            continue;
        }
        if ($task->failed()) {
            continue;
        }
        $tasks[] = $task;
        if (get_class($task) == 'Task_install') {
            if (!in_array($task->server, $servers_in_install)) {
                $servers_in_install[] = $task->server;
            }
        }
        if (get_class($task) == 'Task_remove') {
            if (!in_array($task->server, $servers_in_remove)) {
                $servers_in_remove[] = $task->server;
            }
        }
    }
    // Servers
    if ($app->getAttribute('static')) {
        $servers_all = array();
    } else {
        $servers_all = Abstract_Server::load_all();
    }
    $liaisons = Abstract_Liaison::load('ApplicationServer', $app->getAttribute('id'), NULL);
    $servers_id = array();
    foreach ($liaisons as $liaison) {
        $servers_id[] = $liaison->group;
    }
    $servers = array();
    $servers_available = array();
    foreach ($servers_all as $server) {
        if (in_array($server->fqdn, $servers_id)) {
            $servers[] = $server;
        } elseif (in_array($server->fqdn, $servers_in_install)) {
            continue;
        } elseif (!$server->isOnline()) {
            continue;
        } elseif ($server->type != $app->getAttribute('type')) {
            continue;
        } elseif (is_array($server->roles) && array_key_exists(Server::SERVER_ROLE_APS, $server->roles)) {
            $servers_available[] = $server;
        }
    }
    // App groups
    $appgroups = $applicationsGroupDB->getList(true);
    $groups_id = array();
    $liaisons = Abstract_Liaison::load('AppsGroup', $app->getAttribute('id'), NULL);
    foreach ($liaisons as $liaison) {
        $groups_id[] = $liaison->group;
    }
    $groups = array();
    $groups_available = array();
    foreach ($appgroups as $group) {
        if (in_array($group->id, $groups_id)) {
            $groups[] = $group;
        } else {
            $groups_available[] = $group;
        }
    }
    $can_manage_server = isAuthorized('manageServers');
    $can_manage_applicationsgroups = isAuthorized('manageApplicationsGroups');
    page_header();
    echo '<div>';
    echo '<h1><img src="media/image/cache.php?id=' . $app->getAttribute('id') . '" alt="" title="" /> ' . $app->getAttribute('name') . '</h1>';
    echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3">';
    echo '<tr class="title">';
    echo '<th>' . _('Package') . '</th>';
    echo '<th>' . _('Type') . '</th>';
    //   echo '<th>'._('Status').'</th>';
    echo '<th>' . _('Description') . '</th>';
    echo '<th>' . _('Executable') . '</th>';
    echo '</tr>';
    echo '<tr class="content1">';
    echo '<td>' . $app->getAttribute('package') . '</td>';
    echo '<td style="text-align: center;"><img src="media/image/server-' . $app->getAttribute('type') . '.png" alt="' . $app->getAttribute('type') . '" title="' . $app->getAttribute('type') . '" /><br />' . $app->getAttribute('type') . '</td>';
    //   echo '<td>'.$status.'</td>';
    echo '<td>' . $app->getAttribute('description') . '</td>';
    echo '<td>' . $app->getAttribute('executable_path') . '</td>';
    echo '</tr>';
    echo '</table>';
    echo '<br />';
    echo '<table border="0" cellspacing="0" cellpadding="0">';
    echo '<tr><td>';
    echo '<form action="applications.php" method="get"">';
    echo '<input type="hidden" name="action" value="icon" />';
    echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
    echo '<input type="submit" value="' . _('Set custom icon') . '"/>';
    echo '</form>';
    echo '</td><td style="width: 10px;"></td><td>';
    echo '<form action="actions.php" method="post"">';
    echo '<input type="hidden" name="name" value="Application" />';
    echo '<input type="hidden" name="action" value="clone" />';
    echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
    echo '<input type="submit" value="' . _('Clone to static application') . '"/>';
    echo '</form>';
    echo '</td></tr>';
    echo '</table>';
    echo '<br />';
    // orphan part
    if ($app->isOrphan() && !$app->getAttribute('static')) {
        echo '<br />';
        echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to remove this application?') . '\');">';
        echo '<input type="hidden" name="action" value="del" />';
        echo '<input type="hidden" name="name" value="Application" />';
        echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
        echo _('This application is orphan') . ' <input type="submit" value="' . _('Remove this application') . '"/>';
        echo '</form>';
        echo '<br />';
    }
    //   if ($is_rw) {
    //     echo '<h2>'._('Settings').'</h2>';
    //
    //     echo '<form action="" method="post">';
    //     echo '<input type="hidden" name="action" value="modify" />';
    //     echo '<input type="hidden" name="id" value="'.$app->getAttribute('id').'" />';
    //     echo '<input type="hidden" name="published" value="'.$status_change_value.'" />';
    //     echo '<input type="submit" value="'.$status_change.'"/>';
    //     echo '</form>';
    //   }
    // Server part
    if (count($servers) + count($servers_in_install) + count($servers_available) > 0) {
        echo '<div>';
        echo '<h2>' . _('Servers with this application') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($servers as $server) {
            $remove_in_progress = in_array($server->fqdn, $servers_in_remove);
            echo '<tr><td>';
            echo '<a href="servers.php?action=manage&fqdn=' . $server->fqdn . '">' . $server->fqdn . '</a>';
            echo '</td>';
            echo '<td>';
            if ($remove_in_progress) {
                echo 'remove in progress';
            } elseif ($server->isOnline() and $can_manage_server and $app->getAttribute('type') == 'linux' and $app->hasAttribute('package') and $app->getAttribute('package') !== '') {
                echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to remove this application from this server?') . '\');">';
                echo '<input type="hidden" name="action" value="del" />';
                echo '<input type="hidden" name="name" value="Application_Server" />';
                echo '<input type="hidden" name="application" value="' . $id . '" />';
                echo '<input type="hidden" name="server" value="' . $server->fqdn . '" />';
                echo '<input type="submit" value="' . _('Remove from this server') . '"/>';
                echo '</form>';
            }
            echo '</td>';
            echo '</tr>';
        }
        foreach ($servers_in_install as $server) {
            echo '<tr><td>';
            echo '<a href="servers.php?action=manage&fqdn=' . $server . '">' . $server . '</a>';
            echo '</td>';
            echo '<td>install in progress</td>';
            echo '</tr>';
        }
        if (count($servers_available) > 0 and $can_manage_server and $app->getAttribute('type') == 'linux' and $app->hasAttribute('package') and $app->getAttribute('package') !== '') {
            $display_list = false;
            foreach ($servers_available as $server) {
                if ($server->hasAttribute('ulteo_system') && $server->getAttribute('ulteo_system') == 1) {
                    $display_list = true;
                    break;
                }
            }
            if ($display_list) {
                echo '<tr>';
                echo '<form action="actions.php" method="post"><td>';
                echo '<input type="hidden" name="name" value="Application_Server" />';
                echo '<input type="hidden" name="action" value="add" />';
                echo '<input type="hidden" name="application" value="' . $id . '" />';
                echo '<select name="server">';
                foreach ($servers_available as $server) {
                    if ($server->hasAttribute('ulteo_system') && $server->getAttribute('ulteo_system') == 1) {
                        echo '<option value="' . $server->fqdn . '">' . $server->fqdn . '</option>';
                    }
                }
                echo '</select>';
                echo '</td><td><input type="submit" value="' . _('Install on this server') . '" /></td>';
                echo '</form>';
                echo '</tr>';
            }
        }
        echo '</table>';
        echo "<div>\n";
    }
    if (count($tasks) > 0) {
        echo '<h2>' . _('Active tasks on this application') . '</h1>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        echo '<tr class="title">';
        echo '<th>' . _('ID') . '</th>';
        echo '<th>' . _('Type') . '</th>';
        echo '<th>' . _('Status') . '</th>';
        echo '<th>' . _('Details') . '</th>';
        echo '</tr>';
        $count = 0;
        foreach ($tasks as $task) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            if ($task->failed()) {
                $status = '<span class="msg_error">' . _('Error') . '</span>';
            } else {
                $status = '<span class="msg_ok">' . $task->status . '</span>';
            }
            echo '<tr class="' . $content . '">';
            echo '<td><a href="tasks.php?action=manage&id=' . $task->id . '">' . $task->id . '</a></td>';
            echo '<td>' . get_class($task) . '</td>';
            echo '<td>' . $status . '</td>';
            echo '<td>' . $task->server . ', ' . $task->getRequest() . ', ' . $task->status_code . '</td>';
            echo '</tr>';
        }
        echo '</table>';
        echo "<div>\n";
    }
    if (count($appgroups) > 0) {
        echo '<div>';
        echo '<h2>' . _('Groups with this application') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($groups as $group) {
            echo '<tr>';
            echo '<td>';
            echo '<a href="appsgroup.php?action=manage&id=' . $group->id . '">' . $group->name . '</a>';
            echo '</td>';
            if ($can_manage_applicationsgroups) {
                echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this application from this group?') . '\');">';
                echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />';
                echo '<input type="hidden" name="action" value="del" />';
                echo '<input type="hidden" name="element" value="' . $id . '" />';
                echo '<input type="hidden" name="group" value="' . $group->id . '" />';
                echo '<input type="submit" value="' . _('Delete from this group') . '" />';
                echo '</form></td>';
            }
            echo '</tr>';
        }
        if (count($groups_available) > 0 and $can_manage_applicationsgroups) {
            echo '<tr>';
            echo '<form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="element" value="' . $id . '" />';
            echo '<select name="group">';
            foreach ($groups_available as $group) {
                echo '<option value="' . $group->id . '">' . $group->name . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add to this group') . '" /></td>';
            echo '</form>';
            echo '</tr>';
        }
        echo '</table>';
        echo "<div>\n";
    }
    // Mime-Type part
    echo '<div>';
    echo '<h2>' . _('Mime-Types') . '</h2>';
    echo '<div>';
    if (count($app->getMimeTypes()) == 0) {
        echo _('No available mimes-type') . '<br />';
    } else {
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($app->getMimeTypes() as $mime) {
            echo '<tr><td>';
            echo '<a href="mimetypes.php?action=manage&id=' . urlencode($mime) . '">' . $mime . '</a>';
            echo '</td></tr>';
        }
        echo '</table>';
    }
    echo '</div>';
    echo '</div>';
    // mime div
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    page_footer();
    die;
}
Esempio n. 3
0
 public function task_debian_upgrade($server_id_)
 {
     $this->check_authorized('manageServers');
     $server = Abstract_Server::load($server_id_);
     if (!is_object($server)) {
         Logger::error('api', sprintf('Unknown server "%s"', $server_id_));
         return null;
     }
     $tm = new Tasks_Manager();
     $tm->load_all();
     $tm->refresh_all();
     $t = new Task_upgrade(0, $server_id_);
     $tm->add($t);
     $this->log_action('task_debian_upgrade', array('server_id' => $server->id, 'server_name' => $server->getDisplayName()));
     return $t->id;
 }
Esempio n. 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;
}