Browse Source

server-side php sync implementation added

Mihai Plasoianu 10 years ago
parent
commit
5a164df2ac
2 changed files with 47 additions and 0 deletions
  1. 20 0
      phpsync/pull.php
  2. 27 0
      phpsync/push.php

+ 20 - 0
phpsync/pull.php

@@ -0,0 +1,20 @@
+<?php
+$bssid = $_POST ["bssid"];
+$timestamp = $_POST ["timestamp"];
+
+$username = "hostage";
+$password = "hostageDB";
+$hostname = "localhost";
+
+$dbhandle = mysql_connect ( $hostname, $username, $password ) or die ( "Unable to connect to MySQL" );
+
+$result = mysql_query ( "SELECT * FROM `hostage`.`sync` WHERE `bssid` = " . $bssid . " AND `timestamp` > " . $timestamp );
+
+if (! $result) {
+	die ( 'Could not select record: ' . mysql_error () );
+}
+
+while ( $row = mysql_fetch_array ( $result ) ) {
+	echo json_encode ( $row );
+}
+?>

+ 27 - 0
phpsync/push.php

@@ -0,0 +1,27 @@
+<?php
+$json = json_decode ( $_POST ["record"], true );
+
+$values = array ();
+$i = 0;
+$line = "(";
+foreach ( $json as $key => $value ) {
+	$line = $line . "'" . $value . "',";
+}
+$line = substr ( $line, 0, strlen ( $line ) - 1 ) . ")";
+$values [$i] = $line;
+++ $i;
+
+$values = implode ( ",", $values );
+
+$username = "hostage";
+$password = "hostageDB";
+$hostname = "localhost";
+
+$dbhandle = mysql_connect ( $hostname, $username, $password ) or die ( "Unable to connect to MySQL" );
+
+$result = mysql_query ( "INSERT INTO `hostage`.`sync` (`bssid`, `ssid`, `longitude`, `latitude`, `timestamp`, `attacks`, `portscans`) VALUES " . $values );
+
+if (! $result) {
+	die ( 'Could not insert record: ' . mysql_error () );
+}
+?>