Skip to content

Commit 3919adc

Browse files
committed
gateway-check for OPNsense, fixes opnsense/core#8417
1 parent ac08234 commit 3919adc

6 files changed

+400
-0
lines changed

opnsense/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Update Gateway
2+
3+
This script is used in OPNsense to update the WAN gateway if the current
4+
gateway is not reachable.
5+
6+
Copy the script for example to `/root/gateway-check.php` and create `/root/gateway-check.ini` with:
7+
8+
```
9+
; Gateway Check Configuration
10+
[general]
11+
; UUID for gateway configuration
12+
uuid = 00000000-0000-0000-0000-000000000000
13+
; Interface name
14+
interface = wan
15+
; Gateway IPs to check (in order of priority)
16+
gateway_ips = X.X.X.X, Y.Y.Y.Y, Z.Z.Z.Z
17+
; Ping timeout in seconds
18+
ping_timeout = 1
19+
; Number of ping attempts
20+
ping_count = 3
21+
22+
[logging]
23+
; Enable detailed logging
24+
debug = false
25+
; Log file location
26+
log_file = /var/log/gateway-check.log
27+
; Rotate logs after they reach this size (in bytes), 0 to disable
28+
log_rotate_size = 1048576
29+
; Number of rotated log files to keep
30+
log_rotate_count = 5
31+
```
32+
33+
To get the UUID for the gateway configuration, you can use the API:
34+
35+
```
36+
curl -u "user":"pass" -k -s https://<opnsense/api/routing/settings/get | jq
37+
```
38+
39+
> jq is only needed if you want to pretty print the JSON output.

opnsense/actions.d/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Check https://docs.opnsense.org/development/backend/configd.html
2+
3+
Copy the files:
4+
- actions_gateway-check.conf
5+
- actions_gateway-check-sleep.conf
6+
7+
Into `/usr/local/opnsense/service/conf/actions.d/`
8+
9+
Then restart configd with:
10+
11+
```
12+
service configd restart
13+
```
14+
15+
Create 2 entries in the cron via OPNsense UI: (settings -> cron):
16+
17+
![cron](cron.png)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[reload]
2+
command:/usr/local/bin/flock -n -E 0 -o /tmp/gateway_check.lock sleep 30; /usr/local/bin/php /root/gateway-check.php
3+
parameter:
4+
type:script
5+
Message:Check WAN gateway and update if required
6+
description:Check WAN gateway (sleep 30)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[reload]
2+
command:/usr/local/bin/flock -n -E 0 -o /tmp/gateway_check.lock /usr/local/bin/php /root/gateway-check.php
3+
parameter:
4+
type:script
5+
Message:Check WAN gateway and update if required
6+
description:Check WAN gateway

opnsense/actions.d/cron.png

34.6 KB
Loading

0 commit comments

Comments
 (0)