Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update install.sh script (#113)
Leendert de Borstac284ba71ab7
diff --git a/README.md b/README.mdindex 7c04840fe..eab3d32e7 100644--- a/README.md+++ b/README.md@@ -4,8 +4,9 @@[<img src="https://img.shields.io/github/v/release/lanedirt/AliasVault?include_prereleases&logo=github">](https://github.com/lanedirt/OGameX/releases)[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/docker-compose-build.yml?label=docker-compose%20build">](https://github.com/lanedirt/AliasVault/actions/workflows/docker-compose-build.yml)-[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/dotnet-build-run-tests.yml?label=unit tests">](https://github.com/lanedirt/AliasVault/actions/workflows/dotnet-build-run-tests.yml)-[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/dotnet-integration-tests.yml?label=e2e tests">](https://github.com/lanedirt/AliasVault/actions/workflows/dotnet-integration-tests.yml)+[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/dotnet-unit-tests.yml?label=unit tests">](https://github.com/lanedirt/AliasVault/actions/workflows/dotnet-build-run-tests.yml)+[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/dotnet-integration-tests.yml?label=integration tests">](https://github.com/lanedirt/AliasVault/actions/workflows/dotnet-build-run-tests.yml)+[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/dotnet-e2e-tests.yml?label=e2e tests">](https://github.com/lanedirt/AliasVault/actions/workflows/dotnet-integration-tests.yml)[<img src="https://img.shields.io/sonar/coverage/lanedirt_AliasVault?server=https%3A%2F%2Fsonarcloud.io&label=test code coverage">](https://sonarcloud.io/summary/new_code?id=lanedirt_AliasVault)[<img src="https://img.shields.io/sonar/quality_gate/lanedirt_AliasVault?server=https%3A%2F%2Fsonarcloud.io&label=sonarcloud&logo=sonarcloud">](https://sonarcloud.io/summary/new_code?id=lanedirt_AliasVault)</div>@@ -39,32 +40,33 @@ To install AliasVault on your own machine, follow the steps below. Note: the ins$ git clone https://github.com/lanedirt/AliasVault.git```-### 2. Run the init script.-This script will create a .env file in the root directory of the project if it does not yet exist and populate it with a random encryption secret.+### 2. Run the install script.+The script checks and creates a .env file with a JWT secret, generates an admin password, and manages Docker image building and container initiation. It ensures necessary configurations and services are ready for the application's operation.+```bash# Go to the project directory$ cd AliasVault-# Make init script executable-$ chmod +x init.sh+# Make install script executable+$ chmod +x install.sh-# Run the init script and follow the steps-$ ./init.sh+# Run the install script+$ ./install.sh```-### 3. Build and run the app via Docker:+Note: if you do not wish to run the script, you can set up the environment variables and build the Docker image and containers manually instead. See the [manual setup instructions](docs/setup/1-manually-setup-docker.md) for more information.-```bash-# Build and run the app via Docker Compose-$ docker compose up -d --build --force-recreate-```-> Note: the container binds to port 80 by default. If you have another service running on port 80, you can change the port in the `docker-compose.yml` file.+### 3. AliasVault is ready to use.+The script will output the URL where the app is available. You can now open the app in your browser and create an account.++> Note: the container binds to port 80 for client and port 8080 for admin by default. If you have another service running on these ports, you can change the AliasVault ports in the `docker-compose.yml` file.#### Note for first time build:-- When running the docker compose command for the first time, it may take a few minutes to build the Docker image.+- When running the init script for the first time, it may take a few minutes for Docker to download all dependencies. Subsequent builds will be faster.- A SQLite database file will be created in `./database/AliasServerDb.sqlite`. This file will store all (encrypted) password vaults. It should be kept secure and not shared.-After the Docker containers have started the app will be available at http://localhost:80+#### Other useful commands:+- To reset the admin password, run the install.sh script with the `--reset-admin-password` flag.## Tech stack / creditsThe following technologies, frameworks and libraries are used in this project:diff --git a/docs/setup/1-manually-setup-docker.md b/docs/setup/1-manually-setup-docker.mdnew file mode 100644index 000000000..3dc132f5c--- /dev/null+++ b/docs/setup/1-manually-setup-docker.md@@ -0,0 +1,110 @@+# Manual Setup Instructions for AliasVault++This README provides step-by-step instructions for manually setting up AliasVault without using the `install.sh` script. Follow these steps if you prefer to execute all statements yourself.++## Prerequisites++- Docker and Docker Compose installed on your system+- OpenSSL for generating random passwords++## Steps++1. **Create .env file**++ Copy the `.env.example` file to create a new `.env` file:+ ```+ cp .env.example .env+ ```++2. **Generate and set JWT_KEY**++ Update the .env file and set the JWT_KEY environment variable to a random 32-char string. This key is used for JWT token generation and should be kept secure.++ Generate a random 32 char string for the JWT:+ ```+ openssl rand -base64 32+ ```++ Add the generated key to the .env file:++ ```+ JWT_KEY=your_32_char_string_here++3. **Set SMTP_ALLOWED_DOMAINS**++ Update the .env file and set the SMTP_ALLOWED_DOMAINS value the allowed domains that can be used for email addresses. Separate multiple domains with commas.+ ```+ SMTP_ALLOWED_DOMAINS=yourdomain.com,anotherdomain.com+ ```+ Replace `yourdomain.com,anotherdomain.com` with your actual allowed domains.++4. **Set SMTP_TLS_ENABLED**++ Decide whether to enable TLS for email and add it to the .env file:+ ```+ SMTP_TLS_ENABLED=true+ ```+ Or set it to `false` if you don't want to enable TLS.++5. **Generate admin password**++ Set the admin password hash in the .env file. The password hash is generated using the `InitializationCLI` utility.++ Build the Docker image for password hashing:+ ```+ docker build -t initcli -f src/Utilities/InitializationCLI/Dockerfile .+ ```++ Generate the password hash:+ ```+ docker run --rm initcli "<your_prefered_admin_password_here>"+ ```++ Add the password hash and generation timestamp to the .env file:+ ```+ ADMIN_PASSWORD_HASH=<output_of_step_above>+ ADMIN_PASSWORD_GENERATED=2024-01-01T00:00:00Z+ ```++6. **Build and start Docker containers**++ Build the Docker Compose stack:+ ```+ docker-compose build+ ```++ Start the Docker Compose stack:+ ```+ docker-compose up -d+ ```++7. **Access AliasVault**++ AliasVault should now be running. You can access it as follows:++ - Admin Panel: http://localhost:8080/+ - Username: admin+ - Password: [Use the ADMIN_PASSWORD generated in step 5]++ - Client Website: http://localhost:80/+ - Create your own account from here++## Important Notes++- Make sure to save the admin password (ADMIN_PASSWORD) generated in step 5 in a secure location. It won't be shown again.+- If you need to reset the admin password in the future, you'll need to generate a new hash and update the .env file manually.+Afterwards restart the docker containers which will update the admin password in the database.+- Always keep your .env file secure and do not share it, as it contains sensitive information.++## Troubleshooting++If you encounter any issues during the setup:++1. Check the Docker logs:+ ```+ docker-compose logs+ ```+2. Ensure all required ports (8080 and 80) are available and not being used by other services.+3. Verify that all environment variables in the .env file are set correctly.++For further assistance, please refer to the project documentation or seek support through the appropriate channels.diff --git a/init.sh b/init.shdeleted file mode 100755index c416c3a9a..000000000--- a/init.sh+++ /dev/null@@ -1,279 +0,0 @@-#!/bin/sh--# Define colors for CLI output-RED='\033[0;31m'-GREEN='\033[0;32m'-YELLOW='\033[0;33m'-BLUE='\033[0;34m'-MAGENTA='\033[0;35m'-CYAN='\033[0;36m'-NC='\033[0m' # No Color--# Define the path to the .env and .env.example files-ENV_FILE=".env"-ENV_EXAMPLE_FILE=".env.example"--# Define verbose flag-VERBOSE=false--# Function to parse command-line arguments-parse_args() {- while [ $# -gt 0 ]; do- case "$1" in- --verbose)- VERBOSE=true- ;;- *)- printf "${RED}Unknown argument: $1${NC}\n"- exit 1- ;;- esac- shift- done-}--# Function to generate a new 32-character JWT key-generate_jwt_key() {- dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 | head -c 32-}--# Function to create .env file from .env.example if it doesn't exist-create_env_file() {- if [ ! -f "$ENV_FILE" ]; then- if [ -f "$ENV_EXAMPLE_FILE" ]; then- cp "$ENV_EXAMPLE_FILE" "$ENV_FILE"- printf "${GREEN}> .env file created from .env.example.${NC}\n"- else- touch "$ENV_FILE"- printf "${YELLOW}> .env file created as empty because .env.example was not found.${NC}\n"- fi- else- printf "${CYAN}> .env file already exists.${NC}\n"- fi-}--# Function to check and populate the .env file with JWT_KEY-populate_jwt_key() {- if ! grep -q "^JWT_KEY=" "$ENV_FILE" || [ -z "$(grep "^JWT_KEY=" "$ENV_FILE" | cut -d '=' -f2)" ]; then- printf "${YELLOW}JWT_KEY not found or empty in $ENV_FILE. Generating a new JWT key...${NC}\n"- JWT_KEY=$(generate_jwt_key)- if grep -q "^JWT_KEY=" "$ENV_FILE"; then- awk -v key="$JWT_KEY" '/^JWT_KEY=/ {$0="JWT_KEY="key} 1' "$ENV_FILE" > "$ENV_FILE.tmp" && mv "$ENV_FILE.tmp" "$ENV_FILE"- else- printf "JWT_KEY=${JWT_KEY}" >> "$ENV_FILE\n"- fi- printf "${GREEN}> JWT_KEY has been added to $ENV_FILE.${NC}\n"- else- printf "${CYAN}> JWT_KEY already exists and has a value in $ENV_FILE.${NC}\n"- fi-}--# Function to ask the user for SMTP_ALLOWED_DOMAINS-set_smtp_allowed_domains() {- if ! grep -q "^SMTP_ALLOWED_DOMAINS=" "$ENV_FILE" || [ -z "$(grep "^SMTP_ALLOWED_DOMAINS=" "$ENV_FILE" | cut -d '=' -f2)" ]; then- printf "${YELLOW}Please enter the domains that should be allowed to send email, separated by commas:${NC}\n"- read -r smtp_allowed_domains- if grep -q "^SMTP_ALLOWED_DOMAINS=" "$ENV_FILE"; then- awk -v domains="$smtp_allowed_domains" '/^SMTP_ALLOWED_DOMAINS=/ {$0="SMTP_ALLOWED_DOMAINS="domains} 1' "$ENV_FILE" > "$ENV_FILE.tmp" && mv "$ENV_FILE.tmp" "$ENV_FILE"- else- printf "SMTP_ALLOWED_DOMAINS=${smtp_allowed_domains}\n" >> "$ENV_FILE"- fi- printf "${GREEN}> SMTP_ALLOWED_DOMAINS has been set in $ENV_FILE.${NC}\n"- else- printf "${CYAN}> SMTP_ALLOWED_DOMAINS already exists and has a value in $ENV_FILE.${NC}\n"- fi-}--# Function to ask the user if TLS should be enabled for email-set_smtp_tls_enabled() {- if ! grep -q "^SMTP_TLS_ENABLED=" "$ENV_FILE" || [ -z "$(grep "^SMTP_TLS_ENABLED=" "$ENV_FILE" | cut -d '=' -f2)" ]; then- printf "${YELLOW}Do you want TLS enabled for email? (yes/no):${NC}\n"- read -r tls_enabled- tls_enabled=$(echo "$tls_enabled" | tr '[:upper:]' '[:lower:]')- if [ "$tls_enabled" = "yes" ] || [ "$tls_enabled" = "y" ]; then- tls_enabled="true"- else- tls_enabled="false"- fi- if grep -q "^SMTP_TLS_ENABLED=" "$ENV_FILE"; then- awk -v tls="$tls_enabled" '/^SMTP_TLS_ENABLED=/ {$0="SMTP_TLS_ENABLED="tls} 1' "$ENV_FILE" > "$ENV_FILE.tmp" && mv "$ENV_FILE.tmp" "$ENV_FILE"- else- printf "SMTP_TLS_ENABLED=${tls_enabled}\n" >> "$ENV_FILE"- fi- printf "${GREEN}> SMTP_TLS_ENABLED has been set to ${tls_enabled} in $ENV_FILE.${NC}\n"- else- printf "${CYAN}> SMTP_TLS_ENABLED already exists and has a value in $ENV_FILE.${NC}\n"- fi-}--# Function to generate a random admin password and store its hash in the .env file with progress indication-generate_admin_password() {- if grep -q "^ADMIN_PASSWORD_HASH=" ".env"; then- ADMIN_PASSWORD_GENERATED=$(grep "^ADMIN_PASSWORD_GENERATED=" ".env" | cut -d '=' -f2)-- printf "${CYAN}> ADMIN_PASSWORD_HASH already exists in .env. Last generated at ${ADMIN_PASSWORD_GENERATED}.${NC}\n"-- printf "\n"- read -p " Do you want to update the admin password? (yes/no): " confirm- if [[ "$confirm" != "yes" ]]; then- printf "${CYAN}> Admin password will not be changed.${NC}\n"- return 0- fi-- # Remove existing entries- sed -i '' '/^ADMIN_PASSWORD_HASH=/d' .env- sed -i '' '/^ADMIN_PASSWORD_GENERATED=/d' .env- fi-- ADMIN_PASSWORD=$(openssl rand -base64 12)- printf "\n"- printf "${BLUE} Building Docker image for password generation...${NC}\n "- if [ "$VERBOSE" = true ]; then- docker build -t initcli -f src/Utilities/InitializationCLI/Dockerfile .- else- {- docker build -t initcli -f src/Utilities/InitializationCLI/Dockerfile . | while IFS= read -r line; do- printf "."- done- } > init_build_output.log 2>&1 &- BUILD_PID=$!- while kill -0 $BUILD_PID 2> /dev/null; do- printf "."- sleep 1- done- wait $BUILD_PID- BUILD_EXIT_CODE=$?- if [ $BUILD_EXIT_CODE -ne 0 ]; then- printf "\n${RED} Error occurred while building Docker image:${NC}\n"- cat init_build_output.log- return 1- fi- fi-- printf "\n"- printf "${BLUE} Running Docker container to generate admin password hash...${NC}\n"- {- ADMIN_PASSWORD_HASH=$(docker run --rm initcli "$ADMIN_PASSWORD")- } &> init_run_output.log- if [ $? -ne 0 ]; then- printf "${RED} Error occurred while running Docker container:${NC}\n"- cat init_run_output.log- return 1- fi-- CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")-- # Append new entries- echo "ADMIN_PASSWORD_HASH=$ADMIN_PASSWORD_HASH" >> .env- echo "ADMIN_PASSWORD_GENERATED=$CURRENT_TIME" >> .env-- printf "\n"- printf "${CYAN}> New admin password generated successfully.${NC}\n"-}--# Function to build and run the Docker Compose stack with muted output unless an error occurs, showing progress indication-build_and_run_docker_compose() {- printf "\n"- printf "${BLUE}Building Docker Compose stack...${NC}\n"- if [ "$VERBOSE" = true ]; then- docker-compose build- else- {- docker-compose build | while IFS= read -r line; do- printf "."- done- } > compose_build_output.log 2>&1 &- BUILD_PID=$!- while kill -0 $BUILD_PID 2> /dev/null; do- printf "."- sleep 1- done- wait $BUILD_PID- BUILD_EXIT_CODE=$?- if [ $BUILD_EXIT_CODE -ne 0 ]; then- printf "\n${RED}Error occurred while building Docker Compose stack:${NC}\n"- cat compose_build_output.log- return 1- fi- fi-- printf "\n"- printf "\n${BLUE}Starting Docker Compose stack...${NC}\n"- if [ "$VERBOSE" = true ]; then- docker-compose up -d- else- {- docker-compose up -d | while IFS= read -r line; do- printf "."- done- } > compose_up_output.log 2>&1 &- UP_PID=$!- while kill -0 $UP_PID 2> /dev/null; do- printf "."- sleep 1- done- wait $UP_PID- UP_EXIT_CODE=$?- if [ $UP_EXIT_CODE -ne 0 ]; then- printf "\n${RED}Error occurred while starting Docker Compose stack:${NC}\n"- cat compose_up_output.log- return 1- fi- fi-- printf "\n${GREEN}Docker Compose stack built and started successfully.${NC}\n"-}---# Function to print the CLI logo-print_logo() {- printf "${MAGENTA}\n"- printf "=========================================================\n"- printf " _ _ __ __ _ _ \n"- printf " /\ | (_) \ \ / / | | | \n"- printf " / \ | |_ __ _ __\ \ / /_ _ _ _| | |_\n"- printf " / /\ \ | | |/ _ / __\ \/ / _ | | | | | __|\n"- printf " / ____ \| | | (_| \__ \\ / (_| | |_| | | |_ \n"- printf " /_/ \_\_|_|\__,_|___/ \/ \__,_|\__,_|_|\__|\n"- printf "\n"- printf "=========================================================\n"- printf "${NC}\n"-}--# Parse arguments-parse_args "$@"--# Run the functions and print status-print_logo-printf "${BLUE}+++ Initializing .env file...${NC}\n"-printf "\n"-create_env_file-populate_jwt_key-set_smtp_allowed_domains-set_smtp_tls_enabled-generate_admin_password-printf "\n${BLUE}+++ Finish initializing .env file...${NC}\n"-build_and_run_docker_compose-printf "${BLUE}If no errors are reported, the AliasVault Docker containers should have started successfully.${NC}\n"-printf "\n"-printf "${MAGENTA}=========================================================${NC}\n"-printf "\n"-printf "AliasVault is successfully initialized!\n"-printf "\n"-printf "You can now login to the admin panel:\n"-printf "\n"-if [ "$ADMIN_PASSWORD" != "" ]; then- printf "${CYAN}Admin Panel: http://localhost:8080/${NC}\n"- printf "${CYAN}Username: admin${NC}\n"- printf "${CYAN}Password: $ADMIN_PASSWORD${NC}\n"- printf "\n"- printf "(!) Caution: Make sure to backup the above credentials in a safe place, they won't be shown again!\n"- printf "\n"-else- printf "${CYAN}Admin Panel: http://localhost:8080/${NC}\n"- printf "${CYAN}Username: admin${NC}\n"- printf "${CYAN}Password: (Previously set.)${NC}\n"- printf "\n"- printf "\n"-fi-diff --git a/install.sh b/install.shnew file mode 100755index 000000000..fd20fde4c--- /dev/null+++ b/install.sh@@ -0,0 +1,342 @@+#!/bin/sh++# Define colors for CLI output+RED='\033[0;31m'+GREEN='\033[0;32m'+YELLOW='\033[0;33m'+BLUE='\033[0;34m'+MAGENTA='\033[0;35m'+CYAN='\033[0;36m'+NC='\033[0m' # No Color++# Define the path to the .env and .env.example files+ENV_FILE=".env"+ENV_EXAMPLE_FILE=".env.example"++# Define verbose flag and reset password flag+VERBOSE=false+RESET_PASSWORD=false++# Function to parse command-line arguments+parse_args() {+ while [ $# -gt 0 ]; do+ case "$1" in+ --verbose)+ VERBOSE=true+ ;;+ --reset-password)+ RESET_PASSWORD=true+ ;;+ *)+ printf "${RED}Unknown argument: $1${NC}\n"+ exit 1+ ;;+ esac+ shift+ done+}++# Function to generate a random admin password and store its hash in the .env file+generate_admin_password() {+ if grep -q "^ADMIN_PASSWORD_HASH=" ".env" && [ "$RESET_PASSWORD" = false ]; then+ printf "${CYAN}> ADMIN_PASSWORD_HASH already exists in .env. Use --reset-password to generate a new one.${NC}\n"+ return 0+ fi++ printf "${CYAN}> Generating new admin password...${NC}\n"++ ADMIN_PASSWORD=$(openssl rand -base64 12)+ printf "${BLUE} Building Docker image for password generation:${NC} "++ if [ "$VERBOSE" = true ]; then+ docker build -t initcli -f src/Utilities/InitializationCLI/Dockerfile .+ else+ (+ # Run docker build and capture its output+ docker build -t initcli -f src/Utilities/InitializationCLI/Dockerfile . > install_build_output.log 2>&1 &+ BUILD_PID=$!++ # Print dots while the build is running+ while kill -0 $BUILD_PID 2>/dev/null; do+ printf "."+ sleep 1+ done++ # Wait for the build to finish and capture its exit code+ wait $BUILD_PID+ BUILD_EXIT_CODE=$?++ # If there was an error, display it+ if [ $BUILD_EXIT_CODE -ne 0 ]; then+ printf "\n${RED} An error occurred while building the Docker image for password generation. Check the output above.${NC}\n"+ printf "\n"+ cat install_build_output.log+ exit $BUILD_EXIT_CODE+ fi+ )++ SUBSHELL_EXIT_CODE=$?+ if [ $SUBSHELL_EXIT_CODE -ne 0 ]; then+ return $SUBSHELL_EXIT_CODE+ fi+ fi++ printf "\n"+ printf "${BLUE} Running Docker container to generate admin password hash: ${NC}"++ # Run the Docker container to generate the password hash+ ADMIN_PASSWORD_HASH=$(docker run --rm initcli "$ADMIN_PASSWORD" 2> install_run_output.log)+ RUN_EXIT_CODE=$?++ if [ $RUN_EXIT_CODE -ne 0 ]; then+ printf "${RED} Error occurred while running the Docker container:${NC}\n"+ cat install_run_output.log+ return $RUN_EXIT_CODE+ fi++ # Remove existing ADMIN_PASSWORD_HASH and ADMIN_PASSWORD_GENERATED if it exists+ sed -i '' '/^ADMIN_PASSWORD_HASH=/d' .env+ sed -i '' '/^ADMIN_PASSWORD_GENERATED=/d' .env++ # Append new entries+ echo "ADMIN_PASSWORD_HASH=$ADMIN_PASSWORD_HASH" >> .env+ echo "ADMIN_PASSWORD_GENERATED=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> .env++ printf " ok\n"+ printf "${CYAN}> New admin password generated and hash stored in .env${NC}\n"+}+++# Function to restart Docker containers+restart_docker_containers() {+ printf "${CYAN}> Restarting Docker containers...${NC}\n"+ docker-compose down+ docker-compose up -d+ printf "${GREEN}> Docker containers restarted successfully.${NC}\n"+}++# Function to generate a new 32-character JWT key+generate_jwt_key() {+ dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 | head -c 32+}++# Function to create .env file from .env.example if it doesn't exist+create_env_file() {+ if [ ! -f "$ENV_FILE" ]; then+ if [ -f "$ENV_EXAMPLE_FILE" ]; then+ cp "$ENV_EXAMPLE_FILE" "$ENV_FILE"+ printf "${GREEN}> .env file created from .env.example.${NC}\n"+ else+ touch "$ENV_FILE"+ printf "${YELLOW}> .env file created as empty because .env.example was not found.${NC}\n"+ fi+ else+ printf "${CYAN}> .env file already exists.${NC}\n"+ fi+}++# Function to check and populate the .env file with JWT_KEY+populate_jwt_key() {+ if ! grep -q "^JWT_KEY=" "$ENV_FILE" || [ -z "$(grep "^JWT_KEY=" "$ENV_FILE" | cut -d '=' -f2)" ]; then+ printf "${YELLOW}JWT_KEY not found or empty in $ENV_FILE. Generating a new JWT key...${NC}\n"+ JWT_KEY=$(generate_jwt_key)+ if grep -q "^JWT_KEY=" "$ENV_FILE"; then+ awk -v key="$JWT_KEY" '/^JWT_KEY=/ {$0="JWT_KEY="key} 1' "$ENV_FILE" > "$ENV_FILE.tmp" && mv "$ENV_FILE.tmp" "$ENV_FILE"+ else+ printf "JWT_KEY=${JWT_KEY}" >> "$ENV_FILE\n"+ fi+ printf "${GREEN}> JWT_KEY has been added to $ENV_FILE.${NC}\n"+ else+ printf "${CYAN}> JWT_KEY already exists and has a value in $ENV_FILE.${NC}\n"+ fi+}++# Function to ask the user for SMTP_ALLOWED_DOMAINS+set_smtp_allowed_domains() {+ if ! grep -q "^SMTP_ALLOWED_DOMAINS=" "$ENV_FILE" || [ -z "$(grep "^SMTP_ALLOWED_DOMAINS=" "$ENV_FILE" | cut -d '=' -f2)" ]; then+ printf "${YELLOW}Please enter the domains that should be allowed to send email, separated by commas:${NC}\n"+ read -r smtp_allowed_domains+ if grep -q "^SMTP_ALLOWED_DOMAINS=" "$ENV_FILE"; then+ awk -v domains="$smtp_allowed_domains" '/^SMTP_ALLOWED_DOMAINS=/ {$0="SMTP_ALLOWED_DOMAINS="domains} 1' "$ENV_FILE" > "$ENV_FILE.tmp" && mv "$ENV_FILE.tmp" "$ENV_FILE"+ else+ printf "SMTP_ALLOWED_DOMAINS=${smtp_allowed_domains}\n" >> "$ENV_FILE"+ fi+ printf "${GREEN}> SMTP_ALLOWED_DOMAINS has been set in $ENV_FILE.${NC}\n"+ else+ printf "${CYAN}> SMTP_ALLOWED_DOMAINS already exists and has a value in $ENV_FILE.${NC}\n"+ fi+}++# Function to ask the user if TLS should be enabled for email+set_smtp_tls_enabled() {+ if ! grep -q "^SMTP_TLS_ENABLED=" "$ENV_FILE" || [ -z "$(grep "^SMTP_TLS_ENABLED=" "$ENV_FILE" | cut -d '=' -f2)" ]; then+ printf "${YELLOW}Do you want TLS enabled for email? (yes/no):${NC}\n"+ read -r tls_enabled+ tls_enabled=$(echo "$tls_enabled" | tr '[:upper:]' '[:lower:]')+ if [ "$tls_enabled" = "yes" ] || [ "$tls_enabled" = "y" ]; then+ tls_enabled="true"+ else+ tls_enabled="false"+ fi+ if grep -q "^SMTP_TLS_ENABLED=" "$ENV_FILE"; then+ awk -v tls="$tls_enabled" '/^SMTP_TLS_ENABLED=/ {$0="SMTP_TLS_ENABLED="tls} 1' "$ENV_FILE" > "$ENV_FILE.tmp" && mv "$ENV_FILE.tmp" "$ENV_FILE"+ else+ printf "SMTP_TLS_ENABLED=${tls_enabled}\n" >> "$ENV_FILE"+ fi+ printf "${GREEN}> SMTP_TLS_ENABLED has been set to ${tls_enabled} in $ENV_FILE.${NC}\n"+ else+ printf "${CYAN}> SMTP_TLS_ENABLED already exists and has a value in $ENV_FILE.${NC}\n"+ fi+}++# Function to build and run the Docker Compose stack with muted output unless an error occurs, showing progress indication+build_and_run_docker_compose() {+ printf "\n"+ printf "${CYAN}> Building Docker Compose stack:${NC} "+ if [ "$VERBOSE" = true ]; then+ docker-compose build+ else+ (+ # Run docker-compose build and capture its output+ docker-compose build 2>&1 > install_compose_build_output.log &+ BUILD_PID=$!++ # Print dots while the build is running+ while kill -0 $BUILD_PID 2>/dev/null; do+ printf "."+ sleep 1+ done++ # Wait for the build to finish and capture its exit code+ wait $BUILD_PID+ BUILD_EXIT_CODE=$?++ # If there was an error, display it+ if [ $BUILD_EXIT_CODE -ne 0 ]; then+ printf "\n${RED}An error occurred while building the Docker Compose stack. See the output above.${NC}\n"+ printf "\n"+ cat install_compose_build_output.log+ exit $BUILD_EXIT_CODE+ fi+ )++ # Capture the exit code of the subshell+ SUBSHELL_EXIT_CODE=$?+ if [ $SUBSHELL_EXIT_CODE -ne 0 ]; then+ return $SUBSHELL_EXIT_CODE+ fi+ fi++ printf "\n"+ printf "${CYAN}> Starting Docker Compose stack:${NC}\n"+ if [ "$VERBOSE" = true ]; then+ docker-compose up -d+ return $?+ else+ (+ # Run docker-compose up -d and capture its output+ docker-compose up -d &+ UP_PID=$!++ # Wait for the process to finish and capture its exit code+ wait $UP_PID+ UP_EXIT_CODE=$?++ # If there was an error, display it+ if [ $UP_EXIT_CODE -ne 0 ]; then+ printf "\n${RED}An error occurred while starting the Docker Compose stack. See the output above.${NC}\n"+ printf "\n"+ cat install_compose_up_output.log+ exit $UP_EXIT_CODE+ fi+ )++ # Capture the exit code of the subshell+ SUBSHELL_EXIT_CODE=$?+ if [ $SUBSHELL_EXIT_CODE -ne 0 ]; then+ return $SUBSHELL_EXIT_CODE+ fi+ fi+}++# Function to restart Docker containers+restart_docker_containers() {+ printf "${CYAN}> Restarting Docker containers...${NC}\n"+ docker-compose up -d --no-deps --force-recreate+ printf "${GREEN}> Docker containers restarted successfully.${NC}\n"+}++# Function to print the CLI logo+print_logo() {+ printf "${MAGENTA}\n"+ printf "=========================================================\n"+ printf " _ _ __ __ _ _ \n"+ printf " /\ | (_) \ \ / / | | | \n"+ printf " / \ | |_ __ _ __\ \ / /_ _ _ _| | |_\n"+ printf " / /\ \ | | |/ _ / __\ \/ / _ | | | | | __|\n"+ printf " / ____ \| | | (_| \__ \\ / (_| | |_| | | |_ \n"+ printf " /_/ \_\_|_|\__,_|___/ \/ \__,_|\__,_|_|\__|\n"+ printf "\n"+ printf "=========================================================\n"+ printf "${NC}\n"+}++# Main execution flow+main() {+ parse_args "$@"++ if [ "$RESET_PASSWORD" = true ]; then+ print_logo+ generate_admin_password+ if [ $? -eq 0 ]; then+ restart_docker_containers+ fi+ else+ # Run the original initialization process+ print_logo++ printf "${YELLOW}+++ Initializing .env file +++${NC}\n"+ printf "\n"+ create_env_file || exit $?+ populate_jwt_key || exit $?+ set_smtp_allowed_domains || exit $?+ set_smtp_tls_enabled || exit $?+ generate_admin_password || exit $?+ printf "\n${YELLOW}+++ Building Docker containers +++${NC}\n"++ build_and_run_docker_compose || exit $?+ printf "\n"+ printf "${MAGENTA}=========================================================${NC}\n"+ printf "\n"+ printf "AliasVault is successfully installed!\n"+ printf "\n"+ printf "To configure the server, login to the admin panel:\n"+ printf "\n"+ if [ "$ADMIN_PASSWORD" != "" ]; then+ printf "${CYAN}Admin Panel: http://localhost:8080/${NC}\n"+ printf "${CYAN}Username: admin${NC}\n"+ printf "${CYAN}Password: $ADMIN_PASSWORD${NC}\n"+ printf "\n"+ printf "(!) Caution: Make sure to backup the above credentials in a safe place, they won't be shown again!\n"+ printf "\n"+ else+ printf "${CYAN}Admin Panel: http://localhost:8080/${NC}\n"+ printf "${CYAN}Username: admin${NC}\n"+ printf "${CYAN}Password: (Previously set. Run this command with --reset-password to generate a new one.)${NC}\n"+ printf "\n"+ printf "\n"+ fi+ printf "===========================\n"+ printf "\n"+ printf "In order to start using AliasVault and create your own vault, log into the client website:\n"+ printf "\n"+ printf "${CYAN}Client Website: http://localhost:80/${NC}\n"+ printf "${CYAN}You can create your own account from there.${NC}\n"+ printf "\n"+ fi+}++# Run the main function+main "$@"++diff --git a/src/AliasVault.Admin/wwwroot/js/utilities.js b/src/AliasVault.Admin/wwwroot/js/utilities.jsindex a0e828de5..023edf851 100644--- a/src/AliasVault.Admin/wwwroot/js/utilities.js+++ b/src/AliasVault.Admin/wwwroot/js/utilities.js@@ -40,8 +40,7 @@ function generateQrCode(id) {element.appendChild(qrContainer);// Initialize QRCode object- new QRCode(qrContainer, {- text: dataUrl,+ let qrcode = new QRCode(qrContainer, {width: 256,height: 256,colorDark : "#000000",@@ -49,6 +48,6 @@ function generateQrCode(id) {correctLevel : QRCode.CorrectLevel.H});- console.log(`QR code generated successfully for element with id "${id}".`);+ qrcode.makeCode(dataUrl);}