bulk provisioning via ftp and SOAP #5202
[freeside.git] / FS / FS / svc_acct.pm
index 7bcd0e7..1a42e65 100644 (file)
@@ -6,7 +6,7 @@ use vars qw( @ISA $DEBUG $me $conf $skip_fuzzyfiles
              $usernamemax $passwordmin $passwordmax
              $username_ampersand $username_letter $username_letterfirst
              $username_noperiod $username_nounderscore $username_nodash
-             $username_uppercase $username_percent
+             $username_uppercase $username_percent $username_colon
              $password_noampersand $password_noexclamation
              $warning_template $warning_from $warning_subject $warning_mimetype
              $warning_cc
@@ -65,6 +65,7 @@ FS::UID->install_callback( sub {
   $username_uppercase = $conf->exists('username-uppercase');
   $username_ampersand = $conf->exists('username-ampersand');
   $username_percent = $conf->exists('username-percent');
+  $username_colon = $conf->exists('username-colon');
   $password_noampersand = $conf->exists('password-noexclamation');
   $password_noexclamation = $conf->exists('password-noexclamation');
   $dirhash = $conf->config('dirhash') || 0;
@@ -214,9 +215,9 @@ sub table_info {
     'fields' => {
         'dir'       => 'Home directory',
         'uid'       => {
-                         label     => 'UID',
-                        def_label => 'UID (set to fixed and blank for no UIDs)',
-                        type      => 'text',
+                         label    => 'UID',
+                        def_info => 'set to fixed and blank for no UIDs',
+                        type     => 'text',
                       },
         'slipip'    => 'IP address',
     #    'popnum'    => qq!<A HREF="$p/browse/svc_acct_pop.cgi/">POP number</A>!,
@@ -243,15 +244,14 @@ sub table_info {
                        },
         '_password' => 'Password',
         'gid'       => {
-                         label     => 'GID',
-                        def_label => 'GID (when blank, defaults to UID)',
-                        type      => 'text',
+                         label    => 'GID',
+                        def_info => 'when blank, defaults to UID',
+                        type     => 'text',
                       },
         'shell'     => {
-                         #desc =>'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file, set to blank for no shell tracking)',
                         label    => 'Shell',
-                         def_label=> 'Shell (set to blank for no shell tracking)',
-                         type     =>'select',
+                         def_info => 'set to blank for no shell tracking',
+                         type     => 'select',
                          #select_list => [ $conf->config('shells') ],
                          select_list => [ $conf ? $conf->config('shells') : () ],
                          disable_inventory => 1,
@@ -260,7 +260,6 @@ sub table_info {
         'finger'    => 'Real name', # (GECOS)',
         'domsvc'    => {
                          label     => 'Domain',
-                         #def_label => 'svcnum from svc_domain',
                          type      => 'select',
                          select_table => 'svc_domain',
                          select_key   => 'svcnum',
@@ -459,9 +458,12 @@ history records.
 
 sub label_long {
   my $self = shift;
-  ( $self->finger =~ /\S/ )
-    ? $self->finger. ' <'.$self->label(@_).'>'
-    : $self->label(@_);
+  my $label = $self->label(@_);
+  my $finger = $self->finger;
+  return $label unless $finger =~ /\S/;
+  my $maxlen = 40 - length($label) - length($self->cust_svc->part_svc->svc);
+  $finger = substr($finger, 0, $maxlen-3).'...' if length($finger) > $maxlen;
+  "$finger <$label>";
 }
 
 =item insert [ , OPTION => VALUE ... ]
@@ -1021,13 +1023,28 @@ sub check {
   ;
   return $error if $error;
 
+  my $cust_pkg;
+  local $username_letter = $username_letter;
+  if ($self->svcnum) {
+    my $cust_svc = $self->cust_svc
+      or return "no cust_svc record found for svcnum ". $self->svcnum;
+    my $cust_pkg = $cust_svc->cust_pkg;
+  }
+  if ($self->pkgnum) {
+    $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $self->pkgnum } );#complain?
+  }
+  if ($cust_pkg) {
+    $username_letter =
+      $conf->exists('username-letter', $cust_pkg->cust_main->agentnum);
+  }
+
   my $ulen = $usernamemax || $self->dbdef_table->column('username')->length;
   if ( $username_uppercase ) {
-    $recref->{username} =~ /^([a-z0-9_\-\.\&\%]{$usernamemin,$ulen})$/i
+    $recref->{username} =~ /^([a-z0-9_\-\.\&\%\:]{$usernamemin,$ulen})$/i
       or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
     $recref->{username} = $1;
   } else {
-    $recref->{username} =~ /^([a-z0-9_\-\.\&\%]{$usernamemin,$ulen})$/
+    $recref->{username} =~ /^([a-z0-9_\-\.\&\%\:]{$usernamemin,$ulen})$/
       or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
     $recref->{username} = $1;
   }
@@ -1052,6 +1069,9 @@ sub check {
   unless ( $username_percent ) {
     $recref->{username} =~ /\%/ and return gettext('illegal_username');
   }
+  unless ( $username_colon ) {
+    $recref->{username} =~ /\:/ and return gettext('illegal_username');
+  }
 
   $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum};
   $recref->{popnum} = $1;
@@ -1704,7 +1724,7 @@ my %op2condition = (
                $self->$column - $amount <= 0;
              },
   '+' => sub { my($self, $column, $amount) = @_;
-               $self->$column + $amount > 0;
+               ($self->$column || 0) + $amount > 0;
              },
 );
 my %op2warncondition = (
@@ -1713,7 +1733,7 @@ my %op2warncondition = (
                $self->$column - $amount <= $self->$threshold + 0;
              },
   '+' => sub { my($self, $column, $amount) = @_;
-               $self->$column + $amount > 0;
+               ($self->$column || 0) + $amount > 0;
              },
 );