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:
geos_one 2010-01-29 16:25:04 +00:00
parent 21e101f718
commit 6457a9f909
5 changed files with 887 additions and 4 deletions

View File

@ -1,7 +1,12 @@
# ChangeLog for app-admin/mmc-agent # ChangeLog for app-admin/mmc-agent
# Copyright 1999-2009 Gentoo Foundation; Distributed under the GPL v2 # Copyright 1999-2010 Gentoo Foundation; Distributed under the GPL v2
# $Header: $ # $Header: $
29 Jan 2010; Mario Fetka <mario.fetka@gmail.com>
mmc-agent-2.3.2_p798.ebuild, +files/mmc-agent-2.3.2-bulkimport-1.patch,
+files/mmc-agent-2.3.2-userquota-1.patch:
Add Userquota & bulkimport module
05 Dec 2009; Mario Fetka <mario.fetka@gmail.com> 05 Dec 2009; Mario Fetka <mario.fetka@gmail.com>
+mmc-agent-2.3.2_p798.ebuild: +mmc-agent-2.3.2_p798.ebuild:
Use the special pulse2 release Use the special pulse2 release

View File

@ -1,7 +1,9 @@
AUX mmc-agent-2.3.1-kerberos-1.patch 16835 RMD160 c7bc79766967ed988a6b9d85be73a5f4cdf90f2b SHA1 fa43b2173e716b207cc6fbc10e739efef188e048 SHA256 69d7c88f5b3a35910c8650f69fdd9f9ee877248a41c03e7e99fa0a1a3b109c1c AUX mmc-agent-2.3.1-kerberos-1.patch 16835 RMD160 c7bc79766967ed988a6b9d85be73a5f4cdf90f2b SHA1 fa43b2173e716b207cc6fbc10e739efef188e048 SHA256 69d7c88f5b3a35910c8650f69fdd9f9ee877248a41c03e7e99fa0a1a3b109c1c
AUX mmc-agent-2.3.2-bulkimport-1.patch 6855 RMD160 13c16e3322a072ae41663696e8a53f299861b718 SHA1 ebea9f8d6f8f3b20b5ab19e328228dd17db2dd2b SHA256 fd76b1e7fde2547c1b505960d43dc363a3432937ea09f4b3d0619277edec5cac
AUX mmc-agent-2.3.2-powerdns-1.patch 37711 RMD160 dfade7296129ea3a302fad701845d057e9050bd4 SHA1 711c0dd404ce59470e3b1418a9f83726a10e0aac SHA256 6c0f6df0dccca0b42d0860c289333e3d670fa1ef416885bdf561124aec45d258 AUX mmc-agent-2.3.2-powerdns-1.patch 37711 RMD160 dfade7296129ea3a302fad701845d057e9050bd4 SHA1 711c0dd404ce59470e3b1418a9f83726a10e0aac SHA256 6c0f6df0dccca0b42d0860c289333e3d670fa1ef416885bdf561124aec45d258
AUX mmc-agent-2.3.2-powerdns-2.patch 38803 RMD160 ecde3d096a278446fbe0f866d6165f5940d53fb2 SHA1 d4518fc05dd57aadb4f05689e9675aa6b96d451b SHA256 33f4d1bd8e6509833bae5eec194c67371cb471c2c25d6978979057af2d67464a AUX mmc-agent-2.3.2-powerdns-2.patch 38803 RMD160 ecde3d096a278446fbe0f866d6165f5940d53fb2 SHA1 d4518fc05dd57aadb4f05689e9675aa6b96d451b SHA256 33f4d1bd8e6509833bae5eec194c67371cb471c2c25d6978979057af2d67464a
AUX mmc-agent-2.3.2-printing-1.patch 33371 RMD160 f7064ec4dfc2e923c522f01190ca5d4f7d493d43 SHA1 ca9219b982e210bd92c85db8f982e1a3c6b9d48b SHA256 97dc50bb286361286e5451d2e85ea9b9d8609a2f92c3f3ca3836e9bcbcd1c931 AUX mmc-agent-2.3.2-printing-1.patch 33371 RMD160 f7064ec4dfc2e923c522f01190ca5d4f7d493d43 SHA1 ca9219b982e210bd92c85db8f982e1a3c6b9d48b SHA256 97dc50bb286361286e5451d2e85ea9b9d8609a2f92c3f3ca3836e9bcbcd1c931
AUX mmc-agent-2.3.2-userquota-1.patch 28599 RMD160 4f2695794b23d666f8b00769452359700c1cd63a SHA1 88515db08641e0ac0dfef2ea71ea0f223d75bfbe SHA256 3397c6c3642826fefc0314572abf59bfd01a455f1c6048478b38a6e7eb0094cb
AUX mmc-agent.initd 438 RMD160 d7dc64366782ab0d6fe4347d6a169b88a4e03a49 SHA1 e4ae8808678161237703bbb63b144899c9a544c9 SHA256 922d0bacad3eda749f8807e3ae5c183f636fa93e0d41d7079e570c58ebccb879 AUX mmc-agent.initd 438 RMD160 d7dc64366782ab0d6fe4347d6a169b88a4e03a49 SHA1 e4ae8808678161237703bbb63b144899c9a544c9 SHA256 922d0bacad3eda749f8807e3ae5c183f636fa93e0d41d7079e570c58ebccb879
DIST mmc-agent-2.3.2-798.tar.gz 122211 RMD160 2630890c80e3e9fdf2d3510659e00692b1d487cb SHA1 914d3ce64f5e49abe1558eab23fa316b8a8ce3ec SHA256 411bb2a8475dda2f08450cae40812f35a5d426047cccd1a560881d41d621c55c DIST mmc-agent-2.3.2-798.tar.gz 122211 RMD160 2630890c80e3e9fdf2d3510659e00692b1d487cb SHA1 914d3ce64f5e49abe1558eab23fa316b8a8ce3ec SHA256 411bb2a8475dda2f08450cae40812f35a5d426047cccd1a560881d41d621c55c
DIST mmc-agent-2.3.2.tar.gz 120949 RMD160 871b3b7766d69019de392e42ebf25a216d217c71 SHA1 1e7c634243c00c6b214f24c3467315d31a444215 SHA256 0ac8ff97818c58008cadb3c6b08dba39e42b078fea9d392fda649e036eabaea2 DIST mmc-agent-2.3.2.tar.gz 120949 RMD160 871b3b7766d69019de392e42ebf25a216d217c71 SHA1 1e7c634243c00c6b214f24c3467315d31a444215 SHA256 0ac8ff97818c58008cadb3c6b08dba39e42b078fea9d392fda649e036eabaea2
@ -9,6 +11,6 @@ EBUILD mmc-agent-2.3.2-r1.ebuild 1635 RMD160 774f66ecfc207a8c86dadc010f8d9d04b50
EBUILD mmc-agent-2.3.2-r2.ebuild 1557 RMD160 fd12dd7afc50f7d37dd4d9e0291ec2509cc057ba SHA1 cfa7d9721d4b45a52499c481c99e1449844eeb3b SHA256 1ed12652595fc95f9f98be38721899ae6d811746fd7854687911243dd1d59d6d EBUILD mmc-agent-2.3.2-r2.ebuild 1557 RMD160 fd12dd7afc50f7d37dd4d9e0291ec2509cc057ba SHA1 cfa7d9721d4b45a52499c481c99e1449844eeb3b SHA256 1ed12652595fc95f9f98be38721899ae6d811746fd7854687911243dd1d59d6d
EBUILD mmc-agent-2.3.2-r3.ebuild 1557 RMD160 2a6e73ba6a2981f4e010fbb05af6439d39e096ad SHA1 35a64b2ec82aef8c5907c11861e7c53cefa0bf76 SHA256 d62618c640f6cf9c531c2a12780046fe1a53ea59712cd8964225a1c436ef4e25 EBUILD mmc-agent-2.3.2-r3.ebuild 1557 RMD160 2a6e73ba6a2981f4e010fbb05af6439d39e096ad SHA1 35a64b2ec82aef8c5907c11861e7c53cefa0bf76 SHA256 d62618c640f6cf9c531c2a12780046fe1a53ea59712cd8964225a1c436ef4e25
EBUILD mmc-agent-2.3.2-r4.ebuild 1616 RMD160 d8b85301b0c72e1be4f1655ec7fe16b2e338203f SHA1 7d2623589b14a75042f3c6f06dd766b16dc3af42 SHA256 8461d4fc8aba2670dce89d65932d18afa6e85e00aee72c1a134fa14f7496d2c4 EBUILD mmc-agent-2.3.2-r4.ebuild 1616 RMD160 d8b85301b0c72e1be4f1655ec7fe16b2e338203f SHA1 7d2623589b14a75042f3c6f06dd766b16dc3af42 SHA256 8461d4fc8aba2670dce89d65932d18afa6e85e00aee72c1a134fa14f7496d2c4
EBUILD mmc-agent-2.3.2_p798.ebuild 1789 RMD160 fd2403834f355d9f90b1ca68c701933ac42b2cec SHA1 1dbea38f276206636309080e22396c9ded2f4381 SHA256 be97ed0eb3183280e37e2154fff87ad64e9df083353a1c55ee7f22fa8015e7f0 EBUILD mmc-agent-2.3.2_p798.ebuild 1894 RMD160 c58ccbfe5b069e4e16158209c24f9eea553fe207 SHA1 780477a3510b6bbbfa9856d8274d51ae0d15a99d SHA256 3ec466d94ddf957382108b0a2e168ecae34d2010ddbd359fa2b5740e895e25a5
MISC ChangeLog 1940 RMD160 c4d30a33a2091d530a7ce71e3e8c5bc78a9f4561 SHA1 d36a9ab5880f061c88e6f23ef636b5bc5b0b2a3e SHA256 a5d12338f7894822ed33fb5961f0a9bece78cad924c173a34c48e110716c15a0 MISC ChangeLog 2146 RMD160 bdc55ed294fa6675f39beb4575871c170cde9747 SHA1 c2450e1fbaf17046aa5a21705b4b71761a895e7a SHA256 632563b375f8733b478b6120c2c1cfc5f94cc318e00210de5a8f37dbff278606
MISC metadata.xml 170 RMD160 645927a396fdc21cdeb089fe42c5397332420ea6 SHA1 ac7f48a14fec325926f9ce1be8fbf1f311b4f2e4 SHA256 d797a2ec6f9dc516c9f9c1a758ee87ad3e8c43101b5dc76c2f872d5bd4639b42 MISC metadata.xml 170 RMD160 645927a396fdc21cdeb089fe42c5397332420ea6 SHA1 ac7f48a14fec325926f9ce1be8fbf1f311b4f2e4 SHA256 d797a2ec6f9dc516c9f9c1a758ee87ad3e8c43101b5dc76c2f872d5bd4639b42

View 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"],
)

View 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"],
)

View File

@ -1,4 +1,4 @@
# Copyright 1999-2009 Gentoo Foundation # Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2 # Distributed under the terms of the GNU General Public License v2
# $Header: $ # $Header: $
@ -34,6 +34,8 @@ src_prepare() {
epatch "${FILESDIR}"/${PN}-2.3.1-kerberos-1.patch epatch "${FILESDIR}"/${PN}-2.3.1-kerberos-1.patch
epatch "${FILESDIR}"/${PN}-2.3.2-printing-1.patch epatch "${FILESDIR}"/${PN}-2.3.2-printing-1.patch
epatch "${FILESDIR}"/${PN}-2.3.2-powerdns-2.patch epatch "${FILESDIR}"/${PN}-2.3.2-powerdns-2.patch
epatch "${FILESDIR}"/${PN}-2.3.2-userquota-1.patch
epatch "${FILESDIR}"/${PN}-2.3.2-bulkimport-1.patch
} }
# from marienz's setuptools.eclass: # from marienz's setuptools.eclass: