diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 365ae63..f6dacc9 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,3 +1,12 @@ +------------------------------------------------------------------------------------------------------------------------------------ +Network Tools V 1.1.3 - A. GIBERT - 2025/09/19 +------------------------------------------------------------------------------------------------------------------------------------ + +- Fix uptime for gateway destinations, +- Add status filtering in the VPN Admin page. + + + ------------------------------------------------------------------------------------------------------------------------------------ Network Tools V 1.1.2 - A. GIBERT - 2025/09/12 ------------------------------------------------------------------------------------------------------------------------------------ diff --git a/usr/local/lib/network.bash b/usr/local/lib/network.bash index 144f76b..ecfaed2 100644 --- a/usr/local/lib/network.bash +++ b/usr/local/lib/network.bash @@ -406,9 +406,14 @@ network_dst_tab_load() if [[ "${ndtl_status}" == "1" ]] then - - ndtl_start_date="$( stat -c %Z /sys/class/net/${ndtl_device})" - ndtl_uptime="$( echo $(( $(date +%s) - ${ndtl_start_date})) | awk '{days = int($1/86400); print days " day" (( days > 1 ) ? "s" : "") strftime(" %H:%M:%S", $1,1)}')" + if [[ "${ndtl_type}" == "1" ]] + then + ndtl_start_date="${ovpn_stat_connected_date}" + ndtl_uptime="$( echo $(( $(date +%s) - ${ovpn_stat_connected_time_t})) | awk '{days = int($1/86400); print days " day" (( days > 1 ) ? "s" : "") strftime(" %H:%M:%S", $1,1)}')" + else + ndtl_start_date="$( stat -c %Z /sys/class/net/${ndtl_device})" + ndtl_uptime="$( echo $(( $(date +%s) - ${ndtl_start_date})) | awk '{days = int($1/86400); print days " day" (( days > 1 ) ? "s" : "") strftime(" %H:%M:%S", $1,1)}')" + fi else ndtl_start_date="" ndtl_uptime="" diff --git a/var/www/cgi-bin/vpn-admin_board.cgi b/var/www/cgi-bin/vpn-admin_board.cgi index e520b03..ec55143 100755 --- a/var/www/cgi-bin/vpn-admin_board.cgi +++ b/var/www/cgi-bin/vpn-admin_board.cgi @@ -125,33 +125,35 @@ Destination_Status_Board() dst_ip="-" fi - if [[ "${format}" == "html" ]] + if [[ ( "${status}" == "" ) || ( "${status}" == "${dst_status}") ]] then - echo -n "${dst_id}${dst_name}${NETWORK_DST_TYPE[${dst_type}]}${dst_device}" + if [[ "${format}" == "html" ]] + then + echo -n "${dst_id}${dst_name}${NETWORK_DST_TYPE[${dst_type}]}${dst_device}" - case "${dst_status}" - in - "0") - echo -n "\"Down\"" - ;; + case "${dst_status}" + in + "0") + echo -n "\"Down\"" + ;; - "1") - echo -n "\"Up\"" - ;; + "1") + echo -n "\"Up\"" + ;; - "2") - echo -n "\"Unready\"" - ;; + "2") + echo -n "\"Unready\"" + ;; - *) - echo -n "\"Unknown\"" - ;; - esac - + *) + echo -n "\"Unknown\"" + ;; + esac - echo "${dst_ip:--}${dst_host_name:--}${dst_config:--}${dst_table}${dst_bytes_received:--}${dst_bytes_sent:--}${dst_uptime:--}" - else - echo "${dst_id};${dst_name};${NETWORK_DST_TYPE[${dst_type}]};${dst_device};${dst_status};${dst_ip};${dst_host_name};${dst_config};${dst_table};${dst_bytes_received};${dst_bytes_sent};${dst_uptime}" + echo "${dst_ip:--}${dst_host_name:--}${dst_config:--}${dst_table}${dst_bytes_received:--}${dst_bytes_sent:--}${dst_uptime:--}" + else + echo "${dst_id};${dst_name};${NETWORK_DST_TYPE[${dst_type}]};${dst_device};${dst_status};${dst_ip};${dst_host_name};${dst_config};${dst_table};${dst_bytes_received};${dst_bytes_sent};${dst_uptime}" + fi fi done @@ -179,13 +181,13 @@ Source_Routing_Board_Line() network_src_tab_get ${src_id} - if [[ ( "${filter}" == "") || ( "${filter}" == "owner") || ( "${filter}" == "${src_owner}") ]] + if [[ ( "${user}" == "") || ( "${user}" == "owner") || ( "${user}" == "${src_owner}") ]] then if [[ ( "${admin}" == "true") || ( "${REMOTE_USER}" == "${src_owner}") ]] then class="default" else - if [[ "${filter}" == "owner" ]] + if [[ "${user}" == "owner" ]] then class="skip" else @@ -193,10 +195,15 @@ Source_Routing_Board_Line() fi fi else - # filter == user not owner of this line + # user == user not owner of this line class="skip" fi + + if [[ ( "${status}" != "") && ( "${status}" != "${src_status}") ]] + then + class="skip" + fi if [[ "${class}" != "skip" ]] @@ -212,19 +219,19 @@ Source_Routing_Board_Line() case "${src_status}" in "0") - echo -n "\"Down\"" + echo -n "\"Down\"" ;; "1") - echo -n "\"Up\"" + echo -n "\"Up\"" ;; "2") - echo -n "-" + echo -n "-" ;; esac else - echo -n "${src_id};${NETWORK_SRC_TYPE[${src_type}]};${src_ip};${src_host_name};${src_device};${status};" + echo -n "${src_id};${NETWORK_SRC_TYPE[${src_type}]};${src_ip};${src_host_name};${src_device};${src_status};" fi @@ -246,7 +253,7 @@ Source_Routing_Board_Line() if [[ ( ${admin} == "true") || ( "${REMOTE_USER}" == "${src_owner}") ]] then - echo -n "\"Activate\"" + echo -n "\"Activate\"" else echo -n " " fi @@ -274,7 +281,7 @@ Source_Routing_Board_Line() echo -n "${src_port_range}--" fi - echo "${src_owner}${src_bytes_received:--}${src_bytes_sent:--}${src_uptime:--}${src_last_seen:--}" + echo "${src_owner}${src_bytes_received:--}${src_bytes_sent:--}${src_uptime:--}${src_last_seen:--}" else echo "${src_port_range};${src_port_start};${src_port_end};${src_owner};${src_bytes_received};${src_bytes_sent};${src_uptime};${src_last_seen}" fi @@ -378,13 +385,13 @@ VPN_OpenVPN_Board() if [[ "${src_type}" == 2 ]] then - if [[ ( "${filter}" == "") || ( "${filter}" == "owner") || ( "${filter}" == "${src_owner}") ]] + if [[ ( "${user}" == "") || ( "${user}" == "owner") || ( "${user}" == "${src_owner}") ]] then if [[ ( "${admin}" == "true") || ( "${REMOTE_USER}" == "${src_owner}") ]] then class="default" else - if [[ "${filter}" == "owner" ]] + if [[ "${user}" == "owner" ]] then class="skip" else @@ -392,30 +399,36 @@ VPN_OpenVPN_Board() fi fi else - # filter == user not owner of this line + # user == user not owner of this line class="skip" fi + if [[ ( "${status}" != "") && ( "${status}" != "${src_status}") ]] + then + class="skip" + fi + + if [[ "${class}" != "skip" ]] then if [[ "${format}" == "html" ]] then echo -n " ${idx}${src_ip}${src_host_name}" - echo -n "\"Configuration" + echo -n "\"Configuration" if [[ ( "${admin}" == "true") || ( "${REMOTE_USER}" == "${src_owner}") ]] then - echo -n "\"Configuration" + echo -n "\"Configuration" else echo -n "\"Configuration" fi - echo -n "\"Configuration" + echo -n "\"Configuration" if [[ ( "${admin}" == "true") || ( "${REMOTE_USER}" == "${src_owner}") ]] then - echo -n "\"Configuration" + echo -n "\"Configuration" else echo -n "\"Configuration" fi @@ -425,17 +438,17 @@ VPN_OpenVPN_Board() if [[ "${format}" == "html" ]] then - echo -n "\"CA" + echo -n "\"CA" if [[ ( "${admin}" == "true") || ( "${REMOTE_USER}" == "${src_owner}") ]] then - echo -n "\"TC" + echo -n "\"TC" if [[ -f /etc/openvpn/tls/certs/${src_host_name}.crt ]] then - echo -n "\"Private" - echo -n "\"Certificat" - echo "\"Public" + echo -n "\"Private" + echo -n "\"Certificat" + echo "\"Public" else echo -n "\"Private" echo -n "\"Certificat" @@ -497,22 +510,46 @@ Main_Board_Print() admin_mode="" fi - case "${filter}" + case "${user}" in - "owner") - filter_mode="My VPN" + "") + user_mode="All" ;; - "") - filter_mode="All VPN" + "owner") + user_mode="My" ;; *) - filter_mode="${filter} VPN" + user_mode="${user}" ;; esac - echo "

VPN Admin Board: ${filter_mode}${admin_mode}

" + case "${status}" + in + "") + status_mode="All" + ;; + + "0") + status_mode="Down" + ;; + + "1") + status_mode="UP" + ;; + + "2") + status_mode="Not Conected" + ;; + + *) + status_mode="Unkwown" + ;; + esac + + + echo "

VPN Admin Board: ${user_mode} VPN - ${status_mode} Status${admin_mode}

" echo "

" @@ -539,19 +576,25 @@ Main_Board_Print() then if [[ "${admin}" == "true" ]] then - echo -n "Non Admin Mode" + echo -n "Non Admin Mode" else - echo -n "Admin Mode" + echo -n "Admin Mode" fi echo -n "   " fi - if [[ "${filter}" != "" ]] + if [[ "${user}" != "" ]] then - echo -n "All VPN" + echo -n "All VPN" + echo -n "   " fi + if [[ "${status}" != "" ]] + then + echo -n "All Status" + fi + echo "" echo "

" @@ -598,7 +641,8 @@ Main_Board_Print() cmd="" format="" -filter="" +user="" +status="" ip="" vpn="" type="" @@ -638,6 +682,14 @@ then filter=${arg} ;; + "user") + user=${arg} + ;; + + "status") + status=${arg} + ;; + "ip") ip=${arg} ;; @@ -685,7 +737,7 @@ if [[ ( ${admin} == "true") && ( " ${ADMIN_USER_LIST} " != *" ${REMOTE_USER} "*) then cmd_status="${cmd}: Admin NOT_AUTHORIZED" - redirect="?filter=${filter}" + redirect="?user=${user}&up=${up}" Header_Print Footer_Print