set_network_action.php 3.8 KB

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