locationreport.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. include("../functions.php");
  3. $con = startdb('rw');
  4. //Get fields
  5. $user = mysqli_real_escape_string($con, $_GET['user']);
  6. $code = mysqli_real_escape_string($con, $_GET['code']);
  7. $lat = mysqli_real_escape_string($con, $_GET['lat']);
  8. $lon = mysqli_real_escape_string($con, $_GET['lon']);
  9. $action = mysqli_real_escape_string($con, $_GET['action']);
  10. $manual = mysqli_real_escape_string($con, $_GET['manual']);
  11. //Validate code
  12. $q = mysqli_query($con, "SELECT id FROM user WHERE id = $user AND md5(concat(password, md5(salt))) = '$code';");
  13. //echo "SELECT id FROM user WHERE id = $user AND md5(concat(password, md5(salt))) = '$code'";
  14. if (mysqli_num_rows($q) == 0){
  15. echo("Reporting location with wrong credentials (IP $_SERVER[REMOTE_ADDR])");
  16. error_log("Reporting location with wrong credentials (IP $_SERVER[REMOTE_ADDR])");
  17. echo("<status>0</status>\n");
  18. exit(-1);
  19. }
  20. //If its an automatic update, and the last singal from the user was to stop, stop it
  21. // if ($manual == 1){
  22. // $q = mysqli_query($con, "SELECT action FROM location WHERE user = $user AND (action = 'start' OR action = 'stop') ORDER BY dtime DESC LIMIT 1");
  23. // if (mysqli_num_rows($q) == 0){
  24. // echo("<status>0</status>\n");
  25. // exit(0);
  26. // }
  27. // else{
  28. // $r = mysqli_fetch_array($q);
  29. // if ($r['action'] == 'stop'){
  30. // echo("<status>0</status>\n");
  31. // exit(0);
  32. // }
  33. // }
  34. // }
  35. //Validate fields
  36. if (is_numeric($lat) == false || is_numeric($lon) == false){
  37. error_log("Reporting location: invalid coordinates (IP $_SERVER[REMOTE_ADDR])");
  38. echo("<status>0</status>\n");
  39. exit(-1);
  40. }
  41. if ($action != "start" && $action != "stop" && $action != "report"){
  42. error_log("Reporting location: invalid action '$action' (IP $_SERVER[REMOTE_ADDR])");
  43. echo("<status>0</status>\n");
  44. exit(-1);
  45. }
  46. if ($manual != 0 && $manual != 1){
  47. error_log("Reporting location: invalid value for manual '$manual' (IP $_SERVER[REMOTE_ADDR])");
  48. echo("<status>0</status>\n");
  49. exit(-1);
  50. }
  51. //Insert
  52. mysqli_query($con, "INSERT INTO location (lat, lon, manual, action, user) VALUES ($lat, $lon, $manual, '$action', $user);");
  53. echo("<status>1</status>\n");
  54. ?>