Exemple #1
0
// Loop through the added elements parts to display it
foreach ($removed_elems as $part => $removed_part) {
    if (!empty($removed_part)) {
        // Loop through each element of the part
        foreach ($removed_part as $elem) {
            // Loop through elems to change arrays into dates
            foreach ($elem as $k => $v) {
                if (is_array($v)) {
                    $elem[$k] = _toDate($v);
                }
            }
            // Create a ListInfos to display the infos of the element in a list
            $list = new ListInfos(array_keys($elem), _T("Element", "inventory"));
            $list->addExtraInfo(array_values($elem), _T("Value", "inventory"));
            $list->setName(_T($part));
            $list->setTableHeaderPadding(0);
            // Append the ListInfo in an array, to display all ListInfos together at the end of the page loading
            $removed_part_lists[] = $list;
        }
    }
}
// Display the page
$p->display();
// Display the added elements (without navbar)
print "<h3>" . _T("Added elements", "inventory") . "</h3>";
foreach ($added_part_lists as $list) {
    print '<h4>' . $list->name . '</h4>';
    $list->display($navbar = 0, $header = 0);
}
print "<br/><br/><br/>";
// Display the removed elements (without navbar)
$editAction = new ActionItem(_T("edit static host", "network"), "subnetedithost", "edit", "ipaddress", "network", "network");
$emptyAction = new EmptyActionItem();
foreach ($lines as $ipaddress => $infos) {
    $hosts[] = $infos["hostname"];
    $ipaddresses[] = long2ip($ipaddress);
    $macaddresses[] = $infos["macaddress"];
    $types[] = $infos["type"];
    $params[] = array("host" => $infos["hostname"], "macaddress" => $infos["macaddress"], "subnet" => $subnet);
    if ($infos["type"] == _T("Static", "network")) {
        $actionsAdd[] = $emptyAction;
        $actionsDel[] = $deleteAction;
        $actionsEdit[] = $editAction;
    } else {
        $actionsAdd[] = $addAction;
        $actionsDel[] = $emptyAction;
        $actionsEdit[] = $emptyAction;
    }
}
$n = new ListInfos($ipaddresses, _T("IP address", "network"));
$n->setNavBar(new AjaxNavBar(count($ipaddresses), $filter));
$n->disableFirstColumnActionLink();
$n->setTableHeaderPadding(1);
$n->addExtraInfo($hosts, _T("Host name", "network"));
$n->addExtraInfo($macaddresses, _T("MAC address", "network"));
$n->addExtraInfo($types, _T("Type", "network"));
$n->setName(_T("Host", "network"));
$n->setParamInfo($params);
$n->addActionItemArray($actionsAdd);
$n->addActionItemArray($actionsEdit);
$n->addActionItemArray($actionsDel);
$n->display();
Exemple #3
0
        $a_desc[] = $entry['image']['desc'];
        $default_name = $entry['image']['name'];
        $kind = 'IM';
    } else {
        $a_desc[] = $entry['boot_service']['default_desc'];
        $default_name = $entry['boot_service']['default_name'];
        $kind = 'BS';
    }
    $list_params[$i]["itemlabel"] = urlencode($default_name);
    $a_label[] = sprintf("%s%s", $kind == 'IM' ? '<img src="modules/imaging/graph/images/imaging-action.png" style="vertical-align: middle" /> ' : '<img src="modules/imaging/graph/images/service-action.png" style="vertical-align: middle" /> ', $default_name);
    $a_default[] = $entry['default'];
    $a_display[] = $entry['hidden'] ? False : True;
    $a_defaultWOL[] = $entry['default_WOL'];
    $a_displayWOL[] = $entry['hidden_WOL'] ? False : True;
}
$t = new TitleElement(_T("Default boot menu configuration", "imaging"), 3);
$t->display();
$l = new ListInfos($a_label, _T("Label", "imaging"));
$l->setParamInfo($list_params);
$l->addExtraInfo($a_desc, _T("Description", "imaging"));
$l->addExtraInfo($a_default, _T("Default", "imaging"));
$l->addExtraInfo($a_display, _T("Displayed", "imaging"));
$l->addExtraInfo($a_defaultWOL, _T("Default on WOL", "imaging"));
$l->addExtraInfo($a_displayWOL, _T("Displayed on WOL", "imaging"));
$l->addActionItemArray($actionsUp);
$l->addActionItemArray($actionsDown);
$l->addActionItem(new ActionItem(_T("Edit"), "bootmenu_edit", "edit", "item", "imaging", "manage"));
$l->setTableHeaderPadding(19);
$l->disableFirstColumnActionLink();
$l->display();
require "../includes/ajaxcommon_bottom.inc.php";
 function display()
 {
     // display parameters
     if (!$this->db_cmd) {
         # use does not have the good permissions
         $widget = new RenderedMSCCommandDontExists();
         $widget->display();
         return;
     }
     if ($this->db_cmd['start_date']) {
         if ($this->db_cmd['end_date']) {
             $validity = sprintf(_T('<i>from</i> %s <i>to</i> %s', 'msc'), _toDate($this->db_cmd['start_date']), _toDate($this->db_cmd['end_date']));
         } else {
             $validity = sprintf(_T('<i>from</i> %s', 'msc'), _toDate($this->db_cmd['start_date']));
         }
     } else {
         if ($this->db_cmd['end_date']) {
             $validity = sprintf(_T('<i>to</i> %s', 'msc'), _toDate($this->db_cmd['end_date']));
         } else {
             $validity = _T('<i>forever</i>', 'msc');
         }
     }
     if ($this->db_cmd['deployment_intervals']) {
         $deploy_interv = str_replace(array('-', ','), array(' - ', ', '), $this->db_cmd['deployment_intervals']);
     } else {
         $deploy_interv = _T('<i>whole day</i>', 'msc');
     }
     if ($this->db_cmd['deployment_intervals']) {
         $deploy_interv = str_replace(array('-', ','), array(' - ', ', '), $this->db_cmd['deployment_intervals']);
     } else {
         $deploy_interv = _T('<i>whole day</i>', 'msc');
     }
     if ($this->db_coh['next_launch_date']) {
         $next_launch_date = _toDate($this->db_coh['next_launch_date']);
     } else {
         if ($this->db_cmd['start_date']) {
             $next_launch_date = _toDate($this->db_cmd['start_date']);
         } else {
             $next_launch_date = _T('<i>as soon as possible</i>', 'msc');
         }
     }
     if ($this->db_coh['start_date']) {
         $start_date = _toDate($this->db_coh['start_date']);
     } else {
         $start_date = _T('<i>not yet available</i>', 'msc');
     }
     if ($this->db_coh['end_date']) {
         $end_date = _toDate($this->db_coh['end_date']);
     } else {
         $end_date = _T('<i>not yet available</i>', 'msc');
     }
     if ($this->db_coh['last_wol_attempt']) {
         $last_wol_attempt = _toDate($this->db_coh['last_wol_attempt']);
     } else {
         $last_wol_attempt = _T('<i>not available</i>', 'msc');
     }
     if ($this->db_cmd['start_file']) {
         if ($this->db_cmd['parameters']) {
             $command_line = sprintf(_T('%s %s', 'msc'), $this->db_cmd['start_file'], $this->db_cmd['parameters']);
         } else {
             $command_line = sprintf(_T('%s <i>(no additional parameter given)</i>', 'msc'), $this->db_cmd['start_file']);
         }
     } else {
         $command_line = _T('<i>not set</i>', 'msc');
     }
     if ($this->db_coh['order_in_proxy'] == '') {
         $proxy_priority = _T('None (Local Proxy Client)', 'msc');
     } else {
         $proxy_priority = sprintf(_T('%s (Local Proxy Server)', 'msc'), $this->db_coh['order_in_proxy']);
     }
     if ($this->db_cmd['proxy_mode'] == 'split') {
         $proxy_mode = _T('Multiple', 'msc');
     } elseif ($this->db_cmd['proxy_mode'] == 'queue') {
         $proxy_mode = _T('Single with fallback', 'msc');
     } elseif ($this->db_cmd['proxy_mode'] == 'none') {
         $proxy_mode = _T('No proxy', 'msc');
         $proxy_priority = _T('None', 'msc');
     } else {
         $proxy_mode = _T('<i>not available</i>', 'msc');
         $proxy_priority = _T('<i>not available</i>', 'msc');
     }
     if ($this->db_lproxy) {
         $current_proxy = $this->db_lproxy['host'];
     } else {
         $current_proxy = _T('<i>not available</i>', 'msc');
     }
     // gettext obfucation
     _T('enable', 'msc');
     _T('disable', 'msc');
     _T('done', 'msc');
     _T('failed', 'msc');
     _T('over_time', 'msc');
     _T('out_of_interval', 'msc');
     // =====================================================================
     function formatLog($hist)
     {
         $i = 1;
         if ($hist['state'] == 'upload_in_progress' && $hist['error_code'] == '0' && array_key_exists('stderr', $hist) && $i != count($this->db_ch) && strpos($hist['stderr'], 'is available on mirror') !== False) {
             /*
              We are displaying which package server was used in push pull
              mode. We want to keep the led green instead of orange to
              tell the user that there was no problem.
             */
             $staticon = history_stat2icon("upload_done");
         } elseif ($hist['state'] == 'wol_failed' && $hist['error_code'] == '2001') {
             $staticon = history_stat2icon("stop");
         } else {
             $staticon = history_stat2icon($hist['state']);
         }
         $history = date("Y-m-d H:i:s", $hist['date']);
         /* Split lines in stdout and stderr */
         if (gettype($hist["stdout"]) != 'array') {
             $hist["stdout"] = split("\n", $hist["stdout"]);
         }
         if (gettype($hist["stderr"]) != 'array') {
             $hist["stderr"] = split("\n", $hist["stderr"]);
         }
         if (count($hist["stdout"]) > 0 && !(count($hist["stdout"]) == 1 && $hist["stdout"][0] == '')) {
             $hist["stderr"] = array_merge($hist["stderr"], $hist["stdout"]);
         }
         if (strpos($hist['state'], '_failed') !== False || $hist['error_code'] > 4501 && $hist['error_code'] < 5000) {
             $msgs = array(255 => _T("Error while connecting to secure agent on this host. Please check network connectivity, and that the secure agent is installed on this host.", 'msc'), 200 + 9 => _T("The script was killed by Pulse 2 (timeout ?).", 'msc'), 200 + 15 => _T("The script was terminated by Pulse 2.", 'msc'), 240 + 0 => _T("Something goes wrong while checking client identity.", 'msc'), 240 + 1 => _T("The current host name doesn't match the host name from the inventory database.", 'msc'), 240 + 2 => _T("The current host IP address doesn't match the IP address from the inventory database.", 'msc'), 240 + 3 => _T("The current host MAC address doesn't match the MAC address from the inventory database.", 'msc'), 4000 + 1 => sprintf(_T("The package '%s' is not available on any mirror.", "msc"), $hist['stderr'][0]), 4000 + 2 => sprintf(_T("Can't get files URI for package '%s' on mirror %s.\nPlease check that the package and its files have not been modified since the planning of the command.", "msc"), $hist['stderr'][0], $hist['stderr'][1]), 4000 + 3 => sprintf(_T("Can't get files URI for package '%s' on fallback mirror %s.\nPlease check that the package and its files have not been modified since the planning of the command.", "msc"), $hist['stderr'][0], $hist['stderr'][1]), 4000 + 4 => sprintf(_T("An error occurred when trying to contact the mirror '%s' : the connection was refused.", "msc"), $hist['stderr'][0]), 4000 + 5 => sprintf(_T("An error occurred when trying to contact the fallback mirror '%s' : the connection was refused.", "msc"), $hist['stderr'][0]), 4000 + 6 => sprintf(_T("An error occurred when trying to contact the mirror '%s' : the mountpoint doesn't exists.", "msc"), $hist['stderr'][0]), 4000 + 7 => sprintf(_T("An error occurred when trying to contact the fallback mirror '%s' : the mountpoint doesn't exists.", "msc"), $hist['stderr'][0]), 4500 + 8 => sprintf(_T("Package '%s' is NOT available on primary mirror %s\nPackage '%s' is available on fallback mirror %s", "msc"), $hist['stdout'][0], $hist['stdout'][1], $hist['stdout'][2], $hist['stdout'][3]), 4500 + 9 => sprintf(_T("Package '%s' is available on primary mirror %s", "msc"), $hist['stdout'][0], $hist['stdout'][1]));
             if ($hist['error_code'] >= 4001 && $hist['error_code'] < 5000) {
                 $hist["stderr"] = array('');
             }
             if (array_key_exists($hist['error_code'], $msgs)) {
                 $hist['stderr'][] = $msgs[$hist['error_code']];
             }
         }
         $raw_errors = array_map('_colorise', array_filter($hist["stderr"]));
         $purge_errors = array();
         foreach ($raw_errors as $error) {
             if (isset($error)) {
                 array_push($purge_errors, $error);
             }
         }
         return array($history, $purge_errors);
     }
     // =====================================================================
     ### Display command phases ###
     $phases = $this->db_coh['phases'];
     $phase_labels = getPhaseLabels();
     $hidden_phases = array('done');
     $phase_names = array();
     $phase_dates = array();
     $phase_states = array();
     $phase_logs = array();
     $btn_showfull_log = array();
     // Organize logs by phase
     $logs_by_phase = array();
     foreach ($this->db_ch as $entry) {
         // Decode base64 stdout and stderr before processing
         $entry['stdout'] = base64_decode($entry['stdout']);
         $entry['stderr'] = base64_decode($entry['stderr']);
         // if $logs_by_phase doesnt contain phase key we create it
         if (!isset($logs_by_phase[$entry['phase']])) {
             $logs_by_phase[$entry['phase']] = array();
         }
         $logs_by_phase[$entry['phase']][] = $entry;
     }
     $ts_next_launch_time = _toTimestamp($this->db_coh['next_launch_date']);
     foreach ($phases as $phase) {
         // Passing hidden phases
         if (in_array($phase['name'], $hidden_phases)) {
             continue;
         }
         $phase_names[] = $phase_labels[$phase['name']];
         $phase_states[] = _plusIcon($phase['state']);
         if (isset($logs_by_phase[$phase['name']]) && count($logs_by_phase[$phase['name']])) {
             $formatted_logs = array_map('formatLog', $logs_by_phase[$phase['name']]);
         } else {
             if ($ts_next_launch_time > mktime() && ($phase['state'] == 'failed' || $phase['state'] == 'ready')) {
                 $last_try_time = _toDate($this->db_coh['next_launch_date']) . sprintf(' (%s)', _T('next attempt', 'msc'));
                 $ts_next_launch_time = 0;
             } else {
                 $last_try_time = '';
             }
             $phase_dates[] = $last_try_time;
             $phase_logs[] = '';
             continue;
         }
         $log = '';
         foreach ($formatted_logs as $onetry_log) {
             // info: $onetry_log == array($history, $log_lines)
             $log .= implode('<br/>', $onetry_log[1]) . '<br/>';
         }
         $text = "<h1>" . _T('Step log', 'msc') . "</h1>";
         $text .= '<div style="height:400px;width:100%;overflow-y:scroll;">';
         $text .= nl2br($log);
         $text .= "</div>";
         $f = new NotifyWidget(FALSE);
         $f->add($text, FALSE);
         $divid = $phase['name'] . '_log';
         printf('<div id="%s" style="display:none">%s</div>', $divid, $f->begin() . $f->content() . $f->end());
         $btn_showfull_log[] = sprintf('<ul class="action"><li class="status"><a title="%s" href="#" onclick="PopupWindow(null, \'\', 300, _centerPlacement,jQuery(\'#%s\').html());return false;"></a></li></ul>', _T('Show log', 'msc'), $divid);
         $last_try = $formatted_logs[count($formatted_logs) - 1][1];
         // If next_launch_date is a later time and this step is failed
         if ($ts_next_launch_time > mktime() && ($phase['state'] == 'failed' || $phase['state'] == 'ready')) {
             $last_try_time = _toDate($this->db_coh['next_launch_date']) . sprintf(' (%s)', _T('next attempt', 'msc'));
             $ts_next_launch_time = 0;
         } else {
             $last_try_time = $formatted_logs[count($formatted_logs) - 1][0];
         }
         $phase_dates[] = $last_try_time;
         $log_last_lines = '...<br/>';
         $last_lines_number = 3;
         for ($i = $last_lines_number; $i > 0; $i--) {
             if (isset($last_try[count($last_try) - ($i + 1)])) {
                 $log_last_lines .= $last_try[count($last_try) - ($i + 1)];
             }
         }
         // if log_last_lines didnt change (no previous line),
         // we return exit code
         // else ''
         if ($log_last_lines == '...<br/>') {
             if (isset($last_try[count($last_try) - 1])) {
                 $log_last_lines = $last_try[count($last_try) - 1];
             } else {
                 $log_last_lines = '';
             }
         }
         $phase_logs[] = $log_last_lines;
     }
     //$n = new ListInfos(array_map("_names", $values), _T('<b>Command Overview</b>', 'msc'));
     $n = new ListInfos($phase_names, '<b>' . _T('Step', 'msc') . '</b>', '', '80px');
     //$n->addExtraInfo(array_map("_values", $values), '', '400px');
     $n->addExtraInfo($phase_states, 'State', '20px');
     $n->addExtraInfo($phase_dates, 'Execution time', '120px');
     $n->addExtraInfo($phase_logs, 'Details');
     $n->addExtraInfo($btn_showfull_log, '', '20px');
     $n->setTableHeaderPadding(0);
     $n->setRowsPerPage(20);
     $n->drawTable(0);
     print "<br/>";
     ### Display command environment ###
     $values = array(array(_T('Reserved bandwidth', 'msc'), $this->db_cmd['maxbw'] == '0' ? _T('<i>none</i>', 'msc') : prettyOctetDisplay($this->db_cmd['maxbw'], 1024, _T('bit/s', 'msc'))), array(_T('Proxy mode', 'msc'), $proxy_mode), array(_T('Proxy priority', 'msc'), $proxy_priority), array(_T('Scheduler', 'msc'), $this->db_coh['scheduler']), array(_T('Current launcher', 'msc'), !empty($this->db_coh['current_launcher']) ? $this->db_coh['current_launcher'] : _T('<i>not available</i>', 'msc')), array(_T('Current proxy', 'msc'), $current_proxy));
     $n = new ListInfos(array_map("_names", $values), _T('<b>Command Environment</b>', 'msc'));
     $n->addExtraInfo(array_map("_values", $values), '', '400px');
     $n->setTableHeaderPadding(0);
     $n->setRowsPerPage(count($values));
     $n->drawTable(0);
     print "<br/>";
     # display command history
     # display log files
     $statusTable = getStatusTable();
     $i = 1;
 }
Exemple #5
0
function item_list() {

    if(isset($_GET['gid'])) {
        $type = 'group';
        list($count, $menu) = xmlrpc_getProfileBootMenu($_GET['gid']);
    } else {
        $type = '';
        list($count, $menu) = xmlrpc_getComputerBootMenu($_GET['uuid']);
    }

    $params = getParams();

    // forge params
    $upAction = new ActionItem(_T("Move Up"), $type."imgtabs", "up", "item", "base", "computers", $type."tabbootmenu", "up");
    $downAction = new ActionItem(_T("Move down"), $type."imgtabs", "down", "item", "base", "computers", $type."tabbootmenu", "down");
    $editAction = new ActionItem(_T("Edit"), $type."imgtabs", "edit", "item", "base", "computers", $type."tabbootmenu", "edit");
    $deleteAction = new ActionPopupItem(_T("Delete"), "bootmenu_remove", "delete", "item", "base", "computers", $type."tabbootmenu", 300, "delete");

    $emptyAction = new EmptyActionItem();
    $actionUp = array();
    $actionDown = array();
    $actionEdit = array();
    $actionDelete = array();

    $nbItems = $count;

    $a_label = array();
    $a_desc = array();
    $a_default = array();
    $a_display = array();
    $a_defaultWOL = array();
    $a_displayWOL = array();
    $params['from'] = 'tabbootmenu';

    $i = -1;
    $root_len = 0;
    foreach ($menu as $entry) {
        $i = $i + 1;
        $is_image = False;
        if (isset($entry['image'])) {
            $is_image = True;
        }

        if ($is_image) { # TODO $entry has now a cache for desc.
            $a_desc[] = $entry['image']['desc'];
            $entry['default_name'] = $entry['image']['name'];
            $kind = 'IM';
            if ($entry['read_only']) {
                $url = '<img src="modules/imaging/graph/images/imaging-action-ro.png" style="vertical-align: middle" alt="'._T('master from the profile', 'imaging').'"/> ';
            } else {
                $url = '<img src="modules/imaging/graph/images/imaging-action.png" style="vertical-align: middle" alt="'._T('master', 'imaging').'"/> ';
            }
        } else {
            $a_desc[] = $entry['boot_service']['default_desc'];
            $entry['default_name'] = $entry['boot_service']['default_name'];
            $kind = 'BS';
            if ($entry['read_only']) {
                $url = '<img src="modules/imaging/graph/images/service-action-ro.png" style="vertical-align: middle" alt="'._T('boot service from profile', 'imaging').'"/> ';
            } else {
                $url = '<img src="modules/imaging/graph/images/service-action.png" style="vertical-align: middle" alt="'._T('boot service', 'imaging').'"/> ';
            }
        }

        $list_params[$i] = $params;
        $list_params[$i]["itemid"] = $entry['imaging_uuid'];
        $list_params[$i]["itemlabel"] = urlencode($entry['default_name']);

        if ($entry['read_only']) {
            $actionsDown[] = $emptyAction;
            $actionsUp[] = $emptyAction;
            $root_len += 1;
            $actionEdit[] = $emptyAction;
            $actionDelete[] = $emptyAction;
        } else {
            $actionEdit[] = $editAction;
            $actionDelete[] = $deleteAction;
            if ($i == $root_len) {
                if ($count == 1 || $root_len == $count - 1) {
                    $actionsDown[] = $emptyAction;
                    $actionsUp[] = $emptyAction;
                } else {
                    $actionsDown[] = $downAction;
                    $actionsUp[] = $emptyAction;
                }
            } elseif ($i > $root_len && $i == $nbItems-1) {
                $actionsDown[] = $emptyAction;
                $actionsUp[] = $upAction;
            } elseif ($i > $root_len) {
                $actionsDown[] = $downAction;
                $actionsUp[] = $upAction;
            }
        }

        $a_label[] = sprintf("%s%s", $url, $entry['default_name']); # should be replaced by the label in the good language
        $a_default[] = $entry['default'];
        $a_display[] = ($entry['hidden'] ? False:True);
        $a_defaultWOL[] = $entry['default_WOL'];
        $a_displayWOL[] = ($entry['hidden_WOL'] ? False:True);
    }
    $firstp = "<p>" . _T("\"Preselected choice\" and \"Preselected choice on WOL\" values will be used to set the default imaging client menu item to run, if no choice is made by the user on the client side prior to the menu timeout.", "imaging") . "</p>";
    /* Build tooltip text on column name */
    if ($type == "") {
        $text = $firstp . "<p>" . _T("Once the operation triggered by a choice is successfull, the preselected choice will default to the first item of the boot menu.", "imaging") . "</p>";
    } else {
        $text = $firstp . "<p>" . _T("When you modify the \"Preselected choice\" or \"Preselected choice on WOL\" values on a profile, those values will be set on all the boot menu of the computers owned by the profile.", "imaging") . "</p>" . "<p>" . _T("Then for each computer, once the operation triggered by a choice is successfull, the preselected choice will default to the first item of the boot menu.", "imaging") . "</p>";
    }
    $l = new ListInfos($a_label, _T("Label"));
    $l->setParamInfo($list_params);
    $l->addExtraInfo($a_desc, _T("Description", "imaging"));
    $l->addExtraInfo($a_default, _T("Preselected choice", "imaging")
                     , "", $text);
    $l->addExtraInfo($a_display, _T("Displayed", "imaging"));
    $l->addExtraInfo($a_defaultWOL, _T("Preselected choice on WOL", "imaging")
                     , "", $text);
    $l->addExtraInfo($a_displayWOL, _T("Displayed on WOL", "imaging"));
    $l->addActionItemArray($actionsUp);
    $l->addActionItemArray($actionsDown);
    $l->addActionItemArray($actionEdit);
    if ($count > 1) {
        $l->addActionItemArray($actionDelete);
    }
    $l->disableFirstColumnActionLink();
    $l->setTableHeaderPadding(19);
    $l->display();
}
Exemple #6
0
function item_list()
{
    if (isset($_GET['gid'])) {
        $type = 'group';
        list($count, $menu) = xmlrpc_getProfileBootMenu($_GET['gid']);
    } else {
        $type = '';
        list($count, $menu) = xmlrpc_getComputerBootMenu($_GET['uuid']);
    }
    $params = getParams();
    // forge params
    if ($type == 'group') {
        $module = "imaging";
        $submod = "manage";
    } else {
        $module = "base";
        $submod = "computers";
    }
    $upAction = new ActionItem(_T("Move Up"), $type . "imgtabs", "up", "item", $module, $submod, $type . "tabbootmenu", "up");
    $downAction = new ActionItem(_T("Move down"), $type . "imgtabs", "down", "item", $module, $submod, $type . "tabbootmenu", "down");
    $editAction = new ActionItem(_T("Edit"), $type . "imgtabs", "edit", "item", $module, $submod, $type . "tabbootmenu", "edit");
    $deleteAction = new ActionPopupItem(_T("Delete"), $type . "bootmenu_remove", "delete", "item", $module, $submod, $type . "tabbootmenu", 300, "delete");
    $emptyAction = new EmptyActionItem();
    $actionUp = array();
    $actionDown = array();
    $actionEdit = array();
    $actionDelete = array();
    $nbItems = $count;
    $a_label = array();
    $a_desc = array();
    $a_default = array();
    $a_display = array();
    $a_defaultWOL = array();
    $a_displayWOL = array();
    $params['from'] = 'tabbootmenu';
    $i = -1;
    $root_len = 0;
    foreach ($menu as $entry) {
        $i = $i + 1;
        $is_image = False;
        if (isset($entry['image'])) {
            $is_image = True;
        }
        if ($is_image) {
            # TODO $entry has now a cache for desc.
            $a_desc[] = $entry['image']['desc'];
            $entry['default_name'] = $entry['image']['name'];
            $kind = 'IM';
            if ($entry['read_only']) {
                $url = '<img src="modules/imaging/graph/images/imaging-action-ro.png" style="vertical-align: middle" alt="' . _T('master from the profile', 'imaging') . '"/> ';
            } else {
                $url = '<img src="modules/imaging/graph/images/imaging-action.png" style="vertical-align: middle" alt="' . _T('master', 'imaging') . '"/> ';
            }
        } else {
            $a_desc[] = $entry['boot_service']['default_desc'];
            $entry['default_name'] = $entry['boot_service']['default_name'];
            $kind = 'BS';
            if ($entry['read_only']) {
                $url = '<img src="modules/imaging/graph/images/service-action-ro.png" style="vertical-align: middle" alt="' . _T('boot service from profile', 'imaging') . '"/> ';
            } else {
                $url = '<img src="modules/imaging/graph/images/service-action.png" style="vertical-align: middle" alt="' . _T('boot service', 'imaging') . '"/> ';
            }
        }
        $list_params[$i] = $params;
        $list_params[$i]["itemid"] = $entry['imaging_uuid'];
        $list_params[$i]["itemlabel"] = urlencode($entry['default_name']);
        if ($entry['read_only']) {
            $actionsDown[] = $emptyAction;
            $actionsUp[] = $emptyAction;
            $root_len += 1;
            $actionEdit[] = $emptyAction;
            $actionDelete[] = $emptyAction;
        } else {
            $actionEdit[] = $editAction;
            $actionDelete[] = $deleteAction;
            if ($i == $root_len) {
                if ($count == 1 || $root_len == $count - 1) {
                    $actionsDown[] = $emptyAction;
                    $actionsUp[] = $emptyAction;
                } else {
                    $actionsDown[] = $downAction;
                    $actionsUp[] = $emptyAction;
                }
            } elseif ($i > $root_len && $i == $nbItems - 1) {
                $actionsDown[] = $emptyAction;
                $actionsUp[] = $upAction;
            } elseif ($i > $root_len) {
                $actionsDown[] = $downAction;
                $actionsUp[] = $upAction;
            }
        }
        $a_label[] = sprintf("%s%s", $url, $entry['default_name']);
        # should be replaced by the label in the good language
        $a_default[] = $entry['default'];
        $a_display[] = $entry['hidden'] ? False : True;
        $a_defaultWOL[] = $entry['default_WOL'];
        $a_displayWOL[] = $entry['hidden_WOL'] ? False : True;
    }
    $firstp = "<p>" . _T("Use \"Preselected choice\" or \"Preselected choice on WOL\" to define the default boot entry.", "imaging") . "</p>";
    /* Build tooltip text on column name */
    if ($type == "") {
        $text = $firstp . "<p>" . _T("If the default entry is an image creation or restore, the following network boots will fall back to the first menu entry.", "imaging") . "</p>";
    } else {
        $text = $firstp . "<p>" . _T("When changing \"Preselected choice\" or \"Preselected choice on WOL\" entry, this value will be set on all the computers in this group.", "imaging") . "</p>" . "<p>" . _T("If the default entry is an image creation or restore, the following network boots will fall back to the first menu entry.", "imaging") . "</p>";
    }
    $l = new ListInfos($a_label, _T("Label"));
    $l->setParamInfo($list_params);
    $l->addExtraInfo($a_desc, _T("Description", "imaging"));
    $l->addExtraInfo($a_default, _T("Preselected choice", "imaging"), "", $text);
    $l->addExtraInfo($a_display, _T("Displayed", "imaging"));
    $l->addExtraInfo($a_defaultWOL, _T("Preselected choice on WOL", "imaging"), "", $text);
    $l->addExtraInfo($a_displayWOL, _T("Displayed on WOL", "imaging"));
    $l->addActionItemArray($actionsUp);
    $l->addActionItemArray($actionsDown);
    $l->addActionItemArray($actionEdit);
    if ($count > 1) {
        $l->addActionItemArray($actionDelete);
    }
    $l->disableFirstColumnActionLink();
    $l->setTableHeaderPadding(19);
    $l->display();
}
Exemple #7
0
 function display()
 {
     // display parameters
     if (!$this->db_cmd) {
         # use does not have the good permissions
         $widget = new RenderedMSCCommandDontExists();
         $widget->display();
         return;
     }
     if ($this->db_cmd['start_date']) {
         if ($this->db_cmd['end_date']) {
             $validity = sprintf(_T('<i>from</i> %s <i>to</i> %s', 'msc'), _toDate($this->db_cmd['start_date']), _toDate($this->db_cmd['end_date']));
         } else {
             $validity = sprintf(_T('<i>from</i> %s', 'msc'), _toDate($this->db_cmd['start_date']));
         }
     } else {
         if ($this->db_cmd['end_date']) {
             $validity = sprintf(_T('<i>to</i> %s', 'msc'), _toDate($this->db_cmd['end_date']));
         } else {
             $validity = _T('<i>forever</i>', 'msc');
         }
     }
     if ($this->db_cmd['deployment_intervals']) {
         $deploy_interv = str_replace(array('-', ','), array(' - ', ', '), $this->db_cmd['deployment_intervals']);
     } else {
         $deploy_interv = _T('<i>whole day</i>', 'msc');
     }
     if ($this->db_cmd['deployment_intervals']) {
         $deploy_interv = str_replace(array('-', ','), array(' - ', ', '), $this->db_cmd['deployment_intervals']);
     } else {
         $deploy_interv = _T('<i>whole day</i>', 'msc');
     }
     if ($this->db_coh['next_launch_date']) {
         $next_launch_date = _toDate($this->db_coh['next_launch_date']);
     } else {
         if ($this->db_cmd['start_date']) {
             $next_launch_date = _toDate($this->db_cmd['start_date']);
         } else {
             $next_launch_date = _T('<i>as soon as possible</i>', 'msc');
         }
     }
     if ($this->db_coh['start_date']) {
         $start_date = _toDate($this->db_coh['start_date']);
     } else {
         $start_date = _T('<i>not yet available</i>', 'msc');
     }
     if ($this->db_coh['end_date']) {
         $end_date = _toDate($this->db_coh['end_date']);
     } else {
         $end_date = _T('<i>not yet available</i>', 'msc');
     }
     if ($this->db_coh['last_wol_attempt']) {
         $last_wol_attempt = _toDate($this->db_coh['last_wol_attempt']);
     } else {
         $last_wol_attempt = _T('<i>not available</i>', 'msc');
     }
     if ($this->db_cmd['start_file']) {
         if ($this->db_cmd['parameters']) {
             $command_line = sprintf(_T('%s %s', 'msc'), $this->db_cmd['start_file'], $this->db_cmd['parameters']);
         } else {
             $command_line = sprintf(_T('%s <i>(no additional parameter given)</i>', 'msc'), $this->db_cmd['start_file']);
         }
     } else {
         $command_line = _T('<i>not set</i>', 'msc');
     }
     if ($this->db_coh['order_in_proxy'] == '') {
         $proxy_priority = _T('None (Local Proxy Client)', 'msc');
     } else {
         $proxy_priority = sprintf(_T('%s (Local Proxy Server)', 'msc'), $this->db_coh['order_in_proxy']);
     }
     if ($this->db_cmd['proxy_mode'] == 'split') {
         $proxy_mode = _T('Multiple', 'msc');
     } elseif ($this->db_cmd['proxy_mode'] == 'queue') {
         $proxy_mode = _T('Single with fallback', 'msc');
     } elseif ($this->db_cmd['proxy_mode'] == 'none') {
         $proxy_mode = _T('No proxy', 'msc');
         $proxy_priority = _T('None', 'msc');
     } else {
         $proxy_mode = _T('<i>not available</i>', 'msc');
         $proxy_priority = _T('<i>not available</i>', 'msc');
     }
     if ($this->db_lproxy) {
         $current_proxy = $this->db_lproxy['host'];
     } else {
         $current_proxy = _T('<i>not available</i>', 'msc');
     }
     // gettext obfucation
     _T('enable', 'msc');
     _T('disable', 'msc');
     _T('done', 'msc');
     _T('failed', 'msc');
     _T('over_time', 'msc');
     _T('out_of_interval', 'msc');
     ### Display command overview ###
     $values = array(array(_T('Command name', 'msc'), $this->db_cmd['title']), array(_T('Creation', 'msc'), sprintf(_T('<i>on</i> %s <i>by</i> %s', 'msc'), _toDate($this->db_cmd['creation_date']), $this->db_cmd['creator'])), array(_T('Validity period', 'msc'), $validity), array(_T('Deployment interval', 'msc'), $deploy_interv));
     $n = new ListInfos(array_map("_names", $values), _T('<b>Command Overview</b>', 'msc'));
     $n->addExtraInfo(array_map("_values", $values), '', '400px');
     $n->setTableHeaderPadding(0);
     $n->setRowsPerPage(count($values));
     $n->drawTable(0);
     print "<hr/><br/>";
     ### Display command stages ###
     $values = array(array(_T('Command line to run', 'msc'), $command_line), array(_T('Start "Wake On Lan" query if connection fails', 'msc'), $this->db_cmd['do_wol'] == 'enable' ? _T('yes', 'msc') : _T('no', 'msc')), array(_T('Execute command line ?', 'msc'), $this->db_cmd['start_script'] == 'enable' ? _T('yes', 'msc') : _T('no', 'msc')), array(_T('Delete files after a successful execution ?', 'msc'), $this->db_cmd['clean_on_success'] == 'enable' ? _T('yes', 'msc') : _T('no', 'msc')), array(_T('Do an inventory after a successful execution ?', 'msc'), $this->db_cmd['do_inventory'] == 'enable' ? _T('yes', 'msc') : _T('no', 'msc')), array(_T('Reboot client after a successful deletion ?', 'msc'), $this->db_cmd['do_reboot'] == 'enable' ? _T('yes', 'msc') : _T('no', 'msc')), array(_T('Halt client after :', 'msc'), i18nparts($this->db_cmd['do_halt'])));
     $n = new ListInfos(array_map("_names", $values), _T('<b>Command Stages</b>', 'msc'));
     $n->addExtraInfo(array_map("_values", $values), '', '400px');
     $n->setTableHeaderPadding(0);
     $n->setRowsPerPage(count($values));
     $n->drawTable(0);
     print "<hr/><br/>";
     ### Display command environment ###
     $values = array(array(_T('Reserved bandwidth', 'msc'), $this->db_cmd['maxbw'] == '0' ? _T('<i>none</i>', 'msc') : prettyOctetDisplay($this->db_cmd['maxbw'], 1024, _T('bit/s', 'msc'))), array(_T('Proxy mode', 'msc'), $proxy_mode), array(_T('Proxy priority', 'msc'), $proxy_priority), array(_T('Scheduler', 'msc'), $this->db_coh['scheduler']), array(_T('Current launcher', 'msc'), $this->db_coh['launcher'] == '' ? _T('<i>not available</i>', 'msc') : $this->db_coh['launcher']), array(_T('Current proxy', 'msc'), $current_proxy));
     $n = new ListInfos(array_map("_names", $values), _T('<b>Command Environment</b>', 'msc'));
     $n->addExtraInfo(array_map("_values", $values), '', '400px');
     $n->setTableHeaderPadding(0);
     $n->setRowsPerPage(count($values));
     $n->drawTable(0);
     print "<hr/><br/>";
     ### Display command life cycle ###
     $values = array(array(_T('First operation at', 'msc'), $start_date), array(_T('Remaining connection attempts', 'msc'), sprintf(_T('%s (on %s)', 'msc'), $this->db_coh['attempts_left'], $this->db_cmd['max_connection_attempt'])), array(_T('Delay between two attempts (minutes)', 'msc'), $this->db_cmd['next_connection_delay'] ? $this->db_cmd['next_connection_delay'] : _T('<i>not set</i>', 'msc')), array(_T('Last WOL attempt', 'msc'), $last_wol_attempt), array(_T('Next attempt', 'msc'), $next_launch_date), array(_T('Last operation at', 'msc'), $end_date));
     $n = new ListInfos(array_map("_names", $values), _T('<b>Command Life Cycle</b>', 'msc'));
     $n->addExtraInfo(array_map("_values", $values), '', '400px');
     $n->setTableHeaderPadding(0);
     $n->setRowsPerPage(count($values));
     $n->drawTable(0);
     print "<hr/><br/>";
     ### Display to be transfered files ###
     $files = array(_T('List of files to be transfered is empty.', 'msc'));
     if ($this->db_cmd["files"] != "" && $this->db_cmd["files"] != array()) {
         if (gettype($command["files"]) != 'array') {
             $files = explode("\n", $this->db_cmd["files"]);
         } else {
             $files = $this->db_cmd["files"];
         }
     }
     $n = new ListInfos($files, _T('<b>Files to be transfered</b>', 'msc'));
     $n->setTableHeaderPadding(0);
     $n->setRowsPerPage(count($values));
     $n->drawTable(0);
     print "<hr/><br/>";
     # display command history
     # display log files
     $statusTable = getStatusTable();
     $i = 1;
     foreach ($this->db_ch as $hist) {
         if ($hist['state'] == 'upload_in_progress' && $hist['error_code'] == '0' && array_key_exists('stderr', $hist) && $i != count($this->db_ch) && strpos($hist['stderr'], 'is available on mirror') !== False) {
             /*
               We are displaying which package server was used in push pull
               mode. We want to keep the led green instead of orange to
               tell the user that there was no problem.
             */
             $staticon = history_stat2icon("upload_done");
         } elseif ($hist['state'] == 'wol_failed' && $hist['error_code'] == '2001') {
             $staticon = history_stat2icon("stop");
         } else {
             $staticon = history_stat2icon($hist['state']);
         }
         $history = '<img style="vertical-align: middle;" alt="' . $hist['state'] . '" src="modules/msc/graph/images/status/' . $staticon . '"/> ' . date("Y-m-d H:i:s", $hist['date']) . ': <b>' . $statusTable[$hist['state']] . '</b>';
         /* Split lines in stdout and stderr */
         if (gettype($hist["stdout"]) != 'array') {
             $hist["stdout"] = split("\n", $hist["stdout"]);
         }
         if (gettype($hist["stderr"]) != 'array') {
             $hist["stderr"] = split("\n", $hist["stderr"]);
         }
         if (count($hist["stdout"]) > 0 && !(count($hist["stdout"]) == 1 && $hist["stdout"][0] == '')) {
             $hist["stderr"] = array_merge($hist["stderr"], $hist["stdout"]);
         }
         if (strpos($hist['state'], '_failed') !== False || $hist['error_code'] > 4501 && $hist['error_code'] < 5000) {
             $msgs = array(255 => _T("Error while connecting to secure agent on this host. Please check network connectivity, and that the secure agent is installed on this host.", 'msc'), 200 + 9 => _T("The script was killed by Pulse 2 (timeout ?).", 'msc'), 200 + 15 => _T("The script was terminated by Pulse 2.", 'msc'), 240 + 0 => _T("Something goes wrong while checking client identity.", 'msc'), 240 + 1 => _T("The current host name doesn't match the host name from the inventory database.", 'msc'), 240 + 2 => _T("The current host IP address doesn't match the IP address from the inventory database.", 'msc'), 240 + 3 => _T("The current host MAC address doesn't match the MAC address from the inventory database.", 'msc'), 4000 + 1 => sprintf(_T("The package '%s' is not available on any mirror.", "msc"), $hist['stderr'][0]), 4000 + 2 => sprintf(_T("Can't get files URI for package '%s' on mirror %s.\nPlease check that the package and its files have not been modified since the planning of the command.", "msc"), $hist['stderr'][0], $hist['stderr'][1]), 4000 + 3 => sprintf(_T("Can't get files URI for package '%s' on fallback mirror %s.\nPlease check that the package and its files have not been modified since the planning of the command.", "msc"), $hist['stderr'][0], $hist['stderr'][1]), 4000 + 4 => sprintf(_T("An error occurred when trying to contact the mirror '%s' : the connection was refused.", "msc"), $hist['stderr'][0]), 4000 + 5 => sprintf(_T("An error occurred when trying to contact the fallback mirror '%s' : the connection was refused.", "msc"), $hist['stderr'][0]), 4000 + 6 => sprintf(_T("An error occurred when trying to contact the mirror '%s' : the mountpoint doesn't exists.", "msc"), $hist['stderr'][0]), 4000 + 7 => sprintf(_T("An error occurred when trying to contact the fallback mirror '%s' : the mountpoint doesn't exists.", "msc"), $hist['stderr'][0]), 4500 + 8 => sprintf(_T("Package '%s' is NOT available on primary mirror %s\nPackage '%s' is available on fallback mirror %s", "msc"), $hist['stdout'][0], $hist['stdout'][1], $hist['stdout'][2], $hist['stdout'][3]), 4500 + 9 => sprintf(_T("Package '%s' is available on primary mirror %s", "msc"), $hist['stdout'][0], $hist['stdout'][1]));
             if ($hist['error_code'] >= 4001 && $hist['error_code'] < 5000) {
                 $hist["stderr"] = array('');
             }
             if (array_key_exists($hist['error_code'], $msgs)) {
                 $hist['stderr'][] = $msgs[$hist['error_code']];
             }
         }
         $raw_errors = array_map('_colorise', array_filter($hist["stderr"]));
         $purge_errors = array();
         foreach ($raw_errors as $error) {
             if (isset($error)) {
                 array_push($purge_errors, $error);
             }
         }
         $n = new ListInfos($purge_errors, $history);
         $n->setTableHeaderPadding(0);
         $n->setRowsPerPage(count($purge_errors) + 1);
         if (count($hist["stderr"]) > 0 && !(count($hist["stderr"]) == 1 && $hist["stderr"][0] == '')) {
             $n->drawTable(0);
         }
         $i++;
     }
 }