set_backend_action.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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($_REQUEST['OcppServerURL']!=""){
  15. if(!preg_match($pattern, $_REQUEST['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. if($_REQUEST['MaintainServerURL']!=""){
  23. if(!preg_match($pattern, $_REQUEST['MaintainServerURL'])){
  24. $jsone['result'] = "Fail";
  25. $jsone['message'] = "MaintainServerURL format error, fill it with 'ws://' or 'wss://'";
  26. echo json_encode($jsone);
  27. return false;
  28. }
  29. }
  30. checkValue("OfflinePolicy");
  31. checkLength("ChargeBoxId",25);
  32. checkLength("chargePointVendor",20);
  33. if(isset($_REQUEST['BackendConnTimeout'])){
  34. $json['BackendConnTimeout'] = (int)$_REQUEST['BackendConnTimeout'];
  35. }
  36. if(isset($_REQUEST['OfflinePolicy'])){
  37. $json['OfflinePolicy'] = (int)$_REQUEST['OfflinePolicy'];
  38. }
  39. if(isset($_REQUEST['OfflineMaxChargeEnergy'])){
  40. $json['OfflineMaxChargeEnergy'] = (int)$_REQUEST['OfflineMaxChargeEnergy'];
  41. }
  42. if(isset($_REQUEST['OfflineMaxChargeDuration'])){
  43. $json['OfflineMaxChargeDuration'] = (int)$_REQUEST['OfflineMaxChargeDuration'];
  44. }
  45. if(isset($_REQUEST['OcppServerURL'])){
  46. $json['OcppServerURL'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppServerURL'])))));
  47. }
  48. if(isset($_REQUEST['MaintainServerURL'])){
  49. $json['MaintainServerURL'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['MaintainServerURL'])))));
  50. }
  51. if(isset($_REQUEST['ChargeBoxId'])){
  52. $json['ChargeBoxId'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['ChargeBoxId'])))));
  53. }
  54. if(isset($_REQUEST['chargePointVendor'])){
  55. $json['chargePointVendor'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['chargePointVendor'])))));
  56. }
  57. if(isset($_REQUEST['OcppSecurityProfile'])){
  58. checkValue("OcppSecurityProfile");
  59. $json['OcppSecurityProfile'] = (int)$_REQUEST['OcppSecurityProfile'];
  60. }
  61. if(isset($_REQUEST['OcppSecurityPassword'])){
  62. $json['OcppSecurityPassword'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppSecurityPassword'])))));
  63. }
  64. if(isset($_REQUEST['isEnableLocalPowerSharging'])){
  65. checkValue("isEnableLocalPowerSharging");
  66. $json['isEnableLocalPowerSharging'] = (int)$_REQUEST['isEnableLocalPowerSharging'];
  67. }
  68. if(isset($_REQUEST['OcppReceiptrURL'])){
  69. $json['OcppReceiptrURL'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppReceiptrURL'])))));
  70. }
  71. if(isset($_REQUEST['isEnableTTIA'])){
  72. checkValue("isEnableTTIA");
  73. $json['isEnableTTIA'] = (int)$_REQUEST['isEnableTTIA'];
  74. }
  75. if(isset($_REQUEST['server_addr'])){
  76. $json['server_addr'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['server_addr'])))));
  77. }
  78. if(isset($_REQUEST['server_port'])){
  79. isNumeric("server_port",65535);
  80. $json['server_port'] = (int)$_REQUEST['server_port'];
  81. }
  82. if(isset($_REQUEST['busVenderId'])){
  83. isNumeric("busVenderId",65535);
  84. $json['busVenderId'] = (int)$_REQUEST['busVenderId'];
  85. }
  86. if(isset($_REQUEST['EquipmentProvider'])){
  87. checkLength("EquipmentProvider",15);
  88. $json['EquipmentProvider'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['EquipmentProvider'])))));
  89. }
  90. if(isset($_REQUEST['TransportationCompanyNo'])){
  91. isNumeric("TransportationCompanyNo",255);
  92. $json['TransportationCompanyNo'] = (int)$_REQUEST['TransportationCompanyNo'];
  93. }
  94. if(isset($_REQUEST['TTIAChargeBoxId'])){
  95. isNumeric("TTIAChargeBoxId",255);
  96. $json['TTIAChargeBoxId'] = (int)$_REQUEST['TTIAChargeBoxId'];
  97. }
  98. if(isset($_REQUEST['evseStation'])){
  99. checkLength("evseStation",15);
  100. $json['evseStation'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['evseStation'])))));
  101. }
  102. // ob_start();
  103. shell_exec('sync;sync;sync');
  104. chdir("/root");
  105. $str_json=json_encode($json);//var_dump($str_json);
  106. exec("'./WebService' '4' '".$str_json."'",$output,$return_var);
  107. if(count($output)!=0){
  108. $jsone['result'] = "Success";
  109. $jsone['message'] = $json;
  110. echo json_encode($jsone);
  111. exit;
  112. }
  113. else{
  114. $jsone['result'] = "Error";
  115. $jsone['message'] = "Something went wrong on machine";
  116. echo json_encode($jsone);
  117. return false;
  118. exit;
  119. }
  120. // ob_end_clean();
  121. }
  122. function checkValue($id){
  123. if($_REQUEST[$id] != ""){
  124. if(strlen($_REQUEST[$id])!=1){
  125. $jsone['result'] = "Fail";
  126. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  127. echo json_encode($jsone);
  128. exit;
  129. }
  130. if(!ereg("[0-9]",$_REQUEST[$id])){
  131. $jsone['result'] = "Fail";
  132. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  133. echo json_encode($jsone);
  134. exit;
  135. }
  136. }
  137. }
  138. function checkLength($id,$value){
  139. if(strlen($_REQUEST[$id])>$value){
  140. $jsone['result'] = "Fail";
  141. $jsone['message'] = "Length of " . $id . " should be less than ".$value+"(Chinese 5 words)";
  142. echo json_encode($jsone);
  143. exit;
  144. }
  145. }
  146. function isNumeric($id,$value){
  147. if($_REQUEST[$id] != ""){
  148. if(!ereg("[0-9]",$_REQUEST[$id])){
  149. $jsone['result'] = "Fail";
  150. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  151. echo json_encode($jsone);
  152. exit;
  153. }
  154. if($_REQUEST[$id]>$value){
  155. $jsone['result'] = "Fail";
  156. $jsone['message'] = "Value of " . $id . " should be less than ".$value;
  157. echo json_encode($jsone);
  158. exit;
  159. }
  160. }
  161. }
  162. ?>