From bd5c0ecbd665d7ef074a5a2d3c1446726743b9aa Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Tue, 8 Jul 2025 23:25:17 +0200 Subject: [PATCH] - Start new external VPN management implementation. --- usr/local/lib/network.bash | 81 +++++++++++++++++++++++++++++++++++++ usr/local/sbin/rx3_net_adm | 32 ++++++++++++++- usr/local/sbin/vyprvpn-down | 4 +- usr/local/sbin/vyprvpn-up | 32 ++------------- 4 files changed, 118 insertions(+), 31 deletions(-) diff --git a/usr/local/lib/network.bash b/usr/local/lib/network.bash index 8ab0e37..248edbf 100644 --- a/usr/local/lib/network.bash +++ b/usr/local/lib/network.bash @@ -759,6 +759,87 @@ network_table_set() +#-------------------------------------------------------------------------------------------------------------------------- +# network_dst_address_refresh +#-------------------------------------------------------------------------------------------------------------------------- + +network_dst_address_refresh() +{ + local dst_id="$1" + local dst_host_name="$2" + local dst_ip_old="$3" + + local dst_ip_new + local proxy_host="proxy${dst_id}.not.rx3" + local proxy_port=8080 + + + dst_ip_new=$( nc ${proxy_host} ${proxy_port}) + + if [[ "${dst_ip_old}" != "${dst_ip_new}" ]] + then + ${LOG} "Update ${dst_host_name}: Old: [${dst_ip_old}] New: [${dst_ip_new}]" + ${DEBUG} /usr/local/sbin/ip_host_update "${dst_host_name/.*}" "${dst_host_name#*.}" "${dst_ip_new}" 60 + + tab_assign NETWORK_DST_TAB "${dst_id},IP" "${dst_ip_new}" + else + ${LOG} "Skiping ${dst_host_name}: IP: [${dst_ip_old}]" + fi +} + + + + + +#-------------------------------------------------------------------------------------------------------------------------- +# network_dst_address_refresh +#-------------------------------------------------------------------------------------------------------------------------- + +network_dst_address_refresh() +{ + local dst_id="$1" + local dst_host_name="$2" + local dst_ip_old="$3" + + local dst_ip_new + local proxy_host="proxy${dst_id}.not.rx3" + local proxy_port=8080 + + + dst_ip_new=$( nc ${proxy_host} ${proxy_port}) + + if [[ "${dst_ip_old}" != "${dst_ip_new}" ]] + then + ${LOG} "Update ${dst_host_name}: Old: [${dst_ip_old}] New: [${dst_ip_new}]" + ${DEBUG} /usr/local/sbin/ip_host_update "${dst_host_name/.*}" "${dst_host_name#*.}" "${dst_ip_new}" 60 + + tab_assign NETWORK_DST_TAB "${dst_id},IP" "${dst_ip_new}" + else + ${LOG} "Skiping ${dst_host_name}: IP: [${dst_ip_old}]" + fi +} + + + + + +#-------------------------------------------------------------------------------------------------------------------------- +# network_dst_address_refresh_all +#-------------------------------------------------------------------------------------------------------------------------- + +network_dst_address_refresh_all() +{ + for dst_id in ${NETWORK_DST_ID_LIST} + do + network_dst_tab_get ${dst_id} + network_dst_address_refresh ${dst_id} ${dst_host_name} ${dst_ip} + done +} + + + + + #-------------------------------------------------------------------------------------------------------------------------- # bridge_up #-------------------------------------------------------------------------------------------------------------------------- diff --git a/usr/local/sbin/rx3_net_adm b/usr/local/sbin/rx3_net_adm index 334b131..a25a505 100755 --- a/usr/local/sbin/rx3_net_adm +++ b/usr/local/sbin/rx3_net_adm @@ -99,7 +99,7 @@ dump() #-------------------------------------------------------------------------------------------------------------------------- -# Table-Set () +# Table_Set #-------------------------------------------------------------------------------------------------------------------------- table_set() @@ -111,6 +111,32 @@ table_set() + + +#-------------------------------------------------------------------------------------------------------------------------- +# Address_Refresh +#-------------------------------------------------------------------------------------------------------------------------- + +address_refresh() +{ + dst_id="$1" + + + if [[ "${dst_id}" != "" ]] + then + echo "Refreshing address: [${dst_id}]..." + + network_dst_tab_get ${dst_id} + network_dst_address_refresh ${dst_id} ${dst_host_name} ${dst_ip} + else + echo "Refreshing all address..." + + network_dst_address_refresh_all + fi +} + + + #-------------------------------------------------------------------------------------------------------------------------- # Main #-------------------------------------------------------------------------------------------------------------------------- @@ -143,6 +169,10 @@ case "$1" in table_set) table_set $2 $3 ;; + + refresh_address) + address_refresh $2 + ;; *) echo "Usage: $0 {start|stop|restart|status|dump|table_set}" diff --git a/usr/local/sbin/vyprvpn-down b/usr/local/sbin/vyprvpn-down index cdea3ee..fb612b5 100755 --- a/usr/local/sbin/vyprvpn-down +++ b/usr/local/sbin/vyprvpn-down @@ -1,10 +1,10 @@ #!/bin/bash #DEBUG="" -DEBUG="echo" +#DEBUG="echo" #DEBUG=":" -LOG=":" +#LOG=":" #LOG="echo" diff --git a/usr/local/sbin/vyprvpn-up b/usr/local/sbin/vyprvpn-up index 43c406d..e37251f 100755 --- a/usr/local/sbin/vyprvpn-up +++ b/usr/local/sbin/vyprvpn-up @@ -1,11 +1,12 @@ #!/bin/bash #DEBUG="" -DEBUG="echo" +#DEBUG="echo" #DEBUG=":" -LOG=":" +#LOG=":" #LOG="echo" +LOG="" @@ -52,33 +53,8 @@ then ${DEBUG} ip route del table ${dst_table} default ${DEBUG} ip route add table ${dst_table} default dev ${Dev} - -# ( -# sleep 3 -# -# i=0 -# -# while [[ ${remote_address} == "" && $i -lt 5 ]] -# do -# remote_address=$(/usr/local/sbin/ns-launch 3 ${dst_table} /usr/local/bin/my_address_get 2>/dev/null) -# echo >>${log_file} "$(date): Up: ${Dev}: Remote_Address=${remote_address} try=$i" -# -# i=$(($i + 1)) -# sleep 5 -# done -# -# if [[ remote_address != "" ]] -# then -# echo >>${log_file} "$(date): Up: ${Dev}: set ${remote_address} to vpn${dst_id}.vpn.rx3" -# /usr/local/sbin/ip_host_update vpn${dst_id} vpn.rx3 ${remote_address} 60 -# else -# echo >>${log_file} "$(date): Up: ${Dev}: VPN not working?" -# fi -# -# echo >>${log_file} "$(date): Up: ${Dev}: Done!" -# ) & - echo >>${LOG_FILE} "$(date): Up: ${Dev}: Partially Done..." + echo >>${LOG_FILE} "$(date): Up: ${Dev}: Done!" else echo >>${LOG_FILE} " Status: [ERROR]!" echo >>${LOG_FILE} "$(date): Up: [${Dev}] Done"