Advertisement
gpz1100

Untitled

Feb 25th, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. cat rc.gateway_alarm
  2. #!/bin/sh
  3. #
  4. # rc.gateway_alarm
  5. #
  6. # Copyright (c) 2015-2016 Electric Sheep Fencing
  7. # Copyright (c) 2015-2024 Rubicon Communications, LLC (Netgate)
  8. # All rights reserved.
  9. #
  10. # Licensed under the Apache License, Version 2.0 (the "License");
  11. # you may not use this file except in compliance with the License.
  12. # You may obtain a copy of the License at
  13. #
  14. # http://www.apache.org/licenses/LICENSE-2.0
  15. #
  16. # Unless required by applicable law or agreed to in writing, software
  17. # distributed under the License is distributed on an "AS IS" BASIS,
  18. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. # See the License for the specific language governing permissions and
  20. # limitations under the License.
  21.  
  22. GW="$1"
  23. alarm_addr="$2"
  24. alarm_flag="$3"
  25. alarm_rtt="$4"
  26. alarm_rttsd="$5"
  27. alarm_loss="$6"
  28.  
  29. if [ -z "$GW" ]; then
  30. exit 1
  31. fi
  32.  
  33. print_rtt() {
  34. usec=$1
  35. usec_to_ms=$( echo "scale=3; ${usec}/1000" | bc -l )
  36. echo "${usec_to_ms}ms"
  37. }
  38.  
  39. echo ">>> Gateway alarm: ${GW} (Addr:${alarm_addr} Alarm:${alarm_flag} RTT:$( print_rtt ${alarm_rtt} ) RTTsd:$( print_rtt ${alarm_rttsd} ) Loss:${alarm_loss}%)" | /usr/bin/logger -p daemon.info -i -t rc.gateway_alarm
  40.  
  41. /usr/local/sbin/pfSctl \
  42. -c "service reload dyndns ${GW}" \
  43. -c "service reload ipsec ${GW}" \
  44. -c "service reload openvpn ${GW}" \
  45. -c "filter reload" >/dev/null 2>&1
  46.  
  47. # after above signal the check_reload_status process calls the following scripts simultaneously.:
  48. # - "/etc/rc.dyndns.update", "dyndns=%s"
  49. # - "/etc/rc.ipsec", "interface=%s"
  50. # - "/etc/rc.openvpn", "interface=%s"
  51. # - "/etc/rc.filter_configure_sync"
  52.  
  53.  
  54. #ip used to verify internet connectivity
  55. testip="8.8.8.8"
  56.  
  57. #obtained wan interface
  58.  
  59. WAN_INTERFACE_RENEW=$(cat /var/etc/dhclient_wan.conf | head -n 1 | cut -f 2 -d '"' -s)
  60. #GW="WAN_DHCP"
  61.  
  62. if [ $GW = "WAN_DHCP" ] && ! ping -c 2 -W 1000 $testip >/dev/null 2>&1 ; then
  63. logger -s -t "ATT14DAY" "Forced dhcp renew due to 14 day outage" >/dev/null 2>&1
  64. # sleep 10
  65. /sbin/dhclient -c /var/etc/dhclient_wan.conf $WAN_INTERFACE_RENEW
  66. sleep 2
  67. logger -s -t "ATT14DAY" "$WAN_INTERFACE_RENEW Interface DHCP renewal complete" >/dev/null 2>&1
  68. else
  69. exit $?
  70. fi
  71.  
  72. exit $?
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement