'POST', CURLOPT_POSTFIELDS => 'username='.$_POST['username'].'&password='.$_POST['password'], CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded') ); $r = curl_call($_SESSION['ProxmoxApiURL'].'access/ticket', $curlOptions); if(empty($r['error']) && !empty($r['response'])){ $data = @json_decode($r['response'], true); if($data !== false){ $_SESSION['ticket'] = $data['data']['ticket']; $_SESSION['token'] = $data['data']['CSRFPreventionToken']; } } } // LOGON FORM if(empty($_SESSION['ticket']) || empty($_SESSION['ProxmoxApiURL']) || isset($_GET['logon'])){ echo '
'. '
'. '
'. '
'. ''. '
'; } else { // SHOW MENU echo '

Welcome '.$_SESSION['username'].'! Logout

'. 'Pick an option: '. ''; if(!empty($_GET['call'])){ if($_GET['call'] == 'status' && !isset($_GET['node'])){ echo '
'. ''. ' '. ''. '
'; } else { $curlOptions = array( CURLOPT_HTTPHEADER => array( 'CSRFPreventionToken: '.$_SESSION['token'], 'Cookie: PVEAuthCookie='.$_SESSION['ticket'] ) ); switch($_GET['call']){ case 'version': $URL = $_SESSION['ProxmoxApiURL'].'version'; break; case 'nodes': $URL = $_SESSION['ProxmoxApiURL'].'nodes'; break; case 'status': $URL = $_SESSION['ProxmoxApiURL'].'nodes/'.$_GET['node'].'/status'; break; } $r = curl_call($URL, $curlOptions); if(empty($r['error']) && !empty($r['response'])){ $data = @json_decode($r['response'], true); if($data !== false){ echo 'API Response:
'. '
';
							print_r($data);
						echo '
'; } } else { echo $r['header']; } } } } function curl_call($url, $options = null){ $curl = curl_init(); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:75.0) Gecko/20100101 Firefox/75.0'); curl_setopt($curl, CURLOPT_NOBODY, false); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_HEADER_OUT, true); if(is_array($options)){ foreach($options AS $k=>$v){ curl_setopt($curl, $k, $v); } } $response = curl_exec($curl); $error = curl_error($curl); $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $responseBody = substr($response, $header_size); return array('error'=>$error, 'header'=>$header, 'response'=>$responseBody); } ?>