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);
path => 'clamav',
});
+__PACKAGE__->register_method ({
+ subclass => "PMG::API2::SpamAssassin",
+ path => 'spamassassin',
+});
+
__PACKAGE__->register_method ({
subclass => "PMG::API2::Network",
path => 'network',
path => 'tracker',
});
+__PACKAGE__->register_method ({
+ subclass => "PMG::API2::Backup",
+ path => 'backup',
+});
+
__PACKAGE__->register_method ({
name => 'index',
path => '',
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',
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 => {
optional => 1,
default => 0,
},
- websocket => {
- optional => 1,
- type => 'boolean',
- description => "use websocket instead of standard vnc.",
- default => 1,
- },
},
},
returns => {
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();
$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);
name => 'vncwebsocket',
path => 'vncwebsocket',
method => 'GET',
+ permissions => { check => [ 'admin' ] },
description => "Opens a weksocket for VNC traffic.",
parameters => {
additionalProperties => 0,
method => 'GET',
description => "Read DNS settings.",
proxyto => 'node',
+ permissions => { check => [ 'admin', 'audit' ] },
parameters => {
additionalProperties => 0,
properties => {
method => 'GET',
description => "Read server time and time zone settings.",
proxyto => 'node',
+ permissions => { check => [ 'admin', 'audit' ] },
parameters => {
additionalProperties => 0,
properties => {
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,
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')) {
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;