Skip to content

Commit

Permalink
Added upload logs button on About page
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronRP committed Jan 29, 2024
1 parent 22845a4 commit ea0f619
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
22 changes: 22 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,3 +1031,25 @@ func (api *ManagementAPI) GetConnectionStatus(w http.ResponseWriter, r *http.Req
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(data)
}

func (api *ManagementAPI) UploadLogs(w http.ResponseWriter, r *http.Request) {
if err := exec.Command("cp", "/var/log/syslog", "/tmp/syslog").Run(); err != nil {
log.Printf("Error copying syslog: %v", err)
serverError(&w, err)
return
}

if err := exec.Command("gzip", "/tmp/syslog", "-f").Run(); err != nil {
log.Printf("Error compressing syslog: %v", err)
serverError(&w, err)
return
}

if err := exec.Command("salt-call", "cp.push", "/tmp/syslog.gz").Run(); err != nil {
log.Printf("Error pushing syslog with salt: %v", err)
serverError(&w, err)
return
}

w.WriteHeader(http.StatusOK)
}
1 change: 1 addition & 0 deletions cmd/managementd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func main() {
apiRouter.HandleFunc("/enable-wifi", apiObj.EnableWifi).Methods("POST")
apiRouter.HandleFunc("/enable-hotspot", apiObj.EnableHotspot).Methods("POST")
apiRouter.HandleFunc("/wifi-status", apiObj.GetConnectionStatus).Methods("GET")
apiRouter.HandleFunc("/upload-logs", apiObj.UploadLogs).Methods("PUT")

apiRouter.Use(basicAuth)

Expand Down
4 changes: 4 additions & 0 deletions html/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ <h3>Device<br></h3>
</label>
</div>

<div class="container pt-5 pb-4 pl-0">
<button id="upload-logs-button" type="button" onclick="uploadLogs()" class="btn btn-primary">Upload logs</button>
</div>

<div class="container pt-5 pb-4 pl-0">
<h3>Installed Packages<br></h3>
</div>
Expand Down
26 changes: 26 additions & 0 deletions static/js/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@ function runSaltUpdate() {
xmlHttp.send(null);
}

async function uploadLogs() {
$("#upload-logs-button").attr("disabled", true);
$("#upload-logs-button").html("Uploading logs...");
try {
const response = await fetch("/api/upload-logs", {
method: "PUT",
headers: {
"Authorization": "Basic " + btoa("admin:feathers"),
"Content-Type": "application/json"
}
});

if (response.ok) {
alert("Logs uploaded");
} else {
alert("Error uploading logs");
console.error("Error with response:", await response.text());
}
} catch (error) {
alert("Error uploading logs");
console.error("Error with uploading logs:", error);
}
$("#upload-logs-button").attr("disabled", false);
$("#upload-logs-button").html("Upload logs");
}

var runningSaltUpdate = true;
// Check salt update state. Returns true if it is no longer running
function checkSaltUpdateState() {
Expand Down

0 comments on commit ea0f619

Please sign in to comment.