src.dualinventive.com/mtinfo/dist/webroot/support/showlog.php

1471 lines
61 KiB
PHP

<?php
/*
************************************************************************
**
** Copyright (c) 2009..2013 by
** Core|Vision B.V.
** Hambakenwetering 1
** 5231 DD 's-Hertogenbosch
** The Netherlands
**
** All Rights Reserved
**
************************************************************************
*/
/*
************************************************************************
**
** Project name: Dual Inventive: MTinfo Support Scripts
** Filename: showlog.php
** Author: Jack Weeland
** Date: November 11, 2009
** File version: $Revision: 1.77 $
** $Date: 2014/10/15 16:24:58 $
**
************************************************************************
*/
/*
************************************************************************
**
** Display ZKL log files.
**
************************************************************************
*/
define('SHOWLOG_VER_STR', '1.7');
define('SHOWLOG_DATECODE', '20141008');
set_time_limit(0);
require_once("../include/i18n.php");
require_once("../include/cp3000-tcpclient.php");
require_once("../include/db_logtables.php");
require_once("support.inc.php");
if( isset($argc) && $argc > 1 ) {
// called from the command-line
parse_str($argv[1], $_GET);
}
//
// Check inputs for SQL statement injection and such.
// Items not tested below are not vulnerable for SQL statement injection, e.g.
// a time is always converted using 'strtotime()' and other items are only
// used in the PHP but never in the composition of an SQL statement.
// [security audit 2013-10-23]
//
if(
($_GET['zkl'] && !is_numeric($_GET['zkl'])) ||
($_GET['logfile'] && $_GET['logfile'] !== "" && !preg_match('/^[0-9]+,[0-9]+,[0-9]+$/', $_GET['logfile']) && !in_array($_GET['logfile'], array('log_tcp','log_versienummer','log_realtime','log_secure'))) ||
($_GET['sort'] && !in_array($_GET['sort'], array("idcode","serienr","imei","wavecom_serienr","sim","id", "imsi"))) ||
($_GET['limit'] && !is_numeric($_GET['limit'])) ||
($_GET['limit_start'] && !is_numeric($_GET['limit_start'])) ||
($_GET['db'] && dirname($_GET['db']) != ".")
) {
// don't do anything fancy or interruptive as fiddling with the GET parameters
// is intended by the author
die("Parameter error");
}
/* Override LOGTABLES with some extensions */
$_LOGTABLES['log_realtime']['info']['mcu_persistent']['fmt'] = "%08X";
$_LOGTABLES['log_realtime']['info']['mcu_persistent'][] = array( 'mask' => 0x00100000, 'val' => 0x00100000, 'text' => "TD3000 gedetecteerd" );
$_LOGTABLES['log_realtime']['info']['mcu_persistent'][] = array( 'mask' => 0x00200000, 'val' => 0x00200000, 'text' => "Powercycle gedetecteerd" );
// output to file?
if( isset($_GET['output']) && $_GET['output'] != "html" ) {
switch( $_GET['output'] ) {
case 'csv':
$mimetype = "text/csv";
$mime_ext = "csv";
break;
default:
die("Output format not supported");
}
header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: private");
header("Content-transfer-encoding: binary");
header("Content-type: " . $mimetype . "");
header("Content-disposition: attachment; filename=\"showlog-" . date("YmdHis") . "." . $mime_ext . "\"");
}
else $_GET['output'] = "html";
// set up internationalization
if( isset($_GET['lc']) ) {
// old style "language code"
$_GET['i18n'] = $_GET['lc'];
}
if( isset($_GET['i18n']) ) {
i18n_settext_language($_GET['lc']);
setlocale(LC_TIME, $_GET['lc']);
}
else {
i18n_settext_language('nl');
setlocale(LC_TIME, "nl");
}
// print out the HTML headers
if( !$argc && $_GET['output'] == "html" ) {
// don't cache
header('Content-Type: text/html; charset=utf-8');
header('Pragma: no-cache');
header('Expires: ' . date("r"));
?>
<html>
<head>
<title>Show Log <?php
echo SHOWLOG_VER_STR . "-" . SHOWLOG_DATECODE;
if( isset($_GET['zkl']) ) {
echo " - ";
echo $_GET['zkl'];
if( isset($_GET['logfile'])) {
echo "-";
echo $_GET['logfile'];
}
}
?></title>
</head>
<body>
<script type="text/javascript">
function do_device_action(zkl,key,value,db,callback)
{
device_action = new XMLHttpRequest();
device_action.onreadystatechange = callback;
device_action.open('GET', 'device-action.php?db=' + db + '&zkl=' + zkl + '&key=' + key + '&value=' + value);
device_action.setRequestHeader('Content-Type', 'text/plain');
device_action.send(null);
}
function warn_about_settings()
{
var submit_ok = true;
var logfile = document.forms['form_logfile_selectie'].logfile.value;
// warn if a large log file is selected and there is no limit on the number
// of lines and there is no date limit
var limit_checked = document.forms['form_logfile_selectie'].use_limit.checked;
var tlimit_checked = document.forms['form_logfile_selectie'].use_tlimit.checked;
if( !limit_checked && !tlimit_checked ) {
submit_ok = confirm(
'De log \'' + logfile + '\' kan veel gegevens bevatten en ' +
'de limiet op het maximaal aantal regels is niet actief.' +
'\n\n' +
'Wilt u doorgaan?'
);
// cancel clicked?
if( !submit_ok ) document.forms['form_logfile_selectie'].use_limit.focus();
}
return submit_ok;
}
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
jQuery.fn.filterByText = function(textbox, selectSingleMatch) {
return this.each(function() {
var select = this;
var options = [];
$(select).find('option').each(function() {
options.push({value: $(this).val(), text: $(this).text()});
});
$(select).data('options', options);
$(textbox).bind('change keyup', function() {
var options = $(select).empty().data('options');
var search = $.trim($(this).val());
var regex = new RegExp(search,"gi");
$.each(options, function(i) {
var option = options[i];
if(option.text.match(regex) !== null) {
$(select).append(
$('<option>').text(option.text).val(option.value)
);
}
});
if (selectSingleMatch === true && $(select).children().length === 1) {
$(select).children().get(0).selected = true;
}
$(select).scrollTop(1);
});
});
};
$(function() {
$('.showhide').click(function(e) {
e.preventDefault();
$($(this).attr('data-target')).toggle();
});
$('select#zkl').filterByText($('#zklfilter'), false);
});
</script>
<style type="text/css">
* {
font-family: "Times New Roman", serif;
}
table {
font-size: 16px;
}
body {
font-family: "Times New Roman",serif;
font-size: 10pt;
}
h1,h2,h3,h4,h5 {
font-family: Arial,Helvetica,sans-serif;
}
table.DB_TABLE td {
border: 1px solid rgb(192,192,192);
padding: 2px;
}
table.DB_TABLE th {
border: 1px solid black;
border-bottom: 2px solid black;
}
table.SELECT {
border: none;
table-layout: auto;
border-collapse: collapse;
empty-cells: show;
}
table.SELECT td {
border: none;
padding: 0px 4px;
vertical-align: top;
}
</style>
<?php
}
//
// Define and connect to the database
//
// databases
$databases = read_databases(CONFIG_DIR . "/database");
// read the database information
if( ! isset($_GET['db']) ) {
// Set default to di_zkl which is mtinfo_main, 1 small step for a man, one giant leap for mankind
$_GET['db'] = 'di_zkl';
}
if( isset($_GET['db']) ) {
$db_info = read_database(DBCONFIG_DIR, $_GET['db']);
if( !isset($db_info['host']) ) $db_info['host'] = "localhost";
if( !isset($db_info['user']) ) $db_info['user'] = "root";
if( !isset($db_info['passwd']) ) $db_info['passwd'] = "";
if( !isset($db_info['db']) ) $db_info['db'] = "di_zkl";
// open the database
$db_data_handle = mysql_connect($db_info['host'], $db_info['user'], $db_info['passwd']);
if( $db_data_handle === FALSE ) {
echo "Cannot connect to database: " . mysql_error();
exit(1);
}
mysql_select_db($db_info['database'], $db_data_handle);
if( $db_info['main'] ) {
$db_main_info = read_database(DBCONFIG_DIR, $db_info['main']);
$db_main_handle = mysql_connect($db_main_info['host'], $db_main_info['user'], $db_main_info['passwd'], true);
if( $db_main_handle === FALSE ) {
echo "Cannot connect to database: " . mysql_error();
exit(1);
}
mysql_select_db($db_main_info['database'], $db_main_handle);
}
else {
$db_main_handle = $db_data_handle;
$db_main_info = $db_info;
}
}
else {
unset($db_main_handle);
}
//
// Globals
//
// set default value for the limit on the number of lines
if( !isset($_GET['limit']) ) {
$_GET['limit'] = 300;
}
if( !isset($_GET['limit_start']) ) {
$_GET['limit_start'] = 0;
}
if( !isset($_GET['use_limit']) ) {
$_GET['use_limit'] = 1;
}
// and to show extra info
if( !isset($_GET['extra']) ) {
$_GET['extra'] = 1;
}
unset($backtrace);
$gsm_details = array();
$gsm_power_on = 0;
if( $_GET['output'] == "html" ) {
echo "<a name=\"zkl_selectie\">";
echo "<div align=\"right\">";
if( is_numeric($_GET['zkl']) ) {
echo "selecteer:\n";
echo "<a href=\"#zkl_selectie\">device</a>\n";
}
if( $_GET['logfile'] !== "" ) {
echo "ga naar:\n";
echo "<a href=\"#logfile_display\">logdata</a>\n";
}
echo "</div>";
echo "</a>\n";
//
// Database selection
//
echo "<h2>Database-selectie</h2>\n";
echo "<table class=\"SELECT\">";
echo "<tr>";
echo "<td>";
echo "<form id=\"form_db_selectie\" action=\"showlog.php\" method=\"get\">\n";
// remember all other settings
if( isset($_GET['use_tz']) ) echo "<input type=\"hidden\" name=\"use_tz\" value=\"1\">\n";
if( isset($_GET['extra']) ) echo "<input type=\"hidden\" name=\"extra\" value=\"1\">\n";
if( isset($_GET['debug']) ) echo "<input type=\"hidden\" name=\"debug\" value=\"1\">\n";
if( isset($_GET['sort']) ) echo "<input type=\"hidden\" id=\"sort\" name=\"sort\" value=\"" . $_GET['sort'] . "\">\n";
echo "<input type=\"hidden\" id=\"zkl\" name=\"zkl\" value=\"" . $_GET['zkl'] . "\">\n";
echo "<input type=\"hidden\" id=\"logfile\" name=\"logfile\" value=\"" . $_GET['logfile'] . "\">\n";
echo "<input type=\"hidden\" id=\"use_tlog\" name=\"use_tlog\" value=\"" . $_GET['use_tlog'] . "\">\n";
echo "<input type=\"hidden\" id=\"use_limit\" name=\"use_limit\" value=\"" . $_GET['use_limit'] . "\">\n";
echo "<input type=\"hidden\" id=\"limit\" name=\"limit\" value=\"" . $_GET['limit'] . "\">\n";
echo "<input type=\"hidden\" id=\"limit_start\" name=\"limit_start\" value=\"" . $_GET['limit_start'] . "\">\n";
echo "<input type=\"hidden\" id=\"use_tlimit\" name=\"use_tlimit\" value=\"" . $_GET['use_tlimit'] . "\">\n";
echo "<input type=\"hidden\" id=\"tmin\" name=\"tmin\" value=\"" . $_GET['tmin'] . "\">\n";
echo "<input type=\"hidden\" id=\"tmax\" name=\"tmax\" value=\"" . $_GET['tmax'] . "\">\n";
// remember filter settings and options
if( isset($_GET['filter']) ) {
if( $_GET['filter']['all'] == 'all' ) {
echo "<input type=\"hidden\" name=\"filter[all]\" value=\"all\">\n";
}
else {
if( $_GET['filter']['all'] == 'invert' ) {
echo "<input type=\"hidden\" name=\"filter[all]\" value=\"invert\">\n";
}
else {
echo "<input type=\"hidden\" name=\"filter[all]\" value=\"use\">\n";
}
foreach( $_GET['filter'] as $major => $subentries ) if( is_numeric($major) ) {
if( isset($_GET['filter'][$major]['all']) ) {
echo "<input type=\"hidden\" name=\"filter[" . $major . "][all]\" value=\"" . $major . "\">\n";
}
else foreach( $subentries as $minor => $dummy ) {
echo "<input type=\"hidden\" name=\"filter[" . $major . "][" . $minor . "]\" value=\"" . $minor . "\">\n";
}
}
}
}
echo "<select id=\"db\" name=\"db\" size=\"1\" onchange=\"return document.forms['form_db_selectie'].submit();\">\n";
$has_database = false;
foreach( $databases as $database ) {
echo "<option value=\"" . $database['file'] . "\"";
if( $db_info['file'] == $database['file'] ) {
echo " selected";
}
echo ">";
echo $database['name'];
echo "</option>\n";
}
// remember sort order
if( isset($_GET['sort']) ) {
echo "<input type=\"hidden\" id=\"sort\" name=\"sort\" value=\"" . $_GET['sort'] . "\">\n";
}
echo "</select>\n";
echo "<p>";
echo "<input type=\"submit\" value=\"Submit\">";
echo "</p>\n";
echo "</form>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
//
// Device selection and device sort order
//
if( $db_main_info ) {
echo "<h2>Device-selectie</h2>\n";
echo "<table class=\"SELECT\">";
echo "<tr>";
echo "<td>";
echo "<form id=\"form_zkl_selectie\" action=\"showlog.php#logfile_selectie\" method=\"get\">\n";
echo "<input type=\"hidden\" id=\"db\" name=\"db\" value=\"" . $db_info['file'] . "\">\n";
// remember sort order
if( isset($_GET['sort']) ) echo "<input type=\"hidden\" id=\"sort\" name=\"sort\" value=\"" . $_GET['sort'] . "\">\n";
if( isset($_GET['use_tz']) ) echo "<input type=\"hidden\" name=\"use_tz\" value=\"1\">\n";
if( isset($_GET['extra']) ) echo "<input type=\"hidden\" name=\"extra\" value=\"1\">\n";
if( isset($_GET['debug']) ) echo "<input type=\"hidden\" name=\"debug\" value=\"1\">\n";
echo "<input type=\"hidden\" id=\"use_tlog\" name=\"use_tlog\" value=\"" . $_GET['use_tlog'] . "\">\n";
echo "<input type=\"hidden\" id=\"use_limit\" name=\"use_limit\" value=\"" . $_GET['use_limit'] . "\">\n";
echo "<input type=\"hidden\" id=\"limit\" name=\"limit\" value=\"" . $_GET['limit'] . "\">\n";
echo "<input type=\"hidden\" id=\"limit_start\" name=\"limit_start\" value=\"" . $_GET['limit_start'] . "\">\n";
echo "<input type=\"hidden\" id=\"use_tlimit\" name=\"use_tlimit\" value=\"" . $_GET['use_tlimit'] . "\">\n";
echo "<input type=\"hidden\" id=\"tmin\" name=\"tmin\" value=\"" . $_GET['tmin'] . "\">\n";
echo "<input type=\"hidden\" id=\"tmax\" name=\"tmax\" value=\"" . $_GET['tmax'] . "\">\n";
// remember filter settings and options
if( isset($_GET['filter']) ) {
if( $_GET['filter']['all'] == 'all' ) {
echo "<input type=\"hidden\" name=\"filter[all]\" value=\"all\">\n";
}
else {
if( $_GET['filter']['all'] == 'invert' ) {
echo "<input type=\"hidden\" name=\"filter[all]\" value=\"invert\">\n";
}
else {
echo "<input type=\"hidden\" name=\"filter[all]\" value=\"use\">\n";
}
foreach( $_GET['filter'] as $major => $subentries ) if( is_numeric($major) ) {
if( isset($_GET['filter'][$major]['all']) ) {
echo "<input type=\"hidden\" name=\"filter[" . $major . "][all]\" value=\"" . $major . "\">\n";
}
else foreach( $subentries as $minor => $dummy ) {
echo "<input type=\"hidden\" name=\"filter[" . $major . "][" . $minor . "]\" value=\"" . $minor . "\">\n";
}
}
}
}
// page - list ZKLs
$query = "SELECT id,idcode,serienr,imei,wavecom_serienr,sim,imsi FROM zkl";
$query .= " ORDER BY ";
if( !isset($_GET['sort']) )
$query .= "idcode";
else
$query .= $_GET['sort'];
$result = mysql_run($query, $db_main_handle);
if( !$result ) {
echo "Error in query: " .mysql_error();
echo "<pre>" . $query . "</pre>\n";
exit(1);
}
echo "<input type=\"text\" id=\"zklfilter\" autocomplete=\"off\" style=\"width: 300px;\"><br />\n";
echo "<select id=\"zkl\" name=\"zkl\" size=\"10\" style=\"width: 300px;\" ondblclick=\"return document.forms['form_zkl_selectie'].submit();\">\n";
while( $row = mysql_fetch_assoc($result) ) {
echo "<option value=\"" . $row['id'] . "\"";
if( is_numeric($_GET['zkl']) && $_GET['zkl'] == $row['id'] ) echo " selected";
echo ">";
if( !isset($_GET['sort']) || $_GET['sort'] == "idcode" ) {
echo strip_tags($row['idcode']);
}
else if( $_GET['sort'] == "serienr" ) {
echo strip_tags($row['serienr']);
}
else if( $_GET['sort'] == "id" ) {
echo $row['id'] . " (" . strip_tags($row['serienr']) . " - " . strip_tags($row['idcode']) . ")";
}
else {
echo $row[$_GET['sort']] . " (" . strip_tags($row['serienr']) . " - " . strip_tags($row['idcode']) . ")";
}
echo "</option>\n";
}
echo "</select>\n";
echo "<p>";
echo "<input type=\"submit\" value=\"Submit\">";
echo "</p>\n";
echo "</form>\n";
echo "</td>\n";
echo "<td>";
echo "Sorteren: ";
echo "</td>\n";
echo "<td>";
echo "<form id=\"form_sort_selectie\" action=\"showlog.php#zkl_selectie\" method=\"get\">\n";
echo "<input type=\"hidden\" id=\"db\" name=\"db\" value=\"" . $db_info['file'] . "\">\n";
echo "<input type=\"hidden\" id=\"zkl\" name=\"zkl\" value=\"" . $_GET['zkl'] . "\">\n";
echo "<input type=\"hidden\" id=\"use_tlog\" name=\"use_tlog\" value=\"" . $_GET['use_tlog'] . "\">\n";
echo "<input type=\"hidden\" id=\"use_limit\" name=\"use_limit\" value=\"" . $_GET['use_limit'] . "\">\n";
echo "<input type=\"hidden\" id=\"limit\" name=\"limit\" value=\"" . $_GET['limit'] . "\">\n";
echo "<input type=\"hidden\" id=\"limit_start\" name=\"limit_start\" value=\"" . $_GET['limit_start'] . "\">\n";
echo "<input type=\"hidden\" id=\"use_tlimit\" name=\"use_tlimit\" value=\"" . $_GET['use_tlimit'] . "\">\n";
echo "<input type=\"hidden\" id=\"tmin\" name=\"tmin\" value=\"" . $_GET['tmin'] . "\">\n";
echo "<input type=\"hidden\" id=\"tmax\" name=\"tmax\" value=\"" . $_GET['tmax'] . "\">\n";
// remember filter settings and options
if( isset($_GET['filter']) ) {
if( $_GET['filter']['all'] == 'all' ) {
echo "<input type=\"hidden\" name=\"filter[all]\" value=\"all\">\n";
}
else {
if( $_GET['filter']['all'] == 'invert' ) {
echo "<input type=\"hidden\" name=\"filter[all]\" value=\"invert\">\n";
}
else {
echo "<input type=\"hidden\" name=\"filter[all]\" value=\"use\">\n";
}
foreach( $_GET['filter'] as $major => $subentries ) if( is_numeric($major) ) {
if( isset($_GET['filter'][$major]['all']) ) {
echo "<input type=\"hidden\" name=\"filter[" . $major . "][all]\" value=\"" . $major . "\">\n";
}
else foreach( $subentries as $minor => $dummy ) {
echo "<input type=\"hidden\" name=\"filter[" . $major . "][" . $minor . "]\" value=\"" . $minor . "\">\n";
}
}
}
}
if( isset($_GET['use_tz']) ) echo "<input type=\"hidden\" name=\"use_tz\" value=\"1\">\n";
if( isset($_GET['extra']) ) echo "<input type=\"hidden\" name=\"extra\" value=\"1\">\n";
if( isset($_GET['debug']) ) echo "<input type=\"hidden\" name=\"debug\" value=\"1\">\n";
// sort options
echo "<input type=\"radio\" name=\"sort\" value=\"idcode\"";
if( !isset($_GET['sort']) || $_GET['sort'] == "idcode" ) echo " checked";
echo " onclick=\"return document.forms['form_sort_selectie'].submit();\">";
echo "ID-code";
echo "<br>\n";
echo "<input type=\"radio\" name=\"sort\" value=\"serienr\"";
if( isset($_GET['sort']) && $_GET['sort'] == "serienr" ) echo " checked";
echo " onclick=\"return document.forms['form_sort_selectie'].submit();\">";
echo "Serial number";
echo "<br>\n";
echo "<input type=\"radio\" name=\"sort\" value=\"imei\"";
if( isset($_GET['sort']) && $_GET['sort'] == "imei" ) echo " checked";
echo " onclick=\"return document.forms['form_sort_selectie'].submit();\">";
echo "IMEI";
echo "<br>\n";
echo "<input type=\"radio\" name=\"sort\" value=\"wavecom_serienr\"";
if( isset($_GET['sort']) && $_GET['sort'] == "wavecom_serienr" ) echo " checked";
echo " onclick=\"return document.forms['form_sort_selectie'].submit();\">";
echo "Modem S/N";
echo "<br>\n";
echo "<input type=\"radio\" name=\"sort\" value=\"sim\"";
if( isset($_GET['sort']) && $_GET['sort'] == "sim" ) echo " checked";
echo " onclick=\"return document.forms['form_sort_selectie'].submit();\">";
echo "SIM-card number";
echo "<br>\n";
echo "<input type=\"radio\" name=\"sort\" value=\"imsi\"";
if( isset($_GET['sort']) && $_GET['sort'] == "imsi" ) echo " checked";
echo " onclick=\"return document.forms['form_sort_selectie'].submit();\">";
echo "IMSI";
echo "<br>\n";
echo "<input type=\"radio\" name=\"sort\" value=\"id\"";
if( isset($_GET['sort']) && $_GET['sort'] == "id" ) echo " checked";
echo " onclick=\"return document.forms['form_sort_selectie'].submit();\">";
echo "Database ID";
echo "</form>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
}
//
// Logfile selection
//
if (is_numeric($_GET['zkl'])) {
echo "<hr>\n";
echo "<a name=\"logfile_selectie\">";
echo "<div align=\"right\">";
echo "selecteer:\n";
echo "<a href=\"#zkl_selectie\">device</a>\n";
echo "ga naar:\n";
echo "<a href=\"#logfile_display\">logdata</a>\n";
echo "</div>";
echo "</a>\n";
$info_query = "SELECT * FROM zkl WHERE id=" . $_GET['zkl'];
$info_result = mysql_run($info_query, $db_main_handle);
if( !$info_result ) {
echo "Error in query: " .mysql_error();
echo "<pre>" . $info_query . "</pre>\n";
exit(1);
}
$info = mysql_fetch_assoc($info_result);
$tz_query = "SELECT tz FROM klant WHERE id = (SELECT IFNULL(gebruiker,eigenaar) FROM zkl WHERE id=" . $_GET['zkl'] . ")";
$tz_result = mysql_run($info_query, $db_main_handle);
if( !$tz_result ) {
echo "Error in query: " .mysql_error();
echo "<pre>" . $tz_query . "</pre>\n";
exit(1);
}
$tz_result = mysql_fetch_assoc($tz_result);
$info['tz'] = $tz_result['tz'];
$device_info['mcu_versie'] = zkl_get_fw_version($info['mcu_versie']);
$device_info['wcpu_versie'] = zkl_get_fw_version($info['wcpu_versie']);
$device_info['ualfat_versie'] = zkl_get_fw_version($info['ualfat_versie']);
if( $info['sw3000_dversie'] ) $device_info['sw3000_versie']['drive'] = zkl_get_fw_version($info['sw3000_dversie']);
if( $info['sw3000_mversie'] ) $device_info['sw3000_versie']['measure'] = zkl_get_fw_version($info['sw3000_mversie']);
if( $_GET['use_tz'] ) {
putenv("TZ=" . $info['tz']);
}
else putenv("TZ=" . date("e"));
echo "<h1>" . $info['idcode'] . " &ndash; Logfiles</h1>\n";
echo "<h2>Device information</h2>\n";
echo "<table>";
echo "<tr valign=\"top\"><td>Database ID:</td><td>" . $info['id'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>MTinfo V5 (device:uid):</td><td>" . sprintf('01%030d', $info['id']) . "</td></tr>\n";
if ($info['parent'] !== null) {
echo "<tr valign=\"top\"><td>Parent ID:</td><td>" . $info['parent'] . "</td></tr>\n";
}
echo "<tr valign=\"top\"><td>Serialno:</td><td>" . $info['serienr'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>ID-code:</td><td>" . $info['idcode'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>IMEI:</td><td>" . $info['imei'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>IMSI:</td><td>" . $info['imsi'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>SIM-card:</td><td>" . $info['sim'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>Telephone nr:</td><td>" . $info['telefoonnr'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>Next maintenance:</td><td>" . $info['onderhoud'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>SW 3000 mem install:</td><td>" . $info['sw3000_onderhoud'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>Status:</td><td><b>Dual Inventive:</b> " . $info['lans_status'] . ", <b>Customer:</b> " . $info['klant_status'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>Firmware:</td><td>" .
"<b>MCU:</b> " . $info['mcu_versie'] . "<br>" .
"<b>WCPU:</b> " . $info['wcpu_versie'] . "<br>" .
($info['sw3000_dversie'] ? ("<b>SWITCH 3000 drive:</b> " . $info['sw3000_dversie'] . "<br>") : "") .
($info['sw3000_mversie'] ? ("<b>SWITCH 3000 measure:</b> " . $info['sw3000_mversie'] . "<br>") : "") .
"</td></tr>\n";
echo "<tr valign=\"top\"><td>Hardware:</td><td>" .
"Device: <b>PCB-version:</b> " . $info['pcb_versie'] . ", <b>revision</b> " . $info['pcb_revisie'] . ", <b>productionno.</b> " . $info['fabrieksnr'] . "<br>" .
"Modem: <b>FW: </b>" . $info['wavecom_versie'] . ", <b>hardware-revision: </b>" . $info['wavecom_revisie'] . ", <b>S/N:</b> " . $info['wavecom_serienr'] . "<br>" .
"&micro;ALFAT: " . $info['ualfat_versie'] .
"</td></tr>\n";
echo "<tr valign=\"top\"><td>Timezone:</td><td>" . $info['tz'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>Comment:</td><td>" . nl2br($info['opmerking']) . "</td></tr>\n";
echo "</table>\n";
echo "<h2>Device debug</h2>\n";
echo "<ul>\n";
echo "<li><a target=\"_DEVICE_DEBUG_" . $_GET['zkl'] . "_" . date("Uu") . "\" href=\"debugreport.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "\">Debugrapportage</a></li>\n";
echo "<li><a target=\"_PLOT_SAMPLES_" . $_GET['zkl'] . "_" . date("Uu") . "\" href=\"plot-samples.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "\">Laatste meting (samples)</a></li>\n";
echo "<li><a href=\"javascript:do_device_action(";
echo $_GET['zkl'] . ",'debug','0E','" . $db_info['file'] . "',function() {";
echo "if( device_action.readyState == 4 ) {";
echo "if( device_action.status == 200 ) {";
echo "alert('Vergeet niet de debug-logging weer uit te zetten als u genoeg data hebt verzameld.');";
echo "}";
echo "else {";
echo "alert('Status ' + device_action.status + ': ' + device_action.statusText);";
echo "}";
echo "}";
echo "}";
echo ");\">Debug-logging AAN</a>; niet vergeten weer UIT te zetten!\n";
echo "<br>\n";
echo "Let op, met debug-logging actief worden er grote hoeveelheden data verstuurd\n";
echo "en de log-data zal achter gaan lopen met de black-box op het device.</li>\n";
echo "<li><a href=\"javascript:do_device_action(";
echo $_GET['zkl'] . ",'debug','03','" . $db_info['file'] . "',function() {";
echo "if( device_action.readyState == 4 ) {";
echo "if( device_action.status == 200 ) {";
echo "alert('Debug-logging staat nu uit.');";
echo "}";
echo "else {";
echo "alert('Status ' + device_action.status + ': ' + device_action.statusText);";
echo "}";
echo "}";
echo "}";
echo ");\">Debug-logging UIT</a></li>\n";
echo "</ul>\n";
echo "<h2>Grafieken op datum</h2>\n";
echo "<ul>\n";
echo "<li><a target=\"_PLOT_METING_" . $_GET['zkl'] . "_BY_DATE\" href=\"showlog-plot-dialog.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "&type=meting\">Meting</a> (opent een invulscherm)</li>\n";
echo "<li><a target=\"_PLOT_BATTERIJEN_" . $_GET['zkl'] . "_BY_DATE\" href=\"showlog-plot-dialog.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "&type=batterij\">Batterijen</a> (&hellip;)</li>\n";
echo "<li><a target=\"_PLOT_TEMPERATUUR_" . $_GET['zkl'] . "_BY_DATE\" href=\"showlog-plot-dialog.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "&type=temp\">Temperatuur</a> (&hellip;)</li>\n";
echo "<li><a target=\"_PLOT_RSSI_" . $_GET['zkl'] . "_BY_DATE\" href=\"showlog-plot-dialog.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "&type=rssi\">Radiosignaal</a> (&hellip;)</li>\n";
echo "</ul>\n";
echo "<h2>Logfile-selectie</h2>\n";
echo "<table class=\"SELECT\">";
echo "<tr>";
echo "<td colspan=\"3\">";
echo "<form id=\"form_logfile_selectie\" action=\"showlog.php#logfile_display\" method=\"get\" onsubmit=\"return warn_about_settings();\">\n";
echo "<input type=\"hidden\" id=\"db\" name=\"db\" value=\"" . $db_info['file'] . "\">\n";
echo "<input type=\"hidden\" id=\"zkl\" name=\"zkl\" value=\"" . $_GET['zkl'] . "\">\n";
if( isset($_GET['sort']) ) {
echo "<input type=\"hidden\" name=\"sort\" value=\"" . $_GET['sort'] . "\">\n";
}
echo "</td>\n";
echo "</tr>\n";
echo "<tr>";
echo "<td colspan=\"3\">";
echo "<a onclick=\"$('select#logfile').scrollTop(1);return false;\" href=\"#\">Scroll to top</a><br />\n";
$query = "SELECT * FROM zkl_logfile WHERE zkl=IF((SELECT parent FROM zkl WHERE id=" . $_GET['zkl'] . ") IS NULL," . $_GET['zkl'] . ",(SELECT parent FROM zkl WHERE id=" . $_GET['zkl'] . ")) ORDER BY timebase DESC";
$result = mysql_run($query, $db_main_handle);
if( !$result ) {
echo "Error in query: " .mysql_error();
echo "<pre>" . $query . "</pre>\n";
exit(1);
}
echo "<select id=\"logfile\" name=\"logfile\" size=\"10\" ondblclick=\"return warn_about_settings() && document.forms['form_logfile_selectie'].submit();\">\n";
// specials
echo "<option value=\"log_tcp\"" . ($_GET['logfile'] == "log_tcp" ? " selected" : "") . ">TCP log</option>\n";
echo "<option value=\"log_versienummer\"" . ($_GET['logfile'] == "log_versienummer" ? " selected" : "") . ">Versienummers, serienr, id-code, etc.</option>\n";
echo "<option value=\"log_realtime\"" . ($_GET['logfile'] == "log_realtime" ? " selected" : "") . ">Real-time status log</option>\n";
echo "<option value=\"log_secure\"" . ($_GET['logfile'] == "log_secure" ? " selected" : "") . ">Secure Server log</option>\n";
// the log files
while( $row = mysql_fetch_assoc($result) ) {
if ($row['timebase'] == 0 && $row['filepos'] == 0) {
continue;
}
echo "<option value=\"" . $row['sdcard'] . "," . $row['rpgmcount'] . "," . $row['startup'] . "\"";
if(
isset($_GET['logfile'])
? ($_GET['logfile'] == $row['sdcard'] . "," . $row['rpgmcount'] . "," . $row['startup'])
: ($row['status'] == 'current' && $row['sdcard'] == 0)
) echo " selected";
echo ">";
echo date("Y-m-d H:i:s", $row['timebase']);
echo " - " ;
echo $row['sdcard'] . "," . $row['rpgmcount'] . "," . $row['startup'];
echo " - " ;
echo $row['status'] . "," . $row['file_status'];
if( $row['foutcode'] != 0 ) echo ",error=" . $row['foutcode'];
echo " - " ;
echo $row['filepos'] . "/" . $row['filesize'];
echo "</option>\n";
}
echo "</select>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr title=\"Limiet aan het aantal regels\">";
echo "<td>\n";
echo "Limiet: ";
echo "</td>\n";
echo "<td colspan=\"2\">";
echo "<input type=\"checkbox\"". ($_GET['use_limit'] ? " checked" : "") . " name=\"use_limit\" value=\"1\" title=\"Gebruik limiet aan het aantal regels, of niet\">\n";
echo "maximaal <input type=\"text\" value=\"" . $_GET['limit'] . "\" name=\"limit\" size=\"5\"> regels, vanaf regel <input type=\"text\" value=\"" . $_GET['limit_start'] . "\" name=\"limit_start\" size=\"5\"><br>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr title=\"Tijdslimit\">";
echo "<td></td>\n";
echo "<td colspan=\"2\">";
echo "<input type=\"checkbox\"". ($_GET['use_tlimit'] ? " checked" : "") . " name=\"use_tlimit\" value=\"1\" title=\"Gebruik tijdslimiet, of niet\">\n";
echo "alleen entries in de periode\n";
echo "van <input type=\"text\" value=\"" . $_GET['tmin'] . "\" name=\"tmin\" size=\"16\"> ";
echo "tot <input type=\"text\" value=\"" . $_GET['tmax'] . "\" name=\"tmax\" size=\"16\"><br>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr title=\"Gebruik 't_log' i.p.v. 't'\">";
echo "<td></td>\n";
echo "<td colspan=\"2\">";
echo "<input type=\"checkbox\"". ($_GET['use_tlog'] ? " checked" : "") . " name=\"use_tlog\" value=\"1\" title=\"Gebruik 't_log' i.p.v. 't'\">\n";
echo "gebruik de tijd dat de entry naar de database is geschreven in plaats van de tijd van de gelogde gebeurtenis\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr title=\"Tijdzone\">";
echo "<td>\n";
echo "Opties: ";
echo "</td>\n";
echo "<td colspan=\"2\">";
echo "<input type=\"checkbox\"" . (isset($_GET['use_tz']) ? " checked" : "") . " name=\"use_tz\" value=\"1\" title=\"Gebruik tijdzone " . $info['tz'] . ", of de systeemtijd wanneer niet aangevinkt\">\n";
echo "gebruik tijdzone " . $info['tz'] . "\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr title=\"Extra informatie tonen\">";
echo "<td></td>\n";
echo "<td colspan=\"2\">";
echo "<input type=\"checkbox\"" . (isset($_GET['extra']) ? " checked" : "") . " name=\"extra\" value=\"1\">\n";
echo "extra information\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr title=\"Debug-informatie over de logdata\">";
echo "<td></td>\n";
echo "<td colspan=\"2\">";
echo "<input type=\"checkbox\"" . (isset($_GET['debug']) ? " checked" : "") . " name=\"debug\" value=\"1\">\n";
echo "log debugging\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>";
echo "<td>\n";
echo "Filter: ";
echo "</td>\n";
echo "<td colspan=\"2\">";
echo "<input type=\"radio\"" . ($_GET['filter']['all'] == 'all' ? " checked" : "") . " name=\"filter[all]\" value=\"all\"> alle data laten zien (filter niet gebruiken)\n";
echo "<input type=\"radio\"" . ((!isset($_GET['filter']['all']) || $_GET['filter']['all'] == 'use') ? " checked" : "") . " name=\"filter[all]\" value=\"use\"> filter gebruiken\n";
echo "<input type=\"radio\"" . ($_GET['filter']['all'] == 'invert' ? " checked" : "") . " name=\"filter[all]\" value=\"invert\"> filter inverteren<br>\n";
echo "</td>\n";
echo "</tr>\n";
foreach( $_LOGTABLES['log_zkl'] as $major => $logentry ) if( is_numeric($major) ) {
echo "<tr title=\"major: " . $major . "\">";
echo "<td></td>\n";
echo "<td>";
echo "<input type=\"checkbox\" name=\"filter[" . $major . "][all]\" value=\"" . $major . "\"";
if( isset($_GET['filter']) && isset($_GET['filter'][$major]['all']) ) echo " checked";
echo "> ";
echo $logentry['category'];
unset($logentry['category']);
$c = count($logentry);
if( $c > 1 ) {
echo " ";
echo '<a href="#" class="showhide" data-target="#subcat-' . $major . ' div">(expand)</a>';
}
echo "</td>";
echo "<td id=\"subcat-" . $major . "\">";
if( $c > 1 ) {
echo "<div style=\"display:none;\">";
} else {
echo "<div>";
}
foreach( $logentry as $minor => $subentry ) {
if( is_int($minor) ) {
echo "<span title=\"major: " . $major . ", minor: " . $minor . "\">";
echo "<input type=\"checkbox\" name=\"filter[" . $major . "][" . $minor . "]\" value=\"" . $minor . "\"";
if( isset($_GET['filter']) && isset($_GET['filter'][$major][$minor]) )
echo " checked";
echo "> ";
if( is_array($subentry['type']) ) {
$sep = "";
foreach( $subentry['type'] as $type ) {
echo $sep . $type;
$sep = ", ";
}
} else {
echo $subentry['type'];
}
echo "</span>";
echo "<br>\n";
} else if( $minor == "select" ) {
echo "<span title=\"major: " . $major . ", minor: " . $minor . "\">";
echo "<input type=\"checkbox\" name=\"filter[" . $major . "][select]\" value=\"" . $subentry . "\"";
if( isset($_GET['filter']) && isset($_GET['filter'][$major]['select']) ) echo " checked";
echo "> ";
echo $subentry;
echo "\n";
echo "<input type=\"text\" name=\"filter[" . $major . "][value]\" value=\"" . $_GET['filter'][$major]['value'] . "\">";
echo "</span>";
echo "<br>\n";
}
}
echo "</div>";
echo "</td>\n";
echo "</tr>\n";
}
echo "<tr>";
echo "<td colspan=\"3\">";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<p>";
echo "<input type=\"submit\" value=\"Submit\">\n";
echo "<button name=\"output\" value=\"csv\">Download als CSV</button>\n";
echo "</p>";
echo "</form>\n";
}
//
// Logfile display
//
if( is_numeric($_GET['zkl']) && $_GET['logfile'] ) {
echo "<hr>\n";
echo "<a name=\"logfile_display\">";
echo "<div align=\"right\">";
echo "selecteer:\n";
echo "<a href=\"#zkl_selectie\">device</a>\n";
echo "<a href=\"#logfile_selectie\">logfile</a>\n";
echo "</div>";
echo "</a>\n";
$nr_lines = 0;
if(
$_GET['logfile'] == 'log_tcp' ||
$_GET['logfile'] == 'log_versienummer' ||
$_GET['logfile'] == 'log_realtime' ||
$_GET['logfile'] == 'log_secure'
) {
// use indicated table or a subtable?
if( $_GET['logfile'] == "log_secure" ) {
$main_table = "log_secure";
$join_field = "id"; // join field is also called 'id'
$table = "log_secure_zkl";
$table_info = $_LOGTABLES[$_GET['logfile']][$table]['info'];
}
else {
$table = $_GET['logfile'];
$table_info = $_LOGTABLES[$_GET['logfile']]['info'];
}
echo "<h1>" . $info['idcode'] . " (".$info['serienr'].", ".$info['id'].") &ndash; Logfile: " . $_GET['logfile'] . "</h1>\n";
echo "<h2>Logdata</h2>\n";
$query = "SELECT " . $table . ".* ";
$query .= "FROM " . $table;
if( $main_table ) $query .= "," . $main_table;
if( $_GET['logfile'] == 'log_realtime' ) {
if( $_GET['use_tlimit'] ) $query .= " USE KEY (log_realtime_id_tijd) ";
else $query .= " USE KEY (log_realtime_zkl_id) ";
}
$query .= " WHERE zkl=" . $_GET['zkl'];
if( $main_table ) {
$query .= " AND " . $main_table . ".id=" . $table . "." . $join_field;
}
// time limit?
if( $_GET['logfile'] != "log_secure" ) {
if( $_GET['use_tlimit'] && $_GET['tmin'] ) $query .= " AND t>=" . strtotime($_GET['tmin']) . " ";
if( $_GET['use_tlimit'] && $_GET['tmax'] ) $query .= " AND t<=" . strtotime($_GET['tmax']) . " ";
}
else {
if( $_GET['use_tlimit'] && $_GET['tmin'] ) $query .= " AND log_secure.tijd>=" . $_GET['tmin'] . " ";
if( $_GET['use_tlimit'] && $_GET['tmax'] ) $query .= " AND log_secure.tijd<=" . $_GET['tmax'] . " ";
}
// order
if( $_GET['logfile'] == 'log_realtime' ) {
$query .= " ORDER BY id DESC";
}
else if( $_GET['logfile'] == 'log_secure' ) {
$query .= " ORDER BY " . $table . ".seqnr DESC";
}
else {
$query .= " ORDER BY " . $table . ".t DESC";
}
if( $_GET['use_limit'] && $_GET['limit'] ) {
$query .= " LIMIT " . $_GET['limit_start'] . ',' . $_GET['limit'];
}
$result = mysql_run($query, $db_data_handle);
if( !$result ) {
echo "Error in query: " .mysql_error();
echo "<pre>" . $query . "</pre>\n";
exit(1);
}
$n = mysql_num_fields($result);
echo "<table class=\"DB_TABLE\">\n";
echo "<tr>";
$exclude_cols = array("tijd", "gps_tijd", "speed", "heading", "id", "zkl", "latitude");
for( $i = 0; $i < $n; $i++ ) {
$column = mysql_fetch_field($result, $i);
if( in_array($column->name, $exclude_cols) ) {
continue;
}
echo "<th>";
if ($column->name == "longitude") {
echo "lat, long";
} elseif ($column->name == "mcu_local_state") {
echo "mcu loc st";
} else {
echo str_replace("_", " ", $column->name);
}
echo "</th>";
}
echo "</tr>\n";
while( $row = mysql_fetch_assoc($result) ) {
echo "<tr>";
foreach( $row as $key => $val ) {
if( in_array($key, $exclude_cols) ) {
continue;
}
echo "<td";
if( $val != NULL && $_GET['extra'] && $table_info && $table_info[$key] ) {
$extra_info = "";
$sep = "";
if( $table_info[$key]['text'] ) {
$extra_info .= $sep . $table_info[$key]['text'];
$sep = "\n";
}
if( $table_info[$key]['eval'] ) {
$extra_info .= $sep ;
eval($table_info[$key]['eval']);
$sep = "\n";
}
foreach( $table_info[$key] as $logextra_key => $logextra_item ) {
if( $logextra_item['sep'] ) {
if( $extra_info ) $sep = $logextra_item['sep'];
}
else if( isset($logextra_item['mask']) && ($val & $logextra_item['mask']) == $logextra_item['val'] ) {
$extra_info .= $sep . sprintf($logextra_item['text'], $val);
$sep = ", ";
}
}
if( $extra_info ) echo " title=\"" . $extra_info . "\"";
}
echo ">";
if( $table_info[$key]['fmt'] ) {
if( strstr($table_info[$key]['fmt'], "%t") ) {
echo str_replace("%t", date("Y-m-d H:i:s", $val), $table_info[$key]['fmt']);
}
else echo sprintf($table_info[$key]['fmt'], $val, $val, $val, $val);
} elseif ($key == "longitude") {
echo '<a href="http://maps.google.nl/?q='.$row['latitude'] . ",+" . $val.'" target="blank">' . $row['latitude'] . ", " . $val . '</a>';
} else {
echo $val;
}
echo "</td>";
}
echo "</tr>\n";
$nr_lines++;
}
//echo "<tr><td colspan=\"" . $n . "\">";
//echo "<input type=\"button\" value=\"Refresh\" onclick=\"return SelectLogFile();\">\n";
//echo "</td></tr>\n";
echo "</table>\n";
}
else {
list($sdcard,$rpgmcount,$startup) = explode(',', $_GET['logfile']);
echo "<h1>" . $info['idcode'] . " &ndash; Logfile: " . sprintf("%04X%04X.LOG", $rpgmcount,$startup) . "</h1>\n";
echo "<h2>Grafieken aan de hand van deze logfile</h2>\n";
echo "<ul>\n";
echo "<li><a target=\"_PLOT_METING_" . $_GET['zkl'] . "_" . $_GET['logfile'] . "\" href=\"plot-meting.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "&logfile=" . $_GET['logfile'] . "\">Meting</a></li>\n";
echo "<li><a target=\"_PLOT_METING_" . $_GET['zkl'] . "_" . $_GET['logfile'] . "\" href=\"plot-meting.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "&logfile=" . $_GET['logfile'] . "&show_rms\">Meting, met RMS</a></li>\n";
echo "<li><a target=\"_PLOT_BATTERIJEN_" . $_GET['zkl'] . "_" . $_GET['logfile'] . "\" href=\"plot-batterij.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "&logfile=" . $_GET['logfile'] . "\">Batterijen</a></li>\n";
echo "<li><a target=\"_PLOT_TEMPERATUUR_" . $_GET['zkl'] . "_" . $_GET['logfile'] . "\" href=\"plot-temp.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "&logfile=" . $_GET['logfile'] . "\">Temperatuur</a></li>\n";
echo "<li><a target=\"_PLOT_RSSI_" . $_GET['zkl'] . "_" . $_GET['logfile'] . "\" href=\"plot-rssi.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "&logfile=" . $_GET['logfile'] . "\">Radiosignaal</a></li>\n";
echo "<li><a target=\"_GEOFENCE_" . $_GET['zkl'] . "_" . $_GET['logfile'] . "\" href=\"test-geofence.php?db=" . $db_info['file'] . "&zkl=" . $_GET['zkl'] . "&logfile=" . $_GET['logfile'] . "\">Geofence analyze</a></li>\n";
echo "</ul>\n";
echo "<h2>Logfile</h2>\n";
$query = "SELECT id,t,t_log,major,minor ";
$query .= "FROM log_zkl ";
$query .= "WHERE ";
$query .= " zkl=" . $_GET['zkl'] . " AND ";
$query .= " sdcard=" . $sdcard . " AND ";
$query .= " rpgmcount=" . $rpgmcount . " AND ";
$query .= " startup=" . $startup . " ";
if( $_GET['use_tlimit'] ) {
if( $_GET['use_tlog'] ) {
if( $_GET['tmin'] ) $query .= "AND t_log>=" . strtotime($_GET['tmin']) . " ";
if( $_GET['tmax'] ) $query .= "AND t_log<=" . strtotime($_GET['tmax']) . " ";
}
else {
if( $_GET['tmin'] ) $query .= "AND t>=" . strtotime($_GET['tmin']) . " ";
if( $_GET['tmax'] ) $query .= "AND t<=" . strtotime($_GET['tmax']) . " ";
}
}
$query .= "ORDER BY id";
if( $_GET['use_limit'] && $_GET['limit'] ) {
$query .= " LIMIT " . $_GET['limit_start'] . ',' . $_GET['limit'];
}
$result = mysql_run($query, $db_data_handle);
if( !$result ) {
echo "Error in query: " .mysql_error();
echo "<pre>" . $query . "</pre>\n";
exit(1);
}
echo "<table>";
echo "<tr valign=\"top\"><td>Filter:</td><td>";
if( !isset($_GET['filter']) ) echo "<i>alle data gefilterd</i>";
else if( $_GET['filter']['all'] == 'all' ) echo "<i>geen filter; alle data wordt getoond</i>";
else {
if( $_GET['filter']['all'] == 'invert' ) echo "<em>not</em> ";
$sep = "";
foreach( $_GET['filter'] as $major => $subentries ) if( is_numeric($major) ) {
echo $sep;
echo $_LOGTABLES['log_zkl'][$major]['category'];
if( !isset($subentries['all']) ) {
echo "(";
$ssep = "";
foreach( $subentries as $minor => $dummy ) {
if( is_array($_LOGTABLES['log_zkl'][$major][$minor]['type']) ) {
foreach( $_LOGTABLES['log_zkl'][$major][$minor]['type'] as $type ) {
echo $ssep . $type;
$ssep = ", ";
}
}
else {
echo $ssep;
echo $_LOGTABLES['log_zkl'][$major][$minor]['type'];
}
$ssep = ", ";
}
echo ")";
}
$sep = ", ";
}
}
echo "</td></tr>\n";
echo "</table>\n";
echo "<p>";
echo "<table class=\"DB_TABLE\">\n";
echo "<tr>";
echo "<th style=\"width: 20ex;\">tijd</th>";
echo "<th colspan=\"2\">categorie</th>";
echo "<th>data</th>";
echo "</tr>\n";
$prev_time = -1;
while( $row = mysql_fetch_assoc($result) ) {
if( $_GET['debug'] ) {
$curr_time = $row['t'];
if( $curr_time > time() ) {
echo "<tr title=\"id: " . $row['id'] . ", major: " . $row['major'] . ", minor: " . $row['minor'] . ", gelogd op " . date("r", $row['t_log']) . "\">";
echo "<td>" . date("Y-m-d H:i:s", $row['t']) . "</td>";
echo "<td colspan=\"3\"><font style=\"color: red; text-decoration: blink;\">Future time</font></td>";
echo "</tr>\n";
}
else if( $curr_time < $prev_time ) {
echo "<tr title=\"id: " . $row['id'] . ", major: " . $row['major'] . ", minor: " . $row['minor'] . ", gelogd op " . date("r", $row['t_log']) . "\">";
echo "<td>" . date("Y-m-d H:i:s", $row['t']) . "</td>";
echo "<td colspan=\"3\"><font style=\"color: red; text-decoration: blink;\">Time discontinuum</font></td>";
echo "</tr>\n";
}
$prev_time = $curr_time;
}
if(
$_GET['filter']['all'] == 'all' ||
(
$_GET['filter']['all'] == 'invert'
? !(isset($_GET['filter'][$row['major']][$row['minor']]) ||
isset($_GET['filter'][$row['major']]['all']) ||
(isset($_GET['filter'][$row['major']]['select']) && $row[$_GET['filter'][$row['major']]['select']] == $_GET['filter'][$row['major']]['value']))
: isset($_GET['filter'][$row['major']][$row['minor']]) ||
isset($_GET['filter'][$row['major']]['all']) ||
(isset($_GET['filter'][$row['major']]['select']) && $row[$_GET['filter'][$row['major']]['select']] == $_GET['filter'][$row['major']]['value'])
)
) {
echo "<tr title=\"id: " . $row['id'] . ", major: " . $row['major'] . ", minor: " . $row['minor'] . ", gelogd op " . date("r", $row['t_log']) . "\">";
echo "<td>" . date("Y-m-d H:i:s", $row['t']) . "</td>";
if( isset($_LOGTABLES['log_zkl'][$row['major']]['category']) && isset($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type']) ) {
echo "<td>" . $_LOGTABLES['log_zkl'][$row['major']]['category'] . "</td>";
echo "<td>";
if( is_array($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type']) ) {
if( isset($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type'][$device_info['mcu_versie']['devtype']]) )
echo $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type'][$device_info['mcu_versie']['devtype']];
else
echo $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type']['*'];
}
else echo $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type'];
echo "</td>";
$table = $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['table'];
$columns = $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['columns'];
}
else if( isset($_LOGTABLES['log_zkl'][$row['major']]['category']) ) {
echo "<td colspan=\"2\">" . $_LOGTABLES['log_zkl'][$row['major']]['category'] . "</td>";
$table = $_LOGTABLES['log_zkl'][$row['major']]['table'];
$columns = $_LOGTABLES['log_zkl'][$row['major']]['columns'];
}
else if( isset($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type']) ) {
echo "<td colspan=\"2\">" . $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type'] . "</td>";
$table = $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['table'];
$columns = $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['columns'];
}
else {
// huh?
echo "<td colspan=\"3\"></td>\n";
unset($columns);
break;
}
if( isset($table) ) {
$subquery = "SELECT * FROM " . $table . " WHERE id=" . $row['id'];
$subresult = mysql_run($subquery, $db_data_handle);
if( !$subresult ) {
echo "Error in query: " .mysql_error();
echo "<pre>" . $subquery . "</pre>\n";
exit(1);
}
$subrow = mysql_fetch_array($subresult);
if( isset($columns) && isset($columns['count']) )
$m = $columns['count'];
else
$m = mysql_num_fields($subresult);
echo "<td style=\"padding: 0px;\"><table class=\"DB_TABLE\">\n";
echo "<tr>";
for( $i = 1; $i < $m; $i++ ) {
$val = $subrow[$i];
$sep = "";
echo "<td title=\"";
if( isset($columns[$i]['title']) ) {
eval($columns[$i]['title']);
$sep = ";\r\n";
}
else {
$field = mysql_fetch_field($subresult, $i);
echo $sep . $field->name;
$sep = ";\r\n";
}
if( $val != NULL && $_GET['extra'] && $columns[$i]['extra'] ) {
$extra_info = "";
$value_exception = FALSE;
if($columns[$i]['extra']['text'] ) {
$extra_info .= $sep . $columns[$i]['extra']['text'];
$sep = ";\r\n";
}
if( $columns[$i]['extra']['eval'] ) {
$extra_info .= $sep;
eval($columns[$i]['extra']['eval']);
$sep = ";\r\n";
}
if( !$inhibit_value ) foreach( $columns[$i]['extra'] as $logextra_item ) if( is_array($logextra_item) ) {
if( $logextra_item['sep'] ) {
if( $extra_info ) $sep = $logextra_item['sep'];
}
else if( ($val & $logextra_item['mask']) == $logextra_item['val'] ) {
$extra_info .= $sep . sprintf($logextra_item['text'], $val);
$sep = ", ";
}
}
echo $extra_info;
}
echo "\">";
if( isset($columns[$i]['eval']) ) {
eval($columns[$i]['eval']);
}
if( isset($columns[$i]['text']) ) {
if( $columns[$i]['text'] ) {
// set and not an empty string; an empty cell will only be output
// if set and empty string
echo sprintf($columns[$i]['text'], $_GET['zkl'], $db_info['file'], $row['id'], $inline_data);
}
}
else {
echo $val;
}
echo "</td>\n";
}
echo "</tr>\n";
$nr_lines++;
if( isset($_GET['debug']) && isset($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['extra']) ) {
$sep = "";
echo "<tr>";
echo "<td colspan=\"" . $m . "\">";
if( $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['extra']['text'] ) {
echo $sep . $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['extra']['text'];
$sep = "<br>\n";
}
if( $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['extra']['eval'] ) {
echo $sep;
eval($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['extra']['eval']);
}
echo "</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
else echo "<td></td>\n";
echo "</tr>\n";
}
}
echo "</table></td>\n";
}
echo "<div align=\"right\">";
echo $info['idcode'] . "/" . $info['serienr'] . "/" . $info['id'] . "\n&ndash;\n";
echo date("Y-m-d H:i:s") . "\n";
if( $_GET['use_tz'] ) echo date("T") . "\n";
echo "&ndash;\n";
echo $_GET['db'] . "\n";
echo "&ndash;\n";
echo $nr_lines . " regels\n&ndash;\n";
echo "selecteer:\n";
echo "<a href=\"#zkl_selectie\">device</a>\n";
echo "<a href=\"#logfile_selectie\">logfile</a>\n";
echo "ga naar:\n";
echo "<a href=\"#logfile_display\">begin</a>\n";
echo "</div>\n";
}
echo "</body>\n";
echo "</html>\n";
}
else if( $_GET['output'] == "csv" ) {
if( is_numeric($_GET['zkl']) && $_GET['logfile'] ) {
if(
$_GET['logfile'] == 'log_tcp' ||
$_GET['logfile'] == 'log_versienummer' ||
$_GET['logfile'] == 'log_realtime' ||
$_GET['logfile'] == 'log_secure'
) {
// use indicated table or a subtable?
if( $_GET['logfile'] == "log_secure" ) {
$main_table = "log_secure";
$join_field = "id"; // join field is also called 'id'
$table = "log_secure_zkl";
$table_info = $_LOGTABLES[$_GET['logfile']][$table]['info'];
}
else {
$table = $_GET['logfile'];
$table_info = $_LOGTABLES[$_GET['logfile']]['info'];
}
$query = "SELECT " . $table . ".* ";
$query .= "FROM " . $table;
if( $main_table ) $query .= "," . $main_table;
if( $_GET['logfile'] == 'log_realtime' ) {
if( $_GET['use_tlimit'] ) $query .= " USE KEY (log_realtime_id_tijd) ";
else $query .= " USE KEY (log_realtime_zkl_id) ";
}
$query .= " WHERE zkl=" . $_GET['zkl'];
if( $main_table ) {
$query .= " AND " . $main_table . ".id=" . $table . "." . $join_field;
}
// time limit?
if( $_GET['logfile'] != "log_secure" ) {
if( $_GET['use_tlimit'] && $_GET['tmin'] ) $query .= " AND t>=" . strtotime($_GET['tmin']) . " ";
if( $_GET['use_tlimit'] && $_GET['tmax'] ) $query .= " AND t<=" . strtotime($_GET['tmax']) . " ";
}
else {
if( $_GET['use_tlimit'] && $_GET['tmin'] ) $query .= " AND log_secure.tijd>=" . $_GET['tmin'] . " ";
if( $_GET['use_tlimit'] && $_GET['tmax'] ) $query .= " AND log_secure.tijd<=" . $_GET['tmax'] . " ";
}
// order
if( $_GET['logfile'] == 'log_realtime' ) {
$query .= " ORDER BY id DESC";
}
else if( $_GET['logfile'] == 'log_secure' ) {
$query .= " ORDER BY " . $table . ".seqnr DESC";
}
else {
$query .= " ORDER BY " . $table . ".t DESC";
}
if( $_GET['use_limit'] && $_GET['limit'] ) {
$query .= " LIMIT " . $_GET['limit_start'] . ',' . $_GET['limit'];
}
$result = mysql_run($query, $db_data_handle);
if( !$result ) {
echo "Error in query: " .mysql_error();
echo "<pre>" . $query . "</pre>\n";
exit(1);
}
$n = mysql_num_fields($result);
for( $i = 0; $i < $n; $i++ ) {
$column = mysql_fetch_field($result, $i);
if( $i ) echo ",";
echo "\"" . $column->name . "\"";
}
echo "\r\n";
while( $row = mysql_fetch_assoc($result) ) {
$first = TRUE;
foreach( $row as $key => $val ) {
if( $first ) $first = FALSE;
else echo ",";
if( $table_info[$key]['fmt'] ) {
if( strstr($table_info[$key]['fmt'], "%t") ) {
echo str_replace("%t", date("Y-m-d H:i:s", $val), $table_info[$key]['fmt']);
}
else echo sprintf($table_info[$key]['fmt'], $val, $val, $val, $val);
}
else echo $val;
}
echo "\r\n";
}
}
else {
list($sdcard,$rpgmcount,$startup) = explode(',', $_GET['logfile']);
$query = "SELECT id,t,t_log,major,minor ";
$query .= "FROM log_zkl ";
$query .= "WHERE ";
$query .= " zkl=" . $_GET['zkl'] . " AND ";
$query .= " sdcard=" . $sdcard . " AND ";
$query .= " rpgmcount=" . $rpgmcount . " AND ";
$query .= " startup=" . $startup . " ";
if( $_GET['use_tlimit'] ) {
if( $_GET['use_tlog'] ) {
if( $_GET['tmin'] ) $query .= "AND t_log>=" . strtotime($_GET['tmin']) . " ";
if( $_GET['tmax'] ) $query .= "AND t_log<=" . strtotime($_GET['tmax']) . " ";
}
else {
if( $_GET['tmin'] ) $query .= "AND t>=" . strtotime($_GET['tmin']) . " ";
if( $_GET['tmax'] ) $query .= "AND t<=" . strtotime($_GET['tmax']) . " ";
}
}
$query .= "ORDER BY id";
if( $_GET['use_limit'] && $_GET['limit'] ) {
$query .= " LIMIT " . $_GET['limit_start'] . ',' . $_GET['limit'];
}
$result = mysql_run($query, $db_data_handle);
if( !$result ) {
echo "Error in query: " .mysql_error();
echo "<pre>" . $query . "</pre>\n";
exit(1);
}
$prev_time = -1;
while( $row = mysql_fetch_assoc($result) ) {
if(
$_GET['filter']['all'] == 'all' ||
(
$_GET['filter']['all'] == 'invert'
? !(isset($_GET['filter'][$row['major']][$row['minor']]) ||
isset($_GET['filter'][$row['major']]['all']) ||
(isset($_GET['filter'][$row['major']]['select']) && $row[$_GET['filter'][$row['major']]['select']] == $_GET['filter'][$row['major']]['value']))
: isset($_GET['filter'][$row['major']][$row['minor']]) ||
isset($_GET['filter'][$row['major']]['all']) ||
(isset($_GET['filter'][$row['major']]['select']) && $row[$_GET['filter'][$row['major']]['select']] == $_GET['filter'][$row['major']]['value'])
)
) {
echo date("Y-m-d H:i:s", $row['t']);
if( isset($_LOGTABLES['log_zkl'][$row['major']]['category']) && isset($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type']) ) {
echo "," . $_LOGTABLES['log_zkl'][$row['major']]['category'];
if( is_array($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type']) ) {
if( isset($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type'][$device_info['mcu_versie']['devtype']]) )
echo "," . $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type'][$device_info['mcu_versie']['devtype']];
else
echo "," . $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type']['*'];
}
else echo "," . $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type'];
$table = $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['table'];
$columns = $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['columns'];
}
else if( isset($_LOGTABLES['log_zkl'][$row['major']]['category']) ) {
echo "," . $_LOGTABLES['log_zkl'][$row['major']]['category'] . ",";
$table = $_LOGTABLES['log_zkl'][$row['major']]['table'];
$columns = $_LOGTABLES['log_zkl'][$row['major']]['columns'];
}
else if( isset($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type']) ) {
echo "," . $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type'] . ",";
$table = $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['table'];
$columns = $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['columns'];
}
else {
// huh?
echo ",,";
unset($columns);
break;
}
if( isset($table) ) {
$subquery = "SELECT * FROM " . $table . " WHERE id=" . $row['id'];
$subresult = mysql_run($subquery, $db_data_handle);
if( !$subresult ) {
echo "Error in query: " .mysql_error();
echo "<pre>" . $subquery . "</pre>\n";
exit(1);
}
$subrow = mysql_fetch_array($subresult);
if( isset($columns) && isset($columns['count']) )
$m = $columns['count'];
else
$m = mysql_num_fields($subresult);
for( $i = 1; $i < $m; $i++ ) {
$val = $subrow[$i];
$sep = "";
echo ",";
if( isset($columns[$i]['eval']) ) {
eval($columns[$i]['eval']);
}
if( isset($columns[$i]['text']) ) {
if( $columns[$i]['text'] ) {
// set and not an empty string; an empty cell will only be output
// if set and empty string
echo sprintf($columns[$i]['text'], $_GET['zkl'], $db_info['file'], $row['id'], $inline_data);
}
}
else {
echo $val;
}
}
}
echo "\r\n";
}
}
}
}
}
// clean-up
if( $db_main_info['file'] != $db_info['file'] ) mysql_close($db_main_handle);
if( isset($db_data_handle) ) mysql_close($db_data_handle);
?>