def AddGroup(self, groupName, options={}): if groupName and type(options) is dict: groupID = IoTSocketStruct.GroupNameToBin128(groupName) if groupID: self._groups[groupID] = options return True return False
def _processPOSTACL(self, content): try: o = self._getJSONContent(content) except Exception as ex: self._logRefused('BAD REQUEST, %s' % ex) self._sendHTTPResponse(400, '400 : Bad Request (%s)' % ex) return try: acl = [] ok = True for ac in o: groupID = IoTSocketStruct.GroupNameToBin128(ac['GroupName']) uid = IoTSocketStruct.UIDToBin128(ac['UID']) authKey = unhexlify(ac['AuthKey']) if groupID and uid and authKey and len(authKey) == 16: acl.append((groupID, uid, authKey)) else: ok = False break if ok: self._router.ClearACL() for ac in acl: self._router.AddACLAccess(*ac) self._router.SaveACL() self._log('%s ACL SETUP RECEIVED' % len(acl)) self._sendHTTPResponse(200) return except: pass self._logRefused('BAD REQUEST, INCORRECT JSON DATA') self._sendHTTPResponse(400, '400 : Bad Request (incorrect json data)')
def LoadACL(self): try: with open(self._aclFilename, 'r') as file: o = json.load(file) acl = {} for strUID in o: uid = IoTSocketStruct.UIDToBin128(strUID) groupID = IoTSocketStruct.GroupNameToBin128( o[strUID]["GroupName"]) authKey = unhexlify(o[strUID]["AuthKey"]) if not uid or not groupID or len(authKey) != 16 or \ not groupID in self._groups : return False acl[uid] = (groupID, authKey) with self._lock: self._acl = acl return True except: return False