2019-01-18 12:50:53 +00:00
|
|
|
from django.dispatch import Signal
|
2019-01-19 09:51:17 +00:00
|
|
|
from .models import Device, Wifi, DeviceLog, UserLog, WifiLog
|
|
|
|
from django.contrib.auth.models import User
|
2019-01-18 12:50:53 +00:00
|
|
|
|
2019-04-21 08:52:07 +00:00
|
|
|
siglog = Signal(
|
|
|
|
providing_args=[
|
|
|
|
"id",
|
|
|
|
"user",
|
|
|
|
"action",
|
|
|
|
"oldvalue",
|
|
|
|
"newvalue"]
|
|
|
|
)
|
|
|
|
|
2019-01-18 12:50:53 +00:00
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
# Device Signals
|
|
|
|
|
2019-04-21 08:52:07 +00:00
|
|
|
|
2019-01-18 12:50:53 +00:00
|
|
|
def sigDevice(device_id, user, action, oldvalue=None, newvalue=None):
|
2019-04-21 08:52:07 +00:00
|
|
|
siglog.send(
|
|
|
|
sender=Device,
|
|
|
|
id=device_id,
|
|
|
|
user=user,
|
|
|
|
action=action,
|
|
|
|
oldvalue=oldvalue,
|
|
|
|
newvalue=newvalue
|
|
|
|
)
|
|
|
|
|
2019-01-18 12:50:53 +00:00
|
|
|
|
|
|
|
def sigDeleteDevice(device_id, user):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigDevice(
|
|
|
|
device_id,
|
|
|
|
user,
|
|
|
|
DeviceLog.REMOVE
|
|
|
|
)
|
|
|
|
|
2019-01-18 12:50:53 +00:00
|
|
|
|
|
|
|
def sigAddDevice(device_id, user):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigDevice(
|
|
|
|
device_id,
|
|
|
|
user,
|
|
|
|
DeviceLog.ADD
|
|
|
|
)
|
|
|
|
|
2019-01-18 12:50:53 +00:00
|
|
|
|
|
|
|
def sigRenameDevice(device_id, user, oldname, newname):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigDevice(
|
|
|
|
device_id,
|
|
|
|
user,
|
|
|
|
DeviceLog.NAME,
|
|
|
|
oldname,
|
|
|
|
newname
|
|
|
|
)
|
|
|
|
|
2019-01-18 12:50:53 +00:00
|
|
|
|
|
|
|
def sigNetDevice(device_id, user, oldnet, newnet):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigDevice(
|
|
|
|
device_id,
|
|
|
|
user,
|
|
|
|
DeviceLog.NET,
|
|
|
|
oldnet,
|
|
|
|
newnet
|
|
|
|
)
|
|
|
|
|
2019-01-18 12:50:53 +00:00
|
|
|
|
|
|
|
def sigWifiDevice(device_id, user, oldwifis, newwifis):
|
|
|
|
for old in oldwifis:
|
|
|
|
if old not in newwifis:
|
2019-04-21 08:52:07 +00:00
|
|
|
sigDevice(
|
|
|
|
device_id,
|
|
|
|
user,
|
|
|
|
DeviceLog.WIFI,
|
|
|
|
str(old)
|
|
|
|
)
|
|
|
|
|
2019-01-18 12:50:53 +00:00
|
|
|
for new in newwifis:
|
|
|
|
if new not in oldwifis:
|
2019-04-21 08:52:07 +00:00
|
|
|
sigDevice(
|
|
|
|
device_id,
|
|
|
|
user,
|
|
|
|
DeviceLog.WIFI,
|
|
|
|
None,
|
|
|
|
str(new)
|
|
|
|
)
|
|
|
|
|
2019-01-18 12:50:53 +00:00
|
|
|
|
|
|
|
def sigRebootDevice(device_id, user, newstate):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigDevice(
|
|
|
|
device_id,
|
|
|
|
user,
|
|
|
|
DeviceLog.REBOOT,
|
|
|
|
str(not newstate),
|
|
|
|
str(newstate)
|
|
|
|
)
|
|
|
|
|
2019-01-18 12:50:53 +00:00
|
|
|
|
|
|
|
def sigUpdateDevice(device_id, user, newstate):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigDevice(
|
|
|
|
device_id,
|
|
|
|
user,
|
|
|
|
DeviceLog.UPDATE,
|
|
|
|
str(not newstate),
|
|
|
|
str(newstate)
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigOrgaDevice(device_id, user, oldorga, neworga):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigDevice(
|
|
|
|
device_id,
|
|
|
|
user,
|
|
|
|
DeviceLog.ORGA,
|
|
|
|
oldorga,
|
|
|
|
neworga
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
# User Signals
|
|
|
|
|
2019-04-21 08:52:07 +00:00
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
def sigUser(target, source, action, oldvalue=None, newvalue=None):
|
2019-04-21 08:52:07 +00:00
|
|
|
siglog.send(
|
|
|
|
sender=User,
|
|
|
|
id=target,
|
|
|
|
user=source,
|
|
|
|
action=action,
|
|
|
|
oldvalue=oldvalue,
|
|
|
|
newvalue=newvalue
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigAddUser(newuser, source):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigUser(
|
|
|
|
newuser,
|
|
|
|
source,
|
|
|
|
UserLog.ADD
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigDeleteUser(target, source):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigUser(
|
|
|
|
target,
|
|
|
|
source,
|
|
|
|
UserLog.REMOVE
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigRenameUser(target, source, oldname, newname):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigUser(
|
|
|
|
target,
|
|
|
|
source,
|
|
|
|
UserLog.NAME,
|
|
|
|
oldname,
|
|
|
|
newname
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigMailUser(target, source, oldmail, newmail):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigUser(
|
|
|
|
target,
|
|
|
|
source,
|
|
|
|
UserLog.MAIL,
|
|
|
|
oldmail,
|
|
|
|
newmail
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigStaffUser(target, source, newstatus):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigUser(
|
|
|
|
target,
|
|
|
|
source,
|
|
|
|
UserLog.STAFF,
|
|
|
|
str(not newstatus),
|
|
|
|
str(newstatus)
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigSuperUser(target, source, newstatus):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigUser(
|
|
|
|
target,
|
|
|
|
source,
|
|
|
|
UserLog.SUPERUSER,
|
|
|
|
str(not newstatus),
|
|
|
|
str(newstatus)
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigOrgaUser(target, source, oldorga, neworga):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigUser(
|
|
|
|
target,
|
|
|
|
source,
|
|
|
|
UserLog.ORGA,
|
|
|
|
", ".join(str(x) for x in oldorga),
|
|
|
|
", ".join(str(x) for x in neworga)
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
# WiFi Signals
|
|
|
|
|
2019-04-21 08:52:07 +00:00
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
def sigWifi(wifi, user, action, oldvalue=None, newvalue=None):
|
2019-04-21 08:52:07 +00:00
|
|
|
siglog.send(
|
|
|
|
sender=Wifi,
|
|
|
|
id=wifi,
|
|
|
|
user=user,
|
|
|
|
action=action,
|
|
|
|
oldvalue=oldvalue,
|
|
|
|
newvalue=newvalue
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigAddWifi(wifi, user):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigWifi(
|
|
|
|
wifi,
|
|
|
|
user,
|
|
|
|
WifiLog.ADD
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigDeleteWifi(wifi, user):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigWifi(
|
|
|
|
wifi,
|
|
|
|
user,
|
|
|
|
WifiLog.REMOVE
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigRenameWifi(wifi, user, oldname, newname):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigWifi(
|
|
|
|
wifi,
|
|
|
|
user,
|
|
|
|
WifiLog.NAME,
|
|
|
|
oldname,
|
|
|
|
newname
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigSSIDWifi(wifi, user, oldssid, newssid):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigWifi(
|
|
|
|
wifi,
|
|
|
|
user,
|
|
|
|
WifiLog.SSID,
|
|
|
|
oldssid,
|
|
|
|
newssid
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigKeyWifi(wifi, user, oldkey, newkey):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigWifi(
|
|
|
|
wifi,
|
|
|
|
user,
|
|
|
|
WifiLog.KEY,
|
|
|
|
oldkey,
|
|
|
|
newkey
|
|
|
|
)
|
|
|
|
|
2019-01-19 09:51:17 +00:00
|
|
|
|
|
|
|
def sigOrgaWifi(wifi, user, oldorga, neworga):
|
2019-04-21 08:52:07 +00:00
|
|
|
sigWifi(
|
|
|
|
wifi,
|
|
|
|
user,
|
|
|
|
WifiLog.ORGA,
|
|
|
|
oldorga,
|
|
|
|
neworga
|
|
|
|
)
|