Changeset c455d7b
- Timestamp:
- Aug 10, 2017, 6:05:33 PM (9 years ago)
- Branches:
- 0.5, app-cordova, debian/bullseye, debian/jessie, master
- Children:
- 6fec060
- Parents:
- 82b4b49
- Location:
- src/webapp
- Files:
-
- 10 added
- 1 deleted
- 5 edited
- 1 moved
-
build.xml (modified) (3 diffs)
-
phpunit-4.8.9.phar (added)
-
webclient/css/main.css (modified) (1 diff)
-
webclient/index.html (modified) (3 diffs)
-
webclient/js/main.js (modified) (3 diffs)
-
webclient/resources/view-refresh.svg (added)
-
webservice/inc/GnuBoat/Config.php (moved) (moved from src/webapp/webservice/inc/Config.php ) (3 diffs)
-
webservice/inc/GnuBoat/Service.php (added)
-
webservice/inc/GnuBoat/ServiceData.php (added)
-
webservice/inc/GnuBoat/ServiceLogFiles.php (added)
-
webservice/inc/GnuBoat/ServiceMap.php (added)
-
webservice/inc/GnuBoat/ServiceShutdown.php (added)
-
webservice/inc/GnuBoat/Webservice.php (added)
-
webservice/inc/autoloader.php (added)
-
webservice/index.php (modified) (1 diff)
-
webservice/mapupload.php (deleted)
-
webservice/tests/ServiceTest.php (added)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/build.xml
r82b4b49 rc455d7b 27 27 <fileset dir="./webservice" id="filesWebservice"> 28 28 <exclude name="mbtiles/**"/> 29 <exclude name="tests/**"/> 29 30 </fileset> 30 31 <fileset dir="./webservice/mbtiles" id="filesWebserviceMaps"> … … 45 46 <target name="dist" depends="buildwebservice,buildwebclient"> 46 47 <echo msg="Creating archive"/> 47 <tar destfile="${builddir}/..//gnuboat-webapp.tar.gz" compression="gzip">48 <!-- <tar destfile="${builddir}/..//gnuboat-webapp.tar.gz" compression="gzip"> 48 49 <fileset refid="filesWebApp"/> 49 </tar>50 <echo msg="Files copied and compressed in build directory weblcient.tar.gz OK!" />50 </tar>--> 51 <echo msg="Files copied and compressed in build directory weblcient.tar.gz OK!" /> 51 52 </target> 52 53 <target name="testdist" depends="buildwebservice,buildwebclient"> … … 56 57 </copy> 57 58 </target> 59 60 <!-- <phpunit bootstrap="webservice/inc/autoloader.php" pharlocation="phpunit-4.8.9.phar" haltonfailure="true" haltonerror="true" printsummary="true"> 61 <formatter type="plain" usefile="false"/> 62 <batchtest> 63 <fileset dir="webservice"> 64 <include name="tests/ServiceTest.php"/> 65 </fileset> 66 </batchtest> 67 </phpunit> --> 58 68 </project> -
src/webapp/webclient/css/main.css
r82b4b49 rc455d7b 102 102 color: white; 103 103 font-weight: bold; 104 font-size: 24pt;105 104 height: 3em; 105 width: 100%; 106 margin-top: 3em; 106 107 } 108 109 #shutdownMessage { 110 font-weight: bold; 111 color: #8C1C00; 112 } 113 114 .logfiles-reload-button, .logfiles-reload-button:hover, .logfiles-reload-button:active, .logfiles-reload-button:focus { 115 float: right; 116 background:url('../resources/view-refresh.svg') no-repeat left center; 117 } -
src/webapp/webclient/index.html
r82b4b49 rc455d7b 49 49 <a class="pure-menu-heading" href="#">GNUBoat</a> 50 50 <ul class="pure-menu-list"> 51 <li class="pure-menu-item"><a class="pure-menu-link" href="#display"> Home</a></li>51 <li class="pure-menu-item"><a class="pure-menu-link" href="#display">Display</a></li> 52 52 <li class="pure-menu-item"><a class="pure-menu-link" href="#map">Map</a></li> 53 <li class="pure-menu-item"><a class="pure-menu-link" href="#download">Download</a></li> 53 <li class="pure-menu-item"><a class="pure-menu-link" href="#logfiles">Logfiles</a></li> 54 <li class="pure-menu-item"><button type="button" class="pure-button shutdown-button" id="shutdownButton">SHUTDOWN</button></li> 54 55 </ul> 55 56 </div> … … 92 93 <a name="shutdown"></a> 93 94 <p id="shutdownMessage"/> 94 <button type="button" class="pure-button shutdown-button" id="shutdownButton">SHUTDOWN</button>95 <!-- <button type="button" class="pure-button shutdown-button" id="shutdownButton">SHUTDOWN</button> --> 95 96 </div> 96 97 </div> … … 114 115 <input id="mapFileInput" type="file" name="mapFile" value="" placeholder="Path to MAPTile file" required><progress id="mapTileUploadProgress"></progress> 115 116 </div> 116 <input type="submit" class="pure-button pure-button-primary" name=" buttonSendMap" value="Upload"/>117 <input type="submit" class="pure-button pure-button-primary" name="mapUploadButton" value="Upload"/> 117 118 </fieldset> 118 119 </form> 120 121 <h2 class="content-subhead"> 122 Logfiles 123 <button id="logfilesReload" class="pure-button logfiles-reload-button"></button> 124 </h2> 125 <div> 126 <a name="logfiles"></a> 127 <form id="logfilesForm" class="pure-form" method="POST" action="../webservice/?request=logfiles"></form> 128 </div> 119 129 </div> 120 130 </div> -
src/webapp/webclient/js/main.js
r82b4b49 rc455d7b 167 167 var shutdownHint = "Shutting down in "+ Math.floor((shutdownDate - currentDate)/1000) +"s at "+ shutdownTime.toLocaleString(); 168 168 if(shutdownTime == -1){ 169 shutdownHint = "Failed to initiate shutdown !";169 shutdownHint = "Failed to initiate shutdown: "+ data["errormessage"]; 170 170 } 171 171 $("#shutdownMessage").text(shutdownHint); 172 172 }); 173 location.hash = "#shutdown"; 173 174 } 174 175 175 176 function uploadMap(form) 176 177 { 177 var formData = new FormData($("#mapTileUpload")[0]);178 // formData.append("mapFile", $("#mapFileInput")[0].files[0]);179 180 178 $("#mapFileInput").hide(); 181 179 $("#mapTileUploadProgress").show(); 182 180 $.ajax({ 183 181 type: 'POST', 184 url: '../webservice/ mapupload.php',185 data: formData,182 url: '../webservice/?request=map', 183 data: new FormData($("#mapTileUpload")[0]), 186 184 contentType: false, 187 185 processData: false, … … 208 206 } 209 207 208 function logfilesLoad() 209 { 210 $("#logfilesForm").empty(); 211 $.getJSON("../webservice/?request=logfiles", function(data){ 212 if(!Array.isArray(data) || data.length < 1){ 213 $("<p>No Logfiles found!</p>").appendTo("#logfilesForm"); 214 console.log(data); 215 return; 216 } 217 if(("error" in data) && data["error"] == 1){ 218 alert("Failed to upload map: "+ data["errormessage"]); 219 $("#mapTileUploadProgress").hide(); 220 $("#mapFileInput").show(); 221 return; 222 } 223 $("<select id=\"logfilesSelect\" name=\"logfilesSelected[]\" class=\"pure-input-1\" multiple></select>").appendTo("#logfilesForm"); 224 $("<input type=\"submit\" class=\"pure-button pure-button-primary\" name=\"logfilesDownload\" value=\"Download\"/>").appendTo("#logfilesForm"); 225 data.forEach(function(value, index){ 226 $("<option value=\""+ value +"\">"+ value +"</option>").appendTo("#logfilesSelect"); 227 }); 228 }); 229 } 210 230 211 231 $(document).ready(function() { 212 232 $("#mapTileUploadProgress").hide(); 213 $("shutdown").click(shutdown); 214 215 $("#mapTileUpload").validate({ 233 $("#logfilesReload").click(logfilesLoad); 234 $("#shutdownButton").click(shutdown); 235 236 $("#mapTileUpload").validate({ 216 237 rules: { 217 238 mapFile: { … … 226 247 } 227 248 }); 249 250 $("#logfilesForm").validate({ 251 rules: { 252 logfilesSelect: { 253 required: true 254 }, 255 } 256 }); 228 257 229 258 getMapInfos(); 230 259 displayDataGet(); 231 260 setInterval(displayDataGet, 10000); 261 logfilesLoad(); 232 262 }); -
src/webapp/webservice/inc/GnuBoat/Config.php
r82b4b49 rc455d7b 17 17 */ 18 18 19 $configFile = __DIR__ ."/../config/config.php"; 20 if(file_exists($configFile)) 21 include($configFile); 22 else{ 23 error_log("No config file ". $configFile ." not found!"); 24 $config = array(); 25 } 19 namespace GNUBoat; 26 20 27 21 /** 28 22 * @brief Loads the configuration from webservice/config/config.php (if file exists) and provides the settings for usage 29 23 */ 30 class Config { 31 public function __construct(){ 32 global $config; 33 $this->_config = $config; 24 class Config 25 { 26 public function __construct() 27 { 28 $configFile = __DIR__ ."/../config/config.php"; 29 if(file_exists($configFile)){ 30 include($configFile); 31 $this->_config = $config; 32 } 33 else{ 34 $this->_config = array(); 35 } 34 36 } 35 37 36 public function databaseFile(){ 38 public function databaseFile() 39 { 37 40 return $this->dataDirectory() ."gnuboat.rrd"; 38 41 } 39 42 40 public function shutdownRequestFile(){ 43 public function shutdownRequestFile() 44 { 41 45 if(array_key_exists("shutdownfile", $this->_config)) 42 46 return $this->_config["shutdownfile"]; … … 44 48 } 45 49 46 public function dataDirectory(){ 50 public function dataDirectory() 51 { 47 52 if(array_key_exists("datadirectory", $this->_config)) 48 53 return addTrailingSlash($this->_config["datadirectory"]); … … 50 55 } 51 56 52 private static function addTrailingSlash($path){ 57 public function logDirectory() 58 { 59 if(array_key_exists("logdirectory", $this->_config)) 60 return addTrailingSlash($this->_config["logdirectory"]); 61 return "/var/log/gnuboat/"; 62 } 63 64 private static function addTrailingSlash($path) 65 { 53 66 $length = strlen($path); 54 67 if(substr($path, $length - 1, 1) != "/"){ -
src/webapp/webservice/index.php
r82b4b49 rc455d7b 17 17 */ 18 18 19 require_once(__DIR__ ."/inc/Config.php"); 20 $config = new Config(); 21 $dbFile = $config->databaseFile(); 19 require_once(__DIR__ ."/inc/autoloader.php"); 22 20 23 define("REQUEST_DATA", "data"); 24 define("REQUEST_SHUTDOWN", "shutdown"); 25 26 27 // configure roundings per value (key) and precision (value) 28 $configRound = array 29 ( 30 "latitude" => 5, 31 "longitude" => 5, 32 "speedthroughwater" => 1, 33 "speedoverground" => 1, 34 "waterdepth" => 1, 35 "watertemperature" => 1, 36 ); 37 38 function addRrdData($interval, $period, &$result, &$lastValid){ 39 global $dbFile; 40 global $debug; 41 global $configRound; 42 $lastValid = false; 43 44 $endTime = floor(time() / $interval) * $interval; 45 $startTime = $endTime - $period; 46 $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", $startTime, "--end", $endTime)); 47 // $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period, "--align-start")); 48 if($data === false){ 49 echo json_encode($result); 50 $message = "Failure reading rrd database ". $dbFile .": ". rrd_error(); 51 if($debug > 0) 52 echo $message; 53 else 54 error_log($message); 55 return; 56 } 57 58 if($debug > 2){ 59 echo "<pre>"; 60 var_dump($data); 61 echo "</pre>"; 62 } 63 64 $data = $data["data"]; 65 66 // transform them into json format 67 $i = 0; 68 $lastValid = -1; 69 $keys = array_keys($data); 70 $keyTimeframes = $keys[0]; 71 $itemCount = count($keys); 72 if($itemCount < 0 ){ 73 error_log("No keys in fetched rrd data from ". $dbFile); 74 echo json_encode(""); 75 exit; 76 } 77 $timeframesCount = count($data[$keyTimeframes]); 78 if($debug > 0){ 79 echo "<p>Variables: ". $itemCount ."; Timeframes: ". $timeframesCount ."</p>\n"; 80 } 81 foreach($data[$keys[0]] as $timeframe => $value){ 82 $allValid = true; 83 $gpsFix = false; 84 $tmp = array(); 85 foreach($keys as $key){ 86 if($key == "gpsfix"){ 87 switch($data[$key][$timeframe]){ 88 case 2: 89 $tmp[$key] = "2D"; 90 $gpsFix = true; 91 break; 92 case 3: 93 $tmp[$key] = "3D"; 94 $gpsFix = true; 95 break; 96 default: 97 $tmp[$key] = "-"; 98 } 99 } 100 else{ 101 $tmp[$key] = $data[$key][$timeframe]; 102 if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){ 103 $allValid = false; 104 if($debug > 1){ 105 echo "Invalid value ". $key ." (". $tmp[$key] .") at time ". $time ."<br/>"; 106 } 107 } 108 elseif(array_key_exists($key, $configRound) && is_integer($configRound[$key])) 109 $tmp[$key] = round($tmp[$key], $configRound[$key]); 110 } 111 } 112 // only add the timeframe to the track, if the values are valid and we had a gps fix at that time 113 if($allValid){ 114 $lastValid = $tmp; 115 if($gpsFix){ 116 if(!array_key_exists($timeframe, $result["track"])){ 117 $result["track"][$timeframe] = $tmp; 118 } 119 } 120 } 121 else{ 122 if($debug > 1){ 123 echo "Failed <pre>"; 124 var_dump($tmp); 125 echo "</pre>\n"; 126 } 127 } 128 } 129 ksort($result["track"]); 130 } 131 132 $debug = 0; 133 if(array_key_exists("debug", $_GET)) 134 $debug = $_GET["debug"]; 135 136 $request = REQUEST_DATA; 137 if(array_key_exists("request", $_GET)){ 138 $request = $_GET["request"]; 139 } 140 141 if($debug == 0) 142 header('Content-Type: application/json'); 143 144 $result = array(); 145 if($request == REQUEST_SHUTDOWN){ 146 $handle = @fopen($config->shutdownRequestFile(), "w"); 147 if($handle === false){ 148 $message = "Could not create file (". $config->shutdownRequestFile() .") to indicate shutdown to the daemon (Timezone: ". date_default_timezone_get() .")"; 149 if($debug > 0) 150 echo $message; 151 error_log($message); 152 $result["shutdownstart"] = -1; 153 } 154 else{ 155 $shutdownTime = new DateTime('NOW'); 156 $shutdownTime->modify("+15 seconds"); 157 fwrite($handle, $shutdownTime->format(DateTime::ISO8601)); 158 $result["shutdownstart"] = $shutdownTime->format(DateTime::ISO8601); 159 } 160 } 161 elseif($request == REQUEST_DATA){ 162 $result["lastvalid"] = array(); 163 $result["track"] = array(); 164 165 if(!file_exists($dbFile)){ 166 echo json_encode(""); 167 if($debug > 0) 168 echo "Database file ". $dbFile ." does not exist!"; 169 error_log("Database file ". $dbFile ." does not exist"); 170 exit; 171 } 172 // Fetch entries of the last 30s with maximum (available) resolution of 2s 173 addRrdData("2", "240", $result, $lastValid); 174 if($lastValid){ 175 $result["lastvalid"] = $lastValid; 176 } 177 // Fetch entries of the last 1h with maximum (available) resolution of 10s 178 addRrdData("10", "36000", $result, $lastTime); 179 // Fetch entries of the last 24h with maximum (available) resolution of 60s 180 addRrdData("60", "86400", $result, $lastTime); 181 } 182 183 if($debug > 0){ 184 echo json_encode($result, JSON_PRETTY_PRINT) ."\n"; 185 } 186 else{ 187 echo json_encode($result) ."\n"; 188 } 21 $webservice = new GnuBoat\Webservice(); 22 $webservice->process(); 189 23 190 24 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
