From: Roman Bazalevsky <rvb@rvb.name>
Date: Tue, 19 May 2015 14:00:09 +0000 (+0300)
Subject: Web updated
X-Git-Url: https://git.rvb.name/weathermon.git/commitdiff_plain/6f6f38ad845e089ef732873cfcf8e321d8cc1e38?hp=42bd3e809b0fa95d3a463462e242caf40d98bf79

Web updated
---

diff --git a/web/archive.php b/web/archive.php
index c403863..1b21599 100644
--- a/web/archive.php
+++ b/web/archive.php
@@ -23,7 +23,7 @@
     }                                          
     a:visited { text-decoration: none; color:darkblue; }
     a:link { text-decoration: none; color:blue; }
-    a:hover { text-decoration: none; color:navy; }  
+    a:hover { text-decoration: underline; color:navy; }  
   </style>
 </head>
 <body text="black" bgcolor="silver" link="blue" vlink="#000080" alink="#FF0000">         
@@ -33,6 +33,21 @@ include('config_local.php');
 include('calendar.php');
 include('units.php');
 
+  $client_ip = $_SERVER["REMOTE_ADDR"];
+
+  if ((strpos($client_ip, "192.168.") === 0) || (strpos($client_ip, "10.8.") === 0)
+     || (strpos($client_ip, "2a02:578:5002:8174:") === 0)
+     || (strpos($client_ip, "2a02:578:5002:196::2") === 0)) {
+
+    $local_net = True;
+
+  } else {
+
+    $local_net = False;
+
+  }
+
+
 $year = $_REQUEST['year']; 
 $month = $_REQUEST['month'];
 $day = $_REQUEST['day'];
@@ -58,7 +73,7 @@ if (! $year) {
 <?php
   while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 ?> 
-  <a class="year" href="?year=<?php echo $row['year']; ?>">Данные за <?php echo $row['year']; ?> год</a><br>
+  <a class="year" href="?year=<?php echo $row['year']; ?>">Данные за <?php echo $row['year']; ?> год</a>
 <?php
   }
       
@@ -114,6 +129,18 @@ if (! $year) {
     
     $next_year = $year+1;
 
+    if (!$local_net) {
+
+      $filter = ' and s.is_public=1';
+  
+    } else {
+  
+      $filter = '';
+    
+    }  
+    
+    
+
     $q = $db -> prepare (
       'select 
          s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name,
@@ -128,7 +155,7 @@ if (! $year) {
          v.parameter=p.id and
          p.st_unit=u.id and
          v.day>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and 
-         v.day<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\')
+         v.day<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\''.$filter.')
       group by s.id,p.id,s.s_description,p.st_description
       order by s.id,p.id'
       );
@@ -181,14 +208,26 @@ if (! $year) {
       $month      = sprintf('%02d',$month);
       $year      = sprintf('%04d',$year);
 
+      if (!$local_net) {
+
+        $filter = ' and s.is_public=1';
+  
+      } else {
+  
+        $filter = '';
+    
+      }  
+    
+
       $q = $db -> prepare( 
           'select  
              date_format(day,\'%d\') as day
            from 
-             sensors_ranges
+             sensors_ranges r,sensors s 
            where 
+             s.id=r.sensor and
              day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and 
-             day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')
+             day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')'.$filter.'
            group by day
            order by day'
           );
@@ -206,6 +245,17 @@ if (! $year) {
       }
 
       calendar($year,$month,$days,'?year='.$year.'&month='.$month.'&day=%s',3);
+             
+      if (!$local_net) {
+      
+        $filter = ' and s.is_public=1';
+                
+      } else {
+                        
+        $filter = '';
+                                    
+      }
+                                                       
               
       $q = $db -> prepare (
           'select 
@@ -221,7 +271,7 @@ if (! $year) {
              v.parameter=p.id and
              p.st_unit=u.id and
              v.day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and 
-             v.day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')
+             v.day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')'.$filter.'
            group by s.id,p.id,s.s_description,p.st_description
            order by s.id,p.id'
         );
@@ -262,6 +312,17 @@ if (! $year) {
       $year      = sprintf('%04d',$year);
       $day       = sprintf('%02d',$day);
 
+      if (!$local_net) {
+
+        $filter = ' and s.is_public=1';
+  
+      } else {
+  
+        $filter = '';
+    
+      }
+
+
       $q = $db -> prepare(
   	    'select 
     		distinct v.sensor as sensor_id,s.s_description,p.id as param_id,p.st_description 
@@ -270,7 +331,7 @@ if (! $year) {
   	     where 
                 v.day=str_to_date(\''.$year.'-'.$month.'-'.$day.'\',\'%Y-%m-%d\')
                 and v.sensor=s.id 
-                and v.parameter=p.id'
+                and v.parameter=p.id'.$filter
             );
       $q -> execute();
 
diff --git a/web/config_local.php b/web/config_local.php
index 00afede..9ec56a8 100644
--- a/web/config_local.php
+++ b/web/config_local.php
@@ -1,14 +1,14 @@
 <?php
 
-  $mysql_host = 'host';
+  $mysql_host = 'rvb.name';
   $mysql_schema = 'meteo';
   $mysql_user = 'meteo';
-  $mysql_pwd = 'somestrictpasswd';
+  $mysql_pwd = 'somestrongpasswd';
   $mysql_port = 3306;
 
   setlocale(LC_ALL,'ru_RU.UTF8');
 
-  $valid_ip_start = ip2long('192.168.1.161');
-  $valid_ip_end   = ip2long('192.168.1.190');
+  $valid_ip_start = ip2long('192.168.1.0');
+  $valid_ip_end   = ip2long('192.168.1.255');
                 
 ?>
\ No newline at end of file
diff --git a/web/graphs.php b/web/graphs.php
index dfc7450..850d9d7 100644
--- a/web/graphs.php
+++ b/web/graphs.php
@@ -8,7 +8,7 @@
   <style type="text/css">
      a:visited { text-decoration: none; color:darkblue; }
      a:link { text-decoration: none; color:blue; }
-     a:hover { text-decoration: none; color:navy; }
+     a:hover { text-decoration: underline; color:navy; }
   </style>
 </head>
 <body text="black" bgcolor="silver" link="blue" vlink="#000080" alink="#FF0000">         
@@ -16,12 +16,37 @@
 
 include('config_local.php');
 
+$client_ip = $_SERVER["REMOTE_ADDR"];
+  
+if ((strpos($client_ip, "192.168.") === 0) || (strpos($client_ip, "10.8.") === 0)
+   || (strpos($client_ip, "2a02:578:5002:8174:") === 0)
+   || (strpos($client_ip, "2a02:578:5002:196::2") === 0)) {
+              
+   $local_net = True;
+                  
+} else {
+                    
+   $local_net = False;
+               
+}
+                         
+
 if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_schema",$mysql_user,$mysql_pwd,array( PDO::ATTR_PERSISTENT => false)))) {
   die($err);
   }  
 
 $db -> exec('SET CHARACTER SET utf8');
 
+if (!$local_net) {
+
+  $filter = ' and s.is_public=1';
+
+} else {
+
+  $filter = '';
+
+}  
+
 $q = $db -> prepare(
   'select 
     distinct v.sensor_id,s.s_description,p.id as param_id,p.st_description 
@@ -31,7 +56,7 @@ $q = $db -> prepare(
     v.timestamp>adddate(now(), -1) 
     and v.sensor_id=s.id 
     and s.st_id=p.st_id
-    and p.id>=0
+    and p.id>=0'.$filter.'
   order by s_description,st_description'
   );
 $q -> execute();
diff --git a/web/image.php b/web/image.php
index 16fbafb..bf511f2 100644
--- a/web/image.php
+++ b/web/image.php
@@ -200,16 +200,21 @@ if ($type and $param) {
   $g->xaxis->SetPos("min");
 #  $g->xaxis->scale->SetTimeAlign( HOURADJ_1 );
 
-  // We use a scatterplot to illustrate the original
-  // contro points.
-  $splot = new ScatterPlot($ydata,$xdata);
-  $g->Add($splot);
-
-  // 
-  $splot->mark->SetFillColor($dot_color);
-  $splot->mark->SetColor($dot_color);
-  $splot->mark->SetType(MARK_FILLEDCIRCLE);
-  $splot->mark->SetSize(2);
+
+  if ($type!="last24small") {
+
+    // We use a scatterplot to illustrate the original
+    // contro points.
+    $splot = new ScatterPlot($ydata,$xdata);
+    $g->Add($splot);
+
+    // 
+    $splot->mark->SetFillColor($dot_color);
+    $splot->mark->SetColor($dot_color);
+    $splot->mark->SetType(MARK_FILLEDCIRCLE);
+    $splot->mark->SetSize(2);
+
+  }
 
   $fplot = new LinePlot($f_ydata,$xdata);
   $g->Add($fplot);
diff --git a/web/image_minmax.php b/web/image_minmax.php
index dfa66d2..183942b 100644
--- a/web/image_minmax.php
+++ b/web/image_minmax.php
@@ -84,16 +84,17 @@ if ($type and $param) {
     $next_year = $year;
     $next_month = $month+1;
 
-    if ($month==13) {
+    if ($month==12) {
     
       $next_year++;
       $next_month=1;
-    
+
     }
 
     $curr = date("Ym");
+    $ym=sprintf('%04d%02d',$next_year,$next_month);
     
-    if ($curr>$next_year.$next_month) {
+    if ($curr>$ym) {
     
       $cachefilename='meteo.month.'.$sensor.'.'.$param.'.'.$to_unit.'.'.$year.'-'.$month.'.'.$img_format;
     
diff --git a/web/index.php b/web/index.php
index 37251e6..92a8e8e 100644
--- a/web/index.php
+++ b/web/index.php
@@ -9,7 +9,7 @@
   <style type="text/css">
      a:visited { text-decoration: none; color:darkblue; }
      a:link { text-decoration: none; color:blue; }
-     a:hover { text-decoration: none; color:navy; }
+     a:hover { text-decoration: underline; color:navy; }
      .header { font-size: 16; float: left; margin: 10px;}
      .timestamp { font-size: 16; margin: 10px;}
      .value { font-size: 60; margin: 10px; }
@@ -22,6 +22,20 @@
 <div class="container">
 <?php
 
+  $client_ip = $_SERVER["REMOTE_ADDR"];
+
+  if ((strpos($client_ip, "192.168.") === 0) || (strpos($client_ip, "10.8.") === 0)
+     || (strpos($client_ip, "2a02:578:5002:8174:") === 0)
+     || (strpos($client_ip, "2a02:578:5002:196::2") === 0)) {
+   
+    $local_net = True;
+            
+  } else {
+  
+    $local_net = False;
+  
+  }
+
 include('config_local.php');
 include('units.php');
 
@@ -31,6 +45,16 @@ if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_sche
 
 $db -> exec('SET CHARACTER SET utf8');
 
+if (!$local_net) {
+
+  $filter = ' and s.is_public=1'; 
+
+} else {
+
+  $filter = '';
+
+}
+
 $q = $db -> prepare(
   'select 
     distinct v.sensor_id,s.s_description,p.id as param_id,p.st_description 
@@ -38,9 +62,10 @@ $q = $db -> prepare(
     sensor_values v,st_parameters p,sensors s 
   where 
     v.timestamp>adddate(now(), -1) 
-    and v.sensor_id=s.id 
+    and v.sensor_id=s.id
+    and v.parameter_id=p.id  
     and s.st_id=p.st_id
-    and p.id>=0
+    and p.id>=0'.$filter.'
   order by s_description,st_description'
   );
 $q -> execute();
@@ -65,7 +90,7 @@ $ql =  $db -> prepare(
 $ql -> execute();
 
 $printable_ts = "?";
-$value = "?";
+$val = "?";
 
 if ($rowl = $ql -> fetch(PDO::FETCH_ASSOC)) {
 
@@ -77,15 +102,17 @@ if ($rowl = $ql -> fetch(PDO::FETCH_ASSOC)) {
   $from_unit = $units['from'];
   $to_unit = $units['to'];
   $param_unit = $units['name'];
-                        
+
   $val = convert_unit($db,$value,$from_unit,$to_unit);
                               
 }
                                   
-echo '<div class="timestamp">'.$printable_ts.'</div>';
-echo '<div class="value">'.$val.' '.$param_unit.'</div>';
+if ($printable_ts != '?') { 
+  echo '<div class="timestamp">'.$printable_ts.'</div>';
+  echo '<div class="value">'.$val.' '.$param_unit.'</div>';
+}
 ?>
-<div class="graph"><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24small"></div>
+<div class="graph"><a href="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24"><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24small"></a></div>
 <?php  
 
 echo "</div>";
diff --git a/web/send.php b/web/send.php
index 7a69838..60d21db 100644
--- a/web/send.php
+++ b/web/send.php
@@ -21,22 +21,11 @@
     }
         
     $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>
-<?
+    if (!$connection->query($str)) {
+        header('HTTP/1.1 500 Internal Server Error');
+        exit;    
+    } else {
+        $connection->commit();
+        echo "OK Logged";    
     }
 
-?>