testing for Chris
[soho-sigint.git] / server / sohoinput.php
diff --git a/server/sohoinput.php b/server/sohoinput.php
new file mode 100644 (file)
index 0000000..d36df57
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+include("includes.php");
+
+$myFile = "testFile.txt";
+$fh = fopen($myFile, 'w') or die("can't open file");
+
+$inputJSON = file_get_contents('php://input');
+$input= json_decode( $inputJSON, TRUE ); //convert JSON into array
+
+#fwrite($fh, var_export($input, true));
+
+#foreach ($input as $index => $element) {
+  #fwrite($fh, "Param: $index; Value: $element\n");
+  #foreach ($element as $item => $value) {
+    #fwrite($fh, "Param: $item; Value: $value\n");
+    #if ($item == "type" ) {
+      #fwrite($fh, "$value\n");
+    #}
+  #}
+#}
+
+for($i=0; $i<sizeof($input); $i++) {
+  #fwrite($fh, $input[$i][type]."\n");
+  switch ($input[$i][type]) {
+    case 80:
+      #fwrite($fh, "ssid: ".$input[$i][ssid]."\n");
+      $query=open_database("localhost","kismet","asdfqwerty","wireless","select LASTSEEN from beacon where SSID='".$input[$i][ssid]."' and BSSID='".$input[$i][bssid]."'");
+      #write($fh, "select LASTSEEN from beacon where SSID='".$input[$i][ssid]."' and BSSID='".$input[$i][bssid]."'");
+      if (mysql_numrows($query) > 0) {
+        open_database("localhost","kismet","asdfqwerty","wireless","update beacon set CHANNEL='".$input[$i][channel]."', RSSI='".$input[$i][rssi]."', LASTSEEN=UNIX_TIMESTAMP(NOW()) where SSID='".$input[$i][ssid]."' and BSSID='".$input[$i][bssid]."'");
+      } else {
+        open_database("localhost","kismet","asdfqwerty","wireless","insert into beacon set SSID='".$input[$i][ssid]."', BSSID='".$input[$i][bssid]."', LASTSEEN=UNIX_TIMESTAMP(NOW()), CHANNEL='".$input[$i][channel]."', RSSI='".$input[$i][rssi]."'");
+      }
+      break;
+
+    case 50:
+      $query=open_database("localhost","kismet","asdfqwerty","wireless","select LASTSEEN from probe where BSSID='".$input[$i][bssid_mac]."' and MAC='".$input[$i][client_mac]."'");
+      if (mysql_numrows($query) > 0) {
+        open_database("localhost","kismet","asdfqwerty","wireless","update probe set CHANNEL='".$input[$i][channel]."', RSSI='".$input[$i][rssi]."', LASTSEEN=UNIX_TIMESTAMP(NOW()) where BSSID='".$input[$i][bssid_mac]."' and MAC='".$input[$i][client_mac]."'");
+      } else {
+        open_database("localhost","kismet","asdfqwerty","wireless","insert into probe set BSSID='".$input[$i][bssid_mac]."', MAC='".$input[$i][client_mac]."', LASTSEEN=UNIX_TIMESTAMP(NOW()), CHANNEL='".$input[$i][channel]."', RSSI='".$input[$i][rssi]."'");
+      }
+      break;
+
+    case 40:
+      $query=open_database("localhost","kismet","asdfqwerty","wireless","select LASTSEEN from probe where BSSID='".$input[$i][bssid_mac]."' and MAC='".$input[$i][client_mac]."'");
+      if (mysql_numrows($query) > 0) {
+        open_database("localhost","kismet","asdfqwerty","wireless","update probe set CHANNEL='".$input[$i][channel]."', RSSI='".$input[$i][rssi]."', LASTSEEN=UNIX_TIMESTAMP(NOW()) where BSSID='".$input[$i][bssid_mac]."' and MAC='".$input[$i][client_mac]."'");
+      } else {
+        open_database("localhost","kismet","asdfqwerty","wireless","insert into probe set BSSID='".$input[$i][bssid_mac]."', MAC='".$input[$i][client_mac]."', LASTSEEN=UNIX_TIMESTAMP(NOW()), CHANNEL='".$input[$i][channel]."', RSSI='".$input[$i][rssi]."'");
+      }
+
+      break;
+  }
+}
+
+fclose($fh);
+?>