X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PMG%2FAPI2%2FNodes.pm;h=c91e910ab251f227642fbc60d365882f262c3ec0;hb=c2e3529ab6319171fcaa25be6b2935cbf3bb7e86;hp=0f913b9f0ae627369dd39a319d6a10f21bbd6655;hpb=da5777d7cf42cd068fbe74f681d17a995fcbb937;p=pmg-api.git diff --git a/PMG/API2/Nodes.pm b/PMG/API2/Nodes.pm index 0f913b9..c91e910 100644 --- a/PMG/API2/Nodes.pm +++ b/PMG/API2/Nodes.pm @@ -15,14 +15,17 @@ use PVE::ProcFSTools; use PMG::pmgcfg; use PMG::Ticket; +use PMG::Report; 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::SpamAssassin; use PMG::API2::Postfix; use PMG::API2::MailTracker; +use PMG::API2::Backup; use base qw(PVE::RESTHandler); @@ -36,6 +39,11 @@ __PACKAGE__->register_method ({ path => 'clamav', }); +__PACKAGE__->register_method ({ + subclass => "PMG::API2::SpamAssassin", + path => 'spamassassin', +}); + __PACKAGE__->register_method ({ subclass => "PMG::API2::Network", path => 'network', @@ -66,6 +74,11 @@ __PACKAGE__->register_method ({ path => 'tracker', }); +__PACKAGE__->register_method ({ + subclass => "PMG::API2::Backup", + path => 'backup', +}); + __PACKAGE__->register_method ({ name => 'index', path => '', @@ -91,22 +104,46 @@ __PACKAGE__->register_method ({ my $result = [ { name => 'apt' }, + { name => 'backup' }, { name => 'clamav' }, + { name => 'spamassassin' }, { name => 'postfix' }, { name => 'services' }, { name => 'syslog' }, { name => 'tasks' }, { name => 'tracker' }, { name => 'time' }, + { name => 'report' }, { name => 'status' }, { name => 'subscription' }, - { name => 'vncshell' }, + { name => 'termproxy' }, { name => 'rrddata' }, ]; return $result; }}); +__PACKAGE__->register_method({ + name => 'report', + path => 'report', + method => 'GET', + protected => 1, + proxyto => 'node', + permissions => { check => [ 'admin', 'audit' ] }, + description => "Gather various system information about a node", + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + }, + }, + returns => { + type => 'string', + }, + code => sub { + return PMG::Report::generate(); + }}); + __PACKAGE__->register_method({ name => 'rrddata', path => 'rrddata', @@ -223,12 +260,80 @@ __PACKAGE__->register_method({ return $lines; }}); +__PACKAGE__->register_method({ + name => 'journal', + path => 'journal', + method => 'GET', + description => "Read Journal", + proxyto => 'node', + permissions => { check => [ 'admin', 'audit' ] }, + protected => 1, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + since => { + type=> 'number', + description => "Display all log since this UNIX epoch.", + optional => 1, + }, + until => { + type=> 'number', + description => "Display all log until this UNIX epoch.", + optional => 1, + }, + lastentries => { + description => "Limit to the last X lines.", + type => 'integer', + optional => 1, + }, + startcursor => { + description => "Start after the given Cursor.", + type => 'string', + optional => 1, + }, + endcursor => { + description => "End before the given Cursor.", + type => 'string', + optional => 1, + }, + }, + }, + returns => { + type => 'array', + items => { + type => "string", + } + }, + code => sub { + my ($param) = @_; + + my $lines = []; + + my $parser = sub { + push @$lines, shift; + }; + + my $cmd = ["/usr/bin/mini-journalreader"]; + push @$cmd, '-n', $param->{lastentries} if $param->{lastentries}; + push @$cmd, '-b', $param->{since} if $param->{since}; + push @$cmd, '-e', $param->{until} if $param->{until}; + push @$cmd, '-f', $param->{startcursor} if $param->{startcursor}; + push @$cmd, '-t', $param->{endcursor} if $param->{endcursor}; + + PVE::Tools::run_command($cmd, outfunc => $parser); + + return $lines; + }}); + + __PACKAGE__->register_method ({ - name => 'vncshell', - path => 'vncshell', + name => 'termproxy', + path => 'termproxy', method => 'POST', + permissions => { check => [ 'admin' ] }, protected => 1, - description => "Creates a VNC Shell proxy.", + description => "Creates a Terminal proxy.", parameters => { additionalProperties => 0, properties => { @@ -239,12 +344,6 @@ __PACKAGE__->register_method ({ optional => 1, default => 0, }, - websocket => { - optional => 1, - type => 'boolean', - description => "use websocket instead of standard vnc.", - default => 1, - }, }, }, returns => { @@ -262,13 +361,9 @@ __PACKAGE__->register_method ({ my $node = $param->{node}; if ($node ne PVE::INotify::nodename()) { - die "vncproxy to remote node not implemented"; + die "termproxy 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; - my $authpath = "/nodes/$node"; my $restenv = PMG::RESTEnvironment->get(); @@ -295,37 +390,23 @@ __PACKAGE__->register_method ({ $shcmd = [ '/bin/login' ]; } - my $cmd = ['/usr/bin/vncterm', '-rfbport', $port, - '-timeout', 10, '-notls', '-listen', 'localhost', - '-c', @$shcmd]; + my $cmd = ['/usr/bin/termproxy', $port, '--path', $authpath, + '--', @$shcmd]; my $realcmd = sub { my $upid = shift; - syslog ('info', "starting vnc proxy $upid\n"); + syslog ('info', "starting termproxy $upid\n"); my $cmdstr = join (' ', @$cmd); syslog ('info', "launch command: $cmdstr"); - eval { - foreach my $k (keys %ENV) { - next if $k eq 'PATH' || $k eq 'TERM' || $k eq 'USER' || $k eq 'HOME'; - delete $ENV{$k}; - } - $ENV{PWD} = '/'; - - $ENV{PVE_VNC_TICKET} = $ticket; # pass ticket to vncterm - - PVE::Tools::run_command($cmd, errmsg => "vncterm failed"); - }; - if (my $err = $@) { - syslog('err', $err); - } + PVE::Tools::run_command($cmd); return; }; - my $upid = $restenv->fork_worker('vncshell', "", $user, $realcmd); + my $upid = $restenv->fork_worker('termproxy', "", $user, $realcmd); PVE::Tools::wait_for_vnc_port($port); @@ -341,6 +422,7 @@ __PACKAGE__->register_method({ name => 'vncwebsocket', path => 'vncwebsocket', method => 'GET', + permissions => { check => [ 'admin' ] }, description => "Opens a weksocket for VNC traffic.", parameters => { additionalProperties => 0, @@ -386,6 +468,7 @@ __PACKAGE__->register_method({ method => 'GET', description => "Read DNS settings.", proxyto => 'node', + permissions => { check => [ 'admin', 'audit' ] }, parameters => { additionalProperties => 0, properties => { @@ -474,6 +557,7 @@ __PACKAGE__->register_method({ method => 'GET', description => "Read server time and time zone settings.", proxyto => 'node', + permissions => { check => [ 'admin', 'audit' ] }, parameters => { additionalProperties => 0, properties => { @@ -546,6 +630,7 @@ __PACKAGE__->register_method({ method => 'GET', description => "Read server status. This is used by the cluster manager to test the node health.", proxyto => 'node', + permissions => { check => [ 'admin', 'qmanager', 'audit' ] }, protected => 1, parameters => { additionalProperties => 0, @@ -629,7 +714,7 @@ __PACKAGE__->register_method({ total => $dinfo->{blocks}, avail => $dinfo->{bavail}, used => $dinfo->{used}, - free => $dinfo->{bavail} - $dinfo->{used}, + free => $dinfo->{blocks} - $dinfo->{used}, }; if (my $subinfo = PVE::INotify::read_file('subscription')) { @@ -641,6 +726,37 @@ __PACKAGE__->register_method({ return $res; }}); +__PACKAGE__->register_method({ + name => 'node_cmd', + path => 'status', + method => 'POST', + permissions => { check => [ 'admin' ] }, + protected => 1, + description => "Reboot or shutdown a node.", + proxyto => 'node', + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + command => { + description => "Specify the command.", + type => 'string', + enum => [qw(reboot shutdown)], + }, + }, + }, + returns => { type => "null" }, + code => sub { + my ($param) = @_; + + if ($param->{command} eq 'reboot') { + system ("(sleep 2;/sbin/reboot)&"); + } elsif ($param->{command} eq 'shutdown') { + system ("(sleep 2;/sbin/poweroff)&"); + } + + return undef; + }}); package PMG::API2::Nodes;