diff --git a/html/billing-graph.php b/html/billing-graph.php index e290dfd3ce..ded5fb3cf4 100755 --- a/html/billing-graph.php +++ b/html/billing-graph.php @@ -1,13 +1,22 @@ = ? AND `timestamp` <= ?", array($bill_id, $datefrom, $dateto)); @@ -150,6 +163,9 @@ foreach (dbFetch("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bil #print_r($ticks); #print_r($tot_data); +#echo("
");
+#print_r($in_data);
+
 $graph_name = date('M j g:ia', $start) . " - " . date('M j g:ia', $last);
 
 $n = count($ticks);
diff --git a/html/data.php b/html/data.php
new file mode 100644
index 0000000000..8f333299ea
--- /dev/null
+++ b/html/data.php
@@ -0,0 +1,38 @@
+
diff --git a/html/graph-realtime.php b/html/graph-realtime.php
new file mode 100755
index 0000000000..66883a881d
--- /dev/null
+++ b/html/graph-realtime.php
@@ -0,0 +1,354 @@
+, Manuel Kasper 
+	and Jonathan Watt .
+	All rights reserved.
+	
+	Redistribution and use in source and binary forms, with or without
+	modification, are permitted provided that the following conditions are met:
+	
+	1. Redistributions of source code must retain the above copyright notice,
+	   this list of conditions and the following disclaimer.
+	
+	2. Redistributions in binary form must reproduce the above copyright
+	   notice, this list of conditions and the following disclaimer in the
+	   documentation and/or other materials provided with the distribution.
+	
+	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+	POSSIBILITY OF SUCH DAMAGE.
+*/
+
+header("Content-type: image/svg+xml");
+
+/********** HTTP GET Based Conf ***********/
+$ifnum=@$_GET["ifnum"];  // BSD / SNMP interface name / number
+$ifname=@$_GET["ifname"]?$_GET["ifname"]:"Interface $ifnum";  //Interface name that will be showed on top right of graph
+
+/********* Other conf *******/
+$scale_type="follow";               //Autoscale default setup : "up" = only increase scale; "follow" = increase and decrease scale according to current graphed datas
+$nb_plot=240;                   //NB plot in graph
+if(is_numeric($_GET['interval'])) {
+ $time_interval=$_GET['interval'];
+} else {
+ $time_interval=1;		//Refresh time Interval
+}
+$fetch_link = "data.php?id=".$_GET[id];
+
+//SVG attributes
+$attribs['axis']='fill="black" stroke="black"';
+$attribs['in']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="7"';
+$attribs['out']='fill="#8092B3" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="7"';
+$attribs['graph_in']='fill="none" stroke="green" stroke-opacity="0.8"';
+$attribs['graph_out']='fill="none" stroke="blue" stroke-opacity="0.8"';
+$attribs['legend']='fill="black" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4"';
+$attribs['graphname']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="8"';
+$attribs['grid_txt']='fill="gray" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="6"';
+$attribs['grid']='stroke="gray" stroke-opacity="0.5"';
+$attribs['switch_unit']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4" text-decoration="underline"';
+$attribs['switch_scale']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4" text-decoration="underline"';
+$attribs['error']='fill="blue" font-family="Arial" font-size="4"';
+$attribs['collect_initial']='fill="gray" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4"';
+
+//Error text if we cannot fetch data : depends on which method is used
+$error_text = "Cannot get data about interface $ifnum";
+
+$height=100;            //SVG internal height : do not modify
+$width=200;             //SVG internal width : do not modify
+
+/********* Graph DATA **************/
+print('' . "\n");?>
+
+  
+    
+    />
+    />
+    />
+    />
+    />
+     text-anchor="end"> 
+     text-anchor="end"> 
+     text-anchor="end"> 
+    >In
+    >Out
+    > 
+    > 
+     text-anchor="end">
+    >Switch to bytes/s
+    >AutoScale ()
+    > 
+    >Graph shows last  seconds
+     points="  "/>
+     text-anchor="middle">
+     text-anchor="middle">Collecting initial data, please wait...
+  
+  
+
diff --git a/html/pages/bill.inc.php b/html/pages/bill.inc.php
index 2783ec075a..d27c2b6ceb 100644
--- a/html/pages/bill.inc.php
+++ b/html/pages/bill.inc.php
@@ -194,9 +194,11 @@ if (bill_permitted($bill_id))
   $li .= "&width=715&height=200&total=1'>";
 
 
-#  $di =       "";
+  $di =       "";
+
+echo("$di");
 
   $di = "Graphs");
 if ($_GET['optb'] == "graphs" || !$_GET['optb']) { echo(""); }
 
+echo(" | ");
+
+if ($_GET['optb'] == "realtime" || !$_GET['optb']) { echo(""); }
+echo("Real Time");
+if ($_GET['optb'] == "realtime" || !$_GET['optb']) { echo(""); }
+
 
 if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `interface_id` = '".$interface['interface_id']."'") )
 {
diff --git a/includes/functions.php b/includes/functions.php
index 63e6578485..0d9138e16b 100755
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -37,7 +37,6 @@ function only_alphanumeric($string)
 function logfile($string)
 {
   global $config;
-
   $fd = fopen($config['log_file'],'a');
   fputs($fd,$string . "\n");
   fclose($fd);
diff --git a/poll-billing.php b/poll-billing.php
index ba3ae19518..246a5cf33c 100755
--- a/poll-billing.php
+++ b/poll-billing.php
@@ -20,65 +20,53 @@ function CollectData($bill_id)
 {
   foreach (dbFetchRows("SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.interface_id = P.port_id AND D.device_id = I.device_id", array($bill_id)) as $port_data)
   {
-    unset($port_in_measurement);
-    unset($port_in_delta);
-    unset($last_port_in_measurement);
-    unset($last_port_in_delta);
-    unset($port_out_measurement);
-    unset($port_out_delta);
-    unset($last_port_out_measurement);
-    unset($last_port_out_delta);
 
     $port_id = $port_data['port_id'];
     $host    = $port_data['hostname'];
-		$port	 = $port_data['port'];
+    $port    = $port_data['port'];
 
     echo("\nPolling ".$port_data['ifDescr']." on ".$port_data['hostname']."\n");
 
-    $port_in_measurement = getValue($host, $port, $port_data['ifIndex'], "In");
-    $port_out_measurement = getValue($host, $port, $port_data['ifIndex'], "Out");
+    $port_data['in_measurement'] = getValue($host, $port, $port_data['ifIndex'], "In");
+    $port_data['out_measurement'] = getValue($host, $port, $port_data['ifIndex'], "Out");
 
     $now = dbFetchCell("SELECT NOW()");
 
     $last_data = getLastPortCounter($port_id,in);
     if ($last_data[state] == "ok")
     {
-      $last_port_in_measurement = $last_data[counter];
-      $last_port_in_delta = $last_data[delta];
-      if ($port_in_measurement > $last_port_in_measurement)
+      $port_data['last_in_measurement'] = $last_data[counter];
+      $port_data['last_in_delta'] = $last_data[delta];
+      if ($port_data['in_measurement'] > $port_data['last_in_measurement'])
       {
-        $port_in_delta = $port_in_measurement - $last_port_in_measurement;
+        $port_data['in_delta'] = $port_data['in_measurement'] - $port_data['last_in_measurement'];
       } else {
-        $port_in_delta = $last_port_in_delta;
+        $port_data['in_delta'] = $port_data['last_in_delta'];
       }
     } else {
-      $port_in_delta = '0';
+      $port_data['in_delta'] = '0';
     }
-    dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_in_measurement, 'delta' => $port_in_delta), 'port_in_measurements');
-
-    unset($last_data, $last_port_in_measurement, $last_port_in_delta);
+    dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_data['in_measurement'], 'delta' => $port_data['in_delta']), 'port_in_measurements');
 
     $last_data = getLastPortCounter($port_id,out);
     if ($last_data[state] == "ok")
     {
-      $last_port_out_measurement = $last_data[counter];
-      $last_port_out_delta = $last_data[delta];
-      if ($port_out_measurement > $last_port_out_measurement)
+      $port_data['last_out_measurement'] = $last_data[counter];
+      $port_data['last_out_delta'] = $last_data[delta];
+      if ($port_data['out_measurement'] > $port_data['last_out_measurement'])
       {
-        $port_out_delta = $port_out_measurement - $last_port_out_measurement;
+        $port_data['out_delta'] = $port_data['out_measurement'] - $port_data['last_out_measurement'];
       } else {
-        $port_out_delta = $last_port_out_delta;
+        $port_data['out_delta'] = $port_data['last_out_delta'];
       }
     } else {
-      $port_out_delta = '0';
+      $port_data['out_delta'] = '0';
     }
-    dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_out_measurement, 'delta' => $port_out_delta), 'port_out_measurements');
-    unset($last_data, $last_port_in_measurement, $last_port_in_delta);
+    dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_data['out_measurement'], 'delta' => $port_data['out_delta']), 'port_out_measurements');
 
-    $delta = $delta + $port_in_delta + $port_out_delta;
-    $in_delta = $in_delta + $port_in_delta;
-    $out_delta = $out_delta + $port_out_delta;
-    unset($port_in_delta,$port_out_delta,$prev_delta,$prev_timestamp,$period);
+    $delta = $delta + $port_data['in_delta'] + $port_data['out_delta'];
+    $in_delta = $in_delta + $port_data['in_delta'];
+    $out_delta = $out_delta + $port_data['out_delta'];
 
   }
   $last_data = getLastMeasurement($bill_id);
@@ -104,7 +92,12 @@ function CollectData($bill_id)
     $out_delta = $prev_out_delta;
 
   }
-  dbInsert(array('bill_id' => $bill_id, 'timestamp' => $now, 'period' => $period, 'delta' => $delta, 'in_delta' => $in_delta, 'out_delta' => $out_delta), 'bill_data');
+
+  if($period < "0") { 
+    logfile("BILLING: negative period! id:$bill_id period:$period delta:$delta in_delta:$in_delta out_delta:$out_delta"); 
+  } else {
+    dbInsert(array('bill_id' => $bill_id, 'timestamp' => $now, 'period' => $period, 'delta' => $delta, 'in_delta' => $in_delta, 'out_delta' => $out_delta), 'bill_data');
+  }
 }
 
 if ($argv[1]) { CollectData($argv[1]); }