set_backend_action.php 7.3 KB

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