src.dualinventive.com/mtinfo/dist/webroot/support/showlog-plot-dialog.php

190 lines
6.3 KiB
PHP

<?php
/*
** showlog-plot-dialog.php
*/
//
// 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(
(isset($_GET['zkl']) && !is_numeric($_GET['zkl'])) ||
(isset($_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");
}
define('PLOTDIALOG_VER_STR', '1.00');
define('PLOTDIALOG_DATECODE', '20141028');
require_once("../include/i18n.php");
require_once("../include/cp3000-tcpclient.php");
require_once("support.inc.php");
?>
<html>
<title>Show Log - Plot Dialog <?php
echo PLOTDIALOG_VER_STR . "-" . PLOTDIALOG_DATECODE;
if( isset($_GET['zkl']) ) {
echo " - ";
echo $_GET['zkl'];
}
?></title>
</html>
<body>
<style type="text/css">
TABLE.DB_TABLE {
border: 1px solid black;
table-layout: auto;
border-collapse: collapse;
empty-cells: show;
}
TD.DB_TABLE {
border: 1px solid rgb(192,192,192);
padding: 2px;
}
TH.DB_TABLE {
border: 1px solid black;
border-bottom: 2px solid black;
}
TABLE.SELECT {
border: none;
table-layout: auto;
border-collapse: collapse;
empty-cells: show;
}
TD.SELECT {
border: none;
padding: 0px 4px;
vertical-align: top;
}
</style>
<?php
// read the database information
if( isset($_GET['db']) ) $db_info = read_database(DBCONFIG_DIR, $_GET['db']);
else $db_info = array();
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 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 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;
}
// recommended firmware versions
$REC_FW_MCU='1.13-20100331';
$REC_FW_WCPU='2.0-20100401';
switch( ($type = $_GET['type']) ) {
case 'meting':
$title = "Measurement";
break;
case 'batterij':
$title = "Batteries";
break;
case 'temp':
$title = "Temperature";
break;
case 'rssi':
$title = "Radio-signal";
break;
default:
echo "Invalid type";
exit(1);
}
$info_query = "SELECT * FROM zkl WHERE id=" . $_GET['zkl'];
$info_result = mysql_run($info_query, $db_main_handle);
$info = mysql_fetch_assoc($info_result);
echo "<h1>" . $info['idcode'] . "</h1>\n";
echo "<h2>Device information</h2>\n";
echo "<table>";
echo "<tr valign=\"top\"><td>Database:</td><td>" . $info['id'] . "</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>Firmware:</td><td>" . $info['mcu_versie'] . "<br>" . $info['wcpu_versie'] . "</td></tr>\n";
echo "<tr valign=\"top\"><td>Hardware:</td><td>" .
"ZKL: " . $info['pcb_versie'] . ", revision " . $info['pcb_revisie'] . ", " . $info['fabrieksnr'] . "<br>" .
"Wavecom: " . $info['wavecom_versie'] . ", " . $info['wavecom_revisie'] . ", " . $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>Plot graph <q>" . $title . "</q> on date</h2>\n";
echo "<form id=\"plot_meting\" action=\"plot-" . $type . ".php\" 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 "<table>\n";
echo "<tr><td>From:</td><td><input type=\"text\" size=\"16\" name=\"tmin\" value=\"" . date("Y-m-d h:i:s", time()-86400) . "\"></td></tr>\n";
echo "<tr><td>To:</td><td><input type=\"text\" size=\"16\" name=\"tmax\" value=\"" . date("Y-m-d h:i:s") . "\"></td></tr>\n";
echo "<tr><td>Hide header:</td><td><input type=\"checkbox\" name=\"hide_title\"></td></tr>\n";
echo "<tr><td>Hide labels:</td><td><input type=\"checkbox\" name=\"hide_info\"></td></tr>\n";
if( $type == 'meting' ) {
echo "<tr><td>Show RMS:</td><td><input type=\"checkbox\" name=\"show_rms\" checked></td></tr>\n";
}
if( $type == 'batterij' ) {
echo "<tr><td>Hide legend:</td><td><input type=\"checkbox\" name=\"hide_legend\"></td></tr>\n";
echo "<tr><td>Show charger:</td><td><input type=\"checkbox\" name=\"show_charger\"></td></tr>\n";
echo "<tr><td>Batteries:</td><td>";
echo "<input type=\"checkbox\" checked name=\"batterij[]\" value=\"1\"> Battery #1<br>\n";
echo "<input type=\"checkbox\" checked name=\"batterij[]\" value=\"2\"> Battery #2";
echo "</td></tr>\n";
}
echo "<tr><td>Data:</td><td><input type=\"checkbox\" checked name=\"log_realtime\"> Use <q>log_realtime</q></td></tr>\n";
echo "<tr><td>Dimensions:</td><td><input type=\"text\" name=\"w\" value=\"1280\" size=\"5\"> x <input type=\"text\" name=\"h\" value=\"700\" size=\"5\"></td></tr>\n";
echo "<tr><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Plot Grafiek\"></td></tr>\n";
echo "</form>\n";
?>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
function update_graphsz() {
var ww = $(window).width();
var wh = $(window).height();
$('input[name=w]').val(ww);
$('input[name=h]').val(wh);
}
$(document).ready(function() {
$(window).resize(update_graphsz);
update_graphsz();
});
</script>
</body>
</html>