Subversion Repositories php-qbpwcf

Rev

Blame | Last modification | View Log | RSS feed

#!/bin/php
<?php

#使用命名空間qbpwcf
namespace qbpwcf;

#匯入外部套件
include("qbpwcf/allInOne.php");

#help訊息
function help(){

        #提示用法
        echo basename(__FILE__)." -h/--help 顯示本內容".PHP_EOL;
        echo basename(__FILE__)." -ip 要連線到的IP位置 -port 要連接的port -dbFile 用於交換資料的檔案 -timeout 連線idle多少秒要斷開 -email 連線用的賬號".PHP_EOL;

        }#function help end

#函式說明:
#抓取命令列的參數.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$reuslt["error"],執行不正常結束的錯訊息陣列.
#$result["function"],當前執行的函式名稱.
#$result["argu"],使用的參數陣列.
#$result["content"],要回傳的參數陣列.
#$result["count"],參數的數量.
#必填參數:
#無
#可省略參數:
#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
$conf["echo"]="false";
$getArgu=cmd::getArgu($conf);
unset($conf);

#如果執行失敗
if($getArgu["status"]==="false"){

        #印出結果
        var_dump($getArgu);

        #結束執行
        exit;
        
        }#if end

#如果沒有參數
if(!isset($getArgu["content"][1])){

        #提示訊息
        help();
        
        #結束執行
        exit;

        }#if end
        
#反之如果參數為 -h 或 --help
else if( $getArgu["content"][1]==="-h" || $getArgu["content"][1]==="--help"){

        #提示訊息
        help();
        
        #結束執行
        exit;

        }#if end

#函式說明:
#解析參數.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$reuslt["error"],執行不正常結束的錯訊息陣列.
#$result["function"],當前執行的函式名稱.
#$result["content"],解析好的參數陣列.
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
#$result["program"],字串,執行的程式名稱.
#必填參數:
#無
#可省略參數:
#無
#備註:
#僅能在命令列底下執行.
#建議:
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
$conf=array()l
$parseArgu=cmd::parseArgu($conf);
unset($conf);

#如果執行失敗
if($parseArgu["status"]==="false"){

        #印出結果
        var_dump($parseArgu);

        #結束執行
        exit;
        
        }#if end

#如果參數ip或port或dbFile或timeout或email有一個不存在.
if( !isset($parseArgu["content"]["ip"]) || !isset($parseArgu["content"]["port"]) || !isset($parseArgu["content"]["dbFile"]) || !isset($parseArgu["content"]["timeout"]) || !isset($parseArgu["content"]["email"]) ){
        
        #提示訊息
        help();
        
        #結束執行
        exit;
        
        }#if end

#取得目標 ip        
$ip=$parseArgu["content"]["ip"][0];

#取得目標 port
$port=$parseArgu["content"]["port"][0];

#取得用於交換資料的檔案
$dbFile=$parseArgu["content"]["dbFile"][0];

#取得idle timeout的時間秒數
$timeout=$parseArgu["content"]["timeout"][0];

#取得email
$email=$parseArgu["content"]["email"][0];

#建立 tcp socket client       
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

#如果建立 socket 失敗
if ($socket === false) {

        #設置執行失敗
        $result["status"]="false";
        
        #設置錯誤訊息
        $result["error"][]="socket_create() failed: reason: " . socket_strerror(socket_last_error());
        
        #印出結果
        var_dump($result);

        #結束執行
        exit;

        }#if end 
        
#連線到 tcp socket server    
$socket_connect = @socket_connect($socket, $ip, $port);

#如果建立 socket 失敗
if ($socket_connect === false) {

        #設置執行失敗
        $result["status"]="false";
        
        #設置錯誤訊息
        $result["error"][]="socket_create() failed: reason: " . socket_strerror(socket_last_error($socket));
        
        #印出結果
        var_dump($result);

        #結束執行
        exit;
        
        }#if end 

#載入資料庫資訊
#涵式說明:
#解析PHP檔案裡面的變數.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["error"],錯誤訊息.
#$result["function"],當前執行的函數名稱.
#$result["argu"],所使用的參數.    
#$result["content"],找到的變數內容陣列.
#$result["content"]["value"],依找到變數順序的數值.
#$result["content"]["struc"],依找到變數順序的階層結構.
#$result["content"]["direct],變數名稱對應的數值內容.
#必填參數:
#$conf["file"],字串,檔案的路徑與名稱.
$conf["file"]="/var/www/html/latest/application/config/database.php";
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
$conf["fileArgu"]=__FILE__;
#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
$conf["varName"]=array("db['default']['hostname']","db['default']['port']","db['default']['username']","db['default']['password']","db['default']['database']");
#參考資料:
#https://www.php.net/manual/en/function.parse-str.php
$parseVaraiableInPHPfile=fileAccess::parseVaraiableInPHPfile($conf);
unset($conf);

#如果解析檔案失敗
if($parseVaraiableInPHPfile["status"]==="false"){

        #印出內容
        var_dump($parseVaraiableInPHPfile);

        #結束執行
        exit;

        }#if end
        
#取得資料庫位址
$dbAddress=$parseVaraiableInPHPfile["content"]["direct"]["db['default']['hostname']"];

#取得資料庫port
$dbPort=$parseVaraiableInPHPfile["content"]["direct"]["db['default']['port']"];

#取得資料庫使用者
$dbUser=$parseVaraiableInPHPfile["content"]["direct"]["db['default']['username']"];

#取得資料庫密碼
$dbPassword=$parseVaraiableInPHPfile["content"]["direct"]["db['default']['password']"];

#取得資料庫名稱
$dbName=$parseVaraiableInPHPfile["content"]["direct"]["db['default']['database']"];

#查尋賬號對應的密碼
#涵式說明:
#一次取得資料庫、表的資料
#回傳的結果
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
#$result["error"],錯誤訊息陣列。
#$result["function"],當前執行的漢書名稱.
#$result["argu"],使用的參數.
#$result["dataColumnName"],抓取的資料欄位名稱陣列.
        #$result["dataColumnName"][$i]代表第$i+1個欄位名稱
#$result["dataContent"],爲資料的內容。
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
        #$dataSetNum 爲第$dataSetNum+1筆資料
        #$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
#$result["dataCount"],爲取得的資料筆數。
#$result["sql"],執行的sql字串.
#必填的參數:
#$conf["dbAddress"],字串,爲dbServer的位置。
$conf["dbAddress"]=$dbAddress;
#$conf["dbAccount"],字串,爲登入dbServer的帳號。
$conf["dbAccount"]=$dbUser;
#$conf["dbName"],字串,爲要存取的資料庫名稱
$conf["dbName"]=$dbName;
#$conf["tableName"],字串,爲要存取的資料表名稱
$conf["tableName"]="auth_users";
#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.
$conf["columnYouWant"]=array("password");
#可省略的參數:
#$conf["dbPassword"],字串,爲要存取dbServer的密碼.
$conf["dbPassword"]=$dbPassword;
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
$conf["dbPort"]=$dbPort;
#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
$conf["WhereColumnName"]=array("email");
#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
$conf["WhereColumnValue"]=array($email);
#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
#$conf["WhereColumnCombine"]=array("");
#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
#$conf["WhereColumnOperator"]=array("");
#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
#$conf["WhereColumnAndOr"]=array("");
#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
#$conf["whereIn"]=array(array("colName",array("a","b","c")));
#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
#$conf["orderItem"]="";
#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
#$conf["ascORdesc"]="";
#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
#$conf["numberStart"]="0";
#$conf["numLimit"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
#$conf["numLimit"]="30";
#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
#$conf["groupBy"]=array("");
$fastGetDbData=db::fastGetDbData($conf);
unset($conf);

#如果抓取資料失敗
if($fastGetDbData["status"]==="false"){

        #印出內容
        var_dump($fastGetDbData);

        #結束執行
        exit;

        }#if end
        
#取得 password
$password=$fastGetDbData["dataContent"]["password"][0];

#get client info
$_webaddr = trim(`hostname`) . '(' . getHostByName(trim(`hostname`)) . ')';

#進行登入的動作

#登入的語法
$data="SIGNIN;".$_webaddr.";".$email.";".$password.";true;".time(0)."000";

#寫入到 devcom
socket_write($socket,$data,strlen($data));

#讀取回應
#$returnStr=socket_read($socket,2048);

#嘗試開啟dbFile
#涵式說明:
#將字串寫入到檔案
#回傳的結果:
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
#$result["error"],錯誤訊息陣列.
#$result["function"],當前執行的函數名稱.
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
#$result["argu"],使用的參數.
#必填的參數:
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
$conf["fileArgu"]=__FILE__;
#可省略的參數:
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
$conf["fileName"]=$dbFile;
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
$data=array();
$data["connect_time"]=time(0); #連線建立的時間
$data["last_action_time"]=$data["connect_time"]; #初始化最後的連線時間.
$conf["inputString"]=json_encode($data).PHP_EOL;
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
#$conf["writeMethod"]="a";
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
#$conf["checkRepeat"]="";
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
#$conf["filenameExtensionStartPoint"]="";
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
#$conf["repeatNameRule"]="";
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf);
unset($conf);

#如果建立檔案失敗
if($writeTextIntoFile["status"]==="false"){

        #印出結果
        var_dump($result);

        #結束執行
        exit;

        }#if end

#讓程式不會終止 
while(true){

        #函式說明:
        #依據行號分隔抓取檔案的內容,結果會回傳一個陣列
        #回傳的變數說明:
        #$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
        #$result["error"],錯誤訊息提示.
        #$result["warning"],警告訊息.
        #$result["function"],當前執行的函數名稱.
        #$result["fileContent"],爲檔案的內容陣列.
        #$result["lineCount"],爲檔案內容總共的行數.
        #$result["fullContent"],為檔案的完整內容.
        #$result["base64data"],為檔案的base64內容.
        #$result["mimeType"],為檔案的mime type.
        #必填的參數:
        #$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
        $conf["filePositionAndName"]=$dbFile;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #參考資料:
        #file(),取得檔案內容的行數.
        #file=>http:#php.net/manual/en/function.file.php
        #rtrim(),剔除透過file()取得每行內容結尾的換行符號.
        #filesize=>http://php.net/manual/en/function.filesize.php
        $getFileContent=fileAccess::getFileContent($conf);
        unset($conf);
        
        #如果建立檔案失敗
        if($getFileContent["status"]==="false"){

                #印出結果
                var_dump($getFileContent);

                #結束執行
                exit;

                }#if end
        
        #如果讀取的行數小於1
        if($getFileContent["lineCount"]<1){
        
                #印出結果
                var_dump($getFileContent);

                #結束執行
                exit;
        
                }#if end
        
        #初始化儲存第一行的內容
        $firstLine="";
        
        #初始化儲存要寫入的既有行內容
        $oldLine=array();
                
        #初始化儲存要寫入的新行內容
        $newLine=array();       
                
        #針對每一行的結果
        foreach($getFileContent["fileContent"] as $no=>$line){
        
                #如果是第一行的內容
                if($no===0){
                
                        #解析內容
                        $firstLine=json_decode($line);
                        
                        #如果最後一次動作的時間記錄距離現在已經超過 $timeout 秒了
                        if(time(0)-$firstLine->last_action_time > $timeout){
                        
                                #移除檔案
                                #涵式說明:
                                #移除檔案
                                #回傳的結果:
                                #$result["status"],"true"代表移除成功,"false"代表移除失敗.
                                #$result["error"],錯誤訊息陣列
                                #$result["warning"],警告訊息陣列
                                #$result["function"],當前執行的函數名稱
                                #必填的參數:
                                #$conf["fileAddress"],字串,要移除檔案的位置.
                                $conf["fileAddress"]=$dbFile;
                                #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
                                $conf["fileArgu"]=__FILE__;
                                #可省略參數:
                                #$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
                                #$conf["commentsArray"]=array("");
                                $delFile=fileAccess::delFile($conf);
                                unset($conf);
                                
                                #如果移除檔案失敗
                                if($delFile["status"]==="false"){
                                
                                        #印出內容
                                        var_dump($delFile);
                                
                                        #結束執行
                                        exit;
                                
                                        }#if end
                                
                                #結束程式
                                exit;
                        
                                }#if end
                
                        #json_encode first line
                        $firstLine=json_encode($firstLine);
                
                        }#if end
                        
                #反之不是第一行
                else{
                
                        #解析內容
                        $line=json_decode($line);
                        
                        #取得資料
                        $data=$line->data;
                        
                        #取得類型
                        $type=$line->type;
                                
                        #如果是要下發到gw
                        if($type==="tgw"){
                                
                                #初始化取得的回應為 false 代表失敗
                                $returnStr=false;
                                                
                                #休息時間預設為 0 秒
                                $sleepSec=0;
                                                
                                #如果尚未取得回應
                                while( ($returnStr===false) && sleep($sleepSec)===0 ){          
                        
                                        #取得gwId;
                                        $gwId=$line->gwId;
                                        
                                        #讀取資料庫設定
                                        #涵式說明:
                                        #解析PHP檔案裡面的變數.
                                        #回傳結果:
                                        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                                        #$result["error"],錯誤訊息.
                                        #$result["function"],當前執行的函數名稱.
                                        #$result["argu"],所使用的參數.    
                                        #$result["content"],找到的變數內容陣列.
                                        #$result["content"]["value"],依找到變數順序的數值.
                                        #$result["content"]["struc"],依找到變數順序的階層結構.
                                        #$result["content"]["direct],變數名稱對應的數值內容.
                                        #必填參數:
                                        #$conf["file"],字串,檔案的路徑與名稱.
                                        $conf["file"]="/var/www/html/latest/application/config/database.php";
                                        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
                                        $conf["fileArgu"]=__FILE__;
                                        #$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
                                        $conf["varName"]=array("db['default']['hostname']","db['default']['port']","db['default']['username']","db['default']['password']","db['default']['database']");
                                        #參考資料:
                                        #https://www.php.net/manual/en/function.parse-str.php
                                        $parseVaraiableInPHPfile=fileAccess::parseVaraiableInPHPfile($conf);
                                        unset($conf);
                                        
                                        #如果解析檔案失敗
                                        if($parseVaraiableInPHPfile["status"]==="false"){
                                        
                                                #印出內容
                                                var_dump($parseVaraiableInPHPfile);
                                        
                                                #結束執行
                                                exit;
                                        
                                                }#if end
                                                
                                        #取得資料庫位址
                                        $dbAddress=$parseVaraiableInPHPfile["content"]["direct"]["db['default']['hostname']"];
                                        
                                        #取得資料庫port
                                        $dbPort=$parseVaraiableInPHPfile["content"]["direct"]["db['default']['port']"];
                                        
                                        #取得資料庫使用者
                                        $dbUser=$parseVaraiableInPHPfile["content"]["direct"]["db['default']['username']"];
                                        
                                        #取得資料庫密碼
                                        $dbPassword=$parseVaraiableInPHPfile["content"]["direct"]["db['default']['password']"];
                                        
                                        #取得資料庫名稱
                                        $dbName=$parseVaraiableInPHPfile["content"]["direct"]["db['default']['database']"];
                                        
                                        #查尋gw識別碼
                                        #涵式說明:
                                        #一次取得資料庫、表的資料
                                        #回傳的結果
                                        #$result["status"],執行結果"true"為成功;"false"為執行失敗。
                                        #$result["error"],錯誤訊息陣列。
                                        #$result["function"],當前執行的漢書名稱.
                                        #$result["argu"],使用的參數.
                                        #$result["dataColumnName"],抓取的資料欄位名稱陣列.
                                                #$result["dataColumnName"][$i]代表第$i+1個欄位名稱
                                        #$result["dataContent"],爲資料的內容。
                                        #$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
                                                #$dataSetNum 爲第$dataSetNum+1筆資料
                                                #$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
                                        #$result["dataCount"],爲取得的資料筆數。
                                        #$result["sql"],執行的sql字串.
                                        #必填的參數:
                                        #$conf["dbAddress"],字串,爲dbServer的位置。
                                        $conf["dbAddress"]=$dbAddress;
                                        #$conf["dbAccount"],字串,爲登入dbServer的帳號。
                                        $conf["dbAccount"]=$dbUser;
                                        #$conf["dbName"],字串,爲要存取的資料庫名稱
                                        $conf["dbName"]=$dbName;
                                        #$conf["tableName"],字串,爲要存取的資料表名稱
                                        $conf["tableName"]="device";
                                        #$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.
                                        $conf["columnYouWant"]=array("telcom_gsn","lanmac","telcom_imi");
                                        #可省略的參數:
                                        #$conf["dbPassword"],字串,爲要存取dbServer的密碼.
                                        $conf["dbPassword"]=$dbPassword;
                                        #$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
                                        $conf["dbPort"]=$dbPort;
                                        #$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
                                        $conf["WhereColumnName"]=array("id");
                                        #$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
                                        $conf["WhereColumnValue"]=array($gwId);
                                        #$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
                                        #$conf["WhereColumnCombine"]=array("");
                                        #$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
                                        #$conf["WhereColumnOperator"]=array("");
                                        #$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
                                        #$conf["WhereColumnAndOr"]=array("");
                                        #$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
                                        #$conf["whereIn"]=array(array("colName",array("a","b","c")));
                                        #$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
                                        #$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
                                        #$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
                                        #$conf["orderItem"]="";
                                        #$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
                                        #$conf["ascORdesc"]="";
                                        #$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
                                        #$conf["numberStart"]="0";
                                        #$conf["numLimit"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
                                        #$conf["numLimit"]="30";
                                        #$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
                                        #$conf["groupBy"]=array("");
                                        $fastGetDbData=db::fastGetDbData($conf);
                                        unset($conf);
                                        
                                        #如果抓取資料失敗
                                        if($fastGetDbData["status"]==="false"){
                                        
                                                #印出內容
                                                var_dump($fastGetDbData);

                                                #結束執行
                                                exit;
                                        
                                                }#if end
                                                
                                        #取得 gw gsn
                                        $gsn=$fastGetDbData["dataContent"]["telcom_gsn"][0];
                                        
                                        #取得 gw lanmac
                                        $lanamc=$fastGetDbData["dataContent"]["lanmac"][0];
                                        
                                        #取得 gw imi
                                        $imi=$fastGetDbData["dataContent"]["telcom_imi"][0];
                                        
                                        #如果有gsn
                                        if(!empty($gsn)){
                                        
                                                #設置gw真正的識別碼
                                                $gwRiD=$gsn;

                                                #設置gw的識別碼類型
                                                $gwType="GSN";
                                                
                                                }#if end
                                                
                                        #如果有gsn
                                        else if(!empty($lanamc)){
                                        
                                                #設置gw真正的識別碼
                                                $gwRiD=$lanamc;
                                                
                                                #設置gw的識別碼類型
                                                $gwType="MAC";
                                                
                                                }#if end
                                                
                                        #如果有gsn
                                        else if(!empty($imi)){
                                        
                                                #設置gw真正的識別碼
                                                $gwRiD=$imi;
                                                
                                                #設置gw的識別碼類型
                                                $gwType="IMI";
                                                
                                                }#if end
                                        
                                        #設置要傳送給Devcom的訊息
                                        $data="ACTION;".time()."000".";WEBCTL;".$gwRiD.";".$gwType.';'.$data."\r";
                                        
                                        #寫入到 devcom
                                        socket_write($socket,$data,strlen($data));
                                
                                        #讀取回應
                                        $returnStr=socket_read($socket,2048);
                                                                
                                        #如果讀取回應失敗
                                        if($returnStr===false){
                                        
                                                #設置要休息5秒鐘
                                                $sleepSec=5;
                                        
                                                }#if end
                                
                                        }#while end
                                
                                #儲存要寫入的新行
                                $newLine[]=json_encode(array("type"=>"fgw","gwId"=>$gwId,"data"=>$returnStr));
                                
                                #解析第一行
                                $firstLine=json_decode($firstLine);
                                
                                #更新第一行的內容
                                $firstLine->last_action_time=time(0);
                                
                                #編碼第一行的內容
                                $firstLine=json_encode($firstLine);
                                
                                }#if end

                        #反之是 gw 的回應
                        else{                   
                                #儲存既有的gw回應
                                $oldLine[]=$line;
                        
                                }#else end

                        }#else end

                }#foreach end

        #合併要寫入的內容
        #函式說明:
        #將多個一維陣列串聯起來,key從0開始排序.
        #回傳的結果:
        #$result["status"],"true"表執行正常,"false"代表執行不正常.
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前執行的函數.
        #$result["content"],合併好的一維陣列.
        #必填的參數
        #$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
        $conf["inputArray"]=array(array($firstLine),$oldLine,$newLine);
        #可省略的參數:
        #$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
        #$conf["allowRepeat"]="true";
        $mergeArray=arrays::mergeArray($conf);
        unset($conf);
        
        #如果合併資料失敗
        if($mergeArray["status"]==="false"){
        
                #印出內容
                var_dump($mergeArray);
        
                #結束執行
                exit;
        
                }#if end

        #另存要寫入的資料
        $data=$mergeArray["content"];

        #寫入新內容到dbFile
        #涵式說明:
        #將多行字串寫入到檔案
        #回傳的結果:
        #$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前執行函數的名稱.
        #必填的參數:
        #$conf["fileName"],字串,爲要編輯的檔案名稱
        $conf["fileName"]=$dbFile;
        #$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容
        #$conf["inputString"][$i] 代表第 $i+1 行。
        $conf["inputString"]=$data;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略的參數:
        #$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
        $writeMultiLine=fileAccess::writeMultiLine($conf);
        unset($conf);

        #休息0.1秒
        usleep(100000);

        }#while end

?>