Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / edit / process / svc_acct.cgi
index a7d5136..d75ff92 100755 (executable)
@@ -31,6 +31,11 @@ foreach (map { $_,$_."_threshold" } qw( upbytes downbytes totalbytes )) {
   $cgi->param($_, FS::UI::bytecount::parse_bytecount($cgi->param($_)) );
 }
 
+#for slipip, convert '(automatic)' to null
+my $ip_addr = $cgi->param('slipip');
+$ip_addr =~ s/[^\d\.]//g;
+$cgi->param('slipip', $ip_addr);
+
 #unmunge cgp_accessmodes (falze laziness-ish w/part_svc.pm::process &svc_domain)
 unless ( $cgi->param('cgp_accessmodes') ) {
   $cgi->param('cgp_accessmodes', 
@@ -56,13 +61,14 @@ my $new = new FS::svc_acct ( \%hash );
 
 my $error = '';
 
+my $part_svc = $svcnum ? 
+                $old->part_svc : 
+                qsearchs( 'part_svc', 
+                  { 'svcpart' => $cgi->param('svcpart') }
+                );
+
 # google captcha auth
 if ( $cgi->param('captcha_response') ) {
-  my $part_svc = $svcnum ? 
-                  $old->part_svc : 
-                  qsearchs( 'part_svc', 
-                    { 'svcpart' => $cgi->param('svcpart') }
-                  );
   my ($export) = $part_svc->part_export('acct_google');
   if ( $export and
       ! $export->captcha_auth($cgi->param('captcha_response')) ) { 
@@ -75,10 +81,44 @@ if (     $cgi->param('clear_password') eq '*HIDDEN*'
       || $cgi->param('clear_password') =~ /^\(.* encrypted\)$/ ) {
   die "fatal: no previous account to recall hidden password from!" unless $old;
 } else {
-  $error ||= $new->set_password($cgi->param('clear_password'));
+  my $newpass = $cgi->param('clear_password');
+  if ( ! $old->check_password($newpass) ) {
+    # then the password is being changed
+    $error ||= $new->is_password_allowed($newpass)
+           ||  $new->set_password($newpass);
+  }
 }
 
 if ( ! $error ) {
+
+  my $export_info = FS::part_export::export_info();
+
+  my @child_objects =
+    map FS::svc_export_machine->new({
+          'svcnum'     => $svcnum,
+          'exportnum'  => $_->exportnum,
+          'machinenum' => scalar($cgi->param('exportnum'.$_->exportnum.'machinenum')),
+        }),
+      grep { $_->machine eq '_SVC_MACHINE' }
+        $part_svc->part_export;
+
+  if ( $part_svc->has_router ) {
+    my $router = FS::router->new({
+      map { $_ => $cgi->param("router_$_") }
+      qw( routernum routername blocknum )
+    });
+    if (length($router->routername) == 0) {
+      #sensible default
+      $router->set('routername', $new->label);
+    }
+    if (length($router->blocknum) == 0) {
+      #unset it
+      $router->set('blocknum', 0);
+    }
+    push @child_objects, $router;
+  }
+
+
   if ( $svcnum ) {
     foreach ( grep { $old->$_ != $new->$_ }
                    qw( seconds upbytes downbytes totalbytes )
@@ -92,9 +132,9 @@ if ( ! $error ) {
       $error ||= $new->set_usage(\%hash);  #unoverlimit and trigger radius changes
       last;                                #once is enough
     }
-    $error ||= $new->replace($old);
+    $error ||= $new->replace($old, 'child_objects'=>\@child_objects);
   } else {
-    $error ||= $new->insert;
+    $error ||= $new->insert('child_objects'=>\@child_objects);
     $svcnum = $new->svcnum;
   }
 }