set_system_action.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. if($_POST['SystemDateTime'] != ""){
  14. if(!validateDate($_POST['SystemDateTime'])){
  15. $jsone['result'] = "Fail";
  16. $jsone['message'] = "SystemDateTime format or content error, fill it with 'yyyy-mm-dd hh:ii:ss";
  17. echo json_encode($jsone);
  18. return false;
  19. }
  20. }
  21. checkValue("AcPhaseCount",1);
  22. checkValue("FactoryConfiguration",1);
  23. checkValue("AuthorisationMode",1);
  24. checkValue("DefaultLanguage",2);
  25. checkValue("RfidCardNumEndian",1);
  26. // $json = json_decode(file_get_contents("system.txt"), true);
  27. $json['SystemId'] = $_POST["SystemId"];
  28. $json['SystemDateTime'] = $_POST['SystemDateTime'];
  29. $json['AcPhaseCount'] = chr($_POST['AcPhaseCount']);
  30. $json['FactoryConfiguration'] = chr($_POST['FactoryConfiguration']);
  31. $json['AuthorisationMode'] = chr($_POST['AuthorisationMode']);
  32. $json['DefaultLanguage'] = chr($_POST['DefaultLanguage']);
  33. $json['RfidCardNumEndian'] = chr($_POST['RfidCardNumEndian']);
  34. // var_dump($json);echo "\n\n";
  35. // echo json_encode($json);
  36. $jsone['result'] = "Success";
  37. $jsone['message'] = $json;
  38. echo json_encode($jsone);
  39. //echo json_encode($json);
  40. //file_put_contents("system.dat", json_encode($json));
  41. // $json = json_decode(file_get_contents("rateOnline"), true);
  42. // $json['isOnlineSet'] = false;
  43. // file_put_contents("./rateOnline", json_encode($json));
  44. ob_start();
  45. // shell_exec('sudo cp /root/wvdial_conf/wvdial.conf_'.$_POST['mDongle'].' /etc/wvdial.conf'.'> /dev/null 2>/dev/null &');
  46. // if($_POST['lan_ip']=="0")
  47. // shell_exec('sudo cp /root/interfaces/interfaces_static /etc/network/interfaces'.'> /dev/null 2>/dev/null &');
  48. // else
  49. // shell_exec('sudo cp /root/interfaces/interfaces_dhcp /etc/network/interfaces'.'> /dev/null 2>/dev/null &');
  50. // shell_exec('sudo /usr/bin/check_wifi.sh'.'> /dev/null 2>/dev/null &');
  51. //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"].'"');
  52. //shell_exec('sudo mv .tmate.conf /root/');
  53. // shell_exec('sudo /usr/bin/run_apn_set.sh /etc/wvdial.conf '.$_POST['apn_name'].' &');
  54. shell_exec('sync;sync;sync');
  55. //chdir("/home/phihong/Module_WebService");
  56. chdir("/root");
  57. $str_json=json_encode($json);//echo $str_json;exit;
  58. exec("'./WebService' '1' '".$str_json."'",$output,$return_var);
  59. // copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
  60. ob_end_clean();
  61. // print_r($output);
  62. //echo "OK";
  63. }
  64. function validateDate($date, $format = 'Y-m-d H:i:s')
  65. {
  66. $d = DateTime::createFromFormat($format, $date);
  67. return $d && $d->format($format) == $date;
  68. }
  69. function checkValue($id,$idx){
  70. if($idx==1){
  71. if(strlen($_POST[$id])!=1){
  72. $jsone['result'] = "Fail";
  73. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  74. echo json_encode($jsone);
  75. exit;
  76. }
  77. if(!ereg("[0-9]",$_POST[$id])){
  78. $jsone['result'] = "Fail";
  79. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  80. echo json_encode($jsone);
  81. exit;
  82. }
  83. }
  84. if($idx==2){
  85. if(strlen($_POST[$id])>2){
  86. $jsone['result'] = "Fail";
  87. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  88. echo json_encode($jsone);
  89. exit;
  90. }
  91. if(!ereg("[0-9]",$_POST[$id]) & !ereg("[0-9]{2}",$_POST[$id])){
  92. $jsone['result'] = "Fail";
  93. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  94. echo json_encode($jsone);
  95. exit;
  96. }
  97. }
  98. }
  99. ?>