diff --git a/usr/local/lib/network.bash b/usr/local/lib/network.bash index b7d0329..49dfa81 100644 --- a/usr/local/lib/network.bash +++ b/usr/local/lib/network.bash @@ -263,6 +263,7 @@ network_ip_route_tab_dump() network_dst_tab_load() { ndtl_id=0 + vpn_id=0 log_trace "Network" "Loading Dst tab..." @@ -289,45 +290,57 @@ network_dst_tab_load() tab_assign NETWORK_DST_TAB "${ndtl_id},Table" "${ndtl_table}" var_assign NETWORK_TABLE_LIST "${ndtl_table}" INC - - tab_assign NETWORK_DST_TAB "${ndtl_id},Status" "$( ip link show dev ${ndtl_device} 2>/dev/null | grep -q ",UP," && echo 1 || echo 0)" - ndtl_host_name="vpn${ndtl_id}.${NETWORK_DST_NAME}" + + ndtl_status="$( ip link show dev ${ndtl_device} 2>/dev/null | grep -q ",UP," && echo "1" || echo "0")" + + tab_assign NETWORK_DST_TAB "${ndtl_id},Status" "${ndtl_status}" + + + if [[ "${ndtl_type}" == "1" ]] + then + ndtl_host_name="" + dns_value="" + else + ndtl_host_name="vpn${vpn_id}.${NETWORK_DST_NAME}" + dns_lookup "A" "${ndtl_host_name}" "NOCACHE" + vpn_id=$((${vpn_id} + 1)) + fi tab_assign NETWORK_DST_TAB "${ndtl_id},Host_Name" "${ndtl_host_name}" - dns_lookup "A" "${ndtl_host_name}" "NOCACHE" tab_assign NETWORK_DST_TAB "${ndtl_id},IP" "${dns_value}" case "${ndtl_type}" in - "0") - set $(ip -s link show ${ndtl_device} 2>/dev/null ) &>/dev/null - - ndtl_bytes_received="$( echo ${27} | numfmt --to=iec-i --suffix=B)" - ndtl_bytes_sent="$( echo ${40} | numfmt --to=iec-i --suffix=B)" - ndtl_uptime="" - ;; - - "1") - set $( echo "${NETWORK_OPENVPN_STATUS}" | grep ${ndtl_device}) &>/dev/null + "0"|"1") + ndtl_bytes_received="$( cat /sys/class/net/${ndtl_device}/statistics/rx_bytes 2>/dev/null | numfmt --to=iec-i --suffix=B)" + ndtl_bytes_sent="$( cat /sys/class/net/${ndtl_device}/statistics/tx_bytes 2>/dev/null | numfmt --to=iec-i --suffix=B)" + ;; + + "2") + set $( echo "${NETWORK_OPENVPN_STATUS}" | grep ${ndtl_device}'\.') &>/dev/null # i=1; while [[ $i -lt 50 ]]; do eval "val=\${$i}"; echo "($i):[${val}]" 1>&2; i=$(( $i + 1)); done ndtl_bytes_received="$( echo ${18/bytes,} | numfmt --to=iec-i --suffix=B)" ndtl_bytes_sent="$( echo ${22/bytes,} | numfmt --to=iec-i --suffix=B)" - ndtl_start_date="$( grep "ext-client-${ndtl_device}.conf" /var/log/rx3-vpn.status 2>/dev/null | sed -e "s/.*Date: \[//" -e "s/\].*//")" - - if [[ "${ndtl_start_date}" == "" ]] - then - ndtl_uptime="" - else - ndtl_uptime=$( echo "$(($(date +%s) - $(date -d "${ndtl_start_date}" +%s)))" | awk '{days = int($1/86400); print days " day" (( days > 1 ) ? "s" : "") strftime(" %H:%M:%S", $1,1)}') - fi ;; esac + + 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)}')" + else + ndtl_start_date="" + ndtl_uptime="" + fi + tab_assign NETWORK_DST_TAB "${ndtl_id},Bytes_Received" "${ndtl_bytes_received}" tab_assign NETWORK_DST_TAB "${ndtl_id},Bytes_Sent" "${ndtl_bytes_sent}" + tab_assign NETWORK_DST_TAB "${ndtl_id},Start_Date" "${ndtl_start_date}" tab_assign NETWORK_DST_TAB "${ndtl_id},Uptime" "${ndtl_uptime}" tab_assign NETWORK_DST_NAME_IDX "${ndtl_name}" "${ndtl_id}" diff --git a/usr/local/lib/vpn.bash b/usr/local/lib/vpn.bash index 84deab2..1d4135e 100644 --- a/usr/local/lib/vpn.bash +++ b/usr/local/lib/vpn.bash @@ -200,7 +200,7 @@ vpn_job_tab_init() do network_dst_tab_get ${dst_id} - if [[ "${dst_type}" == "1" ]] && [[ "${dst_config}" != "" ]] + if [[ "${dst_type}" == "2" ]] && [[ "${dst_config}" != "" ]] then config_file="${VPN_CONFIG_FILE/DEVICE/${dst_device}}" diff --git a/var/www/cgi-bin/vpn-admin_board.cgi b/var/www/cgi-bin/vpn-admin_board.cgi old mode 100755 new mode 100644 index a58add7..d6c3935 --- a/var/www/cgi-bin/vpn-admin_board.cgi +++ b/var/www/cgi-bin/vpn-admin_board.cgi @@ -109,10 +109,10 @@ Destination_Status_Board() echo "

Destination Status Board

" echo "" echo " " - echo " " + echo " " else echo "TABLE: Destination_Status_Board" - echo "#;Name;Type;Device;IP;Host Name;Config;Table;Status;Bytes In;Bytes Out;UpTime" + echo "#;Name;Type;Device;Status;IP;Host Name;Config;Table;Bytes In;Bytes Out;UpTime" fi @@ -127,18 +127,18 @@ Destination_Status_Board() if [[ "${format}" == "html" ]] then - echo -n "" if [[ "${dst_status}" == 1 ]] then - echo -n "\"Up\"" + echo -n "" else - echo -n "\"Down\"" + echo -n "" fi - echo "" + echo "" else - echo "${dst_id};${dst_name};${NETWORK_DST_TYPE[${dst_type}]};${dst_device};${dst_ip};${dst_host_name};${dst_config};${dst_table};${dst_status};${dst_bytes_received};${dst_bytes_sent};${dst_uptime}" + 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 done @@ -219,32 +219,35 @@ Source_Routing_Board_Line() do network_dst_tab_get ${dst_id} - if [[ "${format}" == "html" ]] + if [[ ( "${admin}" == "true") || ( "${dst_type}" != 1) ]] then - echo -n "" else - echo -n "0;" + + if [[ "${dst_table}" == "${src_table}" ]] + then + echo -n "1;" + else + echo -n "0;" + fi fi fi done @@ -293,12 +296,15 @@ Source_Routing_Board() for dst_id in ${NETWORK_DST_ID_LIST} do network_dst_tab_get ${dst_id} - - if [[ "${format}" == "html" ]] + + if [[ ( "${admin}" == "true") || ( "${dst_type}" != 1) ]] then - echo -n "" - else - echo -n "${dst_name};" + if [[ "${format}" == "html" ]] + then + echo -n "" + else + echo -n "${dst_name};" + fi fi done @@ -684,10 +690,10 @@ else network_src_tab_ip_lookup "${ip}" network_src_tab_get "${src_id}" - if [[ ( ${admin} == "true") || ( "${REMOTE_USER}" == "${src_owner}") ]] + network_dst_tab_get "${vpn}" + + if [[ ( ${admin} == "true") || ( ( "${REMOTE_USER}" == "${src_owner}") && ( "${dst_type}" != 1)) ]] then - network_dst_tab_get "${vpn}" - sudo /usr/local/sbin/rx3_net_adm table_set ${ip} ${dst_table} 1>&2 if [[ "$?" == 0 ]] @@ -697,7 +703,7 @@ else cmd_status="route_set: KO" fi else - cmd_status="route_set: NOT_AUTHORIZED [${REMOTE_USER}]/[${src_owner}]" + cmd_status="route_set: NOT_AUTHORIZED [${REMOTE_USER}]/[${src_owner}]/[${dst_type}]" fi redirect="?admin=${admin}&filter=${filter}"
#NameTypeDeviceIPHost NameConfigTableStatusBytes InBytes OutUpTime
#NameTypeDeviceStatusIPHost NameConfigTableBytes InBytes OutUpTime
${dst_id}${dst_name}${NETWORK_DST_TYPE[${dst_type}]}${dst_device}${dst_ip}${dst_host_name}${dst_config:--}${dst_table}" + echo -n "
${dst_id}${dst_name}${NETWORK_DST_TYPE[${dst_type}]}${dst_device}\"Up\"\"Down\"${dst_bytes_received:--}${dst_bytes_sent:--}${dst_uptime:--}${dst_ip:--}${dst_host_name:--}${dst_config:--}${dst_table}${dst_bytes_received:--}${dst_bytes_sent:--}${dst_uptime:--}" - else - - if [[ "${dst_table}" == "${src_table}" ]] - then - echo -n "1;" + echo -n "
" - - if [[ "${dst_table}" == "${src_table}" ]] + if [[ "${format}" == "html" ]] then - echo -n "\"Up\" " - else - echo -n "\"Down\"" - - if [[ ( ${admin} == "true") || ( "${REMOTE_USER}" == "${src_owner}") ]] + echo -n "
" + + if [[ "${dst_table}" == "${src_table}" ]] then - echo -n "\"Activate\"" + echo -n "\"Up\" " else - echo -n " " + echo -n "\"Down\"" + + if [[ ( ${admin} == "true") || ( "${REMOTE_USER}" == "${src_owner}") ]] + then + echo -n "\"Activate\"" + else + echo -n " " + fi fi - fi - echo -n "
${dst_name}${dst_name}