/* * This file is part of XenAPI <http://www.xenapi.net/>. * * XenAPI is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * XenAPI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ header('Content-type: text/plain'); require_once 'xen_api.php'; $xenAPI = new XenAPI('http://xenapi.net/api.php', 'REPLACE_THIS_WITH_AN_API_KEY'); try { $response = $xenAPI->login('Contex', 'Password', '127.0.0.1'); var_dump($response); } catch (Exception $e) { if ($e->getCode() == 400) { $error = json_decode($e->getMessage(), TRUE); die('API call failed: API ERROR CODE=' . $error['error'] . ' & API ERROR MESSAGE=' . $error['message']); } else { die('API call failed: HTTP RESPONSE=' . $e->getMessage() . ' & HTTP STATUS CODE=' . $e->getCode()); } }
<?php header('Content-type: application/json'); require_once 'includes/xen_api.php'; include 'includes/database.php'; include 'includes/config.php'; $params = $_POST; $xenAPI = new XenAPI($apiUrl, $apiKey); try { $response = $xenAPI->authenticate($params['l'], $params['p']); die(json_encode(array('hash' => $response['hash']), 128)); } catch (Exception $e) { if ($e->getCode() == 400) { $error = json_decode($e->getMessage(), TRUE); $err = $error['error']; $errMsg = 'API call failed: API ERROR CODE=' . $error['error'] . ' & API ERROR MESSAGE=' . $error['message']; } else { $err = $e->getCode(); $errMsg = 'API call failed: HTTP RESPONSE=' . $e->getMessage() . ' & HTTP STATUS CODE=' . $e->getCode(); } } die(json_encode(array('error' => $err, 'errorMsg' => $errMsg), 128));