Add lookup API, add more event types
This commit is contained in:
parent
d04159159f
commit
8c9bc25276
21
api/actions/lookup.php
Normal file
21
api/actions/lookup.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2020 Netsyms Technologies.
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
if (empty($VARS["id"]) || (!Machine::exists($VARS["id"]) && !Machine::serialExists($VARS["id"]))) {
|
||||
sendJsonResp("Requested ID does not exist.", "ERROR");
|
||||
}
|
||||
|
||||
if (Machine::exists($VARS["id"])) {
|
||||
$machine = new Machine($VARS['id']);
|
||||
} else {
|
||||
$machine = new Machine(Machine::getIDFromSerial($VARS['id']));
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
exit(json_encode($machine));
|
@ -11,5 +11,11 @@ $APIS = [
|
||||
"load" => "ping.php",
|
||||
"vars" => [
|
||||
]
|
||||
],
|
||||
"lookup" => [
|
||||
"load" => "lookup.php",
|
||||
"vars" => [
|
||||
"id" => "/^[0-9a-z]+$/"
|
||||
]
|
||||
]
|
||||
];
|
||||
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -4,7 +4,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
class Machine {
|
||||
class Machine implements JsonSerializable {
|
||||
|
||||
private $machineid = "";
|
||||
private $machine = [];
|
||||
@ -26,6 +26,19 @@ class Machine {
|
||||
}
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
if ($this->exists) {
|
||||
return [
|
||||
"status" => "OK",
|
||||
"id" => $this->machineid,
|
||||
"info" => $this->machine,
|
||||
"events" => $this->events,
|
||||
"components" => $this->components
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function create(): Machine {
|
||||
return new Machine(Machine::generateId());
|
||||
}
|
||||
@ -219,7 +232,8 @@ class Machine {
|
||||
public static function generateId(int $min = 1000000000, int $max = 9999999999): int {
|
||||
global $database;
|
||||
|
||||
$id = random_int(1000000000, 9999999999);;
|
||||
$id = random_int(1000000000, 9999999999);
|
||||
;
|
||||
|
||||
do {
|
||||
$id = random_int(1000000000, 9999999999);
|
||||
|
Loading…
x
Reference in New Issue
Block a user