Merge branch 'master' of estia:weathermon
[weathermon.git] / web / send.php
diff --git a/web/send.php b/web/send.php
new file mode 100644 (file)
index 0000000..7a69838
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+    require_once 'config_local.php';
+
+    $client_ip = ip2long($_SERVER["REMOTE_ADDR"]);
+
+    if (!client_ip || $client_ip > $valid_ip_end || $valid_ip_start > $client_ip) {
+      header('HTTP/1.1 403 Forbidden');
+      echo "IP not in allowed range";
+      exit;
+    }
+
+    $stype = $_REQUEST['stype'];
+    $sid   = $_REQUEST['sid'];
+    $param = $_REQUEST['param'];
+    $value = $_REQUEST['value'];
+
+    $connection = new mysqli($mysql_host, $mysql_user, $mysql_pwd, $mysql_schema, $mysql_port);
+    if ($connection->connect_errno) {
+        header('HTTP/1.1 500 Internal Server Error');
+        exit;    
+    }
+        
+    $str = "CALL meteo.submit_value('".$stype."','".$sid."','".$param."',".$value.",NULL)";
+        if (!$connection->query($str)) {
+            header('HTTP/1.1 500 Internal Server Error');
+            exit;    
+        } else {
+            $connection->commit();
+?>        
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+  <title>Meteo logger</title>
+</head>
+<body>
+OK Logged
+</body>
+</html>
+<?
+    }
+
+?>