set_charging_action.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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['isBilling'])){
  98. $json['isBilling'] = (int)$_POST['isBilling'];
  99. }
  100. if(isset($_POST['Currency'])){
  101. $json['Currency'] = (int)$_POST['Currency'];
  102. }
  103. if(isset($_POST['Fee0'])){
  104. $json['Fee0'] = isset($_POST['Fee0'])?round($_POST['Fee0'], 2):"";
  105. }
  106. if(isset($_POST['Fee1'])){
  107. $json['Fee1'] = isset($_POST['Fee1'])?round($_POST['Fee1'], 2):"";
  108. }
  109. if(isset($_POST['Fee2'])){
  110. $json['Fee2'] = isset($_POST['Fee2'])?round($_POST['Fee2'], 2):"";
  111. }
  112. if(isset($_POST['Fee3'])){
  113. $json['Fee3'] = isset($_POST['Fee3'])?round($_POST['Fee3'], 2):"";
  114. }
  115. if(isset($_POST['Fee4'])){
  116. $json['Fee4'] = isset($_POST['Fee4'])?round($_POST['Fee4'], 2):"";
  117. }
  118. if(isset($_POST['Fee5'])){
  119. $json['Fee5'] = isset($_POST['Fee5'])?round($_POST['Fee5'], 2):"";
  120. }
  121. if(isset($_POST['Fee6'])){
  122. $json['Fee6'] = isset($_POST['Fee6'])?round($_POST['Fee6'], 2):"";
  123. }
  124. if(isset($_POST['Fee7'])){
  125. $json['Fee7'] = isset($_POST['Fee7'])?round($_POST['Fee7'], 2):"";
  126. }
  127. if(isset($_POST['Fee8'])){
  128. $json['Fee8'] = isset($_POST['Fee8'])?round($_POST['Fee8'], 2):"";
  129. }
  130. if(isset($_POST['Fee9'])){
  131. $json['Fee9'] = isset($_POST['Fee9'])?round($_POST['Fee9'], 2):"";
  132. }
  133. if(isset($_POST['Fee10'])){
  134. $json['Fee10'] = isset($_POST['Fee10'])?round($_POST['Fee10'], 2):"";
  135. }
  136. if(isset($_POST['Fee11'])){
  137. $json['Fee11'] = isset($_POST['Fee11'])?round($_POST['Fee11'], 2):"";
  138. }
  139. if(isset($_POST['Fee12'])){
  140. $json['Fee12'] = isset($_POST['Fee12'])?round($_POST['Fee12'], 2):"";
  141. }
  142. if(isset($_POST['Fee13'])){
  143. $json['Fee13'] = isset($_POST['Fee13'])?round($_POST['Fee13'], 2):"";
  144. }
  145. if(isset($_POST['Fee14'])){
  146. $json['Fee14'] = isset($_POST['Fee14'])?round($_POST['Fee14'], 2):"";
  147. }
  148. if(isset($_POST['Fee15'])){
  149. $json['Fee15'] = isset($_POST['Fee15'])?round($_POST['Fee15'], 2):"";
  150. }
  151. if(isset($_POST['Fee16'])){
  152. $json['Fee16'] = isset($_POST['Fee16'])?round($_POST['Fee16'], 2):"";
  153. }
  154. if(isset($_POST['Fee17'])){
  155. $json['Fee17'] = isset($_POST['Fee17'])?round($_POST['Fee17'], 2):"";
  156. }
  157. if(isset($_POST['Fee18'])){
  158. $json['Fee18'] = isset($_POST['Fee18'])?round($_POST['Fee18'], 2):"";
  159. }
  160. if(isset($_POST['Fee19'])){
  161. $json['Fee19'] = isset($_POST['Fee19'])?round($_POST['Fee19'], 2):"";
  162. }
  163. if(isset($_POST['Fee20'])){
  164. $json['Fee20'] = isset($_POST['Fee20'])?round($_POST['Fee20'], 2):"";
  165. }
  166. if(isset($_POST['Fee21'])){
  167. $json['Fee21'] = isset($_POST['Fee21'])?round($_POST['Fee21'], 2):"";
  168. }
  169. if(isset($_POST['Fee22'])){
  170. $json['Fee22'] = isset($_POST['Fee22'])?round($_POST['Fee22'], 2):"";
  171. }
  172. if(isset($_POST['Fee23'])){
  173. $json['Fee23'] = isset($_POST['Fee23'])?round($_POST['Fee23'], 2):"";
  174. }
  175. exec('openssl rsa -noout -modulus -in /var/www/private.key');
  176. exec('openssl x509 -noout -modulus -in /var/www/cacert.pem');
  177. $fCount = empty($_FILES['private_key']['tmp_name'][0]);
  178. if($fCount!=1){
  179. if ($_FILES["private_key"]["error"] > 0)
  180. {
  181. $jsone['result'] = "Error";
  182. $jsone['message'] = $_FILES["private_key"]["error"];
  183. echo json_encode($jsone);
  184. exit;
  185. }
  186. else if(strpos(exec('openssl rsa -noout -modulus -in '.$_FILES['private_key']['name']),"Modulus")===false){ //unable to load Private Key
  187. $jsone['result'] = "Error";
  188. $jsone['message'] = "format of Private Key is incorrect";
  189. echo json_encode($jsone);
  190. exit;
  191. }
  192. sleep(1);
  193. move_uploaded_file($_FILES["private_key"]["tmp_name"],"/Storage/OCPP/certCP.key");
  194. }
  195. $fCount = empty($_FILES['certificate']['tmp_name'][0]);
  196. if($fCount!=1){
  197. if ($_FILES["certificate"]["error"] > 0)
  198. {
  199. $jsone['result'] = "Error";
  200. $jsone['message'] = $_FILES["certificate"]["error"];
  201. echo json_encode($jsone);
  202. exit;
  203. }
  204. else if(strpos(exec('openssl x509 -noout -modulus -in '.$_FILES['certificate']['name']),"Modulus")===false){ //unable to load certificate
  205. $jsone['result'] = "Error";
  206. $jsone['message'] = "format of Certificate is incorrect";
  207. echo json_encode($jsone);
  208. exit;
  209. }
  210. sleep(1);
  211. move_uploaded_file($_FILES["certificate"]["tmp_name"],"/Storage/OCPP/certCP.pem");
  212. }
  213. $fCount = empty($_FILES['V2GPrivateKey']['tmp_name'][0]);
  214. if($fCount!=1){
  215. if ($_FILES["V2GPrivateKey"]["error"] > 0)
  216. {
  217. $jsone['result'] = "Error";
  218. $jsone['message'] = $_FILES["V2GPrivateKey"]["error"];
  219. echo json_encode($jsone);
  220. exit;
  221. }
  222. else if(strpos(exec('openssl rsa -noout -modulus -in '.$_FILES['V2GPrivateKey']['name']),"Modulus")===false){ //unable to load V2GPrivateKey
  223. $jsone['result'] = "Error";
  224. $jsone['message'] = "format of V2G Private Key is incorrect";
  225. echo json_encode($jsone);
  226. exit;
  227. }
  228. sleep(1);
  229. move_uploaded_file($_FILES["V2GPrivateKey"]["tmp_name"],"/Storage/certV2G.key");
  230. }
  231. $fCount = empty($_FILES['V2GRootCertificate']['tmp_name'][0]);
  232. if($fCount!=1){
  233. if ($_FILES["V2GRootCertificate"]["error"] > 0)
  234. {
  235. $jsone['result'] = "Error";
  236. $jsone['message'] = $_FILES["V2GRootCertificate"]["error"];
  237. echo json_encode($jsone);
  238. exit;
  239. }
  240. else if(strpos(exec('openssl x509 -noout -modulus -in '.$_FILES['V2GRootCertificate']['name']),"Modulus")===false){ //unable to load V2GRootCertificate
  241. $jsone['result'] = "Error";
  242. $jsone['message'] = "format of V2G Root Certificate is incorrect";
  243. echo json_encode($jsone);
  244. exit;
  245. }
  246. sleep(1);
  247. move_uploaded_file($_FILES["V2GRootCertificate"]["tmp_name"],"/Storage/rootCaV2g.pem");
  248. }
  249. $fCount = empty($_FILES['V2GCertificateChain']['tmp_name'][0]);
  250. if($fCount!=1){
  251. if ($_FILES["V2GCertificateChain"]["error"] > 0)
  252. {
  253. $jsone['result'] = "Error";
  254. $jsone['message'] = $_FILES["V2GCertificateChain"]["error"];
  255. echo json_encode($jsone);
  256. exit;
  257. }
  258. else if(strpos(exec('openssl x509 -noout -modulus -in '.$_FILES['V2GCertificateChain']['name']),"Modulus")===false){ //unable to load V2GCertificateChain
  259. $jsone['result'] = "Error";
  260. $jsone['message'] = "format of V2G Certificate Chain is incorrect";
  261. echo json_encode($jsone);
  262. exit;
  263. }
  264. sleep(1);
  265. move_uploaded_file($_FILES["V2GCertificateChain"]["tmp_name"],"/Storage/certV2g.pem");
  266. }
  267. $fCount = empty($_FILES['MORootCertificate']['tmp_name'][0]);
  268. if($fCount!=1){
  269. if ($_FILES["MORootCertificate"]["error"] > 0)
  270. {
  271. $jsone['result'] = "Error";
  272. $jsone['message'] = $_FILES["MORootCertificate"]["error"];
  273. echo json_encode($jsone);
  274. exit;
  275. }
  276. else if(strpos(exec('openssl x509 -noout -modulus -in '.$_FILES['MORootCertificate']['name']),"Modulus")===false){ //unable to load MORootCertificate
  277. $jsone['result'] = "Error";
  278. $jsone['message'] = "format of MO Root Certificate is incorrect";
  279. echo json_encode($jsone);
  280. exit;
  281. }
  282. sleep(1);
  283. move_uploaded_file($_FILES["MORootCertificate"]["tmp_name"],"/Storage/rootCaMo.pem");
  284. }
  285. $fCount = empty($_FILES['CSRootCertificate']['tmp_name'][0]);
  286. if($fCount!=1){
  287. if ($_FILES["CSRootCertificate"]["error"] > 0)
  288. {
  289. $jsone['result'] = "Error";
  290. $jsone['message'] = $_FILES["CSRootCertificate"]["error"];
  291. echo json_encode($jsone);
  292. exit;
  293. }
  294. else if(strpos(exec('openssl x509 -noout -modulus -in '.$_FILES['CSRootCertificate']['name']),"Modulus")===false){ //unable to load CSRootCertificate
  295. $jsone['result'] = "Error";
  296. $jsone['message'] = "format of CS Root Certificate is incorrect";
  297. echo json_encode($jsone);
  298. exit;
  299. }
  300. sleep(1);
  301. move_uploaded_file($_FILES["CSRootCertificate"]["tmp_name"],"/Storage/OCPP/rootCaCs.pem");
  302. }
  303. $fCount = empty($_FILES['ManufacturerRootCertificate']['tmp_name'][0]);
  304. if($fCount!=1){
  305. if ($_FILES["ManufacturerRootCertificate"]["error"] > 0)
  306. {
  307. $jsone['result'] = "Error";
  308. $jsone['message'] = $_FILES["ManufacturerRootCertificate"]["error"];
  309. echo json_encode($jsone);
  310. exit;
  311. }
  312. else if(strpos(exec('openssl x509 -noout -modulus -in '.$_FILES['ManufacturerRootCertificate']['name']),"Modulus")===false){ //unable to load ManufacturerRootCertificate
  313. $jsone['result'] = "Error";
  314. $jsone['message'] = "format of Manufacturer Root Certificate is incorrect";
  315. echo json_encode($jsone);
  316. exit;
  317. }
  318. sleep(1);
  319. move_uploaded_file($_FILES["ManufacturerRootCertificate"]["tmp_name"],"/Storage/OCPP/rootCaMf.pem");
  320. }
  321. // ob_start();
  322. shell_exec('sync;sync;sync');
  323. chdir("/root");
  324. $str_json=json_encode($json);
  325. if(isset($_POST['RemoteApi'])){
  326. exec("'./WebService' '21' '".$str_json."'",$output,$return_var);
  327. }
  328. else{
  329. exec("'./WebService' '2' '".$str_json."'",$output,$return_var);
  330. }
  331. if(count($output)!=0){
  332. $jsone['result'] = "Success";
  333. $jsone['message'] = $json;
  334. echo json_encode($jsone);
  335. exit;
  336. }
  337. else{
  338. $jsone['result'] = "Error";
  339. $jsone['message'] = "Something went wrong on machine";
  340. echo json_encode($jsone);
  341. return false;
  342. exit;
  343. }
  344. // ob_end_clean();
  345. }
  346. function checkMaxValue($id){
  347. if($_POST[$id] != ""){
  348. if(!is_numeric($_POST[$id])){
  349. $jsone['result'] = "Fail";
  350. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  351. echo json_encode($jsone);
  352. exit;
  353. }
  354. if($_POST[$id]>65535){
  355. $jsone['result'] = "Fail";
  356. $jsone['message'] = "You have entered a over value on " . $id . ", it should be less than 65535";
  357. echo json_encode($jsone);
  358. exit;
  359. }
  360. if($_POST[$id]<0){
  361. $jsone['result'] = "Fail";
  362. $jsone['message'] = "You have entered a over value on " . $id . ", it should be more than 0";
  363. echo json_encode($jsone);
  364. exit;
  365. }
  366. }
  367. }
  368. function checkValue($id){
  369. if($_POST[$id] != ""){
  370. if(strlen($_POST[$id])!=1){
  371. $jsone['result'] = "Fail";
  372. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  373. echo json_encode($jsone);
  374. exit;
  375. }
  376. if(!is_numeric($_POST[$id])){
  377. $jsone['result'] = "Fail";
  378. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  379. echo json_encode($jsone);
  380. exit;
  381. }
  382. }
  383. }
  384. function checkLength($id){
  385. if($_POST[$id] != ""){
  386. if(strlen($_POST[$id])>32){
  387. $jsone['result'] = "Fail";
  388. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be less than 32 bytes";
  389. echo json_encode($jsone);
  390. exit;
  391. }
  392. }
  393. }
  394. ?>