261 lines
7.7 KiB
PHP
261 lines
7.7 KiB
PHP
<?php
|
|
require_once("support.inc.php");
|
|
$db_info = read_database(DBCONFIG_DIR, "di_zkl");
|
|
$host = $db_info['host'];
|
|
$user = $db_info['user'];
|
|
$password = $db_info['passwd'];
|
|
$database = $db_info['database'];
|
|
|
|
// Create connection
|
|
$conn = new mysqli($host, $user, $password, $database);
|
|
// Check connection
|
|
if ($conn->connect_error) {
|
|
die("Connection failed: " . $conn->connect_error);
|
|
}
|
|
|
|
function query_as_result($conn, $sql) {
|
|
$result = $conn->query($sql);
|
|
if ($result->num_rows < 1) {
|
|
return -1;
|
|
}
|
|
$row = $result->fetch_assoc();
|
|
return $row['result'];
|
|
}
|
|
|
|
function sw_errors($conn, $id, $maxAgeSeconds) {
|
|
$sql = "select count(id) as result from log_realtime where zkl=$id and (sw3000_state & 0x0f0) != 0 and t > unix_timestamp()-$maxAgeSeconds";
|
|
return query_as_result($conn, $sql);
|
|
}
|
|
|
|
function sw_mem($conn, $id, $maxAgeSeconds) {
|
|
$sql = "select count(id) as result from log_realtime where zkl=$id and (sw3000_state & 0xff00) != 0x8f00 and t > unix_timestamp()-$maxAgeSeconds";
|
|
return query_as_result($conn, $sql);
|
|
}
|
|
|
|
function connects($conn, $id, $maxAgeSeconds) {
|
|
$sql = "select count(t) as result from log_tcp where zkl=$id and event=\"connect\" and t > unix_timestamp()-$maxAgeSeconds";
|
|
return query_as_result($conn, $sql);
|
|
}
|
|
|
|
function conn_errors($conn, $id, $maxAgeSeconds) {
|
|
$sql = "select count(t) as result from log_tcp where zkl=$id and event=\"error\" and t > unix_timestamp()-$maxAgeSeconds";
|
|
return query_as_result($conn, $sql);
|
|
}
|
|
|
|
function samples($conn, $id) {
|
|
$sql = "select count(*) as result from log_realtime where zkl=$id";
|
|
return query_as_result($conn, $sql);
|
|
}
|
|
|
|
function remarks($conn, $id) {
|
|
$sql = "select rtstatus as result from zkl where id=$id";
|
|
return query_as_result($conn, $sql);
|
|
}
|
|
|
|
function pcm_found($conn, $id) {
|
|
$sql = "select mcu_persistent & 0x00200000 as result from log_realtime where zkl=$id order by id desc limit 1";
|
|
$result = query_as_result($conn, $sql);
|
|
if ($result < 0)
|
|
return "NoPCM";
|
|
return "PCM";
|
|
}
|
|
|
|
function phonenr($conn, $id) {
|
|
$sql = "select telefoonnr as result from zkl where id=$id";
|
|
return query_as_result($conn, $sql);
|
|
}
|
|
|
|
?>
|
|
|
|
<html>
|
|
<head>
|
|
<title>Checkconfig</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<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#ids').filterByText($('#idsfilter'), false);
|
|
});
|
|
</script>
|
|
<style>
|
|
body {
|
|
width: 100%;
|
|
}
|
|
input[type="text"], select {
|
|
width: 100%;
|
|
}
|
|
input[type="submit"] {
|
|
display: block;
|
|
margin: 0 auto;
|
|
}
|
|
.container {
|
|
display: block;
|
|
margin: 0 auto;
|
|
width: 300px;
|
|
}
|
|
.zklselection {
|
|
height: 300px;
|
|
}
|
|
.resulttable, .resulttable tr, .resulttable td, .resulttable th {
|
|
border: solid 1px gray;
|
|
border-collapse: collapse;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<?php if (isset($_POST['form_submitted'])):
|
|
$hours = intval($_POST['timefilter']);
|
|
if ($hours == 0) {
|
|
$hours = 12;
|
|
}
|
|
echo "<p>Filter set to $hours hours</p>";
|
|
?>
|
|
<table class="resulttable">
|
|
<tr>
|
|
<th>SerieNR</th>
|
|
<th>IDcode</th>
|
|
<th>MCU</th>
|
|
<th>WCPU</th>
|
|
<th>Drive</th>
|
|
<th>Measure</th>
|
|
<th>Wavecom</th>
|
|
<th>Wavrev</th>
|
|
<th>SWMEM</th>
|
|
<th>PCB</th>
|
|
<th>BOM</th>
|
|
<th>RTStatus</th>
|
|
<th>APN</th>
|
|
<th>TCP</th>
|
|
<th>SMS</th>
|
|
<th>Language</th>
|
|
<th>ServiceDate</th>
|
|
<th>Status</th>
|
|
<th>SwErrors</th>
|
|
<th>SwMemErrors</th>
|
|
<th>Connects</th>
|
|
<th>ConErrors</th>
|
|
<th>Samples</th>
|
|
<th>PhoneNr</th>
|
|
<th>Remarks</th>
|
|
<th>PCMfound</th>
|
|
</tr>
|
|
<?php
|
|
$maxAgeSeconds = $hours*3600;
|
|
foreach ($_POST['ids'] as $id) {
|
|
$id = (int)$id;
|
|
$sql = "select serienr,idcode,mcu_versie,wcpu_versie,sw3000_dversie,sw3000_mversie,wavecom_versie,wavecom_revisie,sw3000_onderhoud,pcb_versie,mech_versie,capabilities,gprs_apn,tcp_server,sms_server,i18n,onderhoud,lans_status,eigenaar,device,telefoonnr,rtstatus from zkl where id=$id";
|
|
$result = $conn->query($sql);
|
|
if ($result->num_rows < 1) {
|
|
continue;
|
|
}
|
|
$zkl = $result->fetch_assoc();
|
|
echo "<tr>";
|
|
echo "<td>".$zkl['serienr']."</td>";
|
|
echo "<td>".$zkl['idcode']."</td>";
|
|
echo "<td>".$zkl['mcu_versie']."</td>";
|
|
echo "<td>".$zkl['wcpu_versie']."</td>";
|
|
echo "<td>".$zkl['sw3000_dversie']."</td>";
|
|
echo "<td>".$zkl['sw3000_mversie']."</td>";
|
|
echo "<td>".$zkl['wavecom_versie']."</td>";
|
|
echo "<td>".$zkl['wavecom_revisie']."</td>";
|
|
echo "<td>".$zkl['sw3000_onderhoud']."</td>";
|
|
echo "<td>".$zkl['pcb_versie']."</td>";
|
|
echo "<td>".$zkl['mech_versie']."</td>";
|
|
echo "<td>".$zkl['capabilities']."</td>";
|
|
echo "<td>".$zkl['gprs_apn']."</td>";
|
|
echo "<td>".$zkl['tcp_server']."</td>";
|
|
echo "<td>".$zkl['sms_server']."</td>";
|
|
echo "<td>".$zkl['i18n']."</td>";
|
|
echo "<td>".$zkl['onderhoud']."</td>";
|
|
echo "<td>".$zkl['lans_status']."</td>";
|
|
echo "<td>".sw_errors($conn, $id, $maxAgeSeconds)."</td>";
|
|
echo "<td>".sw_mem($conn, $id, $maxAgeSeconds)."</td>";
|
|
echo "<td>".connects($conn, $id, $maxAgeSeconds)."</td>";
|
|
echo "<td>".conn_errors($conn, $id, $maxAgeSeconds)."</td>";
|
|
echo "<td>".samples($conn, $id)."</td>";
|
|
echo "<td>".phonenr($conn, $id)."</td>";
|
|
echo "<td>".remarks($conn, $id)."</td>";
|
|
echo "<td>".pcm_found($conn, $id)."</td>";
|
|
echo "</tr>";
|
|
}
|
|
?>
|
|
|
|
</table>
|
|
|
|
<p>Go <a href="checkconfig.php">back</a> to the form</p>
|
|
|
|
<?php else: ?>
|
|
|
|
<div class="container">
|
|
<h2>Check device configuration</h2>
|
|
|
|
<form action="checkconfig.php" method="POST">
|
|
<table id="mytable">
|
|
<tr><td>Hour filter</td><td><input type="text" type="number" min="1" max="72" name="timefilter" autocomplete="off"></td></tr>
|
|
<tr><td>Quick search</td><td><input type="text" id="idsfilter" autocomplete="off"></td></tr>
|
|
<tr>
|
|
<td colspan="2">
|
|
<select name="ids[]" class="zklselection" name="ids" id="ids" multiple>
|
|
<?php
|
|
$sql = "select id,serienr from zkl where serienr order by serienr";
|
|
if ($result = $conn->query($sql)) {
|
|
if ($result->num_rows > 0) {
|
|
while($row = $result->fetch_assoc()) {
|
|
echo "<option value=".$row['id'].">".$row['serienr']."</option>";
|
|
}
|
|
} else {
|
|
echo '<option value="">No results</option>';
|
|
}
|
|
} else {
|
|
echo '<option value="">No results (query failed: '. $conn->errno .')</option>';
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2"><input type="submit" value="Submit"></td>
|
|
</tr>
|
|
</table>
|
|
<input type="hidden" name="form_submitted" value="1" />
|
|
</form>
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
</body>
|
|
</html>
|