set_network_action.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. // 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['result'] = $str_json;
  91. $jsone['message'] = "Something went wrong on machine";
  92. echo json_encode($jsone);
  93. return false;
  94. exit;
  95. }
  96. // ob_end_clean();
  97. }
  98. function checkip($id){
  99. $ip=$_REQUEST[$id];
  100. if($_REQUEST[$id] != ""){
  101. if(ip2long($ip)){
  102. }
  103. else{
  104. $jsone['result'] = "Fail";
  105. $jsone['message'] = "You have entered an invalid IP address on " . $id;
  106. echo json_encode($jsone);
  107. exit;
  108. }
  109. }
  110. }
  111. function checkValue($id){
  112. if($_REQUEST[$id] != ""){
  113. if(strlen($_REQUEST[$id])!=1){
  114. $jsone['result'] = "Fail";
  115. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  116. echo json_encode($jsone);
  117. exit;
  118. }
  119. if(!ereg("[0-9]",$_REQUEST[$id])){
  120. $jsone['result'] = "Fail";
  121. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  122. echo json_encode($jsone);
  123. exit;
  124. }
  125. }
  126. }
  127. function WifiMode_changed(){
  128. if($_REQUEST['WifiMode']=="0"){
  129. // $_REQUEST['WifiDhcpServer']=1;
  130. // $_REQUEST['WifiDhcpClient']=1;
  131. $_REQUEST['WifiSsid']="";
  132. $_REQUEST['WifiPassword']="";
  133. }
  134. if($_REQUEST['WifiMode']=="1"){
  135. // $_REQUEST['WifiDhcpServer']=1;
  136. // $_REQUEST['WifiDhcpClient']=0;
  137. }
  138. if($_REQUEST['WifiMode']=="2"){
  139. // $_REQUEST['WifiDhcpServer']=0;
  140. // $_REQUEST['WifiDhcpClient']=1;
  141. $_REQUEST['WifiSsid']="";
  142. $_REQUEST['WifiPassword']="";
  143. }
  144. }
  145. ?>