def POST(self, domain): domain = str(domain).lower() form = web.input() domain_in_form = form_utils.get_domain_name(form) current_admin_managed_domains = sql_lib_admin.get_managed_domains( session.get('username'), domain_name_only=True)[1] if ((domain != domain_in_form) or (domain not in current_admin_managed_domains) or (domain_in_form not in current_admin_managed_domains) ) and not session.get('is_global_admin'): raise web.seeother('/domains?msg=PERMISSION_DENIED') # Get username username = form_utils.get_single_value(form, input_name='username', to_string=True) qr = sql_lib_user.add_user_from_form(domain=domain, form=form) if qr[0]: raise web.seeother( '/profile/user/general/{}@{}?msg=CREATED'.format( username, domain)) else: raise web.seeother('/create/user/{}?msg={}'.format( domain, web.urlquote(qr[1])))
def GET(self, domain): domain = str(domain).lower() form = web.input() # Get all managed domains. _wrap = SQLWrap() conn = _wrap.conn if session.get('is_global_admin'): qr = sql_lib_domain.get_all_domains(conn=conn, name_only=True) else: qr = sql_lib_admin.get_managed_domains( conn=conn, admin=session.get('username'), domain_name_only=True) if qr[0] is True: all_domains = qr[1] else: raise web.seeother('/api?msg=' + web.urlquote(qr[1])) # Get domain profile. qr_profile = sql_lib_domain.simple_profile(domain=domain, conn=conn) if qr_profile[0] is True: domain_profile = qr_profile[1] domain_settings = sqlutils.account_settings_string_to_dict( domain_profile['settings']) else: raise web.seeother('/api?msg=%s' % web.urlquote(qr_profile[1])) # Cet total number and allocated quota size of existing users under domain. num_users_under_domain = sql_lib_general.num_users_under_domain( domain=domain, conn=conn) min_passwd_length = domain_settings.get('min_passwd_length', settings.min_passwd_length) max_passwd_length = domain_settings.get('max_passwd_length', settings.max_passwd_length) return web.render( 'api/msg/msg.html', content_type="application/json", msg={ #"cur_domain":domain, #"allDomains":all_domains, #"profile":domain_profile, #"domain_settings":domain_settings, #"min_passwd_length":min_passwd_length, #"max_passwd_length":max_passwd_length, #"store_password_in_plain_text":settings.STORE_PASSWORD_IN_PLAIN_TEXT, #"num_existing_users":num_users_under_domain, #"languagemaps":iredutils.get_language_maps(), #"password_policies":iredutils.get_password_policies(), #"msg":form.get('msg') "msg": "Create User API's GET method!" })
def GET(self, domain): domain = str(domain).lower() form = web.input() # Get all managed domains. _wrap = SQLWrap() conn = _wrap.conn if session.get('is_global_admin'): qr = sql_lib_domain.get_all_domains(conn=conn, name_only=True) else: qr = sql_lib_admin.get_managed_domains( conn=conn, admin=session.get('username'), domain_name_only=True) if qr[0] is True: all_domains = qr[1] else: raise web.seeother('/domains?msg=' + web.urlquote(qr[1])) # Get domain profile. qr_profile = sql_lib_domain.simple_profile(domain=domain, conn=conn) if qr_profile[0] is True: domain_profile = qr_profile[1] domain_settings = sqlutils.account_settings_string_to_dict( domain_profile['settings']) else: raise web.seeother('/domains?msg=%s' % web.urlquote(qr_profile[1])) # Cet total number and allocated quota size of existing users under domain. num_users_under_domain = sql_lib_general.num_users_under_domain( domain=domain, conn=conn) min_passwd_length = domain_settings.get('min_passwd_length', settings.min_passwd_length) max_passwd_length = domain_settings.get('max_passwd_length', settings.max_passwd_length) return web.render( 'sql/user/create.html', cur_domain=domain, allDomains=all_domains, profile=domain_profile, domain_settings=domain_settings, min_passwd_length=min_passwd_length, max_passwd_length=max_passwd_length, store_password_in_plain_text=settings.STORE_PASSWORD_IN_PLAIN_TEXT, num_existing_users=num_users_under_domain, languagemaps=iredutils.get_language_maps(), password_policies=iredutils.get_password_policies(), msg=form.get('msg'), )
def GET(self, account_type): _wrap = SQLWrap() conn = _wrap.conn if session.get('is_global_admin'): qr = sql_lib_domain.get_all_domains(conn=conn, name_only=True) else: qr = sql_lib_admin.get_managed_domains(conn=conn, admin=session.get('username'), domain_name_only=True) if qr[0] is True: all_domains = qr[1] # Go to first available domain. if all_domains: raise web.seeother('/create/{}/{}'.format(account_type, all_domains[0])) else: raise web.seeother('/domains?msg=NO_DOMAIN_AVAILABLE') else: raise web.seeother('/domains?msg=' + web.urlquote(qr[1]))
def GET(self): form = web.input(_unicode=False) # Get queries. form_event = web.safestr(form.get('event', 'all')) form_domain = web.safestr(form.get('domain', 'all')) form_admin = web.safestr(form.get('admin', 'all')) form_cur_page = web.safestr(form.get('page', '1')) if not form_cur_page.isdigit() or form_cur_page == '0': form_cur_page = 1 else: form_cur_page = int(form_cur_page) total, entries = loglib.list_logs(event=form_event, domain=form_domain, admin=form_admin, cur_page=form_cur_page) # Pre-defined all_domains = [] all_admins = [] if settings.backend == 'ldap': _wrap = LDAPWrap() conn = _wrap.conn # Get all managed domains under control. qr = ldap_lib_admin.get_managed_domains( admin=session.get('username'), conn=conn) if qr[0] is True: all_domains = qr[1] # Get all admins. if session.get('is_global_admin') is True: result = ldap_lib_admin.list_accounts(attributes=['mail'], conn=conn) if result[0] is not False: all_admins = [v[1]['mail'][0] for v in result[1]] else: all_admins = [form_admin] elif settings.backend in ['mysql', 'pgsql']: # Get all managed domains under control. _wrap = SQLWrap() conn = _wrap.conn qr = sql_lib_admin.get_managed_domains( conn=conn, admin=session.get('username'), domain_name_only=True) if qr[0] is True: all_domains = qr[1] # Get all admins. if session.get('is_global_admin') is True: qr = sql_lib_admin.get_all_admins(columns=['username'], email_only=True, conn=conn) if qr[0]: all_admins = qr[1] else: all_admins = [form_admin] return web.render('panel/log.html', event=form_event, domain=form_domain, admin=form_admin, log_events=LOG_EVENTS, cur_page=form_cur_page, total=total, entries=entries, all_domains=all_domains, all_admins=all_admins, msg=form.get('msg'))
def GET(self, profile_type, mail): mail = str(mail).lower() form = web.input() if not (session.get('is_global_admin') or session.get('username') == mail): # Don't allow to view/update others' profile. raise web.seeother( '/profile/admin/general/%s?msg=PERMISSION_DENIED' % session.get('username')) _wrap = SQLWrap() conn = _wrap.conn is_global_admin = sql_lib_general.is_global_admin(admin=mail, conn=conn) result = sql_lib_admin.get_profile(mail=mail, conn=conn) if result[0] is True: profile = result[1] qr = sql_lib_general.get_admin_settings(admin=mail, conn=conn) if qr[0]: admin_settings = qr[1] else: return qr # Get all domains. all_domains = [] qr_all_domains = sql_lib_domain.get_all_domains(conn=conn) if qr_all_domains[0] is True: all_domains = qr_all_domains[1] # Get managed domains. managed_domains = [] qr = sql_lib_admin.get_managed_domains(conn=conn, admin=mail, domain_name_only=True, listed_only=True) if qr[0] is True: managed_domains += qr[1] return web.render( 'sql/admin/profile.html', mail=mail, profile_type=profile_type, is_global_admin=is_global_admin, profile=profile, admin_settings=admin_settings, languagemaps=iredutils.get_language_maps(), allDomains=all_domains, managedDomains=managed_domains, min_passwd_length=settings.min_passwd_length, max_passwd_length=settings.max_passwd_length, store_password_in_plain_text=settings. STORE_PASSWORD_IN_PLAIN_TEXT, password_policies=iredutils.get_password_policies(), msg=form.get('msg'), ) else: # Return to user profile page if admin is a mail user. qr = sql_lib_user.simple_profile(conn=conn, mail=mail, columns=['username']) if qr[0]: raise web.seeother('/profile/user/general/' + mail) else: raise web.seeother('/admins?msg=' + web.urlquote(result[1]))