set_charging_action.php 3.9 KB

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