12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- include_once("../auth.php");
- $otherDeviceDir = "devices/";
- if (!file_exists($otherDeviceDir)){
- mkdir($otherDeviceDir);
- }
- if (isset($_GET['ipaddr']) && $_GET['ipaddr'] != "" && isset($_GET['classType']) && $_GET['classType'] != ""){
- //Create a record for this devices
- $filename = gen_uuid();
- $ip = strip_tags($_GET['ipaddr']);
- $classType = strip_tags($_GET['classType']);
- $outfile = $otherDeviceDir . $filename . ".inf";
- file_put_contents($outfile,$ip . "," . $classType);
- echo "DONE";
- }else{
- //Get all record for this node
- $devices = glob($otherDeviceDir . "*.inf");
- $results = [];
- foreach ($devices as $dev){
- $content = trim(file_get_contents($dev));
- $uuid = basename($dev,".inf");
- $tmp = explode(",",$content);
- $ipaddr = $tmp[0];
- $classType = $tmp[1];
- array_push($results,[$uuid,$ipaddr,$classType]);
- }
- header('Content-Type: application/json');
- echo json_encode($results);
- }
- function gen_uuid() {
- return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
- // 32 bits for "time_low"
- mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
- // 16 bits for "time_mid"
- mt_rand( 0, 0xffff ),
- // 16 bits for "time_hi_and_version",
- // four most significant bits holds version number 4
- mt_rand( 0, 0x0fff ) | 0x4000,
- // 16 bits, 8 bits for "clk_seq_hi_res",
- // 8 bits for "clk_seq_low",
- // two most significant bits holds zero and one for variant DCE1.1
- mt_rand( 0, 0x3fff ) | 0x8000,
- // 48 bits for "node"
- mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
- );
- }
- ?>
|