Subversion Repositories php-qbpwcf

Rev

Rev 404 | Rev 406 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
27
類別說明:
28
應用 zerossl 的類別.
29
備註:
30
無.
31
*/
32
class zerossl{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	#備註:
47
	#無.
48
	*/
49
	public function __call($method,$arguments){
226 liveuser 50
 
3 liveuser 51
		#取得當前執行的函式
52
		$result["function"]=__FUNCTION__;
226 liveuser 53
 
3 liveuser 54
		#設置執行不正常
55
		$result["status"]="false";
226 liveuser 56
 
3 liveuser 57
		#設置執行錯誤
58
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 59
 
3 liveuser 60
		#設置所丟入的參數
61
		$result["error"][]=$arguments;
226 liveuser 62
 
3 liveuser 63
		#回傳結果
64
		return $result;
226 liveuser 65
 
3 liveuser 66
		}#function __call end
226 liveuser 67
 
3 liveuser 68
	/*
69
	#函式說明:
70
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
71
	#回傳結果:
72
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
73
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
74
	#$result["function"],當前執行的函式名稱.
75
	#必填參數:
76
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
77
	#$arguments,陣列,為呼叫方法時所用的參數.
78
	#參考資料:
79
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
80
	#備註:
81
	#無.
82
	*/
83
	public static function __callStatic($method,$arguments){
226 liveuser 84
 
3 liveuser 85
		#取得當前執行的函式
86
		$result["function"]=__FUNCTION__;
226 liveuser 87
 
3 liveuser 88
		#設置執行不正常
89
		$result["status"]="false";
226 liveuser 90
 
3 liveuser 91
		#設置執行錯誤
92
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 93
 
3 liveuser 94
		#設置所丟入的參數
95
		$result["error"][]=$arguments;
226 liveuser 96
 
3 liveuser 97
		#回傳結果
98
		return $result;
226 liveuser 99
 
3 liveuser 100
		}#function __callStatic end
226 liveuser 101
 
3 liveuser 102
	/*
103
	#函式說明:
104
	#取得api的資訊
105
	#回傳結果:
106
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
107
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
108
	#$result["function"],當前執行的函式名稱.
109
	#$result["content"],api資訊陣列.
110
	#必填參數:
111
	#無
112
	#可省略參數:
113
	#無
114
	#參考資料:
115
	#無.
116
	#備註:
117
	#無.
118
	*/
119
	public static function getApiInfo(){
226 liveuser 120
 
3 liveuser 121
		#初始化要回傳的陣列
122
		$result=array();
226 liveuser 123
 
3 liveuser 124
		#api domain
125
		$result["apiDomain"]="api.zerossl.com";
226 liveuser 126
 
249 liveuser 127
		#create certificate api path
3 liveuser 128
		$result["csrPath"]="/certificates";
226 liveuser 129
 
3 liveuser 130
		#create certificate url
131
		$result["csrUrl"]=$result["apiDomain"].$result["csrPath"];
226 liveuser 132
 
3 liveuser 133
		#api access key
134
		$result["apiKey"]=zeroSSLapiKey;
226 liveuser 135
 
3 liveuser 136
		#設置執行正常
137
		$result["status"]="true";
226 liveuser 138
 
3 liveuser 139
		#回傳結果
140
		return $result;
226 liveuser 141
 
3 liveuser 142
		}#function getApiInfo end
226 liveuser 143
 
3 liveuser 144
	/*
145
	#函式說明:
146
	#產生ssl private key.
147
	#回傳結果:
148
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
149
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
150
	#$result["function"],當前執行的函式名稱.
151
	#$result["argu"],所使用的參數.
152
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 153
	#$result["content"],ssl用的private key.
3 liveuser 154
	#必填參數:
155
	#$conf["fileArgu"],字串,變數__FILE__的內容.
156
	$conf["fileArgu"]=__FILE__;
157
	#可省略參數:
158
	#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
159
	#$conf["length"]=4096';
160
	#參考資料:
161
	#無.
162
	#備註:
163
	#key generated by openssl with RSA.
164
	*/
165
	public static function createPrivateKey(&$conf){
226 liveuser 166
 
3 liveuser 167
		#初始化要回傳的結果
168
		$result=array();
226 liveuser 169
 
3 liveuser 170
		#取得當前執行的函數名稱
171
		$result["function"]=__FUNCTION__;
226 liveuser 172
 
3 liveuser 173
		#如果 $conf 不為陣列
174
		if(gettype($conf)!="array"){
226 liveuser 175
 
3 liveuser 176
			#設置執行失敗
177
			$result["status"]="false";
226 liveuser 178
 
3 liveuser 179
			#設置執行錯誤訊息
180
			$result["error"][]="\$conf變數須為陣列形態";
181
 
182
			#如果傳入的參數為 null
183
			if($conf==null){
226 liveuser 184
 
3 liveuser 185
				#設置執行錯誤訊息
186
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 187
 
3 liveuser 188
				}#if end
189
 
190
			#回傳結果
191
			return $result;
226 liveuser 192
 
3 liveuser 193
			}#if end
226 liveuser 194
 
3 liveuser 195
		#取得參數
196
		$result["argu"]=$conf;
226 liveuser 197
 
3 liveuser 198
		#函式說明:
199
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
200
		#回傳結果:
201
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
202
		#$result["error"],執行不正常結束的錯訊息陣列.
203
		#$result["simpleError"],簡單表示的錯誤訊息.
204
		#$result["function"],當前執行的函式名稱.
205
		#$result["argu"],設置給予的參數.
206
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
207
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
208
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
209
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
210
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
211
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
212
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
213
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
214
		#必填參數:
215
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
216
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
217
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
218
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
219
		#可省略參數:
220
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
221
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
222
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
223
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
224
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
225
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
226
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
227
		#$conf["canNotBeEmpty"]=array();
228
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
229
		#$conf["canBeEmpty"]=array();
230
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
231
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("length");
232
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
233
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
234
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
235
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer");
236
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
237
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(4096);
238
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
239
		#$conf["disallowAllSkipableVarIsEmpty"]="";
240
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
241
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
242
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
243
		#$conf["disallowAllSkipableVarNotExist"]="";
244
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
245
		#$conf["arrayCountEqualCheck"][]=array();
246
		#參考資料:
247
		#array_keys=>http://php.net/manual/en/function.array-keys.php
248
		#備註:
249
		#無.
250
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
251
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 252
 
3 liveuser 253
		#如果 $checkArguments["status"]等於 "false"
254
		if($checkArguments["status"]==="false"){
255
 
256
			#設置執行錯誤的識別
257
			$result["status"]="false";
258
 
259
			#設置錯誤訊息
260
			$result["error"]=$checkArguments;
261
 
262
			#回傳結果
263
			return $result;
264
 
265
			}#if end
266
 
267
		#如果 $checkArguments["passed"]等於 "false"
268
		if($checkArguments["passed"]==="false"){
269
 
270
			#設置執行錯誤的識別
271
			$result["status"]="false";
272
 
273
			#設置錯誤訊息
274
			$result["error"]=$checkArguments;
275
 
276
			#回傳結果
277
			return $result;
278
 
279
			}#if end
226 liveuser 280
 
3 liveuser 281
		#函式說明:
282
		#呼叫shell執行系統命令,並取得回傳的內容.
283
		#回傳結果:
284
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
285
		#$result["error"],錯誤訊息陣列.
286
		#$result["function"],當前執行的函數名稱.
287
		#$result["argu"],使用的參數.
288
		#$result["cmd"],執行的指令內容.
289
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
290
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
291
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
292
		#$result["running"],是否還在執行.
293
		#$result["pid"],pid.
294
		#$result["statusCode"],執行結束後的代碼.
295
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
296
		#必填參數:
297
		#$conf["command"],字串,要執行的指令.
298
		$conf["external::callShell"]["command"]="openssl";
299
		#$conf["fileArgu"],字串,變數__FILE__的內容.
300
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
301
		#可省略參數:
302
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
303
		$conf["external::callShell"]["argu"]=array("genrsa",$conf["length"]);
304
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
305
		#$conf["arguIsAddr"]=array();
306
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
307
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
308
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
309
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
310
		#$conf["enablePrintDescription"]="true";
311
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
312
		#$conf["printDescription"]="";
313
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
314
		$conf["external::callShell"]["escapeshellarg"]="true";
315
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
316
		#$conf["thereIsShellVar"]=array();
317
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
318
		#$conf["username"]="";
319
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
320
		#$conf["password"]="";
321
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
322
		#$conf["useScript"]="";
323
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
324
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
325
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
326
		#$conf["inBackGround"]="";
327
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
328
		#$conf["getErr"]="false";
329
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
330
		#$conf["doNotRun"]="false";
331
		#參考資料:
332
		#exec=>http://php.net/manual/en/function.exec.php
333
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
334
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
335
		#備註:
336
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
337
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
338
		$callShell=external::callShell($conf["external::callShell"]);
339
		unset($conf["external::callShell"]);
226 liveuser 340
 
3 liveuser 341
		#如果異常
342
		if($callShell["status"]==="false"){
226 liveuser 343
 
3 liveuser 344
			#設置錯誤識別
345
			$result["status"]="false";
226 liveuser 346
 
3 liveuser 347
			#設置錯誤訊息
348
			$result["error"]=$callShell;
226 liveuser 349
 
3 liveuser 350
			#回傳結果
351
			return $result;
226 liveuser 352
 
3 liveuser 353
			}#if end
226 liveuser 354
 
3 liveuser 355
		#函式說明:
356
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
357
		#回傳的結果:
358
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
359
		#$result["function"],當前執行的function名稱
360
		#$result["error"],錯誤訊息陣列.
361
		#$result["content"],處理好的字串.
362
		#$result["argu"],使用的參數.
363
		#必填參數:
364
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
365
		$conf["arrays::arrayToString"]["inputArray"]=$callShell["output"];
366
		#可省略參數:
367
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
255 liveuser 368
		$conf["arrays::arrayToString"]["spiltSymbol"]=PHP_EOL;
3 liveuser 369
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
370
		$conf["arrays::arrayToString"]["skipEnd"]="true";
371
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
372
		#$conf["spiltSymbolAtStart"]="";
373
		#參考資料:
374
		#無.
375
		#備註:
376
		#無.
377
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
378
		unset($conf["arrays::arrayToString"]);
226 liveuser 379
 
3 liveuser 380
		#如果異常
381
		if($arrayToString["status"]==="false"){
226 liveuser 382
 
3 liveuser 383
			#設置錯誤識別
384
			$result["status"]="false";
226 liveuser 385
 
3 liveuser 386
			#設置錯誤訊息
387
			$result["error"]=$arrayToString;
226 liveuser 388
 
3 liveuser 389
			#回傳結果
390
			return $result;
226 liveuser 391
 
3 liveuser 392
			}#if end
226 liveuser 393
 
3 liveuser 394
		#取得 private key 字串
395
		$result["content"]=$arrayToString["content"];
226 liveuser 396
 
3 liveuser 397
		#設置執行正常
398
		$result["status"]="true";
226 liveuser 399
 
3 liveuser 400
		#回傳結果
401
		return $result;
226 liveuser 402
 
3 liveuser 403
		}#function createPrivateKey end
226 liveuser 404
 
3 liveuser 405
	/*
406
	#函式說明:
249 liveuser 407
	#產生certificate sign request(CSR).
3 liveuser 408
	#回傳結果:
409
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
410
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
411
	#$result["function"],當前執行的函式名稱.
412
	#$result["argu"],所使用的參數.
255 liveuser 413
	#$result["content"],csr內容.
3 liveuser 414
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 415
	#$result["privateKey"], private key 的內容.
3 liveuser 416
	#必填參數:
249 liveuser 417
	#$conf["domain"],字串,csr內容的網域名稱.
418
	#$conf["domain"]="";
419
	#可省略參數:
255 liveuser 420
	#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
421
	#$conf["pKey"]="";
249 liveuser 422
	#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
423
	#$conf["country"]="";
424
	#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
425
	#$conf["state"]="";
426
	#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
427
	#$conf["org"]="";
428
	#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
429
	#$conf["unit"]="";
430
	#參考資料:
431
	#無.
432
	#備註:
433
	#無.
434
	*/
435
	public static function createCSR(&$conf){
436
 
437
		#初始化要回傳的結果
438
		$result=array();
439
 
440
		#設置當其函數名稱
441
		$result["function"]=__FUNCTION__;
442
 
443
		#如果 $conf 不為陣列
444
		if(gettype($conf)!="array"){
445
 
446
			#設置執行失敗
447
			$result["status"]="false";
448
 
449
			#設置執行錯誤訊息
450
			$result["error"][]="\$conf變數須為陣列形態";
451
 
452
			#如果傳入的參數為 null
453
			if($conf==null){
454
 
455
				#設置執行錯誤訊息
456
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
457
 
458
				}#if end
459
 
460
			#回傳結果
461
			return $result;
462
 
463
			}#if end
464
 
465
		#取得參數
466
		$result["argu"]=$conf;
467
 
468
		#檢查參數
469
		#函式說明:
470
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
471
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
472
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
473
		#$result["function"],當前執行的函式名稱.
474
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
475
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
476
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
477
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
478
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
479
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
480
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
481
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
482
		#必填寫的參數:
483
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
484
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
485
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
486
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("domain");
487
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
488
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
489
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
490
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
491
		#可以省略的參數:
492
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
493
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
494
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
495
		#$conf["skipableVariableCanNotBeEmpty"]=array();
496
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
255 liveuser 497
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pKey","country","state","city","org","unit");
249 liveuser 498
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
255 liveuser 499
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
249 liveuser 500
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 501
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"TW","Taiwan","Taoyuan City","QBPWCF","RD");
249 liveuser 502
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
503
		#$conf["arrayCountEqualCheck"][]=array();
504
		#參考資料來源:
505
		#array_keys=>http://php.net/manual/en/function.array-keys.php
506
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
507
		unset($conf["variableCheck::checkArguments"]);
508
 
509
		#如果檢查失敗
510
		if($checkArguments["status"]==="false"){
511
 
512
			#設置錯誤識別
513
			$result["status"]="false";
514
 
515
			#設置錯誤訊息
516
			$result["error"]=$checkArguments;
517
 
518
			#回傳結果
519
			return $result;
520
 
521
			}#if end
522
 
523
		#如果檢查不通過
524
		if($checkArguments["passed"]==="false"){
525
 
526
			#設置錯誤識別
527
			$result["status"]="false";
528
 
529
			#設置錯誤訊息
530
			$result["error"]=$checkArguments;
531
 
532
			#回傳結果
533
			return $result;
534
 
535
			}#if end
536
 
255 liveuser 537
		#如果沒有指定 pKey
538
		if(!isset($conf["pKey"])){
249 liveuser 539
 
255 liveuser 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
 
558
			#如果執行異常
559
			if($uuid["status"]==="false"){
249 liveuser 560
 
255 liveuser 561
				#設置錯誤識別
562
				$result["status"]="false";
249 liveuser 563
 
255 liveuser 564
				#設置錯誤訊息
565
				$result["error"]=$uuid;
249 liveuser 566
 
255 liveuser 567
				#回傳結果
568
				return $result;
249 liveuser 569
 
255 liveuser 570
				}#if end
571
 
572
			#取得暫存的檔案名稱
573
			$TFN=$uuid["content"];
574
 
575
			#函式說明:
576
			#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
577
			#回傳結果:
578
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
579
			#$result["error"],錯誤訊息.
580
			#$result["function"],當前執行的函數名稱.
581
			#$result["content"],暫存檔案的路徑與名稱.
582
			#$result["fileName"],暫存檔案的名稱.
583
			#$result["path"],暫存檔案的路徑.
584
			#必填參數:
585
			#無.
586
			#可省略參數:
587
			#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
588
			#$conf["contant"]=array();
589
			#參考資料:
590
			#無.
591
			#備註:
592
			#無.
593
			$conf["fileAccess::createTempFile"]=array();
594
			$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
595
			unset($conf["fileAccess::createTempFile"]);
596
 
597
			#如果執行異常
598
			if($createTempFile["status"]==="false"){
249 liveuser 599
 
255 liveuser 600
				#設置錯誤識別
601
				$result["status"]="false";
249 liveuser 602
 
255 liveuser 603
				#設置錯誤訊息
604
				$result["error"]=$createTempFile;
249 liveuser 605
 
255 liveuser 606
				#回傳結果
607
				return $result;
249 liveuser 608
 
255 liveuser 609
				}#if end
610
 
611
			#暫存的檔案路徑與名稱
612
			$TFN=$createTempFile["content"];
613
 
614
			#產生 privae key
615
			#openssl genrsa -out output.key 4096 
616
 
617
			#函式說明:
618
			#呼叫shell執行系統命令,並取得回傳的內容.
619
			#回傳結果:
620
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
621
			#$result["error"],錯誤訊息陣列.
622
			#$result["function"],當前執行的函數名稱.
623
			#$result["argu"],使用的參數.
624
			#$result["cmd"],執行的指令內容.
625
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
626
			#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
627
			#$result["content"],為執行完後的輸出字串.
628
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
629
			#$result["running"],是否還在執行.
630
			#$result["pid"],pid.
631
			#$result["statusCode"],執行結束後的代碼.
632
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
633
			#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
634
			#必填參數:
635
			#$conf["command"],字串,要執行的指令.
636
			$conf["external::callShell"]["command"]="openssl";
637
			#$conf["fileArgu"],字串,變數__FILE__的內容.
638
			$conf["external::callShell"]["fileArgu"]=__FILE__;
639
			#可省略參數:
640
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
641
			$conf["external::callShell"]["argu"]=array("genrsa","-out",$TFN,"4096");
642
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
643
			#$conf["arguIsAddr"]=array();
644
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
645
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
646
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
647
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
648
			#$conf["enablePrintDescription"]="true";
649
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
650
			#$conf["printDescription"]="";
651
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
652
			#$conf["escapeshellarg"]="false";
653
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
654
			#$conf["thereIsShellVar"]=array();
655
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
656
			#$conf["username"]="";
657
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
658
			#$conf["password"]="";
659
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
660
			#$conf["useScript"]="";
661
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
662
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
663
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
664
			#$conf["inBackGround"]="";
665
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
666
			#$conf["getErr"]="false";
667
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
668
			$conf["external::callShell"]["doNotRun"]="true";
669
			#參考資料:
670
			#exec=>http://php.net/manual/en/function.exec.php
671
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
672
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
673
			#備註:
674
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
675
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
676
			$callShell=external::callShell($conf["external::callShell"]);
677
			unset($conf["external::callShell"]);
678
 
679
			#如果執行異常
680
			if($callShell["status"]==="false"){
249 liveuser 681
 
255 liveuser 682
				#設置錯誤識別
683
				$result["status"]="false";
249 liveuser 684
 
255 liveuser 685
				#設置錯誤訊息
686
				$result["error"]=$callShell;
249 liveuser 687
 
255 liveuser 688
				#回傳結果
689
				return $result;
249 liveuser 690
 
255 liveuser 691
				}#if end
692
 
693
			#debug
694
			#var_dump(__LINE__,$callShell);exit;
695
 
696
			#函式說明:
697
			#透過proc來多執行序運作.
698
			#回傳結果:
699
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
700
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
701
			#$result["function"],當前執行的函式名稱.
702
			#$result["argu"],使用的參數.
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"代表程序的資訊.
704
			#必填參數:
705
			#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
706
			$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
707
			#可省略參數:
708
			#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
709
			$conf["threads::proc"]["wait"]="true";
710
			#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
711
			#$conf["timeout"]=array("10");
712
			#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
713
			#$conf["workingDir"]=array("path");
714
			#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
715
			#$conf["envs"]=array(array("key"=>"value"));
716
			#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
717
			#$conf["executeBy"]=array("bash");
718
			#參考資料:
719
			#https://www.php.net/manual/en/function.proc-open.php
720
			#https://www.php.net/manual/en/function.proc-get-status.php
721
			#https://www.php.net/manual/en/function.proc-terminate.php
722
			#備註:
723
			#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
724
			$proc=threads::proc($conf["threads::proc"]);
725
			unset($conf["threads::proc"]);
726
 
727
			#如果執行異常
728
			if($proc["status"]==="false"){
249 liveuser 729
 
255 liveuser 730
				#設置錯誤識別
731
				$result["status"]="false";
249 liveuser 732
 
255 liveuser 733
				#設置錯誤訊息
734
				$result["error"]=$proc;
249 liveuser 735
 
255 liveuser 736
				#回傳結果
737
				return $result;
249 liveuser 738
 
255 liveuser 739
				}#if end
740
 
741
			#debug
742
			#var_dump(__LINE__,$proc);exit;
743
 
744
			#如果執行異常
745
			if($proc["content"][0]["status"]==="false"){
746
 
747
				#設置錯誤識別
748
				$result["status"]="false";
249 liveuser 749
 
255 liveuser 750
				#設置錯誤訊息
751
				$result["error"]=$proc["content"][0]["error"];
249 liveuser 752
 
255 liveuser 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
				#回傳結果
771
				return $result;
772
 
773
				}#if end
249 liveuser 774
 
775
			}#if end
776
 
255 liveuser 777
		#反之
778
		else{
249 liveuser 779
 
255 liveuser 780
			#檢查 pKey 是否存在
781
			#函式說明:
782
			#檢查多個檔案與資料夾是否存在.
783
			#回傳的結果:
784
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
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"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
293 liveuser 795
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["pKey"]);
255 liveuser 796
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
797
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
798
			#可省略參數:
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"]);
249 liveuser 813
 
255 liveuser 814
			#如果執行異常
815
			if($checkMultiFileExist["status"]==="false"){
249 liveuser 816
 
255 liveuser 817
				#設置錯誤識別
818
				$result["status"]="false";
249 liveuser 819
 
255 liveuser 820
				#設置錯誤訊息
821
				$result["error"]=$checkMultiFileExist;
822
 
823
				#回傳結果
824
				return $result;
825
 
826
				}#if end
249 liveuser 827
 
255 liveuser 828
			#設置pKey
829
			$TFN=$conf["pKey"];
249 liveuser 830
 
255 liveuser 831
			}#else
832
 
249 liveuser 833
		#範例指令
834
		#C,國家,例如TW,代表Taiwan
835
		#ST,州、省,要完整名稱,例如:Taiwan
836
		#L,城市名稱,例如Taoyuan City.
837
		#O=,組織或公司名稱,例如QBPWCF.
838
		#OU,單位名稱,例如RD.
839
		#CN,網域名稱,例如www.qbpwcf.org
840
		#openssl req -new -key qbpwcf.org.key -out qbpwcf.org.csr "-subj=/C=TW/ST=Taiwan/L=Taoyuan City/O=QBPWCF/OU=RD/CN=www.qbpwcf.org/"
841
 
842
		#初始化subj參數
843
		$subjStr="-subj=/";
844
 
845
		#設置 Country 參數
846
		$subjStr=$subjStr."C=".$conf["country"]."/";
847
 
848
		#設置 State 參數
849
		$subjStr=$subjStr."ST=".$conf["state"]."/";
850
 
851
		#設置 city 參數
852
		$subjStr=$subjStr."L=".$conf["city"]."/";
853
 
854
		#設置 Org 參數
855
		$subjStr=$subjStr."O=".$conf["org"]."/";
856
 
857
		#設置 Unit 參數
858
		$subjStr=$subjStr."OU=".$conf["unit"]."/";
859
 
860
		#設置 domain name 參數
861
		$subjStr=$subjStr."CN=".$conf["domain"]."/";
862
 
863
		#函式說明:
864
		#呼叫shell執行系統命令,並取得回傳的內容.
865
		#回傳結果:
866
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
867
		#$result["error"],錯誤訊息陣列.
868
		#$result["function"],當前執行的函數名稱.
869
		#$result["argu"],使用的參數.
870
		#$result["cmd"],執行的指令內容.
871
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
872
		#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
873
		#$result["content"],為執行完後的輸出字串.
874
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
875
		#$result["running"],是否還在執行.
876
		#$result["pid"],pid.
877
		#$result["statusCode"],執行結束後的代碼.
878
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
879
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
880
		#必填參數:
881
		#$conf["command"],字串,要執行的指令.
882
		$conf["external::callShell"]["command"]="openssl";
883
		#$conf["fileArgu"],字串,變數__FILE__的內容.
884
		$conf["external::callShell"]["fileArgu"]=__FILE__;
885
		#可省略參數:
886
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
887
		$conf["external::callShell"]["argu"]=array("req","-new","-key",$TFN,$subjStr);
888
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
889
		#$conf["arguIsAddr"]=array();
890
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
891
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
892
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
893
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
894
		#$conf["enablePrintDescription"]="true";
895
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
896
		#$conf["printDescription"]="";
897
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
898
		$conf["external::callShell"]["escapeshellarg"]="true";
899
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
900
		#$conf["thereIsShellVar"]=array();
901
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
902
		#$conf["username"]="";
903
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
904
		#$conf["password"]="";
905
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
906
		#$conf["useScript"]="";
907
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
908
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
909
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
910
		#$conf["inBackGround"]="";
911
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
912
		#$conf["getErr"]="false";
913
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
914
		$conf["external::callShell"]["doNotRun"]="true";
915
		#參考資料:
916
		#exec=>http://php.net/manual/en/function.exec.php
917
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
918
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
919
		#備註:
920
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
921
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
922
		$callShell=external::callShell($conf["external::callShell"]);
923
		unset($conf["external::callShell"]);
924
 
925
		#如果執行異常
926
		if($callShell["status"]==="false"){
927
 
928
			#設置錯誤識別
929
			$result["status"]="false";
930
 
931
			#設置錯誤訊息
932
			$result["error"]=$callShell;
933
 
934
			#回傳結果
935
			return $result;
936
 
937
			}#if end
938
 
939
		#debug
940
		#var_dump(__LINE__,$callShell);exit;
941
 
942
		#函式說明:
943
		#透過proc來多執行序運作.
944
		#回傳結果:
945
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
946
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
947
		#$result["function"],當前執行的函式名稱.
948
		#$result["argu"],使用的參數.
949
		#$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"代表程序的資訊.
950
		#必填參數:
951
		#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
952
		$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
953
		#可省略參數:
954
		#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
955
		$conf["threads::proc"]["wait"]="true";
956
		#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
957
		#$conf["timeout"]=array("10");
958
		#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
959
		#$conf["workingDir"]=array("path");
960
		#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
961
		#$conf["envs"]=array(array("key"=>"value"));
962
		#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
963
		#$conf["executeBy"]=array("bash");
964
		#參考資料:
965
		#https://www.php.net/manual/en/function.proc-open.php
966
		#https://www.php.net/manual/en/function.proc-get-status.php
967
		#https://www.php.net/manual/en/function.proc-terminate.php
968
		#備註:
969
		#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
970
		$proc=threads::proc($conf["threads::proc"]);
971
		unset($conf["threads::proc"]);
972
 
973
		#如果執行異常
974
		if($proc["status"]==="false"){
975
 
976
			#設置錯誤識別
977
			$result["status"]="false";
978
 
979
			#設置錯誤訊息
980
			$result["error"]=$proc;
981
 
982
			#回傳結果
983
			return $result;
984
 
985
			}#if end
986
 
987
		#如果執行異常
988
		if($proc["content"][0]["status"]==="false"){
989
 
990
			#設置錯誤識別
991
			$result["status"]="false";
992
 
993
			#設置錯誤訊息
994
			$result["error"]=$proc["content"][0]["error"];
995
 
996
			#回傳結果
997
			return $result;
998
 
999
			}#if end
1000
 
1001
		#debug
1002
		#var_dump(__LINE__,$proc);exit;
1003
 
1004
		#儲存csr
1005
		$csr=$proc["content"][0]["content"];
1006
 
1007
		#取得 csr 內容
1008
		$result["content"]=$csr;
1009
 
255 liveuser 1010
		#取得 private key 的內容
249 liveuser 1011
		#函式說明:
255 liveuser 1012
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1013
		#回傳的變數說明:
1014
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1015
		#$result["error"],錯誤訊息提示.
1016
		#$result["warning"],警告訊息.
249 liveuser 1017
		#$result["function"],當前執行的函數名稱.
255 liveuser 1018
		#$result["fileContent"],爲檔案的內容陣列.
1019
		#$result["lineCount"],爲檔案內容總共的行數.
1020
		#$result["fullContent"],為檔案的完整內容.
1021
		#$result["base64dataOnly"],檔案的base64data.
1022
		#$result["base64data"],為在網頁上給予src參數的數值.
1023
		#$result["mimeType"],為檔案的mime type.
249 liveuser 1024
		#必填參數:
255 liveuser 1025
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1026
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$TFN;
1027
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1028
		$conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
249 liveuser 1029
		#可省略參數:
255 liveuser 1030
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
1031
		#$conf["web"]="true";
1032
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1033
		#$conf["createIfnotExist"]="false";
1034
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"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
249 liveuser 1041
		#參考資料:
1042
		#無.
1043
		#備註:
1044
		#無.
255 liveuser 1045
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
1046
		unset($conf["fileAccess::getFileContent"]);
249 liveuser 1047
 
1048
		#如果執行異常
255 liveuser 1049
		if($getFileContent["status"]==="false"){
249 liveuser 1050
 
1051
			#設置錯誤識別
1052
			$result["status"]="false";
1053
 
1054
			#設置錯誤訊息
255 liveuser 1055
			$result["error"]=$getFileContent;
249 liveuser 1056
 
1057
			#回傳結果
1058
			return $result;
1059
 
1060
			}#if end
255 liveuser 1061
 
1062
		#設置要回傳的 private key 的內容
1063
		$result["privateKey"]=$getFileContent["fullContent"];
249 liveuser 1064
 
255 liveuser 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
1111
 
249 liveuser 1112
		#設置執行正常
1113
		$result["status"]="true";
1114
 
1115
		#回傳結果
1116
		return $result;
1117
 
1118
		}#function createCSR end
1119
 
1120
	/*
1121
	#函式說明:
281 liveuser 1122
	#提供certificate sign request(CSR)透過zerossl產生certificate.
249 liveuser 1123
	#回傳結果:
1124
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1125
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1126
	#$result["function"],當前執行的函式名稱.
1127
	#$result["argu"],所使用的參數.
1128
	#$result["curl_verbose_info"],curl執行的詳細資訊.
1129
	#$result["id"],用於zerossl api驗證domain的id.
1130
	#$result["content"],字串,得到的json字串回應.
1131
	#$result["cnameKey"],用於dns CNAME驗證鍵名.
1132
	#$result["cnameVal"],用於dms CNAME驗證鍵值.
1133
	#必填參數:
3 liveuser 1134
	#$conf["certificate_domains"],字串,要簽署的doamin名稱.
1135
	$conf["certificate_domains"]="";
1136
	#$conf["certificate_csr"],字串,簽署的資訊.
1137
	$conf["certificate_csr"]="";
1138
	#$conf["fileArgu"],字串,變數__FILE__的內容.
1139
	$conf["fileArgu"]=__FILE__;
1140
	#可省略參數:
1141
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
1142
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
1143
	#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
1144
	#$conf["path"]=self::getApiInfo()["csrPath"];
1145
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
1146
	#$conf["key"]=self::getApiInfo()["apiKey"];
1147
	#參考資料:
1148
	#無.
1149
	#備註:
1150
	#無.
1151
	*/
249 liveuser 1152
	public static function createCertificate(&$conf){
226 liveuser 1153
 
3 liveuser 1154
		#break point
1155
		#var_dump(self::getApiInfo());exit;
226 liveuser 1156
 
3 liveuser 1157
		#初始化要回傳的結果
1158
		$result=array();
226 liveuser 1159
 
3 liveuser 1160
		#設置當其函數名稱
1161
		$result["function"]=__FUNCTION__;
226 liveuser 1162
 
3 liveuser 1163
		#如果 $conf 不為陣列
1164
		if(gettype($conf)!="array"){
226 liveuser 1165
 
3 liveuser 1166
			#設置執行失敗
1167
			$result["status"]="false";
226 liveuser 1168
 
3 liveuser 1169
			#設置執行錯誤訊息
1170
			$result["error"][]="\$conf變數須為陣列形態";
1171
 
1172
			#如果傳入的參數為 null
1173
			if($conf==null){
226 liveuser 1174
 
3 liveuser 1175
				#設置執行錯誤訊息
1176
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1177
 
3 liveuser 1178
				}#if end
1179
 
1180
			#回傳結果
1181
			return $result;
226 liveuser 1182
 
3 liveuser 1183
			}#if end
226 liveuser 1184
 
3 liveuser 1185
		#取得參數
1186
		$result["argu"]=$conf;
226 liveuser 1187
 
3 liveuser 1188
		#檢查參數
1189
		#函式說明:
1190
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1191
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1192
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1193
		#$result["function"],當前執行的函式名稱.
1194
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1195
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1196
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1197
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1198
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1199
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1200
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1201
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1202
		#必填寫的參數:
1203
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1204
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1205
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1206
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","certificate_domains","certificate_csr");
226 liveuser 1207
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 1208
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
1209
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1210
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1211
		#可以省略的參數:
1212
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1213
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1214
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
1215
		#$conf["skipableVariableCanNotBeEmpty"]=array();
1216
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1217
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","path","key");
226 liveuser 1218
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1219
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1220
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1221
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["csrPath"],self::getApiInfo()["apiKey"]);
1222
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1223
		#$conf["arrayCountEqualCheck"][]=array();
1224
		#參考資料來源:
1225
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1226
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1227
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1228
 
3 liveuser 1229
		#如果檢查失敗
249 liveuser 1230
		if($checkArguments["status"]==="false"){
226 liveuser 1231
 
3 liveuser 1232
			#設置錯誤識別
1233
			$result["status"]="false";
226 liveuser 1234
 
3 liveuser 1235
			#設置錯誤訊息
1236
			$result["error"]=$checkArguments;
226 liveuser 1237
 
3 liveuser 1238
			#回傳結果
1239
			return $result;
226 liveuser 1240
 
3 liveuser 1241
			}#if end
226 liveuser 1242
 
3 liveuser 1243
		#如果檢查不通過
249 liveuser 1244
		if($checkArguments["passed"]==="false"){
226 liveuser 1245
 
3 liveuser 1246
			#設置錯誤識別
1247
			$result["status"]="false";
226 liveuser 1248
 
3 liveuser 1249
			#設置錯誤訊息
1250
			$result["error"]=$checkArguments;
226 liveuser 1251
 
3 liveuser 1252
			#回傳結果
1253
			return $result;
226 liveuser 1254
 
3 liveuser 1255
			}#if end
226 liveuser 1256
 
3 liveuser 1257
		#要傳送的 key -> value
1258
		$postArray=array();
226 liveuser 1259
 
3 liveuser 1260
		#設置要簽署的domain
1261
		$postArray["certificate_domains"]=$conf["certificate_domains"];
226 liveuser 1262
 
3 liveuser 1263
		#設置csr
1264
		$postArray["certificate_csr"]=$conf["certificate_csr"];
226 liveuser 1265
 
3 liveuser 1266
		#預設為 90 天的憑證
1267
		$postArray["certificate_validity_days"]=90;
226 liveuser 1268
 
3 liveuser 1269
		#強制讓 要簽署的domain 為 $postArray["certificate_domains"]
1270
		$postArray["strict_domains"]=1;
226 liveuser 1271
 
3 liveuser 1272
		#設置要傳送的 json
1273
		$postJson=json_encode($postArray);
226 liveuser 1274
 
3 liveuser 1275
		#函式說明:
1276
		#運行curl cmd
1277
		#回傳結果:
1278
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1279
		#$result["error"],錯誤訊息陣列.
1280
		#$result["function"],當前執行的函式名稱.
1281
		#$result["founded"],識別網址找不找得到.
1282
		#$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"代表程序的資訊.
1283
		#$result["fullContent"],取得回應的完整字串內容.
1284
		#$result["cookie"],cookie檔案的位置與名稱.
1285
		#$result["cmd"],執行的command.
1286
		#$result["argu],使用的參數.
1287
		#必填參數:
1288
		#$conf["url"],字串,目標url.
1289
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].$conf["path"]."?access_key=".$conf["key"];
1290
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1291
		$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
1292
		#可省略參數:
1293
		#$conf["header"],字串陣列,要傳送的header.
1294
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
1295
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
1296
		#$conf["allowAnySSLcertificate"]="";
1297
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
1298
		#$conf["postVar"]=array();
1299
		#$conf["rawPost"]="字串",要傳送的raw post內容.
1300
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
1301
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
1302
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
1303
		#$conf["agent"],字串,user agent的名稱.
1304
		#$conf["agent"]="";
1305
		#$conf["cookie"],字串,cookie位置與檔案位置.
1306
		#$conf["cookie"]="";
1307
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
1308
		#$conf["forceNewCookie"]="";
1309
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
1310
		#$conf["inBg"]="true";
1311
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
1312
		#$conf["bgInProc"]="false";
1313
		#參考資料:
1314
		#無.
1315
		#備註:
1316
		#無.
1317
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
1318
		unset($conf["catchWebContent::curlCmd"]);
226 liveuser 1319
 
3 liveuser 1320
		#如果異常
1321
		if($curlCmd["status"]==="false"){
226 liveuser 1322
 
3 liveuser 1323
			#設置錯誤識別
1324
			$result["status"]="false";
226 liveuser 1325
 
3 liveuser 1326
			#設置錯誤訊息
1327
			$result["error"]=$curlCmd;
226 liveuser 1328
 
3 liveuser 1329
			#回傳結果
1330
			return $result;
226 liveuser 1331
 
3 liveuser 1332
			}#if end
226 liveuser 1333
 
3 liveuser 1334
		#設置curl的詳細資訊
1335
		$result["curl_verbose_info"]=$curlCmd;
226 liveuser 1336
 
3 liveuser 1337
		/* 範例 json content
249 liveuser 1338
		{"id":"de9bfbbc78ad2b04323ac0670efefe58","type":"1","common_name":"qbpwcf.org","additional_domains":"","created":"2026-01-19 11:47:13","expires":"2026-04-19 23:59:59","status":"draft","validation_type":null,"validation_emails":null,"replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"qbpwcf.org":["admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"qbpwcf.org":{"file_validation_url_http":"http:\/\/qbpwcf.org\/.well-known\/pki-validation\/3FE7CA1D6DA057FB40FDD333B4C105F9.txt","file_validation_url_https":"https:\/\/qbpwcf.org\/.well-known\/pki-validation\/3FE7CA1D6DA057FB40FDD333B4C105F9.txt","file_validation_content":["7B29341B7148276F5025CE90FC1138037871040E5B7FBDB8E7EEF7CC8DAA4A56","comodoca.com","2e85598b7f1b864"],"cname_validation_p1":"_3FE7CA1D6DA057FB40FDD333B4C105F9.qbpwcf.org","cname_validation_p2":"7B29341B7148276F5025CE90FC113803.7871040E5B7FBDB8E7EEF7CC8DAA4A56.2e85598b7f1b864.comodoca.com"}}},"signature_algorithm_properties":null}
3 liveuser 1339
		*/
226 liveuser 1340
 
249 liveuser 1341
		#驗證結果是否為 json
1342
		$json_validate=json_validate($curlCmd["fullContent"]);
226 liveuser 1343
 
249 liveuser 1344
		#如果回應不是 json
1345
		if(!$json_validate){
1346
 
1347
			#設置錯誤識別
1348
			$result["status"]="false";
1349
 
1350
			#設置錯誤訊息
1351
			$result["error"]=$curlCmd;
1352
 
1353
			#回傳結果
1354
			return $result;
1355
 
1356
			}#if end
1357
 
1358
		#設置json string結果
1359
		$result["content"]=$curlCmd["fullContent"];
1360
 
1361
		#解析json
1362
		$jsonRes=json_decode($result["content"]);
255 liveuser 1363
 
1364
		#另存 certifucate domain
1365
		$cerDomain=$conf["certificate_domains"];
1366
 
1367
		#如果缺少必備的資訊
1368
		if(!isset($jsonRes->validation)){
1369
 
1370
			#設置錯誤識別
1371
			$result["status"]="false";
249 liveuser 1372
 
255 liveuser 1373
			#設置錯誤訊息
1374
			$result["error"]=$curlCmd;
1375
 
1376
			#回傳結果
1377
			return $result;
1378
 
1379
			}#if end
1380
 
249 liveuser 1381
		#取得用於 dns CNAME 驗證的名稱
255 liveuser 1382
		$result["cnameKey"]=$jsonRes->validation->other_methods->$cerDomain->cname_validation_p1;
249 liveuser 1383
 
1384
		#取得用於 dns CNAME 驗證的數值
255 liveuser 1385
		$result["cnameVal"]=$jsonRes->validation->other_methods->$cerDomain->cname_validation_p2;
249 liveuser 1386
 
1387
		#取得用於認證domain時識別用的id
1388
		$result["id"]=$jsonRes->id;
1389
 
3 liveuser 1390
		#設置執行正常
1391
		$result["status"]="true";
226 liveuser 1392
 
3 liveuser 1393
		#回傳結果
1394
		return $result;
226 liveuser 1395
 
249 liveuser 1396
		}#function createCertificate end
3 liveuser 1397
 
249 liveuser 1398
	/*
1399
	#函式說明:
291 liveuser 1400
	#解析RR檔案中其中的一行內容,回傳結果.
1401
	#回傳結果:
1402
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1403
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1404
	#$result["function"],當前執行的函式名稱.
1405
	#$result["argu"],所使用的參數.
404 liveuser 1406
	#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列,"type"的數值可能為"A"、"AAAA"、"$TTL"、"$ORIGIN"、"CNAME"、"TXT"、"NS"、"SOA".
291 liveuser 1407
	#$result["domain"],字串,RR所屬domain.
404 liveuser 1408
	#$result["defaultTTL"],字串,預設的RR更新時間,若line參數解析後type不為$TTL,則不會有該回傳結果.
291 liveuser 1409
	#$result["comment"],字串,一行的註解.
1410
	#必填參數:
1411
	#$conf["line"],字串,要解析的行內容.
1412
	$conf["line"]="";
1413
	#可省略參數:
1414
	#無.
1415
	#參考資料:
1416
	#無.
1417
	#備註:
1418
	#無.
1419
	*/
1420
	public static function parseRRline(&$conf){
1421
 
1422
		#初始化要回傳的結果
1423
		$result=array();
1424
 
1425
		#設置當其函數名稱
1426
		$result["function"]=__FUNCTION__;
1427
 
1428
		#如果 $conf 不為陣列
1429
		if(gettype($conf)!="array"){
1430
 
1431
			#設置執行失敗
1432
			$result["status"]="false";
1433
 
1434
			#設置執行錯誤訊息
1435
			$result["error"][]="\$conf變數須為陣列形態";
1436
 
1437
			#如果傳入的參數為 null
1438
			if($conf==null){
1439
 
1440
				#設置執行錯誤訊息
1441
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1442
 
1443
				}#if end
1444
 
1445
			#回傳結果
1446
			return $result;
1447
 
1448
			}#if end
1449
 
1450
		#取得參數
1451
		$result["argu"]=$conf;
1452
 
1453
		#檢查參數
1454
		#函式說明:
1455
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1456
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1457
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1458
		#$result["function"],當前執行的函式名稱.
1459
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1460
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1461
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1462
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1463
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1464
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1465
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1466
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1467
		#必填寫的參數:
1468
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1469
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1470
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1471
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("line");
1472
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
1473
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
1474
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1475
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1476
		#可以省略的參數:
1477
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1478
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1479
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
1480
		#$conf["skipableVariableCanNotBeEmpty"]=array();
1481
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1482
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThread");
1483
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1484
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1485
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1486
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
1487
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1488
		#$conf["arrayCountEqualCheck"][]=array();
1489
		#參考資料來源:
1490
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1491
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1492
		unset($conf["variableCheck::checkArguments"]);
1493
 
1494
		#如果檢查失敗
1495
		if($checkArguments["status"]==="false"){
1496
 
1497
			#設置錯誤識別
1498
			$result["status"]="false";
1499
 
1500
			#設置錯誤訊息
1501
			$result["error"]=$checkArguments;
1502
 
1503
			#回傳結果
1504
			return $result;
1505
 
1506
			}#if end
1507
 
1508
		#如果檢查不通過
1509
		if($checkArguments["passed"]==="false"){
1510
 
1511
			#設置錯誤識別
1512
			$result["status"]="false";
1513
 
1514
			#設置錯誤訊息
1515
			$result["error"]=$checkArguments;
1516
 
1517
			#回傳結果
1518
			return $result;
1519
 
1520
			}#if end
1521
 
1522
		#初始化要回傳的content
1523
		$result["content"]=array();
1524
 
1525
		#另存一份要處理的RR
1526
		$unFormatStr=$conf["line"];
1527
 
1528
		#初始化該行的資訊陣列
1529
		$info=array();
1530
 
1531
		#尋找";"開頭的內容,亦即整行都是註解.
1532
		#函式說明:
1533
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1534
		#回傳結果:
1535
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1536
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1537
		#$result["function"],當前執行的函式名稱.
1538
		#$result["argu"],所使用的參數.
1539
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1540
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1541
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1542
		#必填參數:
1543
		#$conf["input"],字串,要檢查的字串.
1544
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1545
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1546
		$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
1547
		#可省略參數:
1548
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1549
		#$conf["varEqual"]=array(null,"found");
1550
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1551
		#$conf["varCon"]=array("no_tail"=>" not");
1552
		#參考資料:
1553
		#無.
1554
		#備註:
1555
		#無.
1556
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1557
		unset($conf["search::findSpecifyStrFormat"]);
1558
 
1559
		#如果執行異常
1560
		if($findSpecifyStrFormat["status"]==="false"){
1561
 
1562
			#設置錯誤識別
1563
			$result["status"]="false";
1564
 
1565
			#設置錯誤訊息
1566
			$result["error"]=$findSpecifyStrFormat;
1567
 
1568
			#回傳結果
1569
			return $result;
1570
 
1571
			}#if end
1572
 
1573
		#如果有找到符合格式的內容
1574
		if($findSpecifyStrFormat["found"]==="true"){
1575
 
1576
			#儲存為註解
1577
			$result["comment"]=$unFormatStr;
1578
 
1579
			#設置執行正常
1580
			$result["status"]="true";
1581
 
1582
			#回傳結果
1583
			return $result;
1584
 
1585
			}#if end
1586
 
1587
		#函式說明:
1588
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1589
		#回傳結果:
1590
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1591
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1592
		#$result["function"],當前執行的函式名稱.
1593
		#$result["argu"],所使用的參數.
1594
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1595
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1596
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1597
		#必填參數:
1598
		#$conf["input"],字串,要檢查的字串.
1599
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1600
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1601
		$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
1602
		#可省略參數:
1603
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1604
		#$conf["varEqual"]=array(null,"found");
1605
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1606
		#$conf["varCon"]=array("no_tail"=>" not");
1607
		#參考資料:
1608
		#無.
1609
		#備註:
1610
		#無.
1611
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1612
		unset($conf["search::findSpecifyStrFormat"]);
1613
 
1614
		#如果執行異常
1615
		if($findSpecifyStrFormat["status"]==="false"){
1616
 
1617
			#設置錯誤識別
1618
			$result["status"]="false";
1619
 
1620
			#設置錯誤訊息
1621
			$result["error"]=$findSpecifyStrFormat;
1622
 
1623
			#回傳結果
1624
			return $result;
1625
 
1626
			}#if end
1627
 
1628
		#如果有找到符合格式的內容
1629
		if($findSpecifyStrFormat["found"]==="true"){
1630
 
1631
			#設置 type 的數值
1632
			$info["type"]="\$ORIGIN";
1633
 
1634
			#取得後面待處理的內容
1635
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
1636
 
1637
			#函式說明:
1638
			#將字串開頭的特定關鍵字移除.
1639
			#回傳結果:
1640
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1641
			#$result["error"],錯誤訊息陣列.
1642
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
1643
			#$result["function"],當前執行的函數名稱.
1644
			#$result["argu"],使用的參數.
1645
			#$result["content"],處理好的的字串內容.
1646
			#$result["deleted"],被移除的內容.
1647
			#必填參數:
1648
			#$conf["stringIn"],字串,要處理的字串.
1649
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
1650
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
1651
			$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
1652
			#可省略參數:
1653
			#無.
1654
			#參考資料:
1655
			#無.
1656
			#備註:
1657
			#無.
1658
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
1659
			unset($conf["stringProcess::delHeadStr"]);
1660
 
1661
			#如果執行異常
1662
			if($delHeadStr["status"]==="false"){
1663
 
1664
				#設置錯誤識別
1665
				$result["status"]="false";
1666
 
1667
				#設置錯誤訊息
1668
				$result["error"]=$delHeadStr;
1669
 
1670
				#回傳結果
1671
				return $result;
1672
 
1673
				}#if end
1674
 
1675
			#如果有移除開頭的字串
1676
			if($delHeadStr["founded"]==="true"){
1677
 
1678
				#取得處理後的結果
1679
				$unFormatStr=$delHeadStr["content"];
1680
 
1681
				}#if end
1682
 
1683
			#解析 $ORIGN 的數值, 以及後面是否有註解...
1684
			#函式說明:
1685
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1686
			#回傳結果:
1687
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1688
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1689
			#$result["function"],當前執行的函式名稱.
1690
			#$result["argu"],所使用的參數.
1691
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1692
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1693
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1694
			#必填參數:
1695
			#$conf["input"],字串,要檢查的字串.
1696
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1697
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1698
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
1699
			#可省略參數:
1700
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1701
			#$conf["varEqual"]=array(null,"found");
1702
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1703
			#$conf["varCon"]=array("no_tail"=>" not");
1704
			#參考資料:
1705
			#無.
1706
			#備註:
1707
			#無.
1708
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1709
			unset($conf["search::findSpecifyStrFormat"]);
1710
 
1711
			#如果執行異常
1712
			if($findSpecifyStrFormat["status"]==="false"){
1713
 
1714
				#設置錯誤識別
1715
				$result["status"]="false";
1716
 
1717
				#設置錯誤訊息
1718
				$result["error"]=$findSpecifyStrFormat;
1719
 
1720
				#回傳結果
1721
				return $result;
1722
 
1723
				}#if end
1724
 
1725
			#如果有數值跟註解
1726
			if($findSpecifyStrFormat["found"]==="true"){
1727
 
1728
				#儲存數值
1729
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
1730
 
1731
				#儲存zone domain
1732
				$result["domain"]=trim($info["value"]);
1733
 
1734
				#儲存註解
1735
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
1736
 
1737
				#儲存 RR 的記錄
1738
				$result["content"]=$info;
1739
 
1740
				#設置執行正常
1741
				$result["status"]="true";
1742
 
1743
				#回傳結果
1744
				return $result;
1745
 
1746
				}#if end
1747
 
1748
			#執行到這邊代表剩下的內容都是 value
1749
			$info["value"]=$unFormatStr;
1750
 
1751
			#儲存zone domain
1752
			$result["domain"]=trim($info["value"]);
1753
 
1754
			#儲存 RR 的記錄
1755
			$result["content"]=$info;
1756
 
1757
			#設置執行正常
1758
			$result["status"]="true";
1759
 
1760
			#回傳結果
1761
			return $result;
1762
 
1763
			}#if end
1764
 
1765
		#檢查是否為 $TTL 開頭
1766
		#函式說明:
1767
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1768
		#回傳結果:
1769
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1770
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1771
		#$result["function"],當前執行的函式名稱.
1772
		#$result["argu"],所使用的參數.
1773
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1774
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1775
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1776
		#必填參數:
1777
		#$conf["input"],字串,要檢查的字串.
1778
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1779
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1780
		$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
1781
		#可省略參數:
1782
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1783
		#$conf["varEqual"]=array(null,"found");
1784
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1785
		#$conf["varCon"]=array("no_tail"=>" not");
1786
		#參考資料:
1787
		#無.
1788
		#備註:
1789
		#無.
1790
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1791
		unset($conf["search::findSpecifyStrFormat"]);
1792
 
1793
		#如果執行異常
1794
		if($findSpecifyStrFormat["status"]==="false"){
1795
 
1796
			#設置錯誤識別
1797
			$result["status"]="false";
1798
 
1799
			#設置錯誤訊息
1800
			$result["error"]=$findSpecifyStrFormat;
1801
 
1802
			#回傳結果
1803
			return $result;
1804
 
1805
			}#if end
1806
 
1807
		#如果有找到符合格式的內容
1808
		if($findSpecifyStrFormat["found"]==="true"){
1809
 
1810
			#設置 type 的數值
1811
			$info["type"]="\$TTL";
1812
 
1813
			#取得後面待處理的內容
1814
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
1815
 
1816
			#函式說明:
1817
			#將字串開頭的特定關鍵字移除.
1818
			#回傳結果:
1819
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1820
			#$result["error"],錯誤訊息陣列.
1821
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
1822
			#$result["function"],當前執行的函數名稱.
1823
			#$result["argu"],使用的參數.
1824
			#$result["content"],處理好的的字串內容.
1825
			#$result["deleted"],被移除的內容.
1826
			#必填參數:
1827
			#$conf["stringIn"],字串,要處理的字串.
1828
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
1829
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
1830
			$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
1831
			#可省略參數:
1832
			#無.
1833
			#參考資料:
1834
			#無.
1835
			#備註:
1836
			#無.
1837
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
1838
			unset($conf["stringProcess::delHeadStr"]);
1839
 
1840
			#如果執行異常
1841
			if($delHeadStr["status"]==="false"){
1842
 
1843
				#設置錯誤識別
1844
				$result["status"]="false";
1845
 
1846
				#設置錯誤訊息
1847
				$result["error"]=$delHeadStr;
1848
 
1849
				#回傳結果
1850
				return $result;
1851
 
1852
				}#if end
1853
 
1854
			#如果有移除開頭的字串
1855
			if($delHeadStr["founded"]==="true"){
1856
 
1857
				#取得處理後的結果
1858
				$unFormatStr=$delHeadStr["content"];
1859
 
1860
				}#if end
1861
 
1862
			#解析 $TTL 的數值, 以及後面是否有註解...
1863
			#函式說明:
1864
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1865
			#回傳結果:
1866
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1867
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1868
			#$result["function"],當前執行的函式名稱.
1869
			#$result["argu"],所使用的參數.
1870
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1871
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1872
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1873
			#必填參數:
1874
			#$conf["input"],字串,要檢查的字串.
1875
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1876
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1877
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
1878
			#可省略參數:
1879
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1880
			#$conf["varEqual"]=array(null,"found");
1881
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1882
			#$conf["varCon"]=array("no_tail"=>" not");
1883
			#參考資料:
1884
			#無.
1885
			#備註:
1886
			#無.
1887
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1888
			unset($conf["search::findSpecifyStrFormat"]);
1889
 
1890
			#如果執行異常
1891
			if($findSpecifyStrFormat["status"]==="false"){
1892
 
1893
				#設置錯誤識別
1894
				$result["status"]="false";
1895
 
1896
				#設置錯誤訊息
1897
				$result["error"]=$findSpecifyStrFormat;
1898
 
1899
				#回傳結果
1900
				return $result;
1901
 
1902
				}#if end
1903
 
1904
			#如果有數值跟註解
1905
			if($findSpecifyStrFormat["found"]==="true"){
1906
 
1907
				#儲存數值
1908
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
1909
 
1910
				#儲存註解
1911
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
1912
 
1913
				#儲存預設的 TTL
1914
				$result["defaultTTL"]=trim($info["value"]);
1915
 
1916
				#儲存 RR 的記錄
1917
				$result["content"]=$info;
1918
 
1919
				#設置執行正常
1920
				$result["status"]="true";
1921
 
1922
				#回傳結果
1923
				return $result;
1924
 
1925
				}#if end
1926
 
1927
			#執行到這邊代表剩下的內容都是 value
1928
			$info["value"]=$unFormatStr;
1929
 
1930
			#儲存預設的 TTL
1931
			$result["defaultTTL"]=trim($info["value"]);
1932
 
1933
			#儲存 RR 的記錄
1934
			$result["content"]=$info;
1935
 
1936
			#設置執行正常
1937
			$result["status"]="true";
1938
 
1939
			#回傳結果
1940
			return $result;
1941
 
1942
			}#if end
1943
 
1944
		#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
1945
 
1946
		#函式說明:
1947
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1948
		#回傳結果:
1949
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1950
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1951
		#$result["function"],當前執行的函式名稱.
1952
		#$result["argu"],所使用的參數.
1953
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1954
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1955
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
1956
		#必填參數:
1957
		#$conf["input"],字串,要檢查的字串.
1958
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1959
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1960
		$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
1961
		#可省略參數:
1962
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1963
		#$conf["varEqual"]=array(null,"found");
1964
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1965
		#$conf["varCon"]=array("no_tail"=>" not");
1966
		#參考資料:
1967
		#無.
1968
		#備註:
1969
		#無.
1970
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1971
		unset($conf["search::findSpecifyStrFormat"]);
1972
 
1973
		#如果執行異常
1974
		if($findSpecifyStrFormat["status"]==="false"){
1975
 
1976
			#設置錯誤識別
1977
			$result["status"]="false";
1978
 
1979
			#設置錯誤訊息
1980
			$result["error"]=$findSpecifyStrFormat;
1981
 
1982
			#回傳結果
1983
			return $result;
1984
 
1985
			}#if end
1986
 
1987
		#如果存在"("
1988
		if($findSpecifyStrFormat["found"]==="true"){
1989
 
1990
			#取得無"("的內容
1991
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
1992
 
1993
			#取得拆下來的含開頭"("內容
1994
			$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
1995
 
1996
			}#if end
1997
 
1998
		#反之
1999
		else{
2000
 
2001
			#函式說明:
2002
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2003
			#回傳結果:
2004
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2005
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2006
			#$result["function"],當前執行的函式名稱.
2007
			#$result["argu"],所使用的參數.
2008
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2009
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2010
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2011
			#必填參數:
2012
			#$conf["input"],字串,要檢查的字串.
2013
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2014
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2015
			$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
2016
			#可省略參數:
2017
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2018
			#$conf["varEqual"]=array(null,"found");
2019
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2020
			#$conf["varCon"]=array("no_tail"=>" not");
2021
			#參考資料:
2022
			#無.
2023
			#備註:
2024
			#無.
2025
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2026
			unset($conf["search::findSpecifyStrFormat"]);
2027
 
2028
			#如果執行異常
2029
			if($findSpecifyStrFormat["status"]==="false"){
2030
 
2031
				#設置錯誤識別
2032
				$result["status"]="false";
2033
 
2034
				#設置錯誤訊息
2035
				$result["error"]=$findSpecifyStrFormat;
2036
 
2037
				#回傳結果
2038
				return $result;
2039
 
2040
				}#if end
2041
 
2042
			#如果存在"
2043
			if($findSpecifyStrFormat["found"]==="true"){
2044
 
2045
				#取得無"的內容
2046
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2047
 
2048
				#取得拆下來的含開頭"內容
2049
				$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
2050
 
2051
				}#if end
2052
 
2053
			#反之
2054
			else{
2055
 
2056
				#函式說明:
2057
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2058
				#回傳結果:
2059
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2060
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2061
				#$result["function"],當前執行的函式名稱.
2062
				#$result["argu"],所使用的參數.
2063
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2064
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2065
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2066
				#必填參數:
2067
				#$conf["input"],字串,要檢查的字串.
2068
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2069
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2070
				$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
2071
				#可省略參數:
2072
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2073
				#$conf["varEqual"]=array(null,"found");
2074
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2075
				#$conf["varCon"]=array("no_tail"=>" not");
2076
				#參考資料:
2077
				#無.
2078
				#備註:
2079
				#無.
2080
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2081
				unset($conf["search::findSpecifyStrFormat"]);
2082
 
2083
				#如果執行異常
2084
				if($findSpecifyStrFormat["status"]==="false"){
2085
 
2086
					#設置錯誤識別
2087
					$result["status"]="false";
2088
 
2089
					#設置錯誤訊息
2090
					$result["error"]=$findSpecifyStrFormat;
2091
 
2092
					#回傳結果
2093
					return $result;
2094
 
2095
					}#if end
2096
 
2097
				#如果存在";"
2098
				if($findSpecifyStrFormat["found"]==="true"){
2099
 
2100
					#取得無";"的內容
2101
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2102
 
2103
					#取得拆下來的含開頭";"內容
2104
					$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
2105
 
2106
					}#if end
2107
 
2108
				}#else end
2109
 
2110
			}#else end
2111
 
2112
		#檢查是否為 @ 開頭
2113
		#函式說明:
2114
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2115
		#回傳結果:
2116
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2117
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2118
		#$result["function"],當前執行的函式名稱.
2119
		#$result["argu"],所使用的參數.
2120
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2121
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2122
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2123
		#必填參數:
2124
		#$conf["input"],字串,要檢查的字串.
2125
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2126
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2127
		$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
2128
		#可省略參數:
2129
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2130
		#$conf["varEqual"]=array(null,"found");
2131
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2132
		#$conf["varCon"]=array("no_tail"=>" not");
2133
		#參考資料:
2134
		#無.
2135
		#備註:
2136
		#無.
2137
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2138
		unset($conf["search::findSpecifyStrFormat"]);
2139
 
2140
		#如果執行異常
2141
		if($findSpecifyStrFormat["status"]==="false"){
2142
 
2143
			#設置錯誤識別
2144
			$result["status"]="false";
2145
 
2146
			#設置錯誤訊息
2147
			$result["error"]=$findSpecifyStrFormat;
2148
 
2149
			#回傳結果
2150
			return $result;
2151
 
2152
			}#if end
2153
 
2154
		#如果有找到符合格式的內容
2155
		if($findSpecifyStrFormat["found"]==="true"){
2156
 
2157
			#設置 query 的數值
2158
			$info["query"]="@";
2159
 
2160
			#取得後面待處理的內容
2161
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
2162
 
2163
			#函式說明:
2164
			#將字串開頭的特定關鍵字移除.
2165
			#回傳結果:
2166
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2167
			#$result["error"],錯誤訊息陣列.
2168
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2169
			#$result["function"],當前執行的函數名稱.
2170
			#$result["argu"],使用的參數.
2171
			#$result["content"],處理好的的字串內容.
2172
			#$result["deleted"],被移除的內容.
2173
			#必填參數:
2174
			#$conf["stringIn"],字串,要處理的字串.
2175
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2176
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2177
			$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
2178
			#可省略參數:
2179
			#無.
2180
			#參考資料:
2181
			#無.
2182
			#備註:
2183
			#無.
2184
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2185
			unset($conf["stringProcess::delHeadStr"]);
2186
 
2187
			#如果執行異常
2188
			if($delHeadStr["status"]==="false"){
2189
 
2190
				#設置錯誤識別
2191
				$result["status"]="false";
2192
 
2193
				#設置錯誤訊息
2194
				$result["error"]=$delHeadStr;
2195
 
2196
				#回傳結果
2197
				return $result;
2198
 
2199
				}#if end
2200
 
2201
			#如果有移除開頭的字串
2202
			if($delHeadStr["founded"]==="true"){
2203
 
2204
				#取得處理後的結果 update time..IN..type...value;comment
2205
				$unFormatStr=$delHeadStr["content"];
2206
 
2207
				}#if end
2208
 
2209
			#debug
2210
			#var_dump(__LINE__,$delHeadStr);
2211
 
2212
			}#if end
2213
 
2214
		#反之
2215
		else{
2216
 
2217
			#執行到這邊,代表 query 為一非 @ 的字串
2218
			#函式說明:
2219
			#將指令字串解析成陣列,方便給予 external::callShell 使用
2220
			#回傳結果:
2221
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2222
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2223
			#$result["function"],當前執行的函式名稱.
2224
			#$result["content"],解析好的指令陣列.
2225
			#$result["cmd"],解析好的指令名稱.
2226
			#$result["argus"],解析好的參數陣列.
2227
			#$result["argu"],所使用的參數.
2228
			#必填參數
2229
			#$conf["cmdStr"],字串,要解析的指令字串
2230
			$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
2231
			#可省略參數:
2232
			#無.
2233
			#參考資料:
2234
			#無.
2235
			#備註:
2236
			#無.
2237
			$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
2238
			unset($conf["stringProcess::parseCmdString"]);
2239
 
2240
			#如果執行失敗
2241
			if($parseCmdString["status"]==="false"){
2242
 
2243
				#設置錯誤識別
2244
				$result["status"]="false";
2245
 
2246
				#設置錯誤訊息
2247
				$result["error"]=$parseCmdString;
2248
 
2249
				#debug
2250
				#$result["errorProcessLine"]=$line;
2251
 
2252
				#回傳結果
2253
				return $result;
2254
 
2255
				}#if end
2256
 
2257
			#取得 query 的內容
2258
			$info["query"]=$parseCmdString["content"][0];
2259
 
2260
			#剔除 query以及後面的" "跟\t
2261
			#函式說明:
2262
			#將字串開頭的特定關鍵字移除.
2263
			#回傳結果:
2264
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2265
			#$result["error"],錯誤訊息陣列.
2266
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2267
			#$result["function"],當前執行的函數名稱.
2268
			#$result["argu"],使用的參數.
2269
			#$result["content"],處理好的的字串內容.
2270
			#$result["deleted"],被移除的內容.
2271
			#必填參數:
2272
			#$conf["stringIn"],字串,要處理的字串.
2273
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2274
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2275
			$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
2276
			#可省略參數:
2277
			#無.
2278
			#參考資料:
2279
			#無.
2280
			#備註:
2281
			#無.
2282
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2283
			unset($conf["stringProcess::delHeadStr"]);
2284
 
2285
			#如果執行異常
2286
			if($delHeadStr["status"]==="false"){
2287
 
2288
				#設置錯誤識別
2289
				$result["status"]="false";
2290
 
2291
				#設置錯誤訊息
2292
				$result["error"]=$delHeadStr;
2293
 
2294
				#回傳結果
2295
				return $result;
2296
 
2297
				}#if end
2298
 
2299
			#取得update time..IN..type...value;comment
2300
			$unFormatStr=$delHeadStr["content"];
2301
 
2302
			}#else end
2303
 
2304
		#無窮迴圈
2305
		while(true){
2306
 
2307
			#解析 updateTime..IN..type...value...comment
2308
 
2309
			#判斷是否無 update time
2310
 
2311
			#函式說明:
2312
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2313
			#回傳結果:
2314
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2315
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2316
			#$result["function"],當前執行的函式名稱.
2317
			#$result["argu"],所使用的參數.
2318
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2319
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2320
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2321
			#必填參數:
2322
			#$conf["input"],字串,要檢查的字串.
2323
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2324
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2325
			$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
2326
			#可省略參數:
2327
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2328
			#$conf["varEqual"]=array(null,"found");
2329
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2330
			#$conf["varCon"]=array("no_tail"=>" not");
2331
			#參考資料:
2332
			#無.
2333
			#備註:
2334
			#無.
2335
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2336
			unset($conf["search::findSpecifyStrFormat"]);
2337
 
2338
			#如果執行異常
2339
			if($findSpecifyStrFormat["status"]==="false"){
2340
 
2341
				#設置錯誤識別
2342
				$result["status"]="false";
2343
 
2344
				#設置錯誤訊息
2345
				$result["error"]=$findSpecifyStrFormat;
2346
 
2347
				#回傳結果
2348
				return $result;
2349
 
2350
				}#if end
2351
 
2352
			#如果有找到符合格式的內容
2353
			if($findSpecifyStrFormat["found"]==="true"){
2354
 
2355
				#代表沒有 update time 欄位,因此儲存預設的TTL
2356
				$info["update"]=&$result["defaultTTL"];
2357
 
2358
				#取得剩下的 ...type...value;comment
2359
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
2360
 
2361
				#設置該行沒有指定 update time
2362
				$noUpdateTime="true";
2363
 
2364
				}#if end
2365
 
2366
			#反之
2367
			else{
2368
 
2369
				#設置該行有指定 update time
2370
				$noUpdateTime="false";
2371
 
2372
				#如果有指定 update time
2373
				if($noUpdateTime==="false"){
2374
 
2375
					#要來解析 update time
2376
					#函式說明:
2377
					#將字串進行解析,變成多個參數.
2378
					#回傳結果:
2379
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2380
					#$result["function"],當前執行的函式內容.
2381
					#$result["error"],錯誤訊息陣列.
2382
					#$result["content"],參數陣列.
2383
					#$result["count"],總共有幾個參數.
2384
					#必填參數:
2385
					#$conf["input"],字串,要解析成參數的字串.
2386
					$conf["stringProcess::parse"]["input"]=$unFormatStr;
2387
					#可省略參數:
2388
					#無.
2389
					#參考資料:
2390
					#無.
2391
					#備註:
2392
					#無.
2393
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
2394
					unset($conf["stringProcess::parse"]);
2395
 
2396
					#如果執行異常
2397
					if($parse["status"]==="false"){
2398
 
2399
						#設置錯誤識別
2400
						$result["status"]="false";
2401
 
2402
						#設置錯誤訊息
2403
						$result["error"]=$parse;
2404
 
2405
						#回傳結果
2406
						return $result;
2407
 
2408
						}#if end
2409
 
2410
					#取得更新時間
2411
					$info["update"]=$parse["content"][0];
2412
 
2413
					#取得 update time 後面的內容
2414
					#函式說明:
2415
					#將字串開頭的特定關鍵字移除.
2416
					#回傳結果:
2417
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2418
					#$result["error"],錯誤訊息陣列.
2419
					#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2420
					#$result["function"],當前執行的函數名稱.
2421
					#$result["argu"],使用的參數.
2422
					#$result["content"],處理好的的字串內容.
2423
					#$result["deleted"],被移除的內容.
2424
					#必填參數:
2425
					#$conf["stringIn"],字串,要處理的字串.
2426
					$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2427
					#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2428
					$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
2429
					#可省略參數:
2430
					#無.
2431
					#參考資料:
2432
					#無.
2433
					#備註:
2434
					#無.
2435
					$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2436
					unset($conf["stringProcess::delHeadStr"]);
2437
 
2438
					#如果執行異常
2439
					if($delHeadStr["status"]==="false"){
2440
 
2441
						#設置錯誤識別
2442
						$result["status"]="false";
2443
 
2444
						#設置錯誤訊息
2445
						$result["error"]=$delHeadStr;
2446
 
2447
						#回傳結果
2448
						return $result;
2449
 
2450
						}#if end
2451
 
2452
					#取得...IN...value;comment
2453
					$unFormatStr=$delHeadStr["content"];
2454
 
2455
					}#if end
2456
 
2457
				#取得 ...IN... 後面的內容
2458
				#函式說明:
2459
				#將字串開頭的特定關鍵字移除.
2460
				#回傳結果:
2461
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2462
				#$result["error"],錯誤訊息陣列.
2463
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2464
				#$result["function"],當前執行的函數名稱.
2465
				#$result["argu"],使用的參數.
2466
				#$result["content"],處理好的的字串內容.
2467
				#$result["deleted"],被移除的內容.
2468
				#必填參數:
2469
				#$conf["stringIn"],字串,要處理的字串.
2470
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2471
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2472
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
2473
				#可省略參數:
2474
				#無.
2475
				#參考資料:
2476
				#無.
2477
				#備註:
2478
				#無.
2479
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2480
				unset($conf["stringProcess::delHeadStr"]);
2481
 
2482
				#如果執行異常
2483
				if($delHeadStr["status"]==="false"){
2484
 
2485
					#設置錯誤識別
2486
					$result["status"]="false";
2487
 
2488
					#設置錯誤訊息
2489
					$result["error"]=$delHeadStr;
2490
 
2491
					#回傳結果
2492
					return $result;
2493
 
2494
					}#if end
2495
 
2496
				#取得IN...value;comment
2497
				$unFormatStr=$delHeadStr["content"];
2498
 
2499
				}#else end
2500
 
2501
			#解析 type...value;comment
2502
			#函式說明:
2503
			#將字串進行解析,變成多個參數.
2504
			#回傳結果:
2505
			#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2506
			#$result["function"],當前執行的函式內容.
2507
			#$result["error"],錯誤訊息陣列.
2508
			#$result["content"],參數陣列.
2509
			#$result["count"],總共有幾個參數.
2510
			#必填參數:
2511
			#$conf["input"],字串,要解析成參數的字串.
2512
			$conf["stringProcess::parse"]["input"]=$unFormatStr;
2513
			#可省略參數:
2514
			#無.
2515
			#參考資料:
2516
			#無.
2517
			#備註:
2518
			#無.
2519
			$parse=stringProcess::parse($conf["stringProcess::parse"]);
2520
			unset($conf["stringProcess::parse"]);
2521
 
2522
			#如果執行異常
2523
			if($parse["status"]==="false"){
2524
 
2525
				#設置錯誤識別
2526
				$result["status"]="false";
2527
 
2528
				#設置錯誤訊息
2529
				$result["error"]=$parse;
2530
 
2531
				#回傳結果
2532
				return $result;
2533
 
2534
				}#if end
2535
 
2536
			#取得 type
2537
			$info["type"]=$parse["content"][0];
2538
 
2539
			#取得 type...後面的value;comment內容
2540
			#函式說明:
2541
			#將字串開頭的特定關鍵字移除.
2542
			#回傳結果:
2543
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2544
			#$result["error"],錯誤訊息陣列.
2545
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2546
			#$result["function"],當前執行的函數名稱.
2547
			#$result["argu"],使用的參數.
2548
			#$result["content"],處理好的的字串內容.
2549
			#$result["deleted"],被移除的內容.
2550
			#必填參數:
2551
			#$conf["stringIn"],字串,要處理的字串.
2552
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2553
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2554
			$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
2555
			#可省略參數:
2556
			#無.
2557
			#參考資料:
2558
			#無.
2559
			#備註:
2560
			#無.
2561
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2562
			unset($conf["stringProcess::delHeadStr"]);
2563
 
2564
			#如果執行異常
2565
			if($delHeadStr["status"]==="false"){
2566
 
2567
				#設置錯誤識別
2568
				$result["status"]="false";
2569
 
2570
				#設置錯誤訊息
2571
				$result["error"]=$delHeadStr;
2572
 
2573
				#回傳結果
2574
				return $result;
2575
 
2576
				}#if end
2577
 
2578
			#取得 value;comment
2579
			$unFormatStr=$delHeadStr["content"];
2580
 
2581
			#如果有要合併回去的內容
2582
			if(isset($unFormatStr2add)){
2583
 
2584
				#合併回去內容
2585
				$unFormatStr=$unFormatStr.$unFormatStr2add;
2586
 
2587
				#移除用不到的變數
2588
				unset($unFormatStr2add);
2589
 
2590
				}#if end
2591
 
2592
			#如果type不為 CNAME 跟 TXT 跟 SOA
404 liveuser 2593
			if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" && $info["type"]!=="CAA"){
291 liveuser 2594
 
2595
				#儲存value
2596
				$info["value"]=$unFormatStr;
2597
 
2598
				#判斷是否有 ";" 存在
2599
				#函式說明:
2600
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2601
				#回傳結果:
2602
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2603
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2604
				#$result["function"],當前執行的函式名稱.
2605
				#$result["argu"],所使用的參數.
2606
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2607
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2608
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2609
				#必填參數:
2610
				#$conf["input"],字串,要檢查的字串.
2611
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2612
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2613
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
2614
				#可省略參數:
2615
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2616
				#$conf["varEqual"]=array(null,"found");
2617
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2618
				#$conf["varCon"]=array("no_tail"=>" not");
2619
				#參考資料:
2620
				#無.
2621
				#備註:
2622
				#無.
2623
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2624
				unset($conf["search::findSpecifyStrFormat"]);
2625
 
2626
				#如果執行異常
2627
				if($findSpecifyStrFormat["status"]==="false"){
2628
 
2629
					#設置錯誤識別
2630
					$result["status"]="false";
2631
 
2632
					#設置錯誤訊息
2633
					$result["error"]=$findSpecifyStrFormat;
2634
 
2635
					#回傳結果
2636
					return $result;
2637
 
2638
					}#if end
2639
 
2640
				#如果有 ";"
2641
				if($findSpecifyStrFormat["found"]==="true"){
2642
 
2643
					#儲存value
2644
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
2645
 
2646
					#儲存comment
2647
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
2648
 
2649
					}#if end
2650
 
2651
				#儲存 RR 的記錄
2652
				$result["content"]=$info;
2653
 
2654
				#設置執行正常
2655
				$result["status"]="true";
2656
 
2657
				#回傳結果
2658
				return $result;
2659
 
2660
				}#if end
2661
 
404 liveuser 2662
			#執行到這邊,代表type為CNAME或TXT或SOA或CAA
291 liveuser 2663
 
2664
			#如果 type 是 SOA
2665
			if($info["type"]==="SOA"){
2666
 
2667
				#如果要debug
2668
				if($conf["debug"]==="true"){
2669
 
2670
					#函式說明:
2671
					#撰寫log
2672
					#回傳結果:
2673
					#$result["status"],狀態,"true"或"false".
2674
					#$result["error"],錯誤訊息陣列.
2675
					#$result["function"],當前函式的名稱.
2676
					#$result["argu"],使用的參數.
2677
					#$result["content"],要寫入log的內容字串.
2678
					#必填參數:
2679
					#$conf["path"],字串,log檔案的路徑與名稱.
2680
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2681
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2682
					$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
2683
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2684
					$conf["logs::record"]["fileArgu"]=__FILE__;
2685
					#可省略參數:
2686
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2687
					#$conf["rewrite"]="false";
2688
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2689
					#$conf["returnOnly"]="true";
2690
					#參考資料:
2691
					#無.
2692
					#備註:
2693
					#無.
2694
					$record=logs::record($conf["logs::record"]);
2695
					unset($conf["logs::record"]);
2696
 
2697
					}#if end
2698
 
2699
				#SOA 範例
2700
				#@	1200	IN	SOA	dns.qbpwcf.org. liveuser.qbpwcf.org. 2026012205 10800 1800 1728000 1200 ;domain name server, admin mail, serial, refresh time, expire, Negative Caching, https://bind9.readthedocs.io/en/latest/chapter3.html#term-SOA-minimum
2701
 
2702
				#再度嘗試分割
2703
				#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
2704
 
2705
				#函式說明:
2706
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2707
				#回傳結果:
2708
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2709
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2710
				#$result["function"],當前執行的函式名稱.
2711
				#$result["argu"],所使用的參數.
2712
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2713
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2714
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2715
				#必填參數:
2716
				#$conf["input"],字串,要檢查的字串.
2717
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2718
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2719
				$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
2720
				#可省略參數:
2721
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2722
				#$conf["varEqual"]=array(null,"found");
2723
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2724
				#$conf["varCon"]=array("no_tail"=>" not");
2725
				#參考資料:
2726
				#無.
2727
				#備註:
2728
				#無.
2729
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2730
				unset($conf["search::findSpecifyStrFormat"]);
2731
 
2732
				#如果執行異常
2733
				if($findSpecifyStrFormat["status"]==="false"){
2734
 
2735
					#設置錯誤識別
2736
					$result["status"]="false";
2737
 
2738
					#設置錯誤訊息
2739
					$result["error"]=$findSpecifyStrFormat;
2740
 
2741
					#回傳結果
2742
					return $result;
2743
 
2744
					}#if end
2745
 
2746
				#如果存在"("
2747
				if($findSpecifyStrFormat["found"]==="true"){
2748
 
2749
					#取得無"("的內容
2750
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2751
 
2752
					#取得拆下來的含開頭"("內容
2753
					$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
2754
 
2755
					}#if end
2756
 
2757
				#反之
2758
				else{
2759
 
2760
					#函式說明:
2761
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2762
					#回傳結果:
2763
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2764
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2765
					#$result["function"],當前執行的函式名稱.
2766
					#$result["argu"],所使用的參數.
2767
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2768
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2769
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2770
					#必填參數:
2771
					#$conf["input"],字串,要檢查的字串.
2772
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2773
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2774
					$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
2775
					#可省略參數:
2776
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2777
					#$conf["varEqual"]=array(null,"found");
2778
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2779
					#$conf["varCon"]=array("no_tail"=>" not");
2780
					#參考資料:
2781
					#無.
2782
					#備註:
2783
					#無.
2784
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2785
					unset($conf["search::findSpecifyStrFormat"]);
2786
 
2787
					#如果執行異常
2788
					if($findSpecifyStrFormat["status"]==="false"){
2789
 
2790
						#設置錯誤識別
2791
						$result["status"]="false";
2792
 
2793
						#設置錯誤訊息
2794
						$result["error"]=$findSpecifyStrFormat;
2795
 
2796
						#回傳結果
2797
						return $result;
2798
 
2799
						}#if end
2800
 
2801
					#如果存在"
2802
					if($findSpecifyStrFormat["found"]==="true"){
2803
 
2804
						#取得無"的內容
2805
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2806
 
2807
						#取得拆下來的含開頭"內容
2808
						$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
2809
 
2810
						}#if end
2811
 
2812
					#反之
2813
					else{
2814
 
2815
						#函式說明:
2816
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2817
						#回傳結果:
2818
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2819
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
2820
						#$result["function"],當前執行的函式名稱.
2821
						#$result["argu"],所使用的參數.
2822
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2823
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2824
						#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2825
						#必填參數:
2826
						#$conf["input"],字串,要檢查的字串.
2827
						$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2828
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2829
						$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
2830
						#可省略參數:
2831
						#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2832
						#$conf["varEqual"]=array(null,"found");
2833
						#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2834
						#$conf["varCon"]=array("no_tail"=>" not");
2835
						#參考資料:
2836
						#無.
2837
						#備註:
2838
						#無.
2839
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2840
						unset($conf["search::findSpecifyStrFormat"]);
2841
 
2842
						#如果執行異常
2843
						if($findSpecifyStrFormat["status"]==="false"){
2844
 
2845
							#設置錯誤識別
2846
							$result["status"]="false";
2847
 
2848
							#設置錯誤訊息
2849
							$result["error"]=$findSpecifyStrFormat;
2850
 
2851
							#回傳結果
2852
							return $result;
2853
 
2854
							}#if end
2855
 
2856
						#如果存在";"
2857
						if($findSpecifyStrFormat["found"]==="true"){
2858
 
2859
							#取得無";"的內容
2860
							$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2861
 
2862
							#取得拆下來的含開頭";"內容
2863
							$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
2864
 
2865
							}#if end
2866
 
2867
						}#else end
2868
 
2869
					}#else end
2870
 
2871
				#取得 serial number
2872
				#函式說明:
2873
				#將字串進行解析,變成多個參數.
2874
				#回傳結果:
2875
				#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2876
				#$result["function"],當前執行的函式內容.
2877
				#$result["error"],錯誤訊息陣列.
2878
				#$result["content"],參數陣列.
2879
				#$result["count"],總共有幾個參數.
2880
				#必填參數:
2881
				#$conf["input"],字串,要解析成參數的字串.
2882
				$conf["stringProcess::parse"]["input"]=$unFormatStr;
2883
				#可省略參數:
2884
				#無.
2885
				#參考資料:
2886
				#無.
2887
				#備註:
2888
				#無.
2889
				$parse=stringProcess::parse($conf["stringProcess::parse"]);
2890
				unset($conf["stringProcess::parse"]);
2891
 
2892
				#如果執行異常
2893
				if($parse["status"]==="false"){
2894
 
2895
					#設置錯誤識別
2896
					$result["status"]="false";
2897
 
2898
					#設置錯誤訊息
2899
					$result["error"]=$parse;
2900
 
2901
					#回傳結果
2902
					return $result;
2903
 
2904
					}#if end
2905
 
2906
				#取得serial number
2907
				$serialNo=$parse["content"][2];
2908
 
2909
				#serialNo+1
2910
				$serialNo++;
2911
 
2912
				#回存
2913
				$parse["content"][2]=(string)$serialNo;
2914
 
2915
				#函式說明:
2916
				#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
2917
				#回傳的結果:
2918
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2919
				#$result["function"],當前執行的function名稱
2920
				#$result["error"],錯誤訊息陣列.
2921
				#$result["content"],處理好的字串.
2922
				#$result["argu"],使用的參數.
2923
				#必填參數:
2924
				#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
2925
				$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
2926
				#可省略參數:
2927
				#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
2928
				$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
2929
				#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
2930
				$conf["arrays::arrayToString"]["skipEnd"]="true";
2931
				#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
2932
				#$conf["spiltSymbolAtStart"]="";
2933
				#參考資料:
2934
				#無.
2935
				#備註:
2936
				#無.
2937
				$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
2938
				unset($conf["arrays::arrayToString"]);
2939
 
2940
				#如果執行異常
2941
				if($arrayToString["status"]==="false"){
2942
 
2943
					#設置錯誤識別
2944
					$result["status"]="false";
2945
 
2946
					#設置錯誤訊息
2947
					$result["error"]=$arrayToString;
2948
 
2949
					#回傳結果
2950
					return $result;
2951
 
2952
					}#if end
2953
 
2954
				#取得更新 serial number 後的 SOA value string
2955
				$unFormatStr=$arrayToString["content"];
2956
 
2957
				#如果有要合併回去的內容
2958
				if(isset($unFormatStr2add)){
2959
 
2960
					#合併回去內容
2961
					$unFormatStr=$unFormatStr.$unFormatStr2add;
2962
 
2963
					#移除用不到的變數
2964
					unset($unFormatStr2add);
2965
 
2966
					}#if end
2967
 
2968
				#假設剩下的沒有註解都是 value
2969
				$info["value"]=$unFormatStr;
2970
 
2971
				#函式說明:
2972
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2973
				#回傳結果:
2974
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2975
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2976
				#$result["function"],當前執行的函式名稱.
2977
				#$result["argu"],所使用的參數.
2978
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2979
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2980
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2981
				#必填參數:
2982
				#$conf["input"],字串,要檢查的字串.
2983
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2984
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2985
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
2986
				#可省略參數:
2987
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2988
				#$conf["varEqual"]=array(null,"found");
2989
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2990
				#$conf["varCon"]=array("no_tail"=>" not");
2991
				#參考資料:
2992
				#無.
2993
				#備註:
2994
				#無.
2995
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2996
				unset($conf["search::findSpecifyStrFormat"]);
2997
 
2998
				#如果執行異常
2999
				if($findSpecifyStrFormat["status"]==="false"){
3000
 
3001
					#設置錯誤識別
3002
					$result["status"]="false";
3003
 
3004
					#設置錯誤訊息
3005
					$result["error"]=$findSpecifyStrFormat;
3006
 
3007
					#回傳結果
3008
					return $result;
3009
 
3010
					}#if end
3011
 
3012
				#如果有符合格式
3013
				if($findSpecifyStrFormat["found"]==="true"){
3014
 
3015
					#儲存 value
3016
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3017
 
3018
					#儲存 comment
3019
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3020
 
3021
					}#if end
3022
 
3023
				#儲存 RR 的記錄
3024
				$result["content"]=$info;
3025
 
3026
				#設置執行正常
3027
				$result["status"]="true";
3028
 
3029
				#回傳結果
3030
				return $result;
3031
 
3032
				}#if end
3033
 
3034
			#執行到這邊代表不是 SOA
3035
 
404 liveuser 3036
			#如果是 CAA
3037
			if($info["type"]!=="CAA"){
3038
 
3039
				#判斷內容是否為合法的 CAA value
3040
				#0 issue ";";comment
3041
				#0 issue "domain.name";comment
3042
				#函式說明:
3043
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3044
				#回傳結果:
3045
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3046
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3047
				#$result["function"],當前執行的函式名稱.
3048
				#$result["argu"],所使用的參數.
3049
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3050
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3051
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3052
				#必填參數:
3053
				#$conf["input"],字串,要檢查的字串.
3054
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3055
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3056
				$conf["search::findSpecifyStrFormat"]["format"]="0 issue \"\${domain}\";\${comment}";
3057
				#可省略參數:
3058
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3059
				#$conf["varEqual"]=array(null,"found");
3060
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3061
				#$conf["varCon"]=array("no_tail"=>" not");
3062
				#參考資料:
3063
				#無.
3064
				#備註:
3065
				#無.
3066
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3067
				unset($conf["search::findSpecifyStrFormat"]);
3068
 
3069
				#如果執行異常
3070
				if($findSpecifyStrFormat["status"]==="false"){
3071
 
3072
					#設置錯誤識別
3073
					$result["status"]="false";
3074
 
3075
					#設置錯誤訊息
3076
					$result["error"]=$findSpecifyStrFormat;
3077
 
3078
					#回傳結果
3079
					return $result;
3080
 
3081
					}#if end
3082
 
3083
				#如果有 有符合 "0 issue \"\${domain}\";\${comment}" 的格式
3084
				if($findSpecifyStrFormat["found"]==="true"){
3085
 
3086
					#儲存value
3087
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3088
 
3089
					#儲存comment
3090
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3091
 
3092
					#儲存 RR 的記錄
3093
					$result["content"]=$info;
3094
 
3095
					#設置執行正常
3096
					$result["status"]="true";
3097
 
3098
					#回傳結果
3099
					return $result;
3100
 
3101
					}#if end
3102
 
3103
				#判斷內容是否為合法的 CAA value
3104
				#0 issue ";"
3105
				#0 issue "domain.name"
3106
				#函式說明:
3107
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3108
				#回傳結果:
3109
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3110
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3111
				#$result["function"],當前執行的函式名稱.
3112
				#$result["argu"],所使用的參數.
3113
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3114
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3115
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3116
				#必填參數:
3117
				#$conf["input"],字串,要檢查的字串.
3118
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3119
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3120
				$conf["search::findSpecifyStrFormat"]["format"]="0 issue \"\${domain}\"";
3121
				#可省略參數:
3122
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3123
				#$conf["varEqual"]=array(null,"found");
3124
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3125
				#$conf["varCon"]=array("no_tail"=>" not");
3126
				#參考資料:
3127
				#無.
3128
				#備註:
3129
				#無.
3130
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3131
				unset($conf["search::findSpecifyStrFormat"]);
3132
 
3133
				#如果執行異常
3134
				if($findSpecifyStrFormat["status"]==="false"){
3135
 
3136
					#設置錯誤識別
3137
					$result["status"]="false";
3138
 
3139
					#設置錯誤訊息
3140
					$result["error"]=$findSpecifyStrFormat;
3141
 
3142
					#回傳結果
3143
					return $result;
3144
 
3145
					}#if end
3146
 
3147
				#如果有 有符合 "0 issue \"\${domain}\"" 的格式
3148
				if($findSpecifyStrFormat["found"]==="true"){
3149
 
3150
					#儲存value
3151
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3152
 
3153
					#儲存 RR 的記錄
3154
					$result["content"]=$info;
3155
 
3156
					#設置執行正常
3157
					$result["status"]="true";
3158
 
3159
					#回傳結果
3160
					return $result;
3161
 
3162
					}#if end
3163
 
3164
				}#if end
3165
 
3166
			#執行到這邊代表不是 CAA
3167
 
291 liveuser 3168
			#尋找是否有(...)...的內容存在
3169
			#函式說明:
3170
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3171
			#回傳結果:
3172
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3173
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3174
			#$result["function"],當前執行的函式名稱.
3175
			#$result["argu"],所使用的參數.
3176
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3177
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3178
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3179
			#必填參數:
3180
			#$conf["input"],字串,要檢查的字串.
3181
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3182
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3183
			$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
3184
			#可省略參數:
3185
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3186
			#$conf["varEqual"]=array(null,"found");
3187
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3188
			#$conf["varCon"]=array("no_tail"=>" not");
3189
			#參考資料:
3190
			#無.
3191
			#備註:
3192
			#無.
3193
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3194
			unset($conf["search::findSpecifyStrFormat"]);
3195
 
3196
			#如果執行異常
3197
			if($findSpecifyStrFormat["status"]==="false"){
3198
 
3199
				#設置錯誤識別
3200
				$result["status"]="false";
3201
 
3202
				#設置錯誤訊息
3203
				$result["error"]=$findSpecifyStrFormat;
3204
 
3205
				#回傳結果
3206
				return $result;
3207
 
3208
				}#if end
3209
 
3210
			#如果有 有符合 ($value);${comment} 的格式
3211
			if($findSpecifyStrFormat["found"]==="true"){
3212
 
3213
				#儲存value
3214
				$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
3215
 
3216
				#儲存comment
3217
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3218
 
3219
				#儲存 RR 的記錄
3220
				$result["content"]=$info;
3221
 
3222
				#設置執行正常
3223
				$result["status"]="true";
3224
 
3225
				#回傳結果
3226
				return $result;
3227
 
3228
				}#if end
3229
 
3230
			#執行到這邊代表沒有 (...)... 的內容存在
3231
 
3232
			#尋找是否有 (...) 的內容存在
3233
			#函式說明:
3234
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3235
			#回傳結果:
3236
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3237
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3238
			#$result["function"],當前執行的函式名稱.
3239
			#$result["argu"],所使用的參數.
3240
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3241
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3242
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3243
			#必填參數:
3244
			#$conf["input"],字串,要檢查的字串.
3245
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3246
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3247
			$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
3248
			#可省略參數:
3249
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3250
			#$conf["varEqual"]=array(null,"found");
3251
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3252
			#$conf["varCon"]=array("no_tail"=>" not");
3253
			#參考資料:
3254
			#無.
3255
			#備註:
3256
			#無.
3257
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3258
			unset($conf["search::findSpecifyStrFormat"]);
3259
 
3260
			#如果執行異常
3261
			if($findSpecifyStrFormat["status"]==="false"){
3262
 
3263
				#設置錯誤識別
3264
				$result["status"]="false";
3265
 
3266
				#設置錯誤訊息
3267
				$result["error"]=$findSpecifyStrFormat;
3268
 
3269
				#回傳結果
3270
				return $result;
3271
 
3272
				}#if end
3273
 
3274
			#如果有 有符合 ($value);${comment} 的格式
3275
			if($findSpecifyStrFormat["found"]==="true"){
3276
 
3277
				#儲存value
3278
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3279
 
3280
				#儲存 RR 的記錄
3281
				$result["content"]=$info;
3282
 
3283
				#設置執行正常
3284
				$result["status"]="true";
3285
 
3286
				#回傳結果
3287
				return $result;
3288
 
3289
				}#if end
3290
 
3291
			#執行到這邊代表沒有 (...) 的內容存在
3292
 
3293
			#尋找有無 "...";... 的內容存在
3294
			#函式說明:
3295
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3296
			#回傳結果:
3297
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3298
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3299
			#$result["function"],當前執行的函式名稱.
3300
			#$result["argu"],所使用的參數.
3301
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3302
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3303
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3304
			#必填參數:
3305
			#$conf["input"],字串,要檢查的字串.
3306
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3307
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3308
			$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
3309
			#可省略參數:
3310
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3311
			#$conf["varEqual"]=array(null,"found");
3312
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3313
			#$conf["varCon"]=array("no_tail"=>" not");
3314
			#參考資料:
3315
			#無.
3316
			#備註:
3317
			#無.
3318
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3319
			unset($conf["search::findSpecifyStrFormat"]);
3320
 
3321
			#如果執行異常
3322
			if($findSpecifyStrFormat["status"]==="false"){
3323
 
3324
				#設置錯誤識別
3325
				$result["status"]="false";
3326
 
3327
				#設置錯誤訊息
3328
				$result["error"]=$findSpecifyStrFormat;
3329
 
3330
				#回傳結果
3331
				return $result;
3332
 
3333
				}#if end
3334
 
3335
			#如果有 有符合 "$value";${comment} 的格式
3336
			if($findSpecifyStrFormat["found"]==="true"){
3337
 
3338
				#儲存value
3339
				$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
3340
 
3341
				#儲存comment
3342
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3343
 
3344
				#儲存 RR 的記錄
3345
				$result["content"]=$info;
3346
 
3347
				#設置執行正常
3348
				$result["status"]="true";
3349
 
3350
				#回傳結果
3351
				return $result;
3352
 
3353
				}#if end
3354
 
3355
			#執行到這邊代表沒有 "$value";${comment} 的格式
3356
 
3357
			#尋找有無 "..." 的內容存在
3358
			#函式說明:
3359
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3360
			#回傳結果:
3361
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3362
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3363
			#$result["function"],當前執行的函式名稱.
3364
			#$result["argu"],所使用的參數.
3365
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3366
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3367
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3368
			#必填參數:
3369
			#$conf["input"],字串,要檢查的字串.
3370
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3371
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3372
			$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
3373
			#可省略參數:
3374
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3375
			#$conf["varEqual"]=array(null,"found");
3376
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3377
			#$conf["varCon"]=array("no_tail"=>" not");
3378
			#參考資料:
3379
			#無.
3380
			#備註:
3381
			#無.
3382
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3383
			unset($conf["search::findSpecifyStrFormat"]);
3384
 
3385
			#如果執行異常
3386
			if($findSpecifyStrFormat["status"]==="false"){
3387
 
3388
				#設置錯誤識別
3389
				$result["status"]="false";
3390
 
3391
				#設置錯誤訊息
3392
				$result["error"]=$findSpecifyStrFormat;
3393
 
3394
				#回傳結果
3395
				return $result;
3396
 
3397
				}#if end
3398
 
3399
			#如果有 有符合 "$value" 的格式
3400
			if($findSpecifyStrFormat["found"]==="true"){
3401
 
3402
				#儲存value
3403
				$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
3404
 
3405
				#儲存 RR 的記錄
3406
				$result["content"]=$info;
3407
 
3408
				#設置執行正常
3409
				$result["status"]="true";
3410
 
3411
				#回傳結果
3412
				return $result;
3413
 
3414
				}#if end
3415
 
3416
			#執行到這邊代表沒有 "$value" 格式的內容
3417
 
3418
			#檢查是否有 $value;$comment 格式的內容
3419
			#函式說明:
3420
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3421
			#回傳結果:
3422
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3423
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3424
			#$result["function"],當前執行的函式名稱.
3425
			#$result["argu"],所使用的參數.
3426
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3427
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3428
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3429
			#必填參數:
3430
			#$conf["input"],字串,要檢查的字串.
3431
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3432
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3433
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3434
			#可省略參數:
3435
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3436
			#$conf["varEqual"]=array(null,"found");
3437
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3438
			#$conf["varCon"]=array("no_tail"=>" not");
3439
			#參考資料:
3440
			#無.
3441
			#備註:
3442
			#無.
3443
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3444
			unset($conf["search::findSpecifyStrFormat"]);
3445
 
3446
			#如果執行異常
3447
			if($findSpecifyStrFormat["status"]==="false"){
3448
 
3449
				#設置錯誤識別
3450
				$result["status"]="false";
3451
 
3452
				#設置錯誤訊息
3453
				$result["error"]=$findSpecifyStrFormat;
3454
 
3455
				#回傳結果
3456
				return $result;
3457
 
3458
				}#if end
3459
 
3460
			#如果有 有符合 "$value" 的格式
3461
			if($findSpecifyStrFormat["found"]==="true"){
3462
 
3463
				#儲存value
3464
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3465
 
3466
				#儲存comment
3467
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3468
 
3469
				#儲存 RR 的記錄
3470
				$result["content"]=$info;
3471
 
3472
				#設置執行正常
3473
				$result["status"]="true";
3474
 
3475
				#回傳結果
3476
				return $result;
3477
 
3478
				}#if end
3479
 
3480
			#執行到這邊代表沒有 ${value};${comment} 格式的內容
3481
 
3482
			#亦即剩下的內容都是 value
3483
 
3484
			#儲存value
3485
			$info["value"]=$unFormatStr;
3486
 
3487
			#儲存 RR 的記錄
3488
			$result["content"]=$info;
3489
 
3490
			#設置執行正常
3491
			$result["status"]="true";
3492
 
3493
			#回傳結果
3494
			return $result;
3495
 
3496
			}#while end
3497
 
3498
		}#function parseRRline end
3499
 
3500
	/*
3501
	#函式說明:
249 liveuser 3502
	#新增DNS記錄到檔案裡面.
3503
	#回傳結果:
3504
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3505
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
3506
	#$result["function"],當前執行的函式名稱.
3507
	#$result["argu"],所使用的參數.
3508
	#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
255 liveuser 3509
	#$result["domain"],字串,RR所屬domain.
3510
	#$result["defaultTTL"],字串,預設的RR更新時間.
249 liveuser 3511
	#$result["comment"],字串陣列,逐行的註解.
3512
	#必填參數:
255 liveuser 3513
	#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型(支援的有"A","TXT","CNAME","SOA","$TTL","$ORIGIN")、答案、註解.
249 liveuser 3514
	$conf["add"]=array();
3515
	#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
3516
	$conf["dnsRecordFile"]="";
3517
	#可省略參數:
3518
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
3519
	#$conf["writeNow"]="false";
253 liveuser 3520
	#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
3521
	#$conf["debug"]="false";
293 liveuser 3522
	#$conf["multiThreads"],字串,是否啟動多執行序加快執行速度,預設為"false"代表不要;反之為"true"代表要.
3523
	#$conf["multiThreads"]="false";
249 liveuser 3524
	#參考資料:
3525
	#無.
3526
	#備註:
3527
	#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
291 liveuser 3528
	#本套件是透過sshfs掛載來存取RR(dns記錄檔案),其檔案建議的擁有者權限為 root:qbpwcf,權限代碼為 774.
249 liveuser 3529
	#php-pear上的Net_DNS2也可以解析RR.
293 liveuser 3530
	#參數 multiThreads 目前有 bug.
249 liveuser 3531
	*/
3532
	public static function updateDnsRecordFile(&$conf){
3533
 
3534
		#初始化要回傳的結果
3535
		$result=array();
3536
 
3537
		#設置當其函數名稱
3538
		$result["function"]=__FUNCTION__;
3539
 
3540
		#如果 $conf 不為陣列
3541
		if(gettype($conf)!="array"){
3542
 
3543
			#設置執行失敗
3544
			$result["status"]="false";
3545
 
3546
			#設置執行錯誤訊息
3547
			$result["error"][]="\$conf變數須為陣列形態";
3548
 
3549
			#如果傳入的參數為 null
3550
			if($conf==null){
3551
 
3552
				#設置執行錯誤訊息
3553
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3554
 
3555
				}#if end
3556
 
3557
			#回傳結果
3558
			return $result;
3559
 
3560
			}#if end
3561
 
3562
		#取得參數
3563
		$result["argu"]=$conf;
3564
 
3565
		#檢查參數
3566
		#函式說明:
3567
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3568
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3569
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3570
		#$result["function"],當前執行的函式名稱.
3571
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3572
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3573
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3574
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
3575
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
3576
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3577
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3578
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3579
		#必填寫的參數:
3580
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3581
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3582
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3583
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("add","dnsRecordFile");
3584
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3585
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
3586
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3587
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3588
		#可以省略的參數:
3589
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3590
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3591
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
3592
		#$conf["skipableVariableCanNotBeEmpty"]=array();
3593
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 3594
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThreads");
249 liveuser 3595
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
291 liveuser 3596
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
249 liveuser 3597
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
291 liveuser 3598
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
249 liveuser 3599
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3600
		#$conf["arrayCountEqualCheck"][]=array();
3601
		#參考資料來源:
3602
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3603
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3604
		unset($conf["variableCheck::checkArguments"]);
3605
 
3606
		#如果檢查失敗
3607
		if($checkArguments["status"]==="false"){
3608
 
3609
			#設置錯誤識別
3610
			$result["status"]="false";
3611
 
3612
			#設置錯誤訊息
3613
			$result["error"]=$checkArguments;
3614
 
3615
			#回傳結果
3616
			return $result;
3617
 
3618
			}#if end
3619
 
3620
		#如果檢查不通過
3621
		if($checkArguments["passed"]==="false"){
3622
 
3623
			#設置錯誤識別
3624
			$result["status"]="false";
3625
 
3626
			#設置錯誤訊息
3627
			$result["error"]=$checkArguments;
3628
 
3629
			#回傳結果
3630
			return $result;
3631
 
3632
			}#if end
3633
 
3634
		#初始化要回傳的content
3635
		$result["content"]=array();
3636
 
3637
		#初始化儲存逐行的註解.
3638
		$result["comment"]=array();
3639
 
3640
		#預設的zone file domain為空
3641
		$result["domain"]="";
3642
 
3643
		#預設的 update 時間
3644
		$result["defaultTTL"]=3600;
3645
 
3646
		#取得 dns 記錄檔案的內容
3647
		#函式說明:
3648
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
3649
		#回傳的變數說明:
3650
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
3651
		#$result["error"],錯誤訊息提示.
3652
		#$result["warning"],警告訊息.
3653
		#$result["function"],當前執行的函數名稱.
3654
		#$result["fileContent"],爲檔案的內容陣列.
3655
		#$result["lineCount"],爲檔案內容總共的行數.
3656
		#$result["fullContent"],為檔案的完整內容.
3657
		#$result["base64dataOnly"],檔案的base64data.
3658
		#$result["base64data"],為在網頁上給予src參數的數值.
3659
		#$result["mimeType"],為檔案的mime type.
3660
		#必填參數:
3661
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
3662
		$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$conf["dnsRecordFile"];
3663
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3664
		$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
3665
		#可省略參數:
3666
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
3667
		$conf["fileAccesss::getFileContent"]["web"]="false";
3668
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
3669
		#$conf["createIfnotExist"]="false";
3670
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
3671
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
3672
		#參考資料:
3673
		#file(),取得檔案內容的行數.
3674
		#file=>http:#php.net/manual/en/function.file.php
3675
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
3676
		#filesize=>http://php.net/manual/en/function.filesize.php
3677
		#參考資料:
3678
		#無.
3679
		#備註:
3680
		#無.
3681
		$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
3682
		unset($conf["fileAccesss::getFileContent"]);
3683
 
3684
		#如果檢查失敗
3685
		if($getFileContent["status"]==="false"){
3686
 
3687
			#設置錯誤識別
3688
			$result["status"]="false";
3689
 
3690
			#設置錯誤訊息
3691
			$result["error"]=$getFileContent;
3692
 
3693
			#回傳結果
3694
			return $result;
3695
 
3696
			}#if end
3697
 
3698
		#取得每行內容
3699
		$lines=$getFileContent["fileContent"];
3700
 
3701
		/*
3702
		範例每行內容:
3703
		$ORIGIN server.domain.	;base domain-name,in this Resource Records (RR) file,"@" equal to base domain-name.
3704
		$TTL 86400	;default TTL for zone
3705
		@	1200	IN	SOA	dns.server.domain. admin.server.domain. 2026012205 10800 1800 1728000 1200 ;domain name server, admin mail, serial, refresh time, expire, Negative Caching, https://bind9.readthedocs.io/en/latest/chapter3.html#term-SOA-minimum
3706
		@	3600	IN	TXT	"v=spf1 a mx ~all"
3707
		@	86400	IN	MX	1 mail.server.domain.
3708
		@	86400	IN	A	1.1.1.1
404 liveuser 3709
		@		IN	CAA	0 issue ";"
249 liveuser 3710
		mail.server.domain.	IN	1.1.1.1
3711
		10-42-0-1	IN	A	10.42.0.1
3712
		101-free        IN      A	101.101.101.101
3713
		127-0-0-1	IN	A	127.0.0.1
3714
		_dmarc	IN	TXT	"v=DMARC1;p=reject;sp=reject;pct=100;adkim=r;aspf=r;fo=1;ri=86400;rua=mailto:admin@server.domain"
3715
		default._domainkey	IN	TXT	( "v=DKIM1; k=rsa;" "p=MIGfMA0GCSqG/SIb3DQEBAQQAB" )  ; ----- DKIM key default for qbpwcf.org
3716
		...
3717
		*/
3718
 
3719
		#針對每行內容
3720
		foreach($lines as $lineNo => $line){
3721
 
291 liveuser 3722
			#如果要啟用多執行序
293 liveuser 3723
			if($conf["multiThreads"]==="true"){
291 liveuser 3724
 
293 liveuser 3725
				#如果要debug
3726
				if($conf["debug"]==="true"){
291 liveuser 3727
 
293 liveuser 3728
					#函式說明:
3729
					#撰寫log
3730
					#回傳結果:
3731
					#$result["status"],狀態,"true"或"false".
3732
					#$result["error"],錯誤訊息陣列.
3733
					#$result["function"],當前函式的名稱.
3734
					#$result["argu"],使用的參數.
3735
					#$result["content"],要寫入log的內容字串.
3736
					#必填參數:
3737
					#$conf["path"],字串,log檔案的路徑與名稱.
3738
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3739
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3740
					$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR through multi threads.".PHP_EOL;
3741
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3742
					$conf["logs::record"]["fileArgu"]=__FILE__;
3743
					#可省略參數:
3744
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3745
					#$conf["rewrite"]="false";
3746
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3747
					#$conf["returnOnly"]="true";
3748
					#參考資料:
3749
					#無.
3750
					#備註:
3751
					#無.
3752
					$record=logs::record($conf["logs::record"]);
3753
					unset($conf["logs::record"]);
291 liveuser 3754
 
293 liveuser 3755
					}#if end
3756
 
3757
				#初始化要執行的 php 程式
3758
				$phpCode2run="php -r ";
291 liveuser 3759
 
293 liveuser 3760
				#php code not escaped
3761
				$phpCode2escaped=<<<'PHP'
3762
/*
291 liveuser 3763
 
293 liveuser 3764
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
3765
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3766
 
3767
    This file is part of QBPWCF.
3768
 
3769
    QBPWCF is free software: you can redistribute it and/or modify
3770
    it under the terms of the GNU General Public License as published by
3771
    the Free Software Foundation, either version 3 of the License, or
3772
    (at your option) any later version.
3773
 
3774
    QBPWCF is distributed in the hope that it will be useful,
3775
    but WITHOUT ANY WARRANTY; without even the implied warranty of
3776
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3777
    GNU General Public License for more details.
3778
 
3779
    You should have received a copy of the GNU General Public License
3780
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
3781
 
3782
*/
3783
 
3784
#使用命名空間qbpwcf
3785
namespace qbpwcf;
3786
 
3787
#匯入套件
3788
PHP;
3789
 
3790
#設置 lib root path
3791
$libPath=pathinfo(__FILE__)["dirname"]."/..";
3792
 
3793
#串接匯入QBPWCF套件
3794
$phpCode2escaped=$phpCode2escaped.PHP_EOL."require_once(\"".$libPath."/qbpwcf/allInOne.php\");";
3795
 
3796
#串接php程式
3797
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
291 liveuser 3798
#函式說明:
3799
#解析RR檔案中其中的一行內容.
3800
#回傳結果:
3801
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3802
#$reuslt["error"],執行不正常結束的錯訊息陣列.
3803
#$result["function"],當前執行的函式名稱.
3804
#$result["argu"],所使用的參數.
293 liveuser 3805
#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
291 liveuser 3806
#$result["domain"],字串,RR所屬domain.
3807
#$result["defaultTTL"],字串,預設的RR更新時間.
293 liveuser 3808
#$result["comment"],字串,一行的註解.
291 liveuser 3809
#必填參數:
3810
#$conf["line"],字串,要解析的行內容.
293 liveuser 3811
PHP;
3812
 
3813
#串接變數
3814
$phpCode2escaped=$phpCode2escaped.PHP_EOL."\$conf[\"line\"]=base64_decode(\"".base64_encode($line)."\");";
3815
 
3816
#串接php程式
3817
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
291 liveuser 3818
#可省略參數:
3819
#無.
3820
#參考資料:
3821
#無.
3822
#備註:
3823
#無.
3824
$parseRRline=zerossl::parseRRline($conf);
3825
unset($conf);
3826
 
3827
#如果執行異常 
3828
if($parseRRline["status"]==="false"){
3829
 
3830
	#設置錯誤識別
3831
	$result["status"]="false";
3832
 
3833
	#設置錯誤訊息
3834
	$result["error"]=$parseRRline;
3835
 
3836
	#印出 json 結果
3837
	echo json_encode($result);
3838
 
3839
	#結束執行,回傳1.
3840
	exit(1);
3841
 
3842
	}#if end
3843
 
3844
#印出json
3845
echo json_encode($parseRRline);
3846
PHP;
3847
 
293 liveuser 3848
				#串接要執行的參數
3849
				$phpCode2run=$phpCode2run.escapeshellarg($phpCode2escaped);
3850
 
291 liveuser 3851
				#函式說明:
3852
				#透過proc來多執行序運作.
3853
				#回傳結果:
3854
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3855
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3856
				#$result["function"],當前執行的函式名稱.
3857
				#$result["argu"],使用的參數.
3858
				#$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"代表程序的資訊.
3859
				#必填參數:
3860
				#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
293 liveuser 3861
				$conf["threads::proc"]["cmds"]=array($phpCode2run);
291 liveuser 3862
				#可省略參數:
3863
				#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
3864
				$conf["threads::proc"]["wait"]="false";
3865
				#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
3866
				#$conf["timeout"]=array("10");
3867
				#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
293 liveuser 3868
				#$conf["threads::proc"]["workingDir"]=array(pathinfo(__FILE__)["dirname"]);
291 liveuser 3869
				#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
3870
				#$conf["envs"]=array(array("key"=>"value"));
3871
				#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
3872
				#$conf["executeBy"]=array("bash");
3873
				#參考資料:
3874
				#https://www.php.net/manual/en/function.proc-open.php
3875
				#https://www.php.net/manual/en/function.proc-get-status.php
3876
				#https://www.php.net/manual/en/function.proc-terminate.php
3877
				#備註:
3878
				#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
3879
				#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
3880
				$proc=threads::proc($conf["threads::proc"]);
3881
				unset($conf["threads::proc"]);
3882
 
293 liveuser 3883
				#debug
3884
				#var_dump($proc);exit;
3885
 
291 liveuser 3886
				#如果檢查失敗
3887
				if($proc["status"]==="false"){
3888
 
3889
					#設置錯誤識別
3890
					$result["status"]="false";
3891
 
3892
					#設置錯誤訊息
3893
					$result["error"]=$proc;
3894
 
3895
					#回傳結果
3896
					return $result;
3897
 
3898
					}#if end
3899
 
3900
				#儲存程序資訊
294 liveuser 3901
				$procs[$lineNo]=$proc;	
291 liveuser 3902
 
3903
				#換解析下一行
3904
				continue;
3905
 
3906
				}#if end
3907
 
249 liveuser 3908
			#另存一份要處理的RR
404 liveuser 3909
			#$unFormatStr=$line;
249 liveuser 3910
 
253 liveuser 3911
			#如果要debug
3912
			if($conf["debug"]==="true"){
3913
 
3914
				#函式說明:
3915
				#撰寫log
3916
				#回傳結果:
3917
				#$result["status"],狀態,"true"或"false".
3918
				#$result["error"],錯誤訊息陣列.
3919
				#$result["function"],當前函式的名稱.
3920
				#$result["argu"],使用的參數.
3921
				#$result["content"],要寫入log的內容字串.
3922
				#必填參數:
3923
				#$conf["path"],字串,log檔案的路徑與名稱.
3924
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3925
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3926
				$conf["logs::record"]["content"]="processing lineNo:".$lineNo." content:".$line.PHP_EOL;
3927
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3928
				$conf["logs::record"]["fileArgu"]=__FILE__;
3929
				#可省略參數:
3930
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3931
				#$conf["rewrite"]="false";
3932
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3933
				#$conf["returnOnly"]="true";
3934
				#參考資料:
3935
				#無.
3936
				#備註:
3937
				#無.
3938
				$record=logs::record($conf["logs::record"]);
3939
				unset($conf["logs::record"]);
3940
 
3941
				}#if end
3942
 
404 liveuser 3943
			#函式說明:
3944
			#解析RR檔案中其中的一行內容,回傳結果.
249 liveuser 3945
			#回傳結果:
3946
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3947
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3948
			#$result["function"],當前執行的函式名稱.
3949
			#$result["argu"],所使用的參數.
404 liveuser 3950
			#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
3951
			#$result["domain"],字串,RR所屬domain.
3952
			#$result["defaultTTL"],字串,預設的RR更新時間.
3953
			#$result["comment"],字串,一行的註解.
249 liveuser 3954
			#必填參數:
404 liveuser 3955
			#$conf["line"],字串,要解析的行內容.
3956
			$conf["zerossl::parseRRline"]["line"]=$line;
249 liveuser 3957
			#可省略參數:
3958
			#無.
3959
			#參考資料:
3960
			#無.
3961
			#備註:
3962
			#無.
404 liveuser 3963
			$parseRRline=zerossl::parseRRline($conf["zerossl::parseRRline"]);
3964
			unset($conf["zerossl::parseRRline"]);
249 liveuser 3965
 
404 liveuser 3966
			#如果解析異常 
3967
			if($parseRRline["status"]==="false"){
249 liveuser 3968
 
3969
				#設置錯誤識別
3970
				$result["status"]="false";
3971
 
3972
				#設置錯誤訊息
404 liveuser 3973
				$result["error"]=$proc;
249 liveuser 3974
 
3975
				#回傳結果
3976
				return $result;
3977
 
404 liveuser 3978
				}#iif end
249 liveuser 3979
 
404 liveuser 3980
			#取得該RR的解析結果
3981
			$info=$parseRRline["content"];
249 liveuser 3982
 
404 liveuser 3983
			#如果是TTL列
3984
			if($info["type"]==="\$TTL"){
249 liveuser 3985
 
404 liveuser 3986
				#設置預設的TTL
3987
				$result["defaultTTL"]=$info["defaultTTL"];
249 liveuser 3988
 
3989
				}#if end
3990
 
404 liveuser 3991
			#如果是ORIGIN列
3992
			if($info["type"]==="\$ORIGIN"){	
249 liveuser 3993
 
404 liveuser 3994
				#設置RR所屬的domain
3995
				$result["domain"]=$info["domain"];
249 liveuser 3996
 
3997
				}#if end
3998
 
404 liveuser 3999
			#儲存 RR 的記錄
4000
			$result["content"][]=$info;
249 liveuser 4001
 
4002
			}#foreach end
291 liveuser 4003
 
4004
		#如果要啟用多執行序
293 liveuser 4005
		if($conf["multiThreads"]==="true"){
249 liveuser 4006
 
293 liveuser 4007
			#如果要debug
4008
			if($conf["debug"]==="true"){
4009
 
4010
				#函式說明:
4011
				#撰寫log
4012
				#回傳結果:
4013
				#$result["status"],狀態,"true"或"false".
4014
				#$result["error"],錯誤訊息陣列.
4015
				#$result["function"],當前函式的名稱.
4016
				#$result["argu"],使用的參數.
4017
				#$result["content"],要寫入log的內容字串.
4018
				#必填參數:
4019
				#$conf["path"],字串,log檔案的路徑與名稱.
4020
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4021
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4022
				$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR result through multi threads.".PHP_EOL;
4023
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4024
				$conf["logs::record"]["fileArgu"]=__FILE__;
4025
				#可省略參數:
4026
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4027
				#$conf["rewrite"]="false";
4028
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4029
				#$conf["returnOnly"]="true";
4030
				#參考資料:
4031
				#無.
4032
				#備註:
4033
				#無.
4034
				$record=logs::record($conf["logs::record"]);
4035
				unset($conf["logs::record"]);
4036
 
4037
				}#if end
291 liveuser 4038
 
293 liveuser 4039
			#無窮迴圈
4040
			while(true){
4041
 
4042
				#等後1秒
4043
				sleep(1);
4044
 
4045
				#針對每行處理的狀況
4046
				foreach($procs as $procIndex => $proc){
4047
 
4048
					#如果要debug
4049
					if($conf["debug"]==="true"){
4050
 
4051
						#函式說明:
4052
						#撰寫log
4053
						#回傳結果:
4054
						#$result["status"],狀態,"true"或"false".
4055
						#$result["error"],錯誤訊息陣列.
4056
						#$result["function"],當前函式的名稱.
4057
						#$result["argu"],使用的參數.
4058
						#$result["content"],要寫入log的內容字串.
4059
						#必填參數:
4060
						#$conf["path"],字串,log檔案的路徑與名稱.
4061
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4062
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4063
						$conf["logs::record"]["content"]="lineNo:".__LINE__." Try get result of parsing RR line ".($procIndex+1)." through multi threads.".PHP_EOL;
4064
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4065
						$conf["logs::record"]["fileArgu"]=__FILE__;
4066
						#可省略參數:
4067
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4068
						#$conf["rewrite"]="false";
4069
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4070
						#$conf["returnOnly"]="true";
4071
						#參考資料:
4072
						#無.
4073
						#備註:
4074
						#無.
4075
						$record=logs::record($conf["logs::record"]);
4076
						unset($conf["logs::record"]);
4077
 
4078
						}#if end
4079
 
4080
					#函式說明:
4081
					#更新透過proc執行的多程序資訊.
4082
					#回傳結果:
4083
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4084
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
4085
					#$result["function"],當前執行的函式名稱.
4086
					#$result["argu"],使用的參數.
4087
					#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
4088
					#必填參數:
4089
					#$conf["procs"],陣列,運行self::proc後回傳的content.
4090
					$conf["threads::proc_update"]["procs"]=$proc["content"];
4091
					#可省略參數:
4092
					#無.
4093
					#參考資料:
4094
					#無.
4095
					#備註:
4096
					#無.
4097
					$proc_update=threads::proc_update($conf["threads::proc_update"]);
4098
					unset($conf["threads::proc_update"]);
4099
 
4100
					#debug
4101
					#var_dump($proc_update);exit;
4102
 
4103
					#如果執行異常
4104
					if($proc_update["status"]==="false"){
4105
 
4106
						#設置執行異常
4107
						$result["status"]="false";
4108
 
4109
						#設置執行錯誤
4110
						$result["error"]=$proc_update;
4111
 
4112
						#回傳結果
4113
						return $result;
4114
 
4115
						}#if end
4116
 
4117
					#另存結果
4118
					$procRes=$proc_update["content"][0];
4119
 
4120
					#如果程序執行異常
4121
					if($procRes["status"]==="false"){
4122
 
4123
						#設置執行異常
4124
						$result["status"]="false";
4125
 
4126
						#設置執行錯誤
4127
						$result["error"]=$procRes;
4128
 
4129
						#回傳結果
4130
						return $result;
4131
 
4132
						}#if end
4133
 
4134
					#如果程序尚在執行
4135
					if($procRes["statusCode"]==="?"){
4136
 
4137
						#換看下一列的執行狀況
4138
						continue;
4139
 
4140
						}#if end
4141
 
4142
					#如果輸出內容不是 json
4143
					if(!(json_validate($procRes["content"]))){
4144
 
4145
						#設置執行異常
4146
						$result["status"]="false";
4147
 
4148
						#設置執行錯誤
4149
						$result["error"]=$procRes;
4150
 
4151
						#回傳結果
4152
						return $result;
4153
 
4154
						}#if end
4155
 
4156
					#解析json
4157
					$jsonRes=json_decode($procRes["content"]);
4158
 
4159
					#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","query","update",也可能為空陣列.
4160
					#$result["domain"],字串,RR所屬domain.
4161
					#$result["defaultTTL"],字串,預設的RR更新時間.
4162
					#$result["comment"],字串,一行的註解.
4163
 
4164
					#如果有 content->type 存在
4165
					if(isset($jsonRes->content->type)){
4166
 
4167
						#儲存value
4168
						$info["type"]=$jsonRes->content->type;
4169
 
4170
						}#if end
4171
 
4172
					#如果有 content->value 存在
4173
					if(isset($jsonRes->content->value)){
4174
 
4175
						#儲存value
4176
						$info["value"]=$jsonRes->content->value;
4177
 
4178
						}#if end
4179
 
4180
					#如果有 content->query 存在
4181
					if(isset($jsonRes->content->query)){
4182
 
4183
						#儲存query
4184
						$info["query"]=$jsonRes->content->query;
4185
 
4186
						}#if end
4187
 
4188
					#如果有 content->update 存在
4189
					if(isset($jsonRes->content->update)){
4190
 
4191
						#儲存query
4192
						$info["update"]=$jsonRes->content->update;
4193
 
4194
						}#if end
4195
 
4196
					#如果有 domain 存在
4197
					if(isset($jsonRes->domain)){
4198
 
4199
						#儲存domain
4200
						$result["domain"]=$jsonRes->domain;
4201
 
4202
						}#if end
4203
 
4204
					#如果有 defaultTTL 存在
4205
					if(isset($jsonRes->defaultTTL)){
4206
 
4207
						#儲存domain
404 liveuser 4208
						$result["defaultTTL"]=$jsonRes->defaultTTL;
293 liveuser 4209
 
4210
						}#if end
4211
 
4212
					#如果有 comment 存在
4213
					if(isset($jsonRes->comment)){
4214
 
4215
						#儲存comment,用$procIndex作為先後順率的識別
4216
						$result["comment"][$procIndex]=$jsonRes->comment;
4217
 
4218
						}#if end
4219
 
4220
					#儲存 RR 的記錄
4221
					$result["content"][$procIndex]=$info;
4222
 
4223
					#移除解析好的行號
4224
					unset($procs[$procIndex]);
4225
 
4226
					#如果要debug
4227
					if($conf["debug"]==="true"){
4228
 
4229
						#函式說明:
4230
						#撰寫log
4231
						#回傳結果:
4232
						#$result["status"],狀態,"true"或"false".
4233
						#$result["error"],錯誤訊息陣列.
4234
						#$result["function"],當前函式的名稱.
4235
						#$result["argu"],使用的參數.
4236
						#$result["content"],要寫入log的內容字串.
4237
						#必填參數:
4238
						#$conf["path"],字串,log檔案的路徑與名稱.
4239
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4240
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4241
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR line ".($procIndex+1)." through multi threads fin.".PHP_EOL;
4242
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4243
						$conf["logs::record"]["fileArgu"]=__FILE__;
4244
						#可省略參數:
4245
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4246
						#$conf["rewrite"]="false";
4247
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4248
						#$conf["returnOnly"]="true";
4249
						#參考資料:
4250
						#無.
4251
						#備註:
4252
						#無.
4253
						$record=logs::record($conf["logs::record"]);
4254
						unset($conf["logs::record"]);
4255
 
4256
						}#if end
4257
 
4258
					}#foreach end
4259
 
4260
				#如果每行都已經解析好了
4261
				if(count($procs)===0){
4262
 
4263
					#如果要debug
4264
					if($conf["debug"]==="true"){
4265
 
4266
						#函式說明:
4267
						#撰寫log
4268
						#回傳結果:
4269
						#$result["status"],狀態,"true"或"false".
4270
						#$result["error"],錯誤訊息陣列.
4271
						#$result["function"],當前函式的名稱.
4272
						#$result["argu"],使用的參數.
4273
						#$result["content"],要寫入log的內容字串.
4274
						#必填參數:
4275
						#$conf["path"],字串,log檔案的路徑與名稱.
4276
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4277
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4278
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR through multi threads fin.".PHP_EOL;
4279
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4280
						$conf["logs::record"]["fileArgu"]=__FILE__;
4281
						#可省略參數:
4282
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4283
						#$conf["rewrite"]="false";
4284
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4285
						#$conf["returnOnly"]="true";
4286
						#參考資料:
4287
						#無.
4288
						#備註:
4289
						#無.
4290
						$record=logs::record($conf["logs::record"]);
4291
						unset($conf["logs::record"]);
4292
 
4293
						}#if end
4294
 
4295
					#跳出 while
4296
					break;
4297
 
4298
					}#if end
4299
 
4300
				}#while end
4301
 
291 liveuser 4302
			}#if end
4303
 
253 liveuser 4304
		#如果要debug
4305
		if($conf["debug"]==="true"){
249 liveuser 4306
 
253 liveuser 4307
			#函式說明:
4308
			#撰寫log
4309
			#回傳結果:
4310
			#$result["status"],狀態,"true"或"false".
4311
			#$result["error"],錯誤訊息陣列.
4312
			#$result["function"],當前函式的名稱.
4313
			#$result["argu"],使用的參數.
4314
			#$result["content"],要寫入log的內容字串.
4315
			#必填參數:
4316
			#$conf["path"],字串,log檔案的路徑與名稱.
4317
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4318
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4319
			$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR fin.".PHP_EOL;
4320
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4321
			$conf["logs::record"]["fileArgu"]=__FILE__;
4322
			#可省略參數:
4323
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4324
			#$conf["rewrite"]="false";
4325
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4326
			#$conf["returnOnly"]="true";
4327
			#參考資料:
4328
			#無.
4329
			#備註:
4330
			#無.
4331
			$record=logs::record($conf["logs::record"]);
4332
			unset($conf["logs::record"]);
4333
 
4334
			}#if end
4335
 
249 liveuser 4336
		#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
4337
 
4338
		#針對每個要新增的RR記錄
255 liveuser 4339
		foreach($conf["add"] as $nri => $newRR){
249 liveuser 4340
 
255 liveuser 4341
			#如果要debug
4342
			if($conf["debug"]==="true"){
4343
 
4344
				#函式說明:
4345
				#撰寫log
4346
				#回傳結果:
4347
				#$result["status"],狀態,"true"或"false".
4348
				#$result["error"],錯誤訊息陣列.
4349
				#$result["function"],當前函式的名稱.
4350
				#$result["argu"],使用的參數.
4351
				#$result["content"],要寫入log的內容字串.
4352
				#必填參數:
4353
				#$conf["path"],字串,log檔案的路徑與名稱.
4354
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4355
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4356
				$conf["logs::record"]["content"]="lineNo:".__LINE__." ori newRR:".PHP_EOL;
4357
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4358
				$conf["logs::record"]["fileArgu"]=__FILE__;
4359
				#可省略參數:
4360
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4361
				#$conf["rewrite"]="false";
4362
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4363
				#$conf["returnOnly"]="true";
4364
				#參考資料:
4365
				#無.
4366
				#備註:
4367
				#無.
4368
				$record=logs::record($conf["logs::record"]);
4369
				unset($conf["logs::record"]);
4370
 
4371
				#函式說明:
4372
				#撰寫log
4373
				#回傳結果:
4374
				#$result["status"],狀態,"true"或"false".
4375
				#$result["error"],錯誤訊息陣列.
4376
				#$result["function"],當前函式的名稱.
4377
				#$result["argu"],使用的參數.
4378
				#$result["content"],要寫入log的內容字串.
4379
				#必填參數:
4380
				#$conf["path"],字串,log檔案的路徑與名稱.
4381
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4382
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4383
				$conf["logs::record"]["content"]=$newRR;
4384
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4385
				$conf["logs::record"]["fileArgu"]=__FILE__;
4386
				#可省略參數:
4387
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4388
				#$conf["rewrite"]="false";
4389
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4390
				#$conf["returnOnly"]="true";
4391
				#參考資料:
4392
				#無.
4393
				#備註:
4394
				#無.
4395
				$record=logs::record($conf["logs::record"]);
4396
				unset($conf["logs::record"]);
4397
 
4398
				}#if end
4399
 
4400
			#如果新的 RR 缺少必備的資訊
4401
			if(!isset($newRR["type"])){
4402
 
4403
				#設置執行異常
4404
				$result["status"]="false";
4405
 
4406
				#設置執行錯誤
4407
				$result["error"]="add參數的格式缺少type";
4408
 
4409
				#回傳結果
4410
				return $result;
4411
 
4412
				}#if end
4413
 
404 liveuser 4414
			#如果 query 不是"@"也不為"."結尾
255 liveuser 4415
			if( ($newRR["query"]!=="@") && ($newRR["query"][strlen($newRR["query"])-1]!==".") ){
4416
 
4417
				#加上 "."
4418
				$conf["add"][$nri]["query"]=$newRR["query"]=$newRR["query"].".";
4419
 
4420
				}#if end
4421
 
4422
			#如果新的 query 為 $ORGIN 結尾
4423
			#函式說明:
4424
			#將字串特定關鍵字與其後面的內容剔除
4425
			#回傳結果:
4426
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4427
			#$result["error"],錯誤訊息陣列.
4428
			#$result["warning"],警告訊息鎮列.
4429
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4430
			#$result["function"],當前執行的函數名稱.
4431
			#$result["oriStr"],要處理的原始字串內容.
4432
			#$result["content"],處理好的的字串內容.
4433
			#$result["deleted"],被移除的內容.
4434
			#$result["argu"],使用的參數.
4435
			#必填參數:
4436
			#$conf["stringIn"],字串,要處理的字串.
4437
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
4438
			#$conf["keyWord"],字串,特定字串.
4439
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["domain"];
4440
			#可省略參數:
4441
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
4442
			#$conf["deleteLastRepeatedOne"]="";
4443
			#參考資料:
4444
			#無.
4445
			#備註:
4446
			#無.
4447
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
4448
			unset($conf["stringProcess::delStrAfterKeyWord"]);
4449
 
4450
			#如果要debug
4451
			if($conf["debug"]==="true"){
4452
 
4453
				#函式說明:
4454
				#撰寫log
4455
				#回傳結果:
4456
				#$result["status"],狀態,"true"或"false".
4457
				#$result["error"],錯誤訊息陣列.
4458
				#$result["function"],當前函式的名稱.
4459
				#$result["argu"],使用的參數.
4460
				#$result["content"],要寫入log的內容字串.
4461
				#必填參數:
4462
				#$conf["path"],字串,log檔案的路徑與名稱.
4463
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4464
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4465
				$conf["logs::record"]["content"]="lineNo:".__LINE__." try process newRR with \$ORIGIN end".PHP_EOL;
4466
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4467
				$conf["logs::record"]["fileArgu"]=__FILE__;
4468
				#可省略參數:
4469
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4470
				#$conf["rewrite"]="false";
4471
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4472
				#$conf["returnOnly"]="true";
4473
				#參考資料:
4474
				#無.
4475
				#備註:
4476
				#無.
4477
				$record=logs::record($conf["logs::record"]);
4478
				unset($conf["logs::record"]);
4479
 
4480
				#函式說明:
4481
				#撰寫log
4482
				#回傳結果:
4483
				#$result["status"],狀態,"true"或"false".
4484
				#$result["error"],錯誤訊息陣列.
4485
				#$result["function"],當前函式的名稱.
4486
				#$result["argu"],使用的參數.
4487
				#$result["content"],要寫入log的內容字串.
4488
				#必填參數:
4489
				#$conf["path"],字串,log檔案的路徑與名稱.
4490
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4491
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4492
				$conf["logs::record"]["content"]=$delStrAfterKeyWord;
4493
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4494
				$conf["logs::record"]["fileArgu"]=__FILE__;
4495
				#可省略參數:
4496
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4497
				#$conf["rewrite"]="false";
4498
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4499
				#$conf["returnOnly"]="true";
4500
				#參考資料:
4501
				#無.
4502
				#備註:
4503
				#無.
4504
				$record=logs::record($conf["logs::record"]);
4505
				unset($conf["logs::record"]);
4506
 
4507
				}#if end
4508
 
4509
			#如果異常
4510
			if($delStrAfterKeyWord["status"]==="false"){
4511
 
4512
				#設置執行異常
4513
				$result["status"]="false";
4514
 
4515
				#設置執行錯誤
4516
				$result["error"]=$delStrAfterKeyWord;
4517
 
4518
				#回傳結果
4519
				return $result;
4520
 
4521
				}#if end
4522
 
4523
			#如果有找到 $ORIGIN 結尾
4524
			if($delStrAfterKeyWord["founded"]==="true"){
4525
 
4526
				#更新 query
4527
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
4528
 
4529
				#如果$newRR["query"] 變成 ""
4530
				if(empty($newRR["query"])){
4531
 
4532
					#變成 zone domain,亦即 $result["domain"]
4533
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
4534
 
4535
					}#if end
4536
 
4537
				#如果要debug
4538
				if($conf["debug"]==="true"){
4539
 
4540
					#函式說明:
4541
					#撰寫log
4542
					#回傳結果:
4543
					#$result["status"],狀態,"true"或"false".
4544
					#$result["error"],錯誤訊息陣列.
4545
					#$result["function"],當前函式的名稱.
4546
					#$result["argu"],使用的參數.
4547
					#$result["content"],要寫入log的內容字串.
4548
					#必填參數:
4549
					#$conf["path"],字串,log檔案的路徑與名稱.
4550
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4551
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4552
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4553
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4554
					$conf["logs::record"]["fileArgu"]=__FILE__;
4555
					#可省略參數:
4556
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4557
					#$conf["rewrite"]="false";
4558
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4559
					#$conf["returnOnly"]="true";
4560
					#參考資料:
4561
					#無.
4562
					#備註:
4563
					#無.
4564
					$record=logs::record($conf["logs::record"]);
4565
					unset($conf["logs::record"]);
4566
 
4567
					#函式說明:
4568
					#撰寫log
4569
					#回傳結果:
4570
					#$result["status"],狀態,"true"或"false".
4571
					#$result["error"],錯誤訊息陣列.
4572
					#$result["function"],當前函式的名稱.
4573
					#$result["argu"],使用的參數.
4574
					#$result["content"],要寫入log的內容字串.
4575
					#必填參數:
4576
					#$conf["path"],字串,log檔案的路徑與名稱.
4577
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4578
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4579
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4580
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4581
					$conf["logs::record"]["fileArgu"]=__FILE__;
4582
					#可省略參數:
4583
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4584
					#$conf["rewrite"]="false";
4585
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4586
					#$conf["returnOnly"]="true";
4587
					#參考資料:
4588
					#無.
4589
					#備註:
4590
					#無.
4591
					$record=logs::record($conf["logs::record"]);
4592
					unset($conf["logs::record"]);
4593
 
4594
					}#if end
4595
 
4596
				}#if end
4597
 
4598
			#如果新的 query 為 "." 結尾
4599
			#函式說明:
4600
			#將字串特定關鍵字與其後面的內容剔除
4601
			#回傳結果:
4602
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4603
			#$result["error"],錯誤訊息陣列.
4604
			#$result["warning"],警告訊息鎮列.
4605
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4606
			#$result["function"],當前執行的函數名稱.
4607
			#$result["oriStr"],要處理的原始字串內容.
4608
			#$result["content"],處理好的的字串內容.
4609
			#$result["deleted"],被移除的內容.
4610
			#$result["argu"],使用的參數.
4611
			#必填參數:
4612
			#$conf["stringIn"],字串,要處理的字串.
4613
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
4614
			#$conf["keyWord"],字串,特定字串.
4615
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".";
4616
			#可省略參數:
4617
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
4618
			#$conf["deleteLastRepeatedOne"]="";
4619
			#參考資料:
4620
			#無.
4621
			#備註:
4622
			#無.
4623
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
4624
			unset($conf["stringProcess::delStrAfterKeyWord"]);
4625
 
4626
			#如果異常
4627
			if($delStrAfterKeyWord["status"]==="false"){
4628
 
4629
				#設置執行異常
4630
				$result["status"]="false";
4631
 
4632
				#設置執行錯誤
4633
				$result["error"]=$delStrAfterKeyWord;
4634
 
4635
				#回傳結果
4636
				return $result;
4637
 
4638
				}#if end
4639
 
4640
			#如果有找到 "." 結尾
4641
			if($delStrAfterKeyWord["founded"]==="true"){
4642
 
4643
				#更新 query
4644
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
4645
 
4646
				#如果 $newRR["query"] 變成 ""
4647
				if(empty($newRR["query"])){
4648
 
4649
					#變成 zone domain,亦即 $result["domain"]
4650
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
4651
 
4652
					}#if end
4653
 
4654
				#如果要debug
4655
				if($conf["debug"]==="true"){
4656
 
4657
					#函式說明:
4658
					#撰寫log
4659
					#回傳結果:
4660
					#$result["status"],狀態,"true"或"false".
4661
					#$result["error"],錯誤訊息陣列.
4662
					#$result["function"],當前函式的名稱.
4663
					#$result["argu"],使用的參數.
4664
					#$result["content"],要寫入log的內容字串.
4665
					#必填參數:
4666
					#$conf["path"],字串,log檔案的路徑與名稱.
4667
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4668
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4669
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4670
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4671
					$conf["logs::record"]["fileArgu"]=__FILE__;
4672
					#可省略參數:
4673
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4674
					#$conf["rewrite"]="false";
4675
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4676
					#$conf["returnOnly"]="true";
4677
					#參考資料:
4678
					#無.
4679
					#備註:
4680
					#無.
4681
					$record=logs::record($conf["logs::record"]);
4682
					unset($conf["logs::record"]);
4683
 
4684
					#函式說明:
4685
					#撰寫log
4686
					#回傳結果:
4687
					#$result["status"],狀態,"true"或"false".
4688
					#$result["error"],錯誤訊息陣列.
4689
					#$result["function"],當前函式的名稱.
4690
					#$result["argu"],使用的參數.
4691
					#$result["content"],要寫入log的內容字串.
4692
					#必填參數:
4693
					#$conf["path"],字串,log檔案的路徑與名稱.
4694
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4695
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4696
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4697
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4698
					$conf["logs::record"]["fileArgu"]=__FILE__;
4699
					#可省略參數:
4700
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4701
					#$conf["rewrite"]="false";
4702
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4703
					#$conf["returnOnly"]="true";
4704
					#參考資料:
4705
					#無.
4706
					#備註:
4707
					#無.
4708
					$record=logs::record($conf["logs::record"]);
4709
					unset($conf["logs::record"]);
4710
 
4711
					}#if end
4712
 
4713
				}#if end
4714
 
404 liveuser 4715
			/* 看起來怪怪的
4716
 
255 liveuser 4717
			#如果新 RR 的 type 不是 A 且 value 不為 "." 結尾.
4718
			if( $newRR["type"]!=="A" && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
4719
 
4720
				#new RR add dot to value end.
4721
				$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
4722
 
4723
				#如果要debug
4724
				if($conf["debug"]==="true"){
4725
 
4726
					#函式說明:
4727
					#撰寫log
4728
					#回傳結果:
4729
					#$result["status"],狀態,"true"或"false".
4730
					#$result["error"],錯誤訊息陣列.
4731
					#$result["function"],當前函式的名稱.
4732
					#$result["argu"],使用的參數.
4733
					#$result["content"],要寫入log的內容字串.
4734
					#必填參數:
4735
					#$conf["path"],字串,log檔案的路徑與名稱.
4736
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4737
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4738
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4739
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4740
					$conf["logs::record"]["fileArgu"]=__FILE__;
4741
					#可省略參數:
4742
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4743
					#$conf["rewrite"]="false";
4744
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4745
					#$conf["returnOnly"]="true";
4746
					#參考資料:
4747
					#無.
4748
					#備註:
4749
					#無.
4750
					$record=logs::record($conf["logs::record"]);
4751
					unset($conf["logs::record"]);
4752
 
4753
					#函式說明:
4754
					#撰寫log
4755
					#回傳結果:
4756
					#$result["status"],狀態,"true"或"false".
4757
					#$result["error"],錯誤訊息陣列.
4758
					#$result["function"],當前函式的名稱.
4759
					#$result["argu"],使用的參數.
4760
					#$result["content"],要寫入log的內容字串.
4761
					#必填參數:
4762
					#$conf["path"],字串,log檔案的路徑與名稱.
4763
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4764
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4765
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4766
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4767
					$conf["logs::record"]["fileArgu"]=__FILE__;
4768
					#可省略參數:
4769
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4770
					#$conf["rewrite"]="false";
4771
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4772
					#$conf["returnOnly"]="true";
4773
					#參考資料:
4774
					#無.
4775
					#備註:
4776
					#無.
4777
					$record=logs::record($conf["logs::record"]);
4778
					unset($conf["logs::record"]);
4779
 
4780
					}#if end
4781
 
4782
				}#if end
4783
 
404 liveuser 4784
			*/
4785
 
249 liveuser 4786
			#針對 zone file 中既有的每個RR記錄
4787
			foreach($result["content"] as $index => $oldRR){
4788
 
4789
				#如果既有的跟新的RR都為 $ORIGIN
4790
				if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
4791
 
4792
					#取代既有的 RR
4793
					$result["content"][$index]=$newRR;
4794
 
4795
					#換看下一筆newRR
4796
					continue 2;
4797
 
4798
					}#if end
4799
 
4800
				#如果既有的跟新的RR都為 $TTL
4801
				if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
4802
 
4803
					#取代既有的 RR
4804
					$result["content"][$index]=$newRR;
4805
 
4806
					#換看下一筆newRR
4807
					continue 2;
4808
 
4809
					}#if end
4810
 
253 liveuser 4811
				#如果新舊資料都有query資訊
4812
				if( isset($newRR["query"]) && isset($oldRR["query"]) ){
249 liveuser 4813
 
253 liveuser 4814
					#如果跟既有的 query、type、value 有相同
4815
					if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
249 liveuser 4816
 
253 liveuser 4817
						#如果新 RR 有 update time
4818
						if(isset($newRR["update"])){
249 liveuser 4819
 
253 liveuser 4820
							#如果新舊 update time 不相同
4821
							if( $newRR["update"] !== $oldRR["update"] ){
249 liveuser 4822
 
253 liveuser 4823
								#取代既有的 RR
4824
								$result["content"][$index]=$newRR;
4825
 
4826
								#換看下一筆newRR
4827
								continue 2;
4828
 
4829
								}#if end
4830
 
4831
							}#if end
249 liveuser 4832
 
253 liveuser 4833
						#反之既有的 update time 若跟 global TTL 不一樣
4834
						else if( $oldRR["update"] !== $result["defaultTTL"] ){
4835
 
4836
							#更新為 global TTL
4837
							$result["content"][$index]["update"]=$result["defaultTTL"];
4838
 
249 liveuser 4839
							}#if end
253 liveuser 4840
 
4841
						#如果新 RR 有 comment
4842
						if( isset($newRR["comment"]) ){
249 liveuser 4843
 
253 liveuser 4844
							#更新既有 RR 的 comment
4845
							$result["content"][$index]["comment"]=$newRR["comment"];
249 liveuser 4846
 
253 liveuser 4847
							#換看下一筆newRR
4848
							continue 2;
249 liveuser 4849
 
253 liveuser 4850
							}#if end
4851
 
4852
						#反之,如果有既有 comment
4853
						else if(isset($result["content"][$index]["comment"])){
249 liveuser 4854
 
253 liveuser 4855
							#移除既有 comment
4856
							unset($result["content"][$index]["comment"]);
4857
 
4858
							#換看下一筆newRR
4859
							continue 2;
249 liveuser 4860
 
253 liveuser 4861
							}#else end
249 liveuser 4862
 
253 liveuser 4863
						}#if end
294 liveuser 4864
 
405 liveuser 4865
					#反之如果跟既有的 query、type有相同,且type 為 "CNAME"
4866
					else if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["type"]==="CNAME" ){
294 liveuser 4867
 
4868
						#更新既有 RR 的 value
4869
						$result["content"][$index]["value"]=$newRR["value"];
4870
 
4871
						#換看下一筆newRR
4872
						continue 2;
4873
 
4874
						}#if end
4875
 
405 liveuser 4876
					#反之如果跟既有的 query、type有相同,且type 為 "CAA"
4877
					else if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["type"]==="CAA" ){
4878
 
4879
						#如果既有的 value 為 0 issue ""
4880
						if($oldRR["value"]==="0 issue \"\""){
4881
 
4882
							#代表要從沒有限制變成右限制
4883
 
4884
							#更新既有 RR 的 value
4885
							$result["content"][$index]["value"]=$newRR["value"];
4886
 
4887
							#換看下一筆newRR
4888
							continue 2;
4889
 
4890
							}#if end
4891
 
4892
						}#if end
4893
 
249 liveuser 4894
					}#if end
253 liveuser 4895
 
249 liveuser 4896
				}#foreach end
4897
 
4898
			#儲存確定要新增的RR
4899
			$result["content"][]=$newRR;
4900
 
4901
			}#foreach end
4902
 
255 liveuser 4903
		#如果要debug
4904
		if($conf["debug"]==="true"){
249 liveuser 4905
 
255 liveuser 4906
			#函式說明:
4907
			#撰寫log
4908
			#回傳結果:
4909
			#$result["status"],狀態,"true"或"false".
4910
			#$result["error"],錯誤訊息陣列.
4911
			#$result["function"],當前函式的名稱.
4912
			#$result["argu"],使用的參數.
4913
			#$result["content"],要寫入log的內容字串.
4914
			#必填參數:
4915
			#$conf["path"],字串,log檔案的路徑與名稱.
4916
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4917
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4918
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
4919
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4920
			$conf["logs::record"]["fileArgu"]=__FILE__;
4921
			#可省略參數:
4922
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4923
			#$conf["rewrite"]="false";
4924
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4925
			#$conf["returnOnly"]="true";
4926
			#參考資料:
4927
			#無.
4928
			#備註:
4929
			#無.
4930
			$record=logs::record($conf["logs::record"]);
4931
			unset($conf["logs::record"]);
249 liveuser 4932
 
255 liveuser 4933
			}#if end
4934
 
4935
		#如果要debug
4936
		if($conf["debug"]==="true"){
4937
 
4938
			#函式說明:
4939
			#撰寫log
4940
			#回傳結果:
4941
			#$result["status"],狀態,"true"或"false".
4942
			#$result["error"],錯誤訊息陣列.
4943
			#$result["function"],當前函式的名稱.
4944
			#$result["argu"],使用的參數.
4945
			#$result["content"],要寫入log的內容字串.
4946
			#必填參數:
4947
			#$conf["path"],字串,log檔案的路徑與名稱.
4948
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4949
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4950
			$conf["logs::record"]["content"]=$result["content"];
4951
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4952
			$conf["logs::record"]["fileArgu"]=__FILE__;
4953
			#可省略參數:
4954
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4955
			#$conf["rewrite"]="false";
4956
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4957
			#$conf["returnOnly"]="true";
4958
			#參考資料:
4959
			#無.
4960
			#備註:
4961
			#無.
4962
			$record=logs::record($conf["logs::record"]);
4963
			unset($conf["logs::record"]);
4964
 
4965
			}#if end
4966
 
249 liveuser 4967
		#初始化要寫入的內容
4968
		$strs2write=array();
4969
 
4970
		#針對每個RR記錄
4971
		foreach($result["content"] as $RR){
4972
 
4973
			#初始化暫存要寫入的行內容
4974
			$str2write="";
4975
 
4976
			#如果是
4977
			if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
4978
 
4979
				#組合變數名稱與數值
4980
				$str2write=$str2write.$RR["type"]."\t".$RR["value"];
4981
 
4982
				}#if end
4983
 
4984
			#反之
4985
			else{
4986
 
4987
				#加上查詢的字句
4988
				$str2write=$str2write.$RR["query"];
4989
 
4990
				#如果該筆RR有指定update time該ZONE具備 global TTL.
4991
				if(isset($RR["update"])){
4992
 
4993
					#如果 該ZONE具備 global TTL.
4994
					if(isset($result["defaultTTL"])){
4995
 
4996
						#如果該筆 RR 的 update time 不等於 global TTL
4997
						if($RR["update"]!==$result["defaultTTL"]){
4998
 
4999
							#加上TTL的字句
5000
							$str2write=$str2write."\t".$RR["update"];
5001
 
5002
							}#if end
5003
 
5004
						}#if end
5005
 
5006
					#反之
5007
					else{
5008
 
5009
						#加上TTL的字句
5010
						$str2write=$str2write."\t".$RR["update"];
5011
 
5012
						}#else end
5013
 
5014
					}#if end
5015
 
253 liveuser 5016
				#反之且該ZONE不具備 global TTL.
5017
				else if(!isset($result["defaultTTL"])){
249 liveuser 5018
 
5019
					#加上global TTL的字句
5020
					$str2write=$str2write."\t".$result["defaultTTL"];
5021
 
253 liveuser 5022
					}#if end
249 liveuser 5023
 
5024
				#加上IN跟TYPE跟value
5025
				$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
5026
 
5027
				}#else end
5028
 
5029
			#如果有註解
5030
			if(isset($RR["comment"])){
5031
 
5032
				#加上comment
5033
				$str2write=$str2write.";".$RR["comment"];
5034
 
5035
				}#if end
5036
 
253 liveuser 5037
			#如果要 debug
5038
			if($conf["debug"]==="true"){
249 liveuser 5039
 
253 liveuser 5040
				#函式說明:
5041
				#撰寫log
5042
				#回傳結果:
5043
				#$result["status"],狀態,"true"或"false".
5044
				#$result["error"],錯誤訊息陣列.
5045
				#$result["function"],當前函式的名稱.
5046
				#$result["argu"],使用的參數.
5047
				#$result["content"],要寫入log的內容字串.
5048
				#必填參數:
5049
				#$conf["path"],字串,log檔案的路徑與名稱.
5050
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5051
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5052
				$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
5053
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5054
				$conf["logs::record"]["fileArgu"]=__FILE__;
5055
				#可省略參數:
5056
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5057
				#$conf["rewrite"]="false";
5058
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5059
				#$conf["returnOnly"]="true";
5060
				#參考資料:
5061
				#無.
5062
				#備註:
5063
				#無.
5064
				$record=logs::record($conf["logs::record"]);
5065
				unset($conf["logs::record"]);
5066
 
5067
				}#if end
5068
 
249 liveuser 5069
			#加上要寫入的元素
5070
			$strs2write[]=$str2write;
5071
 
5072
			}#foreach end
5073
 
5074
		#如果有逐行註解
5075
		if(count($result["comment"])>0){
5076
 
5077
			#加到結尾
5078
			#函式說明:
5079
			#將多個一維陣列串聯起來,key從0開始排序.
5080
			#回傳的結果:
5081
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
5082
			#$result["error"],錯誤訊息陣列.
5083
			#$result["function"],當前執行的函數.
5084
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5085
			#$result["content"],合併好的一維陣列.
5086
			#必填參數
5087
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
5088
			$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
5089
			#可省略參數:
5090
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
5091
			#$conf["allowRepeat"]="true";
5092
			#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
5093
			#$conf["looseDiff"]="false";
5094
			#參考資料:
5095
			#無.
5096
			#備註:
5097
			#無.
5098
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
5099
			unset($conf["arrays::mergeArray"]);
5100
 
5101
			#如果執行異常
5102
			if($mergeArray["status"]==="false"){
5103
 
5104
				#設置錯誤識別
5105
				$result["status"]="false";
5106
 
5107
				#設置錯誤訊息
5108
				$result["error"]=$mergeArray;
5109
 
5110
				#回傳結果
5111
				return $result;
5112
 
5113
				}#if end
5114
 
5115
			#取得合併好的陣列
5116
			$strs2write=$mergeArray["content"];
5117
 
5118
			}#if end
5119
 
253 liveuser 5120
		#如果要 debug
5121
		if($conf["debug"]==="true"){
249 liveuser 5122
 
253 liveuser 5123
			#函式說明:
5124
			#撰寫log
5125
			#回傳結果:
5126
			#$result["status"],狀態,"true"或"false".
5127
			#$result["error"],錯誤訊息陣列.
5128
			#$result["function"],當前函式的名稱.
5129
			#$result["argu"],使用的參數.
5130
			#$result["content"],要寫入log的內容字串.
5131
			#必填參數:
5132
			#$conf["path"],字串,log檔案的路徑與名稱.
5133
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5134
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5135
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
5136
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5137
			$conf["logs::record"]["fileArgu"]=__FILE__;
5138
			#可省略參數:
5139
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5140
			#$conf["rewrite"]="false";
5141
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5142
			#$conf["returnOnly"]="true";
5143
			#參考資料:
5144
			#無.
5145
			#備註:
5146
			#無.
5147
			$record=logs::record($conf["logs::record"]);
5148
			unset($conf["logs::record"]);
5149
 
5150
			}#if end
5151
 
249 liveuser 5152
		#儲存新zone file每行的內容
5153
		$result["newZoneFileContent"]=$strs2write;
5154
 
5155
		#如果要寫入ZONE檔案
5156
		if($conf["writeNow"]==="true"){
5157
 
5158
			#覆寫 ZONE file
5159
			#函式說明:
5160
			#更新檔案的內容.
5161
			#回傳結果:
5162
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5163
			#$result["error"],錯誤訊息.
5164
			#$result["function"],當前執行的函數名稱.
5165
			#$result["content"],更新的資訊.
5166
			#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
5167
			#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
5168
			#必填參數:
5169
			#$conf["fileArgu"],字串,變數__FILE__的內容.
5170
			$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
5171
			#$conf["file"],字串,要更新的檔案位置與名稱.
5172
			$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
5173
			#可省略參數:
5174
			#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
5175
			$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
5176
			#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
5177
			#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
5178
			#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
5179
			#$conf["replaceLike"]="false";
5180
			#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
5181
			#$conf["addToTailWhenNoMatch"]="false";
5182
			#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
5183
			#$conf["addToTailBeforeThat"]="?\>";
5184
			#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
5185
			#$conf["replaceSpecifyLine"]=array();
5186
			#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
5187
			#$conf["outputPath"]="";
5188
			#參考資料:
5189
			#無.
5190
			#備註:
5191
			#無.
5192
			$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
5193
			unset($conf["fileAccess::updateFile"]);
5194
 
5195
			#如果執行異常
5196
			if($updateFile["status"]==="false"){
5197
 
5198
				#設置錯誤識別
5199
				$result["status"]="false";
5200
 
5201
				#設置錯誤訊息
5202
				$result["error"]=$updateFile;
5203
 
5204
				#回傳結果
5205
				return $result;
5206
 
5207
				}#if end
291 liveuser 5208
 
5209
			#修正 zone file 的權限
5210
			#函式說明:
5211
			#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
5212
			#回傳結果:
5213
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5214
			#$result["error"],錯誤訊息.
5215
			#$result["function"],當前執行的函式名稱.
5216
			#$result["cmd"],執行的指令.
5217
			#必填參數:
5218
			#$conf["owner"],字串,要變哪個使用者擁有.
5219
			$conf["cmd::chown"]["owner"]="root";
5220
			#$conf["target"],字串,需要變更擁有者、 群組的目標.
5221
			$conf["cmd::chown"]["target"]=$conf["dnsRecordFile"];
5222
			#可省略參數:
5223
			#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
5224
			$conf["cmd::chown"]["group"]=webUser;
5225
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
5226
			#$conf["recursive"]="true";
5227
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
5228
			#$conf["excludeSelf"]="true";
5229
			#參考資料:
5230
			#無.
5231
			#備註:
5232
			#無.
5233
			$chown=cmd::chown($conf["cmd::chown"]);
5234
			unset($conf["cmd::chown"]);
249 liveuser 5235
 
291 liveuser 5236
			#如果執行異常
5237
			if($chown["status"]==="false"){
5238
 
5239
				#設置錯誤識別
5240
				$result["status"]="false";
5241
 
5242
				#設置錯誤訊息
5243
				$result["error"]=$chown;
5244
 
5245
				#回傳結果
5246
				return $result;
5247
 
5248
				}#if end
5249
 
5250
			#函式說明:
5251
			#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
5252
			#回傳結果:
5253
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5254
			#$result["error"],錯誤訊息.
5255
			#$result["function"],當前執行的函式名稱.
5256
			#$result["cmd"],執行的指令.
5257
			#必填參數:
5258
			#$conf["mode"],字串,要變成什麼權限.
5259
			$conf["cmd::chmod"]["mode"]="774";
5260
			#$conf["target"],字串,需要變更權限的目標.
5261
			$conf["cmd::chmod"]["target"]=$conf["dnsRecordFile"];
5262
			#可省略參數:
5263
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
5264
			#$conf["recursive"]="true";
5265
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
5266
			#$conf["excludeSelf"]="true";
5267
			#參考資料:
5268
			#無.
5269
			#備註:
5270
			#無.
5271
			$chmod=cmd::chmod($conf["cmd::chmod"]);
5272
			unset($conf["cmd::chmod"]);
5273
 
5274
			#如果執行異常
5275
			if($chmod["status"]==="false"){
5276
 
5277
				#設置錯誤識別
5278
				$result["status"]="false";
5279
 
5280
				#設置錯誤訊息
5281
				$result["error"]=$chmod;
5282
 
5283
				#回傳結果
5284
				return $result;
5285
 
5286
				}#if end
5287
 
249 liveuser 5288
			}#if end
5289
 
5290
		#設置執行正常
5291
		$result["status"]="true";
5292
 
5293
		#回傳結果
5294
		return $result;
5295
 
5296
		}#function updateDnsRecordFile end
5297
 
5298
	/*
5299
	#函式說明:
255 liveuser 5300
	#請求驗證已經透過zerossl::createCertificate要求的domain.
249 liveuser 5301
	#回傳結果:
5302
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5303
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5304
	#$result["function"],當前執行的函式名稱.
5305
	#$result["argu"],所使用的參數.
5306
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 5307
	#$result["content"],結果json字串.
249 liveuser 5308
	#必填參數:
5309
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
5310
	$conf["id"]="";
5311
	#可省略參數:
5312
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5313
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5314
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5315
	#$conf["key"]=self::getApiInfo()["apiKey"];
5316
	#參考資料:
255 liveuser 5317
	#https://zerossl.com/documentation/api/verify-domains/
249 liveuser 5318
	#備註:
5319
	#無.
5320
	*/
5321
	public static function verifyDomain(&$conf){
5322
 
5323
		#初始化要回傳的結果
5324
		$result=array();
5325
 
5326
		#設置當其函數名稱
5327
		$result["function"]=__FUNCTION__;
5328
 
5329
		#如果 $conf 不為陣列
5330
		if(gettype($conf)!="array"){
5331
 
5332
			#設置執行失敗
5333
			$result["status"]="false";
5334
 
5335
			#設置執行錯誤訊息
5336
			$result["error"][]="\$conf變數須為陣列形態";
5337
 
5338
			#如果傳入的參數為 null
5339
			if($conf==null){
5340
 
5341
				#設置執行錯誤訊息
5342
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5343
 
5344
				}#if end
5345
 
5346
			#回傳結果
5347
			return $result;
5348
 
5349
			}#if end
5350
 
5351
		#取得參數
5352
		$result["argu"]=$conf;
5353
 
5354
		#檢查參數
5355
		#函式說明:
5356
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5357
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5358
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5359
		#$result["function"],當前執行的函式名稱.
5360
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5361
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5362
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5363
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5364
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5365
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5366
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5367
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5368
		#必填寫的參數:
5369
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5370
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5371
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5372
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5373
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5374
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5375
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5376
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5377
		#可以省略的參數:
5378
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5379
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5380
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5381
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5382
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5383
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
5384
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5385
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5386
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 5387
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
249 liveuser 5388
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5389
		#$conf["arrayCountEqualCheck"][]=array();
5390
		#參考資料來源:
5391
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5392
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5393
		unset($conf["variableCheck::checkArguments"]);
5394
 
5395
		#如果檢查失敗
5396
		if($checkArguments["status"]==="false"){
5397
 
5398
			#設置錯誤識別
5399
			$result["status"]="false";
5400
 
5401
			#設置錯誤訊息
5402
			$result["error"]=$checkArguments;
5403
 
5404
			#回傳結果
5405
			return $result;
5406
 
5407
			}#if end
5408
 
5409
		#如果檢查不通過
5410
		if($checkArguments["passed"]==="false"){
5411
 
5412
			#設置錯誤識別
5413
			$result["status"]="false";
5414
 
5415
			#設置錯誤訊息
5416
			$result["error"]=$checkArguments;
5417
 
5418
			#回傳結果
5419
			return $result;
5420
 
5421
			}#if end
5422
 
5423
		#要傳送的 key -> value
5424
		$postArray=array();
5425
 
5426
		#設置要簽署的domain
5427
		$postArray["validation_method"]="CNAME_CSR_HASH";
5428
 
5429
		#設置要傳送的 json
5430
		$postJson=json_encode($postArray);
5431
 
5432
		#函式說明:
5433
		#運行curl cmd
5434
		#回傳結果:
5435
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5436
		#$result["error"],錯誤訊息陣列.
5437
		#$result["function"],當前執行的函式名稱.
5438
		#$result["founded"],識別網址找不找得到.
5439
		#$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"代表程序的資訊.
5440
		#$result["fullContent"],取得回應的完整字串內容.
5441
		#$result["cookie"],cookie檔案的位置與名稱.
5442
		#$result["cmd"],執行的command.
5443
		#$result["argu],使用的參數.
5444
		#必填參數:
5445
		#$conf["url"],字串,目標url.
255 liveuser 5446
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
249 liveuser 5447
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5448
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5449
		#可省略參數:
5450
		#$conf["header"],字串陣列,要傳送的header.
5451
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5452
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5453
		#$conf["allowAnySSLcertificate"]="";
5454
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5455
		#$conf["postVar"]=array();
5456
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5457
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5458
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5459
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5460
		#$conf["agent"],字串,user agent的名稱.
5461
		#$conf["agent"]="";
5462
		#$conf["cookie"],字串,cookie位置與檔案位置.
5463
		#$conf["cookie"]="";
5464
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5465
		#$conf["forceNewCookie"]="";
5466
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5467
		#$conf["inBg"]="true";
5468
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5469
		#$conf["bgInProc"]="false";
5470
		#參考資料:
5471
		#無.
5472
		#備註:
5473
		#無.
5474
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5475
		unset($conf["catchWebContent::curlCmd"]);
5476
 
5477
		#如果異常
5478
		if($curlCmd["status"]==="false"){
5479
 
5480
			#設置錯誤識別
5481
			$result["status"]="false";
5482
 
5483
			#設置錯誤訊息
5484
			$result["error"]=$curlCmd;
5485
 
5486
			#回傳結果
5487
			return $result;
5488
 
5489
			}#if end
5490
 
5491
		#設置curl的詳細資訊
5492
		$result["curl_verbose_info"]=$curlCmd;
5493
 
255 liveuser 5494
		#驗證結果是否為 json
5495
		$json_validate=json_validate($curlCmd["fullContent"]);
5496
 
5497
		#如果回應不是 json
5498
		if(!$json_validate){
249 liveuser 5499
 
255 liveuser 5500
			#設置錯誤識別
5501
			$result["status"]="false";
5502
 
5503
			#設置錯誤訊息
5504
			$result["error"]=$curlCmd;
5505
 
5506
			#回傳結果
5507
			return $result;
5508
 
5509
			}#if end
5510
 
5511
		#設置json string結果
5512
		$result["content"]=$curlCmd["fullContent"];
5513
 
5514
		#解析json
5515
		$jsonRes=json_decode($result["content"]);
5516
 
293 liveuser 5517
		#如果有 success 資訊
5518
		if(isset($jsonRes->success)){
255 liveuser 5519
 
293 liveuser 5520
			#do nothing
5521
 
5522
			}#if end
5523
 
5524
		#反之如果沒有 status
5525
		else if(!isset($jsonRes->status)){
5526
 
255 liveuser 5527
			#設置錯誤識別
5528
			$result["status"]="false";
5529
 
5530
			#設置錯誤訊息
5531
			$result["error"]=$curlCmd;
5532
 
5533
			#回傳結果
5534
			return $result;
5535
 
5536
			}#if end
5537
 
293 liveuser 5538
		#反之有 status 資訊
5539
		else{
255 liveuser 5540
 
293 liveuser 5541
			#如果是 "pending_validation"
5542
			if($jsonRes->status==="pending_validation"){
255 liveuser 5543
 
293 liveuser 5544
				#do nothing
255 liveuser 5545
 
293 liveuser 5546
				}#if end
5547
 
5548
			#反之如果為 "issued"
5549
			else if($jsonRes->status==="issued"){
5550
 
5551
				#do nothing
5552
 
5553
				}#else 
5554
 
5555
			#反之
5556
			else{
5557
 
5558
				#設置錯誤識別
5559
				$result["status"]="false";
255 liveuser 5560
 
293 liveuser 5561
				#設置錯誤訊息
5562
				$result["error"]=$curlCmd;
255 liveuser 5563
 
293 liveuser 5564
				#回傳結果
5565
				return $result;
5566
 
5567
				}#else end
255 liveuser 5568
 
5569
			}#else end
5570
 
5571
		#設置執行正常
5572
		$result["status"]="true";
5573
 
5574
		#回傳結果
5575
		return $result;
5576
 
5577
		}#function verifyDomain end
5578
 
5579
	/*
5580
	#函式說明:
5581
	#取得CSR在zerossl上的狀態
5582
	#回傳結果:
5583
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5584
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5585
	#$result["function"],當前執行的函式名稱.
5586
	#$result["argu"],所使用的參數.
5587
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5588
	#$result["content"],結果json字串.
5589
	#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5590
	#必填參數:
5591
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
5592
	$conf["id"]="";
5593
	#可省略參數:
5594
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5595
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5596
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5597
	#$conf["key"]=self::getApiInfo()["apiKey"];
5598
	#參考資料:
5599
	#https://zerossl.com/documentation/api/get-certificate/
5600
	#備註:
5601
	#無.
5602
	*/
5603
	public static function getCertSta(&$conf){
5604
 
5605
		#初始化要回傳的結果
5606
		$result=array();
5607
 
5608
		#設置當其函數名稱
5609
		$result["function"]=__FUNCTION__;
5610
 
5611
		#如果 $conf 不為陣列
5612
		if(gettype($conf)!="array"){
5613
 
5614
			#設置執行失敗
5615
			$result["status"]="false";
5616
 
5617
			#設置執行錯誤訊息
5618
			$result["error"][]="\$conf變數須為陣列形態";
5619
 
5620
			#如果傳入的參數為 null
5621
			if($conf==null){
5622
 
5623
				#設置執行錯誤訊息
5624
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5625
 
5626
				}#if end
5627
 
5628
			#回傳結果
5629
			return $result;
5630
 
5631
			}#if end
5632
 
5633
		#取得參數
5634
		$result["argu"]=$conf;
291 liveuser 5635
 
5636
		#DEBUG
5637
		#var_dump(__LINE__,self::getApiInfo());exit;
255 liveuser 5638
 
5639
		#檢查參數
5640
		#函式說明:
5641
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5642
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5643
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5644
		#$result["function"],當前執行的函式名稱.
5645
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5646
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5647
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5648
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5649
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5650
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5651
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5652
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5653
		#必填寫的參數:
5654
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5655
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5656
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5657
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5658
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5659
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5660
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5661
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5662
		#可以省略的參數:
5663
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5664
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5665
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5666
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5667
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5668
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
5669
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5670
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5671
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5672
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
5673
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5674
		#$conf["arrayCountEqualCheck"][]=array();
5675
		#參考資料來源:
5676
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5677
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5678
		unset($conf["variableCheck::checkArguments"]);
5679
 
5680
		#如果檢查失敗
5681
		if($checkArguments["status"]==="false"){
5682
 
5683
			#設置錯誤識別
5684
			$result["status"]="false";
5685
 
5686
			#設置錯誤訊息
5687
			$result["error"]=$checkArguments;
5688
 
5689
			#回傳結果
5690
			return $result;
5691
 
5692
			}#if end
5693
 
5694
		#如果檢查不通過
5695
		if($checkArguments["passed"]==="false"){
5696
 
5697
			#設置錯誤識別
5698
			$result["status"]="false";
5699
 
5700
			#設置錯誤訊息
5701
			$result["error"]=$checkArguments;
5702
 
5703
			#回傳結果
5704
			return $result;
5705
 
5706
			}#if end
5707
 
5708
		#函式說明:
5709
		#運行curl cmd
5710
		#回傳結果:
5711
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5712
		#$result["error"],錯誤訊息陣列.
5713
		#$result["function"],當前執行的函式名稱.
5714
		#$result["founded"],識別網址找不找得到.
5715
		#$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"代表程序的資訊.
5716
		#$result["fullContent"],取得回應的完整字串內容.
5717
		#$result["cookie"],cookie檔案的位置與名稱.
5718
		#$result["cmd"],執行的command.
5719
		#$result["argu],使用的參數.
5720
		#必填參數:
5721
		#$conf["url"],字串,目標url.
5722
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
5723
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5724
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5725
		#可省略參數:
5726
		#$conf["header"],字串陣列,要傳送的header.
5727
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5728
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5729
		#$conf["allowAnySSLcertificate"]="";
5730
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5731
		#$conf["postVar"]=array();
5732
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5733
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5734
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5735
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5736
		#$conf["agent"],字串,user agent的名稱.
5737
		#$conf["agent"]="";
5738
		#$conf["cookie"],字串,cookie位置與檔案位置.
5739
		#$conf["cookie"]="";
5740
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5741
		#$conf["forceNewCookie"]="";
5742
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5743
		#$conf["inBg"]="true";
5744
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5745
		#$conf["bgInProc"]="false";
5746
		#參考資料:
5747
		#無.
5748
		#備註:
5749
		#無.
5750
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5751
		unset($conf["catchWebContent::curlCmd"]);
5752
 
5753
		#如果異常
5754
		if($curlCmd["status"]==="false"){
5755
 
5756
			#設置錯誤識別
5757
			$result["status"]="false";
5758
 
5759
			#設置錯誤訊息
5760
			$result["error"]=$curlCmd;
5761
 
5762
			#回傳結果
5763
			return $result;
5764
 
5765
			}#if end
5766
 
5767
		#設置curl的詳細資訊
5768
		$result["curl_verbose_info"]=$curlCmd;
5769
 
5770
		#驗證結果是否為 json
5771
		$json_validate=json_validate($curlCmd["fullContent"]);
5772
 
5773
		#如果回應不是 json
5774
		if(!$json_validate){
5775
 
5776
			#設置錯誤識別
5777
			$result["status"]="false";
5778
 
5779
			#設置錯誤訊息
5780
			$result["error"]=$curlCmd;
5781
 
5782
			#回傳結果
5783
			return $result;
5784
 
5785
			}#if end
5786
 
5787
		#設置json string結果
5788
		$result["content"]=$curlCmd["fullContent"];
5789
 
5790
		#解析json
5791
		$jsonRes=json_decode($result["content"]);
5792
 
5793
		#如果沒有 status
5794
		if(!isset($jsonRes->status)){
5795
 
5796
			#設置錯誤識別
5797
			$result["status"]="false";
5798
 
5799
			#設置錯誤訊息
5800
			$result["error"]=$curlCmd;
5801
 
5802
			#回傳結果
5803
			return $result;
5804
 
5805
			}#if end
5806
 
5807
		#取得csr在zerossl上的狀態
5808
		$result["cerStatus"]=$jsonRes->status;
5809
 
5810
		#設置執行正常
5811
		$result["status"]="true";
5812
 
5813
		#回傳結果
5814
		return $result;
5815
 
5816
		}#function getCertSta end
5817
 
5818
	/*
5819
	#函式說明:
5820
	#取得在zerossl上的CSR清單
5821
	#回傳結果:
5822
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5823
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5824
	#$result["function"],當前執行的函式名稱.
5825
	#$result["argu"],所使用的參數.
5826
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5827
	#$result["content"],結果json字串.
5828
	#$result["tCount"],總共的資料筆數.
5829
	#$result["count"],該頁的筆數.
5830
	#$result["page"],當前的頁碼.
5831
	#$result["certs"],陣列,certificates清單,key為certificate的id.
5832
	#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
5833
	#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
5834
	#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
5835
	#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
5836
	#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5837
	#必填參數:
5838
	#無
5839
	#可省略參數:
5840
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5841
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5842
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5843
	#$conf["key"]=self::getApiInfo()["apiKey"];
5844
	#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5845
	#$conf["cerStatus"]="";
309 liveuser 5846
	#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;"multiDomain90Days"多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
255 liveuser 5847
	#$conf["cerType"]="";
5848
	#$conf["search"],字串,透過certificate包含的domain來搜尋.
5849
	#$conf["search"]="";
5850
	#$conf["limit"],字串,一頁要多少筆,預設為100筆.
5851
	#$conf["limit"]="";
5852
	#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
5853
	#$conf["page"]="";
5854
	#參考資料:
5855
	#https://zerossl.com/documentation/api/list-certificates/
5856
	#備註:
5857
	#無.
5858
	*/
5859
	public static function getCertList(&$conf){
5860
 
5861
		#初始化要回傳的結果
5862
		$result=array();
5863
 
5864
		#設置當其函數名稱
5865
		$result["function"]=__FUNCTION__;
5866
 
5867
		#如果 $conf 不為陣列
5868
		if(gettype($conf)!="array"){
5869
 
5870
			#設置執行失敗
5871
			$result["status"]="false";
5872
 
5873
			#設置執行錯誤訊息
5874
			$result["error"][]="\$conf變數須為陣列形態";
5875
 
5876
			#如果傳入的參數為 null
5877
			if($conf==null){
5878
 
5879
				#設置執行錯誤訊息
5880
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5881
 
5882
				}#if end
5883
 
5884
			#回傳結果
5885
			return $result;
5886
 
5887
			}#if end
5888
 
5889
		#取得參數
5890
		$result["argu"]=$conf;
5891
 
5892
		#檢查參數
5893
		#函式說明:
5894
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5895
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5896
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5897
		#$result["function"],當前執行的函式名稱.
5898
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5899
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5900
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5901
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5902
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5903
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5904
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5905
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5906
		#必填寫的參數:
5907
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5908
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5909
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5910
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5911
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5912
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5913
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5914
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5915
		#可以省略的參數:
5916
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5917
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5918
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5919
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5920
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5921
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
5922
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5923
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
5924
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5925
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
5926
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5927
		#$conf["arrayCountEqualCheck"][]=array();
5928
		#參考資料來源:
5929
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5930
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5931
		unset($conf["variableCheck::checkArguments"]);
5932
 
5933
		#如果檢查失敗
5934
		if($checkArguments["status"]==="false"){
5935
 
5936
			#設置錯誤識別
5937
			$result["status"]="false";
5938
 
5939
			#設置錯誤訊息
5940
			$result["error"]=$checkArguments;
5941
 
5942
			#回傳結果
5943
			return $result;
5944
 
5945
			}#if end
5946
 
5947
		#如果檢查不通過
5948
		if($checkArguments["passed"]==="false"){
5949
 
5950
			#設置錯誤識別
5951
			$result["status"]="false";
5952
 
5953
			#設置錯誤訊息
5954
			$result["error"]=$checkArguments;
5955
 
5956
			#回傳結果
5957
			return $result;
5958
 
5959
			}#if end
5960
 
5961
		#預設網址
291 liveuser 5962
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."?access_key=".$conf["key"];
255 liveuser 5963
 
5964
		#如果有設置 cerStatus
5965
		if(isset($conf["cerStatus"])){
5966
 
5967
			#設置 certificate_status 
291 liveuser 5968
			$url=$url."&certificate_status=".urlencode($conf["cerStatus"]);
255 liveuser 5969
 
5970
			}#if end
5971
 
5972
		#如果有設置 cerType
5973
		if(isset($conf["cerType"])){
5974
 
5975
			#設置 certificate_type
291 liveuser 5976
			$url=$url."&certificate_type=".urlencode($conf["cerType"]);
255 liveuser 5977
 
5978
			}#if end
5979
 
5980
		#如果有設置 search
5981
		if(isset($conf["search"])){
5982
 
5983
			#設置 search
291 liveuser 5984
			$url=$url."&search=".urlencode($conf["search"]);
255 liveuser 5985
 
5986
			}#if end
5987
 
5988
		#如果有設置 limit
5989
		if(isset($conf["limit"])){
5990
 
5991
			#設置 search
291 liveuser 5992
			$url=$url."&limit=".urlencode($conf["limit"]);
255 liveuser 5993
 
5994
			}#if end
5995
 
5996
		#如果有設置 page
5997
		if(isset($conf["page"])){
5998
 
5999
			#設置 search
291 liveuser 6000
			$url=$url."&"."page=".urlencode($conf["page"]);
255 liveuser 6001
 
6002
			}#if end
6003
 
6004
		#函式說明:
6005
		#運行curl cmd
6006
		#回傳結果:
6007
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6008
		#$result["error"],錯誤訊息陣列.
6009
		#$result["function"],當前執行的函式名稱.
6010
		#$result["founded"],識別網址找不找得到.
6011
		#$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"代表程序的資訊.
6012
		#$result["fullContent"],取得回應的完整字串內容.
6013
		#$result["cookie"],cookie檔案的位置與名稱.
6014
		#$result["cmd"],執行的command.
6015
		#$result["argu],使用的參數.
6016
		#必填參數:
6017
		#$conf["url"],字串,目標url.
6018
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6019
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6020
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6021
		#可省略參數:
6022
		#$conf["header"],字串陣列,要傳送的header.
6023
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
6024
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6025
		#$conf["allowAnySSLcertificate"]="";
6026
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6027
		#$conf["postVar"]=array();
6028
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6029
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6030
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
6031
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
6032
		#$conf["agent"],字串,user agent的名稱.
6033
		#$conf["agent"]="";
6034
		#$conf["cookie"],字串,cookie位置與檔案位置.
6035
		#$conf["cookie"]="";
6036
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6037
		#$conf["forceNewCookie"]="";
6038
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6039
		#$conf["inBg"]="true";
6040
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6041
		#$conf["bgInProc"]="false";
6042
		#參考資料:
6043
		#無.
6044
		#備註:
6045
		#無.
6046
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6047
		unset($conf["catchWebContent::curlCmd"]);
6048
 
6049
		#如果異常
6050
		if($curlCmd["status"]==="false"){
6051
 
6052
			#設置錯誤識別
6053
			$result["status"]="false";
6054
 
6055
			#設置錯誤訊息
6056
			$result["error"]=$curlCmd;
6057
 
6058
			#回傳結果
6059
			return $result;
6060
 
6061
			}#if end
6062
 
6063
		#設置curl的詳細資訊
6064
		$result["curl_verbose_info"]=$curlCmd;
6065
 
6066
		#驗證結果是否為 json
6067
		$json_validate=json_validate($curlCmd["fullContent"]);
6068
 
6069
		#如果回應不是 json
6070
		if(!$json_validate){
6071
 
6072
			#設置錯誤識別
6073
			$result["status"]="false";
6074
 
6075
			#設置錯誤訊息
6076
			$result["error"]=$curlCmd;
6077
 
6078
			#回傳結果
6079
			return $result;
6080
 
6081
			}#if end
6082
 
6083
		#設置json string結果
6084
		$result["content"]=$curlCmd["fullContent"];
6085
 
6086
		/* json response 範例
6087
		{
6088
			"total_count": 11,
6089
			"result_count": 10,
6090
			"page": 1,
6091
			"limit": 10,
6092
			"acmeUsageLevel": "LOW",
6093
			"isAcmeLocked": false,
6094
			"results": 
6095
			[
6096
				{
6097
					"id": "a856a39a1c3ad0s8asa606g37667d221",
6098
					"type": "1",
6099
					"common_name": "domain.com",
6100
					"additional_domains": "www.domain.com",
6101
					"created": "2020-04-29 09:04:19",
6102
					"expires": "2020-07-28 00:00:00",
6103
					"status": "draft",
6104
					"validation_type": null,
6105
					"validation_emails": null,
6106
					"replacement_for": "",
6107
					"fingerprint_sha1": null,
6108
					"brand_validation": null,
6109
					"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
6110
					"validation":
6111
					{
6112
						"email_validation":
6113
						{
6114
							"domain.com":
6115
							[
6116
								"admin@domain.com",
6117
								"administrator@domain.com",
6118
								"hostmaster@domain.com",
6119
								"postmaster@domain.com",
6120
								"webmaster@domain.com"
6121
							]
6122
						},
6123
						"other_methods": 
6124
						{
6125
							"domain.com":
6126
							{
6127
								"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
6128
								"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
6129
								"file_validation_content":
6130
								[
6131
									"2B449B722B449B729394793947",
6132
									"comodoca.com",
6133
									"4bad7360c7076ba"
6134
								],
6135
								"cname_validation_p1": "2B449B7293947.domain.com",
6136
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
6137
							},
6138
							"www.domain.com":
6139
							{
6140
								"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
6141
								"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",   
6142
								"file_validation_content":
6143
								[
6144
									"2B449B722B449B729394793947",
6145
									"comodoca.com",
6146
									"4bad7360c7076ba"
6147
								],
6148
								"cname_validation_p1": "2B449B7293947.www.domain.com",
6149
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
6150
							}
6151
						}
6152
					}
6153
				},
6154
				{
6155
					...
6156
				}
6157
			]
6158
		}
249 liveuser 6159
		*/
6160
 
255 liveuser 6161
		#解析json
6162
		$jsonRes=json_decode($result["content"]);
6163
 
6164
		#總共的資料筆數
6165
		$result["tCount"]=$jsonRes->total_count;
6166
 
6167
		#取得該頁的筆數
6168
		$result["count"]=$jsonRes->result_count;
6169
 
6170
		#取得certificate清單
291 liveuser 6171
		$certs=$jsonRes->results;
255 liveuser 6172
 
6173
		#針對每個certificate
6174
		foreach($certs as $index => $cert){
6175
 
6176
			#初始化暫存的陣列
6177
			$tmpA=array();
6178
 
6179
			#儲存 cert id
6180
			#$tmpA["id"]=$cert->id;
6181
 
6182
			#儲存 主要包含的 domain name
6183
			$tmpA["cname"]=$cert->common_name;
6184
 
6185
			#儲存額外包含的 domain name
6186
			$tmpA["anames"]=$cert->additional_domains;
6187
 
6188
			#最後有效年月日,格式為"2020-07-28 00:00:00".
6189
			$tmpA["expiresYMD"]=$cert->expires;
6190
 
6191
			#產生對於當前系統時間的差距(秒數)
6192
			#函式說明:
6193
			#計算時間點距離1970/01/01多少秒,亦即unixtime.
6194
			#回傳結果:
6195
			#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
6196
			#$result["error"],錯誤訊息陣列.
6197
			#$result["content"],時間點距離1970/01/01的多少秒.
6198
			#$result["argu"],使用的參數.
6199
			#$result["unixtime"],執行本函式時的unixtime.
6200
			#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
6201
			#必填參數:
6202
			#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
6203
			$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
6204
			#可省略參數:
6205
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
6206
			#$conf["UTC"]="false";
6207
			#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
6208
			$conf["time::caculateTimeAmount"]["replace0"]="false";
6209
			#參考資料:
6210
			#無.
6211
			#備註:
6212
			#無.
6213
			$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
6214
			unset($conf["time::caculateTimeAmount"]);
6215
 
6216
			#如果執行異常
291 liveuser 6217
			if($caculateTimeAmount["status"]==="false"){
255 liveuser 6218
 
6219
				#設置錯誤識別
6220
				$result["status"]="false";
6221
 
6222
				#設置錯誤訊息
6223
				$result["error"]=$caculateTimeAmount;
6224
 
6225
				#回傳結果
6226
				return $result;
6227
 
6228
				}#if end
6229
 
6230
			#儲存還要多少秒要過期
291 liveuser 6231
			$tmpA["expiresIn"]=$caculateTimeAmount["content"]-time();
255 liveuser 6232
 
6233
			#憑證的狀態
6234
			$tmpA["status"]=$cert->status;
6235
 
291 liveuser 6236
			#儲存要回傳的 certs 清單,key為cert的id.
6237
			$result["certs"][$cert->id]=$tmpA;
255 liveuser 6238
 
6239
			}#foreach end
6240
 
6241
		#設置執行正常
6242
		$result["status"]="true";
6243
 
6244
		#回傳結果
6245
		return $result;
6246
 
6247
		}#function getCertList end
6248
 
6249
	/*
6250
	#函式說明:
6251
	#下載certificate.
6252
	#回傳結果:
6253
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6254
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6255
	#$result["function"],當前執行的函式名稱.
6256
	#$result["argu"],所使用的參數.
6257
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6258
	#$result["content"],結果json字串.
6259
	#$result["certificate.crt"],字串,certificate.crt的內容.
6260
	#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
6261
	#必填參數:
6262
	#無.
6263
	#可省略參數:
6264
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6265
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6266
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6267
	#$conf["key"]=self::getApiInfo()["apiKey"];
6268
	#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
6269
	#$conf["id"]="";
6270
	#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
6271
	#$conf["cname"]="";
6272
	#參考資料:
6273
	#https://zerossl.com/documentation/api/download-certificate-inline/
6274
	#備註:
6275
	#無.
6276
	*/
6277
	public static function getCert(&$conf){
6278
 
6279
		#初始化要回傳的結果
6280
		$result=array();
6281
 
6282
		#設置當其函數名稱
6283
		$result["function"]=__FUNCTION__;
6284
 
6285
		#如果 $conf 不為陣列
6286
		if(gettype($conf)!="array"){
6287
 
6288
			#設置執行失敗
6289
			$result["status"]="false";
6290
 
6291
			#設置執行錯誤訊息
6292
			$result["error"][]="\$conf變數須為陣列形態";
6293
 
6294
			#如果傳入的參數為 null
6295
			if($conf==null){
6296
 
6297
				#設置執行錯誤訊息
6298
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6299
 
6300
				}#if end
6301
 
6302
			#回傳結果
6303
			return $result;
6304
 
6305
			}#if end
6306
 
6307
		#取得參數
6308
		$result["argu"]=$conf;
6309
 
6310
		#檢查參數
6311
		#函式說明:
6312
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6313
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6314
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6315
		#$result["function"],當前執行的函式名稱.
6316
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6317
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6318
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6319
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6320
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6321
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6322
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6323
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6324
		#必填寫的參數:
6325
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6326
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6327
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6328
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6329
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6330
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6331
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6332
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6333
		#可以省略的參數:
6334
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6335
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6336
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6337
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6338
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6339
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
6340
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6341
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
6342
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6343
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
6344
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6345
		#$conf["arrayCountEqualCheck"][]=array();
6346
		#參考資料來源:
6347
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6348
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6349
		unset($conf["variableCheck::checkArguments"]);
6350
 
6351
		#如果檢查失敗
6352
		if($checkArguments["status"]==="false"){
6353
 
6354
			#設置錯誤識別
6355
			$result["status"]="false";
6356
 
6357
			#設置錯誤訊息
6358
			$result["error"]=$checkArguments;
6359
 
6360
			#回傳結果
6361
			return $result;
6362
 
6363
			}#if end
6364
 
6365
		#如果檢查不通過
6366
		if($checkArguments["passed"]==="false"){
6367
 
6368
			#設置錯誤識別
6369
			$result["status"]="false";
6370
 
6371
			#設置錯誤訊息
6372
			$result["error"]=$checkArguments;
6373
 
6374
			#回傳結果
6375
			return $result;
6376
 
6377
			}#if end
6378
 
6379
		#如果有設置 id
6380
		if(isset($conf["id"])){
6381
 
6382
			#設置 id
6383
			$id=$conf["id"];
6384
 
6385
			}#if end
6386
 
6387
		#反之如果有設置 cname
6388
		else if(isset($conf["cname"])){
6389
 
6390
			#函式說明:
6391
			#取得在zerossl上的CSR清單
6392
			#回傳結果:
6393
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6394
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
6395
			#$result["function"],當前執行的函式名稱.
6396
			#$result["argu"],所使用的參數.
6397
			#$result["curl_verbose_info"],curl執行的詳細資訊.
6398
			#$result["content"],結果json字串.
6399
			#$result["tCound"],總共的資料筆數.
6400
			#$result["count"],該頁的筆數.
6401
			#$result["page"],當前的頁碼.
6402
			#$result["certs"],陣列,certificates清單,key為certificate的id.
6403
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
6404
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
6405
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
6406
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6407
			#必填參數:
6408
			#無
6409
			#可省略參數:
6410
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6411
			#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6412
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6413
			#$conf["key"]=self::getApiInfo()["apiKey"];
6414
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6415
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
6416
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
6417
			#$conf["cerType"]="";
6418
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
6419
			$conf["zerossl::getCertList"]["search"]=$conf["cname"];
6420
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
6421
			#$conf["limit"]="";
6422
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
6423
			#$conf["page"]="";
6424
			#參考資料:
6425
			#https://zerossl.com/documentation/api/get-certificate/
6426
			#備註:
6427
			#無.
6428
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
6429
			unset($conf["zerossl::getCertList"]);
6430
 
6431
			#如果檢查失敗
6432
			if($getCertList["status"]==="false"){
6433
 
6434
				#設置錯誤識別
6435
				$result["status"]="false";
6436
 
6437
				#設置錯誤訊息
6438
				$result["error"]=$getCertList;
6439
 
6440
				#回傳結果
6441
				return $result;
6442
 
6443
				}#if end
6444
 
6445
			#如果資料筆數大於0
6446
			if($getCertList["count"]>0){
6447
 
6448
				#取得第一筆
6449
				foreach($getCertList["certs"] as $cerId => $detail){
6450
 
6451
					#取得cettificate id
6452
					$id=$cerId;
6453
 
6454
					}#foreach end
6455
 
6456
				}#if end
6457
 
6458
			}#if end
6459
 
6460
		#預設網址
6461
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
6462
 
6463
		#函式說明:
6464
		#運行curl cmd
6465
		#回傳結果:
6466
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6467
		#$result["error"],錯誤訊息陣列.
6468
		#$result["function"],當前執行的函式名稱.
6469
		#$result["founded"],識別網址找不找得到.
6470
		#$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"代表程序的資訊.
6471
		#$result["fullContent"],取得回應的完整字串內容.
6472
		#$result["cookie"],cookie檔案的位置與名稱.
6473
		#$result["cmd"],執行的command.
6474
		#$result["argu],使用的參數.
6475
		#必填參數:
6476
		#$conf["url"],字串,目標url.
6477
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6478
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6479
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6480
		#可省略參數:
6481
		#$conf["header"],字串陣列,要傳送的header.
6482
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
6483
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6484
		#$conf["allowAnySSLcertificate"]="";
6485
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6486
		#$conf["postVar"]=array();
6487
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6488
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6489
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
6490
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
6491
		#$conf["agent"],字串,user agent的名稱.
6492
		#$conf["agent"]="";
6493
		#$conf["cookie"],字串,cookie位置與檔案位置.
6494
		#$conf["cookie"]="";
6495
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6496
		#$conf["forceNewCookie"]="";
6497
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6498
		#$conf["inBg"]="true";
6499
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6500
		#$conf["bgInProc"]="false";
6501
		#參考資料:
6502
		#無.
6503
		#備註:
6504
		#無.
6505
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6506
		unset($conf["catchWebContent::curlCmd"]);
6507
 
6508
		#如果異常
6509
		if($curlCmd["status"]==="false"){
6510
 
6511
			#設置錯誤識別
6512
			$result["status"]="false";
6513
 
6514
			#設置錯誤訊息
6515
			$result["error"]=$curlCmd;
6516
 
6517
			#回傳結果
6518
			return $result;
6519
 
6520
			}#if end
6521
 
6522
		#設置curl的詳細資訊
6523
		$result["curl_verbose_info"]=$curlCmd;
6524
 
249 liveuser 6525
		#驗證結果是否為 json
6526
		$json_validate=json_validate($curlCmd["fullContent"]);
6527
 
6528
		#如果回應不是 json
6529
		if(!$json_validate){
6530
 
6531
			#設置錯誤識別
6532
			$result["status"]="false";
6533
 
6534
			#設置錯誤訊息
6535
			$result["error"]=$curlCmd;
6536
 
6537
			#回傳結果
6538
			return $result;
6539
 
6540
			}#if end
6541
 
6542
		#設置json string結果
6543
		$result["content"]=$curlCmd["fullContent"];
255 liveuser 6544
 
6545
		#取得 json
6546
		$json=json_decode($curlCmd["fullContent"]);
6547
 
291 liveuser 6548
		#儲存成變數以便透過object呼叫
6549
		$c_crt="certificate.crt";
6550
 
6551
		#儲存成變數以便透過object呼叫
6552
		$ca_crt="ca_bundle.crt";
6553
 
294 liveuser 6554
		#如果沒有該有的 certificate.crt 跟 ca_bundle.crt 物件
6555
		if(!isset($json->$c_crt) || !isset($json->$ca_crt)){
6556
 
6557
			#設置錯誤識別
6558
			$result["status"]="false";
6559
 
6560
			#設置錯誤訊息
6561
			$result["error"]=$json;
6562
 
6563
			#回傳結果
6564
			return $result;
6565
 
6566
			}#if end
6567
 
255 liveuser 6568
		#取得certificate.crt的內容
291 liveuser 6569
		$result["certificate.crt"]=$json->$c_crt;
255 liveuser 6570
 
6571
		#取得ca_bundle.crt的內容
291 liveuser 6572
		$result["ca_bundle.crt"]=$json->$ca_crt;
255 liveuser 6573
 
6574
		#設置執行正常
6575
		$result["status"]="true";
6576
 
6577
		#回傳結果
6578
		return $result;
6579
 
6580
		}#function getCert end
6581
 
6582
	/*
6583
	#函式說明:
6584
	#請求廢除 issued zerossl certificate.
6585
	#回傳結果:
6586
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6587
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6588
	#$result["function"],當前執行的函式名稱.
6589
	#$result["argu"],所使用的參數.
6590
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6591
	#$result["content"],結果json字串.
341 liveuser 6592
	#$result["busy"],若content結果含有busy屬性,且為1,則為"true";反之為"false".
255 liveuser 6593
	#必填參數:
6594
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
6595
	$conf["id"]="";
6596
	#可省略參數:
6597
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6598
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6599
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6600
	#$conf["key"]=self::getApiInfo()["apiKey"];
6601
	#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
6602
	#$conf["reason"]="";
6603
	#參考資料:
6604
	#https://zerossl.com/documentation/api/revoke-certificate/
6605
	#備註:
338 liveuser 6606
	#跟api頁面的描述不同,access_key參數實際上要用get方式傳遞.
341 liveuser 6607
	#跟api頁面的描述不同,api point忙碌中,無法回應時,回應會為空.
255 liveuser 6608
	*/
6609
	public static function revokeCert(&$conf){
6610
 
6611
		#初始化要回傳的結果
6612
		$result=array();
249 liveuser 6613
 
255 liveuser 6614
		#設置當其函數名稱
6615
		$result["function"]=__FUNCTION__;
6616
 
6617
		#如果 $conf 不為陣列
6618
		if(gettype($conf)!="array"){
6619
 
6620
			#設置執行失敗
6621
			$result["status"]="false";
6622
 
6623
			#設置執行錯誤訊息
6624
			$result["error"][]="\$conf變數須為陣列形態";
6625
 
6626
			#如果傳入的參數為 null
6627
			if($conf==null){
6628
 
6629
				#設置執行錯誤訊息
6630
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6631
 
6632
				}#if end
6633
 
6634
			#回傳結果
6635
			return $result;
6636
 
6637
			}#if end
6638
 
6639
		#取得參數
6640
		$result["argu"]=$conf;
6641
 
6642
		#檢查參數
6643
		#函式說明:
6644
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6645
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6646
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6647
		#$result["function"],當前執行的函式名稱.
6648
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6649
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6650
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6651
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6652
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6653
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6654
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6655
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6656
		#必填寫的參數:
6657
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6658
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6659
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6660
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6661
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6662
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6663
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6664
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6665
		#可以省略的參數:
6666
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6667
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6668
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6669
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6670
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6671
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
6672
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
334 liveuser 6673
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
255 liveuser 6674
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6675
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
6676
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6677
		#$conf["arrayCountEqualCheck"][]=array();
6678
		#參考資料來源:
6679
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6680
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6681
		unset($conf["variableCheck::checkArguments"]);
6682
 
6683
		#如果檢查失敗
6684
		if($checkArguments["status"]==="false"){
6685
 
6686
			#設置錯誤識別
6687
			$result["status"]="false";
6688
 
6689
			#設置錯誤訊息
6690
			$result["error"]=$checkArguments;
6691
 
6692
			#回傳結果
6693
			return $result;
6694
 
6695
			}#if end
6696
 
6697
		#如果檢查不通過
6698
		if($checkArguments["passed"]==="false"){
6699
 
6700
			#設置錯誤識別
6701
			$result["status"]="false";
6702
 
6703
			#設置錯誤訊息
6704
			$result["error"]=$checkArguments;
6705
 
6706
			#回傳結果
6707
			return $result;
6708
 
6709
			}#if end
6710
 
338 liveuser 6711
		#url to call,含api key,跟 api 頁面不一致.
6712
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
255 liveuser 6713
 
337 liveuser 6714
		#初始化要post的變數陣列
6715
		$postVar=array();
6716
 
338 liveuser 6717
		#設置  api key,跟 api 頁面不一致.
6718
		#$postVar["access_key"]=$conf["key"];
337 liveuser 6719
 
255 liveuser 6720
		#如果有設置 reason
6721
		if(isset($conf["reason"])){
6722
 
6723
			#設置reason
337 liveuser 6724
			$postVar["reason"]=$conf["reason"];
255 liveuser 6725
 
6726
			}#if end
337 liveuser 6727
 
255 liveuser 6728
		#函式說明:
6729
		#運行curl cmd
6730
		#回傳結果:
6731
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6732
		#$result["error"],錯誤訊息陣列.
6733
		#$result["function"],當前執行的函式名稱.
6734
		#$result["founded"],識別網址找不找得到.
6735
		#$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"代表程序的資訊.
6736
		#$result["fullContent"],取得回應的完整字串內容.
6737
		#$result["cookie"],cookie檔案的位置與名稱.
6738
		#$result["cmd"],執行的command.
6739
		#$result["argu],使用的參數.
6740
		#必填參數:
6741
		#$conf["url"],字串,目標url.
6742
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6743
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6744
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6745
		#可省略參數:
6746
		#$conf["header"],字串陣列,要傳送的header.
338 liveuser 6747
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
255 liveuser 6748
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6749
		#$conf["allowAnySSLcertificate"]="";
338 liveuser 6750
 
6751
		#如果有資料
6752
		if(!empty($postVar)){
6753
 
6754
			#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6755
			$conf["catchWebContent::curlCmd"]["postVar"]=$postVar;
6756
 
6757
			}#if end
6758
 
255 liveuser 6759
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6760
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6761
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
338 liveuser 6762
		$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
255 liveuser 6763
		#$conf["agent"],字串,user agent的名稱.
6764
		#$conf["agent"]="";
6765
		#$conf["cookie"],字串,cookie位置與檔案位置.
6766
		#$conf["cookie"]="";
6767
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6768
		#$conf["forceNewCookie"]="";
6769
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6770
		#$conf["inBg"]="true";
6771
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6772
		#$conf["bgInProc"]="false";
6773
		#參考資料:
6774
		#無.
6775
		#備註:
6776
		#無.
6777
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6778
		unset($conf["catchWebContent::curlCmd"]);
6779
 
6780
		#如果異常
6781
		if($curlCmd["status"]==="false"){
6782
 
6783
			#設置錯誤識別
6784
			$result["status"]="false";
6785
 
6786
			#設置錯誤訊息
6787
			$result["error"]=$curlCmd;
6788
 
6789
			#回傳結果
6790
			return $result;
6791
 
6792
			}#if end
6793
 
6794
		#設置curl的詳細資訊
6795
		$result["curl_verbose_info"]=$curlCmd;
6796
 
341 liveuser 6797
		#如果 server 的回應為空
6798
		if(empty($curlCmd["fullContent"])){
6799
 
6800
			#初始化json回應
6801
			$jsonRes=array();
6802
 
6803
			#設置不成功
6804
			$jsonRes["success"]=0;
6805
 
6806
			#設置server忙碌中,贊述無法處理要求.
6807
			$jsonRes["busy"]=1;
6808
 
6809
			#設置json結果
6810
			$curlCmd["fullContent"]=json_encode($jsonRes);
6811
 
6812
			}#if end
6813
 
255 liveuser 6814
		#驗證結果是否為 json
6815
		$json_validate=json_validate($curlCmd["fullContent"]);
6816
 
6817
		#如果回應不是 json
6818
		if(!$json_validate){
6819
 
6820
			#設置錯誤識別
6821
			$result["status"]="false";
6822
 
6823
			#設置錯誤訊息
6824
			$result["error"]=$curlCmd;
6825
 
6826
			#回傳結果
6827
			return $result;
6828
 
6829
			}#if end
341 liveuser 6830
 
255 liveuser 6831
		#設置json string結果
6832
		$result["content"]=$curlCmd["fullContent"];
6833
 
249 liveuser 6834
		#解析json
6835
		$jsonRes=json_decode($result["content"]);
6836
 
255 liveuser 6837
		#如果沒有要有的attr
6838
		if(!isset($jsonRes->success)){
6839
 
6840
			#設置錯誤識別
6841
			$result["status"]="false";
6842
 
6843
			#設置錯誤訊息
6844
			$result["error"]=$curlCmd;
6845
 
6846
			#回傳結果
6847
			return $result;
6848
 
6849
			}#if end
341 liveuser 6850
 
255 liveuser 6851
		#如果 success 不等於 1
6852
		if($jsonRes->success!==1){
6853
 
341 liveuser 6854
			#如果有 busy 屬性
6855
			if(isset($jsonRes->busy)){
6856
 
6857
				#如果busy為1
6858
				if($jsonRes->busy===1){
6859
 
6860
					#設置sever忙碌中,無法回應.
6861
					$result["busy"]="true";
6862
 
6863
					}#if end
6864
 
6865
				}#if end
6866
 
255 liveuser 6867
			#設置錯誤識別
6868
			$result["status"]="false";
6869
 
6870
			#設置錯誤訊息
6871
			$result["error"]=$curlCmd;
6872
 
6873
			#回傳結果
6874
			return $result;
6875
 
6876
			}#if end
6877
 
341 liveuser 6878
		#如果回應結果不含busy元素
6879
		if(!isset($result["busy"])){
6880
 
6881
			#設置其為"false",代表server沒有忙碌中,無法回應.
6882
			$result["busy"]="false";
6883
 
6884
			}#else end
6885
 
249 liveuser 6886
		#設置執行正常
6887
		$result["status"]="true";
6888
 
6889
		#回傳結果
6890
		return $result;
6891
 
255 liveuser 6892
		}#function revokeCert end
6893
 
6894
	/*
6895
	#函式說明:
6896
	#請求取消 draft or unvalidated zerossl certificate.
6897
	#回傳結果:
6898
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6899
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6900
	#$result["function"],當前執行的函式名稱.
6901
	#$result["argu"],所使用的參數.
6902
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6903
	#$result["content"],結果json字串.
6904
	#必填參數:
6905
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
6906
	$conf["id"]="";
6907
	#可省略參數:
6908
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6909
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6910
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6911
	#$conf["key"]=self::getApiInfo()["apiKey"];
6912
	#參考資料:
6913
	#https://zerossl.com/documentation/api/revoke-certificate/
6914
	#備註:
6915
	#無.
6916
	*/
6917
	public static function cancelCert(&$conf){
6918
 
6919
		#初始化要回傳的結果
6920
		$result=array();
249 liveuser 6921
 
255 liveuser 6922
		#設置當其函數名稱
6923
		$result["function"]=__FUNCTION__;
6924
 
6925
		#如果 $conf 不為陣列
6926
		if(gettype($conf)!="array"){
6927
 
6928
			#設置執行失敗
6929
			$result["status"]="false";
6930
 
6931
			#設置執行錯誤訊息
6932
			$result["error"][]="\$conf變數須為陣列形態";
6933
 
6934
			#如果傳入的參數為 null
6935
			if($conf==null){
6936
 
6937
				#設置執行錯誤訊息
6938
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6939
 
6940
				}#if end
6941
 
6942
			#回傳結果
6943
			return $result;
6944
 
6945
			}#if end
6946
 
6947
		#取得參數
6948
		$result["argu"]=$conf;
6949
 
6950
		#檢查參數
6951
		#函式說明:
6952
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6953
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6954
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6955
		#$result["function"],當前執行的函式名稱.
6956
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6957
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6958
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6959
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6960
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6961
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6962
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6963
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6964
		#必填寫的參數:
6965
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6966
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6967
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6968
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6969
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6970
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6971
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6972
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6973
		#可以省略的參數:
6974
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6975
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6976
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6977
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6978
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6979
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
6980
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6981
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
6982
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6983
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
6984
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6985
		#$conf["arrayCountEqualCheck"][]=array();
6986
		#參考資料來源:
6987
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6988
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6989
		unset($conf["variableCheck::checkArguments"]);
6990
 
6991
		#如果檢查失敗
6992
		if($checkArguments["status"]==="false"){
6993
 
6994
			#設置錯誤識別
6995
			$result["status"]="false";
6996
 
6997
			#設置錯誤訊息
6998
			$result["error"]=$checkArguments;
6999
 
7000
			#回傳結果
7001
			return $result;
7002
 
7003
			}#if end
7004
 
7005
		#如果檢查不通過
7006
		if($checkArguments["passed"]==="false"){
7007
 
7008
			#設置錯誤識別
7009
			$result["status"]="false";
7010
 
7011
			#設置錯誤訊息
7012
			$result["error"]=$checkArguments;
7013
 
7014
			#回傳結果
7015
			return $result;
7016
 
7017
			}#if end
7018
 
7019
		#url to call
7020
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
7021
 
7022
		#函式說明:
7023
		#運行curl cmd
7024
		#回傳結果:
7025
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7026
		#$result["error"],錯誤訊息陣列.
7027
		#$result["function"],當前執行的函式名稱.
7028
		#$result["founded"],識別網址找不找得到.
7029
		#$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"代表程序的資訊.
7030
		#$result["fullContent"],取得回應的完整字串內容.
7031
		#$result["cookie"],cookie檔案的位置與名稱.
7032
		#$result["cmd"],執行的command.
7033
		#$result["argu],使用的參數.
7034
		#必填參數:
7035
		#$conf["url"],字串,目標url.
7036
		$conf["catchWebContent::curlCmd"]["url"]=$url;
7037
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7038
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7039
		#可省略參數:
7040
		#$conf["header"],字串陣列,要傳送的header.
7041
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7042
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7043
		#$conf["allowAnySSLcertificate"]="";
7044
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7045
		#$conf["postVar"]=array();
7046
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7047
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7048
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7049
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7050
		#$conf["agent"],字串,user agent的名稱.
7051
		#$conf["agent"]="";
7052
		#$conf["cookie"],字串,cookie位置與檔案位置.
7053
		#$conf["cookie"]="";
7054
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7055
		#$conf["forceNewCookie"]="";
7056
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7057
		#$conf["inBg"]="true";
7058
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7059
		#$conf["bgInProc"]="false";
7060
		#參考資料:
7061
		#無.
7062
		#備註:
7063
		#無.
7064
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7065
		unset($conf["catchWebContent::curlCmd"]);
7066
 
7067
		#如果異常
7068
		if($curlCmd["status"]==="false"){
7069
 
7070
			#設置錯誤識別
7071
			$result["status"]="false";
7072
 
7073
			#設置錯誤訊息
7074
			$result["error"]=$curlCmd;
7075
 
7076
			#回傳結果
7077
			return $result;
7078
 
7079
			}#if end
7080
 
7081
		#設置curl的詳細資訊
7082
		$result["curl_verbose_info"]=$curlCmd;
7083
 
7084
		#驗證結果是否為 json
7085
		$json_validate=json_validate($curlCmd["fullContent"]);
7086
 
7087
		#如果回應不是 json
7088
		if(!$json_validate){
7089
 
7090
			#設置錯誤識別
7091
			$result["status"]="false";
7092
 
7093
			#設置錯誤訊息
7094
			$result["error"]=$curlCmd;
7095
 
7096
			#回傳結果
7097
			return $result;
7098
 
7099
			}#if end
7100
 
7101
		#設置json string結果
7102
		$result["content"]=$curlCmd["fullContent"];
7103
 
7104
		#解析json
7105
		$jsonRes=json_decode($result["content"]);
7106
 
7107
		#如果沒有要有的attr
7108
		if(!isset($jsonRes->success)){
7109
 
7110
			#設置錯誤識別
7111
			$result["status"]="false";
7112
 
7113
			#設置錯誤訊息
7114
			$result["error"]=$curlCmd;
7115
 
7116
			#回傳結果
7117
			return $result;
7118
 
7119
			}#if end
7120
 
7121
		#如果 success 不等於 1
7122
		if($jsonRes->success!==1){
7123
 
7124
			#設置錯誤識別
7125
			$result["status"]="false";
7126
 
7127
			#設置錯誤訊息
7128
			$result["error"]=$curlCmd;
7129
 
7130
			#回傳結果
7131
			return $result;
7132
 
7133
			}#if end
7134
 
7135
		#設置執行正常
7136
		$result["status"]="true";
7137
 
7138
		#回傳結果
7139
		return $result;
7140
 
7141
		}#function cancelCert end
7142
 
7143
	/*
7144
	#函式說明:
7145
	#透過zerossl api確保ssl沒有過期.
7146
	#回傳結果:
7147
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7148
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7149
	#$result["function"],當前執行的函式名稱.
7150
	#$result["argu"],所使用的參數.
7151
	#必填參數:
7152
	#$conf["cName"],陣列,每個ssl的common domain name.
7153
	$conf["cName"]=array();
7154
	#$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內容合併後的檔案位置與名稱.
7155
	$conf["certInfo"]=array();
7156
	#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
7157
	$conf["rrFile"]=array();
7158
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
7159
	$conf["dnsSerAddr"]=array();
7160
	#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
7161
	$conf["actionAfterUpdateCert"]=array();
7162
	#可省略參數:
288 liveuser 7163
	#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/sslUpdater.sock
7164
	#$conf["sock"]="";
281 liveuser 7165
	#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
7166
	#$conf["debug"]="";
255 liveuser 7167
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7168
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7169
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7170
	#$conf["key"]=self::getApiInfo()["apiKey"];
293 liveuser 7171
	#$conf["multiThreads"],字串,預設為"false"代表不使用多執行序;"true"代表要用多執行序.
7172
	#$conf["multiThreads"]=""
255 liveuser 7173
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
7174
	#$conf["debug"]="";
7175
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
7176
	#$conf["addOnProcessFunc"]=array();
7177
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
7178
	#$conf["funcToRunWhenIdle"]=array();
7179
	#參考資料:
7180
	#無.
7181
	#備註:
7182
	#無.
7183
	*/
7184
	public static function sslUpdater(&$conf){
7185
 
7186
		#初始化要回傳的結果
7187
		$result=array();
7188
 
7189
		#設置當其函數名稱
7190
		$result["function"]=__FUNCTION__;
7191
 
7192
		#如果 $conf 不為陣列
7193
		if(gettype($conf)!="array"){
7194
 
7195
			#設置執行失敗
7196
			$result["status"]="false";
7197
 
7198
			#設置執行錯誤訊息
7199
			$result["error"][]="\$conf變數須為陣列形態";
7200
 
7201
			#如果傳入的參數為 null
7202
			if($conf==null){
7203
 
7204
				#設置執行錯誤訊息
7205
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7206
 
7207
				}#if end
7208
 
7209
			#回傳結果
7210
			return $result;
7211
 
7212
			}#if end
7213
 
7214
		#取得參數
7215
		$result["argu"]=$conf;
288 liveuser 7216
 
7217
		#初始化預設的 unix domain socket 路徑
7218
		$defaultSocket=pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/sslUpdater.sock";
255 liveuser 7219
 
7220
		#檢查參數
7221
		#函式說明:
7222
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7223
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7224
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7225
		#$result["function"],當前執行的函式名稱.
7226
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7227
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7228
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7229
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7230
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7231
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7232
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7233
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7234
		#必填寫的參數:
7235
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7236
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7237
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7238
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
7239
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7240
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
7241
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7242
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7243
		#可以省略的參數:
7244
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7245
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7246
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
293 liveuser 7247
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("multiThreads","sock","debug","apiDomain","key");
255 liveuser 7248
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 7249
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("multiThreads","sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
255 liveuser 7250
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
293 liveuser 7251
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array","array");
255 liveuser 7252
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
293 liveuser 7253
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",$defaultSocket,"false",self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
255 liveuser 7254
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7255
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
7256
		#參考資料來源:
7257
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7258
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7259
		unset($conf["variableCheck::checkArguments"]);
7260
 
7261
		#如果檢查失敗
7262
		if($checkArguments["status"]==="false"){
7263
 
7264
			#設置錯誤識別
7265
			$result["status"]="false";
7266
 
7267
			#設置錯誤訊息
7268
			$result["error"]=$checkArguments;
7269
 
7270
			#回傳結果
7271
			return $result;
7272
 
7273
			}#if end
7274
 
7275
		#如果檢查不通過
7276
		if($checkArguments["passed"]==="false"){
7277
 
7278
			#設置錯誤識別
7279
			$result["status"]="false";
7280
 
7281
			#設置錯誤訊息
7282
			$result["error"]=$checkArguments;
7283
 
7284
			#回傳結果
7285
			return $result;
7286
 
7287
			}#if end
7288
 
7289
		#取得key
7290
		$share["key"]=$conf["key"];
7291
 
7292
		#取得apiDomain
7293
		$share["apiDomain"]=$conf["apiDomain"];
7294
 
281 liveuser 7295
		#設置debug flag
7296
		$share["debug"]=$conf["debug"];
7297
 
293 liveuser 7298
		#設置 multiThreads 
7299
		$share["multiThreads"]=$conf["multiThreads"];
7300
 
255 liveuser 7301
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
7302
		$share["certInfo"]=array();
7303
 
7304
		#針對每個 domain
7305
		foreach($conf["cName"] as $index=>$cName ){
7306
 
7307
			#如果沒有對應的certInfo
7308
			if(!isset($conf["certInfo"][$index])){
7309
 
7310
				#設置錯誤識別
7311
				$result["status"]="false";
7312
 
7313
				#設置錯誤訊息
7314
				$result["error"][]="missing certInfo";
7315
 
7316
				#設置錯誤訊息
7317
				$result["error"][]=$checkArguments;
7318
 
7319
				#回傳結果
7320
				return $result;
7321
 
7322
				}#if end
7323
 
291 liveuser 7324
			#檢查 $conf["certInfo"][$index] 是否資訊都有存在
7325
			#函式說明:
7326
			#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
7327
			#回傳結果:
7328
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7329
			#$result["error"],執行不正常結束的錯訊息陣列.
7330
			#$result["simpleError"],簡單表示的錯誤訊息.
7331
			#$result["function"],當前執行的函式名稱.
7332
			#$result["argu"],設置給予的參數.
7333
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7334
			#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7335
			#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7336
			#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7337
			#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7338
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7339
			#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7340
			#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7341
			#必填參數:
7342
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7343
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["certInfo"][$index];
7344
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7345
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7346
			#可省略參數:
7347
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7348
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
7349
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
7350
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
7351
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7352
			#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7353
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
7354
			#$conf["canNotBeEmpty"]=array();
7355
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
7356
			#$conf["canBeEmpty"]=array();
7357
			#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
7358
			$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("true","true","true","true");
7359
			#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7360
			$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
7361
			#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7362
			$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
7363
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7364
			$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($conf["cName"][$index]."-certificate.crt",$conf["cName"][$index]."-private.key",$conf["cName"][$index]."-ca_bundle.crt",$conf["cName"][$index]."-certWithCaPath.crt");
7365
			#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
7366
			#$conf["disallowAllSkipableVarIsEmpty"]="";
7367
			#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
7368
			#$conf["disallowAllSkipableVarIsEmptyArray"]="";
7369
			#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
7370
			#$conf["disallowAllSkipableVarNotExist"]="";
7371
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7372
			#$conf["arrayCountEqualCheck"][]=array();
7373
			#參考資料:
7374
			#array_keys=>http://php.net/manual/en/function.array-keys.php
7375
			#備註:
7376
			#無.
7377
			$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7378
			unset($conf["variableCheck::checkArguments"]);
7379
 
7380
			#如果檢查失敗
7381
			if($checkArguments["status"]==="false"){
7382
 
7383
				#設置錯誤識別
7384
				$result["status"]="false";
7385
 
7386
				#設置錯誤訊息
7387
				$result["error"]=$checkArguments;
7388
 
7389
				#回傳結果
7390
				return $result;
7391
 
7392
				}#if end
7393
 
7394
			#如果檢查不通過
7395
			if($checkArguments["passed"]==="false"){
7396
 
7397
				#設置錯誤識別
7398
				$result["status"]="false";
7399
 
7400
				#設置錯誤訊息
7401
				$result["error"]=$checkArguments;
7402
 
7403
				#回傳結果
7404
				return $result;
7405
 
7406
				}#if end
7407
 
7408
			#儲存 cName
7409
			$cInfo["cName"]=$cName;
255 liveuser 7410
 
291 liveuser 7411
			#儲存 RR 檔案的路徑與名稱
7412
			$cInfo["rrFile"]=$conf["rrFile"][$index];
255 liveuser 7413
 
291 liveuser 7414
			#儲存 cName 對應的 dns server addr
7415
			$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
255 liveuser 7416
 
291 liveuser 7417
			#儲存 cName 的憑證更新後要做的事情.
7418
			$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
255 liveuser 7419
 
294 liveuser 7420
			#用 ";" 分割來取得有多少個動作要依序執行
7421
			#函式說明:
7422
			#將固定格式的字串分開,並回傳分開的結果.
7423
			#回傳結果:
7424
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7425
			#$result["error"],錯誤訊息陣列
7426
			#$result["function"],當前執行的函數名稱.
7427
			#$result["argu"],使用的參數.
7428
			#$result["oriStr"],要分割的原始字串內容
7429
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7430
			#$result["dataCounts"],爲總共分成幾段
7431
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
7432
			#必填參數:
7433
			#$conf["stringIn"],字串,要處理的字串.
7434
			$conf["stringProcess::spiltString"]["stringIn"]=$cInfo["actionAfterUpdateCert"];
7435
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
7436
			$conf["stringProcess::spiltString"]["spiltSymbol"]=";";
7437
			#可省略參數:
7438
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
7439
			#$conf["allowEmptyStr"]="false";
7440
			#參考資料:
7441
			#無.
7442
			#備註:
7443
			#無.
7444
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
7445
			unset($conf["stringProcess::spiltString"]);
7446
 
7447
			#如果執行異常
7448
			if($spiltString["status"]==="false"){
7449
 
7450
				#設置錯誤識別
7451
				$result["status"]="false";
7452
 
7453
				#設置錯誤訊息
7454
				$result["error"]=$spiltString;
7455
 
7456
				#回傳結果
7457
				return $result;
7458
 
7459
				}#if end
7460
 
7461
			#如果沒有";"存在,代表格式不對
7462
			if($spiltString["found"]==="false"){
7463
 
7464
				#設置錯誤識別
7465
				$result["status"]="false";
7466
 
7467
				#設置錯誤訊息
7468
				$result["error"]=$spiltString;
7469
 
7470
				#回傳結果
7471
				return $result;
7472
 
7473
				}#if end
7474
 
7475
			#取得每個動作
7476
			$cInfo["actionAfterUpdateCert"]=$spiltString["dataArray"];
7477
 
291 liveuser 7478
			#設置 certPath
7479
			$cInfo["ssl"]["certPath"]=$conf["certInfo"][$index]["certPath"];
255 liveuser 7480
 
291 liveuser 7481
			#設置 pKey
7482
			$cInfo["ssl"]["pKey"]=$conf["certInfo"][$index]["pKey"];
7483
 
7484
			#設置 caPath
7485
			$cInfo["ssl"]["caPath"]=$conf["certInfo"][$index]["caPath"];
7486
 
7487
			#設置 certWithCaPath
7488
			$cInfo["ssl"]["certWithCaPath"]=$conf["certInfo"][$index]["certWithCaPath"];
7489
 
7490
			#儲存 certInfo
7491
			$share["certInfo"][]=$cInfo;
7492
 
255 liveuser 7493
			}#foreach end
7494
 
7495
		#如果為空
7496
		if(empty($share["certInfo"])){
7497
 
7498
			#設置錯誤識別
7499
			$result["status"]="false";
7500
 
7501
			#設置錯誤訊息
7502
			$result["error"][]="certInfo 參數有缺";
7503
 
7504
			#設置錯誤訊息
7505
			$result["error"][]=$checkArguments;
7506
 
7507
			#回傳結果
7508
			return $result;
7509
 
7510
			}#if end
7511
 
7512
		#函式說明:
7513
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
7514
		#回傳結果:
7515
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
7516
		#$result["error"],錯誤訊息陣列.
7517
		#$result["function"],當前執行的函式名稱.
7518
		#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
7519
		#$result["serverCache"]["serverSide"],server side 的 cache.
7520
		#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
7521
		#$result["serverCache"]["clientSide"],client site 的 cache.
7522
		#必填參數:
7523
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
291 liveuser 7524
		$conf["sock::unixDomainSockServer"]["sock"]=$conf["sock"];
255 liveuser 7525
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7526
		$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
7527
		#可省略參數:
7528
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
7529
		$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
7530
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
7531
		$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
7532
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
7533
		#$conf["sessionTimeout"]="300";
7534
		#$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"代表執行不正常.
291 liveuser 7535
		$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("\qbpwcf\zerossl::sslUpdater_cmd");
255 liveuser 7536
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
291 liveuser 7537
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\qbpwcf\zerossl::sslUpdater_idle");
255 liveuser 7538
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
7539
		#$conf["paramsForFuncToRunWhenIdle"]=array();
7540
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7541
		$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
7542
		#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
7543
		#$conf["shutdownStrAddr"]="";
7544
		#參考資料:
7545
		#http://php.net/manual/en/function.stream-socket-server.php
7546
		#備註:
7547
		#無.
7548
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
7549
		unset($conf["sock::unixDomainSockServer"]);
7550
 
7551
		#執行異常
7552
		if($unixDomainSockServer["status"]==="false"){
7553
 
7554
			#設置錯誤識別
7555
			$result["status"]="false";
7556
 
7557
			#設置錯誤訊息
7558
			$result["error"]=$unixDomainSockServer;
7559
 
7560
			#回傳結果
7561
			return $result;
7562
 
7563
			}#if end
7564
 
7565
		#設置執行正常
7566
		$result["status"]="true";
7567
 
7568
		#回傳結果
7569
		return $result;
7570
 
7571
		}#function sslUpdater end
7572
 
7573
	/*
7574
	#函式說明:
7575
	#funcion sslUpdater 於收到訊息時要做的事情.
7576
	#回傳結果:
7577
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7578
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7579
	#$result["function"],當前執行的函式名稱.
7580
	#$result["argu"],所使用的參數.
7581
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
7582
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
7583
	#必填參數:
7584
	#$conf["request"],字串,收到的json訊息.
7585
	$conf["request"]="";
7586
	#$conf["sock"],resource,用戶的socket.
7587
	$conf["sock"]="";
7588
	#$conf["clientCache"],陣列,給予所有用戶的cache.
7589
	$conf["clientCache"]=array();
7590
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7591
	$conf["info"]=array();
7592
	#可省略參數:
7593
	#無.
7594
	#參考資料:
7595
	#無.
7596
	#備註:
7597
	#建構中...
7598
	*/
7599
	public static function sslUpdater_cmd(&$conf){
7600
 
7601
		#debug
7602
		var_dump($conf);
7603
 
7604
		}#function sslUpdater_cmd end
7605
 
7606
	/*
7607
	#函式說明:
7608
	#funcion sslUpdater 於閒置時要做的事情
7609
	#回傳結果:
7610
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7611
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7612
	#$result["function"],當前執行的函式名稱.
7613
	#$result["argu"],所使用的參數.
7614
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
7615
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
7616
	#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
7617
	#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
7618
	#必填參數:
7619
	#$conf["client"],陣列,所有用戶的資訊.
7620
	$conf["client"]=array();
7621
	#$conf["clientCache"],陣列,給予所有用戶的cache.
7622
	$conf["clientCache"]=array();
7623
	#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
7624
	$conf["serverCache"]=array();
7625
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7626
	$conf["info"]=array();
7627
	#可省略參數:
7628
	#無.
7629
	#參考資料:
7630
	#無.
7631
	#備註:
291 liveuser 7632
	#無.
255 liveuser 7633
	*/
7634
	public static function sslUpdater_idle(&$conf){
7635
 
7636
		#初始化要回傳的結果
7637
		$result=array();
7638
 
7639
		#設置當其函數名稱
7640
		$result["function"]=__FUNCTION__;
7641
 
7642
		#如果 $conf 不為陣列
7643
		if(gettype($conf)!="array"){
7644
 
7645
			#設置執行失敗
7646
			$result["status"]="false";
7647
 
7648
			#設置執行錯誤訊息
7649
			$result["error"][]="\$conf變數須為陣列形態";
7650
 
7651
			#如果傳入的參數為 null
7652
			if($conf==null){
7653
 
7654
				#設置執行錯誤訊息
7655
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7656
 
7657
				}#if end
7658
 
7659
			#回傳結果
7660
			return $result;
7661
 
7662
			}#if end
7663
 
7664
		#取得參數
7665
		$result["argu"]=$conf;
7666
 
7667
		#檢查參數
7668
		#函式說明:
7669
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7670
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7671
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7672
		#$result["function"],當前執行的函式名稱.
7673
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7674
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7675
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7676
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7677
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7678
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7679
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7680
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7681
		#必填寫的參數:
7682
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7683
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7684
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
291 liveuser 7685
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","serverCache","info");
255 liveuser 7686
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
291 liveuser 7687
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
255 liveuser 7688
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7689
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7690
		#可以省略的參數:
7691
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7692
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7693
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7694
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7695
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7696
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
7697
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7698
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
7699
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7700
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
7701
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7702
		#$conf["arrayCountEqualCheck"][]=array();
7703
		#參考資料來源:
7704
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7705
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7706
		unset($conf["variableCheck::checkArguments"]);
7707
 
7708
		#如果檢查失敗
7709
		if($checkArguments["status"]==="false"){
7710
 
7711
			#設置錯誤識別
7712
			$result["status"]="false";
7713
 
7714
			#設置錯誤訊息
7715
			$result["error"]=$checkArguments;
7716
 
7717
			#回傳結果
7718
			return $result;
7719
 
7720
			}#if end
7721
 
7722
		#如果檢查不通過
7723
		if($checkArguments["passed"]==="false"){
7724
 
7725
			#設置錯誤識別
7726
			$result["status"]="false";
7727
 
7728
			#設置錯誤訊息
7729
			$result["error"]=$checkArguments;
7730
 
7731
			#回傳結果
7732
			return $result;
7733
 
7734
			}#if end
281 liveuser 7735
 
7736
		#預設不開啟 debug flag
7737
		$debug=false;
7738
 
7739
		#如果有設置 debug 為 "true"
291 liveuser 7740
		if($conf["info"]["share"]["debug"]==="true"){
281 liveuser 7741
 
7742
			#設置 debug flag
7743
			$debug=true;
7744
 
7745
			}#if end
7746
 
293 liveuser 7747
		#如果有啟用 multiThreads
7748
		if($conf["info"]["share"]["multiThreads"]==="true"){
7749
 
7750
			#設置 multiThreads flag
7751
			$multiThreads=true;
7752
 
7753
			}#if end
7754
 
261 liveuser 7755
		#另存 server cache 的參考
7756
		$serverCache=&$conf["serverCache"];
7757
 
255 liveuser 7758
		#針對每個 domain name
291 liveuser 7759
		foreach($conf["info"]["share"]["certInfo"] as $certInfoIndex=>$cInfo){
255 liveuser 7760
 
7761
			#取得domain name
7762
			$cName=$cInfo["cName"];
7763
 
261 liveuser 7764
			#如果尚無對應domain name的記錄
7765
			if(!isset($serverCache[$cName])){
7766
 
7767
				#設置最新一次檢測的unixtime
7768
				$serverCache[$cName]["lastCheckUnixTime"]=time();
291 liveuser 7769
 
261 liveuser 7770
				}#if end
7771
 
7772
			#反之距離上次檢查不滿一天
291 liveuser 7773
			else{
261 liveuser 7774
 
291 liveuser 7775
				#計算距離上次檢查多少秒
7776
				$checkedAfter=time()-$serverCache[$cName]["lastCheckUnixTime"];
261 liveuser 7777
 
291 liveuser 7778
				#若距離上次檢查不滿一天
7779
				if($checkedAfter<86400){
7780
 
7781
					#if enable debug
7782
					if($debug){
7783
 
7784
						#debug msg
7785
						echo "Domain name(".$cName.") on zerossl require to check in ".(86400-$checkedAfter)." second(s).".PHP_EOL;
7786
 
7787
						}#if end
7788
 
7789
					#跳過該 domain name 的檢查
7790
					continue;
7791
 
7792
					}#if end
346 liveuser 7793
 
7794
				#反之
7795
				else{
291 liveuser 7796
 
346 liveuser 7797
					#重新設置上次檢查時間為當前時間
7798
					$serverCache[$cName]["lastCheckUnixTime"]=time();
7799
 
7800
					}#else end
7801
 
291 liveuser 7802
				}#else end
261 liveuser 7803
 
281 liveuser 7804
			#if enable debug
7805
			if($debug){
7806
 
7807
				#debug msg
291 liveuser 7808
				echo "Checking domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 7809
 
7810
				}#if end
7811
 
291 liveuser 7812
			#certPath
7813
			#$cInfo["ssl"]["certPath"];
7814
 
7815
			#pKey
7816
			#$cInfo["ssl"]["pKey"];
7817
 
7818
			#caPath
7819
			#$cInfo["ssl"]["caPath"]=;
7820
 
7821
			#certWithCaPath
7822
			#$cInfo["ssl"]["certWithCaPath"];
7823
 
255 liveuser 7824
			#嘗試取得 domain name 對應的可用憑證
7825
			#函式說明:
7826
			#取得在zerossl上的CSR清單
7827
			#回傳結果:
7828
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7829
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
7830
			#$result["function"],當前執行的函式名稱.
7831
			#$result["argu"],所使用的參數.
7832
			#$result["curl_verbose_info"],curl執行的詳細資訊.
7833
			#$result["content"],結果json字串.
7834
			#$result["tCount"],總共的資料筆數.
7835
			#$result["count"],該頁的筆數.
7836
			#$result["page"],當前的頁碼.
7837
			#$result["certs"],陣列,certificates清單,key為certificate的id.
7838
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
7839
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
7840
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
7841
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7842
			#必填參數:
7843
			#無
7844
			#可省略參數:
7845
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 7846
			$conf["zerossl::getCertList"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 7847
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 7848
			$conf["zerossl::getCertList"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 7849
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7850
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
7851
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
7852
			$conf["zerossl::getCertList"]["cerType"]="single90Days";
7853
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
7854
			$conf["zerossl::getCertList"]["search"]=$cName;
7855
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
7856
			#$conf["limit"]="";
7857
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
7858
			#$conf["page"]="";
7859
			#參考資料:
7860
			#https://zerossl.com/documentation/api/list-certificates/
7861
			#備註:
7862
			#無.
7863
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
7864
			unset($conf["zerossl::getCertList"]);
7865
 
7866
			#符合條件的數量
7867
			#$getCertList["tCount"];
7868
 
7869
			#符合條件的當頁數量
7870
			#$getCertList["count"];
7871
 
7872
			#如果執行異常
7873
			if($getCertList["status"]==="false"){
7874
 
7875
				#設置錯誤識別
7876
				$result["status"]="false";
7877
 
7878
				#設置錯誤訊息
7879
				$result["error"]=$getCertList;
7880
 
7881
				#回傳結果
7882
				return $result;
7883
 
7884
				}#if end
291 liveuser 7885
 
294 liveuser 7886
			#如果有資料
7887
			if($getCertList["count"]>0){
7888
 
7889
				#檢查 common name
7890
				foreach($getCertList["certs"] as $certId=>$certInfo){
7891
 
7892
					#如果 common name 不符合
7893
					if($certInfo["cname"]!==$cName){
7894
 
7895
						#移除之
7896
						unset($getCertList["certs"][$certId]);
7897
 
7898
						#當頁筆數-1
7899
						$getCertList["count"]--;
7900
 
7901
						#總共筆數減少1
7902
						$getCertList["tCount"]--;
7903
 
7904
						}#if end
7905
 
7906
					}#foreach end
7907
 
7908
				}#if end
7909
 
255 liveuser 7910
			#如果沒有憑證
291 liveuser 7911
			if($getCertList["count"]===0){
255 liveuser 7912
 
281 liveuser 7913
				#if enable debug
7914
				if($debug){
7915
 
7916
					#debug msg
291 liveuser 7917
					echo "There is not valid ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 7918
 
7919
					}#if end
7920
 
7921
				#if enable debug
7922
				if($debug){
7923
 
7924
					#debug msg
291 liveuser 7925
					echo "Checking ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7926
 
7927
					}#if end
7928
 
255 liveuser 7929
				#確認有無對應 cName 的 private key
7930
				#函式說明:
7931
				#檢查多個檔案與資料夾是否存在.
7932
				#回傳的結果:
7933
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7934
				#$result["error"],錯誤訊息陣列.
7935
				#$resutl["function"],當前執行的涵式名稱.
7936
				#$result["argu"],使用的參數.
7937
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
7938
				#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
7939
				#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
7940
				#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
7941
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
7942
				#必填參數:
7943
				#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
292 liveuser 7944
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 7945
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7946
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
7947
				#可省略參數:
7948
				#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
7949
				#$conf["disableWebSearch"]="false";
7950
				#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
7951
				$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
7952
				#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
7953
				$conf["fileAccess::checkMultiFileExist"]["web"]="false";
7954
				#參考資料:
7955
				#http://php.net/manual/en/function.file-exists.php
7956
				#http://php.net/manual/en/control-structures.foreach.php
7957
				#備註:
7958
				#函數file_exists檢查的路徑為檔案系統的路徑
7959
				#$result["varName"][$i]結果未實作
7960
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
7961
				unset($conf["fileAccess::checkMultiFileExist"]);
7962
 
7963
				#如果運行異常
7964
				if($checkMultiFileExist["status"]==="false"){
7965
 
7966
					#設置錯誤識別
7967
					$result["status"]="false";
7968
 
7969
					#設置錯誤訊息
7970
					$result["error"]=$getCertList;
7971
 
7972
					#回傳結果
7973
					return $result;
7974
 
7975
					}#if end
7976
 
7977
				#如果沒有 private key
7978
				if($checkMultiFileExist["allExist"]==="false"){
7979
 
281 liveuser 7980
					#if enable debug
7981
					if($debug){
7982
 
7983
						#debug msg
291 liveuser 7984
						echo "there is no ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7985
 
7986
						}#if end
7987
 
7988
					#if enable debug
7989
					if($debug){
7990
 
7991
						#debug msg
291 liveuser 7992
						echo "creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7993
 
7994
						}#if end
7995
 
255 liveuser 7996
					#建立 private key
7997
					#函式說明:
7998
					#產生ssl private key.
7999
					#回傳結果:
8000
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8001
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8002
					#$result["function"],當前執行的函式名稱.
8003
					#$result["argu"],所使用的參數.
8004
					#$result["curl_verbose_info"],curl執行的詳細資訊.
8005
					#$result["content"],ssl用的private key.
8006
					#必填參數:
8007
					#$conf["fileArgu"],字串,變數__FILE__的內容.
8008
					$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
8009
					#可省略參數:
8010
					#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
8011
					#$conf["length"]=4096';
8012
					#參考資料:
8013
					#無.
8014
					#備註:
8015
					#key generated by openssl with RSA.
291 liveuser 8016
					$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 8017
					unset($conf["openssl::createPrivateKey"]);
8018
 
8019
					#如果運行異常
8020
					if($createPrivateKey["status"]==="false"){
8021
 
8022
						#設置錯誤識別
8023
						$result["status"]="false";
8024
 
8025
						#設置錯誤訊息
8026
						$result["error"]=$createPrivateKey;
8027
 
8028
						#回傳結果
8029
						return $result;
8030
 
8031
						}#if end
8032
 
8033
					#另存private key的字串
8034
					$pKeyStr=$createPrivateKey["content"];
8035
 
8036
					#建立private key檔案
8037
					#函式說明:
8038
					#將字串寫入到檔案
8039
					#回傳結果:
8040
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
8041
					#$result["error"],錯誤訊息陣列.
8042
					#$result["function"],當前執行的函數名稱.
8043
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
8044
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
8045
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
8046
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
8047
					#$result["argu"],使用的參數.
8048
					#必填參數:
8049
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8050
					$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
8051
					#可省略參數:
8052
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
292 liveuser 8053
					$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 8054
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
8055
					$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
8056
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
8057
					#$conf["writeMethod"]="a";
8058
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
8059
					#$conf["checkRepeat"]="";
8060
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
8061
					#$conf["filenameExtensionStartPoint"]="";
8062
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
8063
					#$conf["repeatNameRule"]="";
8064
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
8065
					$conf["zerossl::writeTextIntoFile"]["web"]="false";
8066
					#參考資料:
8067
					#無.
8068
					#備註:
8069
					#無.
291 liveuser 8070
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
255 liveuser 8071
					unset($conf["zerossl::writeTextIntoFile"]);
8072
 
8073
					#如果運行異常
8074
					if($writeTextIntoFile["status"]==="false"){
8075
 
8076
						#設置錯誤識別
8077
						$result["status"]="false";
8078
 
8079
						#設置錯誤訊息
8080
						$result["error"]=$writeTextIntoFile;
8081
 
8082
						#回傳結果
8083
						return $result;
8084
 
8085
						}#if end
8086
 
8087
					}#if end
8088
 
281 liveuser 8089
				#if enable debug
8090
				if($debug){
8091
 
8092
					#debug msg
291 liveuser 8093
					echo "Creating domain name(".$conf["info"]["share"]["apiDomain"].") csr for zerossl...".PHP_EOL;
281 liveuser 8094
 
8095
					}#if end
8096
 
255 liveuser 8097
				#建立準備給zerossl的csr
8098
				#函式說明:
8099
				#產生certificate sign request(CSR).
8100
				#回傳結果:
8101
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8102
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8103
				#$result["function"],當前執行的函式名稱.
8104
				#$result["argu"],所使用的參數.
8105
				#$result["content"],csr內容.
8106
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8107
				#$result["privateKey"], private key 的內容.
8108
				#必填參數:
8109
				#$conf["domain"],字串,csr內容的網域名稱.
8110
				$conf["zerossl::createCSR"]["domain"]=$cName;
8111
				#可省略參數:
8112
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 8113
				$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 8114
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
8115
				#$conf["country"]="";
8116
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
8117
				#$conf["state"]="";
8118
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
8119
				#$conf["org"]="";
8120
				#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
8121
				#$conf["unit"]="";
8122
				#參考資料:
8123
				#無.
8124
				#備註:
8125
				#無.
8126
				$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
8127
				unset($conf["zerossl::createCSR"]);
8128
 
8129
				#如果運行異常
8130
				if($createCSR["status"]==="false"){
8131
 
8132
					#設置錯誤識別
8133
					$result["status"]="false";
8134
 
8135
					#設置錯誤訊息
8136
					$result["error"]=$createCSR;
8137
 
8138
					#回傳結果
8139
					return $result;
8140
 
8141
					}#if end
8142
 
8143
				#取得本地端產生的csr內容
8144
				$csrLocal=$createCSR["content"];
8145
 
281 liveuser 8146
				#if enable debug
8147
				if($debug){
8148
 
8149
					#debug msg
291 liveuser 8150
					echo "Creating certificate for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 8151
 
8152
					}#if end
8153
 
255 liveuser 8154
				#函式說明:
281 liveuser 8155
				#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 8156
				#回傳結果:
8157
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8158
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8159
				#$result["function"],當前執行的函式名稱.
8160
				#$result["argu"],所使用的參數.
8161
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8162
				#$result["id"],用於zerossl api驗證domain的id.
8163
				#$result["content"],字串,得到的json字串回應.
8164
				#$result["cnameKey"],用於dns CNAME驗證鍵名.
8165
				#$result["cnameVal"],用於dms CNAME驗證鍵值.
8166
				#必填參數:
8167
				#$conf["certificate_domains"],字串,要簽署的doamin名稱.
8168
				$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
8169
				#$conf["certificate_csr"],字串,簽署的資訊.
8170
				$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
8171
				#$conf["fileArgu"],字串,變數__FILE__的內容.
8172
				$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
8173
				#可省略參數:
8174
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 8175
				$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 8176
				#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
8177
				#$conf["path"]=self::getApiInfo()["csrPath"];
8178
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 8179
				$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 8180
				#參考資料:
8181
				#無.
8182
				#備註:
8183
				#無.
8184
				$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
8185
				unset($conf["zerossl::createCertificate"]);
8186
 
8187
				#如果執行異常
8188
				if($createCertificate["status"]==="false"){
8189
 
8190
					#設置錯誤識別
8191
					$result["status"]="false";
8192
 
8193
					#設置錯誤訊息
8194
					$result["error"]=$createCertificate;
8195
 
8196
					#回傳結果
8197
					return $result;
8198
 
8199
					}#if end
8200
 
8201
				#取得csr在zerossl上的id
8202
				$csrId=$createCertificate["id"];
8203
 
8204
				#取得cname key
8205
				$cNameKey=$createCertificate["cnameKey"];
8206
 
8207
				#取得cname val
8208
				$cNameVal=$createCertificate["cnameVal"];
8209
 
8210
				#初始化要增加的RR記錄
8211
				$rr2add=array();
8212
 
8213
				#設置CNAME的查詢
8214
				$rr2add["query"]=$cNameKey;
8215
 
8216
				#設置CNAME的value
8217
				$rr2add["value"]=$cNameVal;
8218
 
8219
				#設置類型為 CNAME
8220
				$rr2add["type"]="CNAME";
8221
 
8222
				#設置註解
8223
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
8224
 
281 liveuser 8225
				#if enable debug
8226
				if($debug){
8227
 
8228
					#debug msg
291 liveuser 8229
					echo "Adding DNS record to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8230
 
8231
					}#if end
8232
 
255 liveuser 8233
				#函式說明:
8234
				#新增DNS記錄到檔案裡面.
8235
				#回傳結果:
8236
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8237
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8238
				#$result["function"],當前執行的函式名稱.
8239
				#$result["argu"],所使用的參數.
8240
				#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
8241
				#$result["domain"],字串,RR所屬domain.
8242
				#$result["defaultTTL"],字串,預設的RR更新時間.
8243
				#$result["comment"],字串陣列,逐行的註解.
8244
				#必填參數:
8245
				#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
291 liveuser 8246
				$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 8247
				#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
8248
				$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
8249
				#可省略參數:
8250
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
8251
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
8252
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
8253
				#$conf["debug"]="false";
293 liveuser 8254
 
8255
				#如果有啟用多執行序
8256
				if($conf["info"]["share"]["multiThreads"]==="true"){
8257
 
8258
					#設置要多執行序
8259
					$conf["zerossl::updateDnsRecordFile"]["multiThreads"]="true";
8260
 
8261
					}#if end
8262
 
255 liveuser 8263
				#參考資料:
8264
				#無.
8265
				#備註:
8266
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
8267
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
8268
				#php-pear上的Net_DNS2也可以解析RR.
8269
				$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
8270
				unset($conf["zerossl::updateDnsRecordFile"]);
8271
 
8272
				#如果執行異常
8273
				if($updateDnsRecordFile["status"]==="false"){
8274
 
8275
					#設置錯誤識別
8276
					$result["status"]="false";
8277
 
8278
					#設置錯誤訊息
8279
					$result["error"]=$updateDnsRecordFile;
8280
 
8281
					#回傳結果
8282
					return $result;
8283
 
8284
					}#if end
281 liveuser 8285
 
8286
				#if enable debug
8287
				if($debug){
8288
 
8289
					#debug msg
291 liveuser 8290
					echo "Restart DNS service to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8291
 
8292
					}#if end
8293
 
255 liveuser 8294
				#重新啟動dns伺服器
8295
				#函式說明:
8296
				#呼叫shell執行系統命令,並取得回傳的內容.
8297
				#回傳結果:
8298
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8299
				#$result["error"],錯誤訊息陣列.
8300
				#$result["function"],當前執行的函數名稱.
8301
				#$result["argu"],使用的參數.
8302
				#$result["cmd"],執行的指令內容.
8303
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8304
				#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8305
				#$result["content"],為執行完後的輸出字串.
8306
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8307
				#$result["running"],是否還在執行.
8308
				#$result["pid"],pid.
8309
				#$result["statusCode"],執行結束後的代碼.
8310
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8311
				#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8312
				#必填參數:
8313
				#$conf["command"],字串,要執行的指令.
291 liveuser 8314
				$conf["external::callShell"]["command"]="systemctl";
255 liveuser 8315
				#$conf["fileArgu"],字串,變數__FILE__的內容.
8316
				$conf["external::callShell"]["fileArgu"]=__FILE__;
8317
				#可省略參數:
8318
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8319
				$conf["external::callShell"]["argu"]=array("restart","named");
8320
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8321
				#$conf["arguIsAddr"]=array();
8322
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8323
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8324
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8325
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8326
				#$conf["enablePrintDescription"]="true";
8327
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8328
				#$conf["printDescription"]="";
8329
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8330
				#$conf["escapeshellarg"]="false";
8331
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8332
				#$conf["thereIsShellVar"]=array();
8333
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8334
				#$conf["username"]="";
8335
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8336
				#$conf["password"]="";
8337
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8338
				#$conf["useScript"]="";
8339
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8340
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8341
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8342
				#$conf["inBackGround"]="";
8343
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8344
				#$conf["getErr"]="false";
8345
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8346
				#$conf["doNotRun"]="false";
8347
				#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8348
				$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
8349
				#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8350
				#$conf["remoteUser"]="root";
8351
				#參考資料:
8352
				#exec=>http://php.net/manual/en/function.exec.php
8353
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8354
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8355
				#備註:
8356
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8357
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8358
				$callShell=external::callShell($conf["external::callShell"]);
8359
				unset($conf["external::callShell"]);
8360
 
8361
				#如果執行異常
8362
				if($callShell["status"]==="false"){
8363
 
8364
					#設置錯誤識別
8365
					$result["status"]="false";
8366
 
8367
					#設置錯誤訊息
8368
					$result["error"]=$callShell;
8369
 
8370
					#回傳結果
8371
					return $result;
8372
 
8373
					}#if end
281 liveuser 8374
 
8375
				#if enable debug
8376
				if($debug){
8377
 
8378
					#debug msg
291 liveuser 8379
					echo "Request zerossl to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8380
 
8381
					}#if end
8382
 
292 liveuser 8383
				#無窮迴圈
8384
				while(true){
255 liveuser 8385
 
292 liveuser 8386
					#函式說明:
8387
					#請求驗證已經透過zerossl::createCertificate要求的domain.
8388
					#回傳結果:
8389
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8390
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8391
					#$result["function"],當前執行的函式名稱.
8392
					#$result["argu"],所使用的參數.
8393
					#$result["curl_verbose_info"],curl執行的詳細資訊.
8394
					#$result["content"],結果json字串.
8395
					#必填參數:
8396
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
8397
					$conf["zerossl::verifyDomain"]["id"]=$csrId;
8398
					#可省略參數:
8399
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8400
					$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
8401
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8402
					$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
8403
					#參考資料:
8404
					#https://zerossl.com/documentation/api/verify-domains/
8405
					#備註:
8406
					#無.
8407
					$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
8408
					unset($conf["zerossl::verifyDomain"]);
291 liveuser 8409
 
292 liveuser 8410
					#如果執行異常
8411
					if($verifyDomain["status"]==="false"){
8412
 
8413
						#設置錯誤識別
8414
						$result["status"]="false";
291 liveuser 8415
 
292 liveuser 8416
						#設置錯誤訊息
8417
						$result["error"]=$verifyDomain;
291 liveuser 8418
 
292 liveuser 8419
						#回傳結果
8420
						return $result;
291 liveuser 8421
 
8422
						}#if end
8423
 
292 liveuser 8424
					#如果沒有回內容
293 liveuser 8425
					if(!isset($verifyDomain["content"])){
292 liveuser 8426
 
8427
						#設置錯誤識別
8428
						$result["status"]="false";
291 liveuser 8429
 
292 liveuser 8430
						#設置錯誤訊息
8431
						$result["error"]=$verifyDomain;
291 liveuser 8432
 
292 liveuser 8433
						#回傳結果
8434
						return $result;
8435
 
8436
						}#if end
8437
 
8438
					#如果回應不是 json
293 liveuser 8439
					if(!(json_validate($verifyDomain["content"]))){
292 liveuser 8440
 
8441
						#設置錯誤識別
8442
						$result["status"]="false";
291 liveuser 8443
 
292 liveuser 8444
						#設置錯誤訊息
8445
						$result["error"]=$verifyDomain;
291 liveuser 8446
 
292 liveuser 8447
						#回傳結果
8448
						return $result;
8449
 
8450
						}#if end
8451
 
294 liveuser 8452
					#if enable debug
8453
					if($debug){
8454
 
8455
						#debug msg
8456
						echo "Response of validating certificate for domain name(".$cName.") on zerossl".PHP_EOL;
8457
 
8458
						#debug msg
8459
						var_dump(__LINE__,$verifyDomain);
8460
 
8461
						}#if end
8462
 
292 liveuser 8463
					/*
8464
					範例json:
8465
					{"id":"51cff04454e6a6860abfecc8072db602","type":"1","common_name":"silverblue-guest.qbpwcf.org","additional_domains":"","created":"2026-03-06 13:45:39","expires":"2026-06-04 23:59:59","status":"pending_validation","validation_type":"CNAME_CSR_HASH","validation_emails":"","replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"silverblue-guest.qbpwcf.org":["admin@silverblue-guest.qbpwcf.org","administrator@silverblue-guest.qbpwcf.org","hostmaster@silverblue-guest.qbpwcf.org","postmaster@silverblue-guest.qbpwcf.org","webmaster@silverblue-guest.qbpwcf.org","admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"silverblue-guest.qbpwcf.org":{"file_validation_url_http":"http:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_url_https":"https:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_content":["58B9EB7890F754D041698170B22D22205D710ED09B419A809E5C92C38195DD36","comodoca.com","627e45f007045f0"],"cname_validation_p1":"_383346FA54F492EC8B2A6C421A052827.silverblue-guest.qbpwcf.org","cname_validation_p2":"58B9EB7890F754D041698170B22D2220.5D710ED09B419A809E5C92C38195DD36.627e45f007045f0.comodoca.com"}}},"signature_algorithm_properties":null}
8466
					*/
8467
 
8468
					#解析json回應
293 liveuser 8469
					$verifyDomainRes=json_decode($verifyDomain["content"]);
291 liveuser 8470
 
293 liveuser 8471
					#如果回應含有 success
8472
					if(isset($verifyDomainRes->success)){
292 liveuser 8473
 
293 liveuser 8474
						#如果是 zerossl 驗證失敗
294 liveuser 8475
						if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
291 liveuser 8476
 
293 liveuser 8477
							#如果是 CNAME 記錄找不到
8478
							if($verifyDomainRes->error->code===0){
291 liveuser 8479
 
293 liveuser 8480
								#取得錯誤訊息
8481
								#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
8482
 
8483
								#if enable debug
8484
								if($debug){
8485
 
8486
									#debug msg
8487
									echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
8488
 
8489
									}#if end
8490
 
8491
								#if enable debug
8492
								if($debug){
8493
 
8494
									#debug msg
8495
									echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
8496
 
8497
									}#if end
8498
 
8499
								#休息60秒
8500
								sleep(60);
294 liveuser 8501
 
8502
								#再跑一次要求認證
8503
								continue;
291 liveuser 8504
 
8505
								}#if end
293 liveuser 8506
 
8507
							#反之為不接受的錯誤訊息
8508
							else{
291 liveuser 8509
 
293 liveuser 8510
								#設置錯誤識別
8511
								$result["status"]="false";
8512
 
8513
								#設置錯誤訊息
8514
								$result["error"]=$verifyDomain;
8515
 
8516
								#回傳結果
8517
								return $result;
291 liveuser 8518
 
293 liveuser 8519
								}#else end
291 liveuser 8520
 
8521
							}#if end
292 liveuser 8522
 
8523
						}#if end
293 liveuser 8524
 
8525
					#反之如果回應含有 status
8526
					else if(isset($verifyDomainRes->status)){
292 liveuser 8527
 
293 liveuser 8528
						#如果是 zerossl 尚在驗證中
8529
						if($verifyDomainRes->status==="pending_validation"){
292 liveuser 8530
 
293 liveuser 8531
							#if enable debug
8532
							if($debug){
292 liveuser 8533
 
293 liveuser 8534
								#debug msg
8535
								echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
292 liveuser 8536
 
8537
								}#if end
8538
 
293 liveuser 8539
							#無窮迴圈
8540
							while(true){
8541
 
8542
								#查詢驗證狀況
8543
								#函式說明:
8544
								#取得CSR在zerossl上的狀態
8545
								#回傳結果:
8546
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8547
								#$reuslt["error"],執行不正常結束的錯訊息陣列.
8548
								#$result["function"],當前執行的函式名稱.
8549
								#$result["argu"],所使用的參數.
8550
								#$result["curl_verbose_info"],curl執行的詳細資訊.
8551
								#$result["content"],結果json字串.
8552
								#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
8553
								#必填參數:
8554
								#$conf["id"],字串,zerossl::createCertificate回傳的id.
8555
								$conf["zerossl::getCertSta"]["id"]=$csrId;
8556
								#可省略參數:
8557
								#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8558
								$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
8559
								#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8560
								$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
8561
								#參考資料:
8562
								#https://zerossl.com/documentation/api/get-certificate/
8563
								#備註:
8564
								#無.
8565
								$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
8566
								unset($conf["zerossl::getCertSta"]);
8567
 
8568
								#如果執行異常
8569
								if($getCertSta["status"]==="false"){
8570
 
8571
									#設置錯誤識別
8572
									$result["status"]="false";
292 liveuser 8573
 
293 liveuser 8574
									#設置錯誤訊息
8575
									$result["error"]=$getCertSta;
292 liveuser 8576
 
293 liveuser 8577
									#回傳結果
8578
									return $result;
292 liveuser 8579
 
293 liveuser 8580
									}#if end
8581
 
8582
								#如果沒有回應內容
8583
								if(!isset($getCertSta["content"])){
8584
 
8585
									#設置錯誤識別
8586
									$result["status"]="false";
292 liveuser 8587
 
293 liveuser 8588
									#設置錯誤訊息
8589
									$result["error"]=$getCertSta;
292 liveuser 8590
 
293 liveuser 8591
									#回傳結果
8592
									return $result;
292 liveuser 8593
 
293 liveuser 8594
									}#if end
8595
 
8596
								#如果回應不是 json
8597
								if(!(json_validate($getCertSta["content"]))){
292 liveuser 8598
 
293 liveuser 8599
									#設置錯誤識別
8600
									$result["status"]="false";
8601
 
8602
									#設置錯誤訊息
8603
									$result["error"]=$getCertSta;
8604
 
8605
									#回傳結果
8606
									return $result;
292 liveuser 8607
 
8608
									}#if end
293 liveuser 8609
 
8610
								#解析json回應
8611
								$getCertStaRes=json_decode($getCertSta["content"]);
292 liveuser 8612
 
293 liveuser 8613
								#如果憑證已經驗證通過了
8614
								if($getCertStaRes->status==="issued"){
292 liveuser 8615
 
293 liveuser 8616
									#if enable debug
8617
									if($debug){
8618
 
8619
										#debug msg
8620
										echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
8621
 
8622
										}#if end
292 liveuser 8623
 
294 liveuser 8624
									#結束等待,跳出 while
293 liveuser 8625
									break 2;
8626
 
292 liveuser 8627
									}#if end
8628
 
293 liveuser 8629
								#如果 zerossl 尚在處理中
8630
								else if($getCertStaRes->status==="pending_validation"){
292 liveuser 8631
 
293 liveuser 8632
									#if enable debug
8633
									if($debug){
8634
 
8635
										#debug msg
8636
										echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
8637
 
8638
										}#if end
8639
 
8640
									#休息1分鐘
8641
									sleep(60);
294 liveuser 8642
 
8643
									#再跑一次取得憑證狀態
8644
									continue;
293 liveuser 8645
 
8646
									}#if end
8647
 
8648
								#反之
8649
								else{
8650
 
8651
									#例外狀況
8652
 
8653
									#設置錯誤識別
8654
									$result["status"]="false";
292 liveuser 8655
 
293 liveuser 8656
									#設置錯誤訊息
8657
									$result["error"]=$getCertSta;
292 liveuser 8658
 
293 liveuser 8659
									#回傳結果
8660
									return $result;
8661
 
8662
									}#else end
292 liveuser 8663
 
293 liveuser 8664
								}#while end
8665
 
8666
							}#if end
8667
 
292 liveuser 8668
						}#if end
294 liveuser 8669
 
8670
					#反之.不應該執行到這邊
8671
					else{
8672
 
8673
						#設置錯誤識別
8674
						$result["status"]="false";
8675
 
8676
						#設置錯誤訊息
8677
						$result["error"]=$verifyDomain;
8678
 
8679
						#回傳結果
8680
						return $result;
8681
 
8682
						}#else 	
291 liveuser 8683
 
292 liveuser 8684
					}#while end
294 liveuser 8685
 
281 liveuser 8686
				#if enable debug
8687
				if($debug){
8688
 
8689
					#debug msg
291 liveuser 8690
					echo "Downloading certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8691
 
8692
					}#if end
8693
 
255 liveuser 8694
				#函式說明:
8695
				#下載certificate.
8696
				#回傳結果:
8697
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8698
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8699
				#$result["function"],當前執行的函式名稱.
8700
				#$result["argu"],所使用的參數.
8701
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8702
				#$result["content"],結果json字串.
8703
				#$result["certificate.crt"],字串,certificate.crt的內容.
8704
				#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
8705
				#必填參數:
8706
				#無.
8707
				#可省略參數:
8708
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 8709
				$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 8710
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 8711
				$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 8712
				#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
8713
				$conf["zerossl::getCert"]["id"]=$csrId;
8714
				#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
8715
				#$conf["zerossl::getCert"]["cname"]="";
8716
				#參考資料:
8717
				#https://zerossl.com/documentation/api/download-certificate-inline/
8718
				#備註:
8719
				#無.
8720
				$getCert=zerossl::getCert($conf["zerossl::getCert"]);
8721
				unset($conf["zerossl::getCert"]);
8722
 
8723
				#如果執行異常
8724
				if($getCert["status"]==="false"){
8725
 
8726
					#設置錯誤識別
8727
					$result["status"]="false";
8728
 
8729
					#設置錯誤訊息
8730
					$result["error"]=$getCert;
8731
 
8732
					#回傳結果
8733
					return $result;
8734
 
8735
					}#if end
281 liveuser 8736
 
8737
				#if enable debug
8738
				if($debug){
8739
 
8740
					#debug msg
291 liveuser 8741
					echo "Creating certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8742
 
8743
					}#if end
8744
 
293 liveuser 8745
				#certPath
8746
				#$cInfo["ssl"]["certPath"];
255 liveuser 8747
 
293 liveuser 8748
				#pKey
8749
				#$cInfo["ssl"]["pKey"];
255 liveuser 8750
 
293 liveuser 8751
				#caPath
8752
				#$cInfo["ssl"]["caPath"]=;
255 liveuser 8753
 
293 liveuser 8754
				#certWithCaPath
8755
				#$cInfo["ssl"]["certWithCaPath"];
8756
 
255 liveuser 8757
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
8758
				#函式說明:
8759
				#一次建立多個檔案,並寫入內容.
8760
				#回傳結果:
8761
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
8762
				#$result["error"],錯誤訊息陣列.
8763
				#$result["function"],當前執行的函數名稱.
8764
				#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
8765
				#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
8766
				#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
8767
				#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
8768
				#$result["argu"],使用的參數.
8769
				#必填參數:
8770
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8771
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
8772
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
293 liveuser 8773
				$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 8774
				#可省略參數:
8775
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
8776
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
8777
				#參考資料:
8778
				#無.
8779
				#備註:
8780
				#無.
293 liveuser 8781
				$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 8782
				unset($conf["zerossl::writeMultiFile"]);
8783
 
8784
				#如果執行異常
8785
				if($writeMultiFile["status"]==="false"){
8786
 
8787
					#設置錯誤識別
8788
					$result["status"]="false";
8789
 
8790
					#設置錯誤訊息
8791
					$result["error"]=$writeMultiFile;
8792
 
8793
					#回傳結果
8794
					return $result;
8795
 
8796
					}#if end
8797
 
8798
				#儲存 actionAfterUpdateCert
8799
				$action=$cInfo["actionAfterUpdateCert"];
8800
 
8801
				#如果有多個指令要執行
294 liveuser 8802
				if(count($action)>1){
255 liveuser 8803
 
281 liveuser 8804
					#if enable debug
8805
					if($debug){
8806
 
8807
						#debug msg
291 liveuser 8808
						echo "There are many cmds to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8809
 
8810
						}#if end
8811
 
8812
					#if enable debug
8813
					if($debug){
8814
 
8815
						#debug msg
291 liveuser 8816
						echo "Running cmd to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8817
 
8818
						}#if end
8819
 
255 liveuser 8820
					#針對每的指令
8821
					foreach($action as $ac){
8822
 
281 liveuser 8823
						#if enable debug
8824
						if($debug){
8825
 
8826
							#debug msg
8827
							echo ".".PHP_EOL;
8828
 
8829
							}#if end
8830
 
255 liveuser 8831
						#函式說明:
8832
						#呼叫shell執行系統命令,並取得回傳的內容.
8833
						#回傳結果:
8834
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8835
						#$result["error"],錯誤訊息陣列.
8836
						#$result["function"],當前執行的函數名稱.
8837
						#$result["argu"],使用的參數.
8838
						#$result["cmd"],執行的指令內容.
8839
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8840
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8841
						#$result["content"],為執行完後的輸出字串.
8842
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8843
						#$result["running"],是否還在執行.
8844
						#$result["pid"],pid.
8845
						#$result["statusCode"],執行結束後的代碼.
8846
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8847
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8848
						#必填參數:
8849
						#$conf["command"],字串,要執行的指令.
294 liveuser 8850
						$conf["external::callShell"]["command"]=$ac;
255 liveuser 8851
						#$conf["fileArgu"],字串,變數__FILE__的內容.
8852
						$conf["external::callShell"]["fileArgu"]=__FILE__;
8853
						#可省略參數:
8854
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
294 liveuser 8855
						#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 8856
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8857
						#$conf["arguIsAddr"]=array();
8858
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8859
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8860
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8861
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8862
						#$conf["enablePrintDescription"]="true";
8863
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8864
						#$conf["printDescription"]="";
8865
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8866
						$conf["external::callShell"]["escapeshellarg"]="true";
8867
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8868
						#$conf["thereIsShellVar"]=array();
8869
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8870
						#$conf["username"]="";
8871
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8872
						#$conf["password"]="";
8873
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8874
						#$conf["useScript"]="";
8875
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8876
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8877
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8878
						#$conf["inBackGround"]="";
8879
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8880
						#$conf["getErr"]="false";
294 liveuser 8881
						#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
8882
						$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 8883
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8884
						#$conf["doNotRun"]="false";
8885
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8886
						#$conf["remoteIp"]="";
8887
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8888
						#$conf["remoteUser"]="";
8889
						#參考資料:
8890
						#exec=>http://php.net/manual/en/function.exec.php
8891
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8892
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8893
						#備註:
8894
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8895
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8896
						$callShell=external::callShell($conf["external::callShell"]);
8897
						unset($conf["external::callShell"]);
8898
 
8899
						#如果執行異常
294 liveuser 8900
						if($callShell["status"]==="false"){
255 liveuser 8901
 
8902
							#設置錯誤識別
8903
							$result["status"]="false";
8904
 
8905
							#設置錯誤訊息
8906
							$result["error"]=$callShell;
8907
 
8908
							#回傳結果
8909
							return $result;
8910
 
8911
							}#if end
8912
 
8913
						}#foreach end
8914
 
8915
					}#if end
8916
 
8917
				#反之
8918
				else{
8919
 
281 liveuser 8920
					#if enable debug
8921
					if($debug){
8922
 
8923
						#debug msg
291 liveuser 8924
						echo "There is only one cmd to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8925
 
8926
						}#if end
8927
 
8928
					#if enable debug
8929
					if($debug){
8930
 
8931
						#debug msg
8932
						echo ".".PHP_EOL;
8933
 
8934
						}#if end
8935
 
255 liveuser 8936
					#函式說明:
8937
					#呼叫shell執行系統命令,並取得回傳的內容.
8938
					#回傳結果:
8939
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8940
					#$result["error"],錯誤訊息陣列.
8941
					#$result["function"],當前執行的函數名稱.
8942
					#$result["argu"],使用的參數.
8943
					#$result["cmd"],執行的指令內容.
8944
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8945
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8946
					#$result["content"],為執行完後的輸出字串.
8947
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8948
					#$result["running"],是否還在執行.
8949
					#$result["pid"],pid.
8950
					#$result["statusCode"],執行結束後的代碼.
8951
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8952
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8953
					#必填參數:
8954
					#$conf["command"],字串,要執行的指令.
302 liveuser 8955
					$conf["external::callShell"]["command"]=$action[0];
255 liveuser 8956
					#$conf["fileArgu"],字串,變數__FILE__的內容.
8957
					$conf["external::callShell"]["fileArgu"]=__FILE__;
8958
					#可省略參數:
8959
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 8960
					#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 8961
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8962
					#$conf["arguIsAddr"]=array();
8963
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8964
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8965
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8966
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8967
					#$conf["enablePrintDescription"]="true";
8968
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8969
					#$conf["printDescription"]="";
8970
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8971
					$conf["external::callShell"]["escapeshellarg"]="true";
8972
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8973
					#$conf["thereIsShellVar"]=array();
8974
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8975
					#$conf["username"]="";
8976
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8977
					#$conf["password"]="";
8978
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8979
					#$conf["useScript"]="";
8980
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8981
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8982
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8983
					#$conf["inBackGround"]="";
8984
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8985
					#$conf["getErr"]="false";
8986
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8987
					#$conf["doNotRun"]="false";
294 liveuser 8988
					#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
8989
					$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 8990
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8991
					#$conf["remoteIp"]="";
8992
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8993
					#$conf["remoteUser"]="";
8994
					#參考資料:
8995
					#exec=>http://php.net/manual/en/function.exec.php
8996
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8997
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8998
					#備註:
8999
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9000
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9001
					$callShell=external::callShell($conf["external::callShell"]);
9002
					unset($conf["external::callShell"]);
294 liveuser 9003
 
255 liveuser 9004
					#如果執行異常
294 liveuser 9005
					if($callShell["status"]==="false"){
255 liveuser 9006
 
9007
						#設置錯誤識別
9008
						$result["status"]="false";
9009
 
9010
						#設置錯誤訊息
9011
						$result["error"]=$callShell;
9012
 
9013
						#回傳結果
9014
						return $result;
9015
 
9016
						}#if end
9017
 
9018
					}#else end
9019
 
9020
				}#if end
9021
 
9022
			#反之
9023
			else{
9024
 
281 liveuser 9025
				#if enable debug
9026
				if($debug){
9027
 
9028
					#debug msg
291 liveuser 9029
					echo "There is already valid ssl for domain name(".$cName.") on zerossl".PHP_EOL;
281 liveuser 9030
 
9031
					}#if end
9032
 
291 liveuser 9033
				#debug
9034
				#var_dump(__LINE__,$getCertList);
9035
 
255 liveuser 9036
				#有 issued 的憑證
9037
 
291 liveuser 9038
				#if enable debug
9039
				if($debug){
9040
 
9041
					#debug msg
9042
					echo "Downloading ssl for domain name(".$cName.") on zerossl".PHP_EOL;
9043
 
9044
					}#if end
9045
 
255 liveuser 9046
				#取得 certificate id at zerossl
9047
				#函式說明:
9048
				#將陣列轉換成存有key與value的陣列
9049
				#回傳的結果:
9050
				#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
9051
				#$result["function"],當前執行的函數
9052
				#$result["error"],錯誤訊息.
9053
				#$result[$i]["key"],原先$i+1個元素的key.
9054
				#$result[$i]["value"],原先$i+1個元素的value.
9055
				#必填參數:
9056
				#$conf["rawInputArray"],陣列,要轉換的陣列變數.
9057
				$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
9058
				#可省略參數:
9059
				#無.
9060
				#參考資料:
9061
				#無.
9062
				#備註:
9063
				#無.
9064
				$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
9065
				unset($conf["arrays::getKeyAndValue"]);
9066
 
9067
				#如果執行異常
9068
				if($getKeyAndValue["status"]==="false"){
9069
 
9070
					#設置錯誤識別
9071
					$result["status"]="false";
9072
 
9073
					#設置錯誤訊息
9074
					$result["error"]=$getKeyAndValue;
9075
 
9076
					#回傳結果
9077
					return $result;
9078
 
9079
					}#if end
9080
 
291 liveuser 9081
				#debug
9082
				#var_dump($getKeyAndValue);exit;
9083
 
255 liveuser 9084
				#儲存 certificate id at zerossl
291 liveuser 9085
				$csrId=$getKeyAndValue[1]["key"];
255 liveuser 9086
 
9087
				#檢查憑證是否已經快過期
9088
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
9089
 
9090
				#如果距離當下不到2個星期就要過期
9091
				if($expiresIn<=86400*14){
291 liveuser 9092
 
281 liveuser 9093
					#if enable debug
9094
					if($debug){
9095
 
9096
						#debug msg
291 liveuser 9097
						echo "Valid ssl for domain name(".$cName.") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
281 liveuser 9098
 
9099
						}#if end
9100
 
291 liveuser 9101
					#debug
9102
					#var_dump($expiresIn);exit;
9103
 
255 liveuser 9104
					#另存舊的憑證id,最後要revoke之.
9105
					$oldCsrId=$csrId;
9106
 
281 liveuser 9107
					#if enable debug
9108
					if($debug){
9109
 
9110
						#debug msg
294 liveuser 9111
						echo "Start request new ssl process for domain name(".$cName.").".PHP_EOL;
281 liveuser 9112
 
9113
						}#if end
9114
 
9115
					#if enable debug
9116
					if($debug){
9117
 
9118
						#debug msg
291 liveuser 9119
						echo "Finding ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9120
 
9121
						}#if end
9122
 
255 liveuser 9123
					#確認有無對應 cName 的 private key
9124
					#函式說明:
9125
					#檢查多個檔案與資料夾是否存在.
9126
					#回傳的結果:
9127
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9128
					#$result["error"],錯誤訊息陣列.
9129
					#$resutl["function"],當前執行的涵式名稱.
9130
					#$result["argu"],使用的參數.
9131
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9132
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9133
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
9134
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
9135
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9136
					#必填參數:
9137
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
291 liveuser 9138
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 9139
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9140
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
9141
					#可省略參數:
9142
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9143
					#$conf["disableWebSearch"]="false";
9144
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9145
					$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
9146
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
9147
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
9148
					#參考資料:
9149
					#http://php.net/manual/en/function.file-exists.php
9150
					#http://php.net/manual/en/control-structures.foreach.php
9151
					#備註:
9152
					#函數file_exists檢查的路徑為檔案系統的路徑
9153
					#$result["varName"][$i]結果未實作
9154
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9155
					unset($conf["fileAccess::checkMultiFileExist"]);
9156
 
9157
					#如果運行異常
9158
					if($checkMultiFileExist["status"]==="false"){
9159
 
9160
						#設置錯誤識別
9161
						$result["status"]="false";
9162
 
9163
						#設置錯誤訊息
9164
						$result["error"]=$getCertList;
9165
 
9166
						#回傳結果
9167
						return $result;
9168
 
9169
						}#if end
9170
 
9171
					#如果沒有 private key
9172
					if($checkMultiFileExist["allExist"]==="false"){
9173
 
281 liveuser 9174
						#if enable debug
9175
						if($debug){
9176
 
9177
							#debug msg
291 liveuser 9178
							echo "Thers is no ssl private key for domain name(".$cName.").".PHP_EOL;
281 liveuser 9179
 
9180
							}#if end
9181
 
9182
						#if enable debug
9183
						if($debug){
9184
 
9185
							#debug msg
291 liveuser 9186
							echo "Creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9187
 
9188
							}#if end
9189
 
255 liveuser 9190
						#建立 private key
9191
						#函式說明:
9192
						#產生ssl private key.
9193
						#回傳結果:
9194
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9195
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
9196
						#$result["function"],當前執行的函式名稱.
9197
						#$result["argu"],所使用的參數.
9198
						#$result["curl_verbose_info"],curl執行的詳細資訊.
9199
						#$result["content"],ssl用的private key.
9200
						#必填參數:
9201
						#$conf["fileArgu"],字串,變數__FILE__的內容.
9202
						$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
9203
						#可省略參數:
9204
						#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
9205
						#$conf["length"]=4096';
9206
						#參考資料:
9207
						#無.
9208
						#備註:
9209
						#key generated by openssl with RSA.
291 liveuser 9210
						$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 9211
						unset($conf["openssl::createPrivateKey"]);
9212
 
9213
						#如果運行異常
9214
						if($createPrivateKey["status"]==="false"){
9215
 
9216
							#設置錯誤識別
9217
							$result["status"]="false";
9218
 
9219
							#設置錯誤訊息
9220
							$result["error"]=$createPrivateKey;
9221
 
9222
							#回傳結果
9223
							return $result;
9224
 
9225
							}#if end
9226
 
9227
						#另存private key的字串
9228
						$pKeyStr=$createPrivateKey["content"];
9229
 
281 liveuser 9230
						#if enable debug
9231
						if($debug){
9232
 
9233
							#debug msg
291 liveuser 9234
							echo "Writing ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9235
 
9236
							}#if end
9237
 
255 liveuser 9238
						#建立private key檔案
9239
						#函式說明:
9240
						#將字串寫入到檔案
9241
						#回傳結果:
9242
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9243
						#$result["error"],錯誤訊息陣列.
9244
						#$result["function"],當前執行的函數名稱.
9245
						#$result["fileInfo"],實際上寫入的檔案資訊陣列.
9246
						#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
9247
						#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
9248
						#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
9249
						#$result["argu"],使用的參數.
9250
						#必填參數:
9251
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9252
						$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
9253
						#可省略參數:
9254
						#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
291 liveuser 9255
						$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 9256
						#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
9257
						$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
9258
						#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
9259
						#$conf["writeMethod"]="a";
9260
						#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
9261
						#$conf["checkRepeat"]="";
9262
						#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
9263
						#$conf["filenameExtensionStartPoint"]="";
9264
						#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
9265
						#$conf["repeatNameRule"]="";
9266
						#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
9267
						$conf["zerossl::writeTextIntoFile"]["web"]="false";
9268
						#參考資料:
9269
						#無.
9270
						#備註:
9271
						#無.
9272
						$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
9273
						unset($conf["zerossl::writeTextIntoFile"]);
9274
 
9275
						#如果運行異常
9276
						if($writeTextIntoFile["status"]==="false"){
9277
 
9278
							#設置錯誤識別
9279
							$result["status"]="false";
9280
 
9281
							#設置錯誤訊息
9282
							$result["error"]=$writeTextIntoFile;
9283
 
9284
							#回傳結果
9285
							return $result;
9286
 
9287
							}#if end
9288
 
9289
						}#if end
9290
 
281 liveuser 9291
					#if enable debug
9292
					if($debug){
9293
 
9294
						#debug msg
291 liveuser 9295
						echo "Creating CSR for domain name(".$cName.") to zerossl.".PHP_EOL;
281 liveuser 9296
 
9297
						}#if end
9298
 
255 liveuser 9299
					#建立準備給zerossl的csr
9300
					#函式說明:
9301
					#產生certificate sign request(CSR).
9302
					#回傳結果:
9303
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9304
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9305
					#$result["function"],當前執行的函式名稱.
9306
					#$result["argu"],所使用的參數.
9307
					#$result["content"],csr內容.
9308
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9309
					#$result["privateKey"], private key 的內容.
9310
					#必填參數:
9311
					#$conf["domain"],字串,csr內容的網域名稱.
9312
					$conf["zerossl::createCSR"]["domain"]=$cName;
9313
					#可省略參數:
9314
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 9315
					$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 9316
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
9317
					#$conf["country"]="";
9318
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
9319
					#$conf["state"]="";
9320
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
9321
					#$conf["org"]="";
9322
					#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
9323
					#$conf["unit"]="";
9324
					#參考資料:
9325
					#無.
9326
					#備註:
9327
					#無.
9328
					$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
9329
					unset($conf["zerossl::createCSR"]);
9330
 
9331
					#如果運行異常
9332
					if($createCSR["status"]==="false"){
9333
 
9334
						#設置錯誤識別
9335
						$result["status"]="false";
9336
 
9337
						#設置錯誤訊息
9338
						$result["error"]=$createCSR;
9339
 
9340
						#回傳結果
9341
						return $result;
9342
 
9343
						}#if end
9344
 
9345
					#取得本地端產生的csr內容
9346
					$csrLocal=$createCSR["content"];
9347
 
281 liveuser 9348
					#if enable debug
9349
					if($debug){
9350
 
9351
						#debug msg
291 liveuser 9352
						echo "Providing CSR for domain name(".$cName.") to zerossl".PHP_EOL;
281 liveuser 9353
 
9354
						}#if end
9355
 
255 liveuser 9356
					#函式說明:
281 liveuser 9357
					#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 9358
					#回傳結果:
9359
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9360
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9361
					#$result["function"],當前執行的函式名稱.
9362
					#$result["argu"],所使用的參數.
9363
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9364
					#$result["id"],用於zerossl api驗證domain的id.
9365
					#$result["content"],字串,得到的json字串回應.
9366
					#$result["cnameKey"],用於dns CNAME驗證鍵名.
9367
					#$result["cnameVal"],用於dms CNAME驗證鍵值.
9368
					#必填參數:
9369
					#$conf["certificate_domains"],字串,要簽署的doamin名稱.
9370
					$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
9371
					#$conf["certificate_csr"],字串,簽署的資訊.
9372
					$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
9373
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9374
					$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
9375
					#可省略參數:
9376
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9377
					$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9378
					#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
9379
					#$conf["path"]=self::getApiInfo()["csrPath"];
9380
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9381
					$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9382
					#參考資料:
9383
					#無.
9384
					#備註:
9385
					#無.
9386
					$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
9387
					unset($conf["zerossl::createCertificate"]);
9388
 
9389
					#如果執行異常
9390
					if($createCertificate["status"]==="false"){
9391
 
9392
						#設置錯誤識別
9393
						$result["status"]="false";
9394
 
9395
						#設置錯誤訊息
9396
						$result["error"]=$createCertificate;
9397
 
9398
						#回傳結果
9399
						return $result;
9400
 
9401
						}#if end
9402
 
9403
					#取得csr在zerossl上的id
9404
					$csrId=$createCertificate["id"];
9405
 
9406
					#取得cname key
9407
					$cNameKey=$createCertificate["cnameKey"];
9408
 
9409
					#取得cname val
9410
					$cNameVal=$createCertificate["cnameVal"];
9411
 
9412
					#初始化要增加的RR記錄
9413
					$rr2add=array();
9414
 
9415
					#設置CNAME的查詢
9416
					$rr2add["query"]=$cNameKey;
9417
 
9418
					#設置CNAME的value
9419
					$rr2add["value"]=$cNameVal;
9420
 
9421
					#設置類型為 CNAME
9422
					$rr2add["type"]="CNAME";
9423
 
9424
					#設置註解
9425
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
9426
 
281 liveuser 9427
					#if enable debug
9428
					if($debug){
9429
 
9430
						#debug msg
335 liveuser 9431
						echo "Adding DNS record to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9432
 
9433
						}#if end
9434
 
255 liveuser 9435
					#函式說明:
9436
					#新增DNS記錄到檔案裡面.
9437
					#回傳結果:
9438
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9439
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9440
					#$result["function"],當前執行的函式名稱.
9441
					#$result["argu"],所使用的參數.
9442
					#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
9443
					#$result["domain"],字串,RR所屬domain.
9444
					#$result["defaultTTL"],字串,預設的RR更新時間.
9445
					#$result["comment"],字串陣列,逐行的註解.
9446
					#必填參數:
9447
					#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
333 liveuser 9448
					$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 9449
					#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
9450
					$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
9451
					#可省略參數:
9452
					#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
9453
					$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
9454
					#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
9455
					#$conf["debug"]="false";
9456
					#參考資料:
9457
					#無.
9458
					#備註:
9459
					#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
9460
					#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
9461
					#php-pear上的Net_DNS2也可以解析RR.
9462
					$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
9463
					unset($conf["zerossl::updateDnsRecordFile"]);
9464
 
9465
					#如果執行異常
9466
					if($updateDnsRecordFile["status"]==="false"){
9467
 
9468
						#設置錯誤識別
9469
						$result["status"]="false";
9470
 
9471
						#設置錯誤訊息
9472
						$result["error"]=$updateDnsRecordFile;
9473
 
9474
						#回傳結果
9475
						return $result;
9476
 
9477
						}#if end
281 liveuser 9478
 
9479
					#if enable debug
9480
					if($debug){
9481
 
9482
						#debug msg
336 liveuser 9483
						echo "Restarting DNS service to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9484
 
9485
						}#if end
9486
 
255 liveuser 9487
					#重新啟動dns伺服器
9488
					#函式說明:
9489
					#呼叫shell執行系統命令,並取得回傳的內容.
9490
					#回傳結果:
9491
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9492
					#$result["error"],錯誤訊息陣列.
9493
					#$result["function"],當前執行的函數名稱.
9494
					#$result["argu"],使用的參數.
9495
					#$result["cmd"],執行的指令內容.
9496
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9497
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9498
					#$result["content"],為執行完後的輸出字串.
9499
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9500
					#$result["running"],是否還在執行.
9501
					#$result["pid"],pid.
9502
					#$result["statusCode"],執行結束後的代碼.
9503
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9504
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9505
					#必填參數:
9506
					#$conf["command"],字串,要執行的指令.
291 liveuser 9507
					$conf["external::callShell"]["command"]="systemctl";
255 liveuser 9508
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9509
					$conf["external::callShell"]["fileArgu"]=__FILE__;
9510
					#可省略參數:
9511
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9512
					$conf["external::callShell"]["argu"]=array("restart","named");
9513
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9514
					#$conf["arguIsAddr"]=array();
9515
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9516
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9517
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9518
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9519
					#$conf["enablePrintDescription"]="true";
9520
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9521
					#$conf["printDescription"]="";
9522
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9523
					#$conf["escapeshellarg"]="false";
9524
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9525
					#$conf["thereIsShellVar"]=array();
9526
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9527
					#$conf["username"]="";
9528
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9529
					#$conf["password"]="";
9530
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9531
					#$conf["useScript"]="";
9532
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9533
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9534
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9535
					#$conf["inBackGround"]="";
9536
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9537
					#$conf["getErr"]="false";
9538
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9539
					#$conf["doNotRun"]="false";
302 liveuser 9540
					#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
9541
					#$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 9542
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
9543
					$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
9544
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
9545
					#$conf["remoteUser"]="root";
9546
					#參考資料:
9547
					#exec=>http://php.net/manual/en/function.exec.php
9548
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9549
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9550
					#備註:
9551
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9552
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9553
					$callShell=external::callShell($conf["external::callShell"]);
9554
					unset($conf["external::callShell"]);
9555
 
9556
					#如果執行異常
9557
					if($callShell["status"]==="false"){
9558
 
9559
						#設置錯誤識別
9560
						$result["status"]="false";
9561
 
9562
						#設置錯誤訊息
9563
						$result["error"]=$callShell;
9564
 
9565
						#回傳結果
9566
						return $result;
9567
 
9568
						}#if end
281 liveuser 9569
 
9570
					#if enable debug
9571
					if($debug){
9572
 
9573
						#debug msg
336 liveuser 9574
						echo "Request zerossl to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9575
 
9576
						}#if end
9577
 
294 liveuser 9578
					#無窮迴圈
9579
					while(true){
255 liveuser 9580
 
294 liveuser 9581
						#函式說明:
9582
						#請求驗證已經透過zerossl::createCertificate要求的domain.
9583
						#回傳結果:
9584
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9585
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
9586
						#$result["function"],當前執行的函式名稱.
9587
						#$result["argu"],所使用的參數.
9588
						#$result["curl_verbose_info"],curl執行的詳細資訊.
9589
						#$result["content"],結果json字串.
9590
						#必填參數:
9591
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
9592
						$conf["zerossl::verifyDomain"]["id"]=$csrId;
9593
						#可省略參數:
9594
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
9595
						$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
9596
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
9597
						$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
9598
						#參考資料:
9599
						#https://zerossl.com/documentation/api/verify-domains/
9600
						#備註:
9601
						#無.
9602
						$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
9603
						unset($conf["zerossl::verifyDomain"]);
9604
 
9605
						#如果執行異常
9606
						if($verifyDomain["status"]==="false"){
9607
 
9608
							#設置錯誤識別
9609
							$result["status"]="false";
255 liveuser 9610
 
294 liveuser 9611
							#設置錯誤訊息
9612
							$result["error"]=$verifyDomain;
255 liveuser 9613
 
294 liveuser 9614
							#回傳結果
9615
							return $result;
9616
 
9617
							}#if end
9618
 
9619
						#如果沒有回內容
9620
						if(!isset($verifyDomain["content"])){
9621
 
9622
							#設置錯誤識別
9623
							$result["status"]="false";
9624
 
9625
							#設置錯誤訊息
9626
							$result["error"]=$verifyDomain;
9627
 
9628
							#回傳結果
9629
							return $result;
9630
 
9631
							}#if end
9632
 
9633
						#如果回應不是 json
9634
						if(!(json_validate($verifyDomain["content"]))){
9635
 
9636
							#設置錯誤識別
9637
							$result["status"]="false";
9638
 
9639
							#設置錯誤訊息
9640
							$result["error"]=$verifyDomain;
9641
 
9642
							#回傳結果
9643
							return $result;
9644
 
9645
							}#if end
9646
 
9647
						/*
9648
						範例json:
9649
						{"id":"51cff04454e6a6860abfecc8072db602","type":"1","common_name":"silverblue-guest.qbpwcf.org","additional_domains":"","created":"2026-03-06 13:45:39","expires":"2026-06-04 23:59:59","status":"pending_validation","validation_type":"CNAME_CSR_HASH","validation_emails":"","replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"silverblue-guest.qbpwcf.org":["admin@silverblue-guest.qbpwcf.org","administrator@silverblue-guest.qbpwcf.org","hostmaster@silverblue-guest.qbpwcf.org","postmaster@silverblue-guest.qbpwcf.org","webmaster@silverblue-guest.qbpwcf.org","admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"silverblue-guest.qbpwcf.org":{"file_validation_url_http":"http:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_url_https":"https:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_content":["58B9EB7890F754D041698170B22D22205D710ED09B419A809E5C92C38195DD36","comodoca.com","627e45f007045f0"],"cname_validation_p1":"_383346FA54F492EC8B2A6C421A052827.silverblue-guest.qbpwcf.org","cname_validation_p2":"58B9EB7890F754D041698170B22D2220.5D710ED09B419A809E5C92C38195DD36.627e45f007045f0.comodoca.com"}}},"signature_algorithm_properties":null}
9650
						*/
9651
 
9652
						#解析json回應
9653
						$verifyDomainRes=json_decode($verifyDomain["content"]);
9654
 
9655
						#如果回應含有 success
9656
						if(isset($verifyDomainRes->success)){
9657
 
9658
							#如果是 zerossl 驗證失敗
9659
							if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
9660
 
9661
								#如果是 CNAME 記錄找不到
9662
								if($verifyDomainRes->error->code===0){
9663
 
9664
									#取得錯誤訊息
9665
									#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
9666
 
9667
									#if enable debug
9668
									if($debug){
9669
 
9670
										#debug msg
9671
										echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
9672
 
9673
										}#if end
9674
 
9675
									#if enable debug
9676
									if($debug){
9677
 
9678
										#debug msg
9679
										echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
9680
 
9681
										}#if end
9682
 
9683
									#休息60秒
9684
									sleep(60);
9685
 
9686
									#再跑一次要求認證憑證
9687
									continue;
9688
 
9689
									}#if end
9690
 
9691
								#反之為不接受的錯誤訊息
9692
								else{
9693
 
9694
									#設置錯誤識別
9695
									$result["status"]="false";
9696
 
9697
									#設置錯誤訊息
9698
									$result["error"]=$verifyDomain;
9699
 
9700
									#回傳結果
9701
									return $result;
9702
 
9703
									}#else end
9704
 
9705
								}#if end
9706
 
9707
							}#if end
9708
 
9709
						#反之如果回應含有 status
9710
						else if(isset($verifyDomainRes->status)){
9711
 
9712
							#如果是 zerossl 尚在驗證中
9713
							if($verifyDomainRes->status==="pending_validation"){
9714
 
9715
								#if enable debug
9716
								if($debug){
9717
 
9718
									#debug msg
9719
									echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9720
 
9721
									}#if end
9722
 
9723
								#無窮迴圈
9724
								while(true){
9725
 
9726
									#查詢驗證狀況
9727
									#函式說明:
9728
									#取得CSR在zerossl上的狀態
9729
									#回傳結果:
9730
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9731
									#$reuslt["error"],執行不正常結束的錯訊息陣列.
9732
									#$result["function"],當前執行的函式名稱.
9733
									#$result["argu"],所使用的參數.
9734
									#$result["curl_verbose_info"],curl執行的詳細資訊.
9735
									#$result["content"],結果json字串.
9736
									#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9737
									#必填參數:
9738
									#$conf["id"],字串,zerossl::createCertificate回傳的id.
9739
									$conf["zerossl::getCertSta"]["id"]=$csrId;
9740
									#可省略參數:
9741
									#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
9742
									$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
9743
									#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
9744
									$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
9745
									#參考資料:
9746
									#https://zerossl.com/documentation/api/get-certificate/
9747
									#備註:
9748
									#無.
9749
									$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
9750
									unset($conf["zerossl::getCertSta"]);
9751
 
9752
									#如果執行異常
9753
									if($getCertSta["status"]==="false"){
9754
 
9755
										#設置錯誤識別
9756
										$result["status"]="false";
9757
 
9758
										#設置錯誤訊息
9759
										$result["error"]=$getCertSta;
9760
 
9761
										#回傳結果
9762
										return $result;
9763
 
9764
										}#if end
9765
 
9766
									#如果沒有回應內容
9767
									if(!isset($getCertSta["content"])){
9768
 
9769
										#設置錯誤識別
9770
										$result["status"]="false";
9771
 
9772
										#設置錯誤訊息
9773
										$result["error"]=$getCertSta;
9774
 
9775
										#回傳結果
9776
										return $result;
9777
 
9778
										}#if end
9779
 
9780
									#如果回應不是 json
9781
									if(!(json_validate($getCertSta["content"]))){
9782
 
9783
										#設置錯誤識別
9784
										$result["status"]="false";
9785
 
9786
										#設置錯誤訊息
9787
										$result["error"]=$getCertSta;
9788
 
9789
										#回傳結果
9790
										return $result;
9791
 
9792
										}#if end
9793
 
9794
									#解析json回應
9795
									$getCertStaRes=json_decode($getCertSta["content"]);
9796
 
9797
									#如果憑證已經驗證通過了
9798
									if($getCertStaRes->status==="issued"){
9799
 
9800
										#if enable debug
9801
										if($debug){
9802
 
9803
											#debug msg
9804
											echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
9805
 
9806
											}#if end
9807
 
9808
										#結束等待,離開while
9809
										break 2;
9810
 
9811
										}#if end
9812
 
9813
									#如果 zerossl 尚在處理中
9814
									else if($getCertStaRes->status==="pending_validation"){
9815
 
9816
										#if enable debug
9817
										if($debug){
9818
 
9819
											#debug msg
9820
											echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9821
 
9822
											}#if end
9823
 
9824
										#休息1分鐘
9825
										sleep(60);
9826
 
9827
										#再次確認憑證的狀態
9828
										continue;
9829
 
9830
										}#if end
9831
 
9832
									#反之
9833
									else{
9834
 
9835
										#例外狀況
9836
 
9837
										#設置錯誤識別
9838
										$result["status"]="false";
9839
 
9840
										#設置錯誤訊息
9841
										$result["error"]=$getCertSta;
9842
 
9843
										#回傳結果
9844
										return $result;
9845
 
9846
										}#else end
9847
 
9848
									}#while end
9849
 
9850
								}#if end
9851
 
9852
							}#if end
255 liveuser 9853
 
294 liveuser 9854
						}#while end
281 liveuser 9855
 
294 liveuser 9856
 
281 liveuser 9857
					#if enable debug
9858
					if($debug){
9859
 
9860
						#debug msg
291 liveuser 9861
						echo "Downling ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 9862
 
9863
						}#if end
9864
 
255 liveuser 9865
					#函式說明:
9866
					#下載certificate.
9867
					#回傳結果:
9868
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9869
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9870
					#$result["function"],當前執行的函式名稱.
9871
					#$result["argu"],所使用的參數.
9872
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9873
					#$result["content"],結果json字串.
9874
					#$result["certificate.crt"],字串,certificate.crt的內容.
9875
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
9876
					#必填參數:
9877
					#無.
9878
					#可省略參數:
9879
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9880
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9881
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9882
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9883
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
9884
					$conf["zerossl::getCert"]["id"]=$csrId;
9885
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
9886
					#$conf["zerossl::getCert"]["cname"]="";
9887
					#參考資料:
9888
					#https://zerossl.com/documentation/api/download-certificate-inline/
9889
					#備註:
9890
					#無.
9891
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
9892
					unset($conf["zerossl::getCert"]);
9893
 
9894
					#如果執行異常
9895
					if($getCert["status"]==="false"){
9896
 
9897
						#設置錯誤識別
9898
						$result["status"]="false";
9899
 
9900
						#設置錯誤訊息
9901
						$result["error"]=$getCert;
9902
 
9903
						#回傳結果
9904
						return $result;
9905
 
9906
						}#if end
281 liveuser 9907
 
9908
					#if enable debug
9909
					if($debug){
9910
 
9911
						#debug msg
291 liveuser 9912
						echo "Creating ssl for domain name(".$cName.").".PHP_EOL;
281 liveuser 9913
 
9914
						}#if end
9915
 
255 liveuser 9916
					#建立 certificate.crt 檔案
9917
					#$cInfo["certPath"];
9918
 
9919
					#建立 ca_bundle.crt 檔案
9920
					#$cInfo["caPath"];
9921
 
9922
					#建立 certAndCa.crt 檔案
9923
					#$cInfo["certWithCaPath"];
9924
 
9925
					#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
9926
					#函式說明:
9927
					#一次建立多個檔案,並寫入內容.
9928
					#回傳結果:
9929
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9930
					#$result["error"],錯誤訊息陣列.
9931
					#$result["function"],當前執行的函數名稱.
9932
					#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
9933
					#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
9934
					#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
9935
					#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
9936
					#$result["argu"],使用的參數.
9937
					#必填參數:
9938
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9939
					$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
9940
					#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 9941
					$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 9942
					#可省略參數:
9943
					#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
9944
					$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
9945
					#參考資料:
9946
					#無.
9947
					#備註:
9948
					#無.
333 liveuser 9949
					$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 9950
					unset($conf["zerossl::writeMultiFile"]);
9951
 
9952
					#如果執行異常
9953
					if($writeMultiFile["status"]==="false"){
9954
 
9955
						#設置錯誤識別
9956
						$result["status"]="false";
9957
 
9958
						#設置錯誤訊息
9959
						$result["error"]=$writeMultiFile;
9960
 
9961
						#回傳結果
9962
						return $result;
9963
 
9964
						}#if end
9965
 
9966
					#儲存 actionAfterUpdateCert
9967
					$action=$cInfo["actionAfterUpdateCert"];
9968
 
9969
					#如果有多個指令要執行
294 liveuser 9970
					if(count($action)>0){
255 liveuser 9971
 
281 liveuser 9972
						#if enable debug
9973
						if($debug){
9974
 
9975
							#debug msg
338 liveuser 9976
							echo "There many cmd to run to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9977
 
9978
							}#if end
9979
 
294 liveuser 9980
						#針對每個指令
255 liveuser 9981
						foreach($action as $ac){
9982
 
281 liveuser 9983
							#if enable debug
9984
							if($debug){
9985
 
9986
								#debug msg
9987
								echo ".".PHP_EOL;
9988
 
9989
								}#if end
9990
 
255 liveuser 9991
							#函式說明:
9992
							#呼叫shell執行系統命令,並取得回傳的內容.
9993
							#回傳結果:
9994
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9995
							#$result["error"],錯誤訊息陣列.
9996
							#$result["function"],當前執行的函數名稱.
9997
							#$result["argu"],使用的參數.
9998
							#$result["cmd"],執行的指令內容.
9999
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10000
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10001
							#$result["content"],為執行完後的輸出字串.
10002
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10003
							#$result["running"],是否還在執行.
10004
							#$result["pid"],pid.
10005
							#$result["statusCode"],執行結束後的代碼.
10006
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10007
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10008
							#必填參數:
10009
							#$conf["command"],字串,要執行的指令.
302 liveuser 10010
							$conf["external::callShell"]["command"]=$ac;
255 liveuser 10011
							#$conf["fileArgu"],字串,變數__FILE__的內容.
10012
							$conf["external::callShell"]["fileArgu"]=__FILE__;
10013
							#可省略參數:
10014
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10015
							#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 10016
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10017
							#$conf["arguIsAddr"]=array();
10018
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10019
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10020
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10021
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10022
							#$conf["enablePrintDescription"]="true";
10023
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10024
							#$conf["printDescription"]="";
10025
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10026
							$conf["external::callShell"]["escapeshellarg"]="true";
10027
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10028
							#$conf["thereIsShellVar"]=array();
10029
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10030
							#$conf["username"]="";
10031
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10032
							#$conf["password"]="";
10033
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10034
							#$conf["useScript"]="";
10035
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10036
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10037
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10038
							#$conf["inBackGround"]="";
10039
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10040
							#$conf["getErr"]="false";
10041
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10042
							#$conf["doNotRun"]="false";
302 liveuser 10043
							#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10044
							$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10045
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10046
							#$conf["remoteIp"]="";
10047
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10048
							#$conf["remoteUser"]="";
10049
							#參考資料:
10050
							#exec=>http://php.net/manual/en/function.exec.php
10051
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10052
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10053
							#備註:
10054
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10055
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10056
							$callShell=external::callShell($conf["external::callShell"]);
10057
							unset($conf["external::callShell"]);
294 liveuser 10058
 
255 liveuser 10059
							#如果執行異常
294 liveuser 10060
							if($callShell["status"]==="false"){
255 liveuser 10061
 
10062
								#設置錯誤識別
10063
								$result["status"]="false";
10064
 
10065
								#設置錯誤訊息
10066
								$result["error"]=$callShell;
10067
 
10068
								#回傳結果
10069
								return $result;
10070
 
10071
								}#if end
10072
 
10073
							}#foreach end
10074
 
10075
						}#if end
10076
 
10077
					#反之
10078
					else{
10079
 
281 liveuser 10080
						#if enable debug
10081
						if($debug){
10082
 
10083
							#debug msg
291 liveuser 10084
							echo "There is only one cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 10085
 
10086
							}#if end
10087
 
10088
						#if enable debug
10089
						if($debug){
10090
 
10091
							#debug msg
10092
							echo ".".PHP_EOL;
10093
 
10094
							}#if end
10095
 
255 liveuser 10096
						#函式說明:
10097
						#呼叫shell執行系統命令,並取得回傳的內容.
10098
						#回傳結果:
10099
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10100
						#$result["error"],錯誤訊息陣列.
10101
						#$result["function"],當前執行的函數名稱.
10102
						#$result["argu"],使用的參數.
10103
						#$result["cmd"],執行的指令內容.
10104
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10105
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10106
						#$result["content"],為執行完後的輸出字串.
10107
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10108
						#$result["running"],是否還在執行.
10109
						#$result["pid"],pid.
10110
						#$result["statusCode"],執行結束後的代碼.
10111
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10112
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10113
						#必填參數:
10114
						#$conf["command"],字串,要執行的指令.
302 liveuser 10115
						$conf["external::callShell"]["command"]=$action[0];
255 liveuser 10116
						#$conf["fileArgu"],字串,變數__FILE__的內容.
10117
						$conf["external::callShell"]["fileArgu"]=__FILE__;
10118
						#可省略參數:
10119
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10120
						#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 10121
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10122
						#$conf["arguIsAddr"]=array();
10123
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10124
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10125
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10126
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10127
						#$conf["enablePrintDescription"]="true";
10128
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10129
						#$conf["printDescription"]="";
10130
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10131
						$conf["external::callShell"]["escapeshellarg"]="true";
10132
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10133
						#$conf["thereIsShellVar"]=array();
10134
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10135
						#$conf["username"]="";
10136
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10137
						#$conf["password"]="";
10138
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10139
						#$conf["useScript"]="";
10140
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10141
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10142
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10143
						#$conf["inBackGround"]="";
10144
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10145
						#$conf["getErr"]="false";
10146
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10147
						#$conf["doNotRun"]="false";
302 liveuser 10148
						#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10149
						$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10150
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10151
						#$conf["remoteIp"]="";
10152
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10153
						#$conf["remoteUser"]="";
10154
						#參考資料:
10155
						#exec=>http://php.net/manual/en/function.exec.php
10156
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10157
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10158
						#備註:
10159
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10160
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10161
						$callShell=external::callShell($conf["external::callShell"]);
10162
						unset($conf["external::callShell"]);
294 liveuser 10163
 
255 liveuser 10164
						#如果執行異常
294 liveuser 10165
						if($callShell["status"]==="false"){
255 liveuser 10166
 
10167
							#設置錯誤識別
10168
							$result["status"]="false";
10169
 
10170
							#設置錯誤訊息
10171
							$result["error"]=$callShell;
10172
 
10173
							#回傳結果
10174
							return $result;
10175
 
10176
							}#if end
10177
 
10178
						}#else end
10179
 
10180
					#要移除舊的憑證 
10181
 
281 liveuser 10182
					#if enable debug
10183
					if($debug){
10184
 
10185
						#debug msg
341 liveuser 10186
						echo "Revoke old ssl(".$conf["info"]["share"]["apiDomain"].") on zerossl".PHP_EOL;
281 liveuser 10187
 
10188
						}#if end
10189
 
255 liveuser 10190
					#舊憑證於zerossl上的id
10191
					#$oldCsrId
10192
 
341 liveuser 10193
					#無窮迴圈
10194
					while(true){
255 liveuser 10195
 
341 liveuser 10196
						#移除舊的憑證
10197
						#函式說明:
10198
						#請求廢除 issued zerossl certificate.
10199
						#回傳結果:
10200
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10201
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
10202
						#$result["function"],當前執行的函式名稱.
10203
						#$result["argu"],所使用的參數.
10204
						#$result["curl_verbose_info"],curl執行的詳細資訊.
10205
						#$result["content"],結果json字串.
10206
						#$result["busy"],若content結果含有busy屬性,且為1,則為"true";反之為"false".
10207
						#必填參數:
10208
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
10209
						$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
10210
						#可省略參數:
10211
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
10212
						$conf["zerosssl::revokeCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
10213
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
10214
						$conf["zerosssl::revokeCert"]["key"]=$conf["info"]["share"]["key"];
10215
						#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
10216
						$conf["zerosssl::revokeCert"]["reason"]="Superseded";
10217
						#參考資料:
10218
						#https://zerossl.com/documentation/api/revoke-certificate/
10219
						#備註:
10220
						#無.
10221
						$revokeCert=zerossl::revokeCert($conf["zerosssl::revokeCert"]);
10222
						unset($conf["zerosssl::revokeCert"]);
10223
 
10224
						#如果執行異常
10225
						if($revokeCert["status"]==="false"){
10226
 
10227
							#如果是 api endpoint busy
10228
							if($revokeCert["busy"]==="true"){
10229
 
10230
								#if enable debug
10231
								if($debug){
10232
 
10233
									#debug msg
10234
									echo "Api endpoint busy, retry revoke old ssl(".$conf["info"]["share"]["apiDomain"].") on zerossl in 60 seconds".PHP_EOL;
10235
 
10236
									}#if end
10237
 
10238
								#休息1分鐘
10239
								sleep(60);
10240
 
10241
								#再執行一次
10242
								continue;
10243
 
10244
								}#if end
10245
 
10246
							#設置錯誤識別
10247
							$result["status"]="false";
255 liveuser 10248
 
341 liveuser 10249
							#設置錯誤訊息
10250
							$result["error"]=$revokeCert;
255 liveuser 10251
 
341 liveuser 10252
							#回傳結果
10253
							return $result;
10254
 
10255
							}#if end
10256
 
10257
						#revoke 成功,跳出 while loop.
10258
						break;
10259
 
10260
						}#while end
10261
 
10262
					#if enable debug
10263
					if($debug){
10264
 
10265
						#debug msg
10266
						echo "Old ssl on zerossl(".$conf["info"]["share"]["apiDomain"].") revoked".PHP_EOL;
10267
 
291 liveuser 10268
						}#if end
10269
 
255 liveuser 10270
					}#if end
10271
 
10272
				#反之,尚不需要提前申請新的憑證
10273
				else{
10274
 
291 liveuser 10275
					#debug
10276
					#var_dump(__LINE__,"尚不需要提前申請新的憑證");exit;
10277
 
281 liveuser 10278
					#if enable debug
10279
					if($debug){
10280
 
10281
						#debug msg
291 liveuser 10282
						echo "ssl for domain name(".$cName.") is valid ".PHP_EOL;
281 liveuser 10283
 
10284
						}#if end
10285
 
10286
					#if enable debug
10287
					if($debug){
10288
 
10289
						#debug msg
291 liveuser 10290
						echo "Downling ssl for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 10291
 
10292
						}#if end
10293
 
310 liveuser 10294
					#if enable debug
10295
					if($debug){
10296
 
10297
						#debug msg
10298
						echo "ID for domain name(".$cName.") on zerossl is ".$csrId.".".PHP_EOL;
10299
 
10300
						}#if end
10301
 
255 liveuser 10302
					#下載憑證
10303
					#函式說明:
10304
					#下載certificate.
10305
					#回傳結果:
10306
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10307
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10308
					#$result["function"],當前執行的函式名稱.
10309
					#$result["argu"],所使用的參數.
10310
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10311
					#$result["content"],結果json字串.
10312
					#$result["certificate.crt"],字串,certificate.crt的內容.
10313
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
10314
					#必填參數:
10315
					#無.
10316
					#可省略參數:
10317
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 10318
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 10319
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 10320
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 10321
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
10322
					$conf["zerossl::getCert"]["id"]=$csrId;
10323
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
10324
					#$conf["zerossl::getCert"]["cname"]="";
10325
					#參考資料:
10326
					#https://zerossl.com/documentation/api/download-certificate-inline/
10327
					#備註:
10328
					#無.
10329
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
10330
					unset($conf["zerossl::getCert"]);
10331
 
10332
					#如果執行異常
10333
					if($getCert["status"]==="false"){
10334
 
10335
						#設置錯誤識別
10336
						$result["status"]="false";
10337
 
10338
						#設置錯誤訊息
10339
						$result["error"]=$getCert;
10340
 
10341
						#回傳結果
10342
						return $result;
10343
 
10344
						}#if end
281 liveuser 10345
 
10346
					#if enable debug
10347
					if($debug){
10348
 
10349
						#debug msg
291 liveuser 10350
						echo "Getting host ssl for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10351
 
10352
						}#if end
10353
 
255 liveuser 10354
					#zerossl上的certificate.crt內容
10355
					#$getCert["certificate.crt"];
310 liveuser 10356
 
255 liveuser 10357
					#zerossl上的ca_bundle.crt內容
10358
					#$getCert["ca_bundle.crt"];
10359
 
10360
					#certificate.crt and ca_bundle.crt 合併後的檔案內容
10361
					#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
10362
 
10363
					#certificate.crt 檔案
10364
					#$cInfo["certPath"];
10365
 
10366
					#ca_bundle.crt 檔案
10367
					#$cInfo["caPath"];
10368
 
10369
					#certAndCa.crt 檔案
10370
					#$cInfo["certWithCaPath"];
281 liveuser 10371
 
10372
					#if enable debug
10373
					if($debug){
10374
 
10375
						#debug msg
310 liveuser 10376
						echo "Getting host ssl(certificate.crt) which path is ".$cInfo["ssl"]["certPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10377
 
10378
						}#if end
255 liveuser 10379
 
10380
					#取得既有的 certificate.crt 檔案內容
10381
					#函式說明:
10382
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10383
					#回傳的變數說明:
10384
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10385
					#$result["error"],錯誤訊息提示.
10386
					#$result["warning"],警告訊息.
10387
					#$result["function"],當前執行的函數名稱.
10388
					#$result["fileContent"],爲檔案的內容陣列.
10389
					#$result["lineCount"],爲檔案內容總共的行數.
10390
					#$result["fullContent"],為檔案的完整內容.
10391
					#$result["base64dataOnly"],檔案的base64data.
10392
					#$result["base64data"],為在網頁上給予src參數的數值.
10393
					#$result["mimeType"],為檔案的mime type.
10394
					#必填參數:
10395
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10396
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certPath"];
255 liveuser 10397
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10398
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10399
					#可省略參數:
10400
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10401
					#$conf["web"]="true";
10402
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10403
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10404
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10405
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10406
					#參考資料:
10407
					#file(),取得檔案內容的行數.
10408
					#file=>http:#php.net/manual/en/function.file.php
10409
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10410
					#filesize=>http://php.net/manual/en/function.filesize.php
10411
					#參考資料:
10412
					#無.
10413
					#備註:
10414
					#無.
291 liveuser 10415
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10416
					unset($conf["fileAccesss::getFileContent"]);
10417
 
10418
					#如果執行異常
10419
					if($getFileContent["status"]==="false"){
10420
 
10421
						#設置錯誤識別
10422
						$result["status"]="false";
10423
 
10424
						#設置錯誤訊息
10425
						$result["error"]=$getFileContent;
10426
 
10427
						#回傳結果
10428
						return $result;
10429
 
10430
						}#if end
10431
 
281 liveuser 10432
					#if enable debug
10433
					if($debug){
10434
 
10435
						#debug msg
291 liveuser 10436
						echo "Checking host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10437
 
10438
						}#if end
10439
 
291 liveuser 10440
					#預設 certificate.crt 不用更新
10441
					$certificate_need_update="false";
10442
 
255 liveuser 10443
					#如果既有憑證跟剛下載的憑證不一樣
10444
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
10445
 
10446
						#識別要改成下載好的憑證
10447
						$certificate_need_update="true";
281 liveuser 10448
 
10449
						#if enable debug
10450
						if($debug){
10451
 
10452
							#debug msg
291 liveuser 10453
							echo "SSL(certificate.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10454
 
10455
							}#if end
255 liveuser 10456
 
10457
						}#if end
281 liveuser 10458
 
10459
					#if enable debug
10460
					if($debug){
10461
 
10462
						#debug msg
310 liveuser 10463
						echo "Getting host ssl(ca_bundle.crt) which path is ".$cInfo["ssl"]["caPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10464
 
10465
						}#if end
10466
 
255 liveuser 10467
					#取得既有的 ca_bundle.crt 檔案內容
10468
					#函式說明:
10469
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10470
					#回傳的變數說明:
10471
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10472
					#$result["error"],錯誤訊息提示.
10473
					#$result["warning"],警告訊息.
10474
					#$result["function"],當前執行的函數名稱.
10475
					#$result["fileContent"],爲檔案的內容陣列.
10476
					#$result["lineCount"],爲檔案內容總共的行數.
10477
					#$result["fullContent"],為檔案的完整內容.
10478
					#$result["base64dataOnly"],檔案的base64data.
10479
					#$result["base64data"],為在網頁上給予src參數的數值.
10480
					#$result["mimeType"],為檔案的mime type.
10481
					#必填參數:
10482
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10483
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["caPath"];
255 liveuser 10484
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10485
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10486
					#可省略參數:
10487
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10488
					#$conf["web"]="true";
10489
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10490
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10491
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10492
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10493
					#參考資料:
10494
					#file(),取得檔案內容的行數.
10495
					#file=>http:#php.net/manual/en/function.file.php
10496
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10497
					#filesize=>http://php.net/manual/en/function.filesize.php
10498
					#參考資料:
10499
					#無.
10500
					#備註:
10501
					#無.
291 liveuser 10502
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10503
					unset($conf["fileAccesss::getFileContent"]);
10504
 
10505
					#如果執行異常
10506
					if($getFileContent["status"]==="false"){
10507
 
10508
						#設置錯誤識別
10509
						$result["status"]="false";
10510
 
10511
						#設置錯誤訊息
10512
						$result["error"]=$getFileContent;
10513
 
10514
						#回傳結果
10515
						return $result;
10516
 
10517
						}#if end
10518
 
281 liveuser 10519
					#if enable debug
10520
					if($debug){
10521
 
10522
						#debug msg
291 liveuser 10523
						echo "Checking host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10524
 
10525
						}#if end
10526
 
291 liveuser 10527
					#預設 ca_bundle.crt 不用更新
10528
					$ca_bundle_need_update="false";
10529
 
255 liveuser 10530
					#如果既有憑證跟剛下載的憑證不一樣
10531
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
10532
 
10533
						#識別要改成下載好的憑證
10534
						$ca_bundle_need_update="true";
281 liveuser 10535
 
10536
						#if enable debug
10537
						if($debug){
10538
 
10539
							#debug msg
291 liveuser 10540
							echo "SSL(ca_bundle.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10541
 
10542
							}#if end
255 liveuser 10543
 
10544
						}#if end
10545
 
281 liveuser 10546
					#if enable debug
10547
					if($debug){
10548
 
10549
						#debug msg
310 liveuser 10550
						echo "Getting host ssl(cert and ca_bundle) which path is ".$cInfo["ssl"]["certWithCaPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10551
 
10552
						}#if end
10553
 
255 liveuser 10554
					#取得既有的 certWithCa 檔案內容
10555
					#函式說明:
10556
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10557
					#回傳的變數說明:
10558
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10559
					#$result["error"],錯誤訊息提示.
10560
					#$result["warning"],警告訊息.
10561
					#$result["function"],當前執行的函數名稱.
10562
					#$result["fileContent"],爲檔案的內容陣列.
10563
					#$result["lineCount"],爲檔案內容總共的行數.
10564
					#$result["fullContent"],為檔案的完整內容.
10565
					#$result["base64dataOnly"],檔案的base64data.
10566
					#$result["base64data"],為在網頁上給予src參數的數值.
10567
					#$result["mimeType"],為檔案的mime type.
10568
					#必填參數:
10569
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10570
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certWithCaPath"];
255 liveuser 10571
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10572
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10573
					#可省略參數:
10574
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10575
					#$conf["web"]="true";
10576
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10577
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10578
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10579
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10580
					#參考資料:
10581
					#file(),取得檔案內容的行數.
10582
					#file=>http:#php.net/manual/en/function.file.php
10583
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10584
					#filesize=>http://php.net/manual/en/function.filesize.php
10585
					#參考資料:
10586
					#無.
10587
					#備註:
10588
					#無.
291 liveuser 10589
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10590
					unset($conf["fileAccesss::getFileContent"]);
10591
 
10592
					#如果執行異常
10593
					if($getFileContent["status"]==="false"){
10594
 
10595
						#設置錯誤識別
10596
						$result["status"]="false";
10597
 
10598
						#設置錯誤訊息
10599
						$result["error"]=$getFileContent;
10600
 
10601
						#回傳結果
10602
						return $result;
10603
 
10604
						}#if end
10605
 
281 liveuser 10606
					#if enable debug
10607
					if($debug){
10608
 
10609
						#debug msg
291 liveuser 10610
						echo "Checking host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10611
 
10612
						}#if end
10613
 
291 liveuser 10614
					#預設 cert_and_ca_bundle.crt 不用更新
10615
					$cert_and_ca_bundle_need_update="false";
10616
 
255 liveuser 10617
					#如果既有憑證跟剛下載的憑證不一樣
10618
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
10619
 
10620
						#識別要改成下載好的憑證
10621
						$cert_and_ca_bundle_need_update="true";
281 liveuser 10622
 
10623
						#if enable debug
10624
						if($debug){
10625
 
10626
							#debug msg
291 liveuser 10627
							echo "SSL(cert and ca_bundle) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10628
 
10629
							}#if end
255 liveuser 10630
 
10631
						}#if end
10632
 
10633
					#預設不需要執行更新憑證後的動作
10634
					$requireActionAfterUpdateCert="false";
10635
 
10636
					#如果 certificate 需要更新
10637
					if($certificate_need_update==="true"){
10638
 
281 liveuser 10639
						#if enable debug
10640
						if($debug){
10641
 
10642
							#debug msg
291 liveuser 10643
							echo "Updating host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10644
 
10645
							}#if end
10646
 
255 liveuser 10647
						#更新之
10648
						#函式說明:
10649
						#一次建立多個檔案,並寫入內容.
10650
						#回傳結果:
10651
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10652
						#$result["error"],錯誤訊息陣列.
10653
						#$result["function"],當前執行的函數名稱.
10654
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10655
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10656
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10657
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10658
						#$result["argu"],使用的參數.
10659
						#必填參數:
10660
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10661
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10662
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10663
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"]);
255 liveuser 10664
						#可省略參數:
10665
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10666
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
10667
						#參考資料:
10668
						#無.
10669
						#備註:
10670
						#無.
291 liveuser 10671
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10672
						unset($conf["zerossl::writeMultiFile"]);
10673
 
10674
						#如果執行異常
10675
						if($writeMultiFile["status"]==="false"){
10676
 
10677
							#設置錯誤識別
10678
							$result["status"]="false";
10679
 
10680
							#設置錯誤訊息
10681
							$result["error"]=$writeMultiFile;
10682
 
10683
							#回傳結果
10684
							return $result;
10685
 
10686
							}#if end
293 liveuser 10687
 
10688
						#設置需要執行指令來生效憑證
10689
						$requireActionAfterUpdateCert="true";
255 liveuser 10690
 
10691
						}#if end
10692
 
10693
					#如果 ca_bunle 需要更新
10694
					if($ca_bundle_need_update==="true"){
10695
 
281 liveuser 10696
						#if enable debug
10697
						if($debug){
10698
 
10699
							#debug msg
291 liveuser 10700
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10701
 
10702
							}#if end
293 liveuser 10703
 
10704
						#設置需要執行指令來生效憑證
10705
						$requireActionAfterUpdateCert="true";
281 liveuser 10706
 
255 liveuser 10707
						#更新之
10708
						#函式說明:
10709
						#一次建立多個檔案,並寫入內容.
10710
						#回傳結果:
10711
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10712
						#$result["error"],錯誤訊息陣列.
10713
						#$result["function"],當前執行的函數名稱.
10714
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10715
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10716
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10717
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10718
						#$result["argu"],使用的參數.
10719
						#必填參數:
10720
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10721
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10722
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10723
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["caPath"]);
255 liveuser 10724
						#可省略參數:
10725
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10726
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
10727
						#參考資料:
10728
						#無.
10729
						#備註:
10730
						#無.
291 liveuser 10731
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10732
						unset($conf["zerossl::writeMultiFile"]);
10733
 
10734
						#如果執行異常
10735
						if($writeMultiFile["status"]==="false"){
10736
 
10737
							#設置錯誤識別
10738
							$result["status"]="false";
10739
 
10740
							#設置錯誤訊息
10741
							$result["error"]=$writeMultiFile;
10742
 
10743
							#回傳結果
10744
							return $result;
10745
 
10746
							}#if end
293 liveuser 10747
 
10748
						#設置需要執行指令來生效憑證
10749
						$requireActionAfterUpdateCert="true";
255 liveuser 10750
 
10751
						}#if end
10752
 
10753
					#如果 certificate and ca_bundle 需要更新
10754
					if($cert_and_ca_bundle_need_update==="true"){
10755
 
281 liveuser 10756
						#if enable debug
10757
						if($debug){
10758
 
10759
							#debug msg
291 liveuser 10760
							echo "Updating host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10761
 
10762
							}#if end
10763
 
255 liveuser 10764
						#更新之
10765
						#函式說明:
10766
						#一次建立多個檔案,並寫入內容.
10767
						#回傳結果:
10768
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10769
						#$result["error"],錯誤訊息陣列.
10770
						#$result["function"],當前執行的函數名稱.
10771
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10772
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10773
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10774
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10775
						#$result["argu"],使用的參數.
10776
						#必填參數:
10777
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10778
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10779
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10780
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certWithCaPath"]);
255 liveuser 10781
						#可省略參數:
10782
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10783
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
10784
						#參考資料:
10785
						#無.
10786
						#備註:
10787
						#無.
291 liveuser 10788
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10789
						unset($conf["zerossl::writeMultiFile"]);
10790
 
10791
						#如果執行異常
10792
						if($writeMultiFile["status"]==="false"){
10793
 
10794
							#設置錯誤識別
10795
							$result["status"]="false";
10796
 
10797
							#設置錯誤訊息
10798
							$result["error"]=$writeMultiFile;
10799
 
10800
							#回傳結果
10801
							return $result;
10802
 
10803
							}#if end
10804
 
293 liveuser 10805
						#設置需要執行指令來生效憑證
10806
						$requireActionAfterUpdateCert="true";
10807
 
255 liveuser 10808
						}#if end
10809
 
10810
					#如果有需要執行指令來生效憑證
10811
					if($requireActionAfterUpdateCert==="true"){
10812
 
281 liveuser 10813
						#if enable debug
10814
						if($debug){
10815
 
10816
							#debug msg
291 liveuser 10817
							echo "Action required to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 10818
 
10819
							}#if end
10820
 
255 liveuser 10821
						#儲存 actionAfterUpdateCert
10822
						$action=$cInfo["actionAfterUpdateCert"];
10823
 
10824
						#如果有多個指令要執行
310 liveuser 10825
						if(count($action)>0){
255 liveuser 10826
 
281 liveuser 10827
							#if enable debug
10828
							if($debug){
10829
 
10830
								#debug msg
291 liveuser 10831
								echo "There are many cmds to run to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 10832
 
10833
								}#if end
10834
 
255 liveuser 10835
							#針對每的指令
10836
							foreach($action as $ac){
10837
 
281 liveuser 10838
								#if enable debug
10839
								if($debug){
10840
 
10841
									#debug msg
10842
									echo ".".PHP_EOL;
10843
 
10844
									}#if end
293 liveuser 10845
 
10846
								#函式說明:
255 liveuser 10847
								#呼叫shell執行系統命令,並取得回傳的內容.
10848
								#回傳結果:
10849
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10850
								#$result["error"],錯誤訊息陣列.
10851
								#$result["function"],當前執行的函數名稱.
10852
								#$result["argu"],使用的參數.
10853
								#$result["cmd"],執行的指令內容.
10854
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10855
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10856
								#$result["content"],為執行完後的輸出字串.
10857
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10858
								#$result["running"],是否還在執行.
10859
								#$result["pid"],pid.
10860
								#$result["statusCode"],執行結束後的代碼.
10861
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10862
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10863
								#必填參數:
10864
								#$conf["command"],字串,要執行的指令.
302 liveuser 10865
								$conf["external::callShell"]["command"]=$ac;
255 liveuser 10866
								#$conf["fileArgu"],字串,變數__FILE__的內容.
10867
								$conf["external::callShell"]["fileArgu"]=__FILE__;
10868
								#可省略參數:
10869
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10870
								#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
255 liveuser 10871
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10872
								#$conf["arguIsAddr"]=array();
10873
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10874
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10875
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10876
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10877
								#$conf["enablePrintDescription"]="true";
10878
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10879
								#$conf["printDescription"]="";
10880
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10881
								$conf["external::callShell"]["escapeshellarg"]="true";
10882
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10883
								#$conf["thereIsShellVar"]=array();
10884
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10885
								#$conf["username"]="";
10886
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10887
								#$conf["password"]="";
10888
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10889
								#$conf["useScript"]="";
10890
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10891
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10892
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10893
								#$conf["inBackGround"]="";
10894
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10895
								#$conf["getErr"]="false";
10896
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10897
								#$conf["doNotRun"]="false";
302 liveuser 10898
								#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10899
								$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10900
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10901
								#$conf["remoteIp"]="";
10902
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10903
								#$conf["remoteUser"]="";
10904
								#參考資料:
10905
								#exec=>http://php.net/manual/en/function.exec.php
10906
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10907
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10908
								#備註:
10909
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10910
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10911
								$callShell=external::callShell($conf["external::callShell"]);
10912
								unset($conf["external::callShell"]);
10913
 
10914
								#如果執行異常
310 liveuser 10915
								if($callShell["status"]==="false"){
255 liveuser 10916
 
10917
									#設置錯誤識別
10918
									$result["status"]="false";
10919
 
10920
									#設置錯誤訊息
10921
									$result["error"]=$callShell;
10922
 
10923
									#回傳結果
10924
									return $result;
10925
 
10926
									}#if end
10927
 
10928
								}#foreach end
10929
 
10930
							}#if end
10931
 
291 liveuser 10932
						#反之
10933
						else{
10934
 
10935
							#if enable debug
10936
							if($debug){
10937
 
10938
								#debug msg
10939
								echo "There is only one cmd to run to apply ssl for domain name(".$cName.")".PHP_EOL;
255 liveuser 10940
 
291 liveuser 10941
								}#if end
281 liveuser 10942
 
291 liveuser 10943
							#函式說明:
10944
							#呼叫shell執行系統命令,並取得回傳的內容.
10945
							#回傳結果:
10946
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10947
							#$result["error"],錯誤訊息陣列.
10948
							#$result["function"],當前執行的函數名稱.
10949
							#$result["argu"],使用的參數.
10950
							#$result["cmd"],執行的指令內容.
10951
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10952
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10953
							#$result["content"],為執行完後的輸出字串.
10954
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10955
							#$result["running"],是否還在執行.
10956
							#$result["pid"],pid.
10957
							#$result["statusCode"],執行結束後的代碼.
10958
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10959
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10960
							#必填參數:
10961
							#$conf["command"],字串,要執行的指令.
302 liveuser 10962
							$conf["external::callShell"]["command"]=$action;
291 liveuser 10963
							#$conf["fileArgu"],字串,變數__FILE__的內容.
10964
							$conf["external::callShell"]["fileArgu"]=__FILE__;
10965
							#可省略參數:
10966
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10967
							#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
291 liveuser 10968
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10969
							#$conf["arguIsAddr"]=array();
10970
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10971
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10972
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10973
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10974
							#$conf["enablePrintDescription"]="true";
10975
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10976
							#$conf["printDescription"]="";
10977
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10978
							$conf["external::callShell"]["escapeshellarg"]="true";
10979
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10980
							#$conf["thereIsShellVar"]=array();
10981
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10982
							#$conf["username"]="";
10983
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10984
							#$conf["password"]="";
10985
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10986
							#$conf["useScript"]="";
10987
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10988
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10989
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10990
							#$conf["inBackGround"]="";
10991
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10992
							#$conf["getErr"]="false";
10993
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10994
							#$conf["doNotRun"]="false";
302 liveuser 10995
							#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10996
							$conf["external::callShell"]["cmdContainArgu"]="true";
291 liveuser 10997
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10998
							#$conf["remoteIp"]="";
10999
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
11000
							#$conf["remoteUser"]="";
11001
							#參考資料:
11002
							#exec=>http://php.net/manual/en/function.exec.php
11003
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11004
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11005
							#備註:
11006
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11007
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11008
							$callShell=external::callShell($conf["external::callShell"]);
11009
							unset($conf["external::callShell"]);
11010
 
11011
							#如果執行異常
310 liveuser 11012
							if($callShell["status"]==="false"){
255 liveuser 11013
 
291 liveuser 11014
								#設置錯誤識別
11015
								$result["status"]="false";
255 liveuser 11016
 
291 liveuser 11017
								#設置錯誤訊息
11018
								$result["error"]=$callShell;
255 liveuser 11019
 
291 liveuser 11020
								#回傳結果
11021
								return $result;
255 liveuser 11022
 
291 liveuser 11023
								}#if end
11024
 
11025
							}#else end
11026
 
11027
						}#if end
255 liveuser 11028
 
11029
					}#else end
11030
 
11031
				}#else end
291 liveuser 11032
 
255 liveuser 11033
			}#foreach end
11034
 
11035
		}#function sslUpdater_idle end
11036
 
226 liveuser 11037
	}#class zerossl end
255 liveuser 11038