From 52a10844fbdb6678269160d31e47b33bbd263f46 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Fri, 13 Sep 2024 16:44:44 -0400 Subject: [PATCH 1/8] update --- mods/scripts/apps_parse copy.sh | 86 +++++++++++++++++++++++++ mods/scripts/apps_parse.sh | 35 +++++++++-- mods/scripts/default_ports.sh | 107 ++++++++++++++++++++++++++++++++ 3 files changed, 224 insertions(+), 4 deletions(-) create mode 100644 mods/scripts/apps_parse copy.sh create mode 100644 mods/scripts/default_ports.sh diff --git a/mods/scripts/apps_parse copy.sh b/mods/scripts/apps_parse copy.sh new file mode 100644 index 0000000000..845281e2c8 --- /dev/null +++ b/mods/scripts/apps_parse copy.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# Function to parse default variables and update the config file +parse_and_store_defaults() { + local app_name="$1" + local app_type="$2" # 'personal' for personal apps, 'official' for official apps + + # Determine paths based on app type + if [[ "$app_type" == "personal" ]]; then + local config_path="/pg/personal_configs/${app_name}.cfg" + local app_path="/pg/p_apps/${app_name}.app" + else + local config_path="/pg/config/${app_name}.cfg" + local app_path="/pg/apps/${app_name}.app" + fi + + # Check if the config file exists, create it if not + [[ ! -f "$config_path" ]] && touch "$config_path" + + # Check if the app file exists + if [[ ! -f "$app_path" ]]; then + # echo "Error: App file $app_path does not exist." + return 1 + fi + + # Source the app's default_variables function + source "$app_path" + + # Call the default_variables function for the specific app + default_variables + + # Parse the default_variables function and write to config if not exist + declare -f default_variables | while read line; do + if [[ $line =~ ^[[:space:]]*([a-zA-Z_][a-zA-Z0-9_]*)=(.*)$ ]]; then + var="${BASH_REMATCH[1]}" + value="${BASH_REMATCH[2]}" + + # Remove any existing quotes and semicolons from the value + value=$(echo "$value" | sed -e 's/^"//' -e 's/"$//' -e "s/^'//" -e "s/'$//" -e 's/;$//') + + # Check if the variable exists in the config file + if ! grep -q "^${var}=" "$config_path"; then + # Add quotes around the value (without semicolon) and write to config + echo "${var}=\"${value}\"" >> "$config_path" + fi + fi + done + + # Add or update traefik_domain + update_traefik_domain "$config_path" +} + +# Function to update or add 'traefik_domain' to the end of the config file +add_or_update_traefik_domain() { + local config_path="$1" + local traefik_domain="$2" + + # Check if the variable already exists in the config file + if grep -q "^traefik_domain=" "$config_path"; then + # If the variable exists, move it to the end by removing it first, then appending it + sed -i '/^traefik_domain=/d' "$config_path" + echo "traefik_domain=\"$traefik_domain\"" >> "$config_path" + else + # If the variable does not exist, append it to the end of the file + echo "traefik_domain=\"$traefik_domain\"" >> "$config_path" + fi +} + +# Function to check the DNS configuration and update 'traefik_domain' +update_traefik_domain() { + local config_path="$1" + + # Load DNS configuration + local dns_config_path="/pg/config/dns_provider.cfg" + if [[ -f "$dns_config_path" ]]; then + source "$dns_config_path" + traefik_domain="${domain_name:-nodomain}" + else + traefik_domain="nodomain" + fi + + # Now call the function to add or update the 'traefik_domain' variable + add_or_update_traefik_domain "$config_path" "$traefik_domain" +} + +parse_and_store_defaults "$app_name" "$app_type" \ No newline at end of file diff --git a/mods/scripts/apps_parse.sh b/mods/scripts/apps_parse.sh index 845281e2c8..8efcc59cff 100644 --- a/mods/scripts/apps_parse.sh +++ b/mods/scripts/apps_parse.sh @@ -4,6 +4,7 @@ parse_and_store_defaults() { local app_name="$1" local app_type="$2" # 'personal' for personal apps, 'official' for official apps + local port_default="$3" # The default port to expose # Determine paths based on app type if [[ "$app_type" == "personal" ]]; then @@ -15,12 +16,14 @@ parse_and_store_defaults() { fi # Check if the config file exists, create it if not - [[ ! -f "$config_path" ]] && touch "$config_path" + if [[ ! -f "$config_path" ]]; then + touch "$config_path" + add_expose_variable "$config_path" "$port_default" + fi # Check if the app file exists if [[ ! -f "$app_path" ]]; then - # echo "Error: App file $app_path does not exist." - return 1 + return 1 # App file does not exist, return with an error fi # Source the app's default_variables function @@ -50,6 +53,29 @@ parse_and_store_defaults() { update_traefik_domain "$config_path" } +# Function to add the 'expose' variable based on default ports status +add_expose_variable() { + local config_path="$1" + local port_default="$2" + + # Check the status of the ports from /pg/config/default_ports.cfg + local default_ports_cfg="/pg/config/default_ports.cfg" + if [[ -f "$default_ports_cfg" ]]; then + source "$default_ports_cfg" + + # If ports=closed, use 127.0.0.1 for $port_default + if [[ "$ports" == "closed" ]]; then + echo "expose=\"127.0.0.1:$port_default\"" >> "$config_path" + else + # If ports=open, just write expose= + echo "expose=" >> "$config_path" + fi + else + # Default to open if the config file doesn't exist + echo "expose=" >> "$config_path" + fi +} + # Function to update or add 'traefik_domain' to the end of the config file add_or_update_traefik_domain() { local config_path="$1" @@ -83,4 +109,5 @@ update_traefik_domain() { add_or_update_traefik_domain "$config_path" "$traefik_domain" } -parse_and_store_defaults "$app_name" "$app_type" \ No newline at end of file +# Call the function with app name, type, and port default +parse_and_store_defaults "$app_name" "$app_type" "$port_default" diff --git a/mods/scripts/default_ports.sh b/mods/scripts/default_ports.sh new file mode 100644 index 0000000000..f031112e96 --- /dev/null +++ b/mods/scripts/default_ports.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +# Define config file and load ports status +config_file="/pg/config/default_ports.cfg" +if [ ! -f "$config_file" ]; then + echo "ports=open" > "$config_file" +fi +source "$config_file" + +# Function to display the header +show_header() { + clear + if [ "$ports" == "open" ]; then + port_status="\033[31m[Open]\033[0m" # Red [Open] + else + port_status="\033[32m[Closed]\033[0m" # Green [Closed] + fi + echo -e "\033[1;33mDefault Port Protection:\033[0m $port_status" # Bold gold for Default Port Protection +} + +# Menu options +show_menu() { + echo "" + if [ "$ports" == "open" ]; then + echo -e "[\033[1;32mC\033[0m] Close Ports by Default" # Bold Green 'C' + else + echo -e "[\033[1;31mO\033[0m] Open Ports by Default" # Bold Red 'O' + fi + echo -e "[\033[1;35mZ\033[0m] Exit\n" # Bold Purple 'Z' +} + +# Function to prompt user for PIN +handle_pin() { + local action=$1 + while true; do + echo "" + # Generate new PINs every time + pin_forward=$((RANDOM % 9000 + 1000)) # 4-digit random number + pin_exit=$((RANDOM % 9000 + 1000)) # 4-digit random number + + echo -e "To proceed, enter this PIN: \033[95m$pin_forward\033[0m" # Hot pink forward PIN + echo -e "To exit, enter this PIN: \033[32m$pin_exit\033[0m" # Green exit PIN + + echo "" + read -p "Enter PIN > " user_pin + if [ "$user_pin" == "$pin_forward" ]; then + if [ "$action" == "O" ]; then + ports="open" + else + ports="closed" + fi + echo "ports=$ports" > "$config_file" + echo -e "\n\033[33mNOTE: This is a default change and does not affect apps that are deployed.\033[0m" + echo "Press [ENTER] to Acknowledge" + read + break + elif [ "$user_pin" == "$pin_exit" ]; then + # Return to the main menu if exit PIN is entered + return + else + echo "" + echo "Invalid PIN. Try again." + fi + done +} + +# Function to prompt user for action +handle_choice() { + local action=$1 + echo "" + if [ "$action" == "O" ]; then + echo -e "\033[31mWarning: Are you sure you want to OPEN all ports by default?\033[0m" + elif [ "$action" == "C" ];then + echo -e "\033[31mWarning: Are you sure you want to CLOSE all ports by default?\033[0m" + fi + handle_pin "$action" +} + +# Main loop +while true; do + show_header + show_menu + read -p "Select an Option > " choice + + case "$choice" in + O|o) + if [ "$ports" == "closed" ]; then + handle_choice "O" + else + echo "Option is hidden. Please select a valid option." + fi + ;; + C|c) + if [ "$ports" == "open" ]; then + handle_choice "C" + else + echo "Option is hidden. Please select a valid option." + fi + ;; + Z|z) + exit 0 # Truly exit the script when Z is selected + ;; + *) + echo "Invalid option. Please try again." + ;; + esac +done From d0be6aade44def78ddea07fd182245acdd626e5d Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Fri, 13 Sep 2024 16:53:04 -0400 Subject: [PATCH 2/8] update --- mods/scripts/apps_interface.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mods/scripts/apps_interface.sh b/mods/scripts/apps_interface.sh index 4ac95d1a50..4bb41e1972 100644 --- a/mods/scripts/apps_interface.sh +++ b/mods/scripts/apps_interface.sh @@ -17,7 +17,7 @@ config_type=$2 # 'personal' for personal configurations, 'official' for officia # Function: check_deployment_status check_deployment_status() { - # Load the configuration file to get the port_number + # Load the configuration file to get the port_number and expose value if [[ "$config_type" == "personal" ]]; then config_file="/pg/personal_configs/${app_name}.cfg" else @@ -28,10 +28,18 @@ check_deployment_status() { source "$config_file" fi + # Determine port status based on the 'expose' variable + if [[ "$expose" == "127.0.0.1"* ]]; then + port_status="Closed" + else + port_status="Open" + fi + + # Check if the app's Docker container is running local container_status=$(docker ps --filter "name=^/${app_name}$" --format "{{.Names}}") if [[ "$container_status" == "$app_name" ]]; then - echo -e "${GREEN}[Deployed]${NC} $app_name - Port: $port_number" + echo -e "${GREEN}[Deployed]${NC} $app_name - Port: $port_number/$port_status" else echo -e "${RED}[Not Deployed]${NC} $app_name" fi @@ -177,4 +185,4 @@ apps_interface() { } # Run the interface with the provided app name and type -apps_interface \ No newline at end of file +apps_interface From 29441f5f508c3e7124c78caa36d2dee3df058cf7 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Fri, 13 Sep 2024 16:59:47 -0400 Subject: [PATCH 3/8] update --- mods/scripts/apps_interface.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mods/scripts/apps_interface.sh b/mods/scripts/apps_interface.sh index 4bb41e1972..5a47e2f6e0 100644 --- a/mods/scripts/apps_interface.sh +++ b/mods/scripts/apps_interface.sh @@ -41,7 +41,12 @@ check_deployment_status() { if [[ "$container_status" == "$app_name" ]]; then echo -e "${GREEN}[Deployed]${NC} $app_name - Port: $port_number/$port_status" else - echo -e "${RED}[Not Deployed]${NC} $app_name" + # App is not deployed, show potential port status if deployed + if [[ "$port_status" == "Closed" ]]; then + echo -e "${RED}[Not Deployed]${NC} $app_name - Port Closed if Deployed" + else + echo -e "${RED}[Not Deployed]${NC} $app_name - Port Open if Deployed" + fi fi } From f0a38d7da6ad02352f94413d054e7ccad368c9c3 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Fri, 13 Sep 2024 17:09:56 -0400 Subject: [PATCH 4/8] update --- mods/scripts/domain_menu.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mods/scripts/domain_menu.sh b/mods/scripts/domain_menu.sh index 41dd8271aa..289751679b 100644 --- a/mods/scripts/domain_menu.sh +++ b/mods/scripts/domain_menu.sh @@ -10,14 +10,34 @@ GREEN="\033[0;32m" BLUE="\033[0;34m" PURPLE="\033[0;35m" NC='\033[0m' # No Color +BOLD="\033[1m" + +# Get the port status from /pg/config/default_ports.cfg +get_port_status() { + config_file="/pg/config/default_ports.cfg" + if [[ -f "$config_file" ]]; then + source "$config_file" + if [[ "$ports" == "open" ]]; then + port_status="Open" + elif [[ "$ports" == "closed" ]]; then + port_status="Closed" + else + port_status="Unknown" + fi + else + port_status="Unknown" + fi +} # Function to display the menu display_menu() { clear + get_port_status # Fetch the port status echo -e "${CYAN}PG Domain Configuration Interface${NC}" echo echo -e "[${YELLOW}${BOLD}A${NC}] CloudFlare Tunnel" echo -e "[${CYAN}${BOLD}B${NC}] CloudFlare Traefik" + echo -e "[${GREEN}${BOLD}P${NC}] Default Port Protection - (Default Ports: ${port_status})" echo -e "[${RED}${BOLD}Z${NC}] Exit" echo } @@ -34,6 +54,9 @@ while true; do [Bb]) bash /pg/scripts/traefik_menu.sh ;; + [Pp]) + bash /pg/scripts/default_ports.sh + ;; [Zz]) echo "Exiting..." exit 0 @@ -44,4 +67,4 @@ while true; do esac echo -done \ No newline at end of file +done From 6d4cf45d7eddf4dfe5962d67aab3abf2379427aa Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Fri, 13 Sep 2024 17:21:27 -0400 Subject: [PATCH 5/8] update --- mods/scripts/apps_starter_menu.sh | 35 ++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/mods/scripts/apps_starter_menu.sh b/mods/scripts/apps_starter_menu.sh index 1a8016c794..33ce30cfcc 100644 --- a/mods/scripts/apps_starter_menu.sh +++ b/mods/scripts/apps_starter_menu.sh @@ -6,6 +6,7 @@ GREEN="\033[0;32m" ORANGE="\033[0;33m" BLUE="\033[0;34m" WHITE="\033[1;37m" +CYAN="\033[0;36m" BOLD="\033[1m" NC="\033[0m" # No color @@ -13,6 +14,23 @@ NC="\033[0m" # No color DEFAULT_USER="None" DEFAULT_REPO="None" +# Function to get the Default Port Status from /pg/config/default_ports.cfg +get_port_status() { + config_file="/pg/config/default_ports.cfg" + if [[ -f "$config_file" ]]; then + source "$config_file" + if [[ "$ports" == "open" ]]; then + port_status="Open" + elif [[ "$ports" == "closed" ]]; then + port_status="Closed" + else + port_status="Unknown" + fi + else + port_status="Unknown" + fi +} + # Function to count running Docker containers that match official app names from .app files in /pg/apps count_docker_apps() { local all_running_apps=$(docker ps --format '{{.Names}}' | grep -v 'cf_tunnel') @@ -102,6 +120,9 @@ main_menu() { # Load personal apps configuration load_personal_apps_config + # Get Default Port Status + get_port_status + clear echo -e "${BLUE}${BOLD}PlexGuide: Applications Interface${NC}" echo -e "${WHITE}────────────────────────────────────────────────────${NC}" @@ -126,15 +147,20 @@ main_menu() { printf " R) Personal: Deploy Apps\n" fi - echo "" # Space between options and input prompt + echo "" # Space for separation else echo "" # Space for separation echo -e "${RED}Please select an App Store version by choosing option A.${NC}" fi + # Default Ports section + echo -e "${CYAN}${BOLD}Default Ports${NC}" + printf " Y) Default Port Status: [%s]\n" "$port_status" + + echo "" # Space between options and input prompt echo -e "${WHITE}────────────────────────────────────────────────────${NC}" # Display the prompt with colors and capture user input - echo -e "Type a Selection or [${GREEN}Z${NC}] to Exit:${NC} \c" + echo -e "Select an Option or [${GREEN}Z${NC}] to Exit >${NC} \c" read -r choice case $choice in @@ -176,6 +202,9 @@ main_menu() { bash /pg/scripts/apps_stage.sh "personal" fi ;; + Y|y) + bash /pg/scripts/default_ports.sh + ;; Z|z) exit 0 ;; @@ -188,4 +217,4 @@ main_menu() { } # Call the main menu function -main_menu \ No newline at end of file +main_menu From 8df8ec9bf7f1825110c16e28a1e2bdaafe3d6c39 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Fri, 13 Sep 2024 17:24:14 -0400 Subject: [PATCH 6/8] update --- mods/scripts/domain_menu.sh | 2 +- mods/scripts/menu.sh | 2 +- mods/scripts/options.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/scripts/domain_menu.sh b/mods/scripts/domain_menu.sh index 289751679b..c912a8b23f 100644 --- a/mods/scripts/domain_menu.sh +++ b/mods/scripts/domain_menu.sh @@ -45,7 +45,7 @@ display_menu() { # Main loop while true; do display_menu - read -p "Enter your choice: " choice + read -p "Make a Choice > " choice case $choice in [Aa]) diff --git a/mods/scripts/menu.sh b/mods/scripts/menu.sh index e5aab37b9e..fee2a5afa1 100644 --- a/mods/scripts/menu.sh +++ b/mods/scripts/menu.sh @@ -109,7 +109,7 @@ main_menu() { echo "" # Space between options and input prompt # Prompt for user input - read -p "Enter your choice: " choice + read -p "Make a Choice > " choice # Process user input case ${choice,,} in diff --git a/mods/scripts/options.sh b/mods/scripts/options.sh index eb4691a15c..a54a2fa162 100644 --- a/mods/scripts/options.sh +++ b/mods/scripts/options.sh @@ -39,7 +39,7 @@ main_menu() { echo "" # Space between options and input prompt # Prompt the user for input - read -p "Enter your choice [G/S/Z]: " choice + read -p "Make a Choice > " choice case ${choice,,} in # Convert input to lowercase for g/G, s/S, z/Z handling g) From 1fea1f03798a564c13104f3b37311ead228a0a8a Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Fri, 13 Sep 2024 17:27:06 -0400 Subject: [PATCH 7/8] update --- mods/scripts/apps_interface.sh | 2 +- mods/scripts/apps_starter_menu.sh | 2 +- mods/scripts/cf_tunnel.sh | 2 +- mods/scripts/cloud_server.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/scripts/apps_interface.sh b/mods/scripts/apps_interface.sh index 5a47e2f6e0..dd1e20be62 100644 --- a/mods/scripts/apps_interface.sh +++ b/mods/scripts/apps_interface.sh @@ -158,7 +158,7 @@ apps_interface() { echo "Z) Exit" echo "" - read -p "Choose an option: " choice + read -p "Make a Choice > " choice case ${choice,,} in # Convert input to lowercase d) diff --git a/mods/scripts/apps_starter_menu.sh b/mods/scripts/apps_starter_menu.sh index 33ce30cfcc..5a2ee4a16b 100644 --- a/mods/scripts/apps_starter_menu.sh +++ b/mods/scripts/apps_starter_menu.sh @@ -160,7 +160,7 @@ main_menu() { echo "" # Space between options and input prompt echo -e "${WHITE}────────────────────────────────────────────────────${NC}" # Display the prompt with colors and capture user input - echo -e "Select an Option or [${GREEN}Z${NC}] to Exit >${NC} \c" + echo -e "Make a Choice or [${GREEN}Z${NC}] to Exit >${NC} \c" read -r choice case $choice in diff --git a/mods/scripts/cf_tunnel.sh b/mods/scripts/cf_tunnel.sh index 75367da248..50e7f30371 100644 --- a/mods/scripts/cf_tunnel.sh +++ b/mods/scripts/cf_tunnel.sh @@ -64,7 +64,7 @@ show_menu() { # Function to prompt the user with a choice prompt_choice() { - read -p "Select an option: " choice + read -p "Make a Choice > " choice case ${choice,,} in # Convert input to lowercase for v/V, c/C, d/D, s/S, z/Z handling v) clear diff --git a/mods/scripts/cloud_server.sh b/mods/scripts/cloud_server.sh index d0ee0fe4db..641ea73077 100644 --- a/mods/scripts/cloud_server.sh +++ b/mods/scripts/cloud_server.sh @@ -87,7 +87,7 @@ cloud_server_menu() { echo "" # Space between options and input prompt # Prompt for user input - read -p "Enter your choice: " choice + read -p "Make a Choice > " choice # Process user input case ${choice,,} in From f848fccac10b3c96e941965ed03fb5fad0d349f4 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Fri, 13 Sep 2024 17:29:50 -0400 Subject: [PATCH 8/8] update --- mods/scripts/graphics.sh | 2 +- mods/scripts/options.sh | 8 +------- mods/scripts/ssh.sh | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/mods/scripts/graphics.sh b/mods/scripts/graphics.sh index 3d8fdd1200..378181fc14 100644 --- a/mods/scripts/graphics.sh +++ b/mods/scripts/graphics.sh @@ -216,7 +216,7 @@ main_menu() { echo # Prompt the user for input - read -p "Make a Selection: " user_choice + read -p "Make a Choice > " user_choice case "$user_choice" in I|i) diff --git a/mods/scripts/options.sh b/mods/scripts/options.sh index a54a2fa162..ec44b54da6 100644 --- a/mods/scripts/options.sh +++ b/mods/scripts/options.sh @@ -11,12 +11,6 @@ clear # Load the configuration load_config -# Function for SSH Management option -ssh_management() { - clear - /pg/scripts/ssh.sh -} - # Function to exit the script exit_script() { clear @@ -46,7 +40,7 @@ main_menu() { bash /pg/scripts/graphics.sh ;; s) - ssh_management + bash /pg/scripts/ssh.sh ;; z) exit_script diff --git a/mods/scripts/ssh.sh b/mods/scripts/ssh.sh index 8eccba919a..604b89d036 100644 --- a/mods/scripts/ssh.sh +++ b/mods/scripts/ssh.sh @@ -180,7 +180,7 @@ main_menu() { echo "" # Space between options and input prompt # Prompt the user for input - read -p "Enter your choice [I/E/D/P/U/Z]: " choice + read -p "Make a Choice > " choice case ${choice,,} in # Convert input to lowercase for i/I, e/E, d/D, p/P, u/U, z/Z handling i) install_ssh ;;