Skip to content

Commit

Permalink
Added support for v4 controller
Browse files Browse the repository at this point in the history
  • Loading branch information
bilbolodz committed Feb 1, 2016
1 parent 1de74a8 commit b2bb194
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 208 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -2,6 +2,7 @@ UniFi-Lab wouldn't exist without code written by the following people. Thank you
(alphabetical order)

- Cherkendov, Alexander
- Goczal Piotr
- Jea, David: Ubiquiti Networks
- Penz, Robert: DVT-Daten-Verarbeitung-Tirol GmbH
- Schroeder, Matt: Computer Information Systems dept., City of Neenah
12 changes: 1 addition & 11 deletions README.md
Expand Up @@ -125,17 +125,7 @@ There are no other parameters for MAC_AUTH. The white list file "unifi_lab_mac_a
* poorSignalThresholdSeconds = M. The controller will reconnect this client if it falls below the threshold for ''M'' seconds. For example, "poorSignalThresholdSeconds = 10" means 10 seconds.

## WLANs on/off schedule feature
* onOffScheduleApNamePrefix = [empty|prefix]. Leave this empty for all APs, or give an alias prefix to only affect those APs.
* onOffScheduleWlanList = wlan1,wlan2,wlan3,wlan4. This is a list of WLANs that will be controlled by the scheduler, separated by a comma ",".
* onOffScheduleWlanOverrideOffList = wlan5,wlan6. This is a list of WLANs that will be overridden to off permanently for these APs, separated by comma ','
* onOffScheduleMonday = 09:00-19:00
* onOffScheduleTuesday = 09:00-19:00
* onOffScheduleWednesday = 09:00-19:00
* onOffScheduleTursday = 09:00-19:00
* onOffScheduleFriday = 09:00-19:00
* onOffScheduleSaturday = 09:00-19:00
* onOffScheduleSunday= 09:00-19:00
* Above is the on/off schedule in 24-hr format. Note: For fully ON day (AP enabled entire day), set to 00:00-24:00. For fully OFF day (AP disabled entire day), set to 24:00-24:00.
Feature removed due to original Unifi support

## For Periodic Reboot feature
* periodicRebootApNamePrefix = [empty|prefix]. Leave this empty for all APs, or give an alias prefix to only affect those APs.
Expand Down
28 changes: 7 additions & 21 deletions config_manager.py
Expand Up @@ -70,7 +70,13 @@ def getControllerUsername(self):

def getControllerPassword(self):
return self._config.get("Controller", "controllerPassword", raw=True)


def getControllerPort(self):
return self._config.get("Controller", "controllerPort")

def getControllerVersion(self):
return self._config.get("Controller", "controllerVersion")


# Mail
def getFromAddress(self):
Expand All @@ -93,9 +99,6 @@ def getEnableMacAuth(self):
def getEnablePoorSignalReconnect(self):
return self._config.getboolean("Feature", "enablePoorSignalReconnect")

def getEnableSsidOnOffSchedule(self):
return self._config.getboolean("Feature", "enableSsidOnOffSchedule")

def getEnablePeriodicReboot(self):
return self._config.getboolean("Feature", "enablePeriodicReboot")

Expand All @@ -115,22 +118,6 @@ def getPoorSignalThreshold(self):
def getPoorSignalThresholdSeconds(self):
return self._config.getint("PoorSignalReconnect", "poorSignalThresholdSeconds")


# SsidOnOffSchedule
def getOnOffScheduleApNamePrefix(self):
return self._config.get("SsidOnOffSchedule", "onOffScheduleApNamePrefix")

def getOnOffScheduleWlanList(self):
return self._config.get("SsidOnOffSchedule", "onOffScheduleWlanList").split(',')

def getOnOffScheduleWlanOverrideOffList(self):
return self._config.get("SsidOnOffSchedule", "onOffScheduleWlanOverrideOffList").split(',')

def getOnOffScheduleForToday(self):
""" return the schedule for today """
return self._config.get("SsidOnOffSchedule", mapSchedule[int(time.strftime("%w", time.localtime()))]).split("-")


# PeriodicReboot
def getPeriodicRebootApNamePrefix(self):
return self._config.get("PeriodicReboot", "periodicRebootApNamePrefix")
Expand All @@ -154,7 +141,6 @@ def main():
print myConfigManager.getToAddresses()
print myConfigManager.getLogFile()
print myConfigManager.getEnablePeriodicReboot()
print myConfigManager.getOnOffScheduleForToday()
print myConfigManager.getRebootToday()
print myConfigManager.getInterval()

Expand Down
58 changes: 10 additions & 48 deletions unifi_lab.py
Expand Up @@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-

#############################################################################
## UniFi-Lab v0.0.2 ##
## UniFi-Lab v0.0.3 ##
#############################################################################
##Copyright (c) 2012, Ubiquiti Networks
##Copyright (c) 2016, Ubiquiti Networks
##All rights reserved.
##
##Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -36,8 +36,7 @@
Ubiquiti Networks UniFi-Lab consists of following tools:
1. MAC list authentication
2. Poor Signal Quality reconnection (based on Signal Strength or RSSI value)
3. SSID schedule on/off
4. Periodic reboot APs (introduced in v0.0.2)
3. Periodic reboot APs
usage: unifi_lab [start|stop|restart] <options>
Expand Down Expand Up @@ -149,7 +148,9 @@ def __init__(self, configManager):
self._config = configManager
self._ctlr = unifi_lab_ctlrobj.MyCtlr(configManager.getControllerHost(),
configManager.getControllerUsername(),
configManager.getControllerPassword())
configManager.getControllerPassword(),
configManager.getControllerPort(),
configManager.getControllerVersion())
self.interval = configManager.getInterval()
# do a first login to make sure we can conect to the controller, before going to the background
# FIXME: does not raise a exception if login does not work
Expand Down Expand Up @@ -181,11 +182,12 @@ def doMacAuth(self):
if m['mac']:
mac_auth_list.append(m['mac'].lower().replace('-',':'))
if m['whitegroup']:
str_whitelist = self._ctlr.ctrl_list_group_members(groups[m['whitegroup']]['_id'])
#str_whitelist = self._ctlr.ctrl_list_group_members(groups[m['whitegroup']]['_id'])
str_whitelist = self._ctlr.ctrl_list_essid_members(m['whitegroup'])
mac_whitelist = self._ctlr.ctlr_get_all_sta_mac(stalist=str_whitelist)
mac_auth_list = mac_auth_list + mac_whitelist
pass
# print "whitelist:%s"%mac_auth_list
#print "whitelist:%s"%mac_auth_list

cur_asso_list = self._ctlr.ctlr_get_all_sta_mac(self._stationList)
for mac in cur_asso_list:
Expand All @@ -198,7 +200,7 @@ def doMacAuth(self):

str_blockedlist = self._ctlr.ctrl_stat_user_blocked()
mac_blockedlist = self._ctlr.ctlr_get_all_sta_mac(stalist=str_blockedlist)
# print "blacklist:%s"%mac_blockedlist
#print "blacklist:%s"%mac_blockedlist
for mac in mac_auth_list:
if mac in mac_blockedlist:
log.info("[MAC Auth] This MAC needs to be unblocked: %s", mac)
Expand Down Expand Up @@ -248,39 +250,6 @@ def doPoorSignalReconnect(self):
self._stationRssi[mac] = time.time()
return

# Monday_ON and Monday_OFF time, all the way to Sunday
def doSsidOnOffSchedule(self):
def openHour(on, off):
"""
this function decides if the Wifi is on or off
"""
# on/off time in 24-Hour format. For example, 08:15 and 19:30
now = time.strftime("%H:%M", time.localtime())
[on_hour,on_min] = on.split(':')
[off_hour,off_min] = off.split(':')
[cur_hour,cur_min] = now.split(':')
if cur_hour > off_hour:
return False
elif cur_hour == off_hour and cur_min > off_min:
return False
if cur_hour < on_hour:
return False
elif cur_hour == on_hour and cur_min < on_min:
return False
return True

"""
this checks the day of the week and calls than openHour to check if need need to be
on or off
"""
power_on_time, power_off_time = self._config.getOnOffScheduleForToday()
if openHour(power_on_time, power_off_time):
log.info("[SSID Sche] Now is OPEN")
self._ctlr.ctlr_enabled_wlans_on_all_ap(self._config.getOnOffScheduleApNamePrefix(),self._config.getOnOffScheduleWlanList(),True,self._config.getOnOffScheduleWlanOverrideOffList())
else:
log.info("[SSID Sche] NOW is CLOSED")
self._ctlr.ctlr_enabled_wlans_on_all_ap(self._config.getOnOffScheduleApNamePrefix(),self._config.getOnOffScheduleWlanList(),False,self._config.getOnOffScheduleWlanOverrideOffList())

def doPeriodicReboot(self):
"""
this function is responsible for rebooting the UAPs at the specified time
Expand Down Expand Up @@ -314,7 +283,6 @@ def continuousLoop(self):


# FIXME: the i3 und i4 stuff is not clean, need to clean it up later
i3 = 0
i4 = 0

while True:
Expand All @@ -332,17 +300,11 @@ def continuousLoop(self):
if self._config.getEnablePoorSignalReconnect():
self.doPoorSignalReconnect()

if self._config.getEnableSsidOnOffSchedule() and i3 > 11: # do this once a minute is good enough, thus i3 > 11
self.doSsidOnOffSchedule()
i3 = 0
i3 = i3 + 1

if self._config.getEnablePeriodicReboot() and i4 > 11:
self.doPeriodicReboot()
i4 = 0
i4 = i4 + 1


# make sure that we runn every x seconds (including the time it took to work
sleepTime = self.interval + 1 - (time.time() - startTime)

Expand Down

0 comments on commit b2bb194

Please sign in to comment.