Commit 49c9e3c1 authored by Igor Pecovnik's avatar Igor Pecovnik
Browse files

Few bug fixes and added VPN client management since I need to fix this elsewhere ...

parent c949c173
......@@ -441,6 +441,105 @@ function jobs ()
;;
# Manage Softether VPN
#
"VPN" )
VPNDIR="/usr/local/vpnclient/"
function vpn_reconfigure ()
{
if [[ -f /etc/server.vpn ]]; then
${VPNDIR}vpnclient stop >/dev/null 2>&1
${VPNDIR}vpnclient start >/dev/null 2>&1
# purge old settings
${VPNDIR}vpncmd /client localhost /cmd accountlist | grep "VPN Connection Setting Name" | cut -d "|" -f 2 | sed 's/^/"/;s/$/"/' | xargs /usr/local/vpnclient/vpncmd /client localhost /cmd accountdisconnect >/dev/null 2>&1
${VPNDIR}vpncmd /client localhost /cmd accountlist | grep "VPN Connection Setting Name" | cut -d "|" -f 2 | sed 's/^/"/;s/$/"/' | xargs /usr/local/vpnclient/vpncmd /client localhost /cmd accountdelete >/dev/null 2>&1
# import new
${VPNDIR}vpncmd /client localhost /cmd accountimport //etc//server.vpn >/dev/null 2>&1
# reload to connect
${VPNDIR}vpnclient stop >/dev/null 2>&1
${VPNDIR}vpnclient start >/dev/null 2>&1
[[ $? = 0 ]] && dialog --backtitle "$BACKTITLE" --title " VPN " --msgbox "\nConfiguration was succesfully imported!" 7 43
fi
}
function get_numbers {
EXCLUDE=$(ip neigh | grep vpn_se | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.' | head -1)
ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)' | grep -v vpn_se | head -1)
IP=$(ip route | grep $ADAPTER | grep default | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)
VPNSERVERIP=$(${VPNDIR}vpncmd /client localhost /cmd accountlist | grep "VPN Server" |grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)
SUBNET=$(ifconfig vpn_se | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
GW=$(ip neigh | grep vpn_se | grep $SUBNET | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)
}
function raise_dev {
i=0;
while [[ -z "$TEMP" && $i<5 ]]; do
TEMP=$(${VPNDIR}vpncmd /client localhost /cmd accountlist | grep Status | grep Connected)
sleep 1
i=$((i+1))
done
dhclient vpn_se
}
if pgrep -x "vpnclient" > /dev/null
then
${VPNDIR}vpnclient stop >/dev/null 2>&1
${VPNDIR}vpnclient start >/dev/null 2>&1
if [[ -z $(${VPNDIR}vpncmd /client localhost /cmd nicList | grep Enabled) ]]; then
${VPNDIR}vpncmd /client localhost /cmd niccreate se >/dev/null 2>&1
fi
if [[ -z $(${VPNDIR}vpncmd /client localhost /cmd accountlist | grep "VPN Server") ]]; then
dialog --backtitle "$BACKTITLE" --no-label " Back " --yes-label " Import " --title " VPN " --yesno "\nVPN configuration was not found.\n\nPlace file to /etc/server.vpn" 9 45
if [[ $? = 0 && -f /etc/server.vpn ]]; then
${VPNDIR}vpncmd /client localhost /cmd accountimport //etc//server.vpn >/dev/null 2>&1
${VPNDIR}vpnclient stop >/dev/null 2>&1
${VPNDIR}vpnclient start >/dev/null 2>&1
[[ $? = 0 ]] && dialog --backtitle "$BACKTITLE" --title " VPN " --msgbox "\nConfiguration was succesfully imported!" 7 43
fi
fi
# raise devices
raise_dev
if [[ -n $(${VPNDIR}vpncmd /client localhost /cmd accountlist | grep Status | grep Connected) ]]; then
get_numbers
echo "ip route add $VPNSERVERIP via $IP dev $ADAPTER"
echo "ip route del default"
echo "ip route add default via $GW dev vpn_se"
read
dialog --title "VPN client is connected to $VPNSERVERIP" --colors --backtitle "$BACKTITLE" --help-button --help-label "Back" --yes-label "Stop" --no-label " Import " --yesno "\n\Z1Stop: \Z0 stop\n\n\Z1Import:\Z0 import new config from /etc/armbian.vpn" 9 70
fi
response=$?
if [[ $response = 0 ]]; then
get_numbers
echo "ip route del $VPNSERVERIP"
echo "ip route del default"
echo "ip route add default via $IP dev $ADAPTER"
read
dialog --backtitle "$BACKTITLE" --nocancel --nook --infobox "\nClosing VPN connection" 5 27
${VPNDIR}vpnclient stop >/dev/null 2>&1
fi
else
dialog --title "VPN client is disconnected" --colors --backtitle "$BACKTITLE" --help-button --help-label "Back" --yes-label "Connect" --no-label " Import " --yesno "\n\Z1Connect:\Z0 Connect with your VPN server \n\n\Z1Import:\Z0 import new config from /etc/armbian.vpn" 9 70
response=$?
if [[ $response = 0 ]]; then
${VPNDIR}vpnclient start >/dev/null 2>&1
# raise devices
raise_dev
get_numbers
echo "ip route add $VPNSERVERIP via $IP dev $ADAPTER"
echo "ip route del default"
echo "ip route add default via $GW dev vpn_se"
read
fi
[[ $response = 1 ]] && vpn_reconfigure
fi
;;
# Connect to Bluetooth
#
"Discover" )
......
......@@ -21,6 +21,8 @@ KERNELID=$(uname -r)
BACKTITLE="Configuration utility, $ARMBIAN, https://www.armbian.com"
TITLE="$BOARD_NAME "
DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)')
[[ -z "${DEFAULT_ADAPTER// }" ]] && DEFAULT_ADAPTER="lo"
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nLoading Armbian configuration utility ... " 5 45
sleep 1
......@@ -443,7 +445,9 @@ function select_default_interface ()
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 1 ]; then
if [ "$LIST_LENGHT" -eq 0 ]; then
DEFAULT_ADAPTER="lo"
elif [ "$LIST_LENGHT" -eq 1 ]; then
DEFAULT_ADAPTER=${ADAPTER[0]}
else
exec 3>&1
......@@ -607,6 +611,8 @@ while true; do
[[ $(hcitool dev | sed '1d') != "" ]] && LIST+=( "Discover" "Discover and connect Bluetooth devices" )
fi
[[ -d /usr/local/vpnclient ]] && LIST+=( "VPN" "Manage Softether VPN client" ) && VPNSERVERIP=$(/usr/local/vpnclient/vpncmd /client localhost /cmd accountlist | grep "VPN Server" |grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)
LIST+=( "Advanced" "Edit /etc/network/interfaces" )
[[ $(ls -1 /etc/NetworkManager/system-connections 2> /dev/null) ]] && \
LIST+=( "Forget" "Disconnect and forget all wireless connections" )
......@@ -634,6 +640,12 @@ while true; do
disclaimer=$disclaimer"$connected"
fi
if [[ -n $VPNSERVERIP ]]; then
local vpnserverip="\n\Z0Connected to VPN server: \Z1${VPNSERVERIP}\n\Z0 "
disclaimer=$disclaimer"$vpnserverip"
LISTLENGHT=$((LISTLENGHT+2))
fi
if [[ -n $HOSTAPDINFO && -n $HOSTAPDSTATUS ]]; then
LISTLENGHT=$((LISTLENGHT+2))
chpid=$(dmesg | grep $(grep ^interface /etc/hostapd.conf | sed 's/interface=//g') | head -1 | sed 's/\[.*\]//g' | awk '{print $1}')
......@@ -752,4 +764,4 @@ while true; do
# run main function
jobs "$selection"
done
}
\ No newline at end of file
}
......@@ -30,6 +30,9 @@ LIST+=( "Syncthing" "Personal cloud @syncthing.net" "$SYNCTHING_STATUS" )
# vpn server
VPN_SERVER_STATUS="$([[ -d /usr/local/vpnserver ]] && echo "on" || echo "off" )"
LIST+=( "VPN server" "VPN server" "$VPN_SERVER_STATUS" )
# vpn client
VPN_CLIENT_STATUS="$([[ -d /usr/local/vpnclient ]] && echo "on" || echo "off" )"
LIST+=( "VPN client" "VPN client" "$VPN_CLIENT_STATUS" )
# OMV
OMV_STATUS="$(check_if_installed openmediavault && echo "on" || echo "off" )"
[[ "$family" != "Ubuntu" ]] && LIST+=( "OMV" "OpenMediaVault NAS solution" "$OMV_STATUS" ) && LIST_CONST=4
......@@ -618,6 +621,33 @@ fi
}
install_vpn_client (){
#------------------------------------------------------------------------------------------------------------------------------------------
# Script downloads latest stable
#------------------------------------------------------------------------------------------------------------------------------------------
cd ${TEMP_DIR}
PREFIX="http://www.softether-download.com/files/softether/"
install_packet "debconf-utils unzip build-essential html2text apt-transport-https" "Downloading basic packages"
URL=$(wget -q $PREFIX -O - | html2text | grep rtm | awk ' { print $(NF) }' | tail -1)
SUFIX="${URL/-tree/}"
if [ "$(dpkg --print-architecture | grep armhf)" != "" ]; then
DLURL=$PREFIX$URL"/Linux/SoftEther_VPN_Client/32bit_-_ARM_EABI/softether-vpnclient-$SUFIX-linux-arm_eabi-32bit.tar.gz"
else
install_packet "gcc-multilib" "Install libraries"
DLURL=$PREFIX$URL"/Linux/SoftEther_VPN_Client/32bit_-_Intel_x86/softether-vpnclient-$SUFIX-linux-x86-32bit.tar.gz"
fi
wget -q $DLURL -O - | tar -xz
cd vpnclient
make i_read_and_agree_the_license_agreement | dialog --backtitle "$BACKTITLE" --title "Compiling SoftEther VPN vpnclient" --progressbox $TTY_Y $TTY_X
cd ..
cp -R vpnclient /usr/local
cd /usr/local/vpnclient/
chmod 600 *
chmod 700 vpncmd
chmod 700 vpnclient
}
install_DashNTP (){
#------------------------------------------------------------------------------------------------------------------------------------------
# Install DASH and ntp service
......@@ -1056,11 +1086,17 @@ while true; do
read -n 1 -s -p "Press any key to continue"
fi
if [[ "$selection" == *VPN* && "$VPN_SERVER_STATUS" != "on" ]]; then
if [[ "$selection" == *server* && "$VPN_SERVER_STATUS" != "on" ]]; then
install_vpn_server
read -n 1 -s -p "Press any key to continue"
fi
if [[ "$selection" == *client* && "$VPN_CLIENT_STATUS" != "on" ]]; then
install_vpn_client
read -n 1 -s -p "Press any key to continue"
fi
if [[ "$selection" == *OMV* && "$OMV_STATUS" != "on" ]]; then
install_omv
read -n 1 -s -p "Press any key to continue"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment