set_backend_action.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. $pattern="/^(ws|wss):\/\/((([0-9]{1,3}\.){3}[0-9]{1,3})|(([a-zA-Z0-9]+(([\-]?[a-zA-Z0-9]+)*\.)+)*[a-zA-Z]{2,}))+/";
  14. if(!preg_match($pattern, $_POST['OcppServerURL'])){
  15. $jsone['result'] = "Fail";
  16. $jsone['message'] = "OcppServerURL format error, fill it with 'ws://' or 'wss://'";
  17. echo json_encode($jsone);
  18. return false;
  19. }
  20. checkValue("OfflinePolicy");
  21. // $json = json_decode(file_get_contents("charging.txt"), true);
  22. // $json = string[];
  23. $json['BackendConnTimeout'] = (int)$_POST['BackendConnTimeout'];
  24. $json['OfflinePolicy'] = chr($_POST['OfflinePolicy']);
  25. $json['OfflineMaxChargeEnergy'] = (int)$_POST['OfflineMaxChargeEnergy'];
  26. $json['OfflineMaxChargeDuration'] = (int)$_POST['OfflineMaxChargeDuration'];
  27. // $json['OcppConnStatus'] = $_POST['OcppConnStatus'];
  28. $json['OcppServerURL'] = $_POST['OcppServerURL'];
  29. $json['ChargeBoxId'] = $_POST['ChargeBoxId'];
  30. // var_dump($json);echo "\n\n";
  31. //echo json_encode($json);
  32. $jsone['result'] = "Success";
  33. $jsone['message'] = $json;
  34. echo json_encode($jsone);
  35. ob_start();
  36. shell_exec('sync;sync;sync');
  37. // chdir("/home/phihong/Module_WebService");
  38. chdir("/root");
  39. $str_json=json_encode($json);//var_dump($str_json);
  40. exec("'./WebService' '4' '".$str_json."'",$output,$return_var);
  41. // copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
  42. ob_end_clean();
  43. // print_r($output);
  44. //echo "OK";
  45. }
  46. function checkValue($id){
  47. if(strlen($_POST[$id])!=1){
  48. $jsone['result'] = "Fail";
  49. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  50. echo json_encode($jsone);
  51. exit;
  52. }
  53. if(!ereg("[0-9]",$_POST[$id])){
  54. $jsone['result'] = "Fail";
  55. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  56. echo json_encode($jsone);
  57. exit;
  58. }
  59. }
  60. ?>