set_network_action.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. checkValue("TelcomEnabled");
  29. WifiMode_changed();
  30. // $json = json_decode(file_get_contents("charging.txt"), true);
  31. // $json = string[];
  32. // $json['FtpServer'] = $_POST['FtpServer'];
  33. $json['Eth0DhcpClient'] = $_POST['Eth0DhcpClient'];
  34. $json['Eth0IpAddress'] = $_POST['Eth0IpAddress'];
  35. $json['Eth0SubmaskAddress'] = $_POST['Eth0SubmaskAddress'];
  36. $json['Eth0GatewayAddress'] = $_POST['Eth0GatewayAddress'];
  37. // $json['Eth1DhcpClient'] = $_POST['Eth1DhcpClient'];
  38. // $json['Eth1IpAddress'] = $_POST['Eth1IpAddress'];
  39. // $json['Eth1SubmaskAddress'] = $_POST['Eth1SubmaskAddress'];
  40. // $json['Eth1GatewayAddress'] = $_POST['Eth1GatewayAddress'];
  41. $json['WifiMode'] = $_POST['WifiMode'];
  42. $json['WifiSsid'] = $_POST['WifiSsid'];
  43. $json['WifiPassword'] = $_POST['WifiPassword'];
  44. $json['WifiDhcpServer'] = $_POST['WifiDhcpServer'];
  45. $json['WifiDhcpClient'] = $_POST['WifiDhcpClient'];
  46. $json['WifiIpAddress'] = $_POST['WifiIpAddress'];
  47. $json['WifiSubmaskAddress'] = $_POST['WifiSubmaskAddress'];
  48. $json['WifiGatewayAddress'] = $_POST['WifiGatewayAddress'];
  49. $json['TelcomApn'] = $_POST['TelcomApn'];
  50. $json['TelcomChapPapId'] = $_POST['TelcomChapPapId'];
  51. $json['TelcomChapPapPwd'] = $_POST['TelcomChapPapPwd'];
  52. $json['TelcomIpAddress'] = $_POST['TelcomIpAddress'];
  53. $json['TelcomEnabled'] = $_POST['TelcomEnabled'];
  54. // ob_start();
  55. shell_exec('sync;sync;sync');
  56. chdir("/root");
  57. $str_json=json_encode($json);
  58. exec("'./WebService' '3' '".$str_json."'",$output,$return_var);
  59. if(count($output)!=0){
  60. $jsone['result'] = "Success";
  61. $jsone['message'] = $json;
  62. echo json_encode($jsone);
  63. exit;
  64. }
  65. else{
  66. $jsone['result'] = "Error";
  67. $jsone['message'] = "Something went wrong on machine";
  68. echo json_encode($jsone);
  69. return false;
  70. exit;
  71. }
  72. // ob_end_clean();
  73. }
  74. function checkip($id){
  75. $ip=$_POST[$id];
  76. if($_POST[$id] != ""){
  77. if(ip2long($ip)){
  78. }
  79. else{
  80. $jsone['result'] = "Fail";
  81. $jsone['message'] = "You have entered an invalid IP address on " . $id;
  82. echo json_encode($jsone);
  83. exit;
  84. }
  85. }
  86. }
  87. function checkValue($id){
  88. if(strlen($_POST[$id])!=1){
  89. $jsone['result'] = "Fail";
  90. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  91. echo json_encode($jsone);
  92. exit;
  93. }
  94. if(!ereg("[0-9]",$_POST[$id])){
  95. $jsone['result'] = "Fail";
  96. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  97. echo json_encode($jsone);
  98. exit;
  99. }
  100. }
  101. function WifiMode_changed(){
  102. if($_POST['WifiMode']=="0"){
  103. // $_POST['WifiDhcpServer']=1;
  104. // $_POST['WifiDhcpClient']=1;
  105. $_POST['WifiSsid']="";
  106. $_POST['WifiPassword']="";
  107. }
  108. if($_POST['WifiMode']=="1"){
  109. // $_POST['WifiDhcpServer']=1;
  110. // $_POST['WifiDhcpClient']=0;
  111. }
  112. if($_POST['WifiMode']=="2"){
  113. // $_POST['WifiDhcpServer']=0;
  114. // $_POST['WifiDhcpClient']=1;
  115. $_POST['WifiSsid']="";
  116. $_POST['WifiPassword']="";
  117. }
  118. }
  119. ?>