Rev 37 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2015~2025 Min-Jhin,ChenThis file is part of QBPWCF.QBPWCF is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.QBPWCF is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with QBPWCF. If not, see <http://www.gnu.org/licenses/>.*/namespace qbpwcf;/*類別說明:跟文字命令列有關的類別.備註:無.*/class cmd{/*#函式說明:#當前類別被呼叫的靜態方法不存在時,將會執行該函式,回報該方法不存在.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$method,物件,為物件實體或類別名稱,會自動置入該參數.#$arguments,陣列,為呼叫方法時所用的參數.#參考資料:#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic*/public function __call($method,$arguments){#取得當前執行的函式$result["function"]=__FUNCTION__;#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";#設置所丟入的參數$result["error"][]=$arguments;#回傳結果return $result;}#function __call end/*#函式說明:#當前類別被呼叫的靜態方法不存在時,將會執行該函式,回報該方法不存在.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$method,物件,為物件實體或類別名稱,會自動置入該參數.#$arguments,陣列,為呼叫方法時所用的參數.#參考資料:#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic*/public static function __callStatic($method,$arguments){#取得當前執行的函式$result["function"]=__FUNCTION__;#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";#設置所丟入的參數$result["error"][]=$arguments;#回傳結果return $result;}#function __callStatic end/*#函式說明:#讀取標準I/O的一行輸入.並提供提示說明.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],取得的輸入內容.#必填參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["commentsArray"]=array("請輸入");#可省略參數:#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";#參考資料:#無.#備註:#無.*/public static function readLine($conf){#初始化要回傳的內容$result=array();#取得當前函式的名稱$result["function"]=__FUNCTION__;#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()=="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。#回傳的結果:#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#必填寫的參數:$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("commentsArray");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");#可以省略的參數:$conf["variableCheck"]["isexistMuti"]["variableType"]=array("array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);unset($conf["variableCheck"]["isexistMuti"]);#如果 $checkResult["status"] 等於 "false"if($checkResult["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $checkResult["passed"] 等於 "false"if($checkResult["passed"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $conf["newLineBreak"] 不存在if(!isset($conf["newLineBreak"])){$conf["newLineBreak"]="true";}#if end#根據 $conf["commentsArray"] 的元素數量foreach($conf["commentsArray"] as $comemntLine){#印出內容echo $comemntLine;#如果 $conf["newLineBreak"] 等於 "true"if($conf["newLineBreak"]=="true"){#換行echo "\n";}#if end}#foreach end#設置執行成功$result["status"]="true";#設置取的內容$result["content"]=trim(fgets(STDIN));#回傳結果return $result;}#function readLine end/*#函式說明:#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["content"],設定值內容.#必填參數:#$conf["readVarName"],字串,要從設定檔取得的變數名稱.$conf["readVarName"]="";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").#$conf["commentsArray"]=array();#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要,預設為"false".#$conf["forceRewrite"]="";#參考資料:#無.#備註:#無.*/public static function getFromConf(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()=="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("readVarName","fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("conf","commentsArray","forceRewrite");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".qbpwcf_tmp/cmd/getFromConf/conf.xml",array("請輸入變數 ".$conf["readVarName"]." 的內容"),"false");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["passed"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#轉換路徑為絕對路徑#函式說明:#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函式名稱.#$result["content"],網址,若是在命令列執行,則為"null".#$result["webPathFromRoot"],相對於網頁根目錄的路徑.#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.#必填參數:#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.$conf["csInformation::getInternetAddress"]["address"]=$conf["conf"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["csInformation::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".$conf["csInformation::getInternetAddress"]["userDir"]="true";#備註:#在命令列執行,所得的路徑是錯誤的。$getInternetAddress=fileAccess::getInternetAddress($conf["csInformation::getInternetAddress"]);unset($conf["csInformation::getInternetAddress"]);#如果轉換位置失敗if($getInternetAddress["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getInternetAddress;#回傳結果return $result;}#if end#取得轉換好的設定檔絕對位置$conf["conf"]=$getInternetAddress["fileSystemAbsoulutePosition"];#函式說明:檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的函式名稱.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["conf"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];#可省略參數#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".#$conf["userDir"]="true";#參考資料來源:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函式file_exists檢查的路徑為檔案系統的路徑$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果檢查設定檔是否存在失敗if($checkMultiFileExist["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果設定檔不存在if($checkMultiFileExist["allExist"]==="false"){#建立設定檔的路徑#函式說明:#確保路徑存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的函式名稱.#$result["path"],建立好的路徑字串.#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.#必填參數:#$conf["path"],要檢查的路徑$conf["fileAccess::validatePath"]["path"]=$conf["conf"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".$conf["fileAccess::validatePath"]["haveFileName"]="true";#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.#$conf["dirPermission"]="";$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);unset($conf["fileAccess::validatePath"]);#如果確保設定檔路徑失敗if($validatePath["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$validatePath;#回傳結果return $result;}#if end#建立設定檔#函式說明:#建立空的xml檔案#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],xml檔案的路徑.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::createEmptyXml"]["xmlPosition"]=$conf["conf"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::createEmptyXml"]["fileArgu"]=$conf["fileArgu"];#參考資料:#simplexmlelement=>http://php.net/manual/en/simplexmlelement.asxml.php$createEmptyXml=xml::createEmptyXml($conf["xml::createEmptyXml"]);unset($conf["xml::createEmptyXml"]);#如果建立設定檔失敗if($createEmptyXml["status"]=="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$createEmptyXml;#回傳結果return $result;}#if end#讀取要寫入到設定檔的變數#函式說明:#讀取標準I/O的一行輸入.並提供提示說明.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],取得的輸入內容.#必填參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["cmd::readLine"]["commentsArray"]=$conf["commentsArray"];#可省略參數:#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";$readLine=cmd::readLine($conf["cmd::readLine"]);unset($conf["cmd::readLine"]);#如果讀取字串失敗if($readLine["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$readLine;#回傳結果return $result;}#if end#取的新的設定值$confVal=$readLine["content"];#過濾 $conf["tag"][$i] 的 「::」 字元#函式說明:#處理字串避免網頁出錯#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式.#$result["content"],爲處理好的字串.#$result["error"],錯誤訊息陣列.#必填參數:$conf["stringProcess::correctCharacter"]["stringIn"]=$conf["readVarName"];#爲要處理的字串#可省略參數:$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("<",">","=","//","'","$","%","&","|","/*","*","#","\"",":");#爲被選擇要處理的字串/字元,須爲陣列值。#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);unset($conf["stringProcess::correctCharacter"]);#如果修正標籤名稱失敗if($correctCharacter["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$correctCharacter;#回傳結果return $result;}#if end#取得修正好的tag名稱$conf["readVarName"]=$correctCharacter["content"];#將設定值內容寫入到設定檔案裡面#函式說明:#在目標層級新增標籤與內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::addTag"]["xmlPosition"]=$conf["conf"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::addTag"]["tag"]=array($conf["readVarName"]);#$conf["tagValue"],字串,目標標籤的內容要放什麼.$conf["xml::addTag"]["tagValue"]=$confVal;#參考資料:#addchild->http://php.net/manual/en/simplexmlelement.addchild.php$addTag=xml::addTag($conf["xml::addTag"]);unset($conf["xml::addTag"]);#如果新增tag失敗if($addTag["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$addTag;#回傳結果return $result;}#if end}#if end#讀取設定檔的內容#函式說明:#取得xml特定標籤的內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["warning"],警告訊息陣列.#$result["function"],當前執行的函式名稱.#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.#$result["content"],xml物件的標籤內容.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::getContent"]["xmlPosition"]=$conf["conf"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::getContent"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::getContent"]["tag"]=array($conf["readVarName"]);$getContent=xml::getTagInfo($conf["xml::getContent"]);unset($conf["xml::getContent"]);#如果取得tag資訊失敗if($getContent["status"]==="false"){#如果是讀取時出錯if($getContent["error"]["error"][0]==="讀取xml檔案失敗!"){#判斷是否為檔案不完整所導致的錯誤#函式說明:#檢查多個字串裡面是否沒有多個任何篩選字存在#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式#$result["error"],函式錯誤訊息,若爲""則表示沒有錯誤#$result["filtered"],該字串是否為要過濾掉的識別陣列,"true"為要過濾掉的;"false"為不用過濾掉的#必填參數:$conf["search::filterMutiString"]["inputStr"]=array($getContent["error"]["error"][1]->message);#要過濾的字串陣列$conf["search::filterMutiString"]["filterWord"]=array("Opening and ending tag mismatch:","Premature end of data in tag","Couldn't find end of Start Tag","expected");#要過濾的字串不能含有該陣列元素之一$filterMutiString=search::filterMutiString($conf["search::filterMutiString"]);unset($conf["search::filterMutiString"]);#如果尋找前置關鍵字失敗if($filterMutiString["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$filterMutiString;#回傳結果return $result;}#if end#如果有找到前置關鍵字if($filterMutiString["filtered"][0]==="true"){#移除該xml檔案#函式說明:#移除檔案#回傳的結果:#$result["status"],"true"代表移除成功,"false"代表移除失敗.#$result["error"],錯誤訊息陣列#$result["warning"],警告訊息陣列#$result["function"],當前執行的函式名稱#必填參數:#$conf["fileAddress"],字串,要移除檔案的位置.$conf["fileAccess::delFile"]["fileAddress"]=$conf["conf"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.#$conf["commentsArray"]=array("");$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);unset($conf["fileAccess::delFile"]);#如果移除檔案失敗if($delFile["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$delFile;#回傳結果return $result;}#if end#遞迴取得xml檔案特定標籤的內容/*#函式說明:#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["content"],設定值內容.#必填參數:#$conf["readVarName"],字串,要從設定檔取得的變數名稱.$conf["readVarName"]="";#可省略參數:#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.#$conf["fileArgu"]=__FILE__;#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").#$conf["commentsArray"]=array();#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要,預設為"false".#$conf["forceRewrite"]="";*/return cmd::getFromConf($conf=$result["argu"]);}#if end}#if end#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getContent;#回傳結果return $result;}#if end#如果要取得的tag不存在if($getContent["tagExist"]==="false"){#讀取要寫入到設定檔的變數#函式說明:#讀取標準I/O的一行輸入.並提供提示說明.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],取得的輸入內容.#必填參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["cmd::readLine"]["commentsArray"]=$conf["commentsArray"];#可省略參數:#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";$readLine=cmd::readLine($conf["cmd::readLine"]);unset($conf["cmd::readLine"]);#如果讀取字串失敗if($readLine["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$readLine;#回傳結果return $result;}#if end#取的新的設定值$confVal=$readLine["content"];#將設定值內容寫入到設定檔案裡面#函式說明:#在目標層級新增標籤與內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::addTag"]["xmlPosition"]=$conf["conf"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::addTag"]["tag"]=array($conf["readVarName"]);#$conf["tagValue"],字串,目標標籤的內容要放什麼.$conf["xml::addTag"]["tagValue"]=$confVal;#參考資料:#addchild->http://php.net/manual/en/simplexmlelement.addchild.php$addTag=xml::addTag($conf["xml::addTag"]);unset($conf["xml::addTag"]);#如果新增tag失敗if($addTag["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$addTag;#回傳結果return $result;}#if end#讀取設定檔的內容#函式說明:#取得xml特定標籤的內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["warning"],警告訊息陣列.#$result["function"],當前執行的函式名稱.#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.#$result["content"],xml物件的標籤內容.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::getContent"]["xmlPosition"]=$conf["conf"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::getContent"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::getContent"]["tag"]=array($conf["readVarName"]);$getContent=xml::getTagInfo($conf["xml::getContent"]);unset($conf["xml::getContent"]);#如果取得tag資訊失敗if($getContent["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getContent;#回傳結果return $result;}#if end#如果要取得的tag不存在if($getContent["tagExist"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getContent;#回傳結果return $result;}#if end}#if end#如果要強制覆寫設定值if($conf["forceRewrite"]==="true"){#讀取要寫入到設定檔的變數#函式說明:#讀取標準I/O的一行輸入.並提供提示說明.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],取得的輸入內容.#必填參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["cmd::readLine"]["commentsArray"]=$conf["commentsArray"];#可省略參數:#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";$readLine=cmd::readLine($conf["cmd::readLine"]);unset($conf["cmd::readLine"]);#如果讀取字串失敗if($readLine["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$readLine;#回傳結果return $result;}#if end#取的新的設定值$confVal=$readLine["content"];#將設定值內容寫入到設定檔案裡面#函式說明:#在目標層級新增標籤與內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::addTag"]["xmlPosition"]=$conf["conf"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::addTag"]["tag"]=array($conf["readVarName"]);#$conf["tagValue"],字串,目標標籤的內容要放什麼.$conf["xml::addTag"]["tagValue"]=$confVal;#參考資料:#addchild->http://php.net/manual/en/simplexmlelement.addchild.php$addTag=xml::updateTag($conf["xml::addTag"]);unset($conf["xml::addTag"]);#如果新增tag失敗if($addTag["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$addTag;#回傳結果return $result;}#if end#讀取設定檔的內容#函式說明:#取得xml特定標籤的內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["warning"],警告訊息陣列.#$result["function"],當前執行的函式名稱.#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.#$result["content"],xml物件的標籤內容.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::getContent"]["xmlPosition"]=$conf["conf"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::getContent"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::getContent"]["tag"]=array($conf["readVarName"]);$getContent=xml::getTagInfo($conf["xml::getContent"]);unset($conf["xml::getContent"]);#如果取得tag資訊失敗if($getContent["status"]=="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getContent;#回傳結果return $result;}#if end#如果要取得的tag不存在if($getContent["tagExist"]=="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getContent;#回傳結果return $result;}#if end}#if end#設置讀取到的設定值$result["content"]=$getContent["content"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function getFromConf end/*#函式說明:#將資料夾打包成tar.gz檔案#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["storePlace"],檔案輸出後的位置與名稱.#必填參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["commentsArray"]=array("正在打包");#$conf["compressedFolder"],字串,要打包的資料夾位置$conf["compressedFolder"]="";#$conf["createdTarGzFile"],字串,打包好的檔案要放在哪裡,副檔名「.tar.gz」會自動加上.$conf["createdTarGzFile"]="";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";#參考資料:#無.#備註:#產生的壓縮檔內的路徑是從根目錄開始的.#移到fileAccess類別會比較恰當*/public static function makeTarGzFile(&$conf){#初始化要回傳的內容$result=array();#取得當前函式的名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("commentsArray","compressedFolder","createdTarGzFile","fileArgu");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string","string");#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("newLineBreak");#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查失敗if($checkResult["status"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果檢查不通過if($checkResult["passed"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $conf["breakNewLine"] 沒有設置if(!isset($conf["breakNewLine"])){# 將 $conf["breakNewLine"] 設為 "true"$conf["breakNewLine"]="true";}#if end#針對$commensArray的每個元素foreach($conf["commentsArray"] as $comment){#印出描述echo $comment;#如果 $conf["breakNewLine"] 等於 "true"if($conf["breakNewLine"]=="true"){#印出斷行符號echo "\n";}#if end}#foreach end#取得當前的工作目錄$workingDir=$_SERVER["PWD"];#檢查 $conf["createdTarGzFile"] 的開頭是否為 "/"#函式說明:#取得字首一樣的字串,並回傳其字串。#回傳的結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["returnString"],爲符合字首條件的字串內容.#必填參數:$conf["search"]["getMeetConditionsString"]["checkString"]=$conf["createdTarGzFile"];#要檢查的字串$conf["search"]["getMeetConditionsString"]["frontWord"]="/";#用來檢查字首應該要有什麼字串#用到的函式:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。$serachResult=search::getMeetConditionsString($conf["search"]["getMeetConditionsString"]);unset($conf["search"]["getMeetConditionsString"]);#如果 $serachResult["status"] 等於 "false"if($serachResult["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$serachResult;#回傳結果return $result;}#if end#如果 $serachResult["founded"] 等於 "false"if($serachResult["founded"]=="false"){#那就代表 $conf["createdTarGzFile"] 不是從根目錄開始的路徑位置$conf["createdTarGzFile"]=$workingDir."/".$conf["createdTarGzFile"];}#if end#檢查 $conf["compressedFolder"] 的開頭是否為 "/"#函式說明:#取得字首一樣的字串,並回傳其字串。#回傳的結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["returnString"],爲符合字首條件的字串內容.#必填參數:$conf["search"]["getMeetConditionsString"]["checkString"]=$conf["compressedFolder"];#要檢查的字串$conf["search"]["getMeetConditionsString"]["frontWord"]="/";#用來檢查字首應該要有什麼字串#用到的函式:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。$serachResult=search::getMeetConditionsString($conf["search"]["getMeetConditionsString"]);unset($conf["search"]["getMeetConditionsString"]);#如果 $serachResult["status"] 等於 "false"if($serachResult["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$serachResult;#回傳結果return $result;}#if end#如果 $serachResult["founded"] 等於 "false"if($serachResult["founded"]=="false"){#那就代表 $conf["compressedFolder"] 不是從根目錄開始的路徑位置$conf["compressedFolder"]=$workingDir."/".$conf["compressedFolder"];}#if end#為 $conf["createdTarGzFile"] 加上 .tar 的副檔名$conf["createdTarGzFile"]=$conf["createdTarGzFile"].".tar";#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="tar";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-cvf",$conf["createdTarGzFile"],$conf["compressedFolder"]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行外部程式失敗if($callShell["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#取得要清除的中介資料$deletedTarFile=$conf["createdTarGzFile"];#取得要壓縮的檔案路徑名稱$conf["compressedFolder"]=$conf["createdTarGzFile"];#為 $conf["createdTarGzFile"] 加上 .gz 的副檔名$conf["createdTarGzFile"]=$conf["createdTarGzFile"].".gz";#壓縮 tar 檔案#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="gzip";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-cv",$conf["compressedFolder"],">>",$conf["createdTarGzFile"]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行外部程式失敗if($callShell["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#檢查 $conf["createdTarGzFile"] 的開頭是否為 "/"#函式說明:#取得字首一樣的字串,並回傳其字串。#回傳的結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["returnString"],爲符合字首條件的字串內容.#必填參數:$conf["search"]["getMeetConditionsString"]["checkString"]=$conf["createdTarGzFile"];#要檢查的字串$conf["search"]["getMeetConditionsString"]["frontWord"]="/";#用來檢查字首應該要有什麼字串#用到的函式:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。$serachResult=search::getMeetConditionsString($conf["search"]["getMeetConditionsString"]);unset($conf["search"]["getMeetConditionsString"]);#如果 $serachResult["status"] 等於 "false"if($serachResult["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$serachResult;#回傳結果return $result;}#if end#如果 $serachResult["founded"] 等於 "false"if($serachResult["founded"]=="false"){#那就代表 $conf["createdTarGzFile"] 不是從根目錄開始的路徑位置$conf["createdTarGzFile"]=$workingDir."/".$conf["createdTarGzFile"];}#if end#儲存輸出檔案的位置$result["storePlace"]=$conf["createdTarGzFile"];#函式說明:#移除檔案#回傳的結果:#$result["status"],"true"代表移除成功,"false"代表移除失敗.#$result["error"],錯誤訊息陣列#$result["warning"],警告訊息陣列#$result["function"],當前執行的函式名稱#必填參數:$conf["fileAccess::delFile"]["fileAddress"]=$deletedTarFile;#要移除檔案的位置#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];$del=fileAccess::delFile($conf["fileAccess::delFile"]);unset($conf["fileAccess::delFile"]);#如果 $del["status"] 等於 "false"#亦即移除檔案失敗if($del["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$del;#回傳結果return $result;}#if end#執行到這邊可能沒有錯誤了#設置執行成功$result["status"]="true";#回傳結果return $result;}#function makeTarGzFile end/*#函式說明:#將資料夾打包成.zst檔案#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["storePlace"],檔案輸出後的位置與名稱.#必填參數:#$conf["target"],字串,要打包的檔案.$conf["target"]="";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["commentsArray"]=array("正透過zstd壓縮");#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.#$conf["path"]="./";#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.#$conf["delAfterSuc"]="false";#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.#$conf["overwrite"]="true";#參考資料:#無.#備註:#無.*/public static function makeZstFile(&$conf){#初始化要回傳的內容$result=array();#取得當前函式的名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("target","fileArgu");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","newLineBreak","path","delAfterSuc","overwrite");#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string","string");#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true","./","false","false");#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查失敗if($checkResult["status"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果檢查不通過if($checkResult["passed"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $conf["breakNewLine"] 沒有設置if(!isset($conf["breakNewLine"])){# 將 $conf["breakNewLine"] 設為 "true"$conf["breakNewLine"]="true";}#if end#針對$commensArray的每個元素foreach($conf["commentsArray"] as $comment){#印出描述echo $comment;#如果 $conf["breakNewLine"] 等於 "true"if($conf["breakNewLine"]=="true"){#印出斷行符號echo PHP_EOL;}#if end}#foreach end#初始化儲存要壓縮的檔案名稱與位置$inputFile=$conf["target"];#初始化原始要產生的壓縮檔案位置名稱$result["storePlace"]=$conf["target"].".zst";#如果path不為"/"結束if($conf["path"][strlen($conf["path"])-1]!=="/"){#串接 "/" 到結尾$conf["path"]=$conf["path"]."/";}#if end#設置產生的檔案位置與名稱$result["storePlace"]=$conf["path"].$result["storePlace"];#設置原始的檔案位置與名稱$inputFile=$conf["path"].$inputFile;#確認檔案有存在#函式說明:#檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($result["storePlace"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".$conf["fileAccess::checkMultiFileExist"]["web"]="false";#參考資料來源:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑#$result["varName"][$i]結果未實作$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果失敗if($checkMultiFileExist["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果壓縮檔已經存在if($checkMultiFileExist["allExist"]==="true"){#如果不要覆蓋既有的檔案if($conf["overwrite"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"][]="zst壓縮檔已經存在";#回傳結果return $result;}#if end#反之else{#移除已經存在的zst壓縮檔#函式說明:#移除檔案#回傳結果:#$result["status"],"true"代表移除成功,"false"代表移除失敗.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],當前函式使用的參數.#必填參數:#$conf["fileAddress"],字串,要移除檔案的位置.$conf["fileAccess::delFile"]["fileAddress"]=$result["storePlace"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.#$conf["commentsArray"]=array("");#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.#$conf["allowDelSymlink"]="true";#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.#$conf["allowDelFolder"]="true";#參考資料:#無.#備註:#無.$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);unset($conf["fileAccess::delFile"]);#如果執行失敗if($delFile["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$delFile;#回傳結果return $result;}#if end}#else end}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="cd";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($conf["path"],";","zstd",$conf["target"]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").$conf["external::callShell"]["arguIsAddr"]=array("true","false","false","false");#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"".#$conf["external::callShell"]["plainArgu"]=array("false","true","true","false");#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行外部程式失敗if($callShell["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#確認檔案有存在#函式說明:#檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($result["storePlace"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".$conf["fileAccess::checkMultiFileExist"]["web"]="false";#參考資料來源:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑#$result["varName"][$i]結果未實作$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果失敗if($checkMultiFileExist["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果壓縮檔產生失敗if($checkMultiFileExist["allExist"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果要移除原始檔案if($conf["delAfterSuc"]==="true"){#函式說明:#移除檔案#回傳結果:#$result["status"],"true"代表移除成功,"false"代表移除失敗.#$result["error"],錯誤訊息陣列#$result["warning"],警告訊息陣列#$result["function"],當前執行的函數名稱#必填參數:#$conf["fileAddress"],字串,要移除檔案的位置.$conf["fileAccess::delFile"]["fileAddress"]=$inputFile;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.#$conf["commentsArray"]=array("");#備註:#無.$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);unset($conf["fileAccess::delFile"]);#如果失敗if($delFile["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$delFile;#回傳結果return $result;}#if end}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function makeZstFile end/*#函式說明:#將資料夾打包成.tar檔案#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["storePlace"],檔案輸出後的位置與名稱.#必填參數:#$conf["target"],字串,要打包的檔案.$conf["target"]="";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["commentsArray"]=array("正透過tar打包");#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.#$conf["path"]="./";#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.#$conf["delAfterSuc"]="false";#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.#$conf["overwrite"]="true";#參考資料:#無.#備註:#無.*/public static function makeTarFile(&$conf){#初始化要回傳的內容$result=array();#取得當前函式的名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("target","fileArgu");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","newLineBreak","path","delAfterSuc","overwrite");#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string","string");#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true","./","false","false");#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查失敗if($checkResult["status"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果檢查不通過if($checkResult["passed"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $conf["breakNewLine"] 沒有設置if(!isset($conf["breakNewLine"])){# 將 $conf["breakNewLine"] 設為 "true"$conf["breakNewLine"]="true";}#if end#如果需要輸出提示if(isset($conf["commentsArray"])){#針對$commensArray的每個元素foreach($conf["commentsArray"] as $comment){#印出描述echo $comment;#如果 $conf["breakNewLine"] 等於 "true"if($conf["breakNewLine"]=="true"){#印出斷行符號echo PHP_EOL;}#if end}#foreach end}#if end#初始化儲存要壓縮的檔案名稱與位置$inputFile=$conf["target"];#初始化原始要產生的壓縮檔案位置名稱$result["storePlace"]=$conf["target"].".tar";#如果路徑不是 "./" 也不是 "../"if($conf["path"]!=="./" && $conf["path"]!=="../"){#檔案位置與名稱前面加上"/"$result["storePlace"]="/".$result["storePlace"];#檔案位置與名稱前面加上"/"$inputFile="/".$inputFile;}#if end#設置產生的檔案位置與名稱$result["storePlace"]=$conf["path"].$result["storePlace"];#設置原始的檔案位置與名稱$inputFile=$conf["path"].$inputFile;#確認檔案有存在#函式說明:#檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($result["storePlace"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;#可省略參數:#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".$conf["fileAccess::checkMultiFileExist"]["web"]="false";#參考資料來源:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑#$result["varName"][$i]結果未實作$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果失敗if($checkMultiFileExist["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果壓縮檔已經存在if($checkMultiFileExist["allExist"]==="true"){#如果不要覆蓋既有的檔案if($conf["overwrite"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"][]="tar檔已經存在";#回傳結果return $result;}#if end#反之else{#移除已經存在的zst壓縮檔#函式說明:#移除檔案#回傳結果:#$result["status"],"true"代表移除成功,"false"代表移除失敗.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],當前函式使用的參數.#必填參數:#$conf["fileAddress"],字串,要移除檔案的位置.$conf["fileAccess::delFile"]["fileAddress"]=$result["storePlace"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.#$conf["commentsArray"]=array("");#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.#$conf["allowDelSymlink"]="true";#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.#$conf["allowDelFolder"]="true";#參考資料:#無.#備註:#無.$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);unset($conf["fileAccess::delFile"]);#如果執行失敗if($delFile["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$delFile;#回傳結果return $result;}#if end}#else end}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="cd";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($conf["path"],";","tar","-c","-v","-f",$conf["target"].".tar",$conf["target"]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").$conf["external::callShell"]["arguIsAddr"]=array("true","false","false","false","false","false","false","false");#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"".#$conf["external::callShell"]["plainArgu"]=array("false","true","true","false");#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行外部程式失敗if($callShell["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#確認檔案有存在#函式說明:#檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($result["storePlace"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;#可省略參數:#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".$conf["fileAccess::checkMultiFileExist"]["web"]="false";#參考資料來源:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑#$result["varName"][$i]結果未實作$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果失敗if($checkMultiFileExist["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果壓縮檔產生失敗if($checkMultiFileExist["allExist"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果要移除原始檔案if($conf["delAfterSuc"]==="true"){#函式說明:#移除檔案#回傳結果:#$result["status"],"true"代表移除成功,"false"代表移除失敗.#$result["error"],錯誤訊息陣列#$result["warning"],警告訊息陣列#$result["function"],當前執行的函數名稱#必填參數:#$conf["fileAddress"],字串,要移除檔案的位置.$conf["fileAccess::delFile"]["fileAddress"]=$inputFile;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.#$conf["commentsArray"]=array("");#備註:#無.$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);unset($conf["fileAccess::delFile"]);#如果失敗if($delFile["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$delFile;#回傳結果return $result;}#if end}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function makeTarFile end/*#函式說明:#將資料夾打包成.tar.zst檔案#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["storePlace"],檔案輸出後的位置與名稱.#必填參數:#$conf["target"],字串,要打包的檔案.$conf["target"]="";#可省略參數:#$conf["commentsArrayForTar"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述,預設為array("正產生 tar 檔案");#$conf["commentsArrayForTar"]=array("正產生 tar 檔案");#$conf["commentsArrayForZst"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述,預設為array("正產生 zst 檔案");#$conf["commentsArrayForZst"]=array("正產生 zst 檔案");#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.#$conf["path"]="./";#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.#$conf["delAfterSuc"]="false";#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.#$conf["overwrite"]="true";#參考資料:#無.#備註:#無.*/public static function makeTarZstFile(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函數".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["simpleError"],簡單表示的錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("target");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArrayForTar","commentsArrayForZst","newLineBreak","path","delAfterSuc","overwrite");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","string","string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"true","./","false","false");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果 $checkArguments["status"] 等於 "false"if($checkArguments["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果 $checkArguments["passed"] 等於 "false"if($checkArguments["passed"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#將資料夾打包成.tar檔案#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["storePlace"],檔案輸出後的位置與名稱.#必填參數:#$conf["target"],字串,要打包的檔案.$conf["cmd::makeTarFile"]["target"]=$conf["target"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["cmd::makeTarFile"]["fileArgu"]=__FILE__;#可省略參數:#如果有設置 $conf["commentsArrayForTar"]if(isset($conf["commentsArrayForTar"])){#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["cmd::makeTarFile"]["commentsArray"]=$conf["commentsArrayForTar"];}#if end#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.$conf["cmd::makeTarFile"]["newLineBreak"]=$conf["newLineBreak"];#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.$conf["cmd::makeTarFile"]["path"]=$conf["path"];#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.$conf["cmd::makeTarFile"]["delAfterSuc"]=$conf["delAfterSuc"];#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.$conf["cmd::makeTarFile"]["overwrite"]=$conf["overwrite"];#參考資料:#無.#備註:#無.$makeTarFile=cmd::makeTarFile($conf["cmd::makeTarFile"]);unset($conf["cmd::makeTarFile"]);#如果 $makeTarFile["status"] 等於 "false"if($makeTarFile["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$makeTarFile;#回傳結果return $result;}#if end#函式說明:#將資料夾打包成.zst檔案#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["storePlace"],檔案輸出後的位置與名稱.#必填參數:#$conf["target"],字串,要打包的檔案.$conf["cmd::makeZstFile"]["target"]=$conf["target"].".tar";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["cmd::makeZstFile"]["fileArgu"]=__FILE__;#可省略參數:#如果有設置 $conf["commentsArrayForZst"]if(isset($conf["commentsArrayForZst"])){#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["cmd::makeZstFile"]["commentsArray"]=$conf["commentsArrayForZst"];}#if end#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.$conf["cmd::makeZstFile"]["newLineBreak"]=$conf["newLineBreak"];#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.$conf["cmd::makeZstFile"]["path"]=$conf["path"];#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.$conf["cmd::makeZstFile"]["delAfterSuc"]=$conf["delAfterSuc"];#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.$conf["cmd::makeZstFile"]["overwrite"]=$conf["overwrite"];#參考資料:#無.#備註:#無.$makeZstFile=cmd::makeZstFile($conf["cmd::makeZstFile"]);unset($conf["cmd::makeZstFile"]);#如果 $makeZstFile["status"] 等於 "false"if($makeZstFile["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$makeZstFile;#回傳結果return $result;}#if end#取得壓縮好的檔案路徑與名稱$result["content"]=$makeZstFile["storePlace"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function makeTarZstFile end/*#函式說明:#移動檔案並重新命名,過程會提供提示說明.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["commentsArray"]=array("正在移動");#$conf["movedFilePositionAndName"],字串,為想要移動的檔案位置與名稱.$conf["movedFilePositionAndName"]="";#$conf["movedTargetFileAndName"],字串,要移動到的位置與新檔案名稱.$conf["movedTargetFileAndName"]="";#可省略參數:#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";#參考資料:#rename函式用法#http://php.net/manual/en/function.rename.php#備註:#無.*/public static function mv($conf){#初始化要回傳的內容$result=array();#取得當前函式的名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#函式說明:#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。#回傳的結果:#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#必填寫的參數:$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("commentsArray","movedFilePositionAndName","movedTargetFileAndName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");#可以省略的參數:$conf["variableCheck"]["isexistMuti"]["variableType"]=array("array","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);unset($conf["variableCheck"]["isexistMuti"]);#如果 $checkResult["status"] 等於 "false"if($checkResult["status"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $checkResult["passed"] 等於 "false"if($checkResult["passed"]==="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $conf["breakNewLine"] 沒有設置if(!isset($conf["breakNewLine"])){# 將 $conf["breakNewLine"] 設為 "true"$conf["breakNewLine"]="true";}#if end#針對$commensArray的每個元素foreach($conf["commentsArray"] as $comment){#印出描述echo $comment;#如果 $conf["breakNewLine"] 等於 "true"if($conf["breakNewLine"]==="true"){#印出斷行符號echo "\n";}#if end}#foreach end#重新命名檔案#回傳結果為 TRUE 的話if(rename($conf["movedFilePositionAndName"],$conf["movedTargetFileAndName"])==TRUE){#代表檔案移動、重新命名成功#設置執行正常$result["status"]="true";#回傳結果return $result;}#if end#反之代表移動、重新命名失敗else{#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="移動、重新命名失敗";#回傳結果return $result;}#else end#執行到這邊代表不正常#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="不應該出現的例外";#回傳結果return $result;}#function mv end/*#函式說明:#檢查是否為相對路徑,並將之轉換為絕對路徑#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息.#$result["absolutePath"],轉換好的路徑檔案字串.#必填參數:#$conf["checkedPath"],字串,要檢查是不是絕對路徑的路徑檔案字串.$conf["checkedPath"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function changeToAbsolutePath($conf){#初始化要回傳的內容$result=array();#取得當前函式的名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。#回傳的結果:#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#必填寫的參數:$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("checkedPath");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");#可以省略的參數:$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。#備註:#功能與checkExistAndType函式相同$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);unset($conf["variableCheck"]["isexistMuti"]);#如果 $checkResult["status"] 等於 "false"if($checkResult["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $checkResult["passed"] 等於 "false"if($checkResult["passed"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#取得當前的工作目錄$workingDir=$_SERVER["PWD"];#檢查 $conf["checkedPath"] 的開頭是否為 "/"#函式說明:#取得字首一樣的字串,並回傳其字串。#回傳的結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["returnString"],爲符合字首條件的字串內容。#必填參數:$conf["search"]["getMeetConditionsString"]["checkString"]=$conf["checkedPath"];#要檢查的字串$conf["search"]["getMeetConditionsString"]["frontWord"]="/";#用來檢查字首應該要有什麼字串#用到的函式:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。$serachResult=search::getMeetConditionsString($conf["search"]["getMeetConditionsString"]);unset($conf["search"]["getMeetConditionsString"]);#如果執行search::getMeetConditionsString失敗if($serachResult["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$serachResult;#回傳結果return $result;}#if end#如果 $serachResult["founded"] 等於 "false"if($serachResult["founded"]=="false"){#那就代表 $conf["checkedPath"] 不是從根目錄開始的路徑位置$conf["checkedPath"]=$workingDir."/".$conf["checkedPath"];}#if end#執行到這邊算是執行成功#設置執行成功的識別$result["status"]="true";#設置轉換好的檔案目錄絕對路徑字串$result["absolutePath"]=$conf["checkedPath"];#回傳結果return $result;}#function changeToAbsolutePath end/*#函式說明:#檢查多個路徑字串是否為相對路徑,並將之轉換為絕對路徑#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["absolutePath"][$i],為轉換好的第$i+1個路徑檔案陣列字串.#必填參數:#$conf["checkedPathArray"],字串陣列,要檢查是不是絕對路徑的路徑檔案字串陣列.$conf["checkedPathArray"]=array("");#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function changeMultiToAbsolutePath($conf){#初始化要回傳的內容$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。#回傳的結果:#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#必填寫的參數:$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("checkedPathArray");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");#可以省略的參數:$conf["variableCheck"]["isexistMuti"]["variableType"]=array("array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。#備註:#功能與checkExistAndType函式相同$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);unset($conf["variableCheck"]["isexistMuti"]);#如果 $checkResult["status"] 等於 "false"if($checkResult["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $checkResult["passed"] 等於 "false"if($checkResult["passed"]=="fssle"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#有幾個 $conf["checkedPathArray"] 就執行幾次for($i=0;$i<count($conf["checkedPathArray"]);$i++){#函式說明:#檢查是否為相對路徑,並將之轉換為絕對路徑#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["absolutePath"],轉換好的路徑檔案字串.#必填參數:#$conf["checkedPath"],字串,要檢查是不是絕對路徑的路徑檔案字串.$conf["cmd"]["changeToAbsolutePath"]["checkedPath"]=$conf["checkedPathArray"][$i];$processedPath=cmd::changeToAbsolutePath($conf["cmd"]["changeToAbsolutePath"]);unset($conf["cmd"]["changeToAbsolutePath"]);#如果 cmd::changeToAbsolutePath 執行失敗if($processedPath["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$processedPath;#回傳結果return $result;}#if end#設置轉換好的檔案目錄絕對路徑字串$result["absolutePath"][$i]=$processedPath["absolutePath"];}#for end#執行到這邊算是執行成功#設置執行成功的識別$result["status"]="true";#回傳結果return $result;}#function changeMultiToAbsolutePath end/*#函式說明:#將資料夾打包成iso檔#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["storePlace"],檔案輸出後的位置與名稱.#$result["execStr"],建立iso檔時所使用的系統呼叫指令內容字串.#必填參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["commentsArray"]=array("正在製作iso檔");#$conf["targetInRoot"],字串陣列,要放在iso檔根目錄底下的多個檔案位置,array("*")代表目錄底下的所有檔案目錄.$conf["targetInRoot"]=array("");#$conf["createdIsoFile"],字串,打包好的檔案要放在哪裡,副檔名「.iso」會自動加上.$conf["createdIsoFile"]="";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["folderInRoot"],字串陣列,要放在iso檔根目錄底下的資料夾#$conf["folderInRoot"]=array();#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";#參考資料:#無.#備註:#無.*/public static function packetToISO(&$conf){#初始化要回傳的內容$result=array();#取得當前函式的名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("commentsArray","targetInRoot","createdIsoFile","fileArgu");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","string","string");#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("folderInRoot","newLineBreak");#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true");#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查失敗if($checkResult["status"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果檢查不通過if($checkResult["passed"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#取得當前的工作目錄$workingDir=$_SERVER["PWD"];#針對$commensArray的每個元素foreach($conf["commentsArray"] as $comment){#印出描述echo $comment;#如果 $conf["newLineBreak"] 等於 "true"if($conf["newLineBreak"]=="true"){#印出斷行符號echo "\n";}#if end}#foreach end#將 $conf["createdIsoFile"] 轉換為絕對路徑#函式說明:#檢查是否為相對路徑,並將之轉換為絕對路徑#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["absolutePath"],轉換好的路徑檔案字串.#必填參數:#$conf["cmd"]["changeToAbsolutePath"]["checkedPath"],"字串",要檢查是不是絕對路徑的路徑檔案字串.$conf["cmd"]["changeToAbsolutePath"]["checkedPath"]=$conf["createdIsoFile"];$processedCreatedIsoFileStr=cmd::changeToAbsolutePath($conf["cmd"]["changeToAbsolutePath"]);unset($conf["cmd"]["changeToAbsolutePath"]);#如果轉換為絕對路徑失敗if($processedCreatedIsoFileStr["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$processedCreatedIsoFileStr;#回傳結果return $result;}#if end#取得絕對路徑$conf["createdIsoFile"]=$processedCreatedIsoFileStr["absolutePath"];#初始化用來儲存要放進iso檔裡面的各個檔案目錄$targetInRootArray=array();#針對 $conf["compresseeTarget"] 中每個元素foreach($conf["targetInRoot"] as $targetInRoot){#將給個 $conf["compresseeTarget"] 轉換為絕對路徑#函式說明:#檢查是否為將相對路徑,並將之轉換為絕對路徑#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["absolutePath"],轉換好的路徑檔案字串.#必填參數:#$conf["checkedPath"],"字串",要檢查是不是絕對路徑的路徑檔案字串.$conf["cmd"]["changeToAbsolutePath"]["checkedPath"]=$targetInRoot;$AbsolutePath=cmd::changeToAbsolutePath($conf["cmd"]["changeToAbsolutePath"]);unset($conf["cmd"]["changeToAbsolutePath"]);#如果轉換為絕對路徑失敗if($AbsolutePath["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$AbsolutePath;#回傳結果return $result;}#if end#取得絕對路徑$targetInRootArray[]=$AbsolutePath["absolutePath"];}#foreach end#取得轉換為絕對路徑的檔案目錄字串陣列$conf["targetInRoot"]=$targetInRootArray;#初始化用來儲存要放進iso檔根目錄裡面的各個以空格分隔的檔案字串$isoContentString="";#檢查每個 $conf["targetInRoot"] 檔案 是否存在#函式說明:檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的函式名稱.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["targetInRoot"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];#可省略參數#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".#$conf["userDir"]="true";#參考資料來源:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函式file_exists檢查的路徑為檔案系統的路徑$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果檢查檔案是否存在失敗if($checkMultiFileExist["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果沒有每個檔案都存在if($checkMultiFileExist["allExist"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#將 $conf["targetInRoot"] 轉換為以空格分隔的字串for($i=0;$i<count($conf["targetInRoot"]);$i++){#如果是第一筆if($i==0){#串接第一個 $isoContent 字串$isoContentString=$isoContentString."\"".$conf["targetInRoot"][$i]."\"";}#if end#反之不是第一筆else{#串接每個 $isoContent 字串$isoContentString=$isoContentString." \"".$conf["targetInRoot"][$i]."\"";}#else end}#for end#取得要放進iso檔根目錄底下以空格分隔的檔案目錄字串$conf["targetInRoot"]=$isoContentString;#將多個目錄的路徑轉換為絕對路徑#函式說明:#檢查多個路徑字串是否為相對路徑,並將之轉換為絕對路徑#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["absolutePath"][$i],為轉換好的第$i+1個路徑檔案陣列字串.#必填參數:#$conf["cmd"]["changeMultiToAbsolutePath"]["checkedPathArray"],字串陣列,要檢查是不是絕對路徑的路徑檔案字串陣列.$conf["cmd"]["changeMultiToAbsolutePath"]["checkedPathArray"]=$conf["folderInRoot"];$processedFolderPath=cmd::changeMultiToAbsolutePath($conf["cmd"]["changeMultiToAbsolutePath"]);unset($conf["cmd"]["changeMultiToAbsolutePath"]);#如果將多個目錄的路徑轉換成絕對路徑失敗if($processedFolderPath["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$processedFolderPath;#回傳結果return $result;}#if end#檢查每個 $processedFolderPath["absolutePath"] 目錄是否存在#函式說明:檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的函式名稱.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$processedFolderPath["absolutePath"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];#可省略參數#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".#$conf["userDir"]="true";#參考資料來源:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函式file_exists檢查的路徑為檔案系統的路徑$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果檢查檔案是否存在失敗if($checkMultiFileExist["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果沒有每個檔案都存在if($checkMultiFileExist["allExist"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#初始化儲存 -graft-point 後面接的字串$graftPointStr="";#針對每個處理過的目錄路徑for($i=0;$i<count($processedFolderPath["absolutePath"]);$i++){#如果是第一筆if($i==0){$graftPointStr="-graft-point \"".$conf["folderInRoot"][$i]."\"=\"".$processedFolderPath["absolutePath"][$i]."\"";}#if end#反之不是第一筆else{#將之變成 -graft-point inputDir=dirNameInISO 的格式$graftPointStr=$graftPointStr." \"".$conf["folderInRoot"][$i]."\"=\"".$processedFolderPath["absolutePath"][$i]."\"";}#else end}#for end#執行的系統命令字串#$result["execStr"]="genisoimage -iso-level 4 -J -L -R ".$graftPointStr." ".$conf["targetInRoot"]." > \"".$conf["createdIsoFile"].".iso\"");#$result["execStr"]=" ".." ".." > \"".\"";#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="genisoimage";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-iso-level","4","-J","-L","-R","-joliet-long",$graftPointStr,$conf["targetInRoot"],">",$conf["createdIsoFile"].".iso");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果產出iso檔失敗if($callShell["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#執行到這邊算是執行成功#設置執行成功的識別$result["status"]="true";#設置輸出的iso檔路徑$result["storePlace"]=$conf["createdIsoFile"].".iso";#回傳結果return $result;}#function packetToISO end/*#函式說明:#轉換攝氏溫度爲華氏溫度#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["C"],華氏溫度#必填參數:#$conf["temperatur"]="";#輸入的溫度,結尾必須加上C代表攝氏,F代表華氏#可省略參數:#$conf["useC"]="true";#輸入內容是否使用單位C、F,如果要則設爲"true";反之不使用。#$conf["useF"]="true";#輸出內容是否使用單位C、F,如果要則設爲"true";反之不使用。#$conf["points"]="1";#要算到小數點後第幾位,並且四捨五入,預設是不限定小數點位數。#參考資料:#無.#備註:#原始公式:F = 9C / 5 + 32*/public static function transferTemperature($conf){#初始化要回傳的內容$result=array();#取得當前函式的名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。#回傳的結果:#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#必填寫的參數:$conf["variableCheck"]["isexistMuti"]["varInput"]=#conf;#要檢查的陣列變數$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("temperatur");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");#可以省略的參數:#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);unset($conf["variableCheck"]["isexistMuti"]);#如果 $checkResult["status"] 等於 "false"if($checkResult["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $checkResult["passed"] 等於 "false"if($checkResult["passed"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#判斷輸入是華氏溫度還是攝氏溫度#將字串內容分割成一個字一個元素$spiltedStr=str_split($conf["temperature"]);#將輸入的C或F踢除,以便進行計算#函式說明:#處理字串避免網頁出錯#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式.#$result["content"],爲處理好的字串.#$result["error"],錯誤訊息陣列.#必填參數:$conf["stringProcess"]["correctCharacter"]["stringIn"]=$conf["temperature"];#爲要處理的字串#可省略參數:$conf["selectedCharacter"]=array("C","F");#爲被選擇要處理的字串/字元,須爲陣列值。#若不設定則預設爲要將這些字串作替換("<" ">" ";" "=" "//" "'" "$" "%" "&" "|" "#" "/*" "*\/")。#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。$temperature=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);unset($conf["stringProcess"]["correctCharacter"]);#如果剔除C或F失敗if($temperature["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$temperature;#回傳結果return $result;}#if end#如果輸入是攝氏溫度if($spiltedStr[count($spiltedStr)-1]=="C"){#計算華氏溫度#如果不爲0度if($temperature["content"]!=0){#求算華氏溫度$F=9*$temperature["content"]/5+32;#如果有設定 $conf["points"]if(isset($conf["points"])){#設定要顯示的小數點位數$F=round($F,$conf["points"]);}#if end#如果 $conf["useF"] 有設置if(isset($conf["useF"])){#如果 $conf["useF"] 爲 "true"if($conf["useF"]=="true"){#加上F$F=$F."F";}#if end}#if end#回傳結果return $F;}#if end#如果爲0度if($temperature["content"]==0){#華氏溫度爲32$F=32;#如果有設定 $conf["points"]if(isset($conf["points"])){#設定要顯示的小數點位數$F=round($F,$conf["points"]);}#if end#如果 $conf["useF"] 有設置if(isset($conf["useF"])){#如果 $conf["useF"] 爲 "true"if($conf["useF"]=="true"){#加上F$F=$F."F";}#if end}#if end#回傳結果return $F;}#else end}#if end#如果輸入是華氏溫度if($spiltedStr[count($spiltedStr)-1]=="F"){#計算攝氏溫度$C=($temperature["content"]-32)*5/9;#如果有設定 $conf["points"]if(isset($conf["points"])){#設定要顯示的小數點位數$C=round($C,$conf["points"]);}#if end#如果 $conf["useC"] 有設置if(isset($conf["useC"])){#如果 $conf["useC"] 爲 "true"if($conf["useC"]=="true"){#加上C$C=$C."C";}#if end}#if end#設置執行成功$result["status"]="true";#設置轉換好的攝氏溫度$result["C"]=$C;;#回傳結果return $result;}#if end#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="請在結尾加上C或F來代表攝氏或華氏溫度";#回傳結果return $result;}#function transferCtoF/*#函式說明:#印出多行文字,結尾自動換行.#回傳的結果:#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#必填參數:#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.$conf["outputStringArray"]=array("");#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function echoMultiLine($conf){#初始化要回傳的內容$result=array();#取得當前函式的名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。#回傳的結果:#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#必填寫的參數:$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("outputStringArray");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");#可以省略的參數:$conf["variableCheck"]["isexistMuti"]["variableType"]=array("array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。#備註:#功能與checkExistAndType函式相同$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);unset($conf["variableCheck"]["isexistMuti"]);#如果 $checkResult["status"] 等於 "false"if($checkResult["status"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果 $checkResult["passed"] 等於 "false"if($checkResult["passed"]=="false"){#設置執行錯誤識別$result["status"]="false";#取得錯誤訊息$result["error"]=$checkResult;#回傳結果return $result;}#if end#$conf["outputStringArray"]有幾個元素就執行幾次for($i=0;$i<count($conf["outputStringArray"]);$i++){#引出該行字,並換行echo $conf["outputStringArray"][$i].PHP_EOL;}#for end#執行到這邊代表執行正常$result["status"]="true";#回傳結果return $result;}#function echoMultiLine end/*#函式說明:#用shell檢查檔案是否存在,可以指定查詢時用的身份.#回傳的結果:#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案.#必填參數:#$conf["fileName"],字串,要檢查的檔案名稱.$conf["fileName"]="";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.#$conf["username"]="";#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.#$conf["password"]="";#參考資料:#無.#備註:#僅能在命令列環境下執行.*/public static function checkFileExist(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileName","fileArgu");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password");#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null);#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查失敗if($checkResult["status"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果檢查不通過if($checkResult["passed"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#初始化儲存檢查檔案是否存在的腳本$cmd="";#設定要檢查的檔案$cmd=$cmd."target=".\escapeshellarg($conf["fileName"]).";";#判斷檔案是否存在並印出 $target found 或 $target not found#$cmd=$cmd."if [ -e \${target} ]; then echo \${target} found ; else echo \${target} not found; fi;";#執行腳本#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]=$cmd;#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("if","[","-e","\${target}","]",";","then","echo","\${target}","found",";","else","echo","\${target}","not founnd",";","fi",";");#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="false";#如果有 $conf["username"]if(isset($conf["username"])){#如果不是以運行php的使用者角色來檢查檔案是否存在if($conf["username"]!==$_SERVER["LOGNAME"]){#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["external::callShell"]["username"]=$conf["username"];}#if end}#if end#如果有 $conf["password"]if(isset($conf["password"])){#如果不是以運行php的使用者角色來檢查檔案是否存在if($conf["username"]!==$_SERVER["LOGNAME"]){#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["external::callShell"]["password"]=$conf["password"];}#if end}#if end#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.#參考資料:#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["external::callShell"]);unset($conf["external::callShell"]);#如果執行腳本失敗if($callShell["status"]=="false"){#設置錯誤識別$result["status"]="false";#設置錯誤提示$result["error"]=$callShell;#回傳結果return $result;}#if end#如果有找到檔案if($callShell["output"][0]===$conf["fileName"]." found"){#設置執行正常的識別$result["status"]="true";#設置有找到檔案$result["founded"]="true";#回傳結果return $result;}#if end#如果有找到檔案else if($callShell["output"][0]===$conf["fileName"]." not found"){#設置執行正常的識別$result["status"]="true";#設置有找到檔案$result["founded"]="false";#回傳結果return $result;}#if end#設置錯誤識別$result["status"]="false";#設置錯誤提示$result["error"]=$callShell;#回傳結果return $result;}#function checkFileExist Exist/*#函式說明:#透過lsblk指令的輸出取得已經掛載的blk.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],lsblk的輸出內容.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function lsblk(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["skipableVariableName"]=array();#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["skipableVariableType"]=array();#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["skipableVarDefaultValue"]=array("");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php#建議:#增加可省略參數全部不能為空字串或空陣列的參數功能.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#執行 lsblk 指令#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="lsblk";#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("--output","NAME,SIZE");#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.#$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/";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行 lsblk 指令失敗if($callShell["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#初始化用儲存欄位名稱的變數$colName=array();#針對每個欄位foreach($callShell["output"] as $lineNum=>$lineStr){#如果是標題列if($lineNum==0){#分割 $lineStr 以便取得欄位名稱#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$lineStr;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#針對每個欄位名稱for($i=0;$i<$spiltString["dataCounts"];$i++){#儲存每個欄位名稱$colName[]=$spiltString["dataArray"][$i];}#for end#跳過continue;}#if end#反之不是標題列else{#將開頭的 "| " 剔除#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函式名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$lineStr;#要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="│ ";#特定字串.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果處理字串失敗if($delStrBeforeKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果含有要處理的關鍵字if($delStrBeforeKeyWord["founded"]==="true"){#取得處理好的字串$lineStr=$delStrBeforeKeyWord["content"];}#if end#分割 $lineStr 以便取得欄位名稱#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$lineStr;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#針對每個欄位名稱for($i=0;$i<$spiltString["dataCounts"];$i++){#如果是NAME欄位if($colName[$i]=="NAME"){#將開頭的 "├─" 剃除#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函式名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$spiltString["dataArray"][$i];#要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="|-";#特定字串.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果移除關鍵字前面的內容失敗if($delStrBeforeKeyWord["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果有找到關鍵字if($delStrBeforeKeyWord["founded"]=="true"){#取得移除開頭關鍵字後的內容$spiltString["dataArray"][$i]=$delStrBeforeKeyWord["content"];#儲存欄位的真正內容#$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["oriStr"];#儲存欄位的真正內容$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["content"];}#if end#反之else{#將開頭的 "└─" 剃除#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函式名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$spiltString["dataArray"][$i];#要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="`-";#特定字串.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果移除關鍵字前面的內容失敗if($delStrBeforeKeyWord["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#取得移除開頭關鍵字後的內容$spiltString["dataArray"][$i]=$delStrBeforeKeyWord["content"];#儲存欄位的真正內容#$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["oriStr"];#儲存欄位的真正內容$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["content"];}#else end#將名稱當中的 "-" 置換為 "/"#函式說明:#處理字串避免網頁出錯#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式.#$result["content"],爲處理好的字串.#$result["error"],錯誤訊息陣列.#必填參數:$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][$i];#爲要處理的字串#可省略參數:$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("-");#爲被選擇要處理的字串/字元,須爲陣列值。#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔$conf["stringProcess::correctCharacter"]["changeTo"]=array("/");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);unset($conf["stringProcess::correctCharacter"]);#如果轉換NAME失敗if($correctCharacter["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$correctCharacter;#回傳結果return $result;}#if end#取得轉換好的 NAME$spiltString["dataArray"][$i]=$correctCharacter["content"];#補上 "/dev/"$spiltString["dataArray"][$i]="/dev/".$spiltString["dataArray"][$i];}#if end#儲存每個欄位名稱$result["content"][$colName[$i]][]=$spiltString["dataArray"][$i];}#for end}#else end}#foreach end#lsblk 的 PKNAME 與 MOUNTPOINT 與 vendor 與 WWN 資訊要個別取得,因為可能是空值$othersCol=array("PKNAME","MOUNTPOINT","vendor","WWN","SERIAL");#新增的欄位,可以得知blk是什麼類型$othersCol[]="TYPE";#每個要各別取得的欄位資訊內容foreach($othersCol as $colName){#執行 lsblk 指令#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="lsblk";#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("--output",$colName);#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.#$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/";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行 lsblk 指令失敗if($callShell["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#針對每列輸出foreach($callShell["output"] as $index=>$colStr){#如果索引為0if($index==0){#跳到下一次迴圈continue;}#if end#分割 $lineStr 以便取得欄位名稱#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$colStr;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="true";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#針對每個欄位名稱for($i=0;$i<$spiltString["dataCounts"];$i++){#儲存每個欄位名稱$result["content"][$colName][]=$spiltString["dataArray"][$i];}#for end}#foreach end}#foreach end#修正 NAME 欄位的名稱,如果是 TYPE 是 LVMforeach($result["content"]["TYPE"] as $key=>$type){#如果 type 是 LVMif($type==="lvm"){#暫存當前的 key$curKey=$key;#如果往前找有 TYPEwhile(isset($result["content"]["TYPE"][--$curKey])){#如果是 "part"if($result["content"]["TYPE"][$curKey]==="part"){#將名稱當中的 "/dev" 置換為 "NAME"#函式說明:#處理字串避免網頁出錯#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式.#$result["content"],爲處理好的字串.#$result["error"],錯誤訊息陣列.#必填參數:$conf["stringProcess::correctCharacter"]["stringIn"]=$result["content"]["NAME"][$key];#爲要處理的字串#可省略參數:$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("/dev");#爲被選擇要處理的字串/字元,須爲陣列值。#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔$conf["stringProcess::correctCharacter"]["changeTo"]=array($result["content"]["NAME"][$curKey]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);unset($conf["stringProcess::correctCharacter"]);#如果轉換NAME失敗if($correctCharacter["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$correctCharacter;#回傳結果return $result;}#if end#取得轉換好的 NAME$result["content"]["NAME"][$key]=$correctCharacter["content"];#結束該 NAME 的修正continue 2;}#if end}#while end#找不到歸屬的 PART#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="找不到 ".$result["content"]["MOUNTPOINT"][$key]." 歸屬的分割區名稱";#回傳結果return $result;}#if end}#foreach end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function lsblk end/*#函式說明:#嘗試掛載儲存裝置#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["warning"],警告訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],lsblk的輸出內容.#必填參數:#$conf["device"],陣列,想要掛載的裝置勢別資訊,當塞選到只剩下一個儲存裝置時,將會掛載之.$conf["device"]=array("");#$conf["partNo"],字串,分割區號碼.$conf["partNo"]="";#$conf["mountPoint"],字串,想要掛載到哪邊.$conf["mountPoint"]="";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["createMountPoint"],字串,當掛載點不存在時是否要建立其目錄與路徑,"true"代表要,"false"代表不要,預設為"false".#$conf["createMountPoint"]="";#參考資料:#無.#備註:#無.*/public static function mountDev(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()=="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("device","partNo","mountPoint","fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string","string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("createMountPoint");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("styleName","styleValue");#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["passed"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#透過lsblk指令的輸出取得已經掛載的blk.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],lsblk的輸出內容.#必填參數:#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::lsblk"]["fileArgu"]=__FILE__;#可省略參數:#無.#備註:#完整解析NAME的規則目前找不到.$lsblk=cmd::lsblk($conf["cmd::lsblk"]);unset($conf["cmd::lsblk"]);#如果取得儲存裝置列表失敗if($lsblk["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$lsblk;#回傳結果return $result;}#if end#初始化儲存符合條件的儲存裝置$targetDevice=$lsblk["content"];#初始化暫存符合條件的儲存裝置$newDevArray=array();#初始化儲存符合條件的裝置索引$devNo=array();#依據每個篩選條件foreach($conf["device"] as $fillter){#依據列表上的每個裝置屬性foreach($targetDevice as $des => $devArray){#依據列表上的每個裝置foreach($devArray as $devIndex =>$devInfo){#如果該裝置的資訊跟篩選條件一樣if($devInfo===$fillter){#取得裝置的索引$devNo[]=$devIndex;}#if end}#foreach end}#foreach end#如果存在 $devNoif(count($devNo)>0){#依據每個符合條件的no#更新target deviceforeach($devNo as $no){#依據每個屬性foreach($targetDevice as $attr=>$devArray){#依據每個裝置foreach($devArray as $devIndex=>$devInfo){#如果是符合條件的裝置if($devIndex==$no){#儲存之$newDevArray[$attr][$devIndex]=$targetDevice[$attr][$devIndex];}#if end}#foreach end}#foreach end}#foreach end#清空要保留的裝置索引$devNo=array();#如果有符合條件的裝置if(isset($newDevArray["NAME"])){#更新可能的儲存裝置列表$targetDevice=$newDevArray;}#if end}#if end}#foreach end#如果篩選完後的結果大於一個if(count($targetDevice["NAME"])>1){#代表給與的篩選條件不足無法取得切確的裝置#設置執行錯誤訊息$result["error"][]="沒有符合條件的裝置可以掛載";#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#初始化儲存裝置的分隔區名稱$diskName="";#初始化儲存裝置的掛載點$mountPoint="";#取得裝置的名稱foreach($targetDevice["NAME"] as $dn){#取得儲存裝置的分隔區名稱$diskName=$dn;}#foreach end#初始化沒有找到分割區$foundPart="false";#依據每個分割區的 NAMEforeach($lsblk["content"]["NAME"] as $devIndex=>$devInfo){#尋找有無分割區 $diskName.$conf["partNo"]if($devInfo===$diskName.$conf["partNo"]){#取得儲存裝置的NAME$diskName=$devInfo;#取得儲存裝置的掛載點$mountPoint=$lsblk["content"]["MOUNTPOINT"][$devIndex];#設置有找到分割區$foundPart="true";}#if end}#foreach end#如果沒有找到分割區if($foundPart==="false"){#設置執行錯誤訊息$result["error"][]="裝置的分割區「".$diskName."」不存在";#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#取得root密碼#函式說明:#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],設定值內容.#必填參數:#$conf["readVarName"],字串,要從設定檔取得的變數名稱.$conf["cmd::getFromConf"]["readVarName"]="root-passwds";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.#$conf["forceRewrite"]="";$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);unset($conf["cmd::getFromConf"]);#如果取得 root 密碼失敗if($getFromConf["status"]=="false"){#設置執行錯誤訊息$result["error"]=$getFromConf;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#驗證密碼是否正確#函式說明:#驗證Linux使用者的密碼是否正確.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["warninig"],警告訊息陣列.#$result["valid"],是否為存在的使用者且密碼正確.#必填參數:#$conf["username"],字串,要驗證的使用者名稱.$conf["authenticate::validUser"]["username"]="root";#$conf["password"],字串,用於驗證使用者的密碼.$conf["authenticate::validUser"]["password"]=$getFromConf["content"];#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];#備註:#僅能在命令列環境下運行.$validUser=authenticate::validUser($conf["authenticate::validUser"]);unset($conf["authenticate::validUser"]);#如果驗證使用者失敗if($validUser["status"]=="false"){#設置執行錯誤訊息$result["error"]=$validUser;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#如果root密碼不正確while($validUser["valid"]==="false"){#取得root密碼#函式說明:#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],設定值內容.#必填參數:#$conf["readVarName"],字串,要從設定檔取得的變數名稱.$conf["cmd::getFromConf"]["readVarName"]="root-passwds";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.$conf["cmd::getFromConf"]["forceRewrite"]="true";$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);unset($conf["cmd::getFromConf"]);#如果取得 root 密碼失敗if($getFromConf["status"]=="false"){#設置執行錯誤訊息$result["error"]=$getFromConf;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#驗證密碼是否正確#函式說明:#驗證Linux使用者的密碼是否正確.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["warninig"],警告訊息陣列.#$result["valid"],是否為存在的使用者且密碼正確.#必填參數:#$conf["username"],字串,要驗證的使用者名稱.$conf["authenticate::validUser"]["username"]="root";#$conf["password"],字串,用於驗證使用者的密碼.$conf["authenticate::validUser"]["password"]=$getFromConf["content"];#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];#備註:#僅能在命令列環境下運行.$validUser=authenticate::validUser($conf["authenticate::validUser"]);unset($conf["authenticate::validUser"]);#如果驗證使用者失敗if($validUser["status"]=="false"){#設置執行錯誤訊息$result["error"]=$validUser;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end}#if end#取得root密碼$rootPasswd=$getFromConf["content"];#取得 $conf["mountPoint"] 的絕對位置#函式說明:#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函式名稱.#$result["content"],網址,若是在命令列執行,則為"null".#$result["webPathFromRoot"],相對於網頁根目錄的路徑.#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.#必填參數:#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.$conf["fileAccess::getInternetAddress"]["address"]=$conf["mountPoint"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".#$conf["fileAccess::getInternetAddress"]["userDir"]="true";#備註:#在命令列執行,所得的路徑是錯誤的。$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);unset($conf["fileAccess::getInternetAddress"]);#如果取得路徑資訊失敗if($getInternetAddress["status"]=="false"){#設置執行錯誤訊息$result["error"]=$getInternetAddress;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#取得掛載點的絕對路徑$conf["mountPoint"]=$getInternetAddress["fileSystemAbsoulutePosition"];#檢查掛載點是否存在#函式說明:檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的函式名稱.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["mountPoint"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];#可省略參數#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".#$conf["userDir"]="true";#參考資料來源:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函式file_exists檢查的路徑為檔案系統的路徑$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果檢查掛載點失敗if($checkMultiFileExist["status"]=="false"){#設置執行錯誤訊息$result["error"]=$checkMultiFileExist;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#如果掛載點不存在if($checkMultiFileExist["allExist"]=="false"){#如果有設定建立不存在的掛載點if($conf["createMountPoint"]=="true"){#函式說明:#確保路徑存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的函式名稱.#$result["path"],建立好的路徑字串.#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.#必填參數:#$conf["path"],要檢查的路徑$conf["fileAccess::validatePath"]["path"]=$conf["mountPoint"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".#$conf["haveFileName"]="false";#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.#$conf["dirPermission"]="";$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);unset($conf["fileAccess::validatePath"]);#如果確保路徑失敗if($validatePath["status"]=="false"){#設置執行錯誤訊息$result["error"]=$validatePath;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#設置已經建立不存在的掛點點$result["warning"][]="已經建立不存在的掛載點「".$conf["mountPoint"]."」";}#if end#反之else{#設置執行錯誤訊息$result["error"]=$checkMultiFileExist;#設置掛載點不存在的錯誤訊息$result["error"][]="掛載點「".$conf["mountPoint"]."」不存在";#設置執行失敗$result["status"]="false";#回傳結果return $result;}#else end}#if end#如果儲存裝置已經掛載在其他地方了if($mountPoint!="" && $mountPoint!=$conf["mountPoint"]){#卸載儲存裝置#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="umount";#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($diskName);#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.$conf["external::callShell"]["username"]="root";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.$conf["external::callShell"]["password"]=$rootPasswd;#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果卸載儲存裝置失敗if($callShell["status"]=="false"){#設置執行錯誤訊息$result["error"]=$callShell;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end}#if#反之已經掛載在正確的地方了else if($mountPoint==$conf["mountPoint"]){#設置執行警告訊息$result["warning"][]="裝置「".$diskName."」已經掛載在「".$conf["mountPoint"]."」了";#設置執行正常$result["status"]="true";#回傳結果return $result;}#if end#掛載儲存裝置#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="mount";#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($diskName,$conf["mountPoint"]);#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.$conf["external::callShell"]["username"]="root";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.$conf["external::callShell"]["password"]=$rootPasswd;#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果掛載行動硬碟失敗if($callShell["status"]=="false"){#設置執行錯誤訊息$result["error"]=$callShell;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function mountDev end/*#函式說明:#卸載儲存裝置#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["warning"],警告訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],lsblk的輸出內容.#必填參數:#$conf["device"],陣列,想要卸載的裝置勢別資訊,當塞選到只剩下一個儲存裝置時,將會掛載之.$conf["device"]=array("");#$conf["partNo"],字串,分割區號碼.$conf["partNo"]="";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["fileArgu"]=__FILE__;#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function umountDev(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()=="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("device","partNo","fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array();#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__);#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("styleName","styleValue");#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["passed"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#透過lsblk指令的輸出取得已經掛載的blk.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],lsblk的輸出內容.#必填參數:#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::lsblk"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#無.$lsblk=cmd::lsblk($conf["cmd::lsblk"]);unset($conf["cmd::lsblk"]);#如果取得儲存裝置列表失敗if($lsblk["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$lsblk;#回傳結果return $result;}#if end#初始化儲存符合條件的儲存裝置$targetDevice=$lsblk["content"];#初始化暫存符合條件的儲存裝置$newDevArray=array();#初始化儲存符合條件的裝置索引$devNo=array();#依據每個篩選條件foreach($conf["device"] as $fillter){#依據列表上的每個裝置屬性foreach($targetDevice as $des => $devArray){#依據列表上的每個裝置foreach($devArray as $devIndex =>$devInfo){#如果該裝置的資訊跟篩選條件一樣if($devInfo===$fillter){#取得裝置的索引$devNo[]=$devIndex;}#if end}#foreach end}#foreach end#如果存在 $devNoif(count($devNo)>0){#依據每個符合條件的no#更新target deviceforeach($devNo as $no){#依據每個屬性foreach($targetDevice as $attr=>$devArray){#依據每個裝置foreach($devArray as $devIndex=>$devInfo){#如果是符合條件的裝置if($devIndex==$no){#儲存之$newDevArray[$attr][$devIndex]=$targetDevice[$attr][$devIndex];}#if end}#foreach end}#foreach end}#foreach end#清空要保留的裝置索引$devNo=array();#如果有符合條件的裝置if(isset($newDevArray["NAME"])){#更新可能的儲存裝置列表$targetDevice=$newDevArray;}#if end}#if end}#foreach end#如果篩選完後的結果大於一個if(count($targetDevice["NAME"])>1){#代表給與的篩選條件不足無法取得切確的裝置#設置執行錯誤訊息$result["error"][]="沒有符合條件的裝置可以卸載";#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#初始化儲存裝置的分隔區名稱$diskName="";#初始化儲存裝置的掛載點$mountPoint="";#取得裝置的名稱foreach($targetDevice["NAME"] as $dn){#取得儲存裝置的分隔區名稱$diskName=$dn;}#foreach end#初始化沒有找到分割區$foundPart="false";#依據每個分割區的 NAMEforeach($lsblk["content"]["NAME"] as $devIndex=>$devInfo){#尋找有無分割區 $diskName.$conf["partNo"]if($devInfo===$diskName.$conf["partNo"]){#取得儲存裝置的NAME$diskName=$devInfo;#取得儲存裝置的掛載點$mountPoint=$lsblk["content"]["MOUNTPOINT"][$devIndex];#設置有找到分割區$foundPart="true";}#if end}#foreach end#如果沒有找到分割區if($foundPart==="false"){#設置執行錯誤訊息$result["error"][]="裝置的分割區「".$diskName."」不存在";#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#如果要被卸載的分割區沒有被掛載if($mountPoint==""){#設置執行錯誤訊息$result["error"][]="裝置的分割區「".$diskName."」並未被掛載";#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#取得root密碼#函式說明:#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],設定值內容.#必填參數:#$conf["readVarName"],字串,要從設定檔取得的變數名稱.$conf["cmd::getFromConf"]["readVarName"]="root-passwds";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.#$conf["forceRewrite"]="";$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);unset($conf["cmd::getFromConf"]);#如果取得 root 密碼失敗if($getFromConf["status"]=="false"){#設置執行錯誤訊息$result["error"]=$getFromConf;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#驗證密碼是否正確#函式說明:#驗證Linux使用者的密碼是否正確.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["warninig"],警告訊息陣列.#$result["valid"],是否為存在的使用者且密碼正確.#必填參數:#$conf["username"],字串,要驗證的使用者名稱.$conf["authenticate::validUser"]["username"]="root";#$conf["password"],字串,用於驗證使用者的密碼.$conf["authenticate::validUser"]["password"]=$getFromConf["content"];#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];#備註:#僅能在命令列環境下運行.$validUser=authenticate::validUser($conf["authenticate::validUser"]);unset($conf["authenticate::validUser"]);#如果驗證使用者失敗if($validUser["status"]=="false"){#設置執行錯誤訊息$result["error"]=$validUser;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#如果root密碼不正確while($validUser["valid"]=="false"){#取得root密碼#函式說明:#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],設定值內容.#必填參數:#$conf["readVarName"],字串,要從設定檔取得的變數名稱.$conf["cmd::getFromConf"]["readVarName"]="root-passwds";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.$conf["cmd::getFromConf"]["forceRewrite"]="true";$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);unset($conf["cmd::getFromConf"]);#如果取得 root 密碼失敗if($getFromConf["status"]=="false"){#設置執行錯誤訊息$result["error"]=$getFromConf;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#驗證密碼是否正確#函式說明:#驗證Linux使用者的密碼是否正確.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["warninig"],警告訊息陣列.#$result["valid"],是否為存在的使用者且密碼正確.#必填參數:#$conf["username"],字串,要驗證的使用者名稱.$conf["authenticate::validUser"]["username"]="root";#$conf["password"],字串,用於驗證使用者的密碼.$conf["authenticate::validUser"]["password"]=$getFromConf["content"];#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];#備註:#僅能在命令列環境下運行.$validUser=authenticate::validUser($conf["authenticate::validUser"]);unset($conf["authenticate::validUser"]);#如果驗證使用者失敗if($validUser["status"]=="false"){#設置執行錯誤訊息$result["error"]=$validUser;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end}#if end#取得root密碼$rootPasswd=$getFromConf["content"];#卸載儲存裝置#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="umount";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($diskName);#$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"],字串,要用什麼使用者來執行,預設為執行apache的使用者.$conf["external::callShell"]["username"]="root";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.$conf["external::callShell"]["password"]=$rootPasswd;#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果卸載儲存裝置失敗if($callShell["status"]=="false"){#設置執行錯誤訊息$result["error"]=$callShell;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function umountDev end/*#函式說明:#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["content"],帳戶密碼.#必填參數:#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".#$conf["password"]="";#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.#$conf["username"]="";#參考資料:#無.#備註:#無.*/public static function validRootPasswd(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("password");#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列$conf["variableCheck::checkArguments"]["canBeEmpty"]=array("password");#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("password","username");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("rootPasswd","root");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]=="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["passed"]=="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#驗證root帳號的密碼#函式說明:#驗證Linux使用者的密碼是否正確.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["warninig"],警告訊息陣列.#$result["valid"],是否為存在的使用者且密碼正確.#必填參數:#$conf["username"],字串,要驗證的使用者名稱.$conf["authenticate::validUser"]["username"]=$conf["username"];#$conf["password"],字串,用於驗證使用者的密碼.$conf["authenticate::validUser"]["password"]=$conf["password"];#$conf["fileArgu"],字串,__FILE__的內容.$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];#備註:#僅能在命令列環境下運行.$validUser=authenticate::validUser($conf["authenticate::validUser"]);unset($conf["authenticate::validUser"]);#如果認證root密碼失敗if($validUser["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$validUser;#回傳結果return $result;}#if end#如果驗證使用者不通過if($validUser["valid"]==="false"){#請使用者輸入帳戶的密碼#函式說明:#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],設定值內容.#必填參數:#$conf["readVarName"],字串,要從設定檔取得的變數名稱.$conf["cmd::getFromConf"]["readVarName"]="cmd::valid".$conf["username"]."Passwd";#可省略參數:#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.#$conf["fileArgu"]=__FILE__;#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入".$conf["username"]."帳戶的密碼:");#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.$conf["cmd::getFromConf"]["forceRewrite"]="true";$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);unset($conf["cmd::getFromConf"]);#如果輸入root密碼失敗if($getFromConf["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getFromConf;#回傳結果return $result;}#if end#驗證帳號的密碼#函式說明:#驗證Linux使用者的密碼是否正確.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["warninig"],警告訊息陣列.#$result["valid"],是否為存在的使用者且密碼正確.#必填參數:#$conf["username"],字串,要驗證的使用者名稱.$conf["authenticate::validUser"]["username"]=$conf["username"];#$conf["password"],字串,用於驗證使用者的密碼.$conf["authenticate::validUser"]["password"]=$getFromConf["content"];#$conf["fileArgu"],字串,__FILE__的內容.$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];#備註:#僅能在命令列環境下運行.$validUser=authenticate::validUser($conf["authenticate::validUser"]);unset($conf["authenticate::validUser"]);#如果認證root密碼失敗if($validUser["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$validUser;#回傳結果return $result;}#if end#如果認證密碼不正確while($validUser["valid"]==="false"){#請使用者輸入root帳戶的密碼#函式說明:#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],設定值內容.#必填參數:#$conf["readVarName"],字串,要從設定檔取得的變數名稱.$conf["cmd::getFromConf"]["readVarName"]="cmd::valid".$conf["username"]."Passwd";#可省略參數:#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.#$conf["fileArgu"]=__FILE__;#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入".$conf["username"]."帳戶的密碼:");#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.$conf["cmd::getFromConf"]["forceRewrite"]="true";$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);unset($conf["cmd::getFromConf"]);#如果輸入root密碼失敗if($getFromConf["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getFromConf;#回傳結果return $result;}#if end#驗證密碼是否正確#函式說明:#驗證Linux使用者的密碼是否正確.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["warninig"],警告訊息陣列.#$result["valid"],是否為存在的使用者且密碼正確.#必填參數:#$conf["username"],字串,要驗證的使用者名稱.$conf["authenticate::validUser"]["username"]=$conf["username"];#$conf["password"],字串,用於驗證使用者的密碼.$conf["authenticate::validUser"]["password"]=$getFromConf["content"];#$conf["fileArgu"],字串,__FILE__的內容.$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];#備註:#僅能在命令列環境下運行.$validUser=authenticate::validUser($conf["authenticate::validUser"]);unset($conf["authenticate::validUser"]);#如果認證帳戶失敗if($validUser["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$validUser;#回傳結果return $result;}#if end#如果帳戶認證的密碼正確if($validUser["valid"]==="true"){#更新認證用的密碼$conf["password"]=$getFromConf["content"];#跳出whilebreak;}#if end}#while end}#if end#如果沒有從設定檔取得的密碼if(!isset($getFromConf["content"])){#代表一開始設定的密碼就是正確的$result["content"]=$conf["password"];}#if end#反之設定檔中的密碼才是正確的else{#取得正確的密碼$result["content"]=$getFromConf["content"];}#else end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function validRootPasswd end/*#函式說明:#取得檔案的內容並以列為單位搜尋多個關鍵字.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],取得讀取到的檔案內容.#$result["founded"],每個關鍵字串尋找的結果,"true"代表有找到,"false"代表沒有找到.#$result["foundedLine"],每個找到的關鍵字是在第幾列找到的,key值與$result["founded"]的key值一樣.#$result["foundedAll"],是否每個關鍵字串都有找到,"true"代表有,"false"代表沒有.#必填參數:#$conf["file"],字串,檔案的位置與名稱.$conf["file"]="";#$conf["keyStr"],陣列字串,要搜尋每列有哪些關鍵字串.$conf["keyStr"]=array();#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.#$conf["username"]="";#$conf["password"],字串,使用者對應的密碼,預設不使用.#$conf["password"]="";#$conf["tempDir"],字串,暫存資料的目錄位置,預設為".cmd/checkFileKeyStrLBL".#$conf["tempDir"]="";#參考資料:#無.#備註:#僅能在命令列環境下運行*/public static function checkFileKeyStrLBL(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","keyStr","fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","tempDir");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,".cmd/checkFileKeyStrLBL");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果參數檢查失敗if($checkArguments["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果參數檢查不通過if($checkArguments["passed"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#將多個路徑字串變成相對於當前路徑的相對路徑字串#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函式名稱.#$result["content"],字串陣列,多個轉換好的相對路徑字串.#必填參數:#$conf["path"],陣列字串,要轉換成相對路徑的字串.;$conf["fileAccess::getRelativePath"]["path"]=array($conf["tempDir"]);#$conf["fileArgu"],字串,當前路徑.$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);unset($conf["fileAccess::getRelativePath"]);#如果轉換路徑失敗if($getRelativePath["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getRelativePath;#回傳結果return $result;}#if end#取得暫存目錄的相對路徑$conf["tempDir"]=$getRelativePath["content"][0];#如果有設置密碼且使用者不為 $_SERVER["LOGNAME"]if(isset($conf["password"]) && $conf["username"]!==$_SERVER["LOGNAME"]){#驗證使用者與密碼#函式說明:#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["content"],帳戶密碼.#必填參數:#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".$conf["cmd::validRootPasswd"]["password"]=$conf["password"];#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.$conf["cmd::validRootPasswd"]["username"]=$conf["username"];$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);unset($conf["cmd::validRootPasswd"]);#如果認證失敗if($validRootPasswd["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$validRootPasswd;#回傳結果return $result;}#if end}#if end#確認檔案是否存在#函式說明:#用shell檢查檔案是否存在,可以指定查詢時用的身份.#回傳的結果:#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案.#必填參數:#$conf["fileName"],字串,要檢查的檔案名稱.$conf["cmd::checkFileExist"]["fileName"]=$conf["file"];#可省略參數:#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.$conf["cmd::checkFileExist"]["username"]=$conf["username"];#如果有設置 $conf["password"]if(isset($conf["password"])){#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.$conf["cmd::checkFileExist"]["password"]=$conf["password"];}#if end#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::checkFileExist"]["fileArgu"]=$conf["fileArgu"];#備註:#該函式若使用可省略參數,則無法在web環境下運行$checkFileExist=cmd::checkFileExist($conf["cmd::checkFileExist"]);unset($conf["cmd::checkFileExist"]);#如果檢查檔案是否存在失敗if($checkFileExist["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkFileExist;#回傳結果return $result;}#if end#如果檔案不存在if($checkFileExist["founded"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkFileExist;#回傳結果return $result;}#if end#建立暫存目錄#函式說明:#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.#回傳的結果:#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],建立的目錄路徑.#必填參數:#$conf["dirPositionAndName"]="";#新建的位置與名稱$conf["fileAccess::createNewFolder"]["dirPositionAndName"]=$conf["tempDir"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::createNewFolder"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.#$conf["dirPermission"]="";#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,預設為"false"不取消,若要取消該功能請設為"true".#$conf["disableWebSearch"]="false";#備註:#同 function createFolderAfterCheck.$createNewFolder=fileAccess::createNewFolder($conf["fileAccess::createNewFolder"]);unset($conf["fileAccess::createNewFolder"]);#如果建立暫存資料夾失敗if($createNewFolder["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$createNewFolder;#回傳結果return $result;}#if end#取得轉換好的暫存目錄$conf["tempDir"]=$createNewFolder["content"];#建立暫存檔案的名稱#函式說明:#建立以圖片(PNG格式)呈現的驗證碼.#回傳的解果:#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.#$result["error"],錯誤訊息.#$result["function"],檔前執行的函式名稱.#$result["randNumberWord"],傳驗證碼的內容.#$result["imgAddress"],圖片的位置與名稱.#必填參數:#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生$conf["authenticate::validationCode"]["imgAddressAndName"]="no used!";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["authenticate::validationCode"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.#$conf["num"]="8";#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消$conf["authenticate::validationCode"]["disableImg"]="true";#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"#$conf["imgToData"]="true";$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);unset($conf["authenticate::validationCode"]);#如果產生亂數名稱失敗if($validationCode["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$validationCode;#回傳結果return $result;}#if end#取得暫存檔案名稱$tempFname=$validationCode["randNumberWord"];#取得暫存檔案的路徑於名稱$tempFileFullPath=$conf["tempDir"]."/".$tempFname;#複製檔案到暫存區塊,並設定權限為當前使用者可以讀取.#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="cp";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($conf["file"],$tempFileFullPath,";","chown",$conf["username"].":".$conf["username"],";","chmod","777",$tempFileFullPath);#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$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["external::callShell"]);unset($conf["external::callShell"]);#如果複製httpd設定檔失敗if($callShell["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#讀取httpd設定檔內容#函式說明:#依據行號分隔抓取檔案的內容,結果會回傳一個陣列#回傳的變數說明:#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.#$result["error"],錯誤訊息提示.#$result["warning"],警告訊息.#$result["function"],當前執行的函式名稱.#$result["fileContent"],爲檔案的內容陣列.#$result["lineCount"],爲檔案內容總共的行數.#$result["fullContent"],為檔案的完整內容.#必填參數:#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.$conf["fileAccess::getFileContent"]["filePositionAndName"]=$tempFileFullPath;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];#參考資料:#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["fileAccess::getFileContent"]);unset($conf["fileAccess::getFileContent"]);#如果取得檔案內容失敗if($getFileContent["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getFileContent;#回傳結果return $result;}#if end#移除暫存檔案#函式說明:#移除檔案#回傳的結果:#$result["status"],"true"代表移除成功,"false"代表移除失敗.#$result["error"],錯誤訊息陣列#$result["warning"],警告訊息陣列#$result["function"],當前執行的函式名稱#必填參數:#$conf["fileAddress"],字串,要移除檔案的位置.$conf["fileAccess::delFile"]["fileAddress"]=$tempFileFullPath;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.#$conf["commentsArray"]=array("");$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);unset($conf["fileAccess::delFile"]);#如果移除暫存檔案失敗if($delFile["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$delFile;#回傳結果return $result;}#if end#有幾個關鍵字串列就執行幾次foreach($conf["keyStr"] as $index => $keyWordStr){#判斷有無關鍵字存在#函式說明:#檢查多個字串中的每個字串是否有多個關鍵字#回傳的結果:#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息.#$result["foundedTrueKey"],結果為"true"的元素key陣列。#$result["foundedFalseKey"],結果為"false"的元素key陣列。#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.#必填參數:$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array($keyWordStr);#想要搜尋的關鍵字$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$getFileContent["fileContent"];#要被搜尋的字串內容陣列#可省略參數:$conf["search::findManyKeyWordsFromManyString"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);unset($conf["search::findManyKeyWordsFromManyString"]);#如果尋找關鍵字失敗if($findManyKeyWordsFromManyString["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$findManyKeyWordsFromManyString;#回傳結果return $result;}#if end#如果尋找到關鍵字串if(isset($findManyKeyWordsFromManyString["foundedTrueKey"])){#設置有找到關鍵字串$result["founded"][$index]="true";#用 foreach 取得無法得知的 keyforeach($findManyKeyWordsFromManyString["foundedTrueKey"] as $foundedLine=>$value){#設置找到的關鍵字串所在列數$result["foundedLine"][$index]=$foundedLine;}#foreach end}#if end#反之沒有找到關鍵字串else{#設置有找到關鍵字串$result["founded"][$index]="false";#設置沒有找到每各關鍵字串$result["foundedAll"]="false";}#else end}#foreach end#如果不存在 $result["foundedAll"]if(!isset($result["foundedAll"])){#代表所有關鍵字串都有找到$result["foundedAll"]="true";}#if end#取得讀取到的檔案內容$result["content"]=$getFileContent["fileContent"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function checkFileKeyStrLBL end/*#函式說明:#複製檔案、資料夾.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],複製好的檔案路徑與名稱.#必填參數:#$conf["file"],字串,檔案的位置與名稱.$conf["file"]="";#$conf["to"],字串,檔案要複製到哪裡.$conf["to"]="";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.#$conf["username"]="";#$conf["password"],字串,使用者對應的密碼,預設不使用.#$conf["password"]="";#參考資料:#無.#備註:#僅能在命令列環境下運行*/public static function cp(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","to","fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null);#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果參數檢查失敗if($checkArguments["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果參數檢查不通過if($checkArguments["passed"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#初始化驗證過的使用者密碼$validPasswd="";#如果不是以運行php的使用者角色來複製檔案if($conf["username"]!==$_SERVER["LOGNAME"]){#驗證帳戶與密碼是否正確#函式說明:#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["content"],帳戶密碼.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#如果有設置密碼if(isset($conf["password"])){#設定驗證用的密碼#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".$conf["cmd::validRootPasswd"]["password"]=$conf["password"];}#if end#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.$conf["cmd::validRootPasswd"]["username"]=$conf["username"];$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);unset($conf["cmd::validRootPasswd"]);#如果驗證帳號密碼失敗if($validRootPasswd["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$validRootPasswd;#回傳結果return $result;}#if end#取得驗證過的使用者密碼$validPasswd=$validRootPasswd["content"];}#if end#檢查要複製的檔案是否存在#函式說明:#用shell檢查檔案是否存在,可以指定查詢時用的身份.#回傳的結果:#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案.#必填參數:#$conf["fileName"],字串,要檢查的檔案名稱.$conf["cmd::checkFileExist"]["fileName"]=$conf["file"];#可省略參數:#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.$conf["cmd::checkFileExist"]["username"]=$conf["username"];#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.$conf["cmd::checkFileExist"]["password"]=$validPasswd;#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::checkFileExist"]["fileArgu"]=$conf["fileArgu"];#備註:#該函式若使用可省略參數,則無法在web環境下運行$checkFileExist=cmd::checkFileExist($conf["cmd::checkFileExist"]);unset($conf["cmd::checkFileExist"]);#如果檢查檔案是否存在失敗if($checkFileExist["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkFileExist;#回傳結果return $result;}#if end#如果要複製的檔案不存在if($checkFileExist["founded"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkFileExist;#設置要複製的檔案不存在$result["error"][]="檔案「".$conf["file"]."」不存在,或沒有權限接觸.";#回傳結果return $result;}#if end#函式說明:#呼叫shell依序執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["content"],爲執行完每個指令後的回傳結果.#$result["cmd"],執行的指令內容,若"sameShell"參數為"true",則會有該數值.#$result["output"],執行後得到的輸出,若"sameShell"參數為"true",則會有該數值.#必填參數:#$conf["command"],字串陣列,要執行的指令.$conf["external::callShellMulti"]["command"]=array("/bin/cp","chown","chmod");#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.$conf["external::callShellMulti"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.$conf["external::callShellMulti"]["argu"]=array(array("-rvf",$conf["file"],$conf["to"]),array($conf["username"].":".$conf["username"],$conf["to"]),array("770",$conf["to"]));#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.#$conf["enablePrintDescription"]=array("false");#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.#$conf["printDescription"]=array("");#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.$conf["external::callShell"]["escapeshellarg"]=array("true");#$conf["username"],陣列字串,每個指令要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["external::callShell"]["username"]=$conf["username"];#$conf["password"],陣列字串,每個指令與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["external::callShell"]["password"]=$validPasswd;#$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"]="";#$conf["sameShell"],字串,"true"代表每個指令都在同空shell環境下執行,亦即會繼承變數、位置等資訊;預設為"false"代表要在個別獨立的shell環境下執行.$conf["external::callShellMulti"]["sameShell"]="true";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);unset($conf["external::callShellMulti"]);#如果複製檔案失敗if($callShellMulti["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$callShellMulti;#回傳結果return $result;}#if end#設置複製好的檔案位置與名稱$result["content"]=$conf["to"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function cp end/*#函式說明:#取得檔案內容#回傳內容#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],檔案的內容.#必填參數:#$conf["file"],字串,想要取得內容的檔案位置.$conf["file"]="";#$conf["fileArgu"],字串,當前檔案的位置,亦即__FILE__.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.#$conf["username"]="";#$conf["password"],字串,使用者對應的密碼,預設不使用.#$conf["password"]="";#參考資料:#無.#備註:#僅能在命令列環境下運行*/public static function getFileContent(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("username","password");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null);#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果參數檢查不通過if($checkArguments["passed"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#初始化認證後的密碼$password="";#如果不是用執行php的使用者來執行if($conf["username"]!==$_SERVER["LOGNAME"]){#驗證帳號密碼#函式說明:#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["content"],帳戶密碼.#必填參數:$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#如果有設定 $conf["password"]if(isset($conf["password"])){#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".$conf["cmd::validRootPasswd"]["password"]=$conf["password"];}#if end#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.$conf["cmd::validRootPasswd"]["username"]=$conf["username"];$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);unset($conf["cmd::validRootPasswd"]);#如果檢查帳戶失敗if($validRootPasswd["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$validRootPasswd;#回傳結果return $result;}#if end#取得認證使用者後的密碼$password=$validRootPasswd["content"];}#if end#反之else{#密碼設為空字串$password="";}#else end#建立暫存的目錄與命名暫存檔案名稱#函式說明:#建立暫存目錄與回傳暫存檔案名稱路徑#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],暫存檔案的路徑與名稱.#必填參數:#無#可省略參數:#$conf["tempDir"],字串,暫存目錄的名稱,預設為.fileAccess/createTempFile#$conf["tempDIr"]="";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["fileAccess::createTempFile"]["fileArgu"]=$conf["fileArgu"];#$conf["createPath"],字串,是否僅要建立目錄,"true"代表要,"false"代表不要,預設為"true".#$conf["createPath"]="";#$conf["createFile"],字串,是否要在暫存路徑建立好後建立暫存檔案,"true"代表要,"false"代表不用,預設為"true".$conf["fileAccess::createTempFile"]["createFile"]="false";$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);unset($conf["fileAccess::createTempFile"]);#若建立暫存目錄取得暫存檔案名稱失敗if($createTempFile["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$createTempFile;#回傳結果return $result;}#if end#複製檔案到目的地#函式說明:#複製檔案#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],複製好的檔案路徑與名稱.#必填參數:#$conf["file"],字串,檔案的位置與名稱.$conf["cmd::cp"]["file"]=$conf["file"];#$conf["to"],字串,檔案要複製到哪裡.$conf["cmd::cp"]["to"]=$createTempFile["content"];#可省略參數:#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.$conf["cmd::cp"]["username"]=$conf["username"];#$conf["password"],字串,使用者對應的密碼,預設不使用.$conf["cmd::cp"]["password"]=$password;#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::cp"]["fileArgu"]=$conf["fileArgu"];$cp=cmd::cp($conf["cmd::cp"]);unset($conf["cmd::cp"]);#如果複製檔案失敗if($cp["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$createTempFile;#回傳結果return $result;}#if end#讀取檔案的內容#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="cat";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($cp["content"]);#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["external::callShell"]["username"]=$conf["username"];#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["external::callShell"]["password"]=$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["external::callShell"]);unset($conf["external::callShell"]);#如果取得檔案內容失敗if($callShell["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#移除暫存檔案#函式說明:#移除檔案#回傳的結果:#$result["status"],"true"代表移除成功,"false"代表移除失敗.#$result["error"],錯誤訊息陣列#$result["warning"],警告訊息陣列#$result["function"],當前執行的函式名稱#必填參數:#$conf["fileAddress"],字串,要移除檔案的位置.$conf["fileAccess::delFile"]["fileAddress"]=$cp["content"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.#$conf["commentsArray"]=array("");$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);unset($conf["fileAccess::delFile"]);#如果移除暫存檔案失敗if($delFile["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$delFile;#回傳結果return $result;}#if end#取得檔案內容$result["content"]=$callShell["output"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function getFileContent end/*#函式說明:#新增文字內容到檔案裡面#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],新增好後的檔案內容.#必填參數:#$conf["file"],字串,檔案的位置與名稱.$conf["file"]="";#$conf["addStr"],陣列字串,要新增的字串內容.$conf["addStr"]=array();#可省略參數:#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.#$conf["username"]="";#$conf["password"],字串,使用者對應的密碼,預設為"password".#$conf["password"]="";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.#$conf["fileArgu"]=__FILE__;#參考資料:#無.#備註:#無.*/public static function addTextToFile(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","addStr");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","fileArgu");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],"password",__FILE__);#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果參數檢查失敗if($checkArguments["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果參數檢查不通過if($checkArguments["passed"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#驗證使用者與密碼#函式說明:#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["content"],帳戶密碼.#必填參數:$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".$conf["cmd::validRootPasswd"]["password"]=$conf["password"];#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.$conf["cmd::validRootPasswd"]["username"]=$conf["username"];$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);unset($conf["cmd::validRootPasswd"]);#如果認證失敗if($validRootPasswd["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$validRootPasswd;#回傳結果return $result;}#if end#取得正確的密碼$conf["password"]=$validRootPasswd["content"];#確認檔案是否存在#函式說明:#用shell檢查檔案是否存在,可以指定查詢時用的身份.#回傳的結果:#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案.#必填參數:#$conf["fileName"],字串,要檢查的檔案名稱.$conf["cmd::checkFileExist"]["fileName"]=$conf["file"];#可省略參數:#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.$conf["cmd::checkFileExist"]["username"]=$conf["username"];#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.$conf["cmd::checkFileExist"]["password"]=$conf["password"];#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["cmd::checkFileExist"]["fileArgu"]=$conf["fileArgu"];#備註:#該函式若使用可省略參數,則無法在web環境下運行$checkFileExist=cmd::checkFileExist($conf["cmd::checkFileExist"]);unset($conf["cmd::checkFileExist"]);#如果檢查檔案是否存在失敗if($checkFileExist["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkFileExist;#回傳結果return $result;}#if end#如果檔案不存在if($checkFileExist["founded"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkFileExist;#回傳結果return $result;}#if end#有幾列內容就執行幾次foreach($conf["addStr"] as $inputText){#組合增加檔案內容的語法#複製檔案到暫存區塊,並設定權限為當前使用者可以讀取.#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="echo";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($inputText,">>",$conf["file"]);#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["external::callShell"]["username"]=$conf["username"];#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["external::callShell"]["password"]=$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["external::callShell"]);unset($conf["external::callShell"]);#如果執行增加檔案內容的語法失敗if($callShell["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end}#foreach end#取得新增內容後的檔案內容#函式說明:#取得檔案內容#回傳內容#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],檔案的內容.#必填參數:#$conf["file"],字串,想要取得內容的檔案位置.$conf["cmd::getFileContent"]["file"]=$conf["file"];#$conf["fileArgu"],字串,當前檔案的位置,亦即__FILE__.$conf["cmd::getFileContent"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.$conf["cmd::getFileContent"]["username"]=$conf["username"];#$conf["password"],字串,使用者對應的密碼,預設不使用.$conf["cmd::getFileContent"]["password"]=$conf["password"];$getFileContent=cmd::getFileContent($conf["cmd::getFileContent"]);unset($conf["cmd::getFileContent"]);#如果取得設定檔內容失敗if($getFileContent["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$getFileContent;#回傳結果return $result;}#if end#新增完資料後的檔案內容$result["content"]=$getFileContent["content"];#設置執行正常$result["status"]="true";#回傳內容return $result;}#function addContentToFile/*#函式說明:#檢查指令的輸出是否含有關鍵字#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["grepCmd"],截取關鍵字的指令.#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.#$result["content"],關鍵字所在列的輸出.#$result["count"],輸出的列數.#必填參數:#$conf["cmd"],字串,要執行的指令.$conf["cmd"]="";#$conf["keyWord"],字串,要檢查是否有關鍵字.$conf["keyWord"]="";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".#$conf["binPath"]="";#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.#$conf["argu"]=array("");#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.#$conf["excludeGrep"]="false";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#參考資料:#無.#備註:#無.*/public static function searchOutPut(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmd","keyWord","fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("binPath","argu","excludeGrep","username","password");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false","root",null);#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("netType","netCard");#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果參數檢查失敗if($checkArguments["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果參數檢查不通過if($checkArguments["passed"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#檢查指令 $conf["cmd"] 是否存在#函式說明:#檢查指令是否存在#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["content"],新增好後的檔案內容.#必填參數:#$conf["cmd"],"字串",要查詢的指令.$conf["self::checkCmdExist"]["cmd"]=$conf["cmd"];#可省略參數:#如果有設置 $conf["binPath"]if(isset($conf["binPath"])){#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".$conf["self::checkCmdExist"]["binPath"]=$conf["binPath"];}#if end$checkCmdExist=self::checkCmdExist($conf["self::checkCmdExist"]);unset($conf["self::checkCmdExist"]);#如果檢查指令是否存在失敗if($checkCmdExist["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkCmdExist;#回傳結果return $result;}#if end#如果指令不存在if($checkCmdExist["founded"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkCmdExist;#回傳結果return $result;}#if end#執行指令並檢查輸出的內容是否有關鍵字#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["checkCmdExist::callShell"]["command"]=$conf["cmd"];#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["checkCmdExist::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#如果有設置 $conf["argu"]if(isset($conf["argu"])){#串接將結果導向給後面指令處理的符號$conf["argu"][]="|";#串接截取關鍵字的參數$conf["argu"][]="grep";#串接要截取的關鍵字$conf["argu"][]=$conf["keyWord"];}#if end#反之else{#設置截取關鍵字的參數$conf["argu"]=array("|","grep",$conf["keyWord"]);}#else end#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["checkCmdExist::callShell"]["argu"]=$conf["argu"];#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["checkCmdExist::callShell"]["escapeshellarg"]="true";#如果有設置 $conf["username"]if(isset($conf["username"])){#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["checkCmdExist::callShell"]["username"]=$conf["username"];}#if end#如果有設置 $conf["password"]if(isset($conf["password"])){#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["checkCmdExist::callShell"]["password"]=$conf["password"];}#if end#$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["checkCmdExist::callShell"]);unset($conf["checkCmdExist::callShell"]);#取得截取關鍵字的指令$result["grepCmd"]=$callShell["cmd"];#如果執行指令失敗if($callShell["status"]==="false"){#如果有紀錄輸出if(isset($callShell["output"])){#取得搜尋的輸出$result["content"]=$callShell["output"];#如果等於空陣列if($callShell["output"]===array()){#設置執行正常$result["status"]="true";#設置找不到關鍵字$result["founded"]="false";#回傳結果return $result;}#if end}#if end#沒有輸出else{#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#else end}#if end#如果有輸出if(isset($callShell["output"])){#初始化新的輸出$newOutput=array();#如果有設置要排除 "| grep ".$conf["keyWord"] 關鍵字if($conf["excludeGrep"]==="true"){#設置不需要的關鍵字串A$notNeedKeyWordA="grep ";#設置不需要的關鍵字串B$notNeedKeyWordB=$conf["keyWord"];#針對每一列輸出foreach($callShell["output"] as $line){#如果含有要排除的關鍵字if(strpos($line,$notNeedKeyWordA)!==false && strpos($line,$notNeedKeyWordB)!==false){#繼續到下一個迴圈continue;}#if end#記錄輸出$newOutput[]=$line;}#foreach end#取得新的輸出$callShell["output"]=$newOutput;}#if end#取得搜尋的輸出$result["content"]=$callShell["output"];#取得搜尋結果的輸出行數$result["count"]=count($result["content"]);#如果等於空陣列if($callShell["output"]===array()){#設置執行正常$result["status"]="true";#設置找不到關鍵字$result["founded"]="false";#回傳結果return $result;}#if end#如果有輸出內容else if(count($callShell["output"])>0){#設置執行正常$result["status"]="true";#設置有找到關鍵字$result["founded"]="true";#回傳結果return $result;}#if end}#if end#沒有輸出else{#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#else end}#function searchOutPut end/*#函式說明:#檢查指令是否存在#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.#$result["cmdFullPath"],指令的絕對路徑.#必填參數:#$conf["cmd"],"字串",要查詢的指令.$conf["cmd"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function checkCmdExist(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmd");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("binPath");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/bin");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("netType","netCard");#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果參數檢查失敗if($checkArguments["status"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果參數檢查不通過if($checkArguments["passed"]==="false"){#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#初始化輸出$output=array();#取得 PATHexec("echo \$PATH",$output,$status);#如果執行失敗if($status!==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="取得系統環境變數 PATH 失敗";#回傳結果return $result;}#if end#取得 PATH 設定$PATHS=$output[0];#函式說明:#將固定格式的字串分開,並回傳分開的結果.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$PATHS;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";#參考資料:#無.#備註:#無.$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="取得系統環境變數 PATH 失敗";#回傳結果return $result;}#if end#取得PATH字串陣列$PATHS=$spiltString["dataArray"];#預設沒有找到程式$cmdFound=false;#針對每個 $PATHSforeach($PATHS as $path){#要運行的指令$cmd="targetToCheck='".$path."/".$conf["cmd"]."';".PHP_EOL."if [ -f \${targetToCheck} ]; then".PHP_EOL."exit;".PHP_EOL."else".PHP_EOL."exit 1;".PHP_EOL."fi";#初始化輸出$output=array();#執行指令exec($cmd,$output,$status);#如果執行正常if($status===0){#代表有找到程式$cmdFound=true;#設置完整的程式路徑$result["cmdFullPath"]=$path."/".$conf["cmd"];#跳離 foreachbreak;}#if end}#foreach end#設置找到指令$result["founded"]=$cmdFound;#設置執行正常$result["status"]="true";#回傳結果return $result;}#function checkCmdExist end/*#函式說明:#掃port的程式#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["content"],掃好可能可以使用的port資訊.#必填參數#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["target"],字串,要掃描的主機,預設為"127.0.0.1",#$conf["target"]="127.0.0.1";#$conf["-Pn"],字串,是否要啟用避免ping不到就會掃port失敗的功能,預設為"false".#$conf["-Pn"]="false";#參考資料:#無.#備註:#無.*/public static function nmap(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("target","-Pn");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("127.0.0.1","false");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php#建議:#增加可省略參數全部不能為空字串或空陣列的參數功能.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#檢查有無指令nmap存在#函式說明:#檢查指令是否存在#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.#必填參數:#$conf["cmd"],"字串",要查詢的指令.$conf["self::checkCmdExist"]["cmd"]="nmap";#可省略參數:#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".#$conf["binPath"]="";$checkCmdExist=self::checkCmdExist($conf["self::checkCmdExist"]);unset($conf["self::checkCmdExist"]);#如果檢查指令 nmap 失敗if($checkCmdExist["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkCmdExist;#回傳結果return $result;}#if end#如果指令 nmap 不存在if($checkCmdExist["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkCmdExist;#回傳結果return $result;}#if end#用 namp 指令掃 port#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="nmap";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($conf["target"]);#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$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["external::callShell"]);unset($conf["external::callShell"]);#如果掃port失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkCmdExist;#回傳結果return $result;}#if end#初始化儲存新的指令輸出$output=array();#針對每行輸出foreach($callShell["output"] as $line){#如果不是空白行if(trim($line)!==""){#記錄該行$output[]=$line;}#if}#foreach end#取代成沒有空白行的輸出$callShell["output"]=$output;#如果輸出列數大於4if(count($callShell["output"])>=4){#如果第4列有關鍵字 "PORT STATE SERVICE"#函式說明:#檢查字串裡面有無指定的關鍵字#回傳的結果:#$result["status"],"true"代表執行成功,"false"代表執行失敗。#$result["error"],錯誤訊息#$result["function"],當前執行的函式名稱.#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。#$result["keyWordCount"],找到的關鍵字數量.#必填參數:$conf["search::findKeyWord"]["keyWord"]="PORT";#想要搜尋的關鍵字$conf["search::findKeyWord"]["string"]=$callShell["output"][4];#要被搜尋的字串內容#可省略參數:#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);unset($conf["search::findKeyWord"]);#如果搜尋失敗if($findKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$findKeyWord;#回傳結果return $result;}#if end#如果找不到關鍵字if($findKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$findKeyWord;#回傳結果return $result;}#if end#nmap輸出範例例輸出/*Starting Nmap 7.12 ( https://nmap.org ) at 2016-08-30 18:18 CSTNmap scan report for 2.2.2.2Host is up (0.00048s latency).Not shown: 994 filtered portsPORT STATE SERVICE80/tcp open http513/tcp open login514/tcp open shell8000/tcp open http-alt8080/tcp open http-proxy8100/tcp open xprint-serverNmap done: 1 IP address (1 host up) scanned in 17.29 seconds*/#初始化使用中的port$result["content"]=array();#從第七列開始抓port資料到倒數第二列for($i=5;$i<count($callShell["output"])-1;$i++){#用「/」去分割#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$callShell["output"][$i];#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有分割用的符號if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得使用中的port$result["content"][]=$spiltString["dataArray"][0];}#for end}#if end#反之代表主機可能不接受ping,且未使用 -Pn 參數.else if($conf["-Pn"]==="false"){#取得計有的參數$params=$conf;#設置用-Pn參數$parmas["-Pn"]="true";#呼叫自己return self::nmap($params);}#else end#反之else{#設置執行不正常$result["status"]="false";#設置錯誤訊息$result["error"][]="無法取得port的使用狀況";#回傳結果return $result;}#else end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function nmap end/*#函式說明:#fedora的nmcli指令,取得所有網路連線設定的資訊.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["content"],連線資訊.有DEVICE,TYPE,UUID,NAME.#必填參數#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#無.#參考資料:#無.#備註:#僅能在命令列環境下執行.*/public static function nmcli_list(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查指令是否存在#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.#必填參數:#$conf["cmd"],"字串",要查詢的指令.$conf["cmd::checkCmdExist"]["cmd"]="nmcli";#可省略參數:#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".#$conf["binPath"]="";$checkCmdExist=$checkCmdExist=cmd::checkCmdExist($conf["cmd::checkCmdExist"]);unset($conf["cmd::checkCmdExist"]);#如果執行失敗if($checkCmdExist["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkCmdExist;#回傳結果return $result;}#if end#如果指令不存在if($checkCmdExist["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkCmdExist;#回傳結果return $result;}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="nmcli";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("c");#$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["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#取得輸出$nmcliStrArray=&$callShell["output"];#初始化儲存欄位的名稱$colName=array();#針對每個連線設定檔foreach($nmcliStrArray as $index=>$cInfo){#範例輸出:/*NAME UUID TYPE DEVICEbr0 0627f17d-f855-4dc7-b8fc-b0f893fe1a8d bridge br0enp3s0 2eca39a1-bacb-4fc2-aea8-eb2a990bf9af 802-3-ethernet enp3s0tap0 4f16a556-7ff7-4c80-a97d-ba1a5a181fbc tun tap0virbr0 84afc773-5d55-48b9-b06b-d91385091ea7 bridge virbr0CHT8909 820ec025-b1e5-45bc-b3c9-b14b6078f3f6 802-11-wireless --Coolbee Wifi ShoppingMall 67b5cd6d-2ebb-4f81-98ae-8cfba6979d58 802-11-wireless --bridge0 slave 1 86bca1ad-f984-47d0-833b-3ff3d8909f0a 802-3-ethernet --enp3s0 e0c87421-5d6c-3197-909e-15a94d42b8fe 802-3-ethernet --*/#分割字串#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$cInfo;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有找到分割用關鍵字" "if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果是標題字串if($index===0){#如果段數不等於4if($spiltString["dataCounts"]!==4){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#有幾段就執行幾次foreach($spiltString["dataArray"] as $cn){#串接欄位名稱$colName[]=$cn;}#foreach end}#if end#反之else{#如果段數小於4if($spiltString["dataCounts"]<4){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果段數不等於4if($spiltString["dataCounts"]!==4){#從後面開始擷取內容#暫存要儲存的key值$count=4;#初始化暫存網路連線設定檔的陣列$ni=array();#初始化迴圈起始的值$i=$spiltString["dataCounts"]-1;#有幾段就執行幾次for(;$i>$spiltString["dataCounts"]-4;$i--){#儲存欄位對應的內容$ni[$colName[--$count]]=$spiltString["dataArray"][$i];}#for end#初始化暫存第一個欄位的名稱$fc="";#剩下的段落為連線的名稱for(;$i>=0;$i--){#如果不是最後一個if($i!==0){#串接第一個欄位的內容$fc=$spiltString["dataArray"][$i]." ".$fc;}#if end#反之else{#串接第一個欄位的內容$fc=$spiltString["dataArray"][$i];}#else end}#for end#取得第一個欄位的內容$ni[$colName[--$count]]=$fc;#取得該連線設定檔的資訊$result["content"][]=$ni;}#if end#如果剛好等於4段if($spiltString["dataCounts"]===4){#有幾段就執行幾次for($i=0;$i<$spiltString["dataCounts"];$i++){#儲存欄位對應的內容$ni[$colName[$i]]=$spiltString["dataArray"][$i];}#for end#取得該連線設定檔的資訊$result["content"][]=$ni;}#if end}#if end}#foreach end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function nmcli_list end/*#函式說明:#fedora的nmcli指令,重新連線指定的連線。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["content"],連線資訊.有DEVICE,TYPE,UUID,NAME.#必填參數#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["name-uuid"],字串,"代表用來識別連線的名稱或UUID".$conf["name-uuid"]="";#可省略參數:#無.#參考資料:#無.#備註:#僅能在命令列環境下執行.*/public static function nmcli_reconnect($conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name-uuid");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("echo");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#若執行失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#若檢查不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="nmcli";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("c","down",$conf["name-uuid"]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);#如果執行失敗if($callShell["status"]==="false" && $callShell["error"][0]!==10 && $callShell["error"][0]!==4){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="nmcli";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("c","up",$conf["name-uuid"]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".#$conf["escapeshellarg"]="false";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);#如果執行失敗if($callShell["status"]==="false" && $callShell["error"][0]!==4){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#設置執行正常$result["status"]="true";#記錄執行結果$result["content"]=$callShell;#回傳結果return $result;}#function nmcli_reconnect end/*#函式說明:#抓取命令列的參數.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數陣列.#$result["content"],要回傳的參數陣列.#$result["count"],參數的數量.#$result["_GET"],收到的 HTTP GET 參數陣列.#$result["_POST"],收到的 HTTP POST 參數陣列.#必填參數:#無#可省略參數:#$conf["echo"],字串,"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".#$conf["echo"]="false";#$conf["httpGetToArgu"],字串,"true"代表要將 http get 參數變成參數來取得,像是 $_GET["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.#$conf["httpGetToArgu"]="false";#$conf["httpPostToArgu"],字串,"true"代表要將 http post 參數變成參數來取得,像是 $_POST["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.#$conf["httpPostToArgu"]="false";#參考資料:#無.#備註:#pipe要用''包住,才會被解析,例如'|'、'>'、'>>'.*/public static function getArgu(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");#$conf["mustBeFilledVariableName"]=array();#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.#$conf["mustBeFilledVariableType"]=array();#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("echo","httpGetToArgu","httpPostToArgu");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#若執行失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#若檢查不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#var_dump($_SERVER["argv"]);#儲存參數$result["content"]=$_SERVER["argv"];#取得參數數量$result["count"]=$_SERVER["argc"];#如果要將 http get 變成參數if($conf["httpGetToArgu"]==="true"){#函式說明:#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的函式名稱.#$result["warning"],警告訊息陣列.#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。#$result["lostVarName"],沒有皆收到的變數名稱陣列#$result["inputDataContent"],所接收的參數陣列.#$result["inputDataContent"]["變數名稱"],所接收變數的內容.#$result["inputDataCount"],從表單總共接收到幾個元素.#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.#必填參數:#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="get";#可省略參數:#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.$conf["form::responseMultiInputDataSecurityEnhance"]["allowGet"]="true";#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.#$conf["limitPrePage"]=array("");#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"#$conf["transferLocation"]="";#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.#$conf["ignore"]=array();#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.#$conf["correctCharacter"]="false";#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.#$conf["checkedVarName"]=array();#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.#$conf["sessionNameArray"]=array();#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.#$conf["unsetSessionArray"]=array();#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.#$conf["recaptcha_url"]="";#參考資料:#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php#備註:#表單變數的名稱若含有「.」,則會變成「-」。$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);unset($conf["form::responseMultiInputDataSecurityEnhance"]);#若執行失敗if($responseMultiInputDataSecurityEnhance["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$responseMultiInputDataSecurityEnhance;#回傳結果return $result;}#if end#取得 GET 變數$result["_GET"]=$responseMultiInputDataSecurityEnhance["inputDataContent"];#函式說明:#將多個一維陣列串聯起來,key從0開始排序.#回傳的結果:#$result["status"],"true"表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數.#$result["content"],合併好的一維陣列.#必填參數#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);$conf["arrays::mergeArray"]["inputArray"]=array($result["content"],$result["_GET"]);#可省略參數:#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.$conf["arrays::mergeArray"]["allowRepeat"]="false";#參考資料:#無.#備註:#無.$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);unset($conf["arrays::mergeArray"]);#若執行失敗if($mergeArray["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$mergeArray;#回傳結果return $result;}#if end#取得合併好的參數陣列$result["content"]=$mergeArray["content"];#更新參數的數量$result["count"]=count($result["content"]);}#if end#如果要將 http post 變成參數if($conf["httpPostToArgu"]==="true"){#函式說明:#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的函式名稱.#$result["warning"],警告訊息陣列.#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。#$result["lostVarName"],沒有皆收到的變數名稱陣列#$result["inputDataContent"],所接收的參數陣列.#$result["inputDataContent"]["變數名稱"],所接收變數的內容.#$result["inputDataCount"],從表單總共接收到幾個元素.#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.#必填參數:#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="post";#可省略參數:#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.$conf["form::responseMultiInputDataSecurityEnhance"]["allowGet"]="true";#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.#$conf["limitPrePage"]=array("");#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"#$conf["transferLocation"]="";#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.#$conf["ignore"]=array();#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.#$conf["correctCharacter"]="false";#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.#$conf["checkedVarName"]=array();#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.#$conf["sessionNameArray"]=array();#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.#$conf["unsetSessionArray"]=array();#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.#$conf["recaptcha_url"]="";#參考資料:#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php#備註:#表單變數的名稱若含有「.」,則會變成「-」。$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);unset($conf["form::responseMultiInputDataSecurityEnhance"]);#若執行失敗if($responseMultiInputDataSecurityEnhance["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$responseMultiInputDataSecurityEnhance;#回傳結果return $result;}#if end#取得 POST 變數$result["_POST"]=$responseMultiInputDataSecurityEnhance["inputDataContent"];#函式說明:#將多個一維陣列串聯起來,key從0開始排序.#回傳的結果:#$result["status"],"true"表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數.#$result["content"],合併好的一維陣列.#必填參數#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);$conf["arrays::mergeArray"]["inputArray"]=array($result["content"],$result["_POST"]);#可省略參數:#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.$conf["arrays::mergeArray"]["allowRepeat"]="false";#參考資料:#無.#備註:#無.$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);unset($conf["arrays::mergeArray"]);#若執行失敗if($mergeArray["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$mergeArray;#回傳結果return $result;}#if end#取得合併好的參數陣列$result["content"]=$mergeArray["content"];#更新參數的數量$result["count"]=count($result["content"]);}#if end#設置執行正常$result["status"]="true";#如果要印出內容if($conf["echo"]==="true"){#針對每個參數foreach($result["content"] as $param){#印出來並換行echo $param.PHP_EOL;}#foreach end}#if end#反之else{#回傳結果return $result;}#else end}#function getArgu end/*#函式說明:#解析參數.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],解析好的參數陣列.#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.#$result["program"],字串,執行的程式名稱.#必填參數:#無.#可省略參數:#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.#$conf["helpFunc"]="help";#$conf["parseFormVar"],解析表單變數(get\post),預設為"false"不使用;反之設置為"true".#$conf["parseFormVar"]="false";#參考資料:#無.#備註:#僅能在命令列底下執行.#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .*/public static function parseArgu(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()=="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");#$conf["mustBeFilledVariableName"]=array();#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.#$conf["mustBeFilledVariableType"]=array();#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("helpFunc","parseFormVar");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#若執行失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#若檢查不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#抓取命令列的參數.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數陣列.#$result["content"],要回傳的參數陣列.#$result["count"],參數的數量.#必填參數:#無#可省略參數:#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".#$conf["echo"]="false";$conf["cmd::getArgu"]=array();#如果要解析表單變數if($conf["parseFormVar"]==="true"){#$conf["httpGetToArgu"],字串,"true"代表要將 http get 參數變成參數來取得,像是 $_GET["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.$conf["cmd::getArgu"]["httpGetToArgu"]="true";#$conf["httpPostToArgu"],字串,"true"代表要將 http post 參數變成參數來取得,像是 $_POST["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.$conf["cmd::getArgu"]["httpPostToArgu"]="true";}#if end$getArgu=cmd::getArgu($conf["cmd::getArgu"]);unset($conf["cmd::getArgu"]);#如果解析失敗if($getArgu["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$getArgu;#回傳結果return $result;}#if end#若參數若不成對if($getArgu["count"]%2===0){#如果有設置 help functionif(isset($conf["helpFunc"])){#若help函式是可以呼叫的if(is_callable("\qbpwcf\\".$conf["helpFunc"])){#呼叫之call_user_func("\qbpwcf\\".$conf["helpFunc"]);}#if end}#if end#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$getArgu;#設置執行錯誤訊息$result["error"][]="參數不成對";#回傳結果return $result;}#if end#取得執行的程式名稱$result["program"]=$getArgu["content"][0];#移除第一個參數unset($getArgu["content"][0]);#初始化抓到的參數$result["content"]=array();#針對每個參數for($i=1;$i<$getArgu["count"]-1;$i=$i+2){#如果不是 "-" 開頭的參數名稱if(strpos($getArgu["content"][$i],"-")!==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$getArgu;#設置執行錯誤訊息$result["error"][]="參數名稱 \"".$getArgu["content"][$i]."\" 必須為 \"-\" 開頭";#回傳結果return $result;}#if end#函式說明:#移除字串開頭的特定內容#回傳的接結果:#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式.#$result["content"],處理好的字串.#必填參數:#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$getArgu["content"][$i];#$conf["keyWord"],字串,要移除的字串開頭關鍵字.$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]="-";#可省略參數:#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.$conf["stringProcess::delKeyWordsInStrHead"]["recursive"]="true";$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);unset($conf["stringProcess::delKeyWordsInStrHead"]);#如果處理字串失敗if($delKeyWordsInStrHead["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$getArgu;#設置執行錯誤訊息$result["error"][]="處理參數 \"".$getArgu["content"][$i]."\" 失敗";#回傳結果return $result;}#if end#取得參數名稱$paramName=$delKeyWordsInStrHead["content"];#如果下一個參數不存在if(!isset($getArgu["content"][$i+1])){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$getArgu;#設置執行錯誤訊息$result["error"][]="參數 \"".$getArgu["content"][$i]."\" 對應的數值不存在";#回傳結果return $result;}#if end#設置參數的數值$result["content"][$paramName][]=$getArgu["content"][$i+1];}#foreach end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function parseArgu end/*#函式說明:#將指令字串解析成陣列,方便給予 external::callShell 使用#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],解析好的指令陣列.#$result["cmd"],解析好的指令名稱.#$result["argus"],解析好的參數陣列.#$result["argu"],所使用的參數.#必填參數#$conf["cmdStr"],字串,要解析的指令字串$conf["cmdStr"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function parseCmdString(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息#必填寫的參數:#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmdStr");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","port","title","fullScreen","spicePassword");#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,"false",null);#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkResult["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkResult["passed"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkResult;#回傳結果return $result;}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]=escapeshellarg(pathinfo(__FILE__)["dirname"])."/../../bin/parse";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($conf["cmdStr"]);#$conf["external::callShell"]["argu"]=array("`cat",$createTempFile["content"]."`","parse","\${params}");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]=-"";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.#$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#debug#var_dump(__FUNCTION__,__LINE__,$callShell);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#設置執行正常$result["status"]="true";#初始化解析得到的參數$result["argus"]=array();#如果有輸出if(isset($callShell["output"][0])){#如果輸出非 jsonif(json_validate($callShell["output"][0])===false){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#取得解析的結果$parseResult=(array)(json_decode($callShell["output"][0]));}#if end#針對執行結果輸出的每個元素foreach($parseResult as $index=>$str){#如果是第1個元素if($index<1){#忽略,換下一個元素continue;}#if end`#如果是第2個元素if($index===1){#設置為解析成的指令$result["cmd"]=$str;#設置為解析成連續的字串之一$result["content"][]=$str;#下一個元素continue;}#if end#取得參數$result["argus"][]=$str;#設置為解析成連續的字串之一$result["content"][]=$str;}#foreach end#回傳結果return $result;}#function parseCmdString end/*#函式說明:#搜尋特定目錄底下或檔案是否有關鍵字存在,其行數為何.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["folder"],搜尋的目標是否為資料夾,"true"為是;"false"為否.#$result["content"],符合的列數與內容.#$result["content"][$i]["AD"],關鍵字是在哪個檔案裡面.#$result["content"][$i]["LN"],第$i+1個符合條件的列數.#$result["content"][$i]["LC"],第$i+1個符合條件的列內容.#必填參數#$conf["target"],字串,要搜尋的路徑或檔案名稱.$conf["target"]="";#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["keyWord"],字串,關鍵字.$conf["keyWord"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function searchFileContent(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息#必填寫的參數:#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("target","keyWord","fileArgu");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","port","title","fullScreen","spicePassword");#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,"false",null);#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkResult["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkResult["passed"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkResult;#回傳結果return $result;}#if end#轉換檔案路徑為相對於當前位置的路徑#函式說明:#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函式名稱.#$result["content"],網址,若是在命令列執行,則為"null".#$result["webPathFromRoot"],相對於網頁根目錄的路徑.#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.#必填參數:#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.$conf["fileAccess::getInternetAddress"]["address"]=$conf["target"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".#$conf["userDir"]="true";#備註:#在命令列執行,所得的路徑是錯誤的。$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);unset($conf["fileAccess::getInternetAddress"]);#如果解析檔案位置失敗if($getInternetAddress["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$getInternetAddress;#回傳結果return $result;}#if end#取得檔案的相對位置$fileRelativeAddr=$getInternetAddress["fileSystemRelativePosition"];#取得檔案的絕對位置$fileAbsolute=$getInternetAddress["fileSystemAbsoulutePosition"];#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#$result["pid"],pid#必填參數#$conf["command"],字串,要執行的指令與.#$conf["external::callShell"]["command"]="grep -asnr \"".$conf["keyWord"]."\" \"".$conf["target"]."\"";$conf["external::callShell"]["command"]="grep";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-asnr",$conf["keyWord"],$fileRelativeAddr);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".$conf["external::callShell"]["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"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果執行cmd失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#取得搜尋結果$output=$callShell["output"];#判斷是檔案還是目錄$folder=is_dir($fileRelativeAddr);#記錄搜尋的目標是檔案$result["folder"]=$folder;#如果是檔案if(!$folder){#針對每行結果foreach($output as $LC){#用":"分割#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$LC;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有分割用的關鍵字if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$spiltString;#回傳結果return $result;}#if end#記錄該行行數$lineN=$spiltString["dataArray"][0];#解析內容#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函式名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$LC;#要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$lineN.":";#特定字串.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果處理字串失敗if($delStrBeforeKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果關鍵字找不到if($delStrBeforeKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#記錄該行內容$lineContent=$delStrBeforeKeyWord["content"];#記錄搜尋到的內容$result["content"][]=array("LN"=>$lineN,"LC"=>$lineContent);}#foreach end}#if end#反之是目錄else{#針對每行結果foreach($output as $LC){#用":"分割#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$LC;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有分割用的關鍵字if($spiltString["found"]==="false"){#如果開頭有 "Binary file "#函式說明:#取得符合特定字首與字尾的字串#回傳的結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["returnString"],爲符合字首條件的字串內容。#必填參數:#$conf["checkString"],字串,要檢查的字串.$conf["search::getMeetConditionsString"]["checkString"]=$LC;#可省略參數:#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.$conf["search::getMeetConditionsString"]["frontWord"]="Binary file ";#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.$conf["tailWord"]=" matches";#參考資料:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);unset($conf["search::getMeetConditionsString"]);#如果找關鍵字失敗if($getMeetConditionsString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$getMeetConditionsString;#回傳結果return $result;}#if end#如果找不到關鍵字if($getMeetConditionsString["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$getMeetConditionsString;#回傳結果return $result;}#if end#忽略該筆紀錄continue;}#if end#記錄該行所屬檔案路徑與名稱$fileAddr=$spiltString["dataArray"][0];#記錄該行行數$lineN=$spiltString["dataArray"][1];#解析內容#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函式名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$LC;#要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$fileAddr.":".$lineN.":";#特定字串.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果處理字串失敗if($delStrBeforeKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果關鍵字找不到if($delStrBeforeKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#記錄該行內容$lineContent=$delStrBeforeKeyWord["content"];#記錄搜尋到的內容$result["content"][]=array("AD"=>$fileAddr,"LN"=>$lineN,"LC"=>$lineContent);}#foreach end}#else end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function searchFileContent end/*#函式說明:#透過"df -h"取得伺服器上的磁碟空間用量#回傳結果#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數#$result["content"],磁碟空間用量.#$result["oriOutput"],原始輸出的逐行內容.#必填參數:#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function getStorageUsage(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["skipableVariableName"]=array();#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["skipableVariableType"]=array();#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["skipableVarDefaultValue"]=array("");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php#建議:#增加可省略參數全部不能為空字串或空陣列的參數功能.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#用 "df -h" 取得分割區使用狀況#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#$result["pid"],pid#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="df";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-h");#$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["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#取的原始的輸出$result["oriOutput"]=$callShell["output"];#針對每個結果foreach($callShell["output"] as $lineN=>$dfOutput){#範例輸出/*Filesystem Size Used Avail Use% Mounted ondevtmpfs 1.5G 0 1.5G 0% /devtmpfs 1.5G 388K 1.5G 1% /dev/shmtmpfs 1.5G 1.6M 1.5G 1% /runtmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup/dev/mapper/fedora-root 50G 29G 19G 61% /tmpfs 1.5G 160K 1.5G 1% /tmp/dev/vda1 477M 162M 286M 37% /boot/dev/mapper/fedora-home 47G 7.5G 37G 17% /hometmpfs 295M 28K 295M 1% /run/user/42tmpfs 295M 18M 278M 6% /run/user/1000*/#如果是標題列if($lineN===0){#分割標題欄位#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$dfOutput;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#如果分割字串失敗if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#針對每個分割好的內容for($i=0;$i<$spiltString["dataCounts"];$i++){#如果後面還有if(isset($spiltString["dataArray"][$i+1])){#如果當前跟後一個是 "Mounted" 跟 "on"if($spiltString["dataArray"][$i+1]==="Mounted" && $spiltString["dataArray"][$i+1]==="on"){#取得 "Mounted on" 標題$title[]=$spiltString["dataArray"][$i]." ".$spiltString["dataArray"][$i+1];#跳出迴圈break;}#if end}#if end#取得標題列$title[]=$spiltString["dataArray"][$i];}#for end}#if end#反之是內容列else{#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$dfOutput;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#如果分割字串失敗if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#初始化暫存的陣列$tempArray=array();#針對每個分割好的內容for($i=0;$i<$spiltString["dataCounts"];$i++){#加上欄位的內容(用名稱為key)$tempArray=$tempArray+array($title[$i]=>$spiltString["dataArray"][$i]);}#for end#儲存內容$result["content"][]=$tempArray;}#else end}#foreach end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function getStorageUsage end/*#函式說明:#檢查與取得net interface的資訊#回傳結果#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],使用的command.#$result["argu"],使用的參數.#$result["founded"],是否有找到目標網路界面,"true"代表有,"false"代表沒有.#$result["content"],原始輸出的逐行內容.#必填參數:#$conf["netInterface"],字串,網路界面的名稱.$conf["netInterface"]="";#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function getNetDevInfo(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("netInterface","fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["skipableVariableName"]=array();#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["skipableVariableType"]=array();#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["skipableVarDefaultValue"]=array("");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php#建議:#增加可省略參數全部不能為空字串或空陣列的參數功能.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完二元碼後的輸出陣列.#$result["pid"],pid#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="ifconfig";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$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["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果執行cmd失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#取得執行的cmd$result["cmd"]=$callShell["cmd"];#取得cmd的輸出$result["content"]=$callShell["output"];#font keyword$keyword=$conf["netInterface"].": ";#函式說明:#取得多個符合特定字首與字尾的字串.#回傳的結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["function"],當前執行的函式名稱.#$result["returnString"],爲符合字首條件的字串陣列內容。#必填參數:#$conf["checkString"],陣列字串,要檢查的字串們.$conf["search::getMeetConditionsStringMulti"]["checkString"]=$result["content"];#要檢查的字串陣列#可省略參數:#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.$conf["search::getMeetConditionsStringMulti"]["frontWord"]=$keyword;#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.#$conf["tailWord"]="";#參考資料:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。$getMeetConditionsStringMulti=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);unset($conf["search::getMeetConditionsStringMulti"]);#如果尋找過程出錯if($getMeetConditionsStringMulti["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$getMeetConditionsStringMulti;#回傳結果return $result;}#if end#設置查網路界面的結果$result["founded"]=$getMeetConditionsStringMulti["founded"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function getNetDevInfo end/*#函式說明:#檢查當前目錄是否在svn版本之下#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["warning"],警告訊息陣列.#$result["content"]["issvnworkdir"],當前目錄是否處於svn版本控制之下,"ture"代表是,"false"代表不是.#$result["content"]["account"],連線到repo的帳戶.#$result["content"]["repo"],連線到的repo.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function issvnworkdir(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()=="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["skipableVariableName"]=array();#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["skipableVariableType"]=array();#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["skipableVarDefaultValue"]=array("");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#若檢查參數不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#執行svn info指令#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("info");#$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["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.$conf["external::callShell"]["getErr"]="true";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行指令失敗if($callShell["status"]==="false"){#設置執行正常$result["status"]="true";#設置警告訊息$result["warning"]=$callShell;#設置警告訊息$result["warning"][]="當前目錄「".$_SERVER["PWD"]."」不是svn工作目錄";#設置當前目錄不是svn目錄$result["content"]["issvnworkdir"]="false";#回傳結果return $result;}#if end#從svn的URL找到使用的帳號foreach($callShell["output"] as $line){#如果找到有 "URL: svn+ssh://" 的關鍵字列if(strpos($line,'Repository Root: svn+ssh://')!==false){#取得帳字元結尾位置$acTail=strpos($line,'@');#取得帳號$result["content"]["account"]=substr($line,strlen('Repository Root: svn+ssh://'),$acTail-strlen('Repository Root: svn+ssh://'));#取得svn repo位址$result["content"]["repo"]=substr($line,$acTail+1);#跳出foreachbreak;}#if ned}#foreach end#設置當前目錄是svn目錄$result["content"]["issvnworkdir"]="true";#設置執行正常$result["status"]="true";#回傳結果return $result;}#function issvnworkdir end/*#函式說明:#執行svn status指令#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"]["ori"],指令輸出的原始結果陣列.#$result["content"]["status"][$i]["status"],第$i+1個目標的狀態.#$result["content"]["status"][$i]["target"],第$i+1個目標的路徑與名稱.#$result["content"]["status"][$i]["is_dir"],第$i+1個目標是否為目錄,"true"代表是,"false"代表不是.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["target"],字串,要檢查status的目標.#$conf["target"]="";#參考資料:#無.#備註:#範例輸出->svn: warning: W155010: The node '.../usr/lib64' was not found.*/public static function svnsta(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()=="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("target");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("target");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["skipableVarDefaultValue"]=array("");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#若檢查參數不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#檢查當前目錄是否在svn版本之下#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["warning"],警告訊息陣列.#$result["content"]["issvnworkdir"],當前目錄是否處於svn版本控制之下,"ture"代表是,"false"代表不是.#$result["content"]["account"],連線到repo的帳戶.#$result["content"]["repo"],連線到的repo.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["cmd::issvnworkdir"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#無.$issvnworkdir=cmd::issvnworkdir($conf["cmd::issvnworkdir"]);unset($conf["cmd::issvnworkdir"]);#如果檢查當前目錄是否在svn版本控制下失敗if($issvnworkdir["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$issvnworkdir;#回傳結果return $result;}#if end#如果當前目錄不是svn工作目錄if($issvnworkdir["content"]["issvnworkdir"]==="false"){#設置執行正常$result["status"]="false";#設置錯誤訊息$result["error"]=$issvnworkdir;#回傳結果return $result;}#if end#設置要執行的指令$cmd="svn";#初始化給 svn 指令的參數$arguForSvn=array("status");#如果有設置要檢查的目標if(isset($conf["target"])){#加上目標的參數$arguForSvn[]=$conf["target"];}#if end#執行svn status指令#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$arguForSvn;#$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["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.$conf["external::callShell"]["getErr"]="true";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行指令失敗if($callShell["status"]==="false"){#設置執行正常$result["status"]="false";#設置警告訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#取得指令輸出的結果$result["content"]["ori"]=$callShell["output"];#如果不等於空陣列if($result["content"]["ori"]!==array()){#未進入版本控制的軟連結到目錄,會出現類似以下警告訊息.#svn: warning: W155010: The node '.../usr/lib64' was not found#如果遇到沒有進入版本控制的軟連結if( strpos($result["content"]["ori"][0]," W155010: ")!==false && strpos($result["content"]["ori"][0]," The node ")!==false && strpos($result["content"]["ori"][0]," was not found")!==false ){#設置該目標的 狀態(status), 路徑與名稱(target), 是否為目錄(is_dir).$result["content"]["status"][]=array("status"=>"?","target"=>$conf["target"],"is_dir"=>"false");}#if end#反之else{#針對每一列foreach($result["content"]["ori"] as $line){#取得檔案的 status 與名稱sscanf($line,"%s %s",$sta,$fi);#設置該目標的 狀態(status), 路徑與名稱(target), 是否為目錄(is_dir).$result["content"]["status"][]=array("status"=>$sta,"target"=>$fi,"is_dir"=>is_file($fi)?"false":"true");}#foreach end}#else end}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function svn status end/*#函式說明:#提供方便進行svn commit的工具#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],commit完得到的結果.#$result["content"]["content"],執行完svn ci得到的終端輸出.#$result["content"]["cmd"],實際執行的指令.#$result["content"]["status"],svn指令回傳的代碼,0代表正常結束.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["author"],字串,作者資訊,若無則預設為"-- Power by QBPWCF"#$conf["author"]="";#參考資料:#sscanf指定讀到特定字符才結束=>http://stackoverflow.com/questions/2854488/reading-a-string-with-spaces-with-sscanf#參考資料:#無.#備註:#無.*/public static function svnci(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()=="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("author");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("-- Power by QBPWCF");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#抓取命令列的參數.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數陣列.#$result["content"],要回傳的參數陣列.#$result["count"],參數的數量.#必填參數:#無#可省略參數:#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".#$conf["echo"]="false";$conf["cmd::getArgu"]=array();$getArgu=cmd::getArgu($conf["cmd::getArgu"]);unset($conf["cmd::getArgu"]);#如果取得參數失敗if($getArgu["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$getArgu;#回傳結果return $result;}#if end#如果有第一個參數if(isset($getArgu["content"][1])){#如果是 "-h" 跟 "--help"if($getArgu["content"][1]==="-h" || $getArgu["content"][1]==="--help"){#提示用法echo "usage: ".basename($_SERVER["PHP_SELF"])." [--ssh-port=ssh connect port] [--ssh-key=ssh prive key] ".PHP_EOL;echo "--ssh-port, 代表ssh連線的port.".PHP_EOL;echo "--ssh-key, 代表ssh連線所要使用的私有金鑰.".PHP_EOL;exit;}#if end}#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["content"]["a"]["b"][$i]=$value .$conf["cmd::parseArgu"]=array();$parseArgu=cmd::parseArgu($conf["cmd::parseArgu"]);unset($conf["cmd::parseArgu"]);#如果解析參數失敗if($parseArgu["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$parseArgu;#回傳結果return $result;}#if end#初始化 ssh 設定的字串$sshOption="--config-option=config:tunnels:ssh=ssh";#如果有設定ssh port的參數if(isset($parseArgu["content"]["ssh-port"])){#如果有第一個參數if(isset($parseArgu["content"]["ssh-port"][0])){#設置 ssh 的 port$sshOption=$sshOption." -p ".$parseArgu["content"]["ssh-port"][0];}#if end}#if end#如果有設定ssh key的參數if(isset($parseArgu["content"]["ssh-key"])){#如果有第一個參數if(isset($parseArgu["content"]["ssh-key"][0])){#設置 ssh 的 port$sshOption=$sshOption." -i ".$parseArgu["content"]["ssh-key"][0];}#if end}#if end#函式說明:#檢查當前目錄是否在svn版本之下#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["warning"],警告訊息陣列.#$result["content"]["issvnworkdir"],當前目錄是否處於svn版本控制之下,"ture"代表是,"false"代表不是.#$result["content"]["account"],連線到repo的帳戶.#$result["content"]["repo"],連線到的repo.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["cmd::issvnworkdir"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#無.$issvnworkdir=cmd::issvnworkdir($conf["cmd::issvnworkdir"]);unset($conf["cmd::issvnworkdir"]);#如果出錯if($issvnworkdir["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$issvnworkdir;#回傳結果return $result;}#if end#如果不在版本控制目錄底下if($issvnworkdir["content"]["issvnworkdir"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$issvnworkdir;#回傳結果return $result;}#if end#取得使用的svn+ssh帳號$account=$issvnworkdir["content"]["account"];#取得svn的repo$repo=$issvnworkdir["content"]["repo"];#預設存放 svn 賬號密碼的 xml 檔案位置$defaultSvnAcctXml=pathinfo(__FILE__)["dirname"]."/../../../etc/qbpwcf/qbpwcf.conf.xml";#預設存放 svn 賬號密碼的 local xml 檔案位置$defaultLocalSvnAcctXml=$defaultSvnAcctXml;#預設存放 svn 賬號密碼的 xml 檔案可能位置$svnAcctXmlArray=array($defaultSvnAcctXml);#如果存在 include pathif(get_include_path()!==false){#函式說明:#將固定格式的字串分開,並回傳分開的結果.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=get_include_path();#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";#參考資料:#無.#備註:#無.$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果執行失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有符合的分割符號if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有切割出東西if($spiltString["dataCounts"]<1){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果 first php include path 不為 "/" 結尾if($spiltString["dataArray"][0][strlen($spiltString["dataArray"][0])-1]!=="/"){#開頭加上 "/"$defaultLocalSvnAcctXml="/".$defaultLocalSvnAcctXml;}#if end#增加 存放帳號密碼的xml檔案 位置$svnAcctXmlArray[]=$spiltString["dataArray"][0].$defaultLocalSvnAcctXml;}#if end#針對每個可能的 存放帳號密碼的xml檔案 位置foreach($svnAcctXmlArray as $index=>$svnAcctXml){#如果存放帳號密碼的xml檔案不存在if(!file_exists($svnAcctXml)){#如果是最後一個xml檔案了if($index===count($svnAcctXmlArray)-1){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]="存放帳號密碼的xml檔案(".$svnAcctXml.")不存在";#回傳結果return $result;}#if end}#if end#反之檔案存在else {#更新要使用的 存放帳號密碼的xml檔案$defaultSvnAcctXml=$svnAcctXml;#跳出 foreachbreak;}#else end}#foreach end#初始化要使用的svn+ssh帳號$password="";#取得qbpwcf設定檔案的內容#檢查是否有svn的URL上帳號對應的密碼是否存在#函式說明:#取得xml特定標籤的內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["warning"],警告訊息陣列.#$result["function"],當前執行的函式名稱.#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.#$result["content"],xml物件的標籤內容.#$result["tag"],修正名稱格式後取得目標標籤內容的階層陣列.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::getTagInfo"]["xmlPosition"]=$defaultSvnAcctXml;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::getTagInfo"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::getTagInfo"]["tag"]=array("qbpwcf","cmd","svnci","conf");$getTagInfo=xml::getTagInfo($conf["xml::getTagInfo"]);unset($conf["xml::getTagInfo"]);#如果讀取xml檔案失敗if($getTagInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$getTagInfo;#回傳結果return $result;}#if end#如果標籤不存在if($getTagInfo["tagExist"]==="false"){#函式說明:#在目標層級新增標籤與內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","account");#$conf["tagValue"],字串,目標標籤的內容要放什麼.$conf["xml::addTag"]["tagValue"]=$account;#參考資料:#addchild->http://php.net/manual/en/simplexmlelement.addchild.php$addTag=xml::addTag($conf["xml::addTag"]);unset($conf["xml::addTag"]);#如果讀取新增標籤檔案失敗if($addTag["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$addTag;#回傳結果return $result;}#if end#函式說明:#在目標層級新增標籤與內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","password");#$conf["tagValue"],字串,目標標籤的內容要放什麼.$conf["xml::addTag"]["tagValue"]=$password;#參考資料:#addchild->http://php.net/manual/en/simplexmlelement.addchild.php$addTag=xml::addTag($conf["xml::addTag"]);unset($conf["xml::addTag"]);#如果讀取新增標籤檔案失敗if($addTag["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$addTag;#回傳結果return $result;}#if end#函式說明:#在目標層級新增標籤與內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","repo");#$conf["tagValue"],字串,目標標籤的內容要放什麼.$conf["xml::addTag"]["tagValue"]=$repo;#參考資料:#addchild->http://php.net/manual/en/simplexmlelement.addchild.php$addTag=xml::addTag($conf["xml::addTag"]);unset($conf["xml::addTag"]);#如果讀取新增標籤檔案失敗if($addTag["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$addTag;#回傳結果return $result;}#if end#取得qbpwcf設定檔案的內容#檢查是否有svn的URL上帳號對應的密碼是否存在#函式說明:#取得xml特定標籤的內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["warning"],警告訊息陣列.#$result["function"],當前執行的函式名稱.#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.#$result["content"],xml物件的標籤內容.#$result["tag"],修正名稱格式後取得目標標籤內容的階層陣列.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::getTagInfo"]["xmlPosition"]=$defaultSvnAcctXml;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::getTagInfo"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::getTagInfo"]["tag"]=array("qbpwcf","cmd","svnci","conf");$getTagInfo=xml::getTagInfo($conf["xml::getTagInfo"]);unset($conf["xml::getTagInfo"]);#如果讀取xml檔案失敗if($getTagInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$getTagInfo;#回傳結果return $result;}#if end#如果標籤不存在if($getTagInfo["tagExist"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$getTagInfo;$result["error"][]="應該存在的tag並不存在";#回傳結果return $result;}#if end}#if end#如果只有一筆資料$dataCount=count($getTagInfo["content"]->account);#針對每個記錄for($i=0;$i<$dataCount;$i++){#如果 帳號 跟 repo 有對上if((string)$getTagInfo["content"]->account[$i]===$account &&(string)$getTagInfo["content"]->repo[$i]===$repo){#提示有找到既有的帳號與repoecho "找到既有的帳號與repo".PHP_EOL;#取得密碼的形態$storedPass=(string)($getTagInfo["content"]->password[$i]);#初始化密碼不ok$passIsOk=false;#無窮迴圈直到密碼對了while(!$passIsOk){#測試密碼是否正確#用 svn ls 來驗證".PHP_EOL;#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShel"]["command"]="echo";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShel"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShel"]["argu"]=array("\"".$storedPass."\"","|","sshpass","-v","svn","ls",$sshOption);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShel"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShel"]);unset($conf["external::callShel"]);#如果執行失敗if($callShell["status"]==="false"){#如果不是密碼錯誤if($callShell["error"][0]!==5){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#提示輸入密碼#函式說明:#讀取標準I/O的一行輸入.並提供提示說明.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],取得的輸入內容.#必填參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["cmd::readLine"]["commentsArray"]=array("請輸入帳號(".$account.")對應的密碼");#可省略參數:#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";$readLine=cmd::readLine($conf["cmd::readLine"]);unset($conf["cmd::readLine"]);#如果執行失敗if($readLine["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$readLine;#回傳結果return $result;}#if end#取得輸入的密碼$untestPass=$readLine["content"];#密碼正確,儲存密碼#函式說明:#更新xml標籤的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::updateTag"]["xmlPosition"]=$defaultSvnAcctXml;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::updateTag"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::updateTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","password");#$conf["tagValue"],字串,目標標籤的內容要放什麼.$conf["xml::updateTag"]["tagValue"]=$untestPass;#參考資料:#replacechild=>http://php.net/manual/en/domnode.replacechild.php#loadxml=>http://php.net/manual/en/domdocument.loadxml.php#update xml node value=>http://stackoverflow.com/questions/4748014/updating-xml-node-with-php#備註:#若有多個同名的tag,則只會對於第一個tag進行操作.$updateTag=xml::updateTag($conf["xml::updateTag"]);unset($conf["xml::updateTag"]);#如果更新檔案失敗if($updateTag["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$updateTag;#回傳結果return $result;}#if end#儲存密碼echo "已更新svn密碼".PHP_EOL;#取得正確的 svn 密碼$storedPass=$untestPass;}#if end#反之else{#設置密碼正確$passIsOk=true;#儲存密碼echo "svn密碼正確".PHP_EOL;#跳出 while forbreak 2;}#else end}#while end}#if end#如果已經是最後一筆帳號、密碼、repo對不上else if($i===$dataCount-1){#提示有找到既有的帳號與repoecho "既有的帳號與repo都不符合".PHP_EOL;#提示輸入密碼#函式說明:#讀取標準I/O的一行輸入.並提供提示說明.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],取得的輸入內容.#必填參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["cmd::readLine"]["commentsArray"]=array("請輸入帳號(".$account.")對應的密碼");#可省略參數:#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";$readLine=cmd::readLine($conf["cmd::readLine"]);unset($conf["cmd::readLine"]);#如果執行失敗if($readLine["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$readLine;#回傳結果return $result;}#if end#取得輸入的密碼$untestPass=$readLine["content"];#初始化密碼不ok$passIsOk=false;#無窮迴圈直到密碼對了while(!$passIsOk){#測試密碼是否正確#用 svn ls 來驗證".PHP_EOL;#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShel"]["command"]="echo";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShel"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.#$conf["external::callShel"]["argu"]=array("\"".$untestPass."\"","|","sshpass","-v","svn","ls",$sshOption);$conf["external::callShel"]["argu"]=array($untestPass,"|","sshpass","-v","svn","ls",$sshOption);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShel"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShel"]);unset($conf["external::callShel"]);#如果執行失敗if($callShell["status"]==="false"){#如果不是密碼錯誤if($callShell["error"][0]!==5){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#提示輸入密碼#函式說明:#讀取標準I/O的一行輸入.並提供提示說明.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],取得的輸入內容.#必填參數:#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["cmd::readLine"]["commentsArray"]=array("請輸入帳號(".$account.")對應的密碼");#可省略參數:#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";$readLine=cmd::readLine($conf["cmd::readLine"]);unset($conf["cmd::readLine"]);#如果執行失敗if($readLine["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$readLine;#回傳結果return $result;}#if end#取得輸入的密碼$untestPass=$readLine["content"];}#if end#反之else{#設置密碼正確$passIsOk=true;#儲存密碼echo "svn密碼正確".PHP_EOL;#取得正確的 svn 密碼$untestPass;#儲存密碼echo "新增 svn帳號、密碼、repo".PHP_EOL;#函式說明:#在目標層級新增標籤與內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","account");#$conf["tagValue"],字串,目標標籤的內容要放什麼.$conf["xml::addTag"]["tagValue"]=$account;#參考資料:#addchild->http://php.net/manual/en/simplexmlelement.addchild.php$addTag=xml::addTag($conf["xml::addTag"]);unset($conf["xml::addTag"]);#如果讀取新增標籤檔案失敗if($addTag["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$addTag;#回傳結果return $result;}#if end#函式說明:#在目標層級新增標籤與內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","password");#$conf["tagValue"],字串,目標標籤的內容要放什麼.$conf["xml::addTag"]["tagValue"]=$untestPass;#參考資料:#addchild->http://php.net/manual/en/simplexmlelement.addchild.php$addTag=xml::addTag($conf["xml::addTag"]);unset($conf["xml::addTag"]);#如果讀取新增標籤檔案失敗if($addTag["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$addTag;#回傳結果return $result;}#if end#函式說明:#在目標層級新增標籤與內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","repo");#$conf["tagValue"],字串,目標標籤的內容要放什麼.$conf["xml::addTag"]["tagValue"]=$repo;#參考資料:#addchild->http://php.net/manual/en/simplexmlelement.addchild.php$addTag=xml::addTag($conf["xml::addTag"]);unset($conf["xml::addTag"]);#如果讀取新增標籤檔案失敗if($addTag["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$addTag;#回傳結果return $result;}#if end#取得qbpwcf設定檔案的內容#檢查是否有svn的URL上帳號對應的密碼是否存在#函式說明:#取得xml特定標籤的內容#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["warning"],警告訊息陣列.#$result["function"],當前執行的函式名稱.#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.#$result["content"],xml物件的標籤內容.#$result["tag"],修正名稱格式後取得目標標籤內容的階層陣列.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::getTagInfo"]["xmlPosition"]=$defaultSvnAcctXml;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::getTagInfo"]["fileArgu"]=$conf["fileArgu"];#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.$conf["xml::getTagInfo"]["tag"]=array("qbpwcf","cmd","svnci","conf");$getTagInfo=xml::getTagInfo($conf["xml::getTagInfo"]);unset($conf["xml::getTagInfo"]);#如果讀取xml檔案失敗if($getTagInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$getTagInfo;#回傳結果return $result;}#if end#如果標籤不存在if($getTagInfo["tagExist"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$getTagInfo;$result["error"][]="應該存在的tag並不存在";#回傳結果return $result;}#if end#取得正確的 svn 密碼$storedPass=$untestPass;}#else end}#if end}#if end}#for end#初始化要commit的檔案清單$filesToCommit=array();#初始化要加到版本控制的檔案清單$fileAdded=array();#初始化要移除的檔案$fileShouldBeDeleted=array();#初始化紀錄複製的清單$copyList=array();#當檔案未指定時while(true){#提示輸入要commit的檔案echo"請輸入要commit的檔案名稱:".PHP_EOL."若要結束輸入請輸入'quit'".PHP_EOL."若要顯示本機目錄的list請輸入'lls sourcePath'".PHP_EOL."若要顯示svn上的list請輸入'rls targetPath'".PHP_EOL."若要檢視commit清單請輸入'ls'".PHP_EOL."若要取消目標的commit請輸入'unci sourcePath/file'".PHP_EOL."若要看相對於repo的差異請輸入'status'".PHP_EOL."若要看檔案相對於repo的差異請輸入'diff sourcePath/file'".PHP_EOL."若要看檔案相對於repo的特定版本差異請輸入'diff 版本號 sourcePath/file'".PHP_EOL."若要將status為「?」的檔案加到svn版本控制,請輸入'add sourcePath/file'".PHP_EOL."若要檢視本次commit新增到版本控制的檔案目錄清單,請輸入'ls add'".PHP_EOL."若要移除檔案則請輸入'del targetPath/file'".PHP_EOL."若要取消移除檔案則請輸入'undel targetPath/file'".PHP_EOL."若要檢視要移除的檔案清單請輸入'ls del'".PHP_EOL."若要複製路徑請輸入'cp sourcePath/file targetPath/file'".PHP_EOL."若要顯示複製的清單請輸入 'ls cp'".PHP_EOL."若要查詢目錄或檔案的歷史commit記錄,請輸入 'log sourcePath/file'".PHP_EOL."若要復原檔案目錄的變更為svn上的最新版本,請輸入 'revert targetPath/file'".PHP_EOL."若要更新請輸入 'update' ".PHP_EOL;#接收輸入$input=trim(fgets(STDIN));#判斷輸入的內容switch($input){#如果是 "quit"case "quit":#如果沒有要commit的目標if(count($filesToCommit)===0){#提示沒有要commit的目標echo "沒有要commit的目標!".PHP_EOL;#等待使用者輸入要commit的目標continue 2;}#if end#則代表結束輸入break 2;#如果是 "ls"case "ls":#針對每一列foreach($filesToCommit as $lineNo=>$lineContent){#印出要上傳的檔案清單echo "[".$lineNo."] ".$lineContent.PHP_EOL;}#foreach end#繼續輸入要commit的檔案名稱continue 2;#如果是 "lls"case "lls":#運行 ls#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="ls";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-alh");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的 cmdecho "執行的指令:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#印出執行的結果echo "本機當前路徑的檔案目錄清單:".PHP_EOL;#函式說明:#顯示多行文字.#回傳的結果:#$result["status"],執行是否正常,"true"為正常,"false"為不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],語法.#必填參數:#$conf["string"],字串陣列,要放置的內容.$conf["text::multiLine"]["string"]=$callShell["output"];#可省略參數:#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"#$conf["class"]="";#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".#$conf["type"]="EOL";$multiLine=text::multiLine($conf["text::multiLine"]);unset($conf["text::multiLine"]);#如過執行失敗if($multiLine["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$multiLine;#回傳結果return $result;}#if end#印出結果echo $multiLine["content"];#繼續輸入要commit的檔案名稱continue 2;#如果是 rlscase "rls":#運行svn ls#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="echo";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","ls",$sshOption);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#印出執行的結果echo "repo當前路徑的檔案目錄清單:".PHP_EOL;#函式說明:#顯示多行文字.#回傳的結果:#$result["status"],執行是否正常,"true"為正常,"false"為不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],語法.#必填參數:#$conf["string"],字串陣列,要放置的內容.$conf["text::multiLine"]["string"]=$callShell["output"];#可省略參數:#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"#$conf["class"]="";#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".#$conf["type"]="EOL";$multiLine=text::multiLine($conf["text::multiLine"]);unset($conf["text::multiLine"]);#如過執行失敗if($multiLine["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$multiLine;#回傳結果return $result;}#if end#印出結果echo $multiLine["content"];#繼續輸入要commit的檔案名稱continue 2;#如果是 "status"case "status":#取得當前目錄相對於repo的差異#函式說明:#執行svn status指令#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"]["ori"],指令輸出的原始結果陣列.#$result["content"]["status"][$i]["status"],第$i+1個目標的狀態.#$result["content"]["status"][$i]["target"],第$i+1個目標的路徑與名稱.#$result["content"]["status"][$i]["is_dir"],第$i+1個目標是否為目錄,"true"代表是,"false"代表不是.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["cmd::svnsta"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["target"],字串,要檢查status的目標.#$conf["target"]="";$svnsta=cmd::svnsta($conf["cmd::svnsta"]);unset($conf["cmd::svnsta"]);#如果執行失敗if($svnsta["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$svnsta;#回傳結果return $result;}#if end#印出相對於repo的差異#針對每列輸出foreach($svnsta["content"]["ori"] as $line){#印出內容echo $line.PHP_EOL;}#foreach end#繼續輸入要commit的檔案名稱continue 2;#如果是 "update"case "update":#運行 svn update#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="echo";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","update",$sshOption);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#印出執行的結果echo "已經更新到最新版本".PHP_EOL;#函式說明:#顯示多行文字.#回傳的結果:#$result["status"],執行是否正常,"true"為正常,"false"為不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],語法.#必填參數:#$conf["string"],字串陣列,要放置的內容.$conf["text::multiLine"]["string"]=$callShell["output"];#可省略參數:#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"#$conf["class"]="";#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".#$conf["type"]="EOL";$multiLine=text::multiLine($conf["text::multiLine"]);unset($conf["text::multiLine"]);#如過執行失敗if($multiLine["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$multiLine;#回傳結果return $result;}#if end#印出結果echo $multiLine["content"];#繼續輸入要commit的檔案名稱continue 2;#如果是 "ls del"case "ls del":#印出本次commit要移除的目標#函式說明:#將陣列字串處理成一個個"[index] 元素內容"的格式,且[index]的寬度會依造陣列的長度而固定。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],處理好的陣列.#必填參數:#$conf["inputArray"],陣列字串,要轉換陣列.$conf["arrays::toPrintableIndex"]["inputArray"]=$fileShouldBeDeleted;#可省略參數:#$conf["newLine"],字串,組合的內容是否要加換行符號,"true"代表要,"false"代表不要,預設為"ture".#$conf["newLine"]="false";#$conf["print"],字串,是否要直接印出來,"true"代表要,"false"代表不要,預設為"false".$conf["arrays::toPrintableIndex"]["print"]="true";$toPrintableIndex=arrays::toPrintableIndex($conf["arrays::toPrintableIndex"]);unset($conf["arrays::toPrintableIndex"]);#如果處理錯誤if($toPrintableIndex["status"]==="false"){#設置錯誤訊息$result["error"]=$toPrintableIndex;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#繼續讓使用者輸入要commit的檔案continue 2;#如果是 "ls add"case "ls add":#印出本次要新增到版本控制的檔案清單#函式說明:#將陣列字串處理成一個個"[index] 元素內容"的格式,且[index]的寬度會依造陣列的長度而固定。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],處理好的陣列.#必填參數:#$conf["inputArray"],陣列字串,要轉換陣列.$conf["arrays::toPrintableIndex"]["inputArray"]=$fileAdded;#可省略參數:#$conf["newLine"],字串,組合的內容是否要加換行符號,"true"代表要,"false"代表不要,預設為"ture".#$conf["newLine"]="false";#$conf["print"],字串,是否要直接印出來,"true"代表要,"false"代表不要,預設為"false".$conf["arrays::toPrintableIndex"]["print"]="true";$toPrintableIndex=arrays::toPrintableIndex($conf["arrays::toPrintableIndex"]);unset($conf["arrays::toPrintableIndex"]);#如果處理錯誤if($toPrintableIndex["status"]==="false"){#設置錯誤訊息$result["error"]=$toPrintableIndex;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#繼續讓使用者輸入要commit的檔案continue 2;#如果是 "ls cp"case "ls cp":#取得本次要新增到版本控制的複製檔案清單長度$fileCopiedCountLength=strlen(count($copyList));#初始化暫存要印出來的元素陣列$tp=array();#有幾個本次要複製的版本控制的檔案就執行幾次foreach($copyList as $index=>$copiedFN){#如果列數長度加3小於要移除檔案之計數長度while(strlen($index)<$fileCopiedCountLength){#在前面加上空格$index=" ".$index;}#if end#儲存元素內容$tp[]="copy from ".$copiedFN["from"]." to ".$copiedFN["to"];}#foreach end#印出本次要新增到版本控制的複製檔案清單#函式說明:#將陣列字串處理成一個個"[index] 元素內容"的格式,且[index]的寬度會依造陣列的長度而固定。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],處理好的陣列.#必填參數:#$conf["inputArray"],陣列字串,要轉換陣列.$conf["arrays::toPrintableIndex"]["inputArray"]=$tp;#可省略參數:#$conf["newLine"],字串,組合的內容是否要加換行符號,"true"代表要,"false"代表不要,預設為"ture".#$conf["newLine"]="false";#$conf["print"],字串,是否要直接印出來,"true"代表要,"false"代表不要,預設為"false".$conf["arrays::toPrintableIndex"]["print"]="true";$toPrintableIndex=arrays::toPrintableIndex($conf["arrays::toPrintableIndex"]);unset($conf["arrays::toPrintableIndex"]);#如果處理錯誤if($toPrintableIndex["status"]==="false"){#設置錯誤訊息$result["error"]=$toPrintableIndex;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#繼續讓使用者輸入要commit的檔案continue 2;#如果是其他數值default:#不做事}#switch end#函式說明:#將字串進行解析,變成多個參數.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],參數陣列.#$result["count"],總共有幾個參數.#必填參數:#$conf["input"],字串,要解析成參數的字串.$conf["stringProcess::parse"]["input"]=$input;#可省略參數:#無.#參考資料:#無.#備註:#無.$parse=stringProcess::parse($conf["stringProcess::parse"]);unset($conf["stringProcess::parse"]);#var_dump(__FUNCTION__,__LINE__,$parse);#如果處理錯誤if($parse["status"]==="false"){#debug#var_dump(__FUNCITON__,__LINE__,$parse);#如果是 bash 語法錯誤if($parse["error"][0]==="bash syntax error"){#提示錯誤訊息echo $parse["error"][0].PHP_EOL;#提示錯誤訊息echo $parse["error"][1]["content"][0]["error"];#debug#var_dump($parse);#繼續讓使用者輸入要commit的檔案continue;}#if end#設置錯誤訊息$result["error"]=$parse;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#取得參數內容$argv=$parse["content"];#取得參數數目$argc=count($argv);#依照參數的數量switch($argc){#如果參數數量為3case 3:#判斷 $argv[0] 的內容switch($argv[0]){#如果是 cpcase "cp":#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#如果第二個參數代表的複製來源不存在if(!file_exists($clearStrSymbol["content"])){#提示複製的來源檔案並不存在echo "要複製的檔案「".$clearStrSymbol["content"]."」不存在!".PHP_EOL;#讓使用者繼續輸入要commit的項目#continue 2;break 2;}#if end#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[2];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#如果第三個參數代表的複製目的已經存在if(file_exists($clearStrSymbol["content"])){#若不是目錄if(!is_dir($clearStrSymbol["content"])){#提示複製的目的已經存在echo "要複製到的目的檔案「".$argv[2]."」已存在!".PHP_EOL;#讓使用者繼續輸入要commit的項目break 2;}#if end#反之代表目的地是目錄else{#檢查目錄是否在版本控制中#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("status",$argv[2]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#如果不等於空陣列if($callShell["output"]!==array()){#取得檔案的 status 與名稱sscanf($callShell["output"][0],"%s %s",$sta,$fi);#如果狀態等於 ?if($sta==="?"){#提示新增檔案到版本控制失敗echo "目的地目錄「".$argv[2]."」不在版本控制裡面,因此無法複製過去".PHP_EOL;#繼續讓使用者輸入要commit的檔案#continue 2;break;}#if end}#if end#提示複製過去的目標的目的已經存在echo "要複製的「".$argv[1]."」會放到「".$argv[2]."」目錄底下!".PHP_EOL;}#else end}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("status",$argv[1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#如果不等於空陣列if($callShell["output"]!==array()){#取得檔案的 status 與名稱sscanf($callShell["output"][0],"%s %s",$sta,$fi);#如果狀態等於 ?if($sta==="?"){#提示新增檔案到版本控制失敗#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if endecho "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法複製".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end}#if end#如果要複製的來源與目的地有存在於本次commit要新增的項目if(in_array($argv[2],$filesToCommit)){#提示不能複製本次要commit的內容echo "不能複製本次要commit的內容".PHP_EOL;#讓使用者繼續輸入要commit的項目break 2;}#if end#執行 svn cpoy 的指令#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("copy",$argv[1],$argv[2]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#針對每列輸出foreach($callShell["output"] as $line){#印出內容echo $line.PHP_EOL;}#foreach end#設置 $argv[2] 為本次要commit的目錄檔案#紀錄複製的來源與目標$copyList[]=array("from"=>$argv[1],"to"=>$argv[2]);#記錄要commit的新增檔案$filesToCommit[]=$argv[2];#記錄本次要新增的檔案$fileAdded[]=$argv[2];#讓使用者繼續輸入要commit的項目break 2;#如果是 diffcase "diff":#跳出 switchbreak;default:}#switch end#如果參數數量為2case 2:#判斷 $argv[0] 的內容switch($argv[0]){#如果第一個參數為 "diff"case "diff":#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["str"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#如果存在第二個參數的檔案if(file_exists($clearStrSymbol["content"])){#執行command#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("diff",$argv[1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#針對每列輸出foreach($callShell["output"] as $line){#印出內容echo $line.PHP_EOL;}#foreach end#清空outputunset($output);#繼續讓使用者輸入要commit的檔案break 2;}#if end#反之else{#提示錯誤echo "檔案「".$clearStrSymbol["content"]."」不存在".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#else end#跳出switchbreak;#如果第一個參數為 "add"#針對軟連結也ok?case "add":#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]="$argv[1]";#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#若第二個參數的名稱檔案存在if(file_exists($clearStrSymbol["content"])){#若該檔案存在於要新增檔案的清單中if(in_array($argv[1],$fileAdded)){#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示要該檔案已經在移除的清單了echo "檔案「".$clearStrSymbol["content"]."」已經在要新增的清單裡面了".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("add",$argv[1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#針對每列輸出foreach($callShell["output"] as $line){#印出內容echo $line.PHP_EOL;}#foreach end#如果新增檔案到版本控制成功if($callShell["statusCode"]===0){#記錄要commit的新增檔案$filesToCommit[]=$argv[1];#記錄本次要新增的檔案$fileAdded[]=$argv[1];#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果執行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示已經新增echo "已新增檔案「".$clearStrSymbol["content"]."」到版本控制".PHP_EOL;}#if end#反之新增檔案到版本控制失敗else{#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果執行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示新增檔案到版本控制失敗echo "新增檔案「".$clearStrSymbol["content"]."」到版本控制失敗".PHP_EOL;}#else end#繼續讓使用者輸入要commit的檔案break 2;}#if end#跳出switchbreak;#如果第一個參數為 "del"case "del":#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["str"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果執行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#函式說明:#檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($clearStrSymbol["content"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;#可省略參數:#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".#$conf["userDir"]="true";#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".$conf["fileAccess::checkMultiFileExist"]["web"]="false";#參考資料:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑#$result["varName"][$i]結果未實作$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果執行失敗if($checkMultiFileExist["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果檔案不存在if($checkMultiFileExist["allExist"]==="false"){#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示新增檔案到版本控制失敗echo "檔案「".$clearStrSymbol["content"]."」不存在".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#若第二個參數的名稱檔案存在else{#如果要移除的檔案是本次要新增的版本控制的檔案if(in_array($argv[1],$fileAdded)){#提示要新增到版本控制的檔案不能在本次commit移除echo "檔案「".$clearStrSymbol["content"]."」不能在本次commit移除".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#如果該檔案已經是要移除的了if(in_array($argv[1],$fileShouldBeDeleted)){#提示要該檔案已經在移除的清單了echo "檔案「".$clearStrSymbol["content"]."」已經在移除的清單裡面了".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#檢查要移除的檔案是否在版本控制中#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("status",$argv[1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#debug#var_dump(__LINE__,$callShell["output"]);#如果不等於空陣列if($callShell["output"]!==array()){#取得檔案的 status 與名稱sscanf($callShell["output"][0],"%s %s",$sta,$fi);#如果狀態等於 ?if($sta==="?"){#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示新增檔案到版本控制失敗echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法移除之".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end}#if end#取得要移除的檔案$fileShouldBeDeleted[]=$argv[1];#記錄要commit的檔案$filesToCommit[]=$argv[1];#繼續讓使用者輸入要commit的檔案#continue 2;break 2;}#if end#繼續讓使用者輸入要commit的檔案break 2;#如果第一個參數是 "undel"case "undel":#如果該檔案是在要移除的清單裡面if(in_array($argv[1],$fileShouldBeDeleted)){#依據每個要commit的目標foreach($filesToCommit as $index=>$target){#如果是 $argv[1]if($target===$argv[1]){#移除之unset($filesToCommit[$index]);}#if end}#foreach#依據每個要移除的目標foreach($fileShouldBeDeleted as $index=>$target){#如果是 $argv[1]if($target===$argv[1]){#移除之unset($fileShouldBeDeleted[$index]);}#if end}#foreach#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示目已經取消移除echo "檔案「".$clearStrSymbol["content"]."」已不在要移除的清單裡面了".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示目標沒有在要移除的清單裡面echo "檔案「".$clearStrSymbol["content"]."」不在要移除的清單裡面".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;#如果第一個參數是 "unci"case "unci":#如果該檔案是在要commit的清單裡面if(in_array($argv[1],$filesToCommit)){#依據每個要commit的目標foreach($filesToCommit as $index=>$target){#如果是 $argv[1]if($target===$argv[1]){#移除之unset($filesToCommit[$index]);}#if end}#foreach#依據每個要移除的目標foreach($fileShouldBeDeleted as $index=>$target){#如果是 $argv[1]if($target===$argv[1]){#移除之unset($fileShouldBeDeleted[$index]);}#if end}#foreach#依據每個要新增的目標foreach($fileAdded as $index=>$target){#如果是 $argv[1]if($target===$argv[1]){#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("revert","--depth","infinity",$argv[1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#移除之unset($fileAdded[$index]);}#if end}#foreach#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示目已經取消移除echo "檔案「".$clearStrSymbol["content"]."」已不在要commit的清單裡面了".PHP_EOL;}#if end#反之else{#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示目標沒有在要移除的清單裡面echo "檔案「".$clearStrSymbol["content"]."」不在要commit的清單裡面".PHP_EOL;}#else end#繼續讓使用者輸入要commit的檔案#continue 2;break 2;#如果第一個參數為 "log"case "log":#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#如果檔案不存在if(!file_exists($clearStrSymbol["content"])){#提示檔案不存在echo "要查詢commmit記錄的檔案「".$clearStrSymbol["content"]."」並不存在".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#檢查要查commit記錄的檔案是否在版本控制中#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("status",$argv[1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#如果不等於空陣列if($callShell["output"]!==array()){#取得檔案的 status 與名稱sscanf($callShell["output"][0],"%s %s",$sta,$fi);#如果狀態等於 ?if($sta==="?"){#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示新增檔案到版本控制失敗echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法查詢commit記錄".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end}#if end#運行svn status#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="echo";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","log",$argv[1],$sshOption);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#初始化儲存版號的陣列$rversion=array();#初始化儲存版本註解的陣列$vlog=array();#依照每列輸出foreach($callShell["output"] as $index=>$line){#如果不是第一列if($index>0){#初始化註解的列數$logLines=0;#如果前一列是 "------------------------------------------------------------------------" 且 當前列第一個字為"r" 且 當前列含有3個 "|" 且下一列為 ""if($callShell["output"][$index-1]==="------------------------------------------------------------------------" && strpos($line,"r")===0 && substr_count($line,"|")===3 && $callShell["output"][$index+1]==="" ){#截取該行的版本號$spiltedLine=explode(" ",$line);#取得該行的版本號$version=substr($spiltedLine[0],1);#儲存版號$rversion[]=$version;#取得註解的行數$logLines=$spiltedLine[count($spiltedLine)-2];}#if end#如果有註解列數for($i=0;$i<$logLines;$i++){#取得註解列的ley$key=$index+1+($i+1);#取得該版本的該列註解$vlog[$rversion[count($rversion)-1]][]=$callShell["output"][$key];}#for end}#if end#印出內容echo $line.PHP_EOL;}#foreach end#提示版號清單echo "版號清單:".PHP_EOL;#有幾個版號就執行幾次foreach($rversion as $version){#提示版號echo "版號: ".$version." 的註解".PHP_EOL;#該版號有幾列註解就執行幾次foreach($vlog[$version] as $vlLine){#印出該版commit時的註解echo $vlLine.PHP_EOL;}#foreach end}#foeach end#換行echo PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;#如果第一個參數為 "revert"case "revert":#檢查要還原的檔案是否在版本控制之中#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("status",$argv[1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#如果不等於空陣列if($callShell["output"]!==array()){#取得檔案的 status 與名稱sscanf($callShell["output"][0],"%s %s",$sta,$fi);#如果狀態等於 ?if($sta==="?"){#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示不在版本控制裡面echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法還原".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#如果狀態等於 ""else if($sta===""){#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示新增檔案到版本控制失敗echo "檔案「".$clearStrSymbol["content"]."」跟當前svn版本無差異".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#反之等於其他狀態,則代表可以 revertelse{#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("revert","--depth","infinity",$argv[1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#如果運行正常if($callShell["statusCode"]===0){#如果該檔案是被rm指令刪除的if($sta==="!"){#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示已經還原變更了echo "已還原被移除的「".$clearStrSymbol["content"]."」".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#如果該檔案是要新增版本控制else if($sta==="A"){#如果 $argv[1] 在本次的 commit 清單裡面if(in_array($argv[1],$filesToCommit)){#依據每個要commit的目標foreach($filesToCommit as $index=>$target){#如果是 $argv[1]if($target===$argv[1]){#移除之unset($filesToCommit[$index]);}#if end}#foreach#依據每個要新增到版本控制的目標foreach($fileAdded as $index=>$target){#如果是 $argv[1]if($target===$argv[1]){#移除之unset($fileAdded[$index]);}#if end}#foreach}#if end#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示已經還原變更了echo "已取消新增「".$clearStrSymbol["content"]."」到版本控制".PHP_EOL;#初始化儲存暫存的複製清單$tempCpList=array();#針對每個複製的清單foreach($copyList as $index=>$info){#如果還原的目標不是被複製出來的if($info["to"]!==$argv[1]){#儲存複製資訊$tempCpList[]=$info;}#if end}#foreach end#更新複製清單$copyList=$tempCpList;#繼續讓使用者輸入要commit的檔案#continue 2;break 2;}#if end#如果該檔案原本是被移除版本控制else if($sta==="D"){#如果 $argv[1] 在本次的 commit 清單裡面if(in_array($argv[1],$filesToCommit)){#依據每個要commit的目標foreach($filesToCommit as $index=>$target){#如果是 $argv[1]if($target===$argv[1]){#移除之unset($filesToCommit[$index]);}#if end}#foreach#依據每個要移除的目標foreach($fileShouldBeDeleted as $index=>$target){#如果是 $argv[1]if($target===$argv[1]){#移除之unset($fileShouldBeDeleted[$index]);}#if end}#foreach}#if end#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示已經還原變更了echo "已還原被移除版本控制的「".$clearStrSymbol["content"]."」".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#如果該檔案是被修改過內容的else if($sta==="M"){#如果 $argv[1] 在本次的 commit 清單裡面if(in_array($argv[1],$filesToCommit)){#依據每個要commit的目標foreach($filesToCommit as $index=>$target){#如果是 $argv[1]if($target===$argv[1]){#移除之unset($filesToCommit[$index]);}#if end}#foreach}#if end#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示已經還原變更了echo "已還原「".$clearStrSymbol["content"]."」的修改".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end}#if end}#else end}#if end#反之else{#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示已經還原變更了echo "目標「".$clearStrSymbol."」跟svn上的版本並無不同,或並不存在".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#else end#跳出switchbreak;#如果是 "lls"case "lls":#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果運行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#如果檔案不存在if(!file_exists($clearStrSymbol["content"])){#提示檔案不存在echo "要檢視的本機目錄檔案「".$clearStrSymbol["content"]."」並不存在".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end#運行 ls#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="ls";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-alh",$argv[1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.#$conf["escapeshellarg"]="false";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的 cmdecho "執行的指令:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#印出執行的結果echo "本機路徑 ".$argv[1]." 底下的檔案目錄清單:".PHP_EOL;#函式說明:#顯示多行文字.#回傳的結果:#$result["status"],執行是否正常,"true"為正常,"false"為不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],語法.#必填參數:#$conf["string"],字串陣列,要放置的內容.$conf["text::multiLine"]["string"]=$callShell["output"];#可省略參數:#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"#$conf["class"]="";#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".#$conf["type"]="EOL";$multiLine=text::multiLine($conf["text::multiLine"]);unset($conf["text::multiLine"]);#如過執行失敗if($multiLine["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$multiLine;#回傳結果return $result;}#if end#印出結果echo $multiLine["content"];#繼續讓使用者輸入要commit的檔案break 2;#如果是 "rls"case "rls":#運行 svn ls#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="echo";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","ls",$argv[1],$sshOption);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的 cmdecho "執行的指令:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#印出執行的結果echo "repo路徑 ".$argv[1]." 底下的檔案目錄清單:".PHP_EOL;#函式說明:#顯示多行文字.#回傳的結果:#$result["status"],執行是否正常,"true"為正常,"false"為不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],語法.#必填參數:#$conf["string"],字串陣列,要放置的內容.$conf["text::multiLine"]["string"]=$callShell["output"];#可省略參數:#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"#$conf["class"]="";#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".#$conf["type"]="EOL";$multiLine=text::multiLine($conf["text::multiLine"]);unset($conf["text::multiLine"]);#如過執行失敗if($multiLine["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤$result["error"]=$multiLine;#回傳結果return $result;}#if end#印出結果echo $multiLine["content"];#繼續讓使用者輸入要commit的檔案#continue 2;break 2;#其他內容default:#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如過執行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示命令 $argv[1] 不存在echo "命令 「".$clearStrSymbol["content"]."」 不存在".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#switch end#提示不正常echo "Oops somethine go wrong. Input is ".print_r($argv,true).PHP_EOL;#繼續輸入要commit的檔案名稱break;#如果參數數量為1case 1:#剔除開頭與結尾的「'」或「""」#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果執行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示檢查檔案是否存在echo "檢查檔案 ".$clearStrSymbol["content"]." 是否存在".PHP_EOL;#函式說明:#檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($clearStrSymbol["content"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;#可省略參數:#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".#$conf["fileAccess::checkMultiFileExist"]["userDir"]="true";#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".$conf["fileAccess::checkMultiFileExist"]["web"]="false";#參考資料:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑#$result["varName"][$i]結果未實作$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果執行失敗if($checkMultiFileExist["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果檔案不存在if($checkMultiFileExist["allExist"]==="false"){#提示檔案不存在echo "檔案".$clearStrSymbol["content"]."不存在".PHP_EOL;#繼續輸入要commit的檔案名稱break;}#if end#檢查檔案 $input 是否處於版本控制中#函式說明:#執行svn status指令#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"]["ori"],指令輸出的原始結果陣列.#$result["content"]["status"][$i]["status"],第$i+1個目標的狀態.#$result["content"]["status"][$i]["target"],第$i+1個目標的路徑與名稱.#$result["content"]["status"][$i]["is_dir"],第$i+1個目標是否為目錄,"true"代表是,"false"代表不是.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["cmd::svnsta"]["fileArgu"]=__FILE__;#可省略參數:#$conf["target"],字串,要檢查status的目標.$conf["cmd::svnsta"]["target"]=$input;#參考資料:#無.#備註:#無.$svnsta=cmd::svnsta($conf["cmd::svnsta"]);unset($conf["cmd::svnsta"]);#如果執行失敗if($svnsta["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$svnsta;#回傳結果return $result;}#if end#var_dump(__LINE__,$svnsta);#如果沒有版本控制記錄if($svnsta["content"]["status"][0]["status"]==="?"){#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("add",$argv[0]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#針對每列輸出foreach($callShell["output"] as $line){#印出內容echo $line.PHP_EOL;}#foreach end#清空outputunset($output);#如果新增檔案到版本控制成功if($callShell["statusCode"]===0){#記錄要commit的新增檔案$filesToCommit[]=$argv[0];#記錄本次要新增的檔案$fileAdded[]=$argv[0];#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果執行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示已經新增echo "已新增檔案「".$clearStrSymbol["content"]."」到版本控制".PHP_EOL;#繼續讓使用者輸入要commit的檔案break;}#if end#反之else{#提示新增檔案到版本控制失敗echo "新增檔案「".$argv[0]."」到版本控制失敗(".$callShell["statusCode"].")".PHP_EOL;#繼續讓使用者輸入要commit的檔案break;}#else end}#if end#反之有異動過else if( $svnsta["content"]["status"][0]["status"]==="M" || $svnsta["content"]["status"][0]["status"]==="A" ){#如果有在commit清單裡面了if(in_array($argv[0],$filesToCommit)){#提示新增檔案到版本控制失敗echo "檔案「".$argv[0]."」的異動已記錄(".$callShell["statusCode"].")".PHP_EOL;#繼續讓使用者輸入要commit的檔案break;}#if end#記錄要commit的新增檔案$filesToCommit[]=$argv[0];#記錄本次要新增的檔案$fileAdded[]=$argv[0];#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果執行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#提示已經新增echo "已將檔案「".$clearStrSymbol["content"]."」的異動加到版本控制".PHP_EOL;#繼續讓使用者輸入要commit的檔案break;}#if end#反之else{#提示node無異動,所以無法加入為commit的清單echo "檔案「".$argv[0]."」無異動".PHP_EOL;#繼續讓使用者輸入要commit的檔案break;}#else end#繼續輸入要commit的檔案名稱break;#如果參數數量為0case 0:#繼續輸入要commit的檔案名稱break;#其他結果default:#判斷第一個參數switch($argv[0]){#如果是 "cp"case "cp":#檢查要複製到的目標#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$argv[$argc-1];#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果執行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#如果最後一個參數代表的複製目的已經存在if(file_exists($clearStrSymbol["content"])){#不是目錄if(!is_dir($clearStrSymbol["content"])){#提示複製的目的已經存在echo "要複製到的目的檔案「".$argv[$argc-1]."」已存在!".PHP_EOL;#讓使用者繼續輸入要commit的項目break 2;}#if end#反之代表目的地是目錄else{#檢查目錄是否在版本控制中#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("status",$argv[$argc-1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#如果不等於空陣列if($callShell["output"]!==array()){#取得檔案的 status 與名稱sscanf($callShell["output"][0],"%s %s",$sta,$fi);#如果狀態等於 ?if($sta==="?"){#提示新增檔案到版本控制失敗echo "目的地目錄「".$argv[$argc-1]."」不在版本控制裡面,因此無法複製過去".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 2;}#if end}#if end#提示複製過去的目標的目的已經存在echo "要複製的清單會放到「".$argv[$argc-1]."」目錄底下!".PHP_EOL;}#else end}#if end#扣掉頭尾剩下幾個參數就執行幾次for($i=1;$i<$argc-1;$i++){#要複製的目標路徑與名稱$source=$argv[$i];#要複製的目標名稱$sourceFileName=$source;#debugecho "Trying copy 「".$sourceFileName."」 to 「".$argv[$argc-1]."」".PHP_EOL;#如果複製來源含有 '/'while($slashPos=strpos($sourceFileName,'/')){#取得 '/' 後面的內容$sourceFileName=substr($sourceFileName,$slashPos);}#while end#複製過去的新位置與名稱$target=$argv[$argc-1].$sourceFileName;#要檢查複製過去的目標是否已經存在if(file_exists($target)){echo "要複製到的目標「".$target."」已經存在,略過".PHP_EOL;#跳過已經存在的目標continue;}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("status",$argv[$i]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#如果不等於空陣列if($callShell["output"]!==array()){#取得檔案的 status 與名稱sscanf($callShell["output"][0],"%s %s",$sta,$fi);#如果狀態等於 ?if($sta==="?"){#提示新增檔案到版本控制失敗#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.$conf["stringProcess::clearStrSymbol"]["str"]=$source;#可省略參數:#無.#參考資料:#無.#備註:#無.$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果執行失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if endecho "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法複製".PHP_EOL;#繼續讓使用者輸入要commit的檔案break 3;}#if end}#if end#如果要複製的來源與目的地有存在於本次commit要新增的項目if(in_array($source,$filesToCommit) && in_array($target,$filesToCommit)){#提示不能複製本次要commit的內容echo "不能複製本次要commit的內容".PHP_EOL;#檢查下一個要複製的項目continue;}#if end#運行 svn cpoy 的指令#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("copy",$source,$argv[$argc-1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#針對每列輸出foreach($callShell["output"] as $line){#印出內容echo $line.PHP_EOL;}#foreach end#紀錄複製的來源與目標$copyList[]=array("from"=>$source,"to"=>$target);#記錄要commit的新增檔案$filesToCommit[]=$target;#記錄本次要新增的檔案$fileAdded[]=$target;}#for end#讓使用者繼續輸入要commit的項目break 2;}#switch end#提示參數數量不對echo "參數數量(".$argc.")不對".PHP_EOL;#提示輸入的參數foreach($argv as $no=>$p){#印出參數echo "參數".$no.":".$p.PHP_EOL;}#foreach end#繼續輸入要commit的檔案名稱break;}#switch end}#while end#提示輸入註解$commentNoteText="請輸入註解:".PHP_EOL."若要結束輸入請輸入'quit'".PHP_EOL."若要顯示所有註解的內容請輸入'show log'".PHP_EOL."跳到下一列請輸入'+line'".PHP_EOL."跳到上一列請輸入'-line'".PHP_EOL."跳到檔案開頭請輸入'head'".PHP_EOL."跳到檔案結尾請輸入'tail'".PHP_EOL."跳到指定的列請輸入'to 列號'".PHP_EOL."若要移除指定列的註解請輸入'del 列號'".PHP_EOL."若要檢視commit清單請輸入'ls'".PHP_EOL."若要看檔案相對於repo的差異請輸入 'diff fileName'".PHP_EOL."若要檢視本次commit新增到版本控制的檔案目錄清單,請輸入'ls add'".PHP_EOL."若要檢視要移除的檔案清單請輸入'ls del'".PHP_EOL."若要顯示複製的清單請輸入 'ls cp'".PHP_EOL;#初始化註解的列陣列$comment=array($conf["author"].PHP_EOL);#初始化目前指到註解那邊的pointer$pointer=1;#無窮迴圈while(true){#印出提示echo $commentNoteText;#接收使用者的輸入$input=trim(fgets(STDIN));#判斷輸入switch($input){#如果輸入為 "quit"case "quit":#跳出 whilebreak 2;#如果輸入為 "-line"case "-line":#如果不存在上一列if(!isset($comment[$pointer-1])){#提示已經是第一列了echo "已經是檔案開頭了".PHP_EOL;}#if end#反之else{#指標減1$pointer--;#印出這一列的內容echo "這一列的內容為:".$comment[$pointer].PHP_EOL;}#else end#等待下個commit的註解break;#如果輸入為 "+line"case "+line":#如果不存在下一列if(!isset($comment[$pointer+1])){#提示已經是最後一列了echo "已經是最後一列了".PHP_EOL;}#if end#反之else{#指標加1$pointer++;#印出這一列的內容echo "這一列的內容為:".$comment[$pointer].PHP_EOL;}#else ened#等待下個commit的註解break;#如果是 "head"case "head":#設置pointer到開頭$pointer=0;#如果存在第一列if(isset($comment[$pointer])){#印出第一列的內容echo "第一列的內容為:".$comment[$pointer].PHP_EOL;}#if end#等待下個commit的註解break;#如果是 "tail"case "tail":#設置pointer到最尾端$pointer=count($comment);#如果存在最後一列if(isset($comment[$pointer-1])){#印出最後一列的內容echo "最後一列的內容為:".$comment[$pointer-1].PHP_EOL;}#if end#等待下個commit的註解break;#如果是 "show log"case "show log":#取得列數$lineCount=$pointer+1;#取得列數長度$numberLenth=strlen((string)$lineCount);#初始化識別是否已經顯示pointer$showPointer=false;#有幾列就執行幾次foreach($comment as $lineNum=>$lineContent){#如果該列號長度小於列數長度while(strlen($lineNum)<$numberLenth){#在前面加上空白$lineNum=" ".$lineNum;}#while end#列號$lineNo="[".$lineNum."] ";#如果是當前列if(intval($lineNum)===intval($pointer)){#顯示目前正在複寫該列內容$lineNo=">> ".$lineNo;#設置已經顯示poniter$showPointer=true;}#if end#印出列號與列內容echo $lineNo.$lineContent;}#foreach end#如果尚未顯示pointerif(!$showPointer){#列號等於$pointer$lineNo=$pointer;#如果該列號長度小於列數長度while(strlen($lineNo)<$numberLenth){#在前面加上空白$lineNo=" ".$lineNo;}#while end#列號$lineNo="[".$lineNo."] ";#印出當前列echo ">> ".$lineNo.PHP_EOL;}#if end#等待下個commit的註解break;#如果是 "ls"case "ls":#針對每一列foreach($filesToCommit as $lineNo=>$lineContent){#印出要上傳的檔案清單echo "[".$lineNo."] ".$lineContent.PHP_EOL;}#foreach end#等待下個commit的註解break;#如果是 "ls del"case "ls del":#取得要移除檔案之計數長度$fileShouldBeDeletedCountLength=strlen(count($fileShouldBeDeleted));#針對每個要移除的檔案foreach($fileShouldBeDeleted as $index=>$delFile){#如果列數長度加3小於要移除檔案之計數長度while(strlen($index)+3<$fileShouldBeDeletedCountLength){#在前面加上空格$index=" ".$index;}#if end#印出內容echo "[".$index."] ".$delFile.PHP_EOL;}#foreach end#如果是 "ls add"case "ls add":#取得本次要新增到版本控制的檔案清單長度$fileAddedCountLength=strlen(count($fileAdded));#有幾個本次要新增的版本控制的檔案就執行幾次foreach($fileAdded as $index=>$addedFN){#如果列數長度加3小於要移除檔案之計數長度while(strlen($index)+3<$fileAddedCountLength){#在前面加上空格$index=" ".$index;}#if end#印出內容echo "[".$index."] ".$addedFN.PHP_EOL;}#foreach end#等待下個commit的註解break;#如果是 "ls cp"case "ls cp":#取得本次要新增到版本控制的複製檔案清單長度$fileCopiedCountLength=strlen(count($copyList));#有幾個本次要複製的版本控制的檔案就執行幾次foreach($copyList as $index=>$copiedFN){#如果列數長度加3小於要移除檔案之計數長度while(strlen($index)+3<$fileCopiedCountLength){#在前面加上空格$index=" ".$index;}#if end#印出內容echo "[".$index."] copy from ".$copiedFN["from"]." to ".$copiedFN["to"].PHP_EOL;}#foreach end#等待下個commit的註解break;#視為註解default:#如果存在 $fileNameif(isset($fileName)){#移除之unset($fileName);}#if end#函式說明:#將字串進行解析,變成多個參數.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],參數陣列.#$result["count"],總共有幾個參數.#必填參數:#$conf["input"],字串,要解析成參數的字串.$conf["stringProcess::parse"]["input"]=$input;#建議:#改用cmd::getArgu構成的command去parse字串$parse=stringProcess::parse($conf["stringProcess::parse"]);unset($conf["stringProcess::parse"]);#如果處理錯誤if($parse["status"]==="false"){#如果是 bash 語法錯誤if($parse["error"][0]==="bash syntax error"){#提示錯誤訊息echo $parse["error"][0].PHP_EOL;#提示錯誤訊息echo $parse["error"][1]["content"][0]["error"];#debug#var_dump($parse);#等待下個commit的註解break;}#if end#設置錯誤訊息$result["error"]=$parse;#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#取得參數數量$argc=$parse["count"];#取得參數陣列$param=$parse["content"];#依照參數的數量switch($argc){#兩個參數case "2":#如果第一個字串為 "diff" ,第二個字串代表要比較的目標檔案.if($param[0]==="diff"){#更新目標檔案名稱#函式說明:#清除字串的「"」或「'」符號.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],剔除「"」或「'」符號後的字串.#必填參數:#$conf["str"],字串,要處理的字串.#$conf["str"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.$conf["stringProcess::clearStrSymbol"]["str"]=$param[1];$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);unset($conf["stringProcess::clearStrSymbol"]);#如果parse字串失敗if($clearStrSymbol["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$clearStrSymbol;#回傳結果return $result;}#if end#如果目標檔案存在if(file_exists($clearStrSymbol["content"])){#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("diff",$param[1]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;#針對每列輸出foreach($callShell["output"] as $line){#印出內容echo $line.PHP_EOL;}#foreach end}#if end#反之代表目標檔案不存在else{#題書目標檔案不存在echo "目標檔案「".$clearStrSymbol["content"]."」不存在!".PHP_EOL;}#else end#繼續讓使用者輸入註解continue 3;}#if end#如果第一個字串為 "to" ,第二個字串代表要去的列(整數)else if($param[0]==="to" && is_int(intval($param[1]))){#如果目標列存在if(isset($comment[$param[1]])){#設置pointer$pointer=$param[1];#提示目標列的內容echo "這一列的內容為:".$comment[$pointer].PHP_EOL;#繼續讓使用者輸入註解continue 3;}#if end#反之else{#提示目標列不存在echo "目標列(".$param[1].")不存在".PHP_EOL;#繼續讓使用者輸入註解continue 3;}#else end}#if end#如果第一個字串為 "del" ,第二個字串代表要去的列(整數)else if($param[0]==="del" && is_int(intval($param[1]))){#debugecho "移除註解列".PHP_EOL;#如果目標列存在if(isset($comment[$param[1]])){#提示目標列的內容echo "移除列「".$param[1]."」的內容「".trim($comment[$param[1]])."」".PHP_EOL;#移除目標列unset($comment[$param[1]]);#如果被移除的列號大於1if($param[1]>0){#設置pointer為被移除列減1$pointer=$param[1]-1;}#if end#暫存排序好的註解陣列$tempCA=array();#依據每列註解foreach($comment as $lineVal){#取得註解列的內容$tempCA[]=$lineVal;}#foreach end#取得重新排序好的註解陣列$comment=$tempCA;#提示目標列的內容echo "這一列的內容為:".$comment[$pointer].PHP_EOL;#繼續讓使用者輸入註解continue 3;}#if end#反之else{#提示目標列不存在echo "目標列(".$param[1].")不存在".PHP_EOL;#繼續讓使用者輸入註解continue 3;}#else end}#if end#跳出switchbreak;#0個參數case "0":#繼續讓使用者輸入註解continue 3;#其他參數數量default:#寫入換行跟輸入的內容$comment[$pointer]=escapeshellarg($input).PHP_EOL;#指標+1$pointer++;#印出上一列的內容echo "上一列的內容為:".$comment[$pointer-1].PHP_EOL;#繼續讓使用者輸入註解continue 3;}#switch end#寫入換行跟輸入的內容$comment[$pointer]=escapeshellarg($input).PHP_EOL;#指標+1$pointer++;#印出上一列的內容echo "上一列的內容為:".$comment[$pointer-1].PHP_EOL;#繼續讓使用者輸入註解continue 2;}#switch end}#while end#如果有要移除的檔案if(count($fileShouldBeDeleted)>0){#針對每個要移除的檔案foreach($fileShouldBeDeleted as $delFile){#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="svn";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("--force","del",$delFile);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#印出執行的cmdecho "cmd:".$callShell["cmd"].PHP_EOL;#印出執行後的回傳代碼echo "status:".$callShell["statusCode"].PHP_EOL;}#foreach end}#if end#函式說明:#建立暫存目錄與回傳暫存檔案名稱路徑#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["content"],暫存檔案的路徑與名稱.#必填參數:#無.#可省略參數:#無.#參考資料:#無.#備註:#無.$createTempFile=fileAccess::createTempFile();#如果執行失敗if($createTempFile["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$createTempFile;#回傳結果return $result;}#if end#指定 commit log file$commitLogFile=$createTempFile["content"];#函式說明:#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的function名稱#$result["error"],錯誤訊息陣列.#$result["content"],處理好的字串.#$result["argu"],使用的參數.#必填參數:#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.$conf["arrays::arrayToString"]["inputArray"]=$comment;#可省略參數:#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;$conf["arrays::arrayToString"]["spiltSymbol"]=PHP_EOL;#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。$conf["arrays::arrayToString"]["skipEnd"]="true";#參考資料:#無.#備註:#無.$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);unset($conf["arrays::arrayToString"]);#如果執行失敗if($arrayToString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$arrayToString;#回傳結果return $result;}#if end#取得註解字串$commentStr=$arrayToString["content"];#函式說明:#將字串寫入到檔案#回傳結果:#$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["fileAcceess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.$conf["fileAcceess::writeTextIntoFile"]["fileName"]=$commitLogFile;#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".$conf["fileAcceess::writeTextIntoFile"]["inputString"]=$commentStr;#$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"]="";#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".$conf["fileAcceess::writeTextIntoFile"]["web"]="false";#參考資料:#無.#備註:#無.$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAcceess::writeTextIntoFile"]);unset($conf["fileAcceess::writeTextIntoFile"]);#如果執行失敗if($writeTextIntoFile["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行失敗訊息$result["error"]=$writeTextIntoFile;#回傳結果return $result;}#if end#函式說明:#將多個一維陣列串聯起來,key從0開始排序.#回傳的結果:#$result["status"],"true"表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式.#$result["content"],合併好的一維陣列.#必填參數:#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);$conf["arrays::mergeArray"]["inputArray"]=array(array($storedPass,"|","sshpass","-v","svn","commit","-F",$commitLogFile),$filesToCommit,array($sshOption));#可省略參數:#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.#$conf["allowRepeat"]="true";$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);unset($conf["arrays::mergeArray"]);#如果建立新陣列失敗if($mergeArray["status"]==="false"){#設置執行錯誤$result["error"]=$mergeArray;#設置執行不正常$result["status"]="false";#回傳結果return $result;}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="echo";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$mergeArray["content"];#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#紀錄 commit 的指令$result["content"]["cmd"]=$callShell["cmd"];#紀錄 commit 的註解$result["content"]["commit"]=$commentStr;#移除commit用的註解檔案#函式說明:#移除檔案#回傳結果:#$result["status"],"true"代表移除成功,"false"代表移除失敗.#$result["error"],錯誤訊息陣列#$result["warning"],警告訊息陣列#$result["function"],當前執行的函數名稱#必填參數:#$conf["fileAddress"],字串,要移除檔案的位置.$conf["fileAccess::delFile"]["fileAddress"]=$commitLogFile;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.#$conf["commentsArray"]=array("");#參考資料:#無.#備註:#無.$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);unset($conf["fileAccess::delFile"]);#如果移除暫存檔案失敗if($delFile["status"]==="false"){#設置執行錯誤$result["error"]=$delFile;#設置執行不正常$result["status"]="false";#回傳結果return $result;}#if end#紀錄 commit 的結果$result["content"]["content"]=$callShell["output"];#如果svn指令的輸出為空if($result["content"]["content"]===array()){#給予可能是被svn server拒絕的提示$result["content"]["content"][]="未commit,請檢查要commit的檔案是否與repo上的檔案沒有差異。";}#if end#記錄 commit 執行後的回傳代碼$result["content"]["status"]=$callShell["statusCode"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function svnci end/*#函式說明:#顯示網路連線的資訊.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],實際執行的指令.#$result["content"],執行完ip link show得到的終端輸出.#$result["content"][$i],第$i+1個網路設備資訊陣列#$result["content"][$i]["devName"],第$i+1個網路設備的名稱.#$result["content"][$i]["deviceFlags"][$flag],第$i+1個網路設備擁有$flag屬性.#$result["content"][$i]["mac"],第$i+1個網路設備的mac.#$result["content"][$i]["brd"],第$i+1個網路設備的廣播位置.#$result["content"][$i]["deviceAttr"]["mtu"],$i+1個網路設備的mtu(Maximum Transmission Unit;最大傳輸單元)屬性數值.#$result["content"][$i]["deviceAttr"]["qdisc"],$i+1個網路設備的qdisc(queueing disciplines;佇列規則)屬性數值.#$result["content"][$i]["deviceAttr"]["state"],$i+1個網路設備的state(UP:啟用;DOWN:停用)屬性數值.#$result["content"][$i]["deviceAttr"]["mode"],$i+1個網路設備的mode屬性數值.#$result["content"][$i]["deviceAttr"]["group"],$i+1個網路設備的group屬性數值.#$result["content"][$i]["deviceAttr"]["qlen"],$i+1個網路設備的qlen(The length of the transmission queue)屬性數值.#$result["content"][$i]["deviceAttr"]["master"],$i+1個網路設備的master(歸屬於哪個網路設備)屬性數值.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["linkName"],字串,要檢視的連線名稱,若省略則會顯示所有的網路設備資訊#$conf["linkName"]="";#參考資料:#LOWER_UP=>http://www.linuxforums.org/forum/networking/155196-what-does-lower_up-state-mean.html#備註:#需要ip link show指令能夠運作.*/public static function ipLinkShow(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("linkName");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#執行 ip link show 指令#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="ip";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("link","show",$conf["linkName"]);#$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["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["external::callShell"]["username"]="root";#$conf["password"],字串,root使用者的密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["external::callShell"]["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果運行 ip link show 指令失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#如果輸出的列數不為偶數if(count($callShell["output"])%2!==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="輸出列數不正常";#回傳結果return $result;}#if end#初始化用來判斷奇偶數的變數$odd_even=0;#初始化用來計數第幾個網路設備的索引$index=0;#初始化用來暫存網路設備的資訊$info=array();#解析回傳的內容foreach($callShell["output"] as $lineNo => $lineContent){#取得是否為奇偶數$odd_even=($odd_even+1)%2;#如果是奇數列if($odd_even===1){#1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000#用 ": " 分割#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$lineContent;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=": ";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果分割字串的關鍵字不存在if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果分割出來小於兩段if($spiltString["dataCounts"]<2){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得網路設備索引$index=$spiltString["dataArray"][0]-1;#取得網路設備名稱$devName=$spiltString["dataArray"][1];#記錄網路設備名稱$info["devName"]=$devName;#初始化剩下的字串$unParseStr="";#將剩下的傳接起來for($i=2;$i<$spiltString["dataCounts"];$i++){#串接字串$unParseStr=$unParseStr.$spiltString["dataArray"][$i];}#for end#<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000#用 " " 分割#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$unParseStr;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果分割字串的關鍵字不存在if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果分割出來小於1段if($spiltString["dataCounts"]<1){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#<LOOPBACK,UP,LOWER_UP>#剔除開頭的"<"跟結尾的">"#函式說明:#處理字串避免網頁出錯#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式.#$result["content"],爲處理好的字串.#$result["error"],錯誤訊息陣列.#必填參數:$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][0];#爲要處理的字串#可省略參數:$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("<",">");#爲被選擇要處理的字串/字元,須爲陣列值。#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);unset($conf["stringProcess::correctCharacter"]);#如果過濾 "<" ">" 失敗if($correctCharacter["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$correctCharacter;#回傳結果return $result;}#if end#取得網路實體層的資訊$lowLevelStr=$correctCharacter["content"];#LOOPBACK,UP,LOWER_UP#用 "," 分割#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$lowLevelStr;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=",";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$lowLevelStr=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($lowLevelStr["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$lowLevelStr;#回傳結果return $result;}#if end#如果分割字串的關鍵字不存在if($lowLevelStr["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$lowLevelStr;#回傳結果return $result;}#if end#如果分割出來小於1段if($lowLevelStr["dataCounts"]<1){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$lowLevelStr;#回傳結果return $result;}#if end#有幾個 device flag 就執行幾次for($i=0;$i<count($lowLevelStr["dataArray"]);$i++){#設置名為 $lowLevelStr["dataArray"] 的 device flags 為 "true"$info["deviceFlags"][$lowLevelStr["dataArray"][$i]]="true";}#for end#string array: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000#$spiltString 有幾個元素for($i=1;$i<$spiltString["dataCounts"];$i=$i+2){#取得設備的屬性與值$info["deviceAttr"][$spiltString["dataArray"][$i]]=$spiltString["dataArray"][$i+1];}#for end}#if end#反之是偶數列else{# link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00#用 " " 分割#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:$conf["stringProcess::spiltString"]["stringIn"]=$lineContent;#要處理的字串。$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割字串失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果分割字串的關鍵字不存在if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果分割出來小於1段if($spiltString["dataCounts"]!==4){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得 mac$info["mac"]=$spiltString["dataArray"][1];#取得廣播位置$info["brd"]=$spiltString["dataArray"][3];#記錄網路設備資訊$result["content"][$index]=$info;#重設 $info 為空陣列$info=array();}#else end}#foreach end#設置取得的網路設備資訊#$result["content"]=$callShell["output"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function ipLinkShow end/*#函式說明:#顯示網路連線的IP相關資訊.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],實際執行的指令.#$result["content"],陣列,每個可能的ip地址.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["linkName"],字串,要檢視的網路界面名稱,若省略則會顯示所有的網路設備的ip地址相關資訊$conf["linkName"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function ipAddrShow(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkName");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("linkName");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end/*#輸出參考3: ens2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 52:54:11:12:35:02 brd ff:ff:ff:ff:ff:ffaltname enp3s2altname enx525411123502inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute ens2valid_lft 74728sec preferred_lft 74728secinet6 fec0::5054:11ff:fe12:3502/64 scope site dynamic noprefixroutevalid_lft 86029sec preferred_lft 14029secinet6 fe80::5054:11ff:fe12:3502/64 scope link noprefixroutevalid_lft forever preferred_lft forever*/#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="ip";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("addr","show",$conf["linkName"]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果檢查參數失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#ip addr show [Network Interface name]#$callShell["output"];#函式說明:#尋找多個字串中是否含有符合多個格式之一的內容,且回傳解析好的變數數值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.#$result["content"],陣列,key為lineNo者為inputs參數的索引;key為content者為符合的資訊,若為n個${*},則當found為"true"時,就會回傳n個元素.#必填參數:#$conf["inputs"],字串陣列,要檢查的字串集合.$conf["search::getMatchFormatsStrings"]["inputs"]=$callShell["output"];#$conf["format"],格式字串陣列,要尋找的可能格式字串集合.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.$conf["search::getMatchFormatsStrings"]["formats"]=array("\${*}inet \${*}/\${*} \${*}","\${*}inet6 \${*}/\${*} \${*}");#可省略參數:#無.#參考資料:#無.#備註:#無.$getMatchFormatsStrings=search::getMatchFormatsStrings($conf["search::getMatchFormatsStrings"]);unset($conf["search::getMatchFormatsStrings"]);#如果執行出錯if($getMatchFormatsStrings["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$getMatchFormatsStrings;#回傳結果return $result;}#if end#如果沒有ip的關鍵字if($getMatchFormatsStrings["found"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$getMatchFormatsStrings;#回傳結果return $result;}#if end#初始化儲存ip地址的陣列$result["content"]=array();#針對每個符合的行結果foreach($getMatchFormatsStrings["content"] as $ipInfo){#var_dump(__LINE__,$ipInfo);#針對每個ip資訊foreach($ipInfo["content"] as $ip){#儲存 ip 地址$result["content"][]=$ip[1]."/".$ip[2];}#foreach end}#foreach end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function ipAddrShow end/*#函式說明:#建立腳本檔案.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["content"],腳本檔案的位置與名稱.#必填參數:#$conf["cmd"],要執行的指令字串陣列.#$conf["cmd"]=array();#可省略參數:#$conf["params"],要執行對應指令所屬的參數字串陣列.#$conf["params"]=array(array());#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.#$conf["excuteBy"]="";#$conf["fileName"],字串,指定要輸出的檔案名稱.#$conf["fileName"]="";#參考資料:#無.#備註:#無.*/public static function createBatch(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函數".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["simpleError"],簡單表示的錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmd");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("params","excuteBy","fileName");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cmd","params");#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果未通過檢查if($callShell["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#初始化要執行的執行字串陣列$multiLineCmdStr="";#如果有設定 $conf["excuteBy"]if(isset($conf["excuteBy"])){#檢查 $conf["excuteBy"] 是否存在#函式說明:#檢查指令是否存在#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.#$result["cmdFullPath"],指令的絕對路徑.#必填參數:#$conf["cmd"],"字串",要查詢的指令.$conf["cmd::checkCmdExist"]["cmd"]=$conf["excuteBy"];#可省略參數:#無.#參考資料:#無.#備註:#無.$checkCmdExist=cmd::checkCmdExist($conf["cmd::checkCmdExist"]);unset($conf["cmd::checkCmdExist"]);#若執行失敗if($checkCmdExist["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkCmdExist;#回傳結果return $result;}#if end#若指令不存在if($checkCmdExist["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkCmdExist;#回傳結果return $result;}#if end#設置要透過哪個程式執行$multiLineCmdStr=$multiLineCmdStr."#!".$checkCmdExist["cmdFullPath"].PHP_EOL;}#if end#針對每行指令foreach($conf["cmd"] as $index=>$cmd){#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]=$cmd;#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$conf["params"][$index];#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.$conf["external::callShell"]["doNotRun"]="true";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果分割字串失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#儲存要執行的指令字串$multiLineCmdStr=$multiLineCmdStr.$callShell["cmd"].PHP_EOL;}#foreach end#函式說明:#將字串寫入到檔案#回傳結果:#$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["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;#可省略參數:#如果有設置 fileNameif(isset($conf["fileName"])){#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.$conf["fileAccess::writeTextIntoFile"]["fileName"]=$conf["fileName"];}#if end#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".$conf["fileAccess::writeTextIntoFile"]["inputString"]=$multiLineCmdStr;#$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"]="";#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".$conf["fileAccess::writeTextIntoFile"]["web"]="false";#參考資料:#無.#備註:#無.$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);unset($conf["fileAccess::writeTextIntoFile"]);#如果執行失敗if($writeTextIntoFile["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#設置 腳本檔案 的位置與名稱$result["content"]=$writeTextIntoFile["fileInfo"]["createdFilePathAndName"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function createBatch end/*#函式說明:#export svn 上的檔案目錄,進行打包放到遠端伺服器上並進行安裝或更新的動作.#回傳結果:#無.#必填參數:#無.#可省略參數:#無.#參考資料:#無.#備註:#用戶端上需要有安裝php,openssh-clients,subversion(svn),openssh-askpass,zstd套件.#網站伺服器端需要有安裝openssh-server,zstd套件.#待測試#建議將svn預先輸入密碼的功能分離出來*/public static function packetFromSvnToRemoteServer(){#歡迎echo "Welcome to ".basename($_SERVER["SCRIPT_FILENAME"])."~".PHP_EOL;#取得參數$params=$_SERVER["argv"];#如果有第一個參數if(isset($params[1])){//初始化檢查與設定用的conf變數$conf=array();$conf["newConfFile"]["name"]="要產生的設定檔名稱";$conf["newConfFile"]["val"]="";$conf["svnAccount"]["name"]="svn+ssh所用的帳戶名稱";$conf["svnAccount"]["val"]="";$conf["svnPass"]["name"]="svn+ssh所用的帳戶密碼";$conf["svnPass"]["val"]="";$conf["svnSshPrivateKey"]["name"]="svn+ssh所用賬戶對應的 ssh private key";$conf["svnSshPrivateKey"]["val"]="";$conf["svnUrl"]["name"]="svn+ssh的完整路徑,例如「svn+ssh://sshAccount@dns/usr/local/projects/projectsName/branch/1.XX.XX」";$conf["svnUrl"]["val"]="";$conf["svnPort"]["name"]="svn+ssh所使用網址對應的port,若要使用22以外的數值請指定.";$conf["svnPort"]["val"]="";$conf["src"]["name"]="export後存在本機上的名稱,預設爲 svn+ssh完整路徑的最後一層目錄名稱";$conf["src"]["val"]="basename(\$svnUrl)";$conf["date"]["name"]="打包時間的產生方式,預設爲 gmdate('YmdHis')";$conf["date"]["val"]="gmdate('YmdHis')";$conf["target"]["name"]="要打包的目錄,預設爲 export後存在本機上的名稱-打包時間";$conf["target"]["val"]="\$src.\"-\".\$date";$conf["exclude"]["name"]="要排除的目錄或檔案";$conf["exclude"]["val"]=array("");$conf["targetRoot"]["name"]="網頁要放置的位置";$conf["targetRoot"]["val"]="/var/www/html";$conf["sshServerDns"]["name"]="網站Server的dns或ip";$conf["sshServerDns"]["val"]="";$conf["sshServerPort"]["name"]="連線到網站Server的ssh port";$conf["sshServerPort"]["val"]="";$conf["sshServerAccount"]["name"]="連線到網站Server的ssh acccount";$conf["sshServerAccount"]["val"]="";$conf["sshServerPassword"]["name"]="連線到網站Server的ssh password";$conf["sshServerPassword"]["val"]="";$conf["sshServerPrivateKey"]["name"]="連線到網站Server的ssh private key";$conf["sshServerPrivateKey"]["val"]="";$conf["serverHtmlManageAccount"]["name"]="網站Server上可以搬移網頁檔案的帳戶";$conf["serverHtmlManageAccount"]["val"]="";$conf["serverHtmlManagePassword"]["name"]="網站Server上可以搬移網頁檔案的賬戶密碼";$conf["serverHtmlManagePassword"]["val"]="";#取得參數1$param=&$params[1];#判斷參數switch($param){#如果參數爲 "--create-conf"case "--create-conf":#提示建立設定檔echo "建立新設定檔...".PHP_EOL;#依據每個設定檔foreach($conf as $varInPhp=>$info){#提示輸入參數echo "請輸入參數 ".$info["name"].":".PHP_EOL;#如果 $info["val"] 不為空字串if($info["val"]!==""){#如果是 "exclude" 的設定if($varInPhp==="exclude"){#提示檢視用法的參數echo "輸入 -h 或 --help 顯示本說明".PHP_EOL;#提示顯示要移除的目錄echo "輸入 ls 來顯示要剔除的路徑或檔案清單".PHP_EOL;#提示輸入路徑與檔案來新增要剔除的目標echo "輸入路徑或檔案名稱來新增要剔除的目標".PHP_EOL;#提示移除剔除清單的方式echo "輸入 \"del 排除項目的編號\" 將項目移除".PHP_EOL;#提示留空的預設數值echo "留空則爲預設的:".PHP_EOL;#針對每個要剔除的對象foreach($info["val"] as $rmNo=>$rmVal){#印出編號與數值內容echo "[".$rmNo."]=>".$rmVal.PHP_EOL;}#foreach end}#if end#反之else{#提示留空的預設數值echo "留空則爲預設的「".$info["val"]."".PHP_EOL."」";}#else end}#if end#無窮迴圈while(true){#取得列輸入$input=trim(fgets(STDIN));#有預設數值則允許爲空字串if($info["val"]!==""){#如果是 "exclude" 的設定if($varInPhp==="exclude"){#判斷輸入的內容switch($input){#如果是 ""case "":#取得要移除的清單$conf[$varInPhp]["val"]=$info["val"];#結束輸入break 2;#如果是 "ls"case "ls":#提示要移除的目錄或檔案echo "要剔除的路徑或檔案清單如下:".PHP_EOL;#針對每個要剔除的對象foreach($info["val"] as $rmNo=>$rmVal){#印出編號與數值內容echo "[".$rmNo."]=>".$rmVal.PHP_EOL;}#foreach end#繼續輸入continue 2;#如果是 "-h"case "-h":#如果是 "--help"case "--help":#其他內容default:#解析輸入字串sscanf($input,'%s %d',$p1,$p2);#如果第一個字是 "del"if($p1==="del"){#檢查$p2是否為數字if(is_integer($p2)){#如果要移除的目標存在if(isset($info["val"][$p2])){#移除之unset($info["val"][$p2]);#重新排序#初始化暫存的陣列$tmp=array();#針對每個要剔除的對象foreach($info["val"] as $rmNo=>$rmVal){#印出編號與數值內容$tmp[]=$rmVal;}#foreach end#取得重新排序好的陣列$info["val"]=$tmp;}#if end}#if end}#if end#反之else{#取得新的排除項目$info["val"][]=$p1;}#else end#提示檢視用法的參數echo "輸入 -h 或 --help 顯示本說明".PHP_EOL;#提示顯示要移除的目錄echo "輸入 ls 來顯示要剔除的路徑或檔案清單".PHP_EOL;#提示輸入路徑與檔案來新增要剔除的目標echo "輸入路徑或檔案名稱來新增要剔除的目標".PHP_EOL;#提示移除剔除清單的方式echo "輸入 \"del 排除項目的編號\" 將項目移除".PHP_EOL;#提示留空代表結束輸入echo "留空代表結束輸入".PHP_EOL;#繼續輸入continue 2;}#switch end}#if end#反之else{#若輸入不為空if($input!==""){#取得輸入的內容$conf[$varInPhp]["val"]=$input;}#if end}#else end#跳出whilebreak;}#if end#無預設數值,輸入不爲空才允許.else{#若輸入不為空字串if($input!==""){#取得輸入內容$conf[$varInPhp]["val"]=$input;#跳出whilebreak;}#if end}#else end#提示輸入參數echo "請輸入參數 ".$info["name"].":".PHP_EOL;#如果輸入不為空字串if($info["val"]!==""){#提示留空的預設內容echo "留空則爲預設的「".$info["val"]."」".PHP_EOL;}#if end}#while end}#foreach end#寫設定檔#取得新設定檔的名稱$ncn=$conf["newConfFile"]["val"];#卸除新設定檔的變數陣列unset($conf["newConfFile"]);#初始化新設定檔的內容$ncc="";#針對每個confforeach($conf as $varInPhp=>$info){#如果是陣列if(is_array($info["val"])){#寫入初始化為陣列$ncc=$ncc."\$".$varInPhp."=array();".PHP_EOL;#針對每個元素foreach($info["val"] as $key=>$val){#寫入元素內容$ncc=$ncc."\$".$varInPhp."[".$key."]=".$val.";".PHP_EOL;}#foreach end}#if end#反之else{#如果數值內容有 "$" 或 "gmdate(" 或 'date(' 或 'time()' 或 'mktime(' 或 'gmmktime('if(strpos($info["val"],'$')!==false || strpos($info["val"],'gmdate(')!==false || strpos($info["val"],'date(')!==false || strpos($info["val"],'time()')!==false || strpos($info["val"],'mktime(')!==false || strpos($info["val"],'gmmktime(')!==false || $varInPhp==="serverHtmlManagePassword"){#直接寫入$ncc=$ncc."\$".$varInPhp."=".$info["val"].";".PHP_EOL;}#if end#反之else{#加上""再寫入$ncc=$ncc."\$".$varInPhp."=\"".$info["val"]."\";".PHP_EOL;}#else end}#else end}#foreach end#函式說明:#將字串寫入到檔案#回傳結果:#$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["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;#可省略參數:#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.$conf["fileAccess::writeTextIntoFile"]["fileName"]=$ncn;#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".$conf["fileAccess::writeTextIntoFile"]["inputString"]=$ncc;#$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"]="";#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".$conf["fileAccess::writeTextIntoFile"]["web"]="false";#參考資料:#無.#備註:#無.$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);unset($conf["fileAccess::writeTextIntoFile"]);#如果執行失敗if($writeTextIntoFile["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$writeTextIntoFile;#回傳結果return $result;}#if end#提示建立設定檔案完成echo "設定檔「".$ncn."」建立完成".PHP_EOL;#程式執行結束exit;#其他則視爲要include進來的conf檔案default:#如果設定檔案不存在if(!file_exists($param)){#提示設定檔不存在或沒有權限讀取echo "設定檔「".$param."」不存在,或沒有權限讀取".PHP_EOL;#提示建立新設定檔案的方式echo "如果要建立新設定檔請用「--create-conf」參數".PHP_EOL;#結束程式exit;}#if end#反之else{#匯入設定檔案include($param);#針對每個設定變數foreach($conf as $varInPhp=>$info){#如果變數key為newConfFileif($varInPhp==="newConfFile"){#則跳過continue;}#if end#如果設定變數不存在if(!isset($$varInPhp)){#提示設定變數未設置echo "設定檔的 ".$info["name"]." 參數未設置!".PHP_EOL;#結束程式exit;}#if end}#foreach end}#else end}#switch end}#if end#反之else{#提示參數用法echo "參數用法:".PHP_EOL;#提示建立新設定檔案的參數echo "php ".$_SERVER["PHP_SELF"]." --create-conf 建立新設定檔".PHP_EOL;#提示使用設定檔進行包code與部署到遠端網頁伺服器的動作echo "php ".$_SERVER["PHP_SELF"]." php_conf_file 依據 php_conf_file 進行包 code 到網站伺服器的動作".PHP_EOL;#結束程式exit;}#else end#確保儲存要包的目錄不存在.#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="rm";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-rf",$src);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#初始化要是給 callShellHelper 的指令與參數陣列$paramsToCallShellHelper=array();#如果 $svnPass 有數值if($svnPass!==""){#設置要使用 ssh 密碼$paramsToCallShellHelper[]="sshpass";#設置密碼參數$paramsToCallShellHelper[]="-p";#設置密碼$paramsToCallShellHelper[]=$svnPass;}#if end#設置要使用 svn$paramsToCallShellHelper[]="svn";#設置要 export$paramsToCallShellHelper[]="export";#設置 svn+ssh 的路徑$paramsToCallShellHelper[]=$svnUrl;#初始化給svn+ssh使用的ssh參數$sshOptionsForSvn=array();#如果有指定 svnSshPrivateKeyif($svnSshPrivateKey!==""){#如果 給svn+ssh使用的ssh參數 預設為空if($sshOptionsForSvn===array()){#設置要指定 ssh 參數.$sshOptionsForSvn[]="--config-option=config:tunnels:ssh=ssh";}#if end#設置 private key 的參數.$sshOptionsForSvn[]="-i";#設置 private key 的路徑與名稱.$sshOptionsForSvn[]=$svnSshPrivateKey;}#if end#如果有指定 svnPortif($svnPort!==""){#如果 給svn+ssh使用的ssh參數 預設為空if($sshOptionsForSvn===array()){#設置要指定 ssh 參數.$sshOptionsForSvn[]="--config-option=config:tunnels:ssh=ssh";}#if end#設置 port 的參數.$sshOptionsForSvn[]="-p";#設置 port.$sshOptionsForSvn[]=$svnPort;}#if end#Merge $paramsToCallShellHelper 跟 $sshOptionsForSvn#函式說明:#將多個一維陣列串聯起來,key從0開始排序.#回傳的結果:#$result["status"],"true"表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數.#$result["content"],合併好的一維陣列.#必填參數#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);$conf["arrays::mergeArray"]["inputArray"]=array($paramsToCallShellHelper,$sshOptionsForSvn);#可省略參數:#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.#$conf["allowRepeat"]="true";#參考資料:#無.#備註:#無.$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);unset($conf["arrays::mergeArray"]);#如果執行失敗if($mergeArray["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$mergeArray;#回傳結果return $result;}#if end#函式說明:#解析指令與參數,回傳指令與參數給 callShell 函式使用.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令名稱.#$result["params"],執行指令伴隨的參數.#必填參數:#$conf["cmdArray"],字串陣列,要執行的指令字串.$conf["external::callShellHelper"]["cmdArray"]=$mergeArray["content"];#可省略參數:#無.#參考資料:#array_shift=>https://www.php.net/manual/en/function.array-shift.php#備註:#無.$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);unset($conf["external::callShellHelper"]);#如果執行失敗if($callShellHelper["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShellHelper;#回傳結果return $result;}#if end#輸出位於 $svnUrl 上的svn code,使用的密碼為 $svnPass#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]=$callShellHelper["cmd"];#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$callShellHelper["params"];#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#複製要包的版本#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="cp";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-R","-v",$src,$target);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#設置複製到網頁Server前要移除的檔案(不覆蓋到Server上既有的檔案)#移除不需要包出去的目錄#初始化暫存剔除的指令$rm=array();#針對每個要剔除的目標foreach($exclude as $delPorF){#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="rm";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-rf","-v",$target,$target."/".$delPorF);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end}#foreach end#打包目標 $target 成 $target.'tar.xz'#函式說明:#將資料夾打包成.tar.zst檔案#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["storePlace"],檔案輸出後的位置與名稱.#必填參數:#$conf["target"],字串,要打包的檔案.$conf["cmd::makeTarZstFile"]["target"]=$target;#可省略參數:#$conf["commentsArrayForTar"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述,預設為array("正產生 tar 檔案");#$conf["commentsArrayForTar"]=array("正產生 tar 檔案");#$conf["commentsArrayForZst"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述,預設為array("正產生 zst 檔案");#$conf["commentsArrayForZst"]=array("正產生 zst 檔案");#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.#$conf["newLineBreak"]="false";#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.#$conf["path"]="./";#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.#$conf["delAfterSuc"]="false";#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.#$conf["overwrite"]="true";#參考資料:#無.#備註:#無.$makeTarZstFile=cmd::makeTarZstFile($conf["cmd::makeTarZstFile"]);unset($conf["cmd::makeTarZstFile"]);#如果執行失敗if($makeTarZstFile["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#建立將打包好的壓縮檔放到 Server 的腳本#建立temp目錄#進入 temp 目錄#把包好的程式放到伺服器端#函式說明:#建立腳本檔案.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["content"],腳本檔案的位置與名稱.#必填參數:#$conf["cmd"],要執行的指令字串陣列.$conf["cmd::createBatch"]["cmd"]=array("mkdir","cd","put");#可省略參數:#$conf["params"],要執行對應指令所屬的參數字串陣列.$conf["cmd::createBatch"]["params"]=array(array("temp"),array("temp"),array($makeTarZstFile["content"]));#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.$conf["cmd::createBatch"]["excuteBy"]="bash";#$conf["fileName"],字串,指定要輸出的檔案名稱.#$conf["fileName"]="";#參考資料:#無.#備註:#無.$createBatch=cmd::createBatch($conf["cmd::createBatch"]);unset($conf["cmd::createBatch"]);#如果執行失敗if($createBatch["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#取得腳本$batchFile=$createBatch["content"];#初始化給 sftp 使用的指令跟參數$paramsForSshServer=array();#如果有指定 $sshServerPasswordif($sshServerPassword!==""){#使用 sshpass 指令$paramsForSshServer[]="sshpass";#設置要指定密碼$paramsForSshServer[]="-p";#設置要使用的密碼$paramsForSshServer[]=$sshServerPassword;}#if end#設置使用 sftp 指令$paramsForSshServer[]="sftp";#如果 $sshServerPort 不為空if($sshServerPort!==""){#設置要指定 port$paramsForSshServer[]="-P";#設置 port$paramsForSshServer[]=$sshServerPort;}#if end#如果 sshServerPrivateKey 不為空if($sshServerPrivateKey!==""){#設置要指定 ssh private key$paramsForSshServer[]="-i";#設置 ssh private key$paramsForSshServer[]=$sshServerPrivateKey;}#if end#設置 sftp 的url以及要使用的賬號$paramsForSshServer[]=$sshServerAccount."@".$sshServerDns;#設置要倒入腳本$paramsForSshServer[]="<";#設置要倒入的腳本$paramsForSshServer[]=$batchFile;#函式說明:#解析指令與參數,回傳指令與參數給 callShell 函式使用.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令名稱.#$result["params"],執行指令伴隨的參數.#必填參數:#$conf["cmdArray"],字串陣列,要執行的指令字串.$conf["external::callShellHelper"]["cmdArray"]=$paramsForSshServer;#可省略參數:#無.#參考資料:#array_shift=>https://www.php.net/manual/en/function.array-shift.php#備註:#無.$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);unset($conf["external::callShellHelper"]);#如果執行失敗if($callShellHelper["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShellHelper;#回傳結果return $result;}#if end#輸出位於 $svnUrl 上的svn code,使用的密碼為 $svnPass#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]=$callShellHelper["cmd"];#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$callShellHelper["params"];#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end/*建立連線到Server要做的cmd1.將打包好的檔案解壓縮2.複製解好的檔案目錄到目標位置3.移除安裝過程產生的檔案*//*#進入temp目錄#解壓縮程式壓縮檔#解壓縮 tar 檔#用網頁管理者賬戶 $serverHtmlManageAccount 的身份與密碼 $serverHtmlManagePassword 執行將網頁檔案目錄 $target 底下的內容放到對的位置 $targetRoot, 變更目標位置 $targetRoot 的擁有着為 apache.apache ,且權限為755.#移除暫存的網頁路徑#移除網頁tar檔#移除網頁xz檔*/#函式說明:#建立腳本檔案.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["content"],腳本檔案的位置與名稱.#必填參數:#$conf["cmd"],要執行的指令字串陣列.$conf["cmd::createBatch"]["cmd"]=array("cd","zstd","tar","echo","rm","rm","rm");#可省略參數:#$conf["params"],要執行對應指令所屬的參數字串陣列.$conf["cmd::createBatch"]["params"]=array(array("temp"),array("-d",$target."tar.zst"),array("-xvf",$target."tar"),array($serverHtmlManagePassword,"|","su",$serverHtmlManageAccount,"-c"," ' cp -R --force ".$target."/. ".$targetRoot.";chown -R apache:apache ".$targetRoot.";chmod 755 -R ".$targetRoot.";'"),array("-rf",$target),array($target."tar"),array($target."tar.xz"));#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.$conf["cmd::createBatch"]["excuteBy"]="bash";#$conf["fileName"],字串,指定要輸出的檔案名稱.#$conf["fileName"]="";#參考資料:#無.#備註:#無.$createBatch=cmd::createBatch($conf["cmd::createBatch"]);unset($conf["cmd::createBatch"]);#如果執行失敗if($createBatch["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$createBatch;#回傳結果return $result;}#if end#取得腳本檔案名稱$batchFile=$createBatch["content"];#初始化給 ssh 使用的指令跟參數$paramsForSshServer=array();#如果有指定 $sshServerPasswordif($sshServerPassword!==""){#使用 sshpass 指令$paramsForSshServer[]="sshpass";#設置要指定密碼$paramsForSshServer[]="-p";#設置要使用的密碼$paramsForSshServer[]=$sshServerPassword;}#if end#設置使用 sftp 指令$paramsForSshServer[]="ssh";#如果 $sshServerPort 不為空if($sshServerPort!==""){#設置要指定 port$paramsForSshServer[]="-p";#設置 port$paramsForSshServer[]=$sshServerPort;}#if end#如果 sshServerPrivateKey 不為空if($sshServerPrivateKey!==""){#設置要指定 ssh private key$paramsForSshServer[]="-i";#設置 ssh private key$paramsForSshServer[]=$sshServerPrivateKey;}#if end#設置 sftp 的url以及要使用的賬號$paramsForSshServer[]=$sshServerAccount."@".$sshServerDns;#設置要倒入腳本$paramsForSshServer[]="<";#設置要倒入的腳本$paramsForSshServer[]=$batchFile;#函式說明:#解析指令與參數,回傳指令與參數給 callShell 函式使用.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令名稱.#$result["params"],執行指令伴隨的參數.#必填參數:#$conf["cmdArray"],字串陣列,要執行的指令字串.$conf["external::callShellHelper"]["cmdArray"]=$paramsForSshServer;#可省略參數:#無.#參考資料:#array_shift=>https://www.php.net/manual/en/function.array-shift.php#備註:#無.$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);unset($conf["external::callShellHelper"]);#如果執行失敗if($callShellHelper["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShellHelper;#回傳結果return $result;}#if end#連線到遠端將檔案解壓縮放到指定的目錄#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]=$callShellHelper["cmd"];#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$callShellHelper["params"];#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#建立移除本機上檔案的腳本/*#移除包code的目錄#移除含有時間標識包code的暫存目錄#移除包code的壓縮檔#移除用不到的batch檔案*/#函式說明:#建立腳本檔案.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["content"],腳本檔案的位置與名稱.#必填參數:#$conf["cmd"],要執行的指令字串陣列.$conf["cmd::createBatch"]["cmd"]=array("rm","rm","rm","rm");#可省略參數:#$conf["params"],要執行對應指令所屬的參數字串陣列.$conf["cmd::createBatch"]["params"]=array(array("-rf",$src),array("-rf",$target),array("-rf",$target."tar.xz"),array($batchFile));#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.$conf["cmd::createBatch"]["excuteBy"]="bash";#$conf["fileName"],字串,指定要輸出的檔案名稱.#$conf["fileName"]="";#參考資料:#無.#備註:#無.$createBatch=cmd::createBatch($conf["cmd::createBatch"]);unset($conf["cmd::createBatch"]);#如果執行失敗if($createBatch["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$createBatch;#回傳結果return $result;}#if end#運行腳本檔案#函式說明:#呼叫shell執行編譯過的2元碼程式或具備執行權限的檔案後回傳的結果#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],正在執行的函式#$result["error"],錯誤訊息陣列.#$result["error"]["returnCode"],錯誤代碼.#$result["output"],爲執行完二元碼後的輸出陣列.#$result["escapedCmd"],實際執行的指令.#必填參數:$conf["exeFileAddress"]=$createBatch["content"];#可執行檔的位置與名稱#可省略參數:#$conf["arguments"]="";#要給執行檔的參數#參考資料:#http://php.net/manual/en/function.exec.php#備註:#無.$execByteCode=external::execByteCode($conf);unset($conf);#如果執行失敗if($execByteCode["status"]==="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$execByteCode;#回傳結果return $result;}#if end}#function packetFromSvnToRemoteServer end/*#函式說明:#輸出標準錯誤#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["errors"],字串陣列,要輸出的標準錯誤訊息.#$conf["errors"]=array();#可省略參數:#$conf["forceEOL"],字串,是否要強制每個元素結尾都要有PHP_EOL,"false"代表不要;預設為"true"代表要.#$conf["forceEOL"]="true";#參考資料#http://php.net/manual/en/features.commandline.io-streams.php#備註:#無.*/public static function outputStdErr(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#函式說明:#判斷當前環境為web還是cmd#回傳結果:#$result,"web"或"cmd"if(csInformation::getEnv()==="web"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("errors");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("forceEOL");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("forceEOL");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查失敗if($checkArguments["status"]=="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查不通過if($checkArguments["passed"]=="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#開啟錯誤輸出的界面$stderr = fopen('php://stderr', 'w');#針對每個錯誤列foreach($conf["errors"] as $error){#取得換行符號的長度$EOLlength=strlen(PHP_EOL);#如果強制要每個元素用PHP_EOLif($conf["forceEOL"]==="true"){#取得該行錯誤的長度$errlength=strlen($error);#如果結尾無PHP_EOLif(strpos($error,PHP_EOL)!==($errlength-$EOLlength+1)){#加上PHP_EOL$error=$error.PHP_EOL;}#if end}#if end#輸出錯誤fwrite($stderr,$error);}#foreach end}#fucntion outputStdErr end/*#函式說明:#用find指令尋找檔案#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["found"],是否有找到符合的檔案,"true"代表有;"false"代表沒有.#$result["content"],找到的檔案陣列.#必填參數:#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.$conf["keyWord"]="";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["path"],字串,搜尋的路徑,預設為"/".#$conf["path"]="/";#$conf["fileOnly"],字串,"true"代表只要找檔案,"false"代表.#$conf["fileOnly"]="";#參考資料:#http://php.net/manual/en/function.glob.php#備註:#無.*/public static function find(&$conf=array()){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函式".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","keyWord");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","fileOnly");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","fileOnly");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/","false");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數失敗if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#初始化參數$params=array();#設置搜尋路徑$params[]=$conf["path"];#如果只要搜尋檔案if($conf["fileOnly"]==="true"){#設置類型$params[]="-type";#設置為檔案$params[]="f";}#if end#設置搜尋的關鍵字$params[]="-name";#設置搜尋的關鍵字參數$params[]=$conf["keyWord"];#初始化是否為路徑的參數$arguIsAddr=array();#針對每個參數foreach($params as $no=>$val){#如果是第一個if($no===0){#設置為路徑$arguIsAddr[]="true";}#if end#反之else{#設置不為路徑$arguIsAddr[]="false";}#else end}#foreach end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="find";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$params;#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").$conf["external::callShell"]["arguIsAddr"]=$arguIsAddr;#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#初始化沒有找到$result["found"]="false";#如果有找到符合的項目if(count($callShell["output"])>0){#設置有找到$result["found"]="true";}#if end#設置取得的檔案$result["content"]=$callShell["output"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function find end/*#函式說明:#檢查 httpd 與 postfix/smtpd 的 log 與 named 的 log 與 sshd 的 log 把惡意連線的 IP 用防火牆阻阻擋#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],阻擋IP的結果或有問題的IP資訊清單.#$result["reason"][$ip],特定ip被阻擋的資訊.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["excludeIp"],字串陣列,白名單ip陣列.#$conf["excludeIp"]=array();#$conf["logPath"],字串,httpd的log位置,預設為 "/var/log/httpd"#$conf["logPath"]="";#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者#$conf["username"]="";#$conf["password"],字串,root使用者的密碼,#$conf["password"]="";#$conf["getIplistOnly"],字串,是否不阻擋IP只取得有問題的IP,預設為"false",要阻擋IP;"true"代表只取得有問題的IP.#$conf["getIplistOnly"]="false";#$conf["dynamic"],字串,是否要動態的阻擋不要永久阻擋,是為"true";反之為"false",預設為"true".#$conf["dynamic"]="true"#參考資料:#無.#備註:#無.*/public static function blockAcctackIp(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath","getIplistOnly","dynamic");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("excludeIp","logPath","username","password","getIplistOnly","dynamic");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array(),"/var/log/httpd","root",null,"false","true");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數失敗if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#取得 http 存取記錄的 log#函式說明:#檢查指令的輸出是否含有關鍵字#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["grepCmd"],截取關鍵字的指令.#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.#$result["content"],關鍵字所在列的輸出.#$result["count"],輸出的列數.#必填參數:#$conf["cmd"],字串,要執行的指令.$conf["cmd::searchOutPut"]["cmd"]="cat";#$conf["keyWord"],字串,要檢查是否有關鍵字.$conf["cmd::searchOutPut"]["keyWord"]=" 404 ";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".#$conf["binPath"]="";#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.$conf["cmd::searchOutPut"]["argu"]=array($conf["logPath"]."/access_log");#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.#$conf["excludeGrep"]="false";#如果有設置 usernameif(isset($conf["username"])){#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["cmd::searchOutPut"]["username"]=$conf["username"];}#if end#如果有設置 passwordif(isset($conf["password"])){#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["cmd::searchOutPut"]["password"]=$conf["password"];}#if end$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);unset($conf["cmd::searchOutPut"]);#如果執行失敗if($searchOutPut["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$searchOutPut;#回傳結果return $result;}#if end#如果不是只抓清單if($conf["getIplistOnly"]==="false"){#清空 access_log#函式說明:#將檔案內容清空#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列#必填參數:#$conf["fileAddr"],字串,要清空的檔案位置與名稱.$conf["fileAccess::emptyFile"]["fileAddr"]=$conf["logPath"]."/access_log";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::emptyFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#可省略參數:#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".$conf["fileAccess::emptyFile"]["web"]="false";$emptyFile=fileAccess::emptyFile($conf["fileAccess::emptyFile"]);unset($conf["fileAccess::emptyFile"]);#如果執行失敗if($emptyFile["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$emptyFile;#回傳結果return $result;}#if end}#if end#過濾掉對於含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.#函式說明:#檢查多個字串中的每個字串是否有多個關鍵字#回傳的結果:#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息.#$result["argu"],使用的參數.#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列.#$result["foundedKeyWords"].找到的關鍵字.#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列.#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.#必填參數:$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(".css",".js","favicon.ico",".jpg",".png");#想要搜尋的關鍵字$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$searchOutPut["content"];#要被搜尋的字串內容陣列#可省略參數:#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);unset($conf["search::findManyKeyWordsFromManyString"]);#如果執行出錯if($findManyKeyWordsFromManyString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$findManyKeyWordsFromManyString;#回傳結果return $result;}#if end#取得不含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.$searchOutPut["content"]=$findManyKeyWordsFromManyString["foundedFalseKey"];#更新計數$searchOutPut["count"]=count($searchOutPut["content"]);#用空格分割字串#函式說明:#將多個固定格式的字串分開,並回傳分開的結果#回傳的參數:#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段#必填參數:#$conf["stringIn"],字串陣列,要處理的字串陣列.$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);unset($conf["stringProcess::spiltMutiString"]);#如果分割失敗if($spiltMutiString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltMutiString;#回傳結果return $result;}#if end#初始化儲存有問題IP的陣列$ips=array();#初始化儲存可能有問題的IP陣列$ips_byIp=array();#針對每行內容for($i=0;$i<$searchOutPut["count"];$i++){#如果沒有分割出來的內容if($spiltMutiString["spiltString"][$i]["dataCounts"]===0){#換下一個continue;}#if end#有問題的資訊$info=array();#設置問題對應的log行內容$info["log"]=$spiltMutiString["spiltString"][$i]["oriStr"];#設置問題時間點$info["time"]=$spiltMutiString["spiltString"][$i]["dataArray"][3];#記錄有問題的ip$info["ip"]=$spiltMutiString["spiltString"][$i]["dataArray"][0];#取得可能有問題的IP位置資訊$ips_byIp[$spiltMutiString["spiltString"][$i]["dataArray"][0]][]=$info;}#for end#針對每個可能有問題的IPforeach($ips_byIp as $ip => $infos){#計數 ip 於同時間前來的計數$ipSameTimeCount=0;#用來存放來存取的同一時間$ipSameTime="";#看來拜訪的時間點foreach($infos as $info){#如果是初次if($ipSameTime===""){#記錄時間點$ipSameTime=$info["time"];#同時間點計數加1$ipSameTimeCount++;}#if end#反之如果時間點相同else if($ipSameTime===$info["time"]){#同時間點計數加1$ipSameTimeCount++;}#if end#反之時間點不相同else{#記錄時間點$ipSameTime=$info["time"];#同時間點計數重設為1$ipSameTimeCount=1;}#else end#如果同時間的計數達到3if($ipSameTimeCount===3){#取得有問題的IP$ips[]=$info;#換檢查下一個IPcontinue 2;}#if end}#foreach end}#foreach end#取得 https 存取記錄的 log#函式說明:#檢查指令的輸出是否含有關鍵字#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["grepCmd"],截取關鍵字的指令.#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.#$result["content"],關鍵字所在列的輸出.#$result["count"],輸出的列數.#必填參數:#$conf["cmd"],字串,要執行的指令.$conf["cmd::searchOutPut"]["cmd"]="cat";#$conf["keyWord"],字串,要檢查是否有關鍵字.$conf["cmd::searchOutPut"]["keyWord"]=" 404 ";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".#$conf["binPath"]="";#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.$conf["cmd::searchOutPut"]["argu"]=array($conf["logPath"]."/ssl_access_log");#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.#$conf["excludeGrep"]="false";#如果有設置 usernameif(isset($conf["username"])){#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["cmd::searchOutPut"]["username"]=$conf["username"];}#if end#如果有設置 passwordif(isset($conf["password"])){#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["cmd::searchOutPut"]["password"]=$conf["password"];}#if end$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);unset($conf["cmd::searchOutPut"]);#如果執行失敗if($searchOutPut["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$searchOutPut;#回傳結果return $result;}#if end#如果不是只抓清單if($conf["getIplistOnly"]==="false"){#清空 ssl_access_log#函式說明:#將檔案內容清空#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列#必填參數:#$conf["fileAddr"],字串,要清空的檔案位置與名稱.$conf["fileAccess::emptyFile"]["fileAddr"]=$conf["logPath"]."/ssl_access_log";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::emptyFile"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#無$emptyFile=fileAccess::emptyFile($conf["fileAccess::emptyFile"]);unset($conf["fileAccess::emptyFile"]);#如果執行失敗if($emptyFile["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$emptyFile;#回傳結果return $result;}#if end}#if end#過濾掉對於含有 ".css",".js","favicon.ico",".jpg",".png" 關鍵字串的結果.#函式說明:#檢查多個字串中的每個字串是否有多個關鍵字#回傳的結果:#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息.#$result["argu"],使用的參數.#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列.#$result["foundedKeyWords"].找到的關鍵字.#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列.#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.#必填參數:$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(".css",".js","favicon.ico",".jpg",".png");#想要搜尋的關鍵字$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$searchOutPut["content"];#要被搜尋的字串內容陣列#可省略參數:#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);unset($conf["search::findManyKeyWordsFromManyString"]);#如果執行出錯if($findManyKeyWordsFromManyString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$findManyKeyWordsFromManyString;#回傳結果return $result;}#if end#取得不含有 ".css",".js","favicon.ico",".jpg",".png" 關鍵字串的結果.$searchOutPut["content"]=$findManyKeyWordsFromManyString["foundedFalseKey"];#更新計數$searchOutPut["count"]=count($searchOutPut["content"]);#用空格分割字串#函式說明:#將多個固定格式的字串分開,並回傳分開的結果#回傳的參數:#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段#必填參數:#$conf["stringIn"],字串陣列,要處理的字串陣列.$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);unset($conf["stringProcess::spiltMutiString"]);#如果分割失敗if($spiltMutiString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltMutiString;#回傳結果return $result;}#if end#初始化儲存有問題IP的陣列$ips_https=array();#初始化儲存可能有問題的IP陣列$ips_byIp_https=array();#針對每行內容for($i=0;$i<$searchOutPut["count"];$i++){#如果沒有分割出來的內容if($spiltMutiString["spiltString"][$i]["dataCounts"]===0){#換下一個continue;}#if end#有問題的資訊$info=array();#設置問題對應的log行內容$info["log"]=$spiltMutiString["spiltString"][$i]["oriStr"];#設置問題時間點$info["time"]=$spiltMutiString["spiltString"][$i]["dataArray"][3];#記錄有問題的ip$info["ip"]=$spiltMutiString["spiltString"][$i]["dataArray"][0];#取得可能有問題的IP位置,key為[ip][int]$ips_byIp_https[$spiltMutiString["spiltString"][$i]["dataArray"][0]][]=$info;}#for end#針對每個可能有問題的IPforeach($ips_byIp_https as $infos){#計數 ip 於同時間前來的計數$ipSameTimeCount=0;#用來存放來存取的同一時間$ipSameTime="";#看來拜訪的時間點foreach($infos as $info){#如果是初次if($ipSameTime===""){#記錄時間點$ipSameTime=$info["time"];#同時間點計數加1$ipSameTimeCount++;}#if end#反之如果時間點相同else if($ipSameTime===$info["time"]){#同時間點計數加1$ipSameTimeCount++;}#if end#反之時間點不相同else{#記錄時間點$ipSameTime=$info["time"];#同時間點計數重設為1$ipSameTimeCount=1;}#else end#如果同時間的計數達到3if($ipSameTimeCount===3){#取得有問題的IP$ips_https[]=$info;#換檢查下一個IPcontinue 2;}#if end}#foreach end}#foreach end#透過 journalctl -a -e | grep "postfix/smtps/smtpd" | grep " connect from unknown" 來取得 IP#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="journalctl";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-a","-e","|","grep","postfix/smtps/smtpd","|","grep"," connect from unknown");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#儲存有問題的smtp IP$ips_smtp=array();#狀態碼不為1才執行if($callShell["statusCode"]!==1){#截取出的格式#Aug 08 18:05:51 www.qbpwcf.org postfix/smtpd[27933]: connect from unknown[185.234.219.62]#Aug 08 18:14:29 www.qbpwcf.org postfix/smtpd[16133]: connect from unknown[185.234.219.62]#Aug 08 18:23:12 www.qbpwcf.org postfix/smtpd[11623]: connect from unknown[185.234.219.62]#Apr 04 15:11:16 mail.qbpwcf.org postfix/smtps/smtpd[10145]: connect from unknown[212.70.149.72]#Apr 04 15:58:01 mail.qbpwcf.org postfix/smtps/smtpd[12382]: connect from unknown[212.70.149.72]#Mar 09 13:44:00 qbpwcf.org postfix/smtpd[1058247]: connect from unknown[194.48.251.15]#Mar 09 13:44:01 qbpwcf.org postfix/smtpd[1058247]: disconnect from unknown[194.48.251.15] ehlo=1 auth=0/1 quit=1 commands=2/3#分割字串#函式說明:#將多個固定格式的字串分開,並回傳分開的結果#回傳的參數:#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段#必填參數:#$conf["stringIn"],字串陣列,要處理的字串陣列.$conf["stringProcess::spiltMutiString"]["stringIn"]=$callShell["output"];#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);unset($conf["stringProcess::spiltMutiString"]);#如果分割失敗if($spiltMutiString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltMutiString;#回傳結果return $result;}#if end#初始化記錄每行log的時間點$occurTime=array();#根據每筆記錄foreach($spiltMutiString["spiltString"] as $index => $splitStr){#儲存時間$occurTime[$index]=$spiltMutiString["spiltString"][$index]["dataArray"][0]." ".$spiltMutiString["spiltString"][$index]["dataArray"][1]." ".$spiltMutiString["spiltString"][$index]["dataArray"][2];}#foreach end#第一次分割的關鍵字$splitKeyWord=" connect from unknown[";#分割字串#函式說明:#將多個固定格式的字串分開,並回傳分開的結果#回傳的參數:#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段#必填參數:#$conf["stringIn"],字串陣列,要處理的字串陣列.$conf["stringProcess::spiltMutiString"]["stringIn"]=$callShell["output"];#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$splitKeyWord;$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);unset($conf["stringProcess::spiltMutiString"]);#如果分割失敗if($spiltMutiString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltMutiString;#回傳結果return $result;}#if end#儲存尚未處理好的字串$unProcessedStr=array();#初始化儲存log行資訊的變數$oriLog=array();#根據每筆記錄foreach($spiltMutiString["spiltString"] as $index => $splitStr){#儲存原始的log行內容$oriLog[$index]=$spiltMutiString["spiltString"][$index ]["oriStr"];#取得所需的字串$unProcessedStr[]=$splitStr["dataArray"][1];}#foreach end#第二次分割的關鍵字$splitKeyWord="]";#分割字串#函式說明:#將多個固定格式的字串分開,並回傳分開的結果#回傳的參數:#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段#必填參數:#$conf["stringIn"],字串陣列,要處理的字串陣列.$conf["stringProcess::spiltMutiString"]["stringIn"]=$unProcessedStr;#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$splitKeyWord;$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);unset($conf["stringProcess::spiltMutiString"]);#如果分割失敗if($spiltMutiString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltMutiString;#回傳結果return $result;}#if end#根據每筆記錄foreach($spiltMutiString["spiltString"] as $index => $splitStr){#有問題的資訊$info=array();#設置問題對應的log行內容$info["log"]=$oriLog[$index];#設置問題時間點$info["time"]=$occurTime[$index];#記錄有問題的ip$info["ip"]=$splitStr["dataArray"][0];#取得所需的有問題的IP$ips_smtp[]=$info;}#foreach end}#if end#透過 journalctl -e | grep named | grep " client " 來取得 IP#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="journalctl";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-a","-e","|","grep"," named","|","grep"," client ");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#記錄攻擊者的IP$attacker_ips_namd=array();#狀態碼不為1才執行if($callShell["statusCode"]!==1){#截取出的格式#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f77180297c0 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f770c077bf0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f770c077bf0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f77180297c0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f77180297c0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#40052 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#48628 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#52460 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#60457 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#10213 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#44377 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#4481 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#53061 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#31654 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc802a410 61.220.11.198#57701 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied#第一次分割的關鍵字$splitKeyWord="#";#分割字串#函式說明:#將多個固定格式的字串分開,並回傳分開的結果#回傳的參數:#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段#必填參數:#$conf["stringIn"],字串陣列,要處理的字串陣列.$conf["stringProcess::spiltMutiString"]["stringIn"]=$callShell["output"];#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$splitKeyWord;$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);unset($conf["stringProcess::spiltMutiString"]);#如果分割失敗if($spiltMutiString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltMutiString;#回傳結果return $result;}#if end#儲存未處理的dns查詢字串$quertString=array();#儲存尚未處理好的字串$unProcessedStr=array();#初始化儲存原始log行內容$oriLog=array();#根據每筆記錄foreach($spiltMutiString["spiltString"] as $index => $splitStr){#如果切割出來小於兩段if($splitStr["dataCounts"]<2){#換下一筆資料continue;}#if end#取得原始log行內容$oriLog[]=$splitStr["oriStr"];#取得所需的字串$unProcessedStr[]=$splitStr["dataArray"][0];#儲存查詢的dns字串$quertString[]=$splitStr["dataArray"][1];}#foreach end#第二次分割的關鍵字$splitKeyWord=" ";#分割字串#函式說明:#將多個固定格式的字串分開,並回傳分開的結果#回傳的參數:#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段#必填參數:#$conf["stringIn"],字串陣列,要處理的字串陣列.$conf["stringProcess::spiltMutiString"]["stringIn"]=$unProcessedStr;#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$splitKeyWord;$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);unset($conf["stringProcess::spiltMutiString"]);#如果分割失敗if($spiltMutiString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltMutiString;#回傳結果return $result;}#if end#儲存有問題的IP$ips_named=array();#根據每筆記錄foreach($spiltMutiString["spiltString"] as $index => $splitStr){#取得所需的可能有問題的IP$ips_named[]=array("ip"=>$splitStr["dataArray"][$splitStr["dataCounts"]-1],"time"=>$splitStr["dataArray"][2],"log"=>$oriLog[$index]);}#foreach end#第三次分割的關鍵字$splitKeyWord=" ";#分割字串#函式說明:#將多個固定格式的字串分開,並回傳分開的結果#回傳的參數:#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段#必填參數:#$conf["stringIn"],字串陣列,要處理的字串陣列.$conf["stringProcess::spiltMutiString"]["stringIn"]=$quertString;#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$splitKeyWord;$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);unset($conf["stringProcess::spiltMutiString"]);#如果分割失敗if($spiltMutiString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltMutiString;#回傳結果return $result;}#if end#根據每筆記錄foreach($spiltMutiString["spiltString"] as $index=>$splitStr){#取得所需的可能有問題IP所查詢的dns$ips_named[$index]["dns"]=$splitStr["dataArray"][$splitStr["dataCounts"]-2];}#foreach end#初始化記錄時間點$time=0;#初始化記錄當前ip$ip="";#初始化記錄當前查詢的dns$dns="";#初始化記錄同時間,ip重複的次數.$count=0;#針對每筆資料for($i=0;$i<count($ips_named);$i++){#如果時間點不同if($ips_named[$i]["time"]!==$time){#初始化記錄時間點$time=$ips_named[$i]["time"];#初始化記錄當前ip$ip=$ips_named[$i]["ip"];#初始化記錄當前的dns$dns=$ips_named[$i]["dns"];#初始化記錄同時間,ip重複的次數.$count=1;}#if end#反之時間點相同且,但ip不同else if($ips_named[$i]["ip"]!==$ip){#初始化記錄時間點$time=$ips_named[$i]["time"];#初始化記錄當前ip$ip=$ips_named[$i]["ip"];#初始化記錄當前的dns$dns=$ips_named[$i]["dns"];#初始化記錄同時間,ip重複的次數.$count=1;}#if end#反之時間點相同,但dns不同else if($ips_named[$i]["dns"]!==$dns){#初始化記錄時間點$time=$ips_named[$i]["time"];#初始化記錄當前ip$ip=$ips_named[$i]["ip"];#初始化記錄當前的dns$dns=$ips_named[$i]["dns"];#初始化記錄同時間,ip重複的次數.$count=1;}#if end#反之時間點與IP與dns皆相同else{#計數+1$count++;#如果計數5次if($count===5){#若該IP是已經重複if(in_array($ips_named[$i]["ip"],$attacker_ips_namd)){#跳過continue;}#if end#反之是新IPelse{#記錄起來$attacker_ips_namd[]=$ips_named[$i];}#else end}#if end}#else end}#for end}#if end#透過 journalctl -a -e | grep dovecot | grep failed 來取得 IP#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="journalctl";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-a","-e","|","grep","dovecot","|","grep","failed");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#記錄攻擊者的IP$attacker_ips_imap=array();/* $callShell["output"] 範例截取結果Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MxQuPu+73xpliNc9>Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hH8xPu+7dBtliNc9>Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<nmI0Pu+7zhtliNc9>Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<1GU2Pu+7NBhliNc9>Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0Io5Pu+7sRhliNc9>Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zbQ+Pu+7rhlliNc9>Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0P5APu+7/BlliNc9>Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<gKRDPu+7XhpliNc9>Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<4hNHPu+77hpliNc9>Feb 23 00:25:00 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<belIPu+7bBtliNc9>Feb 23 00:25:00 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<VhRLPu+7xBtliNc9>Feb 23 00:46:19 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<loiMiu+7cxhliNc9>Feb 23 00:46:19 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<RNCQiu+7/xhliNc9>Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NWCTiu+7PBlliNc9>Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<2tiViu+7hBlliNc9>Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<w6Sbiu+7/xlliNc9>Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SkWkiu+7gBtliNc9>Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<bGCmiu+7qBtliNc9>Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0E+oiu+76RtliNc9>Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<FBGriu+7UhhliNc9>Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<AeSsiu+7iBhliNc9>Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<gpSuiu+70hhliNc9>Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zYfITPC7RBlliNc9>Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<GULMTPC7zhlliNc9>Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3jjOTPC7CBpliNc9>Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vhHQTPC7UBpliNc9>Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vArTTPC7rxpliNc9>Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hDTXTPC7GhtliNc9>Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<c6vZTPC7SRtliNc9>Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<rQzcTPC7jBtliNc9>Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<LSffTPC78htliNc9>Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<XLThTPC7KBhliNc9>Feb 23 01:40:40 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<tZfjTPC7dxhliNc9>Feb 23 03:27:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<i3bIyfG7AxtliNc9>Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0sLVyfG7uxtliNc9>Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<BJXZyfG7BhhliNc9>Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<xK3cyfG7SxhliNc9>Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<q43gyfG7aRhliNc9>Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Oj3syfG7FBlliNc9>Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SF7uyfG7RhlliNc9>Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<IM/wyfG7ZRlliNc9>Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<pXv1yfG7vBlliNc9>Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8ub4yfG7/xlliNc9>Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<H0j7yfG7NRpliNc9>Feb 23 06:10:07 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Zw6FEPS7WxhliNc9>Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vmKTEPS7cRpliNc9>Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SkOXEPS7BxtliNc9>Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<H42bEPS7WRtliNc9>Feb 23 06:10:09 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<jFqoEPS7SRhliNc9>Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<TNy4EPS7DhpliNc9>Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JYW7EPS7mBpliNc9>Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=</Ve+EPS76hpliNc9>Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<StLGEPS7qhtliNc9>Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<7RnLEPS7DBhliNc9>Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<6xTOEPS7eBhliNc9>Feb 23 06:29:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<YHy0VfS7uBhliNc9>Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<WLW4VfS7fxlliNc9>Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<lM66VfS73BlliNc9>Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Q4K9VfS7NxpliNc9>Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JiLBVfS7rRpliNc9>Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<DETIVfS7qxtliNc9>Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<UlLLVfS7GhhliNc9>Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<safNVfS7txhliNc9>Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<M/DQVfS7LxlliNc9>Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<+zPTVfS7eRlliNc9>Feb 23 06:29:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<dxXWVfS72hlliNc9>Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<S0pci/S7SxhliNc9>Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zThji/S78RhliNc9>Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8PJoi/S7ixlliNc9>Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Qkhui/S7PBpliNc9>Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SXVzi/S7hhtliNc9>Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=</X55i/S7uhhliNc9>Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MHJ9i/S74hlliNc9>Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<RBWBi/S7pRpliNc9>Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NJeGi/S7yhtliNc9>Feb 23 06:44:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<QsaMi/S7rxhliNc9>Feb 23 06:44:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8fiPi/S7uBlliNc9>Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<dt04yPS7KBlliNc9>Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<ZMI9yPS7WxpliNc9>Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<nTVAyPS7ARtliNc9>Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<wj1CyPS7lxtliNc9>Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<u7RFyPS7YRhliNc9>Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<tpBLyPS7ZhlliNc9>Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<CRdOyPS7wxlliNc9>Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<v9NQyPS7JxpliNc9>Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<81lUyPS73hpliNc9>Feb 23 07:01:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<PCZXyPS7TRtliNc9>Feb 23 07:01:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<VnNZyPS7qxtliNc9>Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<op+l9vS7ZxhliNc9>Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<aBCr9vS7CBlliNc9>Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0sOt9vS7dRlliNc9>Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NFaw9vS7xhlliNc9>Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<QS609vS7SRpliNc9>Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<4FW79vS76htliNc9>Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Fxu+9vS7gBhliNc9>Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3djA9vS75RhliNc9>Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hgzE9vS7mxlliNc9>Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<J8TG9vS7GBpliNc9>Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<t87I9vS7mBpliNc9>Feb 23 07:29:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<1xBILPW7MRtliNc9>Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<IXZNLPW79htliNc9>Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<6OdPLPW7chhliNc9>Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<M5BSLPW78hhliNc9>Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Nv9VLPW7UxlliNc9>Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<foJbLPW7KRpliNc9>Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<EoVeLPW7nxpliNc9>Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<DwNhLPW7JRtliNc9>Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<mKhkLPW7ohtliNc9>Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3nhnLPW7/htliNc9>Feb 23 07:29:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<e+lpLPW7XRhliNc9>Feb 23 07:44:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<KtTtYfW7dBhliNc9>Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MLTxYfW77BhliNc9>Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<9GL0YfW7KBlliNc9>Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JNT2YfW7fRlliNc9>Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8Zv5YfW72RlliNc9>Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<lbv/YfW73BpliNc9>Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<5zsCYvW7EBtliNc9>Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<aE8EYvW7bRtliNc9>Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<LEIHYvW75RtliNc9>Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<rLsJYvW7MRhliNc9>Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<9oMMYvW7ihhliNc9>Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<x7SUl/W7mBpliNc9>Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<k1KZl/W73xtliNc9>Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Veabl/W7PxhliNc9>Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Yamel/W7sxhliNc9>Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<wpGil/W7OBlliNc9>Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<+VCol/W7aBpliNc9>Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<TMaql/W7zhpliNc9>Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<KnKtl/W7GBtliNc9>Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Lkixl/W7ixtliNc9>Feb 23 07:59:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8bWzl/W7ARhliNc9>Feb 23 07:59:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<70q2l/W7PBhliNc9>*/#針對每列輸出foreach($callShell["output"] as $line){#用 " " 區分內容#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$line;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得時間$time=$spiltString["dataArray"][2];#用 "rip=" 切割#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$line;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]="rip=";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果不存在 client ip 字串if(!isset($spiltString["dataArray"][1])){#跳過continue;}#if end#取得含有 client IP 的字串$clientIpStr=$spiltString["dataArray"][1];#用 "," 切割#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$clientIpStr;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=",";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得來源ip$clientIp=$spiltString["dataArray"][0];#如果計數不存在if(!isset($attacker_ips_imap[$time][$clientIp])){#初始計數為1$attacker_ips_imap[$time][$clientIp]=1;#記錄log行內容$attacker_ips_imap[$time]["log"]=$line;}#if end#反之else{#計數加1$attacker_ips_imap[$time][$clientIp]++;}#else end}#foreach end#存放真正有問題的imap ip清單$ips_imap=array();#針對每個時間點foreach($attacker_ips_imap as $time=>$times){#針對每個列管的ipforeach($times as $ip => $count){#如果是logif($ip==="log"){#跳過continue;}#if end#如果累積次數達到3if($count>=3){#儲存有問題ip的資訊$info=array();#記錄 ip$info["ip"]=$ip;#記錄該行 log 內容$info["log"]=$attacker_ips_imap[$time]["log"];#記錄時間$info["time"]=$time;#記錄有問題的imap ip清單$ips_imap[]=$info;}#if end}#foreach end}#foreach end#記錄ssh攻擊者的IP$attacker_ips_ssh=array();#透過 journalctl -a -e | grep sshd | grep failed 來取得 ssh 攻擊者的 IP#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="journalctl";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-a","-e","|","grep","sshd","|","grep","failed");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end/*得到的範例輸出Apr 03 07:35:05 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858888]: USER_LOGIN pid=2858888 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="(unknown)" exe="/usr/sbin/sshd" hostname=? addr=81.30.179.11 terminal=ssh res=failed'Apr 03 07:35:07 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858891]: USER_AUTH pid=2858891 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'Apr 03 07:35:09 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858891]: USER_AUTH pid=2858891 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'Apr 03 07:35:12 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858891]: USER_AUTH pid=2858891 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'Apr 03 07:35:14 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858891]: USER_LOGIN pid=2858891 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="root" exe="/usr/sbin/sshd" hostname=? addr=49.88.112.77 terminal=ssh res=failed'Apr 03 07:35:22 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858896]: USER_AUTH pid=2858896 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'Apr 03 07:35:23 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858901]: USER_AUTH pid=2858901 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="bot" exe="/usr/sbin/sshd" hostname=103.149.27.65 addr=103.149.27.65 terminal=ssh res=failed'Apr 03 07:35:23 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858899]: USER_AUTH pid=2858899 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="insserver" exe="/usr/sbin/sshd" hostname=129.146.81.43 addr=129.146.81.43 terminal=ssh res=failed'Apr 03 07:35:24 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858896]: USER_AUTH pid=2858896 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'Apr 03 07:35:25 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858901]: USER_LOGIN pid=2858901 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="(unknown)" exe="/usr/sbin/sshd" hostname=? addr=103.149.27.65 terminal=ssh res=failed'Apr 03 07:35:25 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858899]: USER_LOGIN pid=2858899 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="(unknown)" exe="/usr/sbin/sshd" hostname=? addr=129.146.81.43 terminal=ssh res=failed'Apr 03 07:35:27 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858896]: USER_AUTH pid=2858896 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'Apr 03 07:35:29 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858896]: USER_LOGIN pid=2858896 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="root" exe="/usr/sbin/sshd" hostname=? addr=49.88.112.77 terminal=ssh res=failed'Mar 07 12:14:24 mail.qbpwcf.org sshd[3253686]: error: connect_to 127.0.0.1 port 5950: failed.*/#針對每列輸出foreach($callShell["output"] as $line){#用 "addr=" 區分內容#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$line;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]="addr=";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有找到分割用的關鍵字if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="true";#設置警告訊息$result["warning"][]=$spiltString;#跳過continue;}#if end#取得IP位址開頭的字串$ipStr=$spiltString["dataArray"][1];#用 " " 區分內容#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$ipStr;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有找到分割用的關鍵字if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得IP位址$ip=$spiltString["dataArray"][0];#用 " " 區分內容#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$line;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有找到分割用的關鍵字if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得含有秒數的時間點$timeWithSec=$spiltString["dataArray"][2];#用 ":" 區分內容#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$timeWithSec;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有找到分割用的關鍵字if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#時間包含到分鐘的字串$timeWithMin=$spiltString["dataArray"][0].":".$spiltString["dataArray"][1];#如果該時間分對應的ip不存在if(!isset($attacker_ips_ssh[$timeWithMin][$ip])){#初始化為1次$attacker_ips_ssh[$timeWithMin][$ip]["count"]=1;#記錄內容$attacker_ips_ssh[$timeWithMin][$ip]["line"][]=$line;}#if end#反之else{#計數+1$attacker_ips_ssh[$timeWithMin][$ip]["count"]++;#記錄內容$attacker_ips_ssh[$timeWithMin][$ip]["line"][]=$line;}#else end}#foreach end#透過 journalctl -a -e | grep sshd | grep 'Invalid user ' | grep ' from ' 來取得 ssh 攻擊者的 IP#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="journalctl";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-a","-e","|","grep","sshd","|","grep","Invalid user","|","grep"," from ");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#得到的範例輸出#Dec 22 15:51:48 mail.qbpwcf.org sshd[3518693]: Invalid user xl from 159.89.131.172 port 44458#debug#var_dump(__LINE__,$callShell["output"]);#針對每列輸出foreach($callShell["output"] as $line){#備份原始的內容$ori_line=$line;#移除多餘的資訊#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$line;#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" Invalid user ";#可省略參數:#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.#$conf["recursive"]="true";#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則回改回傳該內容.#$conf["lastResult"]=$delStrBeforeKeyWord;#參考資料:#無.#備註:#無.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#debug#var_dump(__LINE__,$delStrBeforeKeyWord);#如果執行失敗if($delStrBeforeKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果沒有理應存在內容if($delStrBeforeKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#取得需要的部分$line=$delStrBeforeKeyWord["content"];#解析 ip#函式說明:#將字串進行解析,取得兩個關鍵字中間的內容.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],取得的內容.#$result["oriStr"],原始的內容.#$result["found"],是否有找到符合條件的內容.#必填參數:#$conf["input"],字串,要處理的字串.$conf["stringProcess::getContentBetweenKeyWord"]["input"]=$line;#$conf["startKeyWord"],字串,開頭的關鍵字.$conf["stringProcess::getContentBetweenKeyWord"]["startKeyWord"]=" from ";#$conf["endKeyWord"],字串,結束的關鍵字.$conf["stringProcess::getContentBetweenKeyWord"]["endKeyWord"]=" port ";#可省略參數:#無.#參考資料:#無.#備註:#無.$getContentBetweenKeyWord=stringProcess::getContentBetweenKeyWord($conf["stringProcess::getContentBetweenKeyWord"]);unset($conf["stringProcess::getContentBetweenKeyWord"]);#如果執行失敗if($getContentBetweenKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getContentBetweenKeyWord;#回傳結果return $result;}#if end#如果沒有有該有的關鍵字if($getContentBetweenKeyWord["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getContentBetweenKeyWord;#回傳結果return $result;}#if end#取得ip$ip=$getContentBetweenKeyWord["content"];#解析time#用 " " 區分內容#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$ori_line;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有找到分割用的關鍵字if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得含有秒數的時間點$timeWithSec=$spiltString["dataArray"][2];#用 ":" 區分內容#函式說明:#將固定格式的字串分開,並回傳分開的結果。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$timeWithSec;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果分割失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有找到分割用的關鍵字if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#時間包含到分鐘的字串$timeWithMin=$spiltString["dataArray"][0].":".$spiltString["dataArray"][1];#如果該時間分對應的ip不存在if(!isset($attacker_ips_ssh[$timeWithMin][$ip])){#初始化為1次$attacker_ips_ssh[$timeWithMin][$ip]["count"]=1;#記錄內容$attacker_ips_ssh[$timeWithMin][$ip]["line"][]=$ori_line;}#if end#反之else{#計數+1$attacker_ips_ssh[$timeWithMin][$ip]["count"]++;#記錄內容$attacker_ips_ssh[$timeWithMin][$ip]["line"][]=$ori_line;}#else end}#foreach end#存放真正有問題的imap ip清單$ips_ssh=array();#針對每個時間點foreach($attacker_ips_ssh as $times){#針對每個列管的ipforeach($times as $ip => $info){#取得計數$count=$info["count"];#取得該行$ori_line=$info["line"];#如果累積次數達到3if($count>=3){#儲存該行log$info["log"]=$ori_line;#儲存ip$info["ip"]=$ip;#記錄有問題的imap ip清單$ips_ssh[]=$info;}#if end}#foreach end}#foreach end#合併取得的有問題IP集合#$ips,$ips_https,$ips_smtp,$ips_imap,$attacker_ips_namd,ips_ssh#函式說明:#將多個一維陣列串聯起來,key從0開始排序.#回傳的結果:#$result["status"],"true"表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式.#$result["content"],合併好的一維陣列.#必填參數:#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);$conf["arrays::mergeArray"]["inputArray"]=array($ips,$ips_https,$ips_smtp,$attacker_ips_namd,$ips_imap,$ips_ssh);#可省略參數:#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.$conf["arrays::mergeArray"]["allowRepeat"]="false";$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);unset($conf["arrays::mergeArray"]);#如果分割失敗if($mergeArray["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$mergeArray;#回傳結果return $result;}#if end#取得不重複的IP$ips=$mergeArray["content"];#取得防火牆的IP block清單#cmd:firewall-cmd --list-rich-rule#函式說明:#檢查指令的輸出是否含有關鍵字#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["grepCmd"],截取關鍵字的指令.#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.#$result["content"],關鍵字所在列的輸出.#必填參數:#$conf["cmd"],字串,要執行的指令.$conf["cmd::searchOutPut"]["cmd"]="firewall-cmd";#$conf["keyWord"],字串,要檢查是否有關鍵字.$conf["cmd::searchOutPut"]["keyWord"]=" reject";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".#$conf["binPath"]="";#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.$conf["cmd::searchOutPut"]["argu"]=array("--list-rich-rule");#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.#$conf["excludeGrep"]="false";#如果有設置 usernameif(isset($conf["username"])){#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["cmd::searchOutPut"]["username"]=$conf["username"];}#if end#如果有設置 passwordif(isset($conf["password"])){#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["cmd::searchOutPut"]["password"]=$conf["password"];}#if end$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);unset($conf["cmd::searchOutPut"]);#如果執行失敗if($searchOutPut["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$searchOutPut;#回傳結果return $result;}#if end#初始化儲存已封鎖IP的陣列$ips_blocked=array();#如果有找到關鍵字 " reject"if($searchOutPut["founded"]==="true"){#用 " 來分割每列字串#函式說明:#將多個固定格式的字串分開,並回傳分開的結果#回傳的參數:#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段#必填參數:#$conf["stringIn"],字串陣列,要處理的字串陣列.$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.$conf["stringProcess::spiltMutiString"]["spiltSymbol"]="\"";$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);unset($conf["stringProcess::spiltMutiString"]);#如果分割失敗if($spiltMutiString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltMutiString;#回傳結果return $result;}#if end#針對每行分割出來的內容for($i=0;$i<$searchOutPut["count"];$i++){#如果不存在 IPif(!isset($spiltMutiString["spiltString"][$i]["dataArray"][3])){#跳過continue;}#if end#取得封鎖的IP位置$ips_blocked[]=$spiltMutiString["spiltString"][$i]["dataArray"][3];}#for end}#if end#儲存有問題的IP資訊陣列#$ips;#儲存已封鎖IP的陣列#$ips_blocked;#初始化要封鎖的ip資訊$ips_to_block=array();#留下未阻擋的有問題IP#針對每個有問題的ip資訊foreach($ips as $info){#函式說明:#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.#回傳結果:#$result["status"],"true"表示執行正確,"false"表示執行錯誤.#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.#$result["error"],錯誤訊息#$result["function"],當前執行的函數名稱#$result["argv"],使用的參數#$result["equalVarName"],相等的變數名稱或key.#$result["equalVarValue"],相等的變數數值內容.#必填參數:#$conf["conditionElement"],字串,條件元素,要等於的元素內容.$conf["search::getEqualVar"]["conditionElement"]=$info["ip"];#$conf["compareElements"],字串陣列,要比對的陣列變數內容.$conf["search::getEqualVar"]["compareElements"]=$ips_blocked;#可省略參數:#無.#參考資料:#無.#備註:#無.$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);unset($conf["search::getEqualVar"]);#如果執行失敗if($getEqualVar["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getEqualVar;#回傳結果return $result;}#if end#如果ip尚未被封鎖if($getEqualVar["founded"]==="false"){#儲存要封鎖的ip資訊$ips_to_block[]=$info;}#if end}#foreach end#如果沒有未阻擋的有問題 IPif(count($ips_to_block)===0){#設置執行成功$result["status"]="true";#回傳結果return $result;}#if end#如果要阻擋IPif($conf["getIplistOnly"]==="false"){#針對每個有問題的IP資訊foreach($ips_to_block as $info){#檢查該ip是否在白名單裡面#函式說明:#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.#回傳結果:#$result["status"],"true"表示執行正確,"false"表示執行錯誤.#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.#$result["error"],錯誤訊息#$result["function"],當前執行的函數名稱#$result["argv"],使用的參數#$result["equalVarName"],相等的變數名稱或key.#$result["equalVarValue"],相等的變數數值內容.#必填參數:$conf["search::getEqualVar"]["conditionElement"]=$info["ip"];#條件元素,要等於的元素內容.$conf["search::getEqualVar"]["compareElements"]=$conf["excludeIp"];#要比對的陣列變數內容.#可省略參數:#無.#備註:#無.$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);unset($conf["search::getEqualVar"]);#如果執行失敗if($getEqualVar["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getEqualVar;#回傳結果return $result;}#if end#如果在白名單ip裡面if($getEqualVar["founded"]==="true"){#跳過該ipcontinue;}#if end#如果不是要動態阻擋if($conf["dynamic"]==="false"){#函式說明:#呼叫shell依序執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完每個指令後的輸出陣列.#必填參數:#$conf["command"],字串陣列,要執行的指令.$conf["external::callShellMulti"]["command"]=array("echo");#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.$conf["external::callShellMulti"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.$conf["external::callShellMulti"]["argu"]=array(array($info["ip"],"|","block_ip.sh"));#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.#$conf["enablePrintDescription"]=array("false");#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.#$conf["printDescription"]=array("");#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.$conf["external::callShellMulti"]["escapeshellarg"]=array("true");#如果有設置 usernameif(isset($conf["username"])){#$conf["username"],陣列字串,每個指令要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["external::callShellMulti"]["username"]=array($conf["username"]);}#if end#如果有設置 passwordif(isset($conf["password"])){#$conf["password"],陣列字串,每個指令與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["external::callShellMulti"]["password"]=array($conf["password"]);}#if end#$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指令無法執行.#參考資料:#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$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);unset($conf["external::callShellMulti"]);#如果執行失敗if($callShellMulti["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShellMulti;#回傳結果return $result;}#if end}#if end#反之是要動態阻擋else{#函式說明:#呼叫shell依序執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令內容.#$result["output"],爲執行完每個指令後的輸出陣列.#必填參數:#$conf["command"],字串陣列,要執行的指令.$conf["external::callShellMulti"]["command"]=array("echo");#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.$conf["external::callShellMulti"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.$conf["external::callShellMulti"]["argu"]=array(array($info["ip"],"|","block_ip_tmp.sh"));#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.#$conf["enablePrintDescription"]=array("false");#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.#$conf["printDescription"]=array("");#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.$conf["external::callShellMulti"]["escapeshellarg"]=array("true");#如果有設置 usernameif(isset($conf["username"])){#$conf["username"],陣列字串,每個指令要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["external::callShellMulti"]["username"]=array($conf["username"]);}#if end#如果有設置 passwordif(isset($conf["password"])){#$conf["password"],陣列字串,每個指令與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["external::callShellMulti"]["password"]=array($conf["password"]);}#if end#$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指令無法執行.#參考資料:#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$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);unset($conf["external::callShellMulti"]);}#else end#如果執行失敗if($callShellMulti["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShellMulti;#回傳結果return $result;}#if end#取得每次執行的結果$result["content"][]=$callShellMulti;#儲存特定ip被阻擋的資訊$result["reason"][$info["ip"]]=$info;}#foreach end}#if end#反之else{#取得有問題的IP資訊清單$result["content"]=$ips_to_block;}#else end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function blockAcctackIp end/*#函式說明:#執行 systemd 程序來管理服務.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],執行的結果.#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#$conf["name"],字串,服務名稱.$conf["name"]="";#可省略參數:#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".#$conf["operation"]="";#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者#$conf["username"]="";#$conf["password"],字串,使用者的密碼,預設不使用.#$conf["password"]="";#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.#$conf["daemonReload"]="true";#參考資料:#無.#備註:#無.*/public static function systemd(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("operation","username","password","daemonReload");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("list","root",null,"false");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數失敗if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果要 reload daemonif($conf["daemonReload"]==="true"){#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="systemctl";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("daemon-reload");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#如果有設置 $conf["username"]if(isset($conf["username"])){#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["external::callShell"]["username"]=$conf["username"];}#if end#如果有設置 $conf["password"]if(isset($conf["password"])){#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["external::callShell"]["password"]=$conf["password"];}#if end#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.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["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#取得運行結果$result["content"]=$callShell["output"];#設置執行成功$result["status"]="true";#回傳結果return $result;}#if end#判斷 $conf["operation"]switch($conf["operation"]){#如果是 listcase "list":#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="systemctl";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.#$conf["external::callShell"]["argu"]=array("2>&1");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#如果有設置 $conf["username"]if(isset($conf["username"])){#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["external::callShell"]["username"]=$conf["username"];}#if end#如果有設置 $conf["password"]if(isset($conf["password"])){#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["external::callShell"]["password"]=$conf["password"];}#if end#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.$conf["external::callShell"]["getErr"]="true";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#取得運行結果$result["content"]=$callShell["output"];#設置執行成功$result["status"]="true";#回傳結果return $result;#跳出 switchbreak;#其他操作case "enable":case "disable":case "start":case "stop":case "restart":case "status":#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="systemctl";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($conf["operation"],$conf["name"]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#如果有設置 $conf["username"]if(isset($conf["username"])){#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["external::callShell"]["username"]=$conf["username"];}#if end#如果有設置 $conf["password"]if(isset($conf["password"])){#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.$conf["external::callShell"]["password"]=$conf["password"];}#if end#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.$conf["external::callShell"]["getErr"]="true";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){if($callShell["statusCode"]!==1 && $callShell["statusCode"]!==3){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end}#if end#取得運行結果$result["content"]=$callShell["output"];#如果運作參數是 "status"if($conf["operation"]==="status"){#"Active: inactive (dead)"#"Active: active (running)"#"Active: failed"#"service; enabled; "#"service; disabled; "#函式說明:#檢查多個字串中的每個字串是否有多個關鍵字#回傳的結果:#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。#$result["function"],當前執行的函式名稱.#$result["error"],錯誤訊息.#$result["foundedTrueKey"],結果為"true"的元素key陣列。#$result["foundedTrueKeyWords"],有找到的關鍵字陣列.#$result["foundedFalseKey"],結果為"false"的元素key陣列。#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.#必填參數:$keyWordToFind=$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("Active: inactive (dead)","Active: active (running)","service; enabled;","service; disabled;","Active: failed","Active: deactivating");#想要搜尋的關鍵字$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$result["content"];#要被搜尋的字串內容陣列#可省略參數:#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);unset($conf["search::findManyKeyWordsFromManyString"]);#如果執行失敗if($findManyKeyWordsFromManyString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$findManyKeyWordsFromManyString;#回傳結果return $result;}#if end#服務狀態的計數$serverStaCount=count($findManyKeyWordsFromManyString["foundedTrueKey"]);#如果沒有剛好取得服務的兩個狀態if($serverStaCount!==2){#設置執行失敗$result["status"]="false";#提示錯誤$result["error"][]="取得啟動狀態與啟用狀態失敗";#設置錯誤訊息$result["error"][]=$findManyKeyWordsFromManyString;#回傳結果return $result;}#if end#針對每個服務狀態foreach($findManyKeyWordsFromManyString["foundedKeyWords"] as $statusDesc){#判斷服務狀態switch($statusDesc){#未啟動case "Active: inactive (dead)":case "Active: failed":case "Active: deactivating":#設置未啟動的識別$result["content"]["srerviceInfo"]["on"]="false";#跳出 switchbreak;#啟動case "Active: active (running)":#設置啟動的識別$result["content"]["srerviceInfo"]["on"]="true";#跳出 switchbreak;#啟用,開機自動啟動case "service; enabled;":#設置啟動的識別$result["content"]["srerviceInfo"]["auto"]="true";#跳出 switchbreak;#未啟用,開機不啟動case "service; disabled;":#設置啟動的識別$result["content"]["srerviceInfo"]["auto"]="false";#跳出 switchbreak;#無法判斷的服務狀態default:#設置執行失敗$result["status"]="false";#提示錯誤$result["error"][]="無法識別的內容「".$statusDesc."」";#設置錯誤訊息$result["error"][]=$findManyKeyWordsFromManyString;#回傳結果return $result;}#switch end}#for end}#if end#設置執行成功$result["status"]="true";#回傳結果return $result;#跳出 switchbreak;#不允許的操作default :#設置執行失敗識別$result["status"]="false";#設置錯誤訊息$result["error"][]="operatio \"".$conf["operation"]."\" is not allowed.";#回傳結果return $result;}#switch end}#function systemd end/*#函式說明:#執行 systemd 程序來確保服務是運行中.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],執行的結果.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileArgu"]=__FILE__;#$conf["name"],字串,服務名稱.$conf["name"]="";#可省略參數:#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者#$conf["username"]="";#$conf["password"],字串,使用者的密碼,預設不使用.#$conf["password"]="";#$conf["checkListen"],陣列,用來判斷服務是否有正確啟動的條件,一個元素代表,其中要有一個socket info符合之,若元素的key為"ip",則其數值為[ipv4/ipv6]:port:protocol(tcp/udp);若元素的key為"addr",則其數值為unix domain socket 的位置與名稱;若元素的key為"name",則其數值為程序名稱.#$conf["checkListen"]=array(array("ip"=>169.254.1.1:443/tcp,"addr"=>/usr/lib/qbpwcf/qbpwcf-usock.sock,"name"=>"addr"),"name"=>"httpd");#$conf["interval"],字串,檢查沒問題後,要多少秒後再檢查一次,預設為30秒,亦即"30".#$conf["interval"]="30";#$conf["reportOnly"],字串,"true"代表不「啟動/重新啟動」服務,只是輸出訊息表示服務有正常或需要處理;預設為"false"代表直接「啟動/重新啟動」.#$conf["reportOnly"]="true";#$conf["verbose"],字串,預設為"false",若為"true"則會印出過程訊息.#$conf["verbose"]="true";#$conf["onlyWhenEnable"],字串,預設為"true",代表若服務為enable才會將其變成運行中;反之為"false".#$conf["onlyWhenEnable"]="false";#參考資料:#無.#備註:#無.*/public static function keepServiceUp(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","checkListen","interval","reportOnly","verbose","onlyWhenEnable");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","string","string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("root",null,null,"30","false","false","true");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數失敗if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#無窮迴圈while(true){#如果有啟用 verboseif($conf["verbose"]==="true"){#提示正在檢查echo "start checking...".PHP_EOL;}#if end#查詢服務啟動沒#函式說明:#執行 systemd 程序來管理服務.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],執行的結果.#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];#$conf["name"],字串,服務名稱.$conf["cmd::systemd"]["name"]=$conf["name"];#可省略參數:#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".$conf["cmd::systemd"]["operation"]="status";#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者#$conf["cmd::systemd"]["username"]="";#如果有設定密碼if(isset($conf["password"])){#$conf["password"],字串,使用者的密碼,預設不使用.$conf["cmd::systemd"]["password"]=$conf["password"];}#if end$systemd=cmd::systemd($conf["cmd::systemd"]);unset($conf["cmd::systemd"]);#若運行出錯if($systemd["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$systemd;#回傳結果return $result;}#if end#如果只處理有設置enable的服務if($conf["onlyWhenEnable"]==="true"){#如果服務沒有 enableif($systemd["content"]["srerviceInfo"]["auto"]==="false"){#過30秒再檢查一次sleep($conf["interval"]);#下一輪continue;}#if end}#if end#如果服務沒啟動if($systemd["content"]["srerviceInfo"]["on"]==="false"){#如果 verbose 為 "true"if($conf["verbose"]==="true"){#印出提示echo "service ".$conf["name"]." down.".PHP_EOL;}#if end#如果只要 Reportif($conf["reportOnly"]==="true"){#輸出echo "service ".$conf["name"]." need to start!";#下一輪continue;}#if end#啟動服務#函式說明:#執行 systemd 程序來管理服務.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],執行的結果.#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];#$conf["name"],字串,服務名稱.$conf["cmd::systemd"]["name"]=$conf["name"];#可省略參數:#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".$conf["cmd::systemd"]["operation"]="start";#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者#$conf["username"]="";#$conf["password"],字串,使用者的密碼,預設不使用.#$conf["password"]="";$systemd=cmd::systemd($conf["cmd::systemd"]);unset($conf["cmd::systemd"]);#若運行出錯if($systemd["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$systemd;#回傳結果return $result;}#if end#如果 verbose 為 "true"if($conf["verbose"]==="true"){#印出提示echo "service ".$conf["name"]." started.".PHP_EOL;}#if end#下一輪continue;}#if end#如果有啟用 verboseif($conf["verbose"]==="true"){#提示正在檢查echo "service seems up.".PHP_EOL;}#if end#如果有指定 checkListen陣列if(isset($conf["checkListen"])){#如果有指定 socket info 的條件if(count($conf["checkListen"])>0){#如果有啟用 verboseif($conf["verbose"]==="true"){#提示正在檢查echo "need check socket info.".PHP_EOL;}#if end#針對每個 socket 的 infosforeach($conf["checkListen"] as $checkListen){#如果有啟用 verboseif($conf["verbose"]==="true"){#提示正在檢查echo "parse socket condition...".PHP_EOL;}#if end#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$checkListen;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("ip","addr","name");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("ip","addr","name");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數失敗if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#debug#echo "check arguments ok!".PHP_EOL;#初始化找到的 socket 資訊$foundSocketInfo=array();#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.#回傳結果:#$result["status"],"true"代表執行正常;"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["sock::execAnyCmdbyQBPWCFunixSocket"]["fileArgu"]=$conf["fileArgu"];#$conf["command"],字串,要執行的指令名稱.$conf["sock::execAnyCmdbyQBPWCFunixSocket"]["command"]="ss";#可省略參數:#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.#$conf["sock"]=qbpwcf_usock_path;#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["sock::execAnyCmdbyQBPWCFunixSocket"]["argu"]=array("-n","-p","-O","-l");#參考資料:#無.#備註:#無.$execAnyCmdbyQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdbyQBPWCFunixSocket"]);unset($conf["sock::execAnyCmdbyQBPWCFunixSocket"]);#如果執行失敗if($execAnyCmdbyQBPWCFunixSocket["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$execAnyCmdbyQBPWCFunixSocket;#回傳結果return $result;}#if end#debug#var_dump($execAnyCmdbyQBPWCFunixSocket["content"]);#函式說明:#解析 ss 指令的輸出#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["columns"],解析好的欄位名稱陣列.#$result["content"],解析好的內容陣列.#必填參數:#$conf["input"],字串陣列,要解析的內容,包含header.$conf["parser::ss"]["input"]=$execAnyCmdbyQBPWCFunixSocket["content"];#可省略參數:#無.#參考資料:#無.#備註:#無.$ss=parser::ss($conf["parser::ss"]);unset($conf["parser::ss"]);#如果執行失敗if($ss["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$ss;#回傳結果return $result;}#if end#debug#var_dump($ss);#如果沒有 Netid 欄位if(!isset($ss["content"]["Netid"])){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="Netid column data not found";#設置錯誤訊息$result["error"][]=$ss;#回傳結果return $result;}#if end#如果有ip條件if(isset($checkListen["ip"])){#取得ip條件$listenInfo=$checkListen["ip"];#函式說明:#將固定格式的字串分開,並回傳分開的結果.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$listenInfo;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";#參考資料:#無.#備註:#無.$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果執行失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有分割用的關鍵字if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有切成兩段if($spiltString["dataCounts"]!==2){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得 listen ip$ip=$spiltString["dataArray"][0];#函式說明:#將固定格式的字串分開,並回傳分開的結果.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$spiltString["dataArray"][1];#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";#參考資料:#無.#備註:#無.$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果執行失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有分割用的關鍵字if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有切成兩段if($spiltString["dataCounts"]!==2){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得 listen port$port=$spiltString["dataArray"][0];#取得 listen protocol$protocol=$spiltString["dataArray"][1];#如果 verbose 為 "true"if($conf["verbose"]==="true"){#印出提示echo "check ip=".$ip." of service ".$conf["name"].PHP_EOL;#印出提示echo "check port=".$port." of service ".$conf["name"].PHP_EOL;#印出提示echo "check protocol=".$protocol." of service ".$conf["name"].PHP_EOL;}#if end#如果 protocol 不是 tcp 也不是 udpif($protocol!=="tcp" && $protocol!=="udp"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="protocol should be tcp or udp";#設置錯誤訊息$result["error"][]=$spiltString;#回傳結果return $result;}#if end#如果沒有 "Local Address:Port" 欄位if(!isset($ss["content"]["Local Address:Port"])){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="Local Address:Port column data not found";#設置錯誤訊息$result["error"][]=$ss;#回傳結果return $result;}#if end#預設沒有通過檢查$pass="false";#要搜尋的ip$ips=array();#要搜尋的ip關鍵字$ips[]=$ip;#如果不是 ipv6,亦即為ipv4.if(strpos($ip,":")!==false){#函式說明:#將ipv4轉換成ipv6#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],取得的回應內容.#$result["argu"],使用的參數.#必填參數:#$conf["ipv4"],字串,人可讀的ipv4字串.$Conf["csInformation::ipv4toipv6"]["ipv4"]=$ip;#可省略參數:#無.#參考資料:#http://benjr.tw/17314#https://www.ultratools.com/tools/ipv4toipv6#備註:#無.$ipv4toipv6=csInformation::ipv4toipv6($Conf["csInformation::ipv4toipv6"]);unset($Conf["csInformation::ipv4toipv6"]);#如果執行失敗if($ipv4toipv6["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$ipv4toipv6;#回傳結果return $result;}#if end#要搜尋的ipv6關鍵字$ips[]=$ipv4toipv6["content"];}#if end#針對每筆資料foreach($ss["content"]["Local Address:Port"] as $index => $localAddrPort){#尋找符合的 Local Address#函式說明:#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.#回傳結果:#$result["status"],"true"表示執行正確,"false"表示執行錯誤.#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.#$result["error"],錯誤訊息#$result["function"],當前執行的函數名稱#$result["argv"],使用的參數#$result["equalVarName"],相等的變數名稱或key.#$result["equalVarValue"],相等的變數數值內容.#必填參數:#$conf["conditionElement"],字串,條件元素,要等於的元素內容.$conf["search::getEqualVar"]["conditionElement"]=$localAddrPort["addr"];#$conf["compareElements"],字串陣列,要比對的陣列變數內容.$conf["search::getEqualVar"]["compareElements"]=$ips;#可省略參數:#無.#參考資料:#無.#備註:#無.$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);unset($conf["search::getEqualVar"]);#如果執行失敗if($getEqualVar["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getEqualVar;#回傳結果return $result;}#if end#如果無找到同 addr 的資料if($getEqualVar["founded"]==="fasle"){#下一輪continue;}#if end#尋找符合的 Port#函式說明:#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.#回傳結果:#$result["status"],"true"表示執行正確,"false"表示執行錯誤.#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.#$result["error"],錯誤訊息#$result["function"],當前執行的函數名稱#$result["argv"],使用的參數#$result["equalVarName"],相等的變數名稱或key.#$result["equalVarValue"],相等的變數數值內容.#必填參數:#$conf["conditionElement"],字串,條件元素,要等於的元素內容.$conf["search::getEqualVar"]["conditionElement"]=$localAddrPort["port"];#$conf["compareElements"],字串陣列,要比對的陣列變數內容.$conf["search::getEqualVar"]["compareElements"]=array($port);#可省略參數:#無.#參考資料:#無.#備註:#無.$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);unset($conf["search::getEqualVar"]);#如果執行失敗if($getEqualVar["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getEqualVar;#回傳結果return $result;}#if end#如果無找到同 port 的資料if($getEqualVar["founded"]==="fasle"){#下一輪continue;}#if end#執行到這邊代表有找到同 ip:port 的資料#若 protocol 正確if($ss["content"]["Netid"][$index]===$protocol){#設置通過檢查$pass="true";}#if end}#foreach end#如果沒有符合的 ip:portif($pass==="false"){#提示問題echo "service ".$conf["name"]." ip and port not match!".PHP_EOL;#如果 verbose 為 "true"if($conf["verbose"]==="true"){#提示搜尋過的內容echo "searched socket list:".PHP_EOL;var_dump($ss["content"]["Local Address:Port"]);}#if end#如果只要 Reportif($conf["reportOnly"]==="true"){#輸出echo "service ".$conf["name"]." need to restart!".PHP_EOL;#下一輪continue;}#if end#啟動服務#函式說明:#執行 systemd 程序來管理服務.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],執行的結果.#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];#$conf["name"],字串,服務名稱.$conf["cmd::systemd"]["name"]=$conf["name"];#可省略參數:#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".$conf["cmd::systemd"]["operation"]="start";#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者#$conf["username"]="";#$conf["password"],字串,使用者的密碼,預設不使用.#$conf["password"]="";$systemd=cmd::systemd($conf["cmd::systemd"]);unset($conf["cmd::systemd"]);#若運行出錯if($systemd["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$systemd;#回傳結果return $result;}#if end#下一輪continue;}#if end}#if end, ip condition end#如果有指定 addrif(isset($checkListen["addr"])){#取得addr資訊$listenInfo=$checkListen["addr"];#如果沒有 "Local Address:Port" 欄位if(!isset($ss["content"]["Local Address:Port"])){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="Local Address:Port column data not found";#設置錯誤訊息$result["error"][]=$ss;#回傳結果return $result;}#if end#預設沒有通過檢查$pass="false";#初始化關鍵字$keyWord=array();#新增關鍵字 unix socket domain$keyWord[]=$listenInfo;#針對每筆資料foreach($ss["content"]["Local Address:Port"] as $index => $localAddrPort){#如果是字串if(gettype($localAddrPort)==="string"){#置換成陣列$localAddrPort=array($localAddrPort);}#if end#尋找符合的 Local Address:Port#函式說明:#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.#回傳結果:#$result["status"],"true"表示執行正確,"false"表示執行錯誤.#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.#$result["error"],錯誤訊息#$result["function"],當前執行的函數名稱#$result["argv"],使用的參數#$result["equalVarName"],相等的變數名稱或key.#$result["equalVarValue"],相等的變數數值內容.#必填參數:#$conf["conditionElement"],字串,條件元素,要等於的元素內容.$conf["search::getEqualVar"]["conditionElement"]=$localAddrPort;#$conf["compareElements"],字串陣列,要比對的陣列變數內容.$conf["search::getEqualVar"]["compareElements"]=$keyWord;#可省略參數:#無.#參考資料:#無.#備註:#無.$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);unset($conf["search::getEqualVar"]);#如果執行失敗if($getEqualVar["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getEqualVar;#回傳結果return $result;}#if end#如果有找到同 unix domain socket 的資料if($getEqualVar["founded"]==="true"){#初始化 剩下要搜尋的 socket list 資訊$new_ss["content"]=array();#針對每個欄位foreach($ss["columns"] as $columnName){#取得欄位對應的資料內容$new_ss["content"][$columnName][]=$ss["content"][$columnName][$index];}#foreach end#更新要搜尋的 socket list 資訊$ss["content"]=$new_ss["content"];#設置通過檢查$pass="true";}#if end}#foreach end#如果沒有符合的 unix domain socketif($pass==="false"){#提示問題echo "service ".$conf["name"]." unix domain socket not match!".PHP_EOL;#如果 verbose 為 "true"if($conf["verbose"]==="true"){#提示搜尋過的內容echo "searched socket list:".PHP_EOL;var_dump($ss["content"]["Local Address:Port"]);}#if end#如果只要 Reportif($conf["reportOnly"]==="true"){#輸出echo "service ".$conf["name"]." need to restart!".PHP_EOL;#下一輪continue;}#if end#啟動服務#函式說明:#執行 systemd 程序來管理服務.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],執行的結果.#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];#$conf["name"],字串,服務名稱.$conf["cmd::systemd"]["name"]=$conf["name"];#可省略參數:#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".$conf["cmd::systemd"]["operation"]="start";#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者#$conf["username"]="";#$conf["password"],字串,使用者的密碼,預設不使用.#$conf["password"]="";$systemd=cmd::systemd($conf["cmd::systemd"]);unset($conf["cmd::systemd"]);#若運行出錯if($systemd["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$systemd;#回傳結果return $result;}#if end#下一輪continue;}#if end}#if end#如果有指定 nameif(isset($checkListen["name"])){#取得name資訊$listenInfo=$checkListen["name"];#如果沒有 "Process" 欄位if(!isset($ss["content"]["Process"])){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="Process column data not found";#設置錯誤訊息$result["error"][]=$ss;#回傳結果return $result;}#if end#預設沒有通過檢查$pass="false";#針對每筆資料foreach($ss["content"]["Process"] as $index => $Process){#尋找符合的 Process#函式說明:#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.#回傳結果:#$result["status"],"true"表示執行正確,"false"表示執行錯誤.#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.#$result["error"],錯誤訊息#$result["function"],當前執行的函數名稱#$result["argv"],使用的參數#$result["equalVarName"],相等的變數名稱或key.#$result["equalVarValue"],相等的變數數值內容.#必填參數:#$conf["conditionElement"],字串,條件元素,要等於的元素內容.$conf["search::getEqualVar"]["conditionElement"]=$listenInfo;#$conf["compareElements"],字串陣列,要比對的陣列變數內容.$conf["search::getEqualVar"]["compareElements"]=$Process;#可省略參數:#無.#參考資料:#無.#備註:#無.$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);unset($conf["search::getEqualVar"]);#如果執行失敗if($getEqualVar["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getEqualVar;#回傳結果return $result;}#if end#如果有找到同 Process 的資料if($getEqualVar["founded"]==="true"){#設置通過檢查$pass="true";}#if end}#foreach end#如果沒有符合的 process program nameif($pass==="false"){#提示問題echo "service ".$conf["name"]." process program name not match!".PHP_EOL;#如果只要 Reportif($conf["reportOnly"]==="true"){#輸出echo "service ".$conf["name"]." need to restart!".PHP_EOL;;#下一輪continue;}#if end#啟動服務#函式說明:#執行 systemd 程序來管理服務.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],執行的結果.#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];#$conf["name"],字串,服務名稱.$conf["cmd::systemd"]["name"]=$conf["name"];#可省略參數:#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".$conf["cmd::systemd"]["operation"]="start";#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者#$conf["username"]="";#$conf["password"],字串,使用者的密碼,預設不使用.#$conf["password"]="";$systemd=cmd::systemd($conf["cmd::systemd"]);unset($conf["cmd::systemd"]);#若運行出錯if($systemd["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$systemd;#回傳結果return $result;}#if end#下一輪continue;}#if end}#if end#如果有 verboseif($conf["verbose"]==="true"){#提示什麼條件檢查通過echo " condition ";#針對每個條件foreach($checkListen as $name => $value){#印出條件echo $name." = ".$value;}#for end#印出結果echo " passed".PHP_EOL;}#if end}#foreach end}#if end}#if end#過30秒再檢查一次sleep($conf["interval"]);#下一輪continue;}#while end}#function keepServiceUp end/*#函式說明:#將要執行的程式變成透過 systemd 來運行.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],執行的結果.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.$conf["fileArgu"]=__FILE__;#$conf["name"],字串,服務名稱,實際產生的system名稱會加上".service".$conf["name"]="";#$conf["cmd"],字串,要執行的指令.$conf["cmd"]="";#可省略參數:#$conf["params"],字串陣列,指令要使用的參數.#$conf["params"]=array("");#$conf["enable"],字串,預設為"true",代表該服務為enable.#$conf["enable"]="true";#$conf["startNow"],字串,預設為"true",代表該服務要立刻執行.#$conf["startNow"]="true";#參考資料:#無.#備註:#無.*/public static function registerService(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name","cmd");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("params","enable","startNow","description");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("params","enable","startNow","description");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$c)onf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true","true","service description.");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數失敗if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#初始化要寫入到服務檔案的內容陣列$serviceFileContent=array();#服務的 Unit 識別$serviceFileContent[]="[Unit]";#服務的描述$serviceFileContent[]="Description= ".$conf["description"];#空一行$serviceFileContent[]="";#網路連線後才執行該服務$serviceFileContent[]="After=network-pre.target dbus.service network.target network.service httpd.service";#空一行$serviceFileContent[]="";#服務的 Service 識別$serviceFileContent[]="[Service]";#服務類型$serviceFileContent[]="Type=simple";#用root身份執行$serviceFileContent[]="User=root";#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]=$conf["cmd"];#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#如果有參數if(isset($conf["params"])){#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$conf["params"];}#if end#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.$conf["external::callShell"]["doNotRun"]="true";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果檢查參數失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#組合完整指令字串#函式說明:#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的function名稱#$result["error"],錯誤訊息陣列.#$result["content"],處理好的字串.#$result["argu"],使用的參數.#必填參數:#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.$conf["arrays::arrayToString"]["inputArray"]=$callShell["escape"]["array"];#可省略參數:#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;$conf["arrays::arrayToString"]["spiltSymbol"]=" ";#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。$conf["arrays::arrayToString"]["skipEnd"]="true";#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.#$conf["spiltSymbolAtStart"]="";#參考資料:#無.#備註:#無.$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);unset($conf["arrays::arrayToString"]);#如果轉換成字串失敗if($arrayToString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$arrayToString;#回傳結果return $result;}#if end#完整指令$fullCmd=$arrayToString["content"];#要執行的程式與參數$serviceFileContent[]="ExecStart=".$fullCmd;#重新執行的程式與參數$serviceFileContent[]="ExecReload=killall ".$conf["cmd"]."; sleep 10; ".$fullCmd;#執行失敗後,會再次嘗試執行$serviceFileContent[]="Restart=on-failure";#沒有timeout$serviceFileContent[]="TimeoutSec=infinity";#空一行$serviceFileContent[]="";#服務的 Install 識別$serviceFileContent[]="[Install]";#預設為 multi-user.target$serviceFileContent[]="WantedBy=multi-user.target";#建立 service 檔案#函式說明:#將多行字串寫入到檔案#回傳結果:#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行函數的名稱.#必填參數:#$conf["fileName"],字串,爲要編輯的檔案名稱$conf["fileAccess::writeMultiLine"]["fileName"]="/etc/systemd/system/".$conf["name"].".service";#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。$conf["fileAccess::writeMultiLine"]["inputString"]=$serviceFileContent;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。#參考資料:#無.#備註:#無.$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);unset($conf["fileAccess::writeMultiLine"]);#如果建立服務檔案失敗if($writeMultiLine["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$writeMultiLine;#回傳結果return $result;}#if end#如果要 enable 服務if($conf["enable"]==="true"){#啟用服務#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="systemctl";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("enable",$conf["name"].".service");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end}#if end#如果要馬上 start 服務if($conf["startNow"]){#啟動服務#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="systemctl";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("start",$conf["name"].".service");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function registerService end/*#函式說明:#透過 ping -c 3 -I [ppp0/網路界面名稱] 1.1.1.1 ,來判斷是否該界面有跟外部連線。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],執行的結果.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#$conf["interface"],字串,網路界面名稱.$conf["interface"]="";#可省略參數:#$conf["pingTarget"],"字串",要ping的目標,預設為"1.1.1.1".#$conf["pingTarget"]="";#參考資料:#無.#備註:#無.*/public static function pingOutsideTest(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","interface");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pingTarget");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("1.1.1.1");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數失敗if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數#$conf["command"],字串,要執行的指令與.$conf["external::callShell"]["command"]="ping";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-c","3","-I",$conf["interface"],$conf["pingTarget"]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".$conf["external::callShell"]["escapeshellarg"]="true";#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.$conf["external::callShell"]["username"]="root";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.$conf["external::callShell"]["getErr"]="true";#備註:#不是所有指令都能用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["external::callShell"]);unset($conf["external::callShell"]);#如果運行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#取得運行結果$result["content"]=$callShell["output"];#設置執行成功$result["status"]="true";#回傳結果return $result;}#function pingOutsideTest end/*#函式說明:#變更word press網站的所有資訊為新的 domain name.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["content"],執行的結果.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#$conf["oldDomain"],字串,舊的domain名稱.$conf["oldDomain"]="";#$conf["newDomain"],字串,新的domain名稱.$conf["newDomain"]="";#可省略參數:#$conf["wpConfig"],字串,wp-cofnig.php的位置與名稱,預設為"/var/www/html/wordpress/wp-config.php".#$conf["wpConfig"]="/var/www/html/wordpress/wp-config.php";#參考資料:#無.#備註:#建構中...*/public static function changeWordPressDomain(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函式名稱$result["function"]=__FUNCTION__;#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","oldDomain","newDomain");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("wpConfig");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wpConfig");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/var/www/html/wordpress/wp-config.php");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數失敗if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#要尋找的db參數$dbParams=array("DB_NAME","DB_USER","DB_PASSWORD","DB_HOST");#函式說明:#解析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["fileAccess::parseVaraiableInPHPfile"]["file"]=$conf["wpConfig"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::parseVaraiableInPHPfile"]["fileArgu"]=$conf["fileArgu"];#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".$conf["fileAccess::parseVaraiableInPHPfile"]["varName"]=$dbParams;#可省略參數:#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".#$conf["web"]="true";#參考資料:#https://www.php.net/manual/en/function.parse-str.php$parseVaraiableInPHPfile=fileAccess::parseVaraiableInPHPfile($conf["fileAccess::parseVaraiableInPHPfile"]);unset($conf["fileAccess::parseVaraiableInPHPfile"]);#如果解析 php 變數失敗if($parseVaraiableInPHPfile["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$parseVaraiableInPHPfile;#回傳結果return $result;}#if end#針對每個要尋找的資料庫連線變數foreach($dbParams as $varName){#如果要尋找的資料庫參數不存在if(!isset($parseVaraiableInPHPfile["content"]["direct"][$varName])){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$parseVaraiableInPHPfile;#回傳結果return $result;}#if end#設置變數名稱$$varName=$parseVaraiableInPHPfile["content"]["direct"][$varName];}#foreach end#update wp_options table start#函式說明:#一次取得資料庫、表的資料#回傳的結果#$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["db::fastGetDbData"]["dbAddress"]=$DB_HOST;#$conf["dbAccount"],字串,爲登入dbServer的帳號。$conf["db::fastGetDbData"]["dbAccount"]=$DB_USER;#$conf["dbName"],字串,爲要存取的資料庫名稱$conf["db::fastGetDbData"]["dbName"]=$DB_NAME;#$conf["tableName"],字串,爲要存取的資料表名稱$conf["db::fastGetDbData"]["tableName"]="wp_options";#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.$conf["db::fastGetDbData"]["columnYouWant"]=array("*");#可省略參數:#$conf["dbPassword"],字串,爲要存取dbServer的密碼.$conf["db::fastGetDbData"]["dbPassword"]=$DB_PASSWORD;#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.#$conf["dbPort"]="";#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。#$conf["WhereColumnName"]=array("");#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。#$conf["WhereColumnValue"]=array("");#$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["db::fastGetDbData"]);unset($conf["db::fastGetDbData"]);#如果查詢失敗if($fastGetDbData["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$fastGetDbData;#回傳結果return $result;}#if end#針對每筆資料foreach($fastGetDbData["dataContent"]["option_value"] as $index=>$value){#遇到空字串if($value===""){#跳過continue;}#if end#函式說明:#處理字串避免網頁出錯#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式.#$result["content"],爲處理好的字串.#$result["error"],錯誤訊息陣列.#$result["argu"],使用的參數.#必填參數:$conf["stringProcess::correctCharacter"]["stringIn"]=$value;#爲要處理的字串#可省略參數:$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array($conf["oldDomain"]);#爲被選擇要處理的字串/字元,須爲陣列值。#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔$conf["stringProcess::correctCharacter"]["changeTo"]=array($conf["newDomain"]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).#備註:#無.$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);unset($conf["stringProcess::correctCharacter"]);#如果查詢失敗if($correctCharacter["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$correctCharacter;#回傳結果return $result;}#if end#取得處理好的內容$value=$correctCharacter["content"];#函式說明:#更新資料表裏面的資料#回傳的結果:#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了#$result["error"],錯誤訊息#$result["function"],當前執行的函式名稱#$result["sql"],執行的sql語法.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["db::updateDataTableContent"]["fileArgu"]=$conf["fileArgu"];#$conf["dbAddress"],字串,爲mysql-Server的位置$conf["db::updateDataTableContent"]["dbAddress"]=$DB_HOST;#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號$conf["db::updateDataTableContent"]["dbAccount"]=$DB_USER;#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱$conf["db::updateDataTableContent"]["selectedDataBaseName"]=$DB_NAME;#$conf["tableName"],字串,要修改的資料表名稱$conf["db::updateDataTableContent"]["tableName"]="wp_options";#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值$conf["db::updateDataTableContent"]["whereColumn"]=array("option_id");#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值$conf["db::updateDataTableContent"]["whereValue"]=array($fastGetDbData["dataContent"]["option_id"][$index]);#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列$conf["db::updateDataTableContent"]["tableColumnName"]=array("option_value");#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值$conf["db::updateDataTableContent"]["updateDataValue"]=array($value);#可省略參數:#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.$conf["db::updateDataTableContent"]["dbPassword"]=$DB_PASSWORD;#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.#$conf["dbPort"]=$dbPort;$updateDataTableContent=db::updateDataTableContent($conf["db::updateDataTableContent"]);unset($conf["db::updateDataTableContent"]);#如果更新失敗if($updateDataTableContent["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$updateDataTableContent;#回傳結果return $result;}#if end}#foreach end#update wp_options table end#update wp_posts table post_content col start#函式說明:#一次取得資料庫、表的資料#回傳的結果#$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["db::fastGetDbData"]["dbAddress"]=$DB_HOST;#$conf["dbAccount"],字串,爲登入dbServer的帳號。$conf["db::fastGetDbData"]["dbAccount"]=$DB_USER;#$conf["dbName"],字串,爲要存取的資料庫名稱$conf["db::fastGetDbData"]["dbName"]=$DB_NAME;#$conf["tableName"],字串,爲要存取的資料表名稱$conf["db::fastGetDbData"]["tableName"]="wp_posts";#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.$conf["db::fastGetDbData"]["columnYouWant"]=array("*");#可省略參數:#$conf["dbPassword"],字串,爲要存取dbServer的密碼.$conf["db::fastGetDbData"]["dbPassword"]=$DB_PASSWORD;#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.#$conf["dbPort"]="";#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。#$conf["WhereColumnName"]=array("");#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。#$conf["WhereColumnValue"]=array("");#$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["db::fastGetDbData"]);unset($conf["db::fastGetDbData"]);#如果查詢失敗if($fastGetDbData["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$fastGetDbData;#回傳結果return $result;}#if end#針對每筆資料foreach($fastGetDbData["dataContent"]["post_content"] as $index=>$value){#函式說明:#處理字串避免網頁出錯#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式.#$result["content"],爲處理好的字串.#$result["error"],錯誤訊息陣列.#$result["argu"],使用的參數.#必填參數:$conf["stringProcess::correctCharacter"]["stringIn"]=$value;#爲要處理的字串#可省略參數:$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array($conf["oldDomain"]);#爲被選擇要處理的字串/字元,須爲陣列值。#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔$conf["stringProcess::correctCharacter"]["changeTo"]=array($conf["newDomain"]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).#備註:#無.$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);unset($conf["stringProcess::correctCharacter"]);#如果查詢失敗if($correctCharacter["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$correctCharacter;#回傳結果return $result;}#if end#取得處理好的內容$value=$correctCharacter["content"];#函式說明:#更新資料表裏面的資料#回傳的結果:#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了#$result["error"],錯誤訊息#$result["function"],當前執行的函式名稱#$result["sql"],執行的sql語法.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["db::updateDataTableContent"]["fileArgu"]=$conf["fileArgu"];#$conf["dbAddress"],字串,爲mysql-Server的位置$conf["db::updateDataTableContent"]["dbAddress"]=$DB_HOST;#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號$conf["db::updateDataTableContent"]["dbAccount"]=$DB_USER;#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱$conf["db::updateDataTableContent"]["selectedDataBaseName"]=$DB_NAME;#$conf["tableName"],字串,要修改的資料表名稱$conf["db::updateDataTableContent"]["tableName"]="wp_posts";#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值$conf["db::updateDataTableContent"]["whereColumn"]=array("id");#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值$conf["db::updateDataTableContent"]["whereValue"]=array($fastGetDbData["dataContent"]["id"][$index]);#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列$conf["db::updateDataTableContent"]["tableColumnName"]=array("post_content");#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值$conf["db::updateDataTableContent"]["updateDataValue"]=array($value);#可省略參數:#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.$conf["db::updateDataTableContent"]["dbPassword"]=$DB_PASSWORD;#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.#$conf["dbPort"]=$dbPort;$updateDataTableContent=db::updateDataTableContent($conf["db::updateDataTableContent"]);unset($conf["db::updateDataTableContent"]);#如果更新失敗if($updateDataTableContent["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$updateDataTableContent;#回傳結果return $result;}#if end}#foreach end#update wp_posts table post_content col end#update wp_posts table guid col start#函式說明:#一次取得資料庫、表的資料#回傳的結果#$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["db::fastGetDbData"]["dbAddress"]=$DB_HOST;#$conf["dbAccount"],字串,爲登入dbServer的帳號。$conf["db::fastGetDbData"]["dbAccount"]=$DB_USER;#$conf["dbName"],字串,爲要存取的資料庫名稱$conf["db::fastGetDbData"]["dbName"]=$DB_NAME;#$conf["tableName"],字串,爲要存取的資料表名稱$conf["db::fastGetDbData"]["tableName"]="wp_posts";#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.$conf["db::fastGetDbData"]["columnYouWant"]=array("*");#可省略參數:#$conf["dbPassword"],字串,爲要存取dbServer的密碼.$conf["db::fastGetDbData"]["dbPassword"]=$DB_PASSWORD;#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.#$conf["dbPort"]="";#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。#$conf["WhereColumnName"]=array("");#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。#$conf["WhereColumnValue"]=array("");#$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["db::fastGetDbData"]);unset($conf["db::fastGetDbData"]);#如果查詢失敗if($fastGetDbData["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$fastGetDbData;#回傳結果return $result;}#if end#針對每筆資料foreach($fastGetDbData["dataContent"]["guid"] as $index=>$value){#函式說明:#處理字串避免網頁出錯#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函式.#$result["content"],爲處理好的字串.#$result["error"],錯誤訊息陣列.#$result["argu"],使用的參數.#必填參數:$conf["stringProcess::correctCharacter"]["stringIn"]=$value;#爲要處理的字串#可省略參數:$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array($conf["oldDomain"]);#爲被選擇要處理的字串/字元,須爲陣列值。#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔$conf["stringProcess::correctCharacter"]["changeTo"]=array($conf["newDomain"]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).#備註:#無.$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);unset($conf["stringProcess::correctCharacter"]);#如果查詢失敗if($correctCharacter["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$correctCharacter;#回傳結果return $result;}#if end#取得處理好的內容$value=$correctCharacter["content"];#函式說明:#更新資料表裏面的資料#回傳的結果:#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了#$result["error"],錯誤訊息#$result["function"],當前執行的函式名稱#$result["sql"],執行的sql語法.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["db::updateDataTableContent"]["fileArgu"]=$conf["fileArgu"];#$conf["dbAddress"],字串,爲mysql-Server的位置$conf["db::updateDataTableContent"]["dbAddress"]=$DB_HOST;#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號$conf["db::updateDataTableContent"]["dbAccount"]=$DB_USER;#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱$conf["db::updateDataTableContent"]["selectedDataBaseName"]=$DB_NAME;#$conf["tableName"],字串,要修改的資料表名稱$conf["db::updateDataTableContent"]["tableName"]="wp_posts";#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值$conf["db::updateDataTableContent"]["whereColumn"]=array("id");#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值$conf["db::updateDataTableContent"]["whereValue"]=array($fastGetDbData["dataContent"]["id"][$index]);#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列$conf["db::updateDataTableContent"]["tableColumnName"]=array("guid");#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值$conf["db::updateDataTableContent"]["updateDataValue"]=array($value);#可省略參數:#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.$conf["db::updateDataTableContent"]["dbPassword"]=$DB_PASSWORD;#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.#$conf["dbPort"]=$dbPort;$updateDataTableContent=db::updateDataTableContent($conf["db::updateDataTableContent"]);unset($conf["db::updateDataTableContent"]);#如果更新失敗if($updateDataTableContent["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$updateDataTableContent;#回傳結果return $result;}#if end}#foreach end#update wp_posts table guid col end#設置執行正常$result["status"]="true";#回傳結果return $reuslt;}#functino changeWordPressDomain/*#函式說明:#使用 linux 的 groups 指令來查詢使用者所屬的群組清單.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令.#必填參數:#無.#可省略參數:#$conf["user"],字串,要查詢的user,若不指定則為查詢當前使用者.$conf["user"]="";#參考資料:#無.#備註:#無.*/public static function getUserGroups(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函數".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("owner","target");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("user");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("user");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果執行失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果沒有指定 userif(!isset($conf["users"])){#函式說明:#取得用戶端的資訊,並依據需要寫入到資料表裡面#回傳的結果:#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.#$result["error"],錯誤訊息.#$result["function"],檔前執行的函數名稱.#$result["mode"],當前的模式是"cmd"還是"web".#$result["userBrowserType"],爲使用者的瀏覽器資訊#$result["userIp"],爲使用者的IP#$result["serverIp"],為伺服器的IP#$result["server_name"],伺服器的 domain name#$result["scheme"],通訊協定#$result["serverPort"],伺服器給對外下載網頁的port#$result["requestUri"],爲使用者要求的網址/php檔案.#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.#$result["clientRequestIP"],用戶端要求的ip與port#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".#$result["header"],接收到的 header 陣列.#$result["body"],接收到的 body 字串.#必填參數:#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.$conf["csInformation::getConnectionInfo"]["getAccount"]="true";#可省略參數:#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].#$conf["accountVar"]=$_SESSION["username"];#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.#$conf["saveToDb"]="true";#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.#$conf["dbAddress"]=$dbAddress;#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.#$conf["dbAccount"]=$dbAccount;#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.#$conf["dbName"]=$dbName;#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.#$conf["tableName"]="visitorInfo";#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.#$conf["dbPassword"]=$dbPassword;#參考資料:#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php#備註:#無.$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);unset($conf["csInformation::getConnectionInfo"]);#如果執行失敗if($getConnectionInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getConnectionInfo;#回傳結果return $result;}#if end#設置預設使用者為自己$conf["users"]=$getConnectionInfo["phpUser"];}#if end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="groups";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array($conf["user"]);#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.#$conf["escapeshellarg"]="false";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#取得群組清單#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$callShell["output"][0];#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" : ";#可省略參數:#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.#$conf["recursive"]="true";#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.#$conf["lastResult"]=$delStrBeforeKeyWord;#參考資料:#無.#備註:#無.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果執行失敗if($delStrBeforeKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果沒有該有的關鍵字if($delStrBeforeKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#函式說明:#將固定格式的字串分開,並回傳分開的結果.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$delStrBeforeKeyWord["content"];#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.#$conf["allowEmptyStr"]="false";#參考資料:#無.#備註:#無.$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果執行失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有結果if($spiltString["dataCounts"]===0){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#設置結果$result["content"]=$spiltString["dataArray"];#設置執行正常$result["status"]="true";#回傳結果return $reuslt;}#function getUserGroups end/*#函式說明:#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令.#必填參數:#$conf["owner"],字串,要變哪個使用者擁有.$conf["owner"]="";#$conf["target"],字串,需要變更擁有者、 群組的目標.$conf["target"]="";#可省略參數:#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.$conf["group"]="";#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".#$conf["recursive"]="true";#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).#$conf["excludeSelf"]="true";#參考資料:#無.#備註:#無.*/public static function chown(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函數".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("owner","target");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("group","recursive","excludeSelf");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("group","recursive","excludeSelf");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"owner\"]","false","false");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果執行失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#確認 $conf["target"] 存在#函式說明:#檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["target"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;#可省略參數:#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".$conf["fileAccess::checkMultiFileExist"]["web"]="false";#參考資料:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑#$result["varName"][$i]結果未實作$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果執行失敗if($checkMultiFileExist["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果 target 不存在if($checkMultiFileExist["allExist"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#初始化給 chown 的參數$paramsForChown=array($conf["owner"].":".$conf["group"]);#如果底下的內容也要一起做設定if($conf["recursive"]==="true"){#加上 -R 參數$paramsForChown[]="-R";#取得目標資訊#函式說明:#取得節點的資訊.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函數名稱.#$result["content"],檔案資訊陣列.#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.#$result["content"]["ownerPerm"],檔案擁有者權限資訊.#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.#$result["content"]["ownerName"],檔案擁有着資訊.#$result["content"]["groupName"],檔案所屬擁有着資訊.#$result["content"]["size"],檔案大小.#$result["content"]["modifyDate"],檔案變更年月日.#$result["content"]["modifyTime"],檔案變更時分秒.#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.#必填參數:#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;#$conf["file"],字串,要查看擁有者資訊的檔案.$conf["fileAccess::fileInfo"]["file"]=$conf["target"];#可省略參數:#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".$conf["fileAccess::fileInfo"]["web"]="false";#參考資料:#fileowner=>http://php.net/manual/en/function.fileowner.php#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php#備註:#無.$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);unset($conf["fileAccess::fileInfo"]);#如果執行失敗if($fileInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$fileInfo;#回傳結果return $result;}#if end#如果目標是資料夾if($fileInfo["content"]["is_folder"]==="true"){#如果要排除目標資料夾或軟連結之類的if($conf["excludeSelf"]==="true"){#函式說明:#開啟特定目錄,取得底下的檔案路徑清單.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["argu"],所使用的參數.#$result["content"],讀取到的內容陣列.#$result["content"][$i],第$i+1個結果.#$result["content"][$i]["name"],第$i+1個名稱.#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).#必填參數:#$conf["path"],字串,要取得檔案資訊的所屬路徑.$conf["fileAccess::listInfo"]["path"]=$conf["target"];#可省略參數:#無.#參考資料#無.#備註:#無.$listInfo=fileAccess::listInfo($conf["fileAccess::listInfo"]);unset($conf["fileAccess::listInfo"]);#如果執行失敗if($listInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$listInfo;#回傳結果return $result;}#if end#針對每個目標foreach($listInfo["content"] as $fileInfo){#忽略當前目錄與上層目錄if($fileInfo["content"]["name"]==="." || $fileInfo["content"]["name"]===".."){#跳過continue;}#if end#函式說明:#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令.#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.#必填參數:#$conf["owner"],字串,要變哪個使用者擁有.$conf["cmd::chown"]["owner"]=$conf["owner"];#$conf["target"],字串,需要變更擁有者、 群組的目標.$conf["cmd::chown"]["target"]=$conf["target"]."/".$fileInfo["content"]["name"];#可省略參數:#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.$conf["cmd::chown"]["group"]=$conf["group"];#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".$conf["cmd::chown"]["recursive"]="true";#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).#$conf["excludeSelf"]="true";#參考資料:#無.#備註:#無.$chown=cmd::chown($conf["cmd::chown"]);unset($conf["cmd::chown"]);#如果執行失敗if($chown["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$chown;#回傳結果return $result;}#if end#記錄結果$result["content"][]=$chown;}#foreach end#設置執行正常$result["status"]="true";#回傳結果return $result;}#if end#執行到這邊代表不用對底下內容做異動}#if end#執行到這邊代表目標不是目錄}#if end#取得目標資訊#函式說明:#取得節點的資訊.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函數名稱.#$result["content"],檔案資訊陣列.#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.#$result["content"]["ownerPerm"],檔案擁有者權限資訊.#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.#$result["content"]["ownerName"],檔案擁有着資訊.#$result["content"]["groupName"],檔案所屬擁有着資訊.#$result["content"]["size"],檔案大小.#$result["content"]["modifyDate"],檔案變更年月日.#$result["content"]["modifyTime"],檔案變更時分秒.#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.#必填參數:#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;#$conf["file"],字串,要查看擁有者資訊的檔案.$conf["fileAccess::fileInfo"]["file"]=$conf["target"];#可省略參數:#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".$conf["fileAccess::fileInfo"]["web"]="false";#參考資料:#fileowner=>http://php.net/manual/en/function.fileowner.php#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php#備註:#無.$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);unset($conf["fileAccess::fileInfo"]);#如果執行失敗if($fileInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$fileInfo;#回傳結果return $result;}#if end#函式說明:#取得用戶端的資訊,並依據需要寫入到資料表裡面#回傳的結果:#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.#$result["error"],錯誤訊息.#$result["function"],檔前執行的函數名稱.#$result["mode"],當前的模式是"cmd"還是"web".#$result["userBrowserType"],爲使用者的瀏覽器資訊#$result["userIp"],爲使用者的IP#$result["serverIp"],為伺服器的IP#$result["server_name"],伺服器的 domain name#$result["scheme"],通訊協定#$result["serverPort"],伺服器給對外下載網頁的port#$result["requestUri"],爲使用者要求的網址/php檔案.#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.#$result["clientRequestIP"],用戶端要求的ip與port#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".#$result["header"],接收到的 header 陣列.#$result["body"],接收到的 body 字串.#必填參數:#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.$conf["csInformation::getConnectionInfo"]["getAccount"]="true";#可省略參數:#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].#$conf["accountVar"]=$_SESSION["username"];#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.#$conf["saveToDb"]="true";#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.#$conf["dbAddress"]=$dbAddress;#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.#$conf["dbAccount"]=$dbAccount;#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.#$conf["dbName"]=$dbName;#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.#$conf["tableName"]="visitorInfo";#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.#$conf["dbPassword"]=$dbPassword;#參考資料:#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php#備註:#無.$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);unset($conf["csInformation::getConnectionInfo"]);#如果執行失敗if($getConnectionInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getConnectionInfo;#回傳結果return $result;}#if end#初始化 chown 指令$chown="chown";#debug#var_dump(__LINE__,$getConnectionInfo);#如果不是root賬戶在運行if($getConnectionInfo["phpUserType"]!=="intrinsic"){#如果不是擁有者的檔案/目錄 或是要變成自己以外的擁有者if($getConnectionInfo["phpUser"]!==$fileInfo["content"]["ownerName"] || $getConnectionInfo["phpUser"]!==$conf["owner"]){#如果是wheel成員if($getConnectionInfo["phpUserType"]==="wheel"){#代表要 sudo 在前$chown="sudo";#函式說明:#將多個多維陣列串聯起來,key從0開始排序.#回傳的結果:#$result["status"],"true"表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數.#$result["argu"],使用的參數.#$result["content"],合併好的一維陣列.#必填參數#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);$conf["arrays::mergeMultiDimensionArray"]["inputArray"]=array(array("chown"),$paramsForChown);#可省略參數:#$conf["allowRepeat"],字串,預設為"false",不允許重複的結果;反之為"true".$conf["arrays::mergeMultiDimensionArray"]["allowRepeat"]="true";#$conf["equalKeyStruc"],字串陣列,若 allowRepeat 參數為 "false", 這該參數生效.該參數為用來判斷每個陣列的哪個鍵值路徑底下的數值相同時要進行取代,後者會取代前者.#$conf["equalKeyStruc"]=array();#參考資料:#無.#備註:#無.$mergeMultiDimensionArray=arrays::mergeMultiDimensionArray($conf["arrays::mergeMultiDimensionArray"]);unset($conf["arrays::mergeMultiDimensionArray"]);#如果執行失敗if($mergeMultiDimensionArray["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$mergeMultiDimensionArray;#回傳結果return $result;}#if end#chown 在後$paramsForChown=$mergeMultiDimensionArray["content"];}#if end#反之else{#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="你沒有權限變更 ".$conf["target"]." 的 file mode bits";#設置錯誤訊息$result["error"][]=$getConnectionInfo;#回傳結果return $result;}#else end}#if end}#if end#加上要變更的目標$paramsForChown[]=$conf["target"];#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]=$chown;#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$paramsForChown;#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#設置執行的指令$result["cmd"]=$callShell["cmd"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#functino chown end/*#函式說明:#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令.#必填參數:#$conf["mode"],字串,要變成什麼權限.$conf["mode"]="";#$conf["target"],字串,需要變更權限的目標.$conf["target"]="";#可省略參數:#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".#$conf["recursive"]="true";#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).#$conf["excludeSelf"]="true";#參考資料:#無.#備註:#無.*/public static function chmod(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函數".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode","target");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("recursive","excludeSelf");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive","excludeSelf");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果執行失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#確認 $conf["target"] 存在#函式說明:#檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["target"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;#可省略參數:#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".$conf["fileAccess::checkMultiFileExist"]["web"]="false";#參考資料:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑#$result["varName"][$i]結果未實作$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果執行失敗if($checkMultiFileExist["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果 target 不存在if($checkMultiFileExist["allExist"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#初始化給 chmod 的參數$paramsForChmod=array($conf["mode"]);#如果底下的內容也要一起做設定if($conf["recursive"]==="true"){#加上 -R 參數$paramsForChmod[]="-R";#取得目標資訊#函式說明:#取得節點的資訊.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函數名稱.#$result["content"],檔案資訊陣列.#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.#$result["content"]["ownerPerm"],檔案擁有者權限資訊.#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.#$result["content"]["ownerName"],檔案擁有着資訊.#$result["content"]["groupName"],檔案所屬擁有着資訊.#$result["content"]["size"],檔案大小.#$result["content"]["modifyDate"],檔案變更年月日.#$result["content"]["modifyTime"],檔案變更時分秒.#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.#必填參數:#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;#$conf["file"],字串,要查看擁有者資訊的檔案.$conf["fileAccess::fileInfo"]["file"]=$conf["target"];#可省略參數:#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".$conf["fileAccess::fileInfo"]["web"]="false";#參考資料:#fileowner=>http://php.net/manual/en/function.fileowner.php#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php#備註:#無.$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);unset($conf["fileAccess::fileInfo"]);#如果執行失敗if($fileInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$fileInfo;#回傳結果return $result;}#if end#如果目標是資料夾if($fileInfo["content"]["is_folder"]==="true"){#如果要排除目標資料夾或軟連結之類的if($conf["excludeSelf"]==="true"){#函式說明:#開啟特定目錄,取得底下的檔案路徑清單.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["argu"],所使用的參數.#$result["content"],讀取到的內容陣列.#$result["content"][$i],第$i+1個結果.#$result["content"][$i]["name"],第$i+1個名稱.#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).#必填參數:#$conf["path"],字串,要取得檔案資訊的所屬路徑.$conf["fileAccess::listInfo"]["path"]=$conf["target"];#可省略參數:#無.#參考資料#無.#備註:#無.$listInfo=fileAccess::listInfo($conf["fileAccess::listInfo"]);unset($conf["fileAccess::listInfo"]);#如果執行失敗if($listInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$listInfo;#回傳結果return $result;}#if end#如果底下有資料if(!empty($listInfo["content"])){#針對每個目標foreach($listInfo["content"] as $fileInfo){#忽略當前目錄與上層目錄if($fileInfo["name"]==="." || $fileInfo["name"]===".."){#跳過continue;}#if end#函式說明:#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["fileAccess::chmod"]["mode"]=$conf["mode"];#$conf["target"],字串,需要變更權限的目標.$conf["fileAccess::chmod"]["target"]=$conf["target"]."/".$fileInfo["name"];#可省略參數:#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".$conf["fileAccess::chmod"]["recursive"]="true";#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).#$conf["excludeSelf"]="true";#參考資料:#無.#備註:#無.$chmod=cmd::chmod($conf["fileAccess::chmod"]);unset($conf["fileAccess::chmod"]);#如果執行失敗if($chmod["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$chmod;#回傳結果return $result;}#if end#記錄結果$result["content"][]=$chmod;}#foreach end}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#if end#執行到這邊代表不用對底下內容做異動}#if end#執行到這邊代表目標不是目錄}#if end#函式說明:#取得用戶端的資訊,並依據需要寫入到資料表裡面#回傳的結果:#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.#$result["error"],錯誤訊息.#$result["function"],檔前執行的函數名稱.#$result["mode"],當前的模式是"cmd"還是"web".#$result["userBrowserType"],爲使用者的瀏覽器資訊#$result["userIp"],爲使用者的IP#$result["serverIp"],為伺服器的IP#$result["server_name"],伺服器的 domain name#$result["scheme"],通訊協定#$result["serverPort"],伺服器給對外下載網頁的port#$result["requestUri"],爲使用者要求的網址/php檔案.#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.#$result["clientRequestIP"],用戶端要求的ip與port#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".#$result["header"],接收到的 header 陣列.#$result["body"],接收到的 body 字串.#必填參數:#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.$conf["csInformation::getConnectionInfo"]["getAccount"]="true";#可省略參數:#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].#$conf["accountVar"]=$_SESSION["username"];#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.#$conf["saveToDb"]="true";#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.#$conf["dbAddress"]=$dbAddress;#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.#$conf["dbAccount"]=$dbAccount;#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.#$conf["dbName"]=$dbName;#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.#$conf["tableName"]="visitorInfo";#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.#$conf["dbPassword"]=$dbPassword;#參考資料:#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php#備註:#無.$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);unset($conf["csInformation::getConnectionInfo"]);#如果執行失敗if($getConnectionInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getConnectionInfo;#回傳結果return $result;}#if end#取得目標資訊#函式說明:#取得節點的資訊.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函數名稱.#$result["content"],檔案資訊陣列.#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.#$result["content"]["ownerPerm"],檔案擁有者權限資訊.#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.#$result["content"]["ownerName"],檔案擁有着資訊.#$result["content"]["groupName"],檔案所屬擁有着資訊.#$result["content"]["size"],檔案大小.#$result["content"]["modifyDate"],檔案變更年月日.#$result["content"]["modifyTime"],檔案變更時分秒.#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.#必填參數:#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;#$conf["file"],字串,要查看擁有者資訊的檔案.$conf["fileAccess::fileInfo"]["file"]=$conf["target"];#可省略參數:#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".$conf["fileAccess::fileInfo"]["web"]="false";#參考資料:#fileowner=>http://php.net/manual/en/function.fileowner.php#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php#備註:#無.$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);unset($conf["fileAccess::fileInfo"]);#如果執行失敗if($fileInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$fileInfo;#回傳結果return $result;}#if end/*#debug$fsock=fopen("/tmp/test.log","w");fwrite($fsock,$getConnectionInfo["phpUser"]);fwrite($fsock,$fileInfo["content"]["ownerName"]);*/#初始化 chmod 指令$chmod="chmod";#如果不是root賬戶在運行if($getConnectionInfo["phpUserType"]!=="intrinsic"){#如果不是擁有者的檔案/目錄if($getConnectionInfo["phpUser"]!==$fileInfo["content"]["ownerName"]){#如果是wheel成員if($getConnectionInfo["phpUserType"]==="wheel"){#代表要 sudo 在前$chmod="sudo";#函式說明:#將多個多維陣列串聯起來,key從0開始排序.#回傳的結果:#$result["status"],"true"表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數.#$result["argu"],使用的參數.#$result["content"],合併好的一維陣列.#必填參數#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);$conf["arrays::mergeMultiDimensionArray"]["inputArray"]=array(array("chmod"),$paramsForChmod);#可省略參數:#$conf["allowRepeat"],字串,預設為"false",不允許重複的結果;反之為"true".$conf["arrays::mergeMultiDimensionArray"]["allowRepeat"]="true";#$conf["equalKeyStruc"],字串陣列,若 allowRepeat 參數為 "false", 這該參數生效.該參數為用來判斷每個陣列的哪個鍵值路徑底下的數值相同時要進行取代,後者會取代前者.#$conf["equalKeyStruc"]=array();#參考資料:#無.#備註:#無.$mergeMultiDimensionArray=arrays::mergeMultiDimensionArray($conf["arrays::mergeMultiDimensionArray"]);unset($conf["arrays::mergeMultiDimensionArray"]);#如果執行失敗if($mergeMultiDimensionArray["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$mergeMultiDimensionArray;#回傳結果return $result;}#if end#chmod 在後$paramsForChmod=$mergeMultiDimensionArray["content"];}#if end#反之else{#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="你沒有權限變更 ".$conf["target"]." 的 file mode bits";#設置錯誤訊息$result["error"][]=$getConnectionInfo;#設置錯誤訊息$result["error"][]=$fileInfo["content"];#回傳結果return $result;}#else end}#if end}#if end#加上要變更的目標$paramsForChmod[]=$conf["target"];#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]=$chmod;#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$paramsForChmod;#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#設置執行的指令$result["cmd"]=$callShell["cmd"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function chmod end/*#函式說明:#使用 linux 的 uuid 指令來產生 uuid 字串#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],uuid.#必填參數:#無.#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function uuid(){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="uuid";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=__FILE__;#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.#$conf["argu"]=array("");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.#$conf["plainArgu"]=array();#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".#$conf["useApostrophe"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#如果沒有預期的 uuid 結果if(!isset($callShell["output"][0])){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="沒有預期的 uuid 輸出";#設置錯誤訊息$result["error"][]=$callShell;#回傳結果return $result;}#if end#取得結果$result["content"]=$callShell["output"][0];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function uuid end/*#函式說明:#將 freeplane 軟體支持的 mm 格式檔案跨平台.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],調整過後的檔案內容simple xml object,若有需要取得純文字的xml內容,可用 echo 來實現.#必填參數:#$conf["mmFile"],字串,mm檔案的位置與名稱.$conf["mmFile"]="";#可省略參數:#$conf["imgFolder"],字串,圖片存放的相對路徑字串,預設為"Pictures".#$conf["imgFolder"]="Pictures";#$conf["output"],字串,更新過後的 mm 檔案位置與名稱,預設為原檔案名稱加上"-1",變成"fileName-1.mm".#$conf["output"]="";#參考資料:#https://www.php.net/manual/en/simplexmlelement.children.php#https://www.php.net/manual/en/simplexmlelement.getname.php#https://www.php.net/manual/en/simplexmlelement.tostring.php#備註:#無.*/public static function msPortable(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函數".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mmFile");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("imgFolder","output");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("imgFolder","output");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("Pictures",null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果執行失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果沒有設置輸出的檔案位置與名稱if(!isset($conf["output"])){#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$conf["mmFile"];#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".mm";#可省略參數:#無.#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);unset($conf["stringProcess::delStrAfterKeyWord"]);#如果執行失敗if($delStrAfterKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#如果沒有符合的關鍵字 ".mm"if($delStrAfterKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#設置預設的輸出檔案路徑與名稱$conf["output"]=$delStrAfterKeyWord["content"]."-1.mm";}#if end#確認 $conf["target"] 存在#函式說明:#檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["mmFile"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;#可省略參數:#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".$conf["fileAccess::checkMultiFileExist"]["web"]="false";#參考資料:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑#$result["varName"][$i]結果未實作$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果執行失敗if($checkMultiFileExist["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果 target 不存在if($checkMultiFileExist["allExist"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#函式說明:#讀取xml檔案,儲存所有標籤的內容,目前尚不能讀取屬性的資訊#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["founded"],是否有抓到xml檔案,"true"代表有抓到,"false"代表沒有抓到.#$result["content"],xml的物件內容.#$result["argu"],所使用的參數.#必填參數:#$conf["xmlPosition"],字串,xml檔案的位置.$conf["xml::getContent"]["xmlPosition"]=$conf["mmFile"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["xml::getContent"]["fileArgu"]=__FILE__;#可省略參數:#無.#參考資料來源:#XML範例檔=>http://msdn.microsoft.com/zh-tw/library/bb387025.aspx#simplexml-load-file=>http://php.net/manual/en/function.simplexml-load-file.php#取得xml檔案內容的示範=>http://php.net/manual/en/simplexml.examples-basic.php#啟用處理xml的錯誤處理=>http://php.net/manual/en/function.libxml-use-internal-errors.php#取得處理xml的錯誤訊息=>http://php.net/manual/en/function.libxml-get-errors.php#備註:#無.$getContent=xml::getContent($conf["xml::getContent"]);unset($conf["xml::getContent"]);#如果執行失敗if($getContent["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getContent;#回傳結果return $result;}#if end#如果xml檔案不存在if($getContent["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getContent;#回傳結果return $result;}#if end#初始化要解析的 simeple xml object$searchArray=array(&$getContent["content"]);#有幾個要解析的 simeple xml object 就執行幾次for($i=0;$i<count($searchArray);$i++){#初始化基準點$base=&$searchArray[$i];#如果存在node子階層if(isset($base->node)){#針對每個同名的node階層for($j=0;$j<count($base->node);$j++){#取得階層的位置$tempLayer=&($base->node)[$j];#如果下一層有 hookif(isset($tempLayer->hook)){#針對底下的屬性foreach($tempLayer->hook->attributes() as $attrName => $attrValue){#如果有指定 URIif($attrName==="URI" && $attrValue!==""){#更新 URI 位置$tempLayer->hook->attributes()->$attrName=$conf["imgFolder"]."/".basename($attrValue);#設置 SIZE 為 1.0$tempLayer->hook->attributes()->SIZE="1.0";}#if end}#foreach end}#if end#保存待處理的 simple xml object$searchArray[]=&$tempLayer;}#for end}#if end}#for end#取得更新後的 simple xml object$result["content"]=$getContent["content"];#建立新 mm 檔案#函式說明:#將字串寫入到檔案#回傳結果:#$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["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;#可省略參數:#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.$conf["fileAccess::writeTextIntoFile"]["fileName"]=$conf["output"];#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".$conf["fileAccess::writeTextIntoFile"]["inputString"]=$getContent["content"]->asXML();#$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"]="";#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".$conf["fileAccess::writeTextIntoFile"]["web"]="false";#參考資料:#無.#備註:#無.$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);unset($conf["fileAccess::writeTextIntoFile"]);#如果執行失敗if($writeTextIntoFile["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$writeTextIntoFile;#回傳結果return $result;}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function msPortable end/*#函式說明:#使用 linux 的 rsync 指令來進行備份檔案.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令.#必填參數:#$conf["source"],字串,需要進行備份的目錄或檔案$conf["source"]="";#$conf["target"],字串,備份到哪個地方或檔案$conf["target"]="";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要複製,預設為"false".#$conf["recursive"]="true";#$conf["exclude"],字串陣列,每個元素代表要排除的項目,預設不指定.#$conf["exclude"]=array();#$conf["excludeFileType"],字串陣列,每個元素代表要排除的副檔名,預設不指定.#$conf["excludeFileType"]=array();#$conf["bandWidthLimit"],字串,代表頻寬上限,單為可為K、M、G等,預設不指定.#$conf["bandWidthLimit"]="";#$conf["newFileOnly"],字串,是否只複製比較新的檔案,預設為"true"代表要;反之為"false".#$conf["newFileOnly"]="true";#$conf["appendMode"],字串,是否用append的方式複製,適用於檔案內同位置內容一樣的檔案,預設值"false"代表不要;反之為"true".#$conf["appendMode"]="true";#參考資料:#無#備註:#無.*/public static function rsync(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函數".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("source","target","fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("recursive","exclude","excludeFileType","bandWidthLimit","newFileOnly","appendMode");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive","exclude","excludeFileType","bandWidthLimit","newFileOnly","appendMode");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","array","string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,null,null,"false","false");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果執行失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#確認 $conf["source"] 存在#函式說明:#檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["source"]);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".$conf["fileAccess::checkMultiFileExist"]["web"]="false";#參考資料:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑#$result["varName"][$i]結果未實作$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果執行失敗if($checkMultiFileExist["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果 source 不存在if($checkMultiFileExist["allExist"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkMultiFileExist;#回傳結果return $result;}#if end#如果要複製的目標不為 "/" 結尾#函式說明:#取得符合特定字首與字尾的字串#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],符合條件的字串,去掉字首字尾後的結果.#$result["returnString"],爲符合字首字、尾條件的字串內容。#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],字串,要檢查的字串.$conf["search::getMeetConditionsString"]["checkString"]=$conf["source"];#可省略參數:#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.#$conf["frontWord"]="";#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.$conf["search::getMeetConditionsString"]["tailWord"]="/";#參考資料:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。#備註:#無.$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);unset($conf["search::getMeetConditionsString"]);#如果執行失敗if($getMeetConditionsString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetConditionsString;#回傳結果return $result;}#if end#如果不是"/"結尾if($getMeetConditionsString["founded"]==="false"){#來源不是資料夾$sourceIsFolder="false";#取得來源目錄或檔案的資訊#函式說明:#取得節點的資訊.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函數名稱.#$result["content"],檔案資訊陣列.#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.#$result["content"]["ownerPerm"],檔案擁有者權限資訊.#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.#$result["content"]["ownerName"],檔案擁有着資訊.#$result["content"]["groupName"],檔案所屬擁有着資訊.#$result["content"]["size"],檔案大小.#$result["content"]["modifyDate"],檔案變更年月日.#$result["content"]["modifyTime"],檔案變更時分秒.#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.#必填參數:#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];#$conf["file"],字串,要查看擁有者資訊的檔案.$conf["fileAccess::fileInfo"]["file"]=$conf["source"];#可省略參數:#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".$conf["fileAccess::fileInfo"]["web"]="false";#參考資料:#fileowner=>http://php.net/manual/en/function.fileowner.php#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php#備註:$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);unset($conf["fileAccess::fileInfo"]);#如果執行失敗if($fileInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$fileInfo;#回傳結果return $result;}#if end#如果要複製的目標為目錄if($fileInfo["content"]["is_folder"]==="true"){#來源是資料夾$sourceIsFolder="true";#結尾加上"/"$conf["source"]=$conf["source"]."/";}#if end}#if end#反之來源為資料夾else{#來源是資料夾$sourceIsFolder="true";}#else end#函式說明:#取得符合特定字首與字尾的字串#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],符合條件的字串,去掉字首字尾後的結果.#$result["returnString"],爲符合字首字、尾條件的字串內容。#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],字串,要檢查的字串.$conf["search::getMeetConditionsString"]["checkString"]=$conf["target"];#可省略參數:#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.#$conf["frontWord"]="";#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.$conf["search::getMeetConditionsString"]["tailWord"]="/";#參考資料:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。#備註:#無.$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);unset($conf["search::getMeetConditionsString"]);#如果執行失敗if($getMeetConditionsString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetConditionsString;#回傳結果return $result;}#if end#如果不是 "/" 結尾if($getMeetConditionsString["founded"]==="false"){#檢查要複製到的目標所屬路徑是否存在#函式說明:#檢查路徑是否存在.#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],使用的參數.#$result["found"],路徑是否存在,"true"代表存在,"false"代表不存在.#$result["content"],每個階層路徑的檢查結果,每個元素有檢查的路徑"path"跟是否有存在或可存取的識別"found".#必填參數:#$conf["path"],要檢查的路徑$conf["fileAccess::checkPathExist"]["path"]=$conf["target"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkPathExist"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".#$conf["fileAccess::checkPathExist"]["haveFileName"]="true";#參考資料:#無.#備註:#無.$checkPathExist=fileAccess::checkPathExist($conf["fileAccess::checkPathExist"]);unset($conf["fileAccess::checkPathExist"]);#如果執行失敗if($checkPathExist["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkPathExist;#回傳結果return $result;}#if end#目的不是資料夾$targetIsFolder="false";#如果路徑都存在if($checkPathExist["found"]==="true"){#取得目標檔案的資訊#函式說明:#取得節點的資訊.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函數名稱.#$result["content"],檔案資訊陣列.#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.#$result["content"]["ownerPerm"],檔案擁有者權限資訊.#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.#$result["content"]["ownerName"],檔案擁有着資訊.#$result["content"]["groupName"],檔案所屬擁有着資訊.#$result["content"]["size"],檔案大小.#$result["content"]["modifyDate"],檔案變更年月日.#$result["content"]["modifyTime"],檔案變更時分秒.#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.#必填參數:#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];#$conf["file"],字串,要查看擁有者資訊的檔案.$conf["fileAccess::fileInfo"]["file"]=$conf["target"];#可省略參數:#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".$conf["fileAccess::fileInfo"]["web"]="false";#參考資料:#fileowner=>http://php.net/manual/en/function.fileowner.php#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php#備註:$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);unset($conf["fileAccess::fileInfo"]);#如果執行失敗if($fileInfo["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$fileInfo;#回傳結果return $result;}#if end#如果要複製到的目標為目錄if($fileInfo["content"]["is_folder"]==="true"){#目的是資料夾$targetIsFolder="true";#結尾加上"/"$conf["target"]=$conf["target"]."/";}#if end}#if end}#if end#反之else{#目的是資料夾$targetIsFolder="true";}#else end#如果來源跟目標不同為檔案為目錄if($sourceIsFolder!==$targetIsFolder){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="複製的來源與目標須同樣為目錄或檔案";#回傳結果return $result;}#if end#初始化給 rsync 的參數$params_for_rsync=array("-v","--progress","--links");#如果目錄底下的內容也要複製if($conf["recursive"]==="true"){#設置目錄底下的內容也要複製$params_for_rsync[]="-r";}#if end#如果有設置頻寬限制if(isset($conf["bandWidthLimit"])){#設置頻寬限制參數$params_for_rsync[]="--bwlimit";#設置頻寬限制參數數值$params_for_rsync[]=$conf["bandWidthLimit"];}#if end#如果有設置只要複製比較新的檔案if($conf["newFileOnly"]==="true"){#設置只要複製比較新的檔案$params_for_rsync[]="--update";}#if end#如果要用append的方法if($conf["appendMode"]==="true"){#設置要用append的方法$params_for_rsync[]="--append";}#if end#如果有排除特定檔案或目錄if(isset($conf["exclude"])){#針對每個要排除的檔案或目錄foreach($conf["exclude"] as $excludeSource){#設置要排除的檔案或目錄$params_for_rsync[]="--exclude=".$excludeSource;}#foreach end}#if end#如果有排除特定檔案類型if(isset($conf["excludeFileType"])){#針對每個要排除的檔案類型foreach($conf["excludeFileType"] as $excludeSource){#設置要排除的檔案類型$params_for_rsync[]="--exclude=\"*.".$excludeSource."\"";}#foreach end}#if end#如果要複製的目標不是 ./ 開頭#函式說明:#取得符合特定字首與字尾的字串#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],符合條件的字串,去掉字首字尾後的結果.#$result["returnString"],爲符合字首字、尾條件的字串內容。#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],字串,要檢查的字串.$conf["search::getMeetConditionsString"]["checkString"]=$conf["source"];#可省略參數:#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.$conf["search::getMeetConditionsString"]["frontWord"]="./";#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.#$conf["tailWord"]="";#參考資料:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。#備註:#無.$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);unset($conf["search::getMeetConditionsString"]);#如果執行失敗if($getMeetConditionsString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetConditionsString;#回傳結果return $result;}#if end#如果沒有符合if($getMeetConditionsString["founded"]==="false"){#如果要複製的目標不是 / 開頭#函式說明:#取得符合特定字首與字尾的字串#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],符合條件的字串,去掉字首字尾後的結果.#$result["returnString"],爲符合字首字、尾條件的字串內容。#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],字串,要檢查的字串.$conf["search::getMeetConditionsString"]["checkString"]=$conf["source"];#可省略參數:#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.$conf["search::getMeetConditionsString"]["frontWord"]="/";#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.#$conf["tailWord"]="";#參考資料:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。#備註:#無.$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);unset($conf["search::getMeetConditionsString"]);#如果執行失敗if($getMeetConditionsString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetConditionsString;#回傳結果return $result;}#if end#如果沒有符合if($getMeetConditionsString["founded"]==="false"){#加上 "./" 變成絕對位置,避免"::"被視為其他含義$conf["source"]="./".$conf["source"];}#if end}#if end#設置要複製的目標$params_for_rsync[]=$conf["source"];#如果要複製的目標不是 ./ 開頭#函式說明:#取得符合特定字首與字尾的字串#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],符合條件的字串,去掉字首字尾後的結果.#$result["returnString"],爲符合字首字、尾條件的字串內容。#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],字串,要檢查的字串.$conf["search::getMeetConditionsString"]["checkString"]=$conf["target"];#可省略參數:#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.$conf["search::getMeetConditionsString"]["frontWord"]="./";#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.#$conf["tailWord"]="";#參考資料:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。#備註:#無.$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);unset($conf["search::getMeetConditionsString"]);#如果執行失敗if($getMeetConditionsString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetConditionsString;#回傳結果return $result;}#if end#如果沒有符合if($getMeetConditionsString["founded"]==="false"){#如果要複製的目標不是 / 開頭#函式說明:#取得符合特定字首與字尾的字串#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],符合條件的字串,去掉字首字尾後的結果.#$result["returnString"],爲符合字首字、尾條件的字串內容。#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],字串,要檢查的字串.$conf["search::getMeetConditionsString"]["checkString"]=$conf["target"];#可省略參數:#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.$conf["search::getMeetConditionsString"]["frontWord"]="/";#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.#$conf["tailWord"]="";#參考資料:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。#備註:#無.$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);unset($conf["search::getMeetConditionsString"]);#如果執行失敗if($getMeetConditionsString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetConditionsString;#回傳結果return $result;}#if end#如果沒有符合if($getMeetConditionsString["founded"]==="false"){#加上 "./" 變成絕對位置,避免"::"被視為其他含義$conf["target"]="./".$conf["target"];}#if end}#if end#設置要備份到的位置或檔案名稱$params_for_rsync[]=$conf["target"];#執行rsync指令#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="rsync";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=$params_for_rsync;#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.$conf["external::callShell"]["escapeshellarg"]="true";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果執行失敗if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end#設置執行正常$result["status"]="true";#設置執行完的回應$result["content"]=$callShell["output"];#回傳結果return $result;}#function rsync end/*#函式說明:#使用 linux 的 httpd 指令來取得 vhost 資訊.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],得到的結果陣列,每個元素可能會含有的key有ServerName、DocumentRoot、ServerAlias,其中DocumentRoot的數值會是用""包起來的路徑.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["defaultConfig"],字串,httpd預設的設定檔位置,預設為"/etc/httpd/conf/http.conf".#$conf["defaultConfig"]="";#參考資料:#無#備註:#無.*/public static function httpdGetVhostInfo(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]="函數".$result["function"]."需要參數";#回傳結果return $result;}#if end#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("defaultConfig");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("defaultConfig");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/etc/httpd/conf/httpd.conf");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["arrayCountEqualCheck"][]=array();#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果執行失敗if($checkArguments["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查不通過if($checkArguments["passed"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#取得設定檔的內容#函式說明:#依據行號分隔抓取檔案的內容,結果會回傳一個陣列#回傳的變數說明:#$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["fileAccess::getFileContent"]["filePositionAndName"]=$conf["defaultConfig"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".#$conf["web"]="true";#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".#$conf["createIfnotExist"]="false";#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"$conf["fileAccess::getFileContent"]["autoDeleteSpaceOnEachLineStart"]="true";#參考資料:#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["fileAccess::getFileContent"]);unset($conf["fileAccess::getFileContent"]);#如果執行失敗if($getFileContent["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getFileContent;#回傳結果return $result;}#if end#取得 default Listen Add、port - start/*#ipv4+portListen 12.34.56.78:80*//*#port onlyListen 80*/#函式說明:#取得符合多個特定字首與字尾之一的字串們#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],陣列字串,要檢查的陣列字串.$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"Listen "),array("front"=>"DocumentRoot "));#可省略參數:#無.#參考資料:#無.#備註:#無.$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);unset($conf["search::getMeetMultiConditionsStrings"]);#如果執行失敗if($getMeetMultiConditionsStrings["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetMultiConditionsStrings;#回傳結果return $result;}#if end#如果沒有需要的關鍵字存在if($getMeetMultiConditionsStrings["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetMultiConditionsStrings;#回傳結果return $result;}#if end#解析 Listen and port and Document string#針對每個 sectionforeach($getMeetMultiConditionsStrings["content"] as $section){#取得區段名稱$name=$section["meetConditions"]["front"];#取得設定檔中該行的內容$lineDef=$section["oriStr"];#取得設定檔中該行定義的數值$lineVal=$section["content"];#判斷是哪個區段名稱switch($name){#如果是 Listen 區段case "Listen ":#函式說明:#將固定格式的字串分開,並回傳分開的結果.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$lineVal;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.#$conf["allowEmptyStr"]="false";#參考資料:#無.#備註:#無.$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果執行失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有需要的關鍵字存在if($spiltString["found"]==="false"){#代表只有設定 port#如果沒有 port 存在if(!isset($spiltString["dataArray"][0])){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="main configuration of httpd seems not right!";#設置錯誤訊息$result["error"][]=$spiltString;#回傳結果return $result;}#if end#確認是否為 只有 listen port#函式說明:#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.#必填參數:#$conf["input"],字串,要檢查的字串.$conf["search::findSpecifyStrFormat"]["input"]=$spiltString["dataArray"][0];#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.$conf["search::findSpecifyStrFormat"]["format"]="\${*}";#可省略參數:#無.#參考資料:#無.#備註:#無.$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);unset($conf["search::findSpecifyStrFormat"]);#若執行失敗if($findSpecifyStrFormat["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$findSpecifyStrFormat;#回傳結果return $result;}#if end#若符合格式if($findSpecifyStrFormat["found"]==="true"){#設置預設ip$defaultIp="*";#設置預設 port$defaultPort=$findSpecifyStrFormat["content"][0];}#if end}#if end#反之如果分成兩段else if($spiltString["dataCounts"]===2){#判斷是否為IPv4+port#函式說明:#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.#必填參數:#$conf["input"],字串,要檢查的字串.$conf["search::findSpecifyStrFormat"]["input"]=$spiltString["dataArray"][1];#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.$conf["search::findSpecifyStrFormat"]["format"]="\${*}.\${*}.\${*}.\${*}:\${*}";#可省略參數:#無.#參考資料:#無.#備註:#無.$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);unset($conf["search::findSpecifyStrFormat"]);#若執行失敗if($findSpecifyStrFormat["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$findSpecifyStrFormat;#回傳結果return $result;}#if end#若符合格式if($findSpecifyStrFormat["found"]==="true"){#設置預設的listen ip$defaultIp=$findSpecifyStrFormat[0].".".$findSpecifyStrFormat[1].".".$findSpecifyStrFormat[2].".".$findSpecifyStrFormat[3];#設置預設的listen port$defaultPort=$findSpecifyStrFormat[4];}#if end#反之非 ipv4+port 的格式else{#確認是否為 ipv6 + port#函式說明:#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.#必填參數:#$conf["input"],字串,要檢查的字串.$conf["search::findSpecifyStrFormat"]["input"]=$spiltString["dataArray"][1];#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.$conf["search::findSpecifyStrFormat"]["format"]="\${*}:\${*}";#可省略參數:#無.#參考資料:#無.#備註:#無.$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);unset($conf["search::findSpecifyStrFormat"]);#若執行失敗if($findSpecifyStrFormat["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$findSpecifyStrFormat;#回傳結果return $result;}#if end#若符合格式if($findSpecifyStrFormat["found"]==="true"){#設置預設ip$defaultIp=$findSpecifyStrFormat["content"][0];#設置預設 port$defaultPort=$findSpecifyStrFormat["content"][1];}#if end#反之,格式錯誤else{#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="main configuration of httpd seems not right!";#設置錯誤訊息$result["error"][]=$findSpecifyStrFormat;#回傳結果return $result;}#else end}#else end}#if end#反之else{#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="main configuration of httpd seems not right!";#設置錯誤訊息$result["error"][]=$findSpecifyStrFormat;#回傳結果return $result;}#else end#跳出 switchbreak;#如果是 DocumentRoot 區段case "DocumentRoot ":#函式說明:#將固定格式的字串分開,並回傳分開的結果.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$lineDef;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.#$conf["allowEmptyStr"]="false";#參考資料:#無.#備註:#無.$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果執行失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有關鍵字存在if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果沒有剛好切割成兩段if($spiltString["dataCounts"]!==2){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#取得預設的 document rooteval("\$documentRoot=".$spiltString["dataArray"][1].";");#另存一分預設的 document root$defaultDocumentRoot=$documentRoot;#跳出 switchbreak;#其他不支援的區段default:#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="unsupported section:".$getMeetMultiConditionsStrings["content"][0]["meetConditions"]["front"];#設置錯誤訊息$result["error"][]=$getMeetMultiConditionsStrings;#回傳結果return $result;}#switch end}#foreach end#取得 defaut Listen Add、port - end#取得 ServerName、ServerAlias、DocumentRoot - start#函式說明:#取得符合多個特定字首與字尾之一的字串們#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],陣列字串,要檢查的陣列字串.$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"ServerName"),array("front"=>"DocumentRoot"),array("front"=>"ServerAlias"));#可省略參數:#無.#參考資料:#無.#備註:#無.$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);unset($conf["search::getMeetMultiConditionsStrings"]);#如果執行失敗if($getMeetMultiConditionsStrings["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetMultiConditionsStrings;#回傳結果return $result;}#if end#如果沒有需要的關鍵字存在if($getMeetMultiConditionsStrings["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetMultiConditionsStrings;#回傳結果return $result;}#if end#如果預設的ip跟port跟document root有缺少任何一個if( !isset($defaultIp) || !isset($defaultPort) || !isset($defaultDocumentRoot) ){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"][]="main configuration of httpd seems not right!";#設置錯誤訊息$result["error"][]=$findSpecifyStrFormat;#回傳結果return $result;}#if end#初始化vhost的資訊$vhostInfo=array("ip"=>$defaultIp,"port"=>$defaultPort,"DocumentRoot"=>$defaultDocumentRoot);#針對每個找到的結果foreach($getMeetMultiConditionsStrings["content"] as $found){#取得符合的關鍵字/屬性名稱$attrName=$found["meetConditions"]["front"];#取得屬性的數值$attrValue=$found["content"];#移除屬性數值前面的空白#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$attrValue;#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";#可省略參數:#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.#$conf["lastResult"]=$delStrBeforeKeyWord;#參考資料:#無.#備註:#無.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果執行失敗if($delStrBeforeKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果不存在開頭的空白if($delStrBeforeKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#取得移除開頭空格後的屬性數值$attrValue=$delStrBeforeKeyWord["content"];#如果是 serverif($attrName==="ServerName"){#判斷 ServerName 的結尾是否為 ":".$port,並移除之.#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["deleted"],被移除的內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$attrValue;#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].#$conf["deleteLastRepeatedOne"]="";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);unset($conf["stringProcess::delStrAfterKeyWord"]);#如果執行失敗if($delStrAfterKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#如果有符合的關鍵字if($delStrAfterKeyWord["founded"]==="true"){#取得處理好的內容$attrValue=$delStrAfterKeyWord["content"];#更新 port$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);}#if end}#if end#如果是 DocumentRoot 的設定if($attrName==="DocumentRoot"){#設置其數值為沒有雙引號的內容eval("\$attrValue=".$attrValue.";");}#if end#設置 vhost 資訊$vhostInfo[$attrName]=$attrValue;}#foreach end#儲存解析出來的 vhost 資訊到要回傳的結果$result["content"][]=$vhostInfo;#取得 ServerName、ServerAlias、DocumentRoot - end#函式說明:#呼叫shell執行系統命令,並取得回傳的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["cmd"],執行的指令內容.#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.#$result["running"],是否還在執行.#$result["pid"],pid.#$result["statusCode"],執行結束後的代碼.#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").#必填參數:#$conf["command"],字串,要執行的指令.$conf["external::callShell"]["command"]="httpd";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.$conf["external::callShell"]["argu"]=array("-T","-D","DUMP_VHOSTS");#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").#$conf["arguIsAddr"]=array();#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".#$conf["enablePrintDescription"]="true";#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.#$conf["printDescription"]="";#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.#$conf["escapeshellarg"]="false";#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.#$conf["thereIsShellVar"]=array();#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.#$conf["username"]="";#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.#$conf["password"]="";#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".#$conf["useScript"]="";#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.#$conf["inBackGround"]="";#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.#$conf["getErr"]="false";#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.#$conf["doNotRun"]="false";#參考資料:#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#備註:#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.$callShell=external::callShell($conf["external::callShell"]);unset($conf["external::callShell"]);#如果檢查不通過if($callShell["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell;#回傳結果return $result;}#if end/*輸出範例VirtualHost configuration:169.254.1.1:80 latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:1)169.254.1.1:443 is a NameVirtualHostdefault server mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)port 443 namevhost mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)alias www.qbpwcf.orgalias qbpwcf.orgport 443 namevhost aesopower-svn-free.qbpwcf.org (/etc/httpd/conf.d/aesopower-svn-free.qbpwcf.org.conf:1)port 443 namevhost www.amaztik.com (/etc/httpd/conf.d/amaztik.conf:1)port 443 namevhost bei-jiao24.qbpwcf.org (/etc/httpd/conf.d/bei-jiao24.conf:1)port 443 namevhost egg-roll.qbpwcf.org (/etc/httpd/conf.d/egg-roll.qbpwcf.org.conf:1)port 443 namevhost freedomainandssl.cloudns.asia (/etc/httpd/conf.d/freeDomainAndSSL.conf:1)port 443 namevhost grgralisa-free.qbpwcf.org (/etc/httpd/conf.d/grgralisa-free.qbpwcf.org.conf:1)port 443 namevhost iuqi-free.qbpwcf.org (/etc/httpd/conf.d/iuqi-free.qbpwcf.org.conf:1)port 443 namevhost ajo-free.qbpwcf.org (/etc/httpd/conf.d/proxy-ajo-free.qbpwcf.org.conf:1)port 443 namevhost dlsite.qbpwcf.org (/etc/httpd/conf.d/proxy-dlsite.qbpwcf.org.conf:1)port 443 namevhost iuqi.qbpwcf.org (/etc/httpd/conf.d/proxy-iuqi.qbpwcf.org.conf:1)port 443 namevhost viivatw-free.qbpwcf.org (/etc/httpd/conf.d/proxy-viivatw-free.qbpwcf.org.conf:1)port 443 namevhost ws.qbpwcf.org (/etc/httpd/conf.d/proxy-ws.qbpwcf.org.conf:1)alias sock-ws.qbpwcf.orgport 443 namevhost latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:13)alias sock-latest.qbpwcf.orgport 443 namevhost sock.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-sock.conf:1)port 443 namevhost svn.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-svn.conf:1)port 443 namevhost sock.freedomainandssl.cloudns.asia (/etc/httpd/conf.d/sock.freeDomainAndSSL.conf:1)port 443 namevhost yao-lan-lesa-free.qbpwcf.org (/etc/httpd/conf.d/yao-lan-lesa-free.qbpwcf.org.conf:1)*/#輸出陣列#$callShell["output"];#初始化搭配的ip與port$ipAndPort="";#針對每行輸出for($line=0;$line<count($callShell["output"]);$line++){#若是第一行if($line===0){#若第一行輸出有錯if($callShell["output"][$line]!=="VirtualHost configuration:"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell["output"];#設置錯誤訊息$result["error"][]="output of VirtualHost configuration seems not right!";#回傳結果return $result;}#if end}#if end#反之else{#函式說明:#取得符合特定字首與字尾的字串#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],符合條件的字串,去掉字首字尾後的結果.#$result["returnString"],爲符合字首字、尾條件的字串內容。#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],字串,要檢查的字串.$conf["search::getMeetConditionsString"]["checkString"]=$callShell["output"][$line];#可省略參數:#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.$conf["search::getMeetConditionsString"]["frontWord"]=" ";#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.#$conf["tailWord"]="";#參考資料:#str_spilt(),可以將字串依照字母分割成一個個陣列字串。#備註:#無.$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);unset($conf["search::getMeetConditionsString"]);#如果執行失敗if($getMeetConditionsString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell["output"];#回傳結果return $result;}#if end#如果該行為空白開頭if($getMeetConditionsString["founded"]==="true"){#若無搭配的ip跟portif($ipAndPort===""){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$callShell["output"];#設置錯誤訊息$result["error"][]="output of VirtualHost configuration seems not right!";#回傳結果return $result;}#if end#執行到這邊代表輸出為以下格式/*default server mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)port 443 namevhost mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)alias www.qbpwcf.orgalias qbpwcf.orgport 443 namevhost aesopower-svn-free.qbpwcf.org (/etc/httpd/conf.d/aesopower-svn-free.qbpwcf.org.conf:1)port 443 namevhost www.amaztik.com (/etc/httpd/conf.d/amaztik.conf:1)port 443 namevhost bei-jiao24.qbpwcf.org (/etc/httpd/conf.d/bei-jiao24.conf:1)port 443 namevhost egg-roll.qbpwcf.org (/etc/httpd/conf.d/egg-roll.qbpwcf.org.conf:1)port 443 namevhost freedomainandssl.cloudns.asia (/etc/httpd/conf.d/freeDomainAndSSL.conf:1)port 443 namevhost grgralisa-free.qbpwcf.org (/etc/httpd/conf.d/grgralisa-free.qbpwcf.org.conf:1)port 443 namevhost iuqi-free.qbpwcf.org (/etc/httpd/conf.d/iuqi-free.qbpwcf.org.conf:1)port 443 namevhost ajo-free.qbpwcf.org (/etc/httpd/conf.d/proxy-ajo-free.qbpwcf.org.conf:1)port 443 namevhost dlsite.qbpwcf.org (/etc/httpd/conf.d/proxy-dlsite.qbpwcf.org.conf:1)port 443 namevhost iuqi.qbpwcf.org (/etc/httpd/conf.d/proxy-iuqi.qbpwcf.org.conf:1)port 443 namevhost viivatw-free.qbpwcf.org (/etc/httpd/conf.d/proxy-viivatw-free.qbpwcf.org.conf:1)port 443 namevhost ws.qbpwcf.org (/etc/httpd/conf.d/proxy-ws.qbpwcf.org.conf:1)alias sock-ws.qbpwcf.orgport 443 namevhost latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:13)alias sock-latest.qbpwcf.orgport 443 namevhost sock.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-sock.conf:1)port 443 namevhost svn.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-svn.conf:1)port 443 namevhost sock.freedomainandssl.cloudns.asia (/etc/httpd/conf.d/sock.freeDomainAndSSL.conf:1)port 443 namevhost yao-lan-lesa-free.qbpwcf.org (/etc/httpd/conf.d/yao-lan-lesa-free.qbpwcf.org.conf:1)*/#嘗試移除 "(" 前面的內容#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$callShell["output"][$line];#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="(";#可省略參數:#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.#$conf["recursive"]="true";#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.#$conf["lastResult"]=$delStrBeforeKeyWord;#參考資料:#無.#備註:#無.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果執行失敗if($delStrBeforeKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果應該要存在的關鍵字存在if($delStrBeforeKeyWord["founded"]==="true"){#嘗試移除 ")" 後面的內容#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=")";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].#$conf["deleteLastRepeatedOne"]="";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);unset($conf["stringProcess::delStrAfterKeyWord"]);#如果執行失敗if($delStrAfterKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#如果無找到 ")"if($delStrAfterKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#嘗試移除":number"#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrAfterKeyWord["content"];#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="true";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);unset($conf["stringProcess::delStrAfterKeyWord"]);#如果執行失敗if($delStrAfterKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#取得 vhost 設定檔案的位置$vhostFile=$delStrAfterKeyWord["content"];#取得設定檔的內容#函式說明:#依據行號分隔抓取檔案的內容,結果會回傳一個陣列#回傳的變數說明:#$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["fileAccess::getFileContent"]["filePositionAndName"]=$vhostFile;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".#$conf["web"]="true";#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".#$conf["createIfnotExist"]="false";#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"$conf["fileAccess::getFileContent"]["autoDeleteSpaceOnEachLineStart"]="true";#參考資料:#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["fileAccess::getFileContent"]);unset($conf["fileAccess::getFileContent"]);#如果執行失敗if($getFileContent["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getFileContent;#回傳結果return $result;}#if end#符合條件的內容範例/*DocumentRoot "/var/www/html/qbpwcf"ServerName mobile.qbpwcf.org:443ServerAlias www.qbpwcf.orgServerAlias qbpwcf.org*/#取得 ServerName、ServerAlias、DocumentRoot - start#函式說明:#取得符合多個特定字首與字尾之一的字串們#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],陣列字串,要檢查的陣列字串.$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"ServerName"),array("front"=>"DocumentRoot"),array("front"=>"ServerAlias"));#可省略參數:#無.#參考資料:#無.#備註:#無.$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);unset($conf["search::getMeetMultiConditionsStrings"]);#如果執行失敗if($getMeetMultiConditionsStrings["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetMultiConditionsStrings;#回傳結果return $result;}#if end#如果沒有需要的關鍵字存在if($getMeetMultiConditionsStrings["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetMultiConditionsStrings;#回傳結果return $result;}#if end#初始化vhost的資訊$vhostInfo=array("ip"=>$ip,"port"=>$port);#針對每個找到的結果foreach($getMeetMultiConditionsStrings["content"] as $found){#取得符合的關鍵字/屬性名稱$attrName=$found["meetConditions"]["front"];#取得屬性的數值$attrValue=$found["content"];#移除屬性數值前面的空白#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$attrValue;#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";#可省略參數:#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.#$conf["lastResult"]=$delStrBeforeKeyWord;#參考資料:#無.#備註:#無.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果執行失敗if($delStrBeforeKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果不存在開頭的空白if($delStrBeforeKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#取得移除開頭空格後的屬性數值$attrValue=$delStrBeforeKeyWord["content"];#如果是 serverif($attrName==="ServerName"){#判斷 ServerName 的結尾是否為 ":".$port,並移除之.#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["deleted"],被移除的內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$attrValue;#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].#$conf["deleteLastRepeatedOne"]="";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);unset($conf["stringProcess::delStrAfterKeyWord"]);#如果執行失敗if($delStrAfterKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#如果有符合的關鍵字if($delStrAfterKeyWord["founded"]==="true"){#取得處理好的內容$attrValue=$delStrAfterKeyWord["content"];#更新 port$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);}#if end}#if end#設置 vhost 資訊$vhostInfo[$attrName]=$attrValue;}#foreach end#如果沒有 document 存在if(!isset($vhostInfo["DocumentRoot"])){#給予預設的 document root$vhostInfo["DocumentRoot"]=$defaultDocumentRoot;}#if end#儲存解析出來的 vhost 資訊到要回傳的結果$result["content"][]=$vhostInfo;#取得 ServerName、ServerAlias、DocumentRoot - end}#if end}#if end#反之為 Listen 的 addr & port infoelse{/*輸出範例169.254.1.1:80 latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:1)169.254.1.1:443 is a NameVirtualHost*/#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$callShell["output"][$line];#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=" ";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].#$conf["deleteLastRepeatedOne"]="";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);unset($conf["stringProcess::delStrAfterKeyWord"]);#如果執行失敗if($delStrAfterKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#如果應該要存在的關鍵字不存在if($delStrAfterKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#取得IP跟Port$listenAddrAndPort=$delStrAfterKeyWord["content"];#函式說明:#將固定格式的字串分開,並回傳分開的結果.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要分割的原始字串內容#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。#$result["dataCounts"],爲總共分成幾段#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::spiltString"]["stringIn"]=$listenAddrAndPort;#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#可省略參數:#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.#$conf["allowEmptyStr"]="false";#參考資料:#無.#備註:#無.$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);unset($conf["stringProcess::spiltString"]);#如果執行失敗if($spiltString["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果應該要存在的關鍵字不存在if($spiltString["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#如果不是切成兩段if($spiltString["dataCounts"]!==2){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$spiltString;#回傳結果return $result;}#if end#更新 ip and port 變數$ipAndPort=$spiltString["oriStr"];#更新 ip$ip=$spiltString["dataArray"][0];#更新 port$port=$spiltString["dataArray"][1];#嘗試移除 "(" 前面的內容#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$callShell["output"][$line];#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="(";#可省略參數:#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.#$conf["recursive"]="true";#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.#$conf["lastResult"]=$delStrBeforeKeyWord;#參考資料:#無.#備註:#無.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果執行失敗if($delStrBeforeKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果應該要存在的關鍵字存在if($delStrBeforeKeyWord["founded"]==="true"){#嘗試移除 ")" 後面的內容#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=")";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].#$conf["deleteLastRepeatedOne"]="";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);unset($conf["stringProcess::delStrAfterKeyWord"]);#如果執行失敗if($delStrAfterKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#如果無找到 ")"if($delStrAfterKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#嘗試移除":number"#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrAfterKeyWord["content"];#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="true";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);unset($conf["stringProcess::delStrAfterKeyWord"]);#如果執行失敗if($delStrAfterKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#取得 vhost 設定檔案的位置$vhostFile=$delStrAfterKeyWord["content"];#取得設定檔的內容#函式說明:#依據行號分隔抓取檔案的內容,結果會回傳一個陣列#回傳的變數說明:#$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["fileAccess::getFileContent"]["filePositionAndName"]=$vhostFile;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".#$conf["web"]="true";#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".#$conf["createIfnotExist"]="false";#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"$conf["fileAccess::getFileContent"]["autoDeleteSpaceOnEachLineStart"]="true";#參考資料:#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["fileAccess::getFileContent"]);unset($conf["fileAccess::getFileContent"]);#如果執行失敗if($getFileContent["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getFileContent;#回傳結果return $result;}#if end#符合條件的內容範例/*DocumentRoot "/var/www/html/qbpwcf"ServerName mobile.qbpwcf.org:443ServerAlias www.qbpwcf.orgServerAlias qbpwcf.org*/#取得 ServerName、ServerAlias、DocumentRoot - start#函式說明:#取得符合多個特定字首與字尾之一的字串們#回傳結果:#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.#$result["argu"],使用的參數.#必填參數:#$conf["checkString"],陣列字串,要檢查的陣列字串.$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"ServerName"),array("front"=>"DocumentRoot"),array("front"=>"ServerAlias"));#可省略參數:#無.#參考資料:#無.#備註:#無.$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);unset($conf["search::getMeetMultiConditionsStrings"]);#如果執行失敗if($getMeetMultiConditionsStrings["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetMultiConditionsStrings;#回傳結果return $result;}#if end#如果沒有需要的關鍵字存在if($getMeetMultiConditionsStrings["found"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$getMeetMultiConditionsStrings;#回傳結果return $result;}#if end#初始化vhost的資訊$vhostInfo=array("ip"=>$defaultIp,"port"=>$defaultPort,"DocumentRoot"=>$defaultDocumentRoot);#針對每個找到的結果foreach($getMeetMultiConditionsStrings["content"] as $found){#取得符合的關鍵字/屬性名稱$attrName=$found["meetConditions"]["front"];#取得屬性的數值$attrValue=$found["content"];#移除屬性數值前面的空白#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$attrValue;#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";#可省略參數:#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.#$conf["lastResult"]=$delStrBeforeKeyWord;#參考資料:#無.#備註:#無.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);unset($conf["stringProcess::delStrBeforeKeyWord"]);#如果執行失敗if($delStrBeforeKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#如果不存在開頭的空白if($delStrBeforeKeyWord["founded"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrBeforeKeyWord;#回傳結果return $result;}#if end#取得移除開頭空格後的屬性數值$attrValue=$delStrBeforeKeyWord["content"];#如果是 ServerName 定義行if($attrName="ServerName"){#判斷 ServerName 的結尾是否為 ":".$port,並移除之.#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["deleted"],被移除的內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$attrValue;#$conf["keyWord"],字串,特定字串.$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].#$conf["deleteLastRepeatedOne"]="";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);unset($conf["stringProcess::delStrAfterKeyWord"]);#如果執行失敗if($delStrAfterKeyWord["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$delStrAfterKeyWord;#回傳結果return $result;}#if end#如果有符合的關鍵字if($delStrAfterKeyWord["founded"]==="true"){#取得處理好的內容$attrValue=$delStrAfterKeyWord["content"];#更新 port$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);}#if end#更新 port$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);}#if end#設置 vhost 資訊$vhostInfo[$attrName]=$attrValue;}#foreach end#如果沒有 document 存在if(!isset($vhostInfo["DocumentRoot"])){#給予預設的 document root$vhostInfo["DocumentRoot"]=$defaultDocumentRoot;}#if end#儲存解析出來的 vhost 資訊到要回傳的結果$result["content"][]=$vhostInfo;#取得 ServerName、ServerAlias、DocumentRoot - end}#if end}#else end}#else end}#if end#剔除重複的vhost內容#函式說明:#將陣列中重複的元素剔除#回傳的結果:#$result["status"],"true"表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["content"],合併好的陣列.#必填參數#$conf["inputArray"],陣列,要合併的陣列變數.$conf["arrays::unique"]["inputArray"]=$result["content"];#可省略參數:#無.#參考資料:#無.#備註:#無.$unique=arrays::unique($conf["arrays::unique"]);unset($conf["arrays::unique"]);#debug#var_dump(__LINE__,$unique);#如果執行失敗if($unique["status"]==="false"){#設置執行失敗$result["status"]="false";#設置錯誤訊息$result["error"]=$unique;#回傳結果return $result;}#if end#取得不重複的vhost內容$result["content"]=$unique["content"];#如果沒有vhost的解析結果if(!isset($result["content"])){#設置錯誤訊息$result["error"][]="No vhost setting found";#設置執行失敗$result["status"]="false";#回傳結果return $result;}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function httpdGetVhostInfo end/*#函式說明:#產生 rpmspec 檔案內容的程式.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],得到的rpm spec檔案內容字串.#必填參數:#$conf["name"],字串,要產生的package名稱.#$conf["name"]="";#$conf["version"],字串,版本號,不可含有"-".#$conf["version"]="";#$conf["summary"],字串,package的簡述.#$conf["summary"]="";#$conf["desc"],字串,package的完整描述.#$conf["desc"]="";#可省略參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑#$conf["fileArgu"]=__FILE__;#$conf["release"],字串,發行版次。初始值一般都應該是 "1%{?dist}" ,每次新發行同版本軟體的軟體包就遞增一個數字。若上游發行新的版本,就對應修改 Version 標籤,然後把 Release >發行版次重設回 1#$conf["release"]="";#$conf["license"],字串,版權宣告,預設為 "GPL-3.0-or-later" .#$conf["license"]="";#$conf["projectUrl"],字串,該package所屬專案的官方網址,預設為"https://%{name}.qbpwcf.org".#$conf["projectUrl"]="";#$conf["sourceFileUrl"],字串,原始碼檔案的下載位置,預設為"https://%{name}.qbpwcf.org/%{name}-%{version}.tar.zst"#$conf["sourceFileUrl"]="";#$conf["preRequiredPacakge"],字串陣列,編譯與安裝該package要有哪些package預先安裝好.預設不設定,亦即沒有須要必備的package.#$conf["preRequiredPacakge"]=array();#$conf["arch"],字串,package對應的處理器架構,例如 "aarch64","x86_64" 等,預設為 "noarch"(不指定處理器架構),亦即為通用的package.#$conf["arch"]="";#$conf["configure"],字串,編譯前是否需要運行 configure 檔案來進行設定,預設為"true"代表要;反之為"false".#$conf["configure"]="";#$conf["build"],字串,是否需要進行編譯的動作,預設為 "false" 代表不用;反之為 "true".#$conf["build"]="";#可省略參數:#無.#參考資料:#無#備註:#建構中...*/public static function createRPMspec(&$conf){}#function createRPMspec end}#class cmd end?>