From 7a1d6492b2541278a2c6a575a1ff5406839d9338 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 12 Oct 2023 17:42:31 +0200 Subject: [PATCH 01/39] Initial commit --- config/vpn-providers.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 config/vpn-providers.json diff --git a/config/vpn-providers.json b/config/vpn-providers.json new file mode 100644 index 00000000..ed2b7641 --- /dev/null +++ b/config/vpn-providers.json @@ -0,0 +1,14 @@ +{ + "providers": [ + { + "id": 1, + "name": "ExpressVPN", + "bin_path": "/usr/bin/expressvpn" + }, + { + "id": 2, + "name": "NordVPN", + "bin_path": "/usr/bin/nordvpn" + } + ] +} From d3c9b00e899bc334322982fa8c553a62b079d6f6 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 12 Oct 2023 17:43:54 +0200 Subject: [PATCH 02/39] Added _prompt_install_vpn_providers() --- installers/common.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/installers/common.sh b/installers/common.sh index a98d0f84..194477a9 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -59,6 +59,7 @@ function _install_raspap() { _prompt_install_openvpn _install_mobile_clients _prompt_install_wireguard + _prompt_install_vpn_providers _patch_system_files _install_complete } @@ -401,6 +402,64 @@ function _install_adblock() { _install_status 0 } +# Prompt to install VPN providers +function _prompt_install_vpn_providers() { + _install_log "Configure VPN provider support" + echo -n "Enable VPN provider client configuration? [Y/n]: " + if [ "$assume_yes" == 0 ]; then + read answer < /dev/tty + if [ "$answer" != "${answer#[Nn]}" ]; then + _install_status 0 "(Skipped)" + else + echo -e "Select an option from the list:" + while true; do + json="$webroot_dir/config/"vpn-providers.json + while IFS='|' read -r key value; do + options["$key"]="$value" + done< <(jq -r '.providers[] | "\(.id)|\(.name)|\(.bin_path)"' "$json") + + # display provider options + for key in "${!options[@]}"; do + echo " $key) ${options[$key]%%|*}" + done + echo " 0) None" + echo -n "Choose an option: " + read answer < /dev/tty + + if [ "$answer" != "${answer#[0]}" ]; then + _install_status 0 "(Skipped)" + break + elif [[ "$answer" =~ ^[0-9]+$ ]] && [[ -n ${options[$answer]+abc} ]]; then + selected="${options[$answer]}" + echo "Configuring support for ${selected%%|*}" + bin_path=${selected#*|} + if ! grep -q "$bin_path" "$webroot_dir/installers/raspap.sudoers"; then + echo "Adding $bin_path to raspap.sudoers" + echo "www-data ALL=(ALL) NOPASSWD:$bin_path" | sudo tee -a "$webroot_dir/installers/raspap.sudoers" > /dev/null || _install_status 1 "Unable to modify raspap.sudoers" + fi + echo "Enabling administration option for ${selected%%|*}" + sudo sed -i "s/\('RASPI_VPN_PROVIDER_ENABLED', \)false/\1true/g" "$webroot_dir/includes/config.php" || _install_status 1 "Unable to modify config.php" + + echo "Adding VPN provider to $raspap_dir/provider.ini" + if [ ! -f "$raspap_dir/provider.ini" ]; then + sudo touch "$raspap_dir/provider.ini" + echo "providerID = $answer" | sudo tee "$raspap_dir/provider.ini" > /dev/null || _install_status 1 "Unable to create $raspap_dir/provider.ini" + elif ! grep -q "providerID = $answer" "$raspap_dir/provider.ini"; then + echo "providerID = $answer" | sudo tee "$raspap_dir/provider.ini" > /dev/null || _install_status 1 "Unable to write to $raspap_dir/provider.ini" + fi + + _install_status 0 + break + else + echo "Invalid choice. Select a valid option:" + fi + done + fi + else + echo "(Skipped)" + fi +} + # Prompt to install openvpn function _prompt_install_openvpn() { _install_log "Configure OpenVPN support" From ac7b4ccb289398f8cd45d8a2a1835d511b95743b Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 12 Oct 2023 19:17:00 +0200 Subject: [PATCH 03/39] Add basic commands for Linux provider CLIs --- config/vpn-providers.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/vpn-providers.json b/config/vpn-providers.json index ed2b7641..39a2be9c 100644 --- a/config/vpn-providers.json +++ b/config/vpn-providers.json @@ -3,12 +3,14 @@ { "id": 1, "name": "ExpressVPN", - "bin_path": "/usr/bin/expressvpn" + "bin_path": "/usr/bin/expressvpn", + "commands": "connect disconnect status version" }, { "id": 2, "name": "NordVPN", - "bin_path": "/usr/bin/nordvpn" + "bin_path": "/usr/bin/nordvpn", + "commands": "connect disconnect status version" } ] } From 5123ab4599301c658d7566882acfc6986ebdd046 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 12 Oct 2023 19:19:15 +0200 Subject: [PATCH 04/39] Update w/ provider constants --- config/config.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/config.php b/config/config.php index 4589092d..630f1ef7 100755 --- a/config/config.php +++ b/config/config.php @@ -3,6 +3,7 @@ define('RASPI_BRAND_TEXT', 'RaspAP'); define('RASPI_CONFIG', '/etc/raspap'); define('RASPI_CONFIG_NETWORK', RASPI_CONFIG.'/networking/defaults.json'); +define('RASPI_CONFIG_PROVIDERS', 'config/vpn-providers.json'); define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth'); define('RASPI_WIFI_AP_INTERFACE', 'wlan0'); define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap'); @@ -43,6 +44,7 @@ define('RASPI_NETWORK_ENABLED', true); define('RASPI_DHCP_ENABLED', true); define('RASPI_ADBLOCK_ENABLED', false); define('RASPI_OPENVPN_ENABLED', false); +define('RASPI_VPN_PROVIDER_ENABLED', false); define('RASPI_WIREGUARD_ENABLED', false); define('RASPI_TORPROXY_ENABLED', false); define('RASPI_CONFAUTH_ENABLED', true); From a2394c0742b0c54cbd6ee3bc0d32b7b00832b5d6 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 12 Oct 2023 19:21:23 +0200 Subject: [PATCH 05/39] Update UI, page actions + functions for basic provider support --- includes/defaults.php | 2 ++ includes/functions.php | 30 ++++++++++++++++++++++++++++++ includes/page_actions.php | 3 +++ includes/sidebar.php | 5 +++++ index.php | 1 + 5 files changed, 41 insertions(+) diff --git a/includes/defaults.php b/includes/defaults.php index 3fc6e914..dd5c588f 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -8,6 +8,7 @@ $defaults = [ 'RASPI_BRAND_TEXT' => 'RaspAP', 'RASPI_VERSION' => '2.9.6', 'RASPI_CONFIG_NETWORK' => RASPI_CONFIG.'/networking/defaults.json', + 'RASPI_CONFIG_PROVIDERS' => 'config/vpn-providers.json', 'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth', 'RASPI_WIFI_AP_INTERFACE' => 'wlan0', 'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap', @@ -45,6 +46,7 @@ $defaults = [ 'RASPI_DHCP_ENABLED' => true, 'RASPI_ADBLOCK_ENABLED' => false, 'RASPI_OPENVPN_ENABLED' => false, + 'RASPI_VPN_PROVIDER_ENABLED' => false, 'RASPI_WIREGUARD_ENABLED' => false, 'RASPI_TORPROXY_ENABLED' => false, 'RASPI_CONFAUTH_ENABLED' => true, diff --git a/includes/functions.php b/includes/functions.php index 24a42f15..e5797507 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -169,6 +169,24 @@ function getDefaultNetOpts($svc,$key) } } +/** + * Returns a value for the specified VPN provider + * + * @param numeric $id + * @param string $key + * @return object $json + */ +function getProviderValue($id,$key) +{ + $obj = json_decode(file_get_contents(RASPI_CONFIG_PROVIDERS), true); + if ($obj === null) { + return false; + } else { + $id--; + return $obj['providers'][$id][$key]; + } +} + /* Functions to write ini files */ /** @@ -669,6 +687,7 @@ function initializeApp() $_SESSION["theme_url"] = getThemeOpt(); $_SESSION["toggleState"] = getSidebarState(); $_SESSION["bridgedEnabled"] = getBridgedState(); + $_SESSION["providerID"] = getProviderID(); } function getThemeOpt() @@ -709,6 +728,17 @@ function getBridgedState() return $arrHostapdConf['BridgedEnable']; } +// Returns VPN provider ID, if defined +function getProviderID() +{ + if (RASPI_VPN_PROVIDER_ENABLED) { + $arrProvider = parse_ini_file(RASPI_CONFIG.'/provider.ini'); + if (isset($arrProvider['providerID'])) { + return $arrProvider['providerID']; + } + } +} + /** * Validates the format of a CIDR notation string * diff --git a/includes/page_actions.php b/includes/page_actions.php index b460dd43..ed64a33e 100755 --- a/includes/page_actions.php +++ b/includes/page_actions.php @@ -27,6 +27,9 @@ case "/wg_conf": DisplayWireGuardConfig(); break; + case "/provider_conf": + DisplayProviderConfig(); + break; case "/torproxy_conf": DisplayTorProxyConfig(); break; diff --git a/includes/sidebar.php b/includes/sidebar.php index ada2a0b0..13558354 100755 --- a/includes/sidebar.php +++ b/includes/sidebar.php @@ -60,6 +60,11 @@ + + +