123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?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");
- // $json = json_decode(file_get_contents("charging.txt"), true);
- // $json = string[];
- $json['FtpServer'] = $_POST['FtpServer'];
- $json['Eth0DhcpClient'] = chr($_POST['Eth0DhcpClient']);
- $json['Eth0IpAddress'] = $_POST['Eth0IpAddress'];
- $json['Eth0SubmaskAddress'] = $_POST['Eth0SubmaskAddress'];
- $json['Eth0GatewayAddress'] = $_POST['Eth0GatewayAddress'];
- $json['Eth1DhcpClient'] = chr($_POST['Eth1DhcpClient']);
- $json['Eth1IpAddress'] = $_POST['Eth1IpAddress'];
- $json['Eth1SubmaskAddress'] = $_POST['Eth1SubmaskAddress'];
- $json['Eth1GatewayAddress'] = $_POST['Eth1GatewayAddress'];
- $json['WifiMode'] = chr($_POST['WifiMode']);
- $json['WifiSsid'] = $_POST['WifiSsid'];
- $json['WifiPassword'] = $_POST['WifiPassword'];
- $json['WifiDhcpServer'] = chr($_POST['WifiDhcpServer']);
- $json['WifiDhcpClient'] = chr($_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'];
-
- // 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;
- }
- }
- }
- 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;
- }
- }
- ?>
|