mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-21 08:29:59 +00:00
Web UI: Handling for non-existence of working dirs (#1130)
This commit is contained in:
parent
5414a78098
commit
ff017a9c1d
@ -710,6 +710,29 @@ function setupWirelessNetworking() {
|
||||
sudo reboot
|
||||
}
|
||||
|
||||
# Detects or creates the file sharing directory
|
||||
function createFileSharingDir() {
|
||||
if [ ! -d "$FILE_SHARE_PATH" ] && [ -d "$HOME/afpshare" ]; then
|
||||
echo
|
||||
echo "File server dir $HOME/afpshare detected. This script will rename it to $FILE_SHARE_PATH."
|
||||
echo
|
||||
echo "Do you want to proceed with the installation? [y/N]"
|
||||
read -r REPLY
|
||||
if [ "$REPLY" == "y" ] || [ "$REPLY" == "Y" ]; then
|
||||
sudo mv "$HOME/afpshare" "$FILE_SHARE_PATH" || exit 1
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
elif [ -d "$FILE_SHARE_PATH" ]; then
|
||||
echo "Found a $FILE_SHARE_PATH directory; will use it for file sharing."
|
||||
else
|
||||
echo "Creating the $FILE_SHARE_PATH directory and granting read/write permissions to all users..."
|
||||
sudo mkdir -p "$FILE_SHARE_PATH"
|
||||
sudo chown -R "$USER:$USER" "$FILE_SHARE_PATH"
|
||||
chmod -Rv 775 "$FILE_SHARE_PATH"
|
||||
fi
|
||||
}
|
||||
|
||||
# Downloads, compiles, and installs Netatalk (AppleShare server)
|
||||
function installNetatalk() {
|
||||
NETATALK_VERSION="230301"
|
||||
@ -729,19 +752,6 @@ function installNetatalk() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d "$FILE_SHARE_PATH" ] && [ -d "$HOME/afpshare" ]; then
|
||||
echo
|
||||
echo "File server dir $HOME/afpshare detected. This script will rename it to $FILE_SHARE_PATH."
|
||||
echo
|
||||
echo "Do you want to proceed with the installation? [y/N]"
|
||||
read -r REPLY
|
||||
if [ "$REPLY" == "y" ] || [ "$REPLY" == "Y" ]; then
|
||||
sudo mv "$HOME/afpshare" "$FILE_SHARE_PATH" || exit 1
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Downloading tarball to $HOME..."
|
||||
cd $HOME || exit 1
|
||||
@ -874,26 +884,6 @@ function installSamba() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d "$FILE_SHARE_PATH" ] && [ -d "$HOME/afpshare" ]; then
|
||||
echo
|
||||
echo "File server dir $HOME/afpshare detected. This script will rename it to $FILE_SHARE_PATH."
|
||||
echo
|
||||
echo "Do you want to proceed with the installation? [y/N]"
|
||||
read -r REPLY
|
||||
if [ "$REPLY" == "y" ] || [ "$REPLY" == "Y" ]; then
|
||||
sudo mv "$HOME/afpshare" "$FILE_SHARE_PATH" || exit 1
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
elif [ -d "$FILE_SHARE_PATH" ]; then
|
||||
echo "Found a $FILE_SHARE_PATH directory; will use it for file sharing."
|
||||
else
|
||||
echo "Creating the $FILE_SHARE_PATH directory and granting read/write permissions to all users..."
|
||||
sudo mkdir -p "$FILE_SHARE_PATH"
|
||||
sudo chown -R "$USER:$USER" "$FILE_SHARE_PATH"
|
||||
chmod -Rv 775 "$FILE_SHARE_PATH"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Installing dependencies..."
|
||||
sudo apt-get update || true
|
||||
@ -1279,6 +1269,7 @@ function runChoice() {
|
||||
;;
|
||||
7)
|
||||
echo "Installing AppleShare File Server"
|
||||
createFileSharingDir
|
||||
installNetatalk
|
||||
echo "Installing AppleShare File Server - Complete!"
|
||||
;;
|
||||
@ -1290,6 +1281,7 @@ function runChoice() {
|
||||
echo "WARNING: The FTP server may transfer unencrypted data over the network."
|
||||
echo "Proceed with this installation only if you are on a private, secure network."
|
||||
sudoCheck
|
||||
createFileSharingDir
|
||||
installFtp
|
||||
echo "Installing FTP File Server - Complete!"
|
||||
;;
|
||||
@ -1301,6 +1293,7 @@ function runChoice() {
|
||||
echo " - Create a directory in the current user's home directory where shared files will be stored"
|
||||
echo " - Create a Samba user for the current user"
|
||||
sudoCheck
|
||||
createFileSharingDir
|
||||
installSamba
|
||||
echo "Installing SMB File Server - Complete!"
|
||||
;;
|
||||
|
@ -383,8 +383,11 @@
|
||||
</summary>
|
||||
<ul>
|
||||
<li>{{ _("Disk Images") }} = {{ env["image_dir"] }}</li>
|
||||
{% if file_server_dir_exists %}
|
||||
<li>{{ _("Shared Files") }} = {{ FILE_SERVER_DIR }}</li>
|
||||
<li>{{ _("To access shared files remotely, you may have to install one of the file servers first.") }}</li>
|
||||
{% else %}
|
||||
<li>{{ _("Install a file server and create the shared files directory in order to share files between the Pi and your vintage computers.") }}</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</details>
|
||||
|
||||
@ -399,6 +402,7 @@
|
||||
{% endfor %}
|
||||
<option value="/" selected>/</option>
|
||||
</select>
|
||||
{% if file_server_dir_exists %}
|
||||
<input type="radio" name="destination" id="shared_files" value="shared_files">
|
||||
<label for="shared_files">{{ _("Shared Files") }}</label>
|
||||
<select name="shared_subdir" id="shared_subdir">
|
||||
@ -407,6 +411,7 @@
|
||||
{% endfor %}
|
||||
<option value="/" selected>/</option>
|
||||
</select>
|
||||
{% endif %}
|
||||
<input type="submit" value="{{ _("Download") }}" onclick="processNotify('{{ _("Downloading File...") }}')">
|
||||
</form>
|
||||
</section>
|
||||
|
@ -6,7 +6,9 @@
|
||||
<li>{{ _("The largest file size accepted in this form is %(max_file_size)s MiB. Use other file transfer means for larger files.", max_file_size=max_file_size) }}</li>
|
||||
<li>{{ _("You have to manually clean up partially uploaded files, as a result of cancelling the upload or closing this page.") }}</li>
|
||||
<li>{{ _("Disk Images") }} = {{ env["image_dir"] }}</li>
|
||||
{% if file_server_dir_exists %}
|
||||
<li>{{ _("Shared Files") }} = {{ FILE_SERVER_DIR }}</li>
|
||||
{% endif %}
|
||||
<li>{{ _("PiSCSI Config") }} = {{ CFG_DIR }}</li>
|
||||
</ul>
|
||||
|
||||
@ -20,6 +22,7 @@
|
||||
{% endfor %}
|
||||
<option value="/" selected>/</option>
|
||||
</select>
|
||||
{% if file_server_dir_exists %}
|
||||
<input type="radio" name="destination" id="shared_files" value="shared_files">
|
||||
<label for="shared_files">{{ _("Shared Files") }}</label>
|
||||
<select name="shared_subdir" id="shared_subdir">
|
||||
@ -28,6 +31,7 @@
|
||||
{% endfor %}
|
||||
<option value="/" selected>/</option>
|
||||
</select>
|
||||
{% endif %}
|
||||
<input type="radio" name="destination" id="piscsi_config" value="piscsi_config">
|
||||
<label for="piscsi_config">{{ _("PiSCSI Config") }}</label>
|
||||
</form>
|
||||
|
@ -24,7 +24,6 @@ from flask import (
|
||||
send_from_directory,
|
||||
make_response,
|
||||
session,
|
||||
abort,
|
||||
jsonify,
|
||||
)
|
||||
|
||||
@ -44,6 +43,7 @@ from return_code_mapper import ReturnCodeMapper
|
||||
from socket_cmds_flask import SocketCmdsFlask
|
||||
|
||||
from web_utils import (
|
||||
working_dirs_exist,
|
||||
sort_and_format_devices,
|
||||
get_valid_scsi_ids,
|
||||
map_device_types_and_names,
|
||||
@ -209,16 +209,9 @@ def index():
|
||||
"""
|
||||
Sets up data structures for and renders the index page
|
||||
"""
|
||||
if not piscsi_cmd.is_token_auth()["status"] and not APP.config["PISCSI_TOKEN"]:
|
||||
abort(
|
||||
403,
|
||||
_(
|
||||
"PiSCSI is password protected. "
|
||||
"Start the Web Interface with the --password parameter."
|
||||
),
|
||||
)
|
||||
|
||||
server_info = piscsi_cmd.get_server_info()
|
||||
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
||||
|
||||
devices = piscsi_cmd.list_devices()
|
||||
device_types = map_device_types_and_names(piscsi_cmd.get_device_types()["device_types"])
|
||||
image_files = file_cmd.list_images()
|
||||
@ -277,6 +270,7 @@ def index():
|
||||
drive_properties=format_drive_properties(APP.config["PISCSI_DRIVE_PROPERTIES"]),
|
||||
images_subdirs=file_cmd.list_subdirs(server_info["image_dir"]),
|
||||
shared_subdirs=file_cmd.list_subdirs(FILE_SERVER_DIR),
|
||||
file_server_dir_exists=Path(FILE_SERVER_DIR).exists(),
|
||||
RESERVATIONS=RESERVATIONS,
|
||||
CFG_DIR=CFG_DIR,
|
||||
FILE_SERVER_DIR=FILE_SERVER_DIR,
|
||||
@ -302,6 +296,8 @@ def drive_list():
|
||||
"""
|
||||
Sets up the data structures and kicks off the rendering of the drive list page
|
||||
"""
|
||||
server_info = piscsi_cmd.get_server_info()
|
||||
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
||||
|
||||
return response(
|
||||
template="drives.html",
|
||||
@ -317,12 +313,14 @@ def upload_page():
|
||||
Sets up the data structures and kicks off the rendering of the file uploading page
|
||||
"""
|
||||
server_info = piscsi_cmd.get_server_info()
|
||||
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
||||
|
||||
return response(
|
||||
template="upload.html",
|
||||
page_title=_("PiSCSI File Upload"),
|
||||
images_subdirs=file_cmd.list_subdirs(server_info["image_dir"]),
|
||||
shared_subdirs=file_cmd.list_subdirs(FILE_SERVER_DIR),
|
||||
file_server_dir_exists=Path(FILE_SERVER_DIR).exists(),
|
||||
max_file_size=int(int(MAX_FILE_SIZE) / 1024 / 1024),
|
||||
CFG_DIR=CFG_DIR,
|
||||
FILE_SERVER_DIR=FILE_SERVER_DIR,
|
||||
@ -516,6 +514,7 @@ def show_diskinfo():
|
||||
if not safe_path["status"]:
|
||||
return response(error=True, message=safe_path["msg"])
|
||||
server_info = piscsi_cmd.get_server_info()
|
||||
working_dirs_exist((server_info["image_dir"], CFG_DIR))
|
||||
returncode, diskinfo = sys_cmd.get_diskinfo(Path(server_info["image_dir"]) / file_name)
|
||||
if returncode == 0:
|
||||
return response(
|
||||
@ -1474,6 +1473,12 @@ if __name__ == "__main__":
|
||||
file_cmd = FileCmds(sock_cmd=sock_cmd, piscsi=piscsi_cmd, token=APP.config["PISCSI_TOKEN"])
|
||||
sys_cmd = SysCmds()
|
||||
|
||||
if not piscsi_cmd.is_token_auth()["status"] and not APP.config["PISCSI_TOKEN"]:
|
||||
raise Exception(
|
||||
"PiSCSI is password protected. "
|
||||
"Start the Web Interface with the --password parameter."
|
||||
)
|
||||
|
||||
if Path(f"{CFG_DIR}/{DEFAULT_CONFIG}").is_file():
|
||||
file_cmd.read_config(DEFAULT_CONFIG)
|
||||
if Path(f"{DRIVE_PROPERTIES_FILE}").is_file():
|
||||
|
@ -9,13 +9,26 @@ from pathlib import Path
|
||||
from ua_parser import user_agent_parser
|
||||
from re import findall
|
||||
|
||||
from flask import request, make_response
|
||||
from flask import request, make_response, abort
|
||||
from flask_babel import _
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from piscsi.sys_cmds import SysCmds
|
||||
|
||||
|
||||
def working_dirs_exist(working_dirs):
|
||||
"""
|
||||
Method for validating that working dirs exist.
|
||||
Takes (tuple) of (str) working_dirs with paths to required dirs.
|
||||
"""
|
||||
for dir_path in working_dirs:
|
||||
if not Path(dir_path).exists():
|
||||
abort(
|
||||
503,
|
||||
_(f"Please create directory: {dir_path}"),
|
||||
)
|
||||
|
||||
|
||||
def get_valid_scsi_ids(devices, reserved_ids):
|
||||
"""
|
||||
Takes a list of (dict)s devices, and list of (int)s reserved_ids.
|
||||
|
Loading…
Reference in New Issue
Block a user