You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
157 lines
3.8 KiB
157 lines
3.8 KiB
package NGCP::Panel::Utils::Subscriber;
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Sipwise::Base;
|
|
use DBIx::Class::Exception;
|
|
|
|
my %LOCK = (
|
|
0, 'none',
|
|
1, 'foreign',
|
|
2, 'outgoing',
|
|
3, 'incoming and outgoing',
|
|
4, 'global',
|
|
);
|
|
|
|
sub get_usr_preference_rs {
|
|
my %params = @_;
|
|
|
|
my $c = $params{c};
|
|
my $attribute = $params{attribute};
|
|
my $prov_subscriber= $params{prov_subscriber};
|
|
|
|
my $preference = $c->model('DB')->resultset('voip_preferences')->find({
|
|
attribute => $attribute, 'usr_pref' => 1,
|
|
})->voip_usr_preferences->search_rs({
|
|
subscriber_id => $prov_subscriber->id,
|
|
});
|
|
return $preference;
|
|
}
|
|
|
|
sub period_as_string {
|
|
my $set = shift;
|
|
|
|
my @wdays = (qw/
|
|
invalid Sunday Monday Tuesday Wednesday Thursday Friday Saturday
|
|
/);
|
|
my @months = (qw/
|
|
invalid January February March April May June July August September October November December
|
|
/);
|
|
|
|
my $string = "";
|
|
foreach my $type(qw/year month mday wday hour minute/) {
|
|
my $s = $set->{$type};
|
|
if(defined $s) {
|
|
given($type) {
|
|
when(/^month$/) {
|
|
my ($from, $to) = split /\-/, $s;
|
|
$s = $months[$from];
|
|
$s .= '-'.$months[$to] if defined($to);
|
|
}
|
|
when(/^wday$/) {
|
|
my ($from, $to) = split /\-/, $s;
|
|
$s = $wdays[$from];
|
|
$s .= '-'.$wdays[$to] if defined($to);
|
|
}
|
|
}
|
|
}
|
|
$string .= "$type { $s } " if defined($s);
|
|
}
|
|
return $string;
|
|
}
|
|
|
|
sub destination_as_string {
|
|
my $destination = shift;
|
|
my $dest = $destination->{destination};
|
|
|
|
if($dest =~ /\@voicebox\.local$/) {
|
|
return "VoiceMail";
|
|
} elsif($dest =~ /\@fax2mail\.local$/) {
|
|
return "Fax2Mail";
|
|
} elsif($dest =~ /\@conference\.local$/) {
|
|
return "Conference";
|
|
} elsif($dest =~ /^sip:callingcard\@app\.local$/) {
|
|
return "CallingCard";
|
|
} elsif($dest =~ /^sip:callthrough\@app\.local$/) {
|
|
return "CallThrough";
|
|
} elsif($dest =~ /^sip:localuser\@.+\.local$/) {
|
|
return "Local Subscriber";
|
|
} else {
|
|
my $d = $dest;
|
|
$d =~ s/sip:(.+)\@.+$/$1/;
|
|
if($d->is_int) {
|
|
return $d;
|
|
} else {
|
|
return $dest;
|
|
}
|
|
}
|
|
}
|
|
|
|
sub lock_provisoning_voip_subscriber {
|
|
my %params = @_;
|
|
|
|
my $c = $params{c};
|
|
my $prov_subscriber= $params{prov_subscriber};
|
|
my $level = $params{level};
|
|
|
|
return unless $prov_subscriber;
|
|
|
|
my $rs = get_usr_preference_rs(
|
|
c => $c,
|
|
prov_subscriber => $prov_subscriber,
|
|
attribute => 'lock'
|
|
);
|
|
try {
|
|
if($rs->first) {
|
|
if($level == 0) {
|
|
$rs->first->delete;
|
|
} else {
|
|
$rs->first->update({ value => $level });
|
|
}
|
|
} elsif($level > 0) { # nothing to do for level 0, if no lock is set yet
|
|
$rs->create({ value => $level });
|
|
}
|
|
} catch($e) {
|
|
$c->log->error("failed to set provisioning_voip_subscriber lock: $e");
|
|
$e->rethrow;
|
|
}
|
|
}
|
|
|
|
sub get_lock_string {
|
|
my $level = shift;
|
|
return $LOCK{$level};
|
|
}
|
|
|
|
1;
|
|
|
|
=head1 NAME
|
|
|
|
NGCP::Panel::Utils::Subscriber
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
A temporary helper to manipulate subscriber data
|
|
|
|
=head1 METHODS
|
|
|
|
=head2 get_usr_preference_rs
|
|
|
|
Parameters:
|
|
c The controller
|
|
prov_subscriber The provisioning_voip_subscriber row
|
|
attribute The name of the usr preference
|
|
|
|
Returns a result set for the voip_usr_preference of the given subscriber.
|
|
|
|
=head1 AUTHOR
|
|
|
|
Andreas Granig,
|
|
|
|
=head1 LICENSE
|
|
|
|
This library is free software. You can redistribute it and/or modify
|
|
it under the same terms as Perl itself.
|
|
|
|
=cut
|
|
# vim: set tabstop=4 expandtab:
|