set_network_action.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // 設置資料類型 json,編碼格式 utf-8
  3. header('Content-Type: application/json; charset=UTF-8');
  4. // 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
  5. // $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
  6. if ($_SERVER['REQUEST_METHOD'] == "GET") {
  7. create();
  8. } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
  9. create();
  10. }
  11. // 新建員工
  12. function create() {
  13. // $json = json_decode(file_get_contents("charging.txt"), true);
  14. // $json = string[];
  15. $json['FtpServer'] = $_POST['FtpServer'];
  16. $json['Eth0DhcpClient'] = $_POST['Eth0DhcpClient'];
  17. $json['Eth0IpAddress'] = $_POST['Eth0IpAddress'];
  18. $json['Eth0SubmaskAddress'] = $_POST['Eth0SubmaskAddress'];
  19. $json['Eth0GatewayAddress'] = $_POST['Eth0GatewayAddress'];
  20. $json['Eth1DhcpClient'] = $_POST['Eth1DhcpClient'];
  21. $json['Eth1IpAddress'] = $_POST['Eth1IpAddress'];
  22. $json['Eth1SubmaskAddress'] = $_POST['Eth1SubmaskAddress'];
  23. $json['Eth1GatewayAddress'] = $_POST['Eth1GatewayAddress'];
  24. $json['WifiMode'] = $_POST['WifiMode'];
  25. $json['WifiSsid'] = $_POST['WifiSsid'];
  26. $json['WifiPassword'] = $_POST['WifiPassword'];
  27. $json['WifiDhcpServer'] = $_POST['WifiDhcpServer'];
  28. $json['WifiDhcpClient'] = $_POST['WifiDhcpClient'];
  29. $json['WifiIpAddress'] = $_POST['WifiIpAddress'];
  30. $json['WifiSubmaskAddress'] = $_POST['WifiSubmaskAddress'];
  31. $json['WifiGatewayAddress'] = $_POST['WifiGatewayAddress'];
  32. $json['TelcomApn'] = $_POST['TelcomApn'];
  33. $json['TelcomChapPapId'] = $_POST['TelcomChapPapId'];
  34. $json['TelcomChapPapPwd'] = $_POST['TelcomChapPapPwd'];
  35. $json['TelcomIpAddress'] = $_POST['TelcomIpAddress'];
  36. checkip("Eth0IpAddress");
  37. checkip("Eth0SubmaskAddress");
  38. checkip("Eth0GatewayAddress");
  39. checkip("Eth1IpAddress");
  40. checkip("Eth1SubmaskAddress");
  41. checkip("Eth1GatewayAddress");
  42. checkip("WifiIpAddress");
  43. checkip("WifiSubmaskAddress");
  44. checkip("WifiGatewayAddress");
  45. checkip("TelcomIpAddress");
  46. // var_dump($json);echo "\n\n";
  47. // echo json_encode($json);
  48. $jsone['result'] = "Success";
  49. $jsone['message'] = $json;
  50. echo json_encode($jsone);
  51. ob_start();
  52. shell_exec('sync;sync;sync');
  53. //chdir("/home/phihong/Module_WebService");
  54. chdir("/root");
  55. $str_json=json_encode($json);var_dump($str_json);
  56. exec("'./WebService' '3' '".$str_json."'",$output,$return_var);
  57. // copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
  58. ob_end_clean();
  59. // print_r($output);
  60. //echo "OK";
  61. }
  62. function checkip($id){
  63. $ip=$_POST[$id];
  64. if($_POST[$id] != ""){
  65. if(ip2long($ip)){
  66. }
  67. else{
  68. $jsone['result'] = "Fail";
  69. $jsone['message'] = "You have entered an invalid IP address on " . $id;
  70. echo json_encode($jsone);
  71. exit;
  72. }
  73. }
  74. }
  75. ?>