10 changed files with 71 additions and 105 deletions
-
8abonapp/forms.py
-
4abonapp/templates/abonapp/editAbon.html
-
10abonapp/templates/abonapp/modal_abonamount.html
-
21abonapp/views.py
-
6devapp/dev_types.py
-
44devapp/models.py
-
24devapp/onu_register.py
-
55devapp/onu_register.sh
-
2devapp/views.py
-
2dialing_app/views.py
@ -0,0 +1,24 @@ |
|||||
|
#!/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 not dev.has_attachable_to_subscriber() or dev.mac_addr is None: |
||||
|
continue |
||||
|
group_code = dev.group.code |
||||
|
if not group_code: |
||||
|
continue |
||||
|
try: |
||||
|
mn = dev.get_manager_klass() |
||||
|
dev_code = mn.tech_code |
||||
|
f.write('subclass "%(group_code)s.%(dev_code)s" "%(mac)s";\n' % { |
||||
|
'group_code': group_code, |
||||
|
'mac': dev.mac_addr, |
||||
|
'dev_code': dev_code |
||||
|
}) |
||||
|
except TypeError: |
||||
|
continue |
||||
|
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