set_backend_action.php 7.5 KB

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