Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(csv): convert timestamp to human readable date (#7533)
Browse files Browse the repository at this point in the history
* enh(BE): securise id from request
* style and PSR2
* enh(csv): homogenize exported date values' format
* enh(BE): filter sanitize strings from REQUEST
* fix(BE): setting a start date if the user didn't
  • Loading branch information
sc979 authored May 16, 2019
1 parent 2cc3c25 commit 11a5c1f
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 110 deletions.
113 changes: 66 additions & 47 deletions www/include/eventLogs/export/data.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
* Copyright 2005-2015 Centreon
* Centreon is developped by : Julien Mathis and Romain Le Merlus under
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
Expand Down Expand Up @@ -35,27 +35,19 @@

ini_set("display_errors", "Off");

/**
* Include configuration
*/
require_once realpath(dirname(__FILE__) . "/../../../../config/centreon.config.php");
// Include configuration
require_once realpath(__DIR__ . "/../../../../config/centreon.config.php");

/**
* Include Classes / Methods
*/
// Include Classes / Methods
require_once _CENTREON_PATH_ . "www/class/centreonDB.class.php";
require_once _CENTREON_PATH_ . "www/class/centreonSession.class.php";
require_once _CENTREON_PATH_ . "www/class/centreon.class.php";

/** *****************************************
* Connect MySQL DB
*/
// Connect MySQL DB
$pearDB = new CentreonDB();
$pearDBO = new CentreonDB("centstorage");

/**
* Security check
*/
// Security check
CentreonSession::start(1);
if (!CentreonSession::checkSession(session_id(), $pearDB)) {
print "Bad Session";
Expand All @@ -64,54 +56,66 @@

$centreon = $_SESSION["centreon"];

/**
* Language informations init
*/
// Language informations init
$locale = $centreon->user->get_lang();
putenv("LANG=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", _CENTREON_PATH_ . "/www/locale/");
bind_textdomain_codeset("messages", "UTF-8");
textdomain("messages");

/**
* save of the XML flow in $flow
*/
// save of the XML flow in $flow
$csv_flag = 1; //setting the csv_flag variable to change limit in SQL request of getODSXmlLog.php when CSV exporting
ob_start();
require_once _CENTREON_PATH_ . "www/include/eventLogs/xml/data.php";
$flow = ob_get_contents();
ob_end_clean();

/**
* Send Headers
*/
// Send Headers
header("Content-Type: application/csv-tab-delimited-table");
header("Content-disposition: filename=EventLogs.csv");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");

/**
* Read flow
*/
// Read flow
$xml = new SimpleXMLElement($flow);
if ($engine == "false") {
echo _("Begin date") . "; " . _("End date") . ";\n";
echo date(_('m/d/Y (H:i:s)'), intval($xml->infos->start))
. ";" . date(_('m/d/Y (H:i:s)'), intval($xml->infos->end)) . "\n";
echo _("Begin date") . "; "
. _("End date") . ";\n";
echo date(_('Y/m/d (H:i:s)'), intval($xml->infos->start)) . ";"
. date(_('Y/m/d (H:i:s)'), intval($xml->infos->end)) . "\n";
echo "\n";

echo _("Type") . ";" . _("Notification") . ";" . _("Alert") . ";" . _("error") . "\n";
echo ";" . $xml->infos->notification . ";" . $xml->infos->alert . ";" . $xml->infos->error . "\n";
echo _("Type") . ";"
. _("Notification") . ";"
. _("Alert") . ";"
. _("error") . "\n";
echo ";"
. $xml->infos->notification . ";"
. $xml->infos->alert . ";"
. $xml->infos->error . "\n";
echo "\n";

echo _("Host") . ";" . _("Up") . ";" . _("Down") . ";" . _("Unreachable") . "\n";
echo ";" . $xml->infos->up . ";" . $xml->infos->down . ";" . $xml->infos->unreachable . "\n";
echo _("Host") . ";"
. _("Up") . ";"
. _("Down") . ";"
. _("Unreachable") . "\n";
echo ";"
. $xml->infos->up . ";"
. $xml->infos->down . ";"
. $xml->infos->unreachable . "\n";
echo "\n";

echo _("Service") . ";" . _("Ok") . ";" . _("Warning") . ";" . _("Critical") . ";" . _("Unknown") . "\n";
echo ";" . $xml->infos->ok . ";" . $xml->infos->warning . ";" .
$xml->infos->critical . ";" . $xml->infos->unknown . "\n";
echo _("Service") . ";"
. _("Ok") . ";"
. _("Warning") . ";"
. _("Critical") . ";"
. _("Unknown") . "\n";
echo ";"
. $xml->infos->ok . ";"
. $xml->infos->warning . ";"
. $xml->infos->critical . ";"
. $xml->infos->unknown . "\n";
echo "\n";

echo _("Day") . ";" .
Expand All @@ -126,8 +130,8 @@
_("Contact") . ";" .
_("Cmd") . "\n";
foreach ($xml->line as $line) {
echo $line->date . ";" .
$line->time . ";" .
echo date(_('Y/m/d'), (int)$line->date) . ";" .
date(_('H:i:s'), (int)$line->time) . ";" .
$line->host_name . ";" .
$line->address . ";" .
$line->service_description . ";" .
Expand All @@ -139,16 +143,31 @@
$line->contact_cmd . "\n";
}
} else {
echo _("Begin date") . "; " . _("End date") . ";\n";
echo date(_('m/d/Y (H:i:s)'), intval($xml->infos->start)) . ";" .
date(_('m/d/Y (H:i:s)'), intval($xml->infos->end)) . "\n";
echo _("Begin date") . "; "
. _("End date") . ";\n";
echo date(_('Y/m/d (H:i:s)'), (int)$xml->infos->start) . ";"
. date(_('Y/m/d (H:i:s)'), (int)$xml->infos->end) . "\n";
echo "\n";
echo _("Type") . ";" . _("Notification") . ";" . _("Alert") . ";" . _("error") . "\n";
echo ";" . $xml->infos->notification . ";" . $xml->infos->alert . ";" . $xml->infos->error . "\n";

echo _("Type") . ";"
. _("Notification") . ";"
. _("Alert") . ";"
. _("error") . "\n";
echo ";"
. $xml->infos->notification . ";"
. $xml->infos->alert . ";"
. $xml->infos->error . "\n";
echo "\n";
echo _("Day") . ";" . _("Time") . ";" . _("Poller") . ";" . _("Output") . ";" . "\n";

echo _("Day") . ";"
. _("Time") . ";"
. _("Poller") . ";"
. _("Output") . "; " . "\n";
foreach ($xml->line as $line) {
echo "\"" . $line->date . "\";\"" . $line->time . "\";\"" . $line->poller .
"\";\"" . $line->output . "\";" . "\n";
echo "\"" .
date(_('Y/m/d'), (int)$line->date) . "\";\"" .
date(_('H:i:s'), (int)$line->time) . "\";\"" .
$line->poller . "\";\"" .
$line->output . "\";" . "\n";
}
}
17 changes: 6 additions & 11 deletions www/include/eventLogs/viewLog.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2005-2018 Centreon
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
Expand Down Expand Up @@ -83,15 +83,10 @@
$openid = $_GET["openid"];
}

if (isset($_GET["id"])) {
$id = $_GET["id"];
} else {
$id = 1;
}

if (isset($_POST["id"])) {
$id = $_POST["id"];
}
$id = filter_var(
$_GET['id'] ?? $_POST['id'] ?? 1,
FILTER_VALIDATE_INT
);

$serviceGrpArray = array();
$pollerArray = array();
Expand Down Expand Up @@ -399,7 +394,7 @@
<script>

/*
* Selecting choosen Host, Service, HG and/or SG
* Selecting chosen Host, Service, HG and/or SG
*/
function apply_period() {
var openid = getArgsForHost();
Expand Down
Loading

0 comments on commit 11a5c1f

Please sign in to comment.