Changes

Jump to navigation Jump to search
m
no edit summary
Line 54: Line 54:  
Edit /boot/config.txt with data from another server, where all works correctly.
 
Edit /boot/config.txt with data from another server, where all works correctly.
    +
 +
==How to add http-API2 converter==
 +
Create folder /home/html/api_v2.
 +
Put the file (index.php) into the folder.
 +
Enable API in LTsetup
 +
Request example: http://192.168.67.154/api_v2/?{"request":"status-get","addr":"395:14","API-KEY":"08283242722612433"}
 
<div class="mw-collapsible mw-collapsed" style="width:400px">
 
<div class="mw-collapsible mw-collapsed" style="width:400px">
index.php
+
'''index.php'''
<div class="mw-collapsible-content">fsdfsdfgdsfsdfsdf sd f
+
<div class="mw-collapsible-content">
sdf sdf dsf dsf dsf ds fds
+
<syntaxhighlight lang="php">
fdsf df
+
<?php
sdf
+
 
ds ds d</div>
+
function api_send($sock, $req) {
 +
    $r = '-JSON-'.$req;
 +
    return fwrite($sock, pack('I', strlen($r)) . $r);
 +
}
 +
 
 +
function api_recv($sock) {
 +
    $s = fread($sock, 4);
 +
    $size = unpack("I", $s)[1];
 +
    $data = fread($sock, $size);
 +
    if (strpos($data, '"error"')) {
 +
die(substr($data, 7));
 +
    }
 +
    return substr($data, 7);
 +
}
 +
 
 +
$headers = apache_request_headers();
 +
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
 +
    $post = file_get_contents('php://input');
 +
} else {
 +
    $post = urldecode($_SERVER['QUERY_STRING']);
 +
}
 +
 
 +
if (!isset($headers['API-KEY'])) { // API key not found in header, Checking request
 +
    $req = json_decode($post, true);
 +
    if (!isset($req['API-KEY'])) die('No API-KEY provided');
 +
    $key = $req['API-KEY'];
 +
    unset($req['API-KEY']);
 +
    $post = json_encode($req);
 +
} else $key = $headers['API-KEY'];
 +
 
 +
$sock = stream_socket_client('unix:///tmp/sh.socket', $errno, $errst);
 +
$auth_req = '{"request": "authorize","key": "'.$key.'"}';
 +
api_send($sock, $auth_req);
 +
api_recv($sock);
 +
api_send($sock, $post);
 +
echo api_recv($sock);
 +
fclose($sock);
 +
</syntaxhighlight>
 +
</div>
 
</div>
 
</div>
editor, Interface administrators, Administrators, translation-admin, translator
9,706

edits

Navigation menu