|
Bogdan Timofte
authored
3 days ago
|
1
|
# MikroTik RouterOS DHCP lease push hook for Madagascar Local Authority.
|
|
|
2
|
#
|
|
|
3
|
# Edit hostManagerDhcpPushToken before import. If the DHCP server already has a
|
|
|
4
|
# lease-script, merge this source manually instead of overwriting it.
|
|
|
5
|
|
|
|
6
|
:global hostManagerDhcpPushUrl "https://hosts.madagascar.xdev.ro/api/collect/dhcp-leases";
|
|
|
7
|
:global hostManagerDhcpPushToken "CHANGE_ME_DHCP_PUSH_TOKEN";
|
|
|
8
|
|
|
|
9
|
/ip dhcp-server set [find] lease-script={
|
|
|
10
|
:global hostManagerDhcpPushUrl;
|
|
|
11
|
:global hostManagerDhcpPushToken;
|
|
|
12
|
|
|
|
13
|
:local leaseName $"lease-hostname";
|
|
|
14
|
:local leaseState "unbound";
|
|
|
15
|
:if ($leaseBound = 1) do={
|
|
|
16
|
:set leaseState "bound";
|
|
|
17
|
}
|
|
|
18
|
|
|
|
19
|
:local payload ("worker_id=dhcp-router&ip_address=" . $leaseActIP . "&mac_address=" . $leaseActMAC . "&observed_name=" . $leaseName . "&lease_state=" . $leaseState . "&bound=" . $leaseBound);
|
|
|
20
|
/tool fetch url=$hostManagerDhcpPushUrl \
|
|
|
21
|
http-method=post \
|
|
|
22
|
http-header-field=("Content-Type:application/x-www-form-urlencoded,X-DHCP-Push-Token:" . $hostManagerDhcpPushToken) \
|
|
|
23
|
http-data=$payload \
|
|
|
24
|
http-percent-encoding=yes \
|
|
|
25
|
check-certificate=no \
|
|
|
26
|
keep-result=no;
|
|
|
27
|
}
|