set_charging_action.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. checkLength("LocalWhiteCard0");
  14. checkLength("LocalWhiteCard1");
  15. checkLength("LocalWhiteCard2");
  16. checkLength("LocalWhiteCard3");
  17. checkLength("LocalWhiteCard4");
  18. checkLength("LocalWhiteCard5");
  19. checkLength("LocalWhiteCard6");
  20. checkLength("LocalWhiteCard7");
  21. checkLength("LocalWhiteCard8");
  22. checkLength("LocalWhiteCard9");
  23. checkMaxValue("MaxChargingEnergy");
  24. checkMaxValue("MaxChargingPower");
  25. checkMaxValue("MaxChargingCurrent");
  26. if(substr($_POST['ModelName'],-2)=="PS"){
  27. checkMaxValue("MaxChargingVoltage");
  28. }
  29. checkMaxValue("AcMaxChargingCurrent");
  30. checkMaxValue("MaxChargingDuration");
  31. checkMaxValue("MaxChargingSoc");
  32. checkValue("StopChargingByButton");
  33. checkValue("FanControlPolicy");
  34. if(substr($_POST['ModelName'],0,1)=="A" && $_POST['MaxChargingCurrent']<6 && $_POST['MaxChargingCurrent']!=0){
  35. $jsone['result'] = "Fail";
  36. $jsone['message'] = "MaxChargingCurrent must > 6";
  37. echo json_encode($jsone);
  38. exit;
  39. }
  40. if(isset($_POST['MaxChargingEnergy'])){
  41. $json['MaxChargingEnergy'] = (int)$_POST['MaxChargingEnergy'];
  42. }
  43. if(isset($_POST['MaxChargingPower'])){
  44. $json['MaxChargingPower'] = (int)$_POST['MaxChargingPower'];
  45. }
  46. if(isset($_POST['MaxChargingCurrent'])){
  47. $json['MaxChargingCurrent'] = (int)$_POST['MaxChargingCurrent'];
  48. }
  49. if(isset($_POST['MaxChargingVoltage'])){
  50. $json['MaxChargingVoltage'] = (int)$_POST['MaxChargingVoltage'];
  51. }
  52. if(isset($_POST['AcMaxChargingCurrent'])){
  53. $json['AcMaxChargingCurrent'] = (int)$_POST['AcMaxChargingCurrent'];
  54. }
  55. if(isset($_POST['MaxChargingDuration'])){
  56. $json['MaxChargingDuration'] = (int)$_POST['MaxChargingDuration'];
  57. }
  58. if(isset($_POST['MaxChargingSoc'])){
  59. $json['MaxChargingSoc'] = (int)$_POST['MaxChargingSoc'];
  60. }
  61. if(isset($_POST['StopChargingByButton'])){
  62. $json['StopChargingByButton'] = (int)$_POST['StopChargingByButton'];
  63. }
  64. if(isset($_POST['FanControlPolicy'])){
  65. $json['FanControlPolicy'] = (int)$_POST['FanControlPolicy'];
  66. }
  67. if(isset($_POST['LocalWhiteCard0'])){
  68. $json['LocalWhiteCard0'] = isset($_POST['LocalWhiteCard0'])?$_POST['LocalWhiteCard0']:"";
  69. }
  70. if(isset($_POST['LocalWhiteCard1'])){
  71. $json['LocalWhiteCard1'] = isset($_POST['LocalWhiteCard1'])?$_POST['LocalWhiteCard1']:"";
  72. }
  73. if(isset($_POST['LocalWhiteCard2'])){
  74. $json['LocalWhiteCard2'] = isset($_POST['LocalWhiteCard2'])?$_POST['LocalWhiteCard2']:"";
  75. }
  76. if(isset($_POST['LocalWhiteCard3'])){
  77. $json['LocalWhiteCard3'] = isset($_POST['LocalWhiteCard3'])?$_POST['LocalWhiteCard3']:"";
  78. }
  79. if(isset($_POST['LocalWhiteCard4'])){
  80. $json['LocalWhiteCard4'] = isset($_POST['LocalWhiteCard4'])?$_POST['LocalWhiteCard4']:"";
  81. }
  82. if(isset($_POST['LocalWhiteCard5'])){
  83. $json['LocalWhiteCard5'] = isset($_POST['LocalWhiteCard5'])?$_POST['LocalWhiteCard5']:"";
  84. }
  85. if(isset($_POST['LocalWhiteCard6'])){
  86. $json['LocalWhiteCard6'] = isset($_POST['LocalWhiteCard6'])?$_POST['LocalWhiteCard6']:"";
  87. }
  88. if(isset($_POST['LocalWhiteCard7'])){
  89. $json['LocalWhiteCard7'] = isset($_POST['LocalWhiteCard7'])?$_POST['LocalWhiteCard7']:"";
  90. }
  91. if(isset($_POST['LocalWhiteCard8'])){
  92. $json['LocalWhiteCard8'] = isset($_POST['LocalWhiteCard8'])?$_POST['LocalWhiteCard8']:"";
  93. }
  94. if(isset($_POST['LocalWhiteCard9'])){
  95. $json['LocalWhiteCard9'] = isset($_POST['LocalWhiteCard9'])?$_POST['LocalWhiteCard9']:"";
  96. }
  97. if(isset($_POST['isEnable15118'])){
  98. $json['isEnable15118'] = (int)$_POST['isEnable15118'];
  99. }
  100. if(isset($_POST['isEnableR2R'])){
  101. $json['isEnableR2R'] = (int)$_POST['isEnableR2R'];
  102. }
  103. if(isset($_POST['isBilling'])){
  104. $json['isBilling'] = (int)$_POST['isBilling'];
  105. }
  106. if(isset($_POST['Currency'])){
  107. $json['Currency'] = (int)$_POST['Currency'];
  108. }
  109. if(isset($_POST['Fee0'])){
  110. $json['Fee0'] = isset($_POST['Fee0'])?round($_POST['Fee0'], 2):"";
  111. }
  112. if(isset($_POST['Fee1'])){
  113. $json['Fee1'] = isset($_POST['Fee1'])?round($_POST['Fee1'], 2):"";
  114. }
  115. if(isset($_POST['Fee2'])){
  116. $json['Fee2'] = isset($_POST['Fee2'])?round($_POST['Fee2'], 2):"";
  117. }
  118. if(isset($_POST['Fee3'])){
  119. $json['Fee3'] = isset($_POST['Fee3'])?round($_POST['Fee3'], 2):"";
  120. }
  121. if(isset($_POST['Fee4'])){
  122. $json['Fee4'] = isset($_POST['Fee4'])?round($_POST['Fee4'], 2):"";
  123. }
  124. if(isset($_POST['Fee5'])){
  125. $json['Fee5'] = isset($_POST['Fee5'])?round($_POST['Fee5'], 2):"";
  126. }
  127. if(isset($_POST['Fee6'])){
  128. $json['Fee6'] = isset($_POST['Fee6'])?round($_POST['Fee6'], 2):"";
  129. }
  130. if(isset($_POST['Fee7'])){
  131. $json['Fee7'] = isset($_POST['Fee7'])?round($_POST['Fee7'], 2):"";
  132. }
  133. if(isset($_POST['Fee8'])){
  134. $json['Fee8'] = isset($_POST['Fee8'])?round($_POST['Fee8'], 2):"";
  135. }
  136. if(isset($_POST['Fee9'])){
  137. $json['Fee9'] = isset($_POST['Fee9'])?round($_POST['Fee9'], 2):"";
  138. }
  139. if(isset($_POST['Fee10'])){
  140. $json['Fee10'] = isset($_POST['Fee10'])?round($_POST['Fee10'], 2):"";
  141. }
  142. if(isset($_POST['Fee11'])){
  143. $json['Fee11'] = isset($_POST['Fee11'])?round($_POST['Fee11'], 2):"";
  144. }
  145. if(isset($_POST['Fee12'])){
  146. $json['Fee12'] = isset($_POST['Fee12'])?round($_POST['Fee12'], 2):"";
  147. }
  148. if(isset($_POST['Fee13'])){
  149. $json['Fee13'] = isset($_POST['Fee13'])?round($_POST['Fee13'], 2):"";
  150. }
  151. if(isset($_POST['Fee14'])){
  152. $json['Fee14'] = isset($_POST['Fee14'])?round($_POST['Fee14'], 2):"";
  153. }
  154. if(isset($_POST['Fee15'])){
  155. $json['Fee15'] = isset($_POST['Fee15'])?round($_POST['Fee15'], 2):"";
  156. }
  157. if(isset($_POST['Fee16'])){
  158. $json['Fee16'] = isset($_POST['Fee16'])?round($_POST['Fee16'], 2):"";
  159. }
  160. if(isset($_POST['Fee17'])){
  161. $json['Fee17'] = isset($_POST['Fee17'])?round($_POST['Fee17'], 2):"";
  162. }
  163. if(isset($_POST['Fee18'])){
  164. $json['Fee18'] = isset($_POST['Fee18'])?round($_POST['Fee18'], 2):"";
  165. }
  166. if(isset($_POST['Fee19'])){
  167. $json['Fee19'] = isset($_POST['Fee19'])?round($_POST['Fee19'], 2):"";
  168. }
  169. if(isset($_POST['Fee20'])){
  170. $json['Fee20'] = isset($_POST['Fee20'])?round($_POST['Fee20'], 2):"";
  171. }
  172. if(isset($_POST['Fee21'])){
  173. $json['Fee21'] = isset($_POST['Fee21'])?round($_POST['Fee21'], 2):"";
  174. }
  175. if(isset($_POST['Fee22'])){
  176. $json['Fee22'] = isset($_POST['Fee22'])?round($_POST['Fee22'], 2):"";
  177. }
  178. if(isset($_POST['Fee23'])){
  179. $json['Fee23'] = isset($_POST['Fee23'])?round($_POST['Fee23'], 2):"";
  180. }
  181. $fCount = empty($_FILES['V2GPrivateKey']['tmp_name'][0]);
  182. if($fCount!=1){
  183. if ($_FILES["V2GPrivateKey"]["error"] > 0)
  184. {
  185. $jsone['result'] = "Error";
  186. $jsone['message'] = $_FILES["V2GPrivateKey"]["error"];
  187. echo json_encode($jsone);
  188. exit;
  189. }
  190. else if(strpos(exec('openssl rsa -noout -modulus -in '.$_FILES['V2GPrivateKey']['tmp_name']),"Modulus")===false){ //unable to load V2GPrivateKey
  191. $jsone['result'] = "Error";
  192. $jsone['message'] = "format of V2G Private Key is incorrect";
  193. echo json_encode($jsone);
  194. exit;
  195. }
  196. sleep(1);
  197. move_uploaded_file($_FILES["V2GPrivateKey"]["tmp_name"],"/Storage/certV2G.key");
  198. }
  199. $fCount = empty($_FILES['V2GRootCertificate']['tmp_name'][0]);
  200. if($fCount!=1){
  201. if ($_FILES["V2GRootCertificate"]["error"] > 0)
  202. {
  203. $jsone['result'] = "Error";
  204. $jsone['message'] = $_FILES["V2GRootCertificate"]["error"];
  205. echo json_encode($jsone);
  206. exit;
  207. }
  208. else if(strpos(exec('openssl x509 -noout -modulus -in '.$_FILES['V2GRootCertificate']['tmp_name']),"Modulus")===false){ //unable to load V2GRootCertificate
  209. $jsone['result'] = "Error";
  210. $jsone['message'] = "format of V2G Root Certificate is incorrect";
  211. echo json_encode($jsone);
  212. exit;
  213. }
  214. sleep(1);
  215. move_uploaded_file($_FILES["V2GRootCertificate"]["tmp_name"],"/Storage/rootCaV2g.pem");
  216. }
  217. $fCount = empty($_FILES['V2GCertificateChain']['tmp_name'][0]);
  218. if($fCount!=1){
  219. if ($_FILES["V2GCertificateChain"]["error"] > 0)
  220. {
  221. $jsone['result'] = "Error";
  222. $jsone['message'] = $_FILES["V2GCertificateChain"]["error"];
  223. echo json_encode($jsone);
  224. exit;
  225. }
  226. else if(strpos(exec('openssl x509 -noout -modulus -in '.$_FILES['V2GCertificateChain']['tmp_name']),"Modulus")===false){ //unable to load V2GCertificateChain
  227. $jsone['result'] = "Error";
  228. $jsone['message'] = "format of V2G Certificate Chain is incorrect";
  229. echo json_encode($jsone);
  230. exit;
  231. }
  232. sleep(1);
  233. move_uploaded_file($_FILES["V2GCertificateChain"]["tmp_name"],"/Storage/certV2g.pem");
  234. }
  235. // ob_start();
  236. shell_exec('sync;sync;sync');
  237. chdir("/root");
  238. $str_json=json_encode($json);
  239. if(isset($_POST['RemoteApi'])){
  240. exec("'./WebService' '21' '".$str_json."'",$output,$return_var);
  241. }
  242. else{
  243. exec("'./WebService' '2' '".$str_json."'",$output,$return_var);
  244. }
  245. if(count($output)!=0){
  246. $jsone['result'] = "Success";
  247. $jsone['message'] = $json;
  248. echo json_encode($jsone);
  249. exit;
  250. }
  251. else{
  252. $jsone['result'] = "Error";
  253. $jsone['message'] = "Something went wrong on machine";
  254. echo json_encode($jsone);
  255. return false;
  256. exit;
  257. }
  258. // ob_end_clean();
  259. }
  260. function checkMaxValue($id){
  261. if($_POST[$id] != ""){
  262. if(!is_numeric($_POST[$id])){
  263. $jsone['result'] = "Fail";
  264. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  265. echo json_encode($jsone);
  266. exit;
  267. }
  268. if($_POST[$id]>65535){
  269. $jsone['result'] = "Fail";
  270. $jsone['message'] = "You have entered a over value on " . $id . ", it should be less than 65535";
  271. echo json_encode($jsone);
  272. exit;
  273. }
  274. if($_POST[$id]<0){
  275. $jsone['result'] = "Fail";
  276. $jsone['message'] = "You have entered a over value on " . $id . ", it should be more than 0";
  277. echo json_encode($jsone);
  278. exit;
  279. }
  280. }
  281. }
  282. function checkValue($id){
  283. if($_POST[$id] != ""){
  284. if(strlen($_POST[$id])!=1){
  285. $jsone['result'] = "Fail";
  286. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  287. echo json_encode($jsone);
  288. exit;
  289. }
  290. if(!is_numeric($_POST[$id])){
  291. $jsone['result'] = "Fail";
  292. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  293. echo json_encode($jsone);
  294. exit;
  295. }
  296. }
  297. }
  298. function checkLength($id){
  299. if($_POST[$id] != ""){
  300. if(strlen($_POST[$id])>32){
  301. $jsone['result'] = "Fail";
  302. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be less than 32 bytes";
  303. echo json_encode($jsone);
  304. exit;
  305. }
  306. }
  307. }
  308. ?>