Improved gui
This commit is contained in:
parent
ec024c9992
commit
40736d1bf2
@ -12,13 +12,10 @@ fi
|
||||
USERNAME="$1"
|
||||
PASSWORD="$2"
|
||||
|
||||
if [[ -z "$USERNAME" ]]; then
|
||||
read -p "Enter username: " USERNAME
|
||||
fi
|
||||
|
||||
if [[ -z "$PASSWORD" ]]; then
|
||||
read -s -p "Enter password: " PASSWORD
|
||||
echo
|
||||
# If no username or password provided, exit with error
|
||||
if [[ -z "$USERNAME" || -z "$PASSWORD" ]]; then
|
||||
echo "Usage: $0 <username> <password>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create system user without extra fields
|
||||
@ -39,11 +36,11 @@ else
|
||||
echo "Failed to add Samba user."
|
||||
fi
|
||||
|
||||
|
||||
log_file="$SMB_TOOLS_PATH/filebrowser/addusers.txt"
|
||||
|
||||
if [ -f "$log_file" ]; then
|
||||
echo "$USERNAME:$PASSWORD" >> "$log_file"
|
||||
fi
|
||||
|
||||
docker restart filebrowser
|
||||
# Non-blocking docker restart
|
||||
docker restart filebrowser </dev/null &>/dev/null &
|
@ -1,7 +0,0 @@
|
||||
alias smbtools_user_add=$SMB_TOOLS_PATH/add_smb_user.sh
|
||||
alias smbtools_user_remove=$SMB_TOOLS_PATH/remove_smb_user.sh
|
||||
alias smbtools_user_list=$SMB_TOOLS_PATH/list_smb_users.sh
|
||||
|
||||
alias smbtools_share_create=$SMB_TOOLS_PATH/create_share.sh
|
||||
alias smbtools_share_remove=$SMB_TOOLS_PATH/remove_share.sh
|
||||
alias smbtools_share_list=$SMB_TOOLS_PATH/list_smb_shares.sh
|
28
gui/dialog_share_create.sh
Executable file
28
gui/dialog_share_create.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
# Ask for username
|
||||
dialog --backtitle "Create SMB share" --inputbox "Enter share name:" 10 40 2>"$TMP_FILE"
|
||||
SHARE_NAME=$(<"$TMP_FILE")
|
||||
|
||||
# Ask for password (input will be hidden)
|
||||
dialog --backtitle "Create SMB share" --inputbox "Enter associated username:" 10 40 2>"$TMP_FILE"
|
||||
USERNAME=$(<"$TMP_FILE")
|
||||
|
||||
|
||||
|
||||
# 3) Call the external script and capture output
|
||||
# adjust the path (“../add_smb_user.sh”) as needed
|
||||
TMP_OUT=$(mktemp)
|
||||
bash ./../create_user_share.sh "$SHARE_NAME" "$USERNAME" >"$TMP_OUT" 2>&1
|
||||
|
||||
# 4) Display the result (use --msgbox for short, --textbox for multiline)
|
||||
dialog --backtitle "Create SMB share" \
|
||||
--title "Result" \
|
||||
--textbox "$TMP_OUT" 20 60
|
||||
|
||||
rm -f "$TMP_OUT"
|
||||
|
||||
|
||||
rm -f "$TMP_FILE"
|
30
gui/dialog_user_add.sh
Executable file
30
gui/dialog_user_add.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
# Ask for username
|
||||
dialog --backtitle "Add User" --inputbox "Enter new username:" 10 40 2>"$TMP_FILE"
|
||||
USERNAME=$(<"$TMP_FILE")
|
||||
|
||||
# Ask for password (input will be hidden)
|
||||
dialog --backtitle "Add User" --insecure --passwordbox "Enter password for $USERNAME:" 10 40 2>"$TMP_FILE"
|
||||
PASSWORD=$(<"$TMP_FILE")
|
||||
|
||||
|
||||
|
||||
# 3) Call the external script and capture output
|
||||
# adjust the path (“../add_smb_user.sh”) as needed
|
||||
TMP_OUT=$(mktemp)
|
||||
bash ./../add_smb_user.sh "$USERNAME" "$PASSWORD" >"$TMP_OUT" 2>&1
|
||||
|
||||
# 4) Display the result (use --msgbox for short, --textbox for multiline)
|
||||
dialog --backtitle "Add SMB User" \
|
||||
--title "Result" \
|
||||
--textbox "$TMP_OUT" 20 60
|
||||
|
||||
rm -f "$TMP_OUT"
|
||||
|
||||
|
||||
# dialog --msgbox "User '$USERNAME' with given password would be created." 8 50
|
||||
|
||||
rm -f "$TMP_FILE"
|
20
gui/dialog_user_list.sh
Executable file
20
gui/dialog_user_list.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
# 3) Call the external script and capture output
|
||||
# adjust the path (“../add_smb_user.sh”) as needed
|
||||
TMP_OUT=$(mktemp)
|
||||
bash ./../list_smb_users.sh >"$TMP_OUT" 2>&1
|
||||
|
||||
# 4) Display the result (use --msgbox for short, --textbox for multiline)
|
||||
dialog --backtitle "SMB Users" \
|
||||
--title "SMB Users" \
|
||||
--textbox "$TMP_OUT" 20 60
|
||||
|
||||
rm -f "$TMP_OUT"
|
||||
|
||||
|
||||
# dialog --msgbox "User '$USERNAME' with given password would be created." 8 50
|
||||
|
||||
rm -f "$TMP_FILE"
|
26
gui/dialog_user_remove.sh
Executable file
26
gui/dialog_user_remove.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
# Ask for username
|
||||
dialog --backtitle "Remove SMB User" --inputbox "Enter username to be removed:" 10 40 2>"$TMP_FILE"
|
||||
USERNAME=$(<"$TMP_FILE")
|
||||
|
||||
|
||||
|
||||
# 3) Call the external script and capture output
|
||||
# adjust the path (“../add_smb_user.sh”) as needed
|
||||
TMP_OUT=$(mktemp)
|
||||
bash ./../remove_smb_user.sh "$USERNAME" >"$TMP_OUT" 2>&1
|
||||
|
||||
# 4) Display the result (use --msgbox for short, --textbox for multiline)
|
||||
dialog --backtitle "Remove SMB User" \
|
||||
--title "Result" \
|
||||
--textbox "$TMP_OUT" 20 60
|
||||
|
||||
rm -f "$TMP_OUT"
|
||||
|
||||
|
||||
# dialog --msgbox "User '$USERNAME' with given password would be created." 8 50
|
||||
|
||||
rm -f "$TMP_FILE"
|
49
gui/main.sh
Executable file
49
gui/main.sh
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
TITLE="System Administration Tool"
|
||||
|
||||
while true; do
|
||||
dialog --clear \
|
||||
--backtitle "$TITLE" \
|
||||
--title "Main Menu" \
|
||||
--menu "Choose an action:" 15 50 6 \
|
||||
1 "Add User" \
|
||||
2 "Remove User" \
|
||||
3 "List Users" \
|
||||
4 "Create Share" \
|
||||
5 "Remove Share" \
|
||||
6 "Exit" 2>"$TMP_FILE"
|
||||
|
||||
CHOICE=$(<"$TMP_FILE")
|
||||
|
||||
case $CHOICE in
|
||||
1)
|
||||
./dialog_user_add.sh
|
||||
;;
|
||||
2)
|
||||
./dialog_user_remove.sh
|
||||
;;
|
||||
3)
|
||||
./dialog_user_list.sh
|
||||
;;
|
||||
4)
|
||||
./dialog_share_create.sh
|
||||
;;
|
||||
5)
|
||||
dialog --inputbox "Enter share name to remove:" 10 40 2>"$TMP_FILE"
|
||||
SHARE=$(<"$TMP_FILE")
|
||||
dialog --msgbox "Share '$SHARE' would be removed." 8 40
|
||||
;;
|
||||
6)
|
||||
break
|
||||
;;
|
||||
*)
|
||||
dialog --msgbox "Invalid option." 8 30
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
clear
|
||||
rm -f "$TMP_FILE"
|
||||
echo "Exited."
|
@ -28,16 +28,6 @@ else
|
||||
echo "Added SMB_TOOLS_PATH to ~/.bashrc"
|
||||
fi
|
||||
|
||||
ALIASES_LINE="source $SMB_TOOLS_PATH/aliases.sh"
|
||||
|
||||
# Check if it's already set in .bashrc
|
||||
if grep -Fxq "$ALIASES_LINE" "$HOME/.bashrc"; then
|
||||
echo "SmbTools aliases already set"
|
||||
else
|
||||
echo "$ALIASES_LINE" >> "$HOME/.bashrc"
|
||||
echo "Set SmbTools aliases"
|
||||
fi
|
||||
|
||||
source $HOME/.bashrc
|
||||
|
||||
# Set it for the current script execution too
|
||||
|
Loading…
x
Reference in New Issue
Block a user