diff --git a/lib/NGCP/Panel/Field/URI.pm b/lib/NGCP/Panel/Field/URI.pm new file mode 100644 index 0000000000..89fd88d34d --- /dev/null +++ b/lib/NGCP/Panel/Field/URI.pm @@ -0,0 +1,98 @@ +package NGCP::Panel::Field::URI; + +use Sipwise::Base; +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler::Field::Text'; +use NGCP::Panel::Utils::Subscriber; + +our $class_messages = { + 'uri_format' => 'URI must be in format "username", "username@domain" or phone number', +}; + +sub get_class_messages { + my $self = shift; + return { + %{ $self->next::method }, + %$class_messages, + } +} + +apply( + [ + { + transform => sub { + lc($_[0]); + } + }, + { + transform => sub { + my ($v, $field) = @_; + my $c = $field->form->ctx; + return $v unless($c); + + my $sub = $c->stash->{subscriber}; + return $v unless($sub); + + $v =~ s/^sips?://; + my ($user, $domain) = split(/\@/, $v); + $domain = $sub->domain->domain unless($domain); + my $uri; + + if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") { + $user = NGCP::Panel::Utils::Subscriber::apply_rewrite( + c => $c, subscriber => $sub, number => $user, direction => 'callee_in' + ); + } + $uri = 'sip:' . $user . '@' . $domain; + + return $uri; + } + }, + { + check => sub { + my ( $value, $field ) = @_; + my ($user, $domain) = split(/\@/, $value); + my $checked = $value if $user && $domain; # TODO: proper check + $field->value($checked) + if $checked; + }, + message => sub { + my ( $value, $field ) = @_; + return $field->get_message('uri_format'); + }, + } + ] +); + +has '+deflate_method' => ( default => sub { \&uri_deflate } ); + +sub uri_deflate { + my ( $field, $v ) = @_; + + my $c = $field->form->ctx; + return $v unless($c); + + my $sub = $c->stash->{subscriber}; + return $v unless($sub); + + $v =~ s/^sips?://; + my $t; + my ($user, $domain) = split(/\@/, $v); + if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") { + $user = NGCP::Panel::Utils::Subscriber::apply_rewrite( + c => $c, subscriber => $sub, number => $user, direction => 'caller_out' + ); + } + if($domain eq $sub->domain->domain) { + $v = $user; + } else { + $v = $user . '@' . $domain; + } + return $v; +} + +1; +__PACKAGE__->meta->make_immutable; +use namespace::autoclean + +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/SubscriberCFSimple.pm b/lib/NGCP/Panel/Form/SubscriberCFSimple.pm index 30e711ab46..88323c7e68 100644 --- a/lib/NGCP/Panel/Form/SubscriberCFSimple.pm +++ b/lib/NGCP/Panel/Form/SubscriberCFSimple.pm @@ -3,6 +3,7 @@ use HTML::FormHandler::Moose; use HTML::FormHandler::Widget::Block::Bootstrap; use Moose::Util::TypeConstraints; use NGCP::Panel::Field::PosInteger; +use NGCP::Panel::Field::URI; extends 'HTML::FormHandler'; has '+widget_wrapper' => (default => 'Bootstrap'); @@ -64,7 +65,7 @@ has_field 'destination.uri' => ( do_label => 0, ); has_field 'destination.uri.destination' => ( - type => 'Text', + type => '+NGCP::Panel::Field::URI', label => 'URI/Number', ); has_field 'destination.uri.timeout' => ( diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm index 3fae18136f..0e1dd5b9b6 100644 --- a/lib/NGCP/Panel/Utils/Subscriber.pm +++ b/lib/NGCP/Panel/Utils/Subscriber.pm @@ -776,13 +776,6 @@ sub field_to_destination { } elsif($d eq "uri") { $d = $uri; } - # TODO: check for valid dest here - if($d !~ /\@/) { - $d .= '@'.$domain; - } - if($d !~ /^sip:/) { - $d = 'sip:' . $d; - } return $d; } @@ -975,18 +968,18 @@ sub apply_rewrite { $replace = qq{"$replace"}; my $found; + #print ">>>>>>>>>>> apply matches\n"; foreach my $m(@{ $match }) { + #print ">>>>>>>>>>> m=$m, r=$replace\n"; if($callee =~ s/$m/$replace/eeg) { # we only process one match + #print ">>>>>>>>>>> match found, callee=$callee\n"; $found = 1; last; } } last if $found; - - #print ">>>>>>>>>>> done, match=$match, replace=$replace, callee is $callee\n"; - } return $callee; diff --git a/ngcp_panel.conf b/ngcp_panel.conf index a893dcca31..059d84f738 100644 --- a/ngcp_panel.conf +++ b/ngcp_panel.conf @@ -81,7 +81,7 @@ log4perl.appender.Default.layout.ConversionPattern=%d{ISO8601} [%p] [%F +%L] %m{ password_musthave_specialchar 0 password_allow_recovery 0 password_sip_autogenerate 1 - password_web_autogenerate 1 + password_web_autogenerate 0 password_sip_expose_subadmin 0 password_web_expose_subadmin 0