svc_acct.pm: allow unicode chars in finger, RT13277
[freeside.git] / FS / FS / svc_acct.pm
index 0525b97..f12eca1 100644 (file)
@@ -746,89 +746,92 @@ sub insert {
     }
 
     #welcome email
-    my $error = '';
-    my $msgnum = $conf->config('welcome_msgnum', $agentnum);
-    if ( $msgnum ) {
-      my $msg_template = qsearchs('msg_template', { msgnum => $msgnum });
-      $error = $msg_template->send('cust_main' => $cust_main,
-                                   'object'    => $self);
-    }
-    else { #!$msgnum
-      my ($to,$welcome_template,$welcome_from,$welcome_subject,$welcome_subject_template,$welcome_mimetype)
-        = ('','','','','','');
-
-      if ( $conf->exists('welcome_email', $agentnum) ) {
-        $welcome_template = new Text::Template (
-          TYPE   => 'ARRAY',
-          SOURCE => [ map "$_\n", $conf->config('welcome_email', $agentnum) ]
-        ) or warn "can't create welcome email template: $Text::Template::ERROR";
-        $welcome_from = $conf->config('welcome_email-from', $agentnum);
-          # || 'your-isp-is-dum'
-        $welcome_subject = $conf->config('welcome_email-subject', $agentnum)
-          || 'Welcome';
-        $welcome_subject_template = new Text::Template (
-          TYPE   => 'STRING',
-          SOURCE => $welcome_subject,
-        ) or warn "can't create welcome email subject template: $Text::Template::ERROR";
-        $welcome_mimetype = $conf->config('welcome_email-mimetype', $agentnum)
-          || 'text/plain';
-      }
-      if ( $welcome_template ) {
-        my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list );
-        if ( $to ) {
-
-          my %hash = (
-                       'custnum'  => $self->custnum,
-                       'username' => $self->username,
-                       'password' => $self->_password,
-                       'first'    => $cust_main->first,
-                       'last'     => $cust_main->getfield('last'),
-                       'pkg'      => $cust_pkg->part_pkg->pkg,
-                     );
-          my $wqueue = new FS::queue {
-            'svcnum' => $self->svcnum,
-            'job'    => 'FS::svc_acct::send_email'
-          };
-          my $error = $wqueue->insert(
-            'to'       => $to,
-            'from'     => $welcome_from,
-            'subject'  => $welcome_subject_template->fill_in( HASH => \%hash, ),
-            'mimetype' => $welcome_mimetype,
-            'body'     => $welcome_template->fill_in( HASH => \%hash, ),
-          );
-          if ( $error ) {
-            $dbh->rollback if $oldAutoCommit;
-            return "error queuing welcome email: $error";
-          }
-
-          if ( $options{'depend_jobnum'} ) {
-            warn "$me depend_jobnum found; adding to welcome email dependancies"
-              if $DEBUG;
-            if ( ref($options{'depend_jobnum'}) ) {
-              warn "$me adding jobs ". join(', ', @{$options{'depend_jobnum'}} ).
-                   "to welcome email dependancies"
-                if $DEBUG;
-              push @jobnums, @{ $options{'depend_jobnum'} };
-            } else {
-              warn "$me adding job $options{'depend_jobnum'} ".
-                   "to welcome email dependancies"
-                if $DEBUG;
-              push @jobnums, $options{'depend_jobnum'};
-            }
+    my @welcome_exclude_svcparts = $conf->config('svc_acct_welcome_exclude');
+    unless ( grep { $_ eq $self->svcpart } @welcome_exclude_svcparts ) {
+        my $error = '';
+        my $msgnum = $conf->config('welcome_msgnum', $agentnum);
+        if ( $msgnum ) {
+          my $msg_template = qsearchs('msg_template', { msgnum => $msgnum });
+          $error = $msg_template->send('cust_main' => $cust_main,
+                                       'object'    => $self);
+        }
+        else { #!$msgnum
+          my ($to,$welcome_template,$welcome_from,$welcome_subject,$welcome_subject_template,$welcome_mimetype)
+            = ('','','','','','');
+
+          if ( $conf->exists('welcome_email', $agentnum) ) {
+            $welcome_template = new Text::Template (
+              TYPE   => 'ARRAY',
+              SOURCE => [ map "$_\n", $conf->config('welcome_email', $agentnum) ]
+            ) or warn "can't create welcome email template: $Text::Template::ERROR";
+            $welcome_from = $conf->config('welcome_email-from', $agentnum);
+              # || 'your-isp-is-dum'
+            $welcome_subject = $conf->config('welcome_email-subject', $agentnum)
+              || 'Welcome';
+            $welcome_subject_template = new Text::Template (
+              TYPE   => 'STRING',
+              SOURCE => $welcome_subject,
+            ) or warn "can't create welcome email subject template: $Text::Template::ERROR";
+            $welcome_mimetype = $conf->config('welcome_email-mimetype', $agentnum)
+              || 'text/plain';
           }
+          if ( $welcome_template ) {
+            my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list );
+            if ( $to ) {
+
+              my %hash = (
+                           'custnum'  => $self->custnum,
+                           'username' => $self->username,
+                           'password' => $self->_password,
+                           'first'    => $cust_main->first,
+                           'last'     => $cust_main->getfield('last'),
+                           'pkg'      => $cust_pkg->part_pkg->pkg,
+                         );
+              my $wqueue = new FS::queue {
+                'svcnum' => $self->svcnum,
+                'job'    => 'FS::svc_acct::send_email'
+              };
+              my $error = $wqueue->insert(
+                'to'       => $to,
+                'from'     => $welcome_from,
+                'subject'  => $welcome_subject_template->fill_in( HASH => \%hash, ),
+                'mimetype' => $welcome_mimetype,
+                'body'     => $welcome_template->fill_in( HASH => \%hash, ),
+              );
+              if ( $error ) {
+                $dbh->rollback if $oldAutoCommit;
+                return "error queuing welcome email: $error";
+              }
+
+              if ( $options{'depend_jobnum'} ) {
+                warn "$me depend_jobnum found; adding to welcome email dependancies"
+                  if $DEBUG;
+                if ( ref($options{'depend_jobnum'}) ) {
+                  warn "$me adding jobs ". join(', ', @{$options{'depend_jobnum'}} ).
+                       "to welcome email dependancies"
+                    if $DEBUG;
+                  push @jobnums, @{ $options{'depend_jobnum'} };
+                } else {
+                  warn "$me adding job $options{'depend_jobnum'} ".
+                       "to welcome email dependancies"
+                    if $DEBUG;
+                  push @jobnums, $options{'depend_jobnum'};
+                }
+              }
+
+              foreach my $jobnum ( @jobnums ) {
+                my $error = $wqueue->depend_insert($jobnum);
+                if ( $error ) {
+                  $dbh->rollback if $oldAutoCommit;
+                  return "error queuing welcome email job dependancy: $error";
+                }
+              }
 
-          foreach my $jobnum ( @jobnums ) {
-            my $error = $wqueue->depend_insert($jobnum);
-            if ( $error ) {
-              $dbh->rollback if $oldAutoCommit;
-              return "error queuing welcome email job dependancy: $error";
             }
-          }
-
-        }
 
-      } # if $welcome_template
-    } # if !$msgnum
+          } # if $welcome_template
+        } # if !$msgnum
+    }
   } # if $cust_pkg
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
@@ -1366,8 +1369,7 @@ sub check {
       $self->setfield('finger', $cust_main->first.' '.$cust_main->get('last') );
     }
   }
-  $self->getfield('finger') =~
-    /^([µ_0123456789aAáÁàÀâÂåÅäÄãêæÆbBcCçÇdDðÐeEéÉèÈêÊëËfFgGhHiIíÍìÌîÎïÏjJkKlLmMnNñÑoOóÓòÒôÔöÖõÕøغpPqQrRsSßtTuUúÚùÙûÛüÜvVwWxXyYýÝÿzZþÞ \t\!\@\#\$\%\&\(\)\-\+\;\'\"\,\.\?\/\*\<\>]*)$/
+  $self->getfield('finger') =~ /^([\w \,\.\-\'\&\t\!\@\#\$\%\(\)\+\;\"\?\/\*\<\>]+)$/
       or return "Illegal finger: ". $self->getfield('finger');
   $self->setfield('finger', $1);
 
@@ -1587,6 +1589,8 @@ sub set_password {
       $pass = crypt($pass, $saltset[int(rand(64))].$saltset[int(rand(64))]);
     }
     # else $encryption eq 'plain', do nothing
+    $pass .= '=' x (4 - length($pass) % 4) #properly padded base64
+      if $encryption eq 'md5' || $encryption eq 'sha1';
     $pass = '{'.uc($encryption).'}'.$pass;
   }
   # else encoding eq 'plain'
@@ -2671,12 +2675,12 @@ sub crypt_password {
 
       my $encryption = ( scalar(@_) && $_[0] ) ? shift : 'crypt';
       if ( $encryption eq 'crypt' ) {
-        crypt(
+        return crypt(
           $self->_password,
           $saltset[int(rand(64))].$saltset[int(rand(64))]
         );
       } elsif ( $encryption eq 'md5' ) {
-        unix_md5_crypt( $self->_password );
+        return unix_md5_crypt( $self->_password );
       } elsif ( $encryption eq 'blowfish' ) {
         croak "unknown encryption method $encryption";
       } else {
@@ -2684,7 +2688,7 @@ sub crypt_password {
       }
 
     } elsif ( $self->_password =~ /^\{CRYPT\}(.+)$/ ) {
-      $1;
+      return $1;
     }
 
   } elsif ( $self->_password_encoding eq 'crypt' ) {
@@ -2697,12 +2701,16 @@ sub crypt_password {
 
     my $encryption = ( scalar(@_) && $_[0] ) ? shift : 'crypt';
     if ( $encryption eq 'crypt' ) {
-      crypt(
+      return crypt(
         $self->_password,
         $saltset[int(rand(64))].$saltset[int(rand(64))]
       );
     } elsif ( $encryption eq 'md5' ) {
-      unix_md5_crypt( $self->_password );
+      return unix_md5_crypt( $self->_password );
+    } elsif ( $encryption eq 'sha1_base64' ) { #for acct_sql
+      my $pass = sha1_base64( $self->_password );
+      $pass .= '=' x (4 - length($pass) % 4); #properly padded base64
+      return $pass;
     } elsif ( $encryption eq 'blowfish' ) {
       croak "unknown encryption method $encryption";
     } else {
@@ -2723,12 +2731,12 @@ sub crypt_password {
 
       my $encryption = ( scalar(@_) && $_[0] ) ? shift : 'crypt';
       if ( $encryption eq 'crypt' ) {
-        crypt(
+        return crypt(
           $self->_password,
           $saltset[int(rand(64))].$saltset[int(rand(64))]
         );
       } elsif ( $encryption eq 'md5' ) {
-        unix_md5_crypt( $self->_password );
+        return unix_md5_crypt( $self->_password );
       } elsif ( $encryption eq 'blowfish' ) {
         croak "unknown encryption method $encryption";
       } else {