mirror of
https://github.com/akuker/RASCSI.git
synced 2024-08-19 22:29:05 +00:00
Support for nested image dirs in the Web Interface (#558)
* Remove secure_filename for user created images * Code cleanup * Store relative path to image file in data structure * Match attached images against relative paths * Display scan depth in UI
This commit is contained in:
parent
ab55d95fd4
commit
c19c814863
@ -17,6 +17,8 @@ def get_server_info():
|
||||
- (list) of (str) log_levels (the log levels RaSCSI supports)
|
||||
- (str) current_log_level
|
||||
- (list) of (int) reserved_ids
|
||||
- (str) image_dir, path to the default images directory
|
||||
- (int) scan_depth, the current images directory scan depth
|
||||
- 5 distinct (list)s of (str)s with file endings recognized by RaSCSI
|
||||
"""
|
||||
command = proto.PbCommand()
|
||||
@ -33,6 +35,7 @@ def get_server_info():
|
||||
current_log_level = result.server_info.log_level_info.current_log_level
|
||||
reserved_ids = list(result.server_info.reserved_ids_info.ids)
|
||||
image_dir = result.server_info.image_files_info.default_image_folder
|
||||
scan_depth = result.server_info.image_files_info.depth
|
||||
|
||||
# Creates lists of file endings recognized by RaSCSI
|
||||
mappings = result.server_info.mapping_info.mapping
|
||||
@ -60,6 +63,7 @@ def get_server_info():
|
||||
"current_log_level": current_log_level,
|
||||
"reserved_ids": reserved_ids,
|
||||
"image_dir": image_dir,
|
||||
"scan_depth": scan_depth,
|
||||
"sahd": sahd,
|
||||
"schd": schd,
|
||||
"scrm": scrm,
|
||||
@ -127,6 +131,32 @@ def get_device_types():
|
||||
return {"status": result.status, "device_types": device_types}
|
||||
|
||||
|
||||
def get_image_files_info():
|
||||
"""
|
||||
Sends a DEFAULT_IMAGE_FILES_INFO command to the server.
|
||||
Returns a dict with:
|
||||
- (bool) status
|
||||
- (str) images_dir, path to images dir
|
||||
- (list) of (str) image_files
|
||||
- (int) scan_depth, the current scan depth
|
||||
"""
|
||||
command = proto.PbCommand()
|
||||
command.operation = proto.PbOperation.DEFAULT_IMAGE_FILES_INFO
|
||||
|
||||
data = send_pb_command(command.SerializeToString())
|
||||
result = proto.PbResult()
|
||||
result.ParseFromString(data)
|
||||
images_dir = result.image_files_info.default_image_folder
|
||||
image_files = result.image_files_info.image_files
|
||||
scan_depth = result.image_files_info.depth
|
||||
return {
|
||||
"status": result.status,
|
||||
"images_dir": images_dir,
|
||||
"image_files": image_files,
|
||||
"scan_depth": scan_depth,
|
||||
}
|
||||
|
||||
|
||||
def attach_image(scsi_id, **kwargs):
|
||||
"""
|
||||
Takes (int) scsi_id and kwargs containing 0 or more device properties
|
||||
@ -264,7 +294,6 @@ def list_devices(scsi_id=None, unit=None):
|
||||
If no attached device is found, returns an empty (list).
|
||||
Returns (bool) status, (list) of dicts device_list
|
||||
"""
|
||||
from os import path
|
||||
command = proto.PbCommand()
|
||||
command.operation = proto.PbOperation.DEVICES_INFO
|
||||
command.params["token"] = current_app.config["TOKEN"]
|
||||
@ -288,6 +317,7 @@ def list_devices(scsi_id=None, unit=None):
|
||||
if not result.devices_info.devices:
|
||||
return {"status": False, "device_list": []}
|
||||
|
||||
image_files_info = get_image_files_info()
|
||||
i = 0
|
||||
while i < len(result.devices_info.devices):
|
||||
did = result.devices_info.devices[i].id
|
||||
@ -308,7 +338,7 @@ def list_devices(scsi_id=None, unit=None):
|
||||
dstat_msg.append("Locked")
|
||||
|
||||
dpath = result.devices_info.devices[i].file.name
|
||||
dfile = path.basename(dpath)
|
||||
dfile = dpath.replace(image_files_info["images_dir"] + "/", "")
|
||||
dparam = result.devices_info.devices[i].params
|
||||
dven = result.devices_info.devices[i].vendor
|
||||
dprod = result.devices_info.devices[i].product
|
||||
|
@ -85,8 +85,8 @@
|
||||
</form>
|
||||
{% else %}
|
||||
{{ device.file }}
|
||||
</td>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% if device.vendor == "RaSCSI" %}
|
||||
<td style="text-align:center">{{ device.product }}</td>
|
||||
{% else %}
|
||||
@ -152,7 +152,7 @@
|
||||
Image File Management
|
||||
</summary>
|
||||
<ul>
|
||||
<li>Manage image files in the active RaSCSI image directory: <tt>{{ base_dir }}</tt></li>
|
||||
<li>Manage image files in the active RaSCSI image directory: <tt>{{ base_dir }}</tt> with a scan depth of {{ scan_depth }}.</li>
|
||||
<li>Select a valid SCSI ID and <a href="https://en.wikipedia.org/wiki/Logical_unit_number">LUN</a> to attach to. Unless you know what you're doing, always use LUN 0.
|
||||
</li>
|
||||
<li>If RaSCSI was unable to detect the device type associated with the image, you can choose the type from the dropdown.</li>
|
||||
|
@ -94,17 +94,17 @@ def index():
|
||||
disk = disk_space()
|
||||
devices = list_devices()
|
||||
device_types = get_device_types()
|
||||
files = list_images()
|
||||
image_files = list_images()
|
||||
config_files = list_config_files()
|
||||
|
||||
sorted_image_files = sorted(files["files"], key=lambda x: x["name"].lower())
|
||||
sorted_image_files = sorted(image_files["files"], key=lambda x: x["name"].lower())
|
||||
sorted_config_files = sorted(config_files, key=lambda x: x.lower())
|
||||
|
||||
attached_images = []
|
||||
units = 0
|
||||
# If there are more than 0 logical unit numbers, display in the Web UI
|
||||
for device in devices["device_list"]:
|
||||
attached_images.append(Path(device["image"]).name)
|
||||
attached_images.append(device["image"].replace(server_info["image_dir"] + "/", ""))
|
||||
units += int(device["unit"])
|
||||
|
||||
reserved_scsi_ids = server_info["reserved_ids"]
|
||||
@ -135,6 +135,7 @@ def index():
|
||||
files=sorted_image_files,
|
||||
config_files=sorted_config_files,
|
||||
base_dir=server_info["image_dir"],
|
||||
scan_depth=server_info["scan_depth"],
|
||||
CFG_DIR=CFG_DIR,
|
||||
AFP_DIR=AFP_DIR,
|
||||
scsi_ids=scsi_ids,
|
||||
@ -814,9 +815,6 @@ def create_file():
|
||||
size = (int(request.form.get("size")) * 1024 * 1024)
|
||||
file_type = request.form.get("type")
|
||||
|
||||
from werkzeug.utils import secure_filename
|
||||
file_name = secure_filename(file_name)
|
||||
|
||||
process = create_new_image(file_name, file_type, size)
|
||||
if process["status"]:
|
||||
flash(f"Drive image created: {file_name}.{file_type}")
|
||||
|
Loading…
Reference in New Issue
Block a user