manualDriverConfig.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. include_once("../auth.php");
  3. $otherDeviceDir = "devices/";
  4. if (!file_exists($otherDeviceDir)){
  5. mkdir($otherDeviceDir);
  6. }
  7. if (isset($_GET['ipaddr']) && $_GET['ipaddr'] != "" && isset($_GET['classType']) && $_GET['classType'] != ""){
  8. //Create a record for this devices
  9. $filename = gen_uuid();
  10. $ip = strip_tags($_GET['ipaddr']);
  11. $classType = strip_tags($_GET['classType']);
  12. $outfile = $otherDeviceDir . $filename . ".inf";
  13. file_put_contents($outfile,$ip . "," . $classType);
  14. echo "DONE";
  15. }else{
  16. //Get all record for this node
  17. $devices = glob($otherDeviceDir . "*.inf");
  18. $results = [];
  19. foreach ($devices as $dev){
  20. $content = trim(file_get_contents($dev));
  21. $uuid = basename($dev,".inf");
  22. $tmp = explode(",",$content);
  23. $ipaddr = $tmp[0];
  24. $classType = $tmp[1];
  25. array_push($results,[$uuid,$ipaddr,$classType]);
  26. }
  27. header('Content-Type: application/json');
  28. echo json_encode($results);
  29. }
  30. function gen_uuid() {
  31. return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  32. // 32 bits for "time_low"
  33. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
  34. // 16 bits for "time_mid"
  35. mt_rand( 0, 0xffff ),
  36. // 16 bits for "time_hi_and_version",
  37. // four most significant bits holds version number 4
  38. mt_rand( 0, 0x0fff ) | 0x4000,
  39. // 16 bits, 8 bits for "clk_seq_hi_res",
  40. // 8 bits for "clk_seq_low",
  41. // two most significant bits holds zero and one for variant DCE1.1
  42. mt_rand( 0, 0x3fff ) | 0x8000,
  43. // 48 bits for "node"
  44. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
  45. );
  46. }
  47. ?>