diff options
author | Anton Šijanec <sijanecantonluka@gmail.com> | 2019-06-01 17:52:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-01 17:52:38 +0200 |
commit | 328de18b9cc149a84feb09b0f95eef6d9c3a2dee (patch) | |
tree | d1dae93e5f9441e888a7e64a23fed1a960fbef75 | |
parent | updated readme (diff) | |
download | server-status-logger-328de18b9cc149a84feb09b0f95eef6d9c3a2dee.tar server-status-logger-328de18b9cc149a84feb09b0f95eef6d9c3a2dee.tar.gz server-status-logger-328de18b9cc149a84feb09b0f95eef6d9c3a2dee.tar.bz2 server-status-logger-328de18b9cc149a84feb09b0f95eef6d9c3a2dee.tar.lz server-status-logger-328de18b9cc149a84feb09b0f95eef6d9c3a2dee.tar.xz server-status-logger-328de18b9cc149a84feb09b0f95eef6d9c3a2dee.tar.zst server-status-logger-328de18b9cc149a84feb09b0f95eef6d9c3a2dee.zip |
Diffstat (limited to '')
-rw-r--r-- | server-status-logger.php | 61 |
1 files changed, 14 insertions, 47 deletions
diff --git a/server-status-logger.php b/server-status-logger.php index 3663f3c..74c97f1 100644 --- a/server-status-logger.php +++ b/server-status-logger.php @@ -1,8 +1,9 @@ #!/usr/bin/env php -#file updated from http://razor.arnes.si/~asija3/files/server-status-logger.php at 29. may 2019 at 22:14 +#file updated from http://razor.arnes.si/~asija3/files/server-status-logger.php at 1. June 2019 at 17:53 +#!/usr/bin/env php <?php if(empty($argv[1])) { - exit("server-status-logger.php v0.1 2019 Anton Ĺ ijanec astiril/server-status-logger\n + exit("server-status-logger.php v0.1 2019 Anton Šijanec astiril/server-status-logger\n $argv[0] server-status-url [dbfile]\n"); } if(empty($argv[2])) { @@ -74,74 +75,40 @@ function tablefromhtml($urltoget) { "request" TEXT )'); - // var_dump($table); // debug - // exit(); // debug $countTable = $dbConnect->querySingle("SELECT COUNT(*) as count FROM ".$tablename.""); $countTable = true; -while($countTable) { // while true basically +while($countTable) { // if table is ok while true basically echo "r"; $table = tablefromhtml($url); - // var_dump($table); // debug end($table); $lastkey = key($table); for($i=1;$i <= $lastkey;$i++) { - // echo $table[$i]["Client"] . " "; $unique = false; $smt = $dbConnect->prepare("SELECT `client`, `request` FROM ".$tablename." WHERE `worker` = :worker ORDER BY `timestamp` DESC LIMIT 1"); $smt->bindValue(':worker', explode('-', $table[$i]["Srv"]), SQLITE3_TEXT)[0]; - @$query = $smt->execute(); // string>array notice ?!?!?!!?!? + @$query = $smt->execute(); // string>array notice $row = $query->fetchArray(SQLITE3_ASSOC); - // var_dump($row); // debug if(!is_array($row) || empty(array_diff($row, array($table[$i]["Client"], $table[$i]["Request"])))) { $unique = true; } - if($table[$i]["Client"] != "::1" && $unique) { // ::1 because localhost is always querying for some reason via IPv6 + if($table[$i]["Client"] != "::1" && $unique) { // ::1 because localhost is always querying for some reason via IPv6 on my target server $smt = $dbConnect->prepare("INSERT INTO ".$tablename." (timestamp, worker, client, vhost, request) VALUES ( :timestamp, :worker, :client, :vhost, :request )"); $smt->bindValue(':timestamp', date("U"), SQLITE3_TEXT); $smt->bindValue(':worker', explode('-', $table[$i]["Srv"])[0], SQLITE3_TEXT); $smt->bindValue(':client', $table[$i]["Client"], SQLITE3_TEXT); $smt->bindValue(':vhost', $table[$i]["VHost"], SQLITE3_TEXT); $smt->bindValue(':request', $table[$i]["Request"], SQLITE3_TEXT); - $query = $smt->execute(); - if($query) { - echo "."; - } else { - echo "x"; + $query = false; + while(!$query) { + $query = @$smt->execute(); + if($query) { + echo "."; + } else { + echo "x"; + } } } } } - -// echo build_table($table); // debug -// header("Content-type: text/plain"); // debug -// var_dump($table); // debug - - - -function build_table($array){ - // start table - $html = '<table>'; - // header row - $html .= '<tr>'; - foreach($array[0] as $key=>$value){ - $html .= '<th>' . htmlspecialchars($key) . '</th>'; - } - $html .= '</tr>'; - - // data rows - foreach( $array as $key=>$value){ - $html .= '<tr>'; - foreach($value as $key2=>$value2){ - $html .= '<td>' . htmlspecialchars($value2) . '</td>'; - } - $html .= '</tr>'; - } - - // finish table and return it - - $html .= '</table>'; - return $html; -} - ?> |