def getGroups(self, username, groupsManager: GroupsManager): # these groups are a bit special. They are in fact ip-ranges, and we must check that the ip is in betwen # The ranges are stored in group names for g in groupsManager.getGroupsNames(): try: if net.ipInNetwork(username, g): groupsManager.validate(g) except Exception as e: logger.error('Invalid network for IP auth: %s', e)
def getHtml(self, request): # doAutoLogin = Config.section('IPAUTH').value('autoLogin', '0').getBool() ip = self.getIp() gm = GroupsManager(self.dbAuthenticator()) self.getGroups(ip, gm) if gm.hasValidGroups() and self.dbAuthenticator().isValidUser(ip, True): passw = '' return '<script type="text/javascript">$("#id_user").val("' + ip + '");$("#id_password").val("' + passw + '");$("#loginform").submit();</script>' else: return '<div>Invalid auth (' + ip + ')</div><script type="text/javascript">$("#backToLogin").click()</script>'
def recreateGroups(self, user): """ Helper method, not needed to be overriden. It simply checks if the source is external and if so, recreates the user groups for storing them at database. user param is a database user object """ if self.isExternalSource: groupsManager = GroupsManager(self._dbAuth) self.getGroups(user.name, groupsManager) user.groups.set([g.dbGroup() for g in groupsManager.getValidGroups()])
def recreateGroups(self, user): ''' Helper method, not needed to be overriden. It simply checks if the source is external and if so, recreates the user groups for storing them at database. user param is a database user object ''' if self.isExternalSource == True: groupsManager = GroupsManager(self._dbAuth) self.getGroups(user.name, groupsManager) user.groups = [g.dbGroup() for g in groupsManager.getValidGroups()]
def getJavascript(self, request): # doAutoLogin = Config.section('IPAUTH').value('autoLogin', '0').getBool() ip = self.getIp() gm = GroupsManager(self.dbAuthenticator()) self.getGroups(ip, gm) if gm.hasValidGroups() and self.dbAuthenticator().isValidUser(ip, True): return '''function setVal(element, value) {{ document.getElementById(element).value = value; }} setVal("id_user", "{ip}"); setVal("id_password", "{passwd}"); document.getElementById("loginform").submit();'''.format(ip=ip, passwd='') else: return 'alert("invalid authhenticator"); window.location.reload();</script>'
def getJavascript(self, request): # doAutoLogin = Config.section('IPAUTH').value('autoLogin', '0').getBool() ip = self.getIp() gm = GroupsManager(self.dbAuthenticator()) self.getGroups(ip, gm) if gm.hasValidGroups() and self.dbAuthenticator().isValidUser( ip, True): return '''function setVal(element, value) {{ document.getElementById(element).value = value; }} setVal("id_user", "{ip}"); setVal("id_password", "{passwd}"); document.getElementById("loginform").submit();'''.format( ip=ip, passwd='') return 'alert("invalid authhenticator"); window.location.reload();'