123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <?php
- // 設置資料類型 json,編碼格式 utf-8
- header('Content-Type: application/json; charset=UTF-8');
-
- // 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
- // $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
- if ($_SERVER['REQUEST_METHOD'] == "GET") {
- create();
- } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
- create();
- }
- // 新建員工
- function create() {
- checkip("Eth0IpAddress");
- checkip("Eth0SubmaskAddress");
- checkip("Eth0GatewayAddress");
- checkip("WifiIpAddress");
- checkip("WifiSubmaskAddress");
- checkip("WifiGatewayAddress");
- checkip("TelcomIpAddress");
- checkValue("Eth0DhcpClient");
- checkValue("WifiMode");
- checkValue("WifiBroadcastSsid");
- checkValue("WifiDhcpServer");
- checkValue("WifiDhcpClient");
- checkValue("TelcomEnabled");
- WifiMode_changed();
- if(isset($_REQUEST['Eth0DhcpClient'])){
- $json['Eth0DhcpClient'] = $_REQUEST['Eth0DhcpClient'];
- }
- if(isset($_REQUEST['Eth0IpAddress'])){
- $json['Eth0IpAddress'] = $_REQUEST['Eth0IpAddress'];
- }
- if(isset($_REQUEST['Eth0SubmaskAddress'])){
- $json['Eth0SubmaskAddress'] = $_REQUEST['Eth0SubmaskAddress'];
- }
- if(isset($_REQUEST['Eth0GatewayAddress'])){
- $json['Eth0GatewayAddress'] = $_REQUEST['Eth0GatewayAddress'];
- }
- if(isset($_REQUEST['WifiMode'])){
- $json['WifiMode'] = $_REQUEST['WifiMode'];
- }
- if(isset($_REQUEST['WifiBroadcastSsid'])){
- $json['WifiBroadcastSsid'] = $_REQUEST['WifiBroadcastSsid'];
- }
- if(isset($_REQUEST['WifiTargetBssidMac'])){
- $json['WifiTargetBssidMac'] = str_replace("&","&",str_replace(""",'"',str_replace("'","'",str_replace("<","<",str_replace(">",">",$_REQUEST['WifiTargetBssidMac'])))));
- }
- if(isset($_REQUEST['WifiSsid'])){
- $json['WifiSsid'] = str_replace("&","&",str_replace(""",'"',str_replace("'","'",str_replace("<","<",str_replace(">",">",$_REQUEST['WifiSsid'])))));
- }
- if(isset($_REQUEST['WifiPassword'])){
- $json['WifiPassword'] = str_replace("&","&",str_replace(""",'"',str_replace("'","'",str_replace("<","<",str_replace(">",">",$_REQUEST['WifiPassword'])))));
- }
- if(isset($_REQUEST['WifiDhcpServer'])){
- $json['WifiDhcpServer'] = $_REQUEST['WifiDhcpServer'];
- }
- if(isset($_REQUEST['WifiDhcpClient'])){
- $json['WifiDhcpClient'] = $_REQUEST['WifiDhcpClient'];
- }
- if(isset($_REQUEST['WifiIpAddress'])){
- $json['WifiIpAddress'] = $_REQUEST['WifiIpAddress'];
- }
- if(isset($_REQUEST['WifiSubmaskAddress'])){
- $json['WifiSubmaskAddress'] = $_REQUEST['WifiSubmaskAddress'];
- }
- if(isset($_REQUEST['WifiGatewayAddress'])){
- $json['WifiGatewayAddress'] = $_REQUEST['WifiGatewayAddress'];
- }
- if(isset($_REQUEST['TelcomApn'])){
- $json['TelcomApn'] = str_replace("&","&",str_replace(""",'"',str_replace("'","'",str_replace("<","<",str_replace(">",">",$_REQUEST['TelcomApn'])))));
- }
- if(isset($_REQUEST['TelcomChapPapId'])){
- $json['TelcomChapPapId'] = str_replace("&","&",str_replace(""",'"',str_replace("'","'",str_replace("<","<",str_replace(">",">",$_REQUEST['TelcomChapPapId'])))));
- }
- if(isset($_REQUEST['TelcomChapPapPwd'])){
- $json['TelcomChapPapPwd'] = str_replace("&","&",str_replace(""",'"',str_replace("'","'",str_replace("<","<",str_replace(">",">",$_REQUEST['TelcomChapPapPwd'])))));
- }
- if(isset($_REQUEST['TelcomIpAddress'])){
- $json['TelcomIpAddress'] = $_REQUEST['TelcomIpAddress'];
- }
- if(isset($_REQUEST['TelcomEnabled'])){
- $json['TelcomEnabled'] = $_REQUEST['TelcomEnabled'];
- }
- if(isset($_REQUEST['TelcomNetworkType'])){
- $json['TelcomNetworkType'] = $_REQUEST['TelcomNetworkType'];
- }
- if(isset($_REQUEST['isEnalbleFirewall'])){
- $json['isEnalbleFirewall'] = $_REQUEST['isEnalbleFirewall'];
- }
- if(isset($_REQUEST['FirewallAcceptAddr0'])){
- checkip2("FirewallAcceptAddr0");
- $json['FirewallAcceptAddr0'] = $_REQUEST['FirewallAcceptAddr0'];
- }
- if(isset($_REQUEST['FirewallAcceptAddr1'])){
- checkip2("FirewallAcceptAddr1");
- $json['FirewallAcceptAddr1'] = $_REQUEST['FirewallAcceptAddr1'];
- }
- if(isset($_REQUEST['FirewallAcceptAddr2'])){
- checkip2("FirewallAcceptAddr2");
- $json['FirewallAcceptAddr2'] = $_REQUEST['FirewallAcceptAddr2'];
- }
- if(isset($_REQUEST['FirewallAcceptAddr3'])){
- checkip2("FirewallAcceptAddr3");
- $json['FirewallAcceptAddr3'] = $_REQUEST['FirewallAcceptAddr3'];
- }
- if(isset($_REQUEST['FirewallAcceptAddr4'])){
- checkip2("FirewallAcceptAddr4");
- $json['FirewallAcceptAddr4'] = $_REQUEST['FirewallAcceptAddr4'];
- }
- if(isset($_REQUEST['FirewallAcceptAddr5'])){
- checkip2("FirewallAcceptAddr5");
- $json['FirewallAcceptAddr5'] = $_REQUEST['FirewallAcceptAddr5'];
- }
- if(isset($_REQUEST['FirewallAcceptAddr6'])){
- checkip2("FirewallAcceptAddr6");
- $json['FirewallAcceptAddr6'] = $_REQUEST['FirewallAcceptAddr6'];
- }
- if(isset($_REQUEST['FirewallAcceptAddr7'])){
- checkip2("FirewallAcceptAddr7");
- $json['FirewallAcceptAddr7'] = $_REQUEST['FirewallAcceptAddr7'];
- }
- if(isset($_REQUEST['FirewallAcceptAddr8'])){
- checkip2("FirewallAcceptAddr8");
- $json['FirewallAcceptAddr8'] = $_REQUEST['FirewallAcceptAddr8'];
- }
- if(isset($_REQUEST['FirewallAcceptAddr9'])){
- checkip2("FirewallAcceptAddr9");
- $json['FirewallAcceptAddr9'] = $_REQUEST['FirewallAcceptAddr9'];
- }
- // ob_start();
-
- shell_exec('sync;sync;sync');
- chdir("/root");
- $str_json=json_encode($json);
- exec("'./WebService' '3' '".$str_json."'",$output,$return_var);
- if(count($output)!=0){
- $jsone['result'] = "Success";
- $jsone['message'] = $json;
- echo json_encode($jsone);
- exit;
- }
- else{
- // $jsone['result'] = "Error";
- $jsone['result'] = $str_json;
- $jsone['message'] = "Something went wrong on machine";
- echo json_encode($jsone);
- return false;
- exit;
- }
- // ob_end_clean();
- }
- function checkip($id){
- $ip=$_REQUEST[$id];
- if($_REQUEST[$id] != ""){
- if(ip2long($ip)){
-
- }
- else{
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered an invalid IP address on " . $id;
- echo json_encode($jsone);
- exit;
- }
- }
- }
- function checkip2($id){
- $ip=$_REQUEST[$id];
- if($_REQUEST[$id] != ""){
- if(ip2long($ip)){
- }
- else if(preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $ip)){
- }
- else{
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered an invalid IP address or domain name on " . $id;
- echo json_encode($jsone);
- exit;
- }
- }
- }
- function checkValue($id){
- if($_REQUEST[$id] != ""){
- if(strlen($_REQUEST[$id])!=1){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- echo json_encode($jsone);
- exit;
- }
- if(!is_numeric($_REQUEST[$id])){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- echo json_encode($jsone);
- exit;
- }
- }
- }
- function WifiMode_changed(){
- if($_REQUEST['WifiMode']=="0"){
- // $_REQUEST['WifiDhcpServer']=1;
- // $_REQUEST['WifiDhcpClient']=1;
- $_REQUEST['WifiSsid']="";
- $_REQUEST['WifiPassword']="";
- }
- if($_REQUEST['WifiMode']=="1"){
- // $_REQUEST['WifiDhcpServer']=1;
- // $_REQUEST['WifiDhcpClient']=0;
- }
- if($_REQUEST['WifiMode']=="2"){
- // $_REQUEST['WifiDhcpServer']=0;
- // $_REQUEST['WifiDhcpClient']=1;
- $_REQUEST['WifiSsid']="";
- $_REQUEST['WifiPassword']="";
- }
- }
- ?>
|