X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=bin%2Fsvc_acct.export;h=0bc370fc0130fbdf7b8b420357f0e1656084644d;hp=a5ec45d489006615b4e0fbeb0e4e45dbde9723f6;hb=91c530c9c397573559834d298ffd7c1d9f7ecb44;hpb=55b29dc1d28b0c27e7f8271e7fe382a36d75d268 diff --git a/bin/svc_acct.export b/bin/svc_acct.export index a5ec45d48..0bc370fc0 100755 --- a/bin/svc_acct.export +++ b/bin/svc_acct.export @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: svc_acct.export,v 1.23 2001-08-17 10:57:40 ivan Exp $ +# $Id: svc_acct.export,v 1.36 2002-05-16 14:28:35 ivan Exp $ # # Create and export password, radius and vpopmail password files: # passwd, passwd.adjunct, shadow, acp_passwd, acp_userinfo, acp_dialup @@ -9,7 +9,6 @@ use strict; use vars qw($conf); -use Archive::Tar; use Fcntl qw(:flock); use File::Path; use IO::Handle; @@ -22,6 +21,9 @@ use FS::svc_acct; use FS::svc_domain; use FS::svc_forward; +my $ssh='ssh'; +my $rsync='rsync'; + my $user = shift or die &usage; adminsuidsetup $user; @@ -45,22 +47,6 @@ my @erpcdmachines = $conf->config('erpcdmachines') my @radiusmachines = $conf->config('radiusmachines') if $conf->exists('radiusmachines'); -my $icradiusmachines = $conf->exists('icradiusmachines'); -my @icradiusmachines = $conf->config('icradiusmachines') if $icradiusmachines; -my $icradius_mysqldest = - $conf->config('icradius_mysqldest') || "/usr/local/var/" - if $icradiusmachines; -my $icradius_mysqlsource = - $conf->config('icradius_mysqlsource') || "/usr/local/var/freeside" - if $icradiusmachines; -my $icradius_dbh; -if ( $icradiusmachines && $conf->exists('icradius_secrets') ) { - $icradius_dbh = DBI->connect($conf->config('icradius_secrets')) - or die $DBI::errstr;; -} else { - $icradius_dbh = dbh; -} - my $textradiusprepend = $conf->exists('textradiusprepend') ? $conf->config('textradiusprepend') @@ -68,10 +54,19 @@ my $textradiusprepend = warn "using depriciated textradiusprepend file" if $textradiusprepend; + +my $radiusprepend = + $conf->exists('radiusprepend') + ? join("\n", $conf->config('radiusprepend')) + : ''; + my @vpopmailmachines = $conf->config('vpopmailmachines') if $conf->exists('vpopmailmachines'); +my $vpopmailrestart = ''; +$vpopmailrestart = $conf->config('vpopmailrestart') + if $conf->exists('vpopmailrestart'); -my ($machine, $vpopdir, $vpopuid, $vpopgid) = split (/\s+/, $vpopmailmachines[0]); +my ($machine, $vpopdir, $vpopuid, $vpopgid) = split (/\s+/, $vpopmailmachines[0]) if $vpopmailmachines[0]; my($shellmachine, @qmailmachines); if ( $conf->exists('qmailmachines') ) { @@ -178,15 +173,10 @@ chmod 0600, "$spooldir/master.passwd", rmtree"$spooldir/domains", 0, 1; mkdir "$spooldir/domains", 0700; -if ( $icradiusmachines ) { - my $sth = $icradius_dbh->prepare("DELETE FROM radcheck"); - $sth->execute or die "Can't reset radcheck table: ". $sth->errstr; - my $sth2 = $icradius_dbh->prepare("DELETE FROM radreply"); - $sth2->execute or die "Can't reset radreply table: ". $sth2->errstr; -} - setpriority(0,0,10); +print USERS "$radiusprepend\n"; + my %usernames; ## this hack helps keep the passwd files sane my @sendmail; @@ -209,7 +199,7 @@ foreach $svc_domain (sort {$a->domain cmp $b->domain} @svc_domain) { "-", "", "", - ), "\n"; + ), "\n" if $vpopmailmachines[0]; (mkdir "$spooldir/domains/" . $domain, 0700) or die "Can't create $spooldir/domains/" . $domain .": $!"; @@ -224,7 +214,7 @@ foreach $svc_domain (sort {$a->domain cmp $b->domain} @svc_domain) { my ($svc_acct); - if ($svc_domain->catchall) { + if ($svc_domain->getfield('catchall')) { $svc_acct = qsearchs('svc_acct', {'svcnum' => $svc_domain->catchall}); die "Cannot find catchall account for domain $domain\n" unless $svc_acct; @@ -236,12 +226,14 @@ foreach $svc_domain (sort {$a->domain cmp $b->domain} @svc_domain) { ### # FORMAT OF THE .QMAIL-DEFAULT FILE HERE - print QMAILDEFAULT "| $vpopdir/bin/vdelivermail \"\" $username\@$domain\n"; + print QMAILDEFAULT "| $vpopdir/bin/vdelivermail \"\" " . $svc_acct->email . "\n" + if $vpopmailmachines[0]; }else{ ### # FORMAT OF THE .QMAIL-DEFAULT FILE HERE - print QMAILDEFAULT "| $vpopdir/bin/vdelivermail \"\" bounce-no-mailbox\n"; + print QMAILDEFAULT "| $vpopdir/bin/vdelivermail \"\" bounce-no-mailbox\n" + if $vpopmailmachines[0]; } print VPOPVIRTUALDOMAINS "$domain:$domain\n"; @@ -249,7 +241,8 @@ foreach $svc_domain (sort {$a->domain cmp $b->domain} @svc_domain) { foreach $svc_acct (qsearch('svc_acct', {'domsvc' => $svc_domain->svcnum})) { my($password)=$svc_acct->getfield('_password'); my($cpassword,$rpassword); - if ( ( length($password) <= 8 ) + #if ( ( length($password) <= 8 ) + if ( ( length($password) <= 12 ) && ( $password ne '*' ) && ( $password ne '!!' ) && ( $password ne '' ) @@ -273,6 +266,10 @@ foreach $svc_domain (sort {$a->domain cmp $b->domain} @svc_domain) { $username=$svc_acct->username . $svc_acct->domsvc; } elsif ($userpolicy =~ /^append domain$/) { $username=$svc_acct->username . $svc_domain->domain; + } elsif ($userpolicy =~ /^append domain$/) { + $username=$svc_acct->username . $svc_domain->domain; + } elsif ($userpolicy =~ /^append \@domain$/) { + $username=$svc_acct->username . '@'. $svc_domain->domain; } else { die "Unknown policy in username_policy\n"; } @@ -332,20 +329,20 @@ foreach $svc_domain (sort {$a->domain cmp $b->domain} @svc_domain) { '', ), "\n"; } + } - ### - # FORMAT OF THE VPASSWD FILE HERE - print VPASSWD join(":", - $svc_acct->username, - $cpassword, - '1', - '0', - $svc_acct->username, - "$vpopdir/domains/" . $svc_domain->domain ."/" . $svc_acct->username, - 'NOQUOTA', - ), "\n"; + ### + # FORMAT OF THE VPASSWD FILE HERE + print VPASSWD join(":", + $svc_acct->username, + $cpassword, + '1', + '0', + $svc_acct->username, + "$vpopdir/domains/" . $svc_domain->domain ."/" . $svc_acct->username, + 'NOQUOTA', + ), "\n"; - } if ( $svc_acct->slipip ne '' ) { @@ -379,55 +376,16 @@ foreach $svc_domain (sort {$a->domain cmp $b->domain} @svc_domain) { $username, qq(\t${textradiusprepend}), $radcheck, - qq(Password = "$rpassword"\n\t), +# qq(Password = "$rpassword"\n\t), join ",\n\t", map { qq($_ = "$radreply{$_}") } keys %radreply; - if ( $ip && $ip ne '0e0' ) { - #print USERS qq(,\n\tFramed-Address = "$ip"\n\n); - print USERS qq(,\n\tFramed-IP-Address = "$ip"\n\n); - } else { + #if ( $ip && $ip ne '0e0' ) { + # #print USERS qq(,\n\tFramed-Address = "$ip"\n\n); + # print USERS qq(,\n\tFramed-IP-Address = "$ip"\n\n); + #} else { print USERS qq(\n\n); - } + #} - ### - # ICRADIUS export - if ( $icradiusmachines ) { - - my $sth = $icradius_dbh->prepare( - "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ". - join(", ", map { $icradius_dbh->quote( $_ ) } ( - '', - $username, - "Password", - $svc_acct->_password, - ) ). " )" - ); - $sth->execute or die "Can't insert into radcheck table: ". $sth->errstr; - - foreach my $attribute ( keys %radcheck ) { - my $sth = $icradius_dbh->prepare( - "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ". - join(", ", map { $icradius_dbh->quote( $_ ) } ( - '', - $username, - $attribute, - $radcheck{$attribute}, - ) ). " )" - ); - $sth->execute or die "Can't insert into radcheck table: ". $sth->errstr; } - - foreach my $attribute ( keys %radreply ) { - my $sth = $icradius_dbh->prepare( - "INSERT INTO radreply (id, UserName, Attribute, Value) VALUES ( ". - join(", ", map { $icradius_dbh->quote( $_ ) } ( - '', - $username, - $attribute, - $radreply{$attribute}, - ) ). " )" - ); - $sth->execute or die "Can't insert into radreply table: ". $sth->errstr; } - } } ### @@ -547,7 +505,8 @@ foreach $bsdshellmachine (@bsdshellmachines) { ssh("root\@$bsdshellmachine", "( ". "mv /etc/passwd.new /etc/passwd; ". - "mv /etc/master.passwd.new /etc/master.passwd; ". + #"mv /etc/master.passwd.new /etc/master.passwd; ". + "pwd_mkdb /etc/master.passwd.new; ". " )" ) == 0 or die "ssh error: $!"; @@ -596,47 +555,32 @@ foreach $radiusmachine (@radiusmachines) { == 0 or die "ssh error: $!"; } -foreach my $icradiusmachine ( @icradiusmachines ) { - my( $machine, $db, $user, $pass ) = split(/\s+/, $icradiusmachine); - chdir $icradius_mysqlsource or die "Can't cd $icradius_mysqlsource: $!"; - open(WRITER,"|ssh root\@$machine mysql -v --user=$user -p $db"); - my $oldfh = select WRITER; $|=1; select $oldfh; - print WRITER "$pass\n"; - sleep 2; - print WRITER "LOCK TABLES radcheck WRITE, radreply WRITE;\n"; - foreach my $file ( glob("radcheck.*") ) { - my $scp = new Net::SCP; - $scp->scp($file,"root\@$machine:$icradius_mysqldest/$db/$file") - or die "scp error: ". $scp->{errstr}; - } - foreach my $file ( glob("radreply.*") ) { - my $scp = new Net::SCP; - $scp->scp($file,"root\@$machine:$icradius_mysqldest/$db/$file") - or die "scp error: ". $scp->{errstr}; - } - close WRITER; -} +#my @args = ("/bin/tar", "c", "--force-local", "-C", "$spooldir", "-f", "$spooldir/vpoptarball", "domains"); -my @args = ("/bin/tar", "c", "--force-local", "-C", "$spooldir", "-f", "$spooldir/vpoptarball", "domains"); - -system {$args[0]} @args; +#system {$args[0]} @args; my($vpopmailmachine); foreach $vpopmailmachine (@vpopmailmachines) { my ($machine, $vpopdir, $vpopuid, $vpopgid) = split (/\s+/, $vpopmailmachine); my $scp = new Net::SCP; - $scp->scp("$spooldir/vpoptarball","root\@$machine:vpoptarball") - or die "scp error: ". $scp->{errstr}; - ssh("root\@$machine", - "( ". - "tar xf vpoptarball; ". - "chown -R $vpopuid:$vpopgid domains; ". - "tar cf vpoptarball domains; ". - "cd $vpopdir; ". - "tar xf ~/vpoptarball; ". - " )" - ) - == 0 or die "ssh error: $!"; +# $scp->scp("$spooldir/vpoptarball","root\@$machine:vpoptarball") +# or die "scp error: ". $scp->{errstr}; +# ssh("root\@$machine", +# "( ". +# "rm -rf domains; ". +# "tar xf vpoptarball; ". +# "chown -R $vpopuid:$vpopgid domains; ". +# "tar cf vpoptarball domains; ". +# "cd $vpopdir; ". +# "tar xf ~/vpoptarball; ". +# " )" +# ) +# == 0 or die "ssh error: $!"; + + chdir $spooldir; + my @args = ("$rsync", "-rlpt", "-e", "$ssh", "domains/", "vpopmail\@$machine:$vpopdir/domains/"); + + system {$args[0]} @args; $scp->scp("$spooldir/assign","root\@$machine:/var/qmail/users/assign") or die "scp error: ". $scp->{errstr}; @@ -644,6 +588,15 @@ foreach $vpopmailmachine (@vpopmailmachines) { or die "scp error: ". $scp->{errstr}; $scp->scp("$spooldir/vpoprcpthosts","root\@$machine:/var/qmail/control/rcpthosts") or die "scp error: ". $scp->{errstr}; + + ssh("root\@$machine", + "( ". + $vpopmailrestart . + " )" + ) + == 0 or die "ssh error: $!"; + + } my($sendmailmachine);