Subversion Repositories php-qbpwcf

Rev

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

Rev 253 Rev 255
Line 148... Line 148...
148
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
148
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
149
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
149
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
150
	#$result["function"],當前執行的函式名稱.
150
	#$result["function"],當前執行的函式名稱.
151
	#$result["argu"],所使用的參數.
151
	#$result["argu"],所使用的參數.
152
	#$result["curl_verbose_info"],curl執行的詳細資訊.
152
	#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
153
	#$result["content"],ssl用的private key.
153
	#必填參數:
154
	#必填參數:
154
	#$conf["fileArgu"],字串,變數__FILE__的內容.
155
	#$conf["fileArgu"],字串,變數__FILE__的內容.
155
	$conf["fileArgu"]=__FILE__;
156
	$conf["fileArgu"]=__FILE__;
156
	#可省略參數:
157
	#可省略參數:
157
	#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
158
	#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
Line 362... Line 363...
362
		#必填參數:
363
		#必填參數:
363
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
364
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
364
		$conf["arrays::arrayToString"]["inputArray"]=$callShell["output"];
365
		$conf["arrays::arrayToString"]["inputArray"]=$callShell["output"];
365
		#可省略參數:
366
		#可省略參數:
366
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
367
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
367
		$conf["arrays::arrayToString"]["spiltSymbol"]="";
368
		$conf["arrays::arrayToString"]["spiltSymbol"]=PHP_EOL;
368
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
369
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
369
		$conf["arrays::arrayToString"]["skipEnd"]="true";
370
		$conf["arrays::arrayToString"]["skipEnd"]="true";
370
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
371
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
371
		#$conf["spiltSymbolAtStart"]="";
372
		#$conf["spiltSymbolAtStart"]="";
372
		#參考資料:
373
		#參考資料:
Line 407... Line 408...
407
	#回傳結果:
408
	#回傳結果:
408
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
409
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
409
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
410
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
410
	#$result["function"],當前執行的函式名稱.
411
	#$result["function"],當前執行的函式名稱.
411
	#$result["argu"],所使用的參數.
412
	#$result["argu"],所使用的參數.
-
 
413
	#$result["content"],csr內容.
412
	#$result["curl_verbose_info"],curl執行的詳細資訊.
414
	#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
415
	#$result["privateKey"], private key 的內容.
413
	#必填參數:
416
	#必填參數:
414
	#$conf["domain"],字串,csr內容的網域名稱.
417
	#$conf["domain"],字串,csr內容的網域名稱.
415
	#$conf["domain"]="";
418
	#$conf["domain"]="";
416
	#可省略參數:
419
	#可省略參數:
-
 
420
	#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
-
 
421
	#$conf["pKey"]="";
417
	#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
422
	#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
418
	#$conf["country"]="";
423
	#$conf["country"]="";
419
	#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
424
	#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
420
	#$conf["state"]="";
425
	#$conf["state"]="";
421
	#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
426
	#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
Line 487... Line 492...
487
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
492
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
488
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
493
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
489
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
494
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
490
		#$conf["skipableVariableCanNotBeEmpty"]=array();
495
		#$conf["skipableVariableCanNotBeEmpty"]=array();
491
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
496
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
492
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("country","state","city","org","unit");
497
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pKey","country","state","city","org","unit");
493
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
498
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
494
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string");
499
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
495
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
500
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
496
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("TW","Taiwan","Taoyuan City","QBPWCF","RD");
501
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"TW","Taiwan","Taoyuan City","QBPWCF","RD");
497
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
502
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
498
		#$conf["arrayCountEqualCheck"][]=array();
503
		#$conf["arrayCountEqualCheck"][]=array();
499
		#參考資料來源:
504
		#參考資料來源:
500
		#array_keys=>http://php.net/manual/en/function.array-keys.php
505
		#array_keys=>http://php.net/manual/en/function.array-keys.php
501
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
506
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
Line 527... Line 532...
527
			#回傳結果
532
			#回傳結果
528
			return $result;
533
			return $result;
529
 
534
 
530
			}#if end
535
			}#if end
531
		
536
		
532
		#產生uuid名稱
-
 
533
		#函式說明:
-
 
534
		#使用 linux 的 uuid 指令來產生 uuid 字串
-
 
535
		#回傳結果:
537
		#如果沒有指定 pKey
536
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
537
		#$result["error"],錯誤訊息.
-
 
538
		#$result["function"],當前執行的函式名稱.
-
 
539
		#$result["content"],uuid.
538
		if(!isset($conf["pKey"])){
540
		#必填參數:
-
 
541
		#無.
-
 
542
		#可省略參數:
-
 
543
		#無.
-
 
544
		#參考資料:
-
 
545
		#無.
-
 
546
		#備註:
-
 
547
		#無.
-
 
548
		$uuid=cmd::uuid();
-
 
549
		
539
		
-
 
540
			#產生uuid名稱
-
 
541
			#函式說明:
-
 
542
			#使用 linux 的 uuid 指令來產生 uuid 字串
-
 
543
			#回傳結果:
-
 
544
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
545
			#$result["error"],錯誤訊息.
-
 
546
			#$result["function"],當前執行的函式名稱.
-
 
547
			#$result["content"],uuid.
-
 
548
			#必填參數:
-
 
549
			#無.
-
 
550
			#可省略參數:
-
 
551
			#無.
-
 
552
			#參考資料:
-
 
553
			#無.
-
 
554
			#備註:
-
 
555
			#無.
-
 
556
			$uuid=cmd::uuid();
-
 
557
			
550
		#如果執行異常
558
			#如果執行異常
551
		if($uuid["status"]==="false"){
559
			if($uuid["status"]==="false"){
552
 
560
 
553
			#設置錯誤識別
561
				#設置錯誤識別
554
			$result["status"]="false";
562
				$result["status"]="false";
555
 
563
 
556
			#設置錯誤訊息
564
				#設置錯誤訊息
557
			$result["error"]=$uuid;
565
				$result["error"]=$uuid;
558
 
566
 
559
			#回傳結果
567
				#回傳結果
560
			return $result;
568
				return $result;
561
 
569
 
562
			}#if end
570
				}#if end
563
		
571
			
564
		#取得暫存的檔案名稱
572
			#取得暫存的檔案名稱
565
		$TFN=$uuid["content"];
573
			$TFN=$uuid["content"];
566
		
574
			
567
		#函式說明:
575
			#函式說明:
568
		#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
576
			#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
569
		#回傳結果:
577
			#回傳結果:
570
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
578
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
571
		#$result["error"],錯誤訊息.
579
			#$result["error"],錯誤訊息.
572
		#$result["function"],當前執行的函數名稱.
580
			#$result["function"],當前執行的函數名稱.
573
		#$result["content"],暫存檔案的路徑與名稱.
581
			#$result["content"],暫存檔案的路徑與名稱.
574
		#$result["fileName"],暫存檔案的名稱.
582
			#$result["fileName"],暫存檔案的名稱.
575
		#$result["path"],暫存檔案的路徑.
583
			#$result["path"],暫存檔案的路徑.
576
		#必填參數:
584
			#必填參數:
577
		#無.
585
			#無.
578
		#可省略參數:
586
			#可省略參數:
579
		#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
587
			#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
580
		#$conf["contant"]=array();
588
			#$conf["contant"]=array();
581
		#參考資料:
589
			#參考資料:
582
		#無.
590
			#無.
583
		#備註:
591
			#備註:
584
		#無.
592
			#無.
585
		$conf["fileAccess::createTempFile"]=array();
593
			$conf["fileAccess::createTempFile"]=array();
586
		$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
594
			$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
587
		unset($conf["fileAccess::createTempFile"]);
595
			unset($conf["fileAccess::createTempFile"]);
588
		
596
			
589
		#如果執行異常
597
			#如果執行異常
590
		if($createTempFile["status"]==="false"){
598
			if($createTempFile["status"]==="false"){
591
 
599
 
592
			#設置錯誤識別
600
				#設置錯誤識別
593
			$result["status"]="false";
601
				$result["status"]="false";
594
 
602
 
595
			#設置錯誤訊息
603
				#設置錯誤訊息
596
			$result["error"]=$createTempFile;
604
				$result["error"]=$createTempFile;
597
 
605
 
598
			#回傳結果
606
				#回傳結果
599
			return $result;
607
				return $result;
600
 
608
 
601
			}#if end
609
				}#if end
602
		
610
			
603
		#暫存的檔案路徑與名稱
611
			#暫存的檔案路徑與名稱
604
		$TFN=$createTempFile["content"];
612
			$TFN=$createTempFile["content"];
605
		
613
			
606
		#產生 privae key
614
			#產生 privae key
607
		#openssl genrsa -out output.key 4096 
615
			#openssl genrsa -out output.key 4096 
608
		
616
			
609
		#函式說明:
617
			#函式說明:
610
		#呼叫shell執行系統命令,並取得回傳的內容.
618
			#呼叫shell執行系統命令,並取得回傳的內容.
611
		#回傳結果:
619
			#回傳結果:
612
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
620
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
613
		#$result["error"],錯誤訊息陣列.
621
			#$result["error"],錯誤訊息陣列.
614
		#$result["function"],當前執行的函數名稱.
622
			#$result["function"],當前執行的函數名稱.
615
		#$result["argu"],使用的參數.
623
			#$result["argu"],使用的參數.
616
		#$result["cmd"],執行的指令內容.
624
			#$result["cmd"],執行的指令內容.
617
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
625
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
618
		#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
626
			#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
619
		#$result["content"],為執行完後的輸出字串.
627
			#$result["content"],為執行完後的輸出字串.
620
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
628
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
621
		#$result["running"],是否還在執行.
629
			#$result["running"],是否還在執行.
622
		#$result["pid"],pid.
630
			#$result["pid"],pid.
623
		#$result["statusCode"],執行結束後的代碼.
631
			#$result["statusCode"],執行結束後的代碼.
624
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
632
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
625
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
633
			#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
626
		#必填參數:
634
			#必填參數:
627
		#$conf["command"],字串,要執行的指令.
635
			#$conf["command"],字串,要執行的指令.
628
		$conf["external::callShell"]["command"]="openssl";
636
			$conf["external::callShell"]["command"]="openssl";
629
		#$conf["fileArgu"],字串,變數__FILE__的內容.
637
			#$conf["fileArgu"],字串,變數__FILE__的內容.
630
		$conf["external::callShell"]["fileArgu"]=__FILE__;
638
			$conf["external::callShell"]["fileArgu"]=__FILE__;
631
		#可省略參數:
639
			#可省略參數:
632
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
640
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
633
		$conf["external::callShell"]["argu"]=array("genrsa","-out",$TFN,"4096");
641
			$conf["external::callShell"]["argu"]=array("genrsa","-out",$TFN,"4096");
634
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
642
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
635
		#$conf["arguIsAddr"]=array();
643
			#$conf["arguIsAddr"]=array();
636
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
644
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
637
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
645
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
638
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
646
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
639
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
647
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
640
		#$conf["enablePrintDescription"]="true";
648
			#$conf["enablePrintDescription"]="true";
641
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
649
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
642
		#$conf["printDescription"]="";
650
			#$conf["printDescription"]="";
643
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
651
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
644
		#$conf["escapeshellarg"]="false";
652
			#$conf["escapeshellarg"]="false";
645
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
653
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
646
		#$conf["thereIsShellVar"]=array();
654
			#$conf["thereIsShellVar"]=array();
647
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
655
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
648
		#$conf["username"]="";
656
			#$conf["username"]="";
649
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
657
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
650
		#$conf["password"]="";
658
			#$conf["password"]="";
651
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
659
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
652
		#$conf["useScript"]="";
660
			#$conf["useScript"]="";
653
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
661
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
654
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
662
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
655
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
663
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
656
		#$conf["inBackGround"]="";
664
			#$conf["inBackGround"]="";
657
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
665
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
658
		#$conf["getErr"]="false";
666
			#$conf["getErr"]="false";
659
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
667
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
660
		$conf["external::callShell"]["doNotRun"]="true";
668
			$conf["external::callShell"]["doNotRun"]="true";
661
		#參考資料:
669
			#參考資料:
662
		#exec=>http://php.net/manual/en/function.exec.php
670
			#exec=>http://php.net/manual/en/function.exec.php
663
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
671
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
664
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
672
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
665
		#備註:
673
			#備註:
666
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
674
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
667
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
675
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
668
		$callShell=external::callShell($conf["external::callShell"]);
676
			$callShell=external::callShell($conf["external::callShell"]);
669
		unset($conf["external::callShell"]);
677
			unset($conf["external::callShell"]);
670
		
678
			
671
		#如果執行異常
679
			#如果執行異常
672
		if($callShell["status"]==="false"){
680
			if($callShell["status"]==="false"){
673
 
681
 
674
			#設置錯誤識別
682
				#設置錯誤識別
675
			$result["status"]="false";
683
				$result["status"]="false";
676
 
684
 
677
			#設置錯誤訊息
685
				#設置錯誤訊息
678
			$result["error"]=$callShell;
686
				$result["error"]=$callShell;
679
 
687
 
680
			#回傳結果
688
				#回傳結果
681
			return $result;
689
				return $result;
682
 
690
 
683
			}#if end
691
				}#if end
684
		
692
			
685
		#debug
693
			#debug
686
		#var_dump(__LINE__,$callShell);exit;
694
			#var_dump(__LINE__,$callShell);exit;
687
		
695
			
688
		#函式說明:
696
			#函式說明:
689
		#透過proc來多執行序運作.
697
			#透過proc來多執行序運作.
690
		#回傳結果:
698
			#回傳結果:
691
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
699
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
692
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
700
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
693
		#$result["function"],當前執行的函式名稱.
701
			#$result["function"],當前執行的函式名稱.
694
		#$result["argu"],使用的參數.
702
			#$result["argu"],使用的參數.
695
		#$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"代表程序的資訊.
703
			#$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"代表程序的資訊.
696
		#必填參數:
704
			#必填參數:
697
		#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
705
			#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
698
		$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
706
			$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
699
		#可省略參數:
707
			#可省略參數:
700
		#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
708
			#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
701
		$conf["threads::proc"]["wait"]="true";
709
			$conf["threads::proc"]["wait"]="true";
702
		#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
710
			#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
703
		#$conf["timeout"]=array("10");
711
			#$conf["timeout"]=array("10");
704
		#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
712
			#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
705
		#$conf["workingDir"]=array("path");
713
			#$conf["workingDir"]=array("path");
706
		#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
714
			#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
707
		#$conf["envs"]=array(array("key"=>"value"));
715
			#$conf["envs"]=array(array("key"=>"value"));
708
		#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
716
			#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
709
		#$conf["executeBy"]=array("bash");
717
			#$conf["executeBy"]=array("bash");
710
		#參考資料:
718
			#參考資料:
711
		#https://www.php.net/manual/en/function.proc-open.php
719
			#https://www.php.net/manual/en/function.proc-open.php
712
		#https://www.php.net/manual/en/function.proc-get-status.php
720
			#https://www.php.net/manual/en/function.proc-get-status.php
713
		#https://www.php.net/manual/en/function.proc-terminate.php
721
			#https://www.php.net/manual/en/function.proc-terminate.php
714
		#備註:
722
			#備註:
715
		#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
723
			#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
716
		$proc=threads::proc($conf["threads::proc"]);
724
			$proc=threads::proc($conf["threads::proc"]);
717
		unset($conf["threads::proc"]);
725
			unset($conf["threads::proc"]);
718
		
726
			
719
		#如果執行異常
727
			#如果執行異常
720
		if($proc["status"]==="false"){
728
			if($proc["status"]==="false"){
721
 
729
 
722
			#設置錯誤識別
730
				#設置錯誤識別
723
			$result["status"]="false";
731
				$result["status"]="false";
724
 
732
 
725
			#設置錯誤訊息
733
				#設置錯誤訊息
726
			$result["error"]=$proc;
734
				$result["error"]=$proc;
727
 
735
 
728
			#回傳結果
736
				#回傳結果
729
			return $result;
737
				return $result;
730
 
738
 
731
			}#if end
739
				}#if end
732
		
740
			
733
		#debug
741
			#debug
734
		#var_dump(__LINE__,$proc);exit;
742
			#var_dump(__LINE__,$proc);exit;
735
		
743
			
736
		#如果執行異常
744
			#如果執行異常
737
		if($proc["content"][0]["status"]==="false"){
745
			if($proc["content"][0]["status"]==="false"){
738
		
746
			
739
			#設置錯誤識別
747
				#設置錯誤識別
740
			$result["status"]="false";
748
				$result["status"]="false";
741
 
749
 
742
			#設置錯誤訊息
750
				#設置錯誤訊息
743
			$result["error"]=$proc["content"][0]["error"];
751
				$result["error"]=$proc["content"][0]["error"];
744
 
752
 
745
			#回傳結果
753
				#回傳結果
-
 
754
				return $result;
-
 
755
			
-
 
756
				}#if end
-
 
757
			
-
 
758
			#儲存錯誤訊息
-
 
759
			$errorMsg=$proc["content"][0]["error"];
-
 
760
			
-
 
761
			#如果有錯誤訊息
-
 
762
			if(!empty($errorMsg)){
-
 
763
			
-
 
764
				#設置錯誤識別
-
 
765
				$result["status"]="false";
-
 
766
 
-
 
767
				#設置錯誤訊息
-
 
768
				$result["error"]=$errorMsg;
-
 
769
 
-
 
770
				#回傳結果
746
			return $result;
771
				return $result;
-
 
772
			
-
 
773
				}#if end
747
		
774
		
748
			}#if end
775
			}#if end
749
		
776
		
750
		#儲存錯誤訊息
777
		#反之
751
		$errorMsg=$proc["content"][0]["error"];
778
		else{
752
		
779
		
-
 
780
			#檢查 pKey 是否存在
-
 
781
			#函式說明:
-
 
782
			#檢查多個檔案與資料夾是否存在.
-
 
783
			#回傳的結果:
-
 
784
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
753
		#如果有錯誤訊息
785
			#$result["error"],錯誤訊息陣列.
-
 
786
			#$resutl["function"],當前執行的涵式名稱.
-
 
787
			#$result["argu"],使用的參數.
-
 
788
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
-
 
789
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
-
 
790
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
-
 
791
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
-
 
792
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
-
 
793
			#必填參數:
-
 
794
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
-
 
795
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["pKey"];
-
 
796
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
797
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
-
 
798
			#可省略參數:
754
		if(!empty($errorMsg)){
799
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
-
 
800
			#$conf["disableWebSearch"]="false";
-
 
801
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
-
 
802
			$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
-
 
803
			#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
-
 
804
			$conf["fileAccess::checkMultiFileExist"]["web"]="false";
-
 
805
			#參考資料:
-
 
806
			#http://php.net/manual/en/function.file-exists.php
-
 
807
			#http://php.net/manual/en/control-structures.foreach.php
-
 
808
			#備註:
-
 
809
			#函數file_exists檢查的路徑為檔案系統的路徑
-
 
810
			#$result["varName"][$i]結果未實作
-
 
811
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
-
 
812
			unset($conf["fileAccess::checkMultiFileExist"]);
755
		
813
		
756
			#設置錯誤識別
814
			#如果執行異常
757
			$result["status"]="false";
815
			if($checkMultiFileExist["status"]==="false"){
758
 
816
 
759
			#設置錯誤訊息
817
				#設置錯誤識別
760
			$result["error"]=$errorMsg;
818
				$result["status"]="false";
761
 
819
 
-
 
820
				#設置錯誤訊息
-
 
821
				$result["error"]=$checkMultiFileExist;
-
 
822
 
762
			#回傳結果
823
				#回傳結果
763
			return $result;
824
				return $result;
-
 
825
 
-
 
826
				}#if end
764
		
827
		
-
 
828
			#設置pKey
-
 
829
			$TFN=$conf["pKey"];
-
 
830
		
765
			}#if end
831
			}#else
766
		
832
		
767
		#範例指令
833
		#範例指令
768
		#C,國家,例如TW,代表Taiwan
834
		#C,國家,例如TW,代表Taiwan
769
		#ST,州、省,要完整名稱,例如:Taiwan
835
		#ST,州、省,要完整名稱,例如:Taiwan
770
		#L,城市名稱,例如Taoyuan City.
836
		#L,城市名稱,例如Taoyuan City.
Line 939... Line 1005...
939
		$csr=$proc["content"][0]["content"];
1005
		$csr=$proc["content"][0]["content"];
940
		
1006
		
941
		#取得 csr 內容
1007
		#取得 csr 內容
942
		$result["content"]=$csr;
1008
		$result["content"]=$csr;
943
		
1009
		
944
		#移除private key
1010
		#取得 private key 的內容
945
		#函式說明:
1011
		#函式說明:
946
		#移除檔案
1012
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
947
		#回傳結果:
1013
		#回傳的變數說明:
948
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
1014
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
949
		#$result["error"],錯誤訊息陣列.
1015
		#$result["error"],錯誤訊息提示.
950
		#$result["warning"],警告訊息陣列.
1016
		#$result["warning"],警告訊息.
951
		#$result["function"],當前執行的函數名稱.
1017
		#$result["function"],當前執行的函數名稱.
-
 
1018
		#$result["fileContent"],爲檔案的內容陣列.
952
		#$result["argu"],當前函式使用的參數.
1019
		#$result["lineCount"],爲檔案內容總共的行數.
-
 
1020
		#$result["fullContent"],為檔案的完整內容.
-
 
1021
		#$result["base64dataOnly"],檔案的base64data.
-
 
1022
		#$result["base64data"],為在網頁上給予src參數的數值.
-
 
1023
		#$result["mimeType"],為檔案的mime type.
953
		#必填參數:
1024
		#必填參數:
954
		#$conf["fileAddress"],字串,要移除檔案的位置.
1025
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
955
		$conf["fileAccess::delFile"]["fileAddress"]=$TFN;
1026
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$TFN;
956
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1027
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
957
		$conf["fileAccess::delFile"]["fileArgu"]=__FILE__;
1028
		$conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
958
		#可省略參數:
1029
		#可省略參數:
959
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1030
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
960
		#$conf["commentsArray"]=array("");
1031
		#$conf["web"]="true";
961
		#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
1032
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
962
		#$conf["allowDelSymlink"]="true";
1033
		#$conf["createIfnotExist"]="false";
963
		#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
1034
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
964
		#$conf["allowDelFolder"]="true";
1035
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
-
 
1036
		#參考資料:
-
 
1037
		#file(),取得檔案內容的行數.
-
 
1038
		#file=>http:#php.net/manual/en/function.file.php
-
 
1039
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
-
 
1040
		#filesize=>http://php.net/manual/en/function.filesize.php
965
		#參考資料:
1041
		#參考資料:
966
		#無.
1042
		#無.
967
		#備註:
1043
		#備註:
968
		#無.
1044
		#無.
969
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
1045
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
970
		unset($conf["fileAccess::delFile"]);
1046
		unset($conf["fileAccess::getFileContent"]);
971
		
1047
		
972
		#如果執行異常
1048
		#如果執行異常
973
		if($delFile["status"]==="false"){
1049
		if($getFileContent["status"]==="false"){
974
 
1050
 
975
			#設置錯誤識別
1051
			#設置錯誤識別
976
			$result["status"]="false";
1052
			$result["status"]="false";
977
 
1053
 
978
			#設置錯誤訊息
1054
			#設置錯誤訊息
979
			$result["error"]=$delFile;
1055
			$result["error"]=$getFileContent;
980
 
1056
 
981
			#回傳結果
1057
			#回傳結果
982
			return $result;
1058
			return $result;
983
 
1059
 
984
			}#if end
1060
			}#if end
-
 
1061
			
-
 
1062
		#設置要回傳的 private key 的內容
-
 
1063
		$result["privateKey"]=$getFileContent["fullContent"];
-
 
1064
		
-
 
1065
		#如果沒有設置 pKey
-
 
1066
		if(!isset($conf["pKey"])){
-
 
1067
		
-
 
1068
			#移除private key
-
 
1069
			#函式說明:
-
 
1070
			#移除檔案
-
 
1071
			#回傳結果:
-
 
1072
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
-
 
1073
			#$result["error"],錯誤訊息陣列.
-
 
1074
			#$result["warning"],警告訊息陣列.
-
 
1075
			#$result["function"],當前執行的函數名稱.
-
 
1076
			#$result["argu"],當前函式使用的參數.
-
 
1077
			#必填參數:
-
 
1078
			#$conf["fileAddress"],字串,要移除檔案的位置.
-
 
1079
			$conf["fileAccess::delFile"]["fileAddress"]=$TFN;
-
 
1080
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
-
 
1081
			$conf["fileAccess::delFile"]["fileArgu"]=__FILE__;
-
 
1082
			#可省略參數:
-
 
1083
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
-
 
1084
			#$conf["commentsArray"]=array("");
-
 
1085
			#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
-
 
1086
			#$conf["allowDelSymlink"]="true";
-
 
1087
			#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
-
 
1088
			#$conf["allowDelFolder"]="true";
-
 
1089
			#參考資料:
-
 
1090
			#無.
-
 
1091
			#備註:
-
 
1092
			#無.
-
 
1093
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
-
 
1094
			unset($conf["fileAccess::delFile"]);
-
 
1095
			
-
 
1096
			#如果執行異常
-
 
1097
			if($delFile["status"]==="false"){
-
 
1098
 
-
 
1099
				#設置錯誤識別
-
 
1100
				$result["status"]="false";
-
 
1101
 
-
 
1102
				#設置錯誤訊息
-
 
1103
				$result["error"]=$delFile;
-
 
1104
 
-
 
1105
				#回傳結果
-
 
1106
				return $result;
-
 
1107
 
-
 
1108
				}#if end
-
 
1109
		
-
 
1110
			}#if end
985
		
1111
		
986
		#設置執行正常
1112
		#設置執行正常
987
		$result["status"]="true";
1113
		$result["status"]="true";
988
		
1114
		
989
		#回傳結果
1115
		#回傳結果
Line 1232... Line 1358...
1232
		#設置json string結果
1358
		#設置json string結果
1233
		$result["content"]=$curlCmd["fullContent"];
1359
		$result["content"]=$curlCmd["fullContent"];
1234
 
1360
 
1235
		#解析json
1361
		#解析json
1236
		$jsonRes=json_decode($result["content"]);
1362
		$jsonRes=json_decode($result["content"]);
-
 
1363
		
-
 
1364
		#另存 certifucate domain
-
 
1365
		$cerDomain=$conf["certificate_domains"];
-
 
1366
		
-
 
1367
		#如果缺少必備的資訊
-
 
1368
		if(!isset($jsonRes->validation)){
-
 
1369
		
-
 
1370
			#設置錯誤識別
-
 
1371
			$result["status"]="false";
-
 
1372
 
-
 
1373
			#設置錯誤訊息
-
 
1374
			$result["error"]=$curlCmd;
1237
 
1375
 
-
 
1376
			#回傳結果
-
 
1377
			return $result;
-
 
1378
		
-
 
1379
			}#if end
-
 
1380
		
1238
		#取得用於 dns CNAME 驗證的名稱
1381
		#取得用於 dns CNAME 驗證的名稱
1239
		$result["cnameKey"]=$jsonRes->validation->other_methods->$conf["certificate_domains"]->cname_validation_p1;
1382
		$result["cnameKey"]=$jsonRes->validation->other_methods->$cerDomain->cname_validation_p1;
1240
 
1383
 
1241
		#取得用於 dns CNAME 驗證的數值
1384
		#取得用於 dns CNAME 驗證的數值
1242
		$result["cnameVal"]=$jsonRes->validation->other_methods->$conf["certificate_domains"]->cname_validation_p2;
1385
		$result["cnameVal"]=$jsonRes->validation->other_methods->$cerDomain->cname_validation_p2;
1243
 
1386
 
1244
		#取得用於認證domain時識別用的id
1387
		#取得用於認證domain時識別用的id
1245
		$result["id"]=$jsonRes->id;
1388
		$result["id"]=$jsonRes->id;
1246
 
1389
 
1247
		#設置執行正常
1390
		#設置執行正常
Line 1259... Line 1402...
1259
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1402
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1260
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1403
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1261
	#$result["function"],當前執行的函式名稱.
1404
	#$result["function"],當前執行的函式名稱.
1262
	#$result["argu"],所使用的參數.
1405
	#$result["argu"],所使用的參數.
1263
	#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
1406
	#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
1264
	#$result["content"]["domain"],字串,RR所屬domain.
1407
	#$result["domain"],字串,RR所屬domain.
1265
	#$result["content"]["defaultTTL"],字串,預設的RR更新時間.
1408
	#$result["defaultTTL"],字串,預設的RR更新時間.
1266
	#$result["comment"],字串陣列,逐行的註解.
1409
	#$result["comment"],字串陣列,逐行的註解.
1267
	#必填參數:
1410
	#必填參數:
1268
	#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
1411
	#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型(支援的有"A","TXT","CNAME","SOA","$TTL","$ORIGIN")、答案、註解.
1269
	$conf["add"]=array();
1412
	$conf["add"]=array();
1270
	#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
1413
	#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
1271
	$conf["dnsRecordFile"]="";
1414
	$conf["dnsRecordFile"]="";
1272
	#可省略參數:
1415
	#可省略參數:
1273
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
1416
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
Line 3469... Line 3612...
3469
			}#if end
3612
			}#if end
3470
		
3613
		
3471
		#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
3614
		#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
3472
		
3615
		
3473
		#針對每個要新增的RR記錄
3616
		#針對每個要新增的RR記錄
3474
		foreach($conf["add"] as $newRR){
3617
		foreach($conf["add"] as $nri => $newRR){
-
 
3618
			
-
 
3619
			#如果要debug
-
 
3620
			if($conf["debug"]==="true"){
-
 
3621
			
-
 
3622
				#函式說明:
-
 
3623
				#撰寫log
-
 
3624
				#回傳結果:
-
 
3625
				#$result["status"],狀態,"true"或"false".
-
 
3626
				#$result["error"],錯誤訊息陣列.
-
 
3627
				#$result["function"],當前函式的名稱.
-
 
3628
				#$result["argu"],使用的參數.
-
 
3629
				#$result["content"],要寫入log的內容字串.
-
 
3630
				#必填參數:
-
 
3631
				#$conf["path"],字串,log檔案的路徑與名稱.
-
 
3632
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
3633
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
3634
				$conf["logs::record"]["content"]="lineNo:".__LINE__." ori newRR:".PHP_EOL;
-
 
3635
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3636
				$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
3637
				#可省略參數:
-
 
3638
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
3639
				#$conf["rewrite"]="false";
-
 
3640
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
3641
				#$conf["returnOnly"]="true";
-
 
3642
				#參考資料:
-
 
3643
				#無.
-
 
3644
				#備註:
-
 
3645
				#無.
-
 
3646
				$record=logs::record($conf["logs::record"]);
-
 
3647
				unset($conf["logs::record"]);
-
 
3648
				
-
 
3649
				#函式說明:
-
 
3650
				#撰寫log
-
 
3651
				#回傳結果:
-
 
3652
				#$result["status"],狀態,"true"或"false".
-
 
3653
				#$result["error"],錯誤訊息陣列.
-
 
3654
				#$result["function"],當前函式的名稱.
-
 
3655
				#$result["argu"],使用的參數.
-
 
3656
				#$result["content"],要寫入log的內容字串.
-
 
3657
				#必填參數:
-
 
3658
				#$conf["path"],字串,log檔案的路徑與名稱.
-
 
3659
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
3660
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
3661
				$conf["logs::record"]["content"]=$newRR;
-
 
3662
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3663
				$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
3664
				#可省略參數:
-
 
3665
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
3666
				#$conf["rewrite"]="false";
-
 
3667
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
3668
				#$conf["returnOnly"]="true";
-
 
3669
				#參考資料:
-
 
3670
				#無.
-
 
3671
				#備註:
-
 
3672
				#無.
-
 
3673
				$record=logs::record($conf["logs::record"]);
-
 
3674
				unset($conf["logs::record"]);
-
 
3675
				
-
 
3676
				}#if end
-
 
3677
			
-
 
3678
			#如果新的 RR 缺少必備的資訊
-
 
3679
			if(!isset($newRR["type"])){
-
 
3680
			
-
 
3681
				#設置執行異常
-
 
3682
				$result["status"]="false";
-
 
3683
				
-
 
3684
				#設置執行錯誤
-
 
3685
				$result["error"]="add參數的格式缺少type";
-
 
3686
				
-
 
3687
				#回傳結果
-
 
3688
				return $result;
-
 
3689
			
-
 
3690
				}#if end
-
 
3691
				
-
 
3692
			#如果 query 結尾不是"@"也不為"."結尾
-
 
3693
			if( ($newRR["query"]!=="@") && ($newRR["query"][strlen($newRR["query"])-1]!==".") ){
-
 
3694
			
-
 
3695
				#加上 "."
-
 
3696
				$conf["add"][$nri]["query"]=$newRR["query"]=$newRR["query"].".";
-
 
3697
			
-
 
3698
				}#if end
-
 
3699
				
-
 
3700
			#如果新的 query 為 $ORGIN 結尾
-
 
3701
			#函式說明:
-
 
3702
			#將字串特定關鍵字與其後面的內容剔除
-
 
3703
			#回傳結果:
-
 
3704
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
3705
			#$result["error"],錯誤訊息陣列.
-
 
3706
			#$result["warning"],警告訊息鎮列.
-
 
3707
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
-
 
3708
			#$result["function"],當前執行的函數名稱.
-
 
3709
			#$result["oriStr"],要處理的原始字串內容.
-
 
3710
			#$result["content"],處理好的的字串內容.
-
 
3711
			#$result["deleted"],被移除的內容.
-
 
3712
			#$result["argu"],使用的參數.
-
 
3713
			#必填參數:
-
 
3714
			#$conf["stringIn"],字串,要處理的字串.
-
 
3715
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
-
 
3716
			#$conf["keyWord"],字串,特定字串.
-
 
3717
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["domain"];
-
 
3718
			#可省略參數:
-
 
3719
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
-
 
3720
			#$conf["deleteLastRepeatedOne"]="";
-
 
3721
			#參考資料:
-
 
3722
			#無.
-
 
3723
			#備註:
-
 
3724
			#無.
-
 
3725
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
-
 
3726
			unset($conf["stringProcess::delStrAfterKeyWord"]);
-
 
3727
			
-
 
3728
			#如果要debug
-
 
3729
			if($conf["debug"]==="true"){
-
 
3730
			
-
 
3731
				#函式說明:
-
 
3732
				#撰寫log
-
 
3733
				#回傳結果:
-
 
3734
				#$result["status"],狀態,"true"或"false".
-
 
3735
				#$result["error"],錯誤訊息陣列.
-
 
3736
				#$result["function"],當前函式的名稱.
-
 
3737
				#$result["argu"],使用的參數.
-
 
3738
				#$result["content"],要寫入log的內容字串.
-
 
3739
				#必填參數:
-
 
3740
				#$conf["path"],字串,log檔案的路徑與名稱.
-
 
3741
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
3742
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
3743
				$conf["logs::record"]["content"]="lineNo:".__LINE__." try process newRR with \$ORIGIN end".PHP_EOL;
-
 
3744
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3745
				$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
3746
				#可省略參數:
-
 
3747
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
3748
				#$conf["rewrite"]="false";
-
 
3749
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
3750
				#$conf["returnOnly"]="true";
-
 
3751
				#參考資料:
-
 
3752
				#無.
-
 
3753
				#備註:
-
 
3754
				#無.
-
 
3755
				$record=logs::record($conf["logs::record"]);
-
 
3756
				unset($conf["logs::record"]);
-
 
3757
				
-
 
3758
				#函式說明:
-
 
3759
				#撰寫log
-
 
3760
				#回傳結果:
-
 
3761
				#$result["status"],狀態,"true"或"false".
-
 
3762
				#$result["error"],錯誤訊息陣列.
-
 
3763
				#$result["function"],當前函式的名稱.
-
 
3764
				#$result["argu"],使用的參數.
-
 
3765
				#$result["content"],要寫入log的內容字串.
-
 
3766
				#必填參數:
-
 
3767
				#$conf["path"],字串,log檔案的路徑與名稱.
-
 
3768
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
3769
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
3770
				$conf["logs::record"]["content"]=$delStrAfterKeyWord;
-
 
3771
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3772
				$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
3773
				#可省略參數:
-
 
3774
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
3775
				#$conf["rewrite"]="false";
-
 
3776
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
3777
				#$conf["returnOnly"]="true";
-
 
3778
				#參考資料:
-
 
3779
				#無.
-
 
3780
				#備註:
-
 
3781
				#無.
-
 
3782
				$record=logs::record($conf["logs::record"]);
-
 
3783
				unset($conf["logs::record"]);
-
 
3784
				
-
 
3785
				}#if end
-
 
3786
			
-
 
3787
			#如果異常
-
 
3788
			if($delStrAfterKeyWord["status"]==="false"){
-
 
3789
			
-
 
3790
				#設置執行異常
-
 
3791
				$result["status"]="false";
-
 
3792
				
-
 
3793
				#設置執行錯誤
-
 
3794
				$result["error"]=$delStrAfterKeyWord;
-
 
3795
				
-
 
3796
				#回傳結果
-
 
3797
				return $result;
-
 
3798
			
-
 
3799
				}#if end
-
 
3800
				
-
 
3801
			#如果有找到 $ORIGIN 結尾
-
 
3802
			if($delStrAfterKeyWord["founded"]==="true"){
-
 
3803
			
-
 
3804
				#更新 query
-
 
3805
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
-
 
3806
			
-
 
3807
				#如果$newRR["query"] 變成 ""
-
 
3808
				if(empty($newRR["query"])){
-
 
3809
				
-
 
3810
					#變成 zone domain,亦即 $result["domain"]
-
 
3811
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
-
 
3812
				
-
 
3813
					}#if end
-
 
3814
					
-
 
3815
				#如果要debug
-
 
3816
				if($conf["debug"]==="true"){
-
 
3817
				
-
 
3818
					#函式說明:
-
 
3819
					#撰寫log
-
 
3820
					#回傳結果:
-
 
3821
					#$result["status"],狀態,"true"或"false".
-
 
3822
					#$result["error"],錯誤訊息陣列.
-
 
3823
					#$result["function"],當前函式的名稱.
-
 
3824
					#$result["argu"],使用的參數.
-
 
3825
					#$result["content"],要寫入log的內容字串.
-
 
3826
					#必填參數:
-
 
3827
					#$conf["path"],字串,log檔案的路徑與名稱.
-
 
3828
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
3829
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
3830
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
-
 
3831
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3832
					$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
3833
					#可省略參數:
-
 
3834
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
3835
					#$conf["rewrite"]="false";
-
 
3836
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
3837
					#$conf["returnOnly"]="true";
-
 
3838
					#參考資料:
-
 
3839
					#無.
-
 
3840
					#備註:
-
 
3841
					#無.
-
 
3842
					$record=logs::record($conf["logs::record"]);
-
 
3843
					unset($conf["logs::record"]);
-
 
3844
					
-
 
3845
					#函式說明:
-
 
3846
					#撰寫log
-
 
3847
					#回傳結果:
-
 
3848
					#$result["status"],狀態,"true"或"false".
-
 
3849
					#$result["error"],錯誤訊息陣列.
-
 
3850
					#$result["function"],當前函式的名稱.
-
 
3851
					#$result["argu"],使用的參數.
-
 
3852
					#$result["content"],要寫入log的內容字串.
-
 
3853
					#必填參數:
-
 
3854
					#$conf["path"],字串,log檔案的路徑與名稱.
-
 
3855
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
3856
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
3857
					$conf["logs::record"]["content"]=$conf["add"][$nri];
-
 
3858
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3859
					$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
3860
					#可省略參數:
-
 
3861
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
3862
					#$conf["rewrite"]="false";
-
 
3863
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
3864
					#$conf["returnOnly"]="true";
-
 
3865
					#參考資料:
-
 
3866
					#無.
-
 
3867
					#備註:
-
 
3868
					#無.
-
 
3869
					$record=logs::record($conf["logs::record"]);
-
 
3870
					unset($conf["logs::record"]);
-
 
3871
					
-
 
3872
					}#if end
-
 
3873
			
-
 
3874
				}#if end
-
 
3875
				
-
 
3876
			#如果新的 query 為 "." 結尾
-
 
3877
			#函式說明:
-
 
3878
			#將字串特定關鍵字與其後面的內容剔除
-
 
3879
			#回傳結果:
-
 
3880
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
3881
			#$result["error"],錯誤訊息陣列.
-
 
3882
			#$result["warning"],警告訊息鎮列.
-
 
3883
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
-
 
3884
			#$result["function"],當前執行的函數名稱.
-
 
3885
			#$result["oriStr"],要處理的原始字串內容.
-
 
3886
			#$result["content"],處理好的的字串內容.
-
 
3887
			#$result["deleted"],被移除的內容.
-
 
3888
			#$result["argu"],使用的參數.
-
 
3889
			#必填參數:
-
 
3890
			#$conf["stringIn"],字串,要處理的字串.
-
 
3891
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
-
 
3892
			#$conf["keyWord"],字串,特定字串.
-
 
3893
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".";
-
 
3894
			#可省略參數:
-
 
3895
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
-
 
3896
			#$conf["deleteLastRepeatedOne"]="";
-
 
3897
			#參考資料:
-
 
3898
			#無.
-
 
3899
			#備註:
-
 
3900
			#無.
-
 
3901
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
-
 
3902
			unset($conf["stringProcess::delStrAfterKeyWord"]);
-
 
3903
			
-
 
3904
			#如果異常
-
 
3905
			if($delStrAfterKeyWord["status"]==="false"){
-
 
3906
			
-
 
3907
				#設置執行異常
-
 
3908
				$result["status"]="false";
-
 
3909
				
-
 
3910
				#設置執行錯誤
-
 
3911
				$result["error"]=$delStrAfterKeyWord;
-
 
3912
				
-
 
3913
				#回傳結果
-
 
3914
				return $result;
-
 
3915
			
-
 
3916
				}#if end
-
 
3917
				
-
 
3918
			#如果有找到 "." 結尾
-
 
3919
			if($delStrAfterKeyWord["founded"]==="true"){
-
 
3920
			
-
 
3921
				#更新 query
-
 
3922
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
-
 
3923
				
-
 
3924
				#如果 $newRR["query"] 變成 ""
-
 
3925
				if(empty($newRR["query"])){
-
 
3926
				
-
 
3927
					#變成 zone domain,亦即 $result["domain"]
-
 
3928
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
-
 
3929
				
-
 
3930
					}#if end
-
 
3931
					
-
 
3932
				#如果要debug
-
 
3933
				if($conf["debug"]==="true"){
-
 
3934
				
-
 
3935
					#函式說明:
-
 
3936
					#撰寫log
-
 
3937
					#回傳結果:
-
 
3938
					#$result["status"],狀態,"true"或"false".
-
 
3939
					#$result["error"],錯誤訊息陣列.
-
 
3940
					#$result["function"],當前函式的名稱.
-
 
3941
					#$result["argu"],使用的參數.
-
 
3942
					#$result["content"],要寫入log的內容字串.
-
 
3943
					#必填參數:
-
 
3944
					#$conf["path"],字串,log檔案的路徑與名稱.
-
 
3945
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
3946
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
3947
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
-
 
3948
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3949
					$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
3950
					#可省略參數:
-
 
3951
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
3952
					#$conf["rewrite"]="false";
-
 
3953
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
3954
					#$conf["returnOnly"]="true";
-
 
3955
					#參考資料:
-
 
3956
					#無.
-
 
3957
					#備註:
-
 
3958
					#無.
-
 
3959
					$record=logs::record($conf["logs::record"]);
-
 
3960
					unset($conf["logs::record"]);
-
 
3961
					
-
 
3962
					#函式說明:
-
 
3963
					#撰寫log
-
 
3964
					#回傳結果:
-
 
3965
					#$result["status"],狀態,"true"或"false".
-
 
3966
					#$result["error"],錯誤訊息陣列.
-
 
3967
					#$result["function"],當前函式的名稱.
-
 
3968
					#$result["argu"],使用的參數.
-
 
3969
					#$result["content"],要寫入log的內容字串.
-
 
3970
					#必填參數:
-
 
3971
					#$conf["path"],字串,log檔案的路徑與名稱.
-
 
3972
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
3973
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
3974
					$conf["logs::record"]["content"]=$conf["add"][$nri];
-
 
3975
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3976
					$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
3977
					#可省略參數:
-
 
3978
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
3979
					#$conf["rewrite"]="false";
-
 
3980
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
3981
					#$conf["returnOnly"]="true";
-
 
3982
					#參考資料:
-
 
3983
					#無.
-
 
3984
					#備註:
-
 
3985
					#無.
-
 
3986
					$record=logs::record($conf["logs::record"]);
-
 
3987
					unset($conf["logs::record"]);
-
 
3988
					
-
 
3989
					}#if end
-
 
3990
			
-
 
3991
				}#if end
-
 
3992
			
-
 
3993
			#如果新 RR 的 type 不是 A 且 value 不為 "." 結尾.
-
 
3994
			if( $newRR["type"]!=="A" && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
-
 
3995
			
-
 
3996
				#new RR add dot to value end.
-
 
3997
				$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
-
 
3998
				
-
 
3999
				#如果要debug
-
 
4000
				if($conf["debug"]==="true"){
-
 
4001
				
-
 
4002
					#函式說明:
-
 
4003
					#撰寫log
-
 
4004
					#回傳結果:
-
 
4005
					#$result["status"],狀態,"true"或"false".
-
 
4006
					#$result["error"],錯誤訊息陣列.
-
 
4007
					#$result["function"],當前函式的名稱.
-
 
4008
					#$result["argu"],使用的參數.
-
 
4009
					#$result["content"],要寫入log的內容字串.
-
 
4010
					#必填參數:
-
 
4011
					#$conf["path"],字串,log檔案的路徑與名稱.
-
 
4012
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
4013
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
4014
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
-
 
4015
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
4016
					$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
4017
					#可省略參數:
-
 
4018
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
4019
					#$conf["rewrite"]="false";
-
 
4020
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
4021
					#$conf["returnOnly"]="true";
-
 
4022
					#參考資料:
-
 
4023
					#無.
-
 
4024
					#備註:
-
 
4025
					#無.
-
 
4026
					$record=logs::record($conf["logs::record"]);
-
 
4027
					unset($conf["logs::record"]);
-
 
4028
					
-
 
4029
					#函式說明:
-
 
4030
					#撰寫log
-
 
4031
					#回傳結果:
-
 
4032
					#$result["status"],狀態,"true"或"false".
-
 
4033
					#$result["error"],錯誤訊息陣列.
-
 
4034
					#$result["function"],當前函式的名稱.
-
 
4035
					#$result["argu"],使用的參數.
-
 
4036
					#$result["content"],要寫入log的內容字串.
-
 
4037
					#必填參數:
-
 
4038
					#$conf["path"],字串,log檔案的路徑與名稱.
-
 
4039
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
4040
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
4041
					$conf["logs::record"]["content"]=$conf["add"][$nri];
-
 
4042
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
4043
					$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
4044
					#可省略參數:
-
 
4045
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
4046
					#$conf["rewrite"]="false";
-
 
4047
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
4048
					#$conf["returnOnly"]="true";
-
 
4049
					#參考資料:
-
 
4050
					#無.
-
 
4051
					#備註:
-
 
4052
					#無.
-
 
4053
					$record=logs::record($conf["logs::record"]);
-
 
4054
					unset($conf["logs::record"]);
-
 
4055
					
-
 
4056
					}#if end
-
 
4057
			
-
 
4058
				}#if end
3475
			
4059
			
3476
			#針對 zone file 中既有的每個RR記錄
4060
			#針對 zone file 中既有的每個RR記錄
3477
			foreach($result["content"] as $index => $oldRR){
4061
			foreach($result["content"] as $index => $oldRR){
3478
			
4062
			
3479
				#如果既有的跟新的RR都為 $ORIGIN
4063
				#如果既有的跟新的RR都為 $ORIGIN
Line 3559... Line 4143...
3559
			#儲存確定要新增的RR
4143
			#儲存確定要新增的RR
3560
			$result["content"][]=$newRR;
4144
			$result["content"][]=$newRR;
3561
		
4145
		
3562
			}#foreach end
4146
			}#foreach end
3563
		
4147
		
3564
		#/*
-
 
3565
		#debug
4148
		#如果要debug
3566
		#函式說明:
-
 
3567
		#撰寫log
-
 
3568
		#回傳結果:
-
 
3569
		#$result["status"],狀態,"true"或"false".
-
 
3570
		#$result["error"],錯誤訊息陣列.
-
 
3571
		#$result["function"],當前函式的名稱.
-
 
3572
		#$result["argu"],使用的參數.
-
 
3573
		#$result["content"],要寫入log的內容字串.
-
 
3574
		#必填參數:
-
 
3575
		#$conf["path"],字串,log檔案的路徑與名稱.
-
 
3576
		$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
3577
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
3578
		$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
-
 
3579
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3580
		$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
3581
		#可省略參數:
-
 
3582
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
3583
		#$conf["rewrite"]="false";
-
 
3584
		#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
3585
		#$conf["returnOnly"]="true";
4149
		if($conf["debug"]==="true"){
3586
		#參考資料:
-
 
3587
		#無.
-
 
3588
		#備註:
-
 
3589
		#無.
-
 
3590
		$record=logs::record($conf["logs::record"]);
-
 
3591
		unset($conf["logs::record"]);
-
 
3592
		#*/
-
 
3593
		
4150
		
-
 
4151
			#函式說明:
-
 
4152
			#撰寫log
-
 
4153
			#回傳結果:
-
 
4154
			#$result["status"],狀態,"true"或"false".
-
 
4155
			#$result["error"],錯誤訊息陣列.
-
 
4156
			#$result["function"],當前函式的名稱.
-
 
4157
			#$result["argu"],使用的參數.
-
 
4158
			#$result["content"],要寫入log的內容字串.
-
 
4159
			#必填參數:
-
 
4160
			#$conf["path"],字串,log檔案的路徑與名稱.
-
 
4161
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
-
 
4162
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
4163
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
-
 
4164
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
4165
			$conf["logs::record"]["fileArgu"]=__FILE__;
-
 
4166
			#可省略參數:
-
 
4167
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
4168
			#$conf["rewrite"]="false";
-
 
4169
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
-
 
4170
			#$conf["returnOnly"]="true";
-
 
4171
			#參考資料:
-
 
4172
			#無.
-
 
4173
			#備註:
-
 
4174
			#無.
-
 
4175
			$record=logs::record($conf["logs::record"]);
-
 
4176
			unset($conf["logs::record"]);
-
 
4177
		
-
 
4178
			}#if end
3594
		#/*
4179
		
3595
		#debug
4180
		#如果要debug
-
 
4181
		if($conf["debug"]==="true"){
-
 
4182
		
3596
		#函式說明:
4183
			#函式說明:
3597
		#撰寫log
4184
			#撰寫log
3598
		#回傳結果:
4185
			#回傳結果:
3599
		#$result["status"],狀態,"true"或"false".
4186
			#$result["status"],狀態,"true"或"false".
3600
		#$result["error"],錯誤訊息陣列.
4187
			#$result["error"],錯誤訊息陣列.
3601
		#$result["function"],當前函式的名稱.
4188
			#$result["function"],當前函式的名稱.
3602
		#$result["argu"],使用的參數.
4189
			#$result["argu"],使用的參數.
3603
		#$result["content"],要寫入log的內容字串.
4190
			#$result["content"],要寫入log的內容字串.
3604
		#必填參數:
4191
			#必填參數:
3605
		#$conf["path"],字串,log檔案的路徑與名稱.
4192
			#$conf["path"],字串,log檔案的路徑與名稱.
3606
		$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4193
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3607
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4194
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3608
		$conf["logs::record"]["content"]=$result["content"];
4195
			$conf["logs::record"]["content"]=$result["content"];
3609
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4196
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3610
		$conf["logs::record"]["fileArgu"]=__FILE__;
4197
			$conf["logs::record"]["fileArgu"]=__FILE__;
3611
		#可省略參數:
4198
			#可省略參數:
3612
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4199
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3613
		#$conf["rewrite"]="false";
4200
			#$conf["rewrite"]="false";
3614
		#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4201
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3615
		#$conf["returnOnly"]="true";
4202
			#$conf["returnOnly"]="true";
3616
		#參考資料:
4203
			#參考資料:
3617
		#無.
4204
			#無.
3618
		#備註:
4205
			#備註:
3619
		#無.
4206
			#無.
3620
		$record=logs::record($conf["logs::record"]);
4207
			$record=logs::record($conf["logs::record"]);
3621
		unset($conf["logs::record"]);
4208
			unset($conf["logs::record"]);
3622
		#*/
4209
		
-
 
4210
			}#if end
3623
		
4211
		
3624
		#初始化要寫入的內容
4212
		#初始化要寫入的內容
3625
		$strs2write=array();
4213
		$strs2write=array();
3626
		
4214
		
3627
		#針對每個RR記錄
4215
		#針對每個RR記錄
Line 3873... Line 4461...
3873
	
4461
	
3874
		}#function updateDnsRecordFile end
4462
		}#function updateDnsRecordFile end
3875
 
4463
 
3876
	/*
4464
	/*
3877
	#函式說明:
4465
	#函式說明:
3878
	#驗證已經透過zerossl::createCertificate要求的domain,並取得ssl憑證.
4466
	#請求驗證已經透過zerossl::createCertificate要求的domain.
3879
	#回傳結果:
4467
	#回傳結果:
3880
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4468
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3881
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
4469
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
3882
	#$result["function"],當前執行的函式名稱.
4470
	#$result["function"],當前執行的函式名稱.
3883
	#$result["argu"],所使用的參數.
4471
	#$result["argu"],所使用的參數.
3884
	#$result["curl_verbose_info"],curl執行的詳細資訊.
4472
	#$result["curl_verbose_info"],curl執行的詳細資訊.
3885
	#$result["content"],字串,得到的json字串回應.
4473
	#$result["content"],結果json字串.
3886
	#必填參數:
4474
	#必填參數:
3887
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
4475
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
3888
	$conf["id"]="";
4476
	$conf["id"]="";
3889
	#可省略參數:
4477
	#可省略參數:
3890
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
4478
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
3891
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
4479
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
3892
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
4480
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
3893
	#$conf["key"]=self::getApiInfo()["apiKey"];
4481
	#$conf["key"]=self::getApiInfo()["apiKey"];
3894
	#參考資料:
4482
	#參考資料:
3895
	#無.
-
 
-
 
4483
	#https://zerossl.com/documentation/api/verify-domains/
3896
	#備註:
4484
	#備註:
3897
	#無.
4485
	#無.
3898
	*/
4486
	*/
3899
	public static function verifyDomain(&$conf){
4487
	public static function verifyDomain(&$conf){
3900
	
4488
	
Line 3960... Line 4548...
3960
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4548
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3961
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
4549
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
3962
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
4550
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3963
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
4551
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3964
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4552
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3965
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["csrPath"],self::getApiInfo()["apiKey"]);
4553
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
3966
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4554
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3967
		#$conf["arrayCountEqualCheck"][]=array();
4555
		#$conf["arrayCountEqualCheck"][]=array();
3968
		#參考資料來源:
4556
		#參考資料來源:
3969
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4557
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3970
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4558
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
Line 4019... Line 4607...
4019
		#$result["cookie"],cookie檔案的位置與名稱.
4607
		#$result["cookie"],cookie檔案的位置與名稱.
4020
		#$result["cmd"],執行的command.
4608
		#$result["cmd"],執行的command.
4021
		#$result["argu],使用的參數.
4609
		#$result["argu],使用的參數.
4022
		#必填參數:
4610
		#必填參數:
4023
		#$conf["url"],字串,目標url.
4611
		#$conf["url"],字串,目標url.
4024
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"]."/".$conf["id"]."/challenges";
4612
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
4025
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4613
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4026
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
4614
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
4027
		#可省略參數:
4615
		#可省略參數:
4028
		#$conf["header"],字串陣列,要傳送的header.
4616
		#$conf["header"],字串陣列,要傳送的header.
4029
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
4617
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
Line 4067... Line 4655...
4067
			}#if end
4655
			}#if end
4068
 
4656
 
4069
		#設置curl的詳細資訊
4657
		#設置curl的詳細資訊
4070
		$result["curl_verbose_info"]=$curlCmd;
4658
		$result["curl_verbose_info"]=$curlCmd;
4071
 
4659
 
-
 
4660
		#驗證結果是否為 json
-
 
4661
		$json_validate=json_validate($curlCmd["fullContent"]);
-
 
4662
 
-
 
4663
		#如果回應不是 json
-
 
4664
		if(!$json_validate){
-
 
4665
		
-
 
4666
			#設置錯誤識別
-
 
4667
			$result["status"]="false";
-
 
4668
 
-
 
4669
			#設置錯誤訊息
-
 
4670
			$result["error"]=$curlCmd;
-
 
4671
 
-
 
4672
			#回傳結果
-
 
4673
			return $result;
-
 
4674
		
-
 
4675
			}#if end
-
 
4676
 
-
 
4677
		#設置json string結果
-
 
4678
		$result["content"]=$curlCmd["fullContent"];
-
 
4679
 
-
 
4680
		#解析json
-
 
4681
		$jsonRes=json_decode($result["content"]);
-
 
4682
		
-
 
4683
		#如果沒有 status
4072
		/* 範例 response json content
4684
		if(!isset($jsonRes->status)){
-
 
4685
		
-
 
4686
			#設置錯誤識別
-
 
4687
			$result["status"]="false";
-
 
4688
 
-
 
4689
			#設置錯誤訊息
-
 
4690
			$result["error"]=$curlCmd;
-
 
4691
 
-
 
4692
			#回傳結果
-
 
4693
			return $result;
-
 
4694
		
-
 
4695
			}#if end
-
 
4696
		
-
 
4697
		#如果是 "pending_validation"
-
 
4698
		if($json->status==="pending_validation"){
4073
		
4699
		
-
 
4700
			#do nothing
-
 
4701
		
-
 
4702
			}#if end
-
 
4703
			
-
 
4704
		#反之如果為 "issued"
-
 
4705
		else if($json->status==="issued"){
-
 
4706
		
-
 
4707
			#do nothing
-
 
4708
		
-
 
4709
			}#else 
-
 
4710
			
-
 
4711
		#反之
-
 
4712
		else{
-
 
4713
		
-
 
4714
			#設置錯誤識別
-
 
4715
			$result["status"]="false";
-
 
4716
 
-
 
4717
			#設置錯誤訊息
-
 
4718
			$result["error"]=$curlCmd;
-
 
4719
 
-
 
4720
			#回傳結果
-
 
4721
			return $result;
-
 
4722
		
-
 
4723
			}#else end
-
 
4724
			
-
 
4725
		
-
 
4726
		#設置執行正常
-
 
4727
		$result["status"]="true";
-
 
4728
	
-
 
4729
		#回傳結果
-
 
4730
		return $result;
-
 
4731
	
-
 
4732
		}#function verifyDomain end
-
 
4733
 
-
 
4734
	/*
-
 
4735
	#函式說明:
-
 
4736
	#取得CSR在zerossl上的狀態
-
 
4737
	#回傳結果:
-
 
4738
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
4739
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
4740
	#$result["function"],當前執行的函式名稱.
-
 
4741
	#$result["argu"],所使用的參數.
-
 
4742
	#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
4743
	#$result["content"],結果json字串.
-
 
4744
	#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
-
 
4745
	#必填參數:
-
 
4746
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
-
 
4747
	$conf["id"]="";
-
 
4748
	#可省略參數:
-
 
4749
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
4750
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
-
 
4751
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
4752
	#$conf["key"]=self::getApiInfo()["apiKey"];
-
 
4753
	#參考資料:
-
 
4754
	#https://zerossl.com/documentation/api/get-certificate/
-
 
4755
	#備註:
-
 
4756
	#無.
-
 
4757
	*/
-
 
4758
	public static function getCertSta(&$conf){
-
 
4759
	
-
 
4760
		#初始化要回傳的結果
-
 
4761
		$result=array();
-
 
4762
 
-
 
4763
		#設置當其函數名稱
-
 
4764
		$result["function"]=__FUNCTION__;
-
 
4765
 
-
 
4766
		#如果 $conf 不為陣列
-
 
4767
		if(gettype($conf)!="array"){
-
 
4768
 
-
 
4769
			#設置執行失敗
-
 
4770
			$result["status"]="false";
-
 
4771
 
-
 
4772
			#設置執行錯誤訊息
-
 
4773
			$result["error"][]="\$conf變數須為陣列形態";
-
 
4774
 
-
 
4775
			#如果傳入的參數為 null
-
 
4776
			if($conf==null){
-
 
4777
 
-
 
4778
				#設置執行錯誤訊息
-
 
4779
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
4780
 
-
 
4781
				}#if end
-
 
4782
 
-
 
4783
			#回傳結果
-
 
4784
			return $result;
-
 
4785
 
-
 
4786
			}#if end
-
 
4787
 
-
 
4788
		#取得參數
-
 
4789
		$result["argu"]=$conf;
-
 
4790
 
-
 
4791
		#檢查參數
-
 
4792
		#函式說明:
-
 
4793
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
-
 
4794
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
4795
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
4796
		#$result["function"],當前執行的函式名稱.
-
 
4797
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
4798
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
4799
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
4800
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
4801
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
4802
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
4803
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
4804
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
4805
		#必填寫的參數:
-
 
4806
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
4807
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
4808
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
4809
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
-
 
4810
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
-
 
4811
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
-
 
4812
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
4813
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
4814
		#可以省略的參數:
-
 
4815
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
4816
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
-
 
4817
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
-
 
4818
		#$conf["skipableVariableCanNotBeEmpty"]=array();
-
 
4819
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
4820
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
-
 
4821
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
4822
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
-
 
4823
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
4824
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
-
 
4825
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
4826
		#$conf["arrayCountEqualCheck"][]=array();
-
 
4827
		#參考資料來源:
-
 
4828
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
4829
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
4830
		unset($conf["variableCheck::checkArguments"]);
-
 
4831
 
-
 
4832
		#如果檢查失敗
-
 
4833
		if($checkArguments["status"]==="false"){
-
 
4834
 
-
 
4835
			#設置錯誤識別
-
 
4836
			$result["status"]="false";
-
 
4837
 
-
 
4838
			#設置錯誤訊息
-
 
4839
			$result["error"]=$checkArguments;
-
 
4840
 
-
 
4841
			#回傳結果
-
 
4842
			return $result;
-
 
4843
 
-
 
4844
			}#if end
-
 
4845
 
-
 
4846
		#如果檢查不通過
-
 
4847
		if($checkArguments["passed"]==="false"){
-
 
4848
 
-
 
4849
			#設置錯誤識別
-
 
4850
			$result["status"]="false";
-
 
4851
 
-
 
4852
			#設置錯誤訊息
-
 
4853
			$result["error"]=$checkArguments;
-
 
4854
 
-
 
4855
			#回傳結果
-
 
4856
			return $result;
-
 
4857
 
-
 
4858
			}#if end
-
 
4859
			
-
 
4860
		#函式說明:
-
 
4861
		#運行curl cmd
-
 
4862
		#回傳結果:
-
 
4863
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
4864
		#$result["error"],錯誤訊息陣列.
-
 
4865
		#$result["function"],當前執行的函式名稱.
-
 
4866
		#$result["founded"],識別網址找不找得到.
-
 
4867
		#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
-
 
4868
		#$result["fullContent"],取得回應的完整字串內容.
-
 
4869
		#$result["cookie"],cookie檔案的位置與名稱.
-
 
4870
		#$result["cmd"],執行的command.
-
 
4871
		#$result["argu],使用的參數.
-
 
4872
		#必填參數:
-
 
4873
		#$conf["url"],字串,目標url.
-
 
4874
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
-
 
4875
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
4876
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
-
 
4877
		#可省略參數:
-
 
4878
		#$conf["header"],字串陣列,要傳送的header.
-
 
4879
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
-
 
4880
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
-
 
4881
		#$conf["allowAnySSLcertificate"]="";
-
 
4882
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
-
 
4883
		#$conf["postVar"]=array();
-
 
4884
		#$conf["rawPost"]="字串",要傳送的raw post內容.
-
 
4885
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
-
 
4886
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
-
 
4887
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
-
 
4888
		#$conf["agent"],字串,user agent的名稱.
-
 
4889
		#$conf["agent"]="";
-
 
4890
		#$conf["cookie"],字串,cookie位置與檔案位置.
-
 
4891
		#$conf["cookie"]="";
-
 
4892
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
-
 
4893
		#$conf["forceNewCookie"]="";
-
 
4894
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
-
 
4895
		#$conf["inBg"]="true";
-
 
4896
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
-
 
4897
		#$conf["bgInProc"]="false";
-
 
4898
		#參考資料:
-
 
4899
		#無.
-
 
4900
		#備註:
-
 
4901
		#無.
-
 
4902
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
-
 
4903
		unset($conf["catchWebContent::curlCmd"]);
-
 
4904
 
-
 
4905
		#如果異常
-
 
4906
		if($curlCmd["status"]==="false"){
-
 
4907
 
-
 
4908
			#設置錯誤識別
-
 
4909
			$result["status"]="false";
-
 
4910
 
-
 
4911
			#設置錯誤訊息
-
 
4912
			$result["error"]=$curlCmd;
-
 
4913
 
-
 
4914
			#回傳結果
-
 
4915
			return $result;
-
 
4916
 
-
 
4917
			}#if end
-
 
4918
 
-
 
4919
		#設置curl的詳細資訊
-
 
4920
		$result["curl_verbose_info"]=$curlCmd;
-
 
4921
 
-
 
4922
		#驗證結果是否為 json
-
 
4923
		$json_validate=json_validate($curlCmd["fullContent"]);
-
 
4924
 
-
 
4925
		#如果回應不是 json
-
 
4926
		if(!$json_validate){
-
 
4927
		
-
 
4928
			#設置錯誤識別
-
 
4929
			$result["status"]="false";
-
 
4930
 
-
 
4931
			#設置錯誤訊息
-
 
4932
			$result["error"]=$curlCmd;
-
 
4933
 
-
 
4934
			#回傳結果
-
 
4935
			return $result;
-
 
4936
		
-
 
4937
			}#if end
-
 
4938
 
-
 
4939
		#設置json string結果
-
 
4940
		$result["content"]=$curlCmd["fullContent"];
-
 
4941
 
-
 
4942
		#解析json
-
 
4943
		$jsonRes=json_decode($result["content"]);
-
 
4944
		
-
 
4945
		#如果沒有 status
-
 
4946
		if(!isset($jsonRes->status)){
-
 
4947
		
-
 
4948
			#設置錯誤識別
-
 
4949
			$result["status"]="false";
-
 
4950
 
-
 
4951
			#設置錯誤訊息
-
 
4952
			$result["error"]=$curlCmd;
-
 
4953
 
-
 
4954
			#回傳結果
-
 
4955
			return $result;
-
 
4956
		
-
 
4957
			}#if end
-
 
4958
		
-
 
4959
		#取得csr在zerossl上的狀態
-
 
4960
		$result["cerStatus"]=$jsonRes->status;
-
 
4961
	
-
 
4962
		#設置執行正常
-
 
4963
		$result["status"]="true";
-
 
4964
	
-
 
4965
		#回傳結果
-
 
4966
		return $result;
-
 
4967
	
-
 
4968
		}#function getCertSta end
-
 
4969
		
-
 
4970
	/*
-
 
4971
	#函式說明:
-
 
4972
	#取得在zerossl上的CSR清單
-
 
4973
	#回傳結果:
-
 
4974
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
4975
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
4976
	#$result["function"],當前執行的函式名稱.
-
 
4977
	#$result["argu"],所使用的參數.
-
 
4978
	#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
4979
	#$result["content"],結果json字串.
-
 
4980
	#$result["tCount"],總共的資料筆數.
-
 
4981
	#$result["count"],該頁的筆數.
-
 
4982
	#$result["page"],當前的頁碼.
-
 
4983
	#$result["certs"],陣列,certificates清單,key為certificate的id.
-
 
4984
	#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
-
 
4985
	#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
-
 
4986
	#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
-
 
4987
	#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
-
 
4988
	#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
-
 
4989
	#必填參數:
-
 
4990
	#無
-
 
4991
	#可省略參數:
-
 
4992
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
4993
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
-
 
4994
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
4995
	#$conf["key"]=self::getApiInfo()["apiKey"];
-
 
4996
	#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
-
 
4997
	#$conf["cerStatus"]="";
-
 
4998
	#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
-
 
4999
	#$conf["cerType"]="";
-
 
5000
	#$conf["search"],字串,透過certificate包含的domain來搜尋.
-
 
5001
	#$conf["search"]="";
-
 
5002
	#$conf["limit"],字串,一頁要多少筆,預設為100筆.
-
 
5003
	#$conf["limit"]="";
-
 
5004
	#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
-
 
5005
	#$conf["page"]="";
-
 
5006
	#參考資料:
-
 
5007
	#https://zerossl.com/documentation/api/list-certificates/
-
 
5008
	#備註:
-
 
5009
	#無.
-
 
5010
	*/
-
 
5011
	public static function getCertList(&$conf){
-
 
5012
	
-
 
5013
		#初始化要回傳的結果
-
 
5014
		$result=array();
-
 
5015
 
-
 
5016
		#設置當其函數名稱
-
 
5017
		$result["function"]=__FUNCTION__;
-
 
5018
 
-
 
5019
		#如果 $conf 不為陣列
-
 
5020
		if(gettype($conf)!="array"){
-
 
5021
 
-
 
5022
			#設置執行失敗
-
 
5023
			$result["status"]="false";
-
 
5024
 
-
 
5025
			#設置執行錯誤訊息
-
 
5026
			$result["error"][]="\$conf變數須為陣列形態";
-
 
5027
 
-
 
5028
			#如果傳入的參數為 null
-
 
5029
			if($conf==null){
-
 
5030
 
-
 
5031
				#設置執行錯誤訊息
-
 
5032
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
5033
 
-
 
5034
				}#if end
-
 
5035
 
-
 
5036
			#回傳結果
-
 
5037
			return $result;
-
 
5038
 
-
 
5039
			}#if end
-
 
5040
 
-
 
5041
		#取得參數
-
 
5042
		$result["argu"]=$conf;
-
 
5043
 
-
 
5044
		#檢查參數
-
 
5045
		#函式說明:
-
 
5046
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
-
 
5047
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5048
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
5049
		#$result["function"],當前執行的函式名稱.
-
 
5050
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
5051
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
5052
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
5053
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
5054
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
5055
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
5056
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
5057
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
5058
		#必填寫的參數:
-
 
5059
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
5060
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
5061
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
5062
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
-
 
5063
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
-
 
5064
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
-
 
5065
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
5066
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
5067
		#可以省略的參數:
-
 
5068
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
5069
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
-
 
5070
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
-
 
5071
		#$conf["skipableVariableCanNotBeEmpty"]=array();
-
 
5072
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
5073
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
-
 
5074
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
5075
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
-
 
5076
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
5077
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
-
 
5078
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
5079
		#$conf["arrayCountEqualCheck"][]=array();
-
 
5080
		#參考資料來源:
-
 
5081
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
5082
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
5083
		unset($conf["variableCheck::checkArguments"]);
-
 
5084
 
-
 
5085
		#如果檢查失敗
-
 
5086
		if($checkArguments["status"]==="false"){
-
 
5087
 
-
 
5088
			#設置錯誤識別
-
 
5089
			$result["status"]="false";
-
 
5090
 
-
 
5091
			#設置錯誤訊息
-
 
5092
			$result["error"]=$checkArguments;
-
 
5093
 
-
 
5094
			#回傳結果
-
 
5095
			return $result;
-
 
5096
 
-
 
5097
			}#if end
-
 
5098
 
-
 
5099
		#如果檢查不通過
-
 
5100
		if($checkArguments["passed"]==="false"){
-
 
5101
 
-
 
5102
			#設置錯誤識別
-
 
5103
			$result["status"]="false";
-
 
5104
 
-
 
5105
			#設置錯誤訊息
-
 
5106
			$result["error"]=$checkArguments;
-
 
5107
 
-
 
5108
			#回傳結果
-
 
5109
			return $result;
-
 
5110
 
-
 
5111
			}#if end
-
 
5112
		
-
 
5113
		#預設網址
-
 
5114
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/?access_key=".$conf["key"];
-
 
5115
		
-
 
5116
		#如果有設置 cerStatus
-
 
5117
		if(isset($conf["cerStatus"])){
-
 
5118
		
-
 
5119
			#設置 certificate_status 
-
 
5120
			$url=$url."?certificate_status=".urlencode($conf["cerStatus"]);
-
 
5121
		
-
 
5122
			}#if end
-
 
5123
			
-
 
5124
		#如果有設置 cerType
-
 
5125
		if(isset($conf["cerType"])){
-
 
5126
		
-
 
5127
			#設置 certificate_type
-
 
5128
			$url=$url."?certificate_type=".$conf["cerType"];
-
 
5129
		
-
 
5130
			}#if end
-
 
5131
			
-
 
5132
		#如果有設置 search
-
 
5133
		if(isset($conf["search"])){
-
 
5134
		
-
 
5135
			#設置 search
-
 
5136
			$url=$url."?search=".urlencode($conf["search"]);
-
 
5137
		
-
 
5138
			}#if end
-
 
5139
			
-
 
5140
		#如果有設置 limit
-
 
5141
		if(isset($conf["limit"])){
-
 
5142
		
-
 
5143
			#設置 search
-
 
5144
			$url=$url."?limit=".$conf["limit"];
-
 
5145
		
-
 
5146
			}#if end
-
 
5147
			
-
 
5148
		#如果有設置 page
-
 
5149
		if(isset($conf["page"])){
-
 
5150
		
-
 
5151
			#設置 search
-
 
5152
			$url=$url."?page=".$conf["page"];
-
 
5153
		
-
 
5154
			}#if end
-
 
5155
		
-
 
5156
		#函式說明:
-
 
5157
		#運行curl cmd
-
 
5158
		#回傳結果:
-
 
5159
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5160
		#$result["error"],錯誤訊息陣列.
-
 
5161
		#$result["function"],當前執行的函式名稱.
-
 
5162
		#$result["founded"],識別網址找不找得到.
-
 
5163
		#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
-
 
5164
		#$result["fullContent"],取得回應的完整字串內容.
-
 
5165
		#$result["cookie"],cookie檔案的位置與名稱.
-
 
5166
		#$result["cmd"],執行的command.
-
 
5167
		#$result["argu],使用的參數.
-
 
5168
		#必填參數:
-
 
5169
		#$conf["url"],字串,目標url.
-
 
5170
		$conf["catchWebContent::curlCmd"]["url"]=$url;
-
 
5171
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
5172
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
-
 
5173
		#可省略參數:
-
 
5174
		#$conf["header"],字串陣列,要傳送的header.
-
 
5175
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
-
 
5176
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
-
 
5177
		#$conf["allowAnySSLcertificate"]="";
-
 
5178
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
-
 
5179
		#$conf["postVar"]=array();
-
 
5180
		#$conf["rawPost"]="字串",要傳送的raw post內容.
-
 
5181
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
-
 
5182
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
-
 
5183
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
-
 
5184
		#$conf["agent"],字串,user agent的名稱.
-
 
5185
		#$conf["agent"]="";
-
 
5186
		#$conf["cookie"],字串,cookie位置與檔案位置.
-
 
5187
		#$conf["cookie"]="";
-
 
5188
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
-
 
5189
		#$conf["forceNewCookie"]="";
-
 
5190
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
-
 
5191
		#$conf["inBg"]="true";
-
 
5192
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
-
 
5193
		#$conf["bgInProc"]="false";
-
 
5194
		#參考資料:
-
 
5195
		#無.
-
 
5196
		#備註:
-
 
5197
		#無.
-
 
5198
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
-
 
5199
		unset($conf["catchWebContent::curlCmd"]);
-
 
5200
 
-
 
5201
		#如果異常
-
 
5202
		if($curlCmd["status"]==="false"){
-
 
5203
 
-
 
5204
			#設置錯誤識別
-
 
5205
			$result["status"]="false";
-
 
5206
 
-
 
5207
			#設置錯誤訊息
-
 
5208
			$result["error"]=$curlCmd;
-
 
5209
 
-
 
5210
			#回傳結果
-
 
5211
			return $result;
-
 
5212
 
-
 
5213
			}#if end
-
 
5214
 
-
 
5215
		#設置curl的詳細資訊
-
 
5216
		$result["curl_verbose_info"]=$curlCmd;
-
 
5217
 
-
 
5218
		#驗證結果是否為 json
-
 
5219
		$json_validate=json_validate($curlCmd["fullContent"]);
-
 
5220
 
-
 
5221
		#如果回應不是 json
-
 
5222
		if(!$json_validate){
-
 
5223
		
-
 
5224
			#設置錯誤識別
-
 
5225
			$result["status"]="false";
-
 
5226
 
-
 
5227
			#設置錯誤訊息
-
 
5228
			$result["error"]=$curlCmd;
-
 
5229
 
-
 
5230
			#回傳結果
-
 
5231
			return $result;
-
 
5232
		
-
 
5233
			}#if end
-
 
5234
 
-
 
5235
		#設置json string結果
-
 
5236
		$result["content"]=$curlCmd["fullContent"];
-
 
5237
 
-
 
5238
		/* json response 範例
-
 
5239
		{
-
 
5240
			"total_count": 11,
-
 
5241
			"result_count": 10,
-
 
5242
			"page": 1,
-
 
5243
			"limit": 10,
-
 
5244
			"acmeUsageLevel": "LOW",
-
 
5245
			"isAcmeLocked": false,
-
 
5246
			"results": 
-
 
5247
			[
-
 
5248
				{
-
 
5249
					"id": "a856a39a1c3ad0s8asa606g37667d221",
-
 
5250
					"type": "1",
-
 
5251
					"common_name": "domain.com",
-
 
5252
					"additional_domains": "www.domain.com",
-
 
5253
					"created": "2020-04-29 09:04:19",
-
 
5254
					"expires": "2020-07-28 00:00:00",
-
 
5255
					"status": "draft",
-
 
5256
					"validation_type": null,
-
 
5257
					"validation_emails": null,
-
 
5258
					"replacement_for": "",
-
 
5259
					"fingerprint_sha1": null,
-
 
5260
					"brand_validation": null,
-
 
5261
					"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
-
 
5262
					"validation":
-
 
5263
					{
-
 
5264
						"email_validation":
-
 
5265
						{
-
 
5266
							"domain.com":
-
 
5267
							[
-
 
5268
								"admin@domain.com",
-
 
5269
								"administrator@domain.com",
-
 
5270
								"hostmaster@domain.com",
-
 
5271
								"postmaster@domain.com",
-
 
5272
								"webmaster@domain.com"
-
 
5273
							]
-
 
5274
						},
-
 
5275
						"other_methods": 
-
 
5276
						{
-
 
5277
							"domain.com":
-
 
5278
							{
-
 
5279
								"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
-
 
5280
								"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
-
 
5281
								"file_validation_content":
-
 
5282
								[
-
 
5283
									"2B449B722B449B729394793947",
-
 
5284
									"comodoca.com",
-
 
5285
									"4bad7360c7076ba"
-
 
5286
								],
-
 
5287
								"cname_validation_p1": "2B449B7293947.domain.com",
-
 
5288
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
-
 
5289
							},
-
 
5290
							"www.domain.com":
-
 
5291
							{
-
 
5292
								"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
-
 
5293
								"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",   
-
 
5294
								"file_validation_content":
-
 
5295
								[
-
 
5296
									"2B449B722B449B729394793947",
-
 
5297
									"comodoca.com",
-
 
5298
									"4bad7360c7076ba"
-
 
5299
								],
-
 
5300
								"cname_validation_p1": "2B449B7293947.www.domain.com",
-
 
5301
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
-
 
5302
							}
-
 
5303
						}
-
 
5304
					}
-
 
5305
				},
-
 
5306
				{
-
 
5307
					...
-
 
5308
				}
-
 
5309
			]
-
 
5310
		}
4074
		*/
5311
		*/
4075
 
5312
 
-
 
5313
		#解析json
-
 
5314
		$jsonRes=json_decode($result["content"]);
-
 
5315
		
-
 
5316
		#總共的資料筆數
-
 
5317
		$result["tCount"]=$jsonRes->total_count;
-
 
5318
		
-
 
5319
		#取得該頁的筆數
-
 
5320
		$result["count"]=$jsonRes->result_count;
-
 
5321
		
-
 
5322
		#取得certificate清單
-
 
5323
		$cers=$jsonRes->results;
-
 
5324
		
-
 
5325
		#針對每個certificate
-
 
5326
		foreach($certs as $index => $cert){
-
 
5327
		
-
 
5328
			#初始化暫存的陣列
-
 
5329
			$tmpA=array();
-
 
5330
			
-
 
5331
			#儲存 cert id
-
 
5332
			#$tmpA["id"]=$cert->id;
-
 
5333
			
-
 
5334
			#儲存 主要包含的 domain name
-
 
5335
			$tmpA["cname"]=$cert->common_name;
-
 
5336
			
-
 
5337
			#儲存額外包含的 domain name
-
 
5338
			$tmpA["anames"]=$cert->additional_domains;
-
 
5339
			
-
 
5340
			#最後有效年月日,格式為"2020-07-28 00:00:00".
-
 
5341
			$tmpA["expiresYMD"]=$cert->expires;
-
 
5342
			
-
 
5343
			#產生對於當前系統時間的差距(秒數)
-
 
5344
			#函式說明:
-
 
5345
			#計算時間點距離1970/01/01多少秒,亦即unixtime.
-
 
5346
			#回傳結果:
-
 
5347
			#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
-
 
5348
			#$result["error"],錯誤訊息陣列.
-
 
5349
			#$result["content"],時間點距離1970/01/01的多少秒.
-
 
5350
			#$result["argu"],使用的參數.
-
 
5351
			#$result["unixtime"],執行本函式時的unixtime.
-
 
5352
			#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
-
 
5353
			#必填參數:
-
 
5354
			#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
-
 
5355
			$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
-
 
5356
			#可省略參數:
-
 
5357
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
-
 
5358
			#$conf["UTC"]="false";
-
 
5359
			#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
-
 
5360
			$conf["time::caculateTimeAmount"]["replace0"]="false";
-
 
5361
			#參考資料:
-
 
5362
			#無.
-
 
5363
			#備註:
-
 
5364
			#無.
-
 
5365
			$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
-
 
5366
			unset($conf["time::caculateTimeAmount"]);
-
 
5367
		
-
 
5368
			#如果執行異常
-
 
5369
			if($caculateTimeAmount["passed"]==="false"){
-
 
5370
 
-
 
5371
				#設置錯誤識別
-
 
5372
				$result["status"]="false";
-
 
5373
 
-
 
5374
				#設置錯誤訊息
-
 
5375
				$result["error"]=$caculateTimeAmount;
-
 
5376
 
-
 
5377
				#回傳結果
-
 
5378
				return $result;
-
 
5379
 
-
 
5380
				}#if end
-
 
5381
				
-
 
5382
			#儲存還要多少秒要過期
-
 
5383
			$tmpA["expiresIn"]=$caculateTimeAmount["unixtime"]-time();
-
 
5384
		
-
 
5385
			#憑證的狀態
-
 
5386
			$tmpA["status"]=$cert->status;
-
 
5387
			
-
 
5388
			#儲存要回傳的 cers 清單,key為cert的id.
-
 
5389
			$result["cers"][$cert->id]=$tmpA;
-
 
5390
		
-
 
5391
			}#foreach end
-
 
5392
	
-
 
5393
		#設置執行正常
-
 
5394
		$result["status"]="true";
-
 
5395
	
-
 
5396
		#回傳結果
-
 
5397
		return $result;
-
 
5398
	
-
 
5399
		}#function getCertList end
-
 
5400
		
-
 
5401
	/*
-
 
5402
	#函式說明:
-
 
5403
	#下載certificate.
-
 
5404
	#回傳結果:
-
 
5405
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5406
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
5407
	#$result["function"],當前執行的函式名稱.
-
 
5408
	#$result["argu"],所使用的參數.
-
 
5409
	#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
5410
	#$result["content"],結果json字串.
-
 
5411
	#$result["certificate.crt"],字串,certificate.crt的內容.
-
 
5412
	#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
-
 
5413
	#必填參數:
-
 
5414
	#無.
-
 
5415
	#可省略參數:
-
 
5416
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
5417
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
-
 
5418
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
5419
	#$conf["key"]=self::getApiInfo()["apiKey"];
-
 
5420
	#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
-
 
5421
	#$conf["id"]="";
-
 
5422
	#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
-
 
5423
	#$conf["cname"]="";
-
 
5424
	#參考資料:
-
 
5425
	#https://zerossl.com/documentation/api/download-certificate-inline/
-
 
5426
	#備註:
-
 
5427
	#無.
-
 
5428
	*/
-
 
5429
	public static function getCert(&$conf){
-
 
5430
	
-
 
5431
		#初始化要回傳的結果
-
 
5432
		$result=array();
-
 
5433
 
-
 
5434
		#設置當其函數名稱
-
 
5435
		$result["function"]=__FUNCTION__;
-
 
5436
 
-
 
5437
		#如果 $conf 不為陣列
-
 
5438
		if(gettype($conf)!="array"){
-
 
5439
 
-
 
5440
			#設置執行失敗
-
 
5441
			$result["status"]="false";
-
 
5442
 
-
 
5443
			#設置執行錯誤訊息
-
 
5444
			$result["error"][]="\$conf變數須為陣列形態";
-
 
5445
 
-
 
5446
			#如果傳入的參數為 null
-
 
5447
			if($conf==null){
-
 
5448
 
-
 
5449
				#設置執行錯誤訊息
-
 
5450
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
5451
 
-
 
5452
				}#if end
-
 
5453
 
-
 
5454
			#回傳結果
-
 
5455
			return $result;
-
 
5456
 
-
 
5457
			}#if end
-
 
5458
 
-
 
5459
		#取得參數
-
 
5460
		$result["argu"]=$conf;
-
 
5461
 
-
 
5462
		#檢查參數
-
 
5463
		#函式說明:
-
 
5464
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
-
 
5465
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5466
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
5467
		#$result["function"],當前執行的函式名稱.
-
 
5468
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
5469
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
5470
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
5471
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
5472
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
5473
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
5474
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
5475
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
5476
		#必填寫的參數:
-
 
5477
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
5478
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
5479
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
5480
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
-
 
5481
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
-
 
5482
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
-
 
5483
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
5484
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
5485
		#可以省略的參數:
-
 
5486
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
5487
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
-
 
5488
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
-
 
5489
		#$conf["skipableVariableCanNotBeEmpty"]=array();
-
 
5490
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
5491
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
-
 
5492
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
5493
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
-
 
5494
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
5495
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
-
 
5496
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
5497
		#$conf["arrayCountEqualCheck"][]=array();
-
 
5498
		#參考資料來源:
-
 
5499
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
5500
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
5501
		unset($conf["variableCheck::checkArguments"]);
-
 
5502
 
-
 
5503
		#如果檢查失敗
-
 
5504
		if($checkArguments["status"]==="false"){
-
 
5505
 
-
 
5506
			#設置錯誤識別
-
 
5507
			$result["status"]="false";
-
 
5508
 
-
 
5509
			#設置錯誤訊息
-
 
5510
			$result["error"]=$checkArguments;
-
 
5511
 
-
 
5512
			#回傳結果
-
 
5513
			return $result;
-
 
5514
 
-
 
5515
			}#if end
-
 
5516
 
-
 
5517
		#如果檢查不通過
-
 
5518
		if($checkArguments["passed"]==="false"){
-
 
5519
 
-
 
5520
			#設置錯誤識別
-
 
5521
			$result["status"]="false";
-
 
5522
 
-
 
5523
			#設置錯誤訊息
-
 
5524
			$result["error"]=$checkArguments;
-
 
5525
 
-
 
5526
			#回傳結果
-
 
5527
			return $result;
-
 
5528
 
-
 
5529
			}#if end
-
 
5530
		
-
 
5531
		#如果有設置 id
-
 
5532
		if(isset($conf["id"])){
-
 
5533
		
-
 
5534
			#設置 id
-
 
5535
			$id=$conf["id"];
-
 
5536
		
-
 
5537
			}#if end
-
 
5538
			
-
 
5539
		#反之如果有設置 cname
-
 
5540
		else if(isset($conf["cname"])){
-
 
5541
		
-
 
5542
			#函式說明:
-
 
5543
			#取得在zerossl上的CSR清單
-
 
5544
			#回傳結果:
-
 
5545
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5546
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
5547
			#$result["function"],當前執行的函式名稱.
-
 
5548
			#$result["argu"],所使用的參數.
-
 
5549
			#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
5550
			#$result["content"],結果json字串.
-
 
5551
			#$result["tCound"],總共的資料筆數.
-
 
5552
			#$result["count"],該頁的筆數.
-
 
5553
			#$result["page"],當前的頁碼.
-
 
5554
			#$result["certs"],陣列,certificates清單,key為certificate的id.
-
 
5555
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
-
 
5556
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
-
 
5557
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
-
 
5558
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
-
 
5559
			#必填參數:
-
 
5560
			#無
-
 
5561
			#可省略參數:
-
 
5562
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
5563
			#$conf["apiDomain"]=self::getApiInfo()["doamin"];
-
 
5564
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
5565
			#$conf["key"]=self::getApiInfo()["apiKey"];
-
 
5566
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
-
 
5567
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
-
 
5568
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
-
 
5569
			#$conf["cerType"]="";
-
 
5570
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
-
 
5571
			$conf["zerossl::getCertList"]["search"]=$conf["cname"];
-
 
5572
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
-
 
5573
			#$conf["limit"]="";
-
 
5574
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
-
 
5575
			#$conf["page"]="";
-
 
5576
			#參考資料:
-
 
5577
			#https://zerossl.com/documentation/api/get-certificate/
-
 
5578
			#備註:
-
 
5579
			#無.
-
 
5580
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
-
 
5581
			unset($conf["zerossl::getCertList"]);
-
 
5582
		
-
 
5583
			#如果檢查失敗
-
 
5584
			if($getCertList["status"]==="false"){
-
 
5585
 
-
 
5586
				#設置錯誤識別
-
 
5587
				$result["status"]="false";
-
 
5588
 
-
 
5589
				#設置錯誤訊息
-
 
5590
				$result["error"]=$getCertList;
-
 
5591
 
-
 
5592
				#回傳結果
-
 
5593
				return $result;
-
 
5594
 
-
 
5595
				}#if end
-
 
5596
			
-
 
5597
			#如果資料筆數大於0
-
 
5598
			if($getCertList["count"]>0){
-
 
5599
			
-
 
5600
				#取得第一筆
-
 
5601
				foreach($getCertList["certs"] as $cerId => $detail){
-
 
5602
				
-
 
5603
					#取得cettificate id
-
 
5604
					$id=$cerId;
-
 
5605
				
-
 
5606
					}#foreach end
-
 
5607
			
-
 
5608
				}#if end
-
 
5609
		
-
 
5610
			}#if end
-
 
5611
		
-
 
5612
		#預設網址
-
 
5613
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
-
 
5614
	
-
 
5615
		#函式說明:
-
 
5616
		#運行curl cmd
-
 
5617
		#回傳結果:
-
 
5618
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5619
		#$result["error"],錯誤訊息陣列.
-
 
5620
		#$result["function"],當前執行的函式名稱.
-
 
5621
		#$result["founded"],識別網址找不找得到.
-
 
5622
		#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
-
 
5623
		#$result["fullContent"],取得回應的完整字串內容.
-
 
5624
		#$result["cookie"],cookie檔案的位置與名稱.
-
 
5625
		#$result["cmd"],執行的command.
-
 
5626
		#$result["argu],使用的參數.
-
 
5627
		#必填參數:
-
 
5628
		#$conf["url"],字串,目標url.
-
 
5629
		$conf["catchWebContent::curlCmd"]["url"]=$url;
-
 
5630
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
5631
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
-
 
5632
		#可省略參數:
-
 
5633
		#$conf["header"],字串陣列,要傳送的header.
-
 
5634
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
-
 
5635
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
-
 
5636
		#$conf["allowAnySSLcertificate"]="";
-
 
5637
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
-
 
5638
		#$conf["postVar"]=array();
-
 
5639
		#$conf["rawPost"]="字串",要傳送的raw post內容.
-
 
5640
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
-
 
5641
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
-
 
5642
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
-
 
5643
		#$conf["agent"],字串,user agent的名稱.
-
 
5644
		#$conf["agent"]="";
-
 
5645
		#$conf["cookie"],字串,cookie位置與檔案位置.
-
 
5646
		#$conf["cookie"]="";
-
 
5647
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
-
 
5648
		#$conf["forceNewCookie"]="";
-
 
5649
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
-
 
5650
		#$conf["inBg"]="true";
-
 
5651
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
-
 
5652
		#$conf["bgInProc"]="false";
-
 
5653
		#參考資料:
-
 
5654
		#無.
-
 
5655
		#備註:
-
 
5656
		#無.
-
 
5657
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
-
 
5658
		unset($conf["catchWebContent::curlCmd"]);
-
 
5659
 
-
 
5660
		#如果異常
-
 
5661
		if($curlCmd["status"]==="false"){
-
 
5662
 
-
 
5663
			#設置錯誤識別
-
 
5664
			$result["status"]="false";
-
 
5665
 
-
 
5666
			#設置錯誤訊息
-
 
5667
			$result["error"]=$curlCmd;
-
 
5668
 
-
 
5669
			#回傳結果
-
 
5670
			return $result;
-
 
5671
 
-
 
5672
			}#if end
-
 
5673
 
-
 
5674
		#設置curl的詳細資訊
-
 
5675
		$result["curl_verbose_info"]=$curlCmd;
-
 
5676
 
-
 
5677
		#驗證結果是否為 json
-
 
5678
		$json_validate=json_validate($curlCmd["fullContent"]);
-
 
5679
 
-
 
5680
		#如果回應不是 json
-
 
5681
		if(!$json_validate){
-
 
5682
		
-
 
5683
			#設置錯誤識別
-
 
5684
			$result["status"]="false";
-
 
5685
 
-
 
5686
			#設置錯誤訊息
-
 
5687
			$result["error"]=$curlCmd;
-
 
5688
 
-
 
5689
			#回傳結果
-
 
5690
			return $result;
-
 
5691
		
-
 
5692
			}#if end
-
 
5693
 
-
 
5694
		#設置json string結果
-
 
5695
		$result["content"]=$curlCmd["fullContent"];
-
 
5696
		
-
 
5697
		#取得 json
-
 
5698
		$json=json_decode($curlCmd["fullContent"]);
-
 
5699
		
-
 
5700
		#取得certificate.crt的內容
-
 
5701
		$result["certificate.crt"]=$json->certificate.crt;
-
 
5702
		
-
 
5703
		#取得ca_bundle.crt的內容
-
 
5704
		$result["ca_bundle.crt"]=$json->ca_bundle.crt;
-
 
5705
		
-
 
5706
		#設置執行正常
-
 
5707
		$result["status"]="true";
-
 
5708
		
-
 
5709
		#回傳結果
-
 
5710
		return $result;
-
 
5711
	
-
 
5712
		}#function getCert end
-
 
5713
		
-
 
5714
	/*
-
 
5715
	#函式說明:
-
 
5716
	#請求廢除 issued zerossl certificate.
-
 
5717
	#回傳結果:
-
 
5718
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5719
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
5720
	#$result["function"],當前執行的函式名稱.
-
 
5721
	#$result["argu"],所使用的參數.
-
 
5722
	#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
5723
	#$result["content"],結果json字串.
-
 
5724
	#必填參數:
-
 
5725
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
-
 
5726
	$conf["id"]="";
-
 
5727
	#可省略參數:
-
 
5728
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
5729
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
-
 
5730
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
5731
	#$conf["key"]=self::getApiInfo()["apiKey"];
-
 
5732
	#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
-
 
5733
	#$conf["reason"]="";
-
 
5734
	#參考資料:
-
 
5735
	#https://zerossl.com/documentation/api/revoke-certificate/
-
 
5736
	#備註:
-
 
5737
	#無.
-
 
5738
	*/
-
 
5739
	public static function revokeCert(&$conf){
-
 
5740
	
-
 
5741
		#初始化要回傳的結果
-
 
5742
		$result=array();
-
 
5743
 
-
 
5744
		#設置當其函數名稱
-
 
5745
		$result["function"]=__FUNCTION__;
-
 
5746
 
-
 
5747
		#如果 $conf 不為陣列
-
 
5748
		if(gettype($conf)!="array"){
-
 
5749
 
-
 
5750
			#設置執行失敗
-
 
5751
			$result["status"]="false";
-
 
5752
 
-
 
5753
			#設置執行錯誤訊息
-
 
5754
			$result["error"][]="\$conf變數須為陣列形態";
-
 
5755
 
-
 
5756
			#如果傳入的參數為 null
-
 
5757
			if($conf==null){
-
 
5758
 
-
 
5759
				#設置執行錯誤訊息
-
 
5760
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
5761
 
-
 
5762
				}#if end
-
 
5763
 
-
 
5764
			#回傳結果
-
 
5765
			return $result;
-
 
5766
 
-
 
5767
			}#if end
-
 
5768
 
-
 
5769
		#取得參數
-
 
5770
		$result["argu"]=$conf;
-
 
5771
 
-
 
5772
		#檢查參數
-
 
5773
		#函式說明:
-
 
5774
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
-
 
5775
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5776
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
5777
		#$result["function"],當前執行的函式名稱.
-
 
5778
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
5779
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
5780
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
5781
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
5782
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
5783
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
5784
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
5785
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
5786
		#必填寫的參數:
-
 
5787
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
5788
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
5789
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
5790
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
-
 
5791
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
-
 
5792
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
-
 
5793
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
5794
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
5795
		#可以省略的參數:
-
 
5796
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
5797
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
-
 
5798
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
-
 
5799
		#$conf["skipableVariableCanNotBeEmpty"]=array();
-
 
5800
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
5801
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
-
 
5802
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
5803
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","status");
-
 
5804
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
5805
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
-
 
5806
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
5807
		#$conf["arrayCountEqualCheck"][]=array();
-
 
5808
		#參考資料來源:
-
 
5809
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
5810
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
5811
		unset($conf["variableCheck::checkArguments"]);
-
 
5812
 
-
 
5813
		#如果檢查失敗
-
 
5814
		if($checkArguments["status"]==="false"){
-
 
5815
 
-
 
5816
			#設置錯誤識別
-
 
5817
			$result["status"]="false";
-
 
5818
 
-
 
5819
			#設置錯誤訊息
-
 
5820
			$result["error"]=$checkArguments;
-
 
5821
 
-
 
5822
			#回傳結果
-
 
5823
			return $result;
-
 
5824
 
-
 
5825
			}#if end
-
 
5826
 
-
 
5827
		#如果檢查不通過
-
 
5828
		if($checkArguments["passed"]==="false"){
-
 
5829
 
-
 
5830
			#設置錯誤識別
-
 
5831
			$result["status"]="false";
-
 
5832
 
-
 
5833
			#設置錯誤訊息
-
 
5834
			$result["error"]=$checkArguments;
-
 
5835
 
-
 
5836
			#回傳結果
-
 
5837
			return $result;
-
 
5838
 
-
 
5839
			}#if end
-
 
5840
		
-
 
5841
		#url to call
-
 
5842
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
-
 
5843
		
-
 
5844
		#如果有設置 reason
-
 
5845
		if(isset($conf["reason"])){
-
 
5846
		
-
 
5847
			#設置reason
-
 
5848
			$reason="&reason=".$conf["reason"];
-
 
5849
			
-
 
5850
			#串接reason
-
 
5851
			$url=$url.$reason;
-
 
5852
		
-
 
5853
			}#if end
-
 
5854
			
-
 
5855
		#函式說明:
-
 
5856
		#運行curl cmd
-
 
5857
		#回傳結果:
-
 
5858
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5859
		#$result["error"],錯誤訊息陣列.
-
 
5860
		#$result["function"],當前執行的函式名稱.
-
 
5861
		#$result["founded"],識別網址找不找得到.
-
 
5862
		#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
-
 
5863
		#$result["fullContent"],取得回應的完整字串內容.
-
 
5864
		#$result["cookie"],cookie檔案的位置與名稱.
-
 
5865
		#$result["cmd"],執行的command.
-
 
5866
		#$result["argu],使用的參數.
-
 
5867
		#必填參數:
-
 
5868
		#$conf["url"],字串,目標url.
-
 
5869
		$conf["catchWebContent::curlCmd"]["url"]=$url;
-
 
5870
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
5871
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
-
 
5872
		#可省略參數:
-
 
5873
		#$conf["header"],字串陣列,要傳送的header.
-
 
5874
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
-
 
5875
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
-
 
5876
		#$conf["allowAnySSLcertificate"]="";
-
 
5877
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
-
 
5878
		#$conf["postVar"]=array();
-
 
5879
		#$conf["rawPost"]="字串",要傳送的raw post內容.
-
 
5880
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
-
 
5881
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
-
 
5882
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
-
 
5883
		#$conf["agent"],字串,user agent的名稱.
-
 
5884
		#$conf["agent"]="";
-
 
5885
		#$conf["cookie"],字串,cookie位置與檔案位置.
-
 
5886
		#$conf["cookie"]="";
-
 
5887
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
-
 
5888
		#$conf["forceNewCookie"]="";
-
 
5889
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
-
 
5890
		#$conf["inBg"]="true";
-
 
5891
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
-
 
5892
		#$conf["bgInProc"]="false";
-
 
5893
		#參考資料:
-
 
5894
		#無.
-
 
5895
		#備註:
-
 
5896
		#無.
-
 
5897
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
-
 
5898
		unset($conf["catchWebContent::curlCmd"]);
-
 
5899
 
-
 
5900
		#如果異常
-
 
5901
		if($curlCmd["status"]==="false"){
-
 
5902
 
-
 
5903
			#設置錯誤識別
-
 
5904
			$result["status"]="false";
-
 
5905
 
-
 
5906
			#設置錯誤訊息
-
 
5907
			$result["error"]=$curlCmd;
-
 
5908
 
-
 
5909
			#回傳結果
-
 
5910
			return $result;
-
 
5911
 
-
 
5912
			}#if end
-
 
5913
 
-
 
5914
		#設置curl的詳細資訊
-
 
5915
		$result["curl_verbose_info"]=$curlCmd;
-
 
5916
 
4076
		#驗證結果是否為 json
5917
		#驗證結果是否為 json
4077
		$json_validate=json_validate($curlCmd["fullContent"]);
5918
		$json_validate=json_validate($curlCmd["fullContent"]);
4078
 
5919
 
4079
		#如果回應不是 json
5920
		#如果回應不是 json
4080
		if(!$json_validate){
5921
		if(!$json_validate){
Line 4094... Line 5935...
4094
		$result["content"]=$curlCmd["fullContent"];
5935
		$result["content"]=$curlCmd["fullContent"];
4095
 
5936
 
4096
		#解析json
5937
		#解析json
4097
		$jsonRes=json_decode($result["content"]);
5938
		$jsonRes=json_decode($result["content"]);
4098
		
5939
		
-
 
5940
		#如果沒有要有的attr
-
 
5941
		if(!isset($jsonRes->success)){
-
 
5942
		
-
 
5943
			#設置錯誤識別
-
 
5944
			$result["status"]="false";
-
 
5945
 
-
 
5946
			#設置錯誤訊息
-
 
5947
			$result["error"]=$curlCmd;
-
 
5948
 
-
 
5949
			#回傳結果
-
 
5950
			return $result;
-
 
5951
		
-
 
5952
			}#if end
-
 
5953
			
-
 
5954
		#如果 success 不等於 1
-
 
5955
		if($jsonRes->success!==1){
-
 
5956
		
-
 
5957
			#設置錯誤識別
-
 
5958
			$result["status"]="false";
-
 
5959
 
-
 
5960
			#設置錯誤訊息
-
 
5961
			$result["error"]=$curlCmd;
-
 
5962
 
-
 
5963
			#回傳結果
-
 
5964
			return $result;
-
 
5965
		
-
 
5966
			}#if end
-
 
5967
			
4099
		#設置執行正常
5968
		#設置執行正常
4100
		$result["status"]="true";
5969
		$result["status"]="true";
4101
	
5970
	
4102
		#回傳結果
5971
		#回傳結果
4103
		return $result;
5972
		return $result;
4104
	
5973
	
-
 
5974
		}#function revokeCert end
-
 
5975
		
-
 
5976
	/*
-
 
5977
	#函式說明:
-
 
5978
	#請求取消 draft or unvalidated zerossl certificate.
-
 
5979
	#回傳結果:
-
 
5980
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
5981
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
5982
	#$result["function"],當前執行的函式名稱.
-
 
5983
	#$result["argu"],所使用的參數.
-
 
5984
	#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
5985
	#$result["content"],結果json字串.
-
 
5986
	#必填參數:
-
 
5987
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
-
 
5988
	$conf["id"]="";
-
 
5989
	#可省略參數:
-
 
5990
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
5991
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
-
 
5992
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
5993
	#$conf["key"]=self::getApiInfo()["apiKey"];
-
 
5994
	#參考資料:
-
 
5995
	#https://zerossl.com/documentation/api/revoke-certificate/
-
 
5996
	#備註:
-
 
5997
	#無.
-
 
5998
	*/
-
 
5999
	public static function cancelCert(&$conf){
-
 
6000
	
-
 
6001
		#初始化要回傳的結果
-
 
6002
		$result=array();
-
 
6003
 
-
 
6004
		#設置當其函數名稱
-
 
6005
		$result["function"]=__FUNCTION__;
-
 
6006
 
-
 
6007
		#如果 $conf 不為陣列
-
 
6008
		if(gettype($conf)!="array"){
-
 
6009
 
-
 
6010
			#設置執行失敗
-
 
6011
			$result["status"]="false";
-
 
6012
 
-
 
6013
			#設置執行錯誤訊息
-
 
6014
			$result["error"][]="\$conf變數須為陣列形態";
-
 
6015
 
-
 
6016
			#如果傳入的參數為 null
-
 
6017
			if($conf==null){
-
 
6018
 
-
 
6019
				#設置執行錯誤訊息
-
 
6020
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
6021
 
-
 
6022
				}#if end
-
 
6023
 
-
 
6024
			#回傳結果
-
 
6025
			return $result;
-
 
6026
 
-
 
6027
			}#if end
-
 
6028
 
-
 
6029
		#取得參數
-
 
6030
		$result["argu"]=$conf;
-
 
6031
 
-
 
6032
		#檢查參數
-
 
6033
		#函式說明:
-
 
6034
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
-
 
6035
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6036
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
6037
		#$result["function"],當前執行的函式名稱.
-
 
6038
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
6039
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
6040
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
6041
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
6042
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
6043
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
6044
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
6045
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
6046
		#必填寫的參數:
-
 
6047
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
6048
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
6049
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
6050
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
-
 
6051
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
-
 
6052
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
-
 
6053
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
6054
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
6055
		#可以省略的參數:
-
 
6056
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
6057
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
-
 
6058
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
-
 
6059
		#$conf["skipableVariableCanNotBeEmpty"]=array();
-
 
6060
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
6061
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
-
 
6062
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
6063
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
-
 
6064
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
6065
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
-
 
6066
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
6067
		#$conf["arrayCountEqualCheck"][]=array();
-
 
6068
		#參考資料來源:
-
 
6069
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
6070
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
6071
		unset($conf["variableCheck::checkArguments"]);
-
 
6072
 
-
 
6073
		#如果檢查失敗
-
 
6074
		if($checkArguments["status"]==="false"){
-
 
6075
 
-
 
6076
			#設置錯誤識別
-
 
6077
			$result["status"]="false";
-
 
6078
 
-
 
6079
			#設置錯誤訊息
-
 
6080
			$result["error"]=$checkArguments;
-
 
6081
 
-
 
6082
			#回傳結果
-
 
6083
			return $result;
-
 
6084
 
-
 
6085
			}#if end
-
 
6086
 
-
 
6087
		#如果檢查不通過
-
 
6088
		if($checkArguments["passed"]==="false"){
-
 
6089
 
-
 
6090
			#設置錯誤識別
-
 
6091
			$result["status"]="false";
-
 
6092
 
-
 
6093
			#設置錯誤訊息
-
 
6094
			$result["error"]=$checkArguments;
-
 
6095
 
-
 
6096
			#回傳結果
-
 
6097
			return $result;
-
 
6098
 
-
 
6099
			}#if end
-
 
6100
		
-
 
6101
		#url to call
-
 
6102
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
-
 
6103
			
-
 
6104
		#函式說明:
-
 
6105
		#運行curl cmd
-
 
6106
		#回傳結果:
-
 
6107
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6108
		#$result["error"],錯誤訊息陣列.
-
 
6109
		#$result["function"],當前執行的函式名稱.
-
 
6110
		#$result["founded"],識別網址找不找得到.
4105
		}#function verifyDomain end
6111
		#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
-
 
6112
		#$result["fullContent"],取得回應的完整字串內容.
-
 
6113
		#$result["cookie"],cookie檔案的位置與名稱.
-
 
6114
		#$result["cmd"],執行的command.
-
 
6115
		#$result["argu],使用的參數.
-
 
6116
		#必填參數:
-
 
6117
		#$conf["url"],字串,目標url.
-
 
6118
		$conf["catchWebContent::curlCmd"]["url"]=$url;
-
 
6119
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
6120
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
-
 
6121
		#可省略參數:
-
 
6122
		#$conf["header"],字串陣列,要傳送的header.
-
 
6123
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
-
 
6124
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
-
 
6125
		#$conf["allowAnySSLcertificate"]="";
-
 
6126
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
-
 
6127
		#$conf["postVar"]=array();
-
 
6128
		#$conf["rawPost"]="字串",要傳送的raw post內容.
-
 
6129
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
-
 
6130
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
-
 
6131
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
-
 
6132
		#$conf["agent"],字串,user agent的名稱.
-
 
6133
		#$conf["agent"]="";
-
 
6134
		#$conf["cookie"],字串,cookie位置與檔案位置.
-
 
6135
		#$conf["cookie"]="";
-
 
6136
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
-
 
6137
		#$conf["forceNewCookie"]="";
-
 
6138
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
-
 
6139
		#$conf["inBg"]="true";
-
 
6140
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
-
 
6141
		#$conf["bgInProc"]="false";
-
 
6142
		#參考資料:
-
 
6143
		#無.
-
 
6144
		#備註:
-
 
6145
		#無.
-
 
6146
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
-
 
6147
		unset($conf["catchWebContent::curlCmd"]);
-
 
6148
 
-
 
6149
		#如果異常
-
 
6150
		if($curlCmd["status"]==="false"){
-
 
6151
 
-
 
6152
			#設置錯誤識別
-
 
6153
			$result["status"]="false";
-
 
6154
 
-
 
6155
			#設置錯誤訊息
-
 
6156
			$result["error"]=$curlCmd;
-
 
6157
 
-
 
6158
			#回傳結果
-
 
6159
			return $result;
-
 
6160
 
-
 
6161
			}#if end
-
 
6162
 
-
 
6163
		#設置curl的詳細資訊
-
 
6164
		$result["curl_verbose_info"]=$curlCmd;
-
 
6165
 
-
 
6166
		#驗證結果是否為 json
-
 
6167
		$json_validate=json_validate($curlCmd["fullContent"]);
-
 
6168
 
-
 
6169
		#如果回應不是 json
-
 
6170
		if(!$json_validate){
-
 
6171
		
-
 
6172
			#設置錯誤識別
-
 
6173
			$result["status"]="false";
-
 
6174
 
-
 
6175
			#設置錯誤訊息
-
 
6176
			$result["error"]=$curlCmd;
-
 
6177
 
-
 
6178
			#回傳結果
-
 
6179
			return $result;
-
 
6180
		
-
 
6181
			}#if end
-
 
6182
 
-
 
6183
		#設置json string結果
-
 
6184
		$result["content"]=$curlCmd["fullContent"];
-
 
6185
 
-
 
6186
		#解析json
-
 
6187
		$jsonRes=json_decode($result["content"]);
-
 
6188
		
-
 
6189
		#如果沒有要有的attr
-
 
6190
		if(!isset($jsonRes->success)){
-
 
6191
		
-
 
6192
			#設置錯誤識別
-
 
6193
			$result["status"]="false";
-
 
6194
 
-
 
6195
			#設置錯誤訊息
-
 
6196
			$result["error"]=$curlCmd;
-
 
6197
 
-
 
6198
			#回傳結果
-
 
6199
			return $result;
-
 
6200
		
-
 
6201
			}#if end
-
 
6202
			
-
 
6203
		#如果 success 不等於 1
-
 
6204
		if($jsonRes->success!==1){
-
 
6205
		
-
 
6206
			#設置錯誤識別
-
 
6207
			$result["status"]="false";
-
 
6208
 
-
 
6209
			#設置錯誤訊息
-
 
6210
			$result["error"]=$curlCmd;
-
 
6211
 
-
 
6212
			#回傳結果
-
 
6213
			return $result;
-
 
6214
		
-
 
6215
			}#if end
-
 
6216
			
-
 
6217
		#設置執行正常
-
 
6218
		$result["status"]="true";
-
 
6219
	
-
 
6220
		#回傳結果
-
 
6221
		return $result;
-
 
6222
	
-
 
6223
		}#function cancelCert end
-
 
6224
		
-
 
6225
	/*
-
 
6226
	#函式說明:
-
 
6227
	#透過zerossl api確保ssl沒有過期.
-
 
6228
	#回傳結果:
-
 
6229
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6230
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
6231
	#$result["function"],當前執行的函式名稱.
-
 
6232
	#$result["argu"],所使用的參數.
-
 
6233
	#必填參數:
-
 
6234
	#$conf["cName"],陣列,每個ssl的common domain name.
-
 
6235
	$conf["cName"]=array();
-
 
6236
	#$conf["certInfo"],陣列,每個cName參數對應的憑證資訊,$conf["certInfo"][$i]["certPath"]為第$+1個cName的certifate.crt的檔案位置與名稱;$conf["certInfo"][$i]["pKey"]為第$i+1個cName的private key;$conf["certInfo"][$i]["caPath"]為第$i+1個cName的ca_bundle.crt的檔案位置與名稱;$conf["certInfo"][$i]["certWithCaPath"]為第$+1個cName的certifate.crt跟ca_bundle.crt內容合併後的檔案位置與名稱.
-
 
6237
	$conf["certInfo"]=array();
-
 
6238
	#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
-
 
6239
	$conf["rrFile"]=array();
-
 
6240
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
-
 
6241
	$conf["dnsSerAddr"]=array();
-
 
6242
	#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
-
 
6243
	$conf["actionAfterUpdateCert"]=array();
-
 
6244
	#可省略參數:
-
 
6245
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
6246
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
-
 
6247
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
6248
	#$conf["key"]=self::getApiInfo()["apiKey"];
-
 
6249
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
-
 
6250
	#$conf["debug"]="";
-
 
6251
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
-
 
6252
	#$conf["addOnProcessFunc"]=array();
-
 
6253
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
-
 
6254
	#$conf["funcToRunWhenIdle"]=array();
-
 
6255
	#參考資料:
-
 
6256
	#無.
-
 
6257
	#備註:
-
 
6258
	#無.
-
 
6259
	*/
-
 
6260
	public static function sslUpdater(&$conf){
-
 
6261
	
-
 
6262
		#初始化要回傳的結果
-
 
6263
		$result=array();
-
 
6264
 
-
 
6265
		#設置當其函數名稱
-
 
6266
		$result["function"]=__FUNCTION__;
-
 
6267
 
-
 
6268
		#如果 $conf 不為陣列
-
 
6269
		if(gettype($conf)!="array"){
-
 
6270
 
-
 
6271
			#設置執行失敗
-
 
6272
			$result["status"]="false";
-
 
6273
 
-
 
6274
			#設置執行錯誤訊息
-
 
6275
			$result["error"][]="\$conf變數須為陣列形態";
-
 
6276
 
-
 
6277
			#如果傳入的參數為 null
-
 
6278
			if($conf==null){
-
 
6279
 
-
 
6280
				#設置執行錯誤訊息
-
 
6281
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
6282
 
-
 
6283
				}#if end
-
 
6284
 
-
 
6285
			#回傳結果
-
 
6286
			return $result;
-
 
6287
 
-
 
6288
			}#if end
-
 
6289
 
-
 
6290
		#取得參數
-
 
6291
		$result["argu"]=$conf;
-
 
6292
 
-
 
6293
		#檢查參數
-
 
6294
		#函式說明:
-
 
6295
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
-
 
6296
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6297
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
6298
		#$result["function"],當前執行的函式名稱.
-
 
6299
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
6300
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
6301
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
6302
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
6303
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
6304
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
6305
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
6306
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
6307
		#必填寫的參數:
-
 
6308
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
6309
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
6310
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
6311
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
-
 
6312
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
-
 
6313
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
-
 
6314
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
6315
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
6316
		#可以省略的參數:
-
 
6317
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
6318
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
-
 
6319
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
-
 
6320
		#$conf["skipableVariableCanNotBeEmpty"]=array();
-
 
6321
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
6322
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
-
 
6323
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
6324
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
-
 
6325
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
6326
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
-
 
6327
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
6328
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
-
 
6329
		#參考資料來源:
-
 
6330
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
6331
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
6332
		unset($conf["variableCheck::checkArguments"]);
-
 
6333
 
-
 
6334
		#如果檢查失敗
-
 
6335
		if($checkArguments["status"]==="false"){
-
 
6336
 
-
 
6337
			#設置錯誤識別
-
 
6338
			$result["status"]="false";
-
 
6339
 
-
 
6340
			#設置錯誤訊息
-
 
6341
			$result["error"]=$checkArguments;
-
 
6342
 
-
 
6343
			#回傳結果
-
 
6344
			return $result;
-
 
6345
 
-
 
6346
			}#if end
-
 
6347
 
-
 
6348
		#如果檢查不通過
-
 
6349
		if($checkArguments["passed"]==="false"){
-
 
6350
 
-
 
6351
			#設置錯誤識別
-
 
6352
			$result["status"]="false";
-
 
6353
 
-
 
6354
			#設置錯誤訊息
-
 
6355
			$result["error"]=$checkArguments;
-
 
6356
 
-
 
6357
			#回傳結果
-
 
6358
			return $result;
-
 
6359
 
-
 
6360
			}#if end
-
 
6361
		
-
 
6362
		#取得key
-
 
6363
		$share["key"]=$conf["key"];
-
 
6364
		
-
 
6365
		#取得apiDomain
-
 
6366
		$share["apiDomain"]=$conf["apiDomain"];
-
 
6367
		
-
 
6368
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
-
 
6369
		$share["certInfo"]=array();
-
 
6370
		
-
 
6371
		#針對每個 domain
-
 
6372
		foreach($conf["cName"] as $index=>$cName ){
-
 
6373
			
-
 
6374
			#如果沒有對應的certInfo
-
 
6375
			if(!isset($conf["certInfo"][$index])){
-
 
6376
				
-
 
6377
				#設置錯誤識別
-
 
6378
				$result["status"]="false";
-
 
6379
 
-
 
6380
				#設置錯誤訊息
-
 
6381
				$result["error"][]="missing certInfo";
-
 
6382
 
-
 
6383
				#設置錯誤訊息
-
 
6384
				$result["error"][]=$checkArguments;
-
 
6385
 
-
 
6386
				#回傳結果
-
 
6387
				return $result;
-
 
6388
			
-
 
6389
				}#if end
-
 
6390
				
-
 
6391
			#檢查 certInfo
-
 
6392
			foreach($certInfo[$index] as $cInfo){
-
 
6393
			
-
 
6394
				#如果沒有設定 certPath
-
 
6395
				if(!isset($cInfo["certPath"])){
-
 
6396
				
-
 
6397
					#初始化為 ${cName}-cerfificate.crt
-
 
6398
					$cInfo["certPath"]=$conf["cName"][$index]."-certificate.crt";
-
 
6399
				
-
 
6400
					}#if end
-
 
6401
					
-
 
6402
				#如果沒有設定 pKey
-
 
6403
				if(!isset($cInfo["pKey"])){
-
 
6404
				
-
 
6405
					#初始化為 ${cName}-private.key
-
 
6406
					$cInfo["pKey"]=$conf["cName"][$index]."-private.key";
-
 
6407
				
-
 
6408
					}#if end
-
 
6409
					
-
 
6410
				#如果沒有設定 caPath
-
 
6411
				if(!isset($cInfo["caPath"])){
-
 
6412
				
-
 
6413
					#初始化為 ${cName}-ca_bundle.crt"
-
 
6414
					$cInfo["caPath"]=$conf["cName"][$index]."-ca_bundle.crt";
-
 
6415
				
-
 
6416
					}#if end
-
 
6417
					
-
 
6418
				#如果沒有設定 certWithCaPath
-
 
6419
				if(!isset($cInfo["certWithCaPath"])){
-
 
6420
				
-
 
6421
					#初始化為 ${cName}-certWithCaPath.crt"
-
 
6422
					$cInfo["certWithCaPath"]=$conf["cName"][$index]."-certWithCaPath.crt";
-
 
6423
				
-
 
6424
					}#if end
-
 
6425
					
-
 
6426
				#儲存 cName
-
 
6427
				$cInfo["cName"]=$cName;
-
 
6428
				
-
 
6429
				#儲存 RR 檔案的路徑與名稱
-
 
6430
				$cInfo["rrFile"]=$conf["rrFile"][$index];
-
 
6431
				
-
 
6432
				#儲存 cName 對應的 dns server addr
-
 
6433
				$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
-
 
6434
				
-
 
6435
				#儲存 cName 的憑證更新後要做的事情.
-
 
6436
				$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
-
 
6437
				
-
 
6438
				#儲存 certInfo
-
 
6439
				$share["certInfo"][]=$cInfo;
-
 
6440
			
-
 
6441
				}#foreach end
-
 
6442
			
-
 
6443
			}#foreach end
-
 
6444
			
-
 
6445
		#如果為空
-
 
6446
		if(empty($share["certInfo"])){
-
 
6447
		
-
 
6448
			#設置錯誤識別
-
 
6449
			$result["status"]="false";
-
 
6450
 
-
 
6451
			#設置錯誤訊息
-
 
6452
			$result["error"][]="certInfo 參數有缺";
-
 
6453
 
-
 
6454
			#設置錯誤訊息
-
 
6455
			$result["error"][]=$checkArguments;
-
 
6456
 
-
 
6457
			#回傳結果
-
 
6458
			return $result;
-
 
6459
		
-
 
6460
			}#if end
-
 
6461
		
-
 
6462
		#函式說明:
-
 
6463
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
-
 
6464
		#回傳結果:
-
 
6465
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
6466
		#$result["error"],錯誤訊息陣列.
-
 
6467
		#$result["function"],當前執行的函式名稱.
-
 
6468
		#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
-
 
6469
		#$result["serverCache"]["serverSide"],server side 的 cache.
-
 
6470
		#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
-
 
6471
		#$result["serverCache"]["clientSide"],client site 的 cache.
-
 
6472
		#必填參數:
-
 
6473
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
-
 
6474
		$conf["sock::unixDomainSockServer"]["sock"]=$unixSocket;
-
 
6475
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
6476
		$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
-
 
6477
		#可省略參數:
-
 
6478
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
-
 
6479
		$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
-
 
6480
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
-
 
6481
		$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
-
 
6482
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
-
 
6483
		#$conf["sessionTimeout"]="300";
-
 
6484
		#$conf["addOnProcessFunc"],字串陣列,增加用於處理 json request 的函式名稱,給予的參數為array("request"=>收到的json訊息,"sock"=>用戶的socket,"clientCache"=>給予所有用戶的cache),若收到的不是json而是"quit"則代表用戶要結束連線;若收到的是$shutdownStr則代表要結束本函式.回傳的內容必須為陣列,例如 $res["continue"]="true"代表要繼續執行下一個addOnProcessFunc;"false"代表代表到此為止. $res["content"]="replaced content";代表要將收到的訊息取代成"replaced content". 最少要有回傳 $res["status"]數值"true"代表執行正常;"false"代表執行不正常.
-
 
6485
		$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("/qbpwcf/zerossl::sslUpdater_cmd");
-
 
6486
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
-
 
6487
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("/qbpwcf/zerossl::sslUpdater_idle");
-
 
6488
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
-
 
6489
		#$conf["paramsForFuncToRunWhenIdle"]=array();
-
 
6490
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
-
 
6491
		$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
-
 
6492
		#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
-
 
6493
		#$conf["shutdownStrAddr"]="";
-
 
6494
		#參考資料:
-
 
6495
		#http://php.net/manual/en/function.stream-socket-server.php
-
 
6496
		#備註:
-
 
6497
		#無.
-
 
6498
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
-
 
6499
		unset($conf["sock::unixDomainSockServer"]);
-
 
6500
	
-
 
6501
		#執行異常
-
 
6502
		if($unixDomainSockServer["status"]==="false"){
-
 
6503
			
-
 
6504
			#設置錯誤識別
-
 
6505
			$result["status"]="false";
-
 
6506
 
-
 
6507
			#設置錯誤訊息
-
 
6508
			$result["error"]=$unixDomainSockServer;
-
 
6509
 
-
 
6510
			#回傳結果
-
 
6511
			return $result;
-
 
6512
 
-
 
6513
			}#if end
-
 
6514
			
-
 
6515
		#設置執行正常
-
 
6516
		$result["status"]="true";
-
 
6517
		
-
 
6518
		#回傳結果
-
 
6519
		return $result;
-
 
6520
	
-
 
6521
		}#function sslUpdater end
-
 
6522
	
-
 
6523
	/*
-
 
6524
	#函式說明:
-
 
6525
	#funcion sslUpdater 於收到訊息時要做的事情.
-
 
6526
	#回傳結果:
-
 
6527
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6528
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
6529
	#$result["function"],當前執行的函式名稱.
-
 
6530
	#$result["argu"],所使用的參數.
-
 
6531
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
-
 
6532
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
-
 
6533
	#必填參數:
-
 
6534
	#$conf["request"],字串,收到的json訊息.
-
 
6535
	$conf["request"]="";
-
 
6536
	#$conf["sock"],resource,用戶的socket.
-
 
6537
	$conf["sock"]="";
-
 
6538
	#$conf["clientCache"],陣列,給予所有用戶的cache.
-
 
6539
	$conf["clientCache"]=array();
-
 
6540
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
-
 
6541
	$conf["info"]=array();
-
 
6542
	#可省略參數:
-
 
6543
	#無.
-
 
6544
	#參考資料:
-
 
6545
	#無.
-
 
6546
	#備註:
-
 
6547
	#建構中...
-
 
6548
	*/
-
 
6549
	public static function sslUpdater_cmd(&$conf){
-
 
6550
		
-
 
6551
		#debug
-
 
6552
		var_dump($conf);
-
 
6553
		
-
 
6554
		}#function sslUpdater_cmd end
-
 
6555
	
-
 
6556
	/*
-
 
6557
	#函式說明:
-
 
6558
	#funcion sslUpdater 於閒置時要做的事情
-
 
6559
	#回傳結果:
-
 
6560
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6561
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
6562
	#$result["function"],當前執行的函式名稱.
-
 
6563
	#$result["argu"],所使用的參數.
-
 
6564
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
-
 
6565
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
-
 
6566
	#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
-
 
6567
	#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
-
 
6568
	#必填參數:
-
 
6569
	#$conf["client"],陣列,所有用戶的資訊.
-
 
6570
	$conf["client"]=array();
-
 
6571
	#$conf["clientCache"],陣列,給予所有用戶的cache.
-
 
6572
	$conf["clientCache"]=array();
-
 
6573
	#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
-
 
6574
	$conf["serverCache"]=array();
-
 
6575
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
-
 
6576
	$conf["info"]=array();
-
 
6577
	#可省略參數:
-
 
6578
	#無.
-
 
6579
	#參考資料:
-
 
6580
	#無.
-
 
6581
	#備註:
-
 
6582
	#建構中...
-
 
6583
	*/
-
 
6584
	public static function sslUpdater_idle(&$conf){
-
 
6585
		
-
 
6586
		#初始化要回傳的結果
-
 
6587
		$result=array();
-
 
6588
 
-
 
6589
		#設置當其函數名稱
-
 
6590
		$result["function"]=__FUNCTION__;
-
 
6591
 
-
 
6592
		#如果 $conf 不為陣列
-
 
6593
		if(gettype($conf)!="array"){
-
 
6594
 
-
 
6595
			#設置執行失敗
-
 
6596
			$result["status"]="false";
-
 
6597
 
-
 
6598
			#設置執行錯誤訊息
-
 
6599
			$result["error"][]="\$conf變數須為陣列形態";
-
 
6600
 
-
 
6601
			#如果傳入的參數為 null
-
 
6602
			if($conf==null){
-
 
6603
 
-
 
6604
				#設置執行錯誤訊息
-
 
6605
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
6606
 
-
 
6607
				}#if end
-
 
6608
 
-
 
6609
			#回傳結果
-
 
6610
			return $result;
-
 
6611
 
-
 
6612
			}#if end
-
 
6613
 
-
 
6614
		#取得參數
-
 
6615
		$result["argu"]=$conf;
-
 
6616
		
-
 
6617
		#檢查參數
-
 
6618
		#函式說明:
-
 
6619
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
-
 
6620
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6621
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
6622
		#$result["function"],當前執行的函式名稱.
-
 
6623
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
6624
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
6625
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
6626
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
6627
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
6628
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
6629
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
6630
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
6631
		#必填寫的參數:
-
 
6632
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
6633
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
6634
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
6635
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","clientCache","serverCache","info");
-
 
6636
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
-
 
6637
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
-
 
6638
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
6639
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
6640
		#可以省略的參數:
-
 
6641
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
6642
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
-
 
6643
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
-
 
6644
		#$conf["skipableVariableCanNotBeEmpty"]=array();
-
 
6645
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
6646
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
-
 
6647
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
6648
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
-
 
6649
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
6650
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
-
 
6651
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
6652
		#$conf["arrayCountEqualCheck"][]=array();
-
 
6653
		#參考資料來源:
-
 
6654
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
6655
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
6656
		unset($conf["variableCheck::checkArguments"]);
-
 
6657
 
-
 
6658
		#如果檢查失敗
-
 
6659
		if($checkArguments["status"]==="false"){
-
 
6660
 
-
 
6661
			#設置錯誤識別
-
 
6662
			$result["status"]="false";
-
 
6663
 
-
 
6664
			#設置錯誤訊息
-
 
6665
			$result["error"]=$checkArguments;
-
 
6666
 
-
 
6667
			#回傳結果
-
 
6668
			return $result;
-
 
6669
 
-
 
6670
			}#if end
-
 
6671
 
-
 
6672
		#如果檢查不通過
-
 
6673
		if($checkArguments["passed"]==="false"){
-
 
6674
 
-
 
6675
			#設置錯誤識別
-
 
6676
			$result["status"]="false";
-
 
6677
 
-
 
6678
			#設置錯誤訊息
-
 
6679
			$result["error"]=$checkArguments;
-
 
6680
 
-
 
6681
			#回傳結果
-
 
6682
			return $result;
-
 
6683
 
-
 
6684
			}#if end
-
 
6685
			
-
 
6686
		#針對每個 domain name
-
 
6687
		foreach($info["share"]["certInfo"] as $cInfo){
-
 
6688
		
-
 
6689
			#取得domain name
-
 
6690
			$cName=$cInfo["cName"];
-
 
6691
		
-
 
6692
			#嘗試取得 domain name 對應的可用憑證
-
 
6693
			#函式說明:
-
 
6694
			#取得在zerossl上的CSR清單
-
 
6695
			#回傳結果:
-
 
6696
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6697
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
6698
			#$result["function"],當前執行的函式名稱.
-
 
6699
			#$result["argu"],所使用的參數.
-
 
6700
			#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
6701
			#$result["content"],結果json字串.
-
 
6702
			#$result["tCount"],總共的資料筆數.
-
 
6703
			#$result["count"],該頁的筆數.
-
 
6704
			#$result["page"],當前的頁碼.
-
 
6705
			#$result["certs"],陣列,certificates清單,key為certificate的id.
-
 
6706
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
-
 
6707
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
-
 
6708
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
-
 
6709
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
-
 
6710
			#必填參數:
-
 
6711
			#無
-
 
6712
			#可省略參數:
-
 
6713
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
6714
			$conf["zerossl::getCertList"]["apiDomain"]=$cInfo["apiDomain"];
-
 
6715
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
6716
			$conf["zerossl::getCertList"]["key"]=$cInfo["key"];
-
 
6717
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
-
 
6718
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
-
 
6719
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
-
 
6720
			$conf["zerossl::getCertList"]["cerType"]="single90Days";
-
 
6721
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
-
 
6722
			$conf["zerossl::getCertList"]["search"]=$cName;
-
 
6723
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
-
 
6724
			#$conf["limit"]="";
-
 
6725
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
-
 
6726
			#$conf["page"]="";
-
 
6727
			#參考資料:
-
 
6728
			#https://zerossl.com/documentation/api/list-certificates/
-
 
6729
			#備註:
-
 
6730
			#無.
-
 
6731
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
-
 
6732
			unset($conf["zerossl::getCertList"]);
-
 
6733
		
-
 
6734
			#符合條件的數量
-
 
6735
			#$getCertList["tCount"];
-
 
6736
			
-
 
6737
			#符合條件的當頁數量
-
 
6738
			#$getCertList["count"];
-
 
6739
		
-
 
6740
			#如果執行異常
-
 
6741
			if($getCertList["status"]==="false"){
-
 
6742
			
-
 
6743
				#設置錯誤識別
-
 
6744
				$result["status"]="false";
-
 
6745
 
-
 
6746
				#設置錯誤訊息
-
 
6747
				$result["error"]=$getCertList;
-
 
6748
 
-
 
6749
				#回傳結果
-
 
6750
				return $result;
-
 
6751
			
-
 
6752
				}#if end
-
 
6753
				
-
 
6754
			#如果沒有憑證
-
 
6755
			if($getCertList["count"]==="0"){
-
 
6756
			
-
 
6757
				#確認有無對應 cName 的 private key
-
 
6758
				#函式說明:
-
 
6759
				#檢查多個檔案與資料夾是否存在.
-
 
6760
				#回傳的結果:
-
 
6761
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
-
 
6762
				#$result["error"],錯誤訊息陣列.
-
 
6763
				#$resutl["function"],當前執行的涵式名稱.
-
 
6764
				#$result["argu"],使用的參數.
-
 
6765
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
-
 
6766
				#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
-
 
6767
				#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
-
 
6768
				#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
-
 
6769
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
-
 
6770
				#必填參數:
-
 
6771
				#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
-
 
6772
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["pKey"]);
-
 
6773
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
6774
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
-
 
6775
				#可省略參數:
-
 
6776
				#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
-
 
6777
				#$conf["disableWebSearch"]="false";
-
 
6778
				#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
-
 
6779
				$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
-
 
6780
				#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
-
 
6781
				$conf["fileAccess::checkMultiFileExist"]["web"]="false";
-
 
6782
				#參考資料:
-
 
6783
				#http://php.net/manual/en/function.file-exists.php
-
 
6784
				#http://php.net/manual/en/control-structures.foreach.php
-
 
6785
				#備註:
-
 
6786
				#函數file_exists檢查的路徑為檔案系統的路徑
-
 
6787
				#$result["varName"][$i]結果未實作
-
 
6788
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
-
 
6789
				unset($conf["fileAccess::checkMultiFileExist"]);
-
 
6790
				
-
 
6791
				#如果運行異常
-
 
6792
				if($checkMultiFileExist["status"]==="false"){
-
 
6793
				
-
 
6794
					#設置錯誤識別
-
 
6795
					$result["status"]="false";
-
 
6796
 
-
 
6797
					#設置錯誤訊息
-
 
6798
					$result["error"]=$getCertList;
-
 
6799
 
-
 
6800
					#回傳結果
-
 
6801
					return $result;
-
 
6802
				
-
 
6803
					}#if end
-
 
6804
					
-
 
6805
				#如果沒有 private key
-
 
6806
				if($checkMultiFileExist["allExist"]==="false"){
-
 
6807
				
-
 
6808
					#建立 private key
-
 
6809
					#函式說明:
-
 
6810
					#產生ssl private key.
-
 
6811
					#回傳結果:
-
 
6812
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6813
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
6814
					#$result["function"],當前執行的函式名稱.
-
 
6815
					#$result["argu"],所使用的參數.
-
 
6816
					#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
6817
					#$result["content"],ssl用的private key.
-
 
6818
					#必填參數:
-
 
6819
					#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
6820
					$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
-
 
6821
					#可省略參數:
-
 
6822
					#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
-
 
6823
					#$conf["length"]=4096';
-
 
6824
					#參考資料:
-
 
6825
					#無.
-
 
6826
					#備註:
-
 
6827
					#key generated by openssl with RSA.
-
 
6828
					$createPrivateKey=openssl::createPrivateKey($conf["openssl::createPrivateKey"]);
-
 
6829
					unset($conf["openssl::createPrivateKey"]);
-
 
6830
				
-
 
6831
					#如果運行異常
-
 
6832
					if($createPrivateKey["status"]==="false"){
-
 
6833
					
-
 
6834
						#設置錯誤識別
-
 
6835
						$result["status"]="false";
-
 
6836
 
-
 
6837
						#設置錯誤訊息
-
 
6838
						$result["error"]=$createPrivateKey;
-
 
6839
 
-
 
6840
						#回傳結果
-
 
6841
						return $result;
-
 
6842
					
-
 
6843
						}#if end
-
 
6844
						
-
 
6845
					#另存private key的字串
-
 
6846
					$pKeyStr=$createPrivateKey["content"];
-
 
6847
				
-
 
6848
					#建立private key檔案
-
 
6849
					#函式說明:
-
 
6850
					#將字串寫入到檔案
-
 
6851
					#回傳結果:
-
 
6852
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
-
 
6853
					#$result["error"],錯誤訊息陣列.
-
 
6854
					#$result["function"],當前執行的函數名稱.
-
 
6855
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
-
 
6856
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
-
 
6857
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
-
 
6858
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
-
 
6859
					#$result["argu"],使用的參數.
-
 
6860
					#必填參數:
-
 
6861
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
6862
					$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
-
 
6863
					#可省略參數:
-
 
6864
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
-
 
6865
					$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["pKey"];
-
 
6866
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
-
 
6867
					$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
-
 
6868
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
-
 
6869
					#$conf["writeMethod"]="a";
-
 
6870
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
-
 
6871
					#$conf["checkRepeat"]="";
-
 
6872
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
-
 
6873
					#$conf["filenameExtensionStartPoint"]="";
-
 
6874
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
-
 
6875
					#$conf["repeatNameRule"]="";
-
 
6876
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
-
 
6877
					$conf["zerossl::writeTextIntoFile"]["web"]="false";
-
 
6878
					#參考資料:
-
 
6879
					#無.
-
 
6880
					#備註:
-
 
6881
					#無.
-
 
6882
					$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
-
 
6883
					unset($conf["zerossl::writeTextIntoFile"]);
-
 
6884
				
-
 
6885
					#如果運行異常
-
 
6886
					if($writeTextIntoFile["status"]==="false"){
-
 
6887
					
-
 
6888
						#設置錯誤識別
-
 
6889
						$result["status"]="false";
-
 
6890
 
-
 
6891
						#設置錯誤訊息
-
 
6892
						$result["error"]=$writeTextIntoFile;
-
 
6893
 
-
 
6894
						#回傳結果
-
 
6895
						return $result;
-
 
6896
					
-
 
6897
						}#if end
-
 
6898
						
-
 
6899
					}#if end
-
 
6900
				
-
 
6901
				#建立準備給zerossl的csr
-
 
6902
				#函式說明:
-
 
6903
				#產生certificate sign request(CSR).
-
 
6904
				#回傳結果:
-
 
6905
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6906
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
6907
				#$result["function"],當前執行的函式名稱.
-
 
6908
				#$result["argu"],所使用的參數.
-
 
6909
				#$result["content"],csr內容.
-
 
6910
				#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
6911
				#$result["privateKey"], private key 的內容.
-
 
6912
				#必填參數:
-
 
6913
				#$conf["domain"],字串,csr內容的網域名稱.
-
 
6914
				$conf["zerossl::createCSR"]["domain"]=$cName;
-
 
6915
				#可省略參數:
-
 
6916
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
-
 
6917
				#$conf["pKey"]="";
-
 
6918
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
-
 
6919
				#$conf["country"]="";
-
 
6920
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
-
 
6921
				#$conf["state"]="";
-
 
6922
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
-
 
6923
				#$conf["org"]="";
-
 
6924
				#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
-
 
6925
				#$conf["unit"]="";
-
 
6926
				#參考資料:
-
 
6927
				#無.
-
 
6928
				#備註:
-
 
6929
				#無.
-
 
6930
				$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
-
 
6931
				unset($conf["zerossl::createCSR"]);
-
 
6932
				
-
 
6933
				#如果運行異常
-
 
6934
				if($createCSR["status"]==="false"){
-
 
6935
				
-
 
6936
					#設置錯誤識別
-
 
6937
					$result["status"]="false";
-
 
6938
 
-
 
6939
					#設置錯誤訊息
-
 
6940
					$result["error"]=$createCSR;
-
 
6941
 
-
 
6942
					#回傳結果
-
 
6943
					return $result;
-
 
6944
				
-
 
6945
					}#if end
-
 
6946
					
-
 
6947
				#取得本地端產生的csr內容
-
 
6948
				$csrLocal=$createCSR["content"];
-
 
6949
				
-
 
6950
				#函式說明:
-
 
6951
				#提供certificate sign request(CSR)透過zerossl產生cergificate.
-
 
6952
				#回傳結果:
-
 
6953
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
6954
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
6955
				#$result["function"],當前執行的函式名稱.
-
 
6956
				#$result["argu"],所使用的參數.
-
 
6957
				#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
6958
				#$result["id"],用於zerossl api驗證domain的id.
-
 
6959
				#$result["content"],字串,得到的json字串回應.
-
 
6960
				#$result["cnameKey"],用於dns CNAME驗證鍵名.
-
 
6961
				#$result["cnameVal"],用於dms CNAME驗證鍵值.
-
 
6962
				#必填參數:
-
 
6963
				#$conf["certificate_domains"],字串,要簽署的doamin名稱.
-
 
6964
				$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
-
 
6965
				#$conf["certificate_csr"],字串,簽署的資訊.
-
 
6966
				$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
-
 
6967
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
6968
				$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
-
 
6969
				#可省略參數:
-
 
6970
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
6971
				$conf["zerossl::createCertificate"]["apiDomain"]=$cInfo["domain"];
-
 
6972
				#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
-
 
6973
				#$conf["path"]=self::getApiInfo()["csrPath"];
-
 
6974
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
6975
				$conf["zerossl::createCertificate"]["key"]=$cInfo["key"];
-
 
6976
				#參考資料:
-
 
6977
				#無.
-
 
6978
				#備註:
-
 
6979
				#無.
-
 
6980
				$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
-
 
6981
				unset($conf["zerossl::createCertificate"]);
-
 
6982
				
-
 
6983
				#如果執行異常
-
 
6984
				if($createCertificate["status"]==="false"){
-
 
6985
				
-
 
6986
					#設置錯誤識別
-
 
6987
					$result["status"]="false";
-
 
6988
 
-
 
6989
					#設置錯誤訊息
-
 
6990
					$result["error"]=$createCertificate;
-
 
6991
 
-
 
6992
					#回傳結果
-
 
6993
					return $result;
-
 
6994
				
-
 
6995
					}#if end
-
 
6996
				
-
 
6997
				#取得csr在zerossl上的id
-
 
6998
				$csrId=$createCertificate["id"];
-
 
6999
				
-
 
7000
				#取得cname key
-
 
7001
				$cNameKey=$createCertificate["cnameKey"];
-
 
7002
				
-
 
7003
				#取得cname val
-
 
7004
				$cNameVal=$createCertificate["cnameVal"];
-
 
7005
				
-
 
7006
				#初始化要增加的RR記錄
-
 
7007
				$rr2add=array();
-
 
7008
				
-
 
7009
				#設置CNAME的查詢
-
 
7010
				$rr2add["query"]=$cNameKey;
-
 
7011
				
-
 
7012
				#設置CNAME的value
-
 
7013
				$rr2add["value"]=$cNameVal;
-
 
7014
				
-
 
7015
				#設置類型為 CNAME
-
 
7016
				$rr2add["type"]="CNAME";
-
 
7017
				
-
 
7018
				#設置註解
-
 
7019
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
-
 
7020
				
-
 
7021
				#函式說明:
-
 
7022
				#新增DNS記錄到檔案裡面.
-
 
7023
				#回傳結果:
-
 
7024
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7025
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
7026
				#$result["function"],當前執行的函式名稱.
-
 
7027
				#$result["argu"],所使用的參數.
-
 
7028
				#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
-
 
7029
				#$result["domain"],字串,RR所屬domain.
-
 
7030
				#$result["defaultTTL"],字串,預設的RR更新時間.
-
 
7031
				#$result["comment"],字串陣列,逐行的註解.
-
 
7032
				#必填參數:
-
 
7033
				#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
-
 
7034
				$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2ad);
-
 
7035
				#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
-
 
7036
				$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
-
 
7037
				#可省略參數:
-
 
7038
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
-
 
7039
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
-
 
7040
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
-
 
7041
				#$conf["debug"]="false";
-
 
7042
				#參考資料:
-
 
7043
				#無.
-
 
7044
				#備註:
-
 
7045
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
-
 
7046
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
-
 
7047
				#php-pear上的Net_DNS2也可以解析RR.
-
 
7048
				$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
-
 
7049
				unset($conf["zerossl::updateDnsRecordFile"]);
-
 
7050
				
-
 
7051
				#如果執行異常
-
 
7052
				if($updateDnsRecordFile["status"]==="false"){
-
 
7053
				
-
 
7054
					#設置錯誤識別
-
 
7055
					$result["status"]="false";
-
 
7056
 
-
 
7057
					#設置錯誤訊息
-
 
7058
					$result["error"]=$updateDnsRecordFile;
-
 
7059
 
-
 
7060
					#回傳結果
-
 
7061
					return $result;
-
 
7062
				
-
 
7063
					}#if end
-
 
7064
					
-
 
7065
				#重新啟動dns伺服器
-
 
7066
				#函式說明:
-
 
7067
				#呼叫shell執行系統命令,並取得回傳的內容.
-
 
7068
				#回傳結果:
-
 
7069
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7070
				#$result["error"],錯誤訊息陣列.
-
 
7071
				#$result["function"],當前執行的函數名稱.
-
 
7072
				#$result["argu"],使用的參數.
-
 
7073
				#$result["cmd"],執行的指令內容.
-
 
7074
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
7075
				#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
7076
				#$result["content"],為執行完後的輸出字串.
-
 
7077
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
7078
				#$result["running"],是否還在執行.
-
 
7079
				#$result["pid"],pid.
-
 
7080
				#$result["statusCode"],執行結束後的代碼.
-
 
7081
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
7082
				#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
7083
				#必填參數:
-
 
7084
				#$conf["command"],字串,要執行的指令.
-
 
7085
				$conf["external::callShell"]["command"]="systemd";
-
 
7086
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
7087
				$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
7088
				#可省略參數:
-
 
7089
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
7090
				$conf["external::callShell"]["argu"]=array("restart","named");
-
 
7091
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
7092
				#$conf["arguIsAddr"]=array();
-
 
7093
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
7094
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
7095
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
7096
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
7097
				#$conf["enablePrintDescription"]="true";
-
 
7098
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
7099
				#$conf["printDescription"]="";
-
 
7100
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
7101
				#$conf["escapeshellarg"]="false";
-
 
7102
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
7103
				#$conf["thereIsShellVar"]=array();
-
 
7104
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
7105
				#$conf["username"]="";
-
 
7106
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
7107
				#$conf["password"]="";
-
 
7108
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
7109
				#$conf["useScript"]="";
-
 
7110
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
7111
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
7112
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
7113
				#$conf["inBackGround"]="";
-
 
7114
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
7115
				#$conf["getErr"]="false";
-
 
7116
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
7117
				#$conf["doNotRun"]="false";
-
 
7118
				#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
-
 
7119
				$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
-
 
7120
				#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
-
 
7121
				#$conf["remoteUser"]="root";
-
 
7122
				#參考資料:
-
 
7123
				#exec=>http://php.net/manual/en/function.exec.php
-
 
7124
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
7125
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
7126
				#備註:
-
 
7127
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
7128
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
7129
				$callShell=external::callShell($conf["external::callShell"]);
-
 
7130
				unset($conf["external::callShell"]);
-
 
7131
				
-
 
7132
				#如果執行異常
-
 
7133
				if($callShell["status"]==="false"){
-
 
7134
				
-
 
7135
					#設置錯誤識別
-
 
7136
					$result["status"]="false";
-
 
7137
 
-
 
7138
					#設置錯誤訊息
-
 
7139
					$result["error"]=$callShell;
-
 
7140
 
-
 
7141
					#回傳結果
-
 
7142
					return $result;
-
 
7143
				
-
 
7144
					}#if end
-
 
7145
					
-
 
7146
				#函式說明:
-
 
7147
				#請求驗證已經透過zerossl::createCertificate要求的domain.
-
 
7148
				#回傳結果:
-
 
7149
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7150
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
7151
				#$result["function"],當前執行的函式名稱.
-
 
7152
				#$result["argu"],所使用的參數.
-
 
7153
				#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
7154
				#$result["content"],結果json字串.
-
 
7155
				#必填參數:
-
 
7156
				#$conf["id"],字串,zerossl::createCertificate回傳的id.
-
 
7157
				$conf["zerossl::verifyDomain"]["id"]=$csrId;
-
 
7158
				#可省略參數:
-
 
7159
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
7160
				$conf["zerossl::verifyDomain"]["apiDomain"]=$cInfo["domain"];
-
 
7161
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
7162
				$conf["zerossl::verifyDomain"]["key"]=$cInfo["key"];
-
 
7163
				#參考資料:
-
 
7164
				#https://zerossl.com/documentation/api/verify-domains/
-
 
7165
				#備註:
-
 
7166
				#無.
-
 
7167
				$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
-
 
7168
				unset($conf["zerossl::verifyDomain"]);
-
 
7169
				
-
 
7170
				#如果執行異常
-
 
7171
				if($verifyDomain["status"]==="false"){
-
 
7172
				
-
 
7173
					#設置錯誤識別
-
 
7174
					$result["status"]="false";
-
 
7175
 
-
 
7176
					#設置錯誤訊息
-
 
7177
					$result["error"]=$verifyDomain;
-
 
7178
 
-
 
7179
					#回傳結果
-
 
7180
					return $result;
-
 
7181
				
-
 
7182
					}#if end
-
 
7183
					
-
 
7184
				#函式說明:
-
 
7185
				#下載certificate.
-
 
7186
				#回傳結果:
-
 
7187
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7188
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
7189
				#$result["function"],當前執行的函式名稱.
-
 
7190
				#$result["argu"],所使用的參數.
-
 
7191
				#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
7192
				#$result["content"],結果json字串.
-
 
7193
				#$result["certificate.crt"],字串,certificate.crt的內容.
-
 
7194
				#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
-
 
7195
				#必填參數:
-
 
7196
				#無.
-
 
7197
				#可省略參數:
-
 
7198
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
7199
				$conf["zerossl::getCert"]["apiDomain"]=$cInfo["domain"];
-
 
7200
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
7201
				$conf["zerossl::getCert"]["key"]=$cInfo["key"];
-
 
7202
				#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
-
 
7203
				$conf["zerossl::getCert"]["id"]=$csrId;
-
 
7204
				#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
-
 
7205
				#$conf["zerossl::getCert"]["cname"]="";
-
 
7206
				#參考資料:
-
 
7207
				#https://zerossl.com/documentation/api/download-certificate-inline/
-
 
7208
				#備註:
-
 
7209
				#無.
-
 
7210
				$getCert=zerossl::getCert($conf["zerossl::getCert"]);
-
 
7211
				unset($conf["zerossl::getCert"]);
-
 
7212
				
-
 
7213
				#如果執行異常
-
 
7214
				if($getCert["status"]==="false"){
-
 
7215
				
-
 
7216
					#設置錯誤識別
-
 
7217
					$result["status"]="false";
-
 
7218
 
-
 
7219
					#設置錯誤訊息
-
 
7220
					$result["error"]=$getCert;
-
 
7221
 
-
 
7222
					#回傳結果
-
 
7223
					return $result;
-
 
7224
				
-
 
7225
					}#if end
-
 
7226
					
-
 
7227
				#建立 certificate.crt 檔案
-
 
7228
				#$cInfo["certPath"];
-
 
7229
				
-
 
7230
				#建立 ca_bundle.crt 檔案
-
 
7231
				#$cInfo["caPath"];
-
 
7232
				
-
 
7233
				#建立 certAndCa.crt 檔案
-
 
7234
				#$cInfo["certWithCaPath"];
-
 
7235
				
-
 
7236
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
-
 
7237
				#函式說明:
-
 
7238
				#一次建立多個檔案,並寫入內容.
-
 
7239
				#回傳結果:
-
 
7240
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
-
 
7241
				#$result["error"],錯誤訊息陣列.
-
 
7242
				#$result["function"],當前執行的函數名稱.
-
 
7243
				#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
-
 
7244
				#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
-
 
7245
				#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
-
 
7246
				#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
-
 
7247
				#$result["argu"],使用的參數.
-
 
7248
				#必填參數:
-
 
7249
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
7250
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
-
 
7251
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
-
 
7252
				$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certPath"],$cInfo["caPath"],$cInfo["certWithCaPath"]);
-
 
7253
				#可省略參數:
-
 
7254
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
-
 
7255
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
-
 
7256
				#參考資料:
-
 
7257
				#無.
-
 
7258
				#備註:
-
 
7259
				#無.
-
 
7260
				$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
-
 
7261
				unset($conf["zerossl::writeMultiFile"]);
-
 
7262
				
-
 
7263
				#如果執行異常
-
 
7264
				if($writeMultiFile["status"]==="false"){
-
 
7265
				
-
 
7266
					#設置錯誤識別
-
 
7267
					$result["status"]="false";
-
 
7268
 
-
 
7269
					#設置錯誤訊息
-
 
7270
					$result["error"]=$writeMultiFile;
-
 
7271
 
-
 
7272
					#回傳結果
-
 
7273
					return $result;
-
 
7274
				
-
 
7275
					}#if end
-
 
7276
					
-
 
7277
				#儲存 actionAfterUpdateCert
-
 
7278
				$action=$cInfo["actionAfterUpdateCert"];
-
 
7279
				
-
 
7280
				#如果有多個指令要執行
-
 
7281
				if(gettype($action[0])==="array"){
-
 
7282
					
-
 
7283
					#針對每的指令
-
 
7284
					foreach($action as $ac){
-
 
7285
					
-
 
7286
						#函式說明:
-
 
7287
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
-
 
7288
						#回傳結果:
-
 
7289
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7290
						#$result["error"],錯誤訊息陣列.
-
 
7291
						#$result["function"],當前執行的函數名稱.
-
 
7292
						#$result["argu"],使用的參數.
-
 
7293
						#$result["cmd"],執行的指令名稱.
-
 
7294
						#$result["params"],執行指令伴隨的參數.
-
 
7295
						#必填參數:
-
 
7296
						#$conf["cmdArray"],字串陣列,要執行的指令字串.
-
 
7297
						$conf["external::callShellHelper"]["cmdArray"]=$ac;
-
 
7298
						#可省略參數:
-
 
7299
						#無.
-
 
7300
						#參考資料:
-
 
7301
						#array_shift=>https://www.php.net/manual/en/function.array-shift.php
-
 
7302
						#備註:
-
 
7303
						#無.
-
 
7304
						$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
-
 
7305
						unset($conf["external::callShellHelper"]);
-
 
7306
					
-
 
7307
						#如果執行異常
-
 
7308
						if($callShellHelper["status"]==="false"){
-
 
7309
						
-
 
7310
							#設置錯誤識別
-
 
7311
							$result["status"]="false";
-
 
7312
 
-
 
7313
							#設置錯誤訊息
-
 
7314
							$result["error"]=$callShellHelper;
-
 
7315
 
-
 
7316
							#回傳結果
-
 
7317
							return $result;
-
 
7318
						
-
 
7319
							}#if end
-
 
7320
							
-
 
7321
						#函式說明:
-
 
7322
						#呼叫shell執行系統命令,並取得回傳的內容.
-
 
7323
						#回傳結果:
-
 
7324
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7325
						#$result["error"],錯誤訊息陣列.
-
 
7326
						#$result["function"],當前執行的函數名稱.
-
 
7327
						#$result["argu"],使用的參數.
-
 
7328
						#$result["cmd"],執行的指令內容.
-
 
7329
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
7330
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
7331
						#$result["content"],為執行完後的輸出字串.
-
 
7332
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
7333
						#$result["running"],是否還在執行.
-
 
7334
						#$result["pid"],pid.
-
 
7335
						#$result["statusCode"],執行結束後的代碼.
-
 
7336
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
7337
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
7338
						#必填參數:
-
 
7339
						#$conf["command"],字串,要執行的指令.
-
 
7340
						$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
-
 
7341
						#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
7342
						$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
7343
						#可省略參數:
-
 
7344
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
7345
						$conf["external::callShell"]["argu"]=$callShellHelper["params"];
-
 
7346
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
7347
						#$conf["arguIsAddr"]=array();
-
 
7348
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
7349
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
7350
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
7351
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
7352
						#$conf["enablePrintDescription"]="true";
-
 
7353
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
7354
						#$conf["printDescription"]="";
-
 
7355
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
7356
						$conf["external::callShell"]["escapeshellarg"]="true";
-
 
7357
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
7358
						#$conf["thereIsShellVar"]=array();
-
 
7359
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
7360
						#$conf["username"]="";
-
 
7361
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
7362
						#$conf["password"]="";
-
 
7363
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
7364
						#$conf["useScript"]="";
-
 
7365
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
7366
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
7367
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
7368
						#$conf["inBackGround"]="";
-
 
7369
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
7370
						#$conf["getErr"]="false";
-
 
7371
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
7372
						#$conf["doNotRun"]="false";
-
 
7373
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
-
 
7374
						#$conf["remoteIp"]="";
-
 
7375
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
-
 
7376
						#$conf["remoteUser"]="";
-
 
7377
						#參考資料:
-
 
7378
						#exec=>http://php.net/manual/en/function.exec.php
-
 
7379
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
7380
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
7381
						#備註:
-
 
7382
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
7383
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
7384
						$callShell=external::callShell($conf["external::callShell"]);
-
 
7385
						unset($conf["external::callShell"]);
-
 
7386
					
-
 
7387
						#如果執行異常
-
 
7388
						if($callShellHelper["status"]==="false"){
-
 
7389
						
-
 
7390
							#設置錯誤識別
-
 
7391
							$result["status"]="false";
-
 
7392
 
-
 
7393
							#設置錯誤訊息
-
 
7394
							$result["error"]=$callShell;
-
 
7395
 
-
 
7396
							#回傳結果
-
 
7397
							return $result;
-
 
7398
						
-
 
7399
							}#if end
-
 
7400
					
-
 
7401
						}#foreach end
-
 
7402
					
-
 
7403
					}#if end
-
 
7404
				
-
 
7405
				#反之
-
 
7406
				else{
-
 
7407
				
-
 
7408
					#函式說明:
-
 
7409
					#解析指令與參數,回傳指令與參數給 callShell 函式使用.
-
 
7410
					#回傳結果:
-
 
7411
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7412
					#$result["error"],錯誤訊息陣列.
-
 
7413
					#$result["function"],當前執行的函數名稱.
-
 
7414
					#$result["argu"],使用的參數.
-
 
7415
					#$result["cmd"],執行的指令名稱.
-
 
7416
					#$result["params"],執行指令伴隨的參數.
-
 
7417
					#必填參數:
-
 
7418
					#$conf["cmdArray"],字串陣列,要執行的指令字串.
-
 
7419
					$conf["external::callShellHelper"]["cmdArray"]=$action;
-
 
7420
					#可省略參數:
-
 
7421
					#無.
-
 
7422
					#參考資料:
-
 
7423
					#array_shift=>https://www.php.net/manual/en/function.array-shift.php
-
 
7424
					#備註:
-
 
7425
					#無.
-
 
7426
					$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
-
 
7427
					unset($conf["external::callShellHelper"]);
-
 
7428
				
-
 
7429
					#如果執行異常
-
 
7430
					if($callShellHelper["status"]==="false"){
-
 
7431
					
-
 
7432
						#設置錯誤識別
-
 
7433
						$result["status"]="false";
-
 
7434
 
-
 
7435
						#設置錯誤訊息
-
 
7436
						$result["error"]=$callShellHelper;
-
 
7437
 
-
 
7438
						#回傳結果
-
 
7439
						return $result;
-
 
7440
					
-
 
7441
						}#if end
-
 
7442
						
-
 
7443
					#函式說明:
-
 
7444
					#呼叫shell執行系統命令,並取得回傳的內容.
-
 
7445
					#回傳結果:
-
 
7446
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7447
					#$result["error"],錯誤訊息陣列.
-
 
7448
					#$result["function"],當前執行的函數名稱.
-
 
7449
					#$result["argu"],使用的參數.
-
 
7450
					#$result["cmd"],執行的指令內容.
-
 
7451
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
7452
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
7453
					#$result["content"],為執行完後的輸出字串.
-
 
7454
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
7455
					#$result["running"],是否還在執行.
-
 
7456
					#$result["pid"],pid.
-
 
7457
					#$result["statusCode"],執行結束後的代碼.
-
 
7458
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
7459
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
7460
					#必填參數:
-
 
7461
					#$conf["command"],字串,要執行的指令.
-
 
7462
					$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
-
 
7463
					#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
7464
					$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
7465
					#可省略參數:
-
 
7466
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
7467
					$conf["external::callShell"]["argu"]=$callShellHelper["params"];
-
 
7468
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
7469
					#$conf["arguIsAddr"]=array();
-
 
7470
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
7471
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
7472
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
7473
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
7474
					#$conf["enablePrintDescription"]="true";
-
 
7475
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
7476
					#$conf["printDescription"]="";
-
 
7477
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
7478
					$conf["external::callShell"]["escapeshellarg"]="true";
-
 
7479
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
7480
					#$conf["thereIsShellVar"]=array();
-
 
7481
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
7482
					#$conf["username"]="";
-
 
7483
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
7484
					#$conf["password"]="";
-
 
7485
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
7486
					#$conf["useScript"]="";
-
 
7487
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
7488
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
7489
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
7490
					#$conf["inBackGround"]="";
-
 
7491
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
7492
					#$conf["getErr"]="false";
-
 
7493
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
7494
					#$conf["doNotRun"]="false";
-
 
7495
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
-
 
7496
					#$conf["remoteIp"]="";
-
 
7497
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
-
 
7498
					#$conf["remoteUser"]="";
-
 
7499
					#參考資料:
-
 
7500
					#exec=>http://php.net/manual/en/function.exec.php
-
 
7501
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
7502
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
7503
					#備註:
-
 
7504
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
7505
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
7506
					$callShell=external::callShell($conf["external::callShell"]);
-
 
7507
					unset($conf["external::callShell"]);
-
 
7508
				
-
 
7509
					#如果執行異常
-
 
7510
					if($callShellHelper["status"]==="false"){
-
 
7511
					
-
 
7512
						#設置錯誤識別
-
 
7513
						$result["status"]="false";
-
 
7514
 
-
 
7515
						#設置錯誤訊息
-
 
7516
						$result["error"]=$callShell;
-
 
7517
 
-
 
7518
						#回傳結果
-
 
7519
						return $result;
-
 
7520
					
-
 
7521
						}#if end
-
 
7522
				
-
 
7523
					}#else end
-
 
7524
				
-
 
7525
				}#if end
-
 
7526
				
-
 
7527
			#反之
-
 
7528
			else{
-
 
7529
			
-
 
7530
				#有 issued 的憑證
-
 
7531
				
-
 
7532
				#取得 certificate id at zerossl
-
 
7533
				#函式說明:
-
 
7534
				#將陣列轉換成存有key與value的陣列
-
 
7535
				#回傳的結果:
-
 
7536
				#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
-
 
7537
				#$result["function"],當前執行的函數
-
 
7538
				#$result["error"],錯誤訊息.
-
 
7539
				#$result[$i]["key"],原先$i+1個元素的key.
-
 
7540
				#$result[$i]["value"],原先$i+1個元素的value.
-
 
7541
				#必填參數:
-
 
7542
				#$conf["rawInputArray"],陣列,要轉換的陣列變數.
-
 
7543
				$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
-
 
7544
				#可省略參數:
-
 
7545
				#無.
-
 
7546
				#參考資料:
-
 
7547
				#無.
-
 
7548
				#備註:
-
 
7549
				#無.
-
 
7550
				$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
-
 
7551
				unset($conf["arrays::getKeyAndValue"]);
-
 
7552
				
-
 
7553
				#如果執行異常
-
 
7554
				if($getKeyAndValue["status"]==="false"){
-
 
7555
				
-
 
7556
					#設置錯誤識別
-
 
7557
					$result["status"]="false";
-
 
7558
 
-
 
7559
					#設置錯誤訊息
-
 
7560
					$result["error"]=$getKeyAndValue;
-
 
7561
 
-
 
7562
					#回傳結果
-
 
7563
					return $result;
-
 
7564
				
-
 
7565
					}#if end
-
 
7566
				
-
 
7567
				#儲存 certificate id at zerossl
-
 
7568
				$csrId=$getKeyAndValue["key"][0];
-
 
7569
				
-
 
7570
				#檢查憑證是否已經快過期
-
 
7571
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
-
 
7572
				
-
 
7573
				#如果距離當下不到2個星期就要過期
-
 
7574
				if($expiresIn<=86400*14){
-
 
7575
				
-
 
7576
					#另存舊的憑證id,最後要revoke之.
-
 
7577
					$oldCsrId=$csrId;
-
 
7578
				
-
 
7579
					#確認有無對應 cName 的 private key
-
 
7580
					#函式說明:
-
 
7581
					#檢查多個檔案與資料夾是否存在.
-
 
7582
					#回傳的結果:
-
 
7583
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
-
 
7584
					#$result["error"],錯誤訊息陣列.
-
 
7585
					#$resutl["function"],當前執行的涵式名稱.
-
 
7586
					#$result["argu"],使用的參數.
-
 
7587
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
-
 
7588
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
-
 
7589
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
-
 
7590
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
-
 
7591
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
-
 
7592
					#必填參數:
-
 
7593
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
-
 
7594
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["pKey"]);
-
 
7595
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
7596
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
-
 
7597
					#可省略參數:
-
 
7598
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
-
 
7599
					#$conf["disableWebSearch"]="false";
-
 
7600
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
-
 
7601
					$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
-
 
7602
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
-
 
7603
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
-
 
7604
					#參考資料:
-
 
7605
					#http://php.net/manual/en/function.file-exists.php
-
 
7606
					#http://php.net/manual/en/control-structures.foreach.php
-
 
7607
					#備註:
-
 
7608
					#函數file_exists檢查的路徑為檔案系統的路徑
-
 
7609
					#$result["varName"][$i]結果未實作
-
 
7610
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
-
 
7611
					unset($conf["fileAccess::checkMultiFileExist"]);
-
 
7612
					
-
 
7613
					#如果運行異常
-
 
7614
					if($checkMultiFileExist["status"]==="false"){
-
 
7615
					
-
 
7616
						#設置錯誤識別
-
 
7617
						$result["status"]="false";
-
 
7618
 
-
 
7619
						#設置錯誤訊息
-
 
7620
						$result["error"]=$getCertList;
-
 
7621
 
-
 
7622
						#回傳結果
-
 
7623
						return $result;
-
 
7624
					
-
 
7625
						}#if end
-
 
7626
						
-
 
7627
					#如果沒有 private key
-
 
7628
					if($checkMultiFileExist["allExist"]==="false"){
-
 
7629
					
-
 
7630
						#建立 private key
-
 
7631
						#函式說明:
-
 
7632
						#產生ssl private key.
-
 
7633
						#回傳結果:
-
 
7634
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7635
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
7636
						#$result["function"],當前執行的函式名稱.
-
 
7637
						#$result["argu"],所使用的參數.
-
 
7638
						#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
7639
						#$result["content"],ssl用的private key.
-
 
7640
						#必填參數:
-
 
7641
						#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
7642
						$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
-
 
7643
						#可省略參數:
-
 
7644
						#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
-
 
7645
						#$conf["length"]=4096';
-
 
7646
						#參考資料:
-
 
7647
						#無.
-
 
7648
						#備註:
-
 
7649
						#key generated by openssl with RSA.
-
 
7650
						$createPrivateKey=openssl::createPrivateKey($conf["openssl::createPrivateKey"]);
-
 
7651
						unset($conf["openssl::createPrivateKey"]);
-
 
7652
					
-
 
7653
						#如果運行異常
-
 
7654
						if($createPrivateKey["status"]==="false"){
-
 
7655
						
-
 
7656
							#設置錯誤識別
-
 
7657
							$result["status"]="false";
-
 
7658
 
-
 
7659
							#設置錯誤訊息
-
 
7660
							$result["error"]=$createPrivateKey;
-
 
7661
 
-
 
7662
							#回傳結果
-
 
7663
							return $result;
-
 
7664
						
-
 
7665
							}#if end
-
 
7666
							
-
 
7667
						#另存private key的字串
-
 
7668
						$pKeyStr=$createPrivateKey["content"];
-
 
7669
					
-
 
7670
						#建立private key檔案
-
 
7671
						#函式說明:
-
 
7672
						#將字串寫入到檔案
-
 
7673
						#回傳結果:
-
 
7674
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
-
 
7675
						#$result["error"],錯誤訊息陣列.
-
 
7676
						#$result["function"],當前執行的函數名稱.
-
 
7677
						#$result["fileInfo"],實際上寫入的檔案資訊陣列.
-
 
7678
						#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
-
 
7679
						#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
-
 
7680
						#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
-
 
7681
						#$result["argu"],使用的參數.
-
 
7682
						#必填參數:
-
 
7683
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
7684
						$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
-
 
7685
						#可省略參數:
-
 
7686
						#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
-
 
7687
						$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["pKey"];
-
 
7688
						#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
-
 
7689
						$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
-
 
7690
						#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
-
 
7691
						#$conf["writeMethod"]="a";
-
 
7692
						#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
-
 
7693
						#$conf["checkRepeat"]="";
-
 
7694
						#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
-
 
7695
						#$conf["filenameExtensionStartPoint"]="";
-
 
7696
						#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
-
 
7697
						#$conf["repeatNameRule"]="";
-
 
7698
						#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
-
 
7699
						$conf["zerossl::writeTextIntoFile"]["web"]="false";
-
 
7700
						#參考資料:
-
 
7701
						#無.
-
 
7702
						#備註:
-
 
7703
						#無.
-
 
7704
						$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
-
 
7705
						unset($conf["zerossl::writeTextIntoFile"]);
-
 
7706
					
-
 
7707
						#如果運行異常
-
 
7708
						if($writeTextIntoFile["status"]==="false"){
-
 
7709
						
-
 
7710
							#設置錯誤識別
-
 
7711
							$result["status"]="false";
-
 
7712
 
-
 
7713
							#設置錯誤訊息
-
 
7714
							$result["error"]=$writeTextIntoFile;
-
 
7715
 
-
 
7716
							#回傳結果
-
 
7717
							return $result;
-
 
7718
						
-
 
7719
							}#if end
-
 
7720
							
-
 
7721
						}#if end
-
 
7722
					
-
 
7723
					#建立準備給zerossl的csr
-
 
7724
					#函式說明:
-
 
7725
					#產生certificate sign request(CSR).
-
 
7726
					#回傳結果:
-
 
7727
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7728
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
7729
					#$result["function"],當前執行的函式名稱.
-
 
7730
					#$result["argu"],所使用的參數.
-
 
7731
					#$result["content"],csr內容.
-
 
7732
					#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
7733
					#$result["privateKey"], private key 的內容.
-
 
7734
					#必填參數:
-
 
7735
					#$conf["domain"],字串,csr內容的網域名稱.
-
 
7736
					$conf["zerossl::createCSR"]["domain"]=$cName;
-
 
7737
					#可省略參數:
-
 
7738
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
-
 
7739
					#$conf["pKey"]="";
-
 
7740
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
-
 
7741
					#$conf["country"]="";
-
 
7742
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
-
 
7743
					#$conf["state"]="";
-
 
7744
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
-
 
7745
					#$conf["org"]="";
-
 
7746
					#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
-
 
7747
					#$conf["unit"]="";
-
 
7748
					#參考資料:
-
 
7749
					#無.
-
 
7750
					#備註:
-
 
7751
					#無.
-
 
7752
					$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
-
 
7753
					unset($conf["zerossl::createCSR"]);
-
 
7754
					
-
 
7755
					#如果運行異常
-
 
7756
					if($createCSR["status"]==="false"){
-
 
7757
					
-
 
7758
						#設置錯誤識別
-
 
7759
						$result["status"]="false";
-
 
7760
 
-
 
7761
						#設置錯誤訊息
-
 
7762
						$result["error"]=$createCSR;
-
 
7763
 
-
 
7764
						#回傳結果
-
 
7765
						return $result;
-
 
7766
					
-
 
7767
						}#if end
-
 
7768
						
-
 
7769
					#取得本地端產生的csr內容
-
 
7770
					$csrLocal=$createCSR["content"];
-
 
7771
					
-
 
7772
					#函式說明:
-
 
7773
					#提供certificate sign request(CSR)透過zerossl產生cergificate.
-
 
7774
					#回傳結果:
-
 
7775
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7776
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
7777
					#$result["function"],當前執行的函式名稱.
-
 
7778
					#$result["argu"],所使用的參數.
-
 
7779
					#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
7780
					#$result["id"],用於zerossl api驗證domain的id.
-
 
7781
					#$result["content"],字串,得到的json字串回應.
-
 
7782
					#$result["cnameKey"],用於dns CNAME驗證鍵名.
-
 
7783
					#$result["cnameVal"],用於dms CNAME驗證鍵值.
-
 
7784
					#必填參數:
-
 
7785
					#$conf["certificate_domains"],字串,要簽署的doamin名稱.
-
 
7786
					$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
-
 
7787
					#$conf["certificate_csr"],字串,簽署的資訊.
-
 
7788
					$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
-
 
7789
					#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
7790
					$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
-
 
7791
					#可省略參數:
-
 
7792
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
7793
					$conf["zerossl::createCertificate"]["apiDomain"]=$cInfo["domain"];
-
 
7794
					#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
-
 
7795
					#$conf["path"]=self::getApiInfo()["csrPath"];
-
 
7796
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
7797
					$conf["zerossl::createCertificate"]["key"]=$cInfo["key"];
-
 
7798
					#參考資料:
-
 
7799
					#無.
-
 
7800
					#備註:
-
 
7801
					#無.
-
 
7802
					$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
-
 
7803
					unset($conf["zerossl::createCertificate"]);
-
 
7804
					
-
 
7805
					#如果執行異常
-
 
7806
					if($createCertificate["status"]==="false"){
-
 
7807
					
-
 
7808
						#設置錯誤識別
-
 
7809
						$result["status"]="false";
-
 
7810
 
-
 
7811
						#設置錯誤訊息
-
 
7812
						$result["error"]=$createCertificate;
-
 
7813
 
-
 
7814
						#回傳結果
-
 
7815
						return $result;
-
 
7816
					
-
 
7817
						}#if end
-
 
7818
					
-
 
7819
					#取得csr在zerossl上的id
-
 
7820
					$csrId=$createCertificate["id"];
-
 
7821
					
-
 
7822
					#取得cname key
-
 
7823
					$cNameKey=$createCertificate["cnameKey"];
-
 
7824
					
-
 
7825
					#取得cname val
-
 
7826
					$cNameVal=$createCertificate["cnameVal"];
-
 
7827
					
-
 
7828
					#初始化要增加的RR記錄
-
 
7829
					$rr2add=array();
-
 
7830
					
-
 
7831
					#設置CNAME的查詢
-
 
7832
					$rr2add["query"]=$cNameKey;
-
 
7833
					
-
 
7834
					#設置CNAME的value
-
 
7835
					$rr2add["value"]=$cNameVal;
-
 
7836
					
-
 
7837
					#設置類型為 CNAME
-
 
7838
					$rr2add["type"]="CNAME";
-
 
7839
					
-
 
7840
					#設置註解
-
 
7841
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
-
 
7842
					
-
 
7843
					#函式說明:
-
 
7844
					#新增DNS記錄到檔案裡面.
-
 
7845
					#回傳結果:
-
 
7846
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7847
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
7848
					#$result["function"],當前執行的函式名稱.
-
 
7849
					#$result["argu"],所使用的參數.
-
 
7850
					#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
-
 
7851
					#$result["domain"],字串,RR所屬domain.
-
 
7852
					#$result["defaultTTL"],字串,預設的RR更新時間.
-
 
7853
					#$result["comment"],字串陣列,逐行的註解.
-
 
7854
					#必填參數:
-
 
7855
					#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
-
 
7856
					$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2ad);
-
 
7857
					#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
-
 
7858
					$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
-
 
7859
					#可省略參數:
-
 
7860
					#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
-
 
7861
					$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
-
 
7862
					#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
-
 
7863
					#$conf["debug"]="false";
-
 
7864
					#參考資料:
-
 
7865
					#無.
-
 
7866
					#備註:
-
 
7867
					#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
-
 
7868
					#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
-
 
7869
					#php-pear上的Net_DNS2也可以解析RR.
-
 
7870
					$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
-
 
7871
					unset($conf["zerossl::updateDnsRecordFile"]);
-
 
7872
					
-
 
7873
					#如果執行異常
-
 
7874
					if($updateDnsRecordFile["status"]==="false"){
-
 
7875
					
-
 
7876
						#設置錯誤識別
-
 
7877
						$result["status"]="false";
-
 
7878
 
-
 
7879
						#設置錯誤訊息
-
 
7880
						$result["error"]=$updateDnsRecordFile;
-
 
7881
 
-
 
7882
						#回傳結果
-
 
7883
						return $result;
-
 
7884
					
-
 
7885
						}#if end
-
 
7886
						
-
 
7887
					#重新啟動dns伺服器
-
 
7888
					#函式說明:
-
 
7889
					#呼叫shell執行系統命令,並取得回傳的內容.
-
 
7890
					#回傳結果:
-
 
7891
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7892
					#$result["error"],錯誤訊息陣列.
-
 
7893
					#$result["function"],當前執行的函數名稱.
-
 
7894
					#$result["argu"],使用的參數.
-
 
7895
					#$result["cmd"],執行的指令內容.
-
 
7896
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
7897
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
7898
					#$result["content"],為執行完後的輸出字串.
-
 
7899
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
7900
					#$result["running"],是否還在執行.
-
 
7901
					#$result["pid"],pid.
-
 
7902
					#$result["statusCode"],執行結束後的代碼.
-
 
7903
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
7904
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
7905
					#必填參數:
-
 
7906
					#$conf["command"],字串,要執行的指令.
-
 
7907
					$conf["external::callShell"]["command"]="systemd";
-
 
7908
					#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
7909
					$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
7910
					#可省略參數:
-
 
7911
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
7912
					$conf["external::callShell"]["argu"]=array("restart","named");
-
 
7913
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
7914
					#$conf["arguIsAddr"]=array();
-
 
7915
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
7916
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
7917
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
7918
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
7919
					#$conf["enablePrintDescription"]="true";
-
 
7920
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
7921
					#$conf["printDescription"]="";
-
 
7922
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
7923
					#$conf["escapeshellarg"]="false";
-
 
7924
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
7925
					#$conf["thereIsShellVar"]=array();
-
 
7926
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
7927
					#$conf["username"]="";
-
 
7928
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
7929
					#$conf["password"]="";
-
 
7930
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
7931
					#$conf["useScript"]="";
-
 
7932
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
7933
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
7934
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
7935
					#$conf["inBackGround"]="";
-
 
7936
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
7937
					#$conf["getErr"]="false";
-
 
7938
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
7939
					#$conf["doNotRun"]="false";
-
 
7940
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
-
 
7941
					$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
-
 
7942
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
-
 
7943
					#$conf["remoteUser"]="root";
-
 
7944
					#參考資料:
-
 
7945
					#exec=>http://php.net/manual/en/function.exec.php
-
 
7946
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
7947
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
7948
					#備註:
-
 
7949
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
7950
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
7951
					$callShell=external::callShell($conf["external::callShell"]);
-
 
7952
					unset($conf["external::callShell"]);
-
 
7953
					
-
 
7954
					#如果執行異常
-
 
7955
					if($callShell["status"]==="false"){
-
 
7956
					
-
 
7957
						#設置錯誤識別
-
 
7958
						$result["status"]="false";
-
 
7959
 
-
 
7960
						#設置錯誤訊息
-
 
7961
						$result["error"]=$callShell;
-
 
7962
 
-
 
7963
						#回傳結果
-
 
7964
						return $result;
-
 
7965
					
-
 
7966
						}#if end
-
 
7967
						
-
 
7968
					#函式說明:
-
 
7969
					#請求驗證已經透過zerossl::createCertificate要求的domain.
-
 
7970
					#回傳結果:
-
 
7971
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
7972
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
7973
					#$result["function"],當前執行的函式名稱.
-
 
7974
					#$result["argu"],所使用的參數.
-
 
7975
					#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
7976
					#$result["content"],結果json字串.
-
 
7977
					#必填參數:
-
 
7978
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
-
 
7979
					$conf["zerossl::verifyDomain"]["id"]=$csrId;
-
 
7980
					#可省略參數:
-
 
7981
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
7982
					$conf["zerossl::verifyDomain"]["apiDomain"]=$cInfo["domain"];
-
 
7983
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
7984
					$conf["zerossl::verifyDomain"]["key"]=$cInfo["key"];
-
 
7985
					#參考資料:
-
 
7986
					#https://zerossl.com/documentation/api/verify-domains/
-
 
7987
					#備註:
-
 
7988
					#無.
-
 
7989
					$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
-
 
7990
					unset($conf["zerossl::verifyDomain"]);
-
 
7991
					
-
 
7992
					#如果執行異常
-
 
7993
					if($verifyDomain["status"]==="false"){
-
 
7994
					
-
 
7995
						#設置錯誤識別
-
 
7996
						$result["status"]="false";
-
 
7997
 
-
 
7998
						#設置錯誤訊息
-
 
7999
						$result["error"]=$verifyDomain;
-
 
8000
 
-
 
8001
						#回傳結果
-
 
8002
						return $result;
-
 
8003
					
-
 
8004
						}#if end
-
 
8005
						
-
 
8006
					#函式說明:
-
 
8007
					#下載certificate.
-
 
8008
					#回傳結果:
-
 
8009
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8010
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
8011
					#$result["function"],當前執行的函式名稱.
-
 
8012
					#$result["argu"],所使用的參數.
-
 
8013
					#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
8014
					#$result["content"],結果json字串.
-
 
8015
					#$result["certificate.crt"],字串,certificate.crt的內容.
-
 
8016
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
-
 
8017
					#必填參數:
-
 
8018
					#無.
-
 
8019
					#可省略參數:
-
 
8020
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
8021
					$conf["zerossl::getCert"]["apiDomain"]=$cInfo["domain"];
-
 
8022
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
8023
					$conf["zerossl::getCert"]["key"]=$cInfo["key"];
-
 
8024
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
-
 
8025
					$conf["zerossl::getCert"]["id"]=$csrId;
-
 
8026
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
-
 
8027
					#$conf["zerossl::getCert"]["cname"]="";
-
 
8028
					#參考資料:
-
 
8029
					#https://zerossl.com/documentation/api/download-certificate-inline/
-
 
8030
					#備註:
-
 
8031
					#無.
-
 
8032
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
-
 
8033
					unset($conf["zerossl::getCert"]);
-
 
8034
					
-
 
8035
					#如果執行異常
-
 
8036
					if($getCert["status"]==="false"){
-
 
8037
					
-
 
8038
						#設置錯誤識別
-
 
8039
						$result["status"]="false";
-
 
8040
 
-
 
8041
						#設置錯誤訊息
-
 
8042
						$result["error"]=$getCert;
-
 
8043
 
-
 
8044
						#回傳結果
-
 
8045
						return $result;
-
 
8046
					
-
 
8047
						}#if end
-
 
8048
						
-
 
8049
					#建立 certificate.crt 檔案
-
 
8050
					#$cInfo["certPath"];
-
 
8051
					
-
 
8052
					#建立 ca_bundle.crt 檔案
-
 
8053
					#$cInfo["caPath"];
-
 
8054
					
-
 
8055
					#建立 certAndCa.crt 檔案
-
 
8056
					#$cInfo["certWithCaPath"];
-
 
8057
					
-
 
8058
					#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
-
 
8059
					#函式說明:
-
 
8060
					#一次建立多個檔案,並寫入內容.
-
 
8061
					#回傳結果:
-
 
8062
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
-
 
8063
					#$result["error"],錯誤訊息陣列.
-
 
8064
					#$result["function"],當前執行的函數名稱.
-
 
8065
					#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
-
 
8066
					#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
-
 
8067
					#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
-
 
8068
					#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
-
 
8069
					#$result["argu"],使用的參數.
-
 
8070
					#必填參數:
-
 
8071
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
8072
					$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
-
 
8073
					#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
-
 
8074
					$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certPath"],$cInfo["caPath"],$cInfo["certWithCaPath"]);
-
 
8075
					#可省略參數:
-
 
8076
					#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
-
 
8077
					$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
-
 
8078
					#參考資料:
-
 
8079
					#無.
-
 
8080
					#備註:
-
 
8081
					#無.
-
 
8082
					$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
-
 
8083
					unset($conf["zerossl::writeMultiFile"]);
-
 
8084
					
-
 
8085
					#如果執行異常
-
 
8086
					if($writeMultiFile["status"]==="false"){
-
 
8087
					
-
 
8088
						#設置錯誤識別
-
 
8089
						$result["status"]="false";
-
 
8090
 
-
 
8091
						#設置錯誤訊息
-
 
8092
						$result["error"]=$writeMultiFile;
-
 
8093
 
-
 
8094
						#回傳結果
-
 
8095
						return $result;
-
 
8096
					
-
 
8097
						}#if end
-
 
8098
						
-
 
8099
					#儲存 actionAfterUpdateCert
-
 
8100
					$action=$cInfo["actionAfterUpdateCert"];
-
 
8101
					
-
 
8102
					#如果有多個指令要執行
-
 
8103
					if(gettype($action[0])==="array"){
-
 
8104
						
-
 
8105
						#針對每的指令
-
 
8106
						foreach($action as $ac){
-
 
8107
						
-
 
8108
							#函式說明:
-
 
8109
							#解析指令與參數,回傳指令與參數給 callShell 函式使用.
-
 
8110
							#回傳結果:
-
 
8111
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8112
							#$result["error"],錯誤訊息陣列.
-
 
8113
							#$result["function"],當前執行的函數名稱.
-
 
8114
							#$result["argu"],使用的參數.
-
 
8115
							#$result["cmd"],執行的指令名稱.
-
 
8116
							#$result["params"],執行指令伴隨的參數.
-
 
8117
							#必填參數:
-
 
8118
							#$conf["cmdArray"],字串陣列,要執行的指令字串.
-
 
8119
							$conf["external::callShellHelper"]["cmdArray"]=$ac;
-
 
8120
							#可省略參數:
-
 
8121
							#無.
-
 
8122
							#參考資料:
-
 
8123
							#array_shift=>https://www.php.net/manual/en/function.array-shift.php
-
 
8124
							#備註:
-
 
8125
							#無.
-
 
8126
							$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
-
 
8127
							unset($conf["external::callShellHelper"]);
-
 
8128
						
-
 
8129
							#如果執行異常
-
 
8130
							if($callShellHelper["status"]==="false"){
-
 
8131
							
-
 
8132
								#設置錯誤識別
-
 
8133
								$result["status"]="false";
-
 
8134
 
-
 
8135
								#設置錯誤訊息
-
 
8136
								$result["error"]=$callShellHelper;
-
 
8137
 
-
 
8138
								#回傳結果
-
 
8139
								return $result;
-
 
8140
							
-
 
8141
								}#if end
-
 
8142
								
-
 
8143
							#函式說明:
-
 
8144
							#呼叫shell執行系統命令,並取得回傳的內容.
-
 
8145
							#回傳結果:
-
 
8146
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8147
							#$result["error"],錯誤訊息陣列.
-
 
8148
							#$result["function"],當前執行的函數名稱.
-
 
8149
							#$result["argu"],使用的參數.
-
 
8150
							#$result["cmd"],執行的指令內容.
-
 
8151
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
8152
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
8153
							#$result["content"],為執行完後的輸出字串.
-
 
8154
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
8155
							#$result["running"],是否還在執行.
-
 
8156
							#$result["pid"],pid.
-
 
8157
							#$result["statusCode"],執行結束後的代碼.
-
 
8158
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
8159
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
8160
							#必填參數:
-
 
8161
							#$conf["command"],字串,要執行的指令.
-
 
8162
							$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
-
 
8163
							#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
8164
							$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
8165
							#可省略參數:
-
 
8166
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
8167
							$conf["external::callShell"]["argu"]=$callShellHelper["params"];
-
 
8168
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
8169
							#$conf["arguIsAddr"]=array();
-
 
8170
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
8171
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
8172
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
8173
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
8174
							#$conf["enablePrintDescription"]="true";
-
 
8175
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
8176
							#$conf["printDescription"]="";
-
 
8177
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
8178
							$conf["external::callShell"]["escapeshellarg"]="true";
-
 
8179
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
8180
							#$conf["thereIsShellVar"]=array();
-
 
8181
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
8182
							#$conf["username"]="";
-
 
8183
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
8184
							#$conf["password"]="";
-
 
8185
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
8186
							#$conf["useScript"]="";
-
 
8187
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
8188
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
8189
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
8190
							#$conf["inBackGround"]="";
-
 
8191
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
8192
							#$conf["getErr"]="false";
-
 
8193
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
8194
							#$conf["doNotRun"]="false";
-
 
8195
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
-
 
8196
							#$conf["remoteIp"]="";
-
 
8197
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
-
 
8198
							#$conf["remoteUser"]="";
-
 
8199
							#參考資料:
-
 
8200
							#exec=>http://php.net/manual/en/function.exec.php
-
 
8201
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
8202
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
8203
							#備註:
-
 
8204
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
8205
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
8206
							$callShell=external::callShell($conf["external::callShell"]);
-
 
8207
							unset($conf["external::callShell"]);
-
 
8208
						
-
 
8209
							#如果執行異常
-
 
8210
							if($callShellHelper["status"]==="false"){
-
 
8211
							
-
 
8212
								#設置錯誤識別
-
 
8213
								$result["status"]="false";
-
 
8214
 
-
 
8215
								#設置錯誤訊息
-
 
8216
								$result["error"]=$callShell;
-
 
8217
 
-
 
8218
								#回傳結果
-
 
8219
								return $result;
-
 
8220
							
-
 
8221
								}#if end
-
 
8222
						
-
 
8223
							}#foreach end
-
 
8224
						
-
 
8225
						}#if end
-
 
8226
					
-
 
8227
					#反之
-
 
8228
					else{
-
 
8229
					
-
 
8230
						#函式說明:
-
 
8231
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
-
 
8232
						#回傳結果:
-
 
8233
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8234
						#$result["error"],錯誤訊息陣列.
-
 
8235
						#$result["function"],當前執行的函數名稱.
-
 
8236
						#$result["argu"],使用的參數.
-
 
8237
						#$result["cmd"],執行的指令名稱.
-
 
8238
						#$result["params"],執行指令伴隨的參數.
-
 
8239
						#必填參數:
-
 
8240
						#$conf["cmdArray"],字串陣列,要執行的指令字串.
-
 
8241
						$conf["external::callShellHelper"]["cmdArray"]=$action;
-
 
8242
						#可省略參數:
-
 
8243
						#無.
-
 
8244
						#參考資料:
-
 
8245
						#array_shift=>https://www.php.net/manual/en/function.array-shift.php
-
 
8246
						#備註:
-
 
8247
						#無.
-
 
8248
						$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
-
 
8249
						unset($conf["external::callShellHelper"]);
-
 
8250
					
-
 
8251
						#如果執行異常
-
 
8252
						if($callShellHelper["status"]==="false"){
-
 
8253
						
-
 
8254
							#設置錯誤識別
-
 
8255
							$result["status"]="false";
-
 
8256
 
-
 
8257
							#設置錯誤訊息
-
 
8258
							$result["error"]=$callShellHelper;
-
 
8259
 
-
 
8260
							#回傳結果
-
 
8261
							return $result;
-
 
8262
						
-
 
8263
							}#if end
-
 
8264
							
-
 
8265
						#函式說明:
-
 
8266
						#呼叫shell執行系統命令,並取得回傳的內容.
-
 
8267
						#回傳結果:
-
 
8268
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8269
						#$result["error"],錯誤訊息陣列.
-
 
8270
						#$result["function"],當前執行的函數名稱.
-
 
8271
						#$result["argu"],使用的參數.
-
 
8272
						#$result["cmd"],執行的指令內容.
-
 
8273
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
8274
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
8275
						#$result["content"],為執行完後的輸出字串.
-
 
8276
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
8277
						#$result["running"],是否還在執行.
-
 
8278
						#$result["pid"],pid.
-
 
8279
						#$result["statusCode"],執行結束後的代碼.
-
 
8280
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
8281
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
8282
						#必填參數:
-
 
8283
						#$conf["command"],字串,要執行的指令.
-
 
8284
						$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
-
 
8285
						#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
8286
						$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
8287
						#可省略參數:
-
 
8288
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
8289
						$conf["external::callShell"]["argu"]=$callShellHelper["params"];
-
 
8290
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
8291
						#$conf["arguIsAddr"]=array();
-
 
8292
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
8293
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
8294
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
8295
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
8296
						#$conf["enablePrintDescription"]="true";
-
 
8297
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
8298
						#$conf["printDescription"]="";
-
 
8299
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
8300
						$conf["external::callShell"]["escapeshellarg"]="true";
-
 
8301
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
8302
						#$conf["thereIsShellVar"]=array();
-
 
8303
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
8304
						#$conf["username"]="";
-
 
8305
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
8306
						#$conf["password"]="";
-
 
8307
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
8308
						#$conf["useScript"]="";
-
 
8309
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
8310
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
8311
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
8312
						#$conf["inBackGround"]="";
-
 
8313
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
8314
						#$conf["getErr"]="false";
-
 
8315
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
8316
						#$conf["doNotRun"]="false";
-
 
8317
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
-
 
8318
						#$conf["remoteIp"]="";
-
 
8319
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
-
 
8320
						#$conf["remoteUser"]="";
-
 
8321
						#參考資料:
-
 
8322
						#exec=>http://php.net/manual/en/function.exec.php
-
 
8323
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
8324
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
8325
						#備註:
-
 
8326
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
8327
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
8328
						$callShell=external::callShell($conf["external::callShell"]);
-
 
8329
						unset($conf["external::callShell"]);
-
 
8330
					
-
 
8331
						#如果執行異常
-
 
8332
						if($callShellHelper["status"]==="false"){
-
 
8333
						
-
 
8334
							#設置錯誤識別
-
 
8335
							$result["status"]="false";
-
 
8336
 
-
 
8337
							#設置錯誤訊息
-
 
8338
							$result["error"]=$callShell;
-
 
8339
 
-
 
8340
							#回傳結果
-
 
8341
							return $result;
-
 
8342
						
-
 
8343
							}#if end
-
 
8344
					
-
 
8345
						}#else end
-
 
8346
						
-
 
8347
					#要移除舊的憑證 
-
 
8348
					
-
 
8349
					#舊憑證於zerossl上的id
-
 
8350
					#$oldCsrId
-
 
8351
					
-
 
8352
					#移除舊的憑證
-
 
8353
					#函式說明:
-
 
8354
					#請求廢除 issued zerossl certificate.
-
 
8355
					#回傳結果:
-
 
8356
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8357
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
8358
					#$result["function"],當前執行的函式名稱.
-
 
8359
					#$result["argu"],所使用的參數.
-
 
8360
					#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
8361
					#$result["content"],結果json字串.
-
 
8362
					#必填參數:
-
 
8363
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
-
 
8364
					$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
-
 
8365
					#可省略參數:
-
 
8366
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
8367
					$conf["zerosssl::revokeCert"]["apiDomain"]=$cInfo["domain"];
-
 
8368
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
8369
					$conf["zerosssl::revokeCert"]["key"]=$cInfo["key"];
-
 
8370
					#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
-
 
8371
					$conf["zerosssl::revokeCert"]["reason"]="Superseded";
-
 
8372
					#參考資料:
-
 
8373
					#https://zerossl.com/documentation/api/revoke-certificate/
-
 
8374
					#備註:
-
 
8375
					#無.
-
 
8376
					$revokeCert=zerosssl::revokeCert($conf["zerosssl::revokeCert"]);
-
 
8377
					unset($conf["zerosssl::revokeCert"]);
-
 
8378
				
-
 
8379
					#如果執行異常
-
 
8380
					if($revokeCert["status"]==="false"){
-
 
8381
					
-
 
8382
						#設置錯誤識別
-
 
8383
						$result["status"]="false";
-
 
8384
 
-
 
8385
						#設置錯誤訊息
-
 
8386
						$result["error"]=$revokeCert;
-
 
8387
 
-
 
8388
						#回傳結果
-
 
8389
						return $result;
-
 
8390
				
-
 
8391
					}#if end
-
 
8392
					
-
 
8393
				#反之,尚不需要提前申請新的憑證
-
 
8394
				else{
-
 
8395
				
-
 
8396
					#下載憑證
-
 
8397
					#函式說明:
-
 
8398
					#下載certificate.
-
 
8399
					#回傳結果:
-
 
8400
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8401
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
8402
					#$result["function"],當前執行的函式名稱.
-
 
8403
					#$result["argu"],所使用的參數.
-
 
8404
					#$result["curl_verbose_info"],curl執行的詳細資訊.
-
 
8405
					#$result["content"],結果json字串.
-
 
8406
					#$result["certificate.crt"],字串,certificate.crt的內容.
-
 
8407
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
-
 
8408
					#必填參數:
-
 
8409
					#無.
-
 
8410
					#可省略參數:
-
 
8411
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
-
 
8412
					$conf["zerossl::getCert"]["apiDomain"]=$cInfo["domain"];
-
 
8413
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
-
 
8414
					$conf["zerossl::getCert"]["key"]=$cInfo["key"];
-
 
8415
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
-
 
8416
					$conf["zerossl::getCert"]["id"]=$csrId;
-
 
8417
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
-
 
8418
					#$conf["zerossl::getCert"]["cname"]="";
-
 
8419
					#參考資料:
-
 
8420
					#https://zerossl.com/documentation/api/download-certificate-inline/
-
 
8421
					#備註:
-
 
8422
					#無.
-
 
8423
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
-
 
8424
					unset($conf["zerossl::getCert"]);
-
 
8425
					
-
 
8426
					#如果執行異常
-
 
8427
					if($getCert["status"]==="false"){
-
 
8428
					
-
 
8429
						#設置錯誤識別
-
 
8430
						$result["status"]="false";
-
 
8431
 
-
 
8432
						#設置錯誤訊息
-
 
8433
						$result["error"]=$getCert;
-
 
8434
 
-
 
8435
						#回傳結果
-
 
8436
						return $result;
-
 
8437
					
-
 
8438
						}#if end
-
 
8439
						
-
 
8440
					#zerossl上的certificate.crt內容
-
 
8441
					#$getCert["certificate.crt"];
-
 
8442
						
-
 
8443
					#zerossl上的ca_bundle.crt內容
-
 
8444
					#$getCert["ca_bundle.crt"];
-
 
8445
					
-
 
8446
					#certificate.crt and ca_bundle.crt 合併後的檔案內容
-
 
8447
					#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
-
 
8448
						
-
 
8449
					#certificate.crt 檔案
-
 
8450
					#$cInfo["certPath"];
-
 
8451
					
-
 
8452
					#ca_bundle.crt 檔案
-
 
8453
					#$cInfo["caPath"];
-
 
8454
					
-
 
8455
					#certAndCa.crt 檔案
-
 
8456
					#$cInfo["certWithCaPath"];
-
 
8457
				
-
 
8458
					#取得既有的 certificate.crt 檔案內容
-
 
8459
					#函式說明:
-
 
8460
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
-
 
8461
					#回傳的變數說明:
-
 
8462
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
-
 
8463
					#$result["error"],錯誤訊息提示.
-
 
8464
					#$result["warning"],警告訊息.
-
 
8465
					#$result["function"],當前執行的函數名稱.
-
 
8466
					#$result["fileContent"],爲檔案的內容陣列.
-
 
8467
					#$result["lineCount"],爲檔案內容總共的行數.
-
 
8468
					#$result["fullContent"],為檔案的完整內容.
-
 
8469
					#$result["base64dataOnly"],檔案的base64data.
-
 
8470
					#$result["base64data"],為在網頁上給予src參數的數值.
-
 
8471
					#$result["mimeType"],為檔案的mime type.
-
 
8472
					#必填參數:
-
 
8473
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
-
 
8474
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["certPath"];
-
 
8475
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
8476
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
-
 
8477
					#可省略參數:
-
 
8478
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
-
 
8479
					#$conf["web"]="true";
-
 
8480
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
-
 
8481
					#$conf["createIfnotExist"]="false";
-
 
8482
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
-
 
8483
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
-
 
8484
					#參考資料:
-
 
8485
					#file(),取得檔案內容的行數.
-
 
8486
					#file=>http:#php.net/manual/en/function.file.php
-
 
8487
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
-
 
8488
					#filesize=>http://php.net/manual/en/function.filesize.php
-
 
8489
					#參考資料:
-
 
8490
					#無.
-
 
8491
					#備註:
-
 
8492
					#無.
-
 
8493
					$getFileContent=fileAccesss::getFileContent($conf["fileAccesss::getFileContent"]);
-
 
8494
					unset($conf["fileAccesss::getFileContent"]);
-
 
8495
				
-
 
8496
					#如果執行異常
-
 
8497
					if($getFileContent["status"]==="false"){
-
 
8498
					
-
 
8499
						#設置錯誤識別
-
 
8500
						$result["status"]="false";
-
 
8501
 
-
 
8502
						#設置錯誤訊息
-
 
8503
						$result["error"]=$getFileContent;
-
 
8504
 
-
 
8505
						#回傳結果
-
 
8506
						return $result;
-
 
8507
					
-
 
8508
						}#if end
-
 
8509
				
-
 
8510
					#如果既有憑證跟剛下載的憑證不一樣
-
 
8511
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
-
 
8512
					
-
 
8513
						#識別要改成下載好的憑證
-
 
8514
						$certificate_need_update="true";
-
 
8515
					
-
 
8516
						}#if end
-
 
8517
						
-
 
8518
					#取得既有的 ca_bundle.crt 檔案內容
-
 
8519
					#函式說明:
-
 
8520
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
-
 
8521
					#回傳的變數說明:
-
 
8522
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
-
 
8523
					#$result["error"],錯誤訊息提示.
-
 
8524
					#$result["warning"],警告訊息.
-
 
8525
					#$result["function"],當前執行的函數名稱.
-
 
8526
					#$result["fileContent"],爲檔案的內容陣列.
-
 
8527
					#$result["lineCount"],爲檔案內容總共的行數.
-
 
8528
					#$result["fullContent"],為檔案的完整內容.
-
 
8529
					#$result["base64dataOnly"],檔案的base64data.
-
 
8530
					#$result["base64data"],為在網頁上給予src參數的數值.
-
 
8531
					#$result["mimeType"],為檔案的mime type.
-
 
8532
					#必填參數:
-
 
8533
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
-
 
8534
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["caPath"];
-
 
8535
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
8536
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
-
 
8537
					#可省略參數:
-
 
8538
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
-
 
8539
					#$conf["web"]="true";
-
 
8540
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
-
 
8541
					#$conf["createIfnotExist"]="false";
-
 
8542
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
-
 
8543
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
-
 
8544
					#參考資料:
-
 
8545
					#file(),取得檔案內容的行數.
-
 
8546
					#file=>http:#php.net/manual/en/function.file.php
-
 
8547
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
-
 
8548
					#filesize=>http://php.net/manual/en/function.filesize.php
-
 
8549
					#參考資料:
-
 
8550
					#無.
-
 
8551
					#備註:
-
 
8552
					#無.
-
 
8553
					$getFileContent=fileAccesss::getFileContent($conf["fileAccesss::getFileContent"]);
-
 
8554
					unset($conf["fileAccesss::getFileContent"]);
-
 
8555
				
-
 
8556
					#如果執行異常
-
 
8557
					if($getFileContent["status"]==="false"){
-
 
8558
					
-
 
8559
						#設置錯誤識別
-
 
8560
						$result["status"]="false";
-
 
8561
 
-
 
8562
						#設置錯誤訊息
-
 
8563
						$result["error"]=$getFileContent;
-
 
8564
 
-
 
8565
						#回傳結果
-
 
8566
						return $result;
-
 
8567
					
-
 
8568
						}#if end
-
 
8569
				
-
 
8570
					#如果既有憑證跟剛下載的憑證不一樣
-
 
8571
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
-
 
8572
					
-
 
8573
						#識別要改成下載好的憑證
-
 
8574
						$ca_bundle_need_update="true";
-
 
8575
					
-
 
8576
						}#if end
-
 
8577
					
-
 
8578
					#取得既有的 certWithCa 檔案內容
-
 
8579
					#函式說明:
-
 
8580
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
-
 
8581
					#回傳的變數說明:
-
 
8582
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
-
 
8583
					#$result["error"],錯誤訊息提示.
-
 
8584
					#$result["warning"],警告訊息.
-
 
8585
					#$result["function"],當前執行的函數名稱.
-
 
8586
					#$result["fileContent"],爲檔案的內容陣列.
-
 
8587
					#$result["lineCount"],爲檔案內容總共的行數.
-
 
8588
					#$result["fullContent"],為檔案的完整內容.
-
 
8589
					#$result["base64dataOnly"],檔案的base64data.
-
 
8590
					#$result["base64data"],為在網頁上給予src參數的數值.
-
 
8591
					#$result["mimeType"],為檔案的mime type.
-
 
8592
					#必填參數:
-
 
8593
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
-
 
8594
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["certWithCaPath"];
-
 
8595
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
8596
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
-
 
8597
					#可省略參數:
-
 
8598
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
-
 
8599
					#$conf["web"]="true";
-
 
8600
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
-
 
8601
					#$conf["createIfnotExist"]="false";
-
 
8602
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
-
 
8603
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
-
 
8604
					#參考資料:
-
 
8605
					#file(),取得檔案內容的行數.
-
 
8606
					#file=>http:#php.net/manual/en/function.file.php
-
 
8607
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
-
 
8608
					#filesize=>http://php.net/manual/en/function.filesize.php
-
 
8609
					#參考資料:
-
 
8610
					#無.
-
 
8611
					#備註:
-
 
8612
					#無.
-
 
8613
					$getFileContent=fileAccesss::getFileContent($conf["fileAccesss::getFileContent"]);
-
 
8614
					unset($conf["fileAccesss::getFileContent"]);
-
 
8615
				
-
 
8616
					#如果執行異常
-
 
8617
					if($getFileContent["status"]==="false"){
-
 
8618
					
-
 
8619
						#設置錯誤識別
-
 
8620
						$result["status"]="false";
-
 
8621
 
-
 
8622
						#設置錯誤訊息
-
 
8623
						$result["error"]=$getFileContent;
-
 
8624
 
-
 
8625
						#回傳結果
-
 
8626
						return $result;
-
 
8627
					
-
 
8628
						}#if end
-
 
8629
				
-
 
8630
					#如果既有憑證跟剛下載的憑證不一樣
-
 
8631
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
-
 
8632
					
-
 
8633
						#識別要改成下載好的憑證
-
 
8634
						$cert_and_ca_bundle_need_update="true";
-
 
8635
					
-
 
8636
						}#if end
-
 
8637
					
-
 
8638
					#預設不需要執行更新憑證後的動作
-
 
8639
					$requireActionAfterUpdateCert="false";
-
 
8640
					
-
 
8641
					#如果 certificate 需要更新
-
 
8642
					if($certificate_need_update==="true"){
-
 
8643
					
-
 
8644
						#更新之
-
 
8645
						#函式說明:
-
 
8646
						#一次建立多個檔案,並寫入內容.
-
 
8647
						#回傳結果:
-
 
8648
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
-
 
8649
						#$result["error"],錯誤訊息陣列.
-
 
8650
						#$result["function"],當前執行的函數名稱.
-
 
8651
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
-
 
8652
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
-
 
8653
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
-
 
8654
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
-
 
8655
						#$result["argu"],使用的參數.
-
 
8656
						#必填參數:
-
 
8657
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
8658
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
-
 
8659
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
-
 
8660
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certPath"]);
-
 
8661
						#可省略參數:
-
 
8662
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
-
 
8663
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
-
 
8664
						#參考資料:
-
 
8665
						#無.
-
 
8666
						#備註:
-
 
8667
						#無.
-
 
8668
						$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
-
 
8669
						unset($conf["zerossl::writeMultiFile"]);
-
 
8670
						
-
 
8671
						#如果執行異常
-
 
8672
						if($writeMultiFile["status"]==="false"){
-
 
8673
						
-
 
8674
							#設置錯誤識別
-
 
8675
							$result["status"]="false";
-
 
8676
 
-
 
8677
							#設置錯誤訊息
-
 
8678
							$result["error"]=$writeMultiFile;
-
 
8679
 
-
 
8680
							#回傳結果
-
 
8681
							return $result;
-
 
8682
						
-
 
8683
							}#if end
-
 
8684
					
-
 
8685
						}#if end
-
 
8686
						
-
 
8687
					#如果 ca_bunle 需要更新
-
 
8688
					if($ca_bundle_need_update==="true"){
-
 
8689
					
-
 
8690
						#更新之
-
 
8691
						#函式說明:
-
 
8692
						#一次建立多個檔案,並寫入內容.
-
 
8693
						#回傳結果:
-
 
8694
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
-
 
8695
						#$result["error"],錯誤訊息陣列.
-
 
8696
						#$result["function"],當前執行的函數名稱.
-
 
8697
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
-
 
8698
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
-
 
8699
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
-
 
8700
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
-
 
8701
						#$result["argu"],使用的參數.
-
 
8702
						#必填參數:
-
 
8703
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
8704
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
-
 
8705
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
-
 
8706
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["caPath"]);
-
 
8707
						#可省略參數:
-
 
8708
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
-
 
8709
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
-
 
8710
						#參考資料:
-
 
8711
						#無.
-
 
8712
						#備註:
-
 
8713
						#無.
-
 
8714
						$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
-
 
8715
						unset($conf["zerossl::writeMultiFile"]);
-
 
8716
						
-
 
8717
						#如果執行異常
-
 
8718
						if($writeMultiFile["status"]==="false"){
-
 
8719
						
-
 
8720
							#設置錯誤識別
-
 
8721
							$result["status"]="false";
-
 
8722
 
-
 
8723
							#設置錯誤訊息
-
 
8724
							$result["error"]=$writeMultiFile;
-
 
8725
 
-
 
8726
							#回傳結果
-
 
8727
							return $result;
-
 
8728
						
-
 
8729
							}#if end
-
 
8730
					
-
 
8731
						}#if end
-
 
8732
						
-
 
8733
					#如果 certificate and ca_bundle 需要更新
-
 
8734
					if($cert_and_ca_bundle_need_update==="true"){
-
 
8735
					
-
 
8736
						#更新之
-
 
8737
						#函式說明:
-
 
8738
						#一次建立多個檔案,並寫入內容.
-
 
8739
						#回傳結果:
-
 
8740
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
-
 
8741
						#$result["error"],錯誤訊息陣列.
-
 
8742
						#$result["function"],當前執行的函數名稱.
-
 
8743
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
-
 
8744
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
-
 
8745
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
-
 
8746
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
-
 
8747
						#$result["argu"],使用的參數.
-
 
8748
						#必填參數:
-
 
8749
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
8750
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
-
 
8751
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
-
 
8752
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certWithCaPath"]);
-
 
8753
						#可省略參數:
-
 
8754
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
-
 
8755
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
-
 
8756
						#參考資料:
-
 
8757
						#無.
-
 
8758
						#備註:
-
 
8759
						#無.
-
 
8760
						$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
-
 
8761
						unset($conf["zerossl::writeMultiFile"]);
-
 
8762
						
-
 
8763
						#如果執行異常
-
 
8764
						if($writeMultiFile["status"]==="false"){
-
 
8765
						
-
 
8766
							#設置錯誤識別
-
 
8767
							$result["status"]="false";
-
 
8768
 
-
 
8769
							#設置錯誤訊息
-
 
8770
							$result["error"]=$writeMultiFile;
-
 
8771
 
-
 
8772
							#回傳結果
-
 
8773
							return $result;
-
 
8774
						
-
 
8775
							}#if end
-
 
8776
					
-
 
8777
						}#if end
-
 
8778
						
-
 
8779
					#如果有需要執行指令來生效憑證
-
 
8780
					if($requireActionAfterUpdateCert==="true"){
-
 
8781
					
-
 
8782
						#儲存 actionAfterUpdateCert
-
 
8783
						$action=$cInfo["actionAfterUpdateCert"];
-
 
8784
						
-
 
8785
						#如果有多個指令要執行
-
 
8786
						if(gettype($action[0])==="array"){
-
 
8787
							
-
 
8788
							#針對每的指令
-
 
8789
							foreach($action as $ac){
-
 
8790
							
-
 
8791
								#函式說明:
-
 
8792
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
-
 
8793
								#回傳結果:
-
 
8794
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8795
								#$result["error"],錯誤訊息陣列.
-
 
8796
								#$result["function"],當前執行的函數名稱.
-
 
8797
								#$result["argu"],使用的參數.
-
 
8798
								#$result["cmd"],執行的指令名稱.
-
 
8799
								#$result["params"],執行指令伴隨的參數.
-
 
8800
								#必填參數:
-
 
8801
								#$conf["cmdArray"],字串陣列,要執行的指令字串.
-
 
8802
								$conf["external::callShellHelper"]["cmdArray"]=$ac;
-
 
8803
								#可省略參數:
-
 
8804
								#無.
-
 
8805
								#參考資料:
-
 
8806
								#array_shift=>https://www.php.net/manual/en/function.array-shift.php
-
 
8807
								#備註:
-
 
8808
								#無.
-
 
8809
								$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
-
 
8810
								unset($conf["external::callShellHelper"]);
-
 
8811
							
-
 
8812
								#如果執行異常
-
 
8813
								if($callShellHelper["status"]==="false"){
-
 
8814
								
-
 
8815
									#設置錯誤識別
-
 
8816
									$result["status"]="false";
-
 
8817
 
-
 
8818
									#設置錯誤訊息
-
 
8819
									$result["error"]=$callShellHelper;
-
 
8820
 
-
 
8821
									#回傳結果
-
 
8822
									return $result;
-
 
8823
								
-
 
8824
									}#if end
-
 
8825
									
-
 
8826
								#函式說明:
-
 
8827
								#呼叫shell執行系統命令,並取得回傳的內容.
-
 
8828
								#回傳結果:
-
 
8829
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8830
								#$result["error"],錯誤訊息陣列.
-
 
8831
								#$result["function"],當前執行的函數名稱.
-
 
8832
								#$result["argu"],使用的參數.
-
 
8833
								#$result["cmd"],執行的指令內容.
-
 
8834
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
8835
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
8836
								#$result["content"],為執行完後的輸出字串.
-
 
8837
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
8838
								#$result["running"],是否還在執行.
-
 
8839
								#$result["pid"],pid.
-
 
8840
								#$result["statusCode"],執行結束後的代碼.
-
 
8841
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
8842
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
8843
								#必填參數:
-
 
8844
								#$conf["command"],字串,要執行的指令.
-
 
8845
								$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
-
 
8846
								#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
8847
								$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
8848
								#可省略參數:
-
 
8849
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
8850
								$conf["external::callShell"]["argu"]=$callShellHelper["params"];
-
 
8851
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
8852
								#$conf["arguIsAddr"]=array();
-
 
8853
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
8854
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
8855
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
8856
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
8857
								#$conf["enablePrintDescription"]="true";
-
 
8858
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
8859
								#$conf["printDescription"]="";
-
 
8860
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
8861
								$conf["external::callShell"]["escapeshellarg"]="true";
-
 
8862
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
8863
								#$conf["thereIsShellVar"]=array();
-
 
8864
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
8865
								#$conf["username"]="";
-
 
8866
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
8867
								#$conf["password"]="";
-
 
8868
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
8869
								#$conf["useScript"]="";
-
 
8870
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
8871
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
8872
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
8873
								#$conf["inBackGround"]="";
-
 
8874
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
8875
								#$conf["getErr"]="false";
-
 
8876
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
8877
								#$conf["doNotRun"]="false";
-
 
8878
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
-
 
8879
								#$conf["remoteIp"]="";
-
 
8880
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
-
 
8881
								#$conf["remoteUser"]="";
-
 
8882
								#參考資料:
-
 
8883
								#exec=>http://php.net/manual/en/function.exec.php
-
 
8884
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
8885
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
8886
								#備註:
-
 
8887
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
8888
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
8889
								$callShell=external::callShell($conf["external::callShell"]);
-
 
8890
								unset($conf["external::callShell"]);
-
 
8891
							
-
 
8892
								#如果執行異常
-
 
8893
								if($callShellHelper["status"]==="false"){
-
 
8894
								
-
 
8895
									#設置錯誤識別
-
 
8896
									$result["status"]="false";
-
 
8897
 
-
 
8898
									#設置錯誤訊息
-
 
8899
									$result["error"]=$callShell;
-
 
8900
 
-
 
8901
									#回傳結果
-
 
8902
									return $result;
-
 
8903
								
-
 
8904
									}#if end
-
 
8905
							
-
 
8906
								}#foreach end
-
 
8907
							
-
 
8908
							}#if end
-
 
8909
						
-
 
8910
							#反之
-
 
8911
							else{
-
 
8912
							
-
 
8913
								#函式說明:
-
 
8914
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
-
 
8915
								#回傳結果:
-
 
8916
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8917
								#$result["error"],錯誤訊息陣列.
-
 
8918
								#$result["function"],當前執行的函數名稱.
-
 
8919
								#$result["argu"],使用的參數.
-
 
8920
								#$result["cmd"],執行的指令名稱.
-
 
8921
								#$result["params"],執行指令伴隨的參數.
-
 
8922
								#必填參數:
-
 
8923
								#$conf["cmdArray"],字串陣列,要執行的指令字串.
-
 
8924
								$conf["external::callShellHelper"]["cmdArray"]=$action;
-
 
8925
								#可省略參數:
-
 
8926
								#無.
-
 
8927
								#參考資料:
-
 
8928
								#array_shift=>https://www.php.net/manual/en/function.array-shift.php
-
 
8929
								#備註:
-
 
8930
								#無.
-
 
8931
								$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
-
 
8932
								unset($conf["external::callShellHelper"]);
-
 
8933
							
-
 
8934
								#如果執行異常
-
 
8935
								if($callShellHelper["status"]==="false"){
-
 
8936
								
-
 
8937
									#設置錯誤識別
-
 
8938
									$result["status"]="false";
-
 
8939
 
-
 
8940
									#設置錯誤訊息
-
 
8941
									$result["error"]=$callShellHelper;
-
 
8942
 
-
 
8943
									#回傳結果
-
 
8944
									return $result;
-
 
8945
								
-
 
8946
									}#if end
-
 
8947
									
-
 
8948
								#函式說明:
-
 
8949
								#呼叫shell執行系統命令,並取得回傳的內容.
-
 
8950
								#回傳結果:
-
 
8951
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
8952
								#$result["error"],錯誤訊息陣列.
-
 
8953
								#$result["function"],當前執行的函數名稱.
-
 
8954
								#$result["argu"],使用的參數.
-
 
8955
								#$result["cmd"],執行的指令內容.
-
 
8956
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
8957
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
8958
								#$result["content"],為執行完後的輸出字串.
-
 
8959
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
8960
								#$result["running"],是否還在執行.
-
 
8961
								#$result["pid"],pid.
-
 
8962
								#$result["statusCode"],執行結束後的代碼.
-
 
8963
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
8964
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
8965
								#必填參數:
-
 
8966
								#$conf["command"],字串,要執行的指令.
-
 
8967
								$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
-
 
8968
								#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
8969
								$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
8970
								#可省略參數:
-
 
8971
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
8972
								$conf["external::callShell"]["argu"]=$callShellHelper["params"];
-
 
8973
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
8974
								#$conf["arguIsAddr"]=array();
-
 
8975
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
8976
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
8977
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
8978
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
8979
								#$conf["enablePrintDescription"]="true";
-
 
8980
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
8981
								#$conf["printDescription"]="";
-
 
8982
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
8983
								$conf["external::callShell"]["escapeshellarg"]="true";
-
 
8984
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
8985
								#$conf["thereIsShellVar"]=array();
-
 
8986
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
8987
								#$conf["username"]="";
-
 
8988
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
8989
								#$conf["password"]="";
-
 
8990
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
8991
								#$conf["useScript"]="";
-
 
8992
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
8993
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
8994
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
8995
								#$conf["inBackGround"]="";
-
 
8996
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
8997
								#$conf["getErr"]="false";
-
 
8998
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
8999
								#$conf["doNotRun"]="false";
-
 
9000
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
-
 
9001
								#$conf["remoteIp"]="";
-
 
9002
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
-
 
9003
								#$conf["remoteUser"]="";
-
 
9004
								#參考資料:
-
 
9005
								#exec=>http://php.net/manual/en/function.exec.php
-
 
9006
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
9007
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
9008
								#備註:
-
 
9009
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
9010
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
9011
								$callShell=external::callShell($conf["external::callShell"]);
-
 
9012
								unset($conf["external::callShell"]);
-
 
9013
							
-
 
9014
								#如果執行異常
-
 
9015
								if($callShellHelper["status"]==="false"){
-
 
9016
								
-
 
9017
									#設置錯誤識別
-
 
9018
									$result["status"]="false";
-
 
9019
 
-
 
9020
									#設置錯誤訊息
-
 
9021
									$result["error"]=$callShell;
-
 
9022
 
-
 
9023
									#回傳結果
-
 
9024
									return $result;
-
 
9025
								
-
 
9026
									}#if end
-
 
9027
							
-
 
9028
								}#else end
-
 
9029
								
-
 
9030
							}#if end
-
 
9031
					
-
 
9032
						}#if end
-
 
9033
				
-
 
9034
					}#else end
-
 
9035
				
-
 
9036
				}#else end
-
 
9037
		
-
 
9038
			}#foreach end
-
 
9039
		
-
 
9040
		}#function sslUpdater_idle end
4106
 
9041
 
4107
	}#class zerossl end
9042
	}#class zerossl end
-
 
9043