diff --git a/debian/ngcp-panel.service b/debian/ngcp-panel.service index eeaa6d7026..9eadec59c6 100644 --- a/debian/ngcp-panel.service +++ b/debian/ngcp-panel.service @@ -17,10 +17,12 @@ PIDFile=/run/fastcgi/ngcp-panel.pid ExecStart=/usr/share/ngcp-panel/ngcp_panel_fastcgi.pl --listen /run/fastcgi/ngcp-panel.sock --pidfile /run/fastcgi/ngcp-panel.pid --nproc $NPROC # Files + directories not directly associated are made invisible in the /proc/ file system -ProcSubset=pid +# ProcSubset=pid +# Disabled: MT#58964, to be able to read /proc/ngcp/flags/ # Processes owned by other users are hidden from /proc/ -ProtectProc=invisible +# ProtectProc=invisible +# Disabled: MT#58964, to be able to read /proc/ngcp/flags/ # Service cannot modify the control group file system (via /sys/fs/cgroup) ProtectControlGroups=true diff --git a/lib/NGCP/Panel/Controller/API/Root.pm b/lib/NGCP/Panel/Controller/API/Root.pm index c5756983a4..92dbf30a0a 100644 --- a/lib/NGCP/Panel/Controller/API/Root.pm +++ b/lib/NGCP/Panel/Controller/API/Root.pm @@ -9,7 +9,7 @@ use HTTP::Headers qw(); use HTTP::Response qw(); use HTTP::Status qw(:constants); use File::Find::Rule; -use JSON qw(to_json encode_json); +use JSON qw(to_json encode_json decode_json); use YAML::XS qw/Dump/; use Safe::Isa qw($_isa); use NGCP::Panel::Utils::API; @@ -17,6 +17,7 @@ use List::Util qw(none); use parent qw/Catalyst::Controller NGCP::Panel::Role::API/; use NGCP::Panel::Utils::Journal qw(); +use NGCP::Panel::Utils::License; #with 'NGCP::Panel::Role::API'; @@ -342,6 +343,17 @@ sub platforminfo :Path('/api/platforminfo') :CaptureArgs(0) { $c->stash->{ngcp_api_realm} = $c->request->env->{NGCP_API_REALM} // ""; $c->stash(template => 'api/platforminfo.tt'); + $c->stash(process_json_file_cb => sub { + my $json_file = shift; + my $json = ''; + my $licenses = NGCP::Panel::Utils::License::get_licenses($c); + open(my $fh, '<', $json_file) || return; + $json .= $_ while <$fh>; + close $fh; + my $data = decode_json($json) || return; + $data->{licenses} = $licenses; + 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 8f3d81a88d..ae660d52d7 100644 --- a/lib/NGCP/Panel/Utils/License.pm +++ b/lib/NGCP/Panel/Utils/License.pm @@ -53,6 +53,37 @@ sub is_license_error { return $ext || $status; } +sub get_licenses { + my $c = shift; + + my $proc_dir = '/proc/ngcp/flags'; + unless (-d $proc_dir) { + $c->log->error("Failed to access $proc_dir"); + return; + }; + + my @lics = (); + opendir(my $dh, $proc_dir) || do { + $c->log->error("Failed to open licenses dir $proc_dir: $!"); + return; + }; + while (readdir($dh)) { + my $lf = $_; + next if $lf =~ /^\.+$/; + open(my $fh, '<', "$proc_dir/$lf") || do { + $c->log->error("Failed to open license file $lf: $!"); + next; + }; + my $enabled = <$fh>; + chomp($enabled) if $enabled; + push @lics, $lf if $enabled && $enabled == 1; + close $fh; + } + closedir $dh; + my @sorted_lics = sort @lics; + return \@sorted_lics; +} + 1; =head1 NAME diff --git a/share/templates/api/platforminfo.tt b/share/templates/api/platforminfo.tt index 131fd1229e..522023f809 100644 --- a/share/templates/api/platforminfo.tt +++ b/share/templates/api/platforminfo.tt @@ -16,11 +16,11 @@ ELSE; END; TRY; - INCLUDE $json_file; + json = c.stash.process_json_file_cb(json_file); CATCH; json = '{"error": "an internal error when fetching the config data"}'; END; json; --%] \ No newline at end of file +-%]