diff --git a/photon-client/src/views/LogsView.vue b/photon-client/src/views/LogsView.vue index 70b136004..615354e19 100644 --- a/photon-client/src/views/LogsView.vue +++ b/photon-client/src/views/LogsView.vue @@ -12,12 +12,21 @@ color="secondary" style="margin-left: auto;" depressed - @click="download('photonlog.log', rawLogs.map(it => it.message).join('\n'))" + @click="$refs.exportLogFile.click()" > mdi-download Download Log + + + +
diff --git a/photon-client/src/views/SettingsView.vue b/photon-client/src/views/SettingsView.vue index c7842d37a..266fe9182 100644 --- a/photon-client/src/views/SettingsView.vue +++ b/photon-client/src/views/SettingsView.vue @@ -37,7 +37,8 @@ import Networking from './SettingsViews/Networking' import Lighting from "./SettingsViews/Lighting"; import cvImage from '../components/common/cv-image' - import General from "./SettingsViews/General"; + import Stats from "./SettingsViews/Stats"; + import DeviceControl from "./SettingsViews/DeviceControl"; export default { name: 'SettingsTab', @@ -69,7 +70,7 @@ }, tabList: { get() { - return [General, Networking].concat(this.$store.state.settings.lighting.supported ? Lighting : []); + return [Stats, DeviceControl, Networking].concat(this.$store.state.settings.lighting.supported ? Lighting : []); } } }, diff --git a/photon-client/src/views/SettingsViews/DeviceControl.vue b/photon-client/src/views/SettingsViews/DeviceControl.vue new file mode 100644 index 000000000..5d63f1ab8 --- /dev/null +++ b/photon-client/src/views/SettingsViews/DeviceControl.vue @@ -0,0 +1,289 @@ + + + + + diff --git a/photon-client/src/views/SettingsViews/General.vue b/photon-client/src/views/SettingsViews/Stats.vue similarity index 85% rename from photon-client/src/views/SettingsViews/General.vue rename to photon-client/src/views/SettingsViews/Stats.vue index 412bbc380..2e7c0b2d1 100644 --- a/photon-client/src/views/SettingsViews/General.vue +++ b/photon-client/src/views/SettingsViews/Stats.vue @@ -117,85 +117,11 @@ - - - - - mdi-download - - Export Settings - - - - - - mdi-upload - - Import Settings - - - - - - mdi-update - - Offline Update - - - - - - mdi-restart - - Restart PhotonVision - - - - - - mdi-restart-alert - - Restart Device - - - {{ snackbar.text }} @@ -230,7 +156,7 @@ diff --git a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java index 59b2723cf..930b748f2 100644 --- a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java +++ b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java @@ -25,6 +25,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; @@ -193,6 +194,43 @@ public class RequestHandler { } } + private static ShellExec shell = new ShellExec(); + + public static void onExportCurrentLogs(Context ctx) { + if (!Platform.isLinux()) { + logger.warn("Cannot export journalctl on non-Linux platforms! Ignoring"); + ctx.status(500); + return; + } + + try { + var tempPath = Files.createTempFile("photonvision-journalctl", ".txt"); + shell.executeBashCommand( + "journalctl -u photonvision.service > " + tempPath.toAbsolutePath().toString()); + + while (!shell.isOutputCompleted()) { + // TODO: add timeout + } + + if (shell.getExitCode() == 0) { + // Wrote to the temp file! Add it to the ctx + var stream = new FileInputStream(tempPath.toFile()); + logger.info("Uploading settings with size " + stream.available()); + ctx.result(stream); + ctx.contentType("application/zip"); + ctx.header("Content-Disposition: attachment; filename=\"photonvision-journalctl.txt\""); + ctx.status(200); + } else { + logger.error("Could not export journactl logs! (exit code != 0)"); + ctx.status(500); + } + } catch (IOException e) { + // TODO Auto-generated catch block + logger.error("Could not export journactl logs! (IOexception)", e); + ctx.status(500); + } + } + public static void onCalibrationEnd(Context ctx) { logger.info("Calibrating camera! This will take a long time..."); var index = Integer.parseInt(ctx.body()); diff --git a/photon-server/src/main/java/org/photonvision/server/Server.java b/photon-server/src/main/java/org/photonvision/server/Server.java index a94035de1..b84bf6635 100644 --- a/photon-server/src/main/java/org/photonvision/server/Server.java +++ b/photon-server/src/main/java/org/photonvision/server/Server.java @@ -84,6 +84,7 @@ public class Server { app.post("/api/settings/import", RequestHandler::onSettingUpload); app.post("/api/settings/offlineUpdate", RequestHandler::onOfflineUpdate); app.get("/api/settings/photonvision_config.zip", RequestHandler::onSettingsDownload); + app.get("/api/settings/photonvision-journalctl.txt", RequestHandler::onExportCurrentLogs); app.post("/api/settings/camera", RequestHandler::onCameraSettingsSave); app.post("/api/settings/general", RequestHandler::onGeneralSettings); app.post("/api/settings/endCalibration", RequestHandler::onCalibrationEnd);