Rev 226 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2014~2026 MIN ZHI, 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;/*類別說明:提供類似cronjob服務的類別.備註:無.*/class autoService{/*#函式說明:#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.#回傳結果:#$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/*#函式說明:#新增或覆蓋系統上有哪些要自動執行的工作.#回傳結果:#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],當前排程資訊內容.#$result["argu"],使用的參數.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#$conf["actions"],字串陣列,每個元素代表要執行的事情,每個事情為要執行的指令與參數所組成的一維陣列.$conf["actions"]=array();#$conf["times"],字串陣列,每個元素代表要執行事情的時間點,單為為秒.格式為UTC時區的「年年年年-月月-日日 時 時:分分:秒秒」格式,事情不存在於啟動的狀態且當前時間大於等於之就會執行.$conf["times"]=array();#$conf["repeat"],字串陣列,每個元素為一維陣列,代表要執行事情的重複方式.key為"times"代表剩下幾次可以執行,其value為"N"代表剩下N次(若N等於-1,則代表無限重複執行;若N等於0,則代表不用執行);key為"after"代表下次執行的時間為times+加其value;key為"fixed"代表下次執行的時間為一個循環的固定時間點,value為每次循環的固定時間點,例如每天01:05則為 yearOfTimes-monthOfTimes-dayOfTimes 01:05:SeccondOfTimes.$conf["repeat"]=array();#可省略參數:#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".#$conf["config"]="";#$conf["uuids"],字串陣列,每個排程的uuid,若不指定則會自動產生,若跟既有action的uuid相同,則會覆蓋其相關資訊.#$conf["uuids"]=array();#參考資料:#無.#備註:#無.*/public static function createList(&$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["argu"]=$conf;#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["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("fileArgu","actions","times","repeat");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","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["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("config");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("config","uuids");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/local/etc/qbpwcf-schedule.conf.php",null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".#$conf["disallowAllSkipableVarNotExist"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("actions","times","repeat");#參考資料:#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#檢查每個 time 的格式foreach($conf["times"] as $time){#函式說明:#檢查字串是否符合 RFC 3339/ISO-8601 格式#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["passed"],檢查是否通過,"true"代表通過,"false"代表不通過.#$result["argu"],使用的參數.#$result["function"],當前執行的函數.#$result["error"],涵式錯誤訊息陣列.#必填參數:#$conf["input"],字串,要檢查格式的字串.$conf["variableCheck::checkRFC3339"]["input"]=$time;#可省略參數:#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"true",代表要;反之為"false".#$conf["variableCheck::checkRFC3339"]["UTC"]="false";#參考資料:#ISO 8601-2:2019=>https://www.rfc-editor.org/info/rfc3339#rfc3339=>https://www.rfc-editor.org/rfc/rfc3339#備註:#無.$checkRFC3339=variableCheck::checkRFC3339($conf["variableCheck::checkRFC3339"]);unset($conf["variableCheck::checkRFC3339"]);#如果執行出錯if($checkRFC3339["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkRFC3339;#回傳結果return $result;}#if end#如果檢查不通過if($checkRFC3339["passed"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkRFC3339;#回傳結果return $result;}#if end}#foreach end#取得uuid的數量應該要多少$uuidCount=count($conf["actions"]);#如果沒有指定 uuidsif(!isset($conf["uuids"])){#初始化 uuids$conf["uuids"]=array();#產生對應數量的uuidfor($i=0;$i<$uuidCount;$i++){#函式說明:#使用 linux 的 uuid 指令來產生 uuid 字串#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#必填參數:#無.#可省略參數:#無.#參考資料:#無.#備註:#無.$uuid=cmd::uuid();#如果執行失敗if($uuid["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$uuid;#回傳結果return $result;}#if end#儲存新的uuid$conf["uuids"][]=$uuid["content"];}#for end}#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["config"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".#$conf["web"]="true";#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".$conf["fileAccess::getFileContent"]["createIfnotExist"]="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#初始化原始設定擋內容$oriConfig=array();#針對每行內容foreach($getFileContent["fileContent"] as $lineNo=>$line){#解析內容#函式說明:#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函數名稱.#$result["content"],加密後的結果.#$result["error"],錯誤訊息陣列.#$result["argu"],使用的參數.#必填參數:#$conf["enCodeStr"],"字串",要加密的字串.$conf["authenticate::enCodeStr"]["enCodeStr"]=$line;#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";#可省略參數:#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".#$conf["sha1Raw"]="false";#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.#$conf["p_hash"]="";#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.#$conf["keyForAes256"]="";#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.#$conf["aes256Encode"]="";#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";#參考資料:#sha1=>http://php.net/manual/en/function.sha1.php#md5=>http://php.net/manual/en/function.md5.php#password_hash=>http://php.net/manual/en/function.password-hash.php#password_verify=>http://php.net/manual/en/function.password-verify.php#json_decode=>https://www.php.net/manual/en/function.json-decode.php#備註:#無.$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);unset($conf["authenticate::enCodeStr"]);#如果執行失敗if($enCodeStr["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$enCodeStr;#回傳結果return $result;}#if end#解碼後的內容$oriConfig[]=$enCodeStr["content"];}#foreach end#針對每個要新增的排程foreach($conf["actions"] as $index => $action){#針對每個既有的排程foreach($oriConfig as $indexFor_oriConfig => $oCfg){#針對既有排程的uuid$ouuid=$oCfg->uuid;#函式說明:#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.#回傳結果:#$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"]=$ouuid;#$conf["compareElements"],字串陣列,要比對的陣列變數內容.$conf["search::getEqualVar"]["compareElements"]=$conf["uuids"];#可省略參數:#無.#參考資料:#無.#備註:#無.$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);unset($conf["search::getEqualVar"]);#如果執行失敗if($getEqualVar["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$getEqualVar;#回傳結果return $result;}#if end#如果有找到相同uuidif($getEqualVar["founded"]==="true"){#移除舊排程unset($oriConfig[$indexFor_oriConfig]);#換看下個新排程的uuidbreak;}#if end}#foreach end}#foreach end#初始化儲存未加密的排程資訊$rawScheduleInfo=$oriConfig;#將剩下的每個舊排程foreach($oriConfig as $index => $config){#加密內容#函式說明:#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函數名稱.#$result["content"],加密後的結果.#$result["error"],錯誤訊息陣列.#$result["argu"],使用的參數.#必填參數:#$conf["enCodeStr"],"字串",要加密的字串.$conf["authenticate::enCodeStr"]["enCodeStr"]=$config;#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";#可省略參數:#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".#$conf["sha1Raw"]="false";#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.#$conf["p_hash"]="";#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.#$conf["keyForAes256"]="";#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.#$conf["aes256Encode"]="";#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.#$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";#參考資料:#sha1=>http://php.net/manual/en/function.sha1.php#md5=>http://php.net/manual/en/function.md5.php#password_hash=>http://php.net/manual/en/function.password-hash.php#password_verify=>http://php.net/manual/en/function.password-verify.php#json_decode=>https://www.php.net/manual/en/function.json-decode.php#備註:#無.$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);unset($conf["authenticate::enCodeStr"]);#如果執行失敗if($enCodeStr["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$enCodeStr;#回傳結果return $result;}#if end#取得加密後的內容$newConfig[]=$enCodeStr["content"];}#foreach end#針對每個要新增的排程foreach($conf["actions"] as $index => $action){#取得該uuid$uuid=$conf["uuids"][$index];#取得該time$time=$conf["times"][$index];#函式說明:#計算時間點距離1970/01/01多少秒,亦即unixtime.#回傳結果:#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.#$result["error"],錯誤訊息陣列.#$result["content"],時間點距離1970/01/01的多少秒.#$result["argu"],使用的參數.#$result["unixtime"],執行本函式時的unixtime.#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.#必填參數:#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.$conf["time::caculateTimeAmount"]["dateAndTime"]=$time;#可省略參數:#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".$conf["time::caculateTimeAmount"]["UTC"]="true";#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".#$conf["replace0"]="true";#參考資料:#無.#備註:#無.$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);unset($conf["time::caculateTimeAmount"]);#如果執行失敗if($caculateTimeAmount["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$caculateTimeAmount;#回傳結果return $result;}#if end#轉換成unixtime$time=$caculateTimeAmount["content"];#取得新增/覆蓋排程設定時的unixtime$lastUpdateUnixTime=$time;#取代該repeat$repeat=$conf["repeat"][$index];#如果有指定固定時間執行if(isset($repeat["fixed"])){#函式說明:#計算時間點距離1970/01/01多少秒,亦即unixtime.#回傳結果:#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.#$result["error"],錯誤訊息陣列.#$result["content"],時間點距離1970/01/01的多少秒.#$result["argu"],使用的參數.#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.#必填參數:#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.$conf["time::caculateTimeAmount"]["dateAndTime"]=$repeat["fixed"];#可省略參數:#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".$conf["time::caculateTimeAmount"]["UTC"]="true";#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".#$conf["replace0"]="true";#參考資料:#無.#備註:#無.$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);unset($conf["time::caculateTimeAmount"]);#如果執行失敗if($caculateTimeAmount["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$caculateTimeAmount;#回傳結果return $result;}#if end#更新時間為unixtime$repeat["fixed"]=$caculateTimeAmount["content"];}#if end#要加密的排程資訊,uuid(排程的識別碼),time(預計要執行的時間),repeat(重複的方式),update(新增/覆蓋排程設定時的unixtime)$scheduleInfo=array("uuid"=>$uuid,"action"=>$action,"time"=>$time,"repeat"=>$repeat,"update"=>$time);#儲存未加密的排程資訊$rawScheduleInfo[]=$scheduleInfo;#加密內容#函式說明:#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函數名稱.#$result["content"],加密後的結果.#$result["error"],錯誤訊息陣列.#$result["argu"],使用的參數.#必填參數:#$conf["enCodeStr"],"字串",要加密的字串.$conf["authenticate::enCodeStr"]["enCodeStr"]=$scheduleInfo;#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";#可省略參數:#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".#$conf["sha1Raw"]="false";#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.#$conf["p_hash"]="";#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.#$conf["keyForAes256"]="";#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.#$conf["aes256Encode"]="";#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.#$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";#參考資料:#sha1=>http://php.net/manual/en/function.sha1.php#md5=>http://php.net/manual/en/function.md5.php#password_hash=>http://php.net/manual/en/function.password-hash.php#password_verify=>http://php.net/manual/en/function.password-verify.php#json_decode=>https://www.php.net/manual/en/function.json-decode.php#備註:#無.$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);unset($conf["authenticate::enCodeStr"]);#如果執行失敗if($enCodeStr["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$enCodeStr;#回傳結果return $result;}#if end#取得加密後的內容$newConfig[]=$enCodeStr["content"];}#foreach end#更新排程設定檔#函式說明:#將多行字串寫入到檔案#回傳結果:#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行函數的名稱.#必填參數:#$conf["fileName"],字串,爲要編輯的檔案名稱$conf["fileAccess::writeMultiLine"]["fileName"]=$conf["config"];#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。$conf["fileAccess::writeMultiLine"]["inputString"]=$newConfig;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。#$conf["fileAccess::writeMultiLine"]["writeMethod"]="a";#參考資料:#無.#備註:#無.$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);unset($conf["fileAccess::writeMultiLine"]);#如果執行失敗if($writeMultiLine["status"]=="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$writeMultiLine;#回傳結果return $result;}#if end#設置當前排程結果資訊$result["content"]=$rawScheduleInfo;#設置執行正常$result["status"]="true";return $result;}#function createList end/*#函式說明:#查詢系統上有哪些要自動執行的工作#回傳結果:#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["content"],回傳的結果,排程的工作資訊陣列,每個元素的key有"uuid"跟"cmd&argu",前者為用於執行完畢時回報的排程項目識別;後者為該排程事項的指令與參數.#$result["function"],當前執行的函式名稱.必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".#$conf["config"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function getList(&$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["argu"]=$conf;#檢查參數#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。#$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("fileArgu");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("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("config");#$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("/usr/local/etc/qbpwcf-schedule.conf.php");#$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#函式說明:#依據行號分隔抓取檔案的內容,結果會回傳一個陣列#回傳的變數說明:#$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["config"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".$conf["fileAccess::getFileContent"]["web"]="false";#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".$conf["fileAccess::getFileContent"]["createIfnotExist"]="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#解析檔案內容#針對每行內容foreach($getFileContent["fileContent"] as $line){#加密內容#函式說明:#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函數名稱.#$result["content"],加密後的結果.#$result["error"],錯誤訊息陣列.#$result["argu"],使用的參數.#必填參數:#$conf["enCodeStr"],"字串",要加密的字串.$conf["authenticate::enCodeStr"]["enCodeStr"]=$line;#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";#可省略參數:#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".#$conf["sha1Raw"]="false";#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.#$conf["p_hash"]="";#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.#$conf["keyForAes256"]="";#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.#$conf["aes256Encode"]="";#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";#參考資料:#sha1=>http://php.net/manual/en/function.sha1.php#md5=>http://php.net/manual/en/function.md5.php#password_hash=>http://php.net/manual/en/function.password-hash.php#password_verify=>http://php.net/manual/en/function.password-verify.php#json_decode=>https://www.php.net/manual/en/function.json-decode.php#備註:#無.$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);unset($conf["authenticate::enCodeStr"]);#如果執行失敗失敗if($enCodeStr["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$enCodeStr;#回傳結果return $result;}#if end#取得解密後的內容$line=$enCodeStr["content"];#debug#var_dump($line);#如果內容沒有 uuidif(!isset($line->uuid)){#忽略該行continue;}#if end#取得排程的uuid$actionUuid=&$line->uuid;#如果內容沒有 time ,亦即排程設定的(預期/已)執行時間if(!isset($line->time)){#忽略該行continue;}#if end#取得排程的時間$actionUnixTime=&$line->time;#如果內容沒有 action ,亦即排程設定的指令與參數.if(!isset($line->action)){#忽略該行continue;}#if end#取得排程要做的事情資訊$actionInfo=&$line->action;#如果內容沒有 repeat ,亦即排程設定的執行模式.if(!isset($line->repeat)){#忽略該行continue;}#if end#反之若不是無窮執行else if($line->repeat!=="-1"){#如果內容有 repeat->times ,亦即排程設定的剩下重複次數.if(isset($line->repeat->times)){#取得剩下的重複執行次數$leftRepeatTimes=&$line->repeat->times;}#if end#反之如果內容沒有 repeat->after(亦即排程設定的重複條件為time的之後多久) 跟 repeat->time->fixed(亦即排程設定的重複條件為用update mask過後的指定時間).else if( !isset($line->repeat->after) && !isset($line->repeat->fixed) ){#忽略該行continue;}#else end}#if end#如果內容沒有 update,亦即排程設定最後更新的時間if(!isset($line->update)){#忽略該行continue;}#if end#初始化要執行的事情資訊$jobInfo=array();#設置其uuid$jobInfo["uuid"]=$actionUuid;#設置其指令與參數$jobInfo["cmd&argu"]=$actionInfo;#設置其預期執行的unixtime$jobInfo["time"]=$actionUnixTime;#設置其重複規則$jobInfo["repeat"]=$line->repeat;#儲存工作資訊$result["content"][]=$jobInfo;}#foreach end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function getList end/*#函式說明:#查詢系統上有哪些於當下要自動執行的工作#回傳結果:#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["content"],回傳的結果,要執行的工作資訊陣列,每個元素的key有"uuid"跟"cmd&argu",前者為用於執行完畢時回報的排程項目識別;後者為該排程事項的指令與參數.#$result["function"],當前執行的函式名稱.#$result["found"],識別是否有要執行的動作.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".#$conf["config"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function checkList(&$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["argu"]=$conf;#檢查參數#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。#$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("fileArgu");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("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("config");#$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("/usr/local/etc/qbpwcf-schedule.conf.php");#$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#函式說明:#依據行號分隔抓取檔案的內容,結果會回傳一個陣列#回傳的變數說明:#$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["config"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".$conf["fileAccess::getFileContent"]["web"]="false";#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".$conf["fileAccess::getFileContent"]["createIfnotExist"]="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#解析檔案內容#針對每行內容foreach($getFileContent["fileContent"] as $line){#加密內容#函式說明:#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函數名稱.#$result["content"],加密後的結果.#$result["error"],錯誤訊息陣列.#$result["argu"],使用的參數.#必填參數:#$conf["enCodeStr"],"字串",要加密的字串.$conf["authenticate::enCodeStr"]["enCodeStr"]=$line;#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";#可省略參數:#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".#$conf["sha1Raw"]="false";#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.#$conf["p_hash"]="";#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.#$conf["keyForAes256"]="";#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.#$conf["aes256Encode"]="";#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";#參考資料:#sha1=>http://php.net/manual/en/function.sha1.php#md5=>http://php.net/manual/en/function.md5.php#password_hash=>http://php.net/manual/en/function.password-hash.php#password_verify=>http://php.net/manual/en/function.password-verify.php#json_decode=>https://www.php.net/manual/en/function.json-decode.php#備註:#無.$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);unset($conf["authenticate::enCodeStr"]);#如果執行失敗失敗if($enCodeStr["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$enCodeStr;#回傳結果return $result;}#if end#取得解密後的內容$line=$enCodeStr["content"];#如果內容沒有 uuidif(!isset($line->uuid)){#忽略該行continue;}#if end#取得排程的uuid$actionUuid=&$line->uuid;#如果內容沒有 time ,亦即排程設定的(預期/已)執行時間if(!isset($line->time)){#忽略該行continue;}#if end#取得排程的時間$actionUnixTime=&$line->time;#如果內容沒有 action ,亦即排程設定的指令與參數.if(!isset($line->action)){#忽略該行continue;}#if end#取得排程要做的事情資訊$actionInfo=&$line->action;#如果內容沒有 repeat ,亦即排程設定的執行模式.if(!isset($line->repeat)){#忽略該行continue;}#if end#反之若不是無窮執行else if($line->repeat!=="-1"){#如果內容有 repeat->times ,亦即排程設定的剩下重複次數.if(isset($line->repeat->times)){#取得剩下的重複執行次數$leftRepeatTimes=&$line->repeat->times;}#if end#反之如果內容沒有 repeat->after(亦即排程設定的重複條件為time的之後多久) 跟 repeat->time->fixed(亦即排程設定的重複條件為用update mask過後的指定時間).else if( !isset($line->repeat->after) && !isset($line->repeat->fixed) ){#忽略該行continue;}#else end}#if end#如果內容沒有 update,亦即排程設定最後更新的時間if(!isset($line->update)){#忽略該行continue;}#if end#取得當下時間$currenUnixTime=time::unix()["content"];#如果當前時間大於等於排程的時間if($currenUnixTime>=$actionUnixTime){#如果有抓到剩下的執行次數if(isset($leftRepeatTimes)){#如果剩下的次數為0if((int)$leftRepeatTimes===0){#跳過不執行continue;}#if end}#if end#初始化要執行的事情資訊$jobInfo=array();#設置其uuid$jobInfo["uuid"]=$actionUuid;#設置其指令與參數$jobInfo["cmd&argu"]=$actionInfo;#儲存工作資訊$result["content"][]=$jobInfo;}#if end}#foreach end#預設置沒有事情要執行$result["found"]="false";#如果有要執行的事情if(isset($result["content"])){#設置有事情要執行$result["found"]="true";}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function checkList end/*#函式說明:#依照autoService::createList建立的設定檔案來執行排程事項,執行完畢後會更新排程設定檔案,並輸出執行結果.#回傳結果:#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],要執行排程的執行結果陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表輸出的陣列,其元素的key有"std"(標準輸出)與"err"(非標準輸出);#$result["updatedConfigContent"],新的排程內容,有異動才會有這數值.#$result["argu"],所使用的參數.#$result["cache"],若本函式作為 sock::unixDomainSockServer 的 funcToRunWhenIdle 參數,則該回傳內容,可以複寫cache,變成下次呼叫本函式的serverCache參數.若沒有執行任何排程,則不會回傳該結果.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".#$conf["config"]="";#$conf["client"],陣列,若本函式作為 sock::unixDomainSockServer 的 funcToRunWhenIdle 參數,則此為所有用戶的資訊.#$conf["client"]=;#$conf["serverCache"],陣列,若本函式作為 sock::unixDomainSockServer 的 funcToRunWhenIdle 參數,則此為要帶入的暫存資料.#$conf["serverCache"]=;#$conf["info"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".#$conf["info"]="";#$conf["log"],字串,要將log寫到哪個地方,若有指定就會嘗試寫log.#$conf["log"]="";#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function runList(&$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#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end#取得使用的參數$result["argu"]=$conf;#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["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("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("config");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("config","client","serverCache","info","log");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","array","array","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/local/etc/qbpwcf-schedule.conf.php",null,null,null,null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".#$conf["disallowAllSkipableVarNotExist"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("actions","times","repeat");#參考資料:#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;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end#如果檢查不通過if($checkArguments["passed"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end#debug#var_dump(__LINE__,$conf["log"]);#初始化預設要回傳的cache$result["cache"]=array();#若有暫存資料要處理if(isset($conf["serverCache"])){/*#如果要寫logif(isset($conf["log"])){#initial debug data$debug=array();#set debug file info$debug["file"]=__FILE__;#set debug function info$debug["function"]=__FUNCTION__;#set debug line info$debug["line"]=__LINE__;#set debug content$debug["content"]=$conf["serverCache"];#write debug info#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#$result["content"],要寫入log的內容字串.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["logs::record"]["path"]=$conf["log"];#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["logs::record"]["content"]=$debug;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["logs::record"]["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.#$conf["returnOnly"]="true";#參考資料:#無.#備註:#無.$record=logs::record($conf["logs::record"]);unset($conf["logs::record"]);#如果執行失敗if($record["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$record;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end}#if end*/#更新預設要回傳的cache$result["cache"]=&$conf["serverCache"];#初始化儲存要更新排程設定的uuid$uuidsForUpdateList=array();#如果有之前的資料if(count($conf["serverCache"])>0){#如果有之前運行的結果if(isset($conf["serverCache"]["result"])){/*#如果要寫logif(isset($conf["log"])){#initial debug data$debug=array();#set debug file info$debug["file"]=__FILE__;#set debug function info$debug["function"]=__FUNCTION__;#set debug line info$debug["line"]=__LINE__;#set debug content$debug["content"]=$conf["serverCache"]["result"];#write debug info#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#$result["content"],要寫入log的內容字串.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["logs::record"]["path"]=$conf["log"];#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["logs::record"]["content"]=$debug;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["logs::record"]["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.#$conf["returnOnly"]="true";#參考資料:#無.#備註:#無.$record=logs::record($conf["logs::record"]);unset($conf["logs::record"]);#如果執行失敗if($record["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$record;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end}#if end*/#如果之前運行正常if($conf["serverCache"]["result"]["status"]==="true"){#如果有 cache 存在if(isset($conf["serverCache"]["result"]["cache"])){#如果有 resultif(isset($conf["serverCache"]["result"]["cache"]["result"])){#如果有 contentif(isset($conf["serverCache"]["result"]["cache"]["result"]["content"])){#針對之前執行的排程事項foreach($conf["serverCache"]["result"]["cache"]["result"]["content"] as $lastRanIndex => $lastRanInfo){#debug#var_dump(__FILE__,__LINE__,$lastRanIndex,$lastRanInfo);#如果記錄上顯示該程序尚在執行中if($lastRanInfo["proc_get_status"]["running"]===true){#嘗試取得該程序的狀態$proc_get_status=proc_get_status($lastRanInfo["process"]);#如果已經結束執行if($proc_get_status["running"]===false){#儲存要更新排程設定的uuid$uuidsForUpdateList[]=$lastRanInfo["uuid"];#移除已經跑完的排程unset($conf["serverCache"]["result"]["cache"]["result"]["content"][$lastRanIndex]);}#if end}#if end}#foreach end}#if end}#if end}#if end}#if end}#if end}#if end#如果有發現已經完工的排程if(count($uuidsForUpdateList)>0){#函式說明:#將指定uuid的已執行排程,依照repeat的規格,進行資料更新.#回傳結果:#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],當前排程資訊內容.#$result["argu"],使用的參數.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["autoService::updateList"]["fileArgu"]=$conf["fileArgu"];#$conf["uuids"],字串陣列,每個排程的uuid,若不指定則會自動產生,若跟既有action的uuid相同,則會覆蓋其相關資訊.$conf["autoService::updateList"]["uuids"]=$uuidsForUpdateList;#可省略參數:#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".$conf["autoService::updateList"]["config"]=$conf["config"];#參考資料:#無.#備註:#無.$updateList=autoService::updateList($conf["autoService::updateList"]);unset($conf["autoService::updateList"]);#如果執行出錯if($updateList["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$updateList;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end#如果有更新後的排程內容if(isset($updateList["content"])){#取得新的排程內容$result["updatedConfigContent"]=$updateList["content"];}#if end}#if end}#if end#函式說明:#查詢系統上有哪些要自動執行的工作檔案#回傳結果:#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["content"],回傳的結果,要執行的工作資訊陣列,每個元素的key有"uuid"跟"cmd&argu",前者為用於執行完畢時回報的排程項目識別;後者為該排程事項的指令與參數.#$result["function"],當前執行的函式名稱.#$result["found"],識別是否有要執行的動作.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["autoService::checkList"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".$conf["autoService::checkList"]["config"]=$conf["config"];#可省略參數:#無.#參考資料:#無.#備註:#無.$checkList=autoService::checkList($conf["autoService::checkList"]);unset($conf["autoService::checkList"]);#如果執行失敗if($checkList["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkList;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end#如果無事可做if($checkList["found"]==="false"){#設置錯誤識別$result["status"]="true";#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end#debug#var_dump(__FILE__,__LINE__,$checkList);#針對每個要執行的排程foreach($checkList["content"] as $index => $actionInfo){#如果有cache參數if(isset($conf["serverCache"])){#如果有之前的資料if(count($conf["serverCache"])>0){#如果有之前運行的結果if(isset($conf["serverCache"]["result"])){#debug#var_dump(__FILE__,__LINE__,$conf["serverCache"]["result"]);/*#如果要寫logif(isset($conf["log"])){#initial debug data$debug=array();#set debug file info$debug["file"]=__FILE__;#set debug function info$debug["function"]=__FUNCTION__;#set debug line info$debug["line"]=__LINE__;#set debug content$debug["content"]=$conf["serverCache"]["result"];#write debug info#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#$result["content"],要寫入log的內容字串.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["logs::record"]["path"]=$conf["log"];#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["logs::record"]["content"]=$debug;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["logs::record"]["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.#$conf["returnOnly"]="true";#參考資料:#無.#備註:#無.$record=logs::record($conf["logs::record"]);unset($conf["logs::record"]);#如果執行失敗if($record["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$record;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end}#if end*/#如果之前運行正常if($conf["serverCache"]["result"]["status"]==="true"){#如果有 cache 存在if(isset($conf["serverCache"]["result"]["cache"])){#如果有 resultif(isset($conf["serverCache"]["result"]["cache"]["result"])){#如果有 contentif(isset($conf["serverCache"]["result"]["cache"]["result"]["content"])){#針對之前執行的排程事項foreach($conf["serverCache"]["result"]["cache"]["result"]["content"] as $lastRanIndex => $lastRanInfo){#如果記錄上顯示該程序尚在執行中if($lastRanInfo["proc_get_status"]["running"]===true){#如果是同排程的事項,亦即尚在執行中.if($actionInfo["uuid"]===$lastRanInfo["uuid"]){#跳過該排程的執行continue 2;}#if end}#if end}#foreach end}#if end}#if end}#if end}#if end}#if end}#if end}#if end#取得排程的uuid$actionUuids[]=$actionInfo["uuid"];/*#函式說明:#將一維陣列轉換為用特定符號間隔的字串,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"]=$actionInfo["cmd&argu"];#可省略參數:#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;$conf["arrays::arrayToString"]["spiltSymbol"]=" ";#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。#$conf["skipEnd"]="";#參考資料:#無.#備註:#無.$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);unset($conf["arrays::arrayToString"]);#如果執行失敗if($arrayToString["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$arrayToString;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end#儲存排程的指令與參數$cmdStrs[]=$arrayToString["content"];*/#儲存排程的指令與參數$cmdStrs[]=$actionInfo["cmd&argu"];}#foreach end#debug#var_dump(__FILE__,__LINE__,$cmdStrs);#如果有要執行的指令if(isset($cmdStrs)){#函式說明:#透過proc來多執行序運作.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.#必填參數:#$conf["cmds"],字串陣列,每個元素代表要執行的指令與參數.$conf["threads::proc"]["cmds"]=$cmdStrs;#可省略參數:#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.$conf["threads::proc"]["wait"]="false";#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.#$conf["workingDir"]=array("path");#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");#$conf["envs"]=array(array("key"=>"value"));#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".#$conf["executeBy"]=array("bash");#參考資料:#https://www.php.net/manual/en/function.proc-open.php#https://www.php.net/manual/en/function.proc-get-status.php#備註:#無.$proc=threads::proc($conf["threads::proc"]);unset($conf["threads::proc"]);#如果執行失敗if($proc["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$proc;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end#針對每個proc資訊foreach($proc["content"] as $index => $procInfo){#附加用於識別排程的uuid$proc["content"][$index]["uuid"]=$actionUuids[$index];#如果要寫logif(isset($conf["log"])){#儲存要提示跑了什麼排程$comment="運行排程 uuid:".$actionUuids[$index]." pid:".$proc["content"][$index]["proc_get_status"]["pid"]." 進入點:".$proc["content"][$index]["proc_get_status"]["command"]." 指令:".$cmdStrs[$index];#提示運行了什麼排程#函式說明:#顯示多行文字.#回傳的結果:#$result["status"],執行是否正常,"true"為正常,"false"為不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["content"],語法.#必填參數:#$conf["string"],字串陣列,要放置的內容.$conf["text::multiLine"]["string"]=array($comment);#可省略參數:#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"#$conf["class"]="";#$conf["type"],字串,要用"div"或"span"或"br"或"p"或"EOL"或"textarea"來段行,預設為"EOL".#$conf["type"]="EOL";#參考資料:#無.#備註:#無.$multiLine=text::multiLine($conf["text::multiLine"]);unset($conf["text::multiLine"]);#如果執行失敗if($multiLine["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$multiLine;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end#initial debug data$debug=array();#set debug file info$debug["file"]=__FILE__;#set debug function info$debug["function"]=__FUNCTION__;#set debug line info$debug["line"]=__LINE__;#set debug content$debug["content"]=$multiLine["content"];#write debug info#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#$result["content"],要寫入log的內容字串.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["logs::record"]["path"]=$conf["log"];#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["logs::record"]["content"]=$debug;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["logs::record"]["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.#$conf["returnOnly"]="true";#參考資料:#無.#備註:#無.$record=logs::record($conf["logs::record"]);unset($conf["logs::record"]);#如果執行失敗if($record["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$record;#設置 cache result$result["cache"]["result"]=&$result;#回傳結果return $result;}#if end}#if end}#foreach end#依照每個剛執行的程序foreach($proc["content"] as $procJustRan){#取得每個程序執的執行結果$result["content"][]=$procJustRan;}#foreach end}#if end#設置執行正常$result["status"]="true";#設置 cache result$result["cache"]["result"]=&$result;#如果該次沒有執行排程if(!isset($result["content"])){#從 cache 取得 content$result["content"]=&$result["cache"]["serverSide"]["funcToRunWhenIdle"]["\QBPWCF\autoService::runList"]["result"]["content"];}#if end#debug#var_dump(__FILE__,__LINE__,$result);#回傳結果return $result;}#function runList end/*#函式說明:#將指定uuid的已執行排程,依照repeat的規格,進行資料更新.#回傳結果:#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],當前排程資訊內容.#$result["argu"],使用的參數.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#$conf["uuids"],字串陣列,每個排程的uuid,若不指定則會自動產生,若跟既有action的uuid相同,則會覆蓋其相關資訊.#$conf["uuids"]=array();#可省略參數:#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".#$conf["config"]="";#參考資料:#無.#備註:#無.*/public static function updateList(&$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["argu"]=$conf;#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["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("fileArgu","uuids");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","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["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("config");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("config");#$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/local/etc/qbpwcf-schedule.conf.php");#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".#$conf["disallowAllSkipableVarNotExist"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("actions","times","repeat");#參考資料:#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#函式說明:#依據行號分隔抓取檔案的內容,結果會回傳一個陣列#回傳的變數說明:#$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["config"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".$conf["fileAccess::getFileContent"]["web"]="false";#參考資料:#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#解析檔案內容#針對每行內容foreach($getFileContent["fileContent"] as $line){#解密內容#函式說明:#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函數名稱.#$result["content"],加密後的結果.#$result["error"],錯誤訊息陣列.#$result["argu"],使用的參數.#必填參數:#$conf["enCodeStr"],"字串",要加密的字串.$conf["authenticate::enCodeStr"]["enCodeStr"]=$line;#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";#可省略參數:#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".#$conf["sha1Raw"]="false";#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.#$conf["p_hash"]="";#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.#$conf["keyForAes256"]="";#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.#$conf["aes256Encode"]="";#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";#參考資料:#sha1=>http://php.net/manual/en/function.sha1.php#md5=>http://php.net/manual/en/function.md5.php#password_hash=>http://php.net/manual/en/function.password-hash.php#password_verify=>http://php.net/manual/en/function.password-verify.php#json_decode=>https://www.php.net/manual/en/function.json-decode.php#備註:#無.$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);unset($conf["authenticate::enCodeStr"]);#如果執行失敗失敗if($enCodeStr["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$enCodeStr;#回傳結果return $result;}#if end#取得解密後的內容$line=$enCodeStr["content"];#debug#var_dump(__LINE__,$line);#如果內容沒有 uuidif(!isset($line->uuid)){#忽略該行continue;}#if end#取得排程的uuid$uuidInFile=$line->uuid;#如果內容沒有 time ,亦即排程設定的(預期/已)執行時間if(!isset($line->time)){#忽略該行continue;}#if end#取得排程的時間$actionUnixTimeInFile=&$line->time;#如果內容沒有 action ,亦即排程設定的指令與參數.if(!isset($line->action)){#忽略該行continue;}#if end#取得排程要做的事情資訊$actionInFile=$line->action;#如果內容沒有 repeat ,亦即排程設定的執行模式.if(!isset($line->repeat)){#忽略該行continue;}#if end#取得重複的方式$repeatInFile=$line->repeat;#如果內容沒有 repeat->time ,亦即排程設定的剩下重複次數.if(!isset($line->repeat->times)){#忽略該行continue;}#if end#取得剩下的重複執行次數$leftRepeatTimesInFile=&$line->repeat->times;#如果內容沒有 repeat->after(亦即排程設定的重複條件為time的之後多久) 跟 repeat->time->fixed(亦即排程設定的重複條件為用update mask過後的指定時間).if( !isset($line->repeat->after) && !isset($line->repeat->fixed) ){#忽略該行continue;}#if end#如果內容沒有 update,亦即排程設定最後更新的時間if(!isset($line->update)){#忽略該行continue;}#if end#取得排程設定產生/更新的時間點$updateTimeInFile=$line->update;#判斷是否為目標排程的uuid#函式說明:#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.#回傳結果:#$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"]=$uuidInFile;#$conf["compareElements"],字串陣列,要比對的陣列變數內容.$conf["search::getEqualVar"]["compareElements"]=$conf["uuids"];#可省略參數:#無.#參考資料:#無.#備註:#無.$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);unset($conf["search::getEqualVar"]);#debug#var_dump(__LINE__,$getEqualVar);#如果執行失敗if($getEqualVar["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$getEqualVar;#回傳結果return $result;}#if end#如果有相符的uuidif($getEqualVar["founded"]==="true"){#當前unixtime$currentUnixTime=time::unix()["content"];#檔案中的排程時間#$actionUnixTimeInFile#檔案中的排程重複方式#$repeatInFile#debug#var_dump(__LINE__,$repeatInFile);#檔案中排程設定產生/更新的時間點#$updateTimeInFile#如果是要固定時間執行if(isset($repeatInFile->fixed)){#如果西元元相等if( gmdate("Y",$repeatInFile->fixed)===gmdate("Y",$updateTimeInFile) ){#debug#var_dump(__LINE__,"西元元相等(".gmdate("Y",$repeatInFile->fixed)."=".gmdate("Y",$updateTimeInFile).")");#如果月份相同if( gmdate("m",$repeatInFile->fixed)===gmdate("m",$updateTimeInFile) ){#debug#var_dump(__LINE__,"月份相同(".gmdate("m",$repeatInFile->fixed)."=".gmdate("m",$updateTimeInFile).")");#如果日相同if( gmdate("d",$repeatInFile->fixed)===gmdate("d",$updateTimeInFile) ){#debug#var_dump(__LINE__,"日相同(".gmdate("d",$repeatInFile->fixed)."=".gmdate("d",$updateTimeInFile).")");#如果時相同if( gmdate("H",$repeatInFile->fixed)===gmdate("H",$updateTimeInFile) ){#debug#var_dump(__LINE__,"時相同(".gmdate("H",$repeatInFile->fixed)."=".gmdate("H",$updateTimeInFile).")");#如果分相同if( gmdate("i",$repeatInFile->fixed)===gmdate("i",$updateTimeInFile) ){#debug#var_dump(__LINE__,"分相同(".gmdate("i",$repeatInFile->fixed)."=".gmdate("i",$updateTimeInFile).")");#代表要在固定秒數執行$runAtThisSec=gmdate("s",$repeatInFile->fixed);#更新下次執行排程的時間,為1分鐘後$line->time=$repeatInFile->fixed+60;#更新用於代表要在固定秒數執行的設定$line->repeat->fixed=$line->time+60;#debug#var_dump(__LINE__,"分相同(".gmdate("i",$repeatInFile->fixed)."=".gmdate("i",$updateTimeInFile).")");}#if end#反之到小時都相同else{#代表要在固定分鐘數執行$runAtThisMin=gmdate("i",$repeatInFile->fixed);#更新下次執行排程的時間,為小1時後.$line->time=$repeatInFile->fixed+60*60;#更新用於代表要在固定分鐘數執行的設定$line->repeat->fixed=$line->time+60*60;}#else end}#if end#反之到日都相等else{#代表要在固定時數執行$runAtThisHour=gmdate("H",$repeatInFile->fixed);#更新下次執行排程的時間,為1天後.$line->time=$repeatInFile->fixed+60*60*24;#更新用於代表要在固定小時數執行的設定$line->repeat->fixed=$line->time+60*60*24;}#else end}#if end#反之到月都相等else{#代表要在固定日執行$runAtThisDay=gmdate("d",$repeatInFile->fixed);#取得該次執行的年份$year=gmdate("Y",$repeatInFile->fixed);#取得執行該次的月份$month=gmdate("m",$repeatInFile->fixed);#如果月份等於"12"if($month==="12"){#將之變為01$month="01";#西元年也加1$year=$year+1;}#if end#反之else{#月份+1$month=printf("02s",$month+1);}#else end#組合YYYY-mm-dd HH:ii:ss字串參數$dateAndTime=$year."-".$month."-".$runAtThisDay." ".gmdate("H",$repeatInFile->fixed).":".gmdate("i",$repeatInFile->fixed).":".gmdate("s",$repeatInFile->fixed);#函式說明:#計算時間點距離1970/01/01多少秒,亦即unixtime.#回傳結果:#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.#$result["error"],錯誤訊息陣列.#$result["content"],時間點距離1970/01/01的多少秒.#$result["argu"],使用的參數.#$result["unixtime"],執行本函式時的unixtime.#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.#必填參數:#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.$conf["time::caculateTimeAmount"]["dateAndTime"]=$dateAndTime;#可省略參數:#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".$conf["time::caculateTimeAmount"]["UTC"]="true";#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".$conf["time::caculateTimeAmount"]["replace0"]="false";#參考資料:#無.#備註:#無.$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);unset($conf["time::caculateTimeAmount"]);#如果執行失敗if($caculateTimeAmount["status"]=="false"){#設置執行失敗的訊息$result["status"]="false";#設置錯誤訊息$result["error"]=$caculateTimeAmount;#回傳結果return $result;}#if end#更新下次執行排程的時間,為1個月後.$line->time=$caculateTimeAmount["content"];#代表要在固定日執行$runAtThisDay=gmdate("d",$repeatInFile->fixed);#如果月份等於"12"if($month==="12"){#將之變為01$month="01";#西元年也加1$year=$year+1;}#if end#反之else{#月份+1$month=printf("02s",$month+1);}#else end#組合YYYY-mm-dd HH:ii:ss字串參數$dateAndTime=$year."-".$month."-".$runAtThisDay." ".gmdate("H",$repeatInFile->fixed).":".gmdate("i",$repeatInFile->fixed).":".gmdate("s",$repeatInFile->fixed);#函式說明:#計算時間點距離1970/01/01多少秒,亦即unixtime.#回傳結果:#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.#$result["error"],錯誤訊息陣列.#$result["content"],時間點距離1970/01/01的多少秒.#$result["argu"],使用的參數.#$result["unixtime"],執行本函式時的unixtime.#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.#必填參數:#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.$conf["time::caculateTimeAmount"]["dateAndTime"]=$dateAndTime;#可省略參數:#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".$conf["time::caculateTimeAmount"]["UTC"]="true";#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".$conf["time::caculateTimeAmount"]["replace0"]="false";#參考資料:#無.#備註:#無.$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);unset($conf["time::caculateTimeAmount"]);#如果執行失敗if($caculateTimeAmount["status"]=="false"){#設置執行失敗的訊息$result["status"]="false";#設置錯誤訊息$result["error"]=$caculateTimeAmount;#回傳結果return $result;}#if end#更新用於代表要在固定日子執行的設定$line->repeat->fixed=$caculateTimeAmount["content"];}#else end}#if end#反之到年都相等else{#代表要在固定月執行$runAtThisMonth=gmdate("m",$repeatInFile->fixed);#取得該次執行的年份$year=gmdate("Y",$repeatInFile->fixed);#明年執行$year=$year+1;#組合YYYY-mm-dd HH:ii:ss字串參數$dateAndTime=$year."-".$runAtThisMonth."-".gmdate("d",$repeatInFile->fixed)." ".gmdate("H",$repeatInFile->fixed).":".gmdate("i",$repeatInFile->fixed).":".gmdate("s",$repeatInFile->fixed);#函式說明:#計算時間點距離1970/01/01多少秒,亦即unixtime.#回傳結果:#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.#$result["error"],錯誤訊息陣列.#$result["content"],時間點距離1970/01/01的多少秒.#$result["argu"],使用的參數.#$result["unixtime"],執行本函式時的unixtime.#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.#必填參數:#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.$conf["time::caculateTimeAmount"]["dateAndTime"]=$dateAndTime;#可省略參數:#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".$conf["time::caculateTimeAmount"]["UTC"]="true";#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".$conf["time::caculateTimeAmount"]["replace0"]="false";#參考資料:#無.#備註:#無.$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);unset($conf["time::caculateTimeAmount"]);#如果執行失敗if($caculateTimeAmount["status"]=="false"){#設置執行失敗的訊息$result["status"]="false";#設置錯誤訊息$result["error"]=$caculateTimeAmount;#回傳結果return $result;}#if end#更新下次執行排程的時間,為1年後.$line->time=$caculateTimeAmount["content"];#代表要在固定月執行$runAtThisMonth=gmdate("m",$repeatInFile->fixed);#取得該次執行的年份$year=gmdate("Y",$repeatInFile->fixed);#明年執行$year=$year+1;#組合YYYY-mm-dd HH:ii:ss字串參數$dateAndTime=$year."-".$runAtThisMonth."-".gmdate("d",$repeatInFile->fixed)." ".gmdate("H",$repeatInFile->fixed).":".gmdate("i",$repeatInFile->fixed).":".gmdate("s",$repeatInFile->fixed);#函式說明:#計算時間點距離1970/01/01多少秒,亦即unixtime.#回傳結果:#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.#$result["error"],錯誤訊息陣列.#$result["content"],時間點距離1970/01/01的多少秒.#$result["argu"],使用的參數.#$result["unixtime"],執行本函式時的unixtime.#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.#必填參數:#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.$conf["time::caculateTimeAmount"]["dateAndTime"]=$dateAndTime;#可省略參數:#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".$conf["time::caculateTimeAmount"]["UTC"]="true";#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".$conf["time::caculateTimeAmount"]["replace0"]="false";#參考資料:#無.#備註:#無.$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);unset($conf["time::caculateTimeAmount"]);#如果執行失敗if($caculateTimeAmount["status"]=="false"){#設置執行失敗的訊息$result["status"]="false";#設置錯誤訊息$result["error"]=$caculateTimeAmount;#回傳結果return $result;}#if end#更新用於代表要在固定月份執行的設定$line->repeat->fixed=$caculateTimeAmount["content"];}#else end}#if end#反之,從年份就不同else{#執行到這邊代表是一次性排程,以後不會在碰到,除非時光倒退.}#else end}#if end#如果是要特定時間後執行else if(isset($repeatInFile->after)){#debug#var_dump(__LINE__,"要特定時間後執行");#更新下次執行排程的時間$line->time=$currentUnixTime+$repeatInFile->after;}#if end#更新異動的時間$line->update=$currentUnixTime;#如果檔案中剩下的可執行次數大於0if($leftRepeatTimesInFile>0){#檔案中剩下的可執行次數-1$line->repeat->times=$leftRepeatTimesInFile-1;}#if end}#if end#debug#var_dump(__LINE__,$line);#取得解密後新排程的內容$result["content"][]=$line;#加密 $line#函式說明:#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函數名稱.#$result["content"],加密後的結果.#$result["error"],錯誤訊息陣列.#$result["argu"],使用的參數.#必填參數:#$conf["enCodeStr"],"字串",要加密的字串.$conf["authenticate::enCodeStr"]["enCodeStr"]=$line;#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";#可省略參數:#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".#$conf["sha1Raw"]="false";#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.#$conf["p_hash"]="";#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.#$conf["keyForAes256"]="";#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.#$conf["aes256Encode"]="";#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.#$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";#參考資料:#sha1=>http://php.net/manual/en/function.sha1.php#md5=>http://php.net/manual/en/function.md5.php#password_hash=>http://php.net/manual/en/function.password-hash.php#password_verify=>http://php.net/manual/en/function.password-verify.php#json_decode=>https://www.php.net/manual/en/function.json-decode.php#備註:#無.$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);unset($conf["authenticate::enCodeStr"]);#如果執行失敗失敗if($enCodeStr["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$enCodeStr;#回傳結果return $result;}#if end#取得加密後的內容$line=$enCodeStr["content"];#將新的內容儲存起來$content2write[]=$line;}#foreach end#如果有要更新排程的內容if(isset($content2write)){#重新寫入排程檔案.#函式說明:#將多行字串寫入到檔案#回傳結果:#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行函數的名稱.#必填參數:#$conf["fileName"],字串,爲要編輯的檔案名稱$conf["fileAccess::writeMultiLine"]["fileName"]=$conf["config"];#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。$conf["fileAccess::writeMultiLine"]["inputString"]=$content2write;#$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}#if end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function updateList end/*#函式說明:#建立unix domain socket server,依照設定檔autoService::createList建立的設定檔案來執行排程事項.#回傳結果:#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],所使用的參數.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".#$conf["config"]="";#$conf["unixDomainSocket"],字串,unix domain socket 檔案要放在哪裡,預設為"/usr/lib/qbpwcf/qbpwcf-autoService.sock".#$conf["unixDomainSocket"]="";#$conf["log"],字串,要將log寫到哪個地方,若有指定就會嘗試寫log.#$conf["log"]="";#參考資料:#無.#備註:#無.*/public static function daemon(&$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["argu"]=$conf;#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["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("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("config","unixDomainSocket");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("config","unixDomainSocket","log");#$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("/usr/local/etc/qbpwcf-schedule.conf.php","/usr/lib/qbpwcf/qbpwcf-autoService.sock",null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".#$conf["disallowAllSkipableVarNotExist"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("actions","times","repeat");#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#debug#var_dump(__LINE__,$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#初始化閒置時要給予 \QBPWCF\autoService::runList 的參數$paramsForFuncToRunWhenIdle=array("config"=>$conf["config"],"fileArgu"=>$conf["fileArgu"]);#如果有指定 log 參數if(isset($conf["log"])){#增加之$paramsForFuncToRunWhenIdle["log"]=$conf["log"];}#if end#debug#var_dump(__LINE__,$paramsForFuncToRunWhenIdle);#函式說明:#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.#回傳結果:#$result["status"],"true"代表執行正常;"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["serverCache"],函式結束前,儲存在serverCache的內容.#必填參數:#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.$conf["sock::unixDomainSockServer"]["sock"]=$conf["unixDomainSocket"];#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["sock::unixDomainSockServer"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.#$conf["changeOwner"]="";#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).#$conf["changePermission"]="";#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.#$conf["sessionTimeout"]="300";#$conf["addOnProcessFunc"],字串陣列,增加用於處理 json request 的函式名稱,給予的參數為array("request"=>收到的json訊息,"sock"=>用戶的socket),回傳的內容必須為陣列,例如 $res["continue"]="true"代表要繼續執行下一個addOnProcessFunc;"false"代表代表到此為止. $res["content"]="replaced content";代表要將收到的訊息取代成"replaced content". 最少要有回傳 $res["status"]數值"true"代表執行正常;"false"代表執行不正常.#$conf["addOnProcessFunc"]=array();#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\QBPWCF\autoService::runList");#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.$conf["sock::unixDomainSockServer"]["paramsForFuncToRunWhenIdle"]=array($paramsForFuncToRunWhenIdle);#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.#$conf["infoToFunction"]=array("debug"=>$debug);#參考資料:#http://php.net/manual/en/function.stream-socket-server.php#備註:#無.$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);unset($conf["sock::unixDomainSockServer"]);#如果執行出錯if($unixDomainSockServer["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$unixDomainSockServer;#回傳結果return $result;}#if end#設置正常識別$result["status"]="true";#回傳結果return $result;}#function daemon end}#class autoService end?>