RASCSI/python/web/src/web.py

1507 lines
47 KiB
Python
Raw Normal View History

"""
Module for the Flask app rendering and endpoints
"""
import logging
import logging.config
import argparse
from pathlib import Path, PurePath
from functools import wraps
from grp import getgrall
import bjoern
from piscsi.return_codes import ReturnCodes
from simplepam import authenticate
from flask_babel import Babel, Locale, refresh, _
from flask import (
Flask,
render_template,
request,
flash,
url_for,
redirect,
send_from_directory,
make_response,
session,
jsonify,
)
from piscsi.piscsi_cmds import PiscsiCmds
from piscsi.file_cmds import FileCmds
from piscsi.sys_cmds import SysCmds
from piscsi.common_settings import (
CFG_DIR,
CONFIG_FILE_SUFFIX,
PROPERTIES_SUFFIX,
ARCHIVE_FILE_SUFFIXES,
RESERVATIONS,
2021-02-01 17:39:50 +00:00
)
from return_code_mapper import ReturnCodeMapper
from socket_cmds_flask import SocketCmdsFlask
from web_utils import (
working_dirs_exist,
sort_and_format_devices,
get_valid_scsi_ids,
map_device_types_and_names,
get_device_name,
map_image_file_descriptions,
format_image_list,
format_drive_properties,
get_properties_by_drive_name,
auth_active,
is_bridge_configured,
is_safe_path,
upload_with_dropzonejs,
browser_supports_modern_themes,
)
from settings import (
WEB_DIR,
FILE_SERVER_DIR,
MAX_FILE_SIZE,
DEFAULT_CONFIG,
DRIVE_PROPERTIES_FILE,
AUTH_GROUP,
2021-12-27 21:21:56 +00:00
LANGUAGES,
TEMPLATE_THEMES,
TEMPLATE_THEME_DEFAULT,
TEMPLATE_THEME_LEGACY,
)
APP = Flask(__name__)
BABEL = Babel(APP)
def get_env_info():
"""
Get information about the app/host environment
"""
server_info = piscsi_cmd.get_server_info()
ip_addr, host = sys_cmd.get_ip_and_host()
if "username" in session:
username = session["username"]
else:
username = None
return {
"running_env": sys_cmd.running_env(),
"username": username,
"auth_active": auth_active(AUTH_GROUP)["status"],
"logged_in": username and auth_active(AUTH_GROUP)["status"],
"ip_addr": ip_addr,
"host": host,
"system_name": sys_cmd.get_pretty_host(),
"free_disk_space": int(sys_cmd.disk_space()["free"] / 1024 / 1024),
"locale": get_locale(),
"version": server_info["version"],
"image_dir": server_info["image_dir"],
"netatalk_configured": sys_cmd.running_proc("afpd"),
"macproxy_configured": sys_cmd.running_proc("macproxy"),
"cd_suffixes": tuple(server_info["sccd"]),
"rm_suffixes": tuple(server_info["scrm"]),
"mo_suffixes": tuple(server_info["scmo"]),
}
def response(
template=None,
message=None,
redirect_url=None,
error=False,
status_code=200,
**kwargs,
):
"""
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":
return (
jsonify(
{
"status": status,
"messages": [{"message": m, "category": c} for m, c in messages],
"data": kwargs,
}
),
status_code,
)
if messages:
for message, category in messages:
flash(message, category)
if template:
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
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
kwargs["current_theme_stylesheet"] = f"themes/{theme}/style.css"
kwargs["current_theme"] = theme
kwargs["available_themes"] = TEMPLATE_THEMES
return render_template(template, **kwargs)
if redirect_url:
return redirect(url_for(redirect_url))
return redirect(url_for("index"))
@BABEL.localeselector
def get_locale():
2021-12-27 21:21:56 +00:00
"""
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-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
"""
locales = [
{"language": x.language, "display_name": x.display_name}
for x in [*BABEL.list_translations(), Locale("en")]
]
return sorted(locales, key=lambda x: x["language"])
2021-12-27 21:21:56 +00:00
# pylint: disable=too-many-locals
@APP.route("/")
def index():
"""
Sets up data structures for and renders the index page
"""
server_info = piscsi_cmd.get_server_info()
working_dirs_exist((server_info["image_dir"], CFG_DIR))
devices = piscsi_cmd.list_devices()
device_types = map_device_types_and_names(piscsi_cmd.get_device_types()["device_types"])
image_files = file_cmd.list_images()
config_files = file_cmd.list_config_files()
ip_addr, host = sys_cmd.get_ip_and_host()
formatted_image_files = format_image_list(image_files["files"], device_types)
attached_images = []
units = 0
# If there are more than 0 logical unit numbers, display in the Web UI
for device in devices["device_list"]:
attached_images.append(device["image"].replace(server_info["image_dir"] + "/", ""))
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +00:00
units += int(device["unit"])
Support for multiple SCSI LUNs (#318) * Updated logging * Updated logging * Updated logging * Updated ID/LUN parsing * Updated handling of max_id * The -HD option sets type to SAHD * Replaced is_sasi by device type * Updated logging * Logging update * Improved LUN evaluation * Check LUN against UnitMax * Comment update * LUN parsing update * Logging update * Logging update * Updated ReportLuns * Updated REPORT LUNS * Cleanup * Updated REPORT LUNS * Updated Execute() * Updated LUN handling * Check for consecutive LUNs * Added LUN check for remotely attached devices * Remember LUN selected by IDENTIFY * Evaluate LUN from IDENTIFY message * Added comment * Updated REPORT LUNS * Initlize LUN * Logging update * Support 32 LUNs * rasctl display update * Updated LUN check for LUNSs > 7 * Simplified LUN validation * Fixed wrong ID/LUN handling with values > 9 * Log level update * Manpage update * rascsi parser update * Updated error handling * Updated error handling * Updated LUN setup validation * Updated logging * Improved validation of consecutive LUNs * Renaming * Detach all LUNs equal to or higher than the one specified * Add support for LUN in the device list * Add ability to show device info for LUNs * Make it possible to detach and eject LUNs * Show full path to prop file * Show only LUN columns when non-0 LUNs present * Support for attaching LUNs * Add helptext * Fix handling of removable media * Retain the previous behavior of recommending the next unoccupied id * SCSI ID validation no longer needed due to changed logic * Make use of recommended id everywhere * Docstring Co-authored-by: Daniel Markstedt <markstedt@gmail.com>
2021-10-13 09:03:31 +00:00
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
reserved_scsi_ids = server_info["reserved_ids"]
scsi_ids = get_valid_scsi_ids(devices["device_list"], reserved_scsi_ids)
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
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
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"}],
reverse=True,
)
+ server_info["scrm"]
+ server_info["scmo"]
)
valid_image_suffixes = (
server_info["schd"] + server_info["scrm"] + server_info["scmo"] + server_info["sccd"]
)
return response(
template="index.html",
page_title=_("PiSCSI Control Page"),
locales=get_supported_locales(),
netinfo=piscsi_cmd.get_network_info(),
bridge_configured=sys_cmd.is_bridge_setup(),
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
devices=formatted_devices,
attached_images=attached_images,
formatted_image_files=formatted_image_files,
files=image_files["files"],
config_files=config_files,
device_types=device_types,
scan_depth=server_info["scan_depth"],
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,
units=units,
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
reserved_scsi_ids=reserved_scsi_ids,
image_suffixes_to_create=image_suffixes_to_create,
valid_image_suffixes=valid_image_suffixes,
drive_properties=format_drive_properties(APP.config["PISCSI_DRIVE_PROPERTIES"]),
images_subdirs=file_cmd.list_subdirs(server_info["image_dir"]),
shared_subdirs=file_cmd.list_subdirs(FILE_SERVER_DIR),
file_server_dir_exists=Path(FILE_SERVER_DIR).exists(),
RESERVATIONS=RESERVATIONS,
CFG_DIR=CFG_DIR,
FILE_SERVER_DIR=FILE_SERVER_DIR,
PROPERTIES_SUFFIX=PROPERTIES_SUFFIX,
ARCHIVE_FILE_SUFFIXES=ARCHIVE_FILE_SUFFIXES,
CONFIG_FILE_SUFFIX=CONFIG_FILE_SUFFIX,
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
)
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
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())
@APP.route("/drive/list", methods=["GET"])
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
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
"""
server_info = piscsi_cmd.get_server_info()
working_dirs_exist((server_info["image_dir"], CFG_DIR))
return response(
template="drives.html",
page_title=_("PiSCSI Create Drive"),
files=file_cmd.list_images()["files"],
drive_properties=format_drive_properties(APP.config["PISCSI_DRIVE_PROPERTIES"]),
)
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29: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
"""
server_info = piscsi_cmd.get_server_info()
working_dirs_exist((server_info["image_dir"], CFG_DIR))
return response(
template="upload.html",
page_title=_("PiSCSI File Upload"),
images_subdirs=file_cmd.list_subdirs(server_info["image_dir"]),
shared_subdirs=file_cmd.list_subdirs(FILE_SERVER_DIR),
file_server_dir_exists=Path(FILE_SERVER_DIR).exists(),
max_file_size=int(int(MAX_FILE_SIZE) / 1024 / 1024),
CFG_DIR=CFG_DIR,
FILE_SERVER_DIR=FILE_SERVER_DIR,
)
@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]
if AUTH_GROUP in groups and authenticate(str(username), str(password)):
session["username"] = request.form["username"]
return response(env=get_env_info())
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,
),
)
@APP.route("/logout")
def logout():
"""
Removes the logged in user from the session
"""
session.pop("username", None)
return response()
@APP.route("/pwa/<path:pwa_path>")
def send_pwa_files(pwa_path):
"""
Sets up mobile web resources
"""
return send_from_directory("pwa", pwa_path)
2021-02-01 17:39:50 +00:00
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
def login_required(func):
"""
Wrapper method for enabling authentication for an endpoint
"""
@wraps(func)
def decorated_function(*args, **kwargs):
auth = auth_active(AUTH_GROUP)
if auth["status"] and "username" not in session:
return response(error=True, message=auth["msg"])
return func(*args, **kwargs)
return decorated_function
@APP.route("/drive/create", methods=["POST"])
@login_required
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
def drive_create():
"""
Creates the image and properties file pair
"""
drive_name = request.form.get("drive_name")
file_name = Path(request.form.get("file_name"))
properties = get_properties_by_drive_name(APP.config["PISCSI_DRIVE_PROPERTIES"], drive_name)
if not properties:
return response(
error=True,
message=_("No properties data for drive %(drive_name)s", drive_name=drive_name),
)
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
# Creating the image file
server_info = piscsi_cmd.get_server_info()
process = file_cmd.create_empty_image(
Path(server_info["image_dir"]) / f"{file_name}.{properties['file_type']}",
properties["size"],
)
process = ReturnCodeMapper.add_msg(process)
if not process["status"]:
return response(error=True, message=process["msg"])
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
# Creating the drive properties file
full_file_name = f"{file_name}.{properties['file_type']}"
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"])
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
return response(
message=_(
"Image file with properties created: %(file_name)s",
file_name=full_file_name,
)
)
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
@APP.route("/drive/cdrom", methods=["POST"])
@login_required
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
def drive_cdrom():
"""
Creates a properties file for a CD-ROM image
"""
drive_name = request.form.get("drive_name")
file_name = Path(request.form.get("file_name"))
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
# Creating the drive properties file
file_name = f"{file_name}.{PROPERTIES_SUFFIX}"
properties = get_properties_by_drive_name(APP.config["PISCSI_DRIVE_PROPERTIES"], drive_name)
if not properties:
return response(
error=True,
message=_("No properties data for drive %(drive_name)s", drive_name=drive_name),
)
process = file_cmd.write_drive_properties(file_name, properties)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
return response(message=process["msg"])
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
return response(error=True, message=process["msg"])
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
@APP.route("/config/save", methods=["POST"])
@login_required
def config_save():
"""
Saves a config file to disk
"""
file_name = Path(request.form.get("name") + f".{CONFIG_FILE_SUFFIX}").name
process = file_cmd.write_config(file_name)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
return response(message=process["msg"])
return response(error=True, message=process["msg"])
@APP.route("/config/action", methods=["POST"])
@login_required
def config_action():
"""
Carries out on an operation on the config file
"""
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:
process = file_cmd.read_config(file_name)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
return response(message=process["msg"])
return response(error=True, message=process["msg"])
if "delete" in request.form:
process = file_cmd.delete_file(Path(CFG_DIR) / file_name)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
return response(message=process["msg"])
return response(error=True, message=process["msg"])
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",
)
@APP.route("/files/diskinfo", methods=["POST"])
def show_diskinfo():
"""
Displays disk image info
"""
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"])
server_info = piscsi_cmd.get_server_info()
working_dirs_exist((server_info["image_dir"], CFG_DIR))
returncode, diskinfo = sys_cmd.get_diskinfo(Path(server_info["image_dir"]) / file_name)
if returncode == 0:
return response(
template="diskinfo.html",
page_title=_("PiSCSI Image Info"),
file_name=str(file_name),
diskinfo=diskinfo,
)
return response(
error=True,
message=_("An error occurred when getting disk info: %(error)s", error=diskinfo),
)
@APP.route("/sys/manpage", methods=["GET"])
def show_manpage():
"""
Displays manpage
"""
app_allowlist = ["piscsi", "scsictl", "scsidump", "scsimon"]
app = request.args.get("app", type=str)
if app not in app_allowlist:
return response(error=True, message=_("%(app)s is not a recognized PiSCSI app", app=app))
file_path = f"{WEB_DIR}/../../../doc/{app}.1"
html_to_strip = [
"Content-type",
"!DOCTYPE",
"<HTML>",
"<HEAD>",
"<BODY>",
"<H1>",
]
returncode, manpage = sys_cmd.get_manpage(file_path)
if returncode == 0:
formatted_manpage = ""
for line in manpage.splitlines(True):
# 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:
line = line.replace('<A HREF="/">man2html</A>', "man2html")
if not any(ele in line for ele in html_to_strip):
formatted_manpage += line
return response(
template="manpage.html",
page_title=_("PiSCSI Manual"),
app=app,
manpage=formatted_manpage,
)
return response(
error=True,
message=_("An error occurred when accessing manual page: %(error)s", error=manpage),
)
@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():
"""
Displays system logs
"""
lines = request.form.get("lines")
scope = request.form.get("scope")
returncode, logs = sys_cmd.get_logs(lines, scope)
if returncode == 0:
return response(
template="logs.html",
page_title=_("PiSCSI System Logs"),
scope=scope,
lines=lines,
logs=logs,
)
return response(
error=True,
message=_("An error occurred when fetching logs: %(error)s", error=logs),
)
@APP.route("/logs/level", methods=["POST"])
@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():
"""
Sets PiSCSI backend log 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
level = request.form.get("level") or "info"
process = piscsi_cmd.set_log_level(level)
if process["status"]:
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
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
@APP.route("/scsi/attach_device", methods=["POST"])
@login_required
def attach_device():
"""
Attaches a peripheral device that doesn't take an image file as argument
"""
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
drive_props = None
if drive_name:
for drive in APP.config["PISCSI_DRIVE_PROPERTIES"]:
if drive["name"] == drive_name:
drive_props = drive
break
# Collect device parameters into a dictionary
PARAM_PREFIX = "param_"
params = {}
for item in request.form:
if item.startswith(PARAM_PREFIX):
param = request.form.get(item)
if param:
params.update({item.replace(PARAM_PREFIX, ""): param})
if "interface" in params.keys():
bridge_status = is_bridge_configured(params["interface"])
if not bridge_status["status"]:
return response(error=True, message=bridge_status["msg"])
kwargs = {
"unit": int(unit),
"device_type": device_type,
"params": params,
}
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"]
process = piscsi_cmd.attach_device(scsi_id, **kwargs)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
return response(
message=_(
"Attached %(device_type)s to SCSI ID %(id_number)s LUN %(unit_number)s",
device_type=get_device_name(device_type),
id_number=scsi_id,
unit_number=unit,
)
)
return response(error=True, message=process["msg"])
@APP.route("/scsi/attach", methods=["POST"])
@login_required
def attach_image():
"""
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")
unit = request.form.get("unit")
device_type = request.form.get("type")
if not scsi_id:
return response(error=True, message=_("No SCSI ID specified"))
if not file_name:
return response(error=True, message=_("No image file to insert"))
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
if device_type:
kwargs["device_type"] = device_type
device_types = piscsi_cmd.get_device_types()
expected_block_size = min(device_types["device_types"][device_type]["block_sizes"])
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
# Attempt to load the device properties file:
# same file name with PROPERTIES_SUFFIX appended
drive_properties = Path(CFG_DIR) / f"{file_name}.{PROPERTIES_SUFFIX}"
if drive_properties.is_file():
process = file_cmd.read_drive_properties(drive_properties)
process = ReturnCodeMapper.add_msg(process)
if not process["status"]:
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"]
expected_block_size = conf["block_size"]
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
process = piscsi_cmd.attach_device(scsi_id, **kwargs)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
if int(file_size) % int(expected_block_size):
logging.warning(
"The image file size %s bytes is not a multiple of %s. "
"PiSCSI will ignore the trailing data. "
"The image may be corrupted, so proceed with caution.",
file_size,
expected_block_size,
)
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,
)
)
return response(error=True, message=process["msg"])
@APP.route("/scsi/detach_all", methods=["POST"])
@login_required
def detach_all_devices():
"""
Detaches all currently attached devices
"""
process = piscsi_cmd.detach_all()
if process["status"]:
return response(message=_("Detached all SCSI devices"))
return response(error=True, message=process["msg"])
@APP.route("/scsi/detach", methods=["POST"])
@login_required
def detach():
"""
Detaches a specified device
"""
2021-02-01 17:39:50 +00:00
scsi_id = request.form.get("scsi_id")
unit = request.form.get("unit")
process = piscsi_cmd.detach_by_id(scsi_id, unit)
if process["status"]:
return response(
message=_(
"Detached SCSI ID %(id_number)s LUN %(unit_number)s",
id_number=scsi_id,
unit_number=unit,
)
)
return response(error=True, message=process["msg"])
@APP.route("/scsi/eject", methods=["POST"])
@login_required
def eject():
"""
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")
unit = request.form.get("unit")
Support for multiple SCSI LUNs (#318) * Updated logging * Updated logging * Updated logging * Updated ID/LUN parsing * Updated handling of max_id * The -HD option sets type to SAHD * Replaced is_sasi by device type * Updated logging * Logging update * Improved LUN evaluation * Check LUN against UnitMax * Comment update * LUN parsing update * Logging update * Logging update * Updated ReportLuns * Updated REPORT LUNS * Cleanup * Updated REPORT LUNS * Updated Execute() * Updated LUN handling * Check for consecutive LUNs * Added LUN check for remotely attached devices * Remember LUN selected by IDENTIFY * Evaluate LUN from IDENTIFY message * Added comment * Updated REPORT LUNS * Initlize LUN * Logging update * Support 32 LUNs * rasctl display update * Updated LUN check for LUNSs > 7 * Simplified LUN validation * Fixed wrong ID/LUN handling with values > 9 * Log level update * Manpage update * rascsi parser update * Updated error handling * Updated error handling * Updated LUN setup validation * Updated logging * Improved validation of consecutive LUNs * Renaming * Detach all LUNs equal to or higher than the one specified * Add support for LUN in the device list * Add ability to show device info for LUNs * Make it possible to detach and eject LUNs * Show full path to prop file * Show only LUN columns when non-0 LUNs present * Support for attaching LUNs * Add helptext * Fix handling of removable media * Retain the previous behavior of recommending the next unoccupied id * SCSI ID validation no longer needed due to changed logic * Make use of recommended id everywhere * Docstring Co-authored-by: Daniel Markstedt <markstedt@gmail.com>
2021-10-13 09:03:31 +00:00
process = piscsi_cmd.eject_by_id(scsi_id, unit)
if process["status"]:
return response(
message=_(
"Ejected SCSI ID %(id_number)s LUN %(unit_number)s",
id_number=scsi_id,
unit_number=unit,
)
)
return response(error=True, message=process["msg"])
@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():
"""
Displays detailed info for all attached devices
"""
process = piscsi_cmd.list_devices()
if process["status"]:
return response(
template="deviceinfo.html",
page_title=_("PiSCSI Device Info"),
devices=process["device_list"],
)
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
return response(error=True, message=_("No devices attached"))
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +00:00
@APP.route("/scsi/reserve", methods=["POST"])
@login_required
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
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")
reserved_ids = piscsi_cmd.get_reserved_ids()["ids"]
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +00:00
reserved_ids.extend(scsi_id)
process = piscsi_cmd.reserve_scsi_ids(reserved_ids)
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +00:00
if process["status"]:
RESERVATIONS[int(scsi_id)] = memo
return response(message=_("Reserved SCSI ID %(id_number)s", id_number=scsi_id))
return response(error=True, message=process["msg"])
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +00:00
@APP.route("/scsi/release", methods=["POST"])
@login_required
def release_id():
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +00:00
"""
Releases the reservation of a SCSI ID as well as the memo for the reservation
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +00:00
"""
scsi_id = request.form.get("scsi_id")
reserved_ids = piscsi_cmd.get_reserved_ids()["ids"]
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +00:00
reserved_ids.remove(scsi_id)
process = piscsi_cmd.reserve_scsi_ids(reserved_ids)
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +00:00
if process["status"]:
RESERVATIONS[int(scsi_id)] = ""
return response(
message=_("Released the reservation for SCSI ID %(id_number)s", id_number=scsi_id)
)
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +00:00
return response(error=True, message=process["msg"])
ID reservation in Web UI (#416) * Remove dead code * Clean up indentation * Cleanup * Move socket commands into its own file * Move non-rascsi command methods into its own file * Refactoring * Bring back list_config_files * Cleanup * Cleanup of status messages * Remove unused libraries * Resolve pylint warnings * Resolve pylint warnings * Remove unused library * Resolve pylint warnings * Clean up status messages * Add requests lib to requirements.txt * Clean up status messages * Resolve interpolation warnings for logging * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Cleanup * Add html/head/body tags to the base document * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Resolve pylint warnings * Add .pylintrc and suppress warnings for the generated protobuf module * Resolve pylint warnings * Clean up docstrings * Fix error * Cleanup * Add info on pylint to README * Store .pylintrc in parent dir to allow other Python packages to use it * Tidy index.html * Cleanup * Resolve jinja-ninja warnings * Cleanup * Cleanup * Cleanup * Cleanup * Cleanup * Save and load id reservations in config file * Reserve and unreserve in the web ui * TODO * Add backwards compatibility with 21.10 config files * Comment cleanup * Save and load reservation memos into the config file * Cleanup * Resolve pylint warnings * Fix bugs * Fix bug * Fix bugs * Cleanup * Fix typo * Fix successful return clause * Cleanup * Fix bugs
2021-11-07 02:11:17 +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."))
@APP.route("/sys/reboot", methods=["POST"])
@login_required
def restart():
"""
Restarts the system
"""
returncode, message = sys_cmd.reboot_system()
if not returncode:
return response()
return response(error=True, message=message)
@APP.route("/sys/shutdown", methods=["POST"])
@login_required
def shutdown():
"""
Shuts down the system
"""
returncode, message = sys_cmd.shutdown_system()
if not returncode:
return response()
return response(error=True, message=message)
@APP.route("/files/create_iso", methods=["POST"])
@login_required
def download_to_iso():
"""
Downloads a file and creates a CD-ROM image with the specified file system and the file
"""
2021-02-01 17:39:50 +00:00
url = request.form.get("url")
iso_type = request.form.get("type")
local_file = request.form.get("file")
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,
message=_("%(iso_type)s is not a valid CD-ROM format.", iso_type=iso_type),
)
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)
process = ReturnCodeMapper.add_msg(process)
if not process["status"]:
return response(
error=True,
message=_(
"The following error occurred when creating the CD-ROM image: %(error)s",
error=process["msg"],
),
)
return response(
message=_(
"CD-ROM image %(file_name)s with type %(iso_type)s was created.",
file_name=process["file_name"],
iso_type=iso_type,
),
)
@APP.route("/files/download_url", methods=["POST"])
@login_required
def download_file():
"""
Downloads a remote file onto the images dir on the system
"""
destination = request.form.get("destination")
2021-02-01 17:39:50 +00:00
url = request.form.get("url")
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)
server_info = piscsi_cmd.get_server_info()
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"))
process = file_cmd.download_to_dir(url, destination_dir, Path(url).name)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
return response(message=process["msg"])
return response(
error=True,
message=_(
"The following error occurred when downloading: %(error)s",
error=process["msg"],
),
)
@APP.route("/files/upload", methods=["POST"])
def upload_file():
"""
Uploads a file from the local computer to the images dir on the system
Depending on the Dropzone.js JavaScript library
"""
# Due to the embedded javascript library, we cannot use the @login_required decorator
auth = auth_active(AUTH_GROUP)
if auth["status"] and "username" not in session:
return make_response(auth["msg"], 403)
destination = request.form.get("destination")
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)
server_info = piscsi_cmd.get_server_info()
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
elif destination == "piscsi_config":
destination_dir = CFG_DIR
else:
return make_response(_("Unknown destination"), 403)
return upload_with_dropzonejs(destination_dir)
@APP.route("/files/create", methods=["POST"])
@login_required
def create_file():
"""
Creates an empty image file in the images dir
"""
file_name = Path(request.form.get("file_name"))
size = int(request.form.get("size")) * 1024 * 1024
file_type = request.form.get("type")
drive_name = request.form.get("drive_name")
drive_format = request.form.get("drive_format")
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}"
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)
if not process["status"]:
return response(error=True, message=process["msg"])
message_postfix = ""
# Formatting and injecting driver, if one is chosen
if drive_format:
volume_name = f"HD {size / 1024 / 1024:0.0f}M"
known_formats = [
"Lido 7.56",
"SpeedTools 3.6",
"FAT16",
"FAT32",
]
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,
),
)
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,
),
)
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(
full_file_name,
# FAT volume labels are max 11 chars
volume_name[:11],
fat_size,
)
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(
full_file_name,
volume_name,
driver_base_path / Path(drive_format.replace(" ", "-") + ".img"),
)
if not process["status"]:
return response(error=True, message=process["msg"])
# Creating the drive properties file, if one is chosen
if drive_name:
properties = get_properties_by_drive_name(APP.config["PISCSI_DRIVE_PROPERTIES"], drive_name)
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"])
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,
)
return response(
status_code=201,
message=_(
"Image file created: %(file_name)s%(drive_format)s",
file_name=full_file_name,
drive_format=message_postfix,
),
image=full_file_name,
)
@APP.route("/files/download_image", methods=["POST"])
@login_required
def download_image():
"""
Downloads a file from the image 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"])
server_info = piscsi_cmd.get_server_info()
return send_from_directory(server_info["image_dir"], str(file_name), as_attachment=True)
@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)
@APP.route("/files/delete", methods=["POST"])
@login_required
def delete():
"""
Deletes a specified file in the images dir
"""
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"])
server_info = piscsi_cmd.get_server_info()
process = file_cmd.delete_file(Path(server_info["image_dir"]) / file_name)
process = ReturnCodeMapper.add_msg(process)
if not process["status"]:
return response(error=True, message=process["msg"])
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
# Delete the drive properties file, if it exists
prop_file_path = Path(CFG_DIR) / f"{file_name}.{PROPERTIES_SUFFIX}"
if prop_file_path.is_file():
process = file_cmd.delete_file(prop_file_path)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
return response(
message=_(
"Image file with properties deleted: %(file_name)s",
file_name=str(file_name),
),
)
else:
return response(error=True, message=process["msg"])
return response(
message=_(
"Image file deleted: %(file_name)s",
file_name=str(file_name),
),
)
Disk image profile management using a sidecar config file (#242) * Handle a case where reserved ids on the Web UI side are not actually reserved on the backend side * Better error handling when no device is found in list_devices * Better warning message * Tag message as error * Fix device_info * Get reserved ids from the server instead of storing a client side state, which caused front and backend to get out of sync in certain cases. * Initial implementation of sidecar configuration reading and writing * Use bytes for drive image creation internally * Add named drive section * Move header to base.html * Create the disk profile list page * Make lists of HDDs, CDRs, and Removable drives * Implement disk image + sidecar creation * Implement CD-ROM device sidecar creation method * Add more device configurations * Add disclaimer * Hide URL if none is provided * Make the web ui use the new protobuf parameter maps * Make daynaport attaching UI more flexible * Use the protobuf interface to create image files * Use new create image method for the sidecar flow as well * Move file deletion logic to protobuf commands; Refactor saving/loading config files * Update disk image creation * Fix error * Disk images the script makes are in Mac format * Add blurb about the risks with using Lido driver (issue#40) to the easyinstall script, while pushing less for using that feature. * Make shutdown and reboot async operations * More informative footer contents * Wordsmith the Mac drive options * Link to relevant section in the wiki * Added GET_IMAGE_FILES * Added default folder to GET_IMAGE_FILES * Renaming * Updated setting image folder * Lists available net interfaces as a drop down when attaching daynaport * Macs should use the hds image file ending * Fixed default image folder handling * Refer to device properties, instead of sidecars * Added NETWORK_INTERFACES_INFO * Filter "lo" * Use PF_INET in favor of PF_INET6 * Added network interfaces to server info * Drive property file ending defined in one place; Add handling of common urllib and file system exceptions. * Use protobuf interface to get network interface info * Use protobuf interface for list_files * Repeated field cleanup * Renaming * Added DEVICE_TYPES_INFO * Comment update * Added -y option to rasctl * Add the remaining recommended drive profiles provided by rpajarola * Fix typos * Add warnings to CD-ROM descriptions * Add more recommended Sun drives * Add capacity to name * Move footer into base.html * Handle removable drive insertion in the attach method (easy to do with protobuf) * Limit which arguments to pass to an image injection command * Cleanup * Sort image and config files alphabetically * Make compatible with updated protobuf interface * Sort drives alphabetically by name * Decriptive text for CD-ROM section * Better description * Hyperlink to disks page instead of button Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
2021-09-19 21:29:01 +00:00
@APP.route("/files/rename", methods=["POST"])
@login_required
def rename():
"""
Renames a specified file in the images dir
"""
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"])
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)
if not process["status"]:
return response(error=True, message=process["msg"])
# Rename the drive properties file, if it exists
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():
process = file_cmd.rename_file(prop_file_path, new_prop_file_path)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
return response(
message=_(
"Image file with properties renamed to: %(file_name)s",
file_name=str(new_file_name),
),
)
else:
return response(error=True, message=process["msg"])
return response(
message=_(
"Image file renamed to: %(file_name)s",
file_name=str(new_file_name),
),
)
@APP.route("/files/copy", methods=["POST"])
@login_required
def copy():
"""
Creates a copy of a specified file in the images dir
"""
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"])
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)
if not process["status"]:
return response(error=True, message=process["msg"])
# Create a copy of the drive properties file, if it exists
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():
process = file_cmd.copy_file(prop_file_path, new_prop_file_path)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
return response(
message=_(
"Copy of image file with properties saved as: %(file_name)s",
file_name=str(new_file_name),
),
)
else:
return response(error=True, message=process["msg"])
return response(
message=_(
"Copy of image file saved as: %(file_name)s",
file_name=str(new_file_name),
),
)
@APP.route("/files/extract_image", methods=["POST"])
@login_required
def extract_image():
"""
Extracts all or a subset of files in the specified archive
"""
archive_file = Path(request.form.get("archive_file"))
archive_members_raw = request.form.get("archive_members") or None
archive_members = archive_members_raw.split("|") if archive_members_raw else None
safe_path = is_safe_path(archive_file)
if not safe_path["status"]:
return response(error=True, message=safe_path["msg"])
extract_result = file_cmd.extract_image(str(archive_file), archive_members)
if extract_result["return_code"] == ReturnCodes.EXTRACTIMAGE_SUCCESS:
for properties_file in extract_result["properties_files_moved"]:
if properties_file["status"]:
logging.info(
"Properties file %s moved to %s",
properties_file["name"],
CFG_DIR,
)
else:
logging.warning(
"Failed to move properties file %s to %s",
properties_file["name"],
CFG_DIR,
)
return response(message=ReturnCodeMapper.add_msg(extract_result).get("msg"))
return response(error=True, message=ReturnCodeMapper.add_msg(extract_result).get("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
2021-12-27 21:21:56 +00:00
@APP.route("/language", methods=["POST"])
def change_language():
"""
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
piscsi_cmd.locale = session["language"]
file_cmd.locale = session["language"]
2021-12-27 21:21:56 +00:00
refresh()
language = Locale.parse(locale)
language_name = language.get_language_name(locale)
return response(message=_("Changed Web Interface language to %(locale)s", locale=language_name))
2021-12-27 21:21:56 +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))
@APP.route("/healthcheck", methods=["GET"])
def healthcheck():
return "", 200
@APP.before_first_request
def detect_locale():
"""
Get the detected locale to use for UI string translations.
This requires the Flask app to have started first.
"""
2021-12-27 21:21:56 +00:00
session["language"] = get_locale()
piscsi_cmd.locale = session["language"]
file_cmd.locale = session["language"]
@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)
if __name__ == "__main__":
APP.secret_key = "piscsi_is_awesome_insecure_secret_key"
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
parser = argparse.ArgumentParser(description="PiSCSI Web Interface command line arguments")
parser.add_argument(
"--port",
type=int,
default=8080,
action="store",
help="Port number the web server will run on",
)
parser.add_argument(
"--password",
type=str,
default="",
action="store",
help="Token password string for authenticating with PiSCSI",
)
parser.add_argument(
"--backend-host",
type=str,
default="localhost",
action="store",
help="PiSCSI backend hostname. Default: localhost",
)
parser.add_argument(
"--backend-port",
type=int,
default=6868,
action="store",
help="PiSCSI backend port number. Default: 6868",
)
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"],
)
parser.add_argument(
"--dev-mode",
action="store_true",
help="Run in development mode",
)
arguments = parser.parse_args()
APP.config["PISCSI_TOKEN"] = arguments.password
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"],
},
}
)
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"])
sys_cmd = SysCmds()
if not piscsi_cmd.is_token_auth()["status"] and not APP.config["PISCSI_TOKEN"]:
raise Exception(
"PiSCSI is password protected. "
"Start the Web Interface with the --password parameter."
)
if Path(f"{CFG_DIR}/{DEFAULT_CONFIG}").is_file():
file_cmd.read_config(DEFAULT_CONFIG)
if Path(f"{DRIVE_PROPERTIES_FILE}").is_file():
process = file_cmd.read_drive_properties(DRIVE_PROPERTIES_FILE)
if process["status"]:
APP.config["PISCSI_DRIVE_PROPERTIES"] = process["conf"]
else:
APP.config["PISCSI_DRIVE_PROPERTIES"] = []
logging.error(process["msg"])
else:
APP.config["PISCSI_DRIVE_PROPERTIES"] = []
logging.warning("Could not read drive properties from %s", DRIVE_PROPERTIES_FILE)
logging.info("Starting WSGI server...")
if arguments.dev_mode:
logging.info("Dev mode enabled")
APP.debug = True
from werkzeug.debug import DebuggedApplication
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)