Subversion Repositories php-qbpwcf

Rev

Rev 183 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

/*
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2014~2025 MIN ZHI, 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;

#初始化輸出
$output=array();

#取得 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];

#初始化輸出
$output=array();

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

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

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

#預設的範例資料參數
$params=array();
$params["dbSecret"]=$dbSecret;
$params["dbAddr"]=$dbAddress;
$params["dbPort"]=$dbPort;
$params["dbName"]=$dbName;
$params["dbUser"]=$dbAccount;
$params["dbPass"]=$dbPassword;
$params["dtName"]="namespace";
$params["cols"]=array("name","comment");
$params["vals"]=array("notExist","not exist namespace");

#加密參數
#函式說明:
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["function"],當前執行的函數名稱.
#$result["content"],加密後的結果.
#$result["error"],錯誤訊息陣列.
#$result["argu"],使用的參數.
#必填參數:
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
$conf["enCodeStr"]=$params;
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
$conf["enCodeType"]="qbpwcf";
#可省略參數:
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
#$conf["sha1Raw"]="false";
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
#$conf["p_hash"]="";
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
#$conf["keyForAes256"]="";
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
#$conf["aes256Encode"]="";
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
#$conf["qbpwcfDecode"]="false";
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
#$conf["gpgDecrypt"]="false";
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
#$conf["gpgId"]="";
#參考資料:
#sha1=>http://php.net/manual/en/function.sha1.php
#md5=>http://php.net/manual/en/function.md5.php
#password_hash=>http://php.net/manual/en/function.password-hash.php
#password_verify=>http://php.net/manual/en/function.password-verify.php
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
#備註:
#無.
$enCodeStr=authenticate::enCodeStr($conf);
unset($conf);

#如果執行異常
if($enCodeStr["status"]==="false"){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],字串,要寫的內容.
        $conf["content"]=json_encode($enCodeStr).PHP_EOL;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log 失敗
        if($record["status"]==="false"){

                #印出訊息
                echo json_encode($record);

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

                }#if end

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

        }#if end

#加密參數
#函式說明:
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["function"],當前執行的函數名稱.
#$result["content"],加密後的結果.
#$result["error"],錯誤訊息陣列.
#$result["argu"],使用的參數.
#必填參數:
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
$conf["enCodeStr"]=$enCodeStr["content"];
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
$conf["enCodeType"]="gpg";
#可省略參數:
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
#$conf["sha1Raw"]="false";
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
#$conf["p_hash"]="";
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
#$conf["keyForAes256"]="";
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
#$conf["aes256Encode"]="";
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
#$conf["qbpwcfDecode"]="false";
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
$conf["gpgDecrypt"]="false";
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
#$conf["gpgId"]="";
#參考資料:
#sha1=>http://php.net/manual/en/function.sha1.php
#md5=>http://php.net/manual/en/function.md5.php
#password_hash=>http://php.net/manual/en/function.password-hash.php
#password_verify=>http://php.net/manual/en/function.password-verify.php
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
#備註:
#無.
$enCodeStr=authenticate::enCodeStr($conf);
unset($conf);

#如果執行異常
if($enCodeStr["status"]==="false"){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],字串,要寫的內容.
        $conf["content"]=json_encode($enCodeStr).PHP_EOL;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log 失敗
        if($record["status"]==="false"){

                #印出訊息
                echo json_encode($record);

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

                }#if end

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

        }#if end

#編碼參數
#函式說明:
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["function"],當前執行的函數名稱.
#$result["content"],加密後的結果.
#$result["error"],錯誤訊息陣列.
#$result["argu"],使用的參數.
#必填參數:
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
$conf["enCodeStr"]=$enCodeStr["content"];
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
$conf["enCodeType"]="bin2hex";
#可省略參數:
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
#$conf["sha1Raw"]="false";
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
#$conf["p_hash"]="";
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
#$conf["keyForAes256"]="";
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
#$conf["aes256Encode"]="";
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
#$conf["qbpwcfDecode"]="false";
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
#$conf["gpgDecrypt"]="false";
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
#$conf["gpgId"]="";
#參考資料:
#sha1=>http://php.net/manual/en/function.sha1.php
#md5=>http://php.net/manual/en/function.md5.php
#password_hash=>http://php.net/manual/en/function.password-hash.php
#password_verify=>http://php.net/manual/en/function.password-verify.php
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
#備註:
#無.
$enCodeStr=authenticate::enCodeStr($conf);
unset($conf);

#如果執行異常
if($enCodeStr["status"]==="false"){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],字串,要寫的內容.
        $conf["content"]=json_encode($enCodeStr).PHP_EOL;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log 失敗
        if($record["status"]==="false"){

                #印出訊息
                echo json_encode($record);

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

                }#if end

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

        }#if end

#更新POST的預設參數
$_POST["params"]=$enCodeStr["content"];

#涵式說明:
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
#回傳的結果:
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
#$result["error"],錯誤訊息陣列.
#$resutl["function"],當前執行的涵式名稱.
#$result["warning"],警告訊息陣列.
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
#$result["lostVarName"],沒有皆收到的變數名稱陣列
#$result["inputDataContent"],所接收的參數陣列.
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
#$result["inputDataCount"],從表單總共接收到幾個元素.
#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
#必填的參數:
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
$conf["method"]="POST";
#可省略的參數:
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
#$conf["allowGet"]="true";
#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
#$conf["limitPrePage"]=array("");
#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
#$conf["transferLocation"]="";
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
#$conf["ignore"]=array();
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
#$conf["correctCharacter"]="false";
#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
$conf["checkedVarName"]=array("params");
#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
#$conf["canBeEmptyString"]="false";
#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
#$conf["sessionNameArray"]=array();
#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
#$conf["unsetSessionArray"]=array();
#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.
#$conf["recaptcha_url"]="";
#參考資料來源:
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
#備註:
#表單變數的名稱若含有「.」,則會變成「-」。
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf);
unset($conf);

#如果執行異常
if($responseMultiInputDataSecurityEnhance["status"]==="false"){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],字串,要寫的內容.
        $conf["content"]="Form data error, please see json:".json_encode($responseMultiInputDataSecurityEnhance).PHP_EOL;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log 失敗
        if($record["status"]==="false"){

                #印出訊息
                echo json_encode($record);

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

                }#if end

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

        }#if end

#函式說明:
#撰寫log
#回傳結果:
#$result["status"],狀態,"true"或"false".
#$result["error"],錯誤訊息陣列.
#$result["function"],當前函式的名稱.
#$result["argu"],使用的參數.
#必填參數:
#$conf["path"],log檔案的路徑與名稱.
$conf["path"]=$logFile;
#$conf["content"],字串,要寫的內容.
$conf["content"]=json_encode($responseMultiInputDataSecurityEnhance).PHP_EOL;
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
$conf["fileArgu"]=__FILE__;
#可省略參數:
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
#$conf["rewrite"]="false";
#參考資料:
#無.
#備註:
#無.
$record=logs::record($conf);
unset($conf);

#如果寫log 失敗
if($record["status"]==="false"){

        #印出訊息
        echo json_encode($record);

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

        }#if end

#取得參數
$params=$responseMultiInputDataSecurityEnhance["inputDataContent"]["params"];

#解碼參數
#函式說明:
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["function"],當前執行的函數名稱.
#$result["content"],加密後的結果.
#$result["error"],錯誤訊息陣列.
#$result["argu"],使用的參數.
#必填參數:
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
$conf["enCodeStr"]=$params;
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
$conf["enCodeType"]="hex2bin";
#可省略參數:
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
#$conf["sha1Raw"]="false";
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
#$conf["p_hash"]="";
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
#$conf["keyForAes256"]="";
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
#$conf["aes256Encode"]="";
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
#$conf["qbpwcfDecode"]="false";
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
#$conf["gpgDecrypt"]="false";
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
#$conf["gpgId"]="";
#參考資料:
#sha1=>http://php.net/manual/en/function.sha1.php
#md5=>http://php.net/manual/en/function.md5.php
#password_hash=>http://php.net/manual/en/function.password-hash.php
#password_verify=>http://php.net/manual/en/function.password-verify.php
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
#備註:
#無.
$enCodeStr=authenticate::enCodeStr($conf);
unset($conf);

#debug
#var_dump(__LINE__,$enCodeStr);

#如果執行異常
if($enCodeStr["status"]==="false"){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],字串,要寫的內容.
        $conf["content"]=json_encode($enCodeStr).PHP_EOL;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log 失敗
        if($record["status"]==="false"){

                #印出訊息
                echo json_encode($record);

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

                }#if end

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

        }#if end

#解密參數
#函式說明:
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["function"],當前執行的函數名稱.
#$result["content"],加密後的結果.
#$result["error"],錯誤訊息陣列.
#$result["argu"],使用的參數.
#必填參數:
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
$conf["enCodeStr"]=$enCodeStr["content"];
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
$conf["enCodeType"]="gpg";
#可省略參數:
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
#$conf["sha1Raw"]="false";
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
#$conf["p_hash"]="";
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
#$conf["keyForAes256"]="";
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
#$conf["aes256Encode"]="";
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
#$conf["qbpwcfDecode"]="true";
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
$conf["gpgDecrypt"]="true";
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
#$conf["gpgId"]="";
#參考資料:
#sha1=>http://php.net/manual/en/function.sha1.php
#md5=>http://php.net/manual/en/function.md5.php
#password_hash=>http://php.net/manual/en/function.password-hash.php
#password_verify=>http://php.net/manual/en/function.password-verify.php
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
#備註:
#無.
$enCodeStr=authenticate::enCodeStr($conf);
unset($conf);

#debug
#var_dump(__LINE__,$enCodeStr);exit;

#如果執行異常
if($enCodeStr["status"]==="false"){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],字串,要寫的內容.
        $conf["content"]=json_encode($enCodeStr).PHP_EOL;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log 失敗
        if($record["status"]==="false"){

                #印出訊息
                echo json_encode($record);

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

                }#if end

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

        }#if end

#解密參數
#函式說明:
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["function"],當前執行的函數名稱.
#$result["content"],加密後的結果.
#$result["error"],錯誤訊息陣列.
#$result["argu"],使用的參數.
#必填參數:
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
$conf["enCodeStr"]=$enCodeStr["content"];
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
$conf["enCodeType"]="qbpwcf";
#可省略參數:
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
#$conf["sha1Raw"]="false";
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
#$conf["p_hash"]="";
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
#$conf["keyForAes256"]="";
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
#$conf["aes256Encode"]="";
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
$conf["qbpwcfDecode"]="true";
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
#$conf["gpgDecrypt"]="true";
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
#$conf["gpgId"]="";
#參考資料:
#sha1=>http://php.net/manual/en/function.sha1.php
#md5=>http://php.net/manual/en/function.md5.php
#password_hash=>http://php.net/manual/en/function.password-hash.php
#password_verify=>http://php.net/manual/en/function.password-verify.php
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
#備註:
#無.
$enCodeStr=authenticate::enCodeStr($conf);
unset($conf);

#debug
#var_dump(__LINE__,$enCodeStr);exit;

#如果執行異常
if($enCodeStr["status"]==="false"){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],字串,要寫的內容.
        $conf["content"]=json_encode($enCodeStr).PHP_EOL;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log 失敗
        if($record["status"]==="false"){

                #印出訊息
                echo json_encode($record);

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

                }#if end

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

        }#if end

#取得解碼後的結果
$params=$enCodeStr["content"];

#轉換為陣列
$params=(array)$params;

#函式說明:
#撰寫log
#回傳結果:
#$result["status"],狀態,"true"或"false".
#$result["error"],錯誤訊息陣列.
#$result["function"],當前函式的名稱.
#$result["argu"],使用的參數.
#必填參數:
#$conf["path"],log檔案的路徑與名稱.
$conf["path"]=$logFile;
#$conf["content"],字串,要寫的內容.
$conf["content"]=json_encode($params).PHP_EOL;
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
$conf["fileArgu"]=__FILE__;
#可省略參數:
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
#$conf["rewrite"]="false";
#參考資料:
#無.
#備註:
#無.
$record=logs::record($conf);
unset($conf);

#如果寫log 失敗
if($record["status"]==="false"){

        #印出訊息
        echo json_encode($record);

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

        }#if end

#如果少了使用資料庫系統的dbSecret
if(!isset($params["dbSecret"])){

        #結束執行
        exit;

        }#if end

#驗證密碼是否正確
else{

        #若dbSecret錯誤
        if($params["dbSecret"]!==dbSecret){

                #函式說明:
                #撰寫log
                #回傳結果:
                #$result["status"],狀態,"true"或"false".
                #$result["error"],錯誤訊息陣列.
                #$result["function"],當前函式的名稱.
                #$result["argu"],使用的參數.
                #必填參數:
                #$conf["path"],log檔案的路徑與名稱.
                $conf["path"]=$logFile;
                #$conf["content"],字串,要寫的內容.
                $conf["content"]="wrong dbSecret".PHP_EOL;
                #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
                $conf["fileArgu"]=__FILE__;
                #可省略參數:
                #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
                #$conf["rewrite"]="false";
                #參考資料:
                #無.
                #備註:
                #無.
                $record=logs::record($conf);
                unset($conf);

                #如果寫log 失敗
                if($record["status"]==="false"){

                        #印出訊息
                        echo json_encode($record);

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

                        }#if end

                #結束執行
                exit;

                }#if end

        #移除傳遞的 dbSecret
        unset($params["dbSecret"]);

        }#else end

#檢查變數
#函式說明:
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$reuslt["error"],執行不正常結束的錯訊息陣列.
#$result["function"],當前執行的函式名稱.
#$result["argu"],設置給予的參數.
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
#必填寫的參數:
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
$conf["variableCheck::checkArguments"]["varInput"]=&$params;
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
#可以省略的參數:
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddr","dbName","dbUser","dbPass","dtName","cols","vals");
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string","array","array");
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
#$conf["canNotBeEmpty"]=array();
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
#$conf["canBeEmpty"]=array();
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
#$conf["skipableVariableCanNotBeEmpty"]=array();
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPort");
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("3306");
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
#$conf["disallowAllSkipableVarIsEmpty"]="";
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cols","vals");
#參考資料來源:
#array_keys=>http://php.net/manual/en/function.array-keys.php
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
unset($conf["variableCheck::checkArguments"]);

#函式說明:
#撰寫log
#回傳結果:
#$result["status"],狀態,"true"或"false".
#$result["error"],錯誤訊息陣列.
#$result["function"],當前函式的名稱.
#$result["argu"],使用的參數.
#必填參數:
#$conf["path"],log檔案的路徑與名稱.
$conf["path"]=$logFile;
#$conf["content"],字串,要寫的內容.
$conf["content"]=json_encode($checkArguments).PHP_EOL;
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
$conf["fileArgu"]=__FILE__;
#可省略參數:
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
#$conf["rewrite"]="false";
#參考資料:
#無.
#備註:
#無.
$record=logs::record($conf);
unset($conf);

#如果寫log 失敗
if($record["status"]==="false"){

        #印出訊息
        echo json_encode($record);

        #結束執行
        exit;

        }#if end

#如果執行失敗
if($checkArguments["status"]==="false"){

        #印出訊息
        echo json_encode($checkArguments);

        #結束執行
        exit;

        }#if end

#如果邊數檢查不通過
if($checkArguments["passed"]==="false"){

        #印出訊息
        echo json_encode($checkArguments);

        #結束執行
        exit;

        }#if end

/*
#可能存在的參數
$params["dbAddr"];
$params["dbPort"];
$params["dbName"];
$params["dbUser"];
$params["dbPass"];
$params["dtName"];
$params["cols"];#條件欄位
$params["vals"];#條件欄位對應數值
*/

#涵式說明:
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
#回傳的數值:
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
#$result["error"],錯誤訊息.
#$result["sql"],執行的sql語法.
#$result["function"],當前執行的涵式
#必填的參數:
$conf["dbAddress"]=$params["dbAddr"];#爲mysql-Server的位置
$conf["dbAccount"]=$params["dbUser"];#爲用於連入mysql-Server時要使用的帳號
$conf["selectedDataBaseName"]=$params["dbName"];#要選取的資料庫名稱
$conf["tableName"]=$params["dtName"];#爲要插入資料的資料表名稱
$conf["columnName"]=$params["cols"];#爲資料表的項目名稱,
        #例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
$conf["insertValue"]=$params["vals"];#爲要插入度數值,
        #例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
#可以省略的變數:
$conf["dbPassword"]=$params["dbPass"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表用預設的 3306 port.
$conf["dbPort"]=$params["dbPort"];
#參考資料來源:
#http://www.javaworld.com.tw/jute/post/view?bid=21&id=173738&sty=1
$insertData=db::insertData($conf);
unset($conf);

#如果執行異常
if($insertData["status"]==="false"){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],字串,要寫的內容.
        $conf["content"]=json_encode($insertData).PHP_EOL;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log 失敗
        if($record["status"]==="false"){

                #印出訊息
                echo json_encode($record);

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

                }#if end

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

        }#if end

#函式說明:
#撰寫log
#回傳結果:
#$result["status"],狀態,"true"或"false".
#$result["error"],錯誤訊息陣列.
#$result["function"],當前函式的名稱.
#$result["argu"],使用的參數.
#必填參數:
#$conf["path"],log檔案的路徑與名稱.
$conf["path"]=$logFile;
#$conf["content"],字串,要寫的內容.
$conf["content"]=json_encode($insertData).PHP_EOL;
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
$conf["fileArgu"]=__FILE__;
#可省略參數:
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
#$conf["rewrite"]="false";
#參考資料:
#無.
#備註:
#無.
$record=logs::record($conf);
unset($conf);

#如果寫log 失敗
if($record["status"]==="false"){

        #印出訊息
        echo json_encode($record);

        #結束執行
        exit;

        }#if end

#印出結果
echo json_encode($insertData);

?>