Go to the source code of this file.
|
if(preg_match("#^/api/auth/( | if [^/\?] *)[/\?]?#", $_SERVER["REQUEST_URI"], $mat)) if ( $_SERVER["REQUEST_URI"]=="/api/post")(preg_match("#^/api/rest/([^/] *)/([^/\?] *)[/\?]?#", $_SERVER["REQUEST_URI"], $mat)) |
| Main code: either we are authenticating or calling one of the APIs or asking for some documentation. More...
|
|
◆ __autoload()
__autoload |
( |
|
$class_name | ) |
|
multiple call-mode API for Alternc you can call this HTTP(s) API as follow: from the base url https://panel.example.fr/api/
- /api/post use GETted data (?token=xx&object=xx&action=yy&option1=value1&option2=value2
- /api/post use POSTED json data using the same keys
- use a sub-url (rest-style) of the form /api/rest/object/action?token=xx&option1=value1&option2=value2
- the same (REST) but options and value are POSTED
the json-object contains: ->object = the Alternc_Api_Object_<classname> to call ->action = the method to call in this class ->options = an object passed as it is while calling the method.
Authentication is done by asking for /api/auth/<method>?option1=value1&option2=value2 or POSTED data a token is returned for this session Use /api/auth to know which method you can use and what parameter they expect
- Todo:
- add HTML pages that will self-document this API
Attempts to load a class in multiple path, the PSR-0 or old style way
@staticvar array $srcPathList @staticvar boolean $init
- Parameters
-
- Returns
- boolean
Definition at line 34 of file index.php.
36 static $srcPathList = array();
46 $srcPathList[
"standard"] =
"/usr/share/php";
49 $includePathList = explode(PATH_SEPARATOR, get_include_path());
51 foreach ($srcPathList as $path) {
52 if (!in_array($path, $includePathList)) {
53 $includePathList[] = $path;
57 $finalIncludePathList = array_reverse($includePathList);
60 set_include_path(implode(PATH_SEPARATOR, $finalIncludePathList));
64 if (preg_match(
"/_/", $class_name)) {
65 $file_name = str_replace(
'_', DIRECTORY_SEPARATOR, $class_name) .
'.php';
68 }
else if (preg_match(
"/\\/", $class_name)) {
69 $file_name = str_replace(
'\\', DIRECTORY_SEPARATOR, ltrim($class_name,
'\\')) .
'.php';
73 $file_name = $class_name .
'.php';
77 foreach ($srcPathList as $namespace => $path) {
78 $file_path = $path . DIRECTORY_SEPARATOR . $file_name;
79 if (is_file($file_path) && is_readable($file_path)) {
◆ apiauth()
Definition at line 115 of file index.php.
117 $options[
"databaseAdapter"] =
$dbh;
121 $response = $service->auth($data);
122 header(
"Content-Type: application/json");
123 echo $response->toJson();
125 }
catch (Exception $e) {
128 header(
"Content-Type: application/json");
130 echo $response->toJson();
141 if (preg_match(
"#^/api/auth/([^/\?]*)[/\?]?#", $_SERVER[
"REQUEST_URI"], $mat)) {
142 if ($_SERVER[
"REQUEST_METHOD"] ==
"POST") {
143 $data = array(
"options" => $_POST,
144 "method" => $mat[1]);
148 $data = array(
"options" => $_GET,
149 "method" => $mat[1]);
156 if ($_SERVER[
"REQUEST_URI"] ==
"/api/post") {
158 if ($_SERVER[
"REQUEST_METHOD"] ==
"POST") {
159 $data = array(
"options" => $_POST,
160 "object" => $_POST[
"object"],
161 "action" => $_POST[
"action"],
163 $token = $_POST[
"token"];
167 $data = array(
"options" => $_GET,
168 "object" => $_GET[
"object"],
169 "action" => $_GET[
"action"],
171 $token = $_GET[
"token"];
176 if (preg_match(
"#^/api/rest/([^/]*)/([^/\?]*)[/\?]?#", $_SERVER[
"REQUEST_URI"], $mat)) {
177 if ($_SERVER[
"REQUEST_METHOD"] ==
"POST") {
178 $data = array(
"options" => $_POST,
182 $token = $_POST[
"token"];
186 $data = array(
"options" => $_GET,
190 $token = $_GET[
"token"];
Standard Response object for the AlternC API.
Service API used by server to export API methods this class can be used to implement an API service /...
References $dbh, and exit.
◆ apicall()
apicall |
( |
|
$data, |
|
|
|
$token |
|
) |
| |
Definition at line 89 of file index.php.
91 $options[
"databaseAdapter"] =
$dbh;
92 $options[
"loginAdapterList"] = array(
"sharedsecret",
"login");
95 $data[
"token_hash"] = $token;
98 $response = $service->call(
102 header(
"Content-Type: application/json");
103 echo $response->toJson();
105 }
catch (Exception $e) {
108 header(
"Content-Type: application/json");
109 $response =
new Alternc_Api_Response(array(
"code" => $e->getCode(),
"message" => $e->getMessage()));
110 echo $response->toJson();
Standard Request object for the AlternC API.
References $dbh, and exit.
◆ if
if |
( |
preg_match("#^/api/rest/([^/]*)/([^/\?]*)[/\?]?#", $_SERVER["REQUEST_URI"], $mat) |
$oneuser_ok | ) |
)[/\?] |
Initial value:{
__(
"No users currently defined, you must create login with the 'Manage allowed users' accounts' menu.")
Main code: either we are authenticating or calling one of the APIs or asking for some documentation.
Definition at line 176 of file index.php.