$fcomputers = array(); $finodes = array(); $states = array(); $computersCache = array(); foreach ($files as $file) { $uuid = $file[1]; if (array_key_exists($uuid, $computersCache)) { $computer = $computersCache[$uuid]; } else { $computer = getMachine(array('uuid' => $uuid), $ping = False); $computersCache[$uuid] = $computer; } if (strlen($filter) == 0 || strlen($filter) > 0 && (strpos($file[0], $filter) !== False || strpos($computer->hostname, $filter) !== False)) { $fnames[] = $file[0]; $fcomputers[] = $computer->hostname; $ftimestamps[] = _toDate($file[2]); $finodes[] = array("id" => $file[4], "objectUUID" => $_GET["objectUUID"]); if ($file[0] == '' && $file[3] == 0) { $states[] = _T('Downloading', 'msc'); $flengths[] = ''; $actionsdl[] = new EmptyActionItem(); $actionsrm[] = new EmptyActionItem(); } else { if ($file[0] == '' && $file[3] == -1) { $states[] = _T('Error', 'msc'); $flengths[] = ''; $actionsdl[] = new EmptyActionItem(); $actionsrm[] = $actionRemove; } else { $states[] = _T('Ready', 'msc'); $flengths[] = $file[3];
return; } $logStates = array("unknown" => array(_T("Status unknow", "imaging"), 'black'), "boot" => array(_T("Boot", "imaging"), 'green'), "menu" => array(_T("Menu", "imaging"), 'green'), "restoration" => array(_T("Restoration", "imaging"), 'green'), "backup" => array(_T("Backup", "imaging"), 'green'), "postinstall" => array(_T("Post-imaging", "imaging"), 'green'), "error" => array(_T("Error", "imaging"), 'red'), "delete" => array(_T("Delete", "imaging"), 'orange'), "inventory" => array(_T("Inventory", "imaging"), 'orange'), "restore_in_progress" => array(_T("Restore in progress", "imaging"), 'orange'), "restore_done" => array(_T("Restore done", "imaging"), 'green'), "restore_failed" => array(_T("Restore failed", "imaging"), 'red'), "backup_in_progress" => array(_T("Backup in progress", "imaging"), 'orange'), "backup_done" => array(_T("Backup done", "imaging"), "green"), "backup_failed" => array(_T("Backup failed", "imaging"), "red"), "unknow" => array(_T("Status unknow", "imaging"), "black")); $a_desc = array(); $a_states = array(); $a_level = array(); $a_date = array(); $a_target = array(); foreach ($db_logs as $log) { $params = array(); $params["itemid"] = $log['imaging_uuid']; $params["uuid"] = $log['target']['uuid']; $params["hostname"] = $log['target']['name']; $list_params[] = $params; $status = $log['imaging_log_state']; $date = _toDate($log['timestamp']); /*if(ereg('backup', $status)) { $date = '<img src="modules/imaging/graph/images/backup.png" style="vertical-align: bottom"/> '.$date; } elseif (ereg('restore', $status)) { $date = '<img src="modules/imaging/graph/images/restore.png" style="vertical-align: bottom"/> '.$date; }*/ // get status if (!array_key_exists($status, $logStates)) { $status = 'unknow'; } // complete status display $led = new LedElement($logStates[$status][1]); $status = $logStates[$status][0]; //$status = $led->value.' '.$logStates[$status][0]; $a_level[] = $log['imaging_log_level']; $a_date[] = $date;
function draw_image($url, $label) { return '<img style="vertical-align: middle;" title="'.$label.'" src="'.$url.'"/>'; } foreach ($cmds as $item) { $label = $item['title']; $creation_date = $item['creation_date']; $creator = $item['creator']; $target = $item['target']; $target_uuid = $item['uuid']; $cmd_id = $item['cmdid']; $coh_id = $item['cohid']; $bid = $item['bid']; $gid = $item['gid']; $current_state = empty($item['current_state']) ? '' : $item['current_state']; $creation_date = _toDate($creation_date); $status = $item['status']; if ($status) { $icons = state_tmpl_macro($status); } else { $icons = state_tmpl($current_state); } $tab = 'tablogs'; if ($icons['play'] == '' && $icons['stop'] == '' && $icons['pause'] == '') { $tab = 'tabhistory'; } if ($target_uuid && $target_uuid != '') { $param = array('uuid'=>$target_uuid, 'cmd_id'=>$cmd_id, 'bundle_id'=>$bid); if (!isset($gid) || $gid == '') { $param['coh_id'] = $coh_id; } else { $param['gid'] = $gid; } $linkdetail = urlStr("base/computers/msctabs/$tab", $param); $linklogs = urlStr("base/computers/msctabs/$tab", array('uuid'=>$target_uuid, 'gid'=>$gid));
} elseif (!isset($image['menu_item'])) { $addActions[] = $addAction; } else { $addActions[] = $delAction; $l_params['mi_itemid'] = $image['menu_item']['imaging_uuid']; } if ($_GET['target_uuid'] == $image['mastered_on_target_uuid']) { $editActions[] = $editAction; } else { $editActions[] = $emptyAction; } $list_params[] = $l_params; # TODO no label in image! $a_label[] = sprintf("%s%s", '<img src="modules/imaging/graph/images/imaging-action.png" style="vertical-align: middle" /> ', $name); $a_desc[] = $image['desc']; $a_date[] = _toDate($image['creation_date']); $a_size[] = humanReadable($image['size']); $a_inbootmenu[] = isset($image['menu_item']) ? True : False; $a_fromprofile[] = $image['read_only'] ? True : False; $a_info[] = sprintf("Plop: %s", $image['fk_status']); $l_im[] = array($image['imaging_uuid'], $_GET['target_uuid'], $type); } if (!$actions) { if (count($l_im) != 0) { $ret = xmlrpc_areImagesUsed($l_im); foreach ($images as $image) { if ($ret[$image['imaging_uuid']]) { $a_destroy[] = $showImAction; } else { $a_destroy[] = $destroyAction; }
$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 $added_part_lists[] = $list; } } } // 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)
$coh_id = $cmd[1]; $coh_status = $cmd[2]; $coh = $cmd[3]; $pull_mode = $cmd[4]; // $pull_mode contains UUID of machine, else False $cmd = $cmd[0]; if (isset($_GET['coh_id']) && $coh_id == $_GET['coh_id'] || !isset($_GET['coh_id'])) { if ($history) { $d = $coh["end_date"]; } else { $d = $coh["next_launch_date"]; } if (!is_array($d)) { $a_date[] = _toDate(array(1970, 1, 1, 0, 0, 0)); } else { $a_date[] = _toDate($d); } if ($uuid) { $a_client[] = $cmd['title']; } else { $a_client[] = $coh['host']; } $proxy_id = $coh['fk_use_as_proxy']; $proxy_str = ''; if ($proxy_id != '') { if ($proxies[$proxy_id] == '') { $lp = get_commands_on_host($proxy_id); $proxies[$proxy_id] = $lp['host']; } $proxy_str = sprintf(_T(', using proxy %s', 'msc'), $proxies[$proxy_id]); }
if (isset($_GET[$get])) { $value = $_GET[$get]; $params[$get] = $value; } } $inventoriesDates = array(); $inventoriesId = array(); $detailsParams = array(); $detailsButtons = array(); $i = 0; // Call the methods to get the inventory history $count = countMachineInventoryHistory($params); $inventory_history = getMachineInventoryHistory($params); // Loop through the inventory history to extract infos foreach ($inventory_history as $inventory) { $inventoriesDates[] = _toDate($inventory[1]); // Add the details link (unless we are on the last line) if ($i < count($inventory_history) - 1) { $detailsButtons[] = new ActionItem(_T("View differences since previous inventory", "inventory"), "invdiff", "display"); } else { $detailsButtons[] = new EmptyActionItem(); } $detailsParams[$i]['inventoryId'] = $inventory[0]; $detailsParams[$i++]['uuid'] = $params['uuid']; } // Create a ListInfos that will display the inventories dates $list = new ListInfos($inventoriesDates, _T("Inventory Date", "inventory")); // Add extra params in the "details" link $list->setParamInfo($detailsParams); $list->disableFirstColumnActionLink(); $list->setName(_T("Inventory", "inventory"));
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; }
if ($target_uuid && $target_uuid != '') { $param = array('uuid' => $target_uuid, 'cmd_id' => $cmd_id, 'bundle_id' => $bid, 'commands' => $command_type); if (!isset($gid) || $gid == '') { $param['coh_id'] = $coh_id; } else { $param['gid'] = $gid; } $linkdetail = urlStr("msc/logs/viewLogs", $param); $linklogs = urlStr("msc/logs/viewLogs", array('uuid' => $target_uuid, 'gid' => $gid)); } else { $linkdetail = urlStr("msc/logs/viewLogs", array('uuid' => $target_uuid, 'cmd_id' => $cmd_id, 'bundle_id' => $bid, 'gid' => $gid, 'commands' => $command_type)); $linklogs = urlStr("msc/logs/viewLogs", array('uuid' => $target_uuid, 'gid' => $gid)); } $a_date[] = $creation_date; $start_dates[] = _toDate($start_date); $end_dates[] = _toDate($end_date); $a_deployment_intervals[] = $deployment_intervals; $a_creator[] = $creator; $param = array('cmd_id' => $cmd_id, 'title' => $label, 'bundle_id' => $bid, 'from' => 'msc|logs|consult'); $no_actions = False; if (!isset($bid) || $bid == '') { $a_donepercent[] = $done_percent; $img = draw_image("modules/msc/graph/images/install_package.png", _T('Package', 'msc')); } else { $img = draw_image("modules/msc/graph/images/install_bundle.png", _T('Bundle', 'msc')); $a_donepercent[] = '-'; } if (isset($type) && $type == 2) { $img = draw_image("modules/msc/graph/images/install_convergence.png", _T('Package', 'msc')); } // If NOW> end_dates, we hide start/stop buttons
$destroyAction = new ActionPopupItem(_T("Delete", "imaging"), "master_delete", "delete", "master", "imaging", "manage"); $showImAction = new ActionPopupItem(_T("Show target using that image", "imaging"), "showtarget", "showtarget", "image", "base", "computers"); foreach ($masters as $master) { $l_params = array(); $l_params = $params; $l_params["itemid"] = $master['imaging_uuid']; $l_params["itemlabel"] = urlencode($master['name']); if (!$master['menu_item']) { $addActions[] = $addAction; } else { $addActions[] = $delAction; } $list_params[] = $l_params; $a_label[] = sprintf("%s%s", '<img src="modules/imaging/graph/images/imaging-action.png" style="vertical-align: middle" /> ', $master['name']); $a_desc[] = $master['desc']; $a_date[] = _toDate($master['creation_date']); $a_size[] = humanReadable($master['size']); $a_is_in_menu[] = $master['menu_item'] ? True : False; $l_im[] = array($master['imaging_uuid'], null, null); } if (count($l_im) != 0) { $ret = xmlrpc_areImagesUsed($l_im); foreach ($masters as $image) { if ($ret[$image['imaging_uuid']]) { $a_destroy[] = $showImAction; } else { $a_destroy[] = $destroyAction; } } } // show images list
$filename .= "C" . $cmd_id; } elseif (strlen($_GET['bundle_id'])) { $filename .= "B" . $_GET['bundle_id']; } if ($specific_state) { $filename .= "_{$state}"; } /* The two following lines make the CSV export works for IE 7.x */ header("Pragma: "); header("Cache-Control: "); header("Content-type: text/txt"); header('Content-Disposition: attachment; filename="' . $filename . '.csv"'); if ($specific_state) { $header = array(_T('uuid', 'msc'), _T('host', 'msc'), _T('current state', 'msc'), _T('start date', 'msc'), _T('end date', 'msc')); $content = array(); foreach ($s as $coh) { $content[] = array($coh['uuid'], $coh['host'], $coh['current_state'], $coh['start_date'] ? _toDate($coh['start_date']) : '', $coh['end_date'] ? _toDate($coh['end_date']) : ''); } } else { $header = array(_T('title', 'msc'), _T('total', 'msc'), _T('computers successfully deployed', 'msc'), _T('computers stopped', 'msc'), _T('computers paused', 'msc'), _T('computers out of the valid period', 'msc'), _T('computers running a deployment', 'msc'), _T('waiting to upload', 'msc'), _T('waiting to upload and already try', 'msc'), _T('running upload', 'msc'), _T('waiting to execute', 'msc'), _T('waiting to execute and already try', 'msc'), _T('running execution', 'msc'), _T('waiting to suppress', 'msc'), _T('waiting to suppress and already try', 'msc'), _T('running suppression', 'msc'), _T('computers failed to deploy', 'msc'), _T('failed during upload', 'msc'), _T('unreachable during upload', 'msc'), _T('failed during execution', 'msc'), _T('unreachable during execution', 'msc'), _T('failed during suppression', 'msc'), _T('unreachable during suppression', 'msc')); $content = array(array($title, $s['total'], $s['success']['total'][0], $s['stopped']['total'][0], $s['paused']['total'][0], $s['failure']['over_timed'][0], $s['running']['total'][0], $s['running']['wait_up'][0] - $s['running']['sec_up'][0], $s['running']['sec_up'][0], $s['running']['run_up'][0], $s['running']['wait_ex'][0] - $s['running']['sec_ex'][0], $s['running']['sec_ex'][0], $s['running']['run_ex'][0], $s['running']['wait_rm'][0] - $s['running']['sec_rm'][0], $s['running']['sec_rm'][0], $s['running']['run_rm'][0], $s['failure']['total'][0], $s['failure']['fail_up'][0], $s['failure']['conn_up'][0], $s['failure']['fail_ex'][0], $s['failure']['conn_ex'][0], $s['failure']['fail_rm'][0], $s['failure']['conn_rm'][0])); } print '"' . join('";"', $header) . "\"\n"; foreach ($content as $line) { print '"' . join('";"', $line) . "\"\n"; } exit; ?>
} // Calls the function that get the number of inventories $count = countInventoryHistory($period, $only_new, $filter); // Calls the function that get the history of inventories $incoming = getInventoryHistory($period, $only_new, $filter, $start + $maxperpage, $start); // Create an array with the machine names $machines = array(); // Create an array with the inventory dates $inventories = array(); // Create an array with the "new_machine" booleans $new_machines = array(); // Create an array with $params needed for cliquable first column $params = array(); foreach ($incoming as $inc) { $machines[] = $inc[0]; $inventories[] = _toDate($inc[1]); $new_machines[] = $inc[2]; $params[] = array('hostname' => $inc[0], 'uuid' => $inc[3]); } // Create the listinfos widget, the first column is the machine name $l = new OptimizedListInfos($machines, _T("Computer name")); // Add the second column, which is the inventory date $l->addExtraInfo($inventories, _T("Inventory date")); // Add the third column, which is the boolean "new_machine" $l->addExtraInfo($new_machines, _T("New computer")); // Add actions item, to make first column cliquable $l->addActionItem(new ActionItem(_T("View", "inventory"), "invtabs", "display", "inventory", "base", "computers")); $l->addActionItem(new ActionPopupItem(_T("Information", "inventory"), "infos", "info", "inventory", "inventory", "inventory")); $l->setParamInfo($params); // Navbar for an Ajax widget $l->setItemCount($count);
if (isset($_GET[$get])) { $value = $_GET[$get]; $params[$get] = $value; } } $inventoriesDates = array(); $inventoriesId = array(); $detailsParams = array(); $detailsButtons = array(); $i = 0; // Call the methods to get the inventory history $count = countMachineInventoryHistory($params); $inventory_history = getMachineInventoryHistory($params); // Loop through the inventory history to extract infos foreach ($inventory_history as $inventory) { $inventoriesDates[] = substr(_toDate($inventory[1]), 0, 10); // Add the details link (unless we are on the last line) if ($i < count($inventory_history) - 1) { $detailsButtons[] = new ActionItem(_T("View differences since previous inventory", "inventory"), "invdiff", "display"); } else { $detailsButtons[] = new EmptyActionItem(); } $detailsParams[$i]['inventoryId'] = $inventory[0]; $detailsParams[$i++]['uuid'] = $params['uuid']; } // Create a ListInfos that will display the inventories dates $list = new ListInfos($inventoriesDates, _T("Inventory Date", "inventory")); // Add extra params in the "details" link $list->setParamInfo($detailsParams); $list->disableFirstColumnActionLink(); $list->setName(_T("Inventory", "inventory"));
// = $datum[$uuid][1] + $content; } } } $firstline = true; foreach (array_values($datum) as $machine) { $name = $machine[0]; $uuid = $machine[2]; $content = $machine[1]; if ($firstline) { $header = array(); foreach (array_keys($content[0]) as $column) { $header[] = _T($column); } print '"' . _T("Computer") . '","' . implode('","', $header) . "\"\n"; $firstline = false; } foreach ($content as $line) { # iterate over results if (in_array('timestamp', array_keys($line))) { $line['timestamp'] = _toDate($line['timestamp']); } print "\"{$name}\",\"" . implode('","', array_values($line)) . "\"\n"; } } } exit; ?>
$actiondetails_logs = new ActionItem(_T("Details", "msc"), "msctabs", "display", "msc", "base", "computers", 'tablogs'); $actiondetails_hist = new ActionItem(_T("Details", "msc"), "msctabs", "display", "msc", "base", "computers", 'tabhistory'); $actionempty = new EmptyActionItem(); $a_start = array(); $a_pause = array(); $a_stop = array(); $a_details = array(); $n = null; foreach ($cmds as $item) { list($coh, $cmd, $target, $bundle) = $item; $coh_id = $coh['id']; $cho_status = $coh['current_state']; if ($history) { $a_date[] = _toDate($coh["end_date"]); } else { $a_date[] = _toDate($coh["next_launch_date"], True); } $bundle_str = ''; if ($cmd['fk_bundle']) { $bundle_str = sprintf(_T("<a href='' class='bundle' title='%s'>(in bundle %s)</a>", "msc"), $bundle['title'], $cmd['fk_bundle']); } $a_cmd[] = sprintf(_T("%s on %s %s", 'msc'), $cmd['title'], $coh['host'], $bundle_str); if ($coh['current_state'] == 'scheduled' && $cmd['max_connection_attempt'] != $coh['attempts_left']) { $coh['current_state'] = 'rescheduled'; } if (isset($statusTable[$coh['current_state']])) { $a_current[] = $statusTable[$coh['current_state']]; } else { $a_current[] = $coh['current_state']; } $params[] = array('coh_id' => $coh_id, 'cmd_id' => $cmd['id'], 'uuid' => $target['target_uuid'], 'from' => "msc|logs|{$from}", 'hostname' => $target['target_name'], 'title' => $cmd['title']);
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++; } }