Commits

Zhang Huangbin committed 5f0c322

Rename decorators:
* @base.protected -> @base.require_login
* @base.check_global_admin -> @base.require_global_admin

in libs/ldaplib/:
* @check_global_admin -> require_global_admin
* @check_domain_access -> require_domain_access

Merge controllers/utils.py into controllers/base.py.

  • Participants
  • Parent commits d151c5b

Comments (0)

Files changed (14)

File controllers/base.py

+#!/usr/bin/env python
+# encoding: utf-8
+
+# Author: Zhang Huangbin <michaelbibby (at) gmail.com>
+
+#---------------------------------------------------------------------
+# This file is part of iRedAdmin-OSE, which is official web-based admin
+# panel (Open Source Edition) for iRedMail.
+#
+# iRedMail is an open source mail server solution for Red Hat(R)
+# Enterprise Linux, CentOS, Debian and Ubuntu.
+#
+# iRedAdmin-OSE is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# iRedAdmin-OSE is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with iRedAdmin-OSE.  If not, see <http://www.gnu.org/licenses/>.
+#---------------------------------------------------------------------
+
+import sys
+import web
+
+session = web.config.get('_session')
+
+class redirect:
+    '''Make url ending with or without '/' going to the same class.
+    '''
+    def GET(self, path):
+        web.redirect('/' + str(path))
+
+class img:
+    def GET(self, encoded_img):
+        web.header('Content-Type', 'image/jpeg')
+        return encoded_img.decode('base64')
+#
+# Decorators
+#
+def require_login(func):
+    def proxyfunc(self, *args, **kw):
+        if session.get('username') != None and session.get('logged') == True:
+            return func(self, *args, **kw)
+        else:
+            session.kill()
+            web.seeother('/login?msg=loginRequired')
+    return proxyfunc
+
+def require_global_admin(func):
+    def proxyfunc(self, *args, **kw):
+        if session.get('domainGlobalAdmin') == 'yes':
+            return func(self, *args, **kw)
+        else:
+            web.seeother('/domains?msg=PERMISSION_DENIED')
+    return proxyfunc

File controllers/ldap/admin.py

 import web
 from web import render
 from controllers.ldap.basic import dbinit
-from controllers.ldap import base
+from controllers import base
 from libs.ldaplib import admin, ldaputils, iredldif
 
 cfg = web.iredconfig
 # Admin related.
 #
 class list(dbinit):
-    @base.check_global_admin
-    @base.protected
+    @base.require_global_admin
+    @base.require_login
     def GET(self):
         i = web.input()
         self.admins = adminLib.list()
         return render.admins(admins=self.admins, msg=i.get('msg', None))
 
     # Delete, disable, enable admin accounts.
-    @base.check_global_admin
-    @base.protected
+    @base.require_global_admin
+    @base.require_login
     def POST(self):
         i = web.input(_unicode=False, mail=[])
         self.mails = i.get('mail', [])
             web.seeother('/admins?' + result[1])
 
 class create(dbinit):
-    @base.check_global_admin
-    @base.protected
+    @base.require_global_admin
+    @base.require_login
     def GET(self):
         return render.admin_create(
                 languagemaps=adminLib.getLanguageMaps(),
                 max_passwd_length=cfg.general.get('max_passwd_length'),
                 )
 
-    @base.check_global_admin
-    @base.protected
+    @base.require_global_admin
+    @base.require_login
     def POST(self):
         i = web.input()
         self.username = web.safestr(i.get('username'))
             web.seeother('/create/admin?msg=' + result[1])
 
 class profile(dbinit):
-    @base.protected
+    @base.require_login
     def GET(self, profile_type, mail):
         self.mail = web.safestr(mail)
         self.profile_type = web.safestr(profile_type)
                     msg=i.get('msg', None),
                     )
 
-    @base.protected
+    @base.require_login
     def POST(self, profile_type, mail):
         self.profile_type = web.safestr(profile_type)
         self.mail = web.safestr(mail)

File controllers/ldap/base.py

-#!/usr/bin/env python
-# encoding: utf-8
-
-# Author: Zhang Huangbin <michaelbibby (at) gmail.com>
-
-#---------------------------------------------------------------------
-# This file is part of iRedAdmin-OSE, which is official web-based admin
-# panel (Open Source Edition) for iRedMail.
-#
-# iRedMail is an open source mail server solution for Red Hat(R)
-# Enterprise Linux, CentOS, Debian and Ubuntu.
-#
-# iRedAdmin-OSE is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# iRedAdmin-OSE is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with iRedAdmin-OSE.  If not, see <http://www.gnu.org/licenses/>.
-#---------------------------------------------------------------------
-
-import sys
-import web
-
-session = web.config.get('_session')
-
-class redirect:
-    '''Make url ending with or without '/' going to the same class.
-    '''
-    def GET(self, path):
-        web.redirect('/' + str(path))
-
-#
-# Decorators
-#
-def protected(func):
-    def proxyfunc(self, *args, **kw):
-        if session.get('username') != None and session.get('logged') == True:
-            return func(self, *args, **kw)
-        else:
-            session.kill()
-            web.seeother('/login?msg=loginRequired')
-    return proxyfunc
-
-def check_global_admin(func):
-    def proxyfunc(self, *args, **kw):
-        if session.get('domainGlobalAdmin') == 'yes':
-            return func(self, *args, **kw)
-        else:
-            web.seeother('/domains?msg=PERMISSION_DENIED')
-    return proxyfunc

File controllers/ldap/basic.py

 import web, sys
 from libs import __version__, __url_iredadmin_lastest__, iredutils
 from libs.ldaplib import core, auth, domain, ldaputils
-from controllers.ldap import base
+from controllers import base
 
 cfg = web.iredconfig
 session = web.config.get('_session')
         web.seeother('/login')
 
 class dashboard:
-    @base.protected
+    @base.require_login
     def GET(self):
         from socket import getfqdn
         import os
                 )
 
 class checknew:
-    @base.check_global_admin
-    @base.protected
+    @base.require_global_admin
+    @base.require_login
     def GET(self):
         import urllib2
         try:

File controllers/ldap/domain.py

 import web
 from web import render
 from web import iredconfig as cfg
-from controllers.ldap import base
+from controllers import base
 from controllers.ldap.basic import dbinit
 from libs.ldaplib import core, admin, domain, attrs
 
 #
 class list(dbinit):
     '''List all virtual mail domains.'''
-    @base.protected
+    @base.require_login
     def GET(self):
         i = web.input()
         result = domainLib.list()
             return result
         return render.domains(allDomains=allDomains, msg=i.get('msg', None))
 
-    @base.check_global_admin
-    @base.protected
+    @base.require_global_admin
+    @base.require_login
     def POST(self):
         i = web.input(domainName=[])
         domainName = i.get('domainName', None)
             web.seeother('/domains?' + result[1])
 
 class profile(dbinit):
-    @base.protected
+    @base.require_login
     def GET(self, profile_type, domain):
         i = web.input()
         self.domain = web.safestr(domain.split('/', 1)[0])
         else:
             web.seeother('/domains?' + result[1])
 
-    @base.protected
+    @base.require_login
     def POST(self, profile_type, domain):
         self.profile_type = web.safestr(profile_type)
         self.domain = web.safestr(domain)
             web.seeother('/profile/domain/%s/%s?' % (self.profile_type, self.domain) + result[1])
 
 class create(dbinit):
-    @base.check_global_admin
-    @base.protected
+    @base.require_global_admin
+    @base.require_login
     def GET(self):
         i = web.input()
         return render.domain_create(msg=i.get('msg'))
 
-    @base.check_global_admin
-    @base.protected
+    @base.require_global_admin
+    @base.require_login
     def POST(self):
         i = web.input()
         result = domainLib.add(data=i)

File controllers/ldap/urls.py

 
 urls = (
         # Make url ending with or without '/' going to the same class.
-        '/(.*)/',                           'controllers.ldap.base.redirect',
+        '/(.*)/',                           'controllers.base.redirect',
 
         # used to display jpegPhoto.
-        '/img/(.*)',                        'controllers.utils.img',
+        '/img/(.*)',                        'controllers.base.img',
 
         '/',                                'controllers.ldap.basic.login',
         '/login',                           'controllers.ldap.basic.login',

File controllers/ldap/user.py

 import web
 from web import render
 from web import iredconfig as cfg
-from controllers.ldap import base
+from controllers import base
 from controllers.ldap.basic import dbinit
 from libs.ldaplib import domain, user, attrs, iredldif, ldaputils
 
     def __del__(self):
         pass
 
-    @base.protected
+    @base.require_login
     def GET(self, domain=''):
         domain = web.safestr(domain.split('/', 1)[0])
         i = web.input()
             else:
                 web.seeother('/domains?' + result[1])
 
-    @base.protected
+    @base.require_login
     def POST(self, domain):
         i = web.input(_unicode=False, mail=[])
         self.domain = web.safestr(domain)
             web.seeother('/users/%s?' % (self.domain) + result[1])
 
 class profile(dbinit):
-    @base.protected
+    @base.require_login
     def GET(self, profile_type, mail):
         i = web.input(
                 enabledService=[],
         else:
             web.seeother('/users/%s?' % (self.domain) + result[1])
 
-    @base.protected
+    @base.require_login
     def POST(self, profile_type, mail):
         i = web.input(enabledService=[],telephoneNumber=[],mailForwardingAddress=[],)
         self.profile_type = web.safestr(profile_type)
             web.seeother('/profile/user/%s/%s?' % (self.profile_type, self.mail) + result[1])
 
 class create(dbinit):
-    @base.protected
+    @base.require_login
     def GET(self, domainName=None):
         if domainName is None:
             self.domain = ''
                 max_passwd_length=cfg.general.get('max_passwd_length'),
                 )
 
-    @base.protected
+    @base.require_login
     def POST(self):
         i = web.input()
 

File controllers/utils.py

-#!/usr/bin/env python
-# encoding: utf-8
-
-# Author: Zhang Huangbin <michaelbibby (at) gmail.com>
-
-#---------------------------------------------------------------------
-# This file is part of iRedAdmin-OSE, which is official web-based admin
-# panel (Open Source Edition) for iRedMail.
-#
-# iRedMail is an open source mail server solution for Red Hat(R)
-# Enterprise Linux, CentOS, Debian and Ubuntu.
-#
-# iRedAdmin-OSE is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# iRedAdmin-OSE is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with iRedAdmin-OSE.  If not, see <http://www.gnu.org/licenses/>.
-#---------------------------------------------------------------------
-
-import web
-
-class img:
-    def GET(self, encoded_img):
-        web.header('Content-Type', 'image/jpeg')
-        return encoded_img.decode('base64')

File libs/ldaplib/admin.py

             else:
                 return result
 
-    @LDAPDecorators.check_global_admin
+    @LDAPDecorators.require_global_admin
     def delete(self, mails):
         if mails is None or len(mails) == 0: return (False, 'msg=NO_ACCOUNT_SELECTED')
 
         else:
             return (False, ldaputils.getExceptionDesc(result))
 
-    @LDAPDecorators.check_global_admin
+    @LDAPDecorators.require_global_admin
     def enableOrDisableAccount(self, mails, value, attr='accountStatus',):
         if mails is None or len(mails) == 0: return (False, 'msg=NO_ACCOUNT_SELECTED')
 

File libs/ldaplib/core.py

     def __del__(self):
         pass
 
-    def check_global_admin(self, func):
+    def require_global_admin(self, func):
         def proxyfunc(self, *args, **kw):
             if session.get('domainGlobalAdmin') == 'yes':
                 return func(self, *args, **kw)
                 return False
         return proxyfunc
 
-    def check_domain_access(self, func):
+    def require_domain_access(self, func):
         def proxyfunc(self, *args, **kw):
             if kw.has_key('mail'):
                 self.domain = web.safestr(kw['mail']).split('@', 1)[1]

File libs/ldaplib/domain.py

     def __del__(self):
         pass
 
-    @LDAPDecorators.check_global_admin
+    @LDAPDecorators.require_global_admin
     def add(self, data):
         # msg: {key: value}
         msg = {}
             return cfg.general.get('default_quota', '1024')
 
     # Delete domain.
-    @LDAPDecorators.check_global_admin
+    @LDAPDecorators.require_global_admin
     def delete(self, domains=[]):
         if domains is None or len(domains) == 0: return False
         
         if msg == {}: return (True,)
         else: return (False, ldaputils.getExceptionDesc(msg))
 
-    @LDAPDecorators.check_global_admin
+    @LDAPDecorators.require_global_admin
     def enableOrDisableAccount(self, domains, value, attr='accountStatus',):
         if domains is None or len(domains) == 0: return (False, 'msg=NO_DOMAIN_SELECTED')
 
             return (False, ldaputils.getExceptionDesc(result))
 
     # Get domain attributes & values.
-    @LDAPDecorators.check_domain_access
+    @LDAPDecorators.require_domain_access
     def profile(self, domain):
         self.domain = web.safestr(domain)
         self.dn = ldaputils.convDomainToDN(self.domain)

File libs/ldaplib/user.py

         pass
 
     # List all users under one domain.
-    @LDAPDecorators.check_domain_access
+    @LDAPDecorators.require_domain_access
     def list(self, domain):
         self.domain = domain
         self.domainDN = ldaputils.convDomainToDN(self.domain)
             return (False, ldaputils.getExceptionDesc(e))
 
     # Get values of user dn.
-    @LDAPDecorators.check_domain_access
+    @LDAPDecorators.require_domain_access
     def profile(self, domain, mail):
         self.mail = web.safestr(mail)
         self.dn = ldaputils.convEmailToUserDN(self.mail)
             return (False, ldaputils.getExceptionDesc(e))
 
 
-    @LDAPDecorators.check_domain_access
+    @LDAPDecorators.require_domain_access
     def add(self, domain, data):
         # Get domain name, username, cn.
         self.domain = web.safestr(data.get('domainName')).lower()
         except Exception, e:
             return (False, ldaputils.getExceptionDesc(e))
 
-    @LDAPDecorators.check_domain_access
+    @LDAPDecorators.require_domain_access
     def delete(self, domain, mails=[]):
         if mails is None or len(mails) == 0: return False
 
         else:
             return (False, ldaputils.getExceptionDesc(result))
 
-    @LDAPDecorators.check_domain_access
+    @LDAPDecorators.require_domain_access
     def enableOrDisableAccount(self, domain, mails, value, attr='accountStatus',):
         if mails is None or len(mails) == 0: return (False, 'msg=NO_ACCOUNT_SELECTED')
 
         else:
             return (False, ldaputils.getExceptionDesc(result))
 
-    @LDAPDecorators.check_domain_access
+    @LDAPDecorators.require_domain_access
     def update(self, profile_type, mail, data):
         self.profile_type = web.safestr(profile_type)
         self.mail = web.safestr(mail)

File static/default/css/iredadmin.css

     }
 
 .brd .paging {
-    float: left;
+    float: right;
     }
 
 .brd .posting {
     text-align: right;
-    float: right;
+    float: left;
     }
 
 .brd .paging, .brd .paging * {
     float: left;
     }
 
+.brd .paging a.noborder {
+    padding: 0;
+    border: 0;
+    float: none;
+    }
+
 .brd .paging .first-item, .brd .paging span.pages {
     border-left: 0;
     padding-left: 0;
     }
 
-.brd .posting .newpost {
+.brd .posting .newpost, .posting .active {
     font-size: 1.084em;
     font-weight: bold;
     }

File static/default/css/iredadmin_cs.css

     color: yellow;
     }
 
+#brd-visit #welcome span a.active {
+    color: #b42000;
+    }
+
+.brd .posting span a.active {
+    color: #b42000;
+    }
+
 /* Logo and Headings
 ----------------------------------------------------------------*/