123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- <?php
- // 設置資料類型 json,編碼格式 utf-8
- header('Content-Type: application/json; charset=UTF-8');
-
- // 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
- // $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
- if ($_SERVER['REQUEST_METHOD'] == "GET") {
- create();
- } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
- create();
- }
- // 新建員工
- function create() {
- checkLength("LocalWhiteCard0");
- checkLength("LocalWhiteCard1");
- checkLength("LocalWhiteCard2");
- checkLength("LocalWhiteCard3");
- checkLength("LocalWhiteCard4");
- checkLength("LocalWhiteCard5");
- checkLength("LocalWhiteCard6");
- checkLength("LocalWhiteCard7");
- checkLength("LocalWhiteCard8");
- checkLength("LocalWhiteCard9");
- checkMaxValue("MaxChargingEnergy");
- checkMaxValue("MaxChargingPower");
- checkMaxValue("MaxChargingCurrent");
- if(substr($_POST['ModelName'],-2)=="PS"){
- checkMaxValue("MaxChargingVoltage");
- }
- checkMaxValue("AcMaxChargingCurrent");
- checkMaxValue("MaxChargingDuration");
- checkMaxValue("MaxChargingSoc");
- checkValue("StopChargingByButton");
- checkValue("FanControlPolicy");
- if(substr($_POST['ModelName'],0,1)=="A" && $_POST['MaxChargingCurrent']<6 && $_POST['MaxChargingCurrent']!=0){
- $jsone['result'] = "Fail";
- $jsone['message'] = "MaxChargingCurrent must > 6";
- echo json_encode($jsone);
- exit;
- }
- if(isset($_POST['MaxChargingEnergy'])){
- $json['MaxChargingEnergy'] = (int)$_POST['MaxChargingEnergy'];
- }
- if(isset($_POST['MaxChargingPower'])){
- $json['MaxChargingPower'] = (int)$_POST['MaxChargingPower'];
- }
- if(isset($_POST['MaxChargingCurrent'])){
- $json['MaxChargingCurrent'] = (int)$_POST['MaxChargingCurrent'];
- }
- if(isset($_POST['MaxChargingVoltage'])){
- $json['MaxChargingVoltage'] = (int)$_POST['MaxChargingVoltage'];
- }
- if(isset($_POST['AcMaxChargingCurrent'])){
- $json['AcMaxChargingCurrent'] = (int)$_POST['AcMaxChargingCurrent'];
- }
- if(isset($_POST['MaxChargingDuration'])){
- $json['MaxChargingDuration'] = (int)$_POST['MaxChargingDuration'];
- }
- if(isset($_POST['MaxChargingSoc'])){
- $json['MaxChargingSoc'] = (int)$_POST['MaxChargingSoc'];
- }
- if(isset($_POST['StopChargingByButton'])){
- $json['StopChargingByButton'] = (int)$_POST['StopChargingByButton'];
- }
- if(isset($_POST['FanControlPolicy'])){
- $json['FanControlPolicy'] = (int)$_POST['FanControlPolicy'];
- }
- if(isset($_POST['LocalWhiteCard0'])){
- $json['LocalWhiteCard0'] = isset($_POST['LocalWhiteCard0'])?$_POST['LocalWhiteCard0']:"";
- }
- if(isset($_POST['LocalWhiteCard1'])){
- $json['LocalWhiteCard1'] = isset($_POST['LocalWhiteCard1'])?$_POST['LocalWhiteCard1']:"";
- }
- if(isset($_POST['LocalWhiteCard2'])){
- $json['LocalWhiteCard2'] = isset($_POST['LocalWhiteCard2'])?$_POST['LocalWhiteCard2']:"";
- }
- if(isset($_POST['LocalWhiteCard3'])){
- $json['LocalWhiteCard3'] = isset($_POST['LocalWhiteCard3'])?$_POST['LocalWhiteCard3']:"";
- }
- if(isset($_POST['LocalWhiteCard4'])){
- $json['LocalWhiteCard4'] = isset($_POST['LocalWhiteCard4'])?$_POST['LocalWhiteCard4']:"";
- }
- if(isset($_POST['LocalWhiteCard5'])){
- $json['LocalWhiteCard5'] = isset($_POST['LocalWhiteCard5'])?$_POST['LocalWhiteCard5']:"";
- }
- if(isset($_POST['LocalWhiteCard6'])){
- $json['LocalWhiteCard6'] = isset($_POST['LocalWhiteCard6'])?$_POST['LocalWhiteCard6']:"";
- }
- if(isset($_POST['LocalWhiteCard7'])){
- $json['LocalWhiteCard7'] = isset($_POST['LocalWhiteCard7'])?$_POST['LocalWhiteCard7']:"";
- }
- if(isset($_POST['LocalWhiteCard8'])){
- $json['LocalWhiteCard8'] = isset($_POST['LocalWhiteCard8'])?$_POST['LocalWhiteCard8']:"";
- }
- if(isset($_POST['LocalWhiteCard9'])){
- $json['LocalWhiteCard9'] = isset($_POST['LocalWhiteCard9'])?$_POST['LocalWhiteCard9']:"";
- }
- if(isset($_POST['isEnable15118'])){
- $json['isEnable15118'] = (int)$_POST['isEnable15118'];
- }
- if(isset($_POST['isEnableR2R'])){
- $json['isEnableR2R'] = (int)$_POST['isEnableR2R'];
- }
- if(isset($_POST['isBilling'])){
- $json['isBilling'] = (int)$_POST['isBilling'];
- }
- if(isset($_POST['Currency'])){
- $json['Currency'] = (int)$_POST['Currency'];
- }
- if(isset($_POST['Fee0'])){
- $json['Fee0'] = isset($_POST['Fee0'])?round($_POST['Fee0'], 2):"";
- }
- if(isset($_POST['Fee1'])){
- $json['Fee1'] = isset($_POST['Fee1'])?round($_POST['Fee1'], 2):"";
- }
- if(isset($_POST['Fee2'])){
- $json['Fee2'] = isset($_POST['Fee2'])?round($_POST['Fee2'], 2):"";
- }
- if(isset($_POST['Fee3'])){
- $json['Fee3'] = isset($_POST['Fee3'])?round($_POST['Fee3'], 2):"";
- }
- if(isset($_POST['Fee4'])){
- $json['Fee4'] = isset($_POST['Fee4'])?round($_POST['Fee4'], 2):"";
- }
- if(isset($_POST['Fee5'])){
- $json['Fee5'] = isset($_POST['Fee5'])?round($_POST['Fee5'], 2):"";
- }
- if(isset($_POST['Fee6'])){
- $json['Fee6'] = isset($_POST['Fee6'])?round($_POST['Fee6'], 2):"";
- }
- if(isset($_POST['Fee7'])){
- $json['Fee7'] = isset($_POST['Fee7'])?round($_POST['Fee7'], 2):"";
- }
- if(isset($_POST['Fee8'])){
- $json['Fee8'] = isset($_POST['Fee8'])?round($_POST['Fee8'], 2):"";
- }
- if(isset($_POST['Fee9'])){
- $json['Fee9'] = isset($_POST['Fee9'])?round($_POST['Fee9'], 2):"";
- }
- if(isset($_POST['Fee10'])){
- $json['Fee10'] = isset($_POST['Fee10'])?round($_POST['Fee10'], 2):"";
- }
- if(isset($_POST['Fee11'])){
- $json['Fee11'] = isset($_POST['Fee11'])?round($_POST['Fee11'], 2):"";
- }
- if(isset($_POST['Fee12'])){
- $json['Fee12'] = isset($_POST['Fee12'])?round($_POST['Fee12'], 2):"";
- }
- if(isset($_POST['Fee13'])){
- $json['Fee13'] = isset($_POST['Fee13'])?round($_POST['Fee13'], 2):"";
- }
- if(isset($_POST['Fee14'])){
- $json['Fee14'] = isset($_POST['Fee14'])?round($_POST['Fee14'], 2):"";
- }
- if(isset($_POST['Fee15'])){
- $json['Fee15'] = isset($_POST['Fee15'])?round($_POST['Fee15'], 2):"";
- }
- if(isset($_POST['Fee16'])){
- $json['Fee16'] = isset($_POST['Fee16'])?round($_POST['Fee16'], 2):"";
- }
- if(isset($_POST['Fee17'])){
- $json['Fee17'] = isset($_POST['Fee17'])?round($_POST['Fee17'], 2):"";
- }
- if(isset($_POST['Fee18'])){
- $json['Fee18'] = isset($_POST['Fee18'])?round($_POST['Fee18'], 2):"";
- }
- if(isset($_POST['Fee19'])){
- $json['Fee19'] = isset($_POST['Fee19'])?round($_POST['Fee19'], 2):"";
- }
- if(isset($_POST['Fee20'])){
- $json['Fee20'] = isset($_POST['Fee20'])?round($_POST['Fee20'], 2):"";
- }
- if(isset($_POST['Fee21'])){
- $json['Fee21'] = isset($_POST['Fee21'])?round($_POST['Fee21'], 2):"";
- }
- if(isset($_POST['Fee22'])){
- $json['Fee22'] = isset($_POST['Fee22'])?round($_POST['Fee22'], 2):"";
- }
- if(isset($_POST['Fee23'])){
- $json['Fee23'] = isset($_POST['Fee23'])?round($_POST['Fee23'], 2):"";
- }
- $fCount = empty($_FILES['V2GPrivateKey']['tmp_name'][0]);
- if($fCount!=1){
- if ($_FILES["V2GPrivateKey"]["error"] > 0)
- {
- $jsone['result'] = "Error";
- $jsone['message'] = $_FILES["V2GPrivateKey"]["error"];
- echo json_encode($jsone);
- exit;
- }
- else if(strpos(exec('openssl rsa -noout -modulus -in '.$_FILES['V2GPrivateKey']['tmp_name']),"Modulus")===false){ //unable to load V2GPrivateKey
- $jsone['result'] = "Error";
- $jsone['message'] = "format of V2G Private Key is incorrect";
- echo json_encode($jsone);
- exit;
- }
- sleep(1);
- move_uploaded_file($_FILES["V2GPrivateKey"]["tmp_name"],"/Storage/certV2G.key");
- }
- $fCount = empty($_FILES['V2GRootCertificate']['tmp_name'][0]);
- if($fCount!=1){
- if ($_FILES["V2GRootCertificate"]["error"] > 0)
- {
- $jsone['result'] = "Error";
- $jsone['message'] = $_FILES["V2GRootCertificate"]["error"];
- echo json_encode($jsone);
- exit;
- }
- else if(strpos(exec('openssl x509 -noout -modulus -in '.$_FILES['V2GRootCertificate']['tmp_name']),"Modulus")===false){ //unable to load V2GRootCertificate
- $jsone['result'] = "Error";
- $jsone['message'] = "format of V2G Root Certificate is incorrect";
- echo json_encode($jsone);
- exit;
- }
- sleep(1);
- move_uploaded_file($_FILES["V2GRootCertificate"]["tmp_name"],"/Storage/rootCaV2g.pem");
- }
- $fCount = empty($_FILES['V2GCertificateChain']['tmp_name'][0]);
- if($fCount!=1){
- if ($_FILES["V2GCertificateChain"]["error"] > 0)
- {
- $jsone['result'] = "Error";
- $jsone['message'] = $_FILES["V2GCertificateChain"]["error"];
- echo json_encode($jsone);
- exit;
- }
- else if(strpos(exec('openssl x509 -noout -modulus -in '.$_FILES['V2GCertificateChain']['tmp_name']),"Modulus")===false){ //unable to load V2GCertificateChain
- $jsone['result'] = "Error";
- $jsone['message'] = "format of V2G Certificate Chain is incorrect";
- echo json_encode($jsone);
- exit;
- }
- sleep(1);
- move_uploaded_file($_FILES["V2GCertificateChain"]["tmp_name"],"/Storage/certV2g.pem");
- }
- // ob_start();
-
- shell_exec('sync;sync;sync');
- chdir("/root");
- $str_json=json_encode($json);
- if(isset($_POST['RemoteApi'])){
- exec("'./WebService' '21' '".$str_json."'",$output,$return_var);
- }
- else{
- exec("'./WebService' '2' '".$str_json."'",$output,$return_var);
- }
- if(count($output)!=0){
- $jsone['result'] = "Success";
- $jsone['message'] = $json;
- echo json_encode($jsone);
- exit;
- }
- else{
- $jsone['result'] = "Error";
- $jsone['message'] = "Something went wrong on machine";
- echo json_encode($jsone);
- return false;
- exit;
- }
- // ob_end_clean();
- }
- function checkMaxValue($id){
- if($_POST[$id] != ""){
- if(!is_numeric($_POST[$id])){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- echo json_encode($jsone);
- exit;
- }
- if($_POST[$id]>65535){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a over value on " . $id . ", it should be less than 65535";
- echo json_encode($jsone);
- exit;
- }
- if($_POST[$id]<0){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a over value on " . $id . ", it should be more than 0";
- echo json_encode($jsone);
- exit;
- }
- }
- }
- function checkValue($id){
- if($_POST[$id] != ""){
- if(strlen($_POST[$id])!=1){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- echo json_encode($jsone);
- exit;
- }
- if(!is_numeric($_POST[$id])){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- echo json_encode($jsone);
- exit;
- }
- }
- }
- function checkLength($id){
- if($_POST[$id] != ""){
- if(strlen($_POST[$id])>32){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be less than 32 bytes";
- echo json_encode($jsone);
- exit;
- }
- }
- }
- ?>
|