Rev 323 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2014~2026 MIN ZHI, CHENThis file is part of QBPWCF.QBPWCF is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.QBPWCF is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with QBPWCF. If not, see <http://www.gnu.org/licenses/>.*//*本程式說明:寄送用於認證的E-mail.*/#使用命名空間qbpwcfnamespace qbpwcf;#初始化輸出$output=array();#取得 lib pathexec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);#如果執行失敗if($status!==0){#debugvar_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());#匯入套件require_once("allInOneForJson.php");#建議的log位置$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";#關閉既有sessionsession_abort();#設置session儲存位置session_save_path(".hta-session");#啟動 sessionsession_start();#取得session id$sId=session_id();#debug#var_dump(__LINE__,$sId);exit;#函式說明:#依照OPTIONS的要求,判斷條件,給予允許呼叫的header。#回傳結果:#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["content"],回傳結果.#$result["content"]["receivedHeader"],陣列,收到的header#$result["content"]["sendedHeader"],陣列,要送出的header.#必填參數:#無#可省略參數:#$conf["allowDomain"],陣列變數,代表允許的來源domain name.#$conf["allowDomain"]=array();#$conf["allowMethod"],陣列變數,代表允許的要求方法.#$conf["allowMethod"]=array();#$conf["allowHeader"],陣列變數,代表要允許的header.#$conf["allowHeader"]=array();#參考資料:#https://www.php.net/manual/en/function.header-remove.php#https://www.php.net/manual/en/function.http-response-code.php#備註:#無.$conf=array();$accessControl=header::accessControl($conf);unset($conf);#如果執行失敗if($accessControl["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"]=$accessControl;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#函式說明:#可以處理多個透過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("sid","mail","id");#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.#$conf["canBeEmptyString"]="false";#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.#$conf["sessionNameArray"]=array("sendMailAgentAPIkey");#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.#$conf["unsetSessionArray"]=array("true");#$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"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$responseMultiInputDataSecurityEnhance;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#如果驗證失敗if($responseMultiInputDataSecurityEnhance["passed"]==="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"]=$responseMultiInputDataSecurityEnhance;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#儲存收到用於識別資訊資源的id$wsClientId=$responseMultiInputDataSecurityEnhance["inputDataContent"]["id"];#debug#var_dump(__LINE__,$responseMultiInputDataSecurityEnhance);#儲存收到的 session id$recvSid=$responseMultiInputDataSecurityEnhance["inputDataContent"]["sid"];#解密收到的 sessoin id#函式說明:#加密或編碼字串,可以用的方法有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"]=base64_decode($recvSid);#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過json_encode、urlencode、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"]="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);#如果執行失敗if($enCodeStr["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"]=$enCodeStr;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#debug#var_dump(__LINE__,"after decrypted randomStr & sid",$enCodeStr);#取得 session id#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["deleted"],被移除的內容.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringIn"]=$enCodeStr["content"];#$conf["keyWord"],字串,特定字串.$conf["keyWord"]="=";#可省略參數:#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.#$conf["recursive"]="true";#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.#$conf["lastResult"]=$delStrBeforeKeyWord;#參考資料:#無.#備註:#無.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf);unset($conf);#如果執行失敗if($delStrBeforeKeyWord["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"]=$delStrBeforeKeyWord;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#如果沒有應該存在的關鍵字 "="if($delStrBeforeKeyWord["founded"]==="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"]=$delStrBeforeKeyWord;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#取得收到的sid$recvSid=$delStrBeforeKeyWord["content"];#debug#var_dump(__LINE__,"after parse sid",$recvSid);#如果收到的 seesion id 跟 當前的 session id 不一樣if($recvSid!==$sId){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]="收到的 seesion id(".$recvSid.") 跟 當前的 session id(".$sId.") 不一樣";#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#儲存收到的 mail$mail=$responseMultiInputDataSecurityEnhance["inputDataContent"]["mail"];#debug#var_dump(__LINE__,"after received unvalid MAIL",$mail);#解碼收到的 mail#函式說明:#加密或編碼字串,可以用的方法有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"]=base64_decode($mail);#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過json_encode、urlencode、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"]="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);#如果執行失敗if($enCodeStr["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"]=$enCodeStr;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#debug#var_dump(__LINE__,"after decrypted unvalid MAIL",$enCodeStr);#如果不存在 mailif(!isset($enCodeStr["content"]->mail)){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]="不存在要驗證的Email地址";#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#取得要驗證的Email$receiverMail=$enCodeStr["content"]->mail;#預設的email登入賬號$username=systemMailAcct;#debug#var_dump(__LINE__,"BEOFRE process unvalid MAIL",$receiverMail);#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["deleted"],被移除的內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringIn"]=$username;#$conf["keyWord"],字串,特定字串.$conf["keyWord"]="@";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].$conf["deleteLastRepeatedOne"]="true";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf);unset($conf);#如果異常if($delStrAfterKeyWord["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"]=$delStrAfterKeyWord;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#如果有@關鍵字if($delStrAfterKeyWord["founded"]==="true"){#取得 username$username=$delStrAfterKeyWord["content"];#取得寄信的 email server$senderMailServer=$delStrAfterKeyWord["deleted"];}#if end#取得收件人的username$rev_username=$receiverMail;#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["deleted"],被移除的內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringIn"]=$receiverMail[0];#$conf["keyWord"],字串,特定字串.$conf["keyWord"]="@";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].$conf["deleteLastRepeatedOne"]="true";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf);unset($conf);#如果異常if($delStrAfterKeyWord["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"]=$delStrAfterKeyWord;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#如果有@關鍵字if($delStrAfterKeyWord["founded"]==="true"){#取得接收者的 username$rev_username[0]=$delStrAfterKeyWord["content"];}#if end#var_dump(__LINE__,"BEOFRE SEND MAIL");#產生亂數#函式說明:#建立以圖片(PNG格式)呈現的驗證碼.#回傳的解果:#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.#$result["error"],錯誤訊息.#$result["function"],檔前執行的函數名稱.#$result["randNumberWord"],傳驗證碼的內容.#$result["imgAddress"],包含src圖片的位置與名稱.#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.#必填參數:#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生$conf["imgAddressAndName"]="/tmp/notExsit.img";#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.#$conf["num"]="8";#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消$conf["disableImg"]="true";#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"#$conf["imgToData"]="true";#$conf["class"],字串,圖片要套用的css樣式類別.#$conf["class"]="";#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).#$conf["content"]=array();#參考資料:#無.#備註:#無.$validationCode=authenticate::validationCode($conf);unset($conf);#如果執行失敗if($validationCode["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"]=$validationCode;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#隨機產生get變數名稱$getVarName=$validationCode["randNumberWord"];#debug#var_dump(__LINE__,$sId);#加密 亂數跟session id作為識別#函式說明:#加密或編碼字串,可以用的方法有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"]=array("sId"=>base64_encode($sId),"email"=>base64_encode($receiverMail),"id"=>base64_encode($wsClientId));#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg",8種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過先json_encdoe後再urlencode最後再base64_encode後bin2hex的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key.$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"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$enCodeStr;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#gpg加密後的內容為2元碼,因此要透過base64_encode為ASCII$enCodeStr["content"]=base64_encode($enCodeStr["content"]);#要作為get變數的數值,因此要 urlencode$enCodeStr["content"]=urlencode($enCodeStr["content"]);#設置get變數,數值為加密後session id跟email字串$encodedGetVar=$getVarName."=".$enCodeStr["content"];#函式說明:#使用 php-pear-smtp 來透過SMTP伺服器寄信.#回傳結果:#$result["status"],執行正常與否,"true"代表正常;反之為"false".#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函數.#必填參數:#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址.若為tls加密,開頭請輸入"ssl://".$conf["mailServer"]="ssl://qbpwcf.org";#$conf["username"],字串,用來登入郵件伺服器的帳號$conf["username"]=$username;#$conf["password"],字串,用來登入郵件伺服器的密碼$conf["password"]=systemMailPass;#$conf["receiverMail"],陣列,收件人的信箱$conf["receiverMail"]=array($receiverMail);#$conf["subject"],字串,郵件的主題$conf["subject"]="Please verify the request is made by yourself";#$conf["plainBody"],字串,郵件本文的純文字內容.$conf["plainBody"]="Please visit url(https://".system_sendMailAgent_domain.system_sendMailAgent_path."usr/share/qbpwcf/system/sendMailAgent/receiver/index.php?".$encodedGetVar.") to finish the email verifition";#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.$conf["htmlBody"]="Please <a href=\"https://".system_sendMailAgent_domain.system_sendMailAgent_path."usr/share/qbpwcf/system/sendMailAgent/receiver/index.php?".$encodedGetVar."\">click this link to verif your email</a>";#可省略參數:#$conf["mailServerPort"],整數,smtp server的port,預設為465.#$conf["mailServerPort"]=465;#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]$conf["mailerMailDisplay"]=systemMailAcct;#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]$conf["mailerNameDisplay"]="send mail agent";#$conf["receiverNameDisplay"],陣列,要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.$conf["receiverNameDisplay"]=array($rev_username);#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱#$conf["attachment"]=array("index.php");#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.#$conf["attachmentName"]=array();#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".#$conf["attachmentMimeType"]array();#$conf["userAgent"],字串,用於表示使用smtp服務的軟體資訊,預設為"Powerd by QBPWCF(https://lib.qbpwcf.org)".#$conf["userAgent"]="Powerd by QBPWCF(https://lib.qbpwcf.org)";#$conf["org"],字串,若要表示來源組織名稱,可在此設定.$conf["org"]="QBPWCF(https://www.qbpwcf.org)";#$conf["notifyReceived"],字串,回報已讀通知,預設為"true"代表要;反之為"false".#$conf["notifyReceived"]="true";#$conf["signWithGPGid"],字串,用於簽署的gpg id,預設不使用.$conf["signWithGPGid"]=systemMailAcct;#$conf["signGpgThroughSocket"],字串,"trute"代表簽署gpg id的操作透過qbpwcf-uscok.service處理;預設為"false",直接用執行本程式的使用者來執行.$conf["signGpgThroughSocket"]="true";#參考資料:#官網=>http://pear.php.net/package/Net_SMTP#Document=>https://github.com/pear/Net_SMTP#SSL=>https://github.com/pear/Net_SMTP?tab=readme-ov-file#secure-connections#Message-ID: =>https://datatracker.ietf.org/doc/html/rfc5322#mail body boundary=>https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html#備註:#需要php-pear-Net-SMTP$pear_smtp_send=mail::pear_smtp_send($conf);unset($conf);#如果失敗if($pear_smtp_send["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"]=$pear_smtp_send;#$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"){#印出json結果echo json_encode($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#debug#var_dump($pear_smtp_send);exit;#設置準備驗證 email 時間點 的 session$_SESSION["sendMailAgent"]["mailStart"]=time();#設置當前狀態為 "wait" 代表尚未被 web socket 接收與驗證$_SESSION["sendMailAgent"]["status"]="wait";#初始化結果$result=array();#設置執行正常$result["status"]="true";#debug$result["session"]=$_SESSION;#印出json結果echo json_encode($result);