Skip to content

Commit

Permalink
feat: add support session user management scripts
Browse files Browse the repository at this point in the history
- 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
Stell0 committed Nov 8, 2024
1 parent e239753 commit 487ae2a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
33 changes: 33 additions & 0 deletions imageroot/actions/support-session-started/10add_support_user
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 imageroot/actions/support-session-stopped/10remove_support_user
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"'\""'

0 comments on commit 487ae2a

Please sign in to comment.