set_network_action.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. checkip("Eth0IpAddress");
  14. checkip("Eth0SubmaskAddress");
  15. checkip("Eth0GatewayAddress");
  16. checkip("Eth1IpAddress");
  17. checkip("Eth1SubmaskAddress");
  18. checkip("Eth1GatewayAddress");
  19. checkip("WifiIpAddress");
  20. checkip("WifiSubmaskAddress");
  21. checkip("WifiGatewayAddress");
  22. checkip("TelcomIpAddress");
  23. checkValue("Eth0DhcpClient");
  24. checkValue("Eth1DhcpClient");
  25. checkValue("WifiMode");
  26. checkValue("WifiDhcpServer");
  27. checkValue("WifiDhcpClient");
  28. // $json = json_decode(file_get_contents("charging.txt"), true);
  29. // $json = string[];
  30. $json['FtpServer'] = $_POST['FtpServer'];
  31. $json['Eth0DhcpClient'] = chr($_POST['Eth0DhcpClient']);
  32. $json['Eth0IpAddress'] = $_POST['Eth0IpAddress'];
  33. $json['Eth0SubmaskAddress'] = $_POST['Eth0SubmaskAddress'];
  34. $json['Eth0GatewayAddress'] = $_POST['Eth0GatewayAddress'];
  35. $json['Eth1DhcpClient'] = chr($_POST['Eth1DhcpClient']);
  36. $json['Eth1IpAddress'] = $_POST['Eth1IpAddress'];
  37. $json['Eth1SubmaskAddress'] = $_POST['Eth1SubmaskAddress'];
  38. $json['Eth1GatewayAddress'] = $_POST['Eth1GatewayAddress'];
  39. $json['WifiMode'] = chr($_POST['WifiMode']);
  40. $json['WifiSsid'] = $_POST['WifiSsid'];
  41. $json['WifiPassword'] = $_POST['WifiPassword'];
  42. $json['WifiDhcpServer'] = chr($_POST['WifiDhcpServer']);
  43. $json['WifiDhcpClient'] = chr($_POST['WifiDhcpClient']);
  44. $json['WifiIpAddress'] = $_POST['WifiIpAddress'];
  45. $json['WifiSubmaskAddress'] = $_POST['WifiSubmaskAddress'];
  46. $json['WifiGatewayAddress'] = $_POST['WifiGatewayAddress'];
  47. $json['TelcomApn'] = $_POST['TelcomApn'];
  48. $json['TelcomChapPapId'] = $_POST['TelcomChapPapId'];
  49. $json['TelcomChapPapPwd'] = $_POST['TelcomChapPapPwd'];
  50. $json['TelcomIpAddress'] = $_POST['TelcomIpAddress'];
  51. // var_dump($json);echo "\n\n";
  52. // echo json_encode($json);
  53. $jsone['result'] = "Success";
  54. $jsone['message'] = $json;
  55. echo json_encode($jsone);
  56. ob_start();
  57. shell_exec('sync;sync;sync');
  58. //chdir("/home/phihong/Module_WebService");
  59. chdir("/root");
  60. $str_json=json_encode($json);var_dump($str_json);
  61. exec("'./WebService' '3' '".$str_json."'",$output,$return_var);
  62. // copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
  63. ob_end_clean();
  64. // print_r($output);
  65. //echo "OK";
  66. }
  67. function checkip($id){
  68. $ip=$_POST[$id];
  69. if($_POST[$id] != ""){
  70. if(ip2long($ip)){
  71. }
  72. else{
  73. $jsone['result'] = "Fail";
  74. $jsone['message'] = "You have entered an invalid IP address on " . $id;
  75. echo json_encode($jsone);
  76. exit;
  77. }
  78. }
  79. }
  80. function checkValue($id){
  81. if(strlen($_POST[$id])!=1){
  82. $jsone['result'] = "Fail";
  83. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  84. echo json_encode($jsone);
  85. exit;
  86. }
  87. if(!ereg("[0-9]",$_POST[$id])){
  88. $jsone['result'] = "Fail";
  89. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  90. echo json_encode($jsone);
  91. exit;
  92. }
  93. }
  94. ?>