def getDefault(self, query=None): if auth.get_login() != None: usr = data.User.get_by_login(cherrypy.request.db, auth.get_login()) return usr.e_mail else: return Text.getDefault(self, query=None)
def getDefault(self, query=None): if auth.get_login()!=None: usr=data.User.get_by_login(cherrypy.request.db, auth.get_login()) return usr.e_mail else: return Text.getDefault(self, query=None)
def index(self, **kwargs): session = cherrypy.request.db login = auth.get_login() user = data.User.get_by_login(session, login) # entities=session.query(self.report_class) entities = data.get_allowed_entities(session, self.report_class, user, ('REPORTS', )) reportsettings = session.query(self.reportsetting_class).filter( self.reportsetting_class.user == user) settings = {} for ent in entities: settings[ent.id] = {} for t in self.reportsetting_class.types: settings[ent.id][t] = (report_frequencies[0], None) for rs in reportsettings: ent_id = getattr(rs, self.id_column) settings[ent_id][rs.report_type] = (rs.frequency, rs.last) return render(self.template, entities=entities, settings=settings, frequencies=report_frequencies, types_dict=self.reportsetting_class.types, **kwargs)
def set_report_freq(reportsetting_class, report_type, report_frequency, report_list=None, ent_id=None): session=cherrypy.request.db login = auth.get_login() user = data.User.get_by_login(session, login) query = session.query(reportsetting_class).filter(reportsetting_class.user == user).filter(reportsetting_class.report_type == report_type) add_args = {} if report_list is not None: ent = data.get_by_id(session, report_list.report_class, ent_id) query = query.with_parent(ent) add_args[report_list.id_column] = ent.id if login != 'admin': acl = ent.acls.filter(data.ACL.userrole_id == user.role.id, data.ACL.privilege == 'REPORTS').one() add_args['acl_id'] = acl.id setting = query.first() if setting is None: setting = reportsetting_class(user=user, report_type=report_type, frequency=report_frequency, **add_args) session.add(setting) setting.frequency = report_frequency session.commit()
def index(self): session = cherrypy.request.db login = auth.get_login() user = data.User.get_by_login(session, login) apps = data.Application.get_allowed_apps(session, user, ('VIEW', 'ADMIN')) root = cherrypy.tree.apps[config.root].root def loaded(app): return app.id in root.apps view_allowed = {} admin_allowed = {} for app in apps: admin_allowed[app.id] = auth.ForceLogin.match_acl( app.get_acl('ADMIN'), login) view_allowed[app.id] = auth.ForceLogin.match_acl( app.get_acl('VIEW'), login) return render('system/admin/apps.genshi', apps=apps, loaded_test=loaded, admin=(login == 'admin'), view_allowed=view_allowed, admin_allowed=admin_allowed)
def index(self, p=1, **kwargs): session = cherrypy.request.db login = auth.get_login() user = data.User.get_by_login(session, login) q = data.Request.get_allowed_requests(session, user, ('VIEW', 'ADMIN')) apps = data.Application.get_allowed_apps(session, user, ('VIEW', 'ADMIN')) view_allowed = {} admin_allowed = {} for app in apps: admin_allowed[app.id] = auth.ForceLogin.match_acl( app.get_acl('ADMIN'), login) view_allowed[app.id] = auth.ForceLogin.match_acl( app.get_acl('VIEW'), login) return render_query_paged('system/admin/requests.genshi', q, int(p), 'requests', config.root + "/admin/requests/", kwargs, view_allowed=view_allowed, admin_allowed=admin_allowed)
def processTemplate(self,file, args, type='xhtml'): if type=='xhtml': tmplt=self.templateLoader.load(file) elif type=='text': tmplt=self.templateLoader.load(file, cls=NewTextTemplate) try: args.mailto=webhelpers.html.tools.mail_to(config.get('Mail', 'admin_email'), unicode(config.get('Mail', 'admin_name'),"UTF-8"), encode="hex") except: pass try: args.e_mail=config.get('Mail', 'admin_email') except: pass try: args.server=config.get('Server', 'name') except: pass try: args.address=config.server_url except: pass try: args.css=config.get('Server', 'css_url') except: pass try: args.media=config.root + '/media' except: pass try: args.root=config.root except: pass try: tmp = cherrypy.request.db except: pass else: if tmp is not None: args.navigation_bar = util.get_WeBIAS().navigation_bar() else: args.navigation_bar = [] args.base = self.base_filename() # args.template_base = config.server_dir + '/templates' args.login=auth.get_login() stream = tmplt.generate(**args.__dict__) return stream.render(type, encoding='UTF-8')
def get_req(self, req_uuid): session=cherrypy.request.db req=data.Request.get_request(session, req_uuid) login=auth.get_login() user=data.User.get_by_login(session,login) return req
def stats(self): if auth.get_login()!='admin': return '' session=cherrypy.request.db sub = data.Hit.session_query(session).subquery() # sub=session.query(data.Hit.session, sqlalchemy.func.count(data.Hit.id).label('num_hits'), sqlalchemy.func.sum(sqlalchemy.sql.expression.cast(data.Hit.req_sub, sqlalchemy.types.Integer), type_=self.CoerceToInt).label('num_reqs')).group_by(data.Hit.session, data.Hit.ip_address).subquery() q=session.query(sqlalchemy.func.sum(sub.c.num_hits), sqlalchemy.func.count(sub.c.session), sqlalchemy.func.sum(sub.c.num_reqs)) stats=q.one() return render('system/statistics/sessions_stats.genshi', num_hits=stats[0], num_sessions=stats[1], num_reqs=stats[2])
def index(self, p=1, **kwargs): session=cherrypy.request.db login=auth.get_login() user=data.User.get_by_login(session,login) q=data.Request.get_allowed_requests(session, user, ('VIEW', 'ADMIN')) apps=data.Application.get_allowed_apps(session, user, ('VIEW', 'ADMIN')) view_allowed={} admin_allowed={} for app in apps: admin_allowed[app.id] = auth.ForceLogin.match_acl(app.get_acl('ADMIN'), login) view_allowed[app.id] = auth.ForceLogin.match_acl(app.get_acl('VIEW'), login) return render_query_paged('system/admin/requests.genshi', q, int(p), 'requests', config.root+"/admin/requests/", kwargs, view_allowed=view_allowed, admin_allowed=admin_allowed)
def index(self): session=cherrypy.request.db login=auth.get_login() user=data.User.get_by_login(session,login) schedulers=data.Scheduler.get_allowed_scheds(session, user, ('VIEW', 'ADMIN')) view_allowed={} admin_allowed={} for sched in schedulers: admin_allowed[sched.id] = auth.ForceLogin.match_acl(sched.get_acl('ADMIN'), login) view_allowed[sched.id] = auth.ForceLogin.match_acl(sched.get_acl('VIEW'), login) return render('system/admin/schedulers.genshi', schedulers=schedulers, admin= (login == 'admin'), view_allowed=view_allowed, admin_allowed=admin_allowed)
def index(self): def sort_key(t): try: return t[1]._order except AttributeError: return t[1]._title def matches_login(t): acl = auth.safe_get_acl(t[1]) return auth.ForceLogin.match_acl(acl, login) login = auth.get_login() features = filter(matches_login, self.get_features().items()) features.sort(key=sort_key) return render('system/feature_list.genshi', features=features, title=self._title)
def index(self): session=cherrypy.request.db login = auth.get_login() user = data.User.get_by_login(session, login) reportsettings = session.query(self.reportsetting_class).filter(self.reportsetting_class.user == user) settings = {} for t in self.reportsetting_class.types: settings[t] = (report_frequencies[0], None) for rs in reportsettings: settings[rs.report_type] = (rs.frequency, rs.last) return render('system/reports/server.genshi', settings=settings, frequencies=report_frequencies, types_dict=self.reportsetting_class.types)
def error_recorder(hit_id=None): session=cherrypy.request.db engine=None if session==None: engine= sqlalchemy.create_engine(config.get('Database', 'db_url'), echo=False) engine.connect(); Session=sqlalchemy.orm.sessionmaker(bind=engine) session=Session() login=auth.get_login() if cherrypy.response.status==None: status='500 Internal Server Error' else: status=cherrypy.response.status if login!=None: user=data.User.get_by_login(session, login) user_id=user.id else: user_id=None date=time.strftime("%Y-%m-%d %H:%M:%S") ip_address=cherrypy.request.remote.ip url = cherrypy.url(qs=cherrypy.request.query_string) headers=["%s: %s"%(k,v) for k,v in cherrypy.request.header_list] request='\n'.join([cherrypy.request.request_line] + headers) trace=''.join(traceback.format_exception(*sys.exc_info())) session_elts=["%s: %s"%(k,v) for k,v in cherrypy.session.items()] session_dump='\n'.join(["id: %s"%cherrypy.session.id] + session_elts) error=data.Error(user_id, login, hit_id, date, ip_address, url, status, cherrypy.session.id, trace, request, session_dump) session.add(error) if engine!=None: session.commit() session.close()
def index(self): session = cherrypy.request.db login = auth.get_login() user = data.User.get_by_login(session, login) reportsettings = session.query(self.reportsetting_class).filter( self.reportsetting_class.user == user) settings = {} for t in self.reportsetting_class.types: settings[t] = (report_frequencies[0], None) for rs in reportsettings: settings[rs.report_type] = (rs.frequency, rs.last) return render('system/reports/server.genshi', settings=settings, frequencies=report_frequencies, types_dict=self.reportsetting_class.types)
def index(self, p=1, all=None, **kwargs): session=cherrypy.request.db login=auth.get_login() user=data.User.get_by_login(session,login) q=session.query(data.Request).with_parent(user) fb = config.root+'/user/requests/' all= all!=None if not all: q=q.filter(data.Request.starred == True) if q.count()==0: raise cherrypy.HTTPRedirect(fb+'?all') else: fb=fb+'?all' return render_query_paged('system/user/requests.genshi', q, int(p), 'requests', fb, kwargs, all=all)
def index(self): session=cherrypy.request.db login=auth.get_login() user=data.User.get_by_login(session,login) apps=data.Application.get_allowed_apps(session, user, ('VIEW', 'ADMIN')) root=cherrypy.tree.apps[config.root].root def loaded(app): return app.id in root.apps view_allowed={} admin_allowed={} for app in apps: admin_allowed[app.id] = auth.ForceLogin.match_acl(app.get_acl('ADMIN'), login) view_allowed[app.id] = auth.ForceLogin.match_acl(app.get_acl('VIEW'), login) return render('system/admin/apps.genshi', apps=apps, loaded_test=loaded, admin= (login == 'admin'), view_allowed=view_allowed, admin_allowed=admin_allowed)
def index(self, **kwargs): session=cherrypy.request.db login = auth.get_login() user = data.User.get_by_login(session, login) # entities=session.query(self.report_class) entities=data.get_allowed_entities(session, self.report_class, user, ('REPORTS', )) reportsettings = session.query(self.reportsetting_class).filter(self.reportsetting_class.user == user) settings = {} for ent in entities: settings[ent.id] = {} for t in self.reportsetting_class.types: settings[ent.id][t] = (report_frequencies[0], None) for rs in reportsettings: ent_id = getattr(rs, self.id_column) settings[ent_id][rs.report_type] = (rs.frequency, rs.last) return render(self.template, entities=entities, settings=settings, frequencies=report_frequencies, types_dict=self.reportsetting_class.types, **kwargs)
def index(self): session = cherrypy.request.db login = auth.get_login() user = data.User.get_by_login(session, login) schedulers = data.Scheduler.get_allowed_scheds(session, user, ('VIEW', 'ADMIN')) view_allowed = {} admin_allowed = {} for sched in schedulers: admin_allowed[sched.id] = auth.ForceLogin.match_acl( sched.get_acl('ADMIN'), login) view_allowed[sched.id] = auth.ForceLogin.match_acl( sched.get_acl('VIEW'), login) return render('system/admin/schedulers.genshi', schedulers=schedulers, admin=(login == 'admin'), view_allowed=view_allowed, admin_allowed=admin_allowed)
def hit_recorder(): if sys.exc_info()[0]==cherrypy._cperror.InternalRedirect: status='XXX Internal redirect' stat_num=0 elif cherrypy.response.status==None: status='500 Internal Server Error' stat_num=500 else: status=cherrypy.response.status stat_num=int(status.split(' ')[0]) # try: # stat_num = int(status) # except: # stat_num=int(status.split(' ')[0]) session=cherrypy.request.db login=auth.get_login() if login!=None: user=data.User.get_by_login(session, login) user_id=user.id else: user_id=None date=time.strftime("%Y-%m-%d %H:%M:%S") ip_address=cherrypy.request.remote.ip url = cherrypy.url(qs=cherrypy.request.query_string) req_sub=getattr(cherrypy.request, 'req_sub', False) hit=data.Hit(user_id, login, date, ip_address, url, status, cherrypy.session.id, req_sub) session.add(hit) session.commit() if stat_num>400: error_recorder(hit.id)
def set_report_freq(reportsetting_class, report_type, report_frequency, report_list=None, ent_id=None): session = cherrypy.request.db login = auth.get_login() user = data.User.get_by_login(session, login) query = session.query(reportsetting_class).filter( reportsetting_class.user == user).filter( reportsetting_class.report_type == report_type) add_args = {} if report_list is not None: ent = data.get_by_id(session, report_list.report_class, ent_id) query = query.with_parent(ent) add_args[report_list.id_column] = ent.id if login != 'admin': acl = ent.acls.filter(data.ACL.userrole_id == user.role.id, data.ACL.privilege == 'REPORTS').one() add_args['acl_id'] = acl.id setting = query.first() if setting is None: setting = reportsetting_class(user=user, report_type=report_type, frequency=report_frequency, **add_args) session.add(setting) setting.frequency = report_frequency session.commit()
def main(): names = get_name() roles = get_roles() access = get_login(names, roles) to_do_something()
def is_available(self): return self.enabled and auth.ForceLogin().match_acl(self._acl, auth.get_login())