package FS::svc_phone;
+use base qw( FS::svc_Domain_Mixin FS::location_Mixin FS::svc_Common );
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 );
use FS::Msgcat qw(gettext);
use FS::part_svc;
-use FS::phone_device;
use FS::svc_pbx;
use FS::svc_domain;
use FS::cust_location;
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;
}
);
sub search_sql {
my( $class, $string ) = @_;
- my $conf = new FS::Conf;
+ #my $conf = new FS::Conf;
if ( $conf->exists('svc_phone-allow_alpha_phonenum') ) {
$string =~ s/\W//g;
sub check {
my $self = shift;
- my $conf = new FS::Conf;
+ #my $conf = new FS::Conf;
+
+ my $x = $self->setfixed;
+ return $x unless ref($x);
+ my $part_svc = $x;
my $phonenum = $self->phonenum;
my $phonenum_check_method;
unless ( length($self->pin) ) {
my $random_pin = $conf->config('svc_phone-random_pin');
- if ( $random_pin =~ /^\d+$/ ) {
+ if ( defined($random_pin) && $random_pin =~ /^\d+$/ ) {
$self->pin(
join('', map int(rand(10)), 0..($random_pin-1))
);
}
}
- 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;
+
+ } elsif ( $part_svc->part_svc_column('sip_password')->columnflag ne 'F' ) {
+ # 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)) )
);
}
my $self = shift;
my %check = ();
- my $conf = new FS::Conf;
+ #my $conf = new FS::Conf;
- $check{'User-Password'} = $conf->config('svc_phone-radius-default_password');
+ my $password;
+ if ( $conf->config('svc_phone-radius-password') eq 'countrycode_phonenum' ) {
+ $password = $self->countrycode. $self->phonenum;
+ } else {
+ $password = $conf->config('svc_phone-radius-default_password');
+ }
+ $check{'User-Password'} = $password;
%check;
}
=cut
-sub phone_device {
- my $self = shift;
- qsearch('phone_device', { 'svcnum' => $self->svcnum } );
-}
-
#override location_Mixin version cause we want to try the cust_pkg location
#in between us and cust_main
# XXX what to do in the unlinked case??? return a pseudo-object that returns