set_backend_action.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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['MaintainServerSecurityProfile'])){
  65. checkValue("MaintainServerSecurityProfile");
  66. $json['MaintainServerSecurityProfile'] = (int)$_REQUEST['MaintainServerSecurityProfile'];
  67. }
  68. if(isset($_REQUEST['MaintainServerSecurityPassword'])){
  69. $json['MaintainServerSecurityPassword'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['MaintainServerSecurityPassword'])))));
  70. }
  71. if(isset($_REQUEST['isEnableLocalPowerSharging'])){
  72. checkValue("isEnableLocalPowerSharging");
  73. $json['isEnableLocalPowerSharging'] = (int)$_REQUEST['isEnableLocalPowerSharging'];
  74. }
  75. if(isset($_REQUEST['OcppReceiptrURL'])){
  76. $json['OcppReceiptrURL'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppReceiptrURL'])))));
  77. }
  78. if(isset($_REQUEST['isEnableTTIA'])){
  79. checkValue("isEnableTTIA");
  80. $json['isEnableTTIA'] = (int)$_REQUEST['isEnableTTIA'];
  81. }
  82. if(isset($_REQUEST['server_addr'])){
  83. $json['server_addr'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['server_addr'])))));
  84. }
  85. if(isset($_REQUEST['server_port'])){
  86. isNumeric("server_port",65535);
  87. $json['server_port'] = (int)$_REQUEST['server_port'];
  88. }
  89. if(isset($_REQUEST['busVenderId'])){
  90. isNumeric("busVenderId",65535);
  91. $json['busVenderId'] = (int)$_REQUEST['busVenderId'];
  92. }
  93. if(isset($_REQUEST['EquipmentProvider'])){
  94. checkLength("EquipmentProvider",15);
  95. $json['EquipmentProvider'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['EquipmentProvider'])))));
  96. }
  97. if(isset($_REQUEST['TransportationCompanyNo'])){
  98. isNumeric("TransportationCompanyNo",255);
  99. $json['TransportationCompanyNo'] = (int)$_REQUEST['TransportationCompanyNo'];
  100. }
  101. if(isset($_REQUEST['TTIAChargeBoxId'])){
  102. isNumeric("TTIAChargeBoxId",255);
  103. $json['TTIAChargeBoxId'] = (int)$_REQUEST['TTIAChargeBoxId'];
  104. }
  105. if(isset($_REQUEST['evseStation'])){
  106. checkLength("evseStation",15);
  107. $json['evseStation'] = str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['evseStation'])))));
  108. }
  109. // ob_start();
  110. shell_exec('sync;sync;sync');
  111. chdir("/root");
  112. $str_json=json_encode($json);//var_dump($str_json);
  113. exec("'./WebService' '4' '".$str_json."'",$output,$return_var);
  114. if(count($output)!=0){
  115. $jsone['result'] = "Success";
  116. $jsone['message'] = $json;
  117. echo json_encode($jsone);
  118. exit;
  119. }
  120. else{
  121. $jsone['result'] = "Error";
  122. $jsone['message'] = "Something went wrong on machine";
  123. echo json_encode($jsone);
  124. return false;
  125. exit;
  126. }
  127. // ob_end_clean();
  128. }
  129. function checkValue($id){
  130. if($_REQUEST[$id] != ""){
  131. if(strlen($_REQUEST[$id])!=1){
  132. $jsone['result'] = "Fail";
  133. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  134. echo json_encode($jsone);
  135. exit;
  136. }
  137. if(!is_numeric($_REQUEST[$id])){
  138. $jsone['result'] = "Fail";
  139. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  140. echo json_encode($jsone);
  141. exit;
  142. }
  143. }
  144. }
  145. function checkLength($id,$value){
  146. if(strlen($_REQUEST[$id])>$value){
  147. $jsone['result'] = "Fail";
  148. $jsone['message'] = "Length of " . $id . " should be less than ".$value+"(Chinese 5 words)";
  149. echo json_encode($jsone);
  150. exit;
  151. }
  152. }
  153. function isNumeric($id,$value){
  154. if($_REQUEST[$id] != ""){
  155. if(!is_numeric($_REQUEST[$id])){
  156. $jsone['result'] = "Fail";
  157. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  158. echo json_encode($jsone);
  159. exit;
  160. }
  161. if($_REQUEST[$id]>$value){
  162. $jsone['result'] = "Fail";
  163. $jsone['message'] = "Value of " . $id . " should be less than ".$value;
  164. echo json_encode($jsone);
  165. exit;
  166. }
  167. }
  168. }
  169. ?>