diff --git a/main/gen_gdl90.go b/main/gen_gdl90.go index 1b36c944..9bdfb67c 100755 --- a/main/gen_gdl90.go +++ b/main/gen_gdl90.go @@ -97,6 +97,7 @@ const ( ) +var logFileHandle *os.File var usage *du.DiskUsage var maxSignalStrength int @@ -790,6 +791,10 @@ func updateStatus() { usage = du.NewDiskUsage("/") globalStatus.DiskBytesFree = usage.Free() + fileInfo, err := logFileHandle.Stat() + if err == nil { + globalStatus.Logfile_Size = fileInfo.Size() + } } type WeatherMessage struct { @@ -1086,8 +1091,8 @@ type status struct { UAT_PIREP_total uint32 UAT_NOTAM_total uint32 UAT_OTHER_total uint32 - - Errors []string + Errors []string + Logfile_Size int64 } var globalSettings settings @@ -1310,6 +1315,23 @@ func signalWatcher() { gracefulShutdown() } +func clearDebugLogFile() { + if logFileHandle != nil { + _, err := logFileHandle.Seek(0,0) + if err != nil { + log.Printf("Could not seek to the beginning of the logfile\n") + return + } else { + err2 := logFileHandle.Truncate(0) + if err2 != nil { + log.Printf("Could not truncate the logfile\n") + return + } + log.Printf("Logfile truncated\n") + } + } +} + func main() { // Catch signals for graceful shutdown. signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) @@ -1374,6 +1396,8 @@ func main() { log.Printf("%s\n", err_log.Error()) } else { defer fp.Close() + // Keep the logfile handle for later use + logFileHandle = fp mfp := io.MultiWriter(fp, os.Stdout) log.SetOutput(mfp) } diff --git a/main/managementinterface.go b/main/managementinterface.go index 9af5cdcd..474635bb 100755 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -364,6 +364,11 @@ func doReboot() { syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART) } +func handleDeleteLogFile(w http.ResponseWriter, r *http.Request) { + log.Printf("handleDeleteLogFile called!!!\n") + clearDebugLogFile() +} + func handleDevelModeToggle(w http.ResponseWriter, r *http.Request) { log.Printf("handleDevelModeToggle called!!!\n") globalSettings.DeveloperMode = true @@ -407,6 +412,18 @@ func delayReboot() { doReboot() } +func handleDownloadLogRequest(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "applicaiton/zip") + w.Header().Set("Content-Disposition", "attachment; filename='stratux.log'") + http.ServeFile(w, r, "/var/log/stratux.log") +} + +func handleDownloadDBRequest(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "applicaiton/zip") + w.Header().Set("Content-Disposition", "attachment; filename='stratux.sqlite'") + http.ServeFile(w, r, "/var/log/stratux.sqlite") +} + // Upload an update file. func handleUpdatePostRequest(w http.ResponseWriter, r *http.Request) { setNoCache(w) @@ -615,7 +632,9 @@ func managementInterface() { http.HandleFunc("/updateUpload", handleUpdatePostRequest) http.HandleFunc("/roPartitionRebuild", handleroPartitionRebuild) http.HandleFunc("/develmodetoggle", handleDevelModeToggle) - + http.HandleFunc("/deletelogfile", handleDeleteLogFile) + http.HandleFunc("/downloadlog", handleDownloadLogRequest) + http.HandleFunc("/downloaddb", handleDownloadDBRequest) err := http.ListenAndServe(managementAddr, nil) if err != nil { diff --git a/web/js/main.js b/web/js/main.js old mode 100644 new mode 100755 index fdfbbb02..3fbb9299 --- a/web/js/main.js +++ b/web/js/main.js @@ -15,6 +15,9 @@ var URL_REBOOT = "http://" + URL_HOST_BASE + "/reboot"; var URL_SHUTDOWN = "http://" + URL_HOST_BASE + "/shutdown"; var URL_RESTARTAPP = "http://" + URL_HOST_BASE + "/restart"; var URL_DEV_TOGGLE_GET = "http://" + URL_HOST_BASE + "/develmodetoggle"; +var URL_DELETELOGFILE = "http://" + URL_HOST_BASE + "/deletelogfile"; +var URL_DOWNLOADLOGFILE = "http://" + URL_HOST_BASE + "/downloadlog"; +var URL_DOWNLOADDB = "http://" + URL_HOST_BASE + "/downloaddb"; // define the module with dependency on mobile-angular-ui //var app = angular.module('stratux', ['ngRoute', 'mobile-angular-ui', 'mobile-angular-ui.gestures', 'appControllers']); diff --git a/web/plates/developer.html b/web/plates/developer.html index 87d3396d..4dfcc865 100644 --- a/web/plates/developer.html +++ b/web/plates/developer.html @@ -1,21 +1,59 @@ -
-
-
- Developer Mode Items -
-
-
-
-
Restart Stratux application
-
- -
-
-
+
+
+
+
+ Restart Stratux application
+ +
+ +
+
-
\ No newline at end of file + +
+
+
+ Logfile (Size: {{Logfile_Size}} bytes) +
+ + +
+
+ +
+
+
+ Database +
+ +
+ +
+
+
+
diff --git a/web/plates/js/developer.js b/web/plates/js/developer.js old mode 100644 new mode 100755 index ee815fa4..e3502571 --- a/web/plates/js/developer.js +++ b/web/plates/js/developer.js @@ -4,6 +4,92 @@ DeveloperCtrl.$inject = ['$rootScope', '$scope', '$state', '$http', '$interval'] // create our controller function with all necessary logic function DeveloperCtrl($rootScope, $scope, $state, $http, $interval) { $scope.$parent.helppage = 'plates/developer-help.html'; + + function connect($scope) { + if (($scope === undefined) || ($scope === null)) + return; // we are getting called once after clicking away from the status page + + if (($scope.socket === undefined) || ($scope.socket === null)) { + socket = new WebSocket(URL_STATUS_WS); + $scope.socket = socket; // store socket in scope for enter/exit usage + } + + $scope.ConnectState = "Disconnected"; + + socket.onopen = function (msg) { + // $scope.ConnectStyle = "label-success"; + $scope.ConnectState = "Connected"; + }; + + socket.onclose = function (msg) { + // $scope.ConnectStyle = "label-danger"; + $scope.ConnectState = "Disconnected"; + $scope.$apply(); + delete $scope.socket; + setTimeout(function() {connect($scope);}, 1000); + }; + + socket.onerror = function (msg) { + // $scope.ConnectStyle = "label-danger"; + $scope.ConnectState = "Error"; + $scope.$apply(); + }; + + socket.onmessage = function (msg) { + console.log('Received status update.') + + var status = JSON.parse(msg.data) + // Update Status + $scope.Version = status.Version; + $scope.Build = status.Build.substr(0, 10); + $scope.Devices = status.Devices; + $scope.Ping_connected = status.Ping_connected; + $scope.Connected_Users = status.Connected_Users; + $scope.UAT_messages_last_minute = status.UAT_messages_last_minute; + $scope.UAT_messages_max = status.UAT_messages_max; + $scope.ES_messages_last_minute = status.ES_messages_last_minute; + $scope.ES_messages_max = status.ES_messages_max; + $scope.GPS_satellites_locked = status.GPS_satellites_locked; + $scope.GPS_satellites_tracked = status.GPS_satellites_tracked; + $scope.GPS_satellites_seen = status.GPS_satellites_seen; + $scope.GPS_solution = status.GPS_solution; + $scope.GPS_position_accuracy = String(status.GPS_solution ? ", " + status.GPS_position_accuracy.toFixed(1) : ""); + $scope.RY835AI_connected = status.RY835AI_connected; + $scope.UAT_METAR_total = status.UAT_METAR_total; + $scope.UAT_TAF_total = status.UAT_TAF_total; + $scope.UAT_NEXRAD_total = status.UAT_NEXRAD_total; + $scope.UAT_SIGMET_total = status.UAT_SIGMET_total; + $scope.UAT_PIREP_total = status.UAT_PIREP_total; + $scope.UAT_NOTAM_total = status.UAT_NOTAM_total; + $scope.UAT_OTHER_total = status.UAT_OTHER_total; + $scope.Logfile_Size = status.Logfile_Size; + // Errors array. + if (status.Errors.length > 0) { + $scope.visible_errors = true; + $scope.Errors = status.Errors; + } + + var uptime = status.Uptime; + if (uptime != undefined) { + var up_d = parseInt((uptime/1000) / 86400), + up_h = parseInt((uptime/1000 - 86400*up_d) / 3600), + up_m = parseInt((uptime/1000 - 86400*up_d - 3600*up_h) / 60), + up_s = parseInt((uptime/1000 - 86400*up_d - 3600*up_h - 60*up_m)); + $scope.Uptime = String(up_d + "/" + ((up_h < 10) ? "0" + up_h : up_h) + ":" + ((up_m < 10) ? "0" + up_m : up_m) + ":" + ((up_s < 10) ? "0" + up_s : up_s)); + } else { + // $('#Uptime').text('unavailable'); + } + var boardtemp = status.CPUTemp; + if (boardtemp != undefined) { + /* boardtemp is celcius to tenths */ + $scope.CPUTemp = String(boardtemp.toFixed(1) + 'C / ' + ((boardtemp * 9 / 5) + 32.0).toFixed(1) + 'F'); + } else { + // $('#CPUTemp').text('unavailable'); + } + + $scope.$apply(); // trigger any needed refreshing of data + }; + } $scope.postRestart = function () { $http.post(URL_RESTARTAPP). @@ -14,5 +100,37 @@ function DeveloperCtrl($rootScope, $scope, $state, $http, $interval) { // do nothing }); }; + $scope.postDeleteLog = function () { + $http.post(URL_DELETELOGFILE). + then(function (response) { + // do nothing + // $scope.$apply(); + }, function (response) { + // do nothing + }); + }; + + $scope.postDownloadLog = function () { + $http.post(URL_DOWNLOADLOGFILE). + then(function (response) { + // do nothing + // $scope.$apply(); + }, function (response) { + // do nothing + }); + }; + + $scope.postDownloadDB = function () { + $http.post(URL_DOWNLOADDB). + then(function (response) { + // do nothing + // $scope.$apply(); + }, function (response) { + // do nothing + }); + }; + + connect($scope); // connect - opens a socket and listens for messages + }; diff --git a/web/plates/settings.html b/web/plates/settings.html index 6c731182..c97d016b 100755 --- a/web/plates/settings.html +++ b/web/plates/settings.html @@ -126,8 +126,8 @@
- +