From c0ed48b35980c0c73995886161d76654437f5e6e Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Mon, 30 Sep 2013 17:34:27 +0200 Subject: [PATCH] Various improvements and fixes --- .gitignore | 2 ++ .htaccess | 4 ++++ connect.php | 4 ++-- create_table.php | 30 +++++++++++++++++++----------- js/main.js | 23 ++++++++++++++++++++--- list.php | 7 ++++++- 6 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 .gitignore create mode 100644 .htaccess diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e923db --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +credentials.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..7709fd6 --- /dev/null +++ b/.htaccess @@ -0,0 +1,4 @@ +# don't supress php errors +php_flag display_startup_errors on +php_flag display_errors on +php_flag html_errors on diff --git a/connect.php b/connect.php index b89e504..242ccc9 100644 --- a/connect.php +++ b/connect.php @@ -1,9 +1,9 @@ prepare("CREATE TABLE IF NOT EXISTS $table (" . - "`id` varchar(151) NOT NULL," . - "`remoteip` varchar(15) NOT NULL," . - "`localip` varchar(15) NOT NULL," . - "`wifiboxid` varchar(140) NOT NULL," . - "`hidden` tinyint(1) NOT NULL DEFAULT '0'," . - "`date` datetime NOT NULL," . - "PRIMARY KEY (`id`)" . - ") ENGINE=InnoDB DEFAULT CHARSET=latin1;"); - $createsql->execute(); + try { + // exported structure using phpMyAdmin + $createsql = $db->prepare("CREATE TABLE IF NOT EXISTS $table (" . + "`id` varchar(151) NOT NULL," . + "`remoteip` varchar(15) NOT NULL," . + "`localip` varchar(15) NOT NULL," . + "`wifiboxid` varchar(140) NOT NULL," . + "`hidden` tinyint(1) NOT NULL DEFAULT '0'," . + "`date` datetime NOT NULL," . + "PRIMARY KEY (`id`)" . + ") ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + + if($createsql->execute() == TRUE) + echo "$table created"; + } catch (PDOException $e) { + $response = array( "status" => "error", + "msg" => $e->getMessage()." (".$e->getCode().")"); + exit(json_encode($response)."\r\n"); + } ?> diff --git a/js/main.js b/js/main.js index 204e869..9517def 100644 --- a/js/main.js +++ b/js/main.js @@ -1,5 +1,6 @@ var retrieveListDelay; // retry setTimout instance var retrieveListInterval = 5000; +var boxTimeoutTime = 300; var $list; $(function() { @@ -10,8 +11,9 @@ $(function() { }) function retrieveList() { $.ajax({ - url: "/list.php", + url: "list.php", dataType: 'json', + timeout: boxTimeoutTime, success: function(response){ //console.log("retrieveList response: ",response); if(response.status == "success") { @@ -27,9 +29,24 @@ function retrieveList() { }); } function updateList(boxes) { - //console.log("list: ",boxes); $list.empty(); jQuery.each(boxes, function (index,box) { - $list.append("
  • "+box.wifiboxid+"
  • "); + checkBox(box); }); +} +function checkBox(box) { + $.ajax({ + url: "http://"+box.localip+"/d3dapi/network/status", + dataType: 'json', + success: function(response){ + if(response.status == "success") { + var url = "http://"+box.localip; + if(boxIsListed(url)) return; + $list.append("
  • "+box.wifiboxid+"
  • "); + } + } + }); +} +function boxIsListed(url){ + return $list.find("a[href|='"+url+"']").length > 0; } \ No newline at end of file diff --git a/list.php b/list.php index f6dfe5e..a5f7ef3 100644 --- a/list.php +++ b/list.php @@ -15,7 +15,12 @@ exit(json_encode($response)."\r\n"); } + $debug = array( "time" => time(), + "hourago" => $hourago, + "remoteip" => $remoteip); + $response = array( "status" => "success", - "data" => $boxes); + "data" => $boxes, + "debug" => $debug); exit(json_encode($response)."\r\n"); ?> \ No newline at end of file