123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?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() {
- $pattern="/^(ws|wss):\/\/((([0-9]{1,3}\.){3}[0-9]{1,3})|(([a-zA-Z0-9]+(([\-]?[a-zA-Z0-9]+)*\.)+)*[a-zA-Z]{2,}))+/";
- if($_POST['OcppServerURL']!=""){
- if(!preg_match($pattern, $_POST['OcppServerURL'])){
- $jsone['result'] = "Fail";
- $jsone['message'] = "OcppServerURL format error, fill it with 'ws://' or 'wss://'";
- echo json_encode($jsone);
- return false;
- }
- }
- checkValue("OfflinePolicy");
- checkLength("ChargeBoxId",25);
- checkLength("chargePointVendor",20);
- // $json = json_decode(file_get_contents("charging.txt"), true);
- // $json = string[];
- $json['BackendConnTimeout'] = (int)$_POST['BackendConnTimeout'];
- $json['OfflinePolicy'] = (int)$_POST['OfflinePolicy'];
- $json['OfflineMaxChargeEnergy'] = (int)$_POST['OfflineMaxChargeEnergy'];
- $json['OfflineMaxChargeDuration'] = (int)$_POST['OfflineMaxChargeDuration'];
- // $json['OcppConnStatus'] = $_POST['OcppConnStatus'];
- $json['OcppServerURL'] = $_POST['OcppServerURL'];
- $json['ChargeBoxId'] = $_POST['ChargeBoxId'];
- $json['chargePointVendor'] = $_POST['chargePointVendor'];
- // ob_start();
-
- shell_exec('sync;sync;sync');
- chdir("/root");
- $str_json=json_encode($json);//var_dump($str_json);
- exec("'./WebService' '4' '".$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 checkValue($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(!ereg("[0-9]",$_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,$value){
- if(strlen($_POST[$id])>$value){
- $jsone['result'] = "Fail";
- $jsone['message'] = "Length of " . $id . " should be less than ".$value;
- echo json_encode($jsone);
- exit;
- }
- }
- ?>
|