Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 915 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

#使用命名空間qbpwcf
namespace qbpwcf;

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

#涵式說明:
#呼叫shell執行系統命令,並取得回傳的內容.
#回傳的結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["error"],錯誤訊息陣列.
#$result["function"],當前執行的函數名稱.
#$result["cmd"],執行的指令內容.
#$result["output"],爲執行完二元碼後的輸出陣列.
#必填的參數
#$conf["command"],字串,要執行的指令與.
$conf["command"]="ps aux | grep 'tracepath www.nttu.edu.tw'";
#$conf["fileArgu"],字串,變數__FILE__的內容.
$conf["fileArgu"]=__FILE__;             
#可省略參數:
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
#$conf["argu"]=array("");
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
#$conf["arguIsAddr"]=array();
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
#$conf["enablePrintDescription"]="true";
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
#$conf["printDescription"]="";
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
#$conf["escapeshellarg"]="false";
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
#$conf["username"]="";
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
#$conf["password"]="";
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
#$conf["useScript"]="";
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
#$conf["inBackGround"]="";
#備註:
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
#參考資料:
#exec=>http://php.net/manual/en/function.exec.php
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php           
$callShell=external::callShell($conf);
unset($conf);

var_dump($callShell);

echo "finish!";

?>