Changeset 73c34f3 for src/webapp
- Timestamp:
- Jul 20, 2016, 5:57:42 PM (10 years ago)
- Branches:
- 0.5, app-cordova, debian/bullseye, debian/jessie, master
- Children:
- 0c7eb83, 10edeb0
- Parents:
- d7ee6ae
- File:
-
- 1 edited
-
src/webapp/webservice/index.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webservice/index.php
rd7ee6ae r73c34f3 36 36 ); 37 37 38 $debug = 0; 39 if(array_key_exists("debug", $_GET)) 40 $debug = $_GET["debug"]; 38 function addRrdData($interval, $period, &$result, &$lastTime){ 39 global $dbFile; 40 global $debug; 41 global $configRound; 41 42 42 $request = REQUEST_DATA; 43 if(array_key_exists("request", $_GET)){ 44 $request = $_GET["request"]; 45 } 46 47 if($debug == 0) 48 header('Content-Type: application/json'); 49 50 $result = array(); 51 if($request == REQUEST_SHUTDOWN){ 52 $handle = @fopen("/var/spool/gnuboat/gnuboat_shutdown", "w"); 53 if($handle === false){ 54 $message = "Could not create file to indicate shutdown to the daemon (Timezone: ". date_default_timezone_get() .")"; 55 if($debug > 0) 56 echo $message; 57 error_log($message); 58 $result["shutdownstart"] = -1; 59 $shutdownTime = new DateTime('NOW'); 60 $shutdownTime->modify("+60 seconds"); 61 $result["shutdownstart"] = $shutdownTime->format(DateTime::ISO8601); 62 } 63 else{ 64 $shutdownTime = new DateTime('NOW'); 65 $shutdownTime>modify("+15 seconds"); 66 fwrite($handle, $shutdownTime->format(DateTime::ISO8601)); 67 $result["shutdownstart"] = $shutdownTime->format(DateTime::ISO8601); 68 } 69 } 70 elseif($request == REQUEST_DATA){ 71 $result["lastvalid"] = array(); 72 $result["track"] = array(); 73 74 if(!file_exists($dbFile)){ 75 echo json_encode(""); 76 if($debug > 0) 77 echo "Database file ". $dbFile ." does not exist!"; 78 error_log("Database file ". $dbFile ." does not exist"); 79 exit; 80 } 81 // Fetch entries of the last 12hours 82 $data = rrd_fetch($dbFile, array( "AVERAGE", "--resolution", "5", "--start", "-12h")); 43 $data = rrd_fetch($dbFile, array( "AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period)); 83 44 if($data === false){ 84 45 echo json_encode($result); 85 $message = " Could not open rrd database ". $dbFile;46 $message = "Failure reading rrd database ". $dbFile .": ". rrd_error(); 86 47 if($debug > 0) 87 48 echo $message; 88 49 else 89 50 error_log($message); 90 exit;91 51 } 92 52 … … 107 67 echo json_encode(""); 108 68 exit; 69 } 70 if($debug > 0){ 71 echo "<p>Variables: ". count($keys) ."; Timeframes: ". count($data[$keys[0]]) ."</p>\n"; 109 72 } 110 73 for($i = 0; $i < count($data[$keys[0]]); $i++){ … … 136 99 // only add the timeframe to the track, if the values are valid and we had a gps fix at that time 137 100 if($allValid && $tmp["gpsfix"] != "-"){ 138 $result["track"][$time] = $tmp; 101 echo "want to add ". $time ."<br/>\n"; 102 if(!array_key_exists($time, $result["track"])){ 103 $result["track"][$time] = $tmp; 104 } 139 105 $lastTime = $time; 140 106 } 141 107 else{ 142 if($debug > 0){108 if($debug > 1){ 143 109 echo "Failed <pre>"; 144 110 var_dump($tmp); … … 147 113 } 148 114 } 115 116 ksort($result["track"]); 117 } 118 119 $debug = 0; 120 if(array_key_exists("debug", $_GET)) 121 $debug = $_GET["debug"]; 122 123 $request = REQUEST_DATA; 124 if(array_key_exists("request", $_GET)){ 125 $request = $_GET["request"]; 126 } 127 128 if($debug == 0) 129 header('Content-Type: application/json'); 130 131 $result = array(); 132 if($request == REQUEST_SHUTDOWN){ 133 $handle = @fopen("/var/spool/gnuboat/gnuboat_shutdown", "w"); 134 if($handle === false){ 135 $message = "Could not create file to indicate shutdown to the daemon (Timezone: ". date_default_timezone_get() .")"; 136 if($debug > 0) 137 echo $message; 138 error_log($message); 139 $result["shutdownstart"] = -1; 140 } 141 else{ 142 $shutdownTime = new DateTime('NOW'); 143 $shutdownTime>modify("+15 seconds"); 144 fwrite($handle, $shutdownTime->format(DateTime::ISO8601)); 145 $result["shutdownstart"] = $shutdownTime->format(DateTime::ISO8601); 146 } 147 } 148 elseif($request == REQUEST_DATA){ 149 $result["lastvalid"] = array(); 150 $result["track"] = array(); 151 152 if(!file_exists($dbFile)){ 153 echo json_encode(""); 154 if($debug > 0) 155 echo "Database file ". $dbFile ." does not exist!"; 156 error_log("Database file ". $dbFile ." does not exist"); 157 exit; 158 } 159 // Fetch entries of the last 30 seconds 160 addRrdData("5s", "30s", $result, $lastTime); 149 161 if($lastTime > -1){ 150 162 $result["lastvalid"] = $result["track"][$lastTime]; 151 163 } 164 addRrdData("15s", "5minutes", $result, $lastTime); 165 addRrdData("30s", "12h", $result, $lastTime); 152 166 } 153 167
Note:
See TracChangeset
for help on using the changeset viewer.
