1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?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() {
- // $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'];
- checkip("Eth0IpAddress");
- checkip("Eth0SubmaskAddress");
- checkip("Eth0GatewayAddress");
- checkip("Eth1IpAddress");
- checkip("Eth1SubmaskAddress");
- checkip("Eth1GatewayAddress");
- checkip("WifiIpAddress");
- checkip("WifiSubmaskAddress");
- checkip("WifiGatewayAddress");
- checkip("TelcomIpAddress");
-
- // var_dump($json);echo "\n\n";
- // echo json_encode($json);
- $jsone['result'] = "Success";
- $jsone['message'] = $json;
- echo json_encode($jsone);
-
- ob_start();
-
- shell_exec('sync;sync;sync');
- //chdir("/home/phihong/Module_WebService");
- chdir("/root");
- $str_json=json_encode($json);var_dump($str_json);
- exec("'./WebService' '3' '".$str_json."'",$output,$return_var);
- // copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
- ob_end_clean();
- // print_r($output);
- //echo "OK";
- }
- 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;
- }
- }
- }
- ?>
|