def connect(username=None, password=None): global conn if conn and conn.loggedin: return # determine credentials to use for login if not username and not password: for mgr in backend.getConfiglets(name="CfgOptManager"): # use first username/password if not username: username = mgr.name if not password: password = mgr.secret # or use destar/password if one is found if mgr.name == "destar": username = mgr.name password = mgr.secret break if not username and not password: # We couldn't log in print "***** manager cant login" return conn = ManagerEvents(username, password) if not conn.loggedin: conn.close() conn = None
def start_request (self): Session.start_request(self) request = get_request() t = time.time() request.response.set_charset('utf-8') # Determine IP of originator, keep Squid in mind :-) try: self.ip = request.environ['HTTP_X_FORWARDED_FOR'] except: self.ip = request.environ['REMOTE_ADDR'] self.port = request.environ['REMOTE_PORT'] #session = sessions.setdefault(ip, # configlets.Holder( # firstaccess=t, # user=None, # phone='', # language='en', # level=-1, # Try to auto-login, based on IP # )) # level==-1 means we should auto-login # This works by searching for the first CfgOptUser configlet where # the 'pc' variable matches the request originating IP: if self.level == -1: # Only try auto-login once, so set it to lowest level self.level = 0 users = backend.getConfiglets(name="CfgOptUser") if len(users) == 0: # be Admin if there are no users configured self.user = "******" self.level = 4 self.language = 'en' sys.stderr.write ("[%s] Logging in with user 'programmer' from ip %s, port %s\n" % (time.asctime(time.localtime()), self.ip, self.port)) else: for user in users: if user.pc == self.ip: self.user = user.name self.level = int(user.level) self.phone = user.phone self.language = user.language break language.setLanguage(self.language)
def start_request(self, request): t = time.time() # Determine IP of originator, keep Squid in mind :-) try: ip = request.environ["HTTP_X_FORWARDED_FOR"] except: ip = request.environ["REMOTE_ADDR"] # Search session object, if none found, create one with default values global sessions session = sessions.setdefault( ip, configlets.Holder( firstaccess=t, user=None, phone="", language="en", level=-1 # Try to auto-login, based on IP ), ) # level==-1 means we should auto-login # This works by searching for the first CfgOptUser configlet where # the 'pc' variable matches the request originating IP: if session.level == -1: # Only try auto-login once, so set it to lowest level session.level = 0 users = backend.getConfiglets(name="CfgOptUser") if len(users) == 0: # be Admin if there are no users configured session.user = "******" session.level = 4 session.language = "en" else: for user in users: if user.pc == ip: session.user = user.name session.level = int(user.level) session.phone = user.phone session.language = user.language break language.setLanguage(session.language) session.lastaccess = t request.session = session