Subversion Repositories php-qbpwcf

Rev

Rev 292 | Rev 294 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 292 Rev 293
Line 790... Line 790...
790
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
790
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
791
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
791
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
792
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
792
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
793
			#必填參數:
793
			#必填參數:
794
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
794
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
795
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["pKey"];
795
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["pKey"]);
796
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
796
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
797
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
797
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
798
			#可省略參數:
798
			#可省略參數:
799
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
799
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
800
			#$conf["disableWebSearch"]="false";
800
			#$conf["disableWebSearch"]="false";
Line 3385... Line 3385...
3385
	#可省略參數:
3385
	#可省略參數:
3386
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
3386
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
3387
	#$conf["writeNow"]="false";
3387
	#$conf["writeNow"]="false";
3388
	#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
3388
	#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
3389
	#$conf["debug"]="false";
3389
	#$conf["debug"]="false";
3390
	#$conf["multiThread"],字串,是否啟動多執行序加快執行速度,預設為"false"代表不要;反之為"true"代表要.
3390
	#$conf["multiThreads"],字串,是否啟動多執行序加快執行速度,預設為"false"代表不要;反之為"true"代表要.
3391
	#$conf["multiThread"]="false";
3391
	#$conf["multiThreads"]="false";
3392
	#參考資料:
3392
	#參考資料:
3393
	#無.
3393
	#無.
3394
	#備註:
3394
	#備註:
3395
	#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
3395
	#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
3396
	#本套件是透過sshfs掛載來存取RR(dns記錄檔案),其檔案建議的擁有者權限為 root:qbpwcf,權限代碼為 774.
3396
	#本套件是透過sshfs掛載來存取RR(dns記錄檔案),其檔案建議的擁有者權限為 root:qbpwcf,權限代碼為 774.
3397
	#php-pear上的Net_DNS2也可以解析RR.
3397
	#php-pear上的Net_DNS2也可以解析RR.
-
 
3398
	#參數 multiThreads 目前有 bug.
3398
	*/
3399
	*/
3399
	public static function updateDnsRecordFile(&$conf){
3400
	public static function updateDnsRecordFile(&$conf){
3400
	
3401
	
3401
		#初始化要回傳的結果
3402
		#初始化要回傳的結果
3402
		$result=array();
3403
		$result=array();
Line 3456... Line 3457...
3456
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3457
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3457
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3458
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3458
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
3459
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
3459
		#$conf["skipableVariableCanNotBeEmpty"]=array();
3460
		#$conf["skipableVariableCanNotBeEmpty"]=array();
3460
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3461
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3461
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThread");
3462
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThreads");
3462
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3463
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3463
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
3464
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
3464
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3465
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3465
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
3466
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
3466
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3467
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
Line 3584... Line 3585...
3584
		
3585
		
3585
		#針對每行內容
3586
		#針對每行內容
3586
		foreach($lines as $lineNo => $line){
3587
		foreach($lines as $lineNo => $line){
3587
		
3588
		
3588
			#如果要啟用多執行序
3589
			#如果要啟用多執行序
3589
			if($conf["multiThread"]==="true"){
3590
			if($conf["multiThreads"]==="true"){
3590
			
3591
			
3591
				#初始化要執行的 php 程式
3592
				#如果要debug
3592
				$phpCode2run=array();
3593
				if($conf["debug"]==="true"){
3593
				
3594
				
-
 
3595
					#函式說明:
-
 
3596
					#撰寫log
-
 
3597
					#回傳結果:
-
 
3598
					#$result["status"],狀態,"true"或"false".
-
 
3599
					#$result["error"],錯誤訊息陣列.
-
 
3600
					#$result["function"],當前函式的名稱.
-
 
3601
					#$result["argu"],使用的參數.
-
 
3602
					#$result["content"],要寫入log的內容字串.
-
 
3603
					#必填參數:
-
 
3604
					#$conf["path"],字串,log檔案的路徑與名稱.
-
 
3605
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
3606
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
3607
					$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR through multi threads.".PHP_EOL;
-
 
3608
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3609
					$conf["logs::record"]["fileArgu"]=__FILE__;
3594
				#用 php 執行
3610
					#可省略參數:
-
 
3611
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3595
				$phpCode2run[]="php";
3612
					#$conf["rewrite"]="false";
-
 
3613
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
3614
					#$conf["returnOnly"]="true";
-
 
3615
					#參考資料:
-
 
3616
					#無.
-
 
3617
					#備註:
-
 
3618
					#無.
-
 
3619
					$record=logs::record($conf["logs::record"]);
-
 
3620
					unset($conf["logs::record"]);
3596
				
3621
				
3597
				#用 "-r" 參數
3622
					}#if end
-
 
3623
			
-
 
3624
				#初始化要執行的 php 程式
3598
				$phpCode2run[]="-r";
3625
				$phpCode2run="php -r ";
3599
				
3626
				
3600
				#用 "-r" 參數
3627
				#php code not escaped
3601
				$phpCode2run[]=<<<'PHP'
3628
				$phpCode2escaped=<<<'PHP'
-
 
3629
/*
-
 
3630
 
-
 
3631
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
-
 
3632
    Copyright (C) 2014~2026 MIN ZHI, CHEN
-
 
3633
 
3602
#匯入QBPWCF套件
3634
    This file is part of QBPWCF.
-
 
3635
 
-
 
3636
    QBPWCF is free software: you can redistribute it and/or modify
-
 
3637
    it under the terms of the GNU General Public License as published by
-
 
3638
    the Free Software Foundation, either version 3 of the License, or
3603
include("allInOne.php");
3639
    (at your option) any later version.
-
 
3640
 
-
 
3641
    QBPWCF is distributed in the hope that it will be useful,
-
 
3642
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-
 
3643
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-
 
3644
    GNU General Public License for more details.
-
 
3645
 
-
 
3646
    You should have received a copy of the GNU General Public License
-
 
3647
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
-
 
3648
 
-
 
3649
*/
3604
 
3650
 
-
 
3651
#使用命名空間qbpwcf
-
 
3652
namespace qbpwcf;
-
 
3653
 
-
 
3654
#匯入套件
-
 
3655
PHP;
-
 
3656
 
-
 
3657
#設置 lib root path
-
 
3658
$libPath=pathinfo(__FILE__)["dirname"]."/..";
-
 
3659
 
-
 
3660
#串接匯入QBPWCF套件
-
 
3661
$phpCode2escaped=$phpCode2escaped.PHP_EOL."require_once(\"".$libPath."/qbpwcf/allInOne.php\");";
-
 
3662
 
-
 
3663
#串接php程式
-
 
3664
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
3605
#函式說明:
3665
#函式說明:
3606
#解析RR檔案中其中的一行內容.
3666
#解析RR檔案中其中的一行內容.
3607
#回傳結果:
3667
#回傳結果:
3608
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3668
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3609
#$reuslt["error"],執行不正常結束的錯訊息陣列.
3669
#$reuslt["error"],執行不正常結束的錯訊息陣列.
3610
#$result["function"],當前執行的函式名稱.
3670
#$result["function"],當前執行的函式名稱.
3611
#$result["argu"],所使用的參數.
3671
#$result["argu"],所使用的參數.
3612
#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
3672
#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
3613
#$result["domain"],字串,RR所屬domain.
3673
#$result["domain"],字串,RR所屬domain.
3614
#$result["defaultTTL"],字串,預設的RR更新時間.
3674
#$result["defaultTTL"],字串,預設的RR更新時間.
3615
#$result["comment"],字串陣列,逐行的註解.
3675
#$result["comment"],字串,一行的註解.
3616
#必填參數:
3676
#必填參數:
3617
#$conf["line"],字串,要解析的行內容.
3677
#$conf["line"],字串,要解析的行內容.
-
 
3678
PHP;
-
 
3679
 
-
 
3680
#串接變數
-
 
3681
$phpCode2escaped=$phpCode2escaped.PHP_EOL."\$conf[\"line\"]=base64_decode(\"".base64_encode($line)."\");";
-
 
3682
 
3618
$conf["line"]=$line;
3683
#串接php程式
-
 
3684
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
3619
#可省略參數:
3685
#可省略參數:
3620
#無.
3686
#無.
3621
#參考資料:
3687
#參考資料:
3622
#無.
3688
#無.
3623
#備註:
3689
#備註:
Line 3642... Line 3708...
3642
 
3708
 
3643
	}#if end
3709
	}#if end
3644
	
3710
	
3645
#印出json
3711
#印出json
3646
echo json_encode($parseRRline);
3712
echo json_encode($parseRRline);
3647
 
-
 
3648
PHP;
3713
PHP;
3649
				
3714
				
-
 
3715
				#串接要執行的參數
-
 
3716
				$phpCode2run=$phpCode2run.escapeshellarg($phpCode2escaped);
-
 
3717
				
3650
				#函式說明:
3718
				#函式說明:
3651
				#透過proc來多執行序運作.
3719
				#透過proc來多執行序運作.
3652
				#回傳結果:
3720
				#回傳結果:
3653
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3721
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3654
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3722
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3655
				#$result["function"],當前執行的函式名稱.
3723
				#$result["function"],當前執行的函式名稱.
3656
				#$result["argu"],使用的參數.
3724
				#$result["argu"],使用的參數.
3657
				#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
3725
				#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
3658
				#必填參數:
3726
				#必填參數:
3659
				#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
3727
				#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
3660
				$conf["threads::proc"]["cmds"]=$phpCode2run;
3728
				$conf["threads::proc"]["cmds"]=array($phpCode2run);
3661
				#可省略參數:
3729
				#可省略參數:
3662
				#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
3730
				#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
3663
				$conf["threads::proc"]["wait"]="false";
3731
				$conf["threads::proc"]["wait"]="false";
3664
				#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
3732
				#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
3665
				#$conf["timeout"]=array("10");
3733
				#$conf["timeout"]=array("10");
3666
				#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
3734
				#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
3667
				$conf["threads::proc"]["workingDir"]=array(pathinfo(__FILE__)["driname"]);
3735
				#$conf["threads::proc"]["workingDir"]=array(pathinfo(__FILE__)["dirname"]);
3668
				#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
3736
				#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
3669
				#$conf["envs"]=array(array("key"=>"value"));
3737
				#$conf["envs"]=array(array("key"=>"value"));
3670
				#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
3738
				#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
3671
				#$conf["executeBy"]=array("bash");
3739
				#$conf["executeBy"]=array("bash");
3672
				#參考資料:
3740
				#參考資料:
Line 3677... Line 3745...
3677
				#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
3745
				#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
3678
				#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
3746
				#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
3679
				$proc=threads::proc($conf["threads::proc"]);
3747
				$proc=threads::proc($conf["threads::proc"]);
3680
				unset($conf["threads::proc"]);
3748
				unset($conf["threads::proc"]);
3681
			
3749
			
-
 
3750
				#debug
-
 
3751
				#var_dump($proc);exit;
-
 
3752
			
3682
				#如果檢查失敗
3753
				#如果檢查失敗
3683
				if($proc["status"]==="false"){
3754
				if($proc["status"]==="false"){
3684
 
3755
 
3685
					#設置錯誤識別
3756
					#設置錯誤識別
3686
					$result["status"]="false";
3757
					$result["status"]="false";
Line 3885... Line 3956...
3885
				
3956
				
3886
					#取得處理後的結果
3957
					#取得處理後的結果
3887
					$unFormatStr=$delHeadStr["content"];
3958
					$unFormatStr=$delHeadStr["content"];
3888
				
3959
				
3889
					}#if end
3960
					}#if end
3890
			
-
 
3891
				
3961
				
3892
			
-
 
3893
				#解析 $ORIGN 的數值, 以及後面是否有註解...
3962
				#解析 $ORIGN 的數值, 以及後面是否有註解...
3894
				#函式說明:
3963
				#函式說明:
3895
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3964
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3896
				#回傳結果:
3965
				#回傳結果:
3897
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3966
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 4038... Line 4107...
4038
				#無.
4107
				#無.
4039
				#備註:
4108
				#備註:
4040
				#無.
4109
				#無.
4041
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4110
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4042
				unset($conf["stringProcess::delHeadStr"]);
4111
				unset($conf["stringProcess::delHeadStr"]);
4043
					
4112
				
4044
				#如果執行異常
4113
				#如果執行異常
4045
				if($delHeadStr["status"]==="false"){
4114
				if($delHeadStr["status"]==="false"){
4046
				
4115
				
4047
					#設置錯誤識別
4116
					#設置錯誤識別
4048
					$result["status"]="false";
4117
					$result["status"]="false";
Line 5666... Line 5735...
5666
				}#while end
5735
				}#while end
5667
			
5736
			
5668
			}#foreach end
5737
			}#foreach end
5669
			
5738
			
5670
		#如果要啟用多執行序
5739
		#如果要啟用多執行序
5671
		if($conf["multiThread"]==="true"){
5740
		if($conf["multiThreads"]==="true"){
5672
		
-
 
5673
			#debug
-
 
5674
			var_dump($procs);
-
 
5675
		
5741
		
-
 
5742
			#如果要debug
-
 
5743
			if($conf["debug"]==="true"){
-
 
5744
			
-
 
5745
				#函式說明:
-
 
5746
				#撰寫log
5676
			#結束執行,回傳shell 1.
5747
				#回傳結果:
-
 
5748
				#$result["status"],狀態,"true"或"false".
-
 
5749
				#$result["error"],錯誤訊息陣列.
-
 
5750
				#$result["function"],當前函式的名稱.
-
 
5751
				#$result["argu"],使用的參數.
-
 
5752
				#$result["content"],要寫入log的內容字串.
-
 
5753
				#必填參數:
-
 
5754
				#$conf["path"],字串,log檔案的路徑與名稱.
-
 
5755
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
5756
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
5757
				$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR result through multi threads.".PHP_EOL;
-
 
5758
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
5759
				$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
5760
				#可省略參數:
-
 
5761
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
5762
				#$conf["rewrite"]="false";
-
 
5763
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
5764
				#$conf["returnOnly"]="true";
-
 
5765
				#參考資料:
-
 
5766
				#無.
-
 
5767
				#備註:
-
 
5768
				#無.
-
 
5769
				$record=logs::record($conf["logs::record"]);
-
 
5770
				unset($conf["logs::record"]);
-
 
5771
			
5677
			exit(1);
5772
				}#if end
5678
		
5773
		
-
 
5774
			#無窮迴圈
-
 
5775
			while(true){
-
 
5776
			
-
 
5777
				#等後1秒
-
 
5778
				sleep(1);
-
 
5779
				
-
 
5780
				#針對每行處理的狀況
-
 
5781
				foreach($procs as $procIndex => $proc){
-
 
5782
				
-
 
5783
					#如果要debug
-
 
5784
					if($conf["debug"]==="true"){
-
 
5785
					
-
 
5786
						#函式說明:
-
 
5787
						#撰寫log
-
 
5788
						#回傳結果:
-
 
5789
						#$result["status"],狀態,"true"或"false".
-
 
5790
						#$result["error"],錯誤訊息陣列.
-
 
5791
						#$result["function"],當前函式的名稱.
-
 
5792
						#$result["argu"],使用的參數.
-
 
5793
						#$result["content"],要寫入log的內容字串.
-
 
5794
						#必填參數:
-
 
5795
						#$conf["path"],字串,log檔案的路徑與名稱.
-
 
5796
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
5797
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
5798
						$conf["logs::record"]["content"]="lineNo:".__LINE__." Try get result of parsing RR line ".($procIndex+1)." through multi threads.".PHP_EOL;
-
 
5799
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
5800
						$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
5801
						#可省略參數:
-
 
5802
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
5803
						#$conf["rewrite"]="false";
-
 
5804
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
5805
						#$conf["returnOnly"]="true";
-
 
5806
						#參考資料:
-
 
5807
						#無.
-
 
5808
						#備註:
-
 
5809
						#無.
-
 
5810
						$record=logs::record($conf["logs::record"]);
-
 
5811
						unset($conf["logs::record"]);
-
 
5812
					
-
 
5813
						}#if end
-
 
5814
				
-
 
5815
					#函式說明:
-
 
5816
					#更新透過proc執行的多程序資訊.
-
 
5817
					#回傳結果:
-
 
5818
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5819
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
5820
					#$result["function"],當前執行的函式名稱.
-
 
5821
					#$result["argu"],使用的參數.
-
 
5822
					#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
-
 
5823
					#必填參數:
-
 
5824
					#$conf["procs"],陣列,運行self::proc後回傳的content.
-
 
5825
					$conf["threads::proc_update"]["procs"]=$proc["content"];
-
 
5826
					#可省略參數:
-
 
5827
					#無.
-
 
5828
					#參考資料:
-
 
5829
					#無.
-
 
5830
					#備註:
-
 
5831
					#無.
-
 
5832
					$proc_update=threads::proc_update($conf["threads::proc_update"]);
-
 
5833
					unset($conf["threads::proc_update"]);
-
 
5834
				
-
 
5835
					#debug
-
 
5836
					#var_dump($proc_update);exit;
-
 
5837
				
-
 
5838
					#如果執行異常
-
 
5839
					if($proc_update["status"]==="false"){
-
 
5840
				
-
 
5841
						#設置執行異常
-
 
5842
						$result["status"]="false";
-
 
5843
						
-
 
5844
						#設置執行錯誤
-
 
5845
						$result["error"]=$proc_update;
-
 
5846
						
-
 
5847
						#回傳結果
-
 
5848
						return $result;
-
 
5849
				
-
 
5850
						}#if end
-
 
5851
					
-
 
5852
					#另存結果
-
 
5853
					$procRes=$proc_update["content"][0];
-
 
5854
				
-
 
5855
					#如果程序執行異常
-
 
5856
					if($procRes["status"]==="false"){
-
 
5857
					
-
 
5858
						#設置執行異常
-
 
5859
						$result["status"]="false";
-
 
5860
						
-
 
5861
						#設置執行錯誤
-
 
5862
						$result["error"]=$procRes;
-
 
5863
						
-
 
5864
						#回傳結果
-
 
5865
						return $result;
-
 
5866
					
-
 
5867
						}#if end
-
 
5868
						
-
 
5869
					#如果程序尚在執行
-
 
5870
					if($procRes["statusCode"]==="?"){
-
 
5871
					
-
 
5872
						#換看下一列的執行狀況
-
 
5873
						continue;
-
 
5874
					
-
 
5875
						}#if end
-
 
5876
					
-
 
5877
					#如果輸出內容不是 json
-
 
5878
					if(!(json_validate($procRes["content"]))){
-
 
5879
					
-
 
5880
						#設置執行異常
-
 
5881
						$result["status"]="false";
-
 
5882
						
-
 
5883
						#設置執行錯誤
-
 
5884
						$result["error"]=$procRes;
-
 
5885
						
-
 
5886
						#回傳結果
-
 
5887
						return $result;
-
 
5888
					
-
 
5889
						}#if end
-
 
5890
						
-
 
5891
					#解析json
-
 
5892
					$jsonRes=json_decode($procRes["content"]);
-
 
5893
				
-
 
5894
					#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","query","update",也可能為空陣列.
-
 
5895
					#$result["domain"],字串,RR所屬domain.
-
 
5896
					#$result["defaultTTL"],字串,預設的RR更新時間.
-
 
5897
					#$result["comment"],字串,一行的註解.
-
 
5898
				
-
 
5899
					#如果有 content->type 存在
-
 
5900
					if(isset($jsonRes->content->type)){
-
 
5901
					
-
 
5902
						#儲存value
-
 
5903
						$info["type"]=$jsonRes->content->type;
-
 
5904
					
-
 
5905
						}#if end
-
 
5906
				
-
 
5907
					#如果有 content->value 存在
-
 
5908
					if(isset($jsonRes->content->value)){
-
 
5909
					
-
 
5910
						#儲存value
-
 
5911
						$info["value"]=$jsonRes->content->value;
-
 
5912
					
-
 
5913
						}#if end
-
 
5914
						
-
 
5915
					#如果有 content->query 存在
-
 
5916
					if(isset($jsonRes->content->query)){
-
 
5917
					
-
 
5918
						#儲存query
-
 
5919
						$info["query"]=$jsonRes->content->query;
-
 
5920
					
-
 
5921
						}#if end
-
 
5922
						
-
 
5923
					#如果有 content->update 存在
-
 
5924
					if(isset($jsonRes->content->update)){
-
 
5925
					
-
 
5926
						#儲存query
-
 
5927
						$info["update"]=$jsonRes->content->update;
-
 
5928
					
-
 
5929
						}#if end
-
 
5930
						
-
 
5931
					#如果有 domain 存在
-
 
5932
					if(isset($jsonRes->domain)){
-
 
5933
					
-
 
5934
						#儲存domain
-
 
5935
						$result["domain"]=$jsonRes->domain;
-
 
5936
					
-
 
5937
						}#if end
-
 
5938
						
-
 
5939
					#如果有 defaultTTL 存在
-
 
5940
					if(isset($jsonRes->defaultTTL)){
-
 
5941
					
-
 
5942
						#儲存domain
-
 
5943
						$result["domain"]=$jsonRes->defaultTTL;
-
 
5944
					
-
 
5945
						}#if end
-
 
5946
						
-
 
5947
					#如果有 comment 存在
-
 
5948
					if(isset($jsonRes->comment)){
-
 
5949
					
-
 
5950
						#儲存comment,用$procIndex作為先後順率的識別
-
 
5951
						$result["comment"][$procIndex]=$jsonRes->comment;
-
 
5952
					
-
 
5953
						}#if end
-
 
5954
					
-
 
5955
					#儲存 RR 的記錄
-
 
5956
					$result["content"][$procIndex]=$info;
-
 
5957
					
-
 
5958
					#移除解析好的行號
-
 
5959
					unset($procs[$procIndex]);
-
 
5960
					
-
 
5961
					#如果要debug
-
 
5962
					if($conf["debug"]==="true"){
-
 
5963
					
-
 
5964
						#函式說明:
-
 
5965
						#撰寫log
-
 
5966
						#回傳結果:
-
 
5967
						#$result["status"],狀態,"true"或"false".
-
 
5968
						#$result["error"],錯誤訊息陣列.
-
 
5969
						#$result["function"],當前函式的名稱.
-
 
5970
						#$result["argu"],使用的參數.
-
 
5971
						#$result["content"],要寫入log的內容字串.
-
 
5972
						#必填參數:
-
 
5973
						#$conf["path"],字串,log檔案的路徑與名稱.
-
 
5974
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
5975
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
5976
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR line ".($procIndex+1)." through multi threads fin.".PHP_EOL;
-
 
5977
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
5978
						$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
5979
						#可省略參數:
-
 
5980
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
5981
						#$conf["rewrite"]="false";
-
 
5982
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
5983
						#$conf["returnOnly"]="true";
-
 
5984
						#參考資料:
-
 
5985
						#無.
-
 
5986
						#備註:
-
 
5987
						#無.
-
 
5988
						$record=logs::record($conf["logs::record"]);
-
 
5989
						unset($conf["logs::record"]);
-
 
5990
					
-
 
5991
						}#if end
-
 
5992
				
-
 
5993
					}#foreach end
-
 
5994
					
-
 
5995
				#如果每行都已經解析好了
-
 
5996
				if(count($procs)===0){
-
 
5997
				
-
 
5998
					#如果要debug
-
 
5999
					if($conf["debug"]==="true"){
-
 
6000
					
-
 
6001
						#函式說明:
-
 
6002
						#撰寫log
-
 
6003
						#回傳結果:
-
 
6004
						#$result["status"],狀態,"true"或"false".
-
 
6005
						#$result["error"],錯誤訊息陣列.
-
 
6006
						#$result["function"],當前函式的名稱.
-
 
6007
						#$result["argu"],使用的參數.
-
 
6008
						#$result["content"],要寫入log的內容字串.
-
 
6009
						#必填參數:
-
 
6010
						#$conf["path"],字串,log檔案的路徑與名稱.
-
 
6011
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
6012
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
6013
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR through multi threads fin.".PHP_EOL;
-
 
6014
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
6015
						$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
6016
						#可省略參數:
-
 
6017
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
6018
						#$conf["rewrite"]="false";
-
 
6019
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
6020
						#$conf["returnOnly"]="true";
-
 
6021
						#參考資料:
-
 
6022
						#無.
-
 
6023
						#備註:
-
 
6024
						#無.
-
 
6025
						$record=logs::record($conf["logs::record"]);
-
 
6026
						unset($conf["logs::record"]);
-
 
6027
					
-
 
6028
						}#if end
-
 
6029
				
-
 
6030
					#跳出 while
-
 
6031
					break;
-
 
6032
				
-
 
6033
					}#if end
-
 
6034
			
-
 
6035
				}#while end
-
 
6036
			
5679
			}#if end
6037
			}#if end
5680
		
6038
		
5681
		#如果要debug
6039
		#如果要debug
5682
		if($conf["debug"]==="true"){
6040
		if($conf["debug"]==="true"){
5683
		
6041
		
Line 6856... Line 7214...
6856
		$result["content"]=$curlCmd["fullContent"];
7214
		$result["content"]=$curlCmd["fullContent"];
6857
 
7215
 
6858
		#解析json
7216
		#解析json
6859
		$jsonRes=json_decode($result["content"]);
7217
		$jsonRes=json_decode($result["content"]);
6860
		
7218
		
-
 
7219
		#如果有 success 資訊
-
 
7220
		if(isset($jsonRes->success)){
-
 
7221
		
-
 
7222
			#do nothing
-
 
7223
		
-
 
7224
			}#if end
-
 
7225
		
6861
		#如果沒有 status
7226
		#反之如果沒有 status
6862
		if(!isset($jsonRes->status)){
7227
		else if(!isset($jsonRes->status)){
6863
		
7228
		
6864
			#設置錯誤識別
7229
			#設置錯誤識別
6865
			$result["status"]="false";
7230
			$result["status"]="false";
6866
 
7231
 
6867
			#設置錯誤訊息
7232
			#設置錯誤訊息
Line 6870... Line 7235...
6870
			#回傳結果
7235
			#回傳結果
6871
			return $result;
7236
			return $result;
6872
		
7237
		
6873
			}#if end
7238
			}#if end
6874
		
7239
		
6875
		#如果是 "pending_validation"
7240
		#反之有 status 資訊
6876
		if($jsonRes->status==="pending_validation"){
-
 
6877
		
7241
		else{
6878
			#do nothing
-
 
6879
		
7242
		
6880
			}#if end
7243
			#如果是 "pending_validation"
-
 
7244
			if($jsonRes->status==="pending_validation"){
6881
			
7245
			
6882
		#反之如果為 "issued"
-
 
6883
		else if($jsonRes->status==="issued"){
-
 
6884
		
-
 
6885
			#do nothing
7246
				#do nothing
6886
		
-
 
6887
			}#else 
-
 
6888
			
7247
			
-
 
7248
				}#if end
-
 
7249
				
-
 
7250
			#反之如果為 "issued"
-
 
7251
			else if($jsonRes->status==="issued"){
-
 
7252
			
-
 
7253
				#do nothing
-
 
7254
			
-
 
7255
				}#else 
-
 
7256
				
6889
		#反之
7257
			#反之
6890
		else{
7258
			else{
6891
		
7259
			
6892
			#設置錯誤識別
7260
				#設置錯誤識別
6893
			$result["status"]="false";
7261
				$result["status"]="false";
6894
 
7262
 
6895
			#設置錯誤訊息
7263
				#設置錯誤訊息
6896
			$result["error"]=$curlCmd;
7264
				$result["error"]=$curlCmd;
6897
 
7265
 
6898
			#回傳結果
7266
				#回傳結果
6899
			return $result;
7267
				return $result;
-
 
7268
			
-
 
7269
				}#else end
6900
		
7270
		
6901
			}#else end
7271
			}#else end
6902
			
-
 
6903
		
7272
		
6904
		#設置執行正常
7273
		#設置執行正常
6905
		$result["status"]="true";
7274
		$result["status"]="true";
6906
	
7275
	
6907
		#回傳結果
7276
		#回傳結果
Line 8435... Line 8804...
8435
	#$conf["debug"]="";
8804
	#$conf["debug"]="";
8436
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8805
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8437
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8806
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8438
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8807
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8439
	#$conf["key"]=self::getApiInfo()["apiKey"];
8808
	#$conf["key"]=self::getApiInfo()["apiKey"];
-
 
8809
	#$conf["multiThreads"],字串,預設為"false"代表不使用多執行序;"true"代表要用多執行序.
-
 
8810
	#$conf["multiThreads"]=""
8440
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
8811
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
8441
	#$conf["debug"]="";
8812
	#$conf["debug"]="";
8442
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
8813
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
8443
	#$conf["addOnProcessFunc"]=array();
8814
	#$conf["addOnProcessFunc"]=array();
8444
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
8815
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
Line 8509... Line 8880...
8509
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8880
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8510
		#可以省略的參數:
8881
		#可以省略的參數:
8511
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8882
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8512
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8883
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8513
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
8884
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
8514
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock","debug","apiDomain","key");
8885
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("multiThreads","sock","debug","apiDomain","key");
8515
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8886
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8516
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
8887
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("multiThreads","sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
8517
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8888
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8518
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","array","array");
8889
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array","array");
8519
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8890
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8520
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($defaultSocket,"false",self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
8891
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",$defaultSocket,"false",self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
8521
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8892
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8522
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
8893
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
8523
		#參考資料來源:
8894
		#參考資料來源:
8524
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8895
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8525
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8896
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
Line 8560... Line 8931...
8560
		$share["apiDomain"]=$conf["apiDomain"];
8931
		$share["apiDomain"]=$conf["apiDomain"];
8561
		
8932
		
8562
		#設置debug flag
8933
		#設置debug flag
8563
		$share["debug"]=$conf["debug"];
8934
		$share["debug"]=$conf["debug"];
8564
		
8935
		
-
 
8936
		#設置 multiThreads 
-
 
8937
		$share["multiThreads"]=$conf["multiThreads"];
-
 
8938
		
8565
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
8939
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
8566
		$share["certInfo"]=array();
8940
		$share["certInfo"]=array();
8567
		
8941
		
8568
		#針對每個 domain
8942
		#針對每個 domain
8569
		foreach($conf["cName"] as $index=>$cName ){
8943
		foreach($conf["cName"] as $index=>$cName ){
Line 8948... Line 9322...
8948
			#設置 debug flag
9322
			#設置 debug flag
8949
			$debug=true;
9323
			$debug=true;
8950
		
9324
		
8951
			}#if end
9325
			}#if end
8952
		
9326
		
-
 
9327
		#如果有啟用 multiThreads
-
 
9328
		if($conf["info"]["share"]["multiThreads"]==="true"){
-
 
9329
		
-
 
9330
			#設置 multiThreads flag
-
 
9331
			$multiThreads=true;
-
 
9332
		
-
 
9333
			}#if end
-
 
9334
		
8953
		#另存 server cache 的參考
9335
		#另存 server cache 的參考
8954
		$serverCache=&$conf["serverCache"];
9336
		$serverCache=&$conf["serverCache"];
8955
		
9337
		
8956
		#針對每個 domain name
9338
		#針對每個 domain name
8957
		foreach($conf["info"]["share"]["certInfo"] as $certInfoIndex=>$cInfo){
9339
		foreach($conf["info"]["share"]["certInfo"] as $certInfoIndex=>$cInfo){
Line 9274... Line 9656...
9274
				#必填參數:
9656
				#必填參數:
9275
				#$conf["domain"],字串,csr內容的網域名稱.
9657
				#$conf["domain"],字串,csr內容的網域名稱.
9276
				$conf["zerossl::createCSR"]["domain"]=$cName;
9658
				$conf["zerossl::createCSR"]["domain"]=$cName;
9277
				#可省略參數:
9659
				#可省略參數:
9278
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
9660
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
9279
				#$conf["pKey"]="";
9661
				$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
9280
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
9662
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
9281
				#$conf["country"]="";
9663
				#$conf["country"]="";
9282
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
9664
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
9283
				#$conf["state"]="";
9665
				#$conf["state"]="";
9284
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
9666
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
Line 9415... Line 9797...
9415
				#可省略參數:
9797
				#可省略參數:
9416
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
9798
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
9417
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
9799
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
9418
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
9800
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
9419
				#$conf["debug"]="false";
9801
				#$conf["debug"]="false";
-
 
9802
				
-
 
9803
				#如果有啟用多執行序
-
 
9804
				if($conf["info"]["share"]["multiThreads"]==="true"){
-
 
9805
				
-
 
9806
					#設置要多執行序
-
 
9807
					$conf["zerossl::updateDnsRecordFile"]["multiThreads"]="true";
-
 
9808
				
-
 
9809
					}#if end
-
 
9810
				
9420
				#參考資料:
9811
				#參考資料:
9421
				#無.
9812
				#無.
9422
				#備註:
9813
				#備註:
9423
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
9814
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
9424
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
9815
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
Line 9577... Line 9968...
9577
						return $result;
9968
						return $result;
9578
					
9969
					
9579
						}#if end
9970
						}#if end
9580
						
9971
						
9581
					#如果沒有回內容
9972
					#如果沒有回內容
9582
					if(!isset($verifyDomain["content"][0])){
9973
					if(!isset($verifyDomain["content"])){
9583
					
9974
					
9584
						#設置錯誤識別
9975
						#設置錯誤識別
9585
						$result["status"]="false";
9976
						$result["status"]="false";
9586
 
9977
 
9587
						#設置錯誤訊息
9978
						#設置錯誤訊息
Line 9591... Line 9982...
9591
						return $result;
9982
						return $result;
9592
					
9983
					
9593
						}#if end
9984
						}#if end
9594
					
9985
					
9595
					#如果回應不是 json
9986
					#如果回應不是 json
9596
					if(!(json_validate($verifyDomain["content"][0]))){
9987
					if(!(json_validate($verifyDomain["content"]))){
9597
					
9988
					
9598
						#設置錯誤識別
9989
						#設置錯誤識別
9599
						$result["status"]="false";
9990
						$result["status"]="false";
9600
 
9991
 
9601
						#設置錯誤訊息
9992
						#設置錯誤訊息
Line 9610... Line 10001...
9610
					範例json:
10001
					範例json:
9611
					{"id":"51cff04454e6a6860abfecc8072db602","type":"1","common_name":"silverblue-guest.qbpwcf.org","additional_domains":"","created":"2026-03-06 13:45:39","expires":"2026-06-04 23:59:59","status":"pending_validation","validation_type":"CNAME_CSR_HASH","validation_emails":"","replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"silverblue-guest.qbpwcf.org":["admin@silverblue-guest.qbpwcf.org","administrator@silverblue-guest.qbpwcf.org","hostmaster@silverblue-guest.qbpwcf.org","postmaster@silverblue-guest.qbpwcf.org","webmaster@silverblue-guest.qbpwcf.org","admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"silverblue-guest.qbpwcf.org":{"file_validation_url_http":"http:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_url_https":"https:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_content":["58B9EB7890F754D041698170B22D22205D710ED09B419A809E5C92C38195DD36","comodoca.com","627e45f007045f0"],"cname_validation_p1":"_383346FA54F492EC8B2A6C421A052827.silverblue-guest.qbpwcf.org","cname_validation_p2":"58B9EB7890F754D041698170B22D2220.5D710ED09B419A809E5C92C38195DD36.627e45f007045f0.comodoca.com"}}},"signature_algorithm_properties":null}
10002
					{"id":"51cff04454e6a6860abfecc8072db602","type":"1","common_name":"silverblue-guest.qbpwcf.org","additional_domains":"","created":"2026-03-06 13:45:39","expires":"2026-06-04 23:59:59","status":"pending_validation","validation_type":"CNAME_CSR_HASH","validation_emails":"","replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"silverblue-guest.qbpwcf.org":["admin@silverblue-guest.qbpwcf.org","administrator@silverblue-guest.qbpwcf.org","hostmaster@silverblue-guest.qbpwcf.org","postmaster@silverblue-guest.qbpwcf.org","webmaster@silverblue-guest.qbpwcf.org","admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"silverblue-guest.qbpwcf.org":{"file_validation_url_http":"http:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_url_https":"https:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_content":["58B9EB7890F754D041698170B22D22205D710ED09B419A809E5C92C38195DD36","comodoca.com","627e45f007045f0"],"cname_validation_p1":"_383346FA54F492EC8B2A6C421A052827.silverblue-guest.qbpwcf.org","cname_validation_p2":"58B9EB7890F754D041698170B22D2220.5D710ED09B419A809E5C92C38195DD36.627e45f007045f0.comodoca.com"}}},"signature_algorithm_properties":null}
9612
					*/
10003
					*/
9613
					
10004
					
9614
					#解析json回應
10005
					#解析json回應
9615
					$verifyDomainRes=json_decode($verifyDomain["content"][0]);
10006
					$verifyDomainRes=json_decode($verifyDomain["content"]);
9616
 
10007
 
9617
					#如果是 zerossl 驗證失敗
10008
					#如果回應含有 success
9618
					if($verifyDomainRes->status==="false"){
10009
					if(isset($verifyDomainRes->success)){
9619
					
10010
					
9620
						#如果是 CNAME 記錄找不到
10011
						#如果是 zerossl 驗證失敗
9621
						if($verifyDomainRes->error->code===0){
10012
						if($verifyDomainRes->success==="false"){
9622
						
10013
						
9623
							#取得錯誤訊息
10014
							#如果是 CNAME 記錄找不到
9624
							#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
10015
							if($verifyDomainRes->error->code===0){
9625
							
-
 
9626
							#if enable debug
-
 
9627
							if($debug){
-
 
9628
							
-
 
9629
								#debug msg
-
 
9630
								echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
-
 
9631
							
10016
							
-
 
10017
								#取得錯誤訊息
-
 
10018
								#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
-
 
10019
								
-
 
10020
								#if enable debug
-
 
10021
								if($debug){
-
 
10022
								
-
 
10023
									#debug msg
-
 
10024
									echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
-
 
10025
								
9632
								}#if end
10026
									}#if end
9633
							
10027
								
9634
							#if enable debug
10028
								#if enable debug
9635
							if($debug){
10029
								if($debug){
9636
							
10030
								
9637
								#debug msg
10031
									#debug msg
9638
								echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
10032
									echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
-
 
10033
								
-
 
10034
									}#if end
-
 
10035
								
-
 
10036
								#休息60秒
-
 
10037
								sleep(60);
9639
							
10038
							
9640
								}#if end
10039
								}#if end
-
 
10040
								
-
 
10041
							#反之為不接受的錯誤訊息
-
 
10042
							else{
9641
							
10043
							
9642
							#休息60秒
-
 
9643
							sleep(60);
-
 
9644
						
-
 
9645
							}#if end
-
 
9646
							
-
 
9647
						#反之為不接受的錯誤訊息
-
 
9648
						else{
-
 
9649
						
-
 
9650
							#設置錯誤識別
10044
								#設置錯誤識別
9651
							$result["status"]="false";
10045
								$result["status"]="false";
9652
 
10046
 
9653
							#設置錯誤訊息
10047
								#設置錯誤訊息
9654
							$result["error"]=$verifyDomain;
10048
								$result["error"]=$verifyDomain;
9655
 
10049
 
9656
							#回傳結果
10050
								#回傳結果
9657
							return $result;
10051
								return $result;
-
 
10052
							
-
 
10053
								}#else end
9658
						
10054
						
9659
							}#else end
10055
							}#if end
9660
					
10056
					
9661
						}#if end
10057
						}#if end
-
 
10058
 
-
 
10059
					#反之如果回應含有 status
-
 
10060
					else if(isset($verifyDomainRes->status)){
9662
					
10061
					
9663
					#如果是 zerossl 尚在驗證中
10062
						#如果是 zerossl 尚在驗證中
9664
					else if($verifyDomainRes->status==="pending_validation"){
10063
						if($verifyDomainRes->status==="pending_validation"){
9665
					
-
 
9666
						#if enable debug
-
 
9667
						if($debug){
-
 
9668
						
10064
						
9669
							#debug msg
-
 
9670
							echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
-
 
9671
						
-
 
9672
							}#if end
10065
							#if enable debug
9673
							
-
 
9674
						#無窮迴圈
-
 
9675
						while(true){
-
 
9676
					
-
 
9677
							#查詢驗證狀況
-
 
9678
							#函式說明:
-
 
9679
							#取得CSR在zerossl上的狀態
-
 
9680
							#回傳結果:
-
 
9681
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
9682
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
9683
							#$result["function"],當前執行的函式名稱.
-
 
9684
							#$result["argu"],所使用的參數.
-
 
9685
							#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
9686
							#$result["content"],結果json字串.
-
 
9687
							#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
10066
							if($debug){
9688
							#必填參數:
-
 
9689
							#$conf["id"],字串,zerossl::createCertificate回傳的id.
-
 
9690
							$conf["zerossl::getCertSta"]["id"]=$csrId;
-
 
9691
							#可省略參數:
-
 
9692
							#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
9693
							$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
-
 
9694
							#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
9695
							$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
-
 
9696
							#參考資料:
-
 
9697
							#https://zerossl.com/documentation/api/get-certificate/
-
 
9698
							#備註:
-
 
9699
							#無.
-
 
9700
							$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
-
 
9701
							unset($conf["zerossl::getCertSta"]);
-
 
9702
							
-
 
9703
							#如果執行異常
-
 
9704
							if($getCertSta["status"]==="false"){
-
 
9705
							
10067
							
9706
								#設置錯誤識別
-
 
9707
								$result["status"]="false";
-
 
9708
 
-
 
9709
								#設置錯誤訊息
-
 
9710
								$result["error"]=$getCertSta;
-
 
9711
 
-
 
9712
								#回傳結果
10068
								#debug msg
9713
								return $result;
10069
								echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9714
							
10070
							
9715
								}#if end
10071
								}#if end
9716
								
10072
								
-
 
10073
							#無窮迴圈
-
 
10074
							while(true){
-
 
10075
						
-
 
10076
								#查詢驗證狀況
-
 
10077
								#函式說明:
-
 
10078
								#取得CSR在zerossl上的狀態
-
 
10079
								#回傳結果:
-
 
10080
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
10081
								#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
10082
								#$result["function"],當前執行的函式名稱.
-
 
10083
								#$result["argu"],所使用的參數.
-
 
10084
								#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
10085
								#$result["content"],結果json字串.
9717
							#如果沒有回應內容
10086
								#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
-
 
10087
								#必填參數:
-
 
10088
								#$conf["id"],字串,zerossl::createCertificate回傳的id.
-
 
10089
								$conf["zerossl::getCertSta"]["id"]=$csrId;
-
 
10090
								#可省略參數:
-
 
10091
								#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
10092
								$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
-
 
10093
								#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
10094
								$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
-
 
10095
								#參考資料:
-
 
10096
								#https://zerossl.com/documentation/api/get-certificate/
-
 
10097
								#備註:
-
 
10098
								#無.
-
 
10099
								$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
-
 
10100
								unset($conf["zerossl::getCertSta"]);
-
 
10101
								
-
 
10102
								#如果執行異常
9718
							if(!isset($getCertSta["content"][0])){
10103
								if($getCertSta["status"]==="false"){
9719
							
10104
								
9720
								#設置錯誤識別
10105
									#設置錯誤識別
9721
								$result["status"]="false";
10106
									$result["status"]="false";
9722
 
10107
 
9723
								#設置錯誤訊息
10108
									#設置錯誤訊息
9724
								$result["error"]=$getCertSta;
10109
									$result["error"]=$getCertSta;
9725
 
10110
 
9726
								#回傳結果
10111
									#回傳結果
9727
								return $result;
10112
									return $result;
9728
							
-
 
9729
								}#if end
-
 
9730
								
10113
								
-
 
10114
									}#if end
-
 
10115
									
9731
							#如果回應不是 json
10116
								#如果沒有回應內容
9732
							if(!(json_validate($getCertSta["content"][0]))){
10117
								if(!isset($getCertSta["content"])){
9733
							
10118
								
9734
								#設置錯誤識別
10119
									#設置錯誤識別
9735
								$result["status"]="false";
10120
									$result["status"]="false";
9736
 
10121
 
9737
								#設置錯誤訊息
10122
									#設置錯誤訊息
9738
								$result["error"]=$getCertSta;
10123
									$result["error"]=$getCertSta;
9739
 
10124
 
9740
								#回傳結果
10125
									#回傳結果
9741
								return $result;
10126
									return $result;
9742
							
-
 
9743
								}#if end
-
 
9744
								
10127
								
9745
							#解析json回應
10128
									}#if end
9746
							$getCertStaRes=json_decode($getCertSta["content"][0]);
-
 
9747
							
10129
									
9748
							#如果憑證已經驗證通過了
10130
								#如果回應不是 json
9749
							if($getCertStaRes->status==="issued"){
10131
								if(!(json_validate($getCertSta["content"]))){
9750
							
-
 
9751
								#if enable debug
-
 
9752
								if($debug){
-
 
9753
								
10132
								
-
 
10133
									#設置錯誤識別
-
 
10134
									$result["status"]="false";
-
 
10135
 
-
 
10136
									#設置錯誤訊息
-
 
10137
									$result["error"]=$getCertSta;
-
 
10138
 
9754
									#debug msg
10139
									#回傳結果
9755
									echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
10140
									return $result;
9756
								
10141
								
9757
									}#if end
10142
									}#if end
9758
							
10143
									
9759
								#結束等待
10144
								#解析json回應
9760
								break 2;
10145
								$getCertStaRes=json_decode($getCertSta["content"]);
9761
							
-
 
9762
								}#if end
-
 
9763
								
10146
								
9764
							#如果 zerossl 尚在處理中
10147
								#如果憑證已經驗證通過了
9765
							else if($getCertStaRes->status==="pending_validation"){
10148
								if($getCertStaRes->status==="issued"){
9766
							
-
 
9767
								#if enable debug
-
 
9768
								if($debug){
-
 
9769
								
10149
								
-
 
10150
									#if enable debug
-
 
10151
									if($debug){
-
 
10152
									
9770
									#debug msg
10153
										#debug msg
9771
									echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
10154
										echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
-
 
10155
									
-
 
10156
										}#if end
-
 
10157
								
-
 
10158
									#結束等待
-
 
10159
									break 2;
9772
								
10160
								
9773
									}#if end
10161
									}#if end
9774
									
10162
									
9775
								#休息1分鐘
10163
								#如果 zerossl 尚在處理中
9776
								sleep(60);
10164
								else if($getCertStaRes->status==="pending_validation"){
9777
							
-
 
9778
								}#if end
-
 
9779
							
-
 
9780
							#反之
-
 
9781
							else{
-
 
9782
							
-
 
9783
								#例外狀況
-
 
9784
								
10165
								
-
 
10166
									#if enable debug
-
 
10167
									if($debug){
-
 
10168
									
-
 
10169
										#debug msg
-
 
10170
										echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
-
 
10171
									
-
 
10172
										}#if end
-
 
10173
										
-
 
10174
									#休息1分鐘
-
 
10175
									sleep(60);
-
 
10176
								
-
 
10177
									}#if end
-
 
10178
								
-
 
10179
								#反之
-
 
10180
								else{
-
 
10181
								
-
 
10182
									#例外狀況
-
 
10183
									
9785
								#設置錯誤識別
10184
									#設置錯誤識別
9786
								$result["status"]="false";
10185
									$result["status"]="false";
9787
 
10186
 
9788
								#設置錯誤訊息
10187
									#設置錯誤訊息
9789
								$result["error"]=$getCertSta;
10188
									$result["error"]=$getCertSta;
9790
 
10189
 
9791
								#回傳結果
10190
									#回傳結果
9792
								return $result;
10191
									return $result;
9793
							
10192
								
9794
								}#else end
10193
									}#else end
9795
 
10194
 
9796
							}#while end
10195
								}#while end
-
 
10196
						
-
 
10197
							}#if end
9797
					
10198
						
9798
						}#if end
10199
						}#if end
9799
				
10200
				
9800
					}#while end
10201
					}#while end
9801
 
10202
 
9802
				#if enable debug
10203
				#if enable debug
Line 9856... Line 10257...
9856
					#debug msg
10257
					#debug msg
9857
					echo "Creating certificate for domain name(".$cName.")".PHP_EOL;
10258
					echo "Creating certificate for domain name(".$cName.")".PHP_EOL;
9858
				
10259
				
9859
					}#if end
10260
					}#if end
9860
				
10261
				
9861
				#建立 certificate.crt 檔案
10262
				#certPath
9862
				#$cInfo["certPath"];
10263
				#$cInfo["ssl"]["certPath"];
9863
				
10264
				
9864
				#建立 ca_bundle.crt 檔案
10265
				#pKey
9865
				#$cInfo["caPath"];
10266
				#$cInfo["ssl"]["pKey"];
9866
				
10267
				
-
 
10268
				#caPath
-
 
10269
				#$cInfo["ssl"]["caPath"]=;
-
 
10270
				
9867
				#建立 certAndCa.crt 檔案
10271
				#certWithCaPath
9868
				#$cInfo["certWithCaPath"];
10272
				#$cInfo["ssl"]["certWithCaPath"];
9869
				
10273
				
9870
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
10274
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
9871
				#函式說明:
10275
				#函式說明:
9872
				#一次建立多個檔案,並寫入內容.
10276
				#一次建立多個檔案,並寫入內容.
9873
				#回傳結果:
10277
				#回傳結果:
Line 9881... Line 10285...
9881
				#$result["argu"],使用的參數.
10285
				#$result["argu"],使用的參數.
9882
				#必填參數:
10286
				#必填參數:
9883
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10287
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9884
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10288
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
9885
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
10289
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
9886
				$conf["zerossl::writeMultiFile"]["fileName"]=array($conf["info"]["share"]["certPath"],$conf["info"]["share"]["caPath"],$conf["info"]["share"]["certWithCaPath"]);
10290
				$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
9887
				#可省略參數:
10291
				#可省略參數:
9888
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10292
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
9889
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
10293
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
9890
				#參考資料:
10294
				#參考資料:
9891
				#無.
10295
				#無.
9892
				#備註:
10296
				#備註:
9893
				#無.
10297
				#無.
9894
				$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
10298
				$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
9895
				unset($conf["zerossl::writeMultiFile"]);
10299
				unset($conf["zerossl::writeMultiFile"]);
9896
				
10300
				
9897
				#如果執行異常
10301
				#如果執行異常
9898
				if($writeMultiFile["status"]==="false"){
10302
				if($writeMultiFile["status"]==="false"){
9899
				
10303
				
Line 10078... Line 10482...
10078
						echo ".".PHP_EOL;
10482
						echo ".".PHP_EOL;
10079
					
10483
					
10080
						}#if end
10484
						}#if end
10081
				
10485
				
10082
					#函式說明:
10486
					#函式說明:
-
 
10487
					#將字串進行解析,變成多個參數.
-
 
10488
					#回傳結果:
-
 
10489
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
-
 
10490
					#$result["function"],當前執行的函式內容.
-
 
10491
					#$result["error"],錯誤訊息陣列.
-
 
10492
					#$result["content"],參數陣列.
-
 
10493
					#$result["count"],總共有幾個參數.
-
 
10494
					#必填參數:
-
 
10495
					#$conf["input"],字串,要解析成參數的字串.
-
 
10496
					$conf["stringProcess::parse"]["input"]=$action;
-
 
10497
					#可省略參數:
-
 
10498
					#無.
-
 
10499
					#參考資料:
-
 
10500
					#無.
-
 
10501
					#備註:
-
 
10502
					#無.
-
 
10503
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
-
 
10504
					unset($conf["stringProcess::parse"]);
-
 
10505
					
-
 
10506
					#如果執行異常
-
 
10507
					if($parse["status"]==="false"){
-
 
10508
					
-
 
10509
						#設置錯誤識別
-
 
10510
						$result["status"]="false";
-
 
10511
 
-
 
10512
						#設置錯誤訊息
-
 
10513
						$result["error"]=$parse;
-
 
10514
 
-
 
10515
						#回傳結果
-
 
10516
						return $result;
-
 
10517
					
-
 
10518
						}#if end
-
 
10519
				
-
 
10520
					#函式說明:
10083
					#解析指令與參數,回傳指令與參數給 callShell 函式使用.
10521
					#解析指令與參數,回傳指令與參數給 callShell 函式使用.
10084
					#回傳結果:
10522
					#回傳結果:
10085
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10523
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10086
					#$result["error"],錯誤訊息陣列.
10524
					#$result["error"],錯誤訊息陣列.
10087
					#$result["function"],當前執行的函數名稱.
10525
					#$result["function"],當前執行的函數名稱.
10088
					#$result["argu"],使用的參數.
10526
					#$result["argu"],使用的參數.
10089
					#$result["cmd"],執行的指令名稱.
10527
					#$result["cmd"],執行的指令名稱.
10090
					#$result["params"],執行指令伴隨的參數.
10528
					#$result["params"],執行指令伴隨的參數.
10091
					#必填參數:
10529
					#必填參數:
10092
					#$conf["cmdArray"],字串陣列,要執行的指令字串.
10530
					#$conf["cmdArray"],字串陣列,要執行的指令字串.
10093
					$conf["external::callShellHelper"]["cmdArray"]=$action;
10531
					$conf["external::callShellHelper"]["cmdArray"]=$parse["content"];
10094
					#可省略參數:
10532
					#可省略參數:
10095
					#無.
10533
					#無.
10096
					#參考資料:
10534
					#參考資料:
10097
					#array_shift=>https://www.php.net/manual/en/function.array-shift.php
10535
					#array_shift=>https://www.php.net/manual/en/function.array-shift.php
10098
					#備註:
10536
					#備註:
Line 10489... Line 10927...
10489
					#必填參數:
10927
					#必填參數:
10490
					#$conf["domain"],字串,csr內容的網域名稱.
10928
					#$conf["domain"],字串,csr內容的網域名稱.
10491
					$conf["zerossl::createCSR"]["domain"]=$cName;
10929
					$conf["zerossl::createCSR"]["domain"]=$cName;
10492
					#可省略參數:
10930
					#可省略參數:
10493
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
10931
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
10494
					#$conf["pKey"]="";
10932
					$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
10495
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
10933
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
10496
					#$conf["country"]="";
10934
					#$conf["country"]="";
10497
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
10935
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
10498
					#$conf["state"]="";
10936
					#$conf["state"]="";
10499
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
10937
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
Line 11640... Line 12078...
11640
 
12078
 
11641
							#回傳結果
12079
							#回傳結果
11642
							return $result;
12080
							return $result;
11643
						
12081
						
11644
							}#if end
12082
							}#if end
-
 
12083
							
-
 
12084
						#設置需要執行指令來生效憑證
-
 
12085
						$requireActionAfterUpdateCert="true";
11645
					
12086
					
11646
						}#if end
12087
						}#if end
11647
						
12088
						
11648
					#如果 ca_bunle 需要更新
12089
					#如果 ca_bunle 需要更新
11649
					if($ca_bundle_need_update==="true"){
12090
					if($ca_bundle_need_update==="true"){
Line 11653... Line 12094...
11653
					
12094
					
11654
							#debug msg
12095
							#debug msg
11655
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
12096
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
11656
						
12097
						
11657
							}#if end
12098
							}#if end
-
 
12099
							
-
 
12100
						#設置需要執行指令來生效憑證
-
 
12101
						$requireActionAfterUpdateCert="true";
11658
					
12102
					
11659
						#更新之
12103
						#更新之
11660
						#函式說明:
12104
						#函式說明:
11661
						#一次建立多個檔案,並寫入內容.
12105
						#一次建立多個檔案,並寫入內容.
11662
						#回傳結果:
12106
						#回傳結果:
Line 11694... Line 12138...
11694
 
12138
 
11695
							#回傳結果
12139
							#回傳結果
11696
							return $result;
12140
							return $result;
11697
						
12141
						
11698
							}#if end
12142
							}#if end
-
 
12143
							
-
 
12144
						#設置需要執行指令來生效憑證
-
 
12145
						$requireActionAfterUpdateCert="true";
11699
					
12146
					
11700
						}#if end
12147
						}#if end
11701
						
12148
						
11702
					#如果 certificate and ca_bundle 需要更新
12149
					#如果 certificate and ca_bundle 需要更新
11703
					if($cert_and_ca_bundle_need_update==="true"){
12150
					if($cert_and_ca_bundle_need_update==="true"){
Line 11749... Line 12196...
11749
							#回傳結果
12196
							#回傳結果
11750
							return $result;
12197
							return $result;
11751
						
12198
						
11752
							}#if end
12199
							}#if end
11753
					
12200
					
-
 
12201
						#設置需要執行指令來生效憑證
-
 
12202
						$requireActionAfterUpdateCert="true";
-
 
12203
					
11754
						}#if end
12204
						}#if end
11755
						
12205
						
11756
					#如果有需要執行指令來生效憑證
12206
					#如果有需要執行指令來生效憑證
11757
					if($requireActionAfterUpdateCert==="true"){
12207
					if($requireActionAfterUpdateCert==="true"){
11758
					
12208
					
Line 11788... Line 12238...
11788
									echo ".".PHP_EOL;
12238
									echo ".".PHP_EOL;
11789
								
12239
								
11790
									}#if end
12240
									}#if end
11791
							
12241
							
11792
								#函式說明:
12242
								#函式說明:
-
 
12243
								#將字串進行解析,變成多個參數.
-
 
12244
								#回傳結果:
-
 
12245
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
-
 
12246
								#$result["function"],當前執行的函式內容.
-
 
12247
								#$result["error"],錯誤訊息陣列.
-
 
12248
								#$result["content"],參數陣列.
-
 
12249
								#$result["count"],總共有幾個參數.
-
 
12250
								#必填參數:
-
 
12251
								#$conf["input"],字串,要解析成參數的字串.
-
 
12252
								$conf["stringProcess::parse"]["input"]=$ac;
-
 
12253
								#可省略參數:
-
 
12254
								#無.
-
 
12255
								#參考資料:
-
 
12256
								#無.
-
 
12257
								#備註:
-
 
12258
								#無.
-
 
12259
								$parse=stringProcess::parse($conf["stringProcess::parse"]);
-
 
12260
								unset($conf["stringProcess::parse"]);
-
 
12261
								
-
 
12262
								#如果執行異常
-
 
12263
								if($parse["status"]==="false"){
-
 
12264
								
-
 
12265
									#設置錯誤識別
-
 
12266
									$result["status"]="false";
-
 
12267
 
-
 
12268
									#設置錯誤訊息
-
 
12269
									$result["error"]=$parse;
-
 
12270
 
-
 
12271
									#回傳結果
-
 
12272
									return $result;
-
 
12273
								
-
 
12274
									}#if end
-
 
12275
									
-
 
12276
								#debug
-
 
12277
								#var_dump(__LINE__,$parse);
-
 
12278
							
-
 
12279
								#函式說明:
11793
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
12280
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
11794
								#回傳結果:
12281
								#回傳結果:
11795
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12282
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11796
								#$result["error"],錯誤訊息陣列.
12283
								#$result["error"],錯誤訊息陣列.
11797
								#$result["function"],當前執行的函數名稱.
12284
								#$result["function"],當前執行的函數名稱.
11798
								#$result["argu"],使用的參數.
12285
								#$result["argu"],使用的參數.
11799
								#$result["cmd"],執行的指令名稱.
12286
								#$result["cmd"],執行的指令名稱.
11800
								#$result["params"],執行指令伴隨的參數.
12287
								#$result["params"],執行指令伴隨的參數.
11801
								#必填參數:
12288
								#必填參數:
11802
								#$conf["cmdArray"],字串陣列,要執行的指令字串.
12289
								#$conf["cmdArray"],字串陣列,要執行的指令字串.
11803
								$conf["external::callShellHelper"]["cmdArray"]=$ac;
12290
								$conf["external::callShellHelper"]["cmdArray"]=$parse["content"];
11804
								#可省略參數:
12291
								#可省略參數:
11805
								#無.
12292
								#無.
11806
								#參考資料:
12293
								#參考資料:
11807
								#array_shift=>https://www.php.net/manual/en/function.array-shift.php
12294
								#array_shift=>https://www.php.net/manual/en/function.array-shift.php
11808
								#備註:
12295
								#備註:
Line 11918... Line 12405...
11918
								echo "There is only one cmd to run to apply ssl for domain name(".$cName.")".PHP_EOL;
12405
								echo "There is only one cmd to run to apply ssl for domain name(".$cName.")".PHP_EOL;
11919
							
12406
							
11920
								}#if end
12407
								}#if end
11921
							
12408
							
11922
							#函式說明:
12409
							#函式說明:
-
 
12410
							#將字串進行解析,變成多個參數.
-
 
12411
							#回傳結果:
-
 
12412
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
-
 
12413
							#$result["function"],當前執行的函式內容.
-
 
12414
							#$result["error"],錯誤訊息陣列.
-
 
12415
							#$result["content"],參數陣列.
-
 
12416
							#$result["count"],總共有幾個參數.
-
 
12417
							#必填參數:
-
 
12418
							#$conf["input"],字串,要解析成參數的字串.
-
 
12419
							$conf["stringProcess::parse"]["input"]=$action;
-
 
12420
							#可省略參數:
-
 
12421
							#無.
-
 
12422
							#參考資料:
-
 
12423
							#無.
-
 
12424
							#備註:
-
 
12425
							#無.
-
 
12426
							$parse=stringProcess::parse($conf["stringProcess::parse"]);
-
 
12427
							unset($conf["stringProcess::parse"]);
-
 
12428
							
-
 
12429
							#如果執行異常
-
 
12430
							if($parse["status"]==="false"){
-
 
12431
							
-
 
12432
								#設置錯誤識別
-
 
12433
								$result["status"]="false";
-
 
12434
 
-
 
12435
								#設置錯誤訊息
-
 
12436
								$result["error"]=$parse;
-
 
12437
 
-
 
12438
								#回傳結果
-
 
12439
								return $result;
-
 
12440
							
-
 
12441
								}#if end
-
 
12442
								
-
 
12443
							#debug
-
 
12444
							#var_dump(__LINE__,$parse);
-
 
12445
							
-
 
12446
							#函式說明:
11923
							#解析指令與參數,回傳指令與參數給 callShell 函式使用.
12447
							#解析指令與參數,回傳指令與參數給 callShell 函式使用.
11924
							#回傳結果:
12448
							#回傳結果:
11925
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12449
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11926
							#$result["error"],錯誤訊息陣列.
12450
							#$result["error"],錯誤訊息陣列.
11927
							#$result["function"],當前執行的函數名稱.
12451
							#$result["function"],當前執行的函數名稱.
11928
							#$result["argu"],使用的參數.
12452
							#$result["argu"],使用的參數.
11929
							#$result["cmd"],執行的指令名稱.
12453
							#$result["cmd"],執行的指令名稱.
11930
							#$result["params"],執行指令伴隨的參數.
12454
							#$result["params"],執行指令伴隨的參數.
11931
							#必填參數:
12455
							#必填參數:
11932
							#$conf["cmdArray"],字串陣列,要執行的指令字串.
12456
							#$conf["cmdArray"],字串陣列,要執行的指令字串.
11933
							$conf["external::callShellHelper"]["cmdArray"]=$action;
12457
							$conf["external::callShellHelper"]["cmdArray"]=$parse["content"];
11934
							#可省略參數:
12458
							#可省略參數:
11935
							#無.
12459
							#無.
11936
							#參考資料:
12460
							#參考資料:
11937
							#array_shift=>https://www.php.net/manual/en/function.array-shift.php
12461
							#array_shift=>https://www.php.net/manual/en/function.array-shift.php
11938
							#備註:
12462
							#備註: