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")); ?> 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']; } } ?> "; echo "
"; if( is_numeric($_GET['zkl']) ) { echo "selecteer:\n"; echo "device\n"; } if( $_GET['logfile'] !== "" ) { echo "ga naar:\n"; echo "logdata\n"; } echo "
"; echo "\n"; // // Database selection // echo "

Database-selectie

\n"; echo ""; echo ""; echo "\n"; echo "\n"; echo "
"; echo "
\n"; // remember all other settings if( isset($_GET['use_tz']) ) echo "\n"; if( isset($_GET['extra']) ) echo "\n"; if( isset($_GET['debug']) ) echo "\n"; if( isset($_GET['sort']) ) echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; // remember filter settings and options if( isset($_GET['filter']) ) { if( $_GET['filter']['all'] == 'all' ) { echo "\n"; } else { if( $_GET['filter']['all'] == 'invert' ) { echo "\n"; } else { echo "\n"; } foreach( $_GET['filter'] as $major => $subentries ) if( is_numeric($major) ) { if( isset($_GET['filter'][$major]['all']) ) { echo "\n"; } else foreach( $subentries as $minor => $dummy ) { echo "\n"; } } } } echo "\n"; } echo "\n"; echo "

"; echo ""; echo "

\n"; echo "
\n"; echo "
\n"; // // Device selection and device sort order // if( $db_main_info ) { echo "

Device-selectie

\n"; echo ""; echo ""; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
"; echo "
\n"; echo "\n"; // remember sort order if( isset($_GET['sort']) ) echo "\n"; if( isset($_GET['use_tz']) ) echo "\n"; if( isset($_GET['extra']) ) echo "\n"; if( isset($_GET['debug']) ) echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; // remember filter settings and options if( isset($_GET['filter']) ) { if( $_GET['filter']['all'] == 'all' ) { echo "\n"; } else { if( $_GET['filter']['all'] == 'invert' ) { echo "\n"; } else { echo "\n"; } foreach( $_GET['filter'] as $major => $subentries ) if( is_numeric($major) ) { if( isset($_GET['filter'][$major]['all']) ) { echo "\n"; } else foreach( $subentries as $minor => $dummy ) { echo "\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 "
" . $query . "
\n"; exit(1); } echo "
\n"; echo "\n"; echo "

"; echo ""; echo "

\n"; echo "
\n"; echo "
"; echo "Sorteren: "; echo ""; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; // remember filter settings and options if( isset($_GET['filter']) ) { if( $_GET['filter']['all'] == 'all' ) { echo "\n"; } else { if( $_GET['filter']['all'] == 'invert' ) { echo "\n"; } else { echo "\n"; } foreach( $_GET['filter'] as $major => $subentries ) if( is_numeric($major) ) { if( isset($_GET['filter'][$major]['all']) ) { echo "\n"; } else foreach( $subentries as $minor => $dummy ) { echo "\n"; } } } } if( isset($_GET['use_tz']) ) echo "\n"; if( isset($_GET['extra']) ) echo "\n"; if( isset($_GET['debug']) ) echo "\n"; // sort options echo ""; echo "ID-code"; echo "
\n"; echo ""; echo "Serial number"; echo "
\n"; echo ""; echo "IMEI"; echo "
\n"; echo ""; echo "Modem S/N"; echo "
\n"; echo ""; echo "SIM-card number"; echo "
\n"; echo ""; echo "IMSI"; echo "
\n"; echo ""; echo "Database ID"; echo "
\n"; echo "
\n"; } // // Logfile selection // if (is_numeric($_GET['zkl'])) { echo "
\n"; echo ""; echo "
"; echo "selecteer:\n"; echo "device\n"; echo "ga naar:\n"; echo "logdata\n"; echo "
"; echo "\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 "
" . $info_query . "
\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 "
" . $tz_query . "
\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 "

" . $info['idcode'] . " – Logfiles

\n"; echo "

Device information

\n"; echo ""; echo "\n"; echo "\n"; if ($info['parent'] !== null) { echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Database ID:" . $info['id'] . "
MTinfo V5 (device:uid):" . sprintf('01%030d', $info['id']) . "
Parent ID:" . $info['parent'] . "
Serialno:" . $info['serienr'] . "
ID-code:" . $info['idcode'] . "
IMEI:" . $info['imei'] . "
IMSI:" . $info['imsi'] . "
SIM-card:" . $info['sim'] . "
Telephone nr:" . $info['telefoonnr'] . "
Next maintenance:" . $info['onderhoud'] . "
SW 3000 mem install:" . $info['sw3000_onderhoud'] . "
Status:Dual Inventive: " . $info['lans_status'] . ", Customer: " . $info['klant_status'] . "
Firmware:" . "MCU: " . $info['mcu_versie'] . "
" . "WCPU: " . $info['wcpu_versie'] . "
" . ($info['sw3000_dversie'] ? ("SWITCH 3000 drive: " . $info['sw3000_dversie'] . "
") : "") . ($info['sw3000_mversie'] ? ("SWITCH 3000 measure: " . $info['sw3000_mversie'] . "
") : "") . "
Hardware:" . "Device: PCB-version: " . $info['pcb_versie'] . ", revision " . $info['pcb_revisie'] . ", productionno. " . $info['fabrieksnr'] . "
" . "Modem: FW: " . $info['wavecom_versie'] . ", hardware-revision: " . $info['wavecom_revisie'] . ", S/N: " . $info['wavecom_serienr'] . "
" . "µALFAT: " . $info['ualfat_versie'] . "
Timezone:" . $info['tz'] . "
Comment:" . nl2br($info['opmerking']) . "
\n"; echo "

Device debug

\n"; echo "\n"; echo "

Grafieken op datum

\n"; echo "\n"; echo "

Logfile-selectie

\n"; echo ""; echo ""; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; foreach( $_LOGTABLES['log_zkl'] as $major => $logentry ) if( is_numeric($major) ) { echo ""; echo "\n"; echo ""; echo "\n"; echo "\n"; } echo ""; echo "\n"; echo "\n"; echo "
"; echo "
\n"; echo "\n"; echo "\n"; if( isset($_GET['sort']) ) { echo "\n"; } echo "
"; echo "Scroll to top
\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 "
" . $query . "
\n"; exit(1); } echo "\n"; echo "
\n"; echo "Limiet: "; echo ""; echo "\n"; echo "maximaal regels, vanaf regel
\n"; echo "
"; echo "\n"; echo "alleen entries in de periode\n"; echo "van "; echo "tot
\n"; echo "
"; echo "\n"; echo "gebruik de tijd dat de entry naar de database is geschreven in plaats van de tijd van de gelogde gebeurtenis\n"; echo "
\n"; echo "Opties: "; echo ""; echo "\n"; echo "gebruik tijdzone " . $info['tz'] . "\n"; echo "
"; echo "\n"; echo "extra information\n"; echo "
"; echo "\n"; echo "log debugging\n"; echo "
\n"; echo "Filter: "; echo ""; echo " alle data laten zien (filter niet gebruiken)\n"; echo " filter gebruiken\n"; echo " filter inverteren
\n"; echo "
"; echo " "; echo $logentry['category']; unset($logentry['category']); $c = count($logentry); if( $c > 1 ) { echo " "; echo '(expand)'; } echo ""; if( $c > 1 ) { echo "
"; } else { echo "
"; } foreach( $logentry as $minor => $subentry ) { if( is_int($minor) ) { echo ""; echo " "; if( is_array($subentry['type']) ) { $sep = ""; foreach( $subentry['type'] as $type ) { echo $sep . $type; $sep = ", "; } } else { echo $subentry['type']; } echo ""; echo "
\n"; } else if( $minor == "select" ) { echo ""; echo " "; echo $subentry; echo "\n"; echo ""; echo ""; echo "
\n"; } } echo "
"; echo "
"; echo "
\n"; echo "

"; echo "\n"; echo "\n"; echo "

"; echo "\n"; } // // Logfile display // if( is_numeric($_GET['zkl']) && $_GET['logfile'] ) { echo "
\n"; echo ""; echo "
"; echo "selecteer:\n"; echo "device\n"; echo "logfile\n"; echo "
"; echo "\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 "

" . $info['idcode'] . " (".$info['serienr'].", ".$info['id'].") – Logfile: " . $_GET['logfile'] . "

\n"; echo "

Logdata

\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 "
" . $query . "
\n"; exit(1); } $n = mysql_num_fields($result); echo "\n"; echo ""; $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 ""; } echo "\n"; while( $row = mysql_fetch_assoc($result) ) { echo ""; foreach( $row as $key => $val ) { if( in_array($key, $exclude_cols) ) { continue; } echo " $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 '' . $row['latitude'] . ", " . $val . ''; } else { echo $val; } echo ""; } echo "\n"; $nr_lines++; } //echo "\n"; echo "
"; if ($column->name == "longitude") { echo "lat, long"; } elseif ($column->name == "mcu_local_state") { echo "mcu loc st"; } else { echo str_replace("_", " ", $column->name); } echo "
"; //echo "\n"; //echo "
\n"; } else { list($sdcard,$rpgmcount,$startup) = explode(',', $_GET['logfile']); echo "

" . $info['idcode'] . " – Logfile: " . sprintf("%04X%04X.LOG", $rpgmcount,$startup) . "

\n"; echo "

Grafieken aan de hand van deze logfile

\n"; echo "\n"; echo "

Logfile

\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 "
" . $query . "
\n"; exit(1); } echo ""; echo "\n"; echo "
Filter:"; if( !isset($_GET['filter']) ) echo "alle data gefilterd"; else if( $_GET['filter']['all'] == 'all' ) echo "geen filter; alle data wordt getoond"; else { if( $_GET['filter']['all'] == 'invert' ) echo "not "; $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 "
\n"; echo "

"; echo "\n"; echo ""; echo ""; echo ""; echo ""; echo "\n"; $prev_time = -1; while( $row = mysql_fetch_assoc($result) ) { if( $_GET['debug'] ) { $curr_time = $row['t']; if( $curr_time > time() ) { echo ""; echo ""; echo ""; echo "\n"; } else if( $curr_time < $prev_time ) { echo ""; echo ""; echo ""; echo "\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 ""; echo ""; if( isset($_LOGTABLES['log_zkl'][$row['major']]['category']) && isset($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type']) ) { echo ""; echo ""; $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 ""; $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 ""; $table = $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['table']; $columns = $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['columns']; } else { // huh? echo "\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 "
" . $subquery . "
\n"; exit(1); } $subrow = mysql_fetch_array($subresult); if( isset($columns) && isset($columns['count']) ) $m = $columns['count']; else $m = mysql_num_fields($subresult); echo "\n"; echo "\n"; } } echo "
tijdcategoriedata
" . date("Y-m-d H:i:s", $row['t']) . "Future time
" . date("Y-m-d H:i:s", $row['t']) . "Time discontinuum
" . date("Y-m-d H:i:s", $row['t']) . "" . $_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']; echo "" . $_LOGTABLES['log_zkl'][$row['major']]['category'] . "" . $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['type'] . "\n"; echo ""; for( $i = 1; $i < $m; $i++ ) { $val = $subrow[$i]; $sep = ""; echo "\n"; } echo "\n"; $nr_lines++; if( isset($_GET['debug']) && isset($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['extra']) ) { $sep = ""; echo ""; echo "\n"; echo "\n"; } echo "
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 "
"; if( $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['extra']['text'] ) { echo $sep . $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['extra']['text']; $sep = "
\n"; } if( $_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['extra']['eval'] ) { echo $sep; eval($_LOGTABLES['log_zkl'][$row['major']][$row['minor']]['extra']['eval']); } echo "
\n"; } else echo "
\n"; } echo "

"; echo $info['idcode'] . "/" . $info['serienr'] . "/" . $info['id'] . "\n–\n"; echo date("Y-m-d H:i:s") . "\n"; if( $_GET['use_tz'] ) echo date("T") . "\n"; echo "–\n"; echo $_GET['db'] . "\n"; echo "–\n"; echo $nr_lines . " regels\n–\n"; echo "selecteer:\n"; echo "device\n"; echo "logfile\n"; echo "ga naar:\n"; echo "begin\n"; echo "
\n"; } echo "\n"; echo "\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 "
" . $query . "
\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 "
" . $query . "
\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 "
" . $subquery . "
\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); ?>