set_network_action.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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("Eth1IpAddress");
  17. checkip("Eth1SubmaskAddress");
  18. checkip("Eth1GatewayAddress");
  19. checkip("WifiIpAddress");
  20. checkip("WifiSubmaskAddress");
  21. checkip("WifiGatewayAddress");
  22. checkip("TelcomIpAddress");
  23. checkValue("Eth0DhcpClient");
  24. checkValue("Eth1DhcpClient");
  25. checkValue("WifiMode");
  26. checkValue("WifiDhcpServer");
  27. checkValue("WifiDhcpClient");
  28. // $json = json_decode(file_get_contents("charging.txt"), true);
  29. // $json = string[];
  30. $json['FtpServer'] = $_POST['FtpServer'];
  31. $json['Eth0DhcpClient'] = $_POST['Eth0DhcpClient'];
  32. $json['Eth0IpAddress'] = $_POST['Eth0IpAddress'];
  33. $json['Eth0SubmaskAddress'] = $_POST['Eth0SubmaskAddress'];
  34. $json['Eth0GatewayAddress'] = $_POST['Eth0GatewayAddress'];
  35. $json['Eth1DhcpClient'] = $_POST['Eth1DhcpClient'];
  36. $json['Eth1IpAddress'] = $_POST['Eth1IpAddress'];
  37. $json['Eth1SubmaskAddress'] = $_POST['Eth1SubmaskAddress'];
  38. $json['Eth1GatewayAddress'] = $_POST['Eth1GatewayAddress'];
  39. $json['WifiMode'] = $_POST['WifiMode'];
  40. $json['WifiSsid'] = $_POST['WifiSsid'];
  41. $json['WifiPassword'] = $_POST['WifiPassword'];
  42. $json['WifiDhcpServer'] = $_POST['WifiDhcpServer'];
  43. $json['WifiDhcpClient'] = $_POST['WifiDhcpClient'];
  44. $json['WifiIpAddress'] = $_POST['WifiIpAddress'];
  45. $json['WifiSubmaskAddress'] = $_POST['WifiSubmaskAddress'];
  46. $json['WifiGatewayAddress'] = $_POST['WifiGatewayAddress'];
  47. $json['TelcomApn'] = $_POST['TelcomApn'];
  48. $json['TelcomChapPapId'] = $_POST['TelcomChapPapId'];
  49. $json['TelcomChapPapPwd'] = $_POST['TelcomChapPapPwd'];
  50. $json['TelcomIpAddress'] = $_POST['TelcomIpAddress'];
  51. // ob_start();
  52. shell_exec('sync;sync;sync');
  53. chdir("/root");
  54. $str_json=json_encode($json);
  55. exec("'./WebService' '3' '".$str_json."'",$output,$return_var);
  56. if(count($output)!=0){
  57. $jsone['result'] = "Success";
  58. $jsone['message'] = $json;
  59. echo json_encode($jsone);
  60. exit;
  61. }
  62. else{
  63. $jsone['result'] = "Error";
  64. $jsone['message'] = "Something went wrong on machine";
  65. echo json_encode($jsone);
  66. return false;
  67. exit;
  68. }
  69. // ob_end_clean();
  70. }
  71. function checkip($id){
  72. $ip=$_POST[$id];
  73. if($_POST[$id] != ""){
  74. if(ip2long($ip)){
  75. }
  76. else{
  77. $jsone['result'] = "Fail";
  78. $jsone['message'] = "You have entered an invalid IP address on " . $id;
  79. echo json_encode($jsone);
  80. exit;
  81. }
  82. }
  83. }
  84. function checkValue($id){
  85. if(strlen($_POST[$id])!=1){
  86. $jsone['result'] = "Fail";
  87. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  88. echo json_encode($jsone);
  89. exit;
  90. }
  91. if(!ereg("[0-9]",$_POST[$id])){
  92. $jsone['result'] = "Fail";
  93. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  94. echo json_encode($jsone);
  95. exit;
  96. }
  97. }
  98. ?>