set_network_action.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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("WifiIpAddress");
  17. checkip("WifiSubmaskAddress");
  18. checkip("WifiGatewayAddress");
  19. checkip("TelcomIpAddress");
  20. checkValue("Eth0DhcpClient");
  21. checkValue("WifiMode");
  22. checkValue("WifiDhcpServer");
  23. checkValue("WifiDhcpClient");
  24. checkValue("TelcomEnabled");
  25. WifiMode_changed();
  26. if($_POST['Eth0DhcpClient'] != ""){
  27. $json['Eth0DhcpClient'] = $_POST['Eth0DhcpClient'];
  28. }
  29. if($_POST['Eth0IpAddress'] != ""){
  30. $json['Eth0IpAddress'] = $_POST['Eth0IpAddress'];
  31. }
  32. if($_POST['Eth0SubmaskAddress'] != ""){
  33. $json['Eth0SubmaskAddress'] = $_POST['Eth0SubmaskAddress'];
  34. }
  35. if($_POST['Eth0GatewayAddress'] != ""){
  36. $json['Eth0GatewayAddress'] = $_POST['Eth0GatewayAddress'];
  37. }
  38. if($_POST['WifiMode'] != ""){
  39. $json['WifiMode'] = $_POST['WifiMode'];
  40. }
  41. if($_POST['WifiSsid'] != ""){
  42. $json['WifiSsid'] = $_POST['WifiSsid'];
  43. }
  44. // if($_POST['WifiPassword'] != ""){
  45. $json['WifiPassword'] = $_POST['WifiPassword'];
  46. // }
  47. if($_POST['WifiDhcpServer'] != ""){
  48. $json['WifiDhcpServer'] = $_POST['WifiDhcpServer'];
  49. }
  50. if($_POST['WifiDhcpClient'] != ""){
  51. $json['WifiDhcpClient'] = $_POST['WifiDhcpClient'];
  52. }
  53. if($_POST['WifiIpAddress'] != ""){
  54. $json['WifiIpAddress'] = $_POST['WifiIpAddress'];
  55. }
  56. if($_POST['WifiSubmaskAddress'] != ""){
  57. $json['WifiSubmaskAddress'] = $_POST['WifiSubmaskAddress'];
  58. }
  59. if($_POST['WifiGatewayAddress'] != ""){
  60. $json['WifiGatewayAddress'] = $_POST['WifiGatewayAddress'];
  61. }
  62. if($_POST['TelcomApn'] != ""){
  63. $json['TelcomApn'] = $_POST['TelcomApn'];
  64. }
  65. if($_POST['TelcomChapPapId'] != ""){
  66. $json['TelcomChapPapId'] = $_POST['TelcomChapPapId'];
  67. }
  68. if($_POST['TelcomChapPapPwd'] != ""){
  69. $json['TelcomChapPapPwd'] = $_POST['TelcomChapPapPwd'];
  70. }
  71. if($_POST['TelcomIpAddress'] != ""){
  72. $json['TelcomIpAddress'] = $_POST['TelcomIpAddress'];
  73. }
  74. if($_POST['TelcomEnabled'] != ""){
  75. $json['TelcomEnabled'] = $_POST['TelcomEnabled'];
  76. }
  77. // ob_start();
  78. shell_exec('sync;sync;sync');
  79. chdir("/root");
  80. $str_json=json_encode($json);
  81. exec("'./WebService' '3' '".$str_json."'",$output,$return_var);
  82. if(count($output)!=0){
  83. $jsone['result'] = "Success";
  84. $jsone['message'] = $json;
  85. echo json_encode($jsone);
  86. exit;
  87. }
  88. else{
  89. $jsone['result'] = "Error";
  90. $jsone['message'] = "Something went wrong on machine";
  91. echo json_encode($jsone);
  92. return false;
  93. exit;
  94. }
  95. // ob_end_clean();
  96. }
  97. function checkip($id){
  98. $ip=$_POST[$id];
  99. if($_POST[$id] != ""){
  100. if(ip2long($ip)){
  101. }
  102. else{
  103. $jsone['result'] = "Fail";
  104. $jsone['message'] = "You have entered an invalid IP address on " . $id;
  105. echo json_encode($jsone);
  106. exit;
  107. }
  108. }
  109. }
  110. function checkValue($id){
  111. if($_POST[$id] != ""){
  112. if(strlen($_POST[$id])!=1){
  113. $jsone['result'] = "Fail";
  114. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  115. echo json_encode($jsone);
  116. exit;
  117. }
  118. if(!ereg("[0-9]",$_POST[$id])){
  119. $jsone['result'] = "Fail";
  120. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  121. echo json_encode($jsone);
  122. exit;
  123. }
  124. }
  125. }
  126. function WifiMode_changed(){
  127. if($_POST['WifiMode']=="0"){
  128. // $_POST['WifiDhcpServer']=1;
  129. // $_POST['WifiDhcpClient']=1;
  130. $_POST['WifiSsid']="";
  131. $_POST['WifiPassword']="";
  132. }
  133. if($_POST['WifiMode']=="1"){
  134. // $_POST['WifiDhcpServer']=1;
  135. // $_POST['WifiDhcpClient']=0;
  136. }
  137. if($_POST['WifiMode']=="2"){
  138. // $_POST['WifiDhcpServer']=0;
  139. // $_POST['WifiDhcpClient']=1;
  140. $_POST['WifiSsid']="";
  141. $_POST['WifiPassword']="";
  142. }
  143. }
  144. ?>