123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?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() {
- checkip("Eth0IpAddress");
- checkip("Eth0SubmaskAddress");
- checkip("Eth0GatewayAddress");
- // checkip("Eth1IpAddress");
- // checkip("Eth1SubmaskAddress");
- // checkip("Eth1GatewayAddress");
- checkip("WifiIpAddress");
- checkip("WifiSubmaskAddress");
- checkip("WifiGatewayAddress");
- checkip("TelcomIpAddress");
- checkValue("Eth0DhcpClient");
- // checkValue("Eth1DhcpClient");
- checkValue("WifiMode");
- checkValue("WifiDhcpServer");
- checkValue("WifiDhcpClient");
- WifiMode_changed();
- // $json = json_decode(file_get_contents("charging.txt"), true);
- // $json = string[];
- // $json['FtpServer'] = $_POST['FtpServer'];
- $json['Eth0DhcpClient'] = $_POST['Eth0DhcpClient'];
- $json['Eth0IpAddress'] = $_POST['Eth0IpAddress'];
- $json['Eth0SubmaskAddress'] = $_POST['Eth0SubmaskAddress'];
- $json['Eth0GatewayAddress'] = $_POST['Eth0GatewayAddress'];
- // $json['Eth1DhcpClient'] = $_POST['Eth1DhcpClient'];
- // $json['Eth1IpAddress'] = $_POST['Eth1IpAddress'];
- // $json['Eth1SubmaskAddress'] = $_POST['Eth1SubmaskAddress'];
- // $json['Eth1GatewayAddress'] = $_POST['Eth1GatewayAddress'];
- $json['WifiMode'] = $_POST['WifiMode'];
- $json['WifiSsid'] = $_POST['WifiSsid'];
- $json['WifiPassword'] = $_POST['WifiPassword'];
- $json['WifiDhcpServer'] = $_POST['WifiDhcpServer'];
- $json['WifiDhcpClient'] = $_POST['WifiDhcpClient'];
- $json['WifiIpAddress'] = $_POST['WifiIpAddress'];
- $json['WifiSubmaskAddress'] = $_POST['WifiSubmaskAddress'];
- $json['WifiGatewayAddress'] = $_POST['WifiGatewayAddress'];
- $json['TelcomApn'] = $_POST['TelcomApn'];
- $json['TelcomChapPapId'] = $_POST['TelcomChapPapId'];
- $json['TelcomChapPapPwd'] = $_POST['TelcomChapPapPwd'];
- $json['TelcomIpAddress'] = $_POST['TelcomIpAddress'];
- // ob_start();
-
- shell_exec('sync;sync;sync');
- chdir("/root");
- $str_json=json_encode($json);
- exec("'./WebService' '3' '".$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 checkip($id){
- $ip=$_POST[$id];
- if($_POST[$id] != ""){
- if(ip2long($ip)){
-
- }
- else{
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered an invalid IP address on " . $id;
- echo json_encode($jsone);
- exit;
- }
- }
- }
- 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 WifiMode_changed(){
- if($_POST['WifiMode']=="0"){
- $_POST['WifiDhcpServer']=1;
- $_POST['WifiDhcpClient']=1;
- $_POST['WifiSsid']="";
- $_POST['WifiPassword']="";
- }
- if($_POST['WifiMode']=="1"){
- $_POST['WifiDhcpServer']=1;
- $_POST['WifiDhcpClient']=0;
- }
- if($_POST['WifiMode']=="2"){
- $_POST['WifiDhcpServer']=0;
- $_POST['WifiDhcpClient']=1;
- $_POST['WifiSsid']="";
- $_POST['WifiPassword']="";
- }
- }
- ?>
|