2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Module for the Flask app rendering and endpoints
|
|
|
|
"""
|
|
|
|
|
2021-09-22 05:51:06 +00:00
|
|
|
import logging
|
2022-12-04 14:31:57 +00:00
|
|
|
import logging.config
|
2021-12-23 17:12:16 +00:00
|
|
|
import argparse
|
2022-11-14 17:32:15 +00:00
|
|
|
from pathlib import Path, PurePath
|
2021-12-13 00:54:15 +00:00
|
|
|
from functools import wraps
|
2022-02-27 05:46:35 +00:00
|
|
|
from grp import getgrall
|
|
|
|
|
|
|
|
import bjoern
|
2022-12-05 17:58:23 +00:00
|
|
|
from piscsi.return_codes import ReturnCodes
|
2022-02-27 05:46:35 +00:00
|
|
|
from simplepam import authenticate
|
|
|
|
from flask_babel import Babel, Locale, refresh, _
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2021-09-20 19:47:39 +00:00
|
|
|
from flask import (
|
|
|
|
Flask,
|
|
|
|
render_template,
|
|
|
|
request,
|
|
|
|
flash,
|
|
|
|
url_for,
|
|
|
|
redirect,
|
|
|
|
send_from_directory,
|
2021-09-22 05:51:06 +00:00
|
|
|
make_response,
|
2021-11-27 04:41:10 +00:00
|
|
|
session,
|
2022-09-25 23:00:18 +00:00
|
|
|
jsonify,
|
2021-09-20 19:47:39 +00:00
|
|
|
)
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
from piscsi.piscsi_cmds import PiscsiCmds
|
|
|
|
from piscsi.file_cmds import FileCmds
|
|
|
|
from piscsi.sys_cmds import SysCmds
|
2022-02-27 05:46:35 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
from piscsi.common_settings import (
|
2022-02-27 05:46:35 +00:00
|
|
|
CFG_DIR,
|
|
|
|
CONFIG_FILE_SUFFIX,
|
|
|
|
PROPERTIES_SUFFIX,
|
2022-08-12 03:19:02 +00:00
|
|
|
ARCHIVE_FILE_SUFFIXES,
|
2022-02-27 05:46:35 +00:00
|
|
|
RESERVATIONS,
|
2021-02-01 17:39:50 +00:00
|
|
|
)
|
2022-01-21 23:08:29 +00:00
|
|
|
|
2022-02-27 05:46:35 +00:00
|
|
|
from return_code_mapper import ReturnCodeMapper
|
|
|
|
from socket_cmds_flask import SocketCmdsFlask
|
|
|
|
|
|
|
|
from web_utils import (
|
2023-03-24 03:07:19 +00:00
|
|
|
working_dirs_exist,
|
2021-11-07 00:25:02 +00:00
|
|
|
sort_and_format_devices,
|
|
|
|
get_valid_scsi_ids,
|
2022-02-21 17:27:31 +00:00
|
|
|
map_device_types_and_names,
|
|
|
|
get_device_name,
|
2022-09-22 00:14:53 +00:00
|
|
|
map_image_file_descriptions,
|
2023-02-25 01:28:58 +00:00
|
|
|
format_image_list,
|
2022-10-01 23:51:30 +00:00
|
|
|
format_drive_properties,
|
2022-10-06 21:04:41 +00:00
|
|
|
get_properties_by_drive_name,
|
2022-02-27 05:46:35 +00:00
|
|
|
auth_active,
|
|
|
|
is_bridge_configured,
|
2022-10-24 02:05:29 +00:00
|
|
|
is_safe_path,
|
2022-02-27 05:46:35 +00:00
|
|
|
upload_with_dropzonejs,
|
2022-11-14 17:32:15 +00:00
|
|
|
browser_supports_modern_themes,
|
2021-11-07 00:25:02 +00:00
|
|
|
)
|
|
|
|
from settings import (
|
2022-10-03 19:46:18 +00:00
|
|
|
WEB_DIR,
|
2022-11-01 23:43:24 +00:00
|
|
|
FILE_SERVER_DIR,
|
2021-11-07 00:25:02 +00:00
|
|
|
MAX_FILE_SIZE,
|
|
|
|
DEFAULT_CONFIG,
|
|
|
|
DRIVE_PROPERTIES_FILE,
|
2021-11-27 04:41:10 +00:00
|
|
|
AUTH_GROUP,
|
2021-12-27 21:21:56 +00:00
|
|
|
LANGUAGES,
|
2022-11-14 17:32:15 +00:00
|
|
|
TEMPLATE_THEMES,
|
|
|
|
TEMPLATE_THEME_DEFAULT,
|
|
|
|
TEMPLATE_THEME_LEGACY,
|
2023-09-01 06:23:12 +00:00
|
|
|
THROTTLE_NOTIFY_MODES,
|
|
|
|
THROTTLE_TEST_MODES,
|
2021-11-07 00:25:02 +00:00
|
|
|
)
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-01-21 23:08:29 +00:00
|
|
|
|
2023-10-25 10:35:15 +00:00
|
|
|
def get_locale():
|
|
|
|
"""
|
|
|
|
Uses the session language, or tries to detect based on accept-languages header
|
|
|
|
"""
|
|
|
|
session_locale = session.get("language")
|
|
|
|
if session_locale:
|
|
|
|
return session_locale
|
|
|
|
|
|
|
|
client_locale = request.accept_languages.best_match(LANGUAGES)
|
|
|
|
if client_locale:
|
|
|
|
return client_locale
|
|
|
|
|
|
|
|
logging.info("The default locale could not be detected. Falling back to English.")
|
|
|
|
return "en"
|
|
|
|
|
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
APP = Flask(__name__)
|
2021-12-26 21:36:12 +00:00
|
|
|
BABEL = Babel(APP)
|
2023-10-25 10:35:15 +00:00
|
|
|
BABEL.init_app(APP, locale_selector=get_locale)
|
2021-12-26 21:36:12 +00:00
|
|
|
|
2022-11-30 05:19:17 +00:00
|
|
|
|
2022-09-25 23:00:18 +00:00
|
|
|
def get_env_info():
|
|
|
|
"""
|
|
|
|
Get information about the app/host environment
|
|
|
|
"""
|
2022-12-05 17:58:23 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
2022-09-25 23:00:18 +00:00
|
|
|
ip_addr, host = sys_cmd.get_ip_and_host()
|
|
|
|
|
|
|
|
if "username" in session:
|
|
|
|
username = session["username"]
|
|
|
|
else:
|
|
|
|
username = None
|
|
|
|
|
2023-09-04 15:08:42 +00:00
|
|
|
throttled_statuses = sys_cmd.get_throttled(THROTTLE_NOTIFY_MODES, THROTTLE_TEST_MODES)
|
2023-09-01 06:23:12 +00:00
|
|
|
|
2022-09-25 23:00:18 +00:00
|
|
|
return {
|
|
|
|
"running_env": sys_cmd.running_env(),
|
|
|
|
"username": username,
|
|
|
|
"auth_active": auth_active(AUTH_GROUP)["status"],
|
2022-11-14 17:32:15 +00:00
|
|
|
"logged_in": username and auth_active(AUTH_GROUP)["status"],
|
2022-09-25 23:00:18 +00:00
|
|
|
"ip_addr": ip_addr,
|
|
|
|
"host": host,
|
2022-11-20 18:20:32 +00:00
|
|
|
"system_name": sys_cmd.get_pretty_host(),
|
2023-05-21 22:27:50 +00:00
|
|
|
"free_disk_space": int(sys_cmd.disk_space(server_info["image_dir"])["free"] / 1024 / 1024),
|
2022-10-07 20:13:29 +00:00
|
|
|
"locale": get_locale(),
|
|
|
|
"version": server_info["version"],
|
|
|
|
"image_dir": server_info["image_dir"],
|
2023-05-21 22:27:50 +00:00
|
|
|
"image_root_dir": Path(server_info["image_dir"]).name,
|
2022-10-07 20:13:29 +00:00
|
|
|
"netatalk_configured": sys_cmd.running_proc("afpd"),
|
2023-09-24 16:30:54 +00:00
|
|
|
"samba_configured": sys_cmd.running_proc("smbd"),
|
|
|
|
"ftp_configured": sys_cmd.running_proc("vsftpd"),
|
2022-10-07 20:13:29 +00:00
|
|
|
"macproxy_configured": sys_cmd.running_proc("macproxy"),
|
2023-09-24 16:30:54 +00:00
|
|
|
"webmin_configured": sys_cmd.running_proc("miniserv.pl"),
|
2022-10-07 20:13:29 +00:00
|
|
|
"cd_suffixes": tuple(server_info["sccd"]),
|
|
|
|
"rm_suffixes": tuple(server_info["scrm"]),
|
|
|
|
"mo_suffixes": tuple(server_info["scmo"]),
|
2023-09-04 15:08:42 +00:00
|
|
|
"throttle_status": [
|
|
|
|
(s[0], ReturnCodeMapper.add_msg({"return_code": s[1]})) for s in throttled_statuses
|
|
|
|
],
|
2022-09-25 23:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def response(
|
|
|
|
template=None,
|
|
|
|
message=None,
|
|
|
|
redirect_url=None,
|
|
|
|
error=False,
|
|
|
|
status_code=200,
|
2022-11-30 05:19:17 +00:00
|
|
|
**kwargs,
|
2022-09-25 23:00:18 +00:00
|
|
|
):
|
|
|
|
"""
|
|
|
|
Generates a HTML or JSON HTTP response
|
|
|
|
"""
|
|
|
|
status = "error" if error else "success"
|
|
|
|
|
|
|
|
if isinstance(message, list):
|
|
|
|
messages = message
|
|
|
|
elif message is None:
|
|
|
|
messages = []
|
|
|
|
else:
|
|
|
|
messages = [(str(message), status)]
|
|
|
|
|
|
|
|
if request.headers.get("accept") == "application/json":
|
2022-11-30 05:19:17 +00:00
|
|
|
return (
|
|
|
|
jsonify(
|
|
|
|
{
|
|
|
|
"status": status,
|
|
|
|
"messages": [{"message": m, "category": c} for m, c in messages],
|
|
|
|
"data": kwargs,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
status_code,
|
|
|
|
)
|
2022-09-25 23:00:18 +00:00
|
|
|
|
|
|
|
if messages:
|
|
|
|
for message, category in messages:
|
|
|
|
flash(message, category)
|
|
|
|
|
|
|
|
if template:
|
2022-11-14 17:32:15 +00:00
|
|
|
if session.get("theme") and session["theme"] in TEMPLATE_THEMES:
|
|
|
|
theme = session["theme"]
|
|
|
|
elif browser_supports_modern_themes():
|
|
|
|
theme = TEMPLATE_THEME_DEFAULT
|
|
|
|
else:
|
|
|
|
theme = TEMPLATE_THEME_LEGACY
|
|
|
|
|
2022-12-11 03:31:37 +00:00
|
|
|
body_classes = [f"page-{PurePath(template).stem.lower()}"]
|
|
|
|
|
|
|
|
env_info = get_env_info()
|
|
|
|
if env_info["auth_active"]:
|
|
|
|
body_classes.append("auth-enabled")
|
|
|
|
if env_info["logged_in"]:
|
|
|
|
body_classes.append("logged-in")
|
|
|
|
else:
|
|
|
|
body_classes.append("auth-disabled")
|
|
|
|
|
|
|
|
kwargs["env"] = env_info
|
|
|
|
kwargs["body_classes"] = body_classes
|
2022-11-14 17:32:15 +00:00
|
|
|
kwargs["current_theme_stylesheet"] = f"themes/{theme}/style.css"
|
|
|
|
kwargs["current_theme"] = theme
|
|
|
|
kwargs["available_themes"] = TEMPLATE_THEMES
|
2022-09-25 23:00:18 +00:00
|
|
|
return render_template(template, **kwargs)
|
|
|
|
|
|
|
|
if redirect_url:
|
|
|
|
return redirect(url_for(redirect_url))
|
|
|
|
return redirect(url_for("index"))
|
|
|
|
|
2022-01-21 23:08:29 +00:00
|
|
|
|
2021-12-27 21:21:56 +00:00
|
|
|
def get_supported_locales():
|
|
|
|
"""
|
2022-09-23 23:20:49 +00:00
|
|
|
Returns a list of languages supported by the web UI
|
2021-12-27 21:21:56 +00:00
|
|
|
"""
|
2022-09-10 01:58:47 +00:00
|
|
|
locales = [
|
|
|
|
{"language": x.language, "display_name": x.display_name}
|
|
|
|
for x in [*BABEL.list_translations(), Locale("en")]
|
2022-11-30 05:19:17 +00:00
|
|
|
]
|
2022-09-10 01:58:47 +00:00
|
|
|
|
|
|
|
return sorted(locales, key=lambda x: x["language"])
|
2021-12-27 21:21:56 +00:00
|
|
|
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-02-27 05:46:35 +00:00
|
|
|
# pylint: disable=too-many-locals
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/")
|
2020-12-31 01:39:32 +00:00
|
|
|
def index():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Sets up data structures for and renders the index page
|
|
|
|
"""
|
2022-12-05 17:58:23 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
2023-03-24 03:07:19 +00:00
|
|
|
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
devices = piscsi_cmd.list_devices()
|
|
|
|
device_types = map_device_types_and_names(piscsi_cmd.get_device_types()["device_types"])
|
2022-02-27 05:46:35 +00:00
|
|
|
image_files = file_cmd.list_images()
|
|
|
|
config_files = file_cmd.list_config_files()
|
|
|
|
ip_addr, host = sys_cmd.get_ip_and_host()
|
2023-05-21 22:27:50 +00:00
|
|
|
formatted_image_files = format_image_list(
|
|
|
|
image_files["files"], Path(server_info["image_dir"]).name, device_types
|
|
|
|
)
|
2022-02-13 16:28:50 +00:00
|
|
|
|
2021-10-15 00:49:06 +00:00
|
|
|
attached_images = []
|
2021-11-07 00:25:02 +00:00
|
|
|
units = 0
|
|
|
|
# If there are more than 0 logical unit numbers, display in the Web UI
|
|
|
|
for device in devices["device_list"]:
|
2021-12-23 17:13:51 +00:00
|
|
|
attached_images.append(device["image"].replace(server_info["image_dir"] + "/", ""))
|
2021-11-07 02:11:17 +00:00
|
|
|
units += int(device["unit"])
|
2021-10-13 09:03:31 +00:00
|
|
|
|
2021-09-19 21:29:01 +00:00
|
|
|
reserved_scsi_ids = server_info["reserved_ids"]
|
2022-10-06 17:00:57 +00:00
|
|
|
scsi_ids = get_valid_scsi_ids(devices["device_list"], reserved_scsi_ids)
|
2021-09-19 21:29:01 +00:00
|
|
|
formatted_devices = sort_and_format_devices(devices["device_list"])
|
2021-09-21 01:55:09 +00:00
|
|
|
|
2022-09-22 00:14:53 +00:00
|
|
|
image_suffixes_to_create = map_image_file_descriptions(
|
|
|
|
# Here we strip out hdi and nhd, since they are proprietary PC-98 emulator formats
|
|
|
|
# that require a particular header to work. We can't generate them on the fly.
|
|
|
|
# We also reverse the resulting list, in order for hds to be the default in the UI.
|
|
|
|
# This might break if something like 'hdt' etc. gets added in the future.
|
|
|
|
sorted(
|
|
|
|
[suffix for suffix in server_info["schd"] if suffix not in {"hdi", "nhd"}],
|
2022-11-30 05:19:17 +00:00
|
|
|
reverse=True,
|
2022-09-22 00:14:53 +00:00
|
|
|
)
|
2022-11-30 05:19:17 +00:00
|
|
|
+ server_info["scrm"]
|
|
|
|
+ server_info["scmo"]
|
|
|
|
)
|
2022-09-22 00:14:53 +00:00
|
|
|
|
2022-09-22 00:20:22 +00:00
|
|
|
valid_image_suffixes = (
|
2022-11-30 05:19:17 +00:00
|
|
|
server_info["schd"] + server_info["scrm"] + server_info["scmo"] + server_info["sccd"]
|
|
|
|
)
|
2021-09-30 21:10:51 +00:00
|
|
|
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(
|
|
|
|
template="index.html",
|
2022-12-25 15:23:16 +00:00
|
|
|
page_title=_("PiSCSI Control Page"),
|
2022-02-21 17:27:31 +00:00
|
|
|
locales=get_supported_locales(),
|
2022-12-05 17:58:23 +00:00
|
|
|
netinfo=piscsi_cmd.get_network_info(),
|
2022-02-27 05:46:35 +00:00
|
|
|
bridge_configured=sys_cmd.is_bridge_setup(),
|
2021-09-19 21:29:01 +00:00
|
|
|
devices=formatted_devices,
|
2022-10-07 20:13:29 +00:00
|
|
|
attached_images=attached_images,
|
2023-02-25 01:28:58 +00:00
|
|
|
formatted_image_files=formatted_image_files,
|
|
|
|
files=image_files["files"],
|
2022-02-21 17:27:31 +00:00
|
|
|
config_files=config_files,
|
2022-10-07 20:13:29 +00:00
|
|
|
device_types=device_types,
|
2021-12-23 17:13:51 +00:00
|
|
|
scan_depth=server_info["scan_depth"],
|
2022-10-07 20:13:29 +00:00
|
|
|
log_levels=server_info["log_levels"],
|
|
|
|
current_log_level=server_info["current_log_level"],
|
2021-02-01 17:39:50 +00:00
|
|
|
scsi_ids=scsi_ids,
|
2021-11-07 00:25:02 +00:00
|
|
|
units=units,
|
2021-09-19 21:29:01 +00:00
|
|
|
reserved_scsi_ids=reserved_scsi_ids,
|
2022-09-22 00:14:53 +00:00
|
|
|
image_suffixes_to_create=image_suffixes_to_create,
|
2022-09-03 07:14:13 +00:00
|
|
|
valid_image_suffixes=valid_image_suffixes,
|
2022-12-05 17:58:23 +00:00
|
|
|
drive_properties=format_drive_properties(APP.config["PISCSI_DRIVE_PROPERTIES"]),
|
2023-03-05 00:57:32 +00:00
|
|
|
images_subdirs=file_cmd.list_subdirs(server_info["image_dir"]),
|
|
|
|
shared_subdirs=file_cmd.list_subdirs(FILE_SERVER_DIR),
|
2023-03-24 03:07:19 +00:00
|
|
|
file_server_dir_exists=Path(FILE_SERVER_DIR).exists(),
|
2022-10-07 20:13:29 +00:00
|
|
|
RESERVATIONS=RESERVATIONS,
|
|
|
|
CFG_DIR=CFG_DIR,
|
2022-11-01 23:43:24 +00:00
|
|
|
FILE_SERVER_DIR=FILE_SERVER_DIR,
|
2021-11-09 03:10:52 +00:00
|
|
|
PROPERTIES_SUFFIX=PROPERTIES_SUFFIX,
|
2022-09-22 00:20:22 +00:00
|
|
|
ARCHIVE_FILE_SUFFIXES=ARCHIVE_FILE_SUFFIXES,
|
2022-10-07 20:13:29 +00:00
|
|
|
CONFIG_FILE_SUFFIX=CONFIG_FILE_SUFFIX,
|
2022-12-05 17:58:23 +00:00
|
|
|
REMOVABLE_DEVICE_TYPES=piscsi_cmd.get_removable_device_types(),
|
|
|
|
DISK_DEVICE_TYPES=piscsi_cmd.get_disk_device_types(),
|
|
|
|
PERIPHERAL_DEVICE_TYPES=piscsi_cmd.get_peripheral_device_types(),
|
2021-02-01 17:39:50 +00:00
|
|
|
)
|
|
|
|
|
2021-09-19 21:29:01 +00:00
|
|
|
|
2022-09-19 16:00:59 +00:00
|
|
|
@APP.route("/env")
|
|
|
|
def env():
|
|
|
|
"""
|
|
|
|
Shows information about the app/host environment
|
|
|
|
"""
|
|
|
|
return response(**get_env_info())
|
|
|
|
|
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/drive/list", methods=["GET"])
|
2021-09-19 21:29:01 +00:00
|
|
|
def drive_list():
|
|
|
|
"""
|
|
|
|
Sets up the data structures and kicks off the rendering of the drive list page
|
|
|
|
"""
|
2023-03-24 03:07:19 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
|
|
|
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(
|
2022-09-27 00:44:41 +00:00
|
|
|
template="drives.html",
|
2022-12-25 15:23:16 +00:00
|
|
|
page_title=_("PiSCSI Create Drive"),
|
2022-02-27 05:46:35 +00:00
|
|
|
files=file_cmd.list_images()["files"],
|
2022-12-05 17:58:23 +00:00
|
|
|
drive_properties=format_drive_properties(APP.config["PISCSI_DRIVE_PROPERTIES"]),
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2021-09-19 21:29:01 +00:00
|
|
|
|
|
|
|
|
2022-12-20 01:21:01 +00:00
|
|
|
@APP.route("/upload", methods=["GET"])
|
|
|
|
def upload_page():
|
|
|
|
"""
|
|
|
|
Sets up the data structures and kicks off the rendering of the file uploading page
|
|
|
|
"""
|
2023-03-05 00:57:32 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
2023-03-24 03:07:19 +00:00
|
|
|
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
2022-12-20 01:21:01 +00:00
|
|
|
|
|
|
|
return response(
|
|
|
|
template="upload.html",
|
2022-12-25 15:23:16 +00:00
|
|
|
page_title=_("PiSCSI File Upload"),
|
2023-03-05 00:57:32 +00:00
|
|
|
images_subdirs=file_cmd.list_subdirs(server_info["image_dir"]),
|
|
|
|
shared_subdirs=file_cmd.list_subdirs(FILE_SERVER_DIR),
|
2023-03-24 03:07:19 +00:00
|
|
|
file_server_dir_exists=Path(FILE_SERVER_DIR).exists(),
|
2022-12-20 01:21:01 +00:00
|
|
|
max_file_size=int(int(MAX_FILE_SIZE) / 1024 / 1024),
|
2023-01-28 22:34:34 +00:00
|
|
|
CFG_DIR=CFG_DIR,
|
2022-12-20 01:21:01 +00:00
|
|
|
FILE_SERVER_DIR=FILE_SERVER_DIR,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-11-27 04:41:10 +00:00
|
|
|
@APP.route("/login", methods=["POST"])
|
|
|
|
def login():
|
|
|
|
"""
|
|
|
|
Uses simplepam to authenticate against Linux users
|
|
|
|
"""
|
|
|
|
username = request.form["username"]
|
|
|
|
password = request.form["password"]
|
|
|
|
groups = [g.gr_name for g in getgrall() if username in g.gr_mem]
|
2022-09-25 23:00:18 +00:00
|
|
|
|
2022-10-09 20:50:20 +00:00
|
|
|
if AUTH_GROUP in groups and authenticate(str(username), str(password)):
|
|
|
|
session["username"] = request.form["username"]
|
|
|
|
return response(env=get_env_info())
|
2022-09-25 23:00:18 +00:00
|
|
|
|
2022-11-30 05:19:17 +00:00
|
|
|
return response(
|
|
|
|
error=True,
|
|
|
|
status_code=401,
|
|
|
|
message=_(
|
|
|
|
"You must log in with valid credentials for a user in the '%(group)s' group",
|
|
|
|
group=AUTH_GROUP,
|
|
|
|
),
|
|
|
|
)
|
2021-11-27 04:41:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/logout")
|
|
|
|
def logout():
|
|
|
|
"""
|
|
|
|
Removes the logged in user from the session
|
|
|
|
"""
|
|
|
|
session.pop("username", None)
|
2022-09-25 23:00:18 +00:00
|
|
|
return response()
|
2021-11-27 04:41:10 +00:00
|
|
|
|
|
|
|
|
2022-02-27 05:46:35 +00:00
|
|
|
@APP.route("/pwa/<path:pwa_path>")
|
|
|
|
def send_pwa_files(pwa_path):
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Sets up mobile web resources
|
|
|
|
"""
|
2022-02-27 05:46:35 +00:00
|
|
|
return send_from_directory("pwa", pwa_path)
|
2021-02-01 17:39:50 +00:00
|
|
|
|
2021-09-19 21:29:01 +00:00
|
|
|
|
2021-12-13 00:54:15 +00:00
|
|
|
def login_required(func):
|
|
|
|
"""
|
|
|
|
Wrapper method for enabling authentication for an endpoint
|
|
|
|
"""
|
2022-11-30 05:19:17 +00:00
|
|
|
|
2021-12-13 00:54:15 +00:00
|
|
|
@wraps(func)
|
|
|
|
def decorated_function(*args, **kwargs):
|
2022-02-27 05:46:35 +00:00
|
|
|
auth = auth_active(AUTH_GROUP)
|
2021-12-13 00:54:15 +00:00
|
|
|
if auth["status"] and "username" not in session:
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(error=True, message=auth["msg"])
|
2021-12-13 00:54:15 +00:00
|
|
|
return func(*args, **kwargs)
|
2022-11-30 05:19:17 +00:00
|
|
|
|
2021-12-13 00:54:15 +00:00
|
|
|
return decorated_function
|
|
|
|
|
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/drive/create", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2021-09-19 21:29:01 +00:00
|
|
|
def drive_create():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Creates the image and properties file pair
|
|
|
|
"""
|
2022-10-06 21:04:41 +00:00
|
|
|
drive_name = request.form.get("drive_name")
|
2023-01-28 22:36:07 +00:00
|
|
|
file_name = Path(request.form.get("file_name"))
|
2022-10-06 21:04:41 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
properties = get_properties_by_drive_name(APP.config["PISCSI_DRIVE_PROPERTIES"], drive_name)
|
2021-09-22 05:51:06 +00:00
|
|
|
|
2022-11-16 06:28:27 +00:00
|
|
|
if not properties:
|
|
|
|
return response(
|
|
|
|
error=True,
|
|
|
|
message=_("No properties data for drive %(drive_name)s", drive_name=drive_name),
|
|
|
|
)
|
|
|
|
|
2021-09-19 21:29:01 +00:00
|
|
|
# Creating the image file
|
2023-01-27 05:51:59 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
|
|
|
process = file_cmd.create_empty_image(
|
|
|
|
Path(server_info["image_dir"]) / f"{file_name}.{properties['file_type']}",
|
2022-10-08 02:55:53 +00:00
|
|
|
properties["size"],
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2023-01-27 05:51:59 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2022-09-25 23:00:18 +00:00
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
2021-09-19 21:29:01 +00:00
|
|
|
|
|
|
|
# Creating the drive properties file
|
2022-10-06 21:04:41 +00:00
|
|
|
full_file_name = f"{file_name}.{properties['file_type']}"
|
|
|
|
prop_file_name = f"{full_file_name}.{PROPERTIES_SUFFIX}"
|
2022-02-27 05:46:35 +00:00
|
|
|
process = file_cmd.write_drive_properties(prop_file_name, properties)
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2022-09-25 23:00:18 +00:00
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
2021-09-19 21:29:01 +00:00
|
|
|
|
2022-11-30 05:19:17 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
|
|
|
"Image file with properties created: %(file_name)s",
|
|
|
|
file_name=full_file_name,
|
|
|
|
)
|
2022-10-24 02:05:29 +00:00
|
|
|
)
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2021-09-19 21:29:01 +00:00
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/drive/cdrom", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2021-09-19 21:29:01 +00:00
|
|
|
def drive_cdrom():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Creates a properties file for a CD-ROM image
|
|
|
|
"""
|
2022-10-06 21:04:41 +00:00
|
|
|
drive_name = request.form.get("drive_name")
|
2023-01-28 22:36:07 +00:00
|
|
|
file_name = Path(request.form.get("file_name"))
|
2021-09-19 21:29:01 +00:00
|
|
|
|
|
|
|
# Creating the drive properties file
|
2021-10-15 00:47:02 +00:00
|
|
|
file_name = f"{file_name}.{PROPERTIES_SUFFIX}"
|
2022-12-05 17:58:23 +00:00
|
|
|
properties = get_properties_by_drive_name(APP.config["PISCSI_DRIVE_PROPERTIES"], drive_name)
|
2022-11-16 06:28:27 +00:00
|
|
|
|
|
|
|
if not properties:
|
|
|
|
return response(
|
|
|
|
error=True,
|
|
|
|
message=_("No properties data for drive %(drive_name)s", drive_name=drive_name),
|
|
|
|
)
|
|
|
|
|
2022-02-27 05:46:35 +00:00
|
|
|
process = file_cmd.write_drive_properties(file_name, properties)
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(message=process["msg"])
|
2021-09-19 21:29:01 +00:00
|
|
|
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2021-09-19 21:29:01 +00:00
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/config/save", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2021-02-01 18:24:59 +00:00
|
|
|
def config_save():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Saves a config file to disk
|
|
|
|
"""
|
2022-10-24 02:05:29 +00:00
|
|
|
file_name = Path(request.form.get("name") + f".{CONFIG_FILE_SUFFIX}").name
|
2021-02-01 18:24:59 +00:00
|
|
|
|
2022-02-27 05:46:35 +00:00
|
|
|
process = file_cmd.write_config(file_name)
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(message=process["msg"])
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-02-01 18:24:59 +00:00
|
|
|
|
|
|
|
|
2023-01-28 22:34:34 +00:00
|
|
|
@APP.route("/config/action", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2023-01-28 22:34:34 +00:00
|
|
|
def config_action():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2023-01-28 22:34:34 +00:00
|
|
|
Carries out on an operation on the config file
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2023-01-28 22:34:34 +00:00
|
|
|
file_name = Path(request.form.get("name"))
|
|
|
|
safe_path = is_safe_path(file_name)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
Configurable block size, controller/device cleanup, dispatchers per device, bridge setup (#203)
* Use foreach
* Renaming
* Revert "Renaming"
This reverts commit b0554b9c0a052e282625a4565d429313af2b3cc7.
* Manpage updates
* Removed obsolete assertions
* Replaced QWORD by uint64_t and removed respective typedef
* Removed LPCSTR typedef
* Removed LPCTSTR typedef
* Removed LPTSTR typedef
* Renamed SCSI command interface classes
* Renamed xm6.h to rascsi.h
* Moved interface classes to new interfaces subfolder
* Added include
* Fixed compilation issues of 64 bit Ubuntu
* Renaming
* Sort block sizes
* protobuf interface description update
* Fixed handling for sector size for non-disk devices
* Fixed typo
* Fixed comment
* Translate code commends into English, removing redundant ones (#214)
* Comment update
* For other bridge interfaces than eth0 IP address and netmask can be provided
* Added special rule for testing on x86 PCs
* Translated code comments into English, removing some redundant ones in the process, plus fixing typos (#215)
* Translate code commends into English, removing redundant ones
* - Translated all remaining Japanese code comments in src/raspberrypi/ to English, with the exception of cfilesystem.cpp|h
- Removed some redundant comments where the context is obvious from the
code
- Fixed a few typos and mistakes
* Comment update
* Removed unused typedefs
* Added special rule for testing on x86 PCs
* Comment update
* Comment update
* Updated capacity calculation
* Updated protobuf interface to signal parameter support
* Simplified protobuf interface
* Updated rasctl server info output
* Updated logging
* protobuf interface has to return block only if it is configurable
* Updated block size handling
* Improved error message if ID is already in use
* Removed typedef
* Renamed protobuf interface method
* Renaming
* Use protobuf::Messsge instead of protobuf::MessageLite
* default_image_folder cannot be an empty string, removed obsolete check
* Logging update
* Made some error messages more concise
* Removed magic constant
* Updated error message
* Comment update
* Names of removable media drives must be constant and not contain the capacity
* Improved DeviceFactory error handling
* More error handing improvements
* Interface comment update
* Pass interface list to ctapdriver when creating bridge
* Moved initialization code
* Updated rasctl server information output
* Improved handling of MO capacities
* Renaming
* Comment update
* Reject inserting a medium when there is already a medium present (eject first)
* Save list of files in use before dry-run
* Updated rasctl server info message
* Comment update
* Fixed typo
* Cleaned list handling
* Sort devices list by ID *and unit*
* Improved block size check
* Fixed issue with missing method in old Raspberry Pi OS protobuf implementation
* Updated error message
* Improve and fix bugs with saving&loading configuration files for rascsi-web (#218)
* Translate code commends into English, removing redundant ones
* - Translated all remaining Japanese code comments in src/raspberrypi/ to English, with the exception of cfilesystem.cpp|h
- Removed some redundant comments where the context is obvious from the
code
- Fixed a few typos and mistakes
* - Store only file path and name to configuration csv
- Strip known non-file path strings when reading configuration csv (backwards compatibility)
- Validate SCSI ID before attempting to attach a device
* Add comment and TODO
* Partial translation of cfilesystem.h
* Move csv read/write logic into file_cmd.py
* Load default.csv on rascsi-web startup
* Add rudimentary error handling to config loading/saving
* Implement a delete configuration csv file feature. Also rename the delete_image method to delete_file and made it take the full file patch as argument to be consistent with other file operation methods.
* Catch the exception when attempting to exclude SCSI id that is already in use from a list of valid SCSI ids
* Fix error handling when failing to open a csv file for read or write
* Removed unused structures, code and type cleanup
* Use unscoped enums for commands
* SASI Format opcode is 0x06, not 0x04 (see comment in code)
* Removed duplicate command
* Code review, data type updates
* Data type updated, use #pragma once
* Logging update
* Renaming
* Renaming
* Removed duplicate code
* Renaming
* Refactoring
* Removed TODO
* Updated logging
* Comment update
* Comment update
* Updated GetEventStatusNotification
* Removed goto
* Options -h and -v do not require to be the root user (fixes issue #166)
* Updated error messages and exception handling
* Added number of supported LUNs to protobuf interface
* Updated list handling of protobuf interface
* Comment update
* Improved error handling
* Added missing return statement
* Allow empty device list
* Fixed unnecessary detach_all() when config file isn't read (#221)
* Translate code commends into English, removing redundant ones
* - Translated all remaining Japanese code comments in src/raspberrypi/ to English, with the exception of cfilesystem.cpp|h
- Removed some redundant comments where the context is obvious from the
code
- Fixed a few typos and mistakes
* - Store only file path and name to configuration csv
- Strip known non-file path strings when reading configuration csv (backwards compatibility)
- Validate SCSI ID before attempting to attach a device
* Add comment and TODO
* Partial translation of cfilesystem.h
* Move csv read/write logic into file_cmd.py
* Load default.csv on rascsi-web startup
* Add rudimentary error handling to config loading/saving
* Implement a delete configuration csv file feature. Also rename the delete_image method to delete_file and made it take the full file patch as argument to be consistent with other file operation methods.
* Catch the exception when attempting to exclude SCSI id that is already in use from a list of valid SCSI ids
* Fix error handling when failing to open a csv file for read or write
* Run detach_all() only after succeeding to open a file for reading
* Protecting/unprotecing a non-ready medium is considered not possible
* Updated error message
* Extract detaching all devices, add parameter list support
* Comment update
* Fixed typos
* Restore files in use if dry-run fails
* Feature configurable reserved id for rascsi-web (#223)
* Translate code commends into English, removing redundant ones
* - Translated all remaining Japanese code comments in src/raspberrypi/ to English, with the exception of cfilesystem.cpp|h
- Removed some redundant comments where the context is obvious from the
code
- Fixed a few typos and mistakes
* - Store only file path and name to configuration csv
- Strip known non-file path strings when reading configuration csv (backwards compatibility)
- Validate SCSI ID before attempting to attach a device
* Add comment and TODO
* Partial translation of cfilesystem.h
* Move csv read/write logic into file_cmd.py
* Load default.csv on rascsi-web startup
* Add rudimentary error handling to config loading/saving
* Implement a delete configuration csv file feature. Also rename the delete_image method to delete_file and made it take the full file patch as argument to be consistent with other file operation methods.
* Catch the exception when attempting to exclude SCSI id that is already in use from a list of valid SCSI ids
* Fix error handling when failing to open a csv file for read or write
* Run detach_all() only after succeeding to open a file for reading
* Make the reserved SCSI id configurable through an argument to start.sh; make the rascsi-web service reserve 7 by default to maintain current behavior.
* Make it possible to reserve multiple scsi ids in the web ui
* Added support for reserved IDs
* rasctl output update
* Re-ordered logging
* Logging update
* Make use of the newly introduced 'rasctl -r' to have the webui reserve ids on the backend side upon startup (#224)
* Translate code commends into English, removing redundant ones
* - Translated all remaining Japanese code comments in src/raspberrypi/ to English, with the exception of cfilesystem.cpp|h
- Removed some redundant comments where the context is obvious from the
code
- Fixed a few typos and mistakes
* - Store only file path and name to configuration csv
- Strip known non-file path strings when reading configuration csv (backwards compatibility)
- Validate SCSI ID before attempting to attach a device
* Add comment and TODO
* Partial translation of cfilesystem.h
* Move csv read/write logic into file_cmd.py
* Load default.csv on rascsi-web startup
* Add rudimentary error handling to config loading/saving
* Implement a delete configuration csv file feature. Also rename the delete_image method to delete_file and made it take the full file patch as argument to be consistent with other file operation methods.
* Catch the exception when attempting to exclude SCSI id that is already in use from a list of valid SCSI ids
* Fix error handling when failing to open a csv file for read or write
* Run detach_all() only after succeeding to open a file for reading
* Make use of the new 'rasctl -r' command to reserve IDs on the backend side as well.
* Updated string to integer conversions
* Improved string to integer conversion
* Move string to integer conversion to rasutil
* Removed unused variable
* Fixed detach, which did not remove the filename from the filenames set
* Re-added folder to gitignore
* Set/Display patch version
* Fix issue where reserved ids were not reserved again when restarting rascsi-service from within the web ui (#226)
* Translate code commends into English, removing redundant ones
* - Translated all remaining Japanese code comments in src/raspberrypi/ to English, with the exception of cfilesystem.cpp|h
- Removed some redundant comments where the context is obvious from the
code
- Fixed a few typos and mistakes
* - Store only file path and name to configuration csv
- Strip known non-file path strings when reading configuration csv (backwards compatibility)
- Validate SCSI ID before attempting to attach a device
* Add comment and TODO
* Partial translation of cfilesystem.h
* Move csv read/write logic into file_cmd.py
* Load default.csv on rascsi-web startup
* Add rudimentary error handling to config loading/saving
* Implement a delete configuration csv file feature. Also rename the delete_image method to delete_file and made it take the full file patch as argument to be consistent with other file operation methods.
* Catch the exception when attempting to exclude SCSI id that is already in use from a list of valid SCSI ids
* Fix error handling when failing to open a csv file for read or write
* Run detach_all() only after succeeding to open a file for reading
* Make use of the new 'rasctl -r' command to reserve IDs on the backend side as well.
* Make sure reserved SCSI IDs gets reserved again when restarting rascsi-service from within the web ui
* Updated interface comment
* Accept daynaport as legacy type
* Fixed typo
* Remove file from the list of files in use when ejected with a SCSI command
* Check for attached device for INSERT, EJECT, PROTECT, UNPROTECT
* Fixed error handling
* Fixed filepath handling
* Added more device shortcuts to rasctl
* Fixed function declaration
* Extraced ATTACH and DETACH
* Extracted INSERT
* Simplified ProcessCmd
* Comment update
* Fixed memory leak
* Log information on whether a new device is protected or read-only
* Updated errro message
* Updated error message
* Initialize private fields
* Updated rasctl help message
* Added DEVICE_INFO to protobuf interface
* Improved error handling
* DEVICE_INFO supports device list
* Updated server info handling
* Unified result handling with oneof, all commands now return PbResult
* A result can always return a message string
* Fixed typo
* Simplified sending of commands
* Improved error handling
* Removed unused code
* Updated error handling
* Code cleanup
* Comment update
* Updated logging
* Updated error handling
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Added default parameters to device properties
* Return parameters a device was set up with
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Manage default parameters in the respective device
* Do not pass empty parameter string
* Added supports_params flag
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Renaming
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Made logging more consistent
* Updated log level
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Updated logging
* Logging update
* README update
* Added block_count
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Extended property/status display
* Property display update
* Updated error handling
* (Doc only changes) Fix typos and add clarification that SASI is used on Unix workstations
Co-authored-by: Daniel Markstedt <markstedt@gmail.com>
Co-authored-by: Tony Kuker <akuker@gmail.com>
2021-09-15 01:23:04 +00:00
|
|
|
|
|
|
|
if "load" in request.form:
|
2022-02-27 05:46:35 +00:00
|
|
|
process = file_cmd.read_config(file_name)
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(message=process["msg"])
|
|
|
|
|
|
|
|
return response(error=True, message=process["msg"])
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2021-12-28 20:09:47 +00:00
|
|
|
if "delete" in request.form:
|
2023-01-28 22:34:34 +00:00
|
|
|
process = file_cmd.delete_file(Path(CFG_DIR) / file_name)
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(message=process["msg"])
|
2021-02-01 18:24:59 +00:00
|
|
|
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-02-01 18:24:59 +00:00
|
|
|
|
2023-01-28 22:34:34 +00:00
|
|
|
if "send" in request.form:
|
|
|
|
return send_from_directory(CFG_DIR, str(file_name), as_attachment=True)
|
|
|
|
|
|
|
|
return response(
|
|
|
|
error=True,
|
|
|
|
message="No known operation in request header. Expected one of: load, delete, send",
|
|
|
|
)
|
2021-11-07 00:25:02 +00:00
|
|
|
|
|
|
|
|
2022-09-27 00:44:41 +00:00
|
|
|
@APP.route("/files/diskinfo", methods=["POST"])
|
|
|
|
def show_diskinfo():
|
|
|
|
"""
|
|
|
|
Displays disk image info
|
|
|
|
"""
|
2022-10-24 02:05:29 +00:00
|
|
|
file_name = Path(request.form.get("file_name"))
|
|
|
|
safe_path = is_safe_path(file_name)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
2022-12-05 17:58:23 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
2023-03-24 03:07:19 +00:00
|
|
|
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
2022-11-30 05:19:17 +00:00
|
|
|
returncode, diskinfo = sys_cmd.get_diskinfo(Path(server_info["image_dir"]) / file_name)
|
2022-09-27 00:44:41 +00:00
|
|
|
if returncode == 0:
|
|
|
|
return response(
|
|
|
|
template="diskinfo.html",
|
2022-12-25 15:23:16 +00:00
|
|
|
page_title=_("PiSCSI Image Info"),
|
2022-10-24 02:05:29 +00:00
|
|
|
file_name=str(file_name),
|
2022-09-27 00:44:41 +00:00
|
|
|
diskinfo=diskinfo,
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2022-09-27 00:44:41 +00:00
|
|
|
|
|
|
|
return response(
|
|
|
|
error=True,
|
2022-11-30 05:19:17 +00:00
|
|
|
message=_("An error occurred when getting disk info: %(error)s", error=diskinfo),
|
2022-09-27 00:44:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-03 19:46:18 +00:00
|
|
|
@APP.route("/sys/manpage", methods=["GET"])
|
|
|
|
def show_manpage():
|
|
|
|
"""
|
|
|
|
Displays manpage
|
|
|
|
"""
|
2022-12-05 17:58:23 +00:00
|
|
|
app_allowlist = ["piscsi", "scsictl", "scsidump", "scsimon"]
|
2022-10-03 19:46:18 +00:00
|
|
|
|
2022-11-30 05:19:17 +00:00
|
|
|
app = request.args.get("app", type=str)
|
2022-10-03 19:46:18 +00:00
|
|
|
|
|
|
|
if app not in app_allowlist:
|
2022-12-05 17:58:23 +00:00
|
|
|
return response(error=True, message=_("%(app)s is not a recognized PiSCSI app", app=app))
|
2022-10-03 19:46:18 +00:00
|
|
|
|
2022-10-04 13:38:15 +00:00
|
|
|
file_path = f"{WEB_DIR}/../../../doc/{app}.1"
|
|
|
|
html_to_strip = [
|
2022-11-30 05:19:17 +00:00
|
|
|
"Content-type",
|
|
|
|
"!DOCTYPE",
|
|
|
|
"<HTML>",
|
|
|
|
"<HEAD>",
|
|
|
|
"<BODY>",
|
|
|
|
"<H1>",
|
|
|
|
]
|
2022-10-03 19:46:18 +00:00
|
|
|
|
2022-10-04 13:38:15 +00:00
|
|
|
returncode, manpage = sys_cmd.get_manpage(file_path)
|
2022-10-03 19:46:18 +00:00
|
|
|
if returncode == 0:
|
|
|
|
formatted_manpage = ""
|
|
|
|
for line in manpage.splitlines(True):
|
2022-10-04 13:38:15 +00:00
|
|
|
# Make URIs compatible with the Flask webapp
|
|
|
|
if "/?1+" in line:
|
|
|
|
line = line.replace("/?1+", "manpage?app=")
|
|
|
|
# Strip out useless hyperlink
|
|
|
|
elif "man2html" in line:
|
2022-11-30 05:19:17 +00:00
|
|
|
line = line.replace('<A HREF="/">man2html</A>', "man2html")
|
2022-10-04 13:38:15 +00:00
|
|
|
if not any(ele in line for ele in html_to_strip):
|
2022-10-03 19:46:18 +00:00
|
|
|
formatted_manpage += line
|
|
|
|
|
|
|
|
return response(
|
|
|
|
template="manpage.html",
|
2022-12-25 15:23:16 +00:00
|
|
|
page_title=_("PiSCSI Manual"),
|
2022-10-03 19:46:18 +00:00
|
|
|
app=app,
|
|
|
|
manpage=formatted_manpage,
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2022-10-03 19:46:18 +00:00
|
|
|
|
|
|
|
return response(
|
|
|
|
error=True,
|
2022-12-25 15:23:16 +00:00
|
|
|
message=_("An error occurred when accessing manual page: %(error)s", error=manpage),
|
2022-10-03 19:46:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/logs/show", methods=["POST"])
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
def show_logs():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Displays system logs
|
|
|
|
"""
|
2022-02-28 17:49:48 +00:00
|
|
|
lines = request.form.get("lines")
|
|
|
|
scope = request.form.get("scope")
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-02-27 05:46:35 +00:00
|
|
|
returncode, logs = sys_cmd.get_logs(lines, scope)
|
|
|
|
if returncode == 0:
|
2022-09-27 00:44:41 +00:00
|
|
|
return response(
|
|
|
|
template="logs.html",
|
2022-12-25 15:23:16 +00:00
|
|
|
page_title=_("PiSCSI System Logs"),
|
2022-09-27 00:44:41 +00:00
|
|
|
scope=scope,
|
|
|
|
lines=lines,
|
|
|
|
logs=logs,
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2022-09-27 00:44:41 +00:00
|
|
|
return response(
|
|
|
|
error=True,
|
2022-11-30 05:19:17 +00:00
|
|
|
message=_("An error occurred when fetching logs: %(error)s", error=logs),
|
2022-09-27 00:44:41 +00:00
|
|
|
)
|
2021-02-01 18:24:59 +00:00
|
|
|
|
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/logs/level", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
def log_level():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-12-05 17:58:23 +00:00
|
|
|
Sets PiSCSI backend log level
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
level = request.form.get("level") or "info"
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
process = piscsi_cmd.set_log_level(level)
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(message=_("Log level set to %(value)s", value=level))
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-11-07 00:25:02 +00:00
|
|
|
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
|
2022-02-20 17:49:23 +00:00
|
|
|
@APP.route("/scsi/attach_device", methods=["POST"])
|
2022-02-15 12:06:27 +00:00
|
|
|
@login_required
|
2022-02-20 17:49:23 +00:00
|
|
|
def attach_device():
|
2022-02-15 12:06:27 +00:00
|
|
|
"""
|
2022-02-21 17:27:31 +00:00
|
|
|
Attaches a peripheral device that doesn't take an image file as argument
|
2022-02-15 12:06:27 +00:00
|
|
|
"""
|
2022-10-06 17:00:57 +00:00
|
|
|
scsi_id = request.form.get("scsi_id")
|
|
|
|
unit = request.form.get("unit")
|
|
|
|
device_type = request.form.get("type")
|
|
|
|
drive_name = request.form.get("drive_name")
|
|
|
|
|
|
|
|
if not scsi_id:
|
|
|
|
return response(error=True, message=_("No SCSI ID specified"))
|
|
|
|
|
|
|
|
# Attempt to fetch the drive properties based on drive name
|
2022-10-01 23:51:30 +00:00
|
|
|
drive_props = None
|
2022-10-06 17:00:57 +00:00
|
|
|
if drive_name:
|
2022-12-05 17:58:23 +00:00
|
|
|
for drive in APP.config["PISCSI_DRIVE_PROPERTIES"]:
|
2022-10-06 17:00:57 +00:00
|
|
|
if drive["name"] == drive_name:
|
|
|
|
drive_props = drive
|
|
|
|
break
|
|
|
|
|
|
|
|
# Collect device parameters into a dictionary
|
|
|
|
PARAM_PREFIX = "param_"
|
|
|
|
params = {}
|
2022-02-19 08:04:14 +00:00
|
|
|
for item in request.form:
|
2022-10-06 17:00:57 +00:00
|
|
|
if item.startswith(PARAM_PREFIX):
|
2022-02-20 17:49:23 +00:00
|
|
|
param = request.form.get(item)
|
|
|
|
if param:
|
2022-10-06 17:00:57 +00:00
|
|
|
params.update({item.replace(PARAM_PREFIX, ""): param})
|
2022-02-20 17:49:23 +00:00
|
|
|
|
2023-07-27 01:19:22 +00:00
|
|
|
return_message = "Attached %(device_type)s to SCSI ID %(id_number)s LUN %(unit_number)s"
|
2022-02-20 17:49:23 +00:00
|
|
|
if "interface" in params.keys():
|
2022-02-27 05:46:35 +00:00
|
|
|
bridge_status = is_bridge_configured(params["interface"])
|
2022-10-05 21:14:48 +00:00
|
|
|
if not bridge_status["status"]:
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(error=True, message=bridge_status["msg"])
|
2023-07-27 01:19:22 +00:00
|
|
|
return_message = return_message + " - " + bridge_status["msg"]
|
2022-02-19 08:04:14 +00:00
|
|
|
|
|
|
|
kwargs = {
|
2022-11-30 05:19:17 +00:00
|
|
|
"unit": int(unit),
|
|
|
|
"device_type": device_type,
|
|
|
|
"params": params,
|
|
|
|
}
|
2022-10-01 23:51:30 +00:00
|
|
|
if drive_props:
|
|
|
|
kwargs["vendor"] = drive_props["vendor"]
|
|
|
|
kwargs["product"] = drive_props["product"]
|
|
|
|
kwargs["revision"] = drive_props["revision"]
|
|
|
|
kwargs["block_size"] = drive_props["block_size"]
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
process = piscsi_cmd.attach_device(scsi_id, **kwargs)
|
2022-02-15 12:06:27 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
|
|
|
if process["status"]:
|
2022-11-30 05:19:17 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
2023-07-27 01:19:22 +00:00
|
|
|
return_message,
|
2022-11-30 05:19:17 +00:00
|
|
|
device_type=get_device_name(device_type),
|
|
|
|
id_number=scsi_id,
|
|
|
|
unit_number=unit,
|
|
|
|
)
|
|
|
|
)
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2020-12-31 01:39:32 +00:00
|
|
|
|
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/scsi/attach", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2022-02-19 08:04:14 +00:00
|
|
|
def attach_image():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Attaches a file image as a device
|
|
|
|
"""
|
2021-02-01 17:39:50 +00:00
|
|
|
file_name = request.form.get("file_name")
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
file_size = request.form.get("file_size")
|
2021-02-01 17:39:50 +00:00
|
|
|
scsi_id = request.form.get("scsi_id")
|
2021-11-07 00:25:02 +00:00
|
|
|
unit = request.form.get("unit")
|
2021-09-26 03:27:43 +00:00
|
|
|
device_type = request.form.get("type")
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-10-06 17:00:57 +00:00
|
|
|
if not scsi_id:
|
|
|
|
return response(error=True, message=_("No SCSI ID specified"))
|
2022-10-03 18:47:08 +00:00
|
|
|
if not file_name:
|
|
|
|
return response(error=True, message=_("No image file to insert"))
|
|
|
|
|
2022-02-19 08:04:14 +00:00
|
|
|
kwargs = {"unit": int(unit), "params": {"file": file_name}}
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
|
2022-02-21 17:27:31 +00:00
|
|
|
if device_type:
|
2021-09-26 03:27:43 +00:00
|
|
|
kwargs["device_type"] = device_type
|
2022-12-05 17:58:23 +00:00
|
|
|
device_types = piscsi_cmd.get_device_types()
|
2022-02-21 17:27:31 +00:00
|
|
|
expected_block_size = min(device_types["device_types"][device_type]["block_sizes"])
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2021-09-19 21:29:01 +00:00
|
|
|
# Attempt to load the device properties file:
|
2021-11-07 00:25:02 +00:00
|
|
|
# same file name with PROPERTIES_SUFFIX appended
|
2022-10-22 15:01:08 +00:00
|
|
|
drive_properties = Path(CFG_DIR) / f"{file_name}.{PROPERTIES_SUFFIX}"
|
|
|
|
if drive_properties.is_file():
|
2022-02-27 05:46:35 +00:00
|
|
|
process = file_cmd.read_drive_properties(drive_properties)
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2021-11-07 00:25:02 +00:00
|
|
|
if not process["status"]:
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
conf = process["conf"]
|
|
|
|
kwargs["vendor"] = conf["vendor"]
|
|
|
|
kwargs["product"] = conf["product"]
|
|
|
|
kwargs["revision"] = conf["revision"]
|
|
|
|
kwargs["block_size"] = conf["block_size"]
|
2021-10-14 01:00:41 +00:00
|
|
|
expected_block_size = conf["block_size"]
|
2021-09-19 21:29:01 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
process = piscsi_cmd.attach_device(scsi_id, **kwargs)
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2021-10-14 01:00:41 +00:00
|
|
|
if int(file_size) % int(expected_block_size):
|
2022-10-24 02:05:29 +00:00
|
|
|
logging.warning(
|
|
|
|
"The image file size %s bytes is not a multiple of %s. "
|
2022-12-05 17:58:23 +00:00
|
|
|
"PiSCSI will ignore the trailing data. "
|
2022-05-02 19:42:09 +00:00
|
|
|
"The image may be corrupted, so proceed with caution.",
|
2022-10-24 02:05:29 +00:00
|
|
|
file_size,
|
|
|
|
expected_block_size,
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
|
|
|
"Attached %(file_name)s as %(device_type)s to "
|
|
|
|
"SCSI ID %(id_number)s LUN %(unit_number)s",
|
|
|
|
file_name=file_name,
|
|
|
|
device_type=get_device_name(device_type),
|
|
|
|
id_number=scsi_id,
|
|
|
|
unit_number=unit,
|
|
|
|
)
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2022-09-25 23:00:18 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/scsi/detach_all", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2021-02-01 18:24:59 +00:00
|
|
|
def detach_all_devices():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Detaches all currently attached devices
|
|
|
|
"""
|
2022-12-05 17:58:23 +00:00
|
|
|
process = piscsi_cmd.detach_all()
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(message=_("Detached all SCSI devices"))
|
2021-02-01 18:24:59 +00:00
|
|
|
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-02-01 18:24:59 +00:00
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
|
|
|
|
@APP.route("/scsi/detach", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2020-12-31 01:39:32 +00:00
|
|
|
def detach():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Detaches a specified device
|
|
|
|
"""
|
2021-02-01 17:39:50 +00:00
|
|
|
scsi_id = request.form.get("scsi_id")
|
2021-11-07 00:25:02 +00:00
|
|
|
unit = request.form.get("unit")
|
2022-12-05 17:58:23 +00:00
|
|
|
process = piscsi_cmd.detach_by_id(scsi_id, unit)
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2022-11-30 05:19:17 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
|
|
|
"Detached SCSI ID %(id_number)s LUN %(unit_number)s",
|
|
|
|
id_number=scsi_id,
|
|
|
|
unit_number=unit,
|
|
|
|
)
|
|
|
|
)
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/scsi/eject", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2020-12-31 01:39:32 +00:00
|
|
|
def eject():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Ejects a specified removable device image, but keeps the device attached
|
|
|
|
"""
|
2021-02-01 17:39:50 +00:00
|
|
|
scsi_id = request.form.get("scsi_id")
|
2021-11-07 00:25:02 +00:00
|
|
|
unit = request.form.get("unit")
|
2021-10-13 09:03:31 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
process = piscsi_cmd.eject_by_id(scsi_id, unit)
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2022-11-30 05:19:17 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
|
|
|
"Ejected SCSI ID %(id_number)s LUN %(unit_number)s",
|
|
|
|
id_number=scsi_id,
|
|
|
|
unit_number=unit,
|
|
|
|
)
|
|
|
|
)
|
2022-09-25 23:00:18 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
|
|
|
|
@APP.route("/scsi/info", methods=["POST"])
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
def device_info():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-09-27 00:44:41 +00:00
|
|
|
Displays detailed info for all attached devices
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-12-05 17:58:23 +00:00
|
|
|
process = piscsi_cmd.list_devices()
|
2022-09-27 00:44:41 +00:00
|
|
|
if process["status"]:
|
|
|
|
return response(
|
|
|
|
template="deviceinfo.html",
|
2022-12-25 15:23:16 +00:00
|
|
|
page_title=_("PiSCSI Device Info"),
|
2022-09-27 00:44:41 +00:00
|
|
|
devices=process["device_list"],
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2021-09-19 21:29:01 +00:00
|
|
|
|
2022-09-27 00:44:41 +00:00
|
|
|
return response(error=True, message=_("No devices attached"))
|
2022-09-25 23:00:18 +00:00
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2021-11-07 02:11:17 +00:00
|
|
|
@APP.route("/scsi/reserve", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2021-11-07 02:11:17 +00:00
|
|
|
def reserve_id():
|
|
|
|
"""
|
|
|
|
Reserves a SCSI ID and stores the memo for that reservation
|
|
|
|
"""
|
|
|
|
scsi_id = request.form.get("scsi_id")
|
|
|
|
memo = request.form.get("memo")
|
2022-12-05 17:58:23 +00:00
|
|
|
reserved_ids = piscsi_cmd.get_reserved_ids()["ids"]
|
2021-11-07 02:11:17 +00:00
|
|
|
reserved_ids.extend(scsi_id)
|
2022-12-05 17:58:23 +00:00
|
|
|
process = piscsi_cmd.reserve_scsi_ids(reserved_ids)
|
2021-11-07 02:11:17 +00:00
|
|
|
if process["status"]:
|
|
|
|
RESERVATIONS[int(scsi_id)] = memo
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(message=_("Reserved SCSI ID %(id_number)s", id_number=scsi_id))
|
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-11-07 02:11:17 +00:00
|
|
|
|
|
|
|
|
2022-02-21 19:31:38 +00:00
|
|
|
@APP.route("/scsi/release", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2022-02-21 19:31:38 +00:00
|
|
|
def release_id():
|
2021-11-07 02:11:17 +00:00
|
|
|
"""
|
2022-02-21 19:31:38 +00:00
|
|
|
Releases the reservation of a SCSI ID as well as the memo for the reservation
|
2021-11-07 02:11:17 +00:00
|
|
|
"""
|
|
|
|
scsi_id = request.form.get("scsi_id")
|
2022-12-05 17:58:23 +00:00
|
|
|
reserved_ids = piscsi_cmd.get_reserved_ids()["ids"]
|
2021-11-07 02:11:17 +00:00
|
|
|
reserved_ids.remove(scsi_id)
|
2022-12-05 17:58:23 +00:00
|
|
|
process = piscsi_cmd.reserve_scsi_ids(reserved_ids)
|
2021-11-07 02:11:17 +00:00
|
|
|
if process["status"]:
|
|
|
|
RESERVATIONS[int(scsi_id)] = ""
|
2022-11-30 05:19:17 +00:00
|
|
|
return response(
|
|
|
|
message=_("Released the reservation for SCSI ID %(id_number)s", id_number=scsi_id)
|
|
|
|
)
|
2021-11-07 02:11:17 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-11-07 02:11:17 +00:00
|
|
|
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-11-20 18:20:32 +00:00
|
|
|
@APP.route("/sys/rename", methods=["POST"])
|
|
|
|
@login_required
|
|
|
|
def rename_system():
|
|
|
|
"""
|
|
|
|
Changes the hostname of the system
|
|
|
|
"""
|
|
|
|
name = str(request.form.get("system_name"))
|
|
|
|
max_length = 120
|
|
|
|
|
|
|
|
if len(name) <= max_length:
|
|
|
|
process = sys_cmd.set_pretty_host(name)
|
|
|
|
if process:
|
|
|
|
if name:
|
|
|
|
return response(message=_("System name changed to '%(name)s'.", name=name))
|
|
|
|
return response(message=_("System name reset to default."))
|
|
|
|
|
|
|
|
return response(error=True, message=_("Failed to change system name."))
|
|
|
|
|
|
|
|
|
2022-11-18 00:21:18 +00:00
|
|
|
@APP.route("/sys/reboot", methods=["POST"])
|
2021-12-14 03:37:28 +00:00
|
|
|
@login_required
|
|
|
|
def restart():
|
|
|
|
"""
|
2022-11-18 00:21:18 +00:00
|
|
|
Restarts the system
|
2021-12-14 03:37:28 +00:00
|
|
|
"""
|
2022-11-18 00:21:18 +00:00
|
|
|
returncode, message = sys_cmd.reboot_system()
|
|
|
|
if not returncode:
|
|
|
|
return response()
|
|
|
|
|
|
|
|
return response(error=True, message=message)
|
2021-12-14 03:37:28 +00:00
|
|
|
|
|
|
|
|
2022-11-18 00:21:18 +00:00
|
|
|
@APP.route("/sys/shutdown", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2020-12-31 01:39:32 +00:00
|
|
|
def shutdown():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-11-18 00:21:18 +00:00
|
|
|
Shuts down the system
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-11-18 00:21:18 +00:00
|
|
|
returncode, message = sys_cmd.shutdown_system()
|
|
|
|
if not returncode:
|
|
|
|
return response()
|
|
|
|
|
|
|
|
return response(error=True, message=message)
|
2020-12-31 01:39:32 +00:00
|
|
|
|
|
|
|
|
2022-12-24 00:13:52 +00:00
|
|
|
@APP.route("/files/create_iso", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2021-10-26 20:03:29 +00:00
|
|
|
def download_to_iso():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-10-24 02:05:29 +00:00
|
|
|
Downloads a file and creates a CD-ROM image with the specified file system and the file
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2021-02-01 17:39:50 +00:00
|
|
|
url = request.form.get("url")
|
2022-10-24 02:05:29 +00:00
|
|
|
iso_type = request.form.get("type")
|
2022-12-24 00:13:52 +00:00
|
|
|
local_file = request.form.get("file")
|
2022-10-24 02:05:29 +00:00
|
|
|
|
|
|
|
if iso_type == "HFS":
|
|
|
|
iso_args = ["-hfs"]
|
|
|
|
elif iso_type == "ISO-9660 Level 1":
|
|
|
|
iso_args = ["-iso-level", "1"]
|
|
|
|
elif iso_type == "ISO-9660 Level 2":
|
|
|
|
iso_args = ["-iso-level", "2"]
|
|
|
|
elif iso_type == "ISO-9660 Level 3":
|
|
|
|
iso_args = ["-iso-level", "3"]
|
|
|
|
elif iso_type == "Joliet":
|
|
|
|
iso_args = ["-J"]
|
|
|
|
elif iso_type == "Rock Ridge":
|
|
|
|
iso_args = ["-r"]
|
|
|
|
else:
|
|
|
|
return response(
|
|
|
|
error=True,
|
2022-11-30 05:19:17 +00:00
|
|
|
message=_("%(iso_type)s is not a valid CD-ROM format.", iso_type=iso_type),
|
2022-10-24 02:05:29 +00:00
|
|
|
)
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2022-12-24 00:13:52 +00:00
|
|
|
if url:
|
|
|
|
process = file_cmd.download_file_to_iso(url, *iso_args)
|
|
|
|
elif local_file:
|
|
|
|
server_info = piscsi_cmd.get_server_info()
|
|
|
|
file_path = Path(server_info["image_dir"]) / local_file
|
|
|
|
iso_path = Path(str(file_path) + ".iso")
|
|
|
|
process = file_cmd.generate_iso(iso_path, file_path, *iso_args)
|
|
|
|
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2022-09-25 23:00:18 +00:00
|
|
|
if not process["status"]:
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(
|
|
|
|
error=True,
|
|
|
|
message=_(
|
|
|
|
"The following error occurred when creating the CD-ROM image: %(error)s",
|
|
|
|
error=process["msg"],
|
|
|
|
),
|
|
|
|
)
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
2023-01-15 15:38:41 +00:00
|
|
|
"CD-ROM image %(file_name)s with type %(iso_type)s was created.",
|
2022-10-24 02:05:29 +00:00
|
|
|
file_name=process["file_name"],
|
|
|
|
iso_type=iso_type,
|
|
|
|
),
|
|
|
|
)
|
2021-10-26 20:03:29 +00:00
|
|
|
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-09-28 00:38:34 +00:00
|
|
|
@APP.route("/files/download_url", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2022-09-28 00:38:34 +00:00
|
|
|
def download_file():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-11-18 00:21:18 +00:00
|
|
|
Downloads a remote file onto the images dir on the system
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-09-28 00:38:34 +00:00
|
|
|
destination = request.form.get("destination")
|
2021-02-01 17:39:50 +00:00
|
|
|
url = request.form.get("url")
|
2023-03-05 00:57:32 +00:00
|
|
|
images_subdir = request.form.get("images_subdir")
|
|
|
|
shared_subdir = request.form.get("shared_subdir")
|
|
|
|
if destination == "disk_images":
|
|
|
|
safe_path = is_safe_path(Path("." + images_subdir))
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return make_response(safe_path["msg"], 403)
|
2022-12-05 17:58:23 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
2023-03-05 00:57:32 +00:00
|
|
|
destination_dir = server_info["image_dir"] + images_subdir
|
|
|
|
elif destination == "shared_files":
|
|
|
|
safe_path = is_safe_path(Path("." + shared_subdir))
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return make_response(safe_path["msg"], 403)
|
|
|
|
destination_dir = FILE_SERVER_DIR + shared_subdir
|
|
|
|
else:
|
|
|
|
return response(error=True, message=_("Unknown destination"))
|
|
|
|
|
2022-09-28 00:38:34 +00:00
|
|
|
process = file_cmd.download_to_dir(url, destination_dir, Path(url).name)
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(message=process["msg"])
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(
|
|
|
|
error=True,
|
|
|
|
message=_(
|
|
|
|
"The following error occurred when downloading: %(error)s",
|
|
|
|
error=process["msg"],
|
|
|
|
),
|
|
|
|
)
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/files/upload", methods=["POST"])
|
2021-09-22 05:51:06 +00:00
|
|
|
def upload_file():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-11-18 00:21:18 +00:00
|
|
|
Uploads a file from the local computer to the images dir on the system
|
2021-11-07 00:25:02 +00:00
|
|
|
Depending on the Dropzone.js JavaScript library
|
|
|
|
"""
|
2021-12-13 00:54:15 +00:00
|
|
|
# Due to the embedded javascript library, we cannot use the @login_required decorator
|
2022-02-27 05:46:35 +00:00
|
|
|
auth = auth_active(AUTH_GROUP)
|
2021-11-27 04:41:10 +00:00
|
|
|
if auth["status"] and "username" not in session:
|
|
|
|
return make_response(auth["msg"], 403)
|
|
|
|
|
2022-09-28 00:38:34 +00:00
|
|
|
destination = request.form.get("destination")
|
2023-03-05 00:57:32 +00:00
|
|
|
images_subdir = request.form.get("images_subdir")
|
|
|
|
shared_subdir = request.form.get("shared_subdir")
|
2023-01-27 02:10:33 +00:00
|
|
|
if destination == "disk_images":
|
2023-03-05 00:57:32 +00:00
|
|
|
safe_path = is_safe_path(Path("." + images_subdir))
|
2023-02-25 01:28:58 +00:00
|
|
|
if not safe_path["status"]:
|
|
|
|
return make_response(safe_path["msg"], 403)
|
2022-12-05 17:58:23 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
2023-03-05 00:57:32 +00:00
|
|
|
destination_dir = server_info["image_dir"] + images_subdir
|
2023-01-27 02:10:33 +00:00
|
|
|
elif destination == "shared_files":
|
2023-03-05 00:57:32 +00:00
|
|
|
safe_path = is_safe_path(Path("." + shared_subdir))
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return make_response(safe_path["msg"], 403)
|
|
|
|
destination_dir = FILE_SERVER_DIR + shared_subdir
|
2023-01-28 22:34:34 +00:00
|
|
|
elif destination == "piscsi_config":
|
|
|
|
destination_dir = CFG_DIR
|
2023-01-27 02:10:33 +00:00
|
|
|
else:
|
2023-03-05 00:57:32 +00:00
|
|
|
return make_response(_("Unknown destination"), 403)
|
2023-01-27 02:10:33 +00:00
|
|
|
|
2022-09-28 00:38:34 +00:00
|
|
|
return upload_with_dropzonejs(destination_dir)
|
2020-12-31 01:39:32 +00:00
|
|
|
|
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/files/create", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2020-12-31 01:39:32 +00:00
|
|
|
def create_file():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Creates an empty image file in the images dir
|
|
|
|
"""
|
2022-10-24 02:05:29 +00:00
|
|
|
file_name = Path(request.form.get("file_name"))
|
2022-11-30 05:19:17 +00:00
|
|
|
size = int(request.form.get("size")) * 1024 * 1024
|
2021-07-31 15:52:09 +00:00
|
|
|
file_type = request.form.get("type")
|
2022-10-02 02:56:19 +00:00
|
|
|
drive_name = request.form.get("drive_name")
|
2022-11-01 23:43:24 +00:00
|
|
|
drive_format = request.form.get("drive_format")
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
safe_path = is_safe_path(file_name)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
|
|
|
full_file_name = f"{file_name}.{file_type}"
|
2023-01-27 05:51:59 +00:00
|
|
|
|
|
|
|
server_info = piscsi_cmd.get_server_info()
|
|
|
|
process = file_cmd.create_empty_image(Path(server_info["image_dir"]) / full_file_name, size)
|
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2022-10-02 02:56:19 +00:00
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-11-01 23:43:24 +00:00
|
|
|
message_postfix = ""
|
|
|
|
|
2022-12-04 14:31:57 +00:00
|
|
|
# Formatting and injecting driver, if one is chosen
|
2022-11-01 23:43:24 +00:00
|
|
|
if drive_format:
|
|
|
|
volume_name = f"HD {size / 1024 / 1024:0.0f}M"
|
|
|
|
known_formats = [
|
2022-11-30 05:19:17 +00:00
|
|
|
"Lido 7.56",
|
|
|
|
"SpeedTools 3.6",
|
|
|
|
"FAT16",
|
|
|
|
"FAT32",
|
|
|
|
]
|
2022-11-01 23:43:24 +00:00
|
|
|
message_postfix = f" ({drive_format})"
|
|
|
|
|
|
|
|
if drive_format not in known_formats:
|
|
|
|
return response(
|
|
|
|
error=True,
|
|
|
|
message=_(
|
|
|
|
"%(drive_format)s is not a valid hard disk format.",
|
|
|
|
drive_format=drive_format,
|
2022-11-30 05:19:17 +00:00
|
|
|
),
|
2022-11-01 23:43:24 +00:00
|
|
|
)
|
|
|
|
elif drive_format.startswith("FAT"):
|
|
|
|
if drive_format == "FAT16":
|
|
|
|
fat_size = "16"
|
|
|
|
elif drive_format == "FAT32":
|
|
|
|
fat_size = "32"
|
|
|
|
else:
|
|
|
|
return response(
|
|
|
|
error=True,
|
|
|
|
message=_(
|
|
|
|
"%(drive_format)s is not a valid hard disk format.",
|
|
|
|
drive_format=drive_format,
|
2022-11-30 05:19:17 +00:00
|
|
|
),
|
2022-11-01 23:43:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
process = file_cmd.partition_disk(full_file_name, volume_name, "FAT")
|
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
|
|
|
|
|
|
|
process = file_cmd.format_fat(
|
2022-11-30 05:19:17 +00:00
|
|
|
full_file_name,
|
|
|
|
# FAT volume labels are max 11 chars
|
|
|
|
volume_name[:11],
|
|
|
|
fat_size,
|
|
|
|
)
|
2022-11-01 23:43:24 +00:00
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
|
|
|
|
|
|
|
else:
|
|
|
|
driver_base_path = Path(f"{WEB_DIR}/../../../mac-hard-disk-drivers")
|
|
|
|
process = file_cmd.partition_disk(full_file_name, volume_name, "HFS")
|
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
|
|
|
|
|
|
|
process = file_cmd.format_hfs(
|
2022-11-30 05:19:17 +00:00
|
|
|
full_file_name,
|
|
|
|
volume_name,
|
|
|
|
driver_base_path / Path(drive_format.replace(" ", "-") + ".img"),
|
|
|
|
)
|
2022-11-01 23:43:24 +00:00
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
|
|
|
|
2022-10-02 02:56:19 +00:00
|
|
|
# Creating the drive properties file, if one is chosen
|
|
|
|
if drive_name:
|
2022-12-05 17:58:23 +00:00
|
|
|
properties = get_properties_by_drive_name(APP.config["PISCSI_DRIVE_PROPERTIES"], drive_name)
|
2022-11-16 06:28:27 +00:00
|
|
|
if properties:
|
|
|
|
prop_file_name = f"{full_file_name}.{PROPERTIES_SUFFIX}"
|
|
|
|
process = file_cmd.write_drive_properties(prop_file_name, properties)
|
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
2022-10-02 02:56:19 +00:00
|
|
|
|
2022-11-16 06:28:27 +00:00
|
|
|
return response(
|
|
|
|
status_code=201,
|
|
|
|
message=_(
|
|
|
|
"Image file with properties created: %(file_name)s%(drive_format)s",
|
|
|
|
file_name=full_file_name,
|
|
|
|
drive_format=message_postfix,
|
|
|
|
),
|
|
|
|
image=full_file_name,
|
|
|
|
)
|
2022-10-24 02:05:29 +00:00
|
|
|
|
2022-10-04 13:38:15 +00:00
|
|
|
return response(
|
|
|
|
status_code=201,
|
2022-11-01 23:43:24 +00:00
|
|
|
message=_(
|
|
|
|
"Image file created: %(file_name)s%(drive_format)s",
|
|
|
|
file_name=full_file_name,
|
|
|
|
drive_format=message_postfix,
|
|
|
|
),
|
2022-10-04 13:38:15 +00:00
|
|
|
image=full_file_name,
|
2022-10-24 02:05:29 +00:00
|
|
|
)
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2023-01-27 02:10:53 +00:00
|
|
|
@APP.route("/files/download_image", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2023-01-27 02:10:53 +00:00
|
|
|
def download_image():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2023-01-27 02:10:53 +00:00
|
|
|
Downloads a file from the image dir to the local computer
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-10-24 02:05:29 +00:00
|
|
|
file_name = Path(request.form.get("file"))
|
|
|
|
safe_path = is_safe_path(file_name)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
2022-12-05 17:58:23 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
2022-10-24 02:05:29 +00:00
|
|
|
return send_from_directory(server_info["image_dir"], str(file_name), as_attachment=True)
|
2020-12-31 01:39:32 +00:00
|
|
|
|
|
|
|
|
2023-01-27 02:10:53 +00:00
|
|
|
@APP.route("/files/download_config", methods=["POST"])
|
|
|
|
@login_required
|
|
|
|
def download_config():
|
|
|
|
"""
|
|
|
|
Downloads a file from the config dir to the local computer
|
|
|
|
"""
|
|
|
|
file_name = Path(request.form.get("file"))
|
|
|
|
safe_path = is_safe_path(file_name)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
|
|
|
return send_from_directory(CFG_DIR, str(file_name), as_attachment=True)
|
|
|
|
|
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
@APP.route("/files/delete", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2020-12-31 01:39:32 +00:00
|
|
|
def delete():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
|
|
|
Deletes a specified file in the images dir
|
|
|
|
"""
|
2022-10-24 02:05:29 +00:00
|
|
|
file_name = Path(request.form.get("file_name"))
|
|
|
|
safe_path = is_safe_path(file_name)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
2023-01-27 05:51:59 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
|
|
|
process = file_cmd.delete_file(Path(server_info["image_dir"]) / file_name)
|
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2022-09-25 23:00:18 +00:00
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
|
|
|
|
2021-09-19 21:29:01 +00:00
|
|
|
# Delete the drive properties file, if it exists
|
2022-10-09 20:50:20 +00:00
|
|
|
prop_file_path = Path(CFG_DIR) / f"{file_name}.{PROPERTIES_SUFFIX}"
|
|
|
|
if prop_file_path.is_file():
|
2022-02-27 05:46:35 +00:00
|
|
|
process = file_cmd.delete_file(prop_file_path)
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2021-11-07 00:25:02 +00:00
|
|
|
if process["status"]:
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
|
|
|
"Image file with properties deleted: %(file_name)s",
|
|
|
|
file_name=str(file_name),
|
|
|
|
),
|
|
|
|
)
|
2022-09-25 23:00:18 +00:00
|
|
|
else:
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-11-07 00:25:02 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
|
|
|
"Image file deleted: %(file_name)s",
|
|
|
|
file_name=str(file_name),
|
|
|
|
),
|
|
|
|
)
|
2021-09-19 21:29:01 +00:00
|
|
|
|
|
|
|
|
2021-12-14 02:50:36 +00:00
|
|
|
@APP.route("/files/rename", methods=["POST"])
|
|
|
|
@login_required
|
|
|
|
def rename():
|
|
|
|
"""
|
|
|
|
Renames a specified file in the images dir
|
|
|
|
"""
|
2022-10-24 02:05:29 +00:00
|
|
|
file_name = Path(request.form.get("file_name"))
|
|
|
|
new_file_name = Path(request.form.get("new_file_name"))
|
|
|
|
safe_path = is_safe_path(file_name)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
|
|
|
safe_path = is_safe_path(new_file_name)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
2023-01-27 05:51:59 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
|
|
|
process = file_cmd.rename_file(
|
|
|
|
Path(server_info["image_dir"]) / str(file_name),
|
|
|
|
Path(server_info["image_dir"]) / str(new_file_name),
|
|
|
|
)
|
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2022-09-25 23:00:18 +00:00
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
|
|
|
|
2021-12-14 02:50:36 +00:00
|
|
|
# Rename the drive properties file, if it exists
|
2022-10-09 20:50:20 +00:00
|
|
|
prop_file_path = Path(CFG_DIR) / f"{file_name}.{PROPERTIES_SUFFIX}"
|
|
|
|
new_prop_file_path = Path(CFG_DIR) / f"{new_file_name}.{PROPERTIES_SUFFIX}"
|
|
|
|
if prop_file_path.is_file():
|
2022-02-27 05:46:35 +00:00
|
|
|
process = file_cmd.rename_file(prop_file_path, new_prop_file_path)
|
2022-01-21 23:08:29 +00:00
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2021-12-14 02:50:36 +00:00
|
|
|
if process["status"]:
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
|
|
|
"Image file with properties renamed to: %(file_name)s",
|
|
|
|
file_name=str(new_file_name),
|
|
|
|
),
|
|
|
|
)
|
2022-09-25 23:00:18 +00:00
|
|
|
else:
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2021-12-14 02:50:36 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
|
|
|
"Image file renamed to: %(file_name)s",
|
|
|
|
file_name=str(new_file_name),
|
|
|
|
),
|
|
|
|
)
|
2021-12-14 02:50:36 +00:00
|
|
|
|
|
|
|
|
2022-06-15 02:03:56 +00:00
|
|
|
@APP.route("/files/copy", methods=["POST"])
|
|
|
|
@login_required
|
|
|
|
def copy():
|
|
|
|
"""
|
|
|
|
Creates a copy of a specified file in the images dir
|
|
|
|
"""
|
2022-10-24 02:05:29 +00:00
|
|
|
file_name = Path(request.form.get("file_name"))
|
|
|
|
new_file_name = Path(request.form.get("copy_file_name"))
|
|
|
|
safe_path = is_safe_path(file_name)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
|
|
|
safe_path = is_safe_path(new_file_name)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
2023-01-27 05:51:59 +00:00
|
|
|
server_info = piscsi_cmd.get_server_info()
|
|
|
|
process = file_cmd.copy_file(
|
|
|
|
Path(server_info["image_dir"]) / str(file_name),
|
|
|
|
Path(server_info["image_dir"]) / str(new_file_name),
|
|
|
|
)
|
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
2022-09-25 23:00:18 +00:00
|
|
|
if not process["status"]:
|
|
|
|
return response(error=True, message=process["msg"])
|
|
|
|
|
2022-06-15 02:03:56 +00:00
|
|
|
# Create a copy of the drive properties file, if it exists
|
2022-10-09 20:50:20 +00:00
|
|
|
prop_file_path = Path(CFG_DIR) / f"{file_name}.{PROPERTIES_SUFFIX}"
|
|
|
|
new_prop_file_path = Path(CFG_DIR) / f"{new_file_name}.{PROPERTIES_SUFFIX}"
|
|
|
|
if prop_file_path.is_file():
|
2022-06-15 02:03:56 +00:00
|
|
|
process = file_cmd.copy_file(prop_file_path, new_prop_file_path)
|
|
|
|
process = ReturnCodeMapper.add_msg(process)
|
|
|
|
if process["status"]:
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
|
|
|
"Copy of image file with properties saved as: %(file_name)s",
|
|
|
|
file_name=str(new_file_name),
|
|
|
|
),
|
|
|
|
)
|
2022-09-25 23:00:18 +00:00
|
|
|
else:
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(error=True, message=process["msg"])
|
2022-06-15 02:03:56 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(
|
|
|
|
message=_(
|
|
|
|
"Copy of image file saved as: %(file_name)s",
|
|
|
|
file_name=str(new_file_name),
|
|
|
|
),
|
|
|
|
)
|
2022-06-15 02:03:56 +00:00
|
|
|
|
|
|
|
|
2022-08-12 03:19:02 +00:00
|
|
|
@APP.route("/files/extract_image", methods=["POST"])
|
2021-12-13 00:54:15 +00:00
|
|
|
@login_required
|
2022-08-12 03:19:02 +00:00
|
|
|
def extract_image():
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-08-12 03:19:02 +00:00
|
|
|
Extracts all or a subset of files in the specified archive
|
2021-11-07 00:25:02 +00:00
|
|
|
"""
|
2022-10-24 02:05:29 +00:00
|
|
|
archive_file = Path(request.form.get("archive_file"))
|
2022-08-12 03:19:02 +00:00
|
|
|
archive_members_raw = request.form.get("archive_members") or None
|
|
|
|
archive_members = archive_members_raw.split("|") if archive_members_raw else None
|
2022-10-24 02:05:29 +00:00
|
|
|
safe_path = is_safe_path(archive_file)
|
|
|
|
if not safe_path["status"]:
|
|
|
|
return response(error=True, message=safe_path["msg"])
|
2022-11-30 05:19:17 +00:00
|
|
|
extract_result = file_cmd.extract_image(str(archive_file), archive_members)
|
2021-10-22 13:42:28 +00:00
|
|
|
|
2022-08-12 03:19:02 +00:00
|
|
|
if extract_result["return_code"] == ReturnCodes.EXTRACTIMAGE_SUCCESS:
|
|
|
|
|
|
|
|
for properties_file in extract_result["properties_files_moved"]:
|
|
|
|
if properties_file["status"]:
|
2022-10-24 02:05:29 +00:00
|
|
|
logging.info(
|
2022-11-30 05:19:17 +00:00
|
|
|
"Properties file %s moved to %s",
|
|
|
|
properties_file["name"],
|
|
|
|
CFG_DIR,
|
|
|
|
)
|
2022-08-12 03:19:02 +00:00
|
|
|
else:
|
2022-10-24 02:05:29 +00:00
|
|
|
logging.warning(
|
2022-11-30 05:19:17 +00:00
|
|
|
"Failed to move properties file %s to %s",
|
|
|
|
properties_file["name"],
|
|
|
|
CFG_DIR,
|
|
|
|
)
|
2021-10-22 13:42:28 +00:00
|
|
|
|
2022-10-24 02:05:29 +00:00
|
|
|
return response(message=ReturnCodeMapper.add_msg(extract_result).get("msg"))
|
2022-09-25 23:00:18 +00:00
|
|
|
|
|
|
|
return response(error=True, message=ReturnCodeMapper.add_msg(extract_result).get("msg"))
|
2021-10-22 13:42:28 +00:00
|
|
|
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
|
2021-12-27 21:21:56 +00:00
|
|
|
@APP.route("/language", methods=["POST"])
|
|
|
|
def change_language():
|
2021-12-28 20:09:47 +00:00
|
|
|
"""
|
|
|
|
Changes the session language locale and refreshes the Flask app context
|
|
|
|
"""
|
2021-12-27 21:21:56 +00:00
|
|
|
locale = request.form.get("locale")
|
|
|
|
session["language"] = locale
|
2022-12-05 17:58:23 +00:00
|
|
|
piscsi_cmd.locale = session["language"]
|
2022-02-27 05:46:35 +00:00
|
|
|
file_cmd.locale = session["language"]
|
2021-12-27 21:21:56 +00:00
|
|
|
refresh()
|
|
|
|
|
2022-01-29 22:22:39 +00:00
|
|
|
language = Locale.parse(locale)
|
|
|
|
language_name = language.get_language_name(locale)
|
2022-09-25 23:00:18 +00:00
|
|
|
return response(message=_("Changed Web Interface language to %(locale)s", locale=language_name))
|
2021-12-27 21:21:56 +00:00
|
|
|
|
|
|
|
|
2022-11-14 17:32:15 +00:00
|
|
|
@APP.route("/theme", methods=["GET", "POST"])
|
|
|
|
def change_theme():
|
|
|
|
if request.method == "GET":
|
|
|
|
theme = request.args.get("name")
|
|
|
|
else:
|
|
|
|
theme = request.form.get("name")
|
|
|
|
|
|
|
|
if theme not in TEMPLATE_THEMES:
|
|
|
|
return response(error=True, message=_("The requested theme does not exist."))
|
|
|
|
|
|
|
|
session["theme"] = theme
|
|
|
|
return response(message=_("Theme changed to '%(theme)s'.", theme=theme))
|
|
|
|
|
|
|
|
|
2022-12-04 14:31:57 +00:00
|
|
|
@APP.route("/healthcheck", methods=["GET"])
|
|
|
|
def healthcheck():
|
|
|
|
return "", 200
|
|
|
|
|
|
|
|
|
2023-05-02 02:21:17 +00:00
|
|
|
@APP.before_request
|
2022-01-29 17:41:39 +00:00
|
|
|
def detect_locale():
|
2021-12-23 17:12:16 +00:00
|
|
|
"""
|
2022-01-29 17:41:39 +00:00
|
|
|
Get the detected locale to use for UI string translations.
|
2023-05-16 19:19:40 +00:00
|
|
|
Assign the language string to objects to be used for requests.
|
2021-12-23 17:12:16 +00:00
|
|
|
"""
|
2023-05-02 02:21:17 +00:00
|
|
|
if "language" not in session.keys():
|
|
|
|
session["language"] = get_locale()
|
2023-05-16 19:19:40 +00:00
|
|
|
|
|
|
|
piscsi_cmd.locale = session["language"]
|
|
|
|
file_cmd.locale = session["language"]
|
2021-12-23 17:12:16 +00:00
|
|
|
|
|
|
|
|
2022-12-04 14:31:57 +00:00
|
|
|
@APP.before_request
|
|
|
|
def log_http_request():
|
|
|
|
if logging.getLogger().isEnabledFor(logging.DEBUG):
|
|
|
|
message = f"HTTP request: {request.method} {request.path}"
|
|
|
|
|
|
|
|
if request.method == "POST":
|
|
|
|
if request.path == "/login":
|
|
|
|
message += " (<hidden>)"
|
|
|
|
elif len(request.get_data()) > 100:
|
|
|
|
message += f" (payload: {request.get_data()[:100]} <truncated>)"
|
|
|
|
else:
|
|
|
|
message += f" (payload: {request.get_data()})"
|
|
|
|
|
|
|
|
logging.debug(message)
|
|
|
|
|
|
|
|
|
2021-11-07 00:25:02 +00:00
|
|
|
if __name__ == "__main__":
|
2022-12-05 17:58:23 +00:00
|
|
|
APP.secret_key = "piscsi_is_awesome_insecure_secret_key"
|
2021-11-07 00:25:02 +00:00
|
|
|
APP.config["SESSION_TYPE"] = "filesystem"
|
|
|
|
APP.config["MAX_CONTENT_LENGTH"] = int(MAX_FILE_SIZE)
|
Move to protobuf for the webapp, major overhaul to easyinstall.sh, code comment translations (#229)
* Making saving and loading config files work with protobuf
* Formatted the Status column, and fixed the available ID logic
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Updated handling of removed status for devices without image file support
* Comment update
* Fixed typo
* Updated logging
* Better handling of device status
* Updated parameter handling
* Updated setting default interfaces
* Revert "Updated setting default interfaces"
This reverts commit 210abc775d9a79dd0c631cf3877966a2923f4d5b.
* Revert "Updated parameter handling"
This reverts commit 35302addd59f5f5e1cc032888ba32dcbb426a846.
* Abort with a 404 if rascsi is not running. Use any protobuf response to determine whether rascsi is running (should hardly be required anymore due to the other change, but just in case).
* Move id reservation back into __main__
* Remove check for device type when validating Removed image
* Leverage device property data for better status messages
* Remove redundant string sanitation when reading config csv file
* Clean up device list generation
* Cleanup
* Remove duplicates before building valid scsi id list
* Fully translated cfilesystem.h code comments to English; partially translated cfilesystem.cpp
* rascsi supports reserving IDs
* Updated help message
* Replaced BOOL by bool
* Logging update
* Logging update
* Cleanup
* Restructure the easyinstall.sh script to combine the install/update flows, and disallow installing the webapp by itself
* Remove redundant steps handled in Makefile
* Add the functionality to specify connect_type through a parameter
* Add validation to the argument parser allowing only STANDARD and FULLSPEC as options
* Complete translation of code comments for cfilesystem.h; partial translation for cfilesystem.cpp
* Cleanup
* Merge parts of the Network Assistant script by sonique6784; fix the run_choice startup parameter
* Improve on the network setup messages
* Fix routing address
* Add checks for previous configuration; cleanup
* Cleanup
* Remove redundant step in wired setup. Improve messages.
* Cleanup
* Added default parameters to device properties
* Return parameters a device was set up with
* Add flows for configuring custom network settings; adopting some logic by sonique6784
* Improved device initialization
* Updated default parameter handling
* Updated default parameter handling
* Fixed typo
* Comment updates
* Comment update
* Make iso generation work again, and add error handling to urllib actions
* Manage default parameters in the respective device
* Print available network interfaces. Clean up step and improve descriptive messages.
* Make the script clean up previous configurations
* Make the script only show relevant interfaces
* Partial translation of cfilesystem.cpp
* Do not pass empty parameter string
* Added supports_params flag
* Completely translate code comments in cfilesystem.cpp
* Show rascsi-web status after installing
* Refactoring
* Made comparisons more consistent
* Updated error handling
* Updated exception handling
* Made comparisons more consistent
* Updated error handling
* Overlooked code comment translation
* Renaming
* Better error handling for socket connection
* Disable two NEC hd image types due to issue#232
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Comment update
* NEC sectors size must be 512 bytes
* Updated logging
* Updated vendor name handling
* Updated handling of media loading/unloading
* Better handling of removable disks in the web ui
* Added stoppable property and stopped status
* Made MO stoppable
* Removed duplicate code
* Removed duplicate code
* Copy read-only property
* Renaming
* Add an assistant for reserving scsi ids
* Don't show action if no device attached
* Implement a device_info app path, and cut down on device columns always shown
* Cleanup
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Removed duplicate code, added START/STOP
* Improved default parameter handling
* Updated load/eject handling
* Logging update
* Fixed typo
* Verified START/STOP UNIT
* Updated logging
* Updated status handling
* Updated status handling
* More status handling updates
* Logging update
* Made instance fields local variables
* Made disk_t private
* Made some data structures private
* Fixed ARM compile issue
* Fast forward instead of rebase existing git repo
* Fixed ctapdriver initialization issue
* Reset read-only status when opening an image file
* Cleanup
* Cleanup
* Made logging more consistent
* Updated log level
* Cleanup
* Log load/eject on error level for testing
* Revert "Log load/eject on error level for testing"
This reverts commit d35a15ea8e520517d25e1e1054ad1aeda9f85f2e.
* Assume drive is not ready after having been stopped
* Updated status handling
* Make the csv config files store all relevant device data for reading
* Read 9 column csv config files
* Fixed typo
* Rebuild manpage
* Fixed issue #234 (MODE SENSE (10) returns wrong mode parameter header)
* Removed unused code
* Enum data type update
* Removed duplicate range check
* Removed duplicate code
* Removed more duplicate code
* Logging update
* SCCD sector size was not meant to be configurable
* Better error handling for csv reading and writing
* Updated configurable sector size properties
* Removed assertion
* Improved error handling
* Updated error handling
* Re-added special error handling only relevant for SASI
* Added TODOs
* Comment update
* Added override modifier
* Removed obsolete debug flag (related code was not called)
* Comment and logging updates
* Removed obsolete try/catch
* Revert "Removed obsolete try/catch"
This reverts commit 39ca12d8b153c706316ce79f4fec65c9abc60024.
* Comment update
* Removed duplicate code
* Updated error messages, use more foreach loops
* Avoid storing RaSCSI generated product info in config file
* Updated logging
* Logging update
* Save config files in json instead of csv
* Fix bugs with json config loading
* Refactoring & remove unused code
* Refactoring
* Display upper case file endings in file management list
* Only show product vendor for non-RaSCSI devices in the device list
* Translate code comment
* Refactoring
* Fix bad identation
* Improve valid file extension handling
* Add validation when attaching removable media
* Display valid file endings under the file list
* Cleanup
* Don't store 0 block size
* Fix indentation
* Read and write config files in key:pair format
* Add section for controlling logging
* README update
* Added block_count
* Cleanup, fix typos
* Support attaching CD-ROM with custom block size
* Evaluate block size when inserting a media
* rasctl display capacity if available
* Info message update
* Use kwargs for device attachment
* Fix bugs in attach_image kwargs; make config file more readable
* POC for attaching device with profile
* Only list product types valid for the particular image file
* Perform validation of HDD image size based on the product profile
* Implement sidecar config files for drive images.
* Added missing product name to NEC vital product data
* MO block size depends on capacity only
* Better error handling for device sidecar config loading
* Extended property/status display
* Property display update
* Updated error handling
* Handle image sizes in bytes internally
* Revert change
* Resolve bad merge
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-15 02:51:12 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
parser = argparse.ArgumentParser(description="PiSCSI Web Interface command line arguments")
|
2021-12-23 17:12:16 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--port",
|
|
|
|
type=int,
|
|
|
|
default=8080,
|
|
|
|
action="store",
|
|
|
|
help="Port number the web server will run on",
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2021-12-23 17:12:16 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--password",
|
|
|
|
type=str,
|
|
|
|
default="",
|
|
|
|
action="store",
|
2022-12-05 17:58:23 +00:00
|
|
|
help="Token password string for authenticating with PiSCSI",
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2022-01-21 23:08:29 +00:00
|
|
|
parser.add_argument(
|
2022-12-05 17:58:23 +00:00
|
|
|
"--backend-host",
|
2022-01-21 23:08:29 +00:00
|
|
|
type=str,
|
|
|
|
default="localhost",
|
|
|
|
action="store",
|
2022-12-05 17:58:23 +00:00
|
|
|
help="PiSCSI backend hostname. Default: localhost",
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2022-01-21 23:08:29 +00:00
|
|
|
parser.add_argument(
|
2022-12-05 17:58:23 +00:00
|
|
|
"--backend-port",
|
2022-07-26 04:47:11 +00:00
|
|
|
type=int,
|
2022-01-21 23:08:29 +00:00
|
|
|
default=6868,
|
|
|
|
action="store",
|
2022-12-05 17:58:23 +00:00
|
|
|
help="PiSCSI backend port number. Default: 6868",
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2022-08-01 00:02:14 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--log-level",
|
|
|
|
type=str,
|
|
|
|
default="warning",
|
|
|
|
action="store",
|
|
|
|
help="Log level for Web UI. Default: warning",
|
|
|
|
choices=["debug", "info", "warning", "error", "critical"],
|
2022-11-30 05:19:17 +00:00
|
|
|
)
|
2022-08-28 13:51:31 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--dev-mode",
|
|
|
|
action="store_true",
|
2022-11-30 05:19:17 +00:00
|
|
|
help="Run in development mode",
|
|
|
|
)
|
2022-08-01 00:02:14 +00:00
|
|
|
|
2021-12-28 20:09:47 +00:00
|
|
|
arguments = parser.parse_args()
|
2022-12-05 17:58:23 +00:00
|
|
|
APP.config["PISCSI_TOKEN"] = arguments.password
|
2021-11-15 19:00:32 +00:00
|
|
|
|
2022-12-04 14:31:57 +00:00
|
|
|
logging.config.dictConfig(
|
|
|
|
{
|
|
|
|
"version": 1,
|
|
|
|
"formatters": {
|
|
|
|
"default": {
|
|
|
|
"format": "[%(asctime)s] [%(levelname)s] %(filename)s:%(lineno)s %(message)s",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"handlers": {
|
|
|
|
"wsgi": {
|
|
|
|
"class": "logging.StreamHandler",
|
|
|
|
"formatter": "default",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"root": {
|
|
|
|
"level": arguments.log_level.upper(),
|
|
|
|
"handlers": ["wsgi"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
sock_cmd = SocketCmdsFlask(host=arguments.backend_host, port=arguments.backend_port)
|
|
|
|
piscsi_cmd = PiscsiCmds(sock_cmd=sock_cmd, token=APP.config["PISCSI_TOKEN"])
|
|
|
|
file_cmd = FileCmds(sock_cmd=sock_cmd, piscsi=piscsi_cmd, token=APP.config["PISCSI_TOKEN"])
|
2022-02-27 05:46:35 +00:00
|
|
|
sys_cmd = SysCmds()
|
2022-01-21 23:08:29 +00:00
|
|
|
|
2023-03-24 03:07:19 +00:00
|
|
|
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."
|
|
|
|
)
|
|
|
|
|
2022-01-29 17:41:39 +00:00
|
|
|
if Path(f"{CFG_DIR}/{DEFAULT_CONFIG}").is_file():
|
2022-02-27 05:46:35 +00:00
|
|
|
file_cmd.read_config(DEFAULT_CONFIG)
|
2022-10-01 23:51:30 +00:00
|
|
|
if Path(f"{DRIVE_PROPERTIES_FILE}").is_file():
|
|
|
|
process = file_cmd.read_drive_properties(DRIVE_PROPERTIES_FILE)
|
|
|
|
if process["status"]:
|
2022-12-05 17:58:23 +00:00
|
|
|
APP.config["PISCSI_DRIVE_PROPERTIES"] = process["conf"]
|
2022-10-01 23:51:30 +00:00
|
|
|
else:
|
2022-12-05 17:58:23 +00:00
|
|
|
APP.config["PISCSI_DRIVE_PROPERTIES"] = []
|
2022-10-01 23:51:30 +00:00
|
|
|
logging.error(process["msg"])
|
|
|
|
else:
|
2022-12-05 17:58:23 +00:00
|
|
|
APP.config["PISCSI_DRIVE_PROPERTIES"] = []
|
2022-10-01 23:51:30 +00:00
|
|
|
logging.warning("Could not read drive properties from %s", DRIVE_PROPERTIES_FILE)
|
2022-01-29 17:41:39 +00:00
|
|
|
|
2022-12-04 14:31:57 +00:00
|
|
|
logging.info("Starting WSGI server...")
|
2022-08-28 13:51:31 +00:00
|
|
|
if arguments.dev_mode:
|
2022-12-04 14:31:57 +00:00
|
|
|
logging.info("Dev mode enabled")
|
2022-08-28 13:51:31 +00:00
|
|
|
APP.debug = True
|
|
|
|
from werkzeug.debug import DebuggedApplication
|
2022-11-30 05:19:17 +00:00
|
|
|
|
2022-08-28 13:51:31 +00:00
|
|
|
try:
|
|
|
|
bjoern.run(DebuggedApplication(APP, evalex=False), "0.0.0.0", arguments.port)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
bjoern.run(APP, "0.0.0.0", arguments.port)
|