set_network_action.php 5.0 KB

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