mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-15 21:52:47 +01:00
Add support for validating email address via so-user tool
This commit is contained in:
@@ -22,8 +22,13 @@ got_root() {
|
||||
got_root
|
||||
|
||||
if [[ $# < 1 || $# > 2 ]]; then
|
||||
echo "Usage: $0 <list|add|update|delete|checkpw> [email]"
|
||||
echo "Note that checkpw only checks that the given password meets the minimum requirements, it does not test that it matches for an existing user."
|
||||
echo "Usage: $0 <list|add|update|delete|validate> [email]"
|
||||
echo ""
|
||||
echo " list: Lists all user email addresses currently defined in the identity system"
|
||||
echo " add: Adds a new user to the identity system; requires 'email' parameter"
|
||||
echo " update: Updates a user's password; requires 'email' parameter"
|
||||
echo " delete: Deletes an existing user; requires 'email' parameter"
|
||||
echo " validate: Validates that the given email address and password are acceptable for defining a new user; requires 'email' parameter"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -50,14 +55,16 @@ function require() {
|
||||
}
|
||||
|
||||
# Verify this environment is capable of running this script
|
||||
require "argon2"
|
||||
require "jq"
|
||||
require "curl"
|
||||
require "openssl"
|
||||
require "sqlite3"
|
||||
[[ ! -f $databasePath ]] && fail "Unable to find database file; specify path via KRATOS_DB_PATH environment variable"
|
||||
response=$(curl -Ss ${kratosUrl}/)
|
||||
[[ "$response" != "404 page not found" ]] && fail "Unable to communicate with Kratos; specify URL via KRATOS_URL environment variable"
|
||||
function verifyEnvironment() {
|
||||
require "argon2"
|
||||
require "jq"
|
||||
require "curl"
|
||||
require "openssl"
|
||||
require "sqlite3"
|
||||
[[ ! -f $databasePath ]] && fail "Unable to find database file; specify path via KRATOS_DB_PATH environment variable"
|
||||
response=$(curl -Ss ${kratosUrl}/)
|
||||
[[ "$response" != "404 page not found" ]] && fail "Unable to communicate with Kratos; specify URL via KRATOS_URL environment variable"
|
||||
}
|
||||
|
||||
function findIdByEmail() {
|
||||
email=$1
|
||||
@@ -77,6 +84,15 @@ function validatePassword() {
|
||||
fi
|
||||
}
|
||||
|
||||
function validateEmail() {
|
||||
email=$1
|
||||
# (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
|
||||
if [[ ! "$email" =~ ^[[:alnum:]._%+-]+@[[:alnum:].-]+\.[[:alpha:]]{2,}$ ]]; then
|
||||
echo "Email address is invalid"
|
||||
exit 3
|
||||
fi
|
||||
}
|
||||
|
||||
function updatePassword() {
|
||||
identityId=$1
|
||||
|
||||
@@ -164,17 +180,21 @@ function deleteUser() {
|
||||
|
||||
case "${operation}" in
|
||||
"add")
|
||||
verifyEnvironment
|
||||
[[ "$email" == "" ]] && fail "Email address must be provided"
|
||||
|
||||
validateEmail "$email"
|
||||
createUser "$email"
|
||||
echo "Successfully added new user"
|
||||
;;
|
||||
|
||||
"list")
|
||||
verifyEnvironment
|
||||
listUsers
|
||||
;;
|
||||
|
||||
"update")
|
||||
verifyEnvironment
|
||||
[[ "$email" == "" ]] && fail "Email address must be provided"
|
||||
|
||||
updateUser "$email"
|
||||
@@ -182,13 +202,15 @@ case "${operation}" in
|
||||
;;
|
||||
|
||||
"delete")
|
||||
verifyEnvironment
|
||||
[[ "$email" == "" ]] && fail "Email address must be provided"
|
||||
|
||||
deleteUser "$email"
|
||||
echo "Successfully deleted user"
|
||||
;;
|
||||
|
||||
"checkpw")
|
||||
"validate")
|
||||
validateEmail "$email"
|
||||
updatePassword
|
||||
echo "Password is acceptable"
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user