Example #1
0
 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);
 }
Example #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');
     ### 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++;
     }
 }