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

error 401: no ticket #41

Closed
mm580486 opened this issue Nov 17, 2020 · 3 comments
Closed

error 401: no ticket #41

mm580486 opened this issue Nov 17, 2020 · 3 comments

Comments

@mm580486
Copy link

Hi

i have proble with ticket and cookie system


<?php

/*
For the first you need:
1. Create User group "VNC" –> Datacenter / Permissions / Group
2. Create new user -> Datacenter / Permissions / Users - select Group: "VNC", Realm: pve
3. Create new Role -> Datacenter / Permissions / Roles - select Name: "VNC", Privilegies: VM.Console (only)
3. Add permision to access VM -> Datacenter / Node / VM / Permissions / Add Group Permissions - select Group: "VNC", Role: "VNC"
*/

require_once 'vendor/autoload.php';
use ProxmoxVE\Proxmox;



$host = 'X.x.x.x';
$node = 'node';
$vmid = '102';

$credentials = [
    'hostname'  => $host,
    'username'  => 'root',
    'password'  => 'XXXX'
];

$proxmox = new Proxmox($credentials);

if($login = $proxmox->login()) {
    // Get and save ticket
    $ticket = $login->getTicket();
    $config = $proxmox->create('/nodes/'.$node.'/qemu/'.$vmid.'/vncproxy', [
        'websocket' => 1 // Start websocket
    ]);
    $websock = $proxmox->get('/nodes/'.$node.'/qemu/'.$vmid.'/vncwebsocket', [
        'vncticket' => $ticket,
        'port'      => $config['data']['port'],

    ]);
    // Set Cookies (domain must be in same space that pve. Example: pve – pve1.your.com, host – auth.your.com, Set cookies to your.com)
    setcookie('PVEAuthCookie', $ticket , 0, '/', 'localhost:4000', false);

    $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;
    echo '<iframe src="'.$src_href.'" frameborder="0" scrolling="no" width="800px" height="600px"></iframe>';
}

?>

i got 401 error i think this happend because i used spicial port 4000 but i dont know how fix it

@zzantares
Copy link
Owner

This isn't likely a problem with the library itself, 401 means your credentials are invalid. If this is regarding VNC setup see this.

@mm580486
Copy link
Author

my credentials arn't invalid because i used this credit on another request like nodes request and works fine also when i change credit to wrong detail proxmox return credit error


<?php

// Require the autoloader
require_once 'vendor/autoload.php';

// Use the library namespace
use ProxmoxVE\Proxmox;

// Create your credentials array
$credentials = [
    'hostname' => 'XXXXXXXX',  // Also can be an IP
    'username' => 'root',
    'password' => 'XXXXXXX',
];

// realm and port defaults to 'pam' and '8006' but you can specify them like so
// $credentials = [
//     'hostname' => 'proxmox.server.com',
//     'username' => 'root',
//     'password' => 'secret',
//     'realm' => 'pve',
//     'port' => '9009',
// ];

// Then simply pass your credentials when creating the API client object.
$proxmox = new Proxmox($credentials);

$allNodes = $proxmox->get('/nodes');

print_r($allNodes);

result when credit has wronng:

Fatal error: Uncaught exception 'ProxmoxVE\Exception\AuthenticationException' with message 'Can not login using credentials: [Host: XXXXXXX:8006], [Username: vnc@pve].' in /var/www/html/vendor/zzantares/proxmoxve/src/Proxmox.php:208 Stack trace: #0 /var/www/html/vendor/zzantares/proxmoxve/src/Proxmox.php(246): ProxmoxVE\Proxmox->login() #1 /var/www/html/vendor/zzantares/proxmoxve/src/Proxmox.php(87): ProxmoxVE\Proxmox->setCredentials(Array) #2 /var/www/html/vnc.php(25): ProxmoxVE\Proxmox->__construct(Array) #3 {main} thrown in /var/www/html/vendor/zzantares/proxmoxve/src/Proxmox.php on line 208

@mm580486
Copy link
Author

i used latest proxmox version , annd i just copied your code and i tested this code with root permissions and vnc but failed and return 401 no ticket , can someone help me to fix this issue

thanks
@dagababaev @zzantares

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants