Example #1
0
function launch_bundle($cible, $orders, $gid = null, $proxy = array())
{
    $params = array();
    foreach (array('start_date', 'end_date', 'create_directory', 'start_script', 'delete_file_after_execute_successful', 'wake_on_lan', 'next_connection_delay', 'max_connection_attempt', 'start_inventory', 'maxbw', 'deployment_intervals', 'copy_mode', 'clean_on_success', 'do_wol', 'do_inventory', 'do_reboot', 'bundle_title') as $param) {
        $params[$param] = $_POST[$param];
    }
    $halt_to = array();
    foreach ($_POST as $p => $v) {
        if (preg_match('/^issue_halt_to_/', $p)) {
            $p = preg_replace('/^issue_halt_to_/', '', $p);
            if ($v == 'on') {
                $halt_to[] = $p;
            }
        }
    }
    $params['issue_halt_to'] = $halt_to;
    // given a proxy list and a proxy style, we now have to build or proxy chain
    // target structure is an dict using the following stucture: "priority" => array(proxies)
    $ordered_proxies = array();
    if ($_POST['proxy_mode'] == 'multiple') {
        // first case: split mode; every proxy got the same priority (1 in our case)
        foreach ($proxy as $p) {
            array_push($ordered_proxies, array('uuid' => $p, 'priority' => 1, 'max_clients' => $_POST['max_clients_per_proxy']));
        }
        $params['proxy_mode'] = 'split';
    } elseif ($_POST['proxy_mode'] == 'single') {
        // second case: queue mode; one priority level per proxy, starting at 1
        $current_priority = 1;
        foreach ($proxy as $p) {
            array_push($ordered_proxies, array('uuid' => $p, 'priority' => $current_priority, 'max_clients' => $_POST['max_clients_per_proxy']));
            $current_priority += 1;
        }
        $params['proxy_mode'] = 'queue';
    }
    // TODO: activate this  : msc_command_set_pause($cmd_id);
    $ret = add_bundle_api($orders, $cible, $params, $params['copy_mode'], $gid, $ordered_proxies);
    if (is_array($ret) && !empty($ret)) {
        $commands = $ret[1];
        scheduler_start_these_commands('', $commands);
    }
    return $ret;
}
Example #2
0
$params['tab'] = $prefix . 'tablaunch';
$halt_to = array();
foreach ($_POST as $p => $v) {
    if (preg_match('/^issue_halt_to_/', $p)) {
        $p = preg_replace('/^issue_halt_to_/', '', $p);
        if ($v == 'on') {
            $halt_to[] = $p;
        }
    }
}
$params['issue_halt_to'] = $halt_to;
$mode = web_def_mode();
$prefix = '';
if (strlen($gid)) {
    $prefix = 'group';
}
$cible = array($uuid);
// TODO: activate this  : msc_command_set_pause($cmd_id);
$id_command = add_command_api($pid, $cible, $params, $p_api, $mode, $gid);
if (!isXMLRPCError()) {
    scheduler_start_these_commands('', array($id_command));
    header("Location: " . urlStrRedirect("msc/logs/viewLogs", array('tab' => $prefix . $tab, 'uuid' => $uuid, 'hostname' => $hostname, 'gid' => $gid, 'cmd_id' => $id_command)));
    exit;
} else {
    ## Return to the launch tab, the backtrace will be displayed
    header("Location: " . urlStrRedirect("msc/logs/viewLogs", array('tab' => $prefix . 'tablaunch', 'uuid' => $uuid, 'hostname' => $hostname, 'gid' => $gid, 'cmd_id' => $id_command)));
    exit;
}
?>

<?php

require_once 'modules/msc/includes/commands_xmlrpc.inc.php';
require_once 'modules/msc/includes/scheduler_xmlrpc.php';
$input = file_get_contents('php://input');
$data = json_decode($input, true);
// This ajax page permits to deploy a package using params from POST
$pid = $data['pid'];
$uuids = $data['uuids'];
$deploy_params = $data['deploy_params'];
$mirror = $data['mirror'];
$method = $data['method'];
// Adding command
$cmd_id = add_command_api($pid, $uuids, $deploy_params, $mirror, $method, '', array(), 0);
// Starting command
scheduler_start_these_commands('', array($cmd_id));
Example #4
0
function start_a_command($proxy = array())
{
    if ($_POST['editConvergence']) {
        $changed_params = getChangedParams($_POST);
        if ($changed_params == array('active')) {
            print "We have to edit command....";
        }
    }
    $error = "";
    if (!check_date($_POST)) {
        $error .= _T("Your start and end dates are not coherent, please check them.<br/>", "msc");
    }
    # should add some other tests on fields (like int are int? ...)
    if ($error != '') {
        new NotifyWidgetFailure($error);
        complete_post();
        $url = "base/computers/msctabs?";
        foreach ($_GET as $k => $v) {
            $url .= "{$v}={$k}";
        }
        header("Location: " . urlStrRedirect("msc/logs/viewLogs", array_merge($_GET, $_POST, array('failure' => True))));
        exit;
    }
    // Vars seeding
    $post = $_POST;
    $from = $post['from'];
    $path = explode('|', $from);
    $module = $path[0];
    $submod = $path[1];
    $page = $path[2];
    $params = array();
    foreach (array('start_script', 'clean_on_success', 'do_reboot', 'do_wol', 'next_connection_delay', 'max_connection_attempt', 'do_inventory', 'ltitle', 'parameters', 'papi', 'maxbw', 'deployment_intervals', 'max_clients_per_proxy', 'launchAction') as $param) {
        $params[$param] = $post[$param];
    }
    $halt_to = array();
    foreach ($post as $p => $v) {
        if (preg_match('/^issue_halt_to_/', $p)) {
            $p = preg_replace('/^issue_halt_to_/', '', $p);
            if ($v == 'on') {
                $halt_to[] = $p;
            }
        }
    }
    $params['issue_halt_to'] = $halt_to;
    $p_api = new ServerAPI();
    $p_api->fromURI($post['papi']);
    foreach (array('start_date', 'end_date') as $param) {
        if ($post[$param] == _T("now", "msc")) {
            $params[$param] = "0000-00-00 00:00:00";
        } elseif ($post[$param] == _T("never", "msc")) {
            $params[$param] = "0000-00-00 00:00:00";
        } else {
            $params[$param] = $post[$param];
        }
    }
    $pid = $post['pid'];
    $mode = $post['copy_mode'];
    if (isset($post['uuid']) && $post['uuid']) {
        // command on a single target
        $hostname = $post['hostname'];
        $uuid = $post['uuid'];
        $target = array($uuid);
        $tab = 'tablogs';
        /* record new command */
        $id = add_command_api($pid, $target, $params, $p_api, $mode, NULL);
        if (!isXMLRPCError()) {
            scheduler_start_these_commands('', array($id));
            /* then redirect to the logs page */
            header("Location: " . urlStrRedirect("msc/logs/viewLogs", array('tab' => $tab, 'uuid' => $uuid, 'hostname' => $hostname, 'cmd_id' => $id)));
            exit;
        } else {
            /* Return to the launch tab, the backtrace will be displayed */
            header("Location: " . urlStrRedirect("msc/logs/viewLogs", array('tab' => 'tablaunch', 'uuid' => $uuid, 'hostname' => $hostname)));
            exit;
        }
    } else {
        # command on a whole group
        $gid = $post['gid'];
        $tab = 'grouptablogs';
        // record new command
        // given a proxy list and a proxy style, we now have to build or proxy chain
        // target structure is an dict using the following stucture: "priority" => array(proxies)
        $ordered_proxies = array();
        if ($_POST['proxy_mode'] == 'multiple') {
            // first case: split mode; every proxy got the same priority (1 in our case)
            foreach ($proxy as $p) {
                array_push($ordered_proxies, array('uuid' => $p, 'priority' => 1, 'max_clients' => $_POST['max_clients_per_proxy']));
            }
            $params['proxy_mode'] = 'split';
        } elseif ($_POST['proxy_mode'] == 'single') {
            // second case: queue mode; one priority level per proxy, starting at 1
            $current_priority = 1;
            foreach ($proxy as $p) {
                array_push($ordered_proxies, array('uuid' => $p, 'priority' => $current_priority, 'max_clients' => $_POST['max_clients_per_proxy']));
                $current_priority += 1;
            }
            $params['proxy_mode'] = 'queue';
        }
        if (quick_get('convergence')) {
            $active = $_POST['active'] == 'on' ? 1 : 0;
            $cmd_type = 2;
            // Convergence command type
            if (quick_get('editConvergence')) {
                /* Stop command */
                $cmd_id = xmlrpc_get_convergence_command_id($gid, $p_api, $pid);
                stop_command($cmd_id);
                /* Set end date of this command to now(), don't touch to start date */
                $start_date = _get_command_start_date($cmd_id);
                extend_command($cmd_id, $start_date, date("Y-m-d H:i:s"));
                /* Create new command */
                $deploy_group_id = xmlrpc_get_deploy_group_id($gid, $p_api, $pid);
                $command_id = add_command_api($pid, NULL, $params, $p_api, $mode, $deploy_group_id, $ordered_proxies, $cmd_type);
                if (!$active) {
                    // If this convergence is not active, expire this command
                    $start_date = _get_command_start_date($command_id);
                    extend_command($command_id, $start_date, date("Y-m-d H:i:s"));
                }
                /* Update convergence DB */
                $updated_datas = array('active' => $active, 'commandId' => intval($command_id), 'cmdPhases' => $params);
                xmlrpc_edit_convergence_datas($gid, $p_api, $pid, $updated_datas);
            } else {
                /* Create convergence */
                // create sub-groups
                $group = new Group($gid, True);
                $package = to_package(getPackageDetails($p_api, $pid));
                $convergence_groups = $group->createConvergenceGroups($package);
                $deploy_group_id = $convergence_groups['deploy_group_id'];
                $done_group_id = $convergence_groups['done_group_id'];
                // Add command on sub-group
                $command_id = add_command_api($pid, NULL, $params, $p_api, $mode, $deploy_group_id, $ordered_proxies, $cmd_type);
                if (!$active) {
                    // If this convergence is not active, expire this command
                    $start_date = _get_command_start_date($command_id);
                    extend_command($command_id, $start_date, date("Y-m-d H:i:s"));
                }
                // feed convergence db
                xmlrpc_add_convergence_datas($gid, $deploy_group_id, $done_group_id, $pid, $p_api, intval($command_id), $active, $params);
            }
            header("Location: " . urlStrRedirect("base/computers/groupmsctabs", array('gid' => $gid)));
            exit;
        } else {
            $id = add_command_api($pid, NULL, $params, $p_api, $mode, $gid, $ordered_proxies);
            scheduler_start_these_commands('', array($id));
            // then redirect to the logs page
            header("Location: " . urlStrRedirect("msc/logs/viewLogs", array('tab' => $tab, 'gid' => $gid, 'cmd_id' => $id, 'proxy' => $proxy)));
            exit;
        }
    }
}
Example #5
0
function action($action, $target, $is_advanced) {
    $from = $_GET['from'];
    $path =  explode('|', $from);
    $module = $path[0];
    $submod = $path[1];
    $page = $path[2];
    $tab = $path[3];

    /* Handle posting of quick actions */
    if ($_SESSION["lang"] == "C") {
        $current_lang = "";
    } else {
        $current_lang = substr($_SESSION["lang"], 0, 2);
    }
    if (count($_GET["gid"]) > 0) {
        $type = 'group';
    } else {
        $type = '';
    }

    if ($is_advanced) {
        $params = array('from'=> 'base|computers|msctabs|tablaunch');
        foreach (array('gid', 'uuid', 'hostname') as $param) {
            $params[$param] = $_GET[$param];
        }

        $qa = msc_script_detailled_info($action);
        if ($qa[0]) {
            $qa = $qa[1];

            $params['badvanced'] = True;
            if (isset($qa['title'.$current_lang])) {
                $params['ltitle'] = trim('[QA] '.$qa['title'.$current_lang]);
            } else {
                $params['ltitle'] = trim('[QA] '.$qa['title']);
            }

            if ($action == '007wake_on_lan.msc') {
                # this is a very special case for WOL, it's not a command as we usualy understand it...
                $params['failure'] = '1';
                $params['create_directory'] = 'off';
                $params['start_script'] = 'off';
                $params['clean_on_success'] = 'off';
                $params['do_reboot'] = 'off';
                $params['do_wol'] = 'on';
                $params['do_inventory'] = 'off';
                $params['issue_halt'] = 'off';
                $params['next_connection_delay'] = 0;
                $params['max_connection_attempt'] = 1;
                $params['attempts_left'] = 1;
                foreach (array('create_directory', 'start_script', 'clean_on_success', 'do_reboot', 'do_wol', 'next_connection_delay', 'max_connection_attempt', 'do_inventory', 'copy_mode', 'deployment_intervals', 'issue_halt', 'parameters', 'local_proxy', 'maxbw') as $p) {
                     $params['hide_'.$p] = True;
                }
            } else {
                $params['do_reboot'] = '';
                $params["next_connection_delay"]  = web_def_delay();
                $params["max_connection_attempt"] = web_def_attempts();
                $params["maxbw"]                  = web_def_maxbw();
                $params["copy_mode"]              = web_def_mode();
                $params["deployment_intervals"]   = web_def_deployment_intervals();
                $halt = web_def_issue_halt_to();
                foreach ($halt as $h) {
                    $params["issue_halt_to_".$h] = 'on';
                }
            }
            $params['launchAction'] = $action;

            header("Location: ".urlStrRedirect("base/computers/".$type."msctabs", $params));
            exit;
        } else {
            new NotifyWidgetFailure(_T('Failed to retrieve this quick action.', 'msc'));
        }
    } else {
        $id = add_command_quick_with_id($action, $target, $current_lang, $_GET["gid"]);
        if ($id != -1) {
            scheduler_start_these_commands("", array($id));
            // if on a single computer
            if (count($_GET["gid"]) > 0) {
                $actionpage = 'groupmsctabs';
                $tab = 'grouptablogs';
            } else {
                $actionpage = 'msctabs';
                $tab = 'tablogs';
            }
            header("Location: ".urlStrRedirect("base/computers/$actionpage", array('tab'=>$tab, 'uuid'=>$_GET['uuid'], 'hostname'=>$_GET['hostname'], 'cmd_id'=>$id, 'gid'=>$_GET['gid'])));
            exit;
        }
    }
}