-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix account manager * Fix missing escalation tools and checkenv --------- Co-authored-by: nnyyxxxx <[email protected]>
- Loading branch information
Showing
18 changed files
with
175 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -e | ||
|
||
. ./utility_functions.sh | ||
. ../utility_functions.sh | ||
|
||
. ../../common-script.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -e | ||
|
||
. ./utility_functions.sh | ||
. ../utility_functions.sh | ||
|
||
. ../../common-script.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -e | ||
|
||
. ./utility_functions.sh | ||
. ../utility_functions.sh | ||
|
||
. ../../common-script.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -e | ||
|
||
. ./utility_functions.sh | ||
. ../utility_functions.sh | ||
|
||
. ../../common-script.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -e | ||
|
||
. ./utility_functions.sh | ||
. ../utility_functions.sh | ||
|
||
. ../../common-script.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -e | ||
|
||
. ./utility_functions.sh | ||
. ../utility_functions.sh | ||
|
||
. ../../common-script.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -e | ||
|
||
. ./utility_functions.sh | ||
. ../utility_functions.sh | ||
|
||
. ../../common-script.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -e | ||
|
||
. ./utility_functions.sh | ||
. ../utility_functions.sh | ||
|
||
. ../../common-script.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -e | ||
|
||
. ./utility_functions.sh | ||
. ../utility_functions.sh | ||
|
||
. ../../common-script.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -e | ||
|
||
. ./utility_functions.sh | ||
. ../utility_functions.sh | ||
|
||
. ../../common-script.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,47 @@ | ||
#!/bin/sh -e | ||
|
||
. ../../common-script.sh | ||
. ./utility_functions.sh | ||
|
||
clear | ||
printf "%b\n" "${YELLOW}Add to group${RC}" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
. ../utility_functions.sh | ||
|
||
username=$(promptUsername "" "non-root") || exit 1 | ||
user_groups=$(groups "$username" | cut -d: -f2 | sort | tr '\n' ' ') | ||
addToGroup() { | ||
clear | ||
printf "%b\n" "${YELLOW}Add to group${RC}" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
|
||
printf "%b\n" "${YELLOW}Groups user $username is in:${RC} $user_groups" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
printf "%b" "${YELLOW}Enter the username: ${RC}" | ||
read -r username | ||
user_groups=$(groups "$username" | cut -d: -f2 | sort | tr '\n' ' ') | ||
|
||
available_groups=$(cut -d: -f1 /etc/group | sort | tr '\n' ' ') | ||
printf "%b\n" "${YELLOW}Groups user $username is in:${RC} $user_groups" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
|
||
printf "%b\n" "${YELLOW}Available groups:${RC} $available_groups" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
available_groups=$(cut -d: -f1 /etc/group | sort | tr '\n' ' ') | ||
|
||
printf "%b\n" "${YELLOW}Enter the groups you want to add user $username to (space-separated):${RC} " | ||
read -r groups | ||
printf "%b\n" "${YELLOW}Available groups:${RC} $available_groups" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
|
||
checkEmpty "$groups" || exit 1 | ||
checkGroupAvailabe "$groups" "$available_groups" || exit 1 | ||
printf "%b" "${YELLOW}Enter the groups you want to add user $username to (space-separated): ${RC}" | ||
read -r groups | ||
|
||
groups_to_add=$(echo "$groups" | tr ' ' ',') | ||
checkEmpty "$groups" || exit 1 | ||
if ! checkGroups "$groups" "$available_groups"; then | ||
printf "%b\n" "${RED}One or more groups are not available.${RC}" | ||
exit 1 | ||
fi | ||
|
||
printf "Are you sure you want to add user $username to $groups_to_add? [Y/N]: " | ||
read -r confirm | ||
confirmAction || exit 1 | ||
groups_to_add=$(echo "$groups" | tr ' ' ',') | ||
|
||
$ESCALATION_TOOL usermod -aG $groups_to_add "$username" | ||
printf "%b" "${YELLOW}Are you sure you want to add user $username to $groups_to_add? [Y/n]: ${RC}" | ||
read -r confirm | ||
confirmAction || exit 1 | ||
|
||
printf "%b\n" "${GREEN}User successfully added to the $groups_to_add${RC}" | ||
"$ESCALATION_TOOL" usermod -aG "$groups_to_add" "$username" | ||
|
||
checkEnv | ||
printf "%b\n" "${GREEN}User successfully added to the $groups_to_add${RC}" | ||
} | ||
|
||
checkEnv | ||
checkEscalationTool | ||
checkGroups | ||
addToGroup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
#!/bin/sh -e | ||
|
||
. ../../common-script.sh | ||
. ./utility_functions.sh | ||
|
||
clear | ||
printf "%b\n" "${YELLOW}Create a new user${RC}" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
. ../utility_functions.sh | ||
|
||
username=$(promptUsername "add" "non-root") || exit 1 | ||
createUser() { | ||
clear | ||
printf "%b\n" "${YELLOW}Create a new user${RC}" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
printf "%b" "${YELLOW}Enter the username: ${RC}" | ||
read -r username | ||
|
||
# Check if username is valid | ||
if ! echo "$username" | grep '^[a-z][-a-z0-9_]*$' > /dev/null; then | ||
printf "%b\n" "${RED}Username must only contain letters, numbers, hyphens, and underscores. It cannot start with a number or contain spaces.${RC}" | ||
exit 1 | ||
fi | ||
if ! echo "$username" | grep '^[a-zA-Z]*$' > /dev/null; then | ||
printf "%b\n" "${RED}Username must only contain letters and cannot contain spaces.${RC}" | ||
exit 1 | ||
fi | ||
|
||
password=$(promptPassword) || exit 1 | ||
printf "%b" "${YELLOW}Enter the password: ${RC}" | ||
read -r password | ||
printf "%b" "${YELLOW}Enter the password again: ${RC}" | ||
read -r password_confirmation | ||
|
||
$ESCALATION_TOOL useradd -m "$username" -g users -s /bin/bash | ||
echo "$username:$password" | "$ESCALATION_TOOL" chpasswd | ||
if [ "$password" != "$password_confirmation" ]; then | ||
printf "%b\n" "${RED}Passwords do not match${RC}" | ||
exit 1 | ||
fi | ||
|
||
printf "%b\n" "${GREEN}User $username created successfully${RC}" | ||
printf "%b\n" "${GREEN}To add additional groups use Add User To Groups${RC}" | ||
"$ESCALATION_TOOL" useradd -m "$username" -g users -s /bin/bash | ||
echo "$username:$password" | "$ESCALATION_TOOL" chpasswd | ||
|
||
printf "%b\n" "${GREEN}User $username created successfully${RC}" | ||
printf "%b\n" "${GREEN}To add additional groups use Add User To Groups${RC}" | ||
} | ||
|
||
checkEnv | ||
checkEscalationTool | ||
createUser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
#!/bin/sh -e | ||
|
||
. ../../common-script.sh | ||
. ./utility_functions.sh | ||
|
||
clear | ||
printf "%b\n" "${YELLOW}Change password${RC}" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
. ../utility_functions.sh | ||
|
||
username=$(promptUsername "" "root") || exit 1 | ||
password=$(promptPassword) || exit 1 | ||
changePassword() { | ||
clear | ||
printf "%b\n" "${YELLOW}Change password${RC}" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
|
||
printf "Are you sure you want to change password for $username? [Y/N]: " | ||
read -r confirm | ||
confirmAction || exit 1 | ||
printf "%b" "${YELLOW}Enter the username: ${RC}" | ||
read -r username | ||
|
||
echo "$username:$password" | "$ESCALATION_TOOL" chpasswd | ||
printf "%b\n" "${GREEN}Password changed successfully${RC}" | ||
if id "$username" > /dev/null 2>&1; then | ||
printf "%b" "${YELLOW}Enter new password: ${RC}" | ||
read -r password | ||
|
||
checkEnv | ||
printf "%b" "${YELLOW}Are you sure you want to change password for ""$username""? [Y/n]: ${RC}" | ||
read -r confirm | ||
confirmAction || exit 1 | ||
|
||
echo "$username:$password" | "$ESCALATION_TOOL" chpasswd | ||
printf "%b\n" "${GREEN}Password changed successfully${RC}" | ||
else | ||
printf "%b\n" "${RED}User $username does not exist.${RC}" | ||
exit 1 | ||
fi | ||
} | ||
|
||
checkEnv | ||
checkEscalationTool | ||
changePassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
#!/bin/sh -e | ||
|
||
. ../../common-script.sh | ||
. ./utility_functions.sh | ||
|
||
clear | ||
printf "%b\n" "${YELLOW}Delete a user${RC}" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
. ../utility_functions.sh | ||
|
||
username=$(promptUsername "" "non-root") || exit 1 | ||
deleteUser() { | ||
clear | ||
printf "%b\n" "${YELLOW}Delete a user${RC}" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
|
||
# Check if current user | ||
if [ "$username" = "$USER" ]; then | ||
printf "%b\n" "${RED}Cannot delete the current user${RC}" | ||
printf "%b\n" "${RED}Press [Enter] to continue...${RC}" | ||
read -r dummy | ||
return | ||
fi | ||
printf "%b" "${YELLOW}Enter the username: ${RC}" | ||
read -r username | ||
|
||
printf "Are you sure you want to delete user $username? [Y/N]: " | ||
read -r confirm | ||
confirmAction || exit 1 | ||
if id "$username" > /dev/null 2>&1; then | ||
printf "%b" "${YELLOW}Are you sure you want to delete user ""$username""? [Y/n]: ${RC}" | ||
read -r confirm | ||
confirmAction || exit 1 | ||
|
||
$ESCALATION_TOOL userdel --remove "$username" 2>/dev/null | ||
printf "%b\n" "${GREEN}User $username deleted successfully${RC}" | ||
$ESCALATION_TOOL userdel --remove "$username" 2>/dev/null | ||
printf "%b\n" "${GREEN}User $username deleted successfully${RC}" | ||
else | ||
printf "%b\n" "${RED}User $username does not exist.${RC}" | ||
exit 1 | ||
fi | ||
} | ||
|
||
checkEnv | ||
checkEnv | ||
checkEscalationTool | ||
deleteUser |
53 changes: 34 additions & 19 deletions
53
core/tabs/utils/user-account-manager/remove_from_group.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,47 @@ | ||
#!/bin/sh -e | ||
|
||
. ../../common-script.sh | ||
. ./utility_functions.sh | ||
|
||
clear | ||
printf "%b\n" "${YELLOW}Remove from group${RC}" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
. ../utility_functions.sh | ||
|
||
username=$(promptUsername "" "non-root") || exit 1 | ||
user_groups=$(groups "$username" | cut -d: -f2 | sort | tr '\n' ' ') | ||
removeFromGroup() { | ||
clear | ||
printf "%b\n" "${YELLOW}Remove from group${RC}" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
|
||
printf "%b\n" "${YELLOW}Groups user $username is in:${RC} $user_groups" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
printf "%b" "${YELLOW}Enter the username: ${RC}" | ||
read -r username | ||
|
||
printf "%b\n" "${YELLOW}Enter the groups you want to remove user $username from (space-separated):${RC} " | ||
read -r groups | ||
if ! id "$username" > /dev/null 2>&1; then | ||
printf "%b\n" "${RED}User $username does not exist.${RC}" | ||
exit 1 | ||
fi | ||
|
||
checkEmpty "$groups" || exit 1 | ||
checkGroupAvailabe "$groups" "$user_groups" || exit 1 | ||
user_groups=$(groups "$username" | cut -d: -f2 | sort | tr '\n' ' ') | ||
|
||
groups_to_remove=$(echo "$groups" | tr ' ' ',') | ||
printf "%b\n" "${YELLOW}Groups user $username is in:${RC} $user_groups" | ||
printf "%b\n" "${YELLOW}=================${RC}" | ||
|
||
printf "Are you sure you want to remove user $username from $groups_to_remove? [Y/N]: " | ||
read -r confirm | ||
confirmAction || exit 1 | ||
printf "%b" "${YELLOW}Enter the groups you want to remove user $username from (space-separated): ${RC} " | ||
read -r groups | ||
|
||
$ESCALATION_TOOL usermod -rG $groups_to_remove "$username" | ||
checkEmpty "$groups" || exit 1 | ||
if ! checkGroups "$groups" "$user_groups"; then | ||
printf "%b\n" "${RED}One or more specified groups do not exist.${RC}" | ||
exit 1 | ||
fi | ||
|
||
printf "%b\n" "${GREEN}User successfully removed from $groups_to_remove${RC}" | ||
groups_to_remove=$(echo "$groups" | tr ' ' ',') | ||
|
||
checkEnv | ||
printf "%b" "${YELLOW}Are you sure you want to remove user $username from $groups_to_remove? [Y/n]: ${RC}" | ||
read -r confirm | ||
confirmAction || exit 1 | ||
|
||
$ESCALATION_TOOL usermod -rG $groups_to_remove "$username" | ||
|
||
printf "%b\n" "${GREEN}User successfully removed from $groups_to_remove${RC}" | ||
} | ||
|
||
checkEnv | ||
checkEscalationTool | ||
removeFromGroup |
Oops, something went wrong.