Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noVNC HTML5 #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/proxmox_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct($user, $password, $host, $port = 8006)

$this->login();
}

public function login()
{
$res = $this->submit('access/ticket', [
Expand Down
3 changes: 3 additions & 0 deletions proxmox.php
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,8 @@ public function tabClientConsole($package, $service, array $get = null, array $p
*/
private function consoleTab($package, $service, $client = false)
{
// Get the service fields
$service_fields = $this->serviceFieldsToObject($service->fields);
$template = ($client ? 'tab_client_console' : 'tab_console');
$this->view = new View($template, 'default');
// Load the helpers required for this view
Expand Down Expand Up @@ -1924,6 +1926,7 @@ private function consoleTab($package, $service, $client = false)
$this->view->set('console', (object)$session);

$this->view->setDefaultView('components' . DS . 'modules' . DS . 'proxmox' . DS);
$this->view->set('service_fields', $this->serviceFieldsToObject($service->fields));
return $this->view;
}

Expand Down
67 changes: 45 additions & 22 deletions views/default/tab_client_console.pdt
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@

<h4><?php $this->_('Proxmox.tab_client_console.heading_console');?></h4>
<div class="table-responsive">
<table class="table table-striped">
<tbody>
<tr>
<td><strong><?php $this->_('Proxmox.tab_client_console.vnc_ip');?></strong></td>
<td><?php echo (isset($console->vnc_ip) ? $this->Html->safe($console->vnc_ip) : null);?></td>
</tr>
<tr>
<td><strong><?php $this->_('Proxmox.tab_client_console.vnc_port');?></strong></td>
<td><?php echo (isset($console->vnc_port) ? $this->Html->safe($console->vnc_port) : null);?></td>
</tr>
<tr>
<td><strong><?php $this->_('Proxmox.tab_client_console.vnc_user');?></strong></td>
<td><?php echo (isset($console->vnc_user) ? $this->Html->safe($console->vnc_user) : null);?></td>
</tr>
<tr>
<td><strong><?php $this->_('Proxmox.tab_client_console.vnc_password');?></strong></td>
<td><?php echo (isset($console->vnc_password) ? $this->Html->safe($console->vnc_password) : null);?></td>
</tr>
</tbody>
</table>
</div>
<?php
$ticketUrl = 'https://'.$console->vnc_ip.'/api2/json/access/ticket';

$postData = array(
'username' => $service_fields->proxmox_username.'@pve',
'password' => $service_fields->password,
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ticketUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

$ticketData = json_decode($response, true);

function getMainDomain($subdomain) {
$urlParts = parse_url($subdomain);

// Memeriksa apakah parse_url berhasil dan mengandung bagian host
if ($urlParts && isset($urlParts['host'])) {
$hostParts = explode('.', $urlParts['host']);

// Memeriksa apakah ada setidaknya dua bagian pada domain (misal: example.com)
if (count($hostParts) >= 2) {
// Mengambil dua bagian terakhir untuk mendapatkan domain utama
$mainDomain = $hostParts[count($hostParts) - 2] . '.' . $hostParts[count($hostParts) - 1];
return $mainDomain;
}
}

return null; // Mengembalikan null jika tidak dapat menemukan domain utama
}
setcookie("PVEAuthCookie",$ticketData['data']['ticket'], 0, "/", '.'.getMainDomain('https://'.$_SERVER['HTTP_HOST']) );

if($service_fields->proxmox_type == 'qemu'){
$vmType = 'kvm';
}else{
$vmType = 'lxc';
}
$url_vnc = "https://".$console->vnc_ip."/?console=".$vmType."&novnc=1&node=".$service_fields->proxmox_node."&resize=1&vmid=".$service_fields->proxmox_vserver_id."&path=api2/json/nodes/".$service_fields->proxmox_node."/".$service_fields->proxmox_type."/".$service_fields->proxmox_vserver_id."/vncwebsocket/port/".$console->vnc_port."/vncticket/".$console->vnc_password;
echo '<iframe src="'.$url_vnc.'" frameborder="0" scrolling="no" width="100%" height="600px" allow="fullscreen"></iframe>';
?>
51 changes: 45 additions & 6 deletions views/default/tab_console.pdt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,51 @@
<h3><?php $this->_('Proxmox.tab_console.heading_console');?></h3>
</div>
<div class="pad">
<ul>
<li><?php $this->_('Proxmox.tab_console.vnc_ip');?> <?php echo (isset($console->vnc_ip) ? $this->Html->safe($console->vnc_ip) : null);?></li>
<li><?php $this->_('Proxmox.tab_console.vnc_port');?> <?php echo (isset($console->vnc_port) ? $this->Html->safe($console->vnc_port) : null);?></li>
<li><?php $this->_('Proxmox.tab_console.vnc_user');?> <?php echo (isset($console->vnc_user) ? $this->Html->safe($console->vnc_user) : null);?></li>
<li><?php $this->_('Proxmox.tab_console.vnc_password');?> <?php echo (isset($console->vnc_password) ? $this->Html->safe($console->vnc_password) : null);?></li>
</ul>
<?php
$ticketUrl = 'https://'.$console->vnc_ip.'/api2/json/access/ticket';

$postData = array(
'username' => $service_fields->proxmox_username.'@pve',
'password' => $service_fields->password,
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ticketUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

$ticketData = json_decode($response, true);

function getMainDomain($subdomain) {
$urlParts = parse_url($subdomain);

// Memeriksa apakah parse_url berhasil dan mengandung bagian host
if ($urlParts && isset($urlParts['host'])) {
$hostParts = explode('.', $urlParts['host']);

// Memeriksa apakah ada setidaknya dua bagian pada domain (misal: example.com)
if (count($hostParts) >= 2) {
// Mengambil dua bagian terakhir untuk mendapatkan domain utama
$mainDomain = $hostParts[count($hostParts) - 2] . '.' . $hostParts[count($hostParts) - 1];
return $mainDomain;
}
}

return null; // Mengembalikan null jika tidak dapat menemukan domain utama
}
setcookie("PVEAuthCookie",$ticketData['data']['ticket'], 0, "/", '.'.getMainDomain('https://'.$_SERVER['HTTP_HOST']) );

if($service_fields->proxmox_type == 'qemu'){
$vmType = 'kvm';
}else{
$vmType = 'lxc';
}
$url_vnc = "https://".$console->vnc_ip."/?console=".$vmType."&novnc=1&node=".$service_fields->proxmox_node."&resize=1&vmid=".$service_fields->proxmox_vserver_id."&path=api2/json/nodes/".$service_fields->proxmox_node."/".$service_fields->proxmox_type."/".$service_fields->proxmox_vserver_id."/vncwebsocket/port/".$console->vnc_port."/vncticket/".$console->vnc_password;
echo '<iframe src="'.$url_vnc.'" frameborder="0" scrolling="no" width="100%" height="800px" allow="fullscreen"></iframe>';
?>
</div>

<script type="text/javascript">
Expand Down