Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 945 | 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~2025 Min-Jhin,Chen

    This file is part of QBPWCF.

    QBPWCF is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the 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 of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.

*/

#使用 qbpwcf 命名空間
namespace qbpwcf;

#取得 lib path
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/usr/bin/libexec/folderOfUsrLib.php"),$output,$status);

#如果執行失敗
if($status!==0){

        #debug
        var_dump(__LINE__,$output);

        #結束執行,回傳shell 1.
        exit(1);

        }#if end

#儲存lib path
$folderOfUsrLib=$output[0];

#以該檔案的實際位置的 lib path 為 include path 首位
$output=array();
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/usr/".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);

#如果執行失敗
if($status!==0){

        #debug
        var_dump(__LINE__,$output);

        #結束執行,回傳shell 1.
        exit(1);

        }#if end

#設置 include path 
set_include_path($output[0].PATH_SEPARATOR.get_include_path());

#匯入套件
require_once("allInOne.php");

#建議的log位置
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";

#該指令的 help 文件
function help(){

        #help
        echo 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 installed defaultly".PHP_EOL;
        echo "--libOfRootPath path where QBPWCF to put. Default is /".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 "--configUrl ur, specify url to get config, default is https://config.qbpwcf.org".PHP_EOL;
        echo "--getIpUrl url, specify url to get www ip, default is https://ip.qbpwcf.org".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 "--sshAddrAndPort ssh service address, example: 0.0.0.0:22".PHP_EOL;
        echo "--headless true/false, default is false. If true, it means link allInOneForCI.php to allInOne.php".PHP_EOL;
        echo "--whiteIp, outsite ip which will not auto block forever".PHP_EOL;
        exit;

        }#function help end

#debug
#var_dump($_SERVER["argv"]);exit;

#函式說明:
#解析參數.
#回傳結果:
#$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);
                
                }#if end

        #異常結束執行
        exit(1);

        }#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);
        
                }#if end
                
        #異常結束執行
        exit(1);

        }#if end

#預設的套件安裝位置
$libOfRootPath="/";

#預設的套件資料夾名稱
$name="qbpwcf";

#預設運作模式為 "link" 亦即建立軟連結
$mode="link";

#預設取得設定檔服務的網址
$configUrl="https://config.qbpwcf.org";

#預設取得自己對外ip的服務網址
$getIpUrl="https://ip.qbpwcf.org";

#預設不指定自己的IP
$ip="";

#預設的資料庫連線帳號
$dbAcct="root";

#預設的資料庫連線密碼
$dbPass=$uuid["content"];

#預設的資料庫名稱
$dbName="test";

#預設到資料庫位置
$dbAddr="localhost";

#預設的資料庫port
$dbPort="3306";

#預設的 sshd 設定檔案
$defaultSshdConfigAddr="qbpwcf/etc/sshd_config.php";

#預設要要確保ssh服務有運行的ip與port
$sshAddrAndPort=array();

#預設要有自動輸出的內容
$headless="false";

#預設的白名單ip清單
$whiteIp=array();

#檢查參數
#函式說明:
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
#回傳結果:
#$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("libOfRootPath","name","mode","configUrl","getIpUrl","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","sshAddrAndPort","headless","whiteIp");
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
$conf["skipableVariableName"]=array("libOfRootPath","name","mode","configUrl","getIpUrl","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","sshAddrAndPort","headless","whiteIp");
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
$conf["skipableVariableType"]=array("array","array","array","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,null,null,null,null,null,null,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("libOfRootPath","name","mode","configUrl","getIpUrl","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","headless","libonly");
#參考資料:
#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])){
                
                        #更新套件的安裝位置
                        $libOfRootPath=$parseArgu["content"]["rootPath"][0];
                        
                        #如果路徑不為 "/" 結束
                        if($libOfRootPath[strlen($libOfRootPath)-1]!=="/"){
                        
                                #補上 "/"
                                $libOfRootPath=$libOfRootPath."/";
                        
                                }#if end
                
                        }#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
                
        #如果有 getIpUrl 參數
        if(isset($parseArgu["content"]["getIpUrl"])){
        
                #如果有 getIpUrl 參數存在
                if(isset($parseArgu["content"]["getIpUrl"][0])){
                
                        #更新 getIpUrl
                        $getIpUrl=$parseArgu["content"]["getIpUrl"][0];
                
                        }#if end
        
                }#if end
                
        #如果有 configUrl 參數
        if(isset($parseArgu["content"]["configUrl"])){
        
                #如果有 configUrl 參數存在
                if(isset($parseArgu["content"]["configUrl"][0])){
                
                        #更新 configUrl
                        $configUrl=$parseArgu["content"]["configUrl"][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
                                
        #如果有 sshAddrAndPort 參數
        if(isset($parseArgu["content"]["sshAddrAndPort"])){
        
                #如果有 sshAddrAndPort 參數存在
                if(isset($parseArgu["content"]["sshAddrAndPort"][0])){
                
                        #新增 sshAddrAndPort
                        $sshAddrAndPort[]=$parseArgu["content"]["sshAddrAndPort"][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
        
        #如果有 whiteIp 參數
        if(isset($parseArgu["content"]["whiteIp"])){
        
                #針對每個白名單ip
                foreach($parseArgu["content"]["whiteIp"] as $ip){
                
                        #儲存起來
                        $whiteIp[]=$ip;
                
                        }#foreach end
        
                }#if end

        }#if end

#判斷 $mode
switch($mode){

        #如果是 "cp" mode
        case "cp":
        
                #函式說明:
                #建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
                #回傳結果:
                #$result["status"],"true"爲建立成功,"false"爲建立失敗.
                #$result["error"],錯誤訊息陣列
                #$result["warning"],警告訊息陣列
                #$result["argu"],使用的參數.
                #$result["content"],建立的目錄路徑.
                #必填參數:
                #$conf["dirPositionAndName"]="";#新建的位置與名稱
                $conf["dirPositionAndName"]=$libOfRootPath;
                #$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);
                        
                                }#if end
                                
                        #異常結束執行
                        exit(1);

                        }#if end
        
                #複製 etc
                #函式說明:
                #複製檔案、資料夾.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息.
                #$result["function"],當前執行的函式名稱.
                #$result["content"],複製好的檔案路徑與名稱.
                #必填參數:
                #$conf["file"],字串,檔案的位置與名稱.
                $conf["file"]="etc";
                #$conf["to"],字串,檔案要複製到哪裡.
                $conf["to"]=$libOfRootPath;
                #$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);
                                
                                }#if end
                
                        #異常結束執行
                        exit(1);
                
                        }#if end
        
                #複製 usr
                #函式說明:
                #複製檔案、資料夾.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息.
                #$result["function"],當前執行的函式名稱.
                #$result["content"],複製好的檔案路徑與名稱.
                #必填參數:
                #$conf["file"],字串,檔案的位置與名稱.
                $conf["file"]="usr";
                #$conf["to"],字串,檔案要複製到哪裡.
                $conf["to"]=$libOfRootPath;
                #$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);
                                
                                }#if end
                
                        #異常結束執行
                        exit(1);
                
                        }#if end
        
                break;
                
        #如果是 "link" mode
        case "link":
        
                #link /etc/qbpwcf
                #函式說明:
                #建立軟連結.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息.
                #$result["function"],當前執行的函數名稱.
                #$result["content"],軟連結的資訊.
                #必填參數:
                #$conf["fileArgu"],字串,變數__FILE__的內容.
                $conf["fileArgu"]=__FILE__;
                #$conf["linkTo"],字串,軟連結要指向哪邊.
                $conf["linkTo"]="etc/qbpwcf";
                #可省略參數:
                #$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
                $conf["path"]=$libOfRootPath.$conf["linkTo"];
                #$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
                #$conf["name"]=$name;
                #$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
                $conf["overWrite"]="true";
                #參考資料:
                #無.
                #備註:
                #無.
                $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);
                                
                                }#if end
                                
                        #異常結束執行
                        exit(1);

                        }#if end
        
                #link etc/systemd/system 底下的所有內容
                #函式說明:
                #針對特定目錄下的內容建立軟連結.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息.
                #$result["function"],當前執行的函數名稱.
                #$result["content"],字串陣列,每個建立的軟連結資訊.
                #必填參數:
                #$conf["fileArgu"],字串,變數__FILE__的內容.
                $conf["fileArgu"]=__FILE__;
                #$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
                $conf["linkToDir"]="etc/systemd/system";
                #可省略參數:
                #$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
                $conf["path"]=$libOfRootPath.$conf["linkToDir"];
                #$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);
                                
                                }#if end
                                
                        #異常結束執行
                        exit(1);

                        }#if end
        
                #link usr/bin 底下的所有內容
                #函式說明:
                #針對特定目錄下的內容建立軟連結.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息.
                #$result["function"],當前執行的函數名稱.
                #$result["content"],字串陣列,每個建立的軟連結資訊.
                #必填參數:
                #$conf["fileArgu"],字串,變數__FILE__的內容.
                $conf["fileArgu"]=__FILE__;
                #$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
                $conf["linkToDir"]="usr/bin";
                #可省略參數:
                #$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
                $conf["path"]=$libOfRootPath."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);
                                
                                }#if end
                                
                        #異常結束執行
                        exit(1);

                        }#if end
        
                #link usr/bin/libexec 底下的所有內容
                #函式說明:
                #針對特定目錄下的內容建立軟連結.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息.
                #$result["function"],當前執行的函數名稱.
                #$result["content"],字串陣列,每個建立的軟連結資訊.
                #必填參數:
                #$conf["fileArgu"],字串,變數__FILE__的內容.
                $conf["fileArgu"]=__FILE__;
                #$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
                $conf["linkToDir"]="usr/bin/libexec";
                #可省略參數:
                #$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
                $conf["path"]=$libOfRootPath.$conf["linkToDir"];
                #$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);
                                
                                }#if end
                                
                        #異常結束執行
                        exit(1);

                        }#if end
        
                break;
                
        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);
                        
                        }#if end
                        
                #異常結束執行
                exit(1);
                
        }#switch 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"]=$libOfRootPath."usr/lib/qbpwcf/allInOneForCI.php";
        #可省略參數:
        #$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
        $conf["path"]=$libOfRootPath."usr/lib/qbpwcf";
        #$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
        $conf["name"]="allInOne.php";
        #$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
        $conf["overWrite"]="true";
        #參考資料:
        #無.
        #備註:
        #無.
        $createLink=fileAccess::createLink($conf);
        unset($conf);

        #var_dump($createLink);

        #如果執行失敗
        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);
                        
                        }#if end
                        
                #異常結束執行
                exit(1);

                }#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"]=$libOfRootPath."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);
                
                }#if end
                
        #異常結束執行
        exit(1);

        }#if end

/*
#break point
var_dump($chmod);
exit;
*/

#讓 "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"]=$libOfRootPath."usr/lib/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);
        
                }#if end
                
        #異常結束執行
        exit(1);

        }#if end

/*
#break point
var_dump($chmod);
exit;
*/
        
#依照參數設定 etc/qbpwcf/config.php
#函式說明:
#建立軟連結.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["error"],錯誤訊息.
#$result["function"],當前執行的函數名稱.
#$result["content"],軟連結的資訊.
#必填參數:
#$conf["fileArgu"],字串,變數__FILE__的內容.
$conf["fileArgu"]=__FILE__;
#$conf["file"],字串,要更新的檔案位置與名稱.
$conf["file"]=$libOfRootPath."etc/qbpwcf/config.php";
#可省略參數:
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
$conf["overWriteWith"][]="<?php";
$conf["overWriteWith"][]="";
$conf["overWriteWith"][]="#specify host ip";
$conf["overWriteWith"][]="\$myIp="."\"".$ip."\";";
$conf["overWriteWith"][]="";
$conf["overWriteWith"][]="#specify url to get self www ip";
$conf["overWriteWith"][]="\$getIpUrl=\"".$getIpUrl."\";";
$conf["overWriteWith"][]="";
$conf["overWriteWith"][]="#specify url to get config";
$conf["overWriteWith"][]="\$configUrl=\"".$configUrl."\";";
$conf["overWriteWith"][]="";
$conf["overWriteWith"][]="?\>";
#$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=fileAccess::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);
                
                }#if end
                
        #異常結束執行
        exit(1);

        }#if end
        
#讓 "etc/qbpwcf/config.php" 可以被大家使用.
#函式說明:
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["error"],錯誤訊息.
#$result["function"],當前執行的函式名稱.
#必填參數:
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
$conf["mode"]="777";
#$conf["target"],字串,需要變更權限的目標.
$conf["target"]=$libOfRootPath."etc/qbpwcf/config.php";
#可省略參數:
#$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);
        
                }#if end
                
        #異常結束執行
        exit(1);

        }#if end

#依照參數設定 "etc/backupDb.conf"
#函式說明:
#建立軟連結.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["error"],錯誤訊息.
#$result["function"],當前執行的函數名稱.
#$result["content"],軟連結的資訊.
#必填參數:
#$conf["fileArgu"],字串,變數__FILE__的內容.
$conf["fileArgu"]=__FILE__;
#$conf["file"],字串,要更新的檔案位置與名稱.
$conf["file"]=$libOfRootPath."etc/qbpwcf/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=fileAccess::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);
                
                }#if end
                
        #異常結束執行
        exit(1);

        }#if end

#重新建置 etc/qbpwcf.conf.xml
#函式說明:
#更新檔案內容.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["error"],錯誤訊息.
#$result["function"],當前執行的函數名稱.
#$result["content"],軟連結的資訊.
#必填參數:
#$conf["fileArgu"],字串,變數__FILE__的內容.
$conf["fileArgu"]=__FILE__;
#$conf["file"],字串,要更新的檔案位置與名稱.
$conf["file"]=$libOfRootPath."etc/qbpwcf/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=fileAccess::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);
                
                }#if end
                
        #異常結束執行
        exit(1);

        }#if end

#讓 "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"]=$libOfRootPath."etc/qbpwcf/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);
        
                }#if end
                
        #異常結束執行
        exit(1);

        }#if end

/*
#break point
var_dump($chmod);
exit;
*/

#若有要指定 ssh addr 與 port
if(count($sshAddrAndPort)>0){

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

        #如果執行失敗
        if($writeTextIntoFile["status"]==="false"){
        
                #印出結果
                var_dump($writeTextIntoFile);
                
                #結束執行
                exit;
        
                }#if end

        #要覆寫的內容
        $overWriteWith=array("<?php".PHP_EOL);

        #debug
        #$overWriteWith[]="\$reportOnly=\"true\";";
        
        #get some verbose info
        $overWriteWith[]="\$verbose=\"true\";";

        #針對每個為了確保ssh服務有運行的設定
        foreach($sshAddrAndPort as $ipAndPort){

                #串接設定
                $overWriteWith[]="\$ipAndPort=\"".$ipAndPort."\";";

                }#foreach end
                
        #要覆寫的內容
        $overWriteWith[]=PHP_EOL."?>";

        #函式說明:
        #更新檔案的內容.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息.
        #$result["function"],當前執行的函數名稱.
        #$result["content"],軟連結的資訊.
        #必填參數:
        #$conf["fileArgu"],字串,變數__FILE__的內容.
        $conf["fileArgu"]=__FILE__;
        #$conf["file"],字串,要更新的檔案位置與名稱.
        $conf["file"]=$defaultSshdConfigAddr;
        #可省略參數:
        #$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
        $conf["overWriteWith"]=$overWriteWith;
        #$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=fileAccess::updateFile($conf);
        unset($conf);

        #如果執行失敗
        if($updateFile["status"]==="false"){
        
                #印出結果
                var_dump($updateFile);
                
                #結束執行
                exit;
        
                }#if end

        }#if end

#移除 etc/systemd/system 底下服務設定檔的執行權限
#函式說明:
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["error"],錯誤訊息.
#$result["function"],當前執行的函式名稱.
#必填參數:
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
$conf["mode"]="640";
#$conf["target"],字串,需要變更權限的目標.
$conf["target"]=$libOfRootPath."etc/systemd/system";
#可省略參數:
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
$conf["recursive"]="true";
#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
$conf["excludeSelf"]="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);
        
                }#if end
                
        #異常結束執行
        exit(1);

        }#if end

#如果 $whiteIp 不為空
if(count($whiteIp)>0){

        #如果有 ip-blockerd.service 存在
        #函式說明:
        #檢查多個檔案與資料夾是否存在.
        #回傳的結果:
        #$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息陣列.
        #$resutl["function"],當前執行的涵式名稱.
        #$result["argu"],使用的參數.
        #$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
        #$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
        #$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
        #$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
        #$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
        #必填參數:
        #$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
        $conf["fileArray"]=array("./etc/system/ip-blockerd.service");
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
        $conf["disableWebSearch"]="true";
        #$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
        $conf["userDir"]="false";
        #$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
        $conf["web"]="false";
        #參考資料:
        #http://php.net/manual/en/function.file-exists.php
        #http://php.net/manual/en/control-structures.foreach.php
        #備註:
        #函數file_exists檢查的路徑為檔案系統的路徑
        #$result["varName"][$i]結果未實作
        $checkMultiFileExist=fileAccess::checkMultiFileExist($conf);
        unset($conf);
        
        #如果執行失敗
        if($checkMultiFileExist["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);
                        
                        }#if end
                        
                #異常結束執行
                exit(1);

                }#if end
                
        #如果存在
        if($checkMultiFileExist["allExist"]==="true"){
        
                #啟動服務的關鍵字
                $serviceStartKeyWord="ExecStart=/usr/bin/ipBlockerd.php";
                
                #重新啟動服務的關鍵字
                $serviceRestartKeyWord="ExecReload=killall ipBlockerd.php; sleep 10; ipBlockerd.php";
                
                #函式說明:
                #將一維陣列轉換為用特定符號間隔的字串,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["inputArray"]=$whiteIp;
                #可省略參數:
                #$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
                $conf["spiltSymbol"]=" --exclude ";
                #$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
                $conf["skipEnd"]="true";
                #$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
                $conf["spiltSymbolAtStart"]="true";
                #參考資料:
                #無.
                #備註:
                #無.
                $arrayToString=arrays::arrayToString($conf);
                unset($conf);
        
                #如果執行出錯
                if($arrayToString["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"]=$arrayToString;
                        #$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);
                                
                                }#if end
                                
                        #異常結束執行
                        exit(1);

                        }#if end

                #啟動服務的新內容
                $serviceStartNewContent=$serviceStartKeyWord.$arrayToString["content"];

                #重新啟動服務的新內容
                $serviceRestartNewContent=$serviceRestartKeyWord.$arrayToString["content"];
        
                #設置白名單ip
                #函式說明:
                #更新檔案的內容.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息.
                #$result["function"],當前執行的函數名稱.
                #$result["content"],軟連結的資訊.
                #必填參數:
                #$conf["fileArgu"],字串,變數__FILE__的內容.
                $conf["fileArgu"]=__FILE__;
                #$conf["file"],字串,要更新的檔案位置與名稱.
                $conf["file"]="./etc/systemd/system/ip-blockerd.service";
                #可省略參數:
                #$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
                #$conf["overWriteWith"]=array();
                #$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
                $conf["replaceWith"]=array(array($serviceStartKeyWord,$serviceStartNewContent),array($serviceRestartKeyWord,$serviceRestartNewContent));
                #$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
                $conf["replaceLike"]="true";
                #$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
                #$conf["addToTailWhenNoMatch"]="false";
                #$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
                #$conf["addToTailBeforeThat"]="?\>";
                #參考資料:
                #無.
                #備註:
                #無.
                $updateFile=fileAccess::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);
                                
                                }#if end
                                
                        #異常結束執行
                        exit(1);

                        }#if end
        
                }#if end

        }#if end

#函式說明:
#取得用戶端的資訊,並依據需要寫入到資料表裡面
#回傳的結果:
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
#$result["error"],錯誤訊息.
#$result["function"],檔前執行的函數名稱.
#$result["mode"],當前的模式是"cmd"還是"web".
#$result["userBrowserType"],爲使用者的瀏覽器資訊
#$result["userIp"],爲使用者的IP
#$result["serverIp"],為伺服器的IP
#$result["server_name"],伺服器的 domain name
#$result["scheme"],通訊協定
#$result["serverPort"],伺服器給對外下載網頁的port
#$result["requestUri"],爲使用者要求的網址/php檔案.
#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
#$result["clientRequestIP"],用戶端要求的ip與port
#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
#$result["header"],接收到的 header 陣列.
#$result["body"],接收到的 body 字串.
#必填參數:
#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
$conf["getAccount"]="true";
#可省略參數:
#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
#$conf["accountVar"]=$_SESSION["username"];
#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
#$conf["saveToDb"]="true";
#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
#$conf["dbAddress"]=$dbAddress;
#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
#$conf["dbAccount"]=$dbAccount;
#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
#$conf["dbName"]=$dbName;
#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
#$conf["tableName"]="visitorInfo";
#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
#$conf["dbPassword"]=$dbPassword;
#參考資料:
#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
#備註:
#無.
$getConnectionInfo=csInformation::getConnectionInfo($conf);
unset($conf);

#如果執行失敗
if($getConnectionInfo["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"]=$getConnectionInfo;
        #$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);
        
                }#if end
                
        #異常結束執行
        exit(1);

        }#if end

#如果不是沒有權限的一般使用者
if($getConnectionInfo["phpUserType"]!=="regular"){

        #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);
                
                        }#if end
                        
                #異常結束執行
                exit(1);

                }#if end

        #enable and restart 於 $libOfRootPath.$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"]=$libOfRootPath."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);
                
                        }#if end
                        
                #異常結束執行
                exit(1);

                }#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);
                        
                                }#if end
                                
                        #異常結束執行
                        exit(1);

                        }#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);
                        
                                }#if end
                                
                        #異常結束執行
                        exit(1);

                        }#if end

                }#foreach end

        }#if end

?>