60d21dbbc704bfedb1c8826a2b3c74ad0a779f7b
[weathermon.git] / web / send.php
1 <?php
2     require_once 'config_local.php';
3
4     $client_ip = ip2long($_SERVER["REMOTE_ADDR"]);
5
6     if (!client_ip || $client_ip > $valid_ip_end || $valid_ip_start > $client_ip) {
7       header('HTTP/1.1 403 Forbidden');
8       echo "IP not in allowed range";
9       exit;
10     }
11
12     $stype = $_REQUEST['stype'];
13     $sid   = $_REQUEST['sid'];
14     $param = $_REQUEST['param'];
15     $value = $_REQUEST['value'];
16
17     $connection = new mysqli($mysql_host, $mysql_user, $mysql_pwd, $mysql_schema, $mysql_port);
18     if ($connection->connect_errno) {
19         header('HTTP/1.1 500 Internal Server Error');
20         exit;    
21     }
22         
23     $str = "CALL meteo.submit_value('".$stype."','".$sid."','".$param."',".$value.",NULL)";
24     if (!$connection->query($str)) {
25         header('HTTP/1.1 500 Internal Server Error');
26         exit;    
27     } else {
28         $connection->commit();
29         echo "OK Logged";    
30     }
31