def start(self): """start a new session""" import os import webnotes import webnotes.utils # generate sid if webnotes.local.login_manager.user=='Guest': sid = 'Guest' else: sid = webnotes.generate_hash() self.data['user'] = webnotes.local.login_manager.user self.data['sid'] = sid self.data['data']['user'] = webnotes.local.login_manager.user self.data['data']['session_ip'] = webnotes.get_request_header('REMOTE_ADDR') self.data['data']['last_updated'] = webnotes.utils.now() self.data['data']['session_expiry'] = self.get_expiry_period() self.data['data']['session_country'] = get_geo_ip_country(webnotes.get_request_header('REMOTE_ADDR')) # insert session webnotes.conn.begin() self.insert_session_record() # update profile webnotes.conn.sql("""UPDATE tabProfile SET last_login = '******', last_ip = '%s' where name='%s'""" % (webnotes.utils.now(), webnotes.get_request_header('REMOTE_ADDR'), self.data['user'])) webnotes.conn.commit() # set cookies to write webnotes.local.session = self.data
def start(self): """start a new session""" # generate sid if self.user=='Guest': sid = 'Guest' else: sid = webnotes.generate_hash() self.data['user'] = self.user self.data['sid'] = sid self.data['data']['user'] = self.user self.data['data']['session_ip'] = webnotes.get_request_header('REMOTE_ADDR') if self.user != "Guest": self.data['data']['last_updated'] = webnotes.utils.now() self.data['data']['session_expiry'] = self.get_expiry_period() self.data['data']['session_country'] = get_geo_ip_country(webnotes.get_request_header('REMOTE_ADDR')) # insert session if self.user!="Guest": webnotes.conn.begin() self.insert_session_record() # update profile webnotes.conn.sql("""UPDATE tabProfile SET last_login = '******', last_ip = '%s' where name='%s'""" % (webnotes.utils.now(), webnotes.get_request_header('REMOTE_ADDR'), self.data['user'])) webnotes.conn.commit()
def validate_ip_address(self): """check if IP Address is valid""" ip_list = webnotes.conn.get_value('Profile', self.user, 'restrict_ip', ignore=True) if not ip_list: return ip_list = ip_list.replace(",", "\n").split('\n') ip_list = [i.strip() for i in ip_list] for ip in ip_list: if webnotes.get_request_header('REMOTE_ADDR', '').startswith(ip) or webnotes.get_request_header('X-Forwarded-For', '').startswith(ip): return webnotes.msgprint('Not allowed from this IP Address') raise webnotes.AuthenticationError
def __init__(self): # Get Environment variables self.domain = webnotes.request.host if self.domain and self.domain.startswith('www.'): self.domain = self.domain[4:] # language self.set_lang(webnotes.get_request_header('HTTP_ACCEPT_LANGUAGE')) # load cookies webnotes.local.cookie_manager = CookieManager() # override request method. All request to be of type POST, but if _type == "POST" then commit if webnotes.form_dict.get("_type"): webnotes.local.request_method = webnotes.form_dict.get("_type") del webnotes.form_dict["_type"] # set db self.connect() # login webnotes.local.login_manager = LoginManager() # check status if webnotes.conn.get_global("__session_status")=='stop': webnotes.msgprint(webnotes.conn.get_global("__session_status_message")) raise webnotes.SessionStopped('Session Stopped') # load profile self.setup_profile() # run login triggers if webnotes.form_dict.get('cmd')=='login': webnotes.local.login_manager.run_trigger('on_session_creation')
def get_request_site_address(full_address=False): """get app url from request""" import os host_name = conf.host_name if not host_name: if webnotes.request: protocol = 'HTTPS' in webnotes.get_request_header('SERVER_PROTOCOL', "") and 'https://' or 'http://' host_name = protocol + webnotes.request.host else: return "http://localhost" if full_address: return host_name + webnotes.get_request_header("REQUEST_URI", "") else: return host_name
def get_request_site_address(full_address=False): """get app url from request""" host_name = webnotes.local.conf.host_name if not host_name: if webnotes.request: protocol = 'https' == webnotes.get_request_header('X-Forwarded-Proto', "") and 'https://' or 'http://' host_name = protocol + webnotes.request.host elif webnotes.local.site: return "http://" + webnotes.local.site else: return "http://localhost" if full_address: return host_name + webnotes.get_request_header("REQUEST_URI", "") else: return host_name
def get_request_site_address(full_address=False): """get app url from request""" import os host_name = conf.host_name if not host_name: if webnotes.request: protocol = "https" == webnotes.get_request_header("X-Forwarded-Proto", "") and "https://" or "http://" host_name = protocol + webnotes.request.host elif webnotes.local.site: return "http://" + webnotes.local.site else: return "http://localhost" if full_address: return host_name + webnotes.get_request_header("REQUEST_URI", "") else: return host_name
def get_city(): p = pygeoip.GeoIP(get_path("app", "data", "GeoLiteCity.dat")) try: r = p.record_by_addr(webnotes.get_request_header("REMOTE_ADDR")) except Exception, e: r = { "city": "Mumbai", "latitude": "18.974999999999994", "longitude": "72.82579999999999" }
def get_request_site_address(full_address=False): """get app url from request""" import os host_name = conf.host_name if not host_name: if webnotes.request: protocol = 'https' == webnotes.get_request_header( 'X-Forwarded-Proto', "") and 'https://' or 'http://' host_name = protocol + webnotes.request.host elif webnotes.local.site: return "http://" + webnotes.local.site else: return "http://localhost" if full_address: return host_name + webnotes.get_request_header("REQUEST_URI", "") else: return host_name
def validate_ip_address(self): """check if IP Address is valid""" ip_list = webnotes.conn.get_value('Profile', self.user, 'restrict_ip', ignore=True) if not ip_list: return ip_list = ip_list.replace(",", "\n").split('\n') ip_list = [i.strip() for i in ip_list] for ip in ip_list: if webnotes.get_request_header( 'REMOTE_ADDR', '').startswith(ip) or webnotes.get_request_header( 'X-Forwarded-For', '').startswith(ip): return webnotes.msgprint('Not allowed from this IP Address') raise webnotes.AuthenticationError
def __init__(self): # Get Environment variables self.domain = webnotes.request.host if self.domain and self.domain.startswith('www.'): self.domain = self.domain[4:] # language self.set_lang(webnotes.get_request_header('HTTP_ACCEPT_LANGUAGE')) # load cookies webnotes.local.cookie_manager = CookieManager() # override request method. All request to be of type POST, but if _type == "POST" then commit if webnotes.form_dict.get("_type"): webnotes.local.request_method = webnotes.form_dict.get("_type") del webnotes.form_dict["_type"] # set db self.connect() # login webnotes.local.login_manager = LoginManager() # start session webnotes.local.session_obj = Session() webnotes.local.session = webnotes.local.session_obj.data # check status if webnotes.conn.get_global("__session_status") == 'stop': webnotes.msgprint( webnotes.conn.get_global("__session_status_message")) raise webnotes.SessionStopped('Session Stopped') # load profile self.setup_profile() # run login triggers if webnotes.form_dict.get('cmd') == 'login': webnotes.local.login_manager.run_trigger('on_login_post_session') # write out cookies webnotes.local.cookie_manager.set_cookies()
def accept_gzip(): if "gzip" in webnotes.get_request_header("HTTP_ACCEPT_ENCODING", ""): return True
def is_ajax(): return webnotes.get_request_header("X-Requested-With")=="XMLHttpRequest"