Merge branch 'develop' into rdmark_inline_prop

This commit is contained in:
Daniel Markstedt 2021-10-24 09:57:08 -07:00 committed by GitHub
commit 17fc99d0fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 14 deletions

View File

@ -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
@ -218,7 +221,8 @@ function createImagesDir() {
}
function stopOldWebInterface() {
sudo systemctl stop rascsi-web || true
stopRaScsiWeb
APACHE_STATUS=$(sudo systemctl status apache2 &> /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
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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");
}

View File

@ -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}"}

View File

@ -147,6 +147,16 @@
{% if file["name"] in attached_images %}
<center>Attached!</center>
{% else %}
{% if file["name"].lower().endswith(archive_file_suffix) %}
<form action="/files/unzip" method="post">
<input type="hidden" name="image" value="{{file["name"]}}">
<input type="submit" value="Unzip" />
</form>
<form action="/files/delete" method="post" onsubmit="return confirm('Delete file?')">
<input type="hidden" name="image" value="{{file["name"]}}">
<input type="submit" value="Delete" />
</form>
{% else %}
<form action="/scsi/attach" method="post">
<input type="hidden" name="file_name" value="{{file["name"]}}">
<input type="hidden" name="file_size" value="{{file["size"]}}">
@ -226,7 +236,7 @@
<details>
<summary class="heading">Upload File</summary>
<ul>
<li>Uploads file to <tt>{{base_dir}}</tt>. The largest file size accepted is {{max_file_size}} MB. Zip files will be unzipped.</li>
<li>Uploads file to <tt>{{base_dir}}</tt>. The largest file size accepted is {{max_file_size}} MB.</li>
<li>For unrecognized file types, try renaming hard drive images to '.hds' and CD-ROM images to '.iso' before uploading.</li>
<li>Recognized file types: {{valid_file_suffix}}</li>
</ul>

View File

@ -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"