set_charging_action.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. checkMaxValue("MaxChargingEnergy");
  14. checkMaxValue("MaxChargingPower");
  15. checkMaxValue("MaxChargingCurrent");
  16. checkMaxValue("MaxChargingDuration");
  17. checkValue("PhaseLossPolicy");
  18. // $json = json_decode(file_get_contents("charging.txt"), true);
  19. // $json = string[];
  20. $json['MaxChargingEnergy'] = (int)$_POST['MaxChargingEnergy'];
  21. $json['MaxChargingPower'] = (int)$_POST['MaxChargingPower'];
  22. $json['MaxChargingCurrent'] = (int)$_POST['MaxChargingCurrent'];
  23. $json['MaxChargingDuration'] = (int)$_POST['MaxChargingDuration'];
  24. $json['PhaseLossPolicy'] = chr($_POST['PhaseLossPolicy']);
  25. $json['LocalWhiteCard0'] = $_POST['LocalWhiteCard0'];
  26. $json['LocalWhiteCard1'] = $_POST['LocalWhiteCard1'];
  27. $json['LocalWhiteCard2'] = $_POST['LocalWhiteCard2'];
  28. $json['LocalWhiteCard3'] = $_POST['LocalWhiteCard3'];
  29. $json['LocalWhiteCard4'] = $_POST['LocalWhiteCard4'];
  30. $json['LocalWhiteCard5'] = $_POST['LocalWhiteCard5'];
  31. $json['LocalWhiteCard6'] = $_POST['LocalWhiteCard6'];
  32. $json['LocalWhiteCard7'] = $_POST['LocalWhiteCard7'];
  33. $json['LocalWhiteCard8'] = $_POST['LocalWhiteCard8'];
  34. $json['LocalWhiteCard9'] = $_POST['LocalWhiteCard9'];
  35. // $json['CcsAuthentication'] = $_POST['CcsAuthentication'];
  36. // $json['AcCcsChargingModel'] = $_POST['AcCcsChargingModel'];
  37. // var_dump($json);echo "\n\n";
  38. // echo json_encode($json);
  39. $jsone['result'] = "Success";
  40. $jsone['message'] = $json;
  41. echo json_encode($jsone);
  42. //file_put_contents("system.dat", json_encode($json));
  43. // $json = json_decode(file_get_contents("rateOnline"), true);
  44. // $json['isOnlineSet'] = false;
  45. // file_put_contents("./rateOnline", json_encode($json));
  46. ob_start();
  47. // shell_exec('sudo cp /root/wvdial_conf/wvdial.conf_'.$_POST['mDongle'].' /etc/wvdial.conf'.'> /dev/null 2>/dev/null &');
  48. // if($_POST['lan_ip']=="0")
  49. // shell_exec('sudo cp /root/interfaces/interfaces_static /etc/network/interfaces'.'> /dev/null 2>/dev/null &');
  50. // else
  51. // shell_exec('sudo cp /root/interfaces/interfaces_dhcp /etc/network/interfaces'.'> /dev/null 2>/dev/null &');
  52. // shell_exec('sudo /usr/bin/check_wifi.sh'.'> /dev/null 2>/dev/null &');
  53. //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"].'"');
  54. //shell_exec('sudo mv .tmate.conf /root/');
  55. // shell_exec('sudo /usr/bin/run_apn_set.sh /etc/wvdial.conf '.$_POST['apn_name'].' &');
  56. shell_exec('sync;sync;sync');
  57. //chdir("/home/phihong/Module_WebService");
  58. chdir("/root");
  59. $str_json=json_encode($json);//var_dump($str_json);
  60. exec("'./WebService' '2' '".$str_json."'",$output,$return_var);
  61. // copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
  62. ob_end_clean();
  63. // print_r($output);
  64. //echo "OK";
  65. }
  66. function checkMaxValue($id){
  67. if($_POST[$id] != ""){
  68. if(!is_numeric($_POST[$id])){
  69. $jsone['result'] = "Fail";
  70. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  71. echo json_encode($jsone);
  72. exit;
  73. }
  74. if($_POST[$id]>65535){
  75. $jsone['result'] = "Fail";
  76. $jsone['message'] = "You have entered a over value on " . $id . ", it should be less than 65535";
  77. echo json_encode($jsone);
  78. exit;
  79. }
  80. if($_POST[$id]<0){
  81. $jsone['result'] = "Fail";
  82. $jsone['message'] = "You have entered a over value on " . $id . ", it should be more than 0";
  83. echo json_encode($jsone);
  84. exit;
  85. }
  86. }
  87. }
  88. function checkValue($id){
  89. if(strlen($_POST[$id])!=1){
  90. $jsone['result'] = "Fail";
  91. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  92. echo json_encode($jsone);
  93. exit;
  94. }
  95. if(!ereg("[0-9]",$_POST[$id])){
  96. $jsone['result'] = "Fail";
  97. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  98. echo json_encode($jsone);
  99. exit;
  100. }
  101. }
  102. ?>