set_backend_action.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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($_POST['OcppServerURL']!=""){
  15. if(!preg_match($pattern, $_POST['OcppServerURL'])){
  16. $jsone['result'] = "Fail";
  17. $jsone['message'] = "OcppServerURL format error, fill it with 'ws://' or 'wss://'";
  18. echo json_encode($jsone);
  19. return false;
  20. }
  21. }
  22. checkValue("OfflinePolicy");
  23. // $json = json_decode(file_get_contents("charging.txt"), true);
  24. // $json = string[];
  25. $json['BackendConnTimeout'] = (int)$_POST['BackendConnTimeout'];
  26. $json['OfflinePolicy'] = (int)$_POST['OfflinePolicy'];
  27. $json['OfflineMaxChargeEnergy'] = (int)$_POST['OfflineMaxChargeEnergy'];
  28. $json['OfflineMaxChargeDuration'] = (int)$_POST['OfflineMaxChargeDuration'];
  29. // $json['OcppConnStatus'] = $_POST['OcppConnStatus'];
  30. $json['OcppServerURL'] = $_POST['OcppServerURL'];
  31. $json['ChargeBoxId'] = $_POST['ChargeBoxId'];
  32. $json['chargePointVendor'] = $_POST['chargePointVendor'];
  33. // ob_start();
  34. shell_exec('sync;sync;sync');
  35. chdir("/root");
  36. $str_json=json_encode($json);//var_dump($str_json);
  37. exec("'./WebService' '4' '".$str_json."'",$output,$return_var);
  38. if(count($output)!=0){
  39. $jsone['result'] = "Success";
  40. $jsone['message'] = $json;
  41. echo json_encode($jsone);
  42. exit;
  43. }
  44. else{
  45. $jsone['result'] = "Error";
  46. $jsone['message'] = "Something went wrong on machine";
  47. echo json_encode($jsone);
  48. return false;
  49. exit;
  50. }
  51. // ob_end_clean();
  52. }
  53. function checkValue($id){
  54. if(strlen($_POST[$id])!=1){
  55. $jsone['result'] = "Fail";
  56. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  57. echo json_encode($jsone);
  58. exit;
  59. }
  60. if(!ereg("[0-9]",$_POST[$id])){
  61. $jsone['result'] = "Fail";
  62. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  63. echo json_encode($jsone);
  64. exit;
  65. }
  66. }
  67. ?>