You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
(30) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(2) |
Feb
(5) |
Mar
(11) |
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: <mn...@us...> - 2007-12-13 16:17:47
|
Revision: 29 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=29&view=rev Author: mnencia Date: 2007-12-13 08:17:47 -0800 (Thu, 13 Dec 2007) Log Message: ----------- Stop vmaild bothering about final slash in maildir Modified Paths: -------------- trunk/setup/bin/vmaild Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-13 16:11:22 UTC (rev 28) +++ trunk/setup/bin/vmaild 2007-12-13 16:17:47 UTC (rev 29) @@ -410,7 +410,7 @@ # nella directory del dominio foreach my $maildir (@maildirs) { my $user = $maildir; - $user =~ s%^.*/([^/]+)$%$1%; + $user =~ s%^.*/([^/]+)/?$%$1%; if ( !$users{$user} || "$domaindir/$users{$user}->{maildir}" ne $maildir ) { logmsg( 'notice', "invalid or deleted user: $user\@$domain " ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-13 16:16:35
|
Revision: 28 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=28&view=rev Author: mnencia Date: 2007-12-13 08:11:22 -0800 (Thu, 13 Dec 2007) Log Message: ----------- Switched function.sql to dollar quoting sintax Stop appending useless slash to maildir Modified Paths: -------------- trunk/setup/sql/functions.sql Modified: trunk/setup/sql/functions.sql =================================================================== --- trunk/setup/sql/functions.sql 2007-12-13 14:38:26 UTC (rev 27) +++ trunk/setup/sql/functions.sql 2007-12-13 16:11:22 UTC (rev 28) @@ -1,84 +1,87 @@ -- Utility functions -CREATE OR REPLACE FUNCTION extract_domain(text) RETURNS text - AS 'SELECT substring($1 from ''([^@]*)$'');' - LANGUAGE sql IMMUTABLE; +CREATE OR REPLACE FUNCTION extract_domain(text) RETURNS text AS $$ + SELECT substring($1 from '([^@]*)$'); +$$ LANGUAGE sql IMMUTABLE; -CREATE OR REPLACE FUNCTION extract_user(text) RETURNS text - AS 'SELECT substring($1 from ''^([^@]*)'');' - LANGUAGE sql IMMUTABLE; +CREATE OR REPLACE FUNCTION extract_user(text) RETURNS text AS $$ + SELECT substring($1 from '^([^@]*)'); +$$ LANGUAGE sql IMMUTABLE; -CREATE OR REPLACE FUNCTION get_id_domain(text) RETURNS integer - AS 'SELECT id FROM virtual_domains - WHERE name = extract_domain($1) AND NOT deleted;' - LANGUAGE sql STABLE; +CREATE OR REPLACE FUNCTION get_id_domain(text) RETURNS integer AS $$ + SELECT id FROM virtual_domains + WHERE name = extract_domain($1) AND NOT deleted; +$$ LANGUAGE sql STABLE; -CREATE OR REPLACE FUNCTION get_domain_by_id(integer) RETURNS text - AS 'SELECT VD.name FROM virtual_domains AS VD WHERE id = $1 - AND NOT deleted;' - LANGUAGE sql STABLE; +CREATE OR REPLACE FUNCTION get_domain_by_id(integer) RETURNS text AS $$ + SELECT VD.name FROM virtual_domains AS VD WHERE id = $1 + AND NOT deleted; +$$ LANGUAGE sql STABLE; -CREATE OR REPLACE FUNCTION get_id_user(text) RETURNS integer - AS 'SELECT id FROM admin_users - WHERE login = $1;' - LANGUAGE sql STABLE; +CREATE OR REPLACE FUNCTION get_id_user(text) RETURNS integer AS $$ + SELECT id FROM admin_users + WHERE login = $1; +$$ LANGUAGE sql STABLE; -CREATE OR REPLACE FUNCTION have_default_delivery(text) RETURNS boolean - AS 'SELECT unknown_to IS NOT NULL FROM virtual_domains WHERE name = extract_domain($1);' - LANGUAGE sql STABLE; +CREATE OR REPLACE FUNCTION have_default_delivery(text) RETURNS boolean AS $$ + SELECT unknown_to IS NOT NULL FROM virtual_domains WHERE name = extract_domain($1); +$$ LANGUAGE sql STABLE; -CREATE OR REPLACE FUNCTION compute_dir(integer) RETURNS text AS ' +CREATE OR REPLACE FUNCTION compute_dir(integer) RETURNS text AS $$ DECLARE usercount ALIAS FOR $1; prefix text; tmpcount integer; tmpnum integer; BEGIN - prefix := ''''; + prefix := ''; tmpcount := floor((usercount - 1)/ 100) - 1; IF tmpcount = -1 THEN RETURN prefix; END IF; LOOP tmpnum := tmpcount % 62; - prefix := tmpnum||''/''||prefix; + prefix := tmpnum||'/'||prefix; IF tmpnum = tmpcount THEN EXIT; END IF; tmpcount := floor(tmpcount / 62) -1; END LOOP; RETURN prefix; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION extract_domain_from_local(text) RETURNS text - AS E'SELECT substring($1 from E''localdelivery\\\\.([^@]*)$'');' - LANGUAGE sql IMMUTABLE; +CREATE OR REPLACE FUNCTION extract_domain_from_local(text) RETURNS text AS $$ + SELECT substring($1 from E'localdelivery\.([^@]*)$'); +$$ LANGUAGE sql IMMUTABLE; -CREATE OR REPLACE FUNCTION get_id_domain_local(text) RETURNS integer - AS 'SELECT id FROM virtual_domains - WHERE name = extract_domain_from_local($1) AND NOT deleted;' - LANGUAGE sql STABLE; +CREATE OR REPLACE FUNCTION get_id_domain_local(text) RETURNS integer AS $$ + SELECT id FROM virtual_domains + WHERE name = extract_domain_from_local($1) AND NOT deleted; +$$ LANGUAGE sql STABLE; -- Validation functions -CREATE OR REPLACE FUNCTION validate_destination_list(text) RETURNS boolean - AS E'SELECT $1 ~ E''^[_a-zA-Z0-9-]+(\\\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\\\.[a-zA-Z0-9-]+)*\\\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))( *[, ] *[_a-zA-Z0-9-]+(\\\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\\\.[a-zA-Z0-9-]+)*\\\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name)))*$'';' - LANGUAGE sql IMMUTABLE; +CREATE OR REPLACE FUNCTION validate_destination_list(text) RETURNS boolean AS $$ + SELECT $1 ~ (E'^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@' + ||E'[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))' + ||E'( *[, ] *[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@' + ||E'[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name)))*$'); +$$ LANGUAGE sql IMMUTABLE; -CREATE OR REPLACE FUNCTION validate_domain_name(text) RETURNS boolean - AS E'SELECT $1 ~ E''^[a-zA-Z0-9-]+(\\\\.[a-zA-Z0-9-]+)*\\\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$'';' - LANGUAGE sql IMMUTABLE; +CREATE OR REPLACE FUNCTION validate_domain_name(text) RETURNS boolean AS $$ + SELECT $1 ~ E'^[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$'; +$$ LANGUAGE sql IMMUTABLE; -CREATE OR REPLACE FUNCTION validate_user_name(text) RETURNS boolean - AS E'SELECT $1 ~ E''^[_a-zA-Z0-9-]+(\\\\.[_a-zA-Z0-9-]+)*$'';' - LANGUAGE sql IMMUTABLE; +CREATE OR REPLACE FUNCTION validate_user_name(text) RETURNS boolean AS $$ + SELECT $1 ~ E'^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*$'; +$$ LANGUAGE sql IMMUTABLE; -- Management Functions - domains -CREATE OR REPLACE FUNCTION create_domain(text,text) RETURNS boolean AS E' +CREATE OR REPLACE FUNCTION create_domain(text,text) RETURNS boolean AS $$ DECLARE dname ALIAS FOR $1; ddefault_to ALIAS FOR $2; @@ -97,18 +100,18 @@ INSERT INTO virtual_domains (name, unknown_to) VALUES (dname, ddefault_to); RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION create_domain(text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION create_domain(text) RETURNS boolean AS $$ DECLARE dname ALIAS FOR $1; BEGIN RETURN create_domain(dname,NULL); - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION update_domain(text,text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION update_domain(text,text) RETURNS boolean AS $$ DECLARE dname ALIAS FOR $1; ddefault_to ALIAS FOR $2; @@ -117,10 +120,10 @@ SET unknown_to = ddefault_to, last_modified = CURRENT_TIMESTAMP WHERE name = dname; RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION delete_domain(text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION delete_domain(text) RETURNS boolean AS $$ DECLARE dname ALIAS FOR $1; BEGIN @@ -128,12 +131,12 @@ SET deleted = true, last_modified = CURRENT_TIMESTAMP WHERE id = get_id_domain(dname); RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -- Management Functions - alias domains -CREATE OR REPLACE FUNCTION create_alias_domain(text,text) RETURNS boolean AS E' +CREATE OR REPLACE FUNCTION create_alias_domain(text,text) RETURNS boolean AS $$ DECLARE dname ALIAS FOR $1; ddestination ALIAS FOR $2; @@ -155,10 +158,10 @@ INSERT INTO alias_domains (name, destination) VALUES (dname, ddestination); RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION update_alias_domain(text,text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION update_alias_domain(text,text) RETURNS boolean AS $$ DECLARE dname ALIAS FOR $1; ddestination ALIAS FOR $2; @@ -167,22 +170,22 @@ SET destination = ddestination WHERE name = dname; RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION delete_alias_domain(text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION delete_alias_domain(text) RETURNS boolean AS $$ DECLARE dname ALIAS FOR $1; BEGIN DELETE FROM alias_domains WHERE name = dname; RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -- Management Functions - users -CREATE OR REPLACE FUNCTION create_user(text,text,boolean) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION create_user(text,text,boolean) RETURNS boolean AS $$ DECLARE email ALIAS FOR $1; pass ALIAS FOR $2; @@ -207,25 +210,25 @@ prefix := compute_dir(ddata.usercount); INSERT INTO virtual_domain_users (id_domain, name, passwd, maildir, pop3_enabled) VALUES - (ddata.id, user, pass, ddata.name||''/''||prefix||user||''/'', pop3); + (ddata.id, user, pass, ddata.name||'/'||prefix||user, pop3); UPDATE virtual_domains SET last_modified = CURRENT_TIMESTAMP, usercount = ddata.usercount WHERE id = ddata.id; RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION create_user(text,text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION create_user(text,text) RETURNS boolean AS $$ DECLARE email ALIAS FOR $1; pass ALIAS FOR $2; BEGIN RETURN create_user(email,pass,TRUE); - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION update_user(text,text,boolean) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION update_user(text,text,boolean) RETURNS boolean AS $$ DECLARE email ALIAS FOR $1; pass ALIAS FOR $2; @@ -253,19 +256,19 @@ END IF; END IF; RETURN TRUE; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION update_user(text,text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION update_user(text,text) RETURNS boolean AS $$ DECLARE email ALIAS FOR $1; pass ALIAS FOR $2; BEGIN RETURN update_user(email,pass,NULL); - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION delete_user(text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION delete_user(text) RETURNS boolean AS $$ DECLARE email ALIAS FOR $1; ddata RECORD; @@ -284,12 +287,12 @@ last_modified = CURRENT_TIMESTAMP WHERE id = ddata.id; RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -- Management Functions - aliases -CREATE OR REPLACE FUNCTION create_alias(text,text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION create_alias(text,text) RETURNS boolean AS $$ DECLARE email ALIAS FOR $1; dest ALIAS FOR $2; @@ -311,10 +314,10 @@ INSERT INTO virtual_domain_aliases (id_domain, name, destination) VALUES (ddata.id, user, dest); RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION update_alias(text,text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION update_alias(text,text) RETURNS boolean AS $$ DECLARE email ALIAS FOR $1; dest ALIAS FOR $2; @@ -332,10 +335,10 @@ UPDATE virtual_domain_aliases SET destination = dest WHERE id_domain = ddata.id AND name = user; RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION delete_alias(text) RETURNS boolean AS ' +CREATE OR REPLACE FUNCTION delete_alias(text) RETURNS boolean AS $$ DECLARE email ALIAS FOR $1; ddata RECORD; @@ -348,8 +351,8 @@ user := extract_user(email); DELETE FROM virtual_domain_aliases WHERE id_domain = ddata.id AND name = user; RETURN FOUND; - END;' - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION create_nwl(text,text) RETURNS boolean AS $$ DECLARE @@ -370,10 +373,12 @@ INSERT INTO newsletter_maps (name, id_domain, passwd) VALUES (user, ddata.id, password); RETURN FOUND; - END;$$ - LANGUAGE plpgsql; + END; +$$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION get_nwl_id(text) RETURNS integer AS $$ - SELECT id FROM newsletter_maps WHERE name = extract_user($1) AND id_domain = get_id_domain($1) OR id_domain = get_id_domain(substring($1 from E'transportdelivery\\.([^@]*)$')); -$$ -LANGUAGE sql STABLE; + SELECT id FROM newsletter_maps + WHERE name = extract_user($1) + AND id_domain = get_id_domain($1) + OR id_domain = get_id_domain(substring($1 from E'transportdelivery\\.([^@]*)$')); +$$ LANGUAGE sql STABLE; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-13 14:38:21
|
Revision: 27 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=27&view=rev Author: mnencia Date: 2007-12-13 06:38:26 -0800 (Thu, 13 Dec 2007) Log Message: ----------- Better log linefor deleted domains Modified Paths: -------------- trunk/setup/bin/vmaild Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-13 14:18:26 UTC (rev 26) +++ trunk/setup/bin/vmaild 2007-12-13 14:38:26 UTC (rev 27) @@ -309,7 +309,7 @@ # inesistenti o errati foreach my $domain ( filelist($domaindir) ) { if (! exists $domains{$domain} ) { - logmsg( 'notice', "unknown directory found: $domaindir/$domain" ); + logmsg( 'notice', "deleted domain: $domain" ); my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); sys_or_log("mv $domaindir/$domain $deldir/${domain}_$deldate"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-13 14:18:22
|
Revision: 26 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=26&view=rev Author: mnencia Date: 2007-12-13 06:18:26 -0800 (Thu, 13 Dec 2007) Log Message: ----------- OMG-commit: vmaild was completely broken before, because maildir/homedir split. Modified Paths: -------------- trunk/setup/bin/vmaild Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-13 14:15:22 UTC (rev 25) +++ trunk/setup/bin/vmaild 2007-12-13 14:18:26 UTC (rev 26) @@ -242,9 +242,11 @@ my %dirlist; my $dir; for ( my $i = 1 ; $i <= $usercount ; $i += 100 ) { - $dir = "$path/" . compute_dir($i); + $dir = $path; + my $prefix = compute_dir($i); + $dir .= "/" . $prefix if $prefix; $dirlist{$dir} = 1; - push @filelist, map { "$dir$_/" } filelist($dir) if -d $dir; + push @filelist, map { "$dir/$_" } filelist($dir) if -d $dir; } @filelist = grep { !$dirlist{$_} } @filelist; return @filelist; @@ -283,7 +285,7 @@ my $sth; # prelevo domini esistenti - $sth = $dbh->prepare("SELECT DISTINCT D.* FROM $db_virtual_domains D INNER JOIN $db_virtual_domain_users U ON D.id = U.id_domain"); + $sth = $dbh->prepare("SELECT DISTINCT * FROM $db_virtual_domains WHERE NOT deleted"); if ( !$sth->execute ) { logmsg( 'error', 'unable to fetch domains list' ); logmsg( 'error', $dbh->errstr ); @@ -306,93 +308,54 @@ # test 1: presenza di directory di dominio per domini # inesistenti o errati foreach my $domain ( filelist($domaindir) ) { - if ( !$domains{$domain} ) { + if (! exists $domains{$domain} ) { logmsg( 'notice', "unknown directory found: $domaindir/$domain" ); my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); sys_or_log("mv $domaindir/$domain $deldir/${domain}_$deldate"); } } + # test 2: creazione domini nuovi foreach my $domain ( keys %domains ) { next unless $domain =~ /^([-a-z0-9]+\.)*[-a-z0-9]+$/; my $ddata = $domains{$domain}; my $dir = "$domaindir/$domain"; - # test 2: eliminazione di domini cancellati - if ( $ddata->{deleted} ) { - logmsg( 'notice', "deleted domain: $domain" ); - if ( !$dry_run ) { - if ( - !( - $dbh->begin_work and $dbh->do( - "DELETE FROM $db_virtual_domain_aliases WHERE id_domain = ?", - { - }, - $ddata->{id} - ) - and $dbh->do( - "DELETE FROM $db_virtual_domain_users WHERE id_domain = ?", - { - }, - $ddata->{id} - ) - and $dbh->do( - "DELETE FROM $db_virtual_domains WHERE id = ?", - { - }, $ddata->{id} ) - and $dbh->commit - ) - ) { - logmsg( 'warning', - "warning: cannot remove deleted $domain from db" ); - logmsg( 'warning', "warning: " . $dbh->errstr ); + if ( !-d $dir ) { + if ( -e $dir ) { + logmsg( 'warning', + "warning: $dir is not a directory, trying to remove it" + ); + if ( !$dry_run ) { + my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); + sys_or_log("mv $dir $deldir/${domain}_$deldate"); } } - - if ( -d $dir ) { - my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); - sys_or_log("mv $dir $deldir/${domain}_$deldate"); - } - } else { - - # test 3: creazione domini nuovi o cancellati - if ( !-d $dir ) { - if ( -e $dir ) { + logmsg( 'notice', "new domain: $domain" ); + if ( !$dry_run ) { + if ( !mkdir( $dir, 0755 ) ) { logmsg( 'warning', - "warning: $dir is not a directory, trying to remove it" - ); - if ( !$dry_run ) { - unlink($dir) - and logmsg( 'warning', "warning: $dir removed" ); - } - } - logmsg( 'notice', "new domain: $domain" ); - if ( !$dry_run ) { - if ( !mkdir( $dir, 0755 ) ) { + "warning: cannot create '$dir': $!" ); + } elsif ( !chown( $vuid, $vgid, $dir ) ) { + logmsg( 'warning', + "warning: cannot chown '$dir' to $vuid:$vgid: $!" ); + } else { + if ( + !$dbh->do( + "UPDATE $db_virtual_domains SET last_modified = CURRENT_TIMESTAMP WHERE id = get_id_domain(?)", + { + }, + $domain + ) + ) { logmsg( 'warning', - "warning: cannot create '$dir': $!" ); - } elsif ( !chown( $vuid, $vgid, $dir ) ) { - logmsg( 'warning', - "warning: cannot chown '$dir' to $vuid:$vgid: $!" ); - } else { - if ( - !$dbh->do( - "UPDATE $db_virtual_domains SET last_modified = CURRENT_TIMESTAMP WHERE id = get_id_domain(?)", - { - }, - $domain - ) - ) { - logmsg( 'warning', - "warning: cannot update $domain status" ); - logmsg( 'warning', "warning: " . $dbh->errstr ); - } + "warning: cannot update $domain status" ); + logmsg( 'warning', "warning: " . $dbh->errstr ); } } } } } - return 1; } @@ -403,13 +366,13 @@ # prelevo domini modificati (o tutti i domini) if ($full) { - $sth = $dbh->prepare( - "SELECT * FROM $db_virtual_domains;" + $sth = $dbh->prepare( + "SELECT * FROM $db_virtual_domains WHERE NOT deleted;" ); } else { $sth = $dbh->prepare( - "SELECT * FROM $db_virtual_domains WHERE last_modified > last_updated OR last_updated IS NULL;" + "SELECT * FROM $db_virtual_domains WHERE NOT deleted AND (last_modified > last_updated OR last_updated IS NULL);" ); } if ( !$sth->execute ) { @@ -430,8 +393,7 @@ # prelevo i dati sugli utenti del dominio my %users; - $sth = $dbh->prepare( - "SELECT * FROM $db_virtual_domain_users WHERE id_domain = ?;"); + $sth = $dbh->prepare("SELECT * FROM $db_virtual_domain_users WHERE id_domain = ?"); if ( !$sth->execute( $ddata->{id} ) ) { logmsg( 'error', 'unable to fetch $domain users list' ); logmsg( 'error', $dbh->errstr ); @@ -448,7 +410,7 @@ # nella directory del dominio foreach my $maildir (@maildirs) { my $user = $maildir; - $user =~ s%^.*/([^/]+)/$%$1%; + $user =~ s%^.*/([^/]+)$%$1%; if ( !$users{$user} || "$domaindir/$users{$user}->{maildir}" ne $maildir ) { logmsg( 'notice', "invalid or deleted user: $user\@$domain " ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-13 14:15:21
|
Revision: 25 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=25&view=rev Author: mnencia Date: 2007-12-13 06:15:22 -0800 (Thu, 13 Dec 2007) Log Message: ----------- Reindented vmaild Modified Paths: -------------- trunk/setup/bin/vmaild Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-12 16:41:33 UTC (rev 24) +++ trunk/setup/bin/vmaild 2007-12-13 14:15:22 UTC (rev 25) @@ -32,12 +32,12 @@ my $dont_fork = 0; open(CONF, "<$configfile") - or die $!; + or die $!; my $conf = join('', <CONF>); close(CONF); eval "# line 1 '$configfile'\n". - "$conf" - or die $@; + "$conf" + or die $@; my $vuid = getpwnam($vuser) or die "Invalid user in config file. ($vuser)"; my $vgid = getgrnam($vgroup) or die "Invalid group in config file ($vgroup)"; @@ -61,77 +61,75 @@ ####################### SUBROUTINES ################################ sub logmsg($$;@) { - my ( $level, $msg, @params ) = @_; - if ($dont_fork) { - printf( "$level: $msg\n", @params ); - } - else { - syslog( $level, $msg, @params ); - } + my ( $level, $msg, @params ) = @_; + if ($dont_fork) { + printf( "$level: $msg\n", @params ); + } else { + syslog( $level, $msg, @params ); + } } sub check_sieve($) { - my ($path) = @_; + my ($path) = @_; - my $ok; - if ($ok = -l "$path/.dovecot.sieve") { - my $dest = File::Spec->rel2abs( readlink "$path/.dovecot.sieve", $path ); - $ok = -f $dest and -s $dest; - } - return $ok; + my $ok; + if ($ok = -l "$path/.dovecot.sieve") { + my $dest = File::Spec->rel2abs( readlink "$path/.dovecot.sieve", $path ); + $ok = -f $dest and -s $dest; + } + return $ok; } # crea lo script sieve sub sieveconfigmake($) { - my ($path) = @_; - if ($dry_run) { - return 0; - } + my ($path) = @_; + if ($dry_run) { + return 0; + } - my %links = (); + my %links = (); - my $ok = 1; + my $ok = 1; - my $sieve_file = "sieve/.dovecot.sieve.sieve"; - - # Special content: sieve script - if ( open( FILE, ">$path/$sieve_file" ) ) { - print FILE $sieve_script; - close(FILE); - } - else { - logmsg( 'warning', - "warning: cannot fill $path/$sieve_file: $!" ); - $ok = 0; - } + my $sieve_file = "sieve/.dovecot.sieve.sieve"; - if ( !symlink( "$sieve_file", $path . "/.dovecot.sieve" ) ) { - logmsg( 'warning', "warning: cannot symlink '$path/.dovecot.sieve' to '$sieve_file': $!" - ); - $ok = 0; - } + # Special content: sieve script + if ( open( FILE, ">$path/$sieve_file" ) ) { + print FILE $sieve_script; + close(FILE); + } else { + logmsg( 'warning', + "warning: cannot fill $path/$sieve_file: $!" ); + $ok = 0; + } - if ( !chown( $vuid, $vgid, "$path/$sieve_file" ) ) { - logmsg( 'warning', "warning: cannot chown '$path/$sieve_file' to $vuid:$vgid: $!" - ); - $ok = 0; - } - if ( !chmod( 0600, "$path/$sieve_file" ) ) { - logmsg( 'warning', - "warning: cannot chmod '$path/$sieve_file' to 0600: $!" ); - $ok = 0; - } + if ( !symlink( "$sieve_file", $path . "/.dovecot.sieve" ) ) { + logmsg( 'warning', "warning: cannot symlink '$path/.dovecot.sieve' to '$sieve_file': $!" + ); + $ok = 0; + } - return $ok; + if ( !chown( $vuid, $vgid, "$path/$sieve_file" ) ) { + logmsg( 'warning', "warning: cannot chown '$path/$sieve_file' to $vuid:$vgid: $!" + ); + $ok = 0; + } + if ( !chmod( 0600, "$path/$sieve_file" ) ) { + logmsg( 'warning', + "warning: cannot chmod '$path/$sieve_file' to 0600: $!" ); + $ok = 0; + } + + return $ok; } # crea una maildir sub maildirmake($) { - my ($path) = @_; - if ($dry_run) { - return 0; - } - my @dirs = ( + my ($path) = @_; + if ($dry_run) { + return 0; + } + my @dirs = ( $path . "/Maildir", $path . "/Maildir/new", $path . "/Maildir/cur", @@ -154,376 +152,366 @@ $path . "/Maildir/.Trash/tmp", $path . "/sieve", $path . "/sieve/tmp", - ); + ); - my @files = ( - $path . "/Maildir/.Drafts/maildirfolder", - $path . "/Maildir/.Sent/maildirfolder", - $path . "/Maildir/.Spam/maildirfolder", - $path . "/Maildir/.Trash/maildirfolder", - $path . "/Maildir/subscriptions", - ); + my @files = ( + $path . "/Maildir/.Drafts/maildirfolder", + $path . "/Maildir/.Sent/maildirfolder", + $path . "/Maildir/.Spam/maildirfolder", + $path . "/Maildir/.Trash/maildirfolder", + $path . "/Maildir/subscriptions", + ); - my @subscriptions = - ( "Drafts", "Sent", "Spam", "Trash", ); + my @subscriptions = + ( "Drafts", "Sent", "Spam", "Trash", ); - my $ok = 1; + my $ok = 1; - if (! -d $path ) { - mkpath( $path, 0, 0700 ); - } - - foreach my $dir (@dirs) { - if ( !mkdir( $dir, 0700 ) ) { - logmsg( 'warning', "warning: cannot create $dir dir: $!" ); - $ok = 0; - } - } - foreach my $file (@files) { - if ( !open( FILE, ">>$file" ) ) { - logmsg( 'warning', "warning: cannot create $file file: $!" ); - $ok = 0; - } - close(FILE); - } + if (! -d $path ) { + mkpath( $path, 0, 0700 ); + } - # Special content: subscriber folders - if ( open( FILE, ">>$path/Maildir/subscriptions" ) ) { - foreach my $subscription (@subscriptions) { - print FILE "$subscription\n"; - } - close(FILE); + foreach my $dir (@dirs) { + if ( !mkdir( $dir, 0700 ) ) { + logmsg( 'warning', "warning: cannot create $dir dir: $!" ); + $ok = 0; } - else { - logmsg( 'warning', "warning: cannot fill $path/subscriptions: $!" ); - $ok = 0; + } + foreach my $file (@files) { + if ( !open( FILE, ">>$file" ) ) { + logmsg( 'warning', "warning: cannot create $file file: $!" ); + $ok = 0; } + close(FILE); + } - if ( !chown( $vuid, $vgid, $path, @dirs, @files ) ) { - logmsg( 'warning', "warning: cannot chown '$path' to $vuid:$vgid: $!" ); - $ok = 0; + # Special content: subscriber folders + if ( open( FILE, ">>$path/Maildir/subscriptions" ) ) { + foreach my $subscription (@subscriptions) { + print FILE "$subscription\n"; } - if ( !chmod( 0600, @files ) ) { - logmsg( 'warning', "warning: cannot chmod '$path' to 0600: $!" ); - $ok = 0; - } + close(FILE); + } else { + logmsg( 'warning', "warning: cannot fill $path/subscriptions: $!" ); + $ok = 0; + } - return sieveconfigmake($path) and $ok; + if ( !chown( $vuid, $vgid, $path, @dirs, @files ) ) { + logmsg( 'warning', "warning: cannot chown '$path' to $vuid:$vgid: $!" ); + $ok = 0; + } + if ( !chmod( 0600, @files ) ) { + logmsg( 'warning', "warning: cannot chmod '$path' to 0600: $!" ); + $ok = 0; + } + + return sieveconfigmake($path) and $ok; } # ritorna una lista con tutti i file (no path) presenti in una directory sub filelist($) { - my ($path) = @_; - my @filelist; - if ( !opendir( DIR, $path ) ) { - logmsg( 'warning', "warning: cannot read '$path': $!" ); - return undef; - } - @filelist = grep { not /^(\.|\.\.)$/ } readdir(DIR); - closedir(DIR); - return @filelist; + my ($path) = @_; + my @filelist; + if ( !opendir( DIR, $path ) ) { + logmsg( 'warning', "warning: cannot read '$path': $!" ); + return undef; + } + @filelist = grep { not /^(\.|\.\.)$/ } readdir(DIR); + closedir(DIR); + return @filelist; } # calcola la directory in cui deve trovarsi una maildir in base al suo # numero di sequenza sub compute_dir($) { - my ($usercount) = @_; - my ( $dircount, $prefix ); - $dircount = POSIX::floor( ( $usercount - 1 ) / 100 ) - 1; - $prefix = ""; - while ( $dircount >= 0 ) { - $prefix = ( $dircount % 62 ) . "/$prefix"; - $dircount = POSIX::floor( $dircount / 62 ) - 1; - } - return $prefix; + my ($usercount) = @_; + my ( $dircount, $prefix ); + $dircount = POSIX::floor( ( $usercount - 1 ) / 100 ) - 1; + $prefix = ""; + while ( $dircount >= 0 ) { + $prefix = ( $dircount % 62 ) . "/$prefix"; + $dircount = POSIX::floor( $dircount / 62 ) - 1; + } + return $prefix; } # elenca tutte le caselle di posta presenti in un dominio sub maildirlist($$) { - my ( $path, $usercount ) = @_; - my @filelist; - my %dirlist; - my $dir; - for ( my $i = 1 ; $i <= $usercount ; $i += 100 ) { - $dir = "$path/" . compute_dir($i); - $dirlist{$dir} = 1; - push @filelist, map { "$dir$_/" } filelist($dir) if -d $dir; - } - @filelist = grep { !$dirlist{$_} } @filelist; - return @filelist; + my ( $path, $usercount ) = @_; + my @filelist; + my %dirlist; + my $dir; + for ( my $i = 1 ; $i <= $usercount ; $i += 100 ) { + $dir = "$path/" . compute_dir($i); + $dirlist{$dir} = 1; + push @filelist, map { "$dir$_/" } filelist($dir) if -d $dir; + } + @filelist = grep { !$dirlist{$_} } @filelist; + return @filelist; } sub sys_or_log(@) { - if ($dry_run) { - return 0; - } - system(@_); - if ( $? == 0 ) { - return 1; # all ok - } - elsif ( $? == -1 ) { - logmsg( 'warning', - "warning: failed to execute '" . join( ' ', @_ ) . "': $!" ); - } - elsif ( $? & 127 ) { - logmsg( - 'warning', - "warning: child '" - . join( ' ', @_ ) - . "' died with signal %d, %s coredump\n", - ( $? & 127 ), - ( $? & 128 ) ? 'with' : 'without' - ); - } - else { - logmsg( 'warning', - "warning: child '" . join( ' ', @_ ) . "' exited with value %d", - $? >> 8 ); - } + if ($dry_run) { return 0; + } + system(@_); + if ( $? == 0 ) { + return 1; # all ok + } elsif ( $? == -1 ) { + logmsg( 'warning', + "warning: failed to execute '" . join( ' ', @_ ) . "': $!" ); + } elsif ( $? & 127 ) { + logmsg( + 'warning', + "warning: child '" + . join( ' ', @_ ) + . "' died with signal %d, %s coredump\n", + ( $? & 127 ), + ( $? & 128 ) ? 'with' : 'without' + ); + } else { + logmsg( 'warning', + "warning: child '" . join( ' ', @_ ) . "' exited with value %d", + $? >> 8 ); + } + return 0; } sub check_domains ($) { - my ($dbh) = @_; - my %domains; - my $sth; + my ($dbh) = @_; + my %domains; + my $sth; - # prelevo domini esistenti - $sth = $dbh->prepare("SELECT DISTINCT D.* FROM $db_virtual_domains D INNER JOIN $db_virtual_domain_users U ON D.id = U.id_domain"); - if ( !$sth->execute ) { - logmsg( 'error', 'unable to fetch domains list' ); - logmsg( 'error', $dbh->errstr ); - return 0; - } - while ( my $res = $sth->fetchrow_hashref ) { - $domains{ $res->{"name"} } = $res; - } + # prelevo domini esistenti + $sth = $dbh->prepare("SELECT DISTINCT D.* FROM $db_virtual_domains D INNER JOIN $db_virtual_domain_users U ON D.id = U.id_domain"); + if ( !$sth->execute ) { + logmsg( 'error', 'unable to fetch domains list' ); + logmsg( 'error', $dbh->errstr ); + return 0; + } + while ( my $res = $sth->fetchrow_hashref ) { + $domains{ $res->{"name"} } = $res; + } - # test 0: directory presence - unless ( -d $domaindir ) { - logmsg( 'notice', "creating root domain directory: $domaindir" ); - mkpath( $domaindir, 0, 0700); - } - unless ( -d $deldir ) { - logmsg( 'notice', "creating root trash directory: $deldir" ); - mkpath( $deldir, 0, 0700); - } + # test 0: directory presence + unless ( -d $domaindir ) { + logmsg( 'notice', "creating root domain directory: $domaindir" ); + mkpath( $domaindir, 0, 0700); + } + unless ( -d $deldir ) { + logmsg( 'notice', "creating root trash directory: $deldir" ); + mkpath( $deldir, 0, 0700); + } - # test 1: presenza di directory di dominio per domini - # inesistenti o errati - foreach my $domain ( filelist($domaindir) ) { - if ( !$domains{$domain} ) { - logmsg( 'notice', "unknown directory found: $domaindir/$domain" ); - my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); - sys_or_log("mv $domaindir/$domain $deldir/${domain}_$deldate"); - } + # test 1: presenza di directory di dominio per domini + # inesistenti o errati + foreach my $domain ( filelist($domaindir) ) { + if ( !$domains{$domain} ) { + logmsg( 'notice', "unknown directory found: $domaindir/$domain" ); + my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); + sys_or_log("mv $domaindir/$domain $deldir/${domain}_$deldate"); } + } - foreach my $domain ( keys %domains ) { - next unless $domain =~ /^([-a-z0-9]+\.)*[-a-z0-9]+$/; - my $ddata = $domains{$domain}; - my $dir = "$domaindir/$domain"; + foreach my $domain ( keys %domains ) { + next unless $domain =~ /^([-a-z0-9]+\.)*[-a-z0-9]+$/; + my $ddata = $domains{$domain}; + my $dir = "$domaindir/$domain"; - # test 2: eliminazione di domini cancellati - if ( $ddata->{deleted} ) { - logmsg( 'notice', "deleted domain: $domain" ); - if ( !$dry_run ) { - if ( - !( - $dbh->begin_work and $dbh->do( -"DELETE FROM $db_virtual_domain_aliases WHERE id_domain = ?", - {}, - $ddata->{id} - ) - and $dbh->do( -"DELETE FROM $db_virtual_domain_users WHERE id_domain = ?", - {}, - $ddata->{id} - ) - and $dbh->do( - "DELETE FROM $db_virtual_domains WHERE id = ?", - {}, $ddata->{id} ) - and $dbh->commit - ) + # test 2: eliminazione di domini cancellati + if ( $ddata->{deleted} ) { + logmsg( 'notice', "deleted domain: $domain" ); + if ( !$dry_run ) { + if ( + !( + $dbh->begin_work and $dbh->do( + "DELETE FROM $db_virtual_domain_aliases WHERE id_domain = ?", + { + }, + $ddata->{id} + ) + and $dbh->do( + "DELETE FROM $db_virtual_domain_users WHERE id_domain = ?", + { + }, + $ddata->{id} ) - { - logmsg( 'warning', - "warning: cannot remove deleted $domain from db" ); - logmsg( 'warning', "warning: " . $dbh->errstr ); - } - } - - if ( -d $dir ) { - my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); - sys_or_log("mv $dir $deldir/${domain}_$deldate"); - } + and $dbh->do( + "DELETE FROM $db_virtual_domains WHERE id = ?", + { + }, $ddata->{id} ) + and $dbh->commit + ) + ) { + logmsg( 'warning', + "warning: cannot remove deleted $domain from db" ); + logmsg( 'warning', "warning: " . $dbh->errstr ); } - else { + } - # test 3: creazione domini nuovi o cancellati - if ( !-d $dir ) { - if ( -e $dir ) { - logmsg( 'warning', - "warning: $dir is not a directory, trying to remove it" - ); - if ( !$dry_run ) { - unlink($dir) - and logmsg( 'warning', "warning: $dir removed" ); - } - } - logmsg( 'notice', "new domain: $domain" ); - if ( !$dry_run ) { - if ( !mkdir( $dir, 0755 ) ) { - logmsg( 'warning', - "warning: cannot create '$dir': $!" ); - } - elsif ( !chown( $vuid, $vgid, $dir ) ) { - logmsg( 'warning', - "warning: cannot chown '$dir' to $vuid:$vgid: $!" ); - } - else { - if ( - !$dbh->do( -"UPDATE $db_virtual_domains SET last_modified = CURRENT_TIMESTAMP WHERE id = get_id_domain(?)", - {}, - $domain - ) - ) - { - logmsg( 'warning', - "warning: cannot update $domain status" ); - logmsg( 'warning', "warning: " . $dbh->errstr ); - } - } - } + if ( -d $dir ) { + my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); + sys_or_log("mv $dir $deldir/${domain}_$deldate"); + } + } else { + + # test 3: creazione domini nuovi o cancellati + if ( !-d $dir ) { + if ( -e $dir ) { + logmsg( 'warning', + "warning: $dir is not a directory, trying to remove it" + ); + if ( !$dry_run ) { + unlink($dir) + and logmsg( 'warning', "warning: $dir removed" ); + } + } + logmsg( 'notice', "new domain: $domain" ); + if ( !$dry_run ) { + if ( !mkdir( $dir, 0755 ) ) { + logmsg( 'warning', + "warning: cannot create '$dir': $!" ); + } elsif ( !chown( $vuid, $vgid, $dir ) ) { + logmsg( 'warning', + "warning: cannot chown '$dir' to $vuid:$vgid: $!" ); + } else { + if ( + !$dbh->do( + "UPDATE $db_virtual_domains SET last_modified = CURRENT_TIMESTAMP WHERE id = get_id_domain(?)", + { + }, + $domain + ) + ) { + logmsg( 'warning', + "warning: cannot update $domain status" ); + logmsg( 'warning', "warning: " . $dbh->errstr ); } + } } + } } + } - return 1; + return 1; } sub check_users($$) { - my ( $dbh, $full ) = @_; - my $sth; - my %domains; + my ( $dbh, $full ) = @_; + my $sth; + my %domains; - # prelevo domini modificati (o tutti i domini) - if ($full) { - $sth = $dbh->prepare( -"SELECT * FROM $db_virtual_domains;" - ); + # prelevo domini modificati (o tutti i domini) + if ($full) { + $sth = $dbh->prepare( + "SELECT * FROM $db_virtual_domains;" + ); + } else { + $sth = + $dbh->prepare( + "SELECT * FROM $db_virtual_domains WHERE last_modified > last_updated OR last_updated IS NULL;" + ); + } + if ( !$sth->execute ) { + logmsg( 'error', 'unable to fetch modified domains list' ); + logmsg( 'error', $dbh->errstr ); + return 0; + } + while ( my $res = $sth->fetchrow_hashref ) { + $domains{ $res->{"name"} } = $res; + } + + foreach my $domain ( keys %domains ) { + my $ddata = $domains{$domain}; + my $ddir = "$domaindir/$domain"; + my $ok = 1; + + logmsg( 'notice', "checking domain $domain" ); + + # prelevo i dati sugli utenti del dominio + my %users; + $sth = $dbh->prepare( + "SELECT * FROM $db_virtual_domain_users WHERE id_domain = ?;"); + if ( !$sth->execute( $ddata->{id} ) ) { + logmsg( 'error', 'unable to fetch $domain users list' ); + logmsg( 'error', $dbh->errstr ); + next; } - else { - $sth = - $dbh->prepare( -"SELECT * FROM $db_virtual_domains WHERE last_modified > last_updated OR last_updated IS NULL;" - ); - } - if ( !$sth->execute ) { - logmsg( 'error', 'unable to fetch modified domains list' ); - logmsg( 'error', $dbh->errstr ); - return 0; - } while ( my $res = $sth->fetchrow_hashref ) { - $domains{ $res->{"name"} } = $res; + $users{ $res->{"name"} } = $res; } - foreach my $domain ( keys %domains ) { - my $ddata = $domains{$domain}; - my $ddir = "$domaindir/$domain"; - my $ok = 1; + # prelevo i dati sul filesystem + my @maildirs = maildirlist( $ddir, $ddata->{usercount} ); - logmsg( 'notice', "checking domain $domain" ); + # test 4: controlla che non ci siano file estranei/utenti cancellati + # nella directory del dominio + foreach my $maildir (@maildirs) { + my $user = $maildir; + $user =~ s%^.*/([^/]+)/$%$1%; + if ( !$users{$user} + || "$domaindir/$users{$user}->{maildir}" ne $maildir ) { + logmsg( 'notice', "invalid or deleted user: $user\@$domain " ); + my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); + sys_or_log("mv $maildir $deldir/$user\@${domain}_$deldate") + or $ok = 0; + } else { + $users{$user}->{found} = 1; + $users{$user}->{sieveok} = check_sieve($maildir); + } + } - # prelevo i dati sugli utenti del dominio - my %users; - $sth = $dbh->prepare( - "SELECT * FROM $db_virtual_domain_users WHERE id_domain = ?;"); - if ( !$sth->execute( $ddata->{id} ) ) { - logmsg( 'error', 'unable to fetch $domain users list' ); - logmsg( 'error', $dbh->errstr ); - next; - } - while ( my $res = $sth->fetchrow_hashref ) { - $users{ $res->{"name"} } = $res; - } - - # prelevo i dati sul filesystem - my @maildirs = maildirlist( $ddir, $ddata->{usercount} ); - - # test 4: controlla che non ci siano file estranei/utenti cancellati - # nella directory del dominio - foreach my $maildir (@maildirs) { - my $user = $maildir; - $user =~ s%^.*/([^/]+)/$%$1%; - if ( !$users{$user} - || "$domaindir/$users{$user}->{maildir}" ne $maildir ) - { - logmsg( 'notice', "invalid or deleted user: $user\@$domain " ); - my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); - sys_or_log("mv $maildir $deldir/$user\@${domain}_$deldate") - or $ok = 0; + # test 5: crea utenti mancanti e configurazioni sieve errate + foreach my $user ( keys %users ) { + next unless $user =~ /^([-a-z0-9_]+\.)*[-a-z0-9_]+$/; + if ( !$users{$user}->{found} ) { + logmsg( 'notice', "new user: $user\@$domain" ); + my $path = "$users{$user}->{maildir}"; + $path =~ s%/$%%; + my @path = no_upwards( splitdir($path) ); + $path = $domaindir; + for ( my $i = 0 ; $i < $#path ; $i++ ) { + $path = catdir( $path, $path[$i] ); + if ( !-d $path ) { + if ( !mkdir( $path, 0755 ) ) { + logmsg( 'warning', + "warning: cannot create '$path': $!" ); + $ok = 0; + } elsif ( !chown( $vuid, $vgid, $path ) ) { + logmsg( 'warning', + "warning: cannot chown '$path' to $vuid:$vgid: $!" + ); + $ok = 0; } - else { - $users{$user}->{found} = 1; - $users{$user}->{sieveok} = check_sieve($maildir); - } + } } + maildirmake( "$domaindir/" . catdir(@path) ) + or $ok = 0; + } elsif ( !$users{$user}->{sieveok} ) { + logmsg( 'notice', + "updateing user's sieve script: $user\@$domain" ); + sieveconfigmake( "$domaindir/" . $users{$user}->{maildir} ) + or $ok = 0; + } + } - # test 5: crea utenti mancanti e configurazioni sieve errate - foreach my $user ( keys %users ) { - next unless $user =~ /^([-a-z0-9_]+\.)*[-a-z0-9_]+$/; - if ( !$users{$user}->{found} ) { - logmsg( 'notice', "new user: $user\@$domain" ); - my $path = "$users{$user}->{maildir}"; - $path =~ s%/$%%; - my @path = no_upwards( splitdir($path) ); - $path = $domaindir; - for ( my $i = 0 ; $i < $#path ; $i++ ) { - $path = catdir( $path, $path[$i] ); - if ( !-d $path ) { - if ( !mkdir( $path, 0755 ) ) { - logmsg( 'warning', - "warning: cannot create '$path': $!" ); - $ok = 0; - } - elsif ( !chown( $vuid, $vgid, $path ) ) { - logmsg( 'warning', -"warning: cannot chown '$path' to $vuid:$vgid: $!" - ); - $ok = 0; - } - } - } - maildirmake( "$domaindir/" . catdir(@path) ) - or $ok = 0; - } - elsif ( !$users{$user}->{sieveok} ) { - logmsg( 'notice', - "updateing user's sieve script: $user\@$domain" ); - sieveconfigmake( "$domaindir/" . $users{$user}->{maildir} ) - or $ok = 0; - } - } - - # il dominio e' ok - if ( !$dry_run and $ok ) { - if ( - !$dbh->do( -"UPDATE $db_virtual_domains SET last_updated = CURRENT_TIMESTAMP WHERE id = ?", - {}, - $ddata->{id} - ) - ) - { - logmsg( 'warning', "warning: cannot update $domain status" ); - logmsg( 'warning', "warning: " . $dbh->errstr ); - } - } + # il dominio e' ok + if ( !$dry_run and $ok ) { + if ( + !$dbh->do( + "UPDATE $db_virtual_domains SET last_updated = CURRENT_TIMESTAMP WHERE id = ?", + { + }, + $ddata->{id} + ) + ) { + logmsg( 'warning', "warning: cannot update $domain status" ); + logmsg( 'warning', "warning: " . $dbh->errstr ); + } } + } - return 1; + return 1; } ####################### PROGRAMMA PRINCIPALE ####################### @@ -536,69 +524,66 @@ if ( $pid == 0 ) { - my $shutdown = 0; - sub sig_handler { $shutdown = 1; } + my $shutdown = 0; + sub sig_handler { $shutdown = 1; } - unless ($dont_fork) { - open( STDIN, '</dev/null' ); - open( STDOUT, '>/dev/null' ); - open( STDERR, '>/dev/null' ); + unless ($dont_fork) { + open( STDIN, '</dev/null' ); + open( STDOUT, '>/dev/null' ); + open( STDERR, '>/dev/null' ); - $SIG{HUP} = 'IGNORED'; - $SIG{INT} = \&sig_handler; - $SIG{TERM} = \&sig_handler; - } - else { - $SIG{HUP} = \&sig_handler; - $SIG{INT} = \&sig_handler; - $SIG{TERM} = \&sig_handler; - } + $SIG{HUP} = 'IGNORED'; + $SIG{INT} = \&sig_handler; + $SIG{TERM} = \&sig_handler; + } else { + $SIG{HUP} = \&sig_handler; + $SIG{INT} = \&sig_handler; + $SIG{TERM} = \&sig_handler; + } - $0 = rel2abs($0); + $0 = rel2abs($0); - openlog( 'vmail', 'pid', $syslog_facility ); - logmsg( 'notice', 'vMail daemon booting.' ); + openlog( 'vmail', 'pid', $syslog_facility ); + logmsg( 'notice', 'vMail daemon booting.' ); - my $full_check_countdown = 0; + my $full_check_countdown = 0; - while ( !$shutdown ) { + while ( !$shutdown ) { - my $dbh; - $dbh = - DBI->connect( - "dbi:Pg:dbname=$db_database;host=$db_host;port=$db_port;", - $db_user, $db_pass ); - if ( !$dbh ) { - logmsg( 'error', "error: " . $dbh->errstr ); - } - else { - check_domains($dbh); - if ( $full_check_countdown == 0 ) { - $full_check_countdown = 60; - check_users( $dbh, 1 ); - } - else { - $full_check_countdown--; - check_users( $dbh, 0 ); - } + my $dbh; + $dbh = + DBI->connect( + "dbi:Pg:dbname=$db_database;host=$db_host;port=$db_port;", + $db_user, $db_pass ); + if ( !$dbh ) { + logmsg( 'error', "error: " . $dbh->errstr ); + } else { + check_domains($dbh); + if ( $full_check_countdown == 0 ) { + $full_check_countdown = 60; + check_users( $dbh, 1 ); + } else { + $full_check_countdown--; + check_users( $dbh, 0 ); + } - # disconnessione dal database - $dbh->disconnect; - } + # disconnessione dal database + $dbh->disconnect; + } - last if $dry_run; + last if $dry_run; - sleep(60); - } + sleep(60); + } - logmsg( 'notice', 'vMail daemon shutdown.' ); + logmsg( 'notice', 'vMail daemon shutdown.' ); } if ( $pid > 0 ) { - open( PID, '>/var/run/vmaild.pid' ); - print PID "$pid\n"; - close(PID); + open( PID, '>/var/run/vmaild.pid' ); + print PID "$pid\n"; + close(PID); } exit 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-12 19:19:47
|
Revision: 24 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=24&view=rev Author: mnencia Date: 2007-12-12 08:41:33 -0800 (Wed, 12 Dec 2007) Log Message: ----------- import: renamed maildirmake in homedirmake import: corrected stupid typo in user insert query Modified Paths: -------------- trunk/setup/contrib/vpopmail2panda/import Modified: trunk/setup/contrib/vpopmail2panda/import =================================================================== --- trunk/setup/contrib/vpopmail2panda/import 2007-12-12 15:43:00 UTC (rev 23) +++ trunk/setup/contrib/vpopmail2panda/import 2007-12-12 16:41:33 UTC (rev 24) @@ -100,8 +100,8 @@ return $ok; } -# crea una maildir -sub maildirmake($) { +# crea una homedir +sub homedirmake($) { my ($path) = @_; my @dirs = ( $path, @@ -1094,14 +1094,14 @@ my $home = "$domain/$dirprefix$user"; my $maildir = "$home/Maildir"; if (! -d "$new_panda_domains_dir/$home") { - maildirmake("$new_panda_domains_dir/$home"); + homedirmake("$new_panda_domains_dir/$home"); &convert_old_maildir($domains_real{$domain}->{"users"}->{$user}->{"maildir"}, "$new_panda_domains_dir/$maildir"); } print(OUT "$user\@localdelivery.$domain\t$maildir/\n"); $sth->execute($id_domain, + $user, + $domains_real{$domain}->{"users"}->{$user}->{"password"}, $home, - $domains_real{$domain}->{"users"}->{$user}->{"password"}, - "$maildir/", $domains_real{$domain}->{"users"}->{$user}->{"pop3_enabled"}) or die $dbh->errstr; } $dbh->do("UPDATE $db_virtual_domains SET usercount = ? WHERE id = ?;", {}, $usercount, $id_domain) or die $dbh->errstr; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-12 15:43:04
|
Revision: 23 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=23&view=rev Author: mnencia Date: 2007-12-12 07:43:00 -0800 (Wed, 12 Dec 2007) Log Message: ----------- Now import can guess vpopmail prefix Spletted configuration Modified Paths: -------------- trunk/setup/contrib/vpopmail2panda/import Added Paths: ----------- trunk/setup/contrib/vpopmail2panda/import.conf Modified: trunk/setup/contrib/vpopmail2panda/import =================================================================== --- trunk/setup/contrib/vpopmail2panda/import 2007-12-12 15:12:35 UTC (rev 22) +++ trunk/setup/contrib/vpopmail2panda/import 2007-12-12 15:43:00 UTC (rev 23) @@ -26,45 +26,40 @@ use File::Path; use File::Copy; -# old -my $old_vpopmail_domains_location = "/home/vpopmail/domains"; # for matching purpouse -my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail.gw-posta/domains"; # actual data location -# my $old_vpopmail_domains_location = "/var/lib/vpopmail/domains"; # for matching purpouse -# my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail.xcon/domains"; # actual data location -my $imap_uidfile = "courierimapuiddb"; -my $pop3_uidfile = "courierpop3dsizelist"; -# new -my $new_panda_domains_dir = "/home/mnencia/q2p/domains"; -my $new_panda_confdump_dir = "/home/mnencia/q2p/etc"; -my $vuser = "mnencia"; -my $vgroup = "mnencia"; -my $sieve_script = q|# Sieve Filter +# Conf +my $configfile = $ARGV[0]; -require ["fileinto"]; - -# Spam -if header :comparator "i;ascii-casemap" :is "X-Spam-Flag" "YES" { - fileinto "Spam"; - stop; +unless (defined $configfile and -r $configfile) { + print "E' richiesto un file di configurazione.\n"; + exit 255; } -|; +# old +my ($old_vpopmail_domains_location, $old_vpopmail_domains_dir, + $imap_uidfile, $pop3_uidfile); +# new +my ($sql_dir, $new_panda_domains_dir, $new_panda_confdump_dir, + $vuser, $vgroup, $sieve_script); + # db -my $db_host = "localhost"; -my $db_port = "5432"; -my $db_database = "vmail"; -my $db_user = "vmail"; -my $db_pass = "vmail"; -my $db_alias_domains = "alias_domains"; -my $db_virtual_domains = "virtual_domains"; -my $db_virtual_domain_aliases = "virtual_domain_aliases"; -my $db_virtual_domain_users = "virtual_domain_users"; +my ($db_host, $db_port, $db_database, $db_user, $db_pass, + $db_alias_domains, $db_virtual_domains, $db_virtual_domain_aliases, + $db_virtual_domain_users); # flags my $db_dont_drop = 0; + +open(CONF, "<$configfile") + or die $!; +my $conf = join('', <CONF>); +close(CONF); +eval "# line 1 '$configfile'\n". + "$conf" + or die $@; + my $vuid = getpwnam($vuser) or die "Invalid user in config file. ($vuser)"; my $vgid = getgrnam($vgroup) or die "Invalid group in config file ($vgroup)"; @@ -726,6 +721,17 @@ $domains_alias{$domain} = $real; } else { $domains_real{$domain} = {"dir" => "$old_vpopmail_domains_dir/$domain"}; + # guessing $old_vpopmail_domains_locatio + unless (defined $old_vpopmail_domains_location) { + open(VPASSWD, "<$old_vpopmail_domains_dir/$domain/vpasswd") + or die "Non posso aprire $old_vpopmail_domains_dir/$domain/vapsswd: $!"; + my $line = <VPASSWD>; + close(VPASSWD); + chomp($line); + my @values = split(/:/, $line); + $values[5] =~m%^(.*?)/$domain/%; + $old_vpopmail_domains_location = $1; + } } } @@ -759,13 +765,18 @@ my %user; $user{"password"} = $values[1]; $user{"pop3_enabled"} = ($values[3] eq '0')?'t':'f'; - $values[5] =~ m%$old_vpopmail_domains_location/([^/]+)/((.*/)*([^/]+))%; - if ($domains_alias{$1}) { - $user{"maildir"} = "$old_vpopmail_domains_dir/".$domains_alias{$1}."/$2/Maildir"; - } else { - $user{"maildir"} = "$old_vpopmail_domains_dir/$1/$2/Maildir"; + if ($values[5] =~ m%$old_vpopmail_domains_location/([^/]+)/((.*/)*([^/]+))% ) { + if ($domains_alias{$1}) { + $user{"maildir"} = "$old_vpopmail_domains_dir/".$domains_alias{$1}."/$2/Maildir"; + } else { + $user{"maildir"} = "$old_vpopmail_domains_dir/$1/$2/Maildir"; + } + $users{$values[0]} = \%user; } - $users{$values[0]} = \%user; + else { + print(STDERR "ERROR: $old_vpopmail_domains_location non \xE8 un prefisso di $values[5]\n"); + next; + } } $domains_real{$domain}->{"users"} = \%users; @@ -951,7 +962,7 @@ # cancello il database if (!$db_dont_drop) { - open(DROP, "<sql/drop.sql"); + open(DROP, "<$sql_dir/drop.sql"); $dbh->do(join("",<DROP>)) or die $dbh->errstr; close(DROP); } @@ -959,22 +970,24 @@ print STDERR "INFO: Creating database.\n"; # ricreo il database -open(CREATE, "<sql/create.sql"); +open(CREATE, "<$sql_dir/create.sql"); $dbh->do(join("",<CREATE>)) or die $dbh->errstr; close(CREATE); -open(CREATE, "<sql/functions.sql"); +open(CREATE, "<$sql_dir/functions.sql"); $dbh->do(join("",<CREATE>)) or die $dbh->errstr; close(CREATE); -open(CREATE, "<sql/users.sql"); +open(CREATE, "<$sql_dir/users.sql"); $dbh->do(join("",<CREATE>)) or die $dbh->errstr; close(CREATE); print STDERR "INFO: Filling alias-domains table.\n"; + # generazione tabella alias-domains $sth = $dbh->prepare(qq| INSERT INTO $db_alias_domains (name, destination) VALUES (?, ?); |) or die $dbh->errstr; +mkpath($new_panda_confdump_dir,0,0700); open (OUT, ">$new_panda_confdump_dir/alias-domains"); print(OUT "# File contenete i domini alias di un altro dominio\n"); foreach my $domain (sort keys %domains_alias) { Added: trunk/setup/contrib/vpopmail2panda/import.conf =================================================================== --- trunk/setup/contrib/vpopmail2panda/import.conf (rev 0) +++ trunk/setup/contrib/vpopmail2panda/import.conf 2007-12-12 15:43:00 UTC (rev 23) @@ -0,0 +1,57 @@ +# -*- perl -*- +# Copyright (C) 2007 - Marco Nenciarini <mn...@gr...> +# +# This program 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, or (at your option) +# any later version. +# +# This program 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 this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +# old vpopmail +$old_vpopmail_domains_dir = "/srv/vpopmail/domains"; # actual data location +$imap_uidfile = "courierimapuiddb"; +$pop3_uidfile = "courierpop3dsizelist"; + +# new panda +$sql_dir = "/srv/vmail/sql"; +$new_panda_domains_dir = "/srv/vmail/domains"; +$new_panda_confdump_dir = "/srv/vmail/etc/postfix"; +$vuser = "vmail"; +$vgroup = "vmail"; +$sieve_script = q|# Sieve Filter + +require ["fileinto", "vacation"]; + +# Spam +if header :comparator "i;ascii-casemap" :is "X-Spam-Flag" "YES" { + fileinto "Spam"; + stop; +} + +|; + +# db config +$db_host = "localhost"; +$db_port = "5432"; +$db_database = "vmail"; +$db_user = "vmail"; +$db_pass = "vmail"; +$db_alias_domains = "alias_domains"; +$db_virtual_domains = "virtual_domains"; +$db_virtual_domain_aliases = "virtual_domain_aliases"; +$db_virtual_domain_users = "virtual_domain_users"; + +# flags +$db_dont_drop = 0; + +### DO NOT REMOVE FOLLOWING LINE ### +1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2007-12-12 15:12:32
|
Revision: 22 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=22&view=rev Author: agrassi Date: 2007-12-12 07:12:35 -0800 (Wed, 12 Dec 2007) Log Message: ----------- Improved encrypting function Modified Paths: -------------- trunk/config.php trunk/includes/backend.php Modified: trunk/config.php =================================================================== --- trunk/config.php 2007-12-12 13:36:22 UTC (rev 21) +++ trunk/config.php 2007-12-12 15:12:35 UTC (rev 22) @@ -35,7 +35,7 @@ define('SMTP_HOST','smtp.fastweb.it'); // Encryption algorythm for mailboxes passwords -// currently 'md5' and 'crypt' are supported -define('CRYPT_ALGO','md5'); +// currently 'crypt-md5' and 'crypt-des' are supported +define('CRYPT_ALGO','crypt-md5'); ?> Modified: trunk/includes/backend.php =================================================================== --- trunk/includes/backend.php 2007-12-12 13:36:22 UTC (rev 21) +++ trunk/includes/backend.php 2007-12-12 15:12:35 UTC (rev 22) @@ -191,17 +191,20 @@ // Crypt a password following config file function crypt_pw($clearpw) { + $cset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; + switch(CRYPT_ALGO) { - case 'md5': - return md5($clearpw); - case 'crypt': + case 'crypt-md5': + $salt = '$1$' . substr(str_shuffle($cset), 0, 8) . '$'; + break; + case 'crypt-des': // Salt generation - $cset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; $salt = substr($cset, time() & 63, 1) . substr($cset, time() / 64 & 63, 1); - return crypt($clearpw, $salt); + break; default: die("No encryption algorhytm specified."); } + return crypt($clearpw,$salt); } // crypt_pw() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2007-12-12 13:36:20
|
Revision: 21 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=21&view=rev Author: agrassi Date: 2007-12-12 05:36:22 -0800 (Wed, 12 Dec 2007) Log Message: ----------- Both md5 and crypt are now supported Modified Paths: -------------- trunk/config.php trunk/includes/backend.php Modified: trunk/config.php =================================================================== --- trunk/config.php 2007-12-12 11:41:20 UTC (rev 20) +++ trunk/config.php 2007-12-12 13:36:22 UTC (rev 21) @@ -34,5 +34,8 @@ define('MAIL_FROM','new...@gr...'); define('SMTP_HOST','smtp.fastweb.it'); +// Encryption algorythm for mailboxes passwords +// currently 'md5' and 'crypt' are supported +define('CRYPT_ALGO','md5'); ?> Modified: trunk/includes/backend.php =================================================================== --- trunk/includes/backend.php 2007-12-12 11:41:20 UTC (rev 20) +++ trunk/includes/backend.php 2007-12-12 13:36:22 UTC (rev 21) @@ -188,6 +188,23 @@ * Mail creating/modifying/deleting functions */ +// Crypt a password following config file +function crypt_pw($clearpw) { + + switch(CRYPT_ALGO) { + case 'md5': + return md5($clearpw); + case 'crypt': + // Salt generation + $cset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; + $salt = substr($cset, time() & 63, 1) . substr($cset, time() / 64 & 63, 1); + return crypt($clearpw, $salt); + default: + die("No encryption algorhytm specified."); + } +} // crypt_pw() + + // Delete $email function deleteEmail($email) { @@ -212,13 +229,9 @@ check_permission('domain',$status->domain); - // Salt generation - $cset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; - $salt = substr($cset, time() & 63, 1) . substr($cset, time() / 64 & 63, 1); - $result = $dbh->getOne('SELECT update_user(?,?)', array ( $email, - crypt($password, $salt) + crypt_pw($password) )); check_db_error($result); @@ -264,13 +277,9 @@ check_permission('domain',$status->domain); - // Salt generation - $cset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; - $salt = substr($cset, time() & 63, 1) . substr($cset, time() / 64 & 63, 1); - $result = $dbh->getOne('SELECT create_user(?,?)', array ( $email, - crypt($password, $salt) + crypt_pw($password) )); check_db_error($result); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2007-12-12 11:41:19
|
Revision: 20 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=20&view=rev Author: agrassi Date: 2007-12-12 03:41:20 -0800 (Wed, 12 Dec 2007) Log Message: ----------- Fixed missing navigation link creation in changemypw module Modified Paths: -------------- trunk/modules/chmypw.php Modified: trunk/modules/chmypw.php =================================================================== --- trunk/modules/chmypw.php 2007-12-11 17:14:07 UTC (rev 19) +++ trunk/modules/chmypw.php 2007-12-12 11:41:20 UTC (rev 20) @@ -23,6 +23,9 @@ */ +add_navigation_link('cambio password', + make_link(array ('mode'))); + // If there is no password, ask for it if (empty ($status->data) || !check_scookie()) { create_scookie(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-11 17:14:03
|
Revision: 19 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=19&view=rev Author: mnencia Date: 2007-12-11 09:14:07 -0800 (Tue, 11 Dec 2007) Log Message: ----------- Added import progress indication. Debugged imap keywords migration. Removed all <$dir/*> construct because are buggy with spaces in names. Modified Paths: -------------- trunk/setup/contrib/vpopmail2panda/import Modified: trunk/setup/contrib/vpopmail2panda/import =================================================================== --- trunk/setup/contrib/vpopmail2panda/import 2007-12-11 12:05:01 UTC (rev 18) +++ trunk/setup/contrib/vpopmail2panda/import 2007-12-11 17:14:07 UTC (rev 19) @@ -28,7 +28,7 @@ # old my $old_vpopmail_domains_location = "/home/vpopmail/domains"; # for matching purpouse -my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail.gw/domains"; # actual data location +my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail.gw-posta/domains"; # actual data location # my $old_vpopmail_domains_location = "/var/lib/vpopmail/domains"; # for matching purpouse # my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail.xcon/domains"; # actual data location my $imap_uidfile = "courierimapuiddb"; @@ -158,10 +158,13 @@ sub scan_maildir($$) { my ($dir, $map) = @_; - foreach (<$dir/*>) { - s/^$dir\///; - next if ($_ eq "." || $_ eq ".."); - + if (! opendir(DIR, $dir)) { + print(STDERR "ERROR: Impossibile aprire la directory $dir: $!\n"); + return; + } + my @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); + closedir(DIR); + foreach (@list) { my $base_fname; if (/^([^:]+):2,/) { ($base_fname) = ($1); @@ -380,49 +383,54 @@ my $keyword_dir = "$old/courierimapkeywords"; my $dovecot_keyfname = "$new/dovecot-keywords"; - if (!-f "$keyword_dir/:list") { - # no keywords - return; - } + return if ! -d $keyword_dir; my (%keywords, %files); my $f; - open ($f, "$keyword_dir/:list") || die $!; - # read keyword names - while (<$f>) { - chomp $_; - last if (/^$/); - $keywords{$_} = scalar keys %keywords; - } - # read filenames -> keywords mapping - while (<$f>) { - if (/([^:]+):([\d ]+)$/) { - my $fname = $1; - foreach (sort { $a <=> $b } split(" ", $2)) { - $files{$fname} .= chr(97 + $_); + if (-f "$keyword_dir/:list") { + open ($f, "$keyword_dir/:list") || die $!; + # read keyword names + while (<$f>) { + chomp $_; + + last if (/^$/); + $keywords{$_} = scalar keys %keywords; + } + # read filenames -> keywords mapping + while (<$f>) { + if (/([^:]+):([\d ]+)$/) { + my $fname = $1; + foreach (sort { $a <=> $b } split(" ", $2)) { + $files{$fname} .= chr(97 + $_); + } + } else { + print STDERR "WARNING: $keyword_dir/:list: Broken entry: $_\n"; } - } else { - print STDERR "WARNING: $keyword_dir/:list: Broken entry: $_\n"; } + close $f; } - close $f; # read updates from the directory my %updates; - foreach (<$keyword_dir/*>) { - s,^$keyword_dir/,,; + if (! opendir(DIR, $keyword_dir)) { + print(STDERR "ERROR: Impossibile aprire la directory $keyword_dir: $!\n"); + return; + } + my @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); + closedir(DIR); + foreach (@list) { next if ($_ eq ":list"); my $fname = $_; if (/^\.(\d+)\.(.*)$/) { my ($num, $base_fname) = ($1, $2); - if (!defined $updates{$fname}) { - $updates{$fname} = $num; + if (!defined $updates{$base_fname}) { + $updates{$base_fname} = $num; } else { - my $old = $updates{$fname}; + my $old = $updates{$base_fname}; if ($old >= 0 && $num > $old) { - $updates{$fname} = $num; + $updates{$base_fname} = $num; } } } else { @@ -444,7 +452,7 @@ } my @kw_list; - open ($f, "$keyword_dir/$fname") || next; + open ($f, "$keyword_dir/$fname") || die $!; while (<$f>) { chomp $_; my $kw = $_; @@ -478,9 +486,14 @@ # update the maildir files my $cur_dir = "$new/cur"; - foreach (<$cur_dir/*>) { - my $fname = $_; - s,^$cur_dir/,,; + if (! opendir(DIR, $cur_dir)) { + print(STDERR "ERROR: Impossibile aprire la directory $cur_dir: $!\n"); + return; + } + @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); + closedir(DIR); + foreach (@list) { + my $fname = "$cur_dir/$_"; my ($base_fname, $flags, $extra_flags); if (/^([^:]+):2,([^,]*)(,.*)?$/) { @@ -559,8 +572,6 @@ my @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); closedir(DIR); foreach my $item (@list) { - $item =~ s/^$old\///; - my ($ofile, $nfile) = ("$old/$item","$new/$item"); if (! -f $ofile) { @@ -652,12 +663,10 @@ ($uidv, $nextuid, %filename_map) = read_courier_imap($old, $new, $uidv, $nextuid, \%curnew_map, %filename_map); } - if (!$found) { - print STDERR "WARNING: $old: No imap/pop3 uidlist files\n" if (!$childbox); - return; + if ($found) { + write_dovecot_uidlist($old, $new, $uidv, $nextuid, %filename_map); } - write_dovecot_uidlist($old, $new, $uidv, $nextuid, %filename_map); convert_subscriptions($old, $new); convert_keywords($old, $new); } @@ -692,6 +701,8 @@ return $prefix.$name; } +######## BEGIN MAIN CODE ############# + my (@domains, %domains_alias, %domains_real, %domain_real_users, %domain_real_alias); # sanity @@ -700,7 +711,9 @@ exit; } -# leggo la lista dei domini +print STDERR "INFO: Loading domain list.\n"; + +# loading domain list opendir(DDIR,$old_vpopmail_domains_dir) or die "Non posso aprire $old_vpopmail_domains_dir: $!"; @domains = sort grep { /^[^.]/ } readdir(DDIR); closedir(DDIR); @@ -724,6 +737,8 @@ } } +print STDERR "INFO: Loading recipients data.\n"; + # aquisisco gli utenti, gli alias e le newsletter per ogni dominio reale foreach my $domain (keys %domains_real) { @@ -856,6 +871,9 @@ $domains_real{$domain}->{"newsletters"} = \%newsletters; } + +print STDERR "INFO: Removing postmaster cruft.\n"; + # sanity: rimuoviamo schifezze while (my ($domain,$data) = each %domains_real) { @@ -869,6 +887,7 @@ my $removed; my $pass = 0; do { + print STDERR "INFO: Canonicalizing recipients. (Pass: $pass)\n"; while (my ($domain,$data) = each %domains_real) { $removed = 0; foreach my $alias (sort keys %{$data->{"aliases"}}) { @@ -917,6 +936,9 @@ $pass = $pass + 1; } while ($removed); # ripetiamo fino a che c'\xE8 almeno una cancellazione... + +print STDERR "INFO: Dropping old database.\n"; + # generazione files e tabelle postgres use DBI; use DBD::Pg qw(:pg_types); @@ -934,6 +956,8 @@ close(DROP); } +print STDERR "INFO: Creating database.\n"; + # ricreo il database open(CREATE, "<sql/create.sql"); $dbh->do(join("",<CREATE>)) or die $dbh->errstr; @@ -945,6 +969,8 @@ $dbh->do(join("",<CREATE>)) or die $dbh->errstr; close(CREATE); +print STDERR "INFO: Filling alias-domains table.\n"; + # generazione tabella alias-domains $sth = $dbh->prepare(qq| INSERT INTO $db_alias_domains (name, destination) VALUES (?, ?); @@ -958,6 +984,8 @@ } close(OUT); +print STDERR "INFO: Filling virtual-domains table.\n"; + # generazione tabella virtual-domains $sth = $dbh->prepare(qq| INSERT INTO $db_virtual_domains (name, unknown_to) VALUES (?, ?); @@ -976,6 +1004,8 @@ } close(OUT); +print STDERR "INFO: Filling virtual-domain-aliases table.\n"; + # generazione tabella virtual-domain-aliases $sth = $dbh->prepare(qq| INSERT INTO $db_virtual_domain_aliases (id_domain, name, destination) VALUES (?, ?, ?); @@ -1012,6 +1042,8 @@ } close(OUT); +print STDERR "INFO: Filling virtual-domain-users table and importing mail.\n"; + # generazione tabella virtual-domain-users e delle caselle di posta if (! -d "$new_panda_domains_dir") { mkdir ("$new_panda_domains_dir", 0700) or die "Non posso creare $new_panda_domains_dir: $!"; @@ -1063,10 +1095,14 @@ } close(OUT); +print STDERR "INFO: Congratulation! Everything's ok. Committing db changes...\n"; + # disconnessione dal database $dbh->commit; $dbh->disconnect; +print STDERR "INFO: Done.\n"; + exit; ########################################## END ########################## # debug print alias domains This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-11 12:04:56
|
Revision: 18 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=18&view=rev Author: mnencia Date: 2007-12-11 04:05:01 -0800 (Tue, 11 Dec 2007) Log Message: ----------- Don't do directory creation twice Random improvements Modified Paths: -------------- trunk/setup/contrib/vpopmail2panda/import Modified: trunk/setup/contrib/vpopmail2panda/import =================================================================== --- trunk/setup/contrib/vpopmail2panda/import 2007-12-11 11:26:54 UTC (rev 17) +++ trunk/setup/contrib/vpopmail2panda/import 2007-12-11 12:05:01 UTC (rev 18) @@ -109,49 +109,28 @@ sub maildirmake($) { my ($path) = @_; my @dirs = ( + $path, $path . "/Maildir", $path . "/Maildir/new", $path . "/Maildir/cur", $path . "/Maildir/tmp", - $path . "/Maildir/.Drafts", - $path . "/Maildir/.Drafts/new", - $path . "/Maildir/.Drafts/cur", - $path . "/Maildir/.Drafts/tmp", - $path . "/Maildir/.Sent", - $path . "/Maildir/.Sent/new", - $path . "/Maildir/.Sent/cur", - $path . "/Maildir/.Sent/tmp", - $path . "/Maildir/.Spam", $path . "/Maildir/.Spam/new", $path . "/Maildir/.Spam/cur", $path . "/Maildir/.Spam/tmp", - $path . "/Maildir/.Trash", - $path . "/Maildir/.Trash/new", - $path . "/Maildir/.Trash/cur", - $path . "/Maildir/.Trash/tmp", $path . "/sieve", $path . "/sieve/tmp", ); my @files = ( - $path . "/Maildir/.Drafts/maildirfolder", - $path . "/Maildir/.Sent/maildirfolder", + $path . "/Maildir/maildirfolder", $path . "/Maildir/.Spam/maildirfolder", - $path . "/Maildir/.Trash/maildirfolder", $path . "/Maildir/subscriptions", ); - my @subscriptions = - ( "Drafts", "Sent", "Spam", "Trash", ); - my $ok = 1; - if (! -d $path ) { - mkpath( $path, 0, 0700 ); - } - foreach my $dir (@dirs) { - if ( !mkdir( $dir, 0700 ) ) { + if ( !mkpath( $dir, 0, 0700 ) ) { print( STDERR "WARNING: cannot create $dir dir: $!\n" ); $ok = 0; } @@ -164,17 +143,6 @@ close(FILE); } - # Special content: subscriber folders - if ( open( FILE, ">>$path/Maildir/subscriptions" ) ) { - foreach my $subscription (@subscriptions) { - print FILE "$subscription\n"; - } - close(FILE); - } else { - print( STDERR "WARNING: cannot fill $path/subscriptions: $!\n" ); - $ok = 0; - } - if ( !chown( $vuid, $vgid, $path, @dirs, @files ) ) { print( STDERR "WARNING: cannot chown '$path' to $vuid:$vgid: $!\n" ); $ok = 0; @@ -403,6 +371,7 @@ print $f "$_ ".$uidlist_map{$_}."\n"; } close $f; + chmod 0600, $uidlist_fname; chown $vuid, $vgid, $uidlist_fname; } @@ -504,6 +473,7 @@ print $f "$idx $_\n"; } close $f; + chmod 0600, $dovecot_keyfname; chown $vuid, $vgid, $dovecot_keyfname; # update the maildir files @@ -572,10 +542,11 @@ close $fin; close $fout; + chmod 0600, $out_fname; chown $vuid, $vgid, $out_fname; } -sub maildir_copy_messages($$) { +sub dir_copy_messages($$) { my ($old, $new) = @_; my @files; @@ -611,23 +582,51 @@ } -sub curnew_copy_messages($$) { +sub maildir_copy_messages($$) { my ($old, $new) = @_; unless (-d "$old/new" or -d "$old/cur") { return; } - mkpath("$new/cur", 0, 0700); - maildir_copy_messages("$old/cur", "$new/cur"); - mkpath("$new/new", 0, 0700); - maildir_copy_messages("$old/new", "$new/new"); - mkpath("$new/tmp", 0, 0700); + my @dirs = ( + $new, + $new . "/new", + $new . "/cur", + $new . "/tmp", + ); - if ( !chown( $vuid, $vgid, "$new", "$new/new", "$new/cur", "$new/tmp" ) ) { + my @files = ( + $new . "/maildirfolder", + ); + + my $ok = 1; + + foreach my $dir (@dirs) { + next if -d $dir; + if ( !mkpath( $dir, 0, 0700 ) ) { + print( STDERR "WARNING: cannot create $dir dir: $!\n" ); + $ok = 0; + } + } + foreach my $file (@files) { + if ( !open( FILE, ">>$file" ) ) { + print( STDERR "WARNING: cannot create $file file: $!\n" ); + $ok = 0; + } + close(FILE); + } + + dir_copy_messages("$old/cur", "$new/cur"); + dir_copy_messages("$old/new", "$new/new"); + + if ( !chown( $vuid, $vgid, "$new", @dirs, @files ) ) { print( STDERR "WARNING: cannot chown '$new' content to $vuid:$vgid: $!\n" ); } - if ( !chmod( 0700, "$new", "$new/new", "$new/cur", "$new/tmp" ) ) { + if ( !chmod( 0700, "$new", @dirs ) ) { + print( STDERR "WARNING: cannot chmod '$new' content to 0700: $!\n" ); + } + if ( !chmod( 0600, @files ) ) { print( STDERR "WARNING: cannot chmod '$new' content to 0600: $!\n" ); } } @@ -640,7 +639,7 @@ my %curnew_map; my $found = 0; - curnew_copy_messages($old,$new); + maildir_copy_messages($old,$new); if (-f "$old/$pop3_uidfile") { $found = 1; @@ -667,12 +666,12 @@ sub convert_old_maildir($$) { my ($old,$new) = @_; + check_maildir_single($old,$new, 0); + if (! opendir(DIR, $old)) { print(STDERR "ERROR: Impossibile aprire la directory $old: $!\n"); return; } - - check_maildir_single($old,$new, 0); my @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); closedir(DIR); foreach my $item (@list) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-11 11:26:56
|
Revision: 17 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=17&view=rev Author: mnencia Date: 2007-12-11 03:26:54 -0800 (Tue, 11 Dec 2007) Log Message: ----------- Now the importer converts maildir from courier format to dovecot one Reindented the importer code Modified Paths: -------------- trunk/setup/contrib/vpopmail2panda/import Modified: trunk/setup/contrib/vpopmail2panda/import =================================================================== --- trunk/setup/contrib/vpopmail2panda/import 2007-12-10 15:44:02 UTC (rev 16) +++ trunk/setup/contrib/vpopmail2panda/import 2007-12-11 11:26:54 UTC (rev 17) @@ -2,6 +2,10 @@ # # Copyright (C) 2007 - Marco Nenciarini <mn...@gr...> # +# Maildir Migration code from Courier IMAP (any version) and Courier +# POP3 (v0.43+) to Dovecot v1.0 taken from courier-dovecot-migrate.pl +# v1.1.7 by Timo Sirainen. +# # This program 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, or (at your option) @@ -20,12 +24,15 @@ use warnings; use File::Path; +use File::Copy; # old my $old_vpopmail_domains_location = "/home/vpopmail/domains"; # for matching purpouse my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail.gw/domains"; # actual data location # my $old_vpopmail_domains_location = "/var/lib/vpopmail/domains"; # for matching purpouse # my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail.xcon/domains"; # actual data location +my $imap_uidfile = "courierimapuiddb"; +my $pop3_uidfile = "courierpop3dsizelist"; # new my $new_panda_domains_dir = "/home/mnencia/q2p/domains"; @@ -37,10 +44,10 @@ require ["fileinto"]; # Spam -if header :comparator "i;ascii-casemap" :is "X-Spam-Flag" "YES" { +if header :comparator "i;ascii-casemap" :is "X-Spam-Flag" "YES" { fileinto "Spam"; stop; -} +} |; @@ -64,45 +71,44 @@ # crea lo script sieve sub sieveconfigmake($) { - my ($path) = @_; + my ($path) = @_; - my %links = (); + my %links = (); - my $ok = 1; + my $ok = 1; - my $sieve_file = "sieve/.dovecot.sieve.sieve"; - - # Special content: sieve script - if ( open( FILE, ">$path/$sieve_file" ) ) { - print FILE $sieve_script; - close(FILE); - } - else { - print( STDERR "WARNING: cannot fill $path/$sieve_file: $!\n" ); - $ok = 0; - } + my $sieve_file = "sieve/.dovecot.sieve.sieve"; - if ( !symlink( "$sieve_file", $path . "/.dovecot.sieve" ) ) { - print( STDERR "WARNING: cannot symlink '$path/.dovecot.sieve' to '$sieve_file': $!\n"); - $ok = 0; - } + # Special content: sieve script + if ( open( FILE, ">$path/$sieve_file" ) ) { + print FILE $sieve_script; + close(FILE); + } else { + print( STDERR "WARNING: cannot fill $path/$sieve_file: $!\n" ); + $ok = 0; + } - if ( !chown( $vuid, $vgid, "$path/$sieve_file" ) ) { - print( STDERR "WARNING: cannot chown '$path/$sieve_file' to $vuid:$vgid: $!\n"); - $ok = 0; - } - if ( !chmod( 0600, "$path/$sieve_file" ) ) { - print( STDERR "WARNING: cannot chmod '$path/$sieve_file' to 0600: $!\n" ); - $ok = 0; - } + if ( !symlink( "$sieve_file", $path . "/.dovecot.sieve" ) ) { + print( STDERR "WARNING: cannot symlink '$path/.dovecot.sieve' to '$sieve_file': $!\n"); + $ok = 0; + } - return $ok; + if ( !chown( $vuid, $vgid, "$path/$sieve_file" ) ) { + print( STDERR "WARNING: cannot chown '$path/$sieve_file' to $vuid:$vgid: $!\n"); + $ok = 0; + } + if ( !chmod( 0600, "$path/$sieve_file" ) ) { + print( STDERR "WARNING: cannot chmod '$path/$sieve_file' to 0600: $!\n" ); + $ok = 0; + } + + return $ok; } # crea una maildir sub maildirmake($) { - my ($path) = @_; - my @dirs = ( + my ($path) = @_; + my @dirs = ( $path . "/Maildir", $path . "/Maildir/new", $path . "/Maildir/cur", @@ -125,95 +131,557 @@ $path . "/Maildir/.Trash/tmp", $path . "/sieve", $path . "/sieve/tmp", - ); + ); - my @files = ( - $path . "/Maildir/.Drafts/maildirfolder", - $path . "/Maildir/.Sent/maildirfolder", - $path . "/Maildir/.Spam/maildirfolder", - $path . "/Maildir/.Trash/maildirfolder", - $path . "/Maildir/subscriptions", - ); + my @files = ( + $path . "/Maildir/.Drafts/maildirfolder", + $path . "/Maildir/.Sent/maildirfolder", + $path . "/Maildir/.Spam/maildirfolder", + $path . "/Maildir/.Trash/maildirfolder", + $path . "/Maildir/subscriptions", + ); - my @subscriptions = - ( "Drafts", "Sent", "Spam", "Trash", ); + my @subscriptions = + ( "Drafts", "Sent", "Spam", "Trash", ); - my $ok = 1; + my $ok = 1; - if (! -d $path ) { - mkpath( $path, 0, 0700 ); - } - - foreach my $dir (@dirs) { - if ( !mkdir( $dir, 0700 ) ) { - print( STDERR "WARNING: cannot create $dir dir: $!\n" ); - $ok = 0; + if (! -d $path ) { + mkpath( $path, 0, 0700 ); + } + + foreach my $dir (@dirs) { + if ( !mkdir( $dir, 0700 ) ) { + print( STDERR "WARNING: cannot create $dir dir: $!\n" ); + $ok = 0; + } + } + foreach my $file (@files) { + if ( !open( FILE, ">>$file" ) ) { + print( STDERR "WARNING: cannot create $file file: $!\n" ); + $ok = 0; + } + close(FILE); + } + + # Special content: subscriber folders + if ( open( FILE, ">>$path/Maildir/subscriptions" ) ) { + foreach my $subscription (@subscriptions) { + print FILE "$subscription\n"; + } + close(FILE); + } else { + print( STDERR "WARNING: cannot fill $path/subscriptions: $!\n" ); + $ok = 0; + } + + if ( !chown( $vuid, $vgid, $path, @dirs, @files ) ) { + print( STDERR "WARNING: cannot chown '$path' to $vuid:$vgid: $!\n" ); + $ok = 0; + } + if ( !chmod( 0600, @files ) ) { + print( STDERR "WARNING: cannot chmod '$path' to 0600: $!\n" ); + $ok = 0; + } + + return sieveconfigmake($path) and $ok; +} + +sub scan_maildir($$) { + my ($dir, $map) = @_; + + foreach (<$dir/*>) { + s/^$dir\///; + next if ($_ eq "." || $_ eq ".."); + + my $base_fname; + if (/^([^:]+):2,/) { + ($base_fname) = ($1); + } else { + $base_fname = $_; + } + $$map{$base_fname} = 1; + } +} + +sub scan_curnew($$$) { + my ($old, $new, $map) = @_; + + return if (scalar keys %$map > 0); + + $$map{'.'} = 1; # just to make sure the map is never empty + scan_maildir("$new/new", $map); + scan_maildir("$new/cur", $map); +} + +sub read_courier_pop3($$$) { + my ($old, $new, $curnew_map) = @_; + + my ($pop3_uidv, $pop3_nextuid) = (-1, 0); + my %filename_map; + + my $f; + my $pop3_fname = "$old/$pop3_uidfile"; + open ($f, $pop3_fname) || die $!; + my $pop3_hdr = <$f>; + if ($pop3_hdr =~ /^\/2 (\d+) (\d+)$/) { + $pop3_nextuid = $1; + $pop3_uidv = $2; + } elsif ($pop3_hdr !~ /^\//) { + # plain UIDs + $pop3_uidv = 0; + } else { + print STDERR "ERROR: $pop3_fname: Broken header: $pop3_hdr\n"; + close $f; + return (-1, 0); + } + my %uidvals; + + my $max_uidv = -1; + my $max_uidv_count = 0; + my $max_uidv_nextuid = 0; + + my $curnew_read = 0; + $curnew_read = 1 if (scalar keys %$curnew_map > 0); + + while (<$f>) { + chomp $_; + + if ($pop3_uidv > 0 && /^([^ ]+) (\d+) (\d+):(\d+)$/) { + my ($fname, $fsize, $uid, $uidv) = ($1, $2, $3, $4); + # get base filename + $fname =~ s/^([^:]+).*$/$1/; + + next if ($curnew_read && !defined($$curnew_map{$fname})); + + if ($uid == 0) { + # use filename + $filename_map{$fname} = $fname; + } else { + $filename_map{$fname} = "$uidv:$uid"; + $uidvals{$uidv}++; + if ($uidvals{$uidv} > $max_uidv_count) { + $max_uidv = $uidv; + $max_uidv_count = $uidvals{$uidv}; + $max_uidv_nextuid = $uid; } + } + } elsif ($pop3_uidv == 0 && /^([^ ]+) (\d+)$/) { + my ($fname, $uid) = ($1, $2); + $fname =~ s/^([^:]+).*$/$1/; + + next if ($curnew_read && !defined($$curnew_map{$fname})); + $filename_map{$fname} = $uid; + } else { + print STDERR "ERROR: $pop3_fname: Broken line: $_\n"; } - foreach my $file (@files) { - if ( !open( FILE, ">>$file" ) ) { - print( STDERR "WARNING: cannot create $file file: $!\n" ); - $ok = 0; + } + close $f; + + if ($max_uidv == $pop3_uidv && $max_uidv_nextuid < $pop3_nextuid) { + $max_uidv_nextuid = $pop3_nextuid; + } + + my $mail_count = scalar keys %filename_map; + if ($mail_count != $max_uidv_count && !$curnew_read) { + # read the maildir and try again. if some of the files are already + # deleted, we can ignore them + scan_curnew($old, $new, $curnew_map); + return &read_courier_pop3($old, $new, $curnew_map); + } + $max_uidv = -1 if ($max_uidv == 0); + return ($max_uidv, $max_uidv_nextuid, %filename_map); +} + +sub read_courier_imap($$$$$%) { + my ($old, $new, $pop3_uidv, $pop3_nextuid, $curnew_map, %filename_map) = @_; + + # check if we can preserve IMAP UIDs + my $imap_fname = "$old/$imap_uidfile"; + if (!-f $imap_fname) { + return; + } + + my $f; + open ($f, $imap_fname) || die $!; + my $imap_hdr = <$f>; + if ($imap_hdr !~ /^1 (\d+) (\d+)$/) { + print STDERR "ERROR: $imap_fname: Broken header: $imap_hdr\n"; + close $f; + return; + } + my ($imap_uidv, $imap_nextuid) = ($1, $2); + + if ($pop3_uidv == -1) { + # no pop3 uidlist file + $pop3_uidv = $imap_uidv; + $pop3_nextuid = 0; + } elsif ($pop3_uidv != $imap_uidv) { + # UIDVALIDITY is different with POP3 and IMAP, we can't use it. + # But if no files actually exist, don't bother complaining. + scan_curnew($old, $new, $curnew_map); + } + + my $curnew_read = 0; + $curnew_read = 1 if (scalar keys %$curnew_map > 0); + + my $imap_mail_count = 0; + my $imap_changes = 0; + my %found_files; + my $found_files_looked_up = 0; + while (<$f>) { + chomp $_; + + if (/^(\d+) (.*)$/) { + my ($uid, $fname) = ($1, $2); + # get the base filename + $fname =~ s/^([^:]+).*$/$1/; + + next if ($curnew_read && !defined($$curnew_map{$fname})); + + my $changed = 0; + if (defined $filename_map{$fname}) { + if ($pop3_uidv == $imap_uidv) { + if ($filename_map{$fname} ne "$imap_uidv:$uid") { + $changed = 1; + } + } else { + $changed = 1; } - close(FILE); + } else { + # not in pop3 list + if ($pop3_uidv == $imap_uidv && $uid >= $pop3_nextuid) { + $filename_map{$fname} = "$imap_uidv:$uid"; + $pop3_nextuid = $uid + 1; + } else { + $changed = 1; + } + } + if ($changed && !$curnew_read) { + scan_curnew($old, $new, $curnew_map); + $curnew_read = 1; + next if (!defined($$curnew_map{$fname})); + } + + $imap_changes++ if ($changed); + $imap_mail_count++; + } else { + print STDERR "ERROR: $imap_fname: Broken header\n"; } + } + close $f; - # Special content: subscriber folders - if ( open( FILE, ">>$path/Maildir/subscriptions" ) ) { - foreach my $subscription (@subscriptions) { - print FILE "$subscription\n"; + if ($pop3_uidv == $imap_uidv && $pop3_nextuid < $imap_nextuid) { + $pop3_nextuid = $imap_nextuid; + } + + return ($pop3_uidv, $pop3_nextuid, %filename_map); +} + +sub write_dovecot_uidlist($$$$%) { + my ($old, $new, $uidv, $nextuid, %filename_map) = @_; + + return if ($uidv <= 0 || $nextuid == 0); + + my $uidlist_fname = "$new/dovecot-uidlist"; + + my %uidlist_map; + foreach (keys %filename_map) { + my $fname = $_; + + if ($filename_map{$fname} =~ /^(\d+):(\d+)$/) { + if ($1 == $uidv && $2 > 0) { + $uidlist_map{$2} = $fname; + } + } + } + + my $f; + open ($f, ">$uidlist_fname") || die $!; + print $f "1 $uidv $nextuid\n"; + foreach (sort { $a <=> $b } keys %uidlist_map) { + print $f "$_ ".$uidlist_map{$_}."\n"; + } + close $f; + chown $vuid, $vgid, $uidlist_fname; +} + +sub convert_keywords($$) { + my ($old, $new) = @_; + my $keyword_dir = "$old/courierimapkeywords"; + my $dovecot_keyfname = "$new/dovecot-keywords"; + + if (!-f "$keyword_dir/:list") { + # no keywords + return; + } + + my (%keywords, %files); + my $f; + open ($f, "$keyword_dir/:list") || die $!; + # read keyword names + while (<$f>) { + chomp $_; + + last if (/^$/); + $keywords{$_} = scalar keys %keywords; + } + # read filenames -> keywords mapping + while (<$f>) { + if (/([^:]+):([\d ]+)$/) { + my $fname = $1; + foreach (sort { $a <=> $b } split(" ", $2)) { + $files{$fname} .= chr(97 + $_); + } + } else { + print STDERR "WARNING: $keyword_dir/:list: Broken entry: $_\n"; + } + } + close $f; + + # read updates from the directory + my %updates; + foreach (<$keyword_dir/*>) { + s,^$keyword_dir/,,; + next if ($_ eq ":list"); + + my $fname = $_; + if (/^\.(\d+)\.(.*)$/) { + my ($num, $base_fname) = ($1, $2); + if (!defined $updates{$fname}) { + $updates{$fname} = $num; + } else { + my $old = $updates{$fname}; + if ($old >= 0 && $num > $old) { + $updates{$fname} = $num; } - close(FILE); + } + } else { + # "fname" overrides .n.fnames + $updates{$fname} = -1; } - else { - print( STDERR "WARNING: cannot fill $path/subscriptions: $!\n" ); - $ok = 0; + } + + # apply the updates + foreach (keys %updates) { + my $base_fname = $_; + my $num = $updates{$_}; + + my $fname; + if ($num < 0) { + $fname = $base_fname; + } else { + $fname = ".$num.$base_fname"; } - if ( !chown( $vuid, $vgid, $path, @dirs, @files ) ) { - print( STDERR "WARNING: cannot chown '$path' to $vuid:$vgid: $!\n" ); - $ok = 0; + my @kw_list; + open ($f, "$keyword_dir/$fname") || next; + while (<$f>) { + chomp $_; + my $kw = $_; + my $idx; + + if (defined $keywords{$kw}) { + $idx = $keywords{$kw}; + } else { + $idx = scalar keys %keywords; + $keywords{$kw} = $idx; + } + $kw_list[scalar @kw_list] = $idx; } + close $f; + + $files{$fname} = ""; + foreach (sort { $a <=> $b } @kw_list) { + $files{$fname} .= chr(97 + $_); + } + } + + # write dovecot-keywords file + open ($f, ">$dovecot_keyfname") || die $!; + foreach (sort { $keywords{$a} <=> $keywords{$b} } keys %keywords) { + my $idx = $keywords{$_}; + print $f "$idx $_\n"; + } + close $f; + chown $vuid, $vgid, $dovecot_keyfname; + + # update the maildir files + my $cur_dir = "$new/cur"; + foreach (<$cur_dir/*>) { + my $fname = $_; + s,^$cur_dir/,,; + + my ($base_fname, $flags, $extra_flags); + if (/^([^:]+):2,([^,]*)(,.*)?$/) { + ($base_fname, $flags, $extra_flags) = ($1, $2, $3); + $extra_flags = "" if (!defined $extra_flags); + } else { + $base_fname = $fname; + $flags = ""; + $extra_flags = ""; + } + + if (defined $files{$base_fname}) { + # merge old and new flags + my %newflags; + foreach (sort split("", $files{$base_fname})) { + $newflags{$_} = 1; + } + foreach (sort split("", $flags)) { + $newflags{$_} = 1; + } + $flags = ""; + foreach (sort keys %newflags) { + $flags .= $_; + } + my $new_fname = "$cur_dir/$base_fname:2,$flags$extra_flags"; + if ($fname ne $new_fname) { + rename($fname, $new_fname) || + print STDERR "ERROR: rename($fname, $new_fname) failed: $!\n"; + } + } + } +} + +sub convert_subscriptions($$) { + my ($old, $new) = @_; + + my $in_fname = "$old/courierimapsubscribed"; + my $out_fname = "$new/subscriptions"; + return if (!-f $in_fname); + + my $spam_found = 0; + my ($fin, $fout); + open ($fin, $in_fname) || die $!; + open ($fout, ">$out_fname") || die $!; + while (<$fin>) { + chomp $_; + + if (/^INBOX$/i) { + print $fout "INBOX\n"; + } elsif (/^INBOX\.(.*)$/i) { + print $fout "$1\n"; + $spam_found = 1 if $1 eq "Spam"; + } else { + # unknown. keep it as-is. + print $fout "$_\n"; + } + } + print $fout "Spam\n" unless $spam_found; + + close $fin; + close $fout; + chown $vuid, $vgid, $out_fname; +} + +sub maildir_copy_messages($$) { + my ($old, $new) = @_; + + my @files; + + if (! opendir(DIR, $old)) { + print(STDERR "ERROR: Impossibile aprire la directory $old: $!\n"); + return; + } + + my @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); + closedir(DIR); + foreach my $item (@list) { + $item =~ s/^$old\///; + + my ($ofile, $nfile) = ("$old/$item","$new/$item"); + + if (! -f $ofile) { + print STDERR "WARNING: Unknown file $ofile\n"; + } + + copy($ofile,$nfile) or die $!; + push @files, $nfile; + } + + if (scalar @files > 0) { + if ( !chown( $vuid, $vgid, @files ) ) { + print( STDERR "WARNING: cannot chown '$new' content to $vuser:$vgroup: $!\n" ); + } if ( !chmod( 0600, @files ) ) { - print( STDERR "WARNING: cannot chmod '$path' to 0600: $!\n" ); - $ok = 0; + print( STDERR "WARNING: cannot chmod '$new' content to 0600: $!\n" ); } + } - return sieveconfigmake($path) and $ok; } +sub curnew_copy_messages($$) { + my ($old, $new) = @_; + + unless (-d "$old/new" or -d "$old/cur") { + return; + } + + mkpath("$new/cur", 0, 0700); + maildir_copy_messages("$old/cur", "$new/cur"); + mkpath("$new/new", 0, 0700); + maildir_copy_messages("$old/new", "$new/new"); + mkpath("$new/tmp", 0, 0700); + + if ( !chown( $vuid, $vgid, "$new", "$new/new", "$new/cur", "$new/tmp" ) ) { + print( STDERR "WARNING: cannot chown '$new' content to $vuid:$vgid: $!\n" ); + } + if ( !chmod( 0700, "$new", "$new/new", "$new/cur", "$new/tmp" ) ) { + print( STDERR "WARNING: cannot chmod '$new' content to 0600: $!\n" ); + } +} + +sub check_maildir_single($$$) { + my ($old, $new, $childbox) = @_; + my $uidv = -1; + my $nextuid = 0; + my %filename_map; + my %curnew_map; + my $found = 0; + + curnew_copy_messages($old,$new); + + if (-f "$old/$pop3_uidfile") { + $found = 1; + ($uidv, $nextuid, %filename_map) = read_courier_pop3($old, $new, \%curnew_map); + } + + my $imap_uidv = 0; + if (-f "$old/$imap_uidfile") { + $found = 1; + ($uidv, $nextuid, %filename_map) = read_courier_imap($old, $new, $uidv, $nextuid, \%curnew_map, %filename_map); + } + + if (!$found) { + print STDERR "WARNING: $old: No imap/pop3 uidlist files\n" if (!$childbox); + return; + } + + write_dovecot_uidlist($old, $new, $uidv, $nextuid, %filename_map); + convert_subscriptions($old, $new); + convert_keywords($old, $new); +} + # convert old courier maildir to dovecot format sub convert_old_maildir($$) { my ($old,$new) = @_; - my (@list, @created); + if (! opendir(DIR, $old)) { print(STDERR "ERROR: Impossibile aprire la directory $old: $!\n"); return; } - @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); + + check_maildir_single($old,$new, 0); + my @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); closedir(DIR); foreach my $item (@list) { my $file = "$old/$item"; my $filenew = "$new/$item"; if ( -d $file ) { - mkdir ($filenew, 0700) or die "Non posso creare $filenew: $!" if ! -d $filenew; - &convert_old_maildir($file, $filenew); - } elsif ( $item eq 'sqwebmail-pass') { - next; - } elsif ( -f $file ) { - open(SOURCE, "<$file") or die "Non posso aprire $file in lettura: $!"; - open(DEST, ">$filenew") or die "Non posso aprire $filenew in scrittura: $!"; - chmod(0600, $filenew); - print DEST while(<SOURCE>); - close(DEST); - close(SOURCE); - } else { - print(STDERR "WARNING: Unknown item $file during conversion: skipped...\n"); - next; + check_maildir_single($file, $filenew, 1); } - push(@created, $filenew); } - chown($vuid, $vgid, @created); } sub scalable_name($$) { @@ -227,6 +695,12 @@ my (@domains, %domains_alias, %domains_real, %domain_real_users, %domain_real_alias); +# sanity +if ( -e $new_panda_domains_dir ) { + print STDERR "ERROR: $new_panda_domains_dir already exists.\n"; + exit; +} + # leggo la lista dei domini opendir(DDIR,$old_vpopmail_domains_dir) or die "Non posso aprire $old_vpopmail_domains_dir: $!"; @domains = sort grep { /^[^.]/ } readdir(DDIR); @@ -240,12 +714,12 @@ $domains_alias{$domain} = $real; } else { $domains_real{$domain} = {"dir" => "$old_vpopmail_domains_dir/$domain"}; - } + } } # sanity: ogni dominio puntato da un alias deve esistere. while (my ($domain,$real) = each %domains_alias) { - if(!$domains_real{$real}) { + if (!$domains_real{$real}) { print(STDERR "WARNING: rimuovo l' alias '$domain' che punta un dominio inesistente ($real).\n"); delete $domains_real{$real}; } @@ -253,9 +727,9 @@ # aquisisco gli utenti, gli alias e le newsletter per ogni dominio reale foreach my $domain (keys %domains_real) { - + my $ddir = $domains_real{$domain}->{"dir"}; - + # utenti open(VPASSWD, "<$ddir/vpasswd") or die "Non posso aprire $ddir/vapsswd: $!"; my @lines = <VPASSWD>; @@ -264,7 +738,7 @@ foreach my $line (@lines) { chomp($line); my @values = split(/:/, $line); - if(!$values[0]) { + if (!$values[0]) { print(STDERR "WARNING: salto username vuoto processando $domain\n"); next; } @@ -280,7 +754,7 @@ $users{$values[0]} = \%user; } $domains_real{$domain}->{"users"} = \%users; - + # alias opendir(DDIR,$ddir) or die "Non posso aprire $ddir: $!"; my @aliasfiles = sort grep { /^\.qmail-/ } readdir(DDIR); @@ -335,8 +809,7 @@ } } print (STDERR "WARNING: default delivery sconosciuto ($domain): $dest\n"); - } - else { + } else { my @dest; foreach my $line (@lines) { chomp($line); @@ -386,7 +859,7 @@ # sanity: rimuoviamo schifezze while (my ($domain,$data) = each %domains_real) { - + # rimuoviamo gli alias e gli utenti postmaster delete($data->{"aliases"}->{"postmaster"}); delete($data->{"users"}->{"postmaster"}); @@ -397,16 +870,16 @@ my $removed; my $pass = 0; do { - while (my ($domain,$data) = each %domains_real) { + while (my ($domain,$data) = each %domains_real) { $removed = 0; foreach my $alias (sort keys %{$data->{"aliases"}}) { - foreach my $destn (0 .. $#{$data->{"aliases"}->{$alias}}) { + foreach my $destn (0 .. $#{$data->{"aliases"}->{$alias}}) { my $dest = $data->{"aliases"}->{$alias}->[$destn]; - + # skip deleted elements next unless defined $dest; - # se :local: deve esistere la casella locale + # se :local: deve esistere la casella locale if ($dest eq ":local:") { if (!$data->{"users"}->{$alias} and !$data->{"default"}) { delete($data->{"aliases"}->{$alias}->[$destn]); @@ -442,7 +915,7 @@ } } } - $pass = $pass + 1; + $pass = $pass + 1; } while ($removed); # ripetiamo fino a che c'\xE8 almeno una cancellazione... # generazione files e tabelle postgres @@ -450,7 +923,7 @@ use DBD::Pg qw(:pg_types); my $dbh; my $sth; -$dbh = DBI->connect("dbi:Pg:dbname=$db_database;host=$db_host;port=$db_port;", $db_user, $db_pass) +$dbh = DBI->connect("dbi:Pg:dbname=$db_database;host=$db_host;port=$db_port;", $db_user, $db_pass) or die $dbh->errstr; $dbh->begin_work(); $dbh->do("SET client_min_messages = 'warning';"); @@ -485,7 +958,7 @@ $sth->execute($domain, $domains_alias{$domain}) or die $dbh->errstr; } close(OUT); - + # generazione tabella virtual-domains $sth = $dbh->prepare(qq| INSERT INTO $db_virtual_domains (name, unknown_to) VALUES (?, ?); @@ -517,7 +990,7 @@ foreach my $alias (sort keys %{$domains_real{$domain}->{"aliases"}}) { my $alldest = ''; foreach my $dest (@{$domains_real{$domain}->{"aliases"}->{$alias}}) { - + # skip deleted elements next unless defined $dest; @@ -575,17 +1048,17 @@ } } my $home = "$domain/$dirprefix$user"; - my $maildir = "$home/Maildir"; + my $maildir = "$home/Maildir"; if (! -d "$new_panda_domains_dir/$home") { maildirmake("$new_panda_domains_dir/$home"); &convert_old_maildir($domains_real{$domain}->{"users"}->{$user}->{"maildir"}, "$new_panda_domains_dir/$maildir"); } print(OUT "$user\@localdelivery.$domain\t$maildir/\n"); $sth->execute($id_domain, - $home, - $domains_real{$domain}->{"users"}->{$user}->{"password"}, - "$maildir/", - $domains_real{$domain}->{"users"}->{$user}->{"pop3_enabled"}) or die $dbh->errstr; + $home, + $domains_real{$domain}->{"users"}->{$user}->{"password"}, + "$maildir/", + $domains_real{$domain}->{"users"}->{$user}->{"pop3_enabled"}) or die $dbh->errstr; } $dbh->do("UPDATE $db_virtual_domains SET usercount = ? WHERE id = ?;", {}, $usercount, $id_domain) or die $dbh->errstr; } @@ -623,6 +1096,6 @@ } } } - } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-10 15:43:58
|
Revision: 16 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=16&view=rev Author: mnencia Date: 2007-12-10 07:44:02 -0800 (Mon, 10 Dec 2007) Log Message: ----------- vmaild bug hunting commit. Tnx to "use warnings;" Modified Paths: -------------- trunk/setup/bin/vmaild Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-10 15:10:52 UTC (rev 15) +++ trunk/setup/bin/vmaild 2007-12-10 15:44:02 UTC (rev 16) @@ -230,6 +230,7 @@ my ($usercount) = @_; my ( $dircount, $prefix ); $dircount = POSIX::floor( ( $usercount - 1 ) / 100 ) - 1; + $prefix = ""; while ( $dircount >= 0 ) { $prefix = ( $dircount % 62 ) . "/$prefix"; $dircount = POSIX::floor( $dircount / 62 ) - 1; @@ -288,10 +289,7 @@ my $sth; # prelevo domini esistenti - $sth = - $dbh->prepare( -"SELECT DISTINCT D.* FROM $db_virtual_domains D INNER JOIN $db_virtual_domain_users U ON D.id = U.id_domain" - ); + $sth = $dbh->prepare("SELECT DISTINCT D.* FROM $db_virtual_domains D INNER JOIN $db_virtual_domain_users U ON D.id = U.id_domain"); if ( !$sth->execute ) { logmsg( 'error', 'unable to fetch domains list' ); logmsg( 'error', $dbh->errstr ); @@ -301,15 +299,22 @@ $domains{ $res->{"name"} } = $res; } + # test 0: directory presence + unless ( -d $domaindir ) { + logmsg( 'notice', "creating root domain directory: $domaindir" ); + mkpath( $domaindir, 0, 0700); + } + unless ( -d $deldir ) { + logmsg( 'notice', "creating root trash directory: $deldir" ); + mkpath( $deldir, 0, 0700); + } + # test 1: presenza di directory di dominio per domini # inesistenti o errati foreach my $domain ( filelist($domaindir) ) { if ( !$domains{$domain} ) { logmsg( 'notice', "unknown directory found: $domaindir/$domain" ); my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); - unless ( -d $deldir ) { - mkpath( $deldir, 0, 0700); - } sys_or_log("mv $domaindir/$domain $deldir/${domain}_$deldate"); } } @@ -350,9 +355,6 @@ if ( -d $dir ) { my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); - unless ( -d $deldir ) { - mkpath( $deldir, 0, 0700); - } sys_or_log("mv $dir $deldir/${domain}_$deldate"); } } @@ -436,8 +438,7 @@ # prelevo i dati sugli utenti del dominio my %users; - $sth = - $dbh->prepare( + $sth = $dbh->prepare( "SELECT * FROM $db_virtual_domain_users WHERE id_domain = ?;"); if ( !$sth->execute( $ddata->{id} ) ) { logmsg( 'error', 'unable to fetch $domain users list' ); @@ -455,15 +456,12 @@ # nella directory del dominio foreach my $maildir (@maildirs) { my $user = $maildir; - $user =~ s%^.*/([^/]+)/$%\1%; + $user =~ s%^.*/([^/]+)/$%$1%; if ( !$users{$user} || "$domaindir/$users{$user}->{maildir}" ne $maildir ) { logmsg( 'notice', "invalid or deleted user: $user\@$domain " ); my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); - unless ( -d $deldir ) { - mkpath( $deldir, 0, 0700); - } sys_or_log("mv $maildir $deldir/$user\@${domain}_$deldate") or $ok = 0; } @@ -575,7 +573,7 @@ } else { check_domains($dbh); - if ( $full_check_countdown = 0 ) { + if ( $full_check_countdown == 0 ) { $full_check_countdown = 60; check_users( $dbh, 1 ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-10 15:10:48
|
Revision: 15 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=15&view=rev Author: mnencia Date: 2007-12-10 07:10:52 -0800 (Mon, 10 Dec 2007) Log Message: ----------- Enabled warnings on vmaild Random improvements to the importer Modified Paths: -------------- trunk/setup/bin/vmaild trunk/setup/contrib/vpopmail2panda/import Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-10 13:01:31 UTC (rev 14) +++ trunk/setup/bin/vmaild 2007-12-10 15:10:52 UTC (rev 15) @@ -17,6 +17,7 @@ # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use strict; +use warnings; # Conf my $configfile = "/srv/vmail/etc/vmaild.conf"; Modified: trunk/setup/contrib/vpopmail2panda/import =================================================================== --- trunk/setup/contrib/vpopmail2panda/import 2007-12-10 13:01:31 UTC (rev 14) +++ trunk/setup/contrib/vpopmail2panda/import 2007-12-10 15:10:52 UTC (rev 15) @@ -78,21 +78,21 @@ close(FILE); } else { - print( STDERR "warning: cannot fill $path/$sieve_file: $!\n" ); + print( STDERR "WARNING: cannot fill $path/$sieve_file: $!\n" ); $ok = 0; } if ( !symlink( "$sieve_file", $path . "/.dovecot.sieve" ) ) { - print( STDERR "warning: cannot symlink '$path/.dovecot.sieve' to '$sieve_file': $!\n"); + print( STDERR "WARNING: cannot symlink '$path/.dovecot.sieve' to '$sieve_file': $!\n"); $ok = 0; } if ( !chown( $vuid, $vgid, "$path/$sieve_file" ) ) { - print( STDERR "warning: cannot chown '$path/$sieve_file' to $vuid:$vgid: $!\n"); + print( STDERR "WARNING: cannot chown '$path/$sieve_file' to $vuid:$vgid: $!\n"); $ok = 0; } if ( !chmod( 0600, "$path/$sieve_file" ) ) { - print( STDERR "warning: cannot chmod '$path/$sieve_file' to 0600: $!\n" ); + print( STDERR "WARNING: cannot chmod '$path/$sieve_file' to 0600: $!\n" ); $ok = 0; } @@ -146,13 +146,13 @@ foreach my $dir (@dirs) { if ( !mkdir( $dir, 0700 ) ) { - print( STDERR "warning: cannot create $dir dir: $!\n" ); + print( STDERR "WARNING: cannot create $dir dir: $!\n" ); $ok = 0; } } foreach my $file (@files) { if ( !open( FILE, ">>$file" ) ) { - print( STDERR "warning: cannot create $file file: $!\n" ); + print( STDERR "WARNING: cannot create $file file: $!\n" ); $ok = 0; } close(FILE); @@ -166,16 +166,16 @@ close(FILE); } else { - print( STDERR "warning: cannot fill $path/subscriptions: $!\n" ); + print( STDERR "WARNING: cannot fill $path/subscriptions: $!\n" ); $ok = 0; } if ( !chown( $vuid, $vgid, $path, @dirs, @files ) ) { - print( STDERR "warning: cannot chown '$path' to $vuid:$vgid: $!\n" ); + print( STDERR "WARNING: cannot chown '$path' to $vuid:$vgid: $!\n" ); $ok = 0; } if ( !chmod( 0600, @files ) ) { - print( STDERR "warning: cannot chmod '$path' to 0600: $!\n" ); + print( STDERR "WARNING: cannot chmod '$path' to 0600: $!\n" ); $ok = 0; } @@ -187,7 +187,7 @@ my ($old,$new) = @_; my (@list, @created); if (! opendir(DIR, $old)) { - print(STDERR "WARNING: Impossibile aprire la directory $old: $!\n"); + print(STDERR "ERROR: Impossibile aprire la directory $old: $!\n"); return; } @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); @@ -246,11 +246,12 @@ # sanity: ogni dominio puntato da un alias deve esistere. while (my ($domain,$real) = each %domains_alias) { if(!$domains_real{$real}) { - print(STDERR "WARNING: l' alias '$domain' punta un dominio inesistente ($real).\n"); + print(STDERR "WARNING: rimuovo l' alias '$domain' che punta un dominio inesistente ($real).\n"); + delete $domains_real{$real}; } } -# aquisisco gli utenti e gli alias per ogni dominio reale +# aquisisco gli utenti, gli alias e le newsletter per ogni dominio reale foreach my $domain (keys %domains_real) { my $ddir = $domains_real{$domain}->{"dir"}; @@ -264,18 +265,17 @@ chomp($line); my @values = split(/:/, $line); if(!$values[0]) { - print(STDERR "WARNING: uid vuoto processando $domain\n"); + print(STDERR "WARNING: salto username vuoto processando $domain\n"); next; } my %user; $user{"password"} = $values[1]; $user{"pop3_enabled"} = ($values[3] eq '0')?'t':'f'; $values[5] =~ m%$old_vpopmail_domains_location/([^/]+)/((.*/)*([^/]+))%; -# print "$1, $2, $3, $4\n"; if ($domains_alias{$1}) { - $user{"maildir"} = "vpopmail/domains/".$domains_alias{$1}."/$2/Maildir"; + $user{"maildir"} = "$old_vpopmail_domains_dir/".$domains_alias{$1}."/$2/Maildir"; } else { - $user{"maildir"} = "vpopmail/domains/$1/$2/Maildir"; + $user{"maildir"} = "$old_vpopmail_domains_dir/$1/$2/Maildir"; } $users{$values[0]} = \%user; } @@ -285,22 +285,46 @@ opendir(DDIR,$ddir) or die "Non posso aprire $ddir: $!"; my @aliasfiles = sort grep { /^\.qmail-/ } readdir(DDIR); closedir(DDIR); + my %newsletters; my %aliases; foreach my $aliasfile (@aliasfiles) { my $alias = $aliasfile; $alias =~ s/^.qmail-//; $alias =~ s/:/./g; - if (! open(AFILE, "<$ddir/$aliasfile") ) { - print STDERR "WARNING: impossibile aprire $ddir/$aliasfile: $!\n"; + + $aliasfile = "$ddir/$aliasfile"; + + # ezmlm handling + if ( -l $aliasfile ) { + $aliasfile = readlink $aliasfile; + $aliasfile =~ s%$old_vpopmail_domains_location%$old_vpopmail_domains_dir%; + } + + if (! open(AFILE, "<$aliasfile") ) { + print STDERR "WARNING: impossibile aprire $aliasfile: $!\n"; next; } my @lines = <AFILE>; close(AFILE); + + # ezmlm handling + if (grep (/ezmlm/, @lines) ) { + $aliasfile =~ m%$old_vpopmail_domains_dir/([^/]+)/(.*/)*([^/]+)/[^/]+$%; + my $newsletter = $3; + + unless (exists $newsletters{$newsletter}) { + print STDERR "WARNING: detected ezmlm newsletter $newsletter\@$domain\n"; + $newsletters{$newsletter} = 1; + } + next; + } + if ($alias eq "default") { my $dest = $lines[0]; chomp($dest); if ($dest =~ s%^\|\s*/[\w/]+/vdelivermail '' %%) { next if ($dest eq "bounce-no-mailbox"); + next if ($dest eq "delete"); # TODO: no blackhole handling if ($dest =~ /^[a-z0-9]+([-\.\+_a-z0-9]+)*\@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}$/i) { $domains_real{$domain}->{"default"} = $dest; next; @@ -319,21 +343,35 @@ if ($line =~ /^\s*$/) { next; } elsif ($line =~ /^\|/) { - next if ($line eq "|/var/lib/vpopmail/blackhole"); - if ($line =~ s%^\|/usr/sbin/vdelivermail '' %%) { + next if ($line =~ m%^\|.*/blackhole$%); # TODO: no blackhole handling + if ($line =~ s%^\|.*/vdelivermail '' %%) { $line =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)$%$3\@$1%; - $line = ":local:" if "$alias\@$domain" eq $line or - "$alias\@$domain" eq "$3\@".$domains_alias{$1}; + $line = ":local:" if "$alias\@$domain" eq $line; + if (exists $domains_alias{$1}) { + $line = ":local:" if "$alias\@$domain" eq "$3\@".$domains_alias{$1}; + } push (@dest, $line); next; } + if ($line =~ s%^\|.*/autorespond%%) { + print STDERR "WARNING: detected autoresponder $alias\@$domain\n"; + next; + } } elsif ($line =~ /^\//) { $line =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)/Maildir/$%$3\@$1%; - $line = ":local:" if "$alias\@$domain" eq $line or - "$alias\@$domain" eq "$3\@".$domains_alias{$1}; + $line = ":local:" if "$alias\@$domain" eq $line; + if (exists $domains_alias{$1}) { + $line = ":local:" if "$alias\@$domain" eq "$3\@".$domains_alias{$1}; + } push (@dest, $line); next; } elsif ($line =~ /^&?[a-z0-9]+([-\.\+_a-z0-9]+)*\@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}$/i ) { + + # remove & in front of destination email + if ($line =~ /^&(.*)$/) { + $line = $1; + } + push (@dest, $line); next; } @@ -343,33 +381,16 @@ } } $domains_real{$domain}->{"aliases"} = \%aliases; + $domains_real{$domain}->{"newsletters"} = \%newsletters; } # sanity: rimuoviamo schifezze -@domains = grep { !/^test.com$/ } @domains; -delete($domains_real{"test.com"}); while (my ($domain,$data) = each %domains_real) { # rimuoviamo gli alias e gli utenti postmaster delete($data->{"aliases"}->{"postmaster"}); delete($data->{"users"}->{"postmaster"}); - - # rimuovo gli alias webmaster quando questi puntano a *@centerweb.it - if ($data->{"aliases"}->{"webmaster"}) { - my @newaliases = grep { ! /^.*\@centerweb.it$/i } @{$data->{"aliases"}->{"webmaster"}}; - if ($#newaliases == -1) { - delete($data->{"aliases"}->{"webmaster"}); - } else { - $data->{"aliases"}->{"webmaster"} = \@newaliases; - } - } - - # rimuovo gli alias con nome test* - while (my ($aliasname,$dests) = each %{$data->{"aliases"}}) { - if ($aliasname =~ /^test/) { - delete ($data->{"aliases"}->{$aliasname}); - } - } + } # rimuovo gli alias che puntano a caselle locali inesistenti o che contengono solo :local: @@ -379,38 +400,44 @@ while (my ($domain,$data) = each %domains_real) { $removed = 0; foreach my $alias (sort keys %{$data->{"aliases"}}) { - foreach my $destn (0 .. $#{$data->{"aliases"}->{$alias}}) { + foreach my $destn (0 .. $#{$data->{"aliases"}->{$alias}}) { my $dest = $data->{"aliases"}->{$alias}->[$destn]; + # skip deleted elements + next unless defined $dest; + # se :local: deve esistere la casella locale - if ($dest eq ":local:" and !$data->{"users"}->{$alias} and !$data->{"default"}) { - delete($data->{"aliases"}->{$alias}->[$destn]); - print (STDERR "WARNING: alias $alias\@$domain: destinazione locale errata($dest)(pass $pass): RIMOSSA!\n"); + if ($dest eq ":local:") { + if (!$data->{"users"}->{$alias} and !$data->{"default"}) { + delete($data->{"aliases"}->{$alias}->[$destn]); + print (STDERR "INFO: alias $alias\@$domain: destinazione locale inesistente ($dest) (pass $pass): RIMOSSA!\n"); + } + next; } - # remove & in fron of destination email - if ($dest =~ /^&(.*)$/) { - $dest = $1; - } + my ($duser,$ddomain) = split(/@/, $dest); $duser =~ s/^([^-]*)-.*?$/$1/; + # dominio alias -> dominio reale - if ($domains_alias{$ddomain}) { + if (exists $domains_alias{$ddomain}) { $ddomain = $domains_alias{$ddomain}; } + # test di esistenza di $dest - if (my $ddata = $domains_real{$ddomain}) { + if (exists $domains_real{$ddomain}) { + my $ddata = $domains_real{$ddomain}; if (!$ddata->{"users"}->{$duser} and !$ddata->{"aliases"}->{$duser} and !$ddata->{"default"}) { delete($data->{"aliases"}->{$alias}->[$destn]); - print (STDERR "WARNING: alias $alias\@$domain: destinazione locale errata($dest)(pass $pass): RIMOSSA!\n"); + print (STDERR "INFO: alias $alias\@$domain: destinazione locale errata($dest)(pass $pass): RIMOSSA!\n"); } - } + } } if ($#{$data->{"aliases"}->{$alias}} == -1) { delete($data->{"aliases"}->{$alias}); - print (STDERR "WARNING: alias $alias\@$domain non ha destinazioni(pass $pass): RIMOSSO!\n"); + print (STDERR "INFO: alias $alias\@$domain non ha destinazioni(pass $pass): RIMOSSO!\n"); $removed = 1; } elsif ($#{$data->{"aliases"}->{$alias}} == 0 and $data->{"aliases"}->{$alias}->[0] eq ":local:") { - print (STDERR "WARNING: alias $alias\@$domain ha solo destinazione :local: (pass $pass): RIMOSSO!\n"); + print (STDERR "INFO: alias $alias\@$domain ha solo destinazione :local: (pass $pass): RIMOSSO!\n"); delete($data->{"aliases"}->{$alias}); } } @@ -490,7 +517,10 @@ foreach my $alias (sort keys %{$domains_real{$domain}->{"aliases"}}) { my $alldest = ''; foreach my $dest (@{$domains_real{$domain}->{"aliases"}->{$alias}}) { - #TODO check how to convert :local: + + # skip deleted elements + next unless defined $dest; + if ($dest eq ":local:") { $alldest .= "$alias\@localdelivery.$domain "; } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2007-12-10 13:01:29
|
Revision: 14 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=14&view=rev Author: agrassi Date: 2007-12-10 05:01:31 -0800 (Mon, 10 Dec 2007) Log Message: ----------- Improved newsletter script: Better input handling Modified Paths: -------------- trunk/setup/bin/newsletter Modified: trunk/setup/bin/newsletter =================================================================== --- trunk/setup/bin/newsletter 2007-12-10 10:37:22 UTC (rev 13) +++ trunk/setup/bin/newsletter 2007-12-10 13:01:31 UTC (rev 14) @@ -33,17 +33,16 @@ "$conf" or die $@; -my $mail = new Mail::Internet [<>]; +my $sender = shift @ARGV; +my $destination = shift @ARGV; + +my $mail = new Mail::Internet [<STDIN>]; my $head = $mail->head(); my $date = $head->get("Date"); chomp $date; -my $sender = $head->get("From"); -chomp $sender; my $subject = $head->get("Subject"); chomp $subject; -my $destination = $head->get("X-Original-To", 0); -chomp $destination; my $fullText = $mail->as_string(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-10 10:37:33
|
Revision: 13 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=13&view=rev Author: mnencia Date: 2007-12-10 02:37:22 -0800 (Mon, 10 Dec 2007) Log Message: ----------- More sleep needed, third commit on the same problem :( Modified Paths: -------------- trunk/setup/bin/vmaild Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-10 10:32:42 UTC (rev 12) +++ trunk/setup/bin/vmaild 2007-12-10 10:37:22 UTC (rev 13) @@ -306,6 +306,9 @@ if ( !$domains{$domain} ) { logmsg( 'notice', "unknown directory found: $domaindir/$domain" ); my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); + unless ( -d $deldir ) { + mkpath( $deldir, 0, 0700); + } sys_or_log("mv $domaindir/$domain $deldir/${domain}_$deldate"); } } @@ -347,7 +350,7 @@ if ( -d $dir ) { my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); unless ( -d $deldir ) { - mkpath $deldir, 0, 700; + mkpath( $deldir, 0, 0700); } sys_or_log("mv $dir $deldir/${domain}_$deldate"); } @@ -458,7 +461,7 @@ logmsg( 'notice', "invalid or deleted user: $user\@$domain " ); my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); unless ( -d $deldir ) { - mkpath $deldir, 0, 700; + mkpath( $deldir, 0, 0700); } sys_or_log("mv $maildir $deldir/$user\@${domain}_$deldate") or $ok = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-10 10:33:03
|
Revision: 12 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=12&view=rev Author: mnencia Date: 2007-12-10 02:32:42 -0800 (Mon, 10 Dec 2007) Log Message: ----------- Completed inclomplete previous commit Modified Paths: -------------- trunk/setup/bin/vmaild Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-10 10:18:05 UTC (rev 11) +++ trunk/setup/bin/vmaild 2007-12-10 10:32:42 UTC (rev 12) @@ -457,6 +457,9 @@ { logmsg( 'notice', "invalid or deleted user: $user\@$domain " ); my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); + unless ( -d $deldir ) { + mkpath $deldir, 0, 700; + } sys_or_log("mv $maildir $deldir/$user\@${domain}_$deldate") or $ok = 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-10 10:18:03
|
Revision: 11 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=11&view=rev Author: mnencia Date: 2007-12-10 02:18:05 -0800 (Mon, 10 Dec 2007) Log Message: ----------- Vmaild handles deletion of $deleted directory Random improvements to import script Modified Paths: -------------- trunk/setup/bin/vmaild trunk/setup/contrib/vpopmail2panda/import Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-06 11:42:18 UTC (rev 10) +++ trunk/setup/bin/vmaild 2007-12-10 10:18:05 UTC (rev 11) @@ -346,6 +346,9 @@ if ( -d $dir ) { my $deldate = POSIX::strftime( "%F-%H%M%S", gmtime ); + unless ( -d $deldir ) { + mkpath $deldir, 0, 700; + } sys_or_log("mv $dir $deldir/${domain}_$deldate"); } } Modified: trunk/setup/contrib/vpopmail2panda/import =================================================================== --- trunk/setup/contrib/vpopmail2panda/import 2007-12-06 11:42:18 UTC (rev 10) +++ trunk/setup/contrib/vpopmail2panda/import 2007-12-10 10:18:05 UTC (rev 11) @@ -17,12 +17,15 @@ # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use strict; +use warnings; use File::Path; # old my $old_vpopmail_domains_location = "/home/vpopmail/domains"; # for matching purpouse -my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail/domains"; # actual data location +my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail.gw/domains"; # actual data location +# my $old_vpopmail_domains_location = "/var/lib/vpopmail/domains"; # for matching purpouse +# my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail.xcon/domains"; # actual data location # new my $new_panda_domains_dir = "/home/mnencia/q2p/domains"; @@ -194,7 +197,7 @@ my $filenew = "$new/$item"; if ( -d $file ) { mkdir ($filenew, 0700) or die "Non posso creare $filenew: $!" if ! -d $filenew; - convert_old_maildir($file, $filenew); + &convert_old_maildir($file, $filenew); } elsif ( $item eq 'sqwebmail-pass') { next; } elsif ( -f $file ) { @@ -267,11 +270,12 @@ my %user; $user{"password"} = $values[1]; $user{"pop3_enabled"} = ($values[3] eq '0')?'t':'f'; - $values[5] =~ m%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)%; + $values[5] =~ m%$old_vpopmail_domains_location/([^/]+)/((.*/)*([^/]+))%; +# print "$1, $2, $3, $4\n"; if ($domains_alias{$1}) { - $user{"maildir"} = "vpopmail/domains/".$domains_alias{$1}."/$2$3/Maildir"; + $user{"maildir"} = "vpopmail/domains/".$domains_alias{$1}."/$2/Maildir"; } else { - $user{"maildir"} = "vpopmail/domains/$1/$2$3/Maildir"; + $user{"maildir"} = "vpopmail/domains/$1/$2/Maildir"; } $users{$values[0]} = \%user; } @@ -286,7 +290,10 @@ my $alias = $aliasfile; $alias =~ s/^.qmail-//; $alias =~ s/:/./g; - open(AFILE, "<$ddir/$aliasfile"); + if (! open(AFILE, "<$ddir/$aliasfile") ) { + print STDERR "WARNING: impossibile aprire $ddir/$aliasfile: $!\n"; + next; + } my @lines = <AFILE>; close(AFILE); if ($alias eq "default") { @@ -298,7 +305,7 @@ $domains_real{$domain}->{"default"} = $dest; next; } elsif ($dest =~ /^\//) { - $dest =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)$%\3@\1%; + $dest =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)$%$3\@$1%; $domains_real{$domain}->{"default"} = $dest; next; } @@ -314,14 +321,14 @@ } elsif ($line =~ /^\|/) { next if ($line eq "|/var/lib/vpopmail/blackhole"); if ($line =~ s%^\|/usr/sbin/vdelivermail '' %%) { - $line =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)$%\3@\1%; + $line =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)$%$3\@$1%; $line = ":local:" if "$alias\@$domain" eq $line or "$alias\@$domain" eq "$3\@".$domains_alias{$1}; push (@dest, $line); next; } } elsif ($line =~ /^\//) { - $line =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)/Maildir/$%\3@\1%; + $line =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)/Maildir/$%$3\@$1%; $line = ":local:" if "$alias\@$domain" eq $line or "$alias\@$domain" eq "$3\@".$domains_alias{$1}; push (@dest, $line); @@ -385,7 +392,7 @@ $dest = $1; } my ($duser,$ddomain) = split(/@/, $dest); - $duser =~ s/^([^-]*)-.*?$/\1/; + $duser =~ s/^([^-]*)-.*?$/$1/; # dominio alias -> dominio reale if ($domains_alias{$ddomain}) { $ddomain = $domains_alias{$ddomain}; @@ -541,7 +548,7 @@ my $maildir = "$home/Maildir"; if (! -d "$new_panda_domains_dir/$home") { maildirmake("$new_panda_domains_dir/$home"); - convert_old_maildir($domains_real{$domain}->{"users"}->{$user}->{"maildir"}, "$new_panda_domains_dir/$maildir"); + &convert_old_maildir($domains_real{$domain}->{"users"}->{$user}->{"maildir"}, "$new_panda_domains_dir/$maildir"); } print(OUT "$user\@localdelivery.$domain\t$maildir/\n"); $sth->execute($id_domain, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-06 11:42:16
|
Revision: 10 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=10&view=rev Author: mnencia Date: 2007-12-06 03:42:18 -0800 (Thu, 06 Dec 2007) Log Message: ----------- Sieve handling in vpopmail2panda and some cleanup Corrected some bug in vmaild introduced in previous commit Modified Paths: -------------- trunk/setup/bin/vmaild trunk/setup/bin/vmaild.conf trunk/setup/contrib/vpopmail2panda/import Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-06 09:50:15 UTC (rev 9) +++ trunk/setup/bin/vmaild 2007-12-06 11:42:18 UTC (rev 10) @@ -73,9 +73,10 @@ my ($path) = @_; my $ok; - $ok = -l "$path/dovecot-sieve"; - $ok = $ok and -f "$path/sieve/phpscript.sieve"; - $ok = $ok and -s "$path/sieve/phpscript.sieve"; + if ($ok = -l "$path/.dovecot.sieve") { + my $dest = File::Spec->rel2abs( readlink "$path/.dovecot.sieve", $path ); + $ok = -f $dest and -s $dest; + } return $ok; } @@ -130,7 +131,7 @@ return 0; } my @dirs = ( - $path, + $path . "/Maildir", $path . "/Maildir/new", $path . "/Maildir/cur", $path . "/Maildir/tmp", @@ -168,7 +169,7 @@ my $ok = 1; if (! -d $path ) { - mkpath( $path, 0700 ); + mkpath( $path, 0, 0700 ); } foreach my $dir (@dirs) { @@ -197,7 +198,7 @@ $ok = 0; } - if ( !chown( $vuid, $vgid, @dirs, @files ) ) { + if ( !chown( $vuid, $vgid, $path, @dirs, @files ) ) { logmsg( 'warning', "warning: cannot chown '$path' to $vuid:$vgid: $!" ); $ok = 0; } Modified: trunk/setup/bin/vmaild.conf =================================================================== --- trunk/setup/bin/vmaild.conf 2007-12-06 09:50:15 UTC (rev 9) +++ trunk/setup/bin/vmaild.conf 2007-12-06 11:42:18 UTC (rev 10) @@ -35,10 +35,14 @@ $sieve_script = q|# Sieve Filter -if header :is "X-Spam-Flag" "YES" -{ +require ["fileinto"]; + +# Spam +if header :comparator "i;ascii-casemap" :is "X-Spam-Flag" "YES" { fileinto "Spam"; -} + stop; +} + |; # Default Flags Modified: trunk/setup/contrib/vpopmail2panda/import =================================================================== --- trunk/setup/contrib/vpopmail2panda/import 2007-12-06 09:50:15 UTC (rev 9) +++ trunk/setup/contrib/vpopmail2panda/import 2007-12-06 11:42:18 UTC (rev 10) @@ -1,14 +1,47 @@ #!/usr/bin/perl +# +# Copyright (C) 2007 - Marco Nenciarini <mn...@gr...> +# +# This program 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, or (at your option) +# any later version. +# +# This program 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 this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use strict; +use File::Path; + # old -my $domaindir = "vpopmail/domains"; -my $basedir = "/home"; +my $old_vpopmail_domains_location = "/home/vpopmail/domains"; # for matching purpouse +my $old_vpopmail_domains_dir = "/home/mnencia/q2p/vpopmail/domains"; # actual data location # new -my $newdomaindir = "/home/mnencia/q2p/domains"; -my $confdir = "/home/mnencia/q2p/etc"; +my $new_panda_domains_dir = "/home/mnencia/q2p/domains"; +my $new_panda_confdump_dir = "/home/mnencia/q2p/etc"; +my $vuser = "mnencia"; +my $vgroup = "mnencia"; +my $sieve_script = q|# Sieve Filter + +require ["fileinto"]; + +# Spam +if header :comparator "i;ascii-casemap" :is "X-Spam-Flag" "YES" { + fileinto "Spam"; + stop; +} + +|; + +# db my $db_host = "localhost"; my $db_port = "5432"; my $db_database = "vmail"; @@ -18,22 +51,135 @@ my $db_virtual_domains = "virtual_domains"; my $db_virtual_domain_aliases = "virtual_domain_aliases"; my $db_virtual_domain_users = "virtual_domain_users"; + +# flags my $db_dont_drop = 0; -# conf -my $postmap = "/usr/sbin/postmap"; -my $vuid = 1000; -my $vgid = 1000; +my $vuid = getpwnam($vuser) or die "Invalid user in config file. ($vuser)"; +my $vgid = getgrnam($vgroup) or die "Invalid group in config file ($vgroup)"; + +# crea lo script sieve +sub sieveconfigmake($) { + my ($path) = @_; + + my %links = (); + + my $ok = 1; + + my $sieve_file = "sieve/.dovecot.sieve.sieve"; + + # Special content: sieve script + if ( open( FILE, ">$path/$sieve_file" ) ) { + print FILE $sieve_script; + close(FILE); + } + else { + print( STDERR "warning: cannot fill $path/$sieve_file: $!\n" ); + $ok = 0; + } + + if ( !symlink( "$sieve_file", $path . "/.dovecot.sieve" ) ) { + print( STDERR "warning: cannot symlink '$path/.dovecot.sieve' to '$sieve_file': $!\n"); + $ok = 0; + } + + if ( !chown( $vuid, $vgid, "$path/$sieve_file" ) ) { + print( STDERR "warning: cannot chown '$path/$sieve_file' to $vuid:$vgid: $!\n"); + $ok = 0; + } + if ( !chmod( 0600, "$path/$sieve_file" ) ) { + print( STDERR "warning: cannot chmod '$path/$sieve_file' to 0600: $!\n" ); + $ok = 0; + } + + return $ok; +} + +# crea una maildir sub maildirmake($) { - my ($path) = @_; - my @dirs = ($path, $path."/new", $path."/cur", $path."/tmp"); - foreach my $dir (@dirs) { - mkdir ($dir, 0700) or die "Non posso creare $dir: $!"; - } - chown($vuid, $vgid, @dirs); + my ($path) = @_; + my @dirs = ( + $path . "/Maildir", + $path . "/Maildir/new", + $path . "/Maildir/cur", + $path . "/Maildir/tmp", + $path . "/Maildir/.Drafts", + $path . "/Maildir/.Drafts/new", + $path . "/Maildir/.Drafts/cur", + $path . "/Maildir/.Drafts/tmp", + $path . "/Maildir/.Sent", + $path . "/Maildir/.Sent/new", + $path . "/Maildir/.Sent/cur", + $path . "/Maildir/.Sent/tmp", + $path . "/Maildir/.Spam", + $path . "/Maildir/.Spam/new", + $path . "/Maildir/.Spam/cur", + $path . "/Maildir/.Spam/tmp", + $path . "/Maildir/.Trash", + $path . "/Maildir/.Trash/new", + $path . "/Maildir/.Trash/cur", + $path . "/Maildir/.Trash/tmp", + $path . "/sieve", + $path . "/sieve/tmp", + ); + + my @files = ( + $path . "/Maildir/.Drafts/maildirfolder", + $path . "/Maildir/.Sent/maildirfolder", + $path . "/Maildir/.Spam/maildirfolder", + $path . "/Maildir/.Trash/maildirfolder", + $path . "/Maildir/subscriptions", + ); + + my @subscriptions = + ( "Drafts", "Sent", "Spam", "Trash", ); + + my $ok = 1; + + if (! -d $path ) { + mkpath( $path, 0, 0700 ); + } + + foreach my $dir (@dirs) { + if ( !mkdir( $dir, 0700 ) ) { + print( STDERR "warning: cannot create $dir dir: $!\n" ); + $ok = 0; + } + } + foreach my $file (@files) { + if ( !open( FILE, ">>$file" ) ) { + print( STDERR "warning: cannot create $file file: $!\n" ); + $ok = 0; + } + close(FILE); + } + + # Special content: subscriber folders + if ( open( FILE, ">>$path/Maildir/subscriptions" ) ) { + foreach my $subscription (@subscriptions) { + print FILE "$subscription\n"; + } + close(FILE); + } + else { + print( STDERR "warning: cannot fill $path/subscriptions: $!\n" ); + $ok = 0; + } + + if ( !chown( $vuid, $vgid, $path, @dirs, @files ) ) { + print( STDERR "warning: cannot chown '$path' to $vuid:$vgid: $!\n" ); + $ok = 0; + } + if ( !chmod( 0600, @files ) ) { + print( STDERR "warning: cannot chmod '$path' to 0600: $!\n" ); + $ok = 0; + } + + return sieveconfigmake($path) and $ok; } +# convert old courier maildir to dovecot format sub convert_old_maildir($$) { my ($old,$new) = @_; my (@list, @created); @@ -79,18 +225,18 @@ my (@domains, %domains_alias, %domains_real, %domain_real_users, %domain_real_alias); # leggo la lista dei domini -opendir(DDIR,$domaindir) or die "Non posso aprire $domaindir: $!"; +opendir(DDIR,$old_vpopmail_domains_dir) or die "Non posso aprire $old_vpopmail_domains_dir: $!"; @domains = sort grep { /^[^.]/ } readdir(DDIR); closedir(DDIR); # distinguo quali domini sono reali e quali alias foreach my $domain (@domains) { - if (-l "$domaindir/$domain") { - my $real = readlink "$domaindir/$domain"; + if (-l "$old_vpopmail_domains_dir/$domain") { + my $real = readlink "$old_vpopmail_domains_dir/$domain"; $real =~ s%^.*/%%; $domains_alias{$domain} = $real; } else { - $domains_real{$domain} = {"dir" => "$domaindir/$domain"}; + $domains_real{$domain} = {"dir" => "$old_vpopmail_domains_dir/$domain"}; } } @@ -121,7 +267,7 @@ my %user; $user{"password"} = $values[1]; $user{"pop3_enabled"} = ($values[3] eq '0')?'t':'f'; - $values[5] =~ m%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)%; + $values[5] =~ m%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)%; if ($domains_alias{$1}) { $user{"maildir"} = "vpopmail/domains/".$domains_alias{$1}."/$2$3/Maildir"; } else { @@ -152,7 +298,7 @@ $domains_real{$domain}->{"default"} = $dest; next; } elsif ($dest =~ /^\//) { - $dest =~ s%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)$%\3@\1%; + $dest =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)$%\3@\1%; $domains_real{$domain}->{"default"} = $dest; next; } @@ -168,14 +314,14 @@ } elsif ($line =~ /^\|/) { next if ($line eq "|/var/lib/vpopmail/blackhole"); if ($line =~ s%^\|/usr/sbin/vdelivermail '' %%) { - $line =~ s%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)$%\3@\1%; + $line =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)$%\3@\1%; $line = ":local:" if "$alias\@$domain" eq $line or "$alias\@$domain" eq "$3\@".$domains_alias{$1}; push (@dest, $line); next; } } elsif ($line =~ /^\//) { - $line =~ s%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)/Maildir/$%\3@\1%; + $line =~ s%$old_vpopmail_domains_location/([^/]+)/(.*/)*([^/]+)/Maildir/$%\3@\1%; $line = ":local:" if "$alias\@$domain" eq $line or "$alias\@$domain" eq "$3\@".$domains_alias{$1}; push (@dest, $line); @@ -234,6 +380,10 @@ delete($data->{"aliases"}->{$alias}->[$destn]); print (STDERR "WARNING: alias $alias\@$domain: destinazione locale errata($dest)(pass $pass): RIMOSSA!\n"); } + # remove & in fron of destination email + if ($dest =~ /^&(.*)$/) { + $dest = $1; + } my ($duser,$ddomain) = split(/@/, $dest); $duser =~ s/^([^-]*)-.*?$/\1/; # dominio alias -> dominio reale @@ -269,6 +419,7 @@ $dbh = DBI->connect("dbi:Pg:dbname=$db_database;host=$db_host;port=$db_port;", $db_user, $db_pass) or die $dbh->errstr; $dbh->begin_work(); +$dbh->do("SET client_min_messages = 'warning';"); # cancello il database if (!$db_dont_drop) { @@ -292,7 +443,7 @@ $sth = $dbh->prepare(qq| INSERT INTO $db_alias_domains (name, destination) VALUES (?, ?); |) or die $dbh->errstr; -open (OUT, ">$confdir/alias-domains"); +open (OUT, ">$new_panda_confdump_dir/alias-domains"); print(OUT "# File contenete i domini alias di un altro dominio\n"); foreach my $domain (sort keys %domains_alias) { print(OUT "\n$domain\tDUMMY_IGNORED\n"); @@ -305,7 +456,7 @@ $sth = $dbh->prepare(qq| INSERT INTO $db_virtual_domains (name, unknown_to) VALUES (?, ?); |) or die $dbh->errstr; -open (OUT, ">$confdir/virtual-domains"); +open (OUT, ">$new_panda_confdump_dir/virtual-domains"); print(OUT "# File contenete i domini virtuali locali.\n"); foreach my $domain (sort keys %domains_real) { print(OUT "\n$domain\tDUMMY_IGNORED\n"); @@ -323,7 +474,7 @@ $sth = $dbh->prepare(qq| INSERT INTO $db_virtual_domain_aliases (id_domain, name, destination) VALUES (?, ?, ?); |) or die $dbh->errstr; -open (OUT, ">$confdir/virtual-domain-aliases"); +open (OUT, ">$new_panda_confdump_dir/virtual-domain-aliases"); print(OUT "# File contenete le email di tipo alias per i domini virtuali locali\n"); foreach my $domain (sort keys %domains_real) { my $id_domain = $dbh->selectrow_array("SELECT id FROM $db_virtual_domains WHERE name = ?", {}, $domain) @@ -344,7 +495,7 @@ $sth->execute($id_domain, $alias, $alldest) or die $dbh->errstr; } if ($domains_real{$domain}->{"default"}) { - print(OUT "# $domain utenti reali (presente default destination)\n") if keys %{$domains_real{$domain}->{"users"}} > 0; + print(OUT "\n# $domain utenti reali (presente default destination)\n") if keys %{$domains_real{$domain}->{"users"}} > 0; foreach my $user (sort keys %{$domains_real{$domain}->{"users"}}) { print(OUT "$user\@$domain\t$user\@localdelivery.$domain\n"); } @@ -353,14 +504,14 @@ close(OUT); # generazione tabella virtual-domain-users e delle caselle di posta -if (! -d "$newdomaindir") { - mkdir ("$newdomaindir") or die "Non posso creare $newdomaindir: $!"; - chown($vuid, $vgid, "$newdomaindir") or die "Non posso settare l'owner di $newdomaindir: $!"; +if (! -d "$new_panda_domains_dir") { + mkdir ("$new_panda_domains_dir", 0700) or die "Non posso creare $new_panda_domains_dir: $!"; + chown($vuid, $vgid, "$new_panda_domains_dir") or die "Non posso settare l'owner di $new_panda_domains_dir: $!"; } $sth = $dbh->prepare(qq| INSERT INTO $db_virtual_domain_users (id_domain, name, passwd, maildir, pop3_enabled) VALUES (?, ?, ?, ?, ?); |) or die $dbh->errstr; -open (OUT, ">$confdir/virtual-domain-users"); +open (OUT, ">$new_panda_confdump_dir/virtual-domain-users"); print(OUT "# File contenete le mailbox per i domini virtuali locali\n"); foreach my $domain (sort keys %domains_real) { my $id_domain = $dbh->selectrow_array("SELECT id FROM $db_virtual_domains WHERE name = ?", {}, $domain) @@ -369,9 +520,9 @@ print(OUT "\n# $domain\n"); print(OUT "localdelivery.$domain\tDUMMY_IGNORED\n"); } - if (! -d "$newdomaindir/$domain") { - mkdir("$newdomaindir/$domain") or die "Non posso creare $newdomaindir/$domain: $!"; - chown($vuid, $vgid, "$newdomaindir/$domain") or die "Non posso settare l'owner di $newdomaindir/$domain: $!"; + if (! -d "$new_panda_domains_dir/$domain") { + mkdir("$new_panda_domains_dir/$domain", 0700) or die "Non posso creare $new_panda_domains_dir/$domain: $!"; + chown($vuid, $vgid, "$new_panda_domains_dir/$domain") or die "Non posso settare l'owner di $new_panda_domains_dir/$domain: $!"; } my $usercount=0; my $dircount=0; @@ -381,20 +532,16 @@ if ($usercount > ($dircount*100 + 100)) { $dirprefix="$dircount/"; $dircount++; - if (! -d "$newdomaindir/$domain/$dirprefix") { - mkdir ("$newdomaindir/$domain/$dirprefix") or die "Non posso creare $newdomaindir/$domain/$dirprefix: $!"; - chown($vuid, $vgid, "$newdomaindir/$domain/$dirprefix") or die "Non posso settare l'owner di $newdomaindir/$domain/$dirprefix: $!"; + if (! -d "$new_panda_domains_dir/$domain/$dirprefix") { + mkdir ("$new_panda_domains_dir/$domain/$dirprefix", 0700) or die "Non posso creare $new_panda_domains_dir/$domain/$dirprefix: $!"; + chown($vuid, $vgid, "$new_panda_domains_dir/$domain/$dirprefix") or die "Non posso settare l'owner di $new_panda_domains_dir/$domain/$dirprefix: $!"; } } my $home = "$domain/$dirprefix$user"; - if (! -d "$newdomaindir/$home") { - mkdir ("$newdomaindir/$home", 0700) or die "Non posso creare $newdomaindir/$home: $!"; - chown($vuid, $vgid, "$newdomaindir/$home"); - } my $maildir = "$home/Maildir"; - if (! -d "$newdomaindir/$maildir") { - maildirmake("$newdomaindir/$maildir"); - convert_old_maildir($domains_real{$domain}->{"users"}->{$user}->{"maildir"}, "$newdomaindir/$maildir"); + if (! -d "$new_panda_domains_dir/$home") { + maildirmake("$new_panda_domains_dir/$home"); + convert_old_maildir($domains_real{$domain}->{"users"}->{$user}->{"maildir"}, "$new_panda_domains_dir/$maildir"); } print(OUT "$user\@localdelivery.$domain\t$maildir/\n"); $sth->execute($id_domain, @@ -411,12 +558,6 @@ $dbh->commit; $dbh->disconnect; -# aggiornamento hash -system("$postmap hash:$confdir/alias-domains"); -system("$postmap hash:$confdir/virtual-domains"); -system("$postmap hash:$confdir/virtual-domain-aliases"); -system("$postmap hash:$confdir/virtual-domain-users"); - exit; ########################################## END ########################## # debug print alias domains This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-06 09:50:28
|
Revision: 9 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=9&view=rev Author: mnencia Date: 2007-12-06 01:50:15 -0800 (Thu, 06 Dec 2007) Log Message: ----------- Made setup/sql/drop.sql working even with empty database. vmaild does not fail anymore if domains dir does not exists, instead creates it. Modified Paths: -------------- trunk/setup/bin/vmaild trunk/setup/sql/drop.sql Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-05 16:43:33 UTC (rev 8) +++ trunk/setup/bin/vmaild 2007-12-06 09:50:15 UTC (rev 9) @@ -51,9 +51,12 @@ # for syslog use Sys::Syslog; -# funzioni sul filesystem +# filesystem functions use File::Spec::Functions qw(:ALL); +# for mkpath +use File::Path; + ####################### SUBROUTINES ################################ sub logmsg($$;@) { @@ -164,6 +167,10 @@ my $ok = 1; + if (! -d $path ) { + mkpath( $path, 0700 ); + } + foreach my $dir (@dirs) { if ( !mkdir( $dir, 0700 ) ) { logmsg( 'warning', "warning: cannot create $dir dir: $!" ); Modified: trunk/setup/sql/drop.sql =================================================================== --- trunk/setup/sql/drop.sql 2007-12-05 16:43:33 UTC (rev 8) +++ trunk/setup/sql/drop.sql 2007-12-06 09:50:15 UTC (rev 9) @@ -1,43 +1,43 @@ -DROP FUNCTION virtual_mailbox_maps(text); -DROP FUNCTION virtual_mailbox_domains(text); -DROP FUNCTION virtual_alias_maps(text); -DROP FUNCTION virtual_alias_domains(text); -DROP FUNCTION get_id_domain_local(text); -DROP FUNCTION extract_domain_from_local(text); -DROP FUNCTION get_nwl_id(text); -DROP FUNCTION create_nwl(text,text); -DROP FUNCTION delete_alias(text); -DROP FUNCTION update_alias(text,text); -DROP FUNCTION create_alias(text,text); -DROP FUNCTION delete_user(text); -DROP FUNCTION update_user(text,text); -DROP FUNCTION update_user(text,text,boolean); -DROP FUNCTION create_user(text,text); -DROP FUNCTION create_user(text,text,boolean); -DROP FUNCTION delete_alias_domain(text); -DROP FUNCTION update_alias_domain(text,text); -DROP FUNCTION create_alias_domain(text,text); -DROP FUNCTION delete_domain(text); -DROP FUNCTION update_domain(text,text); -DROP FUNCTION create_domain(text); -DROP FUNCTION create_domain(text,text); -DROP FUNCTION validate_user_name(text); -DROP FUNCTION validate_domain_name(text); -DROP FUNCTION validate_destination_list(text); -DROP FUNCTION compute_dir(integer); -DROP FUNCTION have_default_delivery(text); -DROP FUNCTION get_id_user(text); -DROP FUNCTION get_domain_by_id(integer); -DROP FUNCTION get_id_domain(text); -DROP FUNCTION extract_user(text); -DROP FUNCTION extract_domain(text); -DROP TABLE newsletter_mails; -DROP TABLE newsletter_addresses; -DROP TABLE newsletter_maps; -DROP TABLE admin_user_alias_domains; -DROP TABLE admin_user_domains; -DROP TABLE admin_users; -DROP TABLE virtual_domain_users; -DROP TABLE virtual_domain_aliases; -DROP TABLE virtual_domains; -DROP TABLE alias_domains; +DROP FUNCTION IF EXISTS virtual_mailbox_maps(text); +DROP FUNCTION IF EXISTS virtual_mailbox_domains(text); +DROP FUNCTION IF EXISTS virtual_alias_maps(text); +DROP FUNCTION IF EXISTS virtual_alias_domains(text); +DROP FUNCTION IF EXISTS get_id_domain_local(text); +DROP FUNCTION IF EXISTS extract_domain_from_local(text); +DROP FUNCTION IF EXISTS get_nwl_id(text); +DROP FUNCTION IF EXISTS create_nwl(text,text); +DROP FUNCTION IF EXISTS delete_alias(text); +DROP FUNCTION IF EXISTS update_alias(text,text); +DROP FUNCTION IF EXISTS create_alias(text,text); +DROP FUNCTION IF EXISTS delete_user(text); +DROP FUNCTION IF EXISTS update_user(text,text); +DROP FUNCTION IF EXISTS update_user(text,text,boolean); +DROP FUNCTION IF EXISTS create_user(text,text); +DROP FUNCTION IF EXISTS create_user(text,text,boolean); +DROP FUNCTION IF EXISTS delete_alias_domain(text); +DROP FUNCTION IF EXISTS update_alias_domain(text,text); +DROP FUNCTION IF EXISTS create_alias_domain(text,text); +DROP FUNCTION IF EXISTS delete_domain(text); +DROP FUNCTION IF EXISTS update_domain(text,text); +DROP FUNCTION IF EXISTS create_domain(text); +DROP FUNCTION IF EXISTS create_domain(text,text); +DROP FUNCTION IF EXISTS validate_user_name(text); +DROP FUNCTION IF EXISTS validate_domain_name(text); +DROP FUNCTION IF EXISTS validate_destination_list(text); +DROP FUNCTION IF EXISTS compute_dir(integer); +DROP FUNCTION IF EXISTS have_default_delivery(text); +DROP FUNCTION IF EXISTS get_id_user(text); +DROP FUNCTION IF EXISTS get_domain_by_id(integer); +DROP FUNCTION IF EXISTS get_id_domain(text); +DROP FUNCTION IF EXISTS extract_user(text); +DROP FUNCTION IF EXISTS extract_domain(text); +DROP TABLE IF EXISTS newsletter_mails; +DROP TABLE IF EXISTS newsletter_addresses; +DROP TABLE IF EXISTS newsletter_maps; +DROP TABLE IF EXISTS admin_user_alias_domains; +DROP TABLE IF EXISTS admin_user_domains; +DROP TABLE IF EXISTS admin_users; +DROP TABLE IF EXISTS virtual_domain_users; +DROP TABLE IF EXISTS virtual_domain_aliases; +DROP TABLE IF EXISTS virtual_domains; +DROP TABLE IF EXISTS alias_domains; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-05 16:43:30
|
Revision: 8 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=8&view=rev Author: mnencia Date: 2007-12-05 08:43:33 -0800 (Wed, 05 Dec 2007) Log Message: ----------- Cleaned vpopmail2panda script and moved it to a better location Added Paths: ----------- trunk/setup/contrib/vpopmail2panda/ trunk/setup/contrib/vpopmail2panda/create-user-group trunk/setup/contrib/vpopmail2panda/import Removed Paths: ------------- trunk/setup/contrib/CHECKLIST trunk/setup/contrib/convert trunk/setup/contrib/etc/ trunk/setup/contrib/functions.txt trunk/setup/contrib/sync trunk/setup/contrib/usergroup Deleted: trunk/setup/contrib/CHECKLIST =================================================================== --- trunk/setup/contrib/CHECKLIST 2007-12-05 16:31:54 UTC (rev 7) +++ trunk/setup/contrib/CHECKLIST 2007-12-05 16:43:33 UTC (rev 8) @@ -1,17 +0,0 @@ -merge della configurazione di postfix e di courier - -lanciare ./usergroup - -modificare gli id utente in ./convert, /etc/courier/authpgsqlrc e -/etc/postfix/main.cf - - -CONNESSIONE AL DB -modificare ./convert, /etc/postfix/*.pg, /etc/courier/authpgsqlrc - - -creare /org/vmail con etc e domains e copiare i file *.pg in /etc/postfix - -./convert - -et voila Deleted: trunk/setup/contrib/convert =================================================================== --- trunk/setup/contrib/convert 2007-12-05 16:31:54 UTC (rev 7) +++ trunk/setup/contrib/convert 2007-12-05 16:43:33 UTC (rev 8) @@ -1,452 +0,0 @@ -#!/usr/bin/perl - -die "questo script non deve essere eseguito mai piu'"; - -use strict; - -# old -my $domaindir = "vpopmail/domains"; -my $basedir = "/var/lib"; - -# new -my $newdomaindir = "/org/vmail/domains"; -my $confdir = "/org/vmail/etc"; -my $db_host = "db.xcon.it"; -my $db_port = "5432"; -my $db_database = "vmail"; -my $db_user = "vmail"; -my $db_pass = "vmail"; -my $db_alias_domains = "alias_domains"; -my $db_virtual_domains = "virtual_domains"; -my $db_virtual_domain_aliases = "virtual_domain_aliases"; -my $db_virtual_domain_users = "virtual_domain_users"; -my $db_dont_drop = 0; - -# conf -my $postmap = "/usr/sbin/postmap"; -my $vuid = 101; -my $vgid = 103; - -sub maildirmake($) { - my ($path) = @_; - my @dirs = ($path, $path."/new", $path."/cur", $path."/tmp"); - foreach my $dir (@dirs) { - mkdir ($dir, 0700) or die "Non posso creare $dir: $!"; - } - chown($vuid, $vgid, @dirs); -} - -sub convert_old_maildir($$) { - my ($old,$new) = @_; - my (@list, @created); - if (! opendir(DIR, $old)) { - print(STDERR "WARNING: Impossibile aprire la directory $old: $!\n"); - return; - } - @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); - closedir(DIR); - foreach my $item (@list) { - my $file = "$old/$item"; - my $filenew = "$new/$item"; - if ( -d $file ) { - mkdir ($filenew, 0700) or die "Non posso creare $filenew: $!" if ! -d $filenew; - convert_old_maildir($file, $filenew); - } elsif ( $item eq 'sqwebmail-pass') { - next; - } elsif ( -f $file ) { - open(SOURCE, "<$file") or die "Non posso aprire $file in lettura: $!"; - open(DEST, ">$filenew") or die "Non posso aprire $filenew in scrittura: $!"; - chmod(0600, $filenew); - print DEST while(<SOURCE>); - close(DEST); - close(SOURCE); - } else { - print(STDERR "WARNING: Unknown item $file during conversion: skipped...\n"); - next; - } - push(@created, $filenew); - } - chown($vuid, $vgid, @created); -} - -sub scalable_name($$) { - my ($name, $deep) = @_; - my $prefix = ''; - for (my $i = 0; $i < $deep; $i++) { - $prefix = $prefix.substr($name,$i,1)."/"; - } - return $prefix.$name; -} - -my (@domains, %domains_alias, %domains_real, %domain_real_users, %domain_real_alias); - -# leggo la lista dei domini -opendir(DDIR,$domaindir) or die "Non posso aprire $domaindir: $!"; -@domains = sort grep { /^[^.]/ } readdir(DDIR); -closedir(DDIR); - -# distinguo quali domini sono reali e quali alias -foreach my $domain (@domains) { - if (-l "$domaindir/$domain") { - my $real = readlink "$domaindir/$domain"; - $real =~ s%^.*/%%; - $domains_alias{$domain} = $real; - } else { - $domains_real{$domain} = {"dir" => "$domaindir/$domain"}; - } -} - -# sanity: ogni dominio puntato da un alias deve esistere. -while (my ($domain,$real) = each %domains_alias) { - if(!$domains_real{$real}) { - print(STDERR "WARNING: l' alias '$domain' punta un dominio inesistente ($real).\n"); - } -} - -# aquisisco gli utenti e gli alias per ogni dominio reale -foreach my $domain (keys %domains_real) { - - my $ddir = $domains_real{$domain}->{"dir"}; - - # utenti - open(VPASSWD, "<$ddir/vpasswd") or die "Non posso aprire $ddir/vapsswd: $!"; - my @lines = <VPASSWD>; - close(VPASSWD); - my %users; - foreach my $line (@lines) { - chomp($line); - my @values = split(/:/, $line); - if(!$values[0]) { - print(STDERR "WARNING: uid vuoto processando $domain\n"); - next; - } - my %user; - $user{"password"} = $values[1]; - $user{"pop3_enabled"} = ($values[3] eq '0')?'t':'f'; - $values[5] =~ m%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)%; - if ($domains_alias{$1}) { - $user{"maildir"} = "vpopmail/domains/".$domains_alias{$1}."/$2$3/Maildir"; - } else { - $user{"maildir"} = "vpopmail/domains/$1/$2$3/Maildir"; - } - $users{$values[0]} = \%user; - } - $domains_real{$domain}->{"users"} = \%users; - - # alias - opendir(DDIR,$ddir) or die "Non posso aprire $ddir: $!"; - my @aliasfiles = sort grep { /^\.qmail-/ } readdir(DDIR); - closedir(DDIR); - my %aliases; - foreach my $aliasfile (@aliasfiles) { - my $alias = $aliasfile; - $alias =~ s/^.qmail-//; - $alias =~ s/:/./g; - open(AFILE, "<$ddir/$aliasfile"); - my @lines = <AFILE>; - close(AFILE); - if ($alias eq "default") { - my $dest = $lines[0]; - chomp($dest); - if ($dest =~ s%^\|\s*/[\w/]+/vdelivermail '' %%) { - next if ($dest eq "bounce-no-mailbox"); - if ($dest =~ /^[a-z0-9]+([-\.\+_a-z0-9]+)*\@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}$/i) { - $domains_real{$domain}->{"default"} = $dest; - next; - } elsif ($dest =~ /^\//) { - $dest =~ s%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)$%\3@\1%; - $domains_real{$domain}->{"default"} = $dest; - next; - } - } - print (STDERR "WARNING: default delivery sconosciuto ($domain): $dest\n"); - } - else { - my @dest; - foreach my $line (@lines) { - chomp($line); - if ($line =~ /^\s*$/) { - next; - } elsif ($line =~ /^\|/) { - next if ($line eq "|/var/lib/vpopmail/blackhole"); - if ($line =~ s%^\|/usr/sbin/vdelivermail '' %%) { - $line =~ s%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)$%\3@\1%; - $line = ":local:" if "$alias\@$domain" eq $line or - "$alias\@$domain" eq "$3\@".$domains_alias{$1}; - push (@dest, $line); - next; - } - } elsif ($line =~ /^\//) { - $line =~ s%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)/Maildir/$%\3@\1%; - $line = ":local:" if "$alias\@$domain" eq $line or - "$alias\@$domain" eq "$3\@".$domains_alias{$1}; - push (@dest, $line); - next; - } elsif ($line =~ /^&?[a-z0-9]+([-\.\+_a-z0-9]+)*\@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}$/i ) { - push (@dest, $line); - next; - } - print (STDERR "WARNING: destinazione sconosciuta in $alias\@$domain: $line\n"); - } - $aliases{$alias} = \@dest; - } - } - $domains_real{$domain}->{"aliases"} = \%aliases; -} - -# sanity: rimuoviamo schifezze -@domains = grep { !/^test.com$/ } @domains; -delete($domains_real{"test.com"}); -while (my ($domain,$data) = each %domains_real) { - - # rimuoviamo gli alias e gli utenti postmaster - delete($data->{"aliases"}->{"postmaster"}); - delete($data->{"users"}->{"postmaster"}); - - # rimuovo gli alias webmaster quando questi puntano a *@centerweb.it - if ($data->{"aliases"}->{"webmaster"}) { - my @newaliases = grep { ! /^.*\@centerweb.it$/i } @{$data->{"aliases"}->{"webmaster"}}; - if ($#newaliases == -1) { - delete($data->{"aliases"}->{"webmaster"}); - } else { - $data->{"aliases"}->{"webmaster"} = \@newaliases; - } - } - - # rimuovo gli alias con nome test* - while (my ($aliasname,$dests) = each %{$data->{"aliases"}}) { - if ($aliasname =~ /^test/) { - delete ($data->{"aliases"}->{$aliasname}); - } - } -} - -# rimuovo gli alias che puntano a caselle locali inesistenti o che contengono solo :local: -my $removed; -my $pass = 0; -do { - while (my ($domain,$data) = each %domains_real) { - $removed = 0; - foreach my $alias (sort keys %{$data->{"aliases"}}) { - foreach my $destn (0 .. $#{$data->{"aliases"}->{$alias}}) { - my $dest = $data->{"aliases"}->{$alias}->[$destn]; - - # se :local: deve esistere la casella locale - if ($dest eq ":local:" and !$data->{"users"}->{$alias} and !$data->{"default"}) { - delete($data->{"aliases"}->{$alias}->[$destn]); - print (STDERR "WARNING: alias $alias\@$domain: destinazione locale errata($dest)(pass $pass): RIMOSSA!\n"); - } - my ($duser,$ddomain) = split(/@/, $dest); - $duser =~ s/^([^-]*)-.*?$/\1/; - # dominio alias -> dominio reale - if ($domains_alias{$ddomain}) { - $ddomain = $domains_alias{$ddomain}; - } - # test di esistenza di $dest - if (my $ddata = $domains_real{$ddomain}) { - if (!$ddata->{"users"}->{$duser} and !$ddata->{"aliases"}->{$duser} and !$ddata->{"default"}) { - delete($data->{"aliases"}->{$alias}->[$destn]); - print (STDERR "WARNING: alias $alias\@$domain: destinazione locale errata($dest)(pass $pass): RIMOSSA!\n"); - } - } - } - if ($#{$data->{"aliases"}->{$alias}} == -1) { - delete($data->{"aliases"}->{$alias}); - print (STDERR "WARNING: alias $alias\@$domain non ha destinazioni(pass $pass): RIMOSSO!\n"); - $removed = 1; - } elsif ($#{$data->{"aliases"}->{$alias}} == 0 and $data->{"aliases"}->{$alias}->[0] eq ":local:") { - print (STDERR "WARNING: alias $alias\@$domain ha solo destinazione :local: (pass $pass): RIMOSSO!\n"); - delete($data->{"aliases"}->{$alias}); - } - } - } - $pass = $pass + 1; -} while ($removed); # ripetiamo fino a che c'\xE8 almeno una cancellazione... - -# generazione files e tabelle postgres -use DBI; -use DBD::Pg qw(:pg_types); -my $dbh; -my $sth; -$dbh = DBI->connect("dbi:Pg:dbname=$db_database;host=$db_host;port=$db_port;", $db_user, $db_pass) - or die $dbh->errstr; -$dbh->begin_work(); - -# cancello il database -if (!$db_dont_drop) { - open(DROP, "<drop.sql"); - $dbh->do(join("",<DROP>)) or die $dbh->errstr; - close(DROP); -} - -# ricreo il database -open(CREATE, "<create.sql"); -$dbh->do(join("",<CREATE>)) or die $dbh->errstr; -close(CREATE); -open(CREATE, "<users.sql"); -$dbh->do(join("",<CREATE>)) or die $dbh->errstr; -close(CREATE); -open(CREATE, "<functions.sql"); -$dbh->do(join("",<CREATE>)) or die $dbh->errstr; -close(CREATE); -open(CREATE, "<functions-postfix.sql"); -$dbh->do(join("",<CREATE>)) or die $dbh->errstr; -close(CREATE); - -# generazione tabella alias-domains -$sth = $dbh->prepare(qq\xA7 - INSERT INTO $db_alias_domains (name, destination) VALUES (?, ?); - \xA7) or die $dbh->errstr; -open (OUT, ">$confdir/alias-domains"); -print(OUT "# File contenete i domini alias di un altro dominio\n"); -foreach my $domain (sort keys %domains_alias) { - print(OUT "\n$domain\tDUMMY_IGNORED\n"); - print(OUT "\@$domain\t\@$domains_alias{$domain}\n"); - $sth->execute($domain, $domains_alias{$domain}) or die $dbh->errstr; -} -close(OUT); - -# generazione tabella virtual-domains -$sth = $dbh->prepare(qq\xA7 - INSERT INTO $db_virtual_domains (name, unknown_to) VALUES (?, ?); - \xA7) or die $dbh->errstr; -open (OUT, ">$confdir/virtual-domains"); -print(OUT "# File contenete i domini virtuali locali.\n"); -foreach my $domain (sort keys %domains_real) { - print(OUT "\n$domain\tDUMMY_IGNORED\n"); - if ($domains_real{$domain}->{"default"}) { - print(OUT "\@$domain\t",$domains_real{$domain}->{"default"},"\n"); - $sth->execute($domain, $domains_real{$domain}->{"default"}) or die $dbh->errstr; - } else { - print(OUT "\@$domain\t\@localdelivery.$domain\n"); - $sth->execute($domain, undef) or die $dbh->errstr; - } -} -close(OUT); - -# generazione tabella virtual-domain-aliases -$sth = $dbh->prepare(qq\xA7 - INSERT INTO $db_virtual_domain_aliases (id_domain, name, destination) VALUES (?, ?, ?); - \xA7) or die $dbh->errstr; -open (OUT, ">$confdir/virtual-domain-aliases"); -print(OUT "# File contenete le email di tipo alias per i domini virtuali locali\n"); -foreach my $domain (sort keys %domains_real) { - my $id_domain = $dbh->selectrow_array("SELECT id FROM $db_virtual_domains WHERE name = ?", {}, $domain) - or die $dbh->errstr; - print(OUT "\n# $domain\n") if keys %{$domains_real{$domain}->{"aliases"}} > 0; - foreach my $alias (sort keys %{$domains_real{$domain}->{"aliases"}}) { - my $alldest = ''; - foreach my $dest (@{$domains_real{$domain}->{"aliases"}->{$alias}}) { - #TODO check how to convert :local: - if ($dest eq ":local:") { - $alldest .= "$alias\@localdelivery.$domain "; - } else { - $alldest .= "$dest "; - } - } - $alldest =~ s/ $//; - print(OUT "$alias\@$domain\t$alldest\n"); - $sth->execute($id_domain, $alias, $alldest) or die $dbh->errstr; - } - if ($domains_real{$domain}->{"default"}) { - print(OUT "# $domain utenti reali (presente default destination)\n") if keys %{$domains_real{$domain}->{"users"}} > 0; - foreach my $user (sort keys %{$domains_real{$domain}->{"users"}}) { - print(OUT "$user\@$domain\t$user\@localdelivery.$domain\n"); - } - } -} -close(OUT); - -# generazione tabella virtual-domain-users e delle caselle di posta -if (! -d "$newdomaindir") { - mkdir ("$newdomaindir") or die "Non posso creare $newdomaindir: $!"; - chown($vuid, $vgid, "$newdomaindir") or die "Non posso settare l'owner di $newdomaindir: $!"; -} -$sth = $dbh->prepare(qq\xA7 - INSERT INTO $db_virtual_domain_users (id_domain, name, passwd, maildir, pop3_enabled) VALUES (?, ?, ?, ?, ?); - \xA7) or die $dbh->errstr; -open (OUT, ">$confdir/virtual-domain-users"); -print(OUT "# File contenete le mailbox per i domini virtuali locali\n"); -foreach my $domain (sort keys %domains_real) { - my $id_domain = $dbh->selectrow_array("SELECT id FROM $db_virtual_domains WHERE name = ?", {}, $domain) - or die $dbh->errstr; - if (keys %{$domains_real{$domain}->{"users"}} > 0) { - print(OUT "\n# $domain\n"); - print(OUT "localdelivery.$domain\tDUMMY_IGNORED\n"); - } - if (! -d "$newdomaindir/$domain") { - mkdir("$newdomaindir/$domain") or die "Non posso creare $newdomaindir/$domain: $!"; - chown($vuid, $vgid, "$newdomaindir/$domain") or die "Non posso settare l'owner di $newdomaindir/$domain: $!"; - } - my $usercount=0; - my $dircount=0; - my $dirprefix=""; - foreach my $user (sort keys %{$domains_real{$domain}->{"users"}}) { - $usercount++; - if ($usercount > ($dircount*100 + 100)) { - $dirprefix="$dircount/"; - $dircount++; - if (! -d "$newdomaindir/$domain/$dirprefix") { - mkdir ("$newdomaindir/$domain/$dirprefix") or die "Non posso creare $newdomaindir/$domain/$dirprefix: $!"; - chown($vuid, $vgid, "$newdomaindir/$domain/$dirprefix") or die "Non posso settare l'owner di $newdomaindir/$domain/$dirprefix: $!"; - } - } - my $maildir = "$domain/$dirprefix$user"; - if (! -d "$newdomaindir/$maildir") { - maildirmake("$newdomaindir/$maildir"); - convert_old_maildir($domains_real{$domain}->{"users"}->{$user}->{"maildir"}, "$newdomaindir/$maildir"); - } - print(OUT "$user\@localdelivery.$domain\t$maildir/\n"); - $sth->execute($id_domain, - $user, - $domains_real{$domain}->{"users"}->{$user}->{"password"}, - "$maildir/", - $domains_real{$domain}->{"users"}->{$user}->{"pop3_enabled"}) or die $dbh->errstr; - } - $dbh->do(qq\xA7 - UPDATE $db_virtual_domains SET usercount = ? WHERE id = ?; - \xA7, {}, $usercount, $id_domain) or die $dbh->errstr; -} -close(OUT); - -# disconnessione dal database -$dbh->commit; -$dbh->disconnect; - -# aggiornamento hash -system("$postmap hash:$confdir/alias-domains"); -system("$postmap hash:$confdir/virtual-domains"); -system("$postmap hash:$confdir/virtual-domain-aliases"); -system("$postmap hash:$confdir/virtual-domain-users"); - -exit; ########################################## END ########################## - -# debug print alias domains -while (my ($key,$val) = each %domains_alias) { - print $key, ' = ', $val, "\n"; -} - -# debug print real domains -while (my ($key,$val) = each %domains_real) { - print $key, " =\n"; - while (my ($key1,$val1) = each %$val) { - if ($key1 =~ /^(dir|default)$/ ) { - print "\t", $key1, ' = ', $val1, "\n" - } else { - print "\t", $key1, " =\n"; - while (my ($key2,$val2) = each %$val1) { - print "\t\t", $key2, " =\n"; - if ($key1 eq "aliases") { - foreach my $val3 (@$val2) { - print "\t\t\t", $val3, "\n"; - } - } else { - while (my ($key3,$val3) = each %$val2) { - print "\t\t\t", $key3, ' = ', $val3, "\n"; - } - } - } - } - } -} - Deleted: trunk/setup/contrib/functions.txt =================================================================== --- trunk/setup/contrib/functions.txt 2007-12-05 16:31:54 UTC (rev 7) +++ trunk/setup/contrib/functions.txt 2007-12-05 16:43:33 UTC (rev 8) @@ -1,14 +0,0 @@ -create_user(email, passwd, pop3_enabled) -create_user(email, passwd) -create_alias(email, destination) -create_domain(domain) -create_domain(domain, unknown_to) - -update_user(email, passwd, boolean) -update_user(email, passwd) -update_alias(email, destination) -update_domain(domain, unknown_to) - -delete_user(email) -delete_alias(email) -delete_domain(domain) Deleted: trunk/setup/contrib/sync =================================================================== --- trunk/setup/contrib/sync 2007-12-05 16:31:54 UTC (rev 7) +++ trunk/setup/contrib/sync 2007-12-05 16:43:33 UTC (rev 8) @@ -1,40 +0,0 @@ -#!/bin/bash - -SOURCE=/var/lib/vpopmail - -#rsync -vazH --progress --stats --delete --delete-excluded \ -# --exclude '*.mbox' \ -# --exclude '*.MSG' \ -# --exclude '*.msg' \ -# --exclude '*.faramir' \ -# --exclude '*.faramir,S=*' \ -# --exclude '*.faramir:2,S' \ -# --exclude '*.faramir:2,' \ -# --exclude '*.voyager' \ -# --exclude '*.voyager,S=*' \ -# --exclude '*.voyager:2,S' \ -# --exclude '*.voyager:2,' \ -# --exclude '*.voyager:2,RS' \ -# --exclude '*~' \ -# ro...@fa...:$SOURCE* . - -rsync -vazH --progress --stats --delete --delete-excluded \ - ro...@fa...:$SOURCE* . - - -find vpopmail/domains -maxdepth 1 \ - -type l -and -not -lname $SOURCE/domains/\* \ - -printf "%p\t%l\n" | \ -while read file path; do - if [ "${path#[./]}" == "${path}" ]; then - echo "Normalizzo link manuale ($file -> $SOURCE/domains/$path)" - rm -f $file - ln -s $SOURCE/domains/$path $file - else - echo "Include dominio esterno (${path#$(dirname $SOURCE)/} -> $file)" - rm -f $file - mv ${path#$(dirname $SOURCE)/} $file - fi -done - -rm -fr $(basename $SOURCE)?* Deleted: trunk/setup/contrib/usergroup =================================================================== --- trunk/setup/contrib/usergroup 2007-12-05 16:31:54 UTC (rev 7) +++ trunk/setup/contrib/usergroup 2007-12-05 16:43:33 UTC (rev 8) @@ -1 +0,0 @@ -adduser --system --home /org/vmail --group vmail Copied: trunk/setup/contrib/vpopmail2panda/create-user-group (from rev 4, trunk/setup/contrib/usergroup) =================================================================== --- trunk/setup/contrib/vpopmail2panda/create-user-group (rev 0) +++ trunk/setup/contrib/vpopmail2panda/create-user-group 2007-12-05 16:43:33 UTC (rev 8) @@ -0,0 +1 @@ +adduser --system --home /org/vmail --group vmail Copied: trunk/setup/contrib/vpopmail2panda/import (from rev 4, trunk/setup/contrib/convert) =================================================================== --- trunk/setup/contrib/vpopmail2panda/import (rev 0) +++ trunk/setup/contrib/vpopmail2panda/import 2007-12-05 16:43:33 UTC (rev 8) @@ -0,0 +1,450 @@ +#!/usr/bin/perl + +use strict; + +# old +my $domaindir = "vpopmail/domains"; +my $basedir = "/home"; + +# new +my $newdomaindir = "/home/mnencia/q2p/domains"; +my $confdir = "/home/mnencia/q2p/etc"; +my $db_host = "localhost"; +my $db_port = "5432"; +my $db_database = "vmail"; +my $db_user = "vmail"; +my $db_pass = "vmail"; +my $db_alias_domains = "alias_domains"; +my $db_virtual_domains = "virtual_domains"; +my $db_virtual_domain_aliases = "virtual_domain_aliases"; +my $db_virtual_domain_users = "virtual_domain_users"; +my $db_dont_drop = 0; + +# conf +my $postmap = "/usr/sbin/postmap"; +my $vuid = 1000; +my $vgid = 1000; + +sub maildirmake($) { + my ($path) = @_; + my @dirs = ($path, $path."/new", $path."/cur", $path."/tmp"); + foreach my $dir (@dirs) { + mkdir ($dir, 0700) or die "Non posso creare $dir: $!"; + } + chown($vuid, $vgid, @dirs); +} + +sub convert_old_maildir($$) { + my ($old,$new) = @_; + my (@list, @created); + if (! opendir(DIR, $old)) { + print(STDERR "WARNING: Impossibile aprire la directory $old: $!\n"); + return; + } + @list = sort grep { ! /^(\.|\.\.)$/ } readdir(DIR); + closedir(DIR); + foreach my $item (@list) { + my $file = "$old/$item"; + my $filenew = "$new/$item"; + if ( -d $file ) { + mkdir ($filenew, 0700) or die "Non posso creare $filenew: $!" if ! -d $filenew; + convert_old_maildir($file, $filenew); + } elsif ( $item eq 'sqwebmail-pass') { + next; + } elsif ( -f $file ) { + open(SOURCE, "<$file") or die "Non posso aprire $file in lettura: $!"; + open(DEST, ">$filenew") or die "Non posso aprire $filenew in scrittura: $!"; + chmod(0600, $filenew); + print DEST while(<SOURCE>); + close(DEST); + close(SOURCE); + } else { + print(STDERR "WARNING: Unknown item $file during conversion: skipped...\n"); + next; + } + push(@created, $filenew); + } + chown($vuid, $vgid, @created); +} + +sub scalable_name($$) { + my ($name, $deep) = @_; + my $prefix = ''; + for (my $i = 0; $i < $deep; $i++) { + $prefix = $prefix.substr($name,$i,1)."/"; + } + return $prefix.$name; +} + +my (@domains, %domains_alias, %domains_real, %domain_real_users, %domain_real_alias); + +# leggo la lista dei domini +opendir(DDIR,$domaindir) or die "Non posso aprire $domaindir: $!"; +@domains = sort grep { /^[^.]/ } readdir(DDIR); +closedir(DDIR); + +# distinguo quali domini sono reali e quali alias +foreach my $domain (@domains) { + if (-l "$domaindir/$domain") { + my $real = readlink "$domaindir/$domain"; + $real =~ s%^.*/%%; + $domains_alias{$domain} = $real; + } else { + $domains_real{$domain} = {"dir" => "$domaindir/$domain"}; + } +} + +# sanity: ogni dominio puntato da un alias deve esistere. +while (my ($domain,$real) = each %domains_alias) { + if(!$domains_real{$real}) { + print(STDERR "WARNING: l' alias '$domain' punta un dominio inesistente ($real).\n"); + } +} + +# aquisisco gli utenti e gli alias per ogni dominio reale +foreach my $domain (keys %domains_real) { + + my $ddir = $domains_real{$domain}->{"dir"}; + + # utenti + open(VPASSWD, "<$ddir/vpasswd") or die "Non posso aprire $ddir/vapsswd: $!"; + my @lines = <VPASSWD>; + close(VPASSWD); + my %users; + foreach my $line (@lines) { + chomp($line); + my @values = split(/:/, $line); + if(!$values[0]) { + print(STDERR "WARNING: uid vuoto processando $domain\n"); + next; + } + my %user; + $user{"password"} = $values[1]; + $user{"pop3_enabled"} = ($values[3] eq '0')?'t':'f'; + $values[5] =~ m%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)%; + if ($domains_alias{$1}) { + $user{"maildir"} = "vpopmail/domains/".$domains_alias{$1}."/$2$3/Maildir"; + } else { + $user{"maildir"} = "vpopmail/domains/$1/$2$3/Maildir"; + } + $users{$values[0]} = \%user; + } + $domains_real{$domain}->{"users"} = \%users; + + # alias + opendir(DDIR,$ddir) or die "Non posso aprire $ddir: $!"; + my @aliasfiles = sort grep { /^\.qmail-/ } readdir(DDIR); + closedir(DDIR); + my %aliases; + foreach my $aliasfile (@aliasfiles) { + my $alias = $aliasfile; + $alias =~ s/^.qmail-//; + $alias =~ s/:/./g; + open(AFILE, "<$ddir/$aliasfile"); + my @lines = <AFILE>; + close(AFILE); + if ($alias eq "default") { + my $dest = $lines[0]; + chomp($dest); + if ($dest =~ s%^\|\s*/[\w/]+/vdelivermail '' %%) { + next if ($dest eq "bounce-no-mailbox"); + if ($dest =~ /^[a-z0-9]+([-\.\+_a-z0-9]+)*\@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}$/i) { + $domains_real{$domain}->{"default"} = $dest; + next; + } elsif ($dest =~ /^\//) { + $dest =~ s%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)$%\3@\1%; + $domains_real{$domain}->{"default"} = $dest; + next; + } + } + print (STDERR "WARNING: default delivery sconosciuto ($domain): $dest\n"); + } + else { + my @dest; + foreach my $line (@lines) { + chomp($line); + if ($line =~ /^\s*$/) { + next; + } elsif ($line =~ /^\|/) { + next if ($line eq "|/var/lib/vpopmail/blackhole"); + if ($line =~ s%^\|/usr/sbin/vdelivermail '' %%) { + $line =~ s%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)$%\3@\1%; + $line = ":local:" if "$alias\@$domain" eq $line or + "$alias\@$domain" eq "$3\@".$domains_alias{$1}; + push (@dest, $line); + next; + } + } elsif ($line =~ /^\//) { + $line =~ s%$basedir/vpopmail/domains/([^/]+)/(.*/)*([^/]+)/Maildir/$%\3@\1%; + $line = ":local:" if "$alias\@$domain" eq $line or + "$alias\@$domain" eq "$3\@".$domains_alias{$1}; + push (@dest, $line); + next; + } elsif ($line =~ /^&?[a-z0-9]+([-\.\+_a-z0-9]+)*\@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}$/i ) { + push (@dest, $line); + next; + } + print (STDERR "WARNING: destinazione sconosciuta in $alias\@$domain: $line\n"); + } + $aliases{$alias} = \@dest; + } + } + $domains_real{$domain}->{"aliases"} = \%aliases; +} + +# sanity: rimuoviamo schifezze +@domains = grep { !/^test.com$/ } @domains; +delete($domains_real{"test.com"}); +while (my ($domain,$data) = each %domains_real) { + + # rimuoviamo gli alias e gli utenti postmaster + delete($data->{"aliases"}->{"postmaster"}); + delete($data->{"users"}->{"postmaster"}); + + # rimuovo gli alias webmaster quando questi puntano a *@centerweb.it + if ($data->{"aliases"}->{"webmaster"}) { + my @newaliases = grep { ! /^.*\@centerweb.it$/i } @{$data->{"aliases"}->{"webmaster"}}; + if ($#newaliases == -1) { + delete($data->{"aliases"}->{"webmaster"}); + } else { + $data->{"aliases"}->{"webmaster"} = \@newaliases; + } + } + + # rimuovo gli alias con nome test* + while (my ($aliasname,$dests) = each %{$data->{"aliases"}}) { + if ($aliasname =~ /^test/) { + delete ($data->{"aliases"}->{$aliasname}); + } + } +} + +# rimuovo gli alias che puntano a caselle locali inesistenti o che contengono solo :local: +my $removed; +my $pass = 0; +do { + while (my ($domain,$data) = each %domains_real) { + $removed = 0; + foreach my $alias (sort keys %{$data->{"aliases"}}) { + foreach my $destn (0 .. $#{$data->{"aliases"}->{$alias}}) { + my $dest = $data->{"aliases"}->{$alias}->[$destn]; + + # se :local: deve esistere la casella locale + if ($dest eq ":local:" and !$data->{"users"}->{$alias} and !$data->{"default"}) { + delete($data->{"aliases"}->{$alias}->[$destn]); + print (STDERR "WARNING: alias $alias\@$domain: destinazione locale errata($dest)(pass $pass): RIMOSSA!\n"); + } + my ($duser,$ddomain) = split(/@/, $dest); + $duser =~ s/^([^-]*)-.*?$/\1/; + # dominio alias -> dominio reale + if ($domains_alias{$ddomain}) { + $ddomain = $domains_alias{$ddomain}; + } + # test di esistenza di $dest + if (my $ddata = $domains_real{$ddomain}) { + if (!$ddata->{"users"}->{$duser} and !$ddata->{"aliases"}->{$duser} and !$ddata->{"default"}) { + delete($data->{"aliases"}->{$alias}->[$destn]); + print (STDERR "WARNING: alias $alias\@$domain: destinazione locale errata($dest)(pass $pass): RIMOSSA!\n"); + } + } + } + if ($#{$data->{"aliases"}->{$alias}} == -1) { + delete($data->{"aliases"}->{$alias}); + print (STDERR "WARNING: alias $alias\@$domain non ha destinazioni(pass $pass): RIMOSSO!\n"); + $removed = 1; + } elsif ($#{$data->{"aliases"}->{$alias}} == 0 and $data->{"aliases"}->{$alias}->[0] eq ":local:") { + print (STDERR "WARNING: alias $alias\@$domain ha solo destinazione :local: (pass $pass): RIMOSSO!\n"); + delete($data->{"aliases"}->{$alias}); + } + } + } + $pass = $pass + 1; +} while ($removed); # ripetiamo fino a che c'\xE8 almeno una cancellazione... + +# generazione files e tabelle postgres +use DBI; +use DBD::Pg qw(:pg_types); +my $dbh; +my $sth; +$dbh = DBI->connect("dbi:Pg:dbname=$db_database;host=$db_host;port=$db_port;", $db_user, $db_pass) + or die $dbh->errstr; +$dbh->begin_work(); + +# cancello il database +if (!$db_dont_drop) { + open(DROP, "<sql/drop.sql"); + $dbh->do(join("",<DROP>)) or die $dbh->errstr; + close(DROP); +} + +# ricreo il database +open(CREATE, "<sql/create.sql"); +$dbh->do(join("",<CREATE>)) or die $dbh->errstr; +close(CREATE); +open(CREATE, "<sql/functions.sql"); +$dbh->do(join("",<CREATE>)) or die $dbh->errstr; +close(CREATE); +open(CREATE, "<sql/users.sql"); +$dbh->do(join("",<CREATE>)) or die $dbh->errstr; +close(CREATE); + +# generazione tabella alias-domains +$sth = $dbh->prepare(qq| + INSERT INTO $db_alias_domains (name, destination) VALUES (?, ?); + |) or die $dbh->errstr; +open (OUT, ">$confdir/alias-domains"); +print(OUT "# File contenete i domini alias di un altro dominio\n"); +foreach my $domain (sort keys %domains_alias) { + print(OUT "\n$domain\tDUMMY_IGNORED\n"); + print(OUT "\@$domain\t\@$domains_alias{$domain}\n"); + $sth->execute($domain, $domains_alias{$domain}) or die $dbh->errstr; +} +close(OUT); + +# generazione tabella virtual-domains +$sth = $dbh->prepare(qq| + INSERT INTO $db_virtual_domains (name, unknown_to) VALUES (?, ?); + |) or die $dbh->errstr; +open (OUT, ">$confdir/virtual-domains"); +print(OUT "# File contenete i domini virtuali locali.\n"); +foreach my $domain (sort keys %domains_real) { + print(OUT "\n$domain\tDUMMY_IGNORED\n"); + if ($domains_real{$domain}->{"default"}) { + print(OUT "\@$domain\t",$domains_real{$domain}->{"default"},"\n"); + $sth->execute($domain, $domains_real{$domain}->{"default"}) or die $dbh->errstr; + } else { + print(OUT "\@$domain\t\@localdelivery.$domain\n"); + $sth->execute($domain, undef) or die $dbh->errstr; + } +} +close(OUT); + +# generazione tabella virtual-domain-aliases +$sth = $dbh->prepare(qq| + INSERT INTO $db_virtual_domain_aliases (id_domain, name, destination) VALUES (?, ?, ?); + |) or die $dbh->errstr; +open (OUT, ">$confdir/virtual-domain-aliases"); +print(OUT "# File contenete le email di tipo alias per i domini virtuali locali\n"); +foreach my $domain (sort keys %domains_real) { + my $id_domain = $dbh->selectrow_array("SELECT id FROM $db_virtual_domains WHERE name = ?", {}, $domain) + or die $dbh->errstr; + print(OUT "\n# $domain\n") if keys %{$domains_real{$domain}->{"aliases"}} > 0; + foreach my $alias (sort keys %{$domains_real{$domain}->{"aliases"}}) { + my $alldest = ''; + foreach my $dest (@{$domains_real{$domain}->{"aliases"}->{$alias}}) { + #TODO check how to convert :local: + if ($dest eq ":local:") { + $alldest .= "$alias\@localdelivery.$domain "; + } else { + $alldest .= "$dest "; + } + } + $alldest =~ s/ $//; + print(OUT "$alias\@$domain\t$alldest\n"); + $sth->execute($id_domain, $alias, $alldest) or die $dbh->errstr; + } + if ($domains_real{$domain}->{"default"}) { + print(OUT "# $domain utenti reali (presente default destination)\n") if keys %{$domains_real{$domain}->{"users"}} > 0; + foreach my $user (sort keys %{$domains_real{$domain}->{"users"}}) { + print(OUT "$user\@$domain\t$user\@localdelivery.$domain\n"); + } + } +} +close(OUT); + +# generazione tabella virtual-domain-users e delle caselle di posta +if (! -d "$newdomaindir") { + mkdir ("$newdomaindir") or die "Non posso creare $newdomaindir: $!"; + chown($vuid, $vgid, "$newdomaindir") or die "Non posso settare l'owner di $newdomaindir: $!"; +} +$sth = $dbh->prepare(qq| + INSERT INTO $db_virtual_domain_users (id_domain, name, passwd, maildir, pop3_enabled) VALUES (?, ?, ?, ?, ?); + |) or die $dbh->errstr; +open (OUT, ">$confdir/virtual-domain-users"); +print(OUT "# File contenete le mailbox per i domini virtuali locali\n"); +foreach my $domain (sort keys %domains_real) { + my $id_domain = $dbh->selectrow_array("SELECT id FROM $db_virtual_domains WHERE name = ?", {}, $domain) + or die $dbh->errstr; + if (keys %{$domains_real{$domain}->{"users"}} > 0) { + print(OUT "\n# $domain\n"); + print(OUT "localdelivery.$domain\tDUMMY_IGNORED\n"); + } + if (! -d "$newdomaindir/$domain") { + mkdir("$newdomaindir/$domain") or die "Non posso creare $newdomaindir/$domain: $!"; + chown($vuid, $vgid, "$newdomaindir/$domain") or die "Non posso settare l'owner di $newdomaindir/$domain: $!"; + } + my $usercount=0; + my $dircount=0; + my $dirprefix=""; + foreach my $user (sort keys %{$domains_real{$domain}->{"users"}}) { + $usercount++; + if ($usercount > ($dircount*100 + 100)) { + $dirprefix="$dircount/"; + $dircount++; + if (! -d "$newdomaindir/$domain/$dirprefix") { + mkdir ("$newdomaindir/$domain/$dirprefix") or die "Non posso creare $newdomaindir/$domain/$dirprefix: $!"; + chown($vuid, $vgid, "$newdomaindir/$domain/$dirprefix") or die "Non posso settare l'owner di $newdomaindir/$domain/$dirprefix: $!"; + } + } + my $home = "$domain/$dirprefix$user"; + if (! -d "$newdomaindir/$home") { + mkdir ("$newdomaindir/$home", 0700) or die "Non posso creare $newdomaindir/$home: $!"; + chown($vuid, $vgid, "$newdomaindir/$home"); + } + my $maildir = "$home/Maildir"; + if (! -d "$newdomaindir/$maildir") { + maildirmake("$newdomaindir/$maildir"); + convert_old_maildir($domains_real{$domain}->{"users"}->{$user}->{"maildir"}, "$newdomaindir/$maildir"); + } + print(OUT "$user\@localdelivery.$domain\t$maildir/\n"); + $sth->execute($id_domain, + $home, + $domains_real{$domain}->{"users"}->{$user}->{"password"}, + "$maildir/", + $domains_real{$domain}->{"users"}->{$user}->{"pop3_enabled"}) or die $dbh->errstr; + } + $dbh->do("UPDATE $db_virtual_domains SET usercount = ? WHERE id = ?;", {}, $usercount, $id_domain) or die $dbh->errstr; +} +close(OUT); + +# disconnessione dal database +$dbh->commit; +$dbh->disconnect; + +# aggiornamento hash +system("$postmap hash:$confdir/alias-domains"); +system("$postmap hash:$confdir/virtual-domains"); +system("$postmap hash:$confdir/virtual-domain-aliases"); +system("$postmap hash:$confdir/virtual-domain-users"); + +exit; ########################################## END ########################## + +# debug print alias domains +while (my ($key,$val) = each %domains_alias) { + print $key, ' = ', $val, "\n"; +} + +# debug print real domains +while (my ($key,$val) = each %domains_real) { + print $key, " =\n"; + while (my ($key1,$val1) = each %$val) { + if ($key1 =~ /^(dir|default)$/ ) { + print "\t", $key1, ' = ', $val1, "\n" + } else { + print "\t", $key1, " =\n"; + while (my ($key2,$val2) = each %$val1) { + print "\t\t", $key2, " =\n"; + if ($key1 eq "aliases") { + foreach my $val3 (@$val2) { + print "\t\t\t", $val3, "\n"; + } + } else { + while (my ($key3,$val3) = each %$val2) { + print "\t\t\t", $key3, ' = ', $val3, "\n"; + } + } + } + } + } +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-05 16:31:53
|
Revision: 7 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=7&view=rev Author: mnencia Date: 2007-12-05 08:31:54 -0800 (Wed, 05 Dec 2007) Log Message: ----------- Moved general purpose funcions in function.sql Deprecated function-postfix.sql Modified Paths: -------------- trunk/setup/sql/functions-postfix.sql trunk/setup/sql/functions.sql Modified: trunk/setup/sql/functions-postfix.sql =================================================================== --- trunk/setup/sql/functions-postfix.sql 2007-12-05 16:26:40 UTC (rev 6) +++ trunk/setup/sql/functions-postfix.sql 2007-12-05 16:31:54 UTC (rev 7) @@ -1,16 +1,8 @@ --- Postfix utility functions +-- DEPRECATED -- -- DEPRECATED -- -- DEPRECATED -- -- DEPRECATED -- +-- DEPRECATED -- -- DEPRECATED -- -- DEPRECATED -- -- DEPRECATED -- +-- DEPRECATED -- -- DEPRECATED -- -- DEPRECATED -- -- DEPRECATED -- -CREATE OR REPLACE FUNCTION extract_domain_from_local(text) RETURNS text - AS E'SELECT substring($1 from E''localdelivery\\\\.([^@]*)$'');' - LANGUAGE sql IMMUTABLE; - - -CREATE OR REPLACE FUNCTION get_id_domain_local(text) RETURNS integer - AS 'SELECT id FROM virtual_domains - WHERE name = extract_domain_from_local($1) AND NOT deleted;' - LANGUAGE sql STABLE; - -- Postfix routing functions CREATE OR REPLACE FUNCTION virtual_alias_domains(text) RETURNS text Modified: trunk/setup/sql/functions.sql =================================================================== --- trunk/setup/sql/functions.sql 2007-12-05 16:26:40 UTC (rev 6) +++ trunk/setup/sql/functions.sql 2007-12-05 16:31:54 UTC (rev 7) @@ -52,6 +52,16 @@ END;' LANGUAGE plpgsql; +CREATE OR REPLACE FUNCTION extract_domain_from_local(text) RETURNS text + AS E'SELECT substring($1 from E''localdelivery\\\\.([^@]*)$'');' + LANGUAGE sql IMMUTABLE; + + +CREATE OR REPLACE FUNCTION get_id_domain_local(text) RETURNS integer + AS 'SELECT id FROM virtual_domains + WHERE name = extract_domain_from_local($1) AND NOT deleted;' + LANGUAGE sql STABLE; + -- Validation functions CREATE OR REPLACE FUNCTION validate_destination_list(text) RETURNS boolean This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-05 16:26:39
|
Revision: 6 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=6&view=rev Author: mnencia Date: 2007-12-05 08:26:40 -0800 (Wed, 05 Dec 2007) Log Message: ----------- Splitted configuration from main vmail executable. Better default config file location for newsletter executable. vmaild migrated to new upcoming mail layout. Modified Paths: -------------- trunk/setup/bin/newsletter trunk/setup/bin/vmaild Added Paths: ----------- trunk/setup/bin/vmaild.conf Modified: trunk/setup/bin/newsletter =================================================================== --- trunk/setup/bin/newsletter 2007-12-05 11:29:43 UTC (rev 5) +++ trunk/setup/bin/newsletter 2007-12-05 16:26:40 UTC (rev 6) @@ -21,7 +21,7 @@ use Date::Parse; # Debian: libtimedate-perl use Date::Format; # Debian: libtimedate-perl -my $configfile = "/home/mnencia/tmp/newsletter.conf"; +my $configfile = "/srv/vmail/etc/newsletter.conf"; my ($db_host, $db_port, $db_dbname, $db_user, $db_password, $table); Modified: trunk/setup/bin/vmaild =================================================================== --- trunk/setup/bin/vmaild 2007-12-05 11:29:43 UTC (rev 5) +++ trunk/setup/bin/vmaild 2007-12-05 16:26:40 UTC (rev 6) @@ -19,38 +19,28 @@ use strict; # Conf -my $domaindir = "/srv/vmail/domains"; -my $deldir = "/srv/vmail/deleted"; -my $db_host = "localhost"; -my $db_port = "5432"; -my $db_database = "vmail"; -my $db_user = "vmail"; -my $db_pass = "vmail"; -my $db_alias_domains = "alias_domains"; -my $db_virtual_domains = "virtual_domains"; -my $db_virtual_domain_aliases = "virtual_domain_aliases"; -my $db_virtual_domain_users = "virtual_domain_users"; -my $vuid = 107; -my $vgid = 110; -my $syslog_facility = 'mail'; -my $dry_run = 0; -my $dont_fork = 0; +my $configfile = "/srv/vmail/etc/vmaild.conf"; -my $sieve_script = q|# This script has been automatically generated by avelsieve -# (Sieve Mail Filters Plugin for Squirrelmail) -# Warning: If you edit this manually, then the changes will not -# be reflected in the users' front-end! -#AVELSIEVE_VERSIONYTo0OntzOjU6Im1ham9yIjtpOjE7czo1OiJtaW5vciI7aTo5O3M6NzoicmVsZWFzZSI7aTo3O3M6Njoic3RyaW5nIjtzOjU6IjEuOS43Ijt9 -#AVELSIEVE_CREATED1190020995 -#AVELSIEVE_MODIFIED1190020995 -require ["fileinto","envelope","reject","vacation","imapflags","relational","comparator-i;ascii-numeric","regex","notify"]; -#START_SIEVE_RULEYTo0OntzOjQ6ImNvbmQiO2E6MTp7aTowO2E6NDp7czo0OiJ0eXBlIjtzOjY6ImhlYWRlciI7czo2OiJoZWFkZXIiO3M6MTE6IlgtU3BhbS1GbGFnIjtzOjk6Im1hdGNodHlwZSI7czoyOiJpcyI7czoxMToiaGVhZGVybWF0Y2giO3M6MzoiWUVTIjt9fXM6NDoidHlwZSI7czoxOiIxIjtzOjY6ImFjdGlvbiI7czoxOiI1IjtzOjY6ImZvbGRlciI7czoxMDoiSU5CT1guU3BhbSI7fQ%3D%3DEND_SIEVE_RULE -if header :is "X-Spam-Flag" "YES" -{ -fileinto "INBOX.Spam"; -} -|; +my ($db_host,$db_port,$db_database,$db_user,$db_pass, + $db_alias_domains,$db_virtual_domains, + $db_virtual_domain_aliases,$db_virtual_domain_users); +my ($domaindir,$deldir,$vuser,$vgroup,$syslog_facility,$sieve_script); + +my $dry_run = 0; +my $dont_fork = 0; + +open(CONF, "<$configfile") + or die $!; +my $conf = join('', <CONF>); +close(CONF); +eval "# line 1 '$configfile'\n". + "$conf" + or die $@; + +my $vuid = getpwnam($vuser) or die "Invalid user in config file. ($vuser)"; +my $vgid = getgrnam($vgroup) or die "Invalid group in config file ($vgroup)"; + ####################### PROGRAMMA ################################## use POSIX; @@ -97,33 +87,33 @@ my $ok = 1; + my $sieve_file = "sieve/.dovecot.sieve.sieve"; + # Special content: sieve script - if ( open( FILE, ">$path/sieve/phpscript.sieve" ) ) { + if ( open( FILE, ">$path/$sieve_file" ) ) { print FILE $sieve_script; close(FILE); } else { logmsg( 'warning', - "warning: cannot fill $path/sieve/phpscript.sieve: $!" ); + "warning: cannot fill $path/$sieve_file: $!" ); $ok = 0; } - if ( !symlink( "sieve/phpscript.sieve", $path . "/dovecot-sieve" ) ) { - logmsg( 'warning', -"warning: cannot symlink '$path/dovecot-sieve' to 'sieve/phpscript.sieve': $!" + if ( !symlink( "$sieve_file", $path . "/.dovecot.sieve" ) ) { + logmsg( 'warning', "warning: cannot symlink '$path/.dovecot.sieve' to '$sieve_file': $!" ); $ok = 0; } - if ( !chown( $vuid, $vgid, "$path/sieve/phpscript.sieve" ) ) { - logmsg( 'warning', -"warning: cannot chown '$path/sieve/phpscript.sieve' to $vuid:$vgid: $!" + if ( !chown( $vuid, $vgid, "$path/$sieve_file" ) ) { + logmsg( 'warning', "warning: cannot chown '$path/$sieve_file' to $vuid:$vgid: $!" ); $ok = 0; } - if ( !chmod( 0600, "$path/sieve/phpscript.sieve" ) ) { + if ( !chmod( 0600, "$path/$sieve_file" ) ) { logmsg( 'warning', - "warning: cannot chmod '$path/sieve/phpscript.sieve' to 0600: $!" ); + "warning: cannot chmod '$path/$sieve_file' to 0600: $!" ); $ok = 0; } @@ -138,39 +128,39 @@ } my @dirs = ( $path, - $path . "/new", - $path . "/cur", - $path . "/tmp", - $path . "/.INBOX.Drafts", - $path . "/.INBOX.Drafts/new", - $path . "/.INBOX.Drafts/cur", - $path . "/.INBOX.Drafts/tmp", - $path . "/.INBOX.Sent", - $path . "/.INBOX.Sent/new", - $path . "/.INBOX.Sent/cur", - $path . "/.INBOX.Sent/tmp", - $path . "/.INBOX.Spam", - $path . "/.INBOX.Spam/new", - $path . "/.INBOX.Spam/cur", - $path . "/.INBOX.Spam/tmp", - $path . "/.INBOX.Trash", - $path . "/.INBOX.Trash/new", - $path . "/.INBOX.Trash/cur", - $path . "/.INBOX.Trash/tmp", + $path . "/Maildir/new", + $path . "/Maildir/cur", + $path . "/Maildir/tmp", + $path . "/Maildir/.Drafts", + $path . "/Maildir/.Drafts/new", + $path . "/Maildir/.Drafts/cur", + $path . "/Maildir/.Drafts/tmp", + $path . "/Maildir/.Sent", + $path . "/Maildir/.Sent/new", + $path . "/Maildir/.Sent/cur", + $path . "/Maildir/.Sent/tmp", + $path . "/Maildir/.Spam", + $path . "/Maildir/.Spam/new", + $path . "/Maildir/.Spam/cur", + $path . "/Maildir/.Spam/tmp", + $path . "/Maildir/.Trash", + $path . "/Maildir/.Trash/new", + $path . "/Maildir/.Trash/cur", + $path . "/Maildir/.Trash/tmp", $path . "/sieve", $path . "/sieve/tmp", ); my @files = ( - $path . "/.INBOX.Drafts/maildirfolder", - $path . "/.INBOX.Sent/maildirfolder", - $path . "/.INBOX.Spam/maildirfolder", - $path . "/.INBOX.Trash/maildirfolder", - $path . "/subscriptions", + $path . "/Maildir/.Drafts/maildirfolder", + $path . "/Maildir/.Sent/maildirfolder", + $path . "/Maildir/.Spam/maildirfolder", + $path . "/Maildir/.Trash/maildirfolder", + $path . "/Maildir/subscriptions", ); my @subscriptions = - ( "INBOX.Drafts", "INBOX.Sent", "INBOX.Spam", "INBOX.Trash", ); + ( "Drafts", "Sent", "Spam", "Trash", ); my $ok = 1; @@ -189,7 +179,7 @@ } # Special content: subscriber folders - if ( open( FILE, ">>$path/subscriptions" ) ) { + if ( open( FILE, ">>$path/Maildir/subscriptions" ) ) { foreach my $subscription (@subscriptions) { print FILE "$subscription\n"; } Added: trunk/setup/bin/vmaild.conf =================================================================== --- trunk/setup/bin/vmaild.conf (rev 0) +++ trunk/setup/bin/vmaild.conf 2007-12-05 16:26:40 UTC (rev 6) @@ -0,0 +1,49 @@ +# -*- perl -*- +# Copyright (C) 2007 - Marco Nenciarini <mn...@gr...> +# +# This program 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, or (at your option) +# any later version. +# +# This program 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 this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Database +$db_host = "localhost"; +$db_port = "5432"; +$db_database = "vmail"; +$db_user = "vmail"; +$db_pass = "vmail"; +$db_alias_domains = "alias_domains"; +$db_virtual_domains = "virtual_domains"; +$db_virtual_domain_aliases = "virtual_domain_aliases"; +$db_virtual_domain_users = "virtual_domain_users"; + +# System settings +$domaindir = "/srv/vmail/domains"; +$deldir = "/srv/vmail/deleted"; +$vuser = "vmail"; +$vgroup = "vmail"; +$syslog_facility = 'mail'; + +$sieve_script = q|# Sieve Filter + +if header :is "X-Spam-Flag" "YES" +{ + fileinto "Spam"; +} +|; + +# Default Flags +# $dry_run = 0; +# $dont_fork = 0; + +### DO NOT REMOVE FOLLOWING LINE ### +1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mn...@us...> - 2007-12-05 11:29:41
|
Revision: 5 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=5&view=rev Author: mnencia Date: 2007-12-05 03:29:43 -0800 (Wed, 05 Dec 2007) Log Message: ----------- Allineate drop.sql to create.sql Removed UNIQUE constraint from virtual_domain(name) column Modified Paths: -------------- trunk/setup/sql/create.sql trunk/setup/sql/drop.sql Modified: trunk/setup/sql/create.sql =================================================================== --- trunk/setup/sql/create.sql 2007-10-10 10:12:21 UTC (rev 4) +++ trunk/setup/sql/create.sql 2007-12-05 11:29:43 UTC (rev 5) @@ -8,7 +8,7 @@ CREATE TABLE virtual_domains ( id serial PRIMARY KEY NOT NULL, - name text UNIQUE NOT NULL, + name text NOT NULL, unknown_to text, usercount integer NOT NULL DEFAULT 0, quota integer DEFAULT 102400, Modified: trunk/setup/sql/drop.sql =================================================================== --- trunk/setup/sql/drop.sql 2007-10-10 10:12:21 UTC (rev 4) +++ trunk/setup/sql/drop.sql 2007-12-05 11:29:43 UTC (rev 5) @@ -1,77 +1,43 @@ -DROP TABLE alias_domains; -DROP TABLE virtual_domains; -DROP TABLE virtual_domain_aliases; -DROP TABLE virtual_domain_users; -DROP TABLE admin_users; -DROP TABLE admin_user_domains; -DROP TABLE admin_user_alias_domains; -DROP TABLE newsletter_maps; -DROP TABLE newsletter_addresses; -DROP TABLE newsletter_mails; -DROP TABLE alias_domains; -DROP TABLE virtual_domains; -DROP TABLE virtual_domain_aliases; -DROP TABLE virtual_domain_users; -DROP TABLE admin_users; -DROP TABLE admin_user_domains; -DROP TABLE admin_user_alias_domains; -DROP TABLE newsletter_maps; -DROP TABLE newsletter_addresses; -DROP TABLE newsletter_mails; -DROP FUNCTION extract_domain_from_local(text); -DROP FUNCTION get_id_domain_local(text); -DROP FUNCTION virtual_alias_domains(text); -DROP FUNCTION virtual_alias_maps(text); -DROP FUNCTION virtual_mailbox_domains(text); DROP FUNCTION virtual_mailbox_maps(text); -DROP FUNCTION extract_domain(text); -DROP FUNCTION extract_user(text); -DROP FUNCTION get_id_domain(text); -DROP FUNCTION get_domain_by_id(integer); -DROP FUNCTION get_id_user(text); -DROP FUNCTION have_default_delivery(text); -DROP FUNCTION compute_dir(integer); -DROP FUNCTION validate_destination_list(text); -DROP FUNCTION validate_domain_name(text); -DROP FUNCTION validate_user_name(text); -DROP FUNCTION create_domain(text,text); -DROP FUNCTION create_domain(text); -DROP FUNCTION update_domain(text,text); -DROP FUNCTION delete_domain(text); -DROP FUNCTION create_alias_domain(text,text); -DROP FUNCTION update_alias_domain(text,text); -DROP FUNCTION delete_alias_domain(text); -DROP FUNCTION create_user(text,text,boolean); -DROP FUNCTION create_user(text,text); -DROP FUNCTION update_user(text,text,boolean); -DROP FUNCTION update_user(text,text); -DROP FUNCTION delete_user(text); -DROP FUNCTION create_alias(text,text); -DROP FUNCTION update_alias(text,text); -DROP FUNCTION delete_alias(text); -DROP FUNCTION create_nwl(text,text); +DROP FUNCTION virtual_mailbox_domains(text); +DROP FUNCTION virtual_alias_maps(text); +DROP FUNCTION virtual_alias_domains(text); +DROP FUNCTION get_id_domain_local(text); +DROP FUNCTION extract_domain_from_local(text); DROP FUNCTION get_nwl_id(text); -DROP FUNCTION extract_domain(text); -DROP FUNCTION extract_user(text); -DROP FUNCTION get_id_domain(text); -DROP FUNCTION get_id_user(text); -DROP FUNCTION have_default_delivery(text); -DROP FUNCTION compute_dir(integer); -DROP FUNCTION validate_destination_list(text); -DROP FUNCTION validate_domain_name(text); -DROP FUNCTION validate_user_name(text); -DROP FUNCTION create_domain(text,text); -DROP FUNCTION create_domain(text); -DROP FUNCTION update_domain(text,text); -DROP FUNCTION delete_domain(text); -DROP FUNCTION create_alias_domain(text,text); -DROP FUNCTION update_alias_domain(text,text); -DROP FUNCTION delete_alias_domain(text); -DROP FUNCTION create_user(text,text,boolean); -DROP FUNCTION create_user(text,text); -DROP FUNCTION update_user(text,text,boolean); -DROP FUNCTION update_user(text,text); -DROP FUNCTION delete_user(text); -DROP FUNCTION create_alias(text,text); -DROP FUNCTION update_alias(text,text); +DROP FUNCTION create_nwl(text,text); DROP FUNCTION delete_alias(text); +DROP FUNCTION update_alias(text,text); +DROP FUNCTION create_alias(text,text); +DROP FUNCTION delete_user(text); +DROP FUNCTION update_user(text,text); +DROP FUNCTION update_user(text,text,boolean); +DROP FUNCTION create_user(text,text); +DROP FUNCTION create_user(text,text,boolean); +DROP FUNCTION delete_alias_domain(text); +DROP FUNCTION update_alias_domain(text,text); +DROP FUNCTION create_alias_domain(text,text); +DROP FUNCTION delete_domain(text); +DROP FUNCTION update_domain(text,text); +DROP FUNCTION create_domain(text); +DROP FUNCTION create_domain(text,text); +DROP FUNCTION validate_user_name(text); +DROP FUNCTION validate_domain_name(text); +DROP FUNCTION validate_destination_list(text); +DROP FUNCTION compute_dir(integer); +DROP FUNCTION have_default_delivery(text); +DROP FUNCTION get_id_user(text); +DROP FUNCTION get_domain_by_id(integer); +DROP FUNCTION get_id_domain(text); +DROP FUNCTION extract_user(text); +DROP FUNCTION extract_domain(text); +DROP TABLE newsletter_mails; +DROP TABLE newsletter_addresses; +DROP TABLE newsletter_maps; +DROP TABLE admin_user_alias_domains; +DROP TABLE admin_user_domains; +DROP TABLE admin_users; +DROP TABLE virtual_domain_users; +DROP TABLE virtual_domain_aliases; +DROP TABLE virtual_domains; +DROP TABLE alias_domains; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |