API lib php

From Mint Panel

Jump to: navigation, search

[edit] Overview

[edit] Example

<?php

header ("X-Powered-By: Mint Panel");

//error_reporting(E_ALL);
error_reporting (E_ALL ^ E_WARNING ^ E_NOTICE); 
ini_set('display_errors', '1');

$class = "mpapi.php";

// check for our API class
if(file_exists($class)) {
	require("mpapi.php");
} else {
	die("Could not locate the file: ".$class." please ensure it came bundled.");
}

// variables

$url = "http://127.0.0.1:5225/api"; // your control panel URL.

$username = "admin@mintpanel.com"; // your administrative username
$password = "admin"; // your administrative password
$api_key = "key"; // your api key
$debug = false;

// start API class

$api = new MPAPI();

// set the header to send/revice XML

$api->set_header("text/xml");

// connect and login
$api->connect($url);
$api->login($username, $password);

$xml = '<?xml version="1.0" encoding="iso-8859-1"?><packet><servers><get></get></servers></packet>';

$packet = array('key' => $api_key, 'xml' => $xml, 'debug' => $debug);

// post to the server and return our responce.
$data = $api->post($packet);

echo($data);

// close our connection
$api->close();
?>

[edit] MPAPI Class

<?php
class MPAPI {
	
	function set_header($header="text/html") {
		curl_setopt($this->curl, CURLOPT_HTTPHEADER, 'Content-Type: '.$header); 
	}
	
	function connect($url) {		
		if($url == "") {
			return "A URL is required to post to.";
		}
		// initialize the curl engine 
		$this->curl = curl_init(); 
		// set the curl options: 
		// do not check the name of SSL certificate of the remote server 
		curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 0); 
		// do not check up the remote server certificate 
		curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); 
		// pass in the url of the target server 
		curl_setopt($this->curl, CURLOPT_URL, $url);
	}
	
	function login($user, $password) {
		if($user == "") {
			return "A username is required to authenticated.";
		}
		if($password == "") {
			return "A password is required to authenticate";
		}
		curl_setopt($this->curl, CURLOPT_USERPWD, "$user:$password");
	}
	
	function post($packet) {
		if(empty($packet)) {
			return "An array is required";
		}
		// tell CURL to return the result rather than to load it to the browser 
		curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); 
		// pass in the packet to deliver 
		curl_setopt($this->curl, CURLOPT_POSTFIELDS, $packet); 
		// perform the CURL request and return the result 
		return curl_exec($this->curl); 
	}
	
	function close() {
		curl_close($this->curl); 
	}
	
}
?>
HELP