set_system_action.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // 設置資料類型 json,編碼格式 utf-8
  3. header('Content-Type: application/json; charset=UTF-8');
  4. // 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
  5. // $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
  6. if ($_SERVER['REQUEST_METHOD'] == "GET") {
  7. create();
  8. } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
  9. create();
  10. }
  11. // 新建員工
  12. function create() {
  13. // $json = json_decode(file_get_contents("system.txt"), true);
  14. $json['SystemId'] = $_POST["SystemId"];
  15. $json['SystemDateTime'] = $_POST['SystemDateTime'];
  16. $json['AcPhaseCount'] = $_POST['AcPhaseCount'];
  17. $json['FactoryConfiguration'] = $_POST['FactoryConfiguration'];
  18. $json['AuthorisationMode'] = $_POST['AuthorisationMode'];
  19. $json['DefaultLanguage'] = chr($_POST['DefaultLanguage']);
  20. $json['RfidCardNumEndian'] = $_POST['RfidCardNumEndian'];
  21. // var_dump($json);echo "\n\n";
  22. // echo json_encode($json);
  23. if($_POST['SystemDateTime'] != ""){
  24. if(!validateDate($_POST['SystemDateTime'])){
  25. $jsone['result'] = "Fail";
  26. $jsone['message'] = "SystemDateTime format or content error, fill it with 'yyyy-mm-dd hh:ii:ss";
  27. echo json_encode($jsone);
  28. return false;
  29. }
  30. }
  31. $jsone['result'] = "Success";
  32. $jsone['message'] = $json;
  33. echo json_encode($jsone);
  34. //echo json_encode($json);
  35. //file_put_contents("system.dat", json_encode($json));
  36. // $json = json_decode(file_get_contents("rateOnline"), true);
  37. // $json['isOnlineSet'] = false;
  38. // file_put_contents("./rateOnline", json_encode($json));
  39. ob_start();
  40. // shell_exec('sudo cp /root/wvdial_conf/wvdial.conf_'.$_POST['mDongle'].' /etc/wvdial.conf'.'> /dev/null 2>/dev/null &');
  41. // if($_POST['lan_ip']=="0")
  42. // shell_exec('sudo cp /root/interfaces/interfaces_static /etc/network/interfaces'.'> /dev/null 2>/dev/null &');
  43. // else
  44. // shell_exec('sudo cp /root/interfaces/interfaces_dhcp /etc/network/interfaces'.'> /dev/null 2>/dev/null &');
  45. // shell_exec('sudo /usr/bin/check_wifi.sh'.'> /dev/null 2>/dev/null &');
  46. //file_put_contents(".tmate.conf", 'set-option -g tmate-webhook-url "http://folus.no-ip.org:8090/tmate_update_payload.php"'."\n".'set-option -g tmate-webhook-userdata "'.$_POST["new_id"].'"');
  47. //shell_exec('sudo mv .tmate.conf /root/');
  48. // shell_exec('sudo /usr/bin/run_apn_set.sh /etc/wvdial.conf '.$_POST['apn_name'].' &');
  49. shell_exec('sync;sync;sync');
  50. //chdir("/home/phihong/Module_WebService");
  51. chdir("/root");
  52. $str_json=json_encode($json);//echo $str_json;exit;
  53. exec("'./WebService' '1' '".$str_json."'",$output,$return_var);
  54. // copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
  55. ob_end_clean();
  56. // print_r($output);
  57. //echo "OK";
  58. }
  59. function validateDate($date, $format = 'Y-m-d H:i:s')
  60. {
  61. $d = DateTime::createFromFormat($format, $date);
  62. return $d && $d->format($format) == $date;
  63. }
  64. ?>