logo

Web api : Manage users via API ( Method GET ,JSON ,AES-128-CBC)

API ip port http://www.example.com:4300/wapi/
API and crypto json line http://www.example.com:4300/wapi/8c621d990a059cd.....

Command PHP Response
ADD user $ptext ='{"command":"add","user":"alex","pass":"1234","notes":"test","maxcon":"10","enddate":"2018-09-28","categories":"2,3,4,5","ip":"","reseller":""}'; {"info":"add_ok"} {"info":"add_err"}
EDIT user $ptext ='{"command":"edit","user":"alex","pass":"1234","notes":"test","maxcon":"10","enddate":"2019-09-28","categories":"2,3,4,5","ip":"","reseller":""}'; {"info":"edit_ok"} {"info":"edit_err"}
DEL user $ptext ='{"command":"del","user":"alex"}'; {"info":"del_ok"} {"info":"del_err"}
GET user $ptext ='{"command":"get","user":"alex"}'; user:[{"id":1,"user":"alex","pass":"1234","categories":"1,14","enddate":1619827200,"notes":"free","maxcon":10,"ip":"allowed ip(s) separated by ,","reseller":""}]
GET all users $ptext ='{"command":"get","user":"all_users"}'; user:[{"id":1,"user":"alex","pass":"1234","categories":"1,14","enddate":1619827200,"notes":"free","maxcon":10,"ip":"allowed ip(s) separated by ,","reseller":""},{"id":2,"user":"alex1","pass":"1234","categories":"1,4","enddate":1619827200,"notes":"free1","maxcon":1,"ip":"allowed ip(s) separated by ,","reseller":""}]
GET users connections $ptext ='{"command":"connections","user":"all_users"}'; user:[{"id":1,"user":"alex","ip":"192.168.1.100","ua":"VLC/3.0.6","type":"mpegts","uptime":1610647406232,"chid":2,"catid":1},{"id":2,"user":"alex1","ip":"192.168.1.101","ua":"VLC/3.0.6","type":"mpegts","uptime":1610647539877,"chid":3,"catid":1}]
- - {"info":"command_err"} {"info":"key_err"} {"info":"user_exists"}
Note Format "enddate" "enddate":"2019-09-28", "enddate":"2019-09-28T05:01:22"
Note - This color is after decryption!

Key from Nice restreamer $key = "o5YHCJYmP7AR2hEz"; $iv = "MH2mEr9N4XY3j6cr";

<?php 
$ptext ='{"command":"add","user":"alex","pass":"1234","notes":"test","maxcon":"10","enddate":"2018-09-28","categories":"2,3,4,5","ip":"","reseller":""}';
//$ptext ='{"command":"edit","user":"alex","pass":"1234","notes":"test","maxcon":"10","enddate":"2019-09-28","categories":"2,3,4,5","ip":"","reseller":""}';
//$ptext ='{"command":"del","user":"alex"}';
//---- NEW NR v5.3 ----
//$ptext ='{"command":"get","user":"alex"}';
//$ptext ='{"command":"get","user":"all_users"}';
$ptext = base64_encode($ptext);
//-------------
$key = "o5YHCJYmP7AR2hEz";
$iv = "MH2mEr9N4XY3j6cr";
$ciphertext_raw = openssl_encrypt($ptext, "AES-128-CBC", $key, $options=OPENSSL_RAW_DATA, $iv);
$encoded = 'http://www.example.com:4300/wapi/' . bin2hex($ciphertext_raw);

$curl = curl_init($encoded); 

curl_setopt($curl, CURLOPT_FAILONERROR, true); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);   
$result = curl_exec($curl); 
$text = json_decode($result, true);


//---- NEW NR v5.3 ----
foreach($text as $keyi=>$value) {
	if($keyi == 'info'){
	   $message = $keyi . ":" . $value . "\n";
       echo $message;
	}else{
	   $dptext = openssl_decrypt(hex2bin($value), "AES-128-CBC", $key, $options=OPENSSL_RAW_DATA, $iv);
	   $btext = base64_decode($dptext);
	   $message = $keyi . ":" . $btext . "\n";
       echo $message;
	}
}
//-------------

?>