From 192bbb6391cdf867b5f53a3779ecbbc2602af89a Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Wed, 20 Oct 2021 22:06:00 -0700 Subject: [PATCH 1/4] Add checks for running services before stopping + stop&start monitor_rascsi when installing rascsi proper --- easyinstall.sh | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/easyinstall.sh b/easyinstall.sh index 9fb0b55a..37e39aa8 100755 --- a/easyinstall.sh +++ b/easyinstall.sh @@ -79,7 +79,8 @@ function installPackages() { # compile and install RaSCSI Service function installRaScsi() { - sudo systemctl stop rascsi || true + stopRaScsiScreen + stopRaScsi if [ -f /etc/systemd/system/rascsi.service ]; then sudo cp /etc/systemd/system/rascsi.service /etc/systemd/system/rascsi.service.old @@ -109,6 +110,8 @@ www-data ALL=NOPASSWD: /sbin/shutdown, /sbin/reboot sudo systemctl restart rsyslog sudo systemctl enable rascsi # optional - start rascsi at boot sudo systemctl start rascsi + + startRaScsiScreen } # install everything required to run an HTTP server (Nginx + Python Flask App) @@ -151,7 +154,7 @@ function installRaScsiScreen() { ROTATION="180" fi - sudo systemctl stop monitor_rascsi || true + stopRaScsiScreen updateRaScsiGit sudo apt-get update && sudo apt-get install python3-dev python3-pip python3-venv libjpeg-dev libpng-dev libopenjp2-7-dev i2c-tools -y /dev/null; echo $?) if [ "$APACHE_STATUS" -eq 0 ] ; then echo "Stopping old Apache2 RaSCSI Web..." @@ -249,6 +253,31 @@ function updateRaScsiGit() { fi } +function stopRaScsi() { + if [[ `systemctl list-units | grep -c rascsi.service` -ge 1 ]]; then + sudo systemctl stop rascsi.service + fi +} + +function stopRaScsiWeb() { + if [[ `systemctl list-units | grep -c rascsi-web.service` -ge 1 ]]; then + sudo systemctl stop rascsi-web.service + fi +} + +function stopRaScsiScreen() { + if [[ `systemctl list-units | grep -c monitor_rascsi.service` -ge 1 ]]; then + sudo systemctl stop monitor_rascsi.service + fi +} + +function startRaScsiScreen() { + if [[ -f "/etc/systemd/system/monitor_rascsi.service" ]]; then + sudo systemctl start monitor_rascsi.service + showRaScsiScreenStatus + fi +} + function showRaScsiStatus() { sudo systemctl status rascsi | tee } From e059432402845e18f1a8b2c84f05885ead9b5738 Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Thu, 21 Oct 2021 17:10:25 -0700 Subject: [PATCH 2/4] Clean up config files after error --- src/web/file_cmds.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/web/file_cmds.py b/src/web/file_cmds.py index e16eba24..c750a15f 100644 --- a/src/web/file_cmds.py +++ b/src/web/file_cmds.py @@ -244,9 +244,11 @@ def write_config(file_name): return {"status": True, "msg": f"Successfully wrote to file: {file_name}"} except (IOError, ValueError, EOFError, TypeError) as e: logging.error(str(e)) + delete_file(file_name) return {"status": False, "msg": str(e)} except: logging.error(f"Could not write to file: {file_name}") + delete_file(file_name) return {"status": False, "msg": f"Could not write to file: {file_name}"} @@ -284,21 +286,24 @@ def read_config(file_name): def write_drive_properties(file_name, conf): """ - Writes a drive property configuration file to the images dir. + Writes a drive property configuration file to the config dir. Takes file name base (str) and conf (list of dicts) as arguments Returns dict with boolean status and str msg """ from json import dump + file_path = cfg_dir + file_name try: - with open(cfg_dir + file_name, "w") as json_file: + with open(file_path, "w") as json_file: dump(conf, json_file, indent=4) - return {"status": True, "msg": f"Successfully wrote to file: {file_name}"} + return {"status": True, "msg": f"Successfully wrote to file: {file_path}"} except (IOError, ValueError, EOFError, TypeError) as e: logging.error(str(e)) + delete_file(file_path) return {"status": False, "msg": str(e)} except: - logging.error(f"Could not write to file: {file_name}") - return {"status": False, "msg": f"Could not write to file: {file_name}"} + logging.error(f"Could not write to file: {file_path}") + delete_file(file_path) + return {"status": False, "msg": f"Could not write to file: {file_path}"} From 39bd6b7ee96d5bb3612093991e0f6207ea81cc07 Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Fri, 22 Oct 2021 06:42:28 -0700 Subject: [PATCH 3/4] Bring back manual unzip, remove automatic unzip on upload, and show only relevant controls for zip files --- src/web/templates/index.html | 13 ++++++++++++- src/web/web.py | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/web/templates/index.html b/src/web/templates/index.html index 5c097d11..013d73cd 100644 --- a/src/web/templates/index.html +++ b/src/web/templates/index.html @@ -134,6 +134,16 @@ {% if file["name"] in attached_images %}
Attached!
{% else %} + {% if file["name"].lower().endswith(archive_file_suffix) %} +
+ + +
+
+ + +
+ {% else %}
@@ -168,6 +178,7 @@
{% endif %} + {% endif %} {% endif %} @@ -219,7 +230,7 @@
Upload File
    -
  • Uploads file to {{base_dir}}. The largest file size accepted is {{max_file_size}} MB. Zip files will be unzipped.
  • +
  • Uploads file to {{base_dir}}. The largest file size accepted is {{max_file_size}} MB.
  • For unrecognized file types, try renaming hard drive images to '.hds' and CD-ROM images to '.iso' before uploading.
  • Recognized file types: {{valid_file_suffix}}
diff --git a/src/web/web.py b/src/web/web.py index 7d49e030..1686d6b7 100644 --- a/src/web/web.py +++ b/src/web/web.py @@ -108,6 +108,7 @@ def index(): device_types=device_types["device_types"], free_disk=int(disk["free"] / 1024 / 1024), valid_file_suffix=valid_file_suffix, + archive_file_suffix=ARCHIVE_FILE_SUFFIX, removable_device_types=REMOVABLE_DEVICE_TYPES, ) @@ -570,13 +571,10 @@ def upload_file(): return make_response(("Transferred file corrupted!", 500)) else: log.info(f"File {file.filename} has been uploaded successfully") - if filename.lower().endswith(".zip"): - unzip_file(filename) else: log.debug(f"Chunk {current_chunk + 1} of {total_chunks} " f"for file {file.filename} completed.") - return make_response(("File upload successful!", 200)) @@ -636,6 +634,18 @@ def delete(): return redirect(url_for("index")) +@app.route("/files/unzip", methods=["POST"]) +def unzip(): + image = request.form.get("image") + + if unzip_file(image): + flash("Unzipped file " + image) + return redirect(url_for("index")) + else: + flash("Failed to unzip " + image, "error") + return redirect(url_for("index")) + + @app.route("/files/prop", methods=["POST"]) def show_properties(): file_name = request.form.get("image") From dcbee64750508a1a41ed6b6c4adf1b4794e2c92e Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Sun, 24 Oct 2021 08:10:31 +0200 Subject: [PATCH 4/4] Do not consider NONE operation an error (#369) * Do not consider NONE operation an error * Cleanup * Code cleanup from other PR --- src/raspberrypi/controllers/sasidev_ctrl.cpp | 2 +- src/raspberrypi/controllers/scsidev_ctrl.cpp | 2 +- src/raspberrypi/rascsi.cpp | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/raspberrypi/controllers/sasidev_ctrl.cpp b/src/raspberrypi/controllers/sasidev_ctrl.cpp index cb445a67..89276f0d 100644 --- a/src/raspberrypi/controllers/sasidev_ctrl.cpp +++ b/src/raspberrypi/controllers/sasidev_ctrl.cpp @@ -356,7 +356,7 @@ void SASIDEV::Execute() ctrl.execstart = SysTimer::GetTimerLow(); // Discard pending sense data from the previous command if the current command is not REQUEST SENSE - if(SASIDEV::eCmdRequestSense != (SASIDEV::sasi_command)ctrl.cmd[0]) { + if ((SASIDEV::sasi_command)ctrl.cmd[0] != SASIDEV::eCmdRequestSense) { ctrl.status = 0; ctrl.device->SetStatusCode(0); } diff --git a/src/raspberrypi/controllers/scsidev_ctrl.cpp b/src/raspberrypi/controllers/scsidev_ctrl.cpp index 59a2e06b..c07d35b6 100644 --- a/src/raspberrypi/controllers/scsidev_ctrl.cpp +++ b/src/raspberrypi/controllers/scsidev_ctrl.cpp @@ -262,7 +262,7 @@ void SCSIDEV::Execute() ctrl.device = ctrl.unit[lun]; - // Discard pending sense data from the previous command + // Discard pending sense data from the previous command if the current command is not REQUEST SENSE if ((SCSIDEV::scsi_command)ctrl.cmd[0] != eCmdRequestSense) { ctrl.device->SetStatusCode(0); } diff --git a/src/raspberrypi/rascsi.cpp b/src/raspberrypi/rascsi.cpp index 4381fccf..29a10757 100644 --- a/src/raspberrypi/rascsi.cpp +++ b/src/raspberrypi/rascsi.cpp @@ -959,6 +959,11 @@ bool ProcessCmd(int fd, const PbDeviceDefinition& pb_device, const PbCommand& co assert(dryRun); break; + case NONE: + // Do nothing, just log + LOGTRACE("Received %s command", PbOperation_Name(operation).c_str()); + break; + default: return ReturnStatus(fd, false, "Unknown operation"); }