Merge branch 'master' of git.freeside.biz:/home/git/freeside
authorIvan Kohler <ivan@freeside.biz>
Sat, 9 Nov 2013 20:03:52 +0000 (12:03 -0800)
committerIvan Kohler <ivan@freeside.biz>
Sat, 9 Nov 2013 20:03:52 +0000 (12:03 -0800)
FS/FS/Conf.pm
FS/FS/svc_phone.pm

index b368c8f..6b9aab2 100644 (file)
@@ -1724,6 +1724,21 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'sip_passwordmin',
+    'section'     => 'telephony',
+    'description' => 'Minimum SIP password length (default 6)',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'sip_passwordmax',
+    'section'     => 'telephony',
+    'description' => 'Maximum SIP password length (default 8) (don\'t set this over 12 if you need to import or export crypt() passwords)',
+    'type'        => 'text',
+  },
+
+
+  {
     'key'         => 'password-noampersand',
     'section'     => 'password',
     'description' => 'Disallow ampersands in passwords',
index 77b0137..72c609c 100644 (file)
@@ -2,9 +2,12 @@ package FS::svc_phone;
 
 use strict;
 use base qw( FS::svc_Domain_Mixin FS::location_Mixin FS::svc_Common );
-use vars qw( $DEBUG $me @pw_set $conf $phone_name_max );
+use vars qw( $DEBUG $me @pw_set $conf $phone_name_max
+             $passwordmin $passwordmax
+           );
 use Data::Dumper;
 use Scalar::Util qw( blessed );
+use List::Util qw( min );
 use FS::Conf;
 use FS::Record qw( qsearch qsearchs dbh );
 use FS::PagedSearch qw( psearch );
@@ -26,6 +29,8 @@ $DEBUG = 0;
 FS::UID->install_callback( sub { 
   $conf = new FS::Conf;
   $phone_name_max = $conf->config('svc_phone-phone_name-max_length');
+  $passwordmin = $conf->config('sip_passwordmin') || 0;
+  $passwordmax = $conf->config('sip_passwordmax') || 80;
 }
 );
 
@@ -534,10 +539,17 @@ sub check {
     }
   }
 
-  unless ( length($self->sip_password) ) { # option for this?
+  if ( length($self->sip_password) ) {
+
+    return "SIP password must be longer than $passwordmin characters"
+      if length($self->sip_password) < $passwordmin;
+    return "SIP password must be shorter than $passwordmax characters"
+      if length($self->sip_password) > $passwordmax;
+
+  } else { # option for this?
 
     $self->sip_password(
-      join('', map $pw_set[ int(rand $#pw_set) ], (0..16) )
+      join('', map $pw_set[ int(rand $#pw_set) ], (1..min($passwordmax,16)) )
     );
 
   }