zack commited on
Commit
bf114ee
1 Parent(s): d2418cd

🔧 Update Proxmox VM functions

Browse files
frontend/src/components/Proxmox/vm_functions.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require 'vendor/autoload.php';
3
+
4
+ use ProxmoxVE\Proxmox;
5
+ use GuzzleHttp\Client;
6
+
7
+ function PreviewVnc($vmID, $nodeid) {
8
+ // pass in the vmid and nodeid from the functions above
9
+ $node = $nodeid;
10
+ $vmid = $vmID;
11
+
12
+ // set up the proxmox creds and login
13
+ $credentials = [
14
+ 'hostname' => 'proxmox-domain', // Also can be an IP
15
+ 'username' => 'api',
16
+ 'password' => 'password',
17
+ ];
18
+
19
+ $host = $credentials['hostname'];
20
+
21
+ $proxmox = new Proxmox($credentials);
22
+
23
+ if ($login = $proxmox->login()) {
24
+
25
+ $ticket = $login->getTicket();
26
+
27
+ $config = $proxmox->create("/nodes/$node/qemu/$vmid/vncproxy", [
28
+ 'websocket' => 1, // Start websocket proxy
29
+ ]);
30
+
31
+
32
+ $websock = $proxmox->get("/nodes/$node/qemu/$vmid/vncwebsocket", [
33
+
34
+ 'vncticket' => $config['data']['ticket'],
35
+ 'port' => $config['data']['port']
36
+ ]);
37
+
38
+
39
+
40
+ $src_href = 'https://'.$host.':8006/?console=kvm&novnc=1&node='.$node.'&resize=1&vmid='.$vmid.'&path=api2/json/nodes/'.$node.'/qemu/'.$vmid.'/vncwebsocket/port/'.$config['data']['port'].'"/vncticket/"'.$ticket;
41
+ echo '<iframe src="'.$src_href.'" frameborder="0" scrolling="no" width="100%" height="100%"></iframe>';
42
+ }
43
+ }
44
+
45
+ ?>