remove arbitary uid requirement for vpasswd generation
[freeside.git] / bin / svc_acct.export
index a5ec45d..cee63bc 100755 (executable)
@@ -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.32 2002-02-15 20:21:56 jeff Exp $
 #
 # Create and export password, radius and vpopmail password files:
 # passwd, passwd.adjunct, shadow, acp_passwd, acp_userinfo, acp_dialup
@@ -48,7 +48,7 @@ my @radiusmachines = $conf->config('radiusmachines')
 my $icradiusmachines = $conf->exists('icradiusmachines');
 my @icradiusmachines = $conf->config('icradiusmachines') if $icradiusmachines;
 my $icradius_mysqldest =
-  $conf->config('icradius_mysqldest') || "/usr/local/var/"
+  $conf->config('icradius_mysqldest') || "/usr/local/var"
     if $icradiusmachines;
 my $icradius_mysqlsource =
   $conf->config('icradius_mysqlsource') || "/usr/local/var/freeside"
@@ -56,7 +56,7 @@ my $icradius_mysqlsource =
 my $icradius_dbh;
 if ( $icradiusmachines && $conf->exists('icradius_secrets') ) {
   $icradius_dbh = DBI->connect($conf->config('icradius_secrets'))
-    or die $DBI::errstr;;
+    or die $DBI::errstr;
 } else {
   $icradius_dbh = dbh;
 }
@@ -68,10 +68,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') ) {
@@ -187,6 +196,8 @@ if ( $icradiusmachines ) {
 
 setpriority(0,0,10);
 
+print USERS "$radiusprepend\n";
+
 my %usernames;  ## this hack helps keep the passwd files sane
 my @sendmail;
 
@@ -209,7 +220,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 +235,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 +247,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 +262,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 +287,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 +350,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 '' ) {
 
@@ -427,6 +445,18 @@ foreach $svc_domain (sort {$a->domain cmp $b->domain} @svc_domain) {
             ) ). " )"
           );
           $sth->execute or die "Can't insert into radreply table: ". $sth->errstr;      }
+  
+        if ( $ip && $ip ne '0e0' ) {
+          my $sth = $icradius_dbh->prepare(
+            "INSERT INTO radreply (id, UserName, Attribute, Value) VALUES ( ".
+            join(", ", map { $icradius_dbh->quote( $_ ) } (
+              '',
+              $username,
+              'Framed-IP-Address',
+              $ip,
+            ) ). " )"
+          );
+          $sth->execute or die "Can't insert into radreply table: ". $sth->errstr;      }
       }
     }
   
@@ -547,7 +577,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: $!";
@@ -644,6 +675,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);