generated from NethServer/ns8-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support session user management scripts
- Add script to create support user upon session start (`10add_support_user`). - Add script to remove support user upon session stop (`10remove_support_user`). These scripts handle support user creation and deletion by interacting with the database, ensuring temporary users are managed appropriately for support sessions.
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
imageroot/actions/support-session-started/10add_support_user
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
exec 1>&2 | ||
set -e | ||
|
||
# Check if JSON argument is provided | ||
if [ -z "$1" ]; then | ||
echo "Error: JSON input is required as an argument." | ||
exit 1 | ||
fi | ||
|
||
# Parse JSON and set variables | ||
support_user=$(echo "$1" | jq -r '.support_user') | ||
session_id=$(echo "$1" | jq -r '.session_id') | ||
|
||
# Launch a MySQL container without mounting /var/lib/mysql and use it as a client to execute the user insert | ||
podman run \ | ||
--rm \ | ||
--detach \ | ||
--name=nethsupport_add_user \ | ||
--network=host \ | ||
--env-file=./passwords.env \ | ||
--env=NETHVOICE_MARIADB_PORT \ | ||
"${NETHVOICE_MARIADB_IMAGE}" \ | ||
bash -c 'mysql -u root -h 127.0.0.1 -P $NETHVOICE_MARIADB_PORT -p$MARIADB_ROOT_PASSWORD asterisk -e " | ||
INSERT INTO ampusers (username, password_sha1, sections) | ||
VALUES (\"'"$support_user"'\", SHA1(\"'"$session_id"'\"), \"*\") | ||
ON DUPLICATE KEY UPDATE password_sha1=SHA1(\"'"$session_id"'\")"' |
30 changes: 30 additions & 0 deletions
30
imageroot/actions/support-session-stopped/10remove_support_user
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
exec 1>&2 | ||
set -e | ||
|
||
# Check if JSON argument is provided | ||
if [ -z "$1" ]; then | ||
echo "Error: JSON input is required as an argument." | ||
exit 1 | ||
fi | ||
|
||
# Parse JSON and set variables | ||
support_user=$(echo "$1" | jq -r '.support_user') | ||
|
||
# Launch a MySQL container without mounting /var/lib/mysql and use it as a client to execute the user delete | ||
podman run \ | ||
--rm \ | ||
--detach \ | ||
--name=nethsupport_remove_user \ | ||
--network=host \ | ||
--env-file=./passwords.env \ | ||
--env=NETHVOICE_MARIADB_PORT \ | ||
"${NETHVOICE_MARIADB_IMAGE}" \ | ||
bash -c 'mysql -u root -h 127.0.0.1 -P $NETHVOICE_MARIADB_PORT -p$MARIADB_ROOT_PASSWORD asterisk -e "DELETE FROM ampusers WHERE username = \"'"$support_user"'\""' | ||
|