Subversion Repositories php-qbpwcf

Rev

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

Rev 261 Rev 281
Line 1117... Line 1117...
1117
		
1117
		
1118
		}#function createCSR end
1118
		}#function createCSR end
1119
 
1119
 
1120
	/*
1120
	/*
1121
	#函式說明:
1121
	#函式說明:
1122
	#提供certificate sign request(CSR)透過zerossl產生cergificate.
1122
	#提供certificate sign request(CSR)透過zerossl產生certificate.
1123
	#回傳結果:
1123
	#回傳結果:
1124
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1124
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1125
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1125
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1126
	#$result["function"],當前執行的函式名稱.
1126
	#$result["function"],當前執行的函式名稱.
1127
	#$result["argu"],所使用的參數.
1127
	#$result["argu"],所使用的參數.
Line 6240... Line 6240...
6240
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
6240
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
6241
	$conf["dnsSerAddr"]=array();
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")).
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();
6243
	$conf["actionAfterUpdateCert"]=array();
6244
	#可省略參數:
6244
	#可省略參數:
-
 
6245
	#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
-
 
6246
	#$conf["debug"]="";
6245
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6247
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6246
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6248
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6247
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6249
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6248
	#$conf["key"]=self::getApiInfo()["apiKey"];
6250
	#$conf["key"]=self::getApiInfo()["apiKey"];
6249
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
6251
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
Line 6315... Line 6317...
6315
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6317
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6316
		#可以省略的參數:
6318
		#可以省略的參數:
6317
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6319
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6318
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6320
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6319
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6321
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6320
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6322
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("debug","apiDomain","key","debug");
6321
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6323
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6322
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
6324
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("debug","apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
6323
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6325
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6324
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
6326
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","array","array");
6325
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6327
		#$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"));
6328
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",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為哪些的變數其元素數量要相等.
6329
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6328
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
6330
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
6329
		#參考資料來源:
6331
		#參考資料來源:
6330
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6332
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6331
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6333
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
Line 6363... Line 6365...
6363
		$share["key"]=$conf["key"];
6365
		$share["key"]=$conf["key"];
6364
		
6366
		
6365
		#取得apiDomain
6367
		#取得apiDomain
6366
		$share["apiDomain"]=$conf["apiDomain"];
6368
		$share["apiDomain"]=$conf["apiDomain"];
6367
		
6369
		
-
 
6370
		#設置debug flag
-
 
6371
		$share["debug"]=$conf["debug"];
-
 
6372
		
6368
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
6373
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
6369
		$share["certInfo"]=array();
6374
		$share["certInfo"]=array();
6370
		
6375
		
6371
		#針對每個 domain
6376
		#針對每個 domain
6372
		foreach($conf["cName"] as $index=>$cName ){
6377
		foreach($conf["cName"] as $index=>$cName ){
Line 6680... Line 6685...
6680
 
6685
 
6681
			#回傳結果
6686
			#回傳結果
6682
			return $result;
6687
			return $result;
6683
 
6688
 
6684
			}#if end
6689
			}#if end
-
 
6690
		
-
 
6691
		#預設不開啟 debug flag
-
 
6692
		$debug=false;
6685
			
6693
		
-
 
6694
		#如果有設置 debug 為 "true"
-
 
6695
		if($info["share"]["debug"]==="true"){
-
 
6696
		
-
 
6697
			#設置 debug flag
-
 
6698
			$debug=true;
-
 
6699
		
-
 
6700
			}#if end
-
 
6701
		
6686
		#另存 server cache 的參考
6702
		#另存 server cache 的參考
6687
		$serverCache=&$conf["serverCache"];
6703
		$serverCache=&$conf["serverCache"];
6688
		
6704
		
6689
		#針對每個 domain name
6705
		#針對每個 domain name
6690
		foreach($info["share"]["certInfo"] as $cInfo){
6706
		foreach($info["share"]["certInfo"] as $cInfo){
Line 6706... Line 6722...
6706
				#跳過該 domain name 的檢查
6722
				#跳過該 domain name 的檢查
6707
				continue;
6723
				continue;
6708
			
6724
			
6709
				}#if end
6725
				}#if end
6710
		
6726
		
-
 
6727
			#if enable debug
-
 
6728
			if($debug){
-
 
6729
			
-
 
6730
				#debug msg
-
 
6731
				echo "Checking domain name(".$cInfo["apiDomain"].") on zerossl...".PHP_EOL;
-
 
6732
			
-
 
6733
				}#if end
-
 
6734
		
6711
			#嘗試取得 domain name 對應的可用憑證
6735
			#嘗試取得 domain name 對應的可用憑證
6712
			#函式說明:
6736
			#函式說明:
6713
			#取得在zerossl上的CSR清單
6737
			#取得在zerossl上的CSR清單
6714
			#回傳結果:
6738
			#回傳結果:
6715
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6739
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 6771... Line 6795...
6771
				}#if end
6795
				}#if end
6772
				
6796
				
6773
			#如果沒有憑證
6797
			#如果沒有憑證
6774
			if($getCertList["count"]==="0"){
6798
			if($getCertList["count"]==="0"){
6775
			
6799
			
-
 
6800
				#if enable debug
-
 
6801
				if($debug){
-
 
6802
				
-
 
6803
					#debug msg
-
 
6804
					echo "There is not valid ssl for domain name(".$cInfo["apiDomain"].") on zerossl.".PHP_EOL;
-
 
6805
				
-
 
6806
					}#if end
-
 
6807
			
-
 
6808
				#if enable debug
-
 
6809
				if($debug){
-
 
6810
				
-
 
6811
					#debug msg
-
 
6812
					echo "Checking ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
6813
				
-
 
6814
					}#if end
-
 
6815
			
6776
				#確認有無對應 cName 的 private key
6816
				#確認有無對應 cName 的 private key
6777
				#函式說明:
6817
				#函式說明:
6778
				#檢查多個檔案與資料夾是否存在.
6818
				#檢查多個檔案與資料夾是否存在.
6779
				#回傳的結果:
6819
				#回傳的結果:
6780
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6820
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
Line 6822... Line 6862...
6822
					}#if end
6862
					}#if end
6823
					
6863
					
6824
				#如果沒有 private key
6864
				#如果沒有 private key
6825
				if($checkMultiFileExist["allExist"]==="false"){
6865
				if($checkMultiFileExist["allExist"]==="false"){
6826
				
6866
				
-
 
6867
					#if enable debug
-
 
6868
					if($debug){
-
 
6869
					
-
 
6870
						#debug msg
-
 
6871
						echo "there is no ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
6872
					
-
 
6873
						}#if end
-
 
6874
						
-
 
6875
					#if enable debug
-
 
6876
					if($debug){
-
 
6877
					
-
 
6878
						#debug msg
-
 
6879
						echo "creating ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
6880
					
-
 
6881
						}#if end
-
 
6882
				
6827
					#建立 private key
6883
					#建立 private key
6828
					#函式說明:
6884
					#函式說明:
6829
					#產生ssl private key.
6885
					#產生ssl private key.
6830
					#回傳結果:
6886
					#回傳結果:
6831
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6887
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 6915... Line 6971...
6915
					
6971
					
6916
						}#if end
6972
						}#if end
6917
						
6973
						
6918
					}#if end
6974
					}#if end
6919
				
6975
				
-
 
6976
				#if enable debug
-
 
6977
				if($debug){
-
 
6978
				
-
 
6979
					#debug msg
-
 
6980
					echo "Creating domain name(".$cInfo["apiDomain"].") csr for zerossl...".PHP_EOL;
-
 
6981
				
-
 
6982
					}#if end
-
 
6983
				
6920
				#建立準備給zerossl的csr
6984
				#建立準備給zerossl的csr
6921
				#函式說明:
6985
				#函式說明:
6922
				#產生certificate sign request(CSR).
6986
				#產生certificate sign request(CSR).
6923
				#回傳結果:
6987
				#回傳結果:
6924
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6988
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 6964... Line 7028...
6964
					}#if end
7028
					}#if end
6965
					
7029
					
6966
				#取得本地端產生的csr內容
7030
				#取得本地端產生的csr內容
6967
				$csrLocal=$createCSR["content"];
7031
				$csrLocal=$createCSR["content"];
6968
				
7032
				
-
 
7033
				#if enable debug
-
 
7034
				if($debug){
-
 
7035
				
-
 
7036
					#debug msg
-
 
7037
					echo "Creating certificate for domain name(".$cInfo["apiDomain"].") on zerossl...".PHP_EOL;
-
 
7038
				
-
 
7039
					}#if end
-
 
7040
				
6969
				#函式說明:
7041
				#函式說明:
6970
				#提供certificate sign request(CSR)透過zerossl產生cergificate.
7042
				#提供certificate sign request(CSR)透過zerossl產生certificate.
6971
				#回傳結果:
7043
				#回傳結果:
6972
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7044
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6973
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
7045
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
6974
				#$result["function"],當前執行的函式名稱.
7046
				#$result["function"],當前執行的函式名稱.
6975
				#$result["argu"],所使用的參數.
7047
				#$result["argu"],所使用的參數.
Line 7035... Line 7107...
7035
				$rr2add["type"]="CNAME";
7107
				$rr2add["type"]="CNAME";
7036
				
7108
				
7037
				#設置註解
7109
				#設置註解
7038
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
7110
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
7039
				
7111
				
-
 
7112
				#if enable debug
-
 
7113
				if($debug){
-
 
7114
				
-
 
7115
					#debug msg
-
 
7116
					echo "Adding DNS record to validate certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
7117
				
-
 
7118
					}#if end
-
 
7119
				
7040
				#函式說明:
7120
				#函式說明:
7041
				#新增DNS記錄到檔案裡面.
7121
				#新增DNS記錄到檔案裡面.
7042
				#回傳結果:
7122
				#回傳結果:
7043
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7123
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7044
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
7124
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 7078... Line 7158...
7078
 
7158
 
7079
					#回傳結果
7159
					#回傳結果
7080
					return $result;
7160
					return $result;
7081
				
7161
				
7082
					}#if end
7162
					}#if end
7083
					
7163
				
-
 
7164
				#if enable debug
-
 
7165
				if($debug){
-
 
7166
				
-
 
7167
					#debug msg
-
 
7168
					echo "Restart DNS service to validate certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
7169
				
-
 
7170
					}#if end
-
 
7171
				
7084
				#重新啟動dns伺服器
7172
				#重新啟動dns伺服器
7085
				#函式說明:
7173
				#函式說明:
7086
				#呼叫shell執行系統命令,並取得回傳的內容.
7174
				#呼叫shell執行系統命令,並取得回傳的內容.
7087
				#回傳結果:
7175
				#回傳結果:
7088
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7176
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 7159... Line 7247...
7159
 
7247
 
7160
					#回傳結果
7248
					#回傳結果
7161
					return $result;
7249
					return $result;
7162
				
7250
				
7163
					}#if end
7251
					}#if end
7164
					
7252
				
-
 
7253
				#if enable debug
-
 
7254
				if($debug){
-
 
7255
				
-
 
7256
					#debug msg
-
 
7257
					echo "Request zerossl to validate certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
7258
				
-
 
7259
					}#if end
-
 
7260
				
7165
				#函式說明:
7261
				#函式說明:
7166
				#請求驗證已經透過zerossl::createCertificate要求的domain.
7262
				#請求驗證已經透過zerossl::createCertificate要求的domain.
7167
				#回傳結果:
7263
				#回傳結果:
7168
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7264
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7169
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
7265
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 7197... Line 7293...
7197
 
7293
 
7198
					#回傳結果
7294
					#回傳結果
7199
					return $result;
7295
					return $result;
7200
				
7296
				
7201
					}#if end
7297
					}#if end
7202
					
7298
				
-
 
7299
				#if enable debug
-
 
7300
				if($debug){
-
 
7301
				
-
 
7302
					#debug msg
-
 
7303
					echo "Downloading certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
7304
				
-
 
7305
					}#if end
-
 
7306
				
7203
				#函式說明:
7307
				#函式說明:
7204
				#下載certificate.
7308
				#下載certificate.
7205
				#回傳結果:
7309
				#回傳結果:
7206
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7310
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7207
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
7311
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 7240... Line 7344...
7240
 
7344
 
7241
					#回傳結果
7345
					#回傳結果
7242
					return $result;
7346
					return $result;
7243
				
7347
				
7244
					}#if end
7348
					}#if end
7245
					
7349
				
-
 
7350
				#if enable debug
-
 
7351
				if($debug){
-
 
7352
				
-
 
7353
					#debug msg
-
 
7354
					echo "Creating certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
7355
				
-
 
7356
					}#if end
-
 
7357
				
7246
				#建立 certificate.crt 檔案
7358
				#建立 certificate.crt 檔案
7247
				#$cInfo["certPath"];
7359
				#$cInfo["certPath"];
7248
				
7360
				
7249
				#建立 ca_bundle.crt 檔案
7361
				#建立 ca_bundle.crt 檔案
7250
				#$cInfo["caPath"];
7362
				#$cInfo["caPath"];
Line 7297... Line 7409...
7297
				$action=$cInfo["actionAfterUpdateCert"];
7409
				$action=$cInfo["actionAfterUpdateCert"];
7298
				
7410
				
7299
				#如果有多個指令要執行
7411
				#如果有多個指令要執行
7300
				if(gettype($action[0])==="array"){
7412
				if(gettype($action[0])==="array"){
7301
					
7413
					
-
 
7414
					#if enable debug
-
 
7415
					if($debug){
-
 
7416
					
-
 
7417
						#debug msg
-
 
7418
						echo "There are many cmds to run to apply certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
7419
					
-
 
7420
						}#if end
-
 
7421
					
-
 
7422
					#if enable debug
-
 
7423
					if($debug){
-
 
7424
					
-
 
7425
						#debug msg
-
 
7426
						echo "Running cmd to apply certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
7427
					
-
 
7428
						}#if end
-
 
7429
					
7302
					#針對每的指令
7430
					#針對每的指令
7303
					foreach($action as $ac){
7431
					foreach($action as $ac){
7304
					
7432
					
-
 
7433
						#if enable debug
-
 
7434
						if($debug){
-
 
7435
						
-
 
7436
							#debug msg
-
 
7437
							echo ".".PHP_EOL;
-
 
7438
						
-
 
7439
							}#if end
-
 
7440
					
7305
						#函式說明:
7441
						#函式說明:
7306
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
7442
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
7307
						#回傳結果:
7443
						#回傳結果:
7308
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7444
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7309
						#$result["error"],錯誤訊息陣列.
7445
						#$result["error"],錯誤訊息陣列.
Line 7422... Line 7558...
7422
					}#if end
7558
					}#if end
7423
				
7559
				
7424
				#反之
7560
				#反之
7425
				else{
7561
				else{
7426
				
7562
				
-
 
7563
					#if enable debug
-
 
7564
					if($debug){
-
 
7565
					
-
 
7566
						#debug msg
-
 
7567
						echo "There is only one cmd to run to apply certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
7568
					
-
 
7569
						}#if end
-
 
7570
				
-
 
7571
					#if enable debug
-
 
7572
					if($debug){
-
 
7573
					
-
 
7574
						#debug msg
-
 
7575
						echo ".".PHP_EOL;
-
 
7576
					
-
 
7577
						}#if end
-
 
7578
				
7427
					#函式說明:
7579
					#函式說明:
7428
					#解析指令與參數,回傳指令與參數給 callShell 函式使用.
7580
					#解析指令與參數,回傳指令與參數給 callShell 函式使用.
7429
					#回傳結果:
7581
					#回傳結果:
7430
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7582
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7431
					#$result["error"],錯誤訊息陣列.
7583
					#$result["error"],錯誤訊息陣列.
Line 7544... Line 7696...
7544
				}#if end
7696
				}#if end
7545
				
7697
				
7546
			#反之
7698
			#反之
7547
			else{
7699
			else{
7548
			
7700
			
-
 
7701
				#if enable debug
-
 
7702
				if($debug){
-
 
7703
				
-
 
7704
					#debug msg
-
 
7705
					echo "There is already valid ssl for domain name(".$cInfo["apiDomain"].") on zerossl".PHP_EOL;
-
 
7706
				
-
 
7707
					}#if end
-
 
7708
			
7549
				#有 issued 的憑證
7709
				#有 issued 的憑證
7550
				
7710
				
7551
				#取得 certificate id at zerossl
7711
				#取得 certificate id at zerossl
7552
				#函式說明:
7712
				#函式說明:
7553
				#將陣列轉換成存有key與value的陣列
7713
				#將陣列轉換成存有key與value的陣列
Line 7590... Line 7750...
7590
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
7750
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
7591
				
7751
				
7592
				#如果距離當下不到2個星期就要過期
7752
				#如果距離當下不到2個星期就要過期
7593
				if($expiresIn<=86400*14){
7753
				if($expiresIn<=86400*14){
7594
				
7754
				
-
 
7755
					#if enable debug
-
 
7756
					if($debug){
-
 
7757
					
-
 
7758
						#debug msg
-
 
7759
						echo "Valid ssl for domain name(".$cInfo["apiDomain"].") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
-
 
7760
					
-
 
7761
						}#if end
-
 
7762
				
7595
					#另存舊的憑證id,最後要revoke之.
7763
					#另存舊的憑證id,最後要revoke之.
7596
					$oldCsrId=$csrId;
7764
					$oldCsrId=$csrId;
7597
				
7765
				
-
 
7766
					#if enable debug
-
 
7767
					if($debug){
-
 
7768
					
-
 
7769
						#debug msg
-
 
7770
						echo "Start requst new ssl process for domain name(".$cInfo["apiDomain"].").".PHP_EOL;
-
 
7771
					
-
 
7772
						}#if end
-
 
7773
						
-
 
7774
					#if enable debug
-
 
7775
					if($debug){
-
 
7776
					
-
 
7777
						#debug msg
-
 
7778
						echo "Finding ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
7779
					
-
 
7780
						}#if end
-
 
7781
				
7598
					#確認有無對應 cName 的 private key
7782
					#確認有無對應 cName 的 private key
7599
					#函式說明:
7783
					#函式說明:
7600
					#檢查多個檔案與資料夾是否存在.
7784
					#檢查多個檔案與資料夾是否存在.
7601
					#回傳的結果:
7785
					#回傳的結果:
7602
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7786
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
Line 7644... Line 7828...
7644
						}#if end
7828
						}#if end
7645
						
7829
						
7646
					#如果沒有 private key
7830
					#如果沒有 private key
7647
					if($checkMultiFileExist["allExist"]==="false"){
7831
					if($checkMultiFileExist["allExist"]==="false"){
7648
					
7832
					
-
 
7833
						#if enable debug
-
 
7834
						if($debug){
-
 
7835
						
-
 
7836
							#debug msg
-
 
7837
							echo "Thers is no ssl private key for domain name(".$cInfo["apiDomain"].").".PHP_EOL;
-
 
7838
						
-
 
7839
							}#if end
-
 
7840
							
-
 
7841
						#if enable debug
-
 
7842
						if($debug){
-
 
7843
						
-
 
7844
							#debug msg
-
 
7845
							echo "Creating ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
7846
						
-
 
7847
							}#if end
-
 
7848
					
7649
						#建立 private key
7849
						#建立 private key
7650
						#函式說明:
7850
						#函式說明:
7651
						#產生ssl private key.
7851
						#產生ssl private key.
7652
						#回傳結果:
7852
						#回傳結果:
7653
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7853
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 7684... Line 7884...
7684
							}#if end
7884
							}#if end
7685
							
7885
							
7686
						#另存private key的字串
7886
						#另存private key的字串
7687
						$pKeyStr=$createPrivateKey["content"];
7887
						$pKeyStr=$createPrivateKey["content"];
7688
					
7888
					
-
 
7889
						#if enable debug
-
 
7890
						if($debug){
-
 
7891
						
-
 
7892
							#debug msg
-
 
7893
							echo "Writing ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
7894
						
-
 
7895
							}#if end
-
 
7896
					
7689
						#建立private key檔案
7897
						#建立private key檔案
7690
						#函式說明:
7898
						#函式說明:
7691
						#將字串寫入到檔案
7899
						#將字串寫入到檔案
7692
						#回傳結果:
7900
						#回傳結果:
7693
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
7901
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
Line 7737... Line 7945...
7737
						
7945
						
7738
							}#if end
7946
							}#if end
7739
							
7947
							
7740
						}#if end
7948
						}#if end
7741
					
7949
					
-
 
7950
					#if enable debug
-
 
7951
					if($debug){
-
 
7952
					
-
 
7953
						#debug msg
-
 
7954
						echo "Creating CSR for domain name(".$cInfo["apiDomain"].") to zerossl.".PHP_EOL;
-
 
7955
					
-
 
7956
						}#if end
-
 
7957
					
7742
					#建立準備給zerossl的csr
7958
					#建立準備給zerossl的csr
7743
					#函式說明:
7959
					#函式說明:
7744
					#產生certificate sign request(CSR).
7960
					#產生certificate sign request(CSR).
7745
					#回傳結果:
7961
					#回傳結果:
7746
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7962
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 7786... Line 8002...
7786
						}#if end
8002
						}#if end
7787
						
8003
						
7788
					#取得本地端產生的csr內容
8004
					#取得本地端產生的csr內容
7789
					$csrLocal=$createCSR["content"];
8005
					$csrLocal=$createCSR["content"];
7790
					
8006
					
-
 
8007
					#if enable debug
-
 
8008
					if($debug){
-
 
8009
					
-
 
8010
						#debug msg
-
 
8011
						echo "Providing CSR for domain name(".$cInfo["apiDomain"].") to zerossl".PHP_EOL;
-
 
8012
					
-
 
8013
						}#if end
-
 
8014
					
7791
					#函式說明:
8015
					#函式說明:
7792
					#提供certificate sign request(CSR)透過zerossl產生cergificate.
8016
					#提供certificate sign request(CSR)透過zerossl產生certificate.
7793
					#回傳結果:
8017
					#回傳結果:
7794
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8018
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7795
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8019
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
7796
					#$result["function"],當前執行的函式名稱.
8020
					#$result["function"],當前執行的函式名稱.
7797
					#$result["argu"],所使用的參數.
8021
					#$result["argu"],所使用的參數.
Line 7857... Line 8081...
7857
					$rr2add["type"]="CNAME";
8081
					$rr2add["type"]="CNAME";
7858
					
8082
					
7859
					#設置註解
8083
					#設置註解
7860
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
8084
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
7861
					
8085
					
-
 
8086
					#if enable debug
-
 
8087
					if($debug){
-
 
8088
					
-
 
8089
						#debug msg
-
 
8090
						echo "Adding DNS record to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
-
 
8091
					
-
 
8092
						}#if end
-
 
8093
					
7862
					#函式說明:
8094
					#函式說明:
7863
					#新增DNS記錄到檔案裡面.
8095
					#新增DNS記錄到檔案裡面.
7864
					#回傳結果:
8096
					#回傳結果:
7865
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8097
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7866
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8098
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 7900... Line 8132...
7900
 
8132
 
7901
						#回傳結果
8133
						#回傳結果
7902
						return $result;
8134
						return $result;
7903
					
8135
					
7904
						}#if end
8136
						}#if end
7905
						
8137
					
-
 
8138
					#if enable debug
-
 
8139
					if($debug){
-
 
8140
					
-
 
8141
						#debug msg
-
 
8142
						echo "Restarting DNS service to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
-
 
8143
					
-
 
8144
						}#if end
-
 
8145
					
7906
					#重新啟動dns伺服器
8146
					#重新啟動dns伺服器
7907
					#函式說明:
8147
					#函式說明:
7908
					#呼叫shell執行系統命令,並取得回傳的內容.
8148
					#呼叫shell執行系統命令,並取得回傳的內容.
7909
					#回傳結果:
8149
					#回傳結果:
7910
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8150
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 7981... Line 8221...
7981
 
8221
 
7982
						#回傳結果
8222
						#回傳結果
7983
						return $result;
8223
						return $result;
7984
					
8224
					
7985
						}#if end
8225
						}#if end
7986
						
8226
					
-
 
8227
					#if enable debug
-
 
8228
					if($debug){
-
 
8229
					
-
 
8230
						#debug msg
-
 
8231
						echo "Request zerossl to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
-
 
8232
					
-
 
8233
						}#if end
-
 
8234
					
7987
					#函式說明:
8235
					#函式說明:
7988
					#請求驗證已經透過zerossl::createCertificate要求的domain.
8236
					#請求驗證已經透過zerossl::createCertificate要求的domain.
7989
					#回傳結果:
8237
					#回傳結果:
7990
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8238
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7991
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8239
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 8019... Line 8267...
8019
 
8267
 
8020
						#回傳結果
8268
						#回傳結果
8021
						return $result;
8269
						return $result;
8022
					
8270
					
8023
						}#if end
8271
						}#if end
8024
						
8272
					
-
 
8273
					#if enable debug
-
 
8274
					if($debug){
-
 
8275
					
-
 
8276
						#debug msg
-
 
8277
						echo "Downling ssl for domain name(".$cInfo["apiDomain"].") on zerossl.".PHP_EOL;
-
 
8278
					
-
 
8279
						}#if end
-
 
8280
					
8025
					#函式說明:
8281
					#函式說明:
8026
					#下載certificate.
8282
					#下載certificate.
8027
					#回傳結果:
8283
					#回傳結果:
8028
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8284
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8029
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8285
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 8062... Line 8318...
8062
 
8318
 
8063
						#回傳結果
8319
						#回傳結果
8064
						return $result;
8320
						return $result;
8065
					
8321
					
8066
						}#if end
8322
						}#if end
8067
						
8323
					
-
 
8324
					#if enable debug
-
 
8325
					if($debug){
-
 
8326
					
-
 
8327
						#debug msg
-
 
8328
						echo "Creating ssl for domain name(".$cInfo["apiDomain"].").".PHP_EOL;
-
 
8329
					
-
 
8330
						}#if end
-
 
8331
					
8068
					#建立 certificate.crt 檔案
8332
					#建立 certificate.crt 檔案
8069
					#$cInfo["certPath"];
8333
					#$cInfo["certPath"];
8070
					
8334
					
8071
					#建立 ca_bundle.crt 檔案
8335
					#建立 ca_bundle.crt 檔案
8072
					#$cInfo["caPath"];
8336
					#$cInfo["caPath"];
Line 8119... Line 8383...
8119
					$action=$cInfo["actionAfterUpdateCert"];
8383
					$action=$cInfo["actionAfterUpdateCert"];
8120
					
8384
					
8121
					#如果有多個指令要執行
8385
					#如果有多個指令要執行
8122
					if(gettype($action[0])==="array"){
8386
					if(gettype($action[0])==="array"){
8123
						
8387
						
-
 
8388
						#if enable debug
-
 
8389
						if($debug){
-
 
8390
						
-
 
8391
							#debug msg
-
 
8392
							echo "There many cmd to run to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
-
 
8393
						
-
 
8394
							}#if end
-
 
8395
						
8124
						#針對每的指令
8396
						#針對每的指令
8125
						foreach($action as $ac){
8397
						foreach($action as $ac){
8126
						
8398
						
-
 
8399
							#if enable debug
-
 
8400
							if($debug){
-
 
8401
							
-
 
8402
								#debug msg
-
 
8403
								echo ".".PHP_EOL;
-
 
8404
							
-
 
8405
								}#if end
-
 
8406
						
8127
							#函式說明:
8407
							#函式說明:
8128
							#解析指令與參數,回傳指令與參數給 callShell 函式使用.
8408
							#解析指令與參數,回傳指令與參數給 callShell 函式使用.
8129
							#回傳結果:
8409
							#回傳結果:
8130
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8410
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8131
							#$result["error"],錯誤訊息陣列.
8411
							#$result["error"],錯誤訊息陣列.
Line 8244... Line 8524...
8244
						}#if end
8524
						}#if end
8245
					
8525
					
8246
					#反之
8526
					#反之
8247
					else{
8527
					else{
8248
					
8528
					
-
 
8529
						#if enable debug
-
 
8530
						if($debug){
-
 
8531
						
-
 
8532
							#debug msg
-
 
8533
							echo "There is only one cmd to run to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
-
 
8534
						
-
 
8535
							}#if end
-
 
8536
							
-
 
8537
						#if enable debug
-
 
8538
						if($debug){
-
 
8539
						
-
 
8540
							#debug msg
-
 
8541
							echo ".".PHP_EOL;
-
 
8542
						
-
 
8543
							}#if end
-
 
8544
					
8249
						#函式說明:
8545
						#函式說明:
8250
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
8546
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
8251
						#回傳結果:
8547
						#回傳結果:
8252
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8548
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8253
						#$result["error"],錯誤訊息陣列.
8549
						#$result["error"],錯誤訊息陣列.
Line 8363... Line 8659...
8363
					
8659
					
8364
						}#else end
8660
						}#else end
8365
						
8661
						
8366
					#要移除舊的憑證 
8662
					#要移除舊的憑證 
8367
					
8663
					
-
 
8664
					#if enable debug
-
 
8665
					if($debug){
-
 
8666
					
-
 
8667
						#debug msg
-
 
8668
						echo "Removing old ssl file".PHP_EOL;
-
 
8669
					
-
 
8670
						}#if end
-
 
8671
					
8368
					#舊憑證於zerossl上的id
8672
					#舊憑證於zerossl上的id
8369
					#$oldCsrId
8673
					#$oldCsrId
8370
					
8674
					
8371
					#移除舊的憑證
8675
					#移除舊的憑證
8372
					#函式說明:
8676
					#函式說明:
Line 8410... Line 8714...
8410
					}#if end
8714
					}#if end
8411
					
8715
					
8412
				#反之,尚不需要提前申請新的憑證
8716
				#反之,尚不需要提前申請新的憑證
8413
				else{
8717
				else{
8414
				
8718
				
-
 
8719
					#if enable debug
-
 
8720
					if($debug){
-
 
8721
					
-
 
8722
						#debug msg
-
 
8723
						echo "ssl for domain name(".$cInfo["apiDomain"].") is valid ".PHP_EOL;
-
 
8724
					
-
 
8725
						}#if end
-
 
8726
				
-
 
8727
					#if enable debug
-
 
8728
					if($debug){
-
 
8729
					
-
 
8730
						#debug msg
-
 
8731
						echo "Downling ssl for domain name(".$cInfo["apiDomain"].") on zerossl...".PHP_EOL;
-
 
8732
					
-
 
8733
						}#if end
-
 
8734
				
8415
					#下載憑證
8735
					#下載憑證
8416
					#函式說明:
8736
					#函式說明:
8417
					#下載certificate.
8737
					#下載certificate.
8418
					#回傳結果:
8738
					#回傳結果:
8419
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8739
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 8453... Line 8773...
8453
 
8773
 
8454
						#回傳結果
8774
						#回傳結果
8455
						return $result;
8775
						return $result;
8456
					
8776
					
8457
						}#if end
8777
						}#if end
8458
						
8778
					
-
 
8779
					#if enable debug
-
 
8780
					if($debug){
-
 
8781
					
-
 
8782
						#debug msg
-
 
8783
						echo "Getting host ssl for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
8784
					
-
 
8785
						}#if end
-
 
8786
					
8459
					#zerossl上的certificate.crt內容
8787
					#zerossl上的certificate.crt內容
8460
					#$getCert["certificate.crt"];
8788
					#$getCert["certificate.crt"];
8461
						
8789
						
8462
					#zerossl上的ca_bundle.crt內容
8790
					#zerossl上的ca_bundle.crt內容
8463
					#$getCert["ca_bundle.crt"];
8791
					#$getCert["ca_bundle.crt"];
Line 8471... Line 8799...
8471
					#ca_bundle.crt 檔案
8799
					#ca_bundle.crt 檔案
8472
					#$cInfo["caPath"];
8800
					#$cInfo["caPath"];
8473
					
8801
					
8474
					#certAndCa.crt 檔案
8802
					#certAndCa.crt 檔案
8475
					#$cInfo["certWithCaPath"];
8803
					#$cInfo["certWithCaPath"];
-
 
8804
					
-
 
8805
					#if enable debug
-
 
8806
					if($debug){
-
 
8807
					
-
 
8808
						#debug msg
-
 
8809
						echo "Getting host ssl(certificate.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
8810
					
-
 
8811
						}#if end
8476
				
8812
				
8477
					#取得既有的 certificate.crt 檔案內容
8813
					#取得既有的 certificate.crt 檔案內容
8478
					#函式說明:
8814
					#函式說明:
8479
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
8815
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
8480
					#回傳的變數說明:
8816
					#回傳的變數說明:
Line 8524... Line 8860...
8524
						#回傳結果
8860
						#回傳結果
8525
						return $result;
8861
						return $result;
8526
					
8862
					
8527
						}#if end
8863
						}#if end
8528
				
8864
				
-
 
8865
					#if enable debug
-
 
8866
					if($debug){
-
 
8867
					
-
 
8868
						#debug msg
-
 
8869
						echo "Checking host ssl(certificate.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
8870
					
-
 
8871
						}#if end
-
 
8872
				
8529
					#如果既有憑證跟剛下載的憑證不一樣
8873
					#如果既有憑證跟剛下載的憑證不一樣
8530
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
8874
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
8531
					
8875
					
8532
						#識別要改成下載好的憑證
8876
						#識別要改成下載好的憑證
8533
						$certificate_need_update="true";
8877
						$certificate_need_update="true";
-
 
8878
						
-
 
8879
						#if enable debug
-
 
8880
						if($debug){
-
 
8881
						
-
 
8882
							#debug msg
-
 
8883
							echo "SSL(certificate.crt) for domain name(".$cInfo["apiDomain"].") differs between host and zerossl".PHP_EOL;
-
 
8884
						
-
 
8885
							}#if end
8534
					
8886
					
8535
						}#if end
8887
						}#if end
8536
						
8888
					
-
 
8889
					#if enable debug
-
 
8890
					if($debug){
-
 
8891
					
-
 
8892
						#debug msg
-
 
8893
						echo "Getting host ssl(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
8894
					
-
 
8895
						}#if end
-
 
8896
					
8537
					#取得既有的 ca_bundle.crt 檔案內容
8897
					#取得既有的 ca_bundle.crt 檔案內容
8538
					#函式說明:
8898
					#函式說明:
8539
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
8899
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
8540
					#回傳的變數說明:
8900
					#回傳的變數說明:
8541
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
8901
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
Line 8584... Line 8944...
8584
						#回傳結果
8944
						#回傳結果
8585
						return $result;
8945
						return $result;
8586
					
8946
					
8587
						}#if end
8947
						}#if end
8588
				
8948
				
-
 
8949
					#if enable debug
-
 
8950
					if($debug){
-
 
8951
					
-
 
8952
						#debug msg
-
 
8953
						echo "Checking host ssl(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
8954
					
-
 
8955
						}#if end
-
 
8956
				
8589
					#如果既有憑證跟剛下載的憑證不一樣
8957
					#如果既有憑證跟剛下載的憑證不一樣
8590
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
8958
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
8591
					
8959
					
8592
						#識別要改成下載好的憑證
8960
						#識別要改成下載好的憑證
8593
						$ca_bundle_need_update="true";
8961
						$ca_bundle_need_update="true";
-
 
8962
						
-
 
8963
						#if enable debug
-
 
8964
						if($debug){
-
 
8965
						
-
 
8966
							#debug msg
-
 
8967
							echo "SSL(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].") differs between host and zerossl".PHP_EOL;
-
 
8968
						
-
 
8969
							}#if end
-
 
8970
					
-
 
8971
						}#if end
-
 
8972
					
-
 
8973
					#if enable debug
-
 
8974
					if($debug){
-
 
8975
					
-
 
8976
						#debug msg
-
 
8977
						echo "Getting host ssl(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
8594
					
8978
					
8595
						}#if end
8979
						}#if end
8596
					
8980
					
8597
					#取得既有的 certWithCa 檔案內容
8981
					#取得既有的 certWithCa 檔案內容
8598
					#函式說明:
8982
					#函式說明:
Line 8644... Line 9028...
8644
						#回傳結果
9028
						#回傳結果
8645
						return $result;
9029
						return $result;
8646
					
9030
					
8647
						}#if end
9031
						}#if end
8648
				
9032
				
-
 
9033
					#if enable debug
-
 
9034
					if($debug){
-
 
9035
					
-
 
9036
						#debug msg
-
 
9037
						echo "Checking host ssl(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
9038
					
-
 
9039
						}#if end
-
 
9040
				
8649
					#如果既有憑證跟剛下載的憑證不一樣
9041
					#如果既有憑證跟剛下載的憑證不一樣
8650
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
9042
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
8651
					
9043
					
8652
						#識別要改成下載好的憑證
9044
						#識別要改成下載好的憑證
8653
						$cert_and_ca_bundle_need_update="true";
9045
						$cert_and_ca_bundle_need_update="true";
-
 
9046
						
-
 
9047
						#if enable debug
-
 
9048
						if($debug){
-
 
9049
						
-
 
9050
							#debug msg
-
 
9051
							echo "SSL(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].") differs between host and zerossl".PHP_EOL;
-
 
9052
						
-
 
9053
							}#if end
8654
					
9054
					
8655
						}#if end
9055
						}#if end
8656
					
9056
					
8657
					#預設不需要執行更新憑證後的動作
9057
					#預設不需要執行更新憑證後的動作
8658
					$requireActionAfterUpdateCert="false";
9058
					$requireActionAfterUpdateCert="false";
8659
					
9059
					
8660
					#如果 certificate 需要更新
9060
					#如果 certificate 需要更新
8661
					if($certificate_need_update==="true"){
9061
					if($certificate_need_update==="true"){
8662
					
9062
					
-
 
9063
						#if enable debug
-
 
9064
						if($debug){
-
 
9065
					
-
 
9066
							#debug msg
-
 
9067
							echo "Updating host ssl(certificate.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
9068
						
-
 
9069
							}#if end
-
 
9070
					
8663
						#更新之
9071
						#更新之
8664
						#函式說明:
9072
						#函式說明:
8665
						#一次建立多個檔案,並寫入內容.
9073
						#一次建立多個檔案,並寫入內容.
8666
						#回傳結果:
9074
						#回傳結果:
8667
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9075
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
Line 8704... Line 9112...
8704
						}#if end
9112
						}#if end
8705
						
9113
						
8706
					#如果 ca_bunle 需要更新
9114
					#如果 ca_bunle 需要更新
8707
					if($ca_bundle_need_update==="true"){
9115
					if($ca_bundle_need_update==="true"){
8708
					
9116
					
-
 
9117
						#if enable debug
-
 
9118
						if($debug){
-
 
9119
					
-
 
9120
							#debug msg
-
 
9121
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
9122
						
-
 
9123
							}#if end
-
 
9124
					
8709
						#更新之
9125
						#更新之
8710
						#函式說明:
9126
						#函式說明:
8711
						#一次建立多個檔案,並寫入內容.
9127
						#一次建立多個檔案,並寫入內容.
8712
						#回傳結果:
9128
						#回傳結果:
8713
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9129
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
Line 8750... Line 9166...
8750
						}#if end
9166
						}#if end
8751
						
9167
						
8752
					#如果 certificate and ca_bundle 需要更新
9168
					#如果 certificate and ca_bundle 需要更新
8753
					if($cert_and_ca_bundle_need_update==="true"){
9169
					if($cert_and_ca_bundle_need_update==="true"){
8754
					
9170
					
-
 
9171
						#if enable debug
-
 
9172
						if($debug){
-
 
9173
					
-
 
9174
							#debug msg
-
 
9175
							echo "Updating host ssl(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
-
 
9176
						
-
 
9177
							}#if end
-
 
9178
					
8755
						#更新之
9179
						#更新之
8756
						#函式說明:
9180
						#函式說明:
8757
						#一次建立多個檔案,並寫入內容.
9181
						#一次建立多個檔案,並寫入內容.
8758
						#回傳結果:
9182
						#回傳結果:
8759
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9183
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
Line 8796... Line 9220...
8796
						}#if end
9220
						}#if end
8797
						
9221
						
8798
					#如果有需要執行指令來生效憑證
9222
					#如果有需要執行指令來生效憑證
8799
					if($requireActionAfterUpdateCert==="true"){
9223
					if($requireActionAfterUpdateCert==="true"){
8800
					
9224
					
-
 
9225
						#if enable debug
-
 
9226
						if($debug){
-
 
9227
					
-
 
9228
							#debug msg
-
 
9229
							echo "Action required to apply ssl for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
9230
						
-
 
9231
							}#if end
-
 
9232
					
8801
						#儲存 actionAfterUpdateCert
9233
						#儲存 actionAfterUpdateCert
8802
						$action=$cInfo["actionAfterUpdateCert"];
9234
						$action=$cInfo["actionAfterUpdateCert"];
8803
						
9235
						
8804
						#如果有多個指令要執行
9236
						#如果有多個指令要執行
8805
						if(gettype($action[0])==="array"){
9237
						if(gettype($action[0])==="array"){
8806
							
9238
							
-
 
9239
							#if enable debug
-
 
9240
							if($debug){
-
 
9241
						
-
 
9242
								#debug msg
-
 
9243
								echo "There are many cmds to run to apply ssl for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
9244
							
-
 
9245
								}#if end
-
 
9246
							
8807
							#針對每的指令
9247
							#針對每的指令
8808
							foreach($action as $ac){
9248
							foreach($action as $ac){
8809
							
9249
							
-
 
9250
								#if enable debug
-
 
9251
								if($debug){
-
 
9252
							
-
 
9253
									#debug msg
-
 
9254
									echo ".".PHP_EOL;
-
 
9255
								
-
 
9256
									}#if end
-
 
9257
							
8810
								#函式說明:
9258
								#函式說明:
8811
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
9259
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
8812
								#回傳結果:
9260
								#回傳結果:
8813
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9261
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8814
								#$result["error"],錯誤訊息陣列.
9262
								#$result["error"],錯誤訊息陣列.
Line 8927... Line 9375...
8927
							}#if end
9375
							}#if end
8928
						
9376
						
8929
							#反之
9377
							#反之
8930
							else{
9378
							else{
8931
							
9379
							
-
 
9380
								#if enable debug
-
 
9381
								if($debug){
-
 
9382
							
-
 
9383
									#debug msg
-
 
9384
									echo "There is only one cmd to run to apply ssl for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
-
 
9385
								
-
 
9386
									}#if end
-
 
9387
							
8932
								#函式說明:
9388
								#函式說明:
8933
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
9389
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
8934
								#回傳結果:
9390
								#回傳結果:
8935
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9391
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8936
								#$result["error"],錯誤訊息陣列.
9392
								#$result["error"],錯誤訊息陣列.