My solution use PHP with a class for easy setup

Overview

Proxmox <-> PHP <-> API[username+password]

Request to proxmox api with username and password. No need for api token.

Directories and files

.
├── class
│   └── Proxmox.php
└── index.php

.index.php


include_once('./class/Proxmox.php');

$proxmox = new Proxmox;
$proxmox->setPM_IP($_GET['PM_IP']);
$proxmox->setPM_PORT($_GET['PM_PORT']);
$proxmox->setPM_USER($_GET['PM_USER']);
$proxmox->setPM_PASS($_GET['PM_PASS']);
$proxmox->PM_URL = $_GET['PM_URL'];

// login => request => logout
$proxmox->login();
echo ($proxmox->reqPrxmox());

.class/Proxmox.php

PM_IP:$this->PM_PORT/api2/json/"; return $this->PM_ADDRESS; } public function getPM_FIELDS() { return "username=$this->PM_USER&password=$this->PM_PASS"; } public function login() { global $proxmox; $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $proxmox->getPM_ADDRESS() . "access/ticket", CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ["Content-Type: application/x-www-form-urlencoded"], CURLOPT_SSL_VERIFYPEER => false, CURLOPT_POSTFIELDS => $proxmox->getPM_FIELDS(), ]); $res = curl_exec($ch); curl_close($ch); $proxmox->token = json_decode($res)->data->CSRFPreventionToken; $proxmox->cookie = json_decode($res)->data->ticket; } public function reqPrxmox() { global $proxmox; $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $proxmox->getPM_ADDRESS() . $proxmox->PM_URL, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ["CSRFPreventionToken=$this->token"], CURLOPT_SSL_VERIFYPEER => false, CURLOPT_COOKIE => "PVEAuthCookie=$this->cookie" ]); $res = curl_exec($ch); curl_close($ch); return $res; } }">

class Proxmox
{
    private $PM_IP;
    private $PM_PORT;
    private $PM_USER;
    private $PM_PASS;
    public $PM_URL;
    public $token;
    public $cookie;

    public function  setPM_IP($v)
    {
        $this->PM_IP = $v;
        return $this;
    }

    public function  setPM_PORT($v)
    {
        $this->PM_PORT = $v;
        return $this;
    }

    public function  setPM_USER($v)
    {
        $this->PM_USER = $v;
        return $this;
    }

    public function  setPM_PASS($v)
    {
        $this->PM_PASS = $v;
        return $this;
    }

    public function  getPM_ADDRESS()
    {
        $this->PM_ADDRESS = "https://$this->PM_IP:$this->PM_PORT/api2/json/";
        return $this->PM_ADDRESS;
    }

    public function getPM_FIELDS()
    {
        return "username=$this->PM_USER&password=$this->PM_PASS";
    }

    public function login()
    {
        global $proxmox;
        $ch = curl_init();
        curl_setopt_array($ch, [
            CURLOPT_URL => $proxmox->getPM_ADDRESS() . "access/ticket",
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HTTPHEADER => ["Content-Type: application/x-www-form-urlencoded"],
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_POSTFIELDS => $proxmox->getPM_FIELDS(),
        ]);
        $res = curl_exec($ch);
        curl_close($ch);
        $proxmox->token = json_decode($res)->data->CSRFPreventionToken;
        $proxmox->cookie = json_decode($res)->data->ticket;
    }

    public function reqPrxmox()
    {
        global $proxmox;
        $ch = curl_init();
        curl_setopt_array($ch, [
            CURLOPT_URL => $proxmox->getPM_ADDRESS() . $proxmox->PM_URL,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HTTPHEADER => ["CSRFPreventionToken=$this->token"],
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_COOKIE => "PVEAuthCookie=$this->cookie"
        ]);
        $res = curl_exec($ch);
        curl_close($ch);
        return $res;
    }
}

How to use?

Access your web server and install git

apt install git

Access the directory "/var/www/"

cd /var/www/

Clone this project into the 'proxmox' folder

git clone https://github.com/Full-Monitoring/proxmox-class-api-login-pass.git proxmox
# open proxmox
cd proxmox/
# list files
ls -la

Request example using get method

To get the version

http://127.0.0.1/proxmox?PM_URL=version&PM_IP=172.33.255.2&PM_PORT=8006&PM_USER=roo@pam&PM_PASS=12345678

To get cluster

http://127.0.0.1/proxmox?PM_URL=cluster&PM_IP=172.33.255.2&PM_PORT=8006&PM_USER=roo@pam&PM_PASS=12345678

To get cluster/resources

http://127.0.0.1/proxmox?PM_URL=cluster/resources&PM_IP=172.33.255.2&PM_PORT=8006&PM_USER=roo@pam&PM_PASS=12345678
You might also like...
Simple IT Documentation Solution for MSPs

SimpleMSPDoc RC 1.0 I wasn't happy with what other IT documention software had. I felt they over complicated things and required so much clicky clicky

Ultimate solution to your KopoKopo needs

ultimate-kopokopo Smith Ultimate Kopokopo PHP SDK This is a module to assist php developers in consuming Kopokopo's API Installation You can install t

X1 - A very simple web based note solution that's designed to serve as my second brain.
X1 - A very simple web based note solution that's designed to serve as my second brain.

X1 A very simple web based note solution that's designed to serve as my second brain. Starting Server To start the tool simply clone the repo and then

Magento 2 Blog Extension - FREE, fully featured, powerful Blog solution for your online store!

Blog MX | Magento 2 Blog Module by Mirasvit FREE, fully featured, powerful Blog solution for your online store! Magento 2 Blog MX allows you to open a

FalconOne Lite is an Open Source solution deployed and updated on a daily basis to help prevent terror and crime globally
FalconOne Lite is an Open Source solution deployed and updated on a daily basis to help prevent terror and crime globally

FalconOne Lite is an Open Source solution deployed and updated on a daily basis to help prevent terror and crime globally. By using advanced tools, functions and stealth strategies, FalconOne community is focused on making a friendly and fast solution for effective results.

Proxy based Redis cluster solution supporting pipeline and scaling dynamically
Proxy based Redis cluster solution supporting pipeline and scaling dynamically

Codis is a proxy based high performance Redis cluster solution written in Go. It is production-ready and widely used at wandoujia.com and many compani

An article about alternative solution for convert object into a JSON Object for your api.

Do we really need a serializer for our JSON API? The last years I did build a lot of JSON APIs but personally was never happy about the magic of using

Mailing Microservice - My solution for Moroccan PHPers's February 2022 Challenge
Mailing Microservice - My solution for Moroccan PHPers's February 2022 Challenge

Mailing Microservice Solution for Moroccan PHPers's February 2022 Challenge by Rabyâ Raghib ([email protected]). It mainly consists of: a php app th

Magento 2 extension. Solution for set Url of Category without Parent path.

Magento 2 extension. Solution for set Url of Category without Parent path.

Owner
Full Monitoring
Full Monitoring
Easy XHProf setup to profile your laravel application!

Introduction Laravel XHProf provides you with a simple setup to profile your laravel application with the well known XHProf php extension originally d

Zacharias Creutznacher 122 Dec 23, 2022
Exploiting and fixing security vulnerabilities of an old version of E-Class. Project implemented as part of the class YS13 Cyber-Security.

Open eClass 2.3 Development of XSS, CSRF, SQLi, RFI attacks/defences of an older,vulnerable version of eclass. Project implemented as part of the clas

Aristi_Papastavrou 11 Apr 23, 2022
Setup Docker Para Projetos Laravel 9 com PHP 8

Setup Docker Para Projetos Laravel 9 com PHP 8

EspecializaTi 56 Dec 6, 2022
Run the following commands in your terminal to setup the project

Run the following commands in your terminal to setup the project You must have the LAMP installed on your system git clone https://github.com/Bashar-A

null 1 Nov 6, 2021
This is a setup for a Tor based shared web hosting server

General Information: This is a setup for a Tor based shared hosting server. It is provided as is and before putting it into production you should make

Daniel Winzen 312 Dec 24, 2022
Production ready scalable Magento setup utilizing the docker

Magento docker image Requirements This docker image expects 2 other linked containers to work . Mysqldb or Mariadb linked as 'db' Memcached linked as

Paim pozhil 49 Jun 21, 2021
composer plugin for a better frontend setup

node-composer composer plugin for a better frontend setup PHP projects mostly are Web-Applications. Many Web-Applications also need a frontend part wh

Marius Büscher 5 Jul 26, 2022
A class for easy connection to the zarinpal port

Payment class with ZarinPal A class to simplify payment operations and confirm payment of ZarrinPal payment gateway service ( به فارسی بخوانید ) Insta

Mohammad Qasemi 7 Jul 15, 2022
S11 Selection est une solution web PHP faite pour automatiser la création d'une grille d'évaluation d'un étudiant puis de les rassembler pour en faire un classement.

[S11] SELECTION BTS 0.1.0 FR Description S11 Selection est une solution web PHP faite pour automatiser la création d'une grille d'évaluation d'un étud

NOIZET Maxence 1 Oct 25, 2022
meterN is a lightweight set of PHP/JS files that make a " Home energy metering & monitoring " solution.

meterN - Home energy monitor - (PHP/JS Energy Metering & Monitoring) What can meterN do for you ? meterN is a lightweight set of PHP/JS files that mak

Jean-Marc Louviaux 4 Nov 30, 2022