thomas: utils/admin kolab_vacation_tool, 1.1, 1.2 kolab_vacation_tool.README, 1.1, 1.2
cvs at intevation.de
cvs at intevation.de
Fri Jan 20 18:11:52 CET 2006
Author: thomas
Update of /kolabrepository/utils/admin
In directory doto:/tmp/cvs-serv28950
Modified Files:
kolab_vacation_tool kolab_vacation_tool.README
Log Message:
Updated to allow setting option "Do not send vacation replies to spam messages"
Index: kolab_vacation_tool
===================================================================
RCS file: /kolabrepository/utils/admin/kolab_vacation_tool,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- kolab_vacation_tool 19 Jan 2006 15:35:18 -0000 1.1
+++ kolab_vacation_tool 20 Jan 2006 17:11:50 -0000 1.2
@@ -1,9 +1,9 @@
#!/kolab/bin/php
<?php
-/*
- * Copyright (c) 2005 Intevation GmbH
+/* $Id$
+ * Copyright (c) 2005, 2006 Intevation GmbH
*
- * Writen by Thomas Arendsen Hein <thomas at intevation.de>
+ * Written by Thomas Arendsen Hein <thomas at intevation.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -28,6 +28,38 @@
include_once 'admin/include/Sieve.php';
+include ("Console/Getopt.php");
+
+
+function usage ( $ret ) {
+ fwrite(STDOUT, "Usage: kolab_vacation_tool [--domain DOMAIN] [--spam] [--nospam] USERPATTERN...\n\n");
+ fwrite(STDOUT, " Set vacation parameters for Kolab users matching a given pattern.\n");
+ fwrite(STDOUT, " Pattern is matched against primary email address and uid.\n");
+ fwrite(STDOUT, " Wildcard for the pattern is \"*\".\n");
+ fwrite(STDOUT, "\nOptions:\n\n");
+ fwrite(STDOUT, " --domain DOMAIN Only react to mail coming from DOMAIN.\n");
+ fwrite(STDOUT, " Use an empty string to react to all domains.\n");
+ fwrite(STDOUT, " --spam Enable vacation replies to spam messages.\n");
+ fwrite(STDOUT, " --nospam Disable vacation replies to spam messages.\n");
+ fwrite(STDOUT, " -v, --verbose Increase verbosity.\n");
+ fwrite(STDOUT, " -q, --quiet Decrease verbosity.\n");
+ fwrite(STDOUT, " --help Show this help message.\n");
+ fwrite(STDOUT, "\nExamples:\n\n");
+ fwrite(STDOUT, " Set vacation domain for selected users to 'example.com':\n");
+ fwrite(STDOUT, " kolab_vacation_tool --domain example.com '*smith*' user at sub.example.com\n");
+ fwrite(STDOUT, " Set vacation domain for _all_ users to 'sub.example.net':\n");
+ fwrite(STDOUT, " kolab_vacation_tool --domain sub.example.net '*'\n");
+ fwrite(STDOUT, " Remove vacation domain setting for a selected user:\n");
+ fwrite(STDOUT, " kolab_vacation_tool --domain '' user at sub.example.com\n");
+ fwrite(STDOUT, " Enable vacation replies to spam messages for a selected user:\n");
+ fwrite(STDOUT, " kolab_vacation_tool --spam user at sub.example.com\n");
+ fwrite(STDOUT, " Disable vacation replies to spam, set vacation domain, list changed values:\n");
+ fwrite(STDOUT, " kolab_vacation_tool --nospam --domain example.com user at example.com\n");
+ fwrite(STDOUT, "\n");
+ exit($ret);
+}
+
+
function load_kolab_conf () {
$kolab_conf = array();
foreach(file('/kolab/etc/kolab/kolab.conf') as $line) {
@@ -72,7 +104,8 @@
}
-function sieve_maildomain ( $auth, $pass, $host, $user, $new_maildomain ) {
+function sieve_update ( $auth, $pass, $host, $user, $verbosity,
+ $maildomain, $dontreacttospam ) {
$errors = array();
$scriptname = 'kolab-vacation.siv';
@@ -90,21 +123,32 @@
}
if( in_array( $scriptname, $scripts ) ) {
$script = $sieve->getScript($scriptname);
- $maildomain = SieveUtils::getMailDomain( $script );
- $reacttospam = SieveUtils::getReactToSpam( $script );
+ $old_maildomain = SieveUtils::getMailDomain( $script );
+ $old_dontreacttospam = SieveUtils::getReactToSpam( $script );
$addresses = SieveUtils::getVacationAddresses( $script );
$days = SieveUtils::getVacationDays( $script );
$text = SieveUtils::getVacationText( $script );
- } else $reacttospam = true;
+ } else $old_dontreacttospam = true;
if( $addresses === false ) $addresses = array( "" );
$active = ( $sieve->getActive() === $scriptname );
- if( $maildomain != $new_maildomain ) {
+ if(is_null($maildomain))
+ $new_maildomain = $old_maildomain;
+ else
+ $new_maildomain = $maildomain;
- $script =
+ if(is_null($dontreacttospam))
+ $new_dontreacttospam = $old_dontreacttospam;
+ else
+ $new_dontreacttospam = $dontreacttospam;
+
+ if( $new_maildomain != $old_maildomain ||
+ $new_dontreacttospam != $old_dontreacttospam ) {
+
+ $script =
"require \"vacation\";\r\n\r\n".
(!empty($new_maildomain)?"if not address :domain :contains \"From\" \"".$new_maildomain."\" { keep; stop; }\r\n":"").
- ($reacttospam?"if header :contains \"X-Spam-Flag\" \"YES\" { keep; stop; }\r\n":"").
+ ($new_dontreacttospam?"if header :contains \"X-Spam-Flag\" \"YES\" { keep; stop; }\r\n":"").
($addresses && $text && $days ?
"vacation :addresses [ \"".join('", "', $addresses )."\" ] :days ".$days." text:\r\n".
SieveUtils::dotstuff($text).".\r\n;":"")."\r\n\r\n";
@@ -116,37 +160,93 @@
return $errors;
}
- fwrite(STDOUT, "$user: \"$maildomain\" -> \"$new_maildomain\" on $host\n");
- } else {
- fwrite(STDOUT, "$user: already set to \"$new_maildomain\" on $host\n");
+ if ($verbosity == 0) {
+ fwrite(STDOUT, "$user on $host: updated\n");
+ }
+ }
+
+ if ($verbosity > 0) {
+ if(!is_null($maildomain)) {
+ if($new_maildomain != $old_maildomain)
+ fwrite(STDOUT, "$user on $host: domain updated: \"$old_maildomain\" -> \"$new_maildomain\"\n");
+ else
+ fwrite(STDOUT, "$user on $host: domain unchanged: \"$new_maildomain\"\n");
+ }
+ if(!is_null($dontreacttospam)) {
+ if($new_dontreacttospam != $old_dontreacttospam)
+ fwrite(STDOUT, "$user on $host: react to spam: " . ($old_dontreacttospam?"NO -> ":"YES -> "));
+ else
+ fwrite(STDOUT, "$user on $host: react to spam unchanged: ");
+ fwrite(STDOUT, ($new_dontreacttospam?"NO\n":"YES\n"));
+ }
}
+
}
// main
-if( count($argv) < 3 ) {
- fwrite(STDOUT, "Usage: $argv[0] MAILDOMAIN USERPATTERN...\n");
- fwrite(STDOUT, "Set vacation parameter \"Only react to mail coming from domain\"\n");
- fwrite(STDOUT, "for Kolab users matching a given pattern. Wildcard is \"*\".\n");
+$cg = new Console_Getopt();
+$args = $cg->readPHPArgv();
+$ret = $cg->getopt($args, "vq", array("domain=", "spam", "nospam",
+ "verbose", "quiet", "help"));
+
+if (PEAR::isError($ret)) {
+ die ("Error in command line: " . $ret->getMessage() . "\n");
+}
+
+$verbosity = 0;
+$maildomain = NULL;
+$dontreacttospam = NULL;
+
+$opts = $ret[0];
+if (sizeof($opts) > 0) {
+ foreach ($opts as $o) {
+ switch ($o[0]) {
+ case '--domain':
+ $maildomain = $o[1];
+ break;
+ case '--spam':
+ $dontreacttospam = false;
+ break;
+ case '--nospam':
+ $dontreacttospam = true;
+ break;
+ case 'q':
+ case '--quiet':
+ $verbosity--;
+ break;
+ case 'v':
+ case '--verbose':
+ $verbosity++;
+ break;
+ case '--help':
+ usage(0);
+ break;
+ }
+ }
+} else {
+ usage(0);
+}
+
+$userpatterns = $ret[1];
+if( count($userpatterns) < 1 ) {
+ fwrite(STDOUT, "You need to specify at least one user pattern.\n\n");
exit(1);
}
$kolab_conf = load_kolab_conf();
-$argv = $_SERVER['argv'];
-unset($argv[0]);
-$new_maildomain = $argv[1];
-unset($argv[1]);
-
-$users = user_homeserver($kolab_conf, $argv);
+$users = user_homeserver($kolab_conf, $userpatterns);
if( count($users) < 1 ) {
fwrite(STDOUT, "No matching users found.\n");
exit(0);
}
foreach($users as $user => $homeserver) {
- $errors = sieve_maildomain ( $kolab_conf['manager'], $kolab_conf['bind_pw'], $homeserver, $user, $new_maildomain );
+ $errors = sieve_update ( $kolab_conf['manager'], $kolab_conf['bind_pw'],
+ $homeserver, $user, $verbosity,
+ $maildomain, $dontreacttospam );
if( $errors ) {
fwrite(STDOUT, "Error while setting vacation maildomain for user ".$user.":\n");
foreach($errors as $line) {
Index: kolab_vacation_tool.README
===================================================================
RCS file: /kolabrepository/utils/admin/kolab_vacation_tool.README,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- kolab_vacation_tool.README 19 Jan 2006 15:35:18 -0000 1.1
+++ kolab_vacation_tool.README 20 Jan 2006 17:11:50 -0000 1.2
@@ -1,13 +1,13 @@
kolab_vacation_tool
===================
-Update vacation domain ("Only react to mail coming from domain XYZ"):
+Set vacation parameters for Kolab users.
Installation
------------
-as user 'root':
+as user 'root' on the kolab server (master or slave):
# cp kolab_vacation_tool /kolab/sbin/
# chown kolab /kolab/sbin/kolab_vacation_tool
# chmod 744 /kolab/sbin/kolab_vacation_tool
@@ -21,22 +21,9 @@
Usage
-----
-as user 'kolab':
-$ kolab_vacation_tool DOMAIN USER_PATTERN...
-
-For selecting users you can use the primary email address or the uid.
-Wildcard character is '*'.
-
-
-Examples
---------
+As user 'kolab' run:
+$ kolab_vacation_tool --help
-Set vacation domain for selected users to 'example.com':
-$ kolab_vacation_tool example.com '*smith*' user at sub.example.com 'foo*'
-Set vacation domain for _all_ users to 'sub.example.net':
-$ kolab_vacation_tool sub.example.net '*'
-
-Remove vacation domain setting for a selected user:
-$ kolab_vacation_tool '' user at sub.example.com
+$Id$
More information about the commits
mailing list