app-admin/mmc-agent: Add Userquota & bulkimport module
git-svn-id: https://svn.disconnected-by-peer.at/svn/linamh/trunk/mds@1881 6952d904-891a-0410-993b-d76249ca496b
This commit is contained in:
198
app-admin/mmc-agent/files/mmc-agent-2.3.2-bulkimport-1.patch
Normal file
198
app-admin/mmc-agent/files/mmc-agent-2.3.2-bulkimport-1.patch
Normal file
@@ -0,0 +1,198 @@
|
||||
Submitted By: Mario Fetka (geos_one) (mario dot fetka at gmail dot com)
|
||||
Date: 2010-01-29
|
||||
Initial Package Version: 2.3.2
|
||||
Origin: https://ml.mandriva.net/wws/arc/mds-devel/2010-01/msg00004.html
|
||||
Upstream Status: unknown
|
||||
Description: Add the bulk user import module
|
||||
|
||||
diff -Naur mmc-agent-2.3.2.orig/conf/plugins/bulkimport.ini mmc-agent-2.3.2/conf/plugins/bulkimport.ini
|
||||
--- mmc-agent-2.3.2.orig/conf/plugins/bulkimport.ini 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ mmc-agent-2.3.2/conf/plugins/bulkimport.ini 2010-01-24 23:03:45.000000000 +0000
|
||||
@@ -0,0 +1,2 @@
|
||||
+[main]
|
||||
+disable = 0
|
||||
diff -Naur mmc-agent-2.3.2.orig/contrib/bulkimport/README mmc-agent-2.3.2/contrib/bulkimport/README
|
||||
--- mmc-agent-2.3.2.orig/contrib/bulkimport/README 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ mmc-agent-2.3.2/contrib/bulkimport/README 2010-01-24 23:50:03.000000000 +0000
|
||||
@@ -0,0 +1,120 @@
|
||||
+Description:
|
||||
+
|
||||
+The bulk user management tool has been designed as a plugin for MDS. It reads a CSV file and then imports, deletes
|
||||
+and modifies user attributes for each user in the CSV file. It does this using a two step process and performs all the
|
||||
+changes while the user waits for the page to refresh.
|
||||
+
|
||||
+For each record, it calls the appropriate methods in the user base module of mmc (python back end).
|
||||
+
|
||||
+Installation:
|
||||
+The following changes are needed to mmc:
|
||||
+
|
||||
+1. Bug fix in PageGenerator, this has already been fixed up stream, but if not, apply the patch.
|
||||
+2. Add in a require to page generator and add menu item to sidebar of user plugin.
|
||||
+
|
||||
+
|
||||
+Apply patches from: bulkuserimport.patch
|
||||
+Apply patch, with
|
||||
+
|
||||
+cd /usr/share/mmc
|
||||
+patch -p1 < /tmp/bulkuserimport.patch
|
||||
+
|
||||
+Patched versions of the following files are included, but not needed if you apply the patch above:
|
||||
+./mmc-web/main.php
|
||||
+./mmc-web/modules/base/users/localSidebar.php
|
||||
+./mmc-web/includes/PageGenerator.php
|
||||
+
|
||||
+
|
||||
+The following files need to be installed:
|
||||
+cp -r ./mmc-web/modules/csvimport /usr/share/mmc/modules
|
||||
+cp ./etc/mmc/plugins/csvimport.ini /etc/mmc/plugins/
|
||||
+cp -r ./mmc-python/plugins/csvimport /usr/lib64/python2.6/site-packages/mmc/plugins/
|
||||
+
|
||||
+Restart mmc-agent after copying files.
|
||||
+
|
||||
+Usage:
|
||||
+
|
||||
+CSV Formatting:
|
||||
+
|
||||
+Delimiator: ,
|
||||
+Wrapper: "
|
||||
+Escape characture: \
|
||||
+
|
||||
+CSV Header requirements:
|
||||
+
|
||||
+Required attribute: "login"
|
||||
+Require for import: "password","firstname","surname"
|
||||
+Additional headers can be set and must match the attribute name in ldap, for example:
|
||||
+"login","password","firstname","surname","primarygroup","mail"
|
||||
+
|
||||
+Special attributes
|
||||
+
|
||||
+The following can be set to: yes or no.
|
||||
+createhomedir (yes by default)
|
||||
+files (default set to yes for delete operation, users home directory will be removed.)
|
||||
+
|
||||
+Defaults
|
||||
+
|
||||
+homdir (homedir/username by default)
|
||||
+primaryGroup (default primary group as per base.ini plugin config)
|
||||
+
|
||||
+Currently supported attributes are:
|
||||
+
|
||||
+ * audio
|
||||
+ * carLicense
|
||||
+ * departmentNumber
|
||||
+ * description
|
||||
+ * files
|
||||
+ * firstname
|
||||
+ * gecos
|
||||
+ * localityName
|
||||
+ * login
|
||||
+ * loginShell
|
||||
+ * mail
|
||||
+ * manager
|
||||
+ * mobile
|
||||
+ * organizationName
|
||||
+ * pager
|
||||
+ * password
|
||||
+ * physicalDeliveryOfficeName
|
||||
+ * postalAddress
|
||||
+ * postalCode
|
||||
+ * preferredLanguage
|
||||
+ * primarygroup
|
||||
+ * roomNumber
|
||||
+ * surname
|
||||
+ * telephoneNumber
|
||||
+ * title
|
||||
+
|
||||
+Examples CSV file contents. Create some users:
|
||||
+
|
||||
+"firstname","surname","mail","login","password","telephoneNumber","localityName"
|
||||
+"User1","Last1","user1@example.com","user1","test1",,"Auckland"
|
||||
+"User2","Last2","user2@example.com","user2","test2",,"Auckland"
|
||||
+"User3","Last3","user3@example.com","user3","test3",,"Auckland"
|
||||
+
|
||||
+Modify the mail and loginShell attributes:
|
||||
+
|
||||
+"mail","login","loginShell"
|
||||
+"user1@oss.co.nz","user1","/bin/bash"
|
||||
+"user2@oss.co.nz","user2","/bin/zsh"
|
||||
+"user3@oss.co.nz","user3","/bin/zsh"
|
||||
+
|
||||
+Delete some users:
|
||||
+
|
||||
+"login"
|
||||
+"user1"
|
||||
+"user2"
|
||||
+
|
||||
+Generating user login names, email addresses, etc.
|
||||
+
|
||||
+This tool does not generate data for you. To generate data from a list of names, use functions in OpenOffice Calc, for example, to generate the
|
||||
+email address, use the function:
|
||||
+
|
||||
+=CONCATENATE(a1,"@example.com")
|
||||
+
|
||||
+and for user names:
|
||||
+
|
||||
+=LOWER(CONCATENATE(LEFT(B1),MID(C1,1,5)))
|
||||
+where B1 is first name, C1 is Last name.
|
||||
+
|
||||
diff -Naur mmc-agent-2.3.2.orig/mmc/plugins/bulkimport/__init__.py mmc-agent-2.3.2/mmc/plugins/bulkimport/__init__.py
|
||||
--- mmc-agent-2.3.2.orig/mmc/plugins/bulkimport/__init__.py 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ mmc-agent-2.3.2/mmc/plugins/bulkimport/__init__.py 2010-01-29 15:57:48.381422910 +0000
|
||||
@@ -0,0 +1,47 @@
|
||||
+# -*- coding: utf-8; -*-
|
||||
+#
|
||||
+# (c) 2009 Open Systems Specilists - Glen Ogilvie
|
||||
+#
|
||||
+# $Id: __init__.py 743 2008-12-15 14:20:35Z cdelfosse $
|
||||
+#
|
||||
+# This file is part of Mandriva Management Console (MMC).
|
||||
+#
|
||||
+# MMC 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 2 of the License, or
|
||||
+# (at your option) any later version.
|
||||
+#
|
||||
+# MMC 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 MMC; if not, write to the Free Software
|
||||
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+
|
||||
+import socket
|
||||
+import ldap
|
||||
+import logging
|
||||
+import os
|
||||
+import os.path
|
||||
+import grp
|
||||
+
|
||||
+from mmc.plugins.base import ldapUserGroupControl
|
||||
+from mmc.support.config import *
|
||||
+from mmc.support import mmctools
|
||||
+import mmc
|
||||
+
|
||||
+INI = "/etc/mmc/plugins/bulkimport.ini"
|
||||
+
|
||||
+VERSION = "0.0.1"
|
||||
+APIVERSION = "1:0:0"
|
||||
+REVISION = int("$Rev: 1 $".split(':')[1].strip(' $'))
|
||||
+
|
||||
+def getVersion(): return VERSION
|
||||
+def getApiVersion(): return APIVERSION
|
||||
+def getRevision(): return REVISION
|
||||
+
|
||||
+
|
||||
+def activate():
|
||||
+ return True
|
||||
diff -Naur mmc-agent-2.3.2.orig/setup.py mmc-agent-2.3.2/setup.py
|
||||
--- mmc-agent-2.3.2.orig/setup.py 2010-01-29 15:56:43.394175082 +0000
|
||||
+++ mmc-agent-2.3.2/setup.py 2010-01-29 16:00:13.916426330 +0000
|
||||
@@ -8,5 +8,5 @@
|
||||
author_email = "cdelfosse@mandriva.com",
|
||||
maintainer = "Cedric Delfosse",
|
||||
maintainer_email = "cdelfosse@mandriva.com",
|
||||
- packages = ["mmc", "mmc.support", "mmc.plugins", "mmc.plugins.base", "mmc.plugins.samba", "mmc.plugins.proxy", "mmc.plugins.mail", "mmc.plugins.network", "mmc.plugins.kerberos", "mmc.plugins.printstats", "mmc.plugins.printing", "mmc.plugins.userquota"],
|
||||
+ packages = ["mmc", "mmc.support", "mmc.plugins", "mmc.plugins.base", "mmc.plugins.samba", "mmc.plugins.proxy", "mmc.plugins.mail", "mmc.plugins.network", "mmc.plugins.kerberos", "mmc.plugins.printstats", "mmc.plugins.printing", "mmc.plugins.userquota", "mmc.plugins.bulkimport"],
|
||||
)
|
||||
676
app-admin/mmc-agent/files/mmc-agent-2.3.2-userquota-1.patch
Normal file
676
app-admin/mmc-agent/files/mmc-agent-2.3.2-userquota-1.patch
Normal file
@@ -0,0 +1,676 @@
|
||||
Submitted By: Mario Fetka (geos_one) (mario dot fetka at gmail dot com)
|
||||
Date: 2010-01-29
|
||||
Initial Package Version: 2.3.2
|
||||
Origin: https://ml.mandriva.net/wws/arc/mds-devel/2010-01/msg00007.html
|
||||
Upstream Status: unknown
|
||||
Description: Add the userquota plugin
|
||||
|
||||
diff -Naur mmc-agent-2.3.2.orig/conf/plugins/userquota.ini mmc-agent-2.3.2/conf/plugins/userquota.ini
|
||||
--- mmc-agent-2.3.2.orig/conf/plugins/userquota.ini 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ mmc-agent-2.3.2/conf/plugins/userquota.ini 2010-01-15 06:19:24.000000000 +0000
|
||||
@@ -0,0 +1,19 @@
|
||||
+[main]
|
||||
+disable = 0
|
||||
+
|
||||
+[diskquota]
|
||||
+enable = 1
|
||||
+# block size found using dumpe2fs -h /dev/vda1 | awk '/Block size:/ { print $3 }'
|
||||
+
|
||||
+# devicemap format: device:blocksize:displayname, ...
|
||||
+devicemap = /dev/vda1:4096:Test Root,/dev/mapper/home:4096:Home dir
|
||||
+softquotablocks = 0.95
|
||||
+softquotainodes = 0.95
|
||||
+inodesperblock = 1.60
|
||||
+
|
||||
+setquotascript = echo /usr/sbin/setquota $uid $softblocks $blocks $softinodes $inodes $devicepath
|
||||
+delquotascript = echo /usr/sbin/setquota $uid 0 0 0 0 $devicepath
|
||||
+
|
||||
+[networkquota]
|
||||
+enable = 1
|
||||
+networkmap = Internet:0.0.0.0/0:any
|
||||
diff -Naur mmc-agent-2.3.2.orig/contrib/ldap/quota.schema mmc-agent-2.3.2/contrib/ldap/quota.schema
|
||||
--- mmc-agent-2.3.2.orig/contrib/ldap/quota.schema 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ mmc-agent-2.3.2/contrib/ldap/quota.schema 2010-01-25 02:16:23.000000000 +0000
|
||||
@@ -0,0 +1,30 @@
|
||||
+##
|
||||
+## schema file for Unix Quotas
|
||||
+## Schema for storing Unix Quotas in LDAP
|
||||
+## OIDs are owned by Cogent Innovators, LLC
|
||||
+##
|
||||
+## 1.3.6.1.4.1.19937.1.1.x - attributetypes
|
||||
+## 1.3.6.1.4.1.19937.1.2.x - objectclasses
|
||||
+##
|
||||
+
|
||||
+attributetype ( 1.3.6.1.4.1.19937.1.1.1 NAME 'quota'
|
||||
+ DESC 'Quotas (FileSystem:BlocksSoft,BlocksHard,InodesSoft,InodesHard)'
|
||||
+ EQUALITY caseIgnoreIA5Match
|
||||
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} )
|
||||
+
|
||||
+attributetype ( 1.3.6.1.4.1.19937.1.1.2 NAME 'networkquota'
|
||||
+ DESC 'Network Quotas (network,protocol,bytes)'
|
||||
+ EQUALITY caseIgnoreIA5Match
|
||||
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} )
|
||||
+
|
||||
+objectclass ( 1.3.6.1.4.1.19937.1.2.1 NAME 'systemQuotas' SUP posixAccount AUXILIARY
|
||||
+ DESC 'System Quotas'
|
||||
+ MUST ( uid )
|
||||
+ MAY ( quota $ networkquota ))
|
||||
+
|
||||
+objectclass ( 1.3.6.1.4.1.19937.1.2.2 NAME 'defaultQuotas'
|
||||
+ DESC 'Quota defaults to apply to members of a group'
|
||||
+ SUP top AUXILIARY
|
||||
+ MUST ( cn )
|
||||
+ MAY ( quota $ networkquota ))
|
||||
+
|
||||
diff -Naur mmc-agent-2.3.2.orig/contrib/userquota/README mmc-agent-2.3.2/contrib/userquota/README
|
||||
--- mmc-agent-2.3.2.orig/contrib/userquota/README 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ mmc-agent-2.3.2/contrib/userquota/README 2010-01-26 00:41:24.000000000 +0000
|
||||
@@ -0,0 +1,51 @@
|
||||
+# (c) 2009 OSS - Glen Ogilvie
|
||||
+# License: GPLv2 or above
|
||||
+
|
||||
+Description: Mandriva Directory Server plugin to store disk and network quotas in OpenLDAP and manage them
|
||||
+using MDS. It provides multiple quotas for both, mapped from the configuration file. It also supports turning
|
||||
+off either disk or network quotas if you only wish to quota one of them.
|
||||
+
|
||||
+This plugin also supports setting quotas for all the members of a group. This can be done by browsing to the
|
||||
+group list in MDS and using the edit group action. It also allows you to set quotas per individual, although these
|
||||
+are reset when you perform a group action.
|
||||
+
|
||||
+When quotas are set for a member of the group, the object classes of that member will be updated to include the systemQuotas schema.
|
||||
+The group will also have an additional object class added to store the defaults for that group.
|
||||
+
|
||||
+New members of the group do not currently get the group default quotas assigned but may do in the future.
|
||||
+
|
||||
+
|
||||
+Installation:
|
||||
+cp ./etc/mmc/plugins/userquota.ini /etc/mmc/plugins/
|
||||
+cp -r ./mmc-python/plugins/userquota /usr/lib64/python2.6/site-packages/mmc/plugins/
|
||||
+cp -r ./mmc-web/modules/userquota /usr/share/mmc/modules/
|
||||
+cp ./etc/openldap/schema/quota.schema /etc/openldap/schema
|
||||
+
|
||||
+Edit: /etc/openldap/schema/local.schema
|
||||
+insert line: include /etc/openldap/schema/quota.schema
|
||||
+restart slapd.
|
||||
+
|
||||
+Configuration:
|
||||
+Edit: /etc/mmc/plugins/userquota.ini
|
||||
+
|
||||
+Configuration options: diskquota
|
||||
+devicemap
|
||||
+ - This maps your physical device that will have the quota applied to a nice human readable name and also includes the block size of the disk
|
||||
+ used for calculation of megabytes.
|
||||
+
|
||||
+softquotablocks, softquotainodes, inodesperblock
|
||||
+ - multipliers for the values passed to the quota command.
|
||||
+
|
||||
+setquotascript, delquotascript
|
||||
+ - system command to run.. Note that in example, these are echo statements so they do nothing
|
||||
+
|
||||
+Configuration options: networkquota
|
||||
+networkmap
|
||||
+ - this maps the name of a network to a subnet and protocol. How the subnet and protocol are processed is up to whatever is reading the network
|
||||
+ - quota values from each user. In my case, a custom script will read these and use them with TC for rate limiting.
|
||||
+
|
||||
+Documentation:
|
||||
+@todo
|
||||
+
|
||||
+Bugs:
|
||||
+Currently, when network operations on large groups are done, an ldap error is presented part way thru the operation. I have not yet discovered why.
|
||||
diff -Naur mmc-agent-2.3.2.orig/mmc/plugins/userquota/__init__.py mmc-agent-2.3.2/mmc/plugins/userquota/__init__.py
|
||||
--- mmc-agent-2.3.2.orig/mmc/plugins/userquota/__init__.py 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ mmc-agent-2.3.2/mmc/plugins/userquota/__init__.py 2010-01-28 20:52:43.000000000 +0000
|
||||
@@ -0,0 +1,543 @@
|
||||
+# -*- coding: utf-8; -*-
|
||||
+# (c) 2009 Open Systems Specilists - Glen Ogilvie
|
||||
+#
|
||||
+# $Id: __init__.py $
|
||||
+#
|
||||
+# This file is a plugin for Mandriva Management Console (MMC).
|
||||
+#
|
||||
+# MMC 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 2 of the License, or
|
||||
+# (at your option) any later version.
|
||||
+#
|
||||
+# MMC 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 MMC; if not, write to the Free Software
|
||||
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+
|
||||
+import socket
|
||||
+import ldap
|
||||
+import logging
|
||||
+import os
|
||||
+import os.path
|
||||
+import grp
|
||||
+
|
||||
+from mmc.plugins.base import ldapUserGroupControl
|
||||
+from mmc.support.config import *
|
||||
+from mmc.support import mmctools
|
||||
+from string import Template
|
||||
+
|
||||
+
|
||||
+import mmc
|
||||
+
|
||||
+INI = "/etc/mmc/plugins/userquota.ini"
|
||||
+
|
||||
+VERSION = "0.0.2"
|
||||
+APIVERSION = "1:0:0"
|
||||
+REVISION = int("$Rev: 1 $".split(':')[1].strip(' $'))
|
||||
+
|
||||
+def getVersion(): return VERSION
|
||||
+def getApiVersion(): return APIVERSION
|
||||
+def getRevision(): return REVISION
|
||||
+
|
||||
+
|
||||
+def activate():
|
||||
+ return True
|
||||
+
|
||||
+def getActiveComponents():
|
||||
+ return UserQuotaControl().getActiveComponents()
|
||||
+
|
||||
+def getDevicemap():
|
||||
+ return UserQuotaControl().getDevicemap()
|
||||
+
|
||||
+def getNetworkmap():
|
||||
+ return UserQuotaControl().getNetworkmap()
|
||||
+
|
||||
+def setDiskQuota(uid, device, quota):
|
||||
+ return UserQuotaControl().setDiskQuota(uid, device, quota)
|
||||
+
|
||||
+def setNetworkQuota(uid, network, quota):
|
||||
+ return UserQuotaControl().setNetworkQuota(uid, network, quota)
|
||||
+
|
||||
+def setGroupDiskQuota(group, device, quota, overwrite):
|
||||
+ return UserQuotaControl().setGroupDiskQuota(group, device, quota, overwrite)
|
||||
+
|
||||
+def deleteGroupDiskQuota(cn, device):
|
||||
+ return UserQuotaControl().deleteGroupDiskQuotas(cn, device)
|
||||
+
|
||||
+def setGroupNetworkQuota(group, network, quota, overwrite):
|
||||
+ return UserQuotaControl().setGroupNetworkQuota(group, network, quota, overwrite)
|
||||
+
|
||||
+def deleteGroupNetworkQuota(cn, device):
|
||||
+ return UserQuotaControl().deleteGroupNetworkQuotas(cn, device)
|
||||
+
|
||||
+
|
||||
+def deleteDiskQuota(uid, device):
|
||||
+ return UserQuotaControl().deleteDiskQuota(uid, device)
|
||||
+
|
||||
+def deleteNetworkQuota(uid, network):
|
||||
+ return UserQuotaControl().deleteNetworkQuota(uid, network)
|
||||
+
|
||||
+def setUserQuotaDefaults(user, group):
|
||||
+ return UserQuotaControl().setUserQuotaDefaults(user, group)
|
||||
+
|
||||
+class UserQuotaConfig(PluginConfig):
|
||||
+
|
||||
+ def readConf(self):
|
||||
+ PluginConfig.readConf(self)
|
||||
+ try: self.diskquotaenable = self.getboolean("diskquota", "enable")
|
||||
+ except: pass
|
||||
+ try: self.networkquotaenable = self.getboolean("networkquota", "enable")
|
||||
+ except: pass
|
||||
+ self.devicemap = self.get("diskquota", "devicemap").split(',')
|
||||
+ self.inodesperblock = self.getfloat("diskquota", "inodesperblock")
|
||||
+ self.softquotablocks = self.getfloat("diskquota", "softquotablocks")
|
||||
+ self.softquotainodes = self.getfloat("diskquota", "softquotainodes")
|
||||
+ self.setquotascript = self.get("diskquota", "setquotascript")
|
||||
+ self.delquotascript = self.get("diskquota", "delquotascript")
|
||||
+ self.networkmap = self.get("networkquota", "networkmap").split(',')
|
||||
+
|
||||
+ def setDefault(self):
|
||||
+ PluginConfig.setDefault(self)
|
||||
+ self.diskquotaenable = True
|
||||
+ self.networkquotaenable = False
|
||||
+
|
||||
+
|
||||
+class UserQuotaControl(ldapUserGroupControl):
|
||||
+ def __init__(self, conffile=None, conffilebase=None):
|
||||
+ mmc.plugins.base.ldapUserGroupControl.__init__(self, conffilebase)
|
||||
+ self.configuserquota = UserQuotaConfig("userquota", conffile)
|
||||
+ def getDevicemap(self):
|
||||
+ return self.configuserquota.devicemap
|
||||
+ def getNetworkmap(self):
|
||||
+ return self.configuserquota.networkmap
|
||||
+ def getActiveComponents(self):
|
||||
+ return ({"disk":self.configuserquota.diskquotaenable, "network":self.configuserquota.networkquotaenable})
|
||||
+
|
||||
+ def deleteNetworkQuota(self, uid, network):
|
||||
+ logger = logging.getLogger()
|
||||
+ try:
|
||||
+ currentquotas = self.getDetailedUser(uid)["networkquota"]
|
||||
+ newquotas = []
|
||||
+ for x in currentquotas:
|
||||
+ if not x.split(',')[0] == network:
|
||||
+ newquotas.append(x)
|
||||
+
|
||||
+ if len(newquotas) == 0:
|
||||
+ self.changeUserAttributes(uid, 'networkquota', None)
|
||||
+ self.delQuotaObjectClass(uid)
|
||||
+
|
||||
+ else:
|
||||
+ self.changeUserAttributes(uid, 'networkquota', newquotas)
|
||||
+
|
||||
+ except KeyError:
|
||||
+ pass
|
||||
+ return True
|
||||
+
|
||||
+ def deleteDiskQuota(self, uid, device):
|
||||
+ logger = logging.getLogger()
|
||||
+# logger.info("Deleting quota for: "+ uid)
|
||||
+ devicepath = device.split(':')[0]
|
||||
+ try:
|
||||
+ currentquotas = self.getDetailedUser(uid)["quota"]
|
||||
+ newquotas = []
|
||||
+ for x in currentquotas:
|
||||
+ if not x.split('=')[0] == devicepath:
|
||||
+ newquotas.append(x)
|
||||
+
|
||||
+ if len(newquotas) == 0:
|
||||
+ self.changeUserAttributes(uid, 'quota', None)
|
||||
+ self.delQuotaObjectClass(uid)
|
||||
+
|
||||
+ else:
|
||||
+ self.changeUserAttributes(uid, 'quota', newquotas)
|
||||
+
|
||||
+ self.deleteQuotaOnFS(uid, devicepath)
|
||||
+
|
||||
+ except KeyError:
|
||||
+ pass
|
||||
+
|
||||
+ return True
|
||||
+
|
||||
+
|
||||
+ def setNetworkQuota(self, uid, network, quota, overwrite = "all"):
|
||||
+ logger = logging.getLogger()
|
||||
+ ldapquota = '%s,%s' % (network, str(int(quota) * 1048576))
|
||||
+ logger.info("Network Quota:" + ldapquota)
|
||||
+
|
||||
+ if not self.hasDiskQuotaObjectClass(uid):
|
||||
+ self.addDiskQuotaObjectClass(uid)
|
||||
+ # @todo, fix copy from disk quotas.
|
||||
+ try:
|
||||
+ userdetails = self.getDetailedUser(uid)
|
||||
+ currentquotas = userdetails["networkquota"]
|
||||
+ newquotas = []
|
||||
+ quotachanged = False
|
||||
+ for x in currentquotas:
|
||||
+ if x.split(',')[0] == network:
|
||||
+ logger.info("Current network quota sizes: " + str(self.convertNetworkQuotaToMB(x)))
|
||||
+ logger.info("Requested quota size: " + quota)
|
||||
+ logger.info("Overwrite mode: " + overwrite)
|
||||
+ if (overwrite == "none"):
|
||||
+ return False
|
||||
+ if overwrite == "smaller" and self.convertNetworkQuotaToMB(x) > int(quota):
|
||||
+ logger.info('Current network quota is bigger than new quota, so not overwriting')
|
||||
+ return False
|
||||
+ if overwrite == "larger" and int(quota) > self.convertNetworkQuotaToMB(x):
|
||||
+ logger.info('Current network quota is smaller than new quota, so not overwriting')
|
||||
+ return False
|
||||
+ newquotas.append(ldapquota)
|
||||
+ quotachanged = True
|
||||
+ else:
|
||||
+ newquotas.append(x)
|
||||
+
|
||||
+ if not quotachanged:
|
||||
+ newquotas.append(ldapquota)
|
||||
+
|
||||
+ self.changeUserAttributes(uid, 'networkquota', newquotas)
|
||||
+ except KeyError:
|
||||
+ self.changeUserAttributes(uid, 'networkquota', ldapquota)
|
||||
+ pass
|
||||
+
|
||||
+ return True
|
||||
+
|
||||
+ def setDiskQuota(self, uid, device, quota, overwrite = "all"):
|
||||
+ logger = logging.getLogger()
|
||||
+ logger.info("received quota for " + uid + ", device: " + device + ", size: " + quota)
|
||||
+ blocks = self.convertMBtoBlocks(quota, device);
|
||||
+ softblocks = int (blocks * self.configuserquota.softquotablocks)
|
||||
+ inodes = int(blocks * self.configuserquota.inodesperblock)
|
||||
+ softinodes = int(inodes * self.configuserquota.softquotainodes)
|
||||
+ devicepath = device.split(':')[0]
|
||||
+# logger.info("Devicepath: " + devicepath)
|
||||
+# logger.info("Blocks: " + str(blocks))
|
||||
+# logger.info("Soft Blocks: " + str(softblocks))
|
||||
+# logger.info("Inodes: " + str(inodes))
|
||||
+# logger.info("Soft Inodes: " + str(softinodes))
|
||||
+ self.applyQuotaToFS(uid, blocks, softblocks, inodes, softinodes, devicepath)
|
||||
+ ldapquota = '%s=%s:%s:%s:%s' % (devicepath, str(blocks), str(softblocks), str(inodes), str(softinodes))
|
||||
+ logger.info("Quota for: " + uid + " - " + ldapquota)
|
||||
+
|
||||
+ if not self.hasDiskQuotaObjectClass(uid):
|
||||
+ self.addDiskQuotaObjectClass(uid)
|
||||
+
|
||||
+ try:
|
||||
+ userdetails = self.getDetailedUser(uid)
|
||||
+ currentquotas = userdetails["quota"]
|
||||
+ newquotas = []
|
||||
+ quotachanged = False
|
||||
+ for x in currentquotas:
|
||||
+ if x.split('=')[0] == devicepath:
|
||||
+ logger.info("Current network quota sizes: " + str(self.convertDiskQuotaToMB(x)))
|
||||
+ logger.info("Requested quota size: " + quota)
|
||||
+ logger.info("Overwrite mode: " + overwrite)
|
||||
+ if overwrite == "none":
|
||||
+ return False
|
||||
+ if overwrite == "smaller" and self.convertDiskQuotaToMB(x) > int(quota):
|
||||
+ logger.info('Current quota is bigger than new quota, so not overwriting')
|
||||
+ return False
|
||||
+ if overwrite == "larger" and int(quota) > self.convertDiskQuotaToMB(x):
|
||||
+ logger.info('Current quota is smaller than new quota, so not overwriting')
|
||||
+ return False
|
||||
+
|
||||
+ newquotas.append(ldapquota)
|
||||
+ quotachanged = True
|
||||
+ else:
|
||||
+ newquotas.append(x)
|
||||
+
|
||||
+ if not quotachanged:
|
||||
+ newquotas.append(ldapquota)
|
||||
+
|
||||
+ self.changeUserAttributes(uid, 'quota', newquotas)
|
||||
+ except KeyError:
|
||||
+ self.changeUserAttributes(uid, 'quota', ldapquota)
|
||||
+ pass
|
||||
+
|
||||
+ return True
|
||||
+
|
||||
+ def applyQuotaToFS(self, uid, blocks, softblocks, inodes, softinodes, devicepath):
|
||||
+ logger = logging.getLogger()
|
||||
+ s = Template(self.configuserquota.setquotascript)
|
||||
+ shellscript = s.substitute(uid=uid, blocks=blocks, softblocks=softblocks, inodes=inodes, softinodes=softinodes, devicepath=devicepath)
|
||||
+ logger.info("SetQuotaScript: " + shellscript);
|
||||
+ def cb(shprocess):
|
||||
+ # The callback just return the process outputs
|
||||
+ logger.info("shell result:" + shprocess.out)
|
||||
+ return shprocess.exitCode, shprocess.out, shprocess.err
|
||||
+ d = mmctools.shLaunchDeferred(shellscript)
|
||||
+ # shLaunchDeferred returns a Deferred() object
|
||||
+ # We add the cb function as a callback
|
||||
+ d.addCallback(cb)
|
||||
+ # We return the Deferred() object
|
||||
+ return d
|
||||
+
|
||||
+ def deleteQuotaOnFS(self, uid, devicepath):
|
||||
+ logger = logging.getLogger()
|
||||
+ s = Template(self.configuserquota.delquotascript)
|
||||
+ shellscript = s.substitute(uid=uid, devicepath=devicepath)
|
||||
+ logger.info("DelQuotaScript: " + shellscript);
|
||||
+ def cb(shprocess):
|
||||
+ # The callback just return the process outputs
|
||||
+ logger.info("shell result:" + shprocess.out)
|
||||
+ return shprocess.exitCode, shprocess.out, shprocess.err
|
||||
+ d = mmctools.shLaunchDeferred(shellscript)
|
||||
+ # shLaunchDeferred returns a Deferred() object
|
||||
+ # We add the cb function as a callback
|
||||
+ d.addCallback(cb)
|
||||
+ # We return the Deferred() object
|
||||
+ return d
|
||||
+
|
||||
+ def convertMBtoBlocks(self, quota, device):
|
||||
+ parts = device.split(':')
|
||||
+ blocks = int(parts[1])
|
||||
+ bytes = int(quota) * 1048576
|
||||
+ return int(bytes / blocks)
|
||||
+
|
||||
+ def convertNetworkQuotaToMB(self, quota):
|
||||
+ return int(quota.split(',')[1])/1048576
|
||||
+
|
||||
+ def convertDiskQuotaToMB(self,quota):
|
||||
+ devicemap = self.getDevicemap()
|
||||
+ devicepath = quota.split('=')[0]
|
||||
+ for x in devicemap:
|
||||
+ if x.split(':')[0] == devicepath:
|
||||
+ return int(quota.split('=')[1].split(":")[0]) * int(x.split(':')[1]) / 1048576
|
||||
+ return False
|
||||
+
|
||||
+
|
||||
+ def hasDiskQuotaObjectClass(self, uid):
|
||||
+ """
|
||||
+ Return true if the user owns the systemQuotas objectClass.
|
||||
+
|
||||
+ @param uid: user name
|
||||
+ @type uid: str
|
||||
+
|
||||
+ @return: return True if the user owns the mailAccount objectClass.
|
||||
+ @rtype: boolean
|
||||
+ """
|
||||
+ return "systemQuotas" in self.getDetailedUser(uid)["objectClass"]
|
||||
+
|
||||
+ def delQuotaObjectClass(self, uid):
|
||||
+ """
|
||||
+ Return true if the objectClass is removed.
|
||||
+
|
||||
+ @return: return True if the object class is able to be removed
|
||||
+ @rtype: boolean
|
||||
+ """
|
||||
+ logger = logging.getLogger()
|
||||
+ user = self.getDetailedUser(uid)
|
||||
+ logger.info("Del object class")
|
||||
+
|
||||
+ if "quota" in user.keys() or "networkquota" in user.keys():
|
||||
+ return False
|
||||
+
|
||||
+ logger.info("Del object class removal")
|
||||
+ if "systemQuotas" in user["objectClass"]:
|
||||
+ user["objectClass"].remove("systemQuotas")
|
||||
+ self.changeUserAttributes(uid, 'objectClass', user["objectClass"])
|
||||
+ return True
|
||||
+ return False
|
||||
+
|
||||
+ def delGroupQuotaObjectClass(self, cn):
|
||||
+ """
|
||||
+ Return true if the objectClass is removed.
|
||||
+
|
||||
+ @return: return True if the object class is able to be removed
|
||||
+ @rtype: boolean
|
||||
+ """
|
||||
+ logger = logging.getLogger()
|
||||
+ group = self.getDetailedGroup(cn)
|
||||
+ logger.info("Del Group object class")
|
||||
+ logger.info("group keys" + str(group.keys()))
|
||||
+ if "quota" in group.keys() or "networkquota" in group.keys():
|
||||
+ return False
|
||||
+
|
||||
+ logger.info("Del object class removal")
|
||||
+ if "defaultQuotas" in group["objectClass"]:
|
||||
+ group["objectClass"].remove("defaultQuotas")
|
||||
+ logger.info("ObjectClass to save:" + str( group["objectClass"]) )
|
||||
+ self.changeGroupAttribute(cn, 'objectClass', group["objectClass"])
|
||||
+ return True
|
||||
+ return False
|
||||
+
|
||||
+ def addDiskQuotaObjectClass(self, uid):
|
||||
+ user = self.getDetailedUser(uid)['objectClass']
|
||||
+ if not "systemQuotas" in user:
|
||||
+ user.append("systemQuotas")
|
||||
+ self.l.modify_s('uid=' + uid + ',' + self.baseUsersDN, [(ldap.MOD_REPLACE, 'objectClass', user)])
|
||||
+ return True
|
||||
+
|
||||
+
|
||||
+ def setGroupDiskQuota(self, group, device, quota, overwrite):
|
||||
+ logger = logging.getLogger()
|
||||
+ logger.info("SetGroupDiskQuota: Overwrite mode: " + overwrite)
|
||||
+ logger.info("ldap timeout:" + str(self.l.timeout))
|
||||
+ self.l.set_option(ldap.OPT_NETWORK_TIMEOUT, 100)
|
||||
+ logger.info("ldap network timeout:" + str(self.l.get_option(ldap.OPT_NETWORK_TIMEOUT)))
|
||||
+
|
||||
+
|
||||
+ self.addGroupDefaultDiskQuotaObjectClass(group)
|
||||
+
|
||||
+ blocks = self.convertMBtoBlocks(quota, device);
|
||||
+ softblocks = int (blocks * self.configuserquota.softquotablocks)
|
||||
+ inodes = int(blocks * self.configuserquota.inodesperblock)
|
||||
+ softinodes = int(inodes * self.configuserquota.softquotainodes)
|
||||
+ devicepath = device.split(':')[0]
|
||||
+ ldapquota = '%s=%s:%s:%s:%s' % (devicepath, str(blocks), str(softblocks), str(inodes), str(softinodes))
|
||||
+ # @todo improve this, it's a copy of set disk quota.
|
||||
+ try:
|
||||
+ currentquotas = self.getDetailedGroup(group)["quota"]
|
||||
+ newquotas = []
|
||||
+ quotachanged = False
|
||||
+ for x in currentquotas:
|
||||
+ if x.split('=')[0] == devicepath:
|
||||
+ newquotas.append(ldapquota)
|
||||
+ quotachanged = True
|
||||
+ else:
|
||||
+ newquotas.append(x)
|
||||
+
|
||||
+ if not quotachanged:
|
||||
+ newquotas.append(ldapquota)
|
||||
+
|
||||
+ self.changeGroupAttribute(group, "quota", newquotas)
|
||||
+
|
||||
+ except KeyError:
|
||||
+ self.changeGroupAttribute(group, "quota", ldapquota)
|
||||
+ pass
|
||||
+
|
||||
+
|
||||
+ for uid in self.getMembers(group):
|
||||
+ self.setDiskQuota(uid, device, quota, overwrite)
|
||||
+
|
||||
+
|
||||
+ return True
|
||||
+
|
||||
+ def setGroupNetworkQuota(self, group, network, quota, overwrite):
|
||||
+ logger = logging.getLogger()
|
||||
+ logger.info("SetGroupNetworkQuota Overwrite mode: " + overwrite)
|
||||
+ self.addGroupDefaultDiskQuotaObjectClass(group)
|
||||
+ ldapquota = '%s,%s' % (network, str(int(quota) * 1048576))
|
||||
+ # @todo improve this, it's a copy of set disk quota.
|
||||
+ try:
|
||||
+ currentquotas = self.getDetailedGroup(group)["networkquota"]
|
||||
+ newquotas = []
|
||||
+ quotachanged = False
|
||||
+ for x in currentquotas:
|
||||
+ if x.split(',')[0] == network:
|
||||
+ newquotas.append(ldapquota)
|
||||
+ quotachanged = True
|
||||
+ else:
|
||||
+ newquotas.append(x)
|
||||
+
|
||||
+ if not quotachanged:
|
||||
+ newquotas.append(ldapquota)
|
||||
+
|
||||
+ self.changeGroupAttribute(group, "networkquota", newquotas)
|
||||
+
|
||||
+ except KeyError:
|
||||
+ self.changeGroupAttribute(group, "networkquota", ldapquota)
|
||||
+ pass
|
||||
+
|
||||
+ for uid in self.getMembers(group):
|
||||
+ self.setNetworkQuota(uid, network, quota, overwrite)
|
||||
+ return True
|
||||
+
|
||||
+ def setUserQuotaDefaults(self, uid, group):
|
||||
+ # @todo: unfinished, does nothing yet.
|
||||
+ logger = logging.getLogger()
|
||||
+ logger.info("Set user quota defaults: user: " + uid + " group: " + group)
|
||||
+ keys = []
|
||||
+ # don't set the quota if one has been set before.
|
||||
+ logger.info(self.getDetailedUser(uid)["objectClass"])
|
||||
+ logger.info("Value of: self.hasDiskQuotaObjectClass(uid)" + str(self.hasDiskQuotaObjectClass(uid)))
|
||||
+ if self.hasDiskQuotaObjectClass(uid):
|
||||
+ logger.info("User already has quota Object class")
|
||||
+ return keys
|
||||
+
|
||||
+ groupdefaults = self.getDetailedGroup(group)
|
||||
+
|
||||
+ # @todo, check components before action
|
||||
+ if "quota" in groupdefaults.keys():
|
||||
+ # copy quota values to user
|
||||
+ logger.info("copy quota values to user:" + uid)
|
||||
+ self.addDiskQuotaObjectClass(uid)
|
||||
+ self.changeUserAttributes(uid, "quota", groupdefaults["quota"])
|
||||
+ keys.append('quota')
|
||||
+
|
||||
+ if "networkquota" in groupdefaults.keys():
|
||||
+ # copy networkquota values to user
|
||||
+ logger.info("copy network quota values to user:" + uid)
|
||||
+ self.addDiskQuotaObjectClass(uid)
|
||||
+ self.changeUserAttributes(uid, "networkquota", groupdefaults["networkquota"])
|
||||
+ keys.append('networkquota')
|
||||
+
|
||||
+ return keys
|
||||
+
|
||||
+ def addGroupDefaultDiskQuotaObjectClass(self, cn):
|
||||
+ group = self.getDetailedGroup(cn)['objectClass']
|
||||
+ if not "defaultQuotas" in group:
|
||||
+ group.append("defaultQuotas")
|
||||
+ self.changeGroupAttribute(cn, 'objectClass', group)
|
||||
+ return True
|
||||
+
|
||||
+ def changeGroupAttribute(self, cn, attr, attrval):
|
||||
+ self.l.modify_s('cn=' + cn + ',' + self.baseGroupsDN, [(ldap.MOD_REPLACE, attr, attrval)])
|
||||
+
|
||||
+ def deleteGroupDiskQuotas(self, cn, device):
|
||||
+ logger = logging.getLogger()
|
||||
+ devicepath = device.split(':')[0]
|
||||
+ logger.info("Delete quotas for members of:" + cn)
|
||||
+ logger.info("ldap timeout:" + str(self.l.timeout))
|
||||
+ self.l.set_option(ldap.OPT_NETWORK_TIMEOUT, 100)
|
||||
+ logger.info("ldap network timeout:" + str(self.l.get_option(ldap.OPT_NETWORK_TIMEOUT)))
|
||||
+
|
||||
+
|
||||
+ for uid in self.getMembers(cn):
|
||||
+ self.deleteDiskQuota(uid, device)
|
||||
+
|
||||
+
|
||||
+ try:
|
||||
+ currentquotas = self.getDetailedGroup(cn)["quota"]
|
||||
+ newquotas = []
|
||||
+ for x in currentquotas:
|
||||
+ if not x.split('=')[0] == devicepath:
|
||||
+ newquotas.append(x)
|
||||
+
|
||||
+ if len(newquotas) == 0:
|
||||
+ self.changeGroupAttribute(cn, 'quota', None)
|
||||
+ self.delGroupQuotaObjectClass(cn)
|
||||
+ else:
|
||||
+ self.changeGroupAttribute(cn, 'quota', newquotas)
|
||||
+
|
||||
+ except KeyError:
|
||||
+ pass
|
||||
+
|
||||
+ return True
|
||||
+
|
||||
+ def deleteGroupNetworkQuotas(self, cn, network):
|
||||
+ logger = logging.getLogger()
|
||||
+ logger.info("Delete networkquotas for members of: " + cn)
|
||||
+ for uid in self.getMembers(cn):
|
||||
+ self.deleteNetworkQuota(uid, network)
|
||||
+ try:
|
||||
+ currentquotas = self.getDetailedGroup(cn)["networkquota"]
|
||||
+ newquotas = []
|
||||
+
|
||||
+ for x in currentquotas:
|
||||
+ if not x.split(',')[0] == network:
|
||||
+ newquotas.append(x)
|
||||
+
|
||||
+ if len(newquotas) == 0:
|
||||
+ self.changeGroupAttribute(cn, 'networkquota', None)
|
||||
+ self.delGroupQuotaObjectClass(cn)
|
||||
+ else:
|
||||
+ self.changeGroupAttribute(cn, 'networkquota', newquotas)
|
||||
+
|
||||
+ except KeyError:
|
||||
+ pass
|
||||
+ return True
|
||||
+
|
||||
diff -Naur mmc-agent-2.3.2.orig/setup.py mmc-agent-2.3.2/setup.py
|
||||
--- mmc-agent-2.3.2.orig/setup.py 2010-01-29 15:50:40.866173716 +0000
|
||||
+++ mmc-agent-2.3.2/setup.py 2010-01-29 15:52:47.926425328 +0000
|
||||
@@ -8,5 +8,5 @@
|
||||
author_email = "cdelfosse@mandriva.com",
|
||||
maintainer = "Cedric Delfosse",
|
||||
maintainer_email = "cdelfosse@mandriva.com",
|
||||
- packages = ["mmc", "mmc.support", "mmc.plugins", "mmc.plugins.base", "mmc.plugins.samba", "mmc.plugins.proxy", "mmc.plugins.mail", "mmc.plugins.network", "mmc.plugins.kerberos", "mmc.plugins.printstats", "mmc.plugins.printing"],
|
||||
+ packages = ["mmc", "mmc.support", "mmc.plugins", "mmc.plugins.base", "mmc.plugins.samba", "mmc.plugins.proxy", "mmc.plugins.mail", "mmc.plugins.network", "mmc.plugins.kerberos", "mmc.plugins.printstats", "mmc.plugins.printing", "mmc.plugins.userquota"],
|
||||
)
|
||||
Reference in New Issue
Block a user