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 } 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"); } diff --git a/src/web/file_cmds.py b/src/web/file_cmds.py index fbf7dbcd..a88fc419 100644 --- a/src/web/file_cmds.py +++ b/src/web/file_cmds.py @@ -245,9 +245,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}"} @@ -285,21 +287,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}"} diff --git a/src/web/templates/index.html b/src/web/templates/index.html index ac4d30a3..e092d363 100644 --- a/src/web/templates/index.html +++ b/src/web/templates/index.html @@ -147,6 +147,16 @@ {% if file["name"] in attached_images %}
Attached!
{% else %} + {% if file["name"].lower().endswith(archive_file_suffix) %} +
+ + +
+
+ + +
+ {% else %}
@@ -226,7 +236,7 @@
Upload File diff --git a/src/web/web.py b/src/web/web.py index 772d3615..b5bac4d1 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")) + + if __name__ == "__main__": app.secret_key = "rascsi_is_awesome_insecure_secret_key" app.config["SESSION_TYPE"] = "filesystem"