]>
git.proxmox.com Git - pmg-api.git/blob - PMG/API2/Nodes.pm
41d6f2dadf25e8a93c7eedf9ab40afd8f20416b6
1 package PMG
::API2
::NodeInfo
;
6 use Time
::Local
qw(timegm_nocheck);
10 use PVE
::JSONSchema
qw(get_standard_option);
11 use PVE
::RESTEnvironment
;
16 use PMG
::API2
::Services
;
17 use PMG
::API2
::Network
;
18 use PMG
::API2
::ClamAV
;
20 use base
qw(PVE::RESTHandler);
22 __PACKAGE__-
>register_method ({
23 subclass
=> "PMG::API2::ClamAV",
27 __PACKAGE__-
>register_method ({
28 subclass
=> "PMG::API2::Network",
32 __PACKAGE__-
>register_method ({
33 subclass
=> "PMG::API2::Tasks",
37 __PACKAGE__-
>register_method ({
38 subclass
=> "PMG::API2::Services",
42 __PACKAGE__-
>register_method ({
46 permissions
=> { user
=> 'all' },
47 description
=> "Node index.",
49 additionalProperties
=> 0,
51 node
=> get_standard_option
('pve-node'),
60 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
67 { name
=> 'services' },
71 { name
=> 'vncshell' },
77 __PACKAGE__-
>register_method({
81 description
=> "Read system log",
85 additionalProperties
=> 0,
87 node
=> get_standard_option
('pve-node'),
100 pattern
=> '^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$',
101 description
=> "Display all log since this date-time string.",
106 pattern
=> '^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$',
107 description
=> "Display all log until this date-time string.",
118 description
=> "Line number",
122 description
=> "Line text",
131 my $restenv = PVE
::RESTEnvironment
::get
();
133 my ($count, $lines) = PVE
::Tools
::dump_journal
($param->{start
}, $param->{limit
},
134 $param->{since
}, $param->{'until'});
136 $restenv->set_result_attrib('total', $count);
141 __PACKAGE__-
>register_method ({
146 description
=> "Creates a VNC Shell proxy.",
148 additionalProperties
=> 0,
150 node
=> get_standard_option
('pve-node'),
154 description
=> "use websocket instead of standard vnc.",
160 additionalProperties
=> 0,
162 user
=> { type
=> 'string' },
163 ticket
=> { type
=> 'string' },
164 port
=> { type
=> 'integer' },
165 upid
=> { type
=> 'string' },
171 my $node = $param->{node
};
173 # we only implement the websocket based VNC here
174 my $websocket = $param->{websocket
} // 1;
175 die "standard VNC not implemented" if !$websocket;
177 my $authpath = "/nodes/$node";
179 my $restenv = PVE
::RESTEnvironment-
>get();
180 my $user = $restenv->get_user();
182 my $ticket = PMG
::Ticket
::assemble_vnc_ticket
($user, $authpath);
184 my $family = PVE
::Tools
::get_host_address_family
($node);
185 my $port = PVE
::Tools
::next_vnc_port
($family);
189 if ($user eq 'root@pam') {
190 $shcmd = [ '/bin/login', '-f', 'root' ];
192 $shcmd = [ '/bin/login' ];
195 my $cmd = ['/usr/bin/vncterm', '-rfbport', $port,
196 '-timeout', 10, '-notls', '-listen', 'localhost',
202 syslog
('info', "starting vnc proxy $upid\n");
204 my $cmdstr = join (' ', @$cmd);
205 syslog
('info', "launch command: $cmdstr");
208 foreach my $k (keys %ENV) {
209 next if $k eq 'PATH' || $k eq 'TERM' || $k eq 'USER' || $k eq 'HOME';
214 $ENV{PVE_VNC_TICKET
} = $ticket; # pass ticket to vncterm
216 PVE
::Tools
::run_command
($cmd, errmsg
=> "vncterm failed");
225 my $upid = $restenv->fork_worker('vncshell', "", $user, $realcmd);
227 PVE
::Tools
::wait_for_vnc_port
($port);
237 __PACKAGE__-
>register_method({
238 name
=> 'vncwebsocket',
239 path
=> 'vncwebsocket',
241 description
=> "Opens a weksocket for VNC traffic.",
243 additionalProperties
=> 0,
245 node
=> get_standard_option
('pve-node'),
247 description
=> "Ticket from previous call to vncproxy.",
252 description
=> "Port number returned by previous vncproxy call.",
262 port
=> { type
=> 'string' },
268 my $authpath = "/nodes/$param->{node}";
270 my $restenv = PVE
::RESTEnvironment-
>get();
271 my $user = $restenv->get_user();
273 PMG
::Ticket
::verify_vnc_ticket
($param->{vncticket
}, $user, $authpath);
275 my $port = $param->{port
};
277 return { port
=> $port };
280 __PACKAGE__-
>register_method({
284 description
=> "Read DNS settings.",
287 additionalProperties
=> 0,
289 node
=> get_standard_option
('pve-node'),
294 additionalProperties
=> 0,
297 description
=> "Search domain for host-name lookup.",
302 description
=> 'First name server IP address.',
307 description
=> 'Second name server IP address.',
312 description
=> 'Third name server IP address.',
321 my $res = PVE
::INotify
::read_file
('resolvconf');
326 __PACKAGE__-
>register_method({
327 name
=> 'update_dns',
330 description
=> "Write DNS settings.",
334 additionalProperties
=> 0,
336 node
=> get_standard_option
('pve-node'),
338 description
=> "Search domain for host-name lookup.",
342 description
=> 'First name server IP address.',
343 type
=> 'string', format
=> 'ip',
347 description
=> 'Second name server IP address.',
348 type
=> 'string', format
=> 'ip',
352 description
=> 'Third name server IP address.',
353 type
=> 'string', format
=> 'ip',
358 returns
=> { type
=> "null" },
362 PVE
::INotify
::update_file
('resolvconf', $param);
368 __PACKAGE__-
>register_method({
372 description
=> "Read server time and time zone settings.",
375 additionalProperties
=> 0,
377 node
=> get_standard_option
('pve-node'),
382 additionalProperties
=> 0,
385 description
=> "Time zone",
389 description
=> "Seconds since 1970-01-01 00:00:00 UTC.",
391 minimum
=> 1297163644,
394 description
=> "Seconds since 1970-01-01 00:00:00 (local time)",
396 minimum
=> 1297163644,
404 my $ltime = timegm_nocheck
(localtime($ctime));
406 timezone
=> PVE
::INotify
::read_file
('timezone'),
414 __PACKAGE__-
>register_method({
415 name
=> 'set_timezone',
418 description
=> "Set time zone.",
422 additionalProperties
=> 0,
424 node
=> get_standard_option
('pve-node'),
426 description
=> "Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names.",
431 returns
=> { type
=> "null" },
435 PVE
::INotify
::write_file
('timezone', $param->{timezone
});
441 package PMG
::API2
::Nodes
;
446 use PVE
::RESTHandler
;
447 use PVE
::JSONSchema
qw(get_standard_option);
449 use base
qw(PVE::RESTHandler);
451 __PACKAGE__-
>register_method ({
452 subclass
=> "PMG::API2::NodeInfo",
456 __PACKAGE__-
>register_method ({
460 permissions
=> { user
=> 'all' },
461 description
=> "Cluster node index.",
463 additionalProperties
=> 0,
472 links
=> [ { rel
=> 'child', href
=> "{node}" } ],
477 my $nodename = PVE
::INotify
::nodename
();
479 { node
=> $nodename },