set_network_action.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. if(isset($_REQUEST['isEnalbleFirewall'])){
  88. $json['isEnalbleFirewall'] = $_REQUEST['isEnalbleFirewall'];
  89. }
  90. if(isset($_REQUEST['FirewallAcceptAddr0'])){
  91. checkip2("FirewallAcceptAddr0");
  92. $json['FirewallAcceptAddr0'] = $_REQUEST['FirewallAcceptAddr0'];
  93. }
  94. if(isset($_REQUEST['FirewallAcceptAddr1'])){
  95. checkip2("FirewallAcceptAddr1");
  96. $json['FirewallAcceptAddr1'] = $_REQUEST['FirewallAcceptAddr1'];
  97. }
  98. if(isset($_REQUEST['FirewallAcceptAddr2'])){
  99. checkip2("FirewallAcceptAddr2");
  100. $json['FirewallAcceptAddr2'] = $_REQUEST['FirewallAcceptAddr2'];
  101. }
  102. if(isset($_REQUEST['FirewallAcceptAddr3'])){
  103. checkip2("FirewallAcceptAddr3");
  104. $json['FirewallAcceptAddr3'] = $_REQUEST['FirewallAcceptAddr3'];
  105. }
  106. if(isset($_REQUEST['FirewallAcceptAddr4'])){
  107. checkip2("FirewallAcceptAddr4");
  108. $json['FirewallAcceptAddr4'] = $_REQUEST['FirewallAcceptAddr4'];
  109. }
  110. if(isset($_REQUEST['FirewallAcceptAddr5'])){
  111. checkip2("FirewallAcceptAddr5");
  112. $json['FirewallAcceptAddr5'] = $_REQUEST['FirewallAcceptAddr5'];
  113. }
  114. if(isset($_REQUEST['FirewallAcceptAddr6'])){
  115. checkip2("FirewallAcceptAddr6");
  116. $json['FirewallAcceptAddr6'] = $_REQUEST['FirewallAcceptAddr6'];
  117. }
  118. if(isset($_REQUEST['FirewallAcceptAddr7'])){
  119. checkip2("FirewallAcceptAddr7");
  120. $json['FirewallAcceptAddr7'] = $_REQUEST['FirewallAcceptAddr7'];
  121. }
  122. if(isset($_REQUEST['FirewallAcceptAddr8'])){
  123. checkip2("FirewallAcceptAddr8");
  124. $json['FirewallAcceptAddr8'] = $_REQUEST['FirewallAcceptAddr8'];
  125. }
  126. if(isset($_REQUEST['FirewallAcceptAddr9'])){
  127. checkip2("FirewallAcceptAddr9");
  128. $json['FirewallAcceptAddr9'] = $_REQUEST['FirewallAcceptAddr9'];
  129. }
  130. // ob_start();
  131. shell_exec('sync;sync;sync');
  132. chdir("/root");
  133. $str_json=json_encode($json);
  134. exec("'./WebService' '3' '".$str_json."'",$output,$return_var);
  135. if(count($output)!=0){
  136. $jsone['result'] = "Success";
  137. $jsone['message'] = $json;
  138. echo json_encode($jsone);
  139. exit;
  140. }
  141. else{
  142. // $jsone['result'] = "Error";
  143. $jsone['result'] = $str_json;
  144. $jsone['message'] = "Something went wrong on machine";
  145. echo json_encode($jsone);
  146. return false;
  147. exit;
  148. }
  149. // ob_end_clean();
  150. }
  151. function checkip($id){
  152. $ip=$_REQUEST[$id];
  153. if($_REQUEST[$id] != ""){
  154. if(ip2long($ip)){
  155. }
  156. else{
  157. $jsone['result'] = "Fail";
  158. $jsone['message'] = "You have entered an invalid IP address on " . $id;
  159. echo json_encode($jsone);
  160. exit;
  161. }
  162. }
  163. }
  164. function checkip2($id){
  165. $ip=$_REQUEST[$id];
  166. if($_REQUEST[$id] != ""){
  167. if(ip2long($ip)){
  168. }
  169. else if(preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $ip)){
  170. }
  171. else{
  172. $jsone['result'] = "Fail";
  173. $jsone['message'] = "You have entered an invalid IP address or domain name on " . $id;
  174. echo json_encode($jsone);
  175. exit;
  176. }
  177. }
  178. }
  179. function checkValue($id){
  180. if($_REQUEST[$id] != ""){
  181. if(strlen($_REQUEST[$id])!=1){
  182. $jsone['result'] = "Fail";
  183. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  184. echo json_encode($jsone);
  185. exit;
  186. }
  187. if(!is_numeric($_REQUEST[$id])){
  188. $jsone['result'] = "Fail";
  189. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  190. echo json_encode($jsone);
  191. exit;
  192. }
  193. }
  194. }
  195. function WifiMode_changed(){
  196. if($_REQUEST['WifiMode']=="0"){
  197. // $_REQUEST['WifiDhcpServer']=1;
  198. // $_REQUEST['WifiDhcpClient']=1;
  199. $_REQUEST['WifiSsid']="";
  200. $_REQUEST['WifiPassword']="";
  201. }
  202. if($_REQUEST['WifiMode']=="1"){
  203. // $_REQUEST['WifiDhcpServer']=1;
  204. // $_REQUEST['WifiDhcpClient']=0;
  205. }
  206. if($_REQUEST['WifiMode']=="2"){
  207. // $_REQUEST['WifiDhcpServer']=0;
  208. // $_REQUEST['WifiDhcpClient']=1;
  209. $_REQUEST['WifiSsid']="";
  210. $_REQUEST['WifiPassword']="";
  211. }
  212. }
  213. ?>