4 changed files with 18 additions and 79 deletions
@ -0,0 +1,14 @@ |
|||
#!/usr/bin/env python3 |
|||
from typing import Iterable |
|||
from subprocess import run |
|||
|
|||
|
|||
def onu_register(devices: Iterable): |
|||
with open('/etc/dhcp/macs.conf', 'w') as f: |
|||
for dev in devices: |
|||
if dev.has_attachable_to_subscriber(): |
|||
f.write('subclass "%(code)s" "%(mac)s";\n' % { |
|||
'code': dev.group.code, |
|||
'mac': dev.mac_addr |
|||
}) |
|||
run(('/usr/bin/sudo', 'systemctl', 'restart', 'isc-dhcp-server.service')) |
|||
@ -1,55 +0,0 @@ |
|||
#!/bin/bash |
|||
|
|||
# Action |
|||
ACT=$1 |
|||
if [[ ${ACT} == '' ]]; then |
|||
echo 'Need the action type parameter' |
|||
exit |
|||
fi |
|||
|
|||
|
|||
# old mac address |
|||
if [[ $2 =~ ^([0-9A-Fa-f]{1,2}[:-]){5}([0-9A-Fa-f]{1,2})$ ]]; then |
|||
MAC=$2 |
|||
else |
|||
echo "Bad mac $MAC addr" |
|||
exit |
|||
fi |
|||
|
|||
|
|||
# part code |
|||
if [[ $3 =~ ^[a-zA-Z]+$ ]]; then |
|||
PART_CODE=$3 |
|||
else |
|||
echo 'code must contains only letters' |
|||
exit |
|||
fi |
|||
|
|||
|
|||
DHCP_MACS='/etc/dhcp/macs.conf' |
|||
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin |
|||
|
|||
|
|||
# if just remove device |
|||
if [[ ${ACT} == 'del' ]]; then |
|||
sed -i "/${MAC}/d" ${DHCP_MACS} |
|||
exit |
|||
fi |
|||
|
|||
|
|||
# If exist mac with code |
|||
if grep "^subclass\ \"${PART_CODE}\" \"${MAC}\";$" "${DHCP_MACS}" > /dev/null; then |
|||
# mac is already exists, quit |
|||
exit |
|||
else |
|||
|
|||
# If mac existing in another group |
|||
if grep "${MAC}" ${DHCP_MACS} > /dev/null; then |
|||
# remove it |
|||
sed -i "/${MAC}/d" ${DHCP_MACS} |
|||
fi |
|||
|
|||
# add new mac |
|||
echo "subclass \"${PART_CODE}\" \"${MAC}\";" >> ${DHCP_MACS} |
|||
sudo systemctl restart isc-dhcp-server.service |
|||
fi |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue