Rev 402 | Rev 414 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/php<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2015~2023 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/>.*/#使用 qbpwcf 命名空間namespace qbpwcf;#匯入套件require_once("qbpwcf/allInOne.php");#建議的log位置$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";#該指令的 help 文件function help(){#helpecho basename($_SERVER["PHP_SELF"])." is a program to install QBPWCF.".PHP_EOL;echo basename($_SERVER["PHP_SELF"])." usage:".PHP_EOL;echo "If run it without any argument, QBPWCF will be install defaultly".PHP_EOL;echo "--rootPath path where QBPWCF to put. Default is /usr/lib/".PHP_EOL;echo "--name folder name where QBPWCF to put inside. Default is qbpwcf".PHP_EOL;echo "--mode cp/link, default is link".PHP_EOL;echo "\tcp means copy and overwrite to installation path".PHP_EOL;echo "\tlink means create a softlink from current path to installation path".PHP_EOL;echo "--ip ip address, specify self ip address, if need.".PHP_EOL;echo "--dbAddr MariaDb service address, default is \"localhost\"".PHP_EOL;echo "--dbAcct MariaDb service account, default is \"root\"".PHP_EOL;echo "--dbPass MariaDb service password, default is output of uuid command".PHP_EOL;echo "--dbName MariaDb service database name, default is test".PHP_EOL;echo "--dbPort MariaDb service port, default is 3306".PHP_EOL;echo "--headless true/false, default is false. If true, it means link allInOneForCI.php to allInOne.php".PHP_EOL;exit;}#function help 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";#參考資料:#無.#備註:#僅能在命令列底下執行.#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .$parseArgu=cmd::parseArgu($conf);unset($conf);#如果執行失敗if($parseArgu["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$parseArgu;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#函式說明:#使用 linux 的 uuid 指令來產生 uuid 字串#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#必填參數:#無.#可省略參數:#無.#參考資料:#無.#備註:#無.$uuid=cmd::uuid();#如果執行失敗if($uuid["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$uuid;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#預設的套件安裝位置$rootPath="/usr/lib/";#預設的套件資料夾名稱$name="qbpwcf";#預設運作模式為 "link" 亦即建立軟連結$mode="link";#預設不指定自己的IP$ip="";#預設的資料庫連線帳號$dbAcct="root";#預設的資料庫連線密碼$dbPass=$uuid["content"];#預設的資料庫名稱$dbName="test";#預設到資料庫位置$dbAddr="localhost";#預設的資料庫port$dbPort="3306";#預設要有自動輸出的內容$headless="false";#檢查參數#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$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["varInput"]=&$parseArgu["content"];#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["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("rootPath","name","mode","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","headless");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["skipableVariableName"]=array("rootPath","name","mode","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","headless");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["skipableVariableType"]=array("array","array","array","array","array","array","array","array","array","array");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["skipableVarDefaultValue"]=array(null,null,null,null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.$conf["arrayCountEqualCheck"][]=array("rootPath","name","mode","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","headless");#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf);unset($conf);#如果有設置參數if(count($parseArgu["content"])>0){#如果有 rootPath 參數if(isset($parseArgu["content"]["rootPath"])){#如果有 rootPath 參數存在if(isset($parseArgu["content"]["rootPath"][0])){#更新套件的安裝位置$rootPath=$parseArgu["content"]["rootPath"][0];}#if end}#if enf#如果有 name 參數if(isset($parseArgu["content"]["name"])){#如果有 name 參數存在if(isset($parseArgu["content"]["name"][0])){#更新套件的資料夾名稱$name=$parseArgu["content"]["name"][0];}#if end}#if end#如果有 mode 參數if(isset($parseArgu["content"]["mode"])){#如果有 mode 參數存在if(isset($parseArgu["content"]["mode"][0])){#更新運作模式$mode=$parseArgu["content"]["mode"][0];}#if end}#if end#如果有 ip 參數if(isset($parseArgu["content"]["ip"])){#如果有 ip 參數存在if(isset($parseArgu["content"]["ip"][0])){#更新ip$ip=$parseArgu["content"]["ip"][0];}#if end}#if end#如果有 dbAcct 參數if(isset($parseArgu["content"]["dbAcct"])){#如果有 dbAcct 參數存在if(isset($parseArgu["content"]["dbAcct"][0])){#更新 dbAcct$dbAcct=$parseArgu["content"]["dbAcct"][0];}#if end}#if end#如果有 dbPass 參數if(isset($parseArgu["content"]["dbPass"])){#如果有 dbPass 參數存在if(isset($parseArgu["content"]["dbPass"][0])){#更新 dbPass$dbPass=$parseArgu["content"]["dbPass"][0];}#if end}#if end#如果有 dbName 參數if(isset($parseArgu["content"]["dbName"])){#如果有 dbName 參數存在if(isset($parseArgu["content"]["dbName"][0])){#更新 dbName$dbName=$parseArgu["content"]["dbName"][0];}#if end}#if end#如果有 dbAddr 參數if(isset($parseArgu["content"]["dbAddr"])){#如果有 dbAddr 參數存在if(isset($parseArgu["content"]["dbAddr"][0])){#更新 dbAddr$dbAddr=$parseArgu["content"]["dbAddr"][0];}#if end}#if end#如果有 dbPort 參數if(isset($parseArgu["content"]["dbPort"])){#如果有 dbPort 參數存在if(isset($parseArgu["content"]["dbPort"][0])){#更新 dbPort$dbPort=$parseArgu["content"]["dbPort"][0];}#if end}#if end#如果有 headless 參數if(isset($parseArgu["content"]["headless"])){#如果有 headless 參數存在if(isset($parseArgu["content"]["headless"][0])){#更新 headless$headless=$parseArgu["content"]["headless"][0];}#if end}#if end}#if end#如果要使用不自動輸出內容的 allInOneForCI.php 檔案if($headless==="true"){#函式說明:#建立軟連結.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["content"],軟連結的資訊.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["linkTo"],字串,軟連結要指向哪邊.$conf["linkTo"]="qbpwcf/allInOneForCI.php";#可省略參數:#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.$conf["path"]="qbpwcf";#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.$conf["name"]="allInOne.php";#參考資料:#無.#備註:#無.$createLink=fileAccess::createLink($conf);unset($conf);#如果執行失敗if($createLink["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$createLink;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end}#if end#讓 "qbpwcf/usr/bin" 底下的所有檔案為可執行.#函式說明:#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["mode"]="+x";#$conf["target"],字串,需要變更權限的目標.$conf["target"]="qbpwcf/usr/bin";#可省略參數:#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".$conf["recursive"]="true";#參考資料:#無.#備註:#無.$chmod=cmd::chmod($conf);unset($conf);#如果執行失敗if($chmod["status"]==="false")#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$chmod;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#讓 "qbpwcf/db" 可以被大家使用.#函式說明:#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["mode"]="777";#$conf["target"],字串,需要變更權限的目標.$conf["target"]="qbpwcf/db";#可省略參數:#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".#$conf["recursive"]="";#參考資料:#無.#備註:#無.$chmod=cmd::chmod($conf);unset($conf);#如果執行失敗if($chmod["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$chmod;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#如果 ip 有指定if($ip!==""){#依照參數設定 $rootPath.$name."/etc/config.php#函式說明:#建立軟連結.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["content"],軟連結的資訊.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["file"],字串,要更新的檔案位置與名稱.$conf["file"]="qbpwcf/etc/config.php";#可省略參數:#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.$conf["overWriteWith"]=array("<?php","\$ip="."\"".$ip."\";","?>");#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.#$conf["addToTailWhenNoMatch"]="false";#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.#$conf["addToTailBeforeThat"]="?\>";#參考資料:#無.#備註:#無.$updateFile=fileaAccess::updateFile($conf);unset($conf);#如果執行失敗if($updateFile["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$updateFile;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end}#if end#依照參數設定 "qbpwcf/usr/local/etc/backupDb.conf"#函式說明:#建立軟連結.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["content"],軟連結的資訊.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["file"],字串,要更新的檔案位置與名稱.$conf["file"]="qbpwcf/usr/local/etc/backupDb.conf";#可省略參數:#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.$conf["overWriteWith"]=array();$conf["overWriteWith"][]="<?php";$conf["overWriteWith"][]="#資料庫連線帳號";$conf["overWriteWith"][]="\$dbAcct=\"".$dbAcct."\";";$conf["overWriteWith"][]="";$conf["overWriteWith"][]="#資料庫連線密碼";$conf["overWriteWith"][]="\$dbPass=\"".$dbPass."\";";$conf["overWriteWith"][]="";$conf["overWriteWith"][]="#資料庫名稱";$conf["overWriteWith"][]="\$dbName=\"".$dbName."\";";$conf["overWriteWith"][]="";$conf["overWriteWith"][]="#資料庫位置";$conf["overWriteWith"][]="\$dbAddr=\"".$dbAddr."\";";$conf["overWriteWith"][]="";$conf["overWriteWith"][]="#資料庫port";$conf["overWriteWith"][]="\$dbPort=\"".$dbPort."\";";#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.#$conf["addToTailWhenNoMatch"]="false";#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.#$conf["addToTailBeforeThat"]="?\>";#參考資料:#無.#備註:#無.$updateFile=fileaAccess::updateFile($conf);unset($conf);#如果執行失敗if($updateFile["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$updateFile;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#重新建置 qbpwcf/usr/local/etc/qbpwcf.conf.xml#函式說明:#建立軟連結.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["content"],軟連結的資訊.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["file"],字串,要更新的檔案位置與名稱.$conf["file"]="qbpwcf/usr/local/etc/qbpwcf.conf.xml";#可省略參數:#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.$conf["overWriteWith"]=array();$conf["overWriteWith"][]="<?xml version=\"1.0\"?>";$conf["overWriteWith"][]="<root></root>";#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.#$conf["addToTailWhenNoMatch"]="false";#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.#$conf["addToTailBeforeThat"]="?\>";#參考資料:#無.#備註:#無.$updateFile=fileaAccess::updateFile($conf);unset($conf);#如果執行失敗if($updateFile["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$updateFile;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#讓 "qbpwcf/usr/local/etc/qbpwcf.conf.xml" 可以被大家使用.#函式說明:#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.$conf["mode"]="777";#$conf["target"],字串,需要變更權限的目標.$conf["target"]="qbpwcf/usr/local/etc/qbpwcf.conf.xml";#可省略參數:#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".#$conf["recursive"]="";#參考資料:#無.#備註:#無.$chmod=cmd::chmod($conf);unset($conf);#如果執行失敗if($chmod["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$chmod;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#判斷 $modeswitch($mode){#如果是 "cp" modecase "cp":#函式說明:#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列#$result["warning"],警告訊息陣列#$result["argu"],使用的參數.#$result["content"],建立的目錄路徑.#必填參數:#$conf["dirPositionAndName"]="";#新建的位置與名稱$conf["dirPositionAndName"]=$rootPath.$name;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.#$conf["dirPermission"]="";#$conf["web"],"false"代表在檔案系統環境,"true"代表在網頁稀系統環境.#$conf["web"]="false";#參考資料:#mkdir=>http://php.net/manual/en/function.mkdir.php#chmod=>http://php.net/manual/en/function.chmod.php#備註:#無.$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf);unset($conf);#如果執行失敗if($createFolderAfterCheck["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$createFolderAfterCheck;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#複製套件#函式說明:#複製檔案、資料夾.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],複製好的檔案路徑與名稱.#必填參數:#$conf["file"],字串,檔案的位置與名稱.$conf["file"]="../";#$conf["to"],字串,檔案要複製到哪裡.$conf["to"]=$rootPath.$name;#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.#$conf["username"]="";#$conf["password"],字串,使用者對應的密碼,預設不使用.#$conf["password"]="";#參考資料:#無.#備註:#僅能在命令列環境下運行$cp=cmd::cp($conf);unset($conf);#如果執行失敗if($cp["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$cp;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if endbreak;#如果是 "link" modecase "link":#函式說明:#建立軟連結.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["content"],軟連結的資訊.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["linkTo"],字串,軟連結要指向哪邊.$conf["linkTo"]=$rootPath.$name;#可省略參數:#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.#$conf["path"]="";#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.#$conf["name"]="";#參考資料:#無.#備註:#無.$createLink=fileAccess::createLink($conf);unset($conf);#如果執行失敗if($createLink["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$createLink;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if endbreak;default:#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]="mode \"".$mode."\" not supported!";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#switch end#於 /usr/bin 底下建立 $rootPath.$name."/usr/bin" 底下所有檔案的軟連結.#函式說明:#針對特定目錄下的內容建立軟連結.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["content"],字串陣列,每個建立的軟連結資訊.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.$conf["linkToDir"]=$rootPath.$name."/usr/bin";#可省略參數:#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.$conf["path"]="/usr/bin";#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.#$conf["name"]=array(array("oriName","newName"));#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.$conf["overWrite"]="true";#參考資料:#無.#備註:#無.$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);unset($conf);#如果執行失敗if($createMultiLinkInDir["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$createMultiLinkInDir;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#於 /etc/systemd/system 底下建立 $rootPath.$name."/usr/lib/systemd/system" 底下所有服務檔案的軟連結.#函式說明:#針對特定目錄下的內容建立軟連結.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["content"],字串陣列,每個建立的軟連結資訊.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.$conf["linkToDir"]=$rootPath.$name."/usr/lib/systemd/system";#可省略參數:#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.$conf["path"]="/etc/systemd/system";#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.#$conf["name"]=array(array("oriName","newName"));#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.$conf["overWrite"]="true";#參考資料:#無.#備註:#無.$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);unset($conf);#如果執行失敗if($createMultiLinkInDir["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$createMultiLinkInDir;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#函式說明:#針對特定目錄下的內容建立軟連結.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函數名稱.#$result["content"],字串陣列,每個建立的軟連結資訊.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.$conf["linkToDir"]=$rootPath.$name."/usr/local/etc";#可省略參數:#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.$conf["path"]="/usr/local/etc";#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.#$conf["name"]=array(array("oriName","newName"));#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.$conf["overWrite"]="true";#參考資料:#無.#備註:#無.$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);unset($conf);#如果執行失敗if($createMultiLinkInDir["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$createMultiLinkInDir;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#systemctl daemon-reload#函式說明:#執行 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"]="daemon-reload";#可省略參數:#$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";#參考資料:#無.#備註:#無.$systemd=cmd::systemd($conf);unset($conf);#如果執行失敗if($systemd["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$systemd;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#enable and restart 於 $rootPath.$name."/usr/lib/systemd/system" 底下的所有服務#函式說明:#取得目錄底下所有目錄與檔案清單.#回傳結果:#$result["status"],"true"爲建立成功,"false"爲建立失敗.#$result["error"],錯誤訊息陣列.#$result["function"],函數名稱.#$result["content"],陣列,目錄底下的檔案與子目錄.#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.#$result["position"],目前的位置.#必填參數:#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.$conf["position"]=$rootPath.$name."/usr/lib/systemd/system";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#無#參考資料:#opendir=>http://php.net/manual/en/function.opendir.php#is_dir=>http://php.net/manual/en/function.is-dir.php#備註:#無.$getList=fileAccess::getList($conf);unset($conf);#如果執行失敗if($getList["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$getList;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end#針對每個服務foreach($getList["content"] as $fileInfo){#取得服務的名稱$serviceName=$fileInfo["name"];#函式說明:#執行 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"]=$serviceName;#可省略參數:#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".$conf["operation"]="enable";#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者#$conf["username"]="";#$conf["password"],字串,使用者的密碼,預設不使用.#$conf["password"]="";#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.#$conf["daemonReload"]="true";#參考資料:#無.#備註:#無.$systemd=cmd::systemd($conf);unset($conf);#如果執行失敗if($systemd["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$systemd;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#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["fileArgu"]=__FILE__;#$conf["name"],字串,服務名稱.$conf["name"]=$serviceName;#可省略參數:#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".$conf["operation"]="restart";#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者#$conf["username"]="";#$conf["password"],字串,使用者的密碼,預設不使用.#$conf["password"]="";#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.#$conf["daemonReload"]="true";#參考資料:#無.#備註:#無.$systemd=cmd::systemd($conf);unset($conf);#如果執行失敗if($systemd["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$systemd;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);#如果執行失敗if($record["status"]==="false"){#印出結果var_dump($record);#異常結束執行exit(1);}#if end}#if end}#foreach end?>