From c5173de1d9be6f9565eb951cabfe9ed9eb74d4cc Mon Sep 17 00:00:00 2001 From: q3aql Date: Sun, 29 May 2022 02:01:22 +0200 Subject: [PATCH] Edit credentials with separated files (dmenu) --- dmenu_protonvpn | 51 ++++++++++++++++++++++- menu/about.sh | 41 ------------------- menu/download-protonvpn-files.sh | 43 -------------------- menu/edit-credentials.sh | 69 -------------------------------- menu/edit-pass-credential.sh | 23 +++++++++++ menu/edit-user-credential.sh | 23 +++++++++++ 6 files changed, 95 insertions(+), 155 deletions(-) delete mode 100755 menu/about.sh delete mode 100755 menu/download-protonvpn-files.sh delete mode 100755 menu/edit-credentials.sh create mode 100755 menu/edit-pass-credential.sh create mode 100755 menu/edit-user-credential.sh diff --git a/dmenu_protonvpn b/dmenu_protonvpn index df9cc4c..13d5d5c 100755 --- a/dmenu_protonvpn +++ b/dmenu_protonvpn @@ -2,19 +2,21 @@ ################################################################ # Script for manage your ProtonVPN connections (Dmenu VERSION) # -# Last change: 28-05-2022 # +# Last change: 29-05-2022 # # Author: q3aql # # Contact: q3aql@duck.com # # License: GPL v2.0 # ################################################################ VERSION="2.0" -M_DATE="280522" +M_DATE="290522" # Variables protonFiles="${HOME}/protonFiles" url_download="https://account.protonvpn.com/downloads" url_credentials="https://account.protonvpn.com/account#openvpn" file_credentials="/opt/dmenu_protonvpn/proton-credentials.txt" +user_credentials="/opt/dmenu_protonvpn/proton-user.txt" +pass_credentials="/opt/dmenu_protonvpn/proton-pass.txt" sed_file_credentials="\/opt\/dmenu_protonvpn\/proton-credentials.txt" menu_files="/opt/dmenu_protonvpn/menu" @@ -81,6 +83,8 @@ function openBrowser() { } function insertCredentials() { + cat ${user_credentials} > ${file_credentials} + cat ${pass_credentials} >> ${file_credentials} if [ -f "${1}" ] ; then check_credentials=$(cat "${1}" | grep "auth-user-pass ${file_credentials}") if [ -z "${check_credentials}" ] ; then @@ -89,7 +93,50 @@ function insertCredentials() { fi } +function editCredentialsText() { + if [ -f ${user_credentials} ] ; then + current_user=$(cat ${user_credentials}) + else + current_user="" + fi + if [ -f ${pass_credentials} ] ; then + current_pass=$(cat ${pass_credentials}) + else + current_pass="" + fi + echo " EDIT CREDENTIALS:" + echo "" + echo " Edit USER" + echo " Edit PASS" + echo "" + echo " URL Credentials: ${url_credentials}" + echo "" + echo " Configured user: ${current_user}" + echo " Configured pass: ${current_pass}" + echo "" +} + function editCredentials() { + select_output=$(editCredentialsText | /opt/dmenu_protonvpn/dmenu "$@" -p "嬨 dmenu_protonvpn v${VERSION}") + if [ "${select_output}" == " URL Credentials: ${url_credentials}" ] ; then + openBrowser "${url_credentials}" & + editCredentials + elif [ "${select_output}" == " Edit USER" ] ; then + ${termrun} "${menu_files}/edit-user-credential.sh" + cat ${user_credentials} > ${file_credentials} + cat ${pass_credentials} >> ${file_credentials} + editCredentials + elif [ "${select_output}" == " Edit PASS" ] ; then + ${termrun} "${menu_files}/edit-pass-credential.sh" + cat ${user_credentials} > ${file_credentials} + cat ${pass_credentials} >> ${file_credentials} + editCredentials + else + run_main + fi +} + +function editCredentials2() { user_openvpn=$(zenity --entry --title "dmenu_protonvpn ${VERSION} (${M_DATE})" \ --text "URL Credentials ${url_credentials}\n\nUser OpenVPN / IKEv2:" --entry-text "USER-HERE") pass_openvpn=$(zenity --entry --title "dmenu_protonvpn ${VERSION} (${M_DATE})" \ diff --git a/menu/about.sh b/menu/about.sh deleted file mode 100755 index 406cf4b..0000000 --- a/menu/about.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -################################################################ -# Script for manage your ProtonVPN connections (Dmenu VERSION) # -# Last change: 28-05-2022 # -# Author: q3aql # -# Contact: q3aql@duck.com # -# License: GPL v2.0 # -################################################################ -VERSION="2.0" -M_DATE="280522" - -# Variables -protonFiles="${HOME}/protonFiles" -url_download="https://account.protonvpn.com/downloads" -url_credentials="https://account.protonvpn.com/account#openvpn" -file_credentials="/opt/dmenu_protonvpn/proton-credentials.txt" -sed_file_credentials="\/opt\/dmenu_protonvpn\/proton-credentials.txt" -menu_files="/opt/dmenu_protonvpn/menu" - -case "${TERM}" in - xterm-color|*-256color) color_prompt=yes;; -esac -if [ "${color_prompt}" == "yes" ] ; then - blue='\e[34m' ; red='\e[31m' ; yellow='\e[33m' - purple='\e[35m' ; green='\e[32m' ; end='\e[0m' -else - blue='' ; red='' ; yellow='' ; morado='' - verde='' ; end='' -fi - -clear -echo "" -echo -e "${green}* About:${end}" -echo "" -echo -e " ${red}-${end} ${green}Software:${end}${purple} dmenu_protonvpn ${VERSION} (${M_DATE})${end}" -echo -e " ${red}-${end} ${green}Author:${end}${purple} q3aql${end}" -echo -e " ${red}-${end} ${green}Contact:${end}${purple} q3aql@duck.com${end}" -echo -e " ${red}-${end} ${green}License:${end}${purple} GPL v2.0${end}" -echo "" -echo -ne "${green}+ Press ${end}${purple}ENTER${end}${green} to return menu${end} " ; read return diff --git a/menu/download-protonvpn-files.sh b/menu/download-protonvpn-files.sh deleted file mode 100755 index 7374058..0000000 --- a/menu/download-protonvpn-files.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -################################################################ -# Script for manage your ProtonVPN connections (Dmenu VERSION) # -# Last change: 28-05-2022 # -# Author: q3aql # -# Contact: q3aql@duck.com # -# License: GPL v2.0 # -################################################################ -VERSION="2.0" -M_DATE="280522" - -# Variables -protonFiles="${HOME}/protonFiles" -url_download="https://account.protonvpn.com/downloads" -url_credentials="https://account.protonvpn.com/account#openvpn" -file_credentials="/opt/dmenu_protonvpn/proton-credentials.txt" -sed_file_credentials="\/opt\/dmenu_protonvpn\/proton-credentials.txt" -menu_files="/opt/dmenu_protonvpn/menu" - -case "${TERM}" in - xterm-color|*-256color) color_prompt=yes;; -esac -if [ "${color_prompt}" == "yes" ] ; then - blue='\e[34m' ; red='\e[31m' ; yellow='\e[33m' - purple='\e[35m' ; green='\e[32m' ; end='\e[0m' -else - blue='' ; red='' ; yellow='' ; morado='' - verde='' ; end='' -fi - -clear -echo "" -echo -e "${green}* dmenu_protonvpn${end}${purple} v${VERSION} ${end}${green}(${M_DATE})${end}" -echo "" -echo -e " ${purple}* Steps for download .ovpn files:${end}" -echo "" -echo -e " ${red}-${end}${green} Open URL: ${end}${yellow}${url_download}${end}" -echo -e " ${red}-${end}${green} Login with your Proton account${end}" -echo -e " ${red}-${end}${green} Click to Downloads > OpenVPN configuration files${end}" -echo -e " ${red}-${end}${green} Download *.ovpn files and copy to ${end}${yellow}${HOME}/protonFiles${end}" -echo "" -echo -ne "${green}+ Press ${end}${purple}ENTER${end}${green} to return menu${end} " ; read return diff --git a/menu/edit-credentials.sh b/menu/edit-credentials.sh deleted file mode 100755 index 57ec81e..0000000 --- a/menu/edit-credentials.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash - -################################################################ -# Script for manage your ProtonVPN connections (Dmenu VERSION) # -# Last change: 28-05-2022 # -# Author: q3aql # -# Contact: q3aql@duck.com # -# License: GPL v2.0 # -################################################################ -VERSION="2.0" -M_DATE="280522" - -# Variables -protonFiles="${HOME}/protonFiles" -url_download="https://account.protonvpn.com/downloads" -url_credentials="https://account.protonvpn.com/account#openvpn" -file_credentials="/opt/dmenu_protonvpn/proton-credentials.txt" -sed_file_credentials="\/opt\/dmenu_protonvpn\/proton-credentials.txt" -menu_files="/opt/dmenu_protonvpn/menu" - -case "${TERM}" in - xterm-color|*-256color) color_prompt=yes;; -esac -if [ "${color_prompt}" == "yes" ] ; then - blue='\e[34m' ; red='\e[31m' ; yellow='\e[33m' - purple='\e[35m' ; green='\e[32m' ; end='\e[0m' -else - blue='' ; red='' ; yellow='' ; morado='' - verde='' ; end='' -fi - -function insertCredentials() { - if [ -f "${1}" ] ; then - check_credentials=$(cat "${1}" | grep "auth-user-pass ${file_credentials}") - if [ -z "${check_credentials}" ] ; then - sed -i "s/auth-user-pass/auth-user-pass ${sed_file_credentials}/g" "${1}" - fi - fi -} - -function checkFileCredentials() { - check_file=$(cat ${file_credentials} 2> /dev/null | wc -l) - if [ ${check_file} -ne 2 ] ; then - editCredentials - fi -} - -function checkFileCredentials() { - check_file=$(cat ${file_credentials} 2> /dev/null | wc -l) - if [ ${check_file} -ne 2 ] ; then - editCredentials - fi -} - -clear -echo "" -echo -e "${green}* dmenu_protonvpn${end}${purple} v${VERSION} ${end}${green}(${M_DATE})${end}" -echo "" -echo -e "${purple}+ URL Credentials:${end}${yellow} ${url_credentials}${end}" -echo "" -echo -ne "${green}* User OpenVPN / IKEv2:${end} " ; read user_openvpn -echo -ne "${green}* Password OpenVPN / IKEv2:${end} " ; read pass_openvpn -if [ -z "${user_openvpn}" ] ; then - echo "# User / Password canceled" -else - echo "${user_openvpn}" > ${file_credentials} - echo "${pass_openvpn}" >> ${file_credentials} -fi - diff --git a/menu/edit-pass-credential.sh b/menu/edit-pass-credential.sh new file mode 100755 index 0000000..58f1ee6 --- /dev/null +++ b/menu/edit-pass-credential.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +################################################################ +# Script for manage your ProtonVPN connections (Dmenu VERSION) # +# Last change: 29-05-2022 # +# Author: q3aql # +# Contact: q3aql@duck.com # +# License: GPL v2.0 # +################################################################ +VERSION="2.0" +M_DATE="290522" + +file_credentials="/opt/dmenu_protonvpn/proton-credentials.txt" +user_credentials="/opt/dmenu_protonvpn/proton-user.txt" +pass_credentials="/opt/dmenu_protonvpn/proton-pass.txt" + +echo "" +echo -n "* Password OpenVPN / IKEv2: " ; read pass_openvpn +if [ -z "${pass_openvpn}" ] ; then + echo "# Pass canceled" +else + echo "${pass_openvpn}" > ${pass_credentials} +fi diff --git a/menu/edit-user-credential.sh b/menu/edit-user-credential.sh new file mode 100755 index 0000000..aff14f0 --- /dev/null +++ b/menu/edit-user-credential.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +################################################################ +# Script for manage your ProtonVPN connections (Dmenu VERSION) # +# Last change: 29-05-2022 # +# Author: q3aql # +# Contact: q3aql@duck.com # +# License: GPL v2.0 # +################################################################ +VERSION="2.0" +M_DATE="290522" + +file_credentials="/opt/dmenu_protonvpn/proton-credentials.txt" +user_credentials="/opt/dmenu_protonvpn/proton-user.txt" +pass_credentials="/opt/dmenu_protonvpn/proton-pass.txt" + +echo "" +echo -n "* User OpenVPN / IKEv2: " ; read user_openvpn +if [ -z "${user_openvpn}" ] ; then + echo "# User canceled" +else + echo "${user_openvpn}" > ${user_credentials} +fi