TT#18838 Implement max subscribers limit via license client

Change-Id: If5d2716eafd906d708415f957e9be97b479ac987
changes/45/15145/3
Richard Fuchs 8 years ago
parent 02a161be2a
commit 0956362be1

@ -0,0 +1,108 @@
package NGCP::Panel::Utils::License;
use strict;
use warnings;
use Sipwise::Base;
sub get_license_status {
my ($ref) = @_;
my $fd;
if (!open($fd, '<', '/proc/ngcp/check')) {
return 'missing';
}
my $status = <$fd>;
close($fd);
chomp($status);
if ($status =~ /^ok/) {
return 'ok';
}
if ($status =~ /missing license/) {
return 'missing';
}
if ($status =~ /^(warning|error) \((.*)\)$/) {
if (ref($ref) eq 'SCALAR') {
$$ref = $2;
}
return $1;
}
if (ref($ref) eq 'SCALAR') {
$$ref = 'internal error';
}
return 'error';
}
sub is_license_status {
my (@allowed) = @_;
my $status = get_license_status();
return scalar grep {$_ eq $status} @allowed;
}
sub is_license_error {
my (@allowed) = @_;
@allowed or @allowed = ('error');
my $ext;
my $status = get_license_status(\$ext);
if (!grep {$_ eq $status} @allowed) {
return 0;
}
return $ext || $status;
}
1;
=head1 NAME
NGCP::Panel::Utils::License
=head1 DESCRIPTION
Helper module for license handling
=head1 METHODS
=head2 get_license_status
Performs the actual check of the license status. Returns one of:
'missing': No license data present.
'ok': License present and all limits observed.
'warning': License present but some limits exceeded within the grace thresholds.
'error': License limits exceeded beyond the grace thresholds, or internal error.
A reference to a scalar can be passed as an optional first argument, in which case
a more detailed status description is written into that scalar in the 'warning'
and 'error' cases.
Example:
my $status = get_license_status(\$ext_status);
=head2 is_license_status
Takes a list of strings as argument list. Returns true or false if the license
status is one of the status names given in the argument list.
Example:
if (is_license_status(qw(missing error))) ...
=head2 is_license_error
Similar to is_license_status() but returns the status string instead of true if
the license status is one of the values given. If the argument list is empty, it
defaults to ('error').
Example:
if (my $status = is_license_error()) ...
=head1 AUTHOR
Richard Fuchs
=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:

@ -13,6 +13,7 @@ use NGCP::Panel::Utils::Preferences;
use NGCP::Panel::Utils::Email;
use NGCP::Panel::Utils::Events;
use NGCP::Panel::Utils::DateTime qw();
use NGCP::Panel::Utils::License;
use UUID qw/generate unparse/;
use JSON qw/decode_json encode_json/;
use IPC::System::Simple qw/capturex/;
@ -187,6 +188,11 @@ sub create_subscriber {
my $prov_domain = $schema->resultset('voip_domains')
->find({domain => $billing_domain->domain});
if (my $status = NGCP::Panel::Utils::License::is_license_error()) {
$c->log->warn("invalid license status: $status");
# die("invalid license status: $status");
}
my ($profile_set, $profile);
if($params->{profile_set}{id}) {
my $profile_set_rs = $c->model('DB')->resultset('voip_subscriber_profile_sets');

Loading…
Cancel
Save