diff --git a/lib/NGCP/Panel/Controller/API/Root.pm b/lib/NGCP/Panel/Controller/API/Root.pm index 92dbf30a0a..dc3b89728e 100644 --- a/lib/NGCP/Panel/Controller/API/Root.pm +++ b/lib/NGCP/Panel/Controller/API/Root.pm @@ -347,11 +347,13 @@ sub platforminfo :Path('/api/platforminfo') :CaptureArgs(0) { my $json_file = shift; my $json = ''; my $licenses = NGCP::Panel::Utils::License::get_licenses($c); + my $license_meta = NGCP::Panel::Utils::License::get_license_meta($c); open(my $fh, '<', $json_file) || return; $json .= $_ while <$fh>; close $fh; my $data = decode_json($json) || return; - $data->{licenses} = $licenses; + $data->{licenses} = $licenses // []; + $data->{license_meta} = $license_meta // {}; return to_json($data, {pretty => 1, canonical => 1}); }); $c->forward($c->view()); diff --git a/lib/NGCP/Panel/Utils/License.pm b/lib/NGCP/Panel/Utils/License.pm index ae660d52d7..9986f15b68 100644 --- a/lib/NGCP/Panel/Utils/License.pm +++ b/lib/NGCP/Panel/Utils/License.pm @@ -3,6 +3,7 @@ use strict; use warnings; use Sipwise::Base; +use List::Util qw(none); sub get_license_status { my ($ref) = @_; @@ -75,7 +76,7 @@ sub get_licenses { next; }; my $enabled = <$fh>; - chomp($enabled) if $enabled; + chomp($enabled) if defined $enabled; push @lics, $lf if $enabled && $enabled == 1; close $fh; } @@ -84,6 +85,53 @@ sub get_licenses { return \@sorted_lics; } +sub get_license_meta { + my $c = shift; + + my $proc_dir = '/proc/ngcp'; + unless (-d $proc_dir) { + $c->log->error("Failed to access $proc_dir"); + return; + }; + + my $meta = {}; + my @collect = qw( + check + current_calls + current_pbx_groups + current_pbx_subscribers + current_registered_subscribers + current_subscribers + license_valid_until + max_calls + max_pbx_groups + max_pbx_subscribers + max_registered_subscribers + max_subscribers + valid + ); + + opendir(my $dh, $proc_dir) || do { + $c->log->error("Failed to open ngcp dir $proc_dir: $!"); + return; + }; + while (readdir($dh)) { + my $lf = $_; + next if $lf =~ /^\.+$/; + next if none { $lf eq $_ } @collect; + open(my $fh, '<', "$proc_dir/$lf") || do { + $c->log->error("Failed to open license file $lf: $!"); + next; + }; + my $value = <$fh>; + chomp($value) if defined $value; + $meta->{$lf} = $value =~ /^-?\d+(\.\d+)?$/ ? $value+0 : $value; + close $fh; + } + closedir $dh; + return $meta; +} + 1; =head1 NAME