mirror of
https://github.com/akuker/RASCSI.git
synced 2026-04-20 11:17:58 +00:00
Web UI: Handling for non-existence of working dirs (#1130)
This commit is contained in:
@@ -383,8 +383,11 @@
|
||||
</summary>
|
||||
<ul>
|
||||
<li>{{ _("Disk Images") }} = {{ env["image_dir"] }}</li>
|
||||
{% if file_server_dir_exists %}
|
||||
<li>{{ _("Shared Files") }} = {{ FILE_SERVER_DIR }}</li>
|
||||
<li>{{ _("To access shared files remotely, you may have to install one of the file servers first.") }}</li>
|
||||
{% else %}
|
||||
<li>{{ _("Install a file server and create the shared files directory in order to share files between the Pi and your vintage computers.") }}</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</details>
|
||||
|
||||
@@ -399,6 +402,7 @@
|
||||
{% endfor %}
|
||||
<option value="/" selected>/</option>
|
||||
</select>
|
||||
{% if file_server_dir_exists %}
|
||||
<input type="radio" name="destination" id="shared_files" value="shared_files">
|
||||
<label for="shared_files">{{ _("Shared Files") }}</label>
|
||||
<select name="shared_subdir" id="shared_subdir">
|
||||
@@ -407,6 +411,7 @@
|
||||
{% endfor %}
|
||||
<option value="/" selected>/</option>
|
||||
</select>
|
||||
{% endif %}
|
||||
<input type="submit" value="{{ _("Download") }}" onclick="processNotify('{{ _("Downloading File...") }}')">
|
||||
</form>
|
||||
</section>
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
<li>{{ _("The largest file size accepted in this form is %(max_file_size)s MiB. Use other file transfer means for larger files.", max_file_size=max_file_size) }}</li>
|
||||
<li>{{ _("You have to manually clean up partially uploaded files, as a result of cancelling the upload or closing this page.") }}</li>
|
||||
<li>{{ _("Disk Images") }} = {{ env["image_dir"] }}</li>
|
||||
{% if file_server_dir_exists %}
|
||||
<li>{{ _("Shared Files") }} = {{ FILE_SERVER_DIR }}</li>
|
||||
{% endif %}
|
||||
<li>{{ _("PiSCSI Config") }} = {{ CFG_DIR }}</li>
|
||||
</ul>
|
||||
|
||||
@@ -20,6 +22,7 @@
|
||||
{% endfor %}
|
||||
<option value="/" selected>/</option>
|
||||
</select>
|
||||
{% if file_server_dir_exists %}
|
||||
<input type="radio" name="destination" id="shared_files" value="shared_files">
|
||||
<label for="shared_files">{{ _("Shared Files") }}</label>
|
||||
<select name="shared_subdir" id="shared_subdir">
|
||||
@@ -28,6 +31,7 @@
|
||||
{% endfor %}
|
||||
<option value="/" selected>/</option>
|
||||
</select>
|
||||
{% endif %}
|
||||
<input type="radio" name="destination" id="piscsi_config" value="piscsi_config">
|
||||
<label for="piscsi_config">{{ _("PiSCSI Config") }}</label>
|
||||
</form>
|
||||
|
||||
+15
-10
@@ -24,7 +24,6 @@ from flask import (
|
||||
send_from_directory,
|
||||
make_response,
|
||||
session,
|
||||
abort,
|
||||
jsonify,
|
||||
)
|
||||
|
||||
@@ -44,6 +43,7 @@ from return_code_mapper import ReturnCodeMapper
|
||||
from socket_cmds_flask import SocketCmdsFlask
|
||||
|
||||
from web_utils import (
|
||||
working_dirs_exist,
|
||||
sort_and_format_devices,
|
||||
get_valid_scsi_ids,
|
||||
map_device_types_and_names,
|
||||
@@ -209,16 +209,9 @@ def index():
|
||||
"""
|
||||
Sets up data structures for and renders the index page
|
||||
"""
|
||||
if not piscsi_cmd.is_token_auth()["status"] and not APP.config["PISCSI_TOKEN"]:
|
||||
abort(
|
||||
403,
|
||||
_(
|
||||
"PiSCSI is password protected. "
|
||||
"Start the Web Interface with the --password parameter."
|
||||
),
|
||||
)
|
||||
|
||||
server_info = piscsi_cmd.get_server_info()
|
||||
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
||||
|
||||
devices = piscsi_cmd.list_devices()
|
||||
device_types = map_device_types_and_names(piscsi_cmd.get_device_types()["device_types"])
|
||||
image_files = file_cmd.list_images()
|
||||
@@ -277,6 +270,7 @@ def index():
|
||||
drive_properties=format_drive_properties(APP.config["PISCSI_DRIVE_PROPERTIES"]),
|
||||
images_subdirs=file_cmd.list_subdirs(server_info["image_dir"]),
|
||||
shared_subdirs=file_cmd.list_subdirs(FILE_SERVER_DIR),
|
||||
file_server_dir_exists=Path(FILE_SERVER_DIR).exists(),
|
||||
RESERVATIONS=RESERVATIONS,
|
||||
CFG_DIR=CFG_DIR,
|
||||
FILE_SERVER_DIR=FILE_SERVER_DIR,
|
||||
@@ -302,6 +296,8 @@ def drive_list():
|
||||
"""
|
||||
Sets up the data structures and kicks off the rendering of the drive list page
|
||||
"""
|
||||
server_info = piscsi_cmd.get_server_info()
|
||||
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
||||
|
||||
return response(
|
||||
template="drives.html",
|
||||
@@ -317,12 +313,14 @@ def upload_page():
|
||||
Sets up the data structures and kicks off the rendering of the file uploading page
|
||||
"""
|
||||
server_info = piscsi_cmd.get_server_info()
|
||||
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
||||
|
||||
return response(
|
||||
template="upload.html",
|
||||
page_title=_("PiSCSI File Upload"),
|
||||
images_subdirs=file_cmd.list_subdirs(server_info["image_dir"]),
|
||||
shared_subdirs=file_cmd.list_subdirs(FILE_SERVER_DIR),
|
||||
file_server_dir_exists=Path(FILE_SERVER_DIR).exists(),
|
||||
max_file_size=int(int(MAX_FILE_SIZE) / 1024 / 1024),
|
||||
CFG_DIR=CFG_DIR,
|
||||
FILE_SERVER_DIR=FILE_SERVER_DIR,
|
||||
@@ -516,6 +514,7 @@ def show_diskinfo():
|
||||
if not safe_path["status"]:
|
||||
return response(error=True, message=safe_path["msg"])
|
||||
server_info = piscsi_cmd.get_server_info()
|
||||
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
||||
returncode, diskinfo = sys_cmd.get_diskinfo(Path(server_info["image_dir"]) / file_name)
|
||||
if returncode == 0:
|
||||
return response(
|
||||
@@ -1474,6 +1473,12 @@ if __name__ == "__main__":
|
||||
file_cmd = FileCmds(sock_cmd=sock_cmd, piscsi=piscsi_cmd, token=APP.config["PISCSI_TOKEN"])
|
||||
sys_cmd = SysCmds()
|
||||
|
||||
if not piscsi_cmd.is_token_auth()["status"] and not APP.config["PISCSI_TOKEN"]:
|
||||
raise Exception(
|
||||
"PiSCSI is password protected. "
|
||||
"Start the Web Interface with the --password parameter."
|
||||
)
|
||||
|
||||
if Path(f"{CFG_DIR}/{DEFAULT_CONFIG}").is_file():
|
||||
file_cmd.read_config(DEFAULT_CONFIG)
|
||||
if Path(f"{DRIVE_PROPERTIES_FILE}").is_file():
|
||||
|
||||
@@ -9,13 +9,26 @@ from pathlib import Path
|
||||
from ua_parser import user_agent_parser
|
||||
from re import findall
|
||||
|
||||
from flask import request, make_response
|
||||
from flask import request, make_response, abort
|
||||
from flask_babel import _
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from piscsi.sys_cmds import SysCmds
|
||||
|
||||
|
||||
def working_dirs_exist(working_dirs):
|
||||
"""
|
||||
Method for validating that working dirs exist.
|
||||
Takes (tuple) of (str) working_dirs with paths to required dirs.
|
||||
"""
|
||||
for dir_path in working_dirs:
|
||||
if not Path(dir_path).exists():
|
||||
abort(
|
||||
503,
|
||||
_(f"Please create directory: {dir_path}"),
|
||||
)
|
||||
|
||||
|
||||
def get_valid_scsi_ids(devices, reserved_ids):
|
||||
"""
|
||||
Takes a list of (dict)s devices, and list of (int)s reserved_ids.
|
||||
|
||||
Reference in New Issue
Block a user