19 changed files with 168 additions and 80 deletions
-
4abonapp/templates/abonapp/editAbon.html
-
4abonapp/templates/abonapp/group_list.html
-
34abonapp/templates/abonapp/peoples.html
-
16accounts_app/templates/accounts/acc_list.html
-
13accounts_app/templates/accounts/login.html
-
4agent/commands/dhcp.py
-
20agent/mod_mikrotik.py
-
2clientsideapp/templates/clientsideapp/ext.html
-
2devapp/models.py
-
2devapp/templates/devapp/custom_dev_page/onu.html
-
44dhcp_lever.py
-
5msg_app/admin.py
-
2msg_app/locale/ru/LC_MESSAGES/django.po
-
9mydefs.py
-
69queue_mngr.py
-
2systemd_units/djing_telebot.service
-
2telebot.py
-
2templates/all_base.html
-
4templates/base.html
@ -1,25 +1,53 @@ |
|||
#!/usr/bin/env python3 |
|||
import sys |
|||
from redis import Redis |
|||
from rq import Queue |
|||
import socket |
|||
|
|||
|
|||
def die(text): |
|||
print(text) |
|||
exit(1) |
|||
|
|||
''' |
|||
obj = { |
|||
'client_ip': ip2int('127.0.0.1'), |
|||
'client_mac': 'aa:bb:cc:dd:ee:ff', |
|||
'switch_mac': 'aa:bb:cc:dd:ee:ff', |
|||
'switch_port': 3, |
|||
'cmd': 'commit' |
|||
} |
|||
''' |
|||
|
|||
|
|||
def send_to(data, addr='127.0.0.1', port=5436): |
|||
from pickle import dumps |
|||
try: |
|||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
|||
s.connect((addr, port)) |
|||
data = dumps(data) |
|||
s.send(data) |
|||
except ConnectionRefusedError: |
|||
print('ERROR: connection refused') |
|||
|
|||
|
|||
if __name__ == "__main__": |
|||
argv = sys.argv |
|||
if len(argv) < 3: |
|||
die('Too few arguments, exiting...') |
|||
action = argv[1] |
|||
q = Queue(connection=Redis()) |
|||
if action == 'commit': |
|||
if len(argv) < 6: |
|||
die('Too few arguments, exiting...') |
|||
q.enqueue('agent.commands.dhcp.dhcp_commit', argv[2], argv[3], argv[4], int(argv[5])) |
|||
elif action == 'expiry': |
|||
q.enqueue('agent.commands.dhcp.dhcp_expiry', argv[2]) |
|||
elif action == 'release': |
|||
q.enqueue('agent.commands.dhcp.dhcp_release', argv[2]) |
|||
dat = { |
|||
'client_ip': argv[2], |
|||
'client_mac': argv[3], |
|||
'switch_mac': argv[4], |
|||
'switch_port': int(argv[5]), |
|||
'cmd': 'commit' |
|||
} |
|||
send_to(dat) |
|||
elif action == 'expiry' or action == 'release': |
|||
dat = { |
|||
'client_ip': argv[2], |
|||
'cmd': action |
|||
} |
|||
send_to(dat) |
|||
@ -1,3 +1,6 @@ |
|||
from django.contrib import admin |
|||
from . import models |
|||
|
|||
admin.site.register(models.Message) |
|||
admin.site.register(models.Conversation) |
|||
|
|||
# Register your models here. |
|||
@ -1,30 +1,55 @@ |
|||
#!/usr/bin/env python3 |
|||
import os |
|||
import sys |
|||
from rq import Connection, Worker |
|||
from pickle import loads |
|||
from pid.decorator import pidfile |
|||
import socket |
|||
import django |
|||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djing.settings") |
|||
from agent import NasFailedResult, NasNetworkError |
|||
from django.core.exceptions import ValidationError |
|||
|
|||
|
|||
""" |
|||
Заустить этот скрипт как демон, он соединяет redis и django |
|||
""" |
|||
@pidfile() |
|||
def main(): |
|||
''' |
|||
obj = { |
|||
'client_ip': ip2int('127.0.0.1'), |
|||
'client_mac': 'aa:bb:cc:dd:ee:ff', |
|||
'switch_mac': 'aa:bb:cc:dd:ee:ff', |
|||
'switch_port': 3, |
|||
'cmd': 'commit' |
|||
} |
|||
''' |
|||
|
|||
|
|||
def on_new_data(client_sock, ip): |
|||
from agent.commands.dhcp import dhcp_commit, dhcp_expiry, dhcp_release |
|||
data = client_sock.recv(16384) |
|||
data = loads(data) |
|||
action = data['cmd'] |
|||
if action == 'commit': |
|||
dhcp_commit( |
|||
data['client_ip'], data['client_mac'], |
|||
data['switch_mac'], data['switch_port'] |
|||
) |
|||
elif action == 'expiry': |
|||
dhcp_expiry(data['client_ip']) |
|||
elif action == 'release': |
|||
dhcp_release(data['client_ip']) |
|||
client_sock.close() |
|||
|
|||
|
|||
@pidfile(pidname='queue_mngr.py.pid', piddir='/run') |
|||
def serve(addr='127.0.0.1', port=5436): |
|||
try: |
|||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
|||
s.bind((addr, port)) |
|||
s.listen(3) |
|||
print('ready') |
|||
while True: |
|||
conn, client_addr = s.accept() |
|||
on_new_data(conn, client_addr) |
|||
except ConnectionRefusedError: |
|||
print('ERROR: connection refused') |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djing.settings") |
|||
django.setup() |
|||
with Connection(): |
|||
qs = sys.argv[1:] or ['default'] |
|||
w = Worker(qs) |
|||
w.work() |
|||
except (NasNetworkError, NasFailedResult) as e: |
|||
print('NAS:', e) |
|||
except (ValidationError, ValueError) as e: |
|||
print('ERROR:', e) |
|||
|
|||
|
|||
if __name__ == "__main__": |
|||
main() |
|||
serve() |
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue