removed debug code i forgot existed
[soho-sigint.git] / server / sohoinput.php
1 <?php
2 include("includes.php");
3
4 $myFile = "testFile.txt";
5 $fh = fopen($myFile, 'w') or die("can't open file");
6
7 $inputJSON = file_get_contents('php://input');
8 $input= json_decode( $inputJSON, TRUE ); //convert JSON into array
9
10 #fwrite($fh, var_export($input, true));
11
12 #foreach ($input as $index => $element) {
13   #fwrite($fh, "Param: $index; Value: $element\n");
14   #foreach ($element as $item => $value) {
15     #fwrite($fh, "Param: $item; Value: $value\n");
16     #if ($item == "type" ) {
17       #fwrite($fh, "$value\n");
18     #}
19   #}
20 #}
21
22 for($i=0; $i<sizeof($input); $i++) {
23   #fwrite($fh, $input[$i][type]."\n");
24   switch ($input[$i][type]) {
25     case 80:
26       #fwrite($fh, "ssid: ".$input[$i][ssid]."\n");
27       $query=open_database("localhost","kismet","asdfqwerty","wireless","select LASTSEEN from beacon where SSID='".$input[$i][ssid]."' and BSSID='".$input[$i][bssid]."'");
28       #write($fh, "select LASTSEEN from beacon where SSID='".$input[$i][ssid]."' and BSSID='".$input[$i][bssid]."'");
29       if (mysql_numrows($query) > 0) {
30         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]."'");
31       } else {
32         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]."'");
33       }
34       break;
35
36     case 50:
37       $query=open_database("localhost","kismet","asdfqwerty","wireless","select LASTSEEN from probe where BSSID='".$input[$i][bssid_mac]."' and MAC='".$input[$i][client_mac]."'");
38       if (mysql_numrows($query) > 0) {
39         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]."'");
40       } else {
41         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]."'");
42       }
43       break;
44
45     case 40:
46       $query=open_database("localhost","kismet","asdfqwerty","wireless","select LASTSEEN from probe where BSSID='".$input[$i][bssid_mac]."' and MAC='".$input[$i][client_mac]."'");
47       if (mysql_numrows($query) > 0) {
48         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]."'");
49       } else {
50         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]."'");
51       }
52
53       break;
54   }
55 }
56
57 fclose($fh);
58 ?>