コード例 #1
0
ファイル: command_history.php プロジェクト: neoclust/mmc
 function CommandOnHost($coh)
 {
     $statusTable = getStatusTable();
     $this->db_coh = get_commands_on_host($coh);
     #$this->db_cmd = command_detail($this->db_coh['fk_commands']);
     $this->values = array(array(_T('Host', 'msc'), $this->db_coh['host'], 1), array(_T('Current State', 'msc'), $statusTable[$this->db_coh['current_state']], 1), array(_T('awoken', 'msc'), _plusIcon($this->db_coh['awoken']), 1), array(_T('uploaded', 'msc'), _plusIcon($this->db_coh['uploaded']), 1), array(_T('executed', 'msc'), _plusIcon($this->db_coh['executed']), 1), array(_T('deleted', 'msc'), _plusIcon($this->db_coh['deleted']), 1), array(_T('inventoried', 'msc'), _plusIcon($this->db_coh['inventoried']), 1), array(_T('rebooted', 'msc'), _plusIcon($this->db_coh['rebooted']), 1), array(_T('halted', 'msc'), _plusIcon($this->db_coh['halted']), 1));
 }
コード例 #2
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');
     // =====================================================================
     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;
 }