]> git.proxmox.com Git - pmg-api.git/blobdiff - PMG/API2/Nodes.pm
PMG/API2/Nodes.pm - fix permissions for rrddata
[pmg-api.git] / PMG / API2 / Nodes.pm
index c5a3ad65dd6414c2761d6dd3a005e1b143c53f09..a03bf6c7d491583cb70cda4f23d78a462728a0c2 100644 (file)
@@ -15,11 +15,14 @@ use PVE::ProcFSTools;
 
 use PMG::pmgcfg;
 use PMG::Ticket;
+use PMG::API2::Subscription;
+use PMG::API2::APT;
 use PMG::API2::Tasks;
 use PMG::API2::Services;
 use PMG::API2::Network;
 use PMG::API2::ClamAV;
 use PMG::API2::Postfix;
+use PMG::API2::MailTracker;
 
 use base qw(PVE::RESTHandler);
 
@@ -48,6 +51,21 @@ __PACKAGE__->register_method ({
     path => 'services',
 });
 
+__PACKAGE__->register_method ({
+    subclass => "PMG::API2::Subscription",
+    path => 'subscription',
+});
+
+__PACKAGE__->register_method ({
+    subclass => "PMG::API2::APT",
+    path => 'apt',
+});
+
+__PACKAGE__->register_method ({
+    subclass => "PMG::API2::MailTracker",
+    path => 'tracker',
+});
+
 __PACKAGE__->register_method ({
     name => 'index',
     path => '',
@@ -72,13 +90,16 @@ __PACKAGE__->register_method ({
        my ($param) = @_;
 
        my $result = [
+           { name => 'apt' },
            { name => 'clamav' },
            { name => 'postfix' },
            { name => 'services' },
            { name => 'syslog' },
            { name => 'tasks' },
+           { name => 'tracker' },
            { name => 'time' },
            { name => 'status' },
+           { name => 'subscription' },
            { name => 'vncshell' },
            { name => 'rrddata' },
        ];
@@ -92,6 +113,7 @@ __PACKAGE__->register_method({
     method => 'GET',
     protected => 1, # fixme: can we avoid that?
     proxyto => 'node',
+    permissions => { check => [ 'admin', 'audit' ] },
     description => "Read node RRD statistics",
     parameters => {
        additionalProperties => 0,
@@ -188,9 +210,8 @@ __PACKAGE__->register_method({
        my $restenv = PMG::RESTEnvironment->get();
 
        my $service = $param->{service};
-       if ($service && $service eq 'postfix') {
-           $service = 'postfix@-';
-       }
+       $service = PMG::Utils::lookup_real_service_name($service)
+           if $service;
 
        my ($count, $lines) = PVE::Tools::dump_journal(
            $param->{start}, $param->{limit},
@@ -211,6 +232,12 @@ __PACKAGE__->register_method ({
        additionalProperties => 0,
        properties => {
            node => get_standard_option('pve-node'),
+           upgrade => {
+               type => 'boolean',
+               description => "Run 'apt-get dist-upgrade' instead of normal shell.",
+               optional => 1,
+               default => 0,
+           },
            websocket => {
                optional => 1,
                type => 'boolean',
@@ -233,6 +260,10 @@ __PACKAGE__->register_method ({
 
        my $node = $param->{node};
 
+       if ($node ne PVE::INotify::nodename()) {
+           die "vncproxy to remote node not implemented";
+       }
+
        # we only implement the websocket based VNC here
        my $websocket = $param->{websocket} // 1;
        die "standard VNC not implemented" if !$websocket;
@@ -242,6 +273,8 @@ __PACKAGE__->register_method ({
        my $restenv = PMG::RESTEnvironment->get();
        my $user = $restenv->get_user();
 
+       raise_perm_exc('user != root@pam') if $param->{upgrade} && $user ne 'root@pam';
+
        my $ticket = PMG::Ticket::assemble_vnc_ticket($user, $authpath);
 
        my $family = PVE::Tools::get_host_address_family($node);
@@ -250,7 +283,13 @@ __PACKAGE__->register_method ({
        my $shcmd;
 
        if ($user eq 'root@pam') {
-           $shcmd = [ '/bin/login', '-f', 'root' ];
+           if ($param->{upgrade}) {
+               my $upgradecmd = "pmgupgrade --shell";
+               # $upgradecmd = PVE::Tools::shellquote($upgradecmd) if $remip;
+               $shcmd = [ '/bin/bash', '-c', $upgradecmd ];
+           } else {
+               $shcmd = [ '/bin/login', '-f', 'root' ];
+           }
        } else {
            $shcmd = [ '/bin/login' ];
        }
@@ -592,6 +631,12 @@ __PACKAGE__->register_method({
            free => $dinfo->{bavail} - $dinfo->{used},
        };
 
+       if (my $subinfo = PVE::INotify::read_file('subscription')) {
+           if (my $level = $subinfo->{level}) {
+               $res->{level} = $level;
+           }
+       }
+
        return $res;
    }});