set_network_action.php 5.4 KB

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