Commits

Zhang Huangbin  committed 81cff4f

Ability to enable/disable domains & admins directly.

  • Participants
  • Parent commits 2989b36

Comments (0)

Files changed (12)

File controllers/ldap/admin.py

         self.admins = adminLib.list()
         return render.admins(admins=self.admins, msg=i.get('msg', None))
 
-    # Delete admins.
+    # Delete, disable, enable admin accounts.
     @base.check_global_admin
     @base.protected
     def POST(self):
         i = web.input(_unicode=False, mail=[])
         self.mails = i.get('mail', [])
-        result = adminLib.delete(mails=self.mails)
+        if i.has_key('delete'):
+            result = adminLib.delete(mails=self.mails,)
+            msg = 'ADMIN_DELETED_SUCCESS'
+        elif i.has_key('disable'):
+            result = adminLib.enableOrDisableAccount(mails=self.mails, value='disabled',)
+            msg = 'ADMIN_DISABLED_SUCCESS'
+        elif i.has_key('enable'):
+            result = adminLib.enableOrDisableAccount(mails=self.mails, value='active',)
+            msg = 'ADMIN_ENABLED_SUCCESS'
+        else:
+            msg = i.get('msg', None)
+
         if result[0] is True:
-            web.seeother('/admins?msg=DELETE_SUCCESS')
+            web.seeother('/admins?msg=%s' % msg)
         else:
             web.seeother('/admins?msg=%s' % result[1])
 

File controllers/ldap/domain.py

     def POST(self):
         i = web.input(domainName=[])
         domainName = i.get('domainName', None)
-        result = domainLib.delete(domainName)
-        web.seeother('/domains')
+        if i.has_key('delete'):
+            result = domainLib.delete(domainName)
+            msg = 'DOMAIN_DELETED_SUCCESS'
+        elif i.has_key('disable'):
+            result = domainLib.enableOrDisableAccount(domains=domainName, value='disabled',)
+            msg = 'DOMAIN_DISABLED_SUCCESS'
+        elif i.has_key('enable'):
+            result = domainLib.enableOrDisableAccount(domains=domainName, value='active',)
+            msg = 'DOMAIN_ENABLED_SUCCESS'
+        else:
+            msg = i.get('msg', None)
+
+        if result[0] is True:
+            web.seeother('/domains?msg=%s' % msg)
+        else:
+            web.seeother('/domains?msg=%s' % result[1])
 
 class profile(dbinit):
     @base.protected

File controllers/ldap/user.py

         self.mails = i.get('mail', [])
         if i.has_key('delete'):
             result = userLib.delete(domain=self.domain, mails=self.mails,)
+            msg = 'USER_DELETED_SUCCESS'
         elif i.has_key('disable'):
             result = userLib.enableOrDisableAccount(domain=self.domain, mails=self.mails, value='disabled',)
+            msg = 'USER_DISABLED_SUCCESS'
         elif i.has_key('enable'):
             result = userLib.enableOrDisableAccount(domain=self.domain, mails=self.mails, value='active',)
-        web.seeother('/users/%s' % self.domain)
+            msg = 'USER_ENABLED_SUCCESS'
+        else:
+            msg = i.get('msg', None)
+
+        if result[0] is True:
+            web.seeother('/users/%s?msg=%s' % (self.domain, msg))
+        else:
+            web.seeother('/users/%s?msg=%s' % (self.domain, result[1]))
 
 class profile(dbinit):
     @base.protected
                 allDomains = r[1]
             else:
                 return r
+
             return render.user_create(
                     domain=self.domain,
                     username=self.username,

File libs/ldaplib/admin.py

 cfg = web.iredconfig
 session = web.config.get('_session')
 
+LDAPDecorators = core.LDAPDecorators()
+
 class Admin(core.LDAPWrap):
     def __del__(self):
         pass
             else:
                 return result
 
+    @LDAPDecorators.check_global_admin
     def delete(self, mails):
         if mails is None or len(mails) == 0: return (False, 'NO_ACCOUNT_SELECTED')
 
             return (True, 'SUCCESS')
         else:
             return (False, result)
+
+    @LDAPDecorators.check_global_admin
+    def enableOrDisableAccount(self, mails, value, attr='accountStatus',):
+        if mails is None or len(mails) == 0: return (False, 'NO_ACCOUNT_SELECTED')
+
+        result = {}
+        for mail in mails:
+            self.mail = web.safestr(mail)
+            self.dn = ldaputils.convEmailToAdminDN(self.mail)
+
+            try:
+                self.updateAttrSingleValue(
+                        dn=self.dn,
+                        attr=web.safestr(attr),
+                        value=web.safestr(value),
+                        )
+            except ldap.LDAPError, e:
+                result[self.mail] = str(e)
+
+        if result == {}:
+            return (True, 'SUCCESS')
+        else:
+            return (False, result)

File libs/ldaplib/domain.py

         if msg == {}: return True
         else: return False
 
+    @LDAPDecorators.check_global_admin
+    def enableOrDisableAccount(self, domains, value, attr='accountStatus',):
+        if domains is None or len(domains) == 0: return (False, 'NO_DOMAIN_SELECTED')
+
+        result = {}
+        for domain in domains:
+            self.domain = web.safestr(domain)
+            self.dn = ldaputils.convDomainToDN(self.domain)
+
+            try:
+                self.updateAttrSingleValue(
+                        dn=self.dn,
+                        attr=web.safestr(attr),
+                        value=web.safestr(value),
+                        )
+            except ldap.LDAPError, e:
+                result[self.domain] = str(e)
+
+        if result == {}:
+            return (True, 'SUCCESS')
+        else:
+            return (False, result)
+
     # Get domain attributes & values.
     @LDAPDecorators.check_domain_access
     def profile(self, domain):

File libs/ldaplib/user.py

 
     @LDAPDecorators.check_domain_access
     def enableOrDisableAccount(self, domain, mails, value, attr='accountStatus',):
-        if mails is None or len(mails) == 0: return False
+        if mails is None or len(mails) == 0: return (False, 'NO_ACCOUNT_SELECTED')
 
         result = {}
         for mail in mails:
         self.profile_type = web.safestr(profile_type)
         self.mail = web.safestr(mail)
         self.domain = self.mail.split('@', 1)[1]
-        self.dn = ldaputils.convEmailToUserDN(self.mail)
-
-        mod_attrs = []
-        if self.profile_type == 'general':
-            # Get cn.
-    @LDAPDecorators.check_domain_access
-    def update(self, profile_type, mail, data):
-        self.profile_type = web.safestr(profile_type)
-        self.mail = web.safestr(mail)
-        self.domain = self.mail.split('@', 1)[1]
 
         mod_attrs = []
         if self.profile_type == 'general':

File static/default/css/iredadmin.css

     background-color: #8dbdd8;
 }
 */
+
+.brd #footer {
+    text-align: center;
+    margin-top: 20px;
+}

File templates/default/ldap/admins.html

 {# Show system message #}
 {% if msg is defined and msg is not sameas none %}
     <div class="ct-box info-box">
-    {% if msg == 'DELETE_SUCCESS' %}
-        <div class="success">{{ _('Account(s) deleted success.') }}</div>
+    {% if msg == 'ADMIN_DELETED_SUCCESS' %}
+        <div class="success">{{ _('Selected accounts are deleted.') }}</div>
+    {% elif msg == 'ADMIN_DISABLED_SUCCESS' %}
+        <div class="success">{{ _('Selected accounts are diabled.') }}</div>
+    {% elif msg == 'ADMIN_ENABLED_SUCCESS' %}
+        <div class="success">{{ _('Selected accounts are enabled.') }}</div>
     {% else %}
         <div class="error">
         {% if msg == 'NO_ACCOUNT_SELECTED' %}
         <div class="frm-buttons">
             <span class="submit">
                 <input type="checkbox" id="checkall" />{{ _('Select/Unselect all') }}
-                <input type="submit" value="{{ _('Delete') }}" onclick="return confirm('{{ _('Are you sure want to delete selected account(s)?') }}');" }}" />
+                <input type="submit" name="delete" value="{{ _('Delete') }}" onclick="return confirm('{{ _('Are you sure want to delete selected account(s)?') }}');" }}" />
+                <input type="submit" name="disable" value="{{ _('Disable') }}" onclick="return confirm('{{ _('Are you sure want to disable selected account(s)?') }}');" }}" />
+                <input type="submit" name="enable" value="{{ _('Enable') }}" onclick="return confirm('{{ _('Are you sure want to enable selected account(s)?') }}');" }}" />
             </span>
         </div>
     </form>

File templates/default/ldap/dashboard.html

             </div>
         </div>
     </div>
+</div>
 
     {% if netif_data is not sameas none %}
     <div class="main-frm">
                     <span class="fld-input">{{ netif[1]['addr'] }}/{{ netif[1]['netmask'] }}</span>
                 </div>
                 {% endfor %}
+                </div>
             </div>
         </div>
     </div>
     {% endif %}
-
-</div>
 {% endif %}
 
 {% endblock main %}

File templates/default/ldap/domains.html

     <div class="ct-box info-box">
         {% if msg == 'CREATE_SUCCESS' %}
             <div class="success">{{ _('Domain created success.') }}</div>
+        {% elif msg == 'DOMAIN_DELETED_SUCCESS' %}
+            <div class="success">{{ _('Selected domains are deleted.') }}</div>
+        {% elif msg == 'DOMAIN_DISABLED_SUCCESS' %}
+            <div class="success">{{ _('Selected domains are diabled.') }}</div>
+        {% elif msg == 'DOMAIN_ENABLED_SUCCESS' %}
+            <div class="success">{{ _('Selected domains are enabled.') }}</div>
         {% else %}
             <div class="error">
             {% if msg == 'SIZELIMIT_EXCEEDED' %}
         <div class="frm-buttons">
             <span class="submit">
                 <input type="checkbox" id="checkall" />{{ _('Select/Unselect all') }}
-                <input type="submit" value="{{ _('Delete') }}" onclick="return confirm('{{ _('Are you sure want to delete selected domain(s) and accounts under it?') }}');" }}" />
+                <input type="submit" name="delete" value="{{ _('Delete') }}" onclick="return confirm('{{ _('Are you sure want to delete selected domain(s) and accounts under it?') }}');" }}" />
+                <input type="submit" name="disable" value="{{ _('Disable') }}" onclick="return confirm('{{ _('Are you sure want to disable selected domain(s)?') }}');" }}" />
+                <input type="submit" name="enable" value="{{ _('Enable') }}" onclick="return confirm('{{ _('Are you sure want to enable selected domain(s)?') }}');" }}" />
             </span>
         </div>
     {% endif %}

File templates/default/ldap/layout.html

         </div>
 
         {% block footer %}
-        <div id="main-foot" class="gen-content">
+        <div id="footer">
             &copy 2009
             | <a href="http://www.iredmail.org/">iRedMail Project</a>
             {% if session.get('domainGlobalAdmin') == 'yes' %}

File templates/default/ldap/users.html

             {{ _('Invalid profile type: %s.') |format(profile_type) }}
         {% elif msg == 'NO_DOMAIN_AVAILABLE' %}
             {{ _('No mail domain available.') }}
+        {% elif msg == 'ADMIN_DELETED_SUCCESS' %}
+            <div class="success">{{ _('Selected accounts are deleted.') }}</div>
+        {% elif msg == 'ADMIN_DISABLED_SUCCESS' %}
+            <div class="success">{{ _('Selected accounts are diabled.') }}</div>
+        {% elif msg == 'ADMIN_ENABLED_SUCCESS' %}
+            <div class="success">{{ _('Selected accounts are enabled.') }}</div>
         {% else %}
             {{ msg }}
         {% endif %}
 </div>
 {% endif %}
 
-
 {% if users is defined %}
     {# List all users. #}
     <div class="main-frm">
                     <td>{{mail}}</td>
                     <td>{{ employeeid }}</td>
 
-                {# mail quota #}
-                <td>{% if entries.get('mailQuota', ['0'])[0] == '0' %}{{ _('Unlimited') }}{% else %}{{ entries.get('mailQuota', ['0'])[0] |filesizeformat }} {% endif %}</td>
+                    {# mail quota #}
+                    <td>{% if entries.get('mailQuota', ['0'])[0] == '0' %}{{ _('Unlimited') }}{% else %}{{ entries.get('mailQuota', ['0'])[0] |filesizeformat }} {% endif %}</td>
 
-                <td>{{createTimestamp[:4]}}-{{createTimestamp[4:6]}}-{{createTimestamp[6:8]}} {{createTimestamp[8:10]}}:{{createTimestamp[10:12]}}:{{createTimestamp[12:14]}}</td>
-            </tr>
-        {% endfor %}
-    {%endif%}
+                    <td>{{createTimestamp[:4]}}-{{createTimestamp[4:6]}}-{{createTimestamp[6:8]}} {{createTimestamp[8:10]}}:{{createTimestamp[10:12]}}:{{createTimestamp[12:14]}}</td>
+                </tr>
+            {% endfor %}
+        {% endif %}
         </tbody>
     </table>
 
     </div>
 </form>
 </div>
-{%endif%}
+{% endif %}
 {% endblock main %}