Subversion Repositories php-qbpwcf

Rev

Rev 346 | Rev 404 | 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"],所使用的參數.
1406
	#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
1407
	#$result["domain"],字串,RR所屬domain.
1408
	#$result["defaultTTL"],字串,預設的RR更新時間.
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
2593
			if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" ){
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
 
2662
			#執行到這邊,代表type為CNAME或TXT或SOA
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
 
3036
			#尋找是否有(...)...的內容存在
3037
			#函式說明:
3038
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3039
			#回傳結果:
3040
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3041
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3042
			#$result["function"],當前執行的函式名稱.
3043
			#$result["argu"],所使用的參數.
3044
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3045
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3046
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3047
			#必填參數:
3048
			#$conf["input"],字串,要檢查的字串.
3049
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3050
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3051
			$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
3052
			#可省略參數:
3053
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3054
			#$conf["varEqual"]=array(null,"found");
3055
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3056
			#$conf["varCon"]=array("no_tail"=>" not");
3057
			#參考資料:
3058
			#無.
3059
			#備註:
3060
			#無.
3061
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3062
			unset($conf["search::findSpecifyStrFormat"]);
3063
 
3064
			#如果執行異常
3065
			if($findSpecifyStrFormat["status"]==="false"){
3066
 
3067
				#設置錯誤識別
3068
				$result["status"]="false";
3069
 
3070
				#設置錯誤訊息
3071
				$result["error"]=$findSpecifyStrFormat;
3072
 
3073
				#回傳結果
3074
				return $result;
3075
 
3076
				}#if end
3077
 
3078
			#如果有 有符合 ($value);${comment} 的格式
3079
			if($findSpecifyStrFormat["found"]==="true"){
3080
 
3081
				#儲存value
3082
				$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
3083
 
3084
				#儲存comment
3085
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3086
 
3087
				#儲存 RR 的記錄
3088
				$result["content"]=$info;
3089
 
3090
				#設置執行正常
3091
				$result["status"]="true";
3092
 
3093
				#回傳結果
3094
				return $result;
3095
 
3096
				}#if end
3097
 
3098
			#執行到這邊代表沒有 (...)... 的內容存在
3099
 
3100
			#尋找是否有 (...) 的內容存在
3101
			#函式說明:
3102
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3103
			#回傳結果:
3104
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3105
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3106
			#$result["function"],當前執行的函式名稱.
3107
			#$result["argu"],所使用的參數.
3108
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3109
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3110
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3111
			#必填參數:
3112
			#$conf["input"],字串,要檢查的字串.
3113
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3114
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3115
			$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
3116
			#可省略參數:
3117
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3118
			#$conf["varEqual"]=array(null,"found");
3119
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3120
			#$conf["varCon"]=array("no_tail"=>" not");
3121
			#參考資料:
3122
			#無.
3123
			#備註:
3124
			#無.
3125
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3126
			unset($conf["search::findSpecifyStrFormat"]);
3127
 
3128
			#如果執行異常
3129
			if($findSpecifyStrFormat["status"]==="false"){
3130
 
3131
				#設置錯誤識別
3132
				$result["status"]="false";
3133
 
3134
				#設置錯誤訊息
3135
				$result["error"]=$findSpecifyStrFormat;
3136
 
3137
				#回傳結果
3138
				return $result;
3139
 
3140
				}#if end
3141
 
3142
			#如果有 有符合 ($value);${comment} 的格式
3143
			if($findSpecifyStrFormat["found"]==="true"){
3144
 
3145
				#儲存value
3146
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3147
 
3148
				#儲存 RR 的記錄
3149
				$result["content"]=$info;
3150
 
3151
				#設置執行正常
3152
				$result["status"]="true";
3153
 
3154
				#回傳結果
3155
				return $result;
3156
 
3157
				}#if end
3158
 
3159
			#執行到這邊代表沒有 (...) 的內容存在
3160
 
3161
			#尋找有無 "...";... 的內容存在
3162
			#函式說明:
3163
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3164
			#回傳結果:
3165
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3166
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3167
			#$result["function"],當前執行的函式名稱.
3168
			#$result["argu"],所使用的參數.
3169
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3170
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3171
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3172
			#必填參數:
3173
			#$conf["input"],字串,要檢查的字串.
3174
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3175
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3176
			$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
3177
			#可省略參數:
3178
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3179
			#$conf["varEqual"]=array(null,"found");
3180
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3181
			#$conf["varCon"]=array("no_tail"=>" not");
3182
			#參考資料:
3183
			#無.
3184
			#備註:
3185
			#無.
3186
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3187
			unset($conf["search::findSpecifyStrFormat"]);
3188
 
3189
			#如果執行異常
3190
			if($findSpecifyStrFormat["status"]==="false"){
3191
 
3192
				#設置錯誤識別
3193
				$result["status"]="false";
3194
 
3195
				#設置錯誤訊息
3196
				$result["error"]=$findSpecifyStrFormat;
3197
 
3198
				#回傳結果
3199
				return $result;
3200
 
3201
				}#if end
3202
 
3203
			#如果有 有符合 "$value";${comment} 的格式
3204
			if($findSpecifyStrFormat["found"]==="true"){
3205
 
3206
				#儲存value
3207
				$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
3208
 
3209
				#儲存comment
3210
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3211
 
3212
				#儲存 RR 的記錄
3213
				$result["content"]=$info;
3214
 
3215
				#設置執行正常
3216
				$result["status"]="true";
3217
 
3218
				#回傳結果
3219
				return $result;
3220
 
3221
				}#if end
3222
 
3223
			#執行到這邊代表沒有 "$value";${comment} 的格式
3224
 
3225
			#尋找有無 "..." 的內容存在
3226
			#函式說明:
3227
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3228
			#回傳結果:
3229
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3230
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3231
			#$result["function"],當前執行的函式名稱.
3232
			#$result["argu"],所使用的參數.
3233
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3234
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3235
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3236
			#必填參數:
3237
			#$conf["input"],字串,要檢查的字串.
3238
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3239
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3240
			$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
3241
			#可省略參數:
3242
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3243
			#$conf["varEqual"]=array(null,"found");
3244
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3245
			#$conf["varCon"]=array("no_tail"=>" not");
3246
			#參考資料:
3247
			#無.
3248
			#備註:
3249
			#無.
3250
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3251
			unset($conf["search::findSpecifyStrFormat"]);
3252
 
3253
			#如果執行異常
3254
			if($findSpecifyStrFormat["status"]==="false"){
3255
 
3256
				#設置錯誤識別
3257
				$result["status"]="false";
3258
 
3259
				#設置錯誤訊息
3260
				$result["error"]=$findSpecifyStrFormat;
3261
 
3262
				#回傳結果
3263
				return $result;
3264
 
3265
				}#if end
3266
 
3267
			#如果有 有符合 "$value" 的格式
3268
			if($findSpecifyStrFormat["found"]==="true"){
3269
 
3270
				#儲存value
3271
				$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
3272
 
3273
				#儲存 RR 的記錄
3274
				$result["content"]=$info;
3275
 
3276
				#設置執行正常
3277
				$result["status"]="true";
3278
 
3279
				#回傳結果
3280
				return $result;
3281
 
3282
				}#if end
3283
 
3284
			#執行到這邊代表沒有 "$value" 格式的內容
3285
 
3286
			#檢查是否有 $value;$comment 格式的內容
3287
			#函式說明:
3288
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3289
			#回傳結果:
3290
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3291
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3292
			#$result["function"],當前執行的函式名稱.
3293
			#$result["argu"],所使用的參數.
3294
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3295
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3296
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3297
			#必填參數:
3298
			#$conf["input"],字串,要檢查的字串.
3299
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3300
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3301
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3302
			#可省略參數:
3303
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3304
			#$conf["varEqual"]=array(null,"found");
3305
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3306
			#$conf["varCon"]=array("no_tail"=>" not");
3307
			#參考資料:
3308
			#無.
3309
			#備註:
3310
			#無.
3311
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3312
			unset($conf["search::findSpecifyStrFormat"]);
3313
 
3314
			#如果執行異常
3315
			if($findSpecifyStrFormat["status"]==="false"){
3316
 
3317
				#設置錯誤識別
3318
				$result["status"]="false";
3319
 
3320
				#設置錯誤訊息
3321
				$result["error"]=$findSpecifyStrFormat;
3322
 
3323
				#回傳結果
3324
				return $result;
3325
 
3326
				}#if end
3327
 
3328
			#如果有 有符合 "$value" 的格式
3329
			if($findSpecifyStrFormat["found"]==="true"){
3330
 
3331
				#儲存value
3332
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3333
 
3334
				#儲存comment
3335
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3336
 
3337
				#儲存 RR 的記錄
3338
				$result["content"]=$info;
3339
 
3340
				#設置執行正常
3341
				$result["status"]="true";
3342
 
3343
				#回傳結果
3344
				return $result;
3345
 
3346
				}#if end
3347
 
3348
			#執行到這邊代表沒有 ${value};${comment} 格式的內容
3349
 
3350
			#亦即剩下的內容都是 value
3351
 
3352
			#儲存value
3353
			$info["value"]=$unFormatStr;
3354
 
3355
			#儲存 RR 的記錄
3356
			$result["content"]=$info;
3357
 
3358
			#設置執行正常
3359
			$result["status"]="true";
3360
 
3361
			#回傳結果
3362
			return $result;
3363
 
3364
			}#while end
3365
 
3366
		}#function parseRRline end
3367
 
3368
	/*
3369
	#函式說明:
249 liveuser 3370
	#新增DNS記錄到檔案裡面.
3371
	#回傳結果:
3372
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3373
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
3374
	#$result["function"],當前執行的函式名稱.
3375
	#$result["argu"],所使用的參數.
3376
	#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
255 liveuser 3377
	#$result["domain"],字串,RR所屬domain.
3378
	#$result["defaultTTL"],字串,預設的RR更新時間.
249 liveuser 3379
	#$result["comment"],字串陣列,逐行的註解.
3380
	#必填參數:
255 liveuser 3381
	#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型(支援的有"A","TXT","CNAME","SOA","$TTL","$ORIGIN")、答案、註解.
249 liveuser 3382
	$conf["add"]=array();
3383
	#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
3384
	$conf["dnsRecordFile"]="";
3385
	#可省略參數:
3386
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
3387
	#$conf["writeNow"]="false";
253 liveuser 3388
	#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
3389
	#$conf["debug"]="false";
293 liveuser 3390
	#$conf["multiThreads"],字串,是否啟動多執行序加快執行速度,預設為"false"代表不要;反之為"true"代表要.
3391
	#$conf["multiThreads"]="false";
249 liveuser 3392
	#參考資料:
3393
	#無.
3394
	#備註:
3395
	#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
291 liveuser 3396
	#本套件是透過sshfs掛載來存取RR(dns記錄檔案),其檔案建議的擁有者權限為 root:qbpwcf,權限代碼為 774.
249 liveuser 3397
	#php-pear上的Net_DNS2也可以解析RR.
293 liveuser 3398
	#參數 multiThreads 目前有 bug.
249 liveuser 3399
	*/
3400
	public static function updateDnsRecordFile(&$conf){
3401
 
3402
		#初始化要回傳的結果
3403
		$result=array();
3404
 
3405
		#設置當其函數名稱
3406
		$result["function"]=__FUNCTION__;
3407
 
3408
		#如果 $conf 不為陣列
3409
		if(gettype($conf)!="array"){
3410
 
3411
			#設置執行失敗
3412
			$result["status"]="false";
3413
 
3414
			#設置執行錯誤訊息
3415
			$result["error"][]="\$conf變數須為陣列形態";
3416
 
3417
			#如果傳入的參數為 null
3418
			if($conf==null){
3419
 
3420
				#設置執行錯誤訊息
3421
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3422
 
3423
				}#if end
3424
 
3425
			#回傳結果
3426
			return $result;
3427
 
3428
			}#if end
3429
 
3430
		#取得參數
3431
		$result["argu"]=$conf;
3432
 
3433
		#檢查參數
3434
		#函式說明:
3435
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3436
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3437
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3438
		#$result["function"],當前執行的函式名稱.
3439
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3440
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3441
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3442
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
3443
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
3444
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3445
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3446
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3447
		#必填寫的參數:
3448
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3449
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3450
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3451
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("add","dnsRecordFile");
3452
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3453
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
3454
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3455
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3456
		#可以省略的參數:
3457
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3458
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3459
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
3460
		#$conf["skipableVariableCanNotBeEmpty"]=array();
3461
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 3462
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThreads");
249 liveuser 3463
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
291 liveuser 3464
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
249 liveuser 3465
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
291 liveuser 3466
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
249 liveuser 3467
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3468
		#$conf["arrayCountEqualCheck"][]=array();
3469
		#參考資料來源:
3470
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3471
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3472
		unset($conf["variableCheck::checkArguments"]);
3473
 
3474
		#如果檢查失敗
3475
		if($checkArguments["status"]==="false"){
3476
 
3477
			#設置錯誤識別
3478
			$result["status"]="false";
3479
 
3480
			#設置錯誤訊息
3481
			$result["error"]=$checkArguments;
3482
 
3483
			#回傳結果
3484
			return $result;
3485
 
3486
			}#if end
3487
 
3488
		#如果檢查不通過
3489
		if($checkArguments["passed"]==="false"){
3490
 
3491
			#設置錯誤識別
3492
			$result["status"]="false";
3493
 
3494
			#設置錯誤訊息
3495
			$result["error"]=$checkArguments;
3496
 
3497
			#回傳結果
3498
			return $result;
3499
 
3500
			}#if end
3501
 
3502
		#初始化要回傳的content
3503
		$result["content"]=array();
3504
 
3505
		#初始化儲存逐行的註解.
3506
		$result["comment"]=array();
3507
 
3508
		#預設的zone file domain為空
3509
		$result["domain"]="";
3510
 
3511
		#預設的 update 時間
3512
		$result["defaultTTL"]=3600;
3513
 
3514
		#取得 dns 記錄檔案的內容
3515
		#函式說明:
3516
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
3517
		#回傳的變數說明:
3518
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
3519
		#$result["error"],錯誤訊息提示.
3520
		#$result["warning"],警告訊息.
3521
		#$result["function"],當前執行的函數名稱.
3522
		#$result["fileContent"],爲檔案的內容陣列.
3523
		#$result["lineCount"],爲檔案內容總共的行數.
3524
		#$result["fullContent"],為檔案的完整內容.
3525
		#$result["base64dataOnly"],檔案的base64data.
3526
		#$result["base64data"],為在網頁上給予src參數的數值.
3527
		#$result["mimeType"],為檔案的mime type.
3528
		#必填參數:
3529
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
3530
		$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$conf["dnsRecordFile"];
3531
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3532
		$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
3533
		#可省略參數:
3534
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
3535
		$conf["fileAccesss::getFileContent"]["web"]="false";
3536
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
3537
		#$conf["createIfnotExist"]="false";
3538
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
3539
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
3540
		#參考資料:
3541
		#file(),取得檔案內容的行數.
3542
		#file=>http:#php.net/manual/en/function.file.php
3543
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
3544
		#filesize=>http://php.net/manual/en/function.filesize.php
3545
		#參考資料:
3546
		#無.
3547
		#備註:
3548
		#無.
3549
		$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
3550
		unset($conf["fileAccesss::getFileContent"]);
3551
 
3552
		#如果檢查失敗
3553
		if($getFileContent["status"]==="false"){
3554
 
3555
			#設置錯誤識別
3556
			$result["status"]="false";
3557
 
3558
			#設置錯誤訊息
3559
			$result["error"]=$getFileContent;
3560
 
3561
			#回傳結果
3562
			return $result;
3563
 
3564
			}#if end
3565
 
3566
		#取得每行內容
3567
		$lines=$getFileContent["fileContent"];
3568
 
3569
		/*
3570
		範例每行內容:
3571
		$ORIGIN server.domain.	;base domain-name,in this Resource Records (RR) file,"@" equal to base domain-name.
3572
		$TTL 86400	;default TTL for zone
3573
		@	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
3574
		@	3600	IN	TXT	"v=spf1 a mx ~all"
3575
		@	86400	IN	MX	1 mail.server.domain.
3576
		@	86400	IN	A	1.1.1.1
3577
		mail.server.domain.	IN	1.1.1.1
3578
		10-42-0-1	IN	A	10.42.0.1
3579
		101-free        IN      A	101.101.101.101
3580
		127-0-0-1	IN	A	127.0.0.1
3581
		_dmarc	IN	TXT	"v=DMARC1;p=reject;sp=reject;pct=100;adkim=r;aspf=r;fo=1;ri=86400;rua=mailto:admin@server.domain"
3582
		default._domainkey	IN	TXT	( "v=DKIM1; k=rsa;" "p=MIGfMA0GCSqG/SIb3DQEBAQQAB" )  ; ----- DKIM key default for qbpwcf.org
3583
		...
3584
		*/
3585
 
3586
		#針對每行內容
3587
		foreach($lines as $lineNo => $line){
3588
 
291 liveuser 3589
			#如果要啟用多執行序
293 liveuser 3590
			if($conf["multiThreads"]==="true"){
291 liveuser 3591
 
293 liveuser 3592
				#如果要debug
3593
				if($conf["debug"]==="true"){
291 liveuser 3594
 
293 liveuser 3595
					#函式說明:
3596
					#撰寫log
3597
					#回傳結果:
3598
					#$result["status"],狀態,"true"或"false".
3599
					#$result["error"],錯誤訊息陣列.
3600
					#$result["function"],當前函式的名稱.
3601
					#$result["argu"],使用的參數.
3602
					#$result["content"],要寫入log的內容字串.
3603
					#必填參數:
3604
					#$conf["path"],字串,log檔案的路徑與名稱.
3605
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3606
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3607
					$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR through multi threads.".PHP_EOL;
3608
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3609
					$conf["logs::record"]["fileArgu"]=__FILE__;
3610
					#可省略參數:
3611
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3612
					#$conf["rewrite"]="false";
3613
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3614
					#$conf["returnOnly"]="true";
3615
					#參考資料:
3616
					#無.
3617
					#備註:
3618
					#無.
3619
					$record=logs::record($conf["logs::record"]);
3620
					unset($conf["logs::record"]);
291 liveuser 3621
 
293 liveuser 3622
					}#if end
3623
 
3624
				#初始化要執行的 php 程式
3625
				$phpCode2run="php -r ";
291 liveuser 3626
 
293 liveuser 3627
				#php code not escaped
3628
				$phpCode2escaped=<<<'PHP'
3629
/*
291 liveuser 3630
 
293 liveuser 3631
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
3632
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3633
 
3634
    This file is part of QBPWCF.
3635
 
3636
    QBPWCF is free software: you can redistribute it and/or modify
3637
    it under the terms of the GNU General Public License as published by
3638
    the Free Software Foundation, either version 3 of the License, or
3639
    (at your option) any later version.
3640
 
3641
    QBPWCF is distributed in the hope that it will be useful,
3642
    but WITHOUT ANY WARRANTY; without even the implied warranty of
3643
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3644
    GNU General Public License for more details.
3645
 
3646
    You should have received a copy of the GNU General Public License
3647
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
3648
 
3649
*/
3650
 
3651
#使用命名空間qbpwcf
3652
namespace qbpwcf;
3653
 
3654
#匯入套件
3655
PHP;
3656
 
3657
#設置 lib root path
3658
$libPath=pathinfo(__FILE__)["dirname"]."/..";
3659
 
3660
#串接匯入QBPWCF套件
3661
$phpCode2escaped=$phpCode2escaped.PHP_EOL."require_once(\"".$libPath."/qbpwcf/allInOne.php\");";
3662
 
3663
#串接php程式
3664
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
291 liveuser 3665
#函式說明:
3666
#解析RR檔案中其中的一行內容.
3667
#回傳結果:
3668
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3669
#$reuslt["error"],執行不正常結束的錯訊息陣列.
3670
#$result["function"],當前執行的函式名稱.
3671
#$result["argu"],所使用的參數.
293 liveuser 3672
#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
291 liveuser 3673
#$result["domain"],字串,RR所屬domain.
3674
#$result["defaultTTL"],字串,預設的RR更新時間.
293 liveuser 3675
#$result["comment"],字串,一行的註解.
291 liveuser 3676
#必填參數:
3677
#$conf["line"],字串,要解析的行內容.
293 liveuser 3678
PHP;
3679
 
3680
#串接變數
3681
$phpCode2escaped=$phpCode2escaped.PHP_EOL."\$conf[\"line\"]=base64_decode(\"".base64_encode($line)."\");";
3682
 
3683
#串接php程式
3684
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
291 liveuser 3685
#可省略參數:
3686
#無.
3687
#參考資料:
3688
#無.
3689
#備註:
3690
#無.
3691
$parseRRline=zerossl::parseRRline($conf);
3692
unset($conf);
3693
 
3694
#如果執行異常 
3695
if($parseRRline["status"]==="false"){
3696
 
3697
	#設置錯誤識別
3698
	$result["status"]="false";
3699
 
3700
	#設置錯誤訊息
3701
	$result["error"]=$parseRRline;
3702
 
3703
	#印出 json 結果
3704
	echo json_encode($result);
3705
 
3706
	#結束執行,回傳1.
3707
	exit(1);
3708
 
3709
	}#if end
3710
 
3711
#印出json
3712
echo json_encode($parseRRline);
3713
PHP;
3714
 
293 liveuser 3715
				#串接要執行的參數
3716
				$phpCode2run=$phpCode2run.escapeshellarg($phpCode2escaped);
3717
 
291 liveuser 3718
				#函式說明:
3719
				#透過proc來多執行序運作.
3720
				#回傳結果:
3721
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3722
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3723
				#$result["function"],當前執行的函式名稱.
3724
				#$result["argu"],使用的參數.
3725
				#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
3726
				#必填參數:
3727
				#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
293 liveuser 3728
				$conf["threads::proc"]["cmds"]=array($phpCode2run);
291 liveuser 3729
				#可省略參數:
3730
				#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
3731
				$conf["threads::proc"]["wait"]="false";
3732
				#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
3733
				#$conf["timeout"]=array("10");
3734
				#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
293 liveuser 3735
				#$conf["threads::proc"]["workingDir"]=array(pathinfo(__FILE__)["dirname"]);
291 liveuser 3736
				#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
3737
				#$conf["envs"]=array(array("key"=>"value"));
3738
				#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
3739
				#$conf["executeBy"]=array("bash");
3740
				#參考資料:
3741
				#https://www.php.net/manual/en/function.proc-open.php
3742
				#https://www.php.net/manual/en/function.proc-get-status.php
3743
				#https://www.php.net/manual/en/function.proc-terminate.php
3744
				#備註:
3745
				#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
3746
				#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
3747
				$proc=threads::proc($conf["threads::proc"]);
3748
				unset($conf["threads::proc"]);
3749
 
293 liveuser 3750
				#debug
3751
				#var_dump($proc);exit;
3752
 
291 liveuser 3753
				#如果檢查失敗
3754
				if($proc["status"]==="false"){
3755
 
3756
					#設置錯誤識別
3757
					$result["status"]="false";
3758
 
3759
					#設置錯誤訊息
3760
					$result["error"]=$proc;
3761
 
3762
					#回傳結果
3763
					return $result;
3764
 
3765
					}#if end
3766
 
3767
				#儲存程序資訊
294 liveuser 3768
				$procs[$lineNo]=$proc;	
291 liveuser 3769
 
3770
				#換解析下一行
3771
				continue;
3772
 
3773
				}#if end
3774
 
249 liveuser 3775
			#另存一份要處理的RR
3776
			$unFormatStr=$line;
3777
 
253 liveuser 3778
			#如果要debug
3779
			if($conf["debug"]==="true"){
3780
 
3781
				#函式說明:
3782
				#撰寫log
3783
				#回傳結果:
3784
				#$result["status"],狀態,"true"或"false".
3785
				#$result["error"],錯誤訊息陣列.
3786
				#$result["function"],當前函式的名稱.
3787
				#$result["argu"],使用的參數.
3788
				#$result["content"],要寫入log的內容字串.
3789
				#必填參數:
3790
				#$conf["path"],字串,log檔案的路徑與名稱.
3791
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3792
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3793
				$conf["logs::record"]["content"]="processing lineNo:".$lineNo." content:".$line.PHP_EOL;
3794
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3795
				$conf["logs::record"]["fileArgu"]=__FILE__;
3796
				#可省略參數:
3797
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3798
				#$conf["rewrite"]="false";
3799
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3800
				#$conf["returnOnly"]="true";
3801
				#參考資料:
3802
				#無.
3803
				#備註:
3804
				#無.
3805
				$record=logs::record($conf["logs::record"]);
3806
				unset($conf["logs::record"]);
3807
 
3808
				}#if end
3809
 
249 liveuser 3810
			#初始化該行的資訊陣列
3811
			$info=array();
3812
 
3813
			#尋找";"開頭的內容,亦即整行都是註解.
3814
			#函式說明:
3815
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3816
			#回傳結果:
3817
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3818
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3819
			#$result["function"],當前執行的函式名稱.
3820
			#$result["argu"],所使用的參數.
3821
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3822
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3823
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3824
			#必填參數:
3825
			#$conf["input"],字串,要檢查的字串.
3826
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3827
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3828
			$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
3829
			#可省略參數:
3830
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3831
			#$conf["varEqual"]=array(null,"found");
3832
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3833
			#$conf["varCon"]=array("no_tail"=>" not");
3834
			#參考資料:
3835
			#無.
3836
			#備註:
3837
			#無.
3838
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3839
			unset($conf["search::findSpecifyStrFormat"]);
3840
 
3841
			#如果執行異常
3842
			if($findSpecifyStrFormat["status"]==="false"){
3843
 
3844
				#設置錯誤識別
3845
				$result["status"]="false";
3846
 
3847
				#設置錯誤訊息
3848
				$result["error"]=$findSpecifyStrFormat;
3849
 
3850
				#回傳結果
3851
				return $result;
3852
 
3853
				}#if end
3854
 
3855
			#如果有找到符合格式的內容
3856
			if($findSpecifyStrFormat["found"]==="true"){
3857
 
3858
				#儲存為註解
3859
				$result["comment"][]=$unFormatStr;
3860
 
3861
				#換下一行
3862
				continue;
3863
 
3864
				}#if end
3865
 
3866
			#函式說明:
3867
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3868
			#回傳結果:
3869
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3870
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3871
			#$result["function"],當前執行的函式名稱.
3872
			#$result["argu"],所使用的參數.
3873
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3874
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3875
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3876
			#必填參數:
3877
			#$conf["input"],字串,要檢查的字串.
3878
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3879
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3880
			$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
3881
			#可省略參數:
3882
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3883
			#$conf["varEqual"]=array(null,"found");
3884
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3885
			#$conf["varCon"]=array("no_tail"=>" not");
3886
			#參考資料:
3887
			#無.
3888
			#備註:
3889
			#無.
3890
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3891
			unset($conf["search::findSpecifyStrFormat"]);
3892
 
3893
			#如果執行異常
3894
			if($findSpecifyStrFormat["status"]==="false"){
3895
 
3896
				#設置錯誤識別
3897
				$result["status"]="false";
3898
 
3899
				#設置錯誤訊息
3900
				$result["error"]=$findSpecifyStrFormat;
3901
 
3902
				#回傳結果
3903
				return $result;
3904
 
3905
				}#if end
3906
 
3907
			#如果有找到符合格式的內容
3908
			if($findSpecifyStrFormat["found"]==="true"){
3909
 
3910
				#設置 type 的數值
3911
				$info["type"]="\$ORIGIN";
3912
 
3913
				#取得後面待處理的內容
3914
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
3915
 
3916
				#函式說明:
3917
				#將字串開頭的特定關鍵字移除.
3918
				#回傳結果:
3919
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3920
				#$result["error"],錯誤訊息陣列.
3921
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
3922
				#$result["function"],當前執行的函數名稱.
3923
				#$result["argu"],使用的參數.
3924
				#$result["content"],處理好的的字串內容.
3925
				#$result["deleted"],被移除的內容.
3926
				#必填參數:
3927
				#$conf["stringIn"],字串,要處理的字串.
3928
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
3929
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
3930
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
3931
				#可省略參數:
3932
				#無.
3933
				#參考資料:
3934
				#無.
3935
				#備註:
3936
				#無.
3937
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
3938
				unset($conf["stringProcess::delHeadStr"]);
3939
 
3940
				#如果執行異常
3941
				if($delHeadStr["status"]==="false"){
3942
 
3943
					#設置錯誤識別
3944
					$result["status"]="false";
3945
 
3946
					#設置錯誤訊息
3947
					$result["error"]=$delHeadStr;
3948
 
3949
					#回傳結果
3950
					return $result;
3951
 
3952
					}#if end
3953
 
3954
				#如果有移除開頭的字串
3955
				if($delHeadStr["founded"]==="true"){
3956
 
3957
					#取得處理後的結果
3958
					$unFormatStr=$delHeadStr["content"];
3959
 
3960
					}#if end
253 liveuser 3961
 
249 liveuser 3962
				#解析 $ORIGN 的數值, 以及後面是否有註解...
3963
				#函式說明:
3964
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3965
				#回傳結果:
3966
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3967
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3968
				#$result["function"],當前執行的函式名稱.
3969
				#$result["argu"],所使用的參數.
3970
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3971
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3972
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3973
				#必填參數:
3974
				#$conf["input"],字串,要檢查的字串.
3975
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3976
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3977
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3978
				#可省略參數:
3979
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3980
				#$conf["varEqual"]=array(null,"found");
3981
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3982
				#$conf["varCon"]=array("no_tail"=>" not");
3983
				#參考資料:
3984
				#無.
3985
				#備註:
3986
				#無.
3987
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3988
				unset($conf["search::findSpecifyStrFormat"]);
3989
 
3990
				#如果執行異常
3991
				if($findSpecifyStrFormat["status"]==="false"){
3992
 
3993
					#設置錯誤識別
3994
					$result["status"]="false";
3995
 
3996
					#設置錯誤訊息
3997
					$result["error"]=$findSpecifyStrFormat;
3998
 
3999
					#回傳結果
4000
					return $result;
4001
 
4002
					}#if end
4003
 
4004
				#如果有數值跟註解
4005
				if($findSpecifyStrFormat["found"]==="true"){
4006
 
4007
					#儲存數值
4008
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
4009
 
4010
					#儲存zone domain
4011
					$result["domain"]=trim($info["value"]);
4012
 
4013
					#儲存註解
253 liveuser 4014
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
249 liveuser 4015
 
4016
					#儲存解析好的RR
4017
					$result["content"][]=$info;
4018
 
4019
					#換下一行
4020
					continue;
4021
 
4022
					}#if end
4023
 
4024
				#執行到這邊代表剩下的內容都是 value
4025
				$info["value"]=$unFormatStr;
4026
 
4027
				#儲存zone domain
4028
				$result["domain"]=trim($info["value"]);
4029
 
4030
				#儲存解析好的RR
4031
				$result["content"][]=$info;
4032
 
4033
				#換下一行
4034
				continue;
4035
 
4036
				}#if end
4037
 
4038
			#檢查是否為 $TTL 開頭
4039
			#函式說明:
4040
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4041
			#回傳結果:
4042
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4043
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
4044
			#$result["function"],當前執行的函式名稱.
4045
			#$result["argu"],所使用的參數.
4046
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4047
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4048
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4049
			#必填參數:
4050
			#$conf["input"],字串,要檢查的字串.
4051
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4052
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4053
			$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
4054
			#可省略參數:
4055
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4056
			#$conf["varEqual"]=array(null,"found");
4057
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4058
			#$conf["varCon"]=array("no_tail"=>" not");
4059
			#參考資料:
4060
			#無.
4061
			#備註:
4062
			#無.
4063
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4064
			unset($conf["search::findSpecifyStrFormat"]);
4065
 
4066
			#如果執行異常
4067
			if($findSpecifyStrFormat["status"]==="false"){
4068
 
4069
				#設置錯誤識別
4070
				$result["status"]="false";
4071
 
4072
				#設置錯誤訊息
4073
				$result["error"]=$findSpecifyStrFormat;
4074
 
4075
				#回傳結果
4076
				return $result;
4077
 
4078
				}#if end
4079
 
4080
			#如果有找到符合格式的內容
4081
			if($findSpecifyStrFormat["found"]==="true"){
4082
 
4083
				#設置 type 的數值
4084
				$info["type"]="\$TTL";
4085
 
4086
				#取得後面待處理的內容
4087
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
4088
 
4089
				#函式說明:
4090
				#將字串開頭的特定關鍵字移除.
4091
				#回傳結果:
4092
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4093
				#$result["error"],錯誤訊息陣列.
4094
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4095
				#$result["function"],當前執行的函數名稱.
4096
				#$result["argu"],使用的參數.
4097
				#$result["content"],處理好的的字串內容.
4098
				#$result["deleted"],被移除的內容.
4099
				#必填參數:
4100
				#$conf["stringIn"],字串,要處理的字串.
4101
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4102
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4103
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
4104
				#可省略參數:
4105
				#無.
4106
				#參考資料:
4107
				#無.
4108
				#備註:
4109
				#無.
4110
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4111
				unset($conf["stringProcess::delHeadStr"]);
293 liveuser 4112
 
249 liveuser 4113
				#如果執行異常
4114
				if($delHeadStr["status"]==="false"){
4115
 
4116
					#設置錯誤識別
4117
					$result["status"]="false";
4118
 
4119
					#設置錯誤訊息
4120
					$result["error"]=$delHeadStr;
4121
 
4122
					#回傳結果
4123
					return $result;
4124
 
4125
					}#if end
4126
 
4127
				#如果有移除開頭的字串
4128
				if($delHeadStr["founded"]==="true"){
4129
 
4130
					#取得處理後的結果
4131
					$unFormatStr=$delHeadStr["content"];
4132
 
4133
					}#if end
4134
 
4135
				#解析 $TTL 的數值, 以及後面是否有註解...
4136
				#函式說明:
4137
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4138
				#回傳結果:
4139
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4140
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4141
				#$result["function"],當前執行的函式名稱.
4142
				#$result["argu"],所使用的參數.
4143
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4144
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4145
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4146
				#必填參數:
4147
				#$conf["input"],字串,要檢查的字串.
4148
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4149
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4150
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
4151
				#可省略參數:
4152
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4153
				#$conf["varEqual"]=array(null,"found");
4154
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4155
				#$conf["varCon"]=array("no_tail"=>" not");
4156
				#參考資料:
4157
				#無.
4158
				#備註:
4159
				#無.
4160
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4161
				unset($conf["search::findSpecifyStrFormat"]);
4162
 
4163
				#如果執行異常
4164
				if($findSpecifyStrFormat["status"]==="false"){
4165
 
4166
					#設置錯誤識別
4167
					$result["status"]="false";
4168
 
4169
					#設置錯誤訊息
4170
					$result["error"]=$findSpecifyStrFormat;
4171
 
4172
					#回傳結果
4173
					return $result;
4174
 
4175
					}#if end
4176
 
4177
				#如果有數值跟註解
4178
				if($findSpecifyStrFormat["found"]==="true"){
4179
 
4180
					#儲存數值
4181
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
4182
 
4183
					#儲存註解
253 liveuser 4184
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
249 liveuser 4185
 
4186
					#儲存預設的 TTL
4187
					$result["defaultTTL"]=trim($info["value"]);
4188
 
4189
					#儲存解析好的RR
4190
					$result["content"][]=$info;
4191
 
4192
					#換下一行
4193
					continue;
4194
 
4195
					}#if end
4196
 
4197
				#執行到這邊代表剩下的內容都是 value
4198
				$info["value"]=$unFormatStr;
4199
 
4200
				#儲存預設的 TTL
4201
				$result["defaultTTL"]=trim($info["value"]);
4202
 
4203
				#儲存解析好的RR
4204
				$result["content"][]=$info;
4205
 
4206
				#換下一行
4207
				continue;
4208
 
4209
				}#if end
4210
 
4211
			#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
4212
 
4213
			#函式說明:
4214
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4215
			#回傳結果:
4216
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4217
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
4218
			#$result["function"],當前執行的函式名稱.
4219
			#$result["argu"],所使用的參數.
4220
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4221
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4222
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
4223
			#必填參數:
4224
			#$conf["input"],字串,要檢查的字串.
4225
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4226
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4227
			$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
4228
			#可省略參數:
4229
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4230
			#$conf["varEqual"]=array(null,"found");
4231
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4232
			#$conf["varCon"]=array("no_tail"=>" not");
4233
			#參考資料:
4234
			#無.
4235
			#備註:
4236
			#無.
4237
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4238
			unset($conf["search::findSpecifyStrFormat"]);
4239
 
4240
			#如果執行異常
4241
			if($findSpecifyStrFormat["status"]==="false"){
4242
 
4243
				#設置錯誤識別
4244
				$result["status"]="false";
4245
 
4246
				#設置錯誤訊息
4247
				$result["error"]=$findSpecifyStrFormat;
4248
 
4249
				#回傳結果
4250
				return $result;
4251
 
4252
				}#if end
4253
 
4254
			#如果存在"("
4255
			if($findSpecifyStrFormat["found"]==="true"){
4256
 
4257
				#取得無"("的內容
4258
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
4259
 
4260
				#取得拆下來的含開頭"("內容
4261
				$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
4262
 
4263
				}#if end
4264
 
4265
			#反之
4266
			else{
4267
 
4268
				#函式說明:
4269
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4270
				#回傳結果:
4271
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4272
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4273
				#$result["function"],當前執行的函式名稱.
4274
				#$result["argu"],所使用的參數.
4275
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4276
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4277
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
4278
				#必填參數:
4279
				#$conf["input"],字串,要檢查的字串.
4280
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4281
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4282
				$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
4283
				#可省略參數:
4284
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4285
				#$conf["varEqual"]=array(null,"found");
4286
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4287
				#$conf["varCon"]=array("no_tail"=>" not");
4288
				#參考資料:
4289
				#無.
4290
				#備註:
4291
				#無.
4292
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4293
				unset($conf["search::findSpecifyStrFormat"]);
4294
 
4295
				#如果執行異常
4296
				if($findSpecifyStrFormat["status"]==="false"){
4297
 
4298
					#設置錯誤識別
4299
					$result["status"]="false";
4300
 
4301
					#設置錯誤訊息
4302
					$result["error"]=$findSpecifyStrFormat;
4303
 
4304
					#回傳結果
4305
					return $result;
4306
 
4307
					}#if end
4308
 
4309
				#如果存在"
4310
				if($findSpecifyStrFormat["found"]==="true"){
4311
 
4312
					#取得無"的內容
4313
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
4314
 
4315
					#取得拆下來的含開頭"內容
4316
					$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
4317
 
4318
					}#if end
4319
 
4320
				#反之
4321
				else{
4322
 
4323
					#函式說明:
4324
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4325
					#回傳結果:
4326
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4327
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
4328
					#$result["function"],當前執行的函式名稱.
4329
					#$result["argu"],所使用的參數.
4330
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4331
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4332
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
4333
					#必填參數:
4334
					#$conf["input"],字串,要檢查的字串.
4335
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4336
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4337
					$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
4338
					#可省略參數:
4339
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4340
					#$conf["varEqual"]=array(null,"found");
4341
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4342
					#$conf["varCon"]=array("no_tail"=>" not");
4343
					#參考資料:
4344
					#無.
4345
					#備註:
4346
					#無.
4347
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4348
					unset($conf["search::findSpecifyStrFormat"]);
4349
 
4350
					#如果執行異常
4351
					if($findSpecifyStrFormat["status"]==="false"){
4352
 
4353
						#設置錯誤識別
4354
						$result["status"]="false";
4355
 
4356
						#設置錯誤訊息
4357
						$result["error"]=$findSpecifyStrFormat;
4358
 
4359
						#回傳結果
4360
						return $result;
4361
 
4362
						}#if end
4363
 
4364
					#如果存在";"
4365
					if($findSpecifyStrFormat["found"]==="true"){
4366
 
4367
						#取得無";"的內容
4368
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
4369
 
4370
						#取得拆下來的含開頭";"內容
4371
						$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
4372
 
4373
						}#if end
4374
 
4375
					}#else end
4376
 
4377
				}#else end
4378
 
4379
			#檢查是否為 @ 開頭
4380
			#函式說明:
4381
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4382
			#回傳結果:
4383
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4384
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
4385
			#$result["function"],當前執行的函式名稱.
4386
			#$result["argu"],所使用的參數.
4387
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4388
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4389
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4390
			#必填參數:
4391
			#$conf["input"],字串,要檢查的字串.
4392
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4393
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4394
			$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
4395
			#可省略參數:
4396
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4397
			#$conf["varEqual"]=array(null,"found");
4398
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4399
			#$conf["varCon"]=array("no_tail"=>" not");
4400
			#參考資料:
4401
			#無.
4402
			#備註:
4403
			#無.
4404
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4405
			unset($conf["search::findSpecifyStrFormat"]);
4406
 
4407
			#如果執行異常
4408
			if($findSpecifyStrFormat["status"]==="false"){
4409
 
4410
				#設置錯誤識別
4411
				$result["status"]="false";
4412
 
4413
				#設置錯誤訊息
4414
				$result["error"]=$findSpecifyStrFormat;
4415
 
4416
				#回傳結果
4417
				return $result;
4418
 
4419
				}#if end
4420
 
4421
			#如果有找到符合格式的內容
4422
			if($findSpecifyStrFormat["found"]==="true"){
4423
 
4424
				#設置 query 的數值
4425
				$info["query"]="@";
4426
 
4427
				#取得後面待處理的內容
4428
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
4429
 
4430
				#函式說明:
4431
				#將字串開頭的特定關鍵字移除.
4432
				#回傳結果:
4433
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4434
				#$result["error"],錯誤訊息陣列.
4435
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4436
				#$result["function"],當前執行的函數名稱.
4437
				#$result["argu"],使用的參數.
4438
				#$result["content"],處理好的的字串內容.
4439
				#$result["deleted"],被移除的內容.
4440
				#必填參數:
4441
				#$conf["stringIn"],字串,要處理的字串.
4442
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4443
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4444
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
4445
				#可省略參數:
4446
				#無.
4447
				#參考資料:
4448
				#無.
4449
				#備註:
4450
				#無.
4451
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4452
				unset($conf["stringProcess::delHeadStr"]);
4453
 
4454
				#如果執行異常
4455
				if($delHeadStr["status"]==="false"){
4456
 
4457
					#設置錯誤識別
4458
					$result["status"]="false";
4459
 
4460
					#設置錯誤訊息
4461
					$result["error"]=$delHeadStr;
4462
 
4463
					#回傳結果
4464
					return $result;
4465
 
4466
					}#if end
4467
 
4468
				#如果有移除開頭的字串
4469
				if($delHeadStr["founded"]==="true"){
4470
 
4471
					#取得處理後的結果 update time..IN..type...value;comment
4472
					$unFormatStr=$delHeadStr["content"];
4473
 
4474
					}#if end
4475
 
4476
				#debug
4477
				#var_dump(__LINE__,$delHeadStr);
4478
 
4479
				}#if end
4480
 
4481
			#反之
4482
			else{
4483
 
4484
				#執行到這邊,代表 query 為一非 @ 的字串
4485
				#函式說明:
4486
				#將指令字串解析成陣列,方便給予 external::callShell 使用
4487
				#回傳結果:
4488
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4489
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4490
				#$result["function"],當前執行的函式名稱.
4491
				#$result["content"],解析好的指令陣列.
4492
				#$result["cmd"],解析好的指令名稱.
4493
				#$result["argus"],解析好的參數陣列.
4494
				#$result["argu"],所使用的參數.
4495
				#必填參數
4496
				#$conf["cmdStr"],字串,要解析的指令字串
4497
				$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
4498
				#可省略參數:
4499
				#無.
4500
				#參考資料:
4501
				#無.
4502
				#備註:
4503
				#無.
4504
				$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
4505
				unset($conf["stringProcess::parseCmdString"]);
4506
 
4507
				#如果執行失敗
4508
				if($parseCmdString["status"]==="false"){
4509
 
4510
					#設置錯誤識別
4511
					$result["status"]="false";
4512
 
4513
					#設置錯誤訊息
4514
					$result["error"]=$parseCmdString;
4515
 
4516
					#debug
4517
					#$result["errorProcessLine"]=$line;
4518
 
4519
					#回傳結果
4520
					return $result;
4521
 
4522
					}#if end
4523
 
4524
				#取得 query 的內容
4525
				$info["query"]=$parseCmdString["content"][0];
4526
 
4527
				#剔除 query以及後面的" "跟\t
4528
				#函式說明:
4529
				#將字串開頭的特定關鍵字移除.
4530
				#回傳結果:
4531
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4532
				#$result["error"],錯誤訊息陣列.
4533
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4534
				#$result["function"],當前執行的函數名稱.
4535
				#$result["argu"],使用的參數.
4536
				#$result["content"],處理好的的字串內容.
4537
				#$result["deleted"],被移除的內容.
4538
				#必填參數:
4539
				#$conf["stringIn"],字串,要處理的字串.
4540
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4541
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4542
				$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
4543
				#可省略參數:
4544
				#無.
4545
				#參考資料:
4546
				#無.
4547
				#備註:
4548
				#無.
4549
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4550
				unset($conf["stringProcess::delHeadStr"]);
4551
 
4552
				#如果執行異常
4553
				if($delHeadStr["status"]==="false"){
4554
 
4555
					#設置錯誤識別
4556
					$result["status"]="false";
4557
 
4558
					#設置錯誤訊息
4559
					$result["error"]=$delHeadStr;
4560
 
4561
					#回傳結果
4562
					return $result;
4563
 
4564
					}#if end
4565
 
4566
				#取得update time..IN..type...value;comment
4567
				$unFormatStr=$delHeadStr["content"];
4568
 
4569
				}#else end
4570
 
4571
			#無窮迴圈
4572
			while(true){
4573
 
253 liveuser 4574
				#如果要debug
4575
				if($conf["debug"]==="true"){
249 liveuser 4576
 
253 liveuser 4577
					#函式說明:
4578
					#撰寫log
4579
					#回傳結果:
4580
					#$result["status"],狀態,"true"或"false".
4581
					#$result["error"],錯誤訊息陣列.
4582
					#$result["function"],當前函式的名稱.
4583
					#$result["argu"],使用的參數.
4584
					#$result["content"],要寫入log的內容字串.
4585
					#必填參數:
4586
					#$conf["path"],字串,log檔案的路徑與名稱.
4587
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4588
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4589
					$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4590
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4591
					$conf["logs::record"]["fileArgu"]=__FILE__;
4592
					#可省略參數:
4593
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4594
					#$conf["rewrite"]="false";
4595
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4596
					#$conf["returnOnly"]="true";
4597
					#參考資料:
4598
					#無.
4599
					#備註:
4600
					#無.
4601
					$record=logs::record($conf["logs::record"]);
4602
					unset($conf["logs::record"]);
4603
 
4604
					}#if end
4605
 
249 liveuser 4606
				#解析 updateTime..IN..type...value...comment
4607
 
4608
				#判斷是否無 update time
4609
 
4610
				#函式說明:
4611
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4612
				#回傳結果:
4613
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4614
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4615
				#$result["function"],當前執行的函式名稱.
4616
				#$result["argu"],所使用的參數.
4617
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4618
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4619
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4620
				#必填參數:
4621
				#$conf["input"],字串,要檢查的字串.
4622
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4623
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4624
				$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
4625
				#可省略參數:
4626
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4627
				#$conf["varEqual"]=array(null,"found");
4628
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4629
				#$conf["varCon"]=array("no_tail"=>" not");
4630
				#參考資料:
4631
				#無.
4632
				#備註:
4633
				#無.
4634
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4635
				unset($conf["search::findSpecifyStrFormat"]);
4636
 
4637
				#如果執行異常
4638
				if($findSpecifyStrFormat["status"]==="false"){
4639
 
4640
					#設置錯誤識別
4641
					$result["status"]="false";
4642
 
4643
					#設置錯誤訊息
4644
					$result["error"]=$findSpecifyStrFormat;
4645
 
4646
					#回傳結果
4647
					return $result;
4648
 
4649
					}#if end
4650
 
4651
				#如果有找到符合格式的內容
4652
				if($findSpecifyStrFormat["found"]==="true"){
4653
 
4654
					#代表沒有 update time 欄位,因此儲存預設的TTL
4655
					$info["update"]=&$result["defaultTTL"];
4656
 
4657
					#取得剩下的 ...type...value;comment
4658
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
4659
 
4660
					#設置該行沒有指定 update time
4661
					$noUpdateTime="true";
4662
 
253 liveuser 4663
					#如果要debug
4664
					if($conf["debug"]==="true"){
4665
 
4666
						#函式說明:
4667
						#撰寫log
4668
						#回傳結果:
4669
						#$result["status"],狀態,"true"或"false".
4670
						#$result["error"],錯誤訊息陣列.
4671
						#$result["function"],當前函式的名稱.
4672
						#$result["argu"],使用的參數.
4673
						#$result["content"],要寫入log的內容字串.
4674
						#必填參數:
4675
						#$conf["path"],字串,log檔案的路徑與名稱.
4676
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4677
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4678
						$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4679
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4680
						$conf["logs::record"]["fileArgu"]=__FILE__;
4681
						#可省略參數:
4682
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4683
						#$conf["rewrite"]="false";
4684
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4685
						#$conf["returnOnly"]="true";
4686
						#參考資料:
4687
						#無.
4688
						#備註:
4689
						#無.
4690
						$record=logs::record($conf["logs::record"]);
4691
						unset($conf["logs::record"]);
4692
 
4693
						}#if end
249 liveuser 4694
 
4695
					}#if end
4696
 
4697
				#反之
4698
				else{
4699
 
4700
					#設置該行有指定 update time
4701
					$noUpdateTime="false";
4702
 
4703
					#如果有指定 update time
4704
					if($noUpdateTime==="false"){
4705
 
4706
						#要來解析 update time
4707
						#函式說明:
4708
						#將字串進行解析,變成多個參數.
4709
						#回傳結果:
4710
						#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
4711
						#$result["function"],當前執行的函式內容.
4712
						#$result["error"],錯誤訊息陣列.
4713
						#$result["content"],參數陣列.
4714
						#$result["count"],總共有幾個參數.
4715
						#必填參數:
4716
						#$conf["input"],字串,要解析成參數的字串.
4717
						$conf["stringProcess::parse"]["input"]=$unFormatStr;
4718
						#可省略參數:
4719
						#無.
4720
						#參考資料:
4721
						#無.
4722
						#備註:
4723
						#無.
4724
						$parse=stringProcess::parse($conf["stringProcess::parse"]);
4725
						unset($conf["stringProcess::parse"]);
4726
 
4727
						#如果執行異常
4728
						if($parse["status"]==="false"){
4729
 
4730
							#設置錯誤識別
4731
							$result["status"]="false";
4732
 
4733
							#設置錯誤訊息
4734
							$result["error"]=$parse;
4735
 
4736
							#回傳結果
4737
							return $result;
4738
 
4739
							}#if end
4740
 
4741
						#取得更新時間
4742
						$info["update"]=$parse["content"][0];
4743
 
4744
						#取得 update time 後面的內容
4745
						#函式說明:
4746
						#將字串開頭的特定關鍵字移除.
4747
						#回傳結果:
4748
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4749
						#$result["error"],錯誤訊息陣列.
4750
						#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4751
						#$result["function"],當前執行的函數名稱.
4752
						#$result["argu"],使用的參數.
4753
						#$result["content"],處理好的的字串內容.
4754
						#$result["deleted"],被移除的內容.
4755
						#必填參數:
4756
						#$conf["stringIn"],字串,要處理的字串.
4757
						$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4758
						#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4759
						$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
4760
						#可省略參數:
4761
						#無.
4762
						#參考資料:
4763
						#無.
4764
						#備註:
4765
						#無.
4766
						$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4767
						unset($conf["stringProcess::delHeadStr"]);
4768
 
4769
						#如果執行異常
4770
						if($delHeadStr["status"]==="false"){
4771
 
4772
							#設置錯誤識別
4773
							$result["status"]="false";
4774
 
4775
							#設置錯誤訊息
4776
							$result["error"]=$delHeadStr;
4777
 
4778
							#回傳結果
4779
							return $result;
4780
 
4781
							}#if end
4782
 
4783
						#取得...IN...value;comment
4784
						$unFormatStr=$delHeadStr["content"];
4785
 
4786
						}#if end
4787
 
4788
					#取得 ...IN... 後面的內容
4789
					#函式說明:
4790
					#將字串開頭的特定關鍵字移除.
4791
					#回傳結果:
4792
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4793
					#$result["error"],錯誤訊息陣列.
4794
					#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4795
					#$result["function"],當前執行的函數名稱.
4796
					#$result["argu"],使用的參數.
4797
					#$result["content"],處理好的的字串內容.
4798
					#$result["deleted"],被移除的內容.
4799
					#必填參數:
4800
					#$conf["stringIn"],字串,要處理的字串.
4801
					$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4802
					#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4803
					$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
4804
					#可省略參數:
4805
					#無.
4806
					#參考資料:
4807
					#無.
4808
					#備註:
4809
					#無.
4810
					$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4811
					unset($conf["stringProcess::delHeadStr"]);
4812
 
4813
					#如果執行異常
4814
					if($delHeadStr["status"]==="false"){
4815
 
4816
						#設置錯誤識別
4817
						$result["status"]="false";
4818
 
4819
						#設置錯誤訊息
4820
						$result["error"]=$delHeadStr;
4821
 
4822
						#回傳結果
4823
						return $result;
4824
 
4825
						}#if end
4826
 
4827
					#取得IN...value;comment
4828
					$unFormatStr=$delHeadStr["content"];
4829
 
253 liveuser 4830
					#如果要debug
4831
					if($conf["debug"]==="true"){
249 liveuser 4832
 
253 liveuser 4833
						#函式說明:
4834
						#撰寫log
4835
						#回傳結果:
4836
						#$result["status"],狀態,"true"或"false".
4837
						#$result["error"],錯誤訊息陣列.
4838
						#$result["function"],當前函式的名稱.
4839
						#$result["argu"],使用的參數.
4840
						#$result["content"],要寫入log的內容字串.
4841
						#必填參數:
4842
						#$conf["path"],字串,log檔案的路徑與名稱.
4843
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4844
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4845
						$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4846
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4847
						$conf["logs::record"]["fileArgu"]=__FILE__;
4848
						#可省略參數:
4849
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4850
						#$conf["rewrite"]="false";
4851
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4852
						#$conf["returnOnly"]="true";
4853
						#參考資料:
4854
						#無.
4855
						#備註:
4856
						#無.
4857
						$record=logs::record($conf["logs::record"]);
4858
						unset($conf["logs::record"]);
4859
 
4860
						}#if end
4861
 
249 liveuser 4862
					}#else end
4863
 
4864
				#解析 type...value;comment
4865
				#函式說明:
4866
				#將字串進行解析,變成多個參數.
4867
				#回傳結果:
4868
				#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
4869
				#$result["function"],當前執行的函式內容.
4870
				#$result["error"],錯誤訊息陣列.
4871
				#$result["content"],參數陣列.
4872
				#$result["count"],總共有幾個參數.
4873
				#必填參數:
4874
				#$conf["input"],字串,要解析成參數的字串.
4875
				$conf["stringProcess::parse"]["input"]=$unFormatStr;
4876
				#可省略參數:
4877
				#無.
4878
				#參考資料:
4879
				#無.
4880
				#備註:
4881
				#無.
4882
				$parse=stringProcess::parse($conf["stringProcess::parse"]);
4883
				unset($conf["stringProcess::parse"]);
4884
 
4885
				#如果執行異常
4886
				if($parse["status"]==="false"){
4887
 
4888
					#設置錯誤識別
4889
					$result["status"]="false";
4890
 
4891
					#設置錯誤訊息
4892
					$result["error"]=$parse;
4893
 
4894
					#回傳結果
4895
					return $result;
4896
 
4897
					}#if end
4898
 
4899
				#取得 type
4900
				$info["type"]=$parse["content"][0];
4901
 
4902
				#取得 type...後面的value;comment內容
4903
				#函式說明:
4904
				#將字串開頭的特定關鍵字移除.
4905
				#回傳結果:
4906
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4907
				#$result["error"],錯誤訊息陣列.
4908
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4909
				#$result["function"],當前執行的函數名稱.
4910
				#$result["argu"],使用的參數.
4911
				#$result["content"],處理好的的字串內容.
4912
				#$result["deleted"],被移除的內容.
4913
				#必填參數:
4914
				#$conf["stringIn"],字串,要處理的字串.
4915
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4916
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4917
				$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
4918
				#可省略參數:
4919
				#無.
4920
				#參考資料:
4921
				#無.
4922
				#備註:
4923
				#無.
4924
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4925
				unset($conf["stringProcess::delHeadStr"]);
4926
 
4927
				#如果執行異常
4928
				if($delHeadStr["status"]==="false"){
4929
 
4930
					#設置錯誤識別
4931
					$result["status"]="false";
4932
 
4933
					#設置錯誤訊息
4934
					$result["error"]=$delHeadStr;
4935
 
4936
					#回傳結果
4937
					return $result;
4938
 
4939
					}#if end
4940
 
4941
				#取得 value;comment
4942
				$unFormatStr=$delHeadStr["content"];
4943
 
4944
				#如果有要合併回去的內容
4945
				if(isset($unFormatStr2add)){
4946
 
4947
					#合併回去內容
4948
					$unFormatStr=$unFormatStr.$unFormatStr2add;
4949
 
4950
					#移除用不到的變數
4951
					unset($unFormatStr2add);
4952
 
4953
					}#if end
4954
 
253 liveuser 4955
				#如果要debug
4956
				if($conf["debug"]==="true"){
249 liveuser 4957
 
253 liveuser 4958
					#函式說明:
4959
					#撰寫log
4960
					#回傳結果:
4961
					#$result["status"],狀態,"true"或"false".
4962
					#$result["error"],錯誤訊息陣列.
4963
					#$result["function"],當前函式的名稱.
4964
					#$result["argu"],使用的參數.
4965
					#$result["content"],要寫入log的內容字串.
4966
					#必填參數:
4967
					#$conf["path"],字串,log檔案的路徑與名稱.
4968
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4969
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4970
					$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4971
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4972
					$conf["logs::record"]["fileArgu"]=__FILE__;
4973
					#可省略參數:
4974
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4975
					#$conf["rewrite"]="false";
4976
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4977
					#$conf["returnOnly"]="true";
4978
					#參考資料:
4979
					#無.
4980
					#備註:
4981
					#無.
4982
					$record=logs::record($conf["logs::record"]);
4983
					unset($conf["logs::record"]);
4984
 
4985
					}#if end
4986
 
249 liveuser 4987
				#如果type不為 CNAME 跟 TXT 跟 SOA
4988
				if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" ){
4989
 
4990
					#儲存value
4991
					$info["value"]=$unFormatStr;
4992
 
4993
					#判斷是否有 ";" 存在
4994
					#函式說明:
4995
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4996
					#回傳結果:
4997
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4998
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
4999
					#$result["function"],當前執行的函式名稱.
5000
					#$result["argu"],所使用的參數.
5001
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5002
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5003
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5004
					#必填參數:
5005
					#$conf["input"],字串,要檢查的字串.
5006
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5007
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5008
					$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
5009
					#可省略參數:
5010
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5011
					#$conf["varEqual"]=array(null,"found");
5012
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5013
					#$conf["varCon"]=array("no_tail"=>" not");
5014
					#參考資料:
5015
					#無.
5016
					#備註:
5017
					#無.
5018
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5019
					unset($conf["search::findSpecifyStrFormat"]);
5020
 
5021
					#如果執行異常
5022
					if($findSpecifyStrFormat["status"]==="false"){
5023
 
5024
						#設置錯誤識別
5025
						$result["status"]="false";
5026
 
5027
						#設置錯誤訊息
5028
						$result["error"]=$findSpecifyStrFormat;
5029
 
5030
						#回傳結果
5031
						return $result;
5032
 
5033
						}#if end
5034
 
5035
					#如果有 ";"
5036
					if($findSpecifyStrFormat["found"]==="true"){
5037
 
5038
						#儲存value
5039
						$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5040
 
5041
						#儲存comment
5042
						$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5043
 
5044
						}#if end
5045
 
5046
					#儲存該筆RR
5047
					$result["content"][]=$info;
5048
 
5049
					#解析完畢換下一行
5050
					continue 2;
5051
 
5052
					}#if end
291 liveuser 5053
 
249 liveuser 5054
				#執行到這邊,代表type為CNAME或TXT或SOA
5055
 
5056
				#如果 type 是 SOA
5057
				if($info["type"]==="SOA"){
5058
 
253 liveuser 5059
					#如果要debug
5060
					if($conf["debug"]==="true"){
5061
 
5062
						#函式說明:
5063
						#撰寫log
5064
						#回傳結果:
5065
						#$result["status"],狀態,"true"或"false".
5066
						#$result["error"],錯誤訊息陣列.
5067
						#$result["function"],當前函式的名稱.
5068
						#$result["argu"],使用的參數.
5069
						#$result["content"],要寫入log的內容字串.
5070
						#必填參數:
5071
						#$conf["path"],字串,log檔案的路徑與名稱.
5072
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5073
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5074
						$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
5075
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5076
						$conf["logs::record"]["fileArgu"]=__FILE__;
5077
						#可省略參數:
5078
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5079
						#$conf["rewrite"]="false";
5080
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5081
						#$conf["returnOnly"]="true";
5082
						#參考資料:
5083
						#無.
5084
						#備註:
5085
						#無.
5086
						$record=logs::record($conf["logs::record"]);
5087
						unset($conf["logs::record"]);
5088
 
5089
						}#if end
5090
 
249 liveuser 5091
					#SOA 範例
5092
					#@	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
5093
 
5094
					#再度嘗試分割
5095
					#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
5096
 
5097
					#函式說明:
5098
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5099
					#回傳結果:
5100
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5101
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
5102
					#$result["function"],當前執行的函式名稱.
5103
					#$result["argu"],所使用的參數.
5104
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5105
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5106
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
5107
					#必填參數:
5108
					#$conf["input"],字串,要檢查的字串.
5109
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5110
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5111
					$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
5112
					#可省略參數:
5113
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5114
					#$conf["varEqual"]=array(null,"found");
5115
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5116
					#$conf["varCon"]=array("no_tail"=>" not");
5117
					#參考資料:
5118
					#無.
5119
					#備註:
5120
					#無.
5121
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5122
					unset($conf["search::findSpecifyStrFormat"]);
5123
 
5124
					#如果執行異常
5125
					if($findSpecifyStrFormat["status"]==="false"){
5126
 
5127
						#設置錯誤識別
5128
						$result["status"]="false";
5129
 
5130
						#設置錯誤訊息
5131
						$result["error"]=$findSpecifyStrFormat;
5132
 
5133
						#回傳結果
5134
						return $result;
5135
 
5136
						}#if end
5137
 
5138
					#如果存在"("
5139
					if($findSpecifyStrFormat["found"]==="true"){
5140
 
5141
						#取得無"("的內容
5142
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
5143
 
5144
						#取得拆下來的含開頭"("內容
5145
						$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
5146
 
5147
						}#if end
5148
 
5149
					#反之
5150
					else{
5151
 
5152
						#函式說明:
5153
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5154
						#回傳結果:
5155
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5156
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
5157
						#$result["function"],當前執行的函式名稱.
5158
						#$result["argu"],所使用的參數.
5159
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5160
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5161
						#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
5162
						#必填參數:
5163
						#$conf["input"],字串,要檢查的字串.
5164
						$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5165
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5166
						$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
5167
						#可省略參數:
5168
						#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5169
						#$conf["varEqual"]=array(null,"found");
5170
						#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5171
						#$conf["varCon"]=array("no_tail"=>" not");
5172
						#參考資料:
5173
						#無.
5174
						#備註:
5175
						#無.
5176
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5177
						unset($conf["search::findSpecifyStrFormat"]);
5178
 
5179
						#如果執行異常
5180
						if($findSpecifyStrFormat["status"]==="false"){
5181
 
5182
							#設置錯誤識別
5183
							$result["status"]="false";
5184
 
5185
							#設置錯誤訊息
5186
							$result["error"]=$findSpecifyStrFormat;
5187
 
5188
							#回傳結果
5189
							return $result;
5190
 
5191
							}#if end
5192
 
5193
						#如果存在"
5194
						if($findSpecifyStrFormat["found"]==="true"){
5195
 
5196
							#取得無"的內容
5197
							$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
5198
 
5199
							#取得拆下來的含開頭"內容
5200
							$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
5201
 
5202
							}#if end
5203
 
5204
						#反之
5205
						else{
5206
 
5207
							#函式說明:
5208
							#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5209
							#回傳結果:
5210
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5211
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
5212
							#$result["function"],當前執行的函式名稱.
5213
							#$result["argu"],所使用的參數.
5214
							#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5215
							#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5216
							#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
5217
							#必填參數:
5218
							#$conf["input"],字串,要檢查的字串.
5219
							$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5220
							#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5221
							$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
5222
							#可省略參數:
5223
							#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5224
							#$conf["varEqual"]=array(null,"found");
5225
							#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5226
							#$conf["varCon"]=array("no_tail"=>" not");
5227
							#參考資料:
5228
							#無.
5229
							#備註:
5230
							#無.
5231
							$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5232
							unset($conf["search::findSpecifyStrFormat"]);
5233
 
5234
							#如果執行異常
5235
							if($findSpecifyStrFormat["status"]==="false"){
5236
 
5237
								#設置錯誤識別
5238
								$result["status"]="false";
5239
 
5240
								#設置錯誤訊息
5241
								$result["error"]=$findSpecifyStrFormat;
5242
 
5243
								#回傳結果
5244
								return $result;
5245
 
5246
								}#if end
5247
 
5248
							#如果存在";"
5249
							if($findSpecifyStrFormat["found"]==="true"){
5250
 
5251
								#取得無";"的內容
5252
								$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
5253
 
5254
								#取得拆下來的含開頭";"內容
5255
								$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
5256
 
5257
								}#if end
5258
 
5259
							}#else end
5260
 
5261
						}#else end
5262
 
5263
					#取得 serial number
5264
					#函式說明:
5265
					#將字串進行解析,變成多個參數.
5266
					#回傳結果:
5267
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
5268
					#$result["function"],當前執行的函式內容.
5269
					#$result["error"],錯誤訊息陣列.
5270
					#$result["content"],參數陣列.
5271
					#$result["count"],總共有幾個參數.
5272
					#必填參數:
5273
					#$conf["input"],字串,要解析成參數的字串.
5274
					$conf["stringProcess::parse"]["input"]=$unFormatStr;
5275
					#可省略參數:
5276
					#無.
5277
					#參考資料:
5278
					#無.
5279
					#備註:
5280
					#無.
5281
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
5282
					unset($conf["stringProcess::parse"]);
5283
 
5284
					#如果執行異常
5285
					if($parse["status"]==="false"){
5286
 
5287
						#設置錯誤識別
5288
						$result["status"]="false";
5289
 
5290
						#設置錯誤訊息
5291
						$result["error"]=$parse;
5292
 
5293
						#回傳結果
5294
						return $result;
5295
 
5296
						}#if end
5297
 
5298
					#取得serial number
5299
					$serialNo=$parse["content"][2];
5300
 
5301
					#serialNo+1
5302
					$serialNo++;
5303
 
5304
					#回存
5305
					$parse["content"][2]=(string)$serialNo;
5306
 
5307
					#函式說明:
5308
					#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
5309
					#回傳的結果:
5310
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5311
					#$result["function"],當前執行的function名稱
5312
					#$result["error"],錯誤訊息陣列.
5313
					#$result["content"],處理好的字串.
5314
					#$result["argu"],使用的參數.
5315
					#必填參數:
5316
					#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
5317
					$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
5318
					#可省略參數:
5319
					#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
5320
					$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
5321
					#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
5322
					$conf["arrays::arrayToString"]["skipEnd"]="true";
5323
					#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
5324
					#$conf["spiltSymbolAtStart"]="";
5325
					#參考資料:
5326
					#無.
5327
					#備註:
5328
					#無.
5329
					$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
5330
					unset($conf["arrays::arrayToString"]);
5331
 
5332
					#如果執行異常
5333
					if($arrayToString["status"]==="false"){
5334
 
5335
						#設置錯誤識別
5336
						$result["status"]="false";
5337
 
5338
						#設置錯誤訊息
5339
						$result["error"]=$arrayToString;
5340
 
5341
						#回傳結果
5342
						return $result;
5343
 
5344
						}#if end
5345
 
5346
					#取得更新 serial number 後的 SOA value string
5347
					$unFormatStr=$arrayToString["content"];
5348
 
5349
					#如果有要合併回去的內容
5350
					if(isset($unFormatStr2add)){
5351
 
5352
						#合併回去內容
5353
						$unFormatStr=$unFormatStr.$unFormatStr2add;
5354
 
5355
						#移除用不到的變數
5356
						unset($unFormatStr2add);
5357
 
5358
						}#if end
5359
 
5360
					#假設剩下的沒有註解都是 value
5361
					$info["value"]=$unFormatStr;
5362
 
5363
					#函式說明:
5364
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5365
					#回傳結果:
5366
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5367
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
5368
					#$result["function"],當前執行的函式名稱.
5369
					#$result["argu"],所使用的參數.
5370
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5371
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5372
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5373
					#必填參數:
5374
					#$conf["input"],字串,要檢查的字串.
5375
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5376
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5377
					$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
5378
					#可省略參數:
5379
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5380
					#$conf["varEqual"]=array(null,"found");
5381
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5382
					#$conf["varCon"]=array("no_tail"=>" not");
5383
					#參考資料:
5384
					#無.
5385
					#備註:
5386
					#無.
5387
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5388
					unset($conf["search::findSpecifyStrFormat"]);
5389
 
5390
					#如果執行異常
5391
					if($findSpecifyStrFormat["status"]==="false"){
5392
 
5393
						#設置錯誤識別
5394
						$result["status"]="false";
5395
 
5396
						#設置錯誤訊息
5397
						$result["error"]=$findSpecifyStrFormat;
5398
 
5399
						#回傳結果
5400
						return $result;
5401
 
5402
						}#if end
5403
 
5404
					#如果有符合格式
5405
					if($findSpecifyStrFormat["found"]==="true"){
5406
 
5407
						#儲存 value
5408
						$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5409
 
5410
						#儲存 comment
5411
						$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5412
 
5413
						}#if end
5414
 
5415
					#儲存該筆RR
5416
					$result["content"][]=$info;
5417
 
5418
					#換下解析下筆RR
5419
					continue 2;
5420
 
5421
					}#if end
5422
 
5423
				#執行到這邊代表不是 SOA
5424
 
5425
				#尋找是否有(...)...的內容存在
5426
				#函式說明:
5427
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5428
				#回傳結果:
5429
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5430
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5431
				#$result["function"],當前執行的函式名稱.
5432
				#$result["argu"],所使用的參數.
5433
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5434
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5435
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5436
				#必填參數:
5437
				#$conf["input"],字串,要檢查的字串.
5438
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5439
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5440
				$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
5441
				#可省略參數:
5442
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5443
				#$conf["varEqual"]=array(null,"found");
5444
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5445
				#$conf["varCon"]=array("no_tail"=>" not");
5446
				#參考資料:
5447
				#無.
5448
				#備註:
5449
				#無.
5450
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5451
				unset($conf["search::findSpecifyStrFormat"]);
5452
 
5453
				#如果執行異常
5454
				if($findSpecifyStrFormat["status"]==="false"){
5455
 
5456
					#設置錯誤識別
5457
					$result["status"]="false";
5458
 
5459
					#設置錯誤訊息
5460
					$result["error"]=$findSpecifyStrFormat;
5461
 
5462
					#回傳結果
5463
					return $result;
5464
 
5465
					}#if end
5466
 
5467
				#如果有 有符合 ($value);${comment} 的格式
5468
				if($findSpecifyStrFormat["found"]==="true"){
5469
 
5470
					#儲存value
5471
					$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
5472
 
5473
					#儲存comment
5474
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5475
 
5476
					#儲存 RR 的記錄
5477
					$result["content"][]=$info;
5478
 
5479
					#跳到下一筆要解析的RR
5480
					continue 2;
5481
 
5482
					}#if end
5483
 
5484
				#執行到這邊代表沒有 (...)... 的內容存在
5485
 
5486
				#尋找是否有 (...) 的內容存在
5487
				#函式說明:
5488
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5489
				#回傳結果:
5490
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5491
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5492
				#$result["function"],當前執行的函式名稱.
5493
				#$result["argu"],所使用的參數.
5494
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5495
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5496
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5497
				#必填參數:
5498
				#$conf["input"],字串,要檢查的字串.
5499
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5500
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5501
				$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
5502
				#可省略參數:
5503
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5504
				#$conf["varEqual"]=array(null,"found");
5505
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5506
				#$conf["varCon"]=array("no_tail"=>" not");
5507
				#參考資料:
5508
				#無.
5509
				#備註:
5510
				#無.
5511
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5512
				unset($conf["search::findSpecifyStrFormat"]);
5513
 
5514
				#如果執行異常
5515
				if($findSpecifyStrFormat["status"]==="false"){
5516
 
5517
					#設置錯誤識別
5518
					$result["status"]="false";
5519
 
5520
					#設置錯誤訊息
5521
					$result["error"]=$findSpecifyStrFormat;
5522
 
5523
					#回傳結果
5524
					return $result;
5525
 
5526
					}#if end
5527
 
5528
				#如果有 有符合 ($value);${comment} 的格式
5529
				if($findSpecifyStrFormat["found"]==="true"){
5530
 
5531
					#儲存value
5532
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5533
 
5534
					#儲存 RR 的記錄
5535
					$result["content"][]=$info;
5536
 
5537
					#跳到下一筆要解析的RR
5538
					continue 2;
5539
 
5540
					}#if end
5541
 
5542
				#執行到這邊代表沒有 (...) 的內容存在
5543
 
5544
				#尋找有無 "...";... 的內容存在
5545
				#函式說明:
5546
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5547
				#回傳結果:
5548
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5549
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5550
				#$result["function"],當前執行的函式名稱.
5551
				#$result["argu"],所使用的參數.
5552
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5553
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5554
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5555
				#必填參數:
5556
				#$conf["input"],字串,要檢查的字串.
5557
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5558
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5559
				$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
5560
				#可省略參數:
5561
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5562
				#$conf["varEqual"]=array(null,"found");
5563
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5564
				#$conf["varCon"]=array("no_tail"=>" not");
5565
				#參考資料:
5566
				#無.
5567
				#備註:
5568
				#無.
5569
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5570
				unset($conf["search::findSpecifyStrFormat"]);
5571
 
5572
				#如果執行異常
5573
				if($findSpecifyStrFormat["status"]==="false"){
5574
 
5575
					#設置錯誤識別
5576
					$result["status"]="false";
5577
 
5578
					#設置錯誤訊息
5579
					$result["error"]=$findSpecifyStrFormat;
5580
 
5581
					#回傳結果
5582
					return $result;
5583
 
5584
					}#if end
5585
 
5586
				#如果有 有符合 "$value";${comment} 的格式
5587
				if($findSpecifyStrFormat["found"]==="true"){
5588
 
5589
					#儲存value
5590
					$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
5591
 
5592
					#儲存comment
5593
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5594
 
5595
					#儲存 RR 的記錄
5596
					$result["content"][]=$info;
5597
 
5598
					#跳到下一筆要解析的RR
5599
					continue 2;
5600
 
5601
					}#if end
5602
 
5603
				#執行到這邊代表沒有 "$value";${comment} 的格式
5604
 
5605
				#尋找有無 "..." 的內容存在
5606
				#函式說明:
5607
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5608
				#回傳結果:
5609
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5610
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5611
				#$result["function"],當前執行的函式名稱.
5612
				#$result["argu"],所使用的參數.
5613
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5614
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5615
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5616
				#必填參數:
5617
				#$conf["input"],字串,要檢查的字串.
5618
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5619
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5620
				$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
5621
				#可省略參數:
5622
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5623
				#$conf["varEqual"]=array(null,"found");
5624
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5625
				#$conf["varCon"]=array("no_tail"=>" not");
5626
				#參考資料:
5627
				#無.
5628
				#備註:
5629
				#無.
5630
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5631
				unset($conf["search::findSpecifyStrFormat"]);
5632
 
5633
				#如果執行異常
5634
				if($findSpecifyStrFormat["status"]==="false"){
5635
 
5636
					#設置錯誤識別
5637
					$result["status"]="false";
5638
 
5639
					#設置錯誤訊息
5640
					$result["error"]=$findSpecifyStrFormat;
5641
 
5642
					#回傳結果
5643
					return $result;
5644
 
5645
					}#if end
5646
 
5647
				#如果有 有符合 "$value" 的格式
5648
				if($findSpecifyStrFormat["found"]==="true"){
5649
 
5650
					#儲存value
5651
					$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
5652
 
5653
					#儲存 RR 的記錄
5654
					$result["content"][]=$info;
5655
 
5656
					#跳到下一筆要解析的RR
5657
					continue 2;
5658
 
5659
					}#if end
5660
 
5661
				#執行到這邊代表沒有 "$value" 格式的內容
5662
 
5663
				#檢查是否有 $value;$comment 格式的內容
5664
				#函式說明:
5665
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5666
				#回傳結果:
5667
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5668
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5669
				#$result["function"],當前執行的函式名稱.
5670
				#$result["argu"],所使用的參數.
5671
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5672
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5673
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5674
				#必填參數:
5675
				#$conf["input"],字串,要檢查的字串.
5676
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5677
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5678
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
5679
				#可省略參數:
5680
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5681
				#$conf["varEqual"]=array(null,"found");
5682
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5683
				#$conf["varCon"]=array("no_tail"=>" not");
5684
				#參考資料:
5685
				#無.
5686
				#備註:
5687
				#無.
5688
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5689
				unset($conf["search::findSpecifyStrFormat"]);
5690
 
5691
				#如果執行異常
5692
				if($findSpecifyStrFormat["status"]==="false"){
5693
 
5694
					#設置錯誤識別
5695
					$result["status"]="false";
5696
 
5697
					#設置錯誤訊息
5698
					$result["error"]=$findSpecifyStrFormat;
5699
 
5700
					#回傳結果
5701
					return $result;
5702
 
5703
					}#if end
5704
 
5705
				#如果有 有符合 "$value" 的格式
5706
				if($findSpecifyStrFormat["found"]==="true"){
5707
 
5708
					#儲存value
5709
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5710
 
5711
					#儲存comment
5712
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5713
 
5714
					#儲存 RR 的記錄
5715
					$result["content"][]=$info;
5716
 
5717
					#跳到下一筆要解析的RR
5718
					continue 2;
5719
 
5720
					}#if end
5721
 
5722
				#執行到這邊代表沒有 ${value};${comment} 格式的內容
5723
 
5724
				#亦即剩下的內容都是 value
5725
 
5726
				#儲存value
5727
				$info["value"]=$unFormatStr;
5728
 
5729
				#儲存 RR 的記錄
5730
				$result["content"][]=$info;
5731
 
5732
				#跳到下一筆要解析的RR
5733
				continue 2;
5734
 
5735
				}#while end
5736
 
5737
			}#foreach end
291 liveuser 5738
 
5739
		#如果要啟用多執行序
293 liveuser 5740
		if($conf["multiThreads"]==="true"){
249 liveuser 5741
 
293 liveuser 5742
			#如果要debug
5743
			if($conf["debug"]==="true"){
5744
 
5745
				#函式說明:
5746
				#撰寫log
5747
				#回傳結果:
5748
				#$result["status"],狀態,"true"或"false".
5749
				#$result["error"],錯誤訊息陣列.
5750
				#$result["function"],當前函式的名稱.
5751
				#$result["argu"],使用的參數.
5752
				#$result["content"],要寫入log的內容字串.
5753
				#必填參數:
5754
				#$conf["path"],字串,log檔案的路徑與名稱.
5755
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5756
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5757
				$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR result through multi threads.".PHP_EOL;
5758
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5759
				$conf["logs::record"]["fileArgu"]=__FILE__;
5760
				#可省略參數:
5761
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5762
				#$conf["rewrite"]="false";
5763
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5764
				#$conf["returnOnly"]="true";
5765
				#參考資料:
5766
				#無.
5767
				#備註:
5768
				#無.
5769
				$record=logs::record($conf["logs::record"]);
5770
				unset($conf["logs::record"]);
5771
 
5772
				}#if end
291 liveuser 5773
 
293 liveuser 5774
			#無窮迴圈
5775
			while(true){
5776
 
5777
				#等後1秒
5778
				sleep(1);
5779
 
5780
				#針對每行處理的狀況
5781
				foreach($procs as $procIndex => $proc){
5782
 
5783
					#如果要debug
5784
					if($conf["debug"]==="true"){
5785
 
5786
						#函式說明:
5787
						#撰寫log
5788
						#回傳結果:
5789
						#$result["status"],狀態,"true"或"false".
5790
						#$result["error"],錯誤訊息陣列.
5791
						#$result["function"],當前函式的名稱.
5792
						#$result["argu"],使用的參數.
5793
						#$result["content"],要寫入log的內容字串.
5794
						#必填參數:
5795
						#$conf["path"],字串,log檔案的路徑與名稱.
5796
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5797
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5798
						$conf["logs::record"]["content"]="lineNo:".__LINE__." Try get result of parsing RR line ".($procIndex+1)." through multi threads.".PHP_EOL;
5799
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5800
						$conf["logs::record"]["fileArgu"]=__FILE__;
5801
						#可省略參數:
5802
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5803
						#$conf["rewrite"]="false";
5804
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5805
						#$conf["returnOnly"]="true";
5806
						#參考資料:
5807
						#無.
5808
						#備註:
5809
						#無.
5810
						$record=logs::record($conf["logs::record"]);
5811
						unset($conf["logs::record"]);
5812
 
5813
						}#if end
5814
 
5815
					#函式說明:
5816
					#更新透過proc執行的多程序資訊.
5817
					#回傳結果:
5818
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5819
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
5820
					#$result["function"],當前執行的函式名稱.
5821
					#$result["argu"],使用的參數.
5822
					#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
5823
					#必填參數:
5824
					#$conf["procs"],陣列,運行self::proc後回傳的content.
5825
					$conf["threads::proc_update"]["procs"]=$proc["content"];
5826
					#可省略參數:
5827
					#無.
5828
					#參考資料:
5829
					#無.
5830
					#備註:
5831
					#無.
5832
					$proc_update=threads::proc_update($conf["threads::proc_update"]);
5833
					unset($conf["threads::proc_update"]);
5834
 
5835
					#debug
5836
					#var_dump($proc_update);exit;
5837
 
5838
					#如果執行異常
5839
					if($proc_update["status"]==="false"){
5840
 
5841
						#設置執行異常
5842
						$result["status"]="false";
5843
 
5844
						#設置執行錯誤
5845
						$result["error"]=$proc_update;
5846
 
5847
						#回傳結果
5848
						return $result;
5849
 
5850
						}#if end
5851
 
5852
					#另存結果
5853
					$procRes=$proc_update["content"][0];
5854
 
5855
					#如果程序執行異常
5856
					if($procRes["status"]==="false"){
5857
 
5858
						#設置執行異常
5859
						$result["status"]="false";
5860
 
5861
						#設置執行錯誤
5862
						$result["error"]=$procRes;
5863
 
5864
						#回傳結果
5865
						return $result;
5866
 
5867
						}#if end
5868
 
5869
					#如果程序尚在執行
5870
					if($procRes["statusCode"]==="?"){
5871
 
5872
						#換看下一列的執行狀況
5873
						continue;
5874
 
5875
						}#if end
5876
 
5877
					#如果輸出內容不是 json
5878
					if(!(json_validate($procRes["content"]))){
5879
 
5880
						#設置執行異常
5881
						$result["status"]="false";
5882
 
5883
						#設置執行錯誤
5884
						$result["error"]=$procRes;
5885
 
5886
						#回傳結果
5887
						return $result;
5888
 
5889
						}#if end
5890
 
5891
					#解析json
5892
					$jsonRes=json_decode($procRes["content"]);
5893
 
5894
					#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","query","update",也可能為空陣列.
5895
					#$result["domain"],字串,RR所屬domain.
5896
					#$result["defaultTTL"],字串,預設的RR更新時間.
5897
					#$result["comment"],字串,一行的註解.
5898
 
5899
					#如果有 content->type 存在
5900
					if(isset($jsonRes->content->type)){
5901
 
5902
						#儲存value
5903
						$info["type"]=$jsonRes->content->type;
5904
 
5905
						}#if end
5906
 
5907
					#如果有 content->value 存在
5908
					if(isset($jsonRes->content->value)){
5909
 
5910
						#儲存value
5911
						$info["value"]=$jsonRes->content->value;
5912
 
5913
						}#if end
5914
 
5915
					#如果有 content->query 存在
5916
					if(isset($jsonRes->content->query)){
5917
 
5918
						#儲存query
5919
						$info["query"]=$jsonRes->content->query;
5920
 
5921
						}#if end
5922
 
5923
					#如果有 content->update 存在
5924
					if(isset($jsonRes->content->update)){
5925
 
5926
						#儲存query
5927
						$info["update"]=$jsonRes->content->update;
5928
 
5929
						}#if end
5930
 
5931
					#如果有 domain 存在
5932
					if(isset($jsonRes->domain)){
5933
 
5934
						#儲存domain
5935
						$result["domain"]=$jsonRes->domain;
5936
 
5937
						}#if end
5938
 
5939
					#如果有 defaultTTL 存在
5940
					if(isset($jsonRes->defaultTTL)){
5941
 
5942
						#儲存domain
5943
						$result["domain"]=$jsonRes->defaultTTL;
5944
 
5945
						}#if end
5946
 
5947
					#如果有 comment 存在
5948
					if(isset($jsonRes->comment)){
5949
 
5950
						#儲存comment,用$procIndex作為先後順率的識別
5951
						$result["comment"][$procIndex]=$jsonRes->comment;
5952
 
5953
						}#if end
5954
 
5955
					#儲存 RR 的記錄
5956
					$result["content"][$procIndex]=$info;
5957
 
5958
					#移除解析好的行號
5959
					unset($procs[$procIndex]);
5960
 
5961
					#如果要debug
5962
					if($conf["debug"]==="true"){
5963
 
5964
						#函式說明:
5965
						#撰寫log
5966
						#回傳結果:
5967
						#$result["status"],狀態,"true"或"false".
5968
						#$result["error"],錯誤訊息陣列.
5969
						#$result["function"],當前函式的名稱.
5970
						#$result["argu"],使用的參數.
5971
						#$result["content"],要寫入log的內容字串.
5972
						#必填參數:
5973
						#$conf["path"],字串,log檔案的路徑與名稱.
5974
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5975
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5976
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR line ".($procIndex+1)." through multi threads fin.".PHP_EOL;
5977
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5978
						$conf["logs::record"]["fileArgu"]=__FILE__;
5979
						#可省略參數:
5980
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5981
						#$conf["rewrite"]="false";
5982
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5983
						#$conf["returnOnly"]="true";
5984
						#參考資料:
5985
						#無.
5986
						#備註:
5987
						#無.
5988
						$record=logs::record($conf["logs::record"]);
5989
						unset($conf["logs::record"]);
5990
 
5991
						}#if end
5992
 
5993
					}#foreach end
5994
 
5995
				#如果每行都已經解析好了
5996
				if(count($procs)===0){
5997
 
5998
					#如果要debug
5999
					if($conf["debug"]==="true"){
6000
 
6001
						#函式說明:
6002
						#撰寫log
6003
						#回傳結果:
6004
						#$result["status"],狀態,"true"或"false".
6005
						#$result["error"],錯誤訊息陣列.
6006
						#$result["function"],當前函式的名稱.
6007
						#$result["argu"],使用的參數.
6008
						#$result["content"],要寫入log的內容字串.
6009
						#必填參數:
6010
						#$conf["path"],字串,log檔案的路徑與名稱.
6011
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6012
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6013
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR through multi threads fin.".PHP_EOL;
6014
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6015
						$conf["logs::record"]["fileArgu"]=__FILE__;
6016
						#可省略參數:
6017
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6018
						#$conf["rewrite"]="false";
6019
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6020
						#$conf["returnOnly"]="true";
6021
						#參考資料:
6022
						#無.
6023
						#備註:
6024
						#無.
6025
						$record=logs::record($conf["logs::record"]);
6026
						unset($conf["logs::record"]);
6027
 
6028
						}#if end
6029
 
6030
					#跳出 while
6031
					break;
6032
 
6033
					}#if end
6034
 
6035
				}#while end
6036
 
291 liveuser 6037
			}#if end
6038
 
253 liveuser 6039
		#如果要debug
6040
		if($conf["debug"]==="true"){
249 liveuser 6041
 
253 liveuser 6042
			#函式說明:
6043
			#撰寫log
6044
			#回傳結果:
6045
			#$result["status"],狀態,"true"或"false".
6046
			#$result["error"],錯誤訊息陣列.
6047
			#$result["function"],當前函式的名稱.
6048
			#$result["argu"],使用的參數.
6049
			#$result["content"],要寫入log的內容字串.
6050
			#必填參數:
6051
			#$conf["path"],字串,log檔案的路徑與名稱.
6052
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6053
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6054
			$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR fin.".PHP_EOL;
6055
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6056
			$conf["logs::record"]["fileArgu"]=__FILE__;
6057
			#可省略參數:
6058
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6059
			#$conf["rewrite"]="false";
6060
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6061
			#$conf["returnOnly"]="true";
6062
			#參考資料:
6063
			#無.
6064
			#備註:
6065
			#無.
6066
			$record=logs::record($conf["logs::record"]);
6067
			unset($conf["logs::record"]);
6068
 
6069
			}#if end
6070
 
249 liveuser 6071
		#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
6072
 
6073
		#針對每個要新增的RR記錄
255 liveuser 6074
		foreach($conf["add"] as $nri => $newRR){
249 liveuser 6075
 
255 liveuser 6076
			#如果要debug
6077
			if($conf["debug"]==="true"){
6078
 
6079
				#函式說明:
6080
				#撰寫log
6081
				#回傳結果:
6082
				#$result["status"],狀態,"true"或"false".
6083
				#$result["error"],錯誤訊息陣列.
6084
				#$result["function"],當前函式的名稱.
6085
				#$result["argu"],使用的參數.
6086
				#$result["content"],要寫入log的內容字串.
6087
				#必填參數:
6088
				#$conf["path"],字串,log檔案的路徑與名稱.
6089
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6090
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6091
				$conf["logs::record"]["content"]="lineNo:".__LINE__." ori newRR:".PHP_EOL;
6092
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6093
				$conf["logs::record"]["fileArgu"]=__FILE__;
6094
				#可省略參數:
6095
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6096
				#$conf["rewrite"]="false";
6097
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6098
				#$conf["returnOnly"]="true";
6099
				#參考資料:
6100
				#無.
6101
				#備註:
6102
				#無.
6103
				$record=logs::record($conf["logs::record"]);
6104
				unset($conf["logs::record"]);
6105
 
6106
				#函式說明:
6107
				#撰寫log
6108
				#回傳結果:
6109
				#$result["status"],狀態,"true"或"false".
6110
				#$result["error"],錯誤訊息陣列.
6111
				#$result["function"],當前函式的名稱.
6112
				#$result["argu"],使用的參數.
6113
				#$result["content"],要寫入log的內容字串.
6114
				#必填參數:
6115
				#$conf["path"],字串,log檔案的路徑與名稱.
6116
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6117
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6118
				$conf["logs::record"]["content"]=$newRR;
6119
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6120
				$conf["logs::record"]["fileArgu"]=__FILE__;
6121
				#可省略參數:
6122
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6123
				#$conf["rewrite"]="false";
6124
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6125
				#$conf["returnOnly"]="true";
6126
				#參考資料:
6127
				#無.
6128
				#備註:
6129
				#無.
6130
				$record=logs::record($conf["logs::record"]);
6131
				unset($conf["logs::record"]);
6132
 
6133
				}#if end
6134
 
6135
			#如果新的 RR 缺少必備的資訊
6136
			if(!isset($newRR["type"])){
6137
 
6138
				#設置執行異常
6139
				$result["status"]="false";
6140
 
6141
				#設置執行錯誤
6142
				$result["error"]="add參數的格式缺少type";
6143
 
6144
				#回傳結果
6145
				return $result;
6146
 
6147
				}#if end
6148
 
6149
			#如果 query 結尾不是"@"也不為"."結尾
6150
			if( ($newRR["query"]!=="@") && ($newRR["query"][strlen($newRR["query"])-1]!==".") ){
6151
 
6152
				#加上 "."
6153
				$conf["add"][$nri]["query"]=$newRR["query"]=$newRR["query"].".";
6154
 
6155
				}#if end
6156
 
6157
			#如果新的 query 為 $ORGIN 結尾
6158
			#函式說明:
6159
			#將字串特定關鍵字與其後面的內容剔除
6160
			#回傳結果:
6161
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6162
			#$result["error"],錯誤訊息陣列.
6163
			#$result["warning"],警告訊息鎮列.
6164
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
6165
			#$result["function"],當前執行的函數名稱.
6166
			#$result["oriStr"],要處理的原始字串內容.
6167
			#$result["content"],處理好的的字串內容.
6168
			#$result["deleted"],被移除的內容.
6169
			#$result["argu"],使用的參數.
6170
			#必填參數:
6171
			#$conf["stringIn"],字串,要處理的字串.
6172
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
6173
			#$conf["keyWord"],字串,特定字串.
6174
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["domain"];
6175
			#可省略參數:
6176
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
6177
			#$conf["deleteLastRepeatedOne"]="";
6178
			#參考資料:
6179
			#無.
6180
			#備註:
6181
			#無.
6182
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
6183
			unset($conf["stringProcess::delStrAfterKeyWord"]);
6184
 
6185
			#如果要debug
6186
			if($conf["debug"]==="true"){
6187
 
6188
				#函式說明:
6189
				#撰寫log
6190
				#回傳結果:
6191
				#$result["status"],狀態,"true"或"false".
6192
				#$result["error"],錯誤訊息陣列.
6193
				#$result["function"],當前函式的名稱.
6194
				#$result["argu"],使用的參數.
6195
				#$result["content"],要寫入log的內容字串.
6196
				#必填參數:
6197
				#$conf["path"],字串,log檔案的路徑與名稱.
6198
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6199
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6200
				$conf["logs::record"]["content"]="lineNo:".__LINE__." try process newRR with \$ORIGIN end".PHP_EOL;
6201
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6202
				$conf["logs::record"]["fileArgu"]=__FILE__;
6203
				#可省略參數:
6204
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6205
				#$conf["rewrite"]="false";
6206
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6207
				#$conf["returnOnly"]="true";
6208
				#參考資料:
6209
				#無.
6210
				#備註:
6211
				#無.
6212
				$record=logs::record($conf["logs::record"]);
6213
				unset($conf["logs::record"]);
6214
 
6215
				#函式說明:
6216
				#撰寫log
6217
				#回傳結果:
6218
				#$result["status"],狀態,"true"或"false".
6219
				#$result["error"],錯誤訊息陣列.
6220
				#$result["function"],當前函式的名稱.
6221
				#$result["argu"],使用的參數.
6222
				#$result["content"],要寫入log的內容字串.
6223
				#必填參數:
6224
				#$conf["path"],字串,log檔案的路徑與名稱.
6225
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6226
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6227
				$conf["logs::record"]["content"]=$delStrAfterKeyWord;
6228
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6229
				$conf["logs::record"]["fileArgu"]=__FILE__;
6230
				#可省略參數:
6231
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6232
				#$conf["rewrite"]="false";
6233
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6234
				#$conf["returnOnly"]="true";
6235
				#參考資料:
6236
				#無.
6237
				#備註:
6238
				#無.
6239
				$record=logs::record($conf["logs::record"]);
6240
				unset($conf["logs::record"]);
6241
 
6242
				}#if end
6243
 
6244
			#如果異常
6245
			if($delStrAfterKeyWord["status"]==="false"){
6246
 
6247
				#設置執行異常
6248
				$result["status"]="false";
6249
 
6250
				#設置執行錯誤
6251
				$result["error"]=$delStrAfterKeyWord;
6252
 
6253
				#回傳結果
6254
				return $result;
6255
 
6256
				}#if end
6257
 
6258
			#如果有找到 $ORIGIN 結尾
6259
			if($delStrAfterKeyWord["founded"]==="true"){
6260
 
6261
				#更新 query
6262
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
6263
 
6264
				#如果$newRR["query"] 變成 ""
6265
				if(empty($newRR["query"])){
6266
 
6267
					#變成 zone domain,亦即 $result["domain"]
6268
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
6269
 
6270
					}#if end
6271
 
6272
				#如果要debug
6273
				if($conf["debug"]==="true"){
6274
 
6275
					#函式說明:
6276
					#撰寫log
6277
					#回傳結果:
6278
					#$result["status"],狀態,"true"或"false".
6279
					#$result["error"],錯誤訊息陣列.
6280
					#$result["function"],當前函式的名稱.
6281
					#$result["argu"],使用的參數.
6282
					#$result["content"],要寫入log的內容字串.
6283
					#必填參數:
6284
					#$conf["path"],字串,log檔案的路徑與名稱.
6285
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6286
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6287
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
6288
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6289
					$conf["logs::record"]["fileArgu"]=__FILE__;
6290
					#可省略參數:
6291
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6292
					#$conf["rewrite"]="false";
6293
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6294
					#$conf["returnOnly"]="true";
6295
					#參考資料:
6296
					#無.
6297
					#備註:
6298
					#無.
6299
					$record=logs::record($conf["logs::record"]);
6300
					unset($conf["logs::record"]);
6301
 
6302
					#函式說明:
6303
					#撰寫log
6304
					#回傳結果:
6305
					#$result["status"],狀態,"true"或"false".
6306
					#$result["error"],錯誤訊息陣列.
6307
					#$result["function"],當前函式的名稱.
6308
					#$result["argu"],使用的參數.
6309
					#$result["content"],要寫入log的內容字串.
6310
					#必填參數:
6311
					#$conf["path"],字串,log檔案的路徑與名稱.
6312
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6313
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6314
					$conf["logs::record"]["content"]=$conf["add"][$nri];
6315
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6316
					$conf["logs::record"]["fileArgu"]=__FILE__;
6317
					#可省略參數:
6318
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6319
					#$conf["rewrite"]="false";
6320
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6321
					#$conf["returnOnly"]="true";
6322
					#參考資料:
6323
					#無.
6324
					#備註:
6325
					#無.
6326
					$record=logs::record($conf["logs::record"]);
6327
					unset($conf["logs::record"]);
6328
 
6329
					}#if end
6330
 
6331
				}#if end
6332
 
6333
			#如果新的 query 為 "." 結尾
6334
			#函式說明:
6335
			#將字串特定關鍵字與其後面的內容剔除
6336
			#回傳結果:
6337
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6338
			#$result["error"],錯誤訊息陣列.
6339
			#$result["warning"],警告訊息鎮列.
6340
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
6341
			#$result["function"],當前執行的函數名稱.
6342
			#$result["oriStr"],要處理的原始字串內容.
6343
			#$result["content"],處理好的的字串內容.
6344
			#$result["deleted"],被移除的內容.
6345
			#$result["argu"],使用的參數.
6346
			#必填參數:
6347
			#$conf["stringIn"],字串,要處理的字串.
6348
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
6349
			#$conf["keyWord"],字串,特定字串.
6350
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".";
6351
			#可省略參數:
6352
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
6353
			#$conf["deleteLastRepeatedOne"]="";
6354
			#參考資料:
6355
			#無.
6356
			#備註:
6357
			#無.
6358
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
6359
			unset($conf["stringProcess::delStrAfterKeyWord"]);
6360
 
6361
			#如果異常
6362
			if($delStrAfterKeyWord["status"]==="false"){
6363
 
6364
				#設置執行異常
6365
				$result["status"]="false";
6366
 
6367
				#設置執行錯誤
6368
				$result["error"]=$delStrAfterKeyWord;
6369
 
6370
				#回傳結果
6371
				return $result;
6372
 
6373
				}#if end
6374
 
6375
			#如果有找到 "." 結尾
6376
			if($delStrAfterKeyWord["founded"]==="true"){
6377
 
6378
				#更新 query
6379
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
6380
 
6381
				#如果 $newRR["query"] 變成 ""
6382
				if(empty($newRR["query"])){
6383
 
6384
					#變成 zone domain,亦即 $result["domain"]
6385
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
6386
 
6387
					}#if end
6388
 
6389
				#如果要debug
6390
				if($conf["debug"]==="true"){
6391
 
6392
					#函式說明:
6393
					#撰寫log
6394
					#回傳結果:
6395
					#$result["status"],狀態,"true"或"false".
6396
					#$result["error"],錯誤訊息陣列.
6397
					#$result["function"],當前函式的名稱.
6398
					#$result["argu"],使用的參數.
6399
					#$result["content"],要寫入log的內容字串.
6400
					#必填參數:
6401
					#$conf["path"],字串,log檔案的路徑與名稱.
6402
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6403
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6404
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
6405
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6406
					$conf["logs::record"]["fileArgu"]=__FILE__;
6407
					#可省略參數:
6408
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6409
					#$conf["rewrite"]="false";
6410
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6411
					#$conf["returnOnly"]="true";
6412
					#參考資料:
6413
					#無.
6414
					#備註:
6415
					#無.
6416
					$record=logs::record($conf["logs::record"]);
6417
					unset($conf["logs::record"]);
6418
 
6419
					#函式說明:
6420
					#撰寫log
6421
					#回傳結果:
6422
					#$result["status"],狀態,"true"或"false".
6423
					#$result["error"],錯誤訊息陣列.
6424
					#$result["function"],當前函式的名稱.
6425
					#$result["argu"],使用的參數.
6426
					#$result["content"],要寫入log的內容字串.
6427
					#必填參數:
6428
					#$conf["path"],字串,log檔案的路徑與名稱.
6429
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6430
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6431
					$conf["logs::record"]["content"]=$conf["add"][$nri];
6432
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6433
					$conf["logs::record"]["fileArgu"]=__FILE__;
6434
					#可省略參數:
6435
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6436
					#$conf["rewrite"]="false";
6437
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6438
					#$conf["returnOnly"]="true";
6439
					#參考資料:
6440
					#無.
6441
					#備註:
6442
					#無.
6443
					$record=logs::record($conf["logs::record"]);
6444
					unset($conf["logs::record"]);
6445
 
6446
					}#if end
6447
 
6448
				}#if end
6449
 
6450
			#如果新 RR 的 type 不是 A 且 value 不為 "." 結尾.
6451
			if( $newRR["type"]!=="A" && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
6452
 
6453
				#new RR add dot to value end.
6454
				$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
6455
 
6456
				#如果要debug
6457
				if($conf["debug"]==="true"){
6458
 
6459
					#函式說明:
6460
					#撰寫log
6461
					#回傳結果:
6462
					#$result["status"],狀態,"true"或"false".
6463
					#$result["error"],錯誤訊息陣列.
6464
					#$result["function"],當前函式的名稱.
6465
					#$result["argu"],使用的參數.
6466
					#$result["content"],要寫入log的內容字串.
6467
					#必填參數:
6468
					#$conf["path"],字串,log檔案的路徑與名稱.
6469
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6470
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6471
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
6472
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6473
					$conf["logs::record"]["fileArgu"]=__FILE__;
6474
					#可省略參數:
6475
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6476
					#$conf["rewrite"]="false";
6477
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6478
					#$conf["returnOnly"]="true";
6479
					#參考資料:
6480
					#無.
6481
					#備註:
6482
					#無.
6483
					$record=logs::record($conf["logs::record"]);
6484
					unset($conf["logs::record"]);
6485
 
6486
					#函式說明:
6487
					#撰寫log
6488
					#回傳結果:
6489
					#$result["status"],狀態,"true"或"false".
6490
					#$result["error"],錯誤訊息陣列.
6491
					#$result["function"],當前函式的名稱.
6492
					#$result["argu"],使用的參數.
6493
					#$result["content"],要寫入log的內容字串.
6494
					#必填參數:
6495
					#$conf["path"],字串,log檔案的路徑與名稱.
6496
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6497
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6498
					$conf["logs::record"]["content"]=$conf["add"][$nri];
6499
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6500
					$conf["logs::record"]["fileArgu"]=__FILE__;
6501
					#可省略參數:
6502
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6503
					#$conf["rewrite"]="false";
6504
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6505
					#$conf["returnOnly"]="true";
6506
					#參考資料:
6507
					#無.
6508
					#備註:
6509
					#無.
6510
					$record=logs::record($conf["logs::record"]);
6511
					unset($conf["logs::record"]);
6512
 
6513
					}#if end
6514
 
6515
				}#if end
6516
 
249 liveuser 6517
			#針對 zone file 中既有的每個RR記錄
6518
			foreach($result["content"] as $index => $oldRR){
6519
 
6520
				#如果既有的跟新的RR都為 $ORIGIN
6521
				if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
6522
 
6523
					#取代既有的 RR
6524
					$result["content"][$index]=$newRR;
6525
 
6526
					#換看下一筆newRR
6527
					continue 2;
6528
 
6529
					}#if end
6530
 
6531
				#如果既有的跟新的RR都為 $TTL
6532
				if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
6533
 
6534
					#取代既有的 RR
6535
					$result["content"][$index]=$newRR;
6536
 
6537
					#換看下一筆newRR
6538
					continue 2;
6539
 
6540
					}#if end
6541
 
253 liveuser 6542
				#如果新舊資料都有query資訊
6543
				if( isset($newRR["query"]) && isset($oldRR["query"]) ){
249 liveuser 6544
 
253 liveuser 6545
					#如果跟既有的 query、type、value 有相同
6546
					if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
249 liveuser 6547
 
253 liveuser 6548
						#如果新 RR 有 update time
6549
						if(isset($newRR["update"])){
249 liveuser 6550
 
253 liveuser 6551
							#如果新舊 update time 不相同
6552
							if( $newRR["update"] !== $oldRR["update"] ){
249 liveuser 6553
 
253 liveuser 6554
								#取代既有的 RR
6555
								$result["content"][$index]=$newRR;
6556
 
6557
								#換看下一筆newRR
6558
								continue 2;
6559
 
6560
								}#if end
6561
 
6562
							}#if end
249 liveuser 6563
 
253 liveuser 6564
						#反之既有的 update time 若跟 global TTL 不一樣
6565
						else if( $oldRR["update"] !== $result["defaultTTL"] ){
6566
 
6567
							#更新為 global TTL
6568
							$result["content"][$index]["update"]=$result["defaultTTL"];
6569
 
249 liveuser 6570
							}#if end
253 liveuser 6571
 
6572
						#如果新 RR 有 comment
6573
						if( isset($newRR["comment"]) ){
249 liveuser 6574
 
253 liveuser 6575
							#更新既有 RR 的 comment
6576
							$result["content"][$index]["comment"]=$newRR["comment"];
249 liveuser 6577
 
253 liveuser 6578
							#換看下一筆newRR
6579
							continue 2;
249 liveuser 6580
 
253 liveuser 6581
							}#if end
6582
 
6583
						#反之,如果有既有 comment
6584
						else if(isset($result["content"][$index]["comment"])){
249 liveuser 6585
 
253 liveuser 6586
							#移除既有 comment
6587
							unset($result["content"][$index]["comment"]);
6588
 
6589
							#換看下一筆newRR
6590
							continue 2;
249 liveuser 6591
 
253 liveuser 6592
							}#else end
249 liveuser 6593
 
253 liveuser 6594
						}#if end
294 liveuser 6595
 
6596
					#反之如果跟既有的 query、type有相同,且type 為 "CNAME"
6597
					else if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["type"]==="CNAME"){
6598
 
6599
						#更新既有 RR 的 value
6600
						$result["content"][$index]["value"]=$newRR["value"];
6601
 
6602
						#換看下一筆newRR
6603
						continue 2;
6604
 
6605
						}#if end
6606
 
249 liveuser 6607
					}#if end
253 liveuser 6608
 
249 liveuser 6609
				}#foreach end
6610
 
6611
			#儲存確定要新增的RR
6612
			$result["content"][]=$newRR;
6613
 
6614
			}#foreach end
6615
 
255 liveuser 6616
		#如果要debug
6617
		if($conf["debug"]==="true"){
249 liveuser 6618
 
255 liveuser 6619
			#函式說明:
6620
			#撰寫log
6621
			#回傳結果:
6622
			#$result["status"],狀態,"true"或"false".
6623
			#$result["error"],錯誤訊息陣列.
6624
			#$result["function"],當前函式的名稱.
6625
			#$result["argu"],使用的參數.
6626
			#$result["content"],要寫入log的內容字串.
6627
			#必填參數:
6628
			#$conf["path"],字串,log檔案的路徑與名稱.
6629
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6630
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6631
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
6632
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6633
			$conf["logs::record"]["fileArgu"]=__FILE__;
6634
			#可省略參數:
6635
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6636
			#$conf["rewrite"]="false";
6637
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6638
			#$conf["returnOnly"]="true";
6639
			#參考資料:
6640
			#無.
6641
			#備註:
6642
			#無.
6643
			$record=logs::record($conf["logs::record"]);
6644
			unset($conf["logs::record"]);
249 liveuser 6645
 
255 liveuser 6646
			}#if end
6647
 
6648
		#如果要debug
6649
		if($conf["debug"]==="true"){
6650
 
6651
			#函式說明:
6652
			#撰寫log
6653
			#回傳結果:
6654
			#$result["status"],狀態,"true"或"false".
6655
			#$result["error"],錯誤訊息陣列.
6656
			#$result["function"],當前函式的名稱.
6657
			#$result["argu"],使用的參數.
6658
			#$result["content"],要寫入log的內容字串.
6659
			#必填參數:
6660
			#$conf["path"],字串,log檔案的路徑與名稱.
6661
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6662
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6663
			$conf["logs::record"]["content"]=$result["content"];
6664
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6665
			$conf["logs::record"]["fileArgu"]=__FILE__;
6666
			#可省略參數:
6667
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6668
			#$conf["rewrite"]="false";
6669
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6670
			#$conf["returnOnly"]="true";
6671
			#參考資料:
6672
			#無.
6673
			#備註:
6674
			#無.
6675
			$record=logs::record($conf["logs::record"]);
6676
			unset($conf["logs::record"]);
6677
 
6678
			}#if end
6679
 
249 liveuser 6680
		#初始化要寫入的內容
6681
		$strs2write=array();
6682
 
6683
		#針對每個RR記錄
6684
		foreach($result["content"] as $RR){
6685
 
6686
			#初始化暫存要寫入的行內容
6687
			$str2write="";
6688
 
6689
			#如果是
6690
			if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
6691
 
6692
				#組合變數名稱與數值
6693
				$str2write=$str2write.$RR["type"]."\t".$RR["value"];
6694
 
6695
				}#if end
6696
 
6697
			#反之
6698
			else{
6699
 
6700
				#加上查詢的字句
6701
				$str2write=$str2write.$RR["query"];
6702
 
6703
				#如果該筆RR有指定update time該ZONE具備 global TTL.
6704
				if(isset($RR["update"])){
6705
 
6706
					#如果 該ZONE具備 global TTL.
6707
					if(isset($result["defaultTTL"])){
6708
 
6709
						#如果該筆 RR 的 update time 不等於 global TTL
6710
						if($RR["update"]!==$result["defaultTTL"]){
6711
 
6712
							#加上TTL的字句
6713
							$str2write=$str2write."\t".$RR["update"];
6714
 
6715
							}#if end
6716
 
6717
						}#if end
6718
 
6719
					#反之
6720
					else{
6721
 
6722
						#加上TTL的字句
6723
						$str2write=$str2write."\t".$RR["update"];
6724
 
6725
						}#else end
6726
 
6727
					}#if end
6728
 
253 liveuser 6729
				#反之且該ZONE不具備 global TTL.
6730
				else if(!isset($result["defaultTTL"])){
249 liveuser 6731
 
6732
					#加上global TTL的字句
6733
					$str2write=$str2write."\t".$result["defaultTTL"];
6734
 
253 liveuser 6735
					}#if end
249 liveuser 6736
 
6737
				#加上IN跟TYPE跟value
6738
				$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
6739
 
6740
				}#else end
6741
 
6742
			#如果有註解
6743
			if(isset($RR["comment"])){
6744
 
6745
				#加上comment
6746
				$str2write=$str2write.";".$RR["comment"];
6747
 
6748
				}#if end
6749
 
253 liveuser 6750
			#如果要 debug
6751
			if($conf["debug"]==="true"){
249 liveuser 6752
 
253 liveuser 6753
				#函式說明:
6754
				#撰寫log
6755
				#回傳結果:
6756
				#$result["status"],狀態,"true"或"false".
6757
				#$result["error"],錯誤訊息陣列.
6758
				#$result["function"],當前函式的名稱.
6759
				#$result["argu"],使用的參數.
6760
				#$result["content"],要寫入log的內容字串.
6761
				#必填參數:
6762
				#$conf["path"],字串,log檔案的路徑與名稱.
6763
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6764
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6765
				$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
6766
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6767
				$conf["logs::record"]["fileArgu"]=__FILE__;
6768
				#可省略參數:
6769
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6770
				#$conf["rewrite"]="false";
6771
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6772
				#$conf["returnOnly"]="true";
6773
				#參考資料:
6774
				#無.
6775
				#備註:
6776
				#無.
6777
				$record=logs::record($conf["logs::record"]);
6778
				unset($conf["logs::record"]);
6779
 
6780
				}#if end
6781
 
249 liveuser 6782
			#加上要寫入的元素
6783
			$strs2write[]=$str2write;
6784
 
6785
			}#foreach end
6786
 
6787
		#如果有逐行註解
6788
		if(count($result["comment"])>0){
6789
 
6790
			#加到結尾
6791
			#函式說明:
6792
			#將多個一維陣列串聯起來,key從0開始排序.
6793
			#回傳的結果:
6794
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
6795
			#$result["error"],錯誤訊息陣列.
6796
			#$result["function"],當前執行的函數.
6797
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6798
			#$result["content"],合併好的一維陣列.
6799
			#必填參數
6800
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
6801
			$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
6802
			#可省略參數:
6803
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
6804
			#$conf["allowRepeat"]="true";
6805
			#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
6806
			#$conf["looseDiff"]="false";
6807
			#參考資料:
6808
			#無.
6809
			#備註:
6810
			#無.
6811
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
6812
			unset($conf["arrays::mergeArray"]);
6813
 
6814
			#如果執行異常
6815
			if($mergeArray["status"]==="false"){
6816
 
6817
				#設置錯誤識別
6818
				$result["status"]="false";
6819
 
6820
				#設置錯誤訊息
6821
				$result["error"]=$mergeArray;
6822
 
6823
				#回傳結果
6824
				return $result;
6825
 
6826
				}#if end
6827
 
6828
			#取得合併好的陣列
6829
			$strs2write=$mergeArray["content"];
6830
 
6831
			}#if end
6832
 
253 liveuser 6833
		#如果要 debug
6834
		if($conf["debug"]==="true"){
249 liveuser 6835
 
253 liveuser 6836
			#函式說明:
6837
			#撰寫log
6838
			#回傳結果:
6839
			#$result["status"],狀態,"true"或"false".
6840
			#$result["error"],錯誤訊息陣列.
6841
			#$result["function"],當前函式的名稱.
6842
			#$result["argu"],使用的參數.
6843
			#$result["content"],要寫入log的內容字串.
6844
			#必填參數:
6845
			#$conf["path"],字串,log檔案的路徑與名稱.
6846
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6847
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6848
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
6849
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6850
			$conf["logs::record"]["fileArgu"]=__FILE__;
6851
			#可省略參數:
6852
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6853
			#$conf["rewrite"]="false";
6854
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6855
			#$conf["returnOnly"]="true";
6856
			#參考資料:
6857
			#無.
6858
			#備註:
6859
			#無.
6860
			$record=logs::record($conf["logs::record"]);
6861
			unset($conf["logs::record"]);
6862
 
6863
			}#if end
6864
 
249 liveuser 6865
		#儲存新zone file每行的內容
6866
		$result["newZoneFileContent"]=$strs2write;
6867
 
6868
		#如果要寫入ZONE檔案
6869
		if($conf["writeNow"]==="true"){
6870
 
6871
			#覆寫 ZONE file
6872
			#函式說明:
6873
			#更新檔案的內容.
6874
			#回傳結果:
6875
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6876
			#$result["error"],錯誤訊息.
6877
			#$result["function"],當前執行的函數名稱.
6878
			#$result["content"],更新的資訊.
6879
			#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
6880
			#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
6881
			#必填參數:
6882
			#$conf["fileArgu"],字串,變數__FILE__的內容.
6883
			$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
6884
			#$conf["file"],字串,要更新的檔案位置與名稱.
6885
			$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
6886
			#可省略參數:
6887
			#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
6888
			$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
6889
			#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
6890
			#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
6891
			#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
6892
			#$conf["replaceLike"]="false";
6893
			#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
6894
			#$conf["addToTailWhenNoMatch"]="false";
6895
			#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
6896
			#$conf["addToTailBeforeThat"]="?\>";
6897
			#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
6898
			#$conf["replaceSpecifyLine"]=array();
6899
			#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
6900
			#$conf["outputPath"]="";
6901
			#參考資料:
6902
			#無.
6903
			#備註:
6904
			#無.
6905
			$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
6906
			unset($conf["fileAccess::updateFile"]);
6907
 
6908
			#如果執行異常
6909
			if($updateFile["status"]==="false"){
6910
 
6911
				#設置錯誤識別
6912
				$result["status"]="false";
6913
 
6914
				#設置錯誤訊息
6915
				$result["error"]=$updateFile;
6916
 
6917
				#回傳結果
6918
				return $result;
6919
 
6920
				}#if end
291 liveuser 6921
 
6922
			#修正 zone file 的權限
6923
			#函式說明:
6924
			#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
6925
			#回傳結果:
6926
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6927
			#$result["error"],錯誤訊息.
6928
			#$result["function"],當前執行的函式名稱.
6929
			#$result["cmd"],執行的指令.
6930
			#必填參數:
6931
			#$conf["owner"],字串,要變哪個使用者擁有.
6932
			$conf["cmd::chown"]["owner"]="root";
6933
			#$conf["target"],字串,需要變更擁有者、 群組的目標.
6934
			$conf["cmd::chown"]["target"]=$conf["dnsRecordFile"];
6935
			#可省略參數:
6936
			#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
6937
			$conf["cmd::chown"]["group"]=webUser;
6938
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
6939
			#$conf["recursive"]="true";
6940
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
6941
			#$conf["excludeSelf"]="true";
6942
			#參考資料:
6943
			#無.
6944
			#備註:
6945
			#無.
6946
			$chown=cmd::chown($conf["cmd::chown"]);
6947
			unset($conf["cmd::chown"]);
249 liveuser 6948
 
291 liveuser 6949
			#如果執行異常
6950
			if($chown["status"]==="false"){
6951
 
6952
				#設置錯誤識別
6953
				$result["status"]="false";
6954
 
6955
				#設置錯誤訊息
6956
				$result["error"]=$chown;
6957
 
6958
				#回傳結果
6959
				return $result;
6960
 
6961
				}#if end
6962
 
6963
			#函式說明:
6964
			#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
6965
			#回傳結果:
6966
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6967
			#$result["error"],錯誤訊息.
6968
			#$result["function"],當前執行的函式名稱.
6969
			#$result["cmd"],執行的指令.
6970
			#必填參數:
6971
			#$conf["mode"],字串,要變成什麼權限.
6972
			$conf["cmd::chmod"]["mode"]="774";
6973
			#$conf["target"],字串,需要變更權限的目標.
6974
			$conf["cmd::chmod"]["target"]=$conf["dnsRecordFile"];
6975
			#可省略參數:
6976
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
6977
			#$conf["recursive"]="true";
6978
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
6979
			#$conf["excludeSelf"]="true";
6980
			#參考資料:
6981
			#無.
6982
			#備註:
6983
			#無.
6984
			$chmod=cmd::chmod($conf["cmd::chmod"]);
6985
			unset($conf["cmd::chmod"]);
6986
 
6987
			#如果執行異常
6988
			if($chmod["status"]==="false"){
6989
 
6990
				#設置錯誤識別
6991
				$result["status"]="false";
6992
 
6993
				#設置錯誤訊息
6994
				$result["error"]=$chmod;
6995
 
6996
				#回傳結果
6997
				return $result;
6998
 
6999
				}#if end
7000
 
249 liveuser 7001
			}#if end
7002
 
7003
		#設置執行正常
7004
		$result["status"]="true";
7005
 
7006
		#回傳結果
7007
		return $result;
7008
 
7009
		}#function updateDnsRecordFile end
7010
 
7011
	/*
7012
	#函式說明:
255 liveuser 7013
	#請求驗證已經透過zerossl::createCertificate要求的domain.
249 liveuser 7014
	#回傳結果:
7015
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7016
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7017
	#$result["function"],當前執行的函式名稱.
7018
	#$result["argu"],所使用的參數.
7019
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 7020
	#$result["content"],結果json字串.
249 liveuser 7021
	#必填參數:
7022
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
7023
	$conf["id"]="";
7024
	#可省略參數:
7025
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7026
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7027
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7028
	#$conf["key"]=self::getApiInfo()["apiKey"];
7029
	#參考資料:
255 liveuser 7030
	#https://zerossl.com/documentation/api/verify-domains/
249 liveuser 7031
	#備註:
7032
	#無.
7033
	*/
7034
	public static function verifyDomain(&$conf){
7035
 
7036
		#初始化要回傳的結果
7037
		$result=array();
7038
 
7039
		#設置當其函數名稱
7040
		$result["function"]=__FUNCTION__;
7041
 
7042
		#如果 $conf 不為陣列
7043
		if(gettype($conf)!="array"){
7044
 
7045
			#設置執行失敗
7046
			$result["status"]="false";
7047
 
7048
			#設置執行錯誤訊息
7049
			$result["error"][]="\$conf變數須為陣列形態";
7050
 
7051
			#如果傳入的參數為 null
7052
			if($conf==null){
7053
 
7054
				#設置執行錯誤訊息
7055
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7056
 
7057
				}#if end
7058
 
7059
			#回傳結果
7060
			return $result;
7061
 
7062
			}#if end
7063
 
7064
		#取得參數
7065
		$result["argu"]=$conf;
7066
 
7067
		#檢查參數
7068
		#函式說明:
7069
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7070
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7071
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7072
		#$result["function"],當前執行的函式名稱.
7073
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7074
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7075
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7076
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7077
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7078
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7079
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7080
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7081
		#必填寫的參數:
7082
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7083
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7084
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7085
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
7086
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7087
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7088
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7089
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7090
		#可以省略的參數:
7091
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7092
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7093
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7094
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7095
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7096
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
7097
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7098
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
7099
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 7100
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
249 liveuser 7101
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7102
		#$conf["arrayCountEqualCheck"][]=array();
7103
		#參考資料來源:
7104
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7105
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7106
		unset($conf["variableCheck::checkArguments"]);
7107
 
7108
		#如果檢查失敗
7109
		if($checkArguments["status"]==="false"){
7110
 
7111
			#設置錯誤識別
7112
			$result["status"]="false";
7113
 
7114
			#設置錯誤訊息
7115
			$result["error"]=$checkArguments;
7116
 
7117
			#回傳結果
7118
			return $result;
7119
 
7120
			}#if end
7121
 
7122
		#如果檢查不通過
7123
		if($checkArguments["passed"]==="false"){
7124
 
7125
			#設置錯誤識別
7126
			$result["status"]="false";
7127
 
7128
			#設置錯誤訊息
7129
			$result["error"]=$checkArguments;
7130
 
7131
			#回傳結果
7132
			return $result;
7133
 
7134
			}#if end
7135
 
7136
		#要傳送的 key -> value
7137
		$postArray=array();
7138
 
7139
		#設置要簽署的domain
7140
		$postArray["validation_method"]="CNAME_CSR_HASH";
7141
 
7142
		#設置要傳送的 json
7143
		$postJson=json_encode($postArray);
7144
 
7145
		#函式說明:
7146
		#運行curl cmd
7147
		#回傳結果:
7148
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7149
		#$result["error"],錯誤訊息陣列.
7150
		#$result["function"],當前執行的函式名稱.
7151
		#$result["founded"],識別網址找不找得到.
7152
		#$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"代表程序的資訊.
7153
		#$result["fullContent"],取得回應的完整字串內容.
7154
		#$result["cookie"],cookie檔案的位置與名稱.
7155
		#$result["cmd"],執行的command.
7156
		#$result["argu],使用的參數.
7157
		#必填參數:
7158
		#$conf["url"],字串,目標url.
255 liveuser 7159
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
249 liveuser 7160
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7161
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7162
		#可省略參數:
7163
		#$conf["header"],字串陣列,要傳送的header.
7164
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7165
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7166
		#$conf["allowAnySSLcertificate"]="";
7167
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7168
		#$conf["postVar"]=array();
7169
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7170
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7171
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7172
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7173
		#$conf["agent"],字串,user agent的名稱.
7174
		#$conf["agent"]="";
7175
		#$conf["cookie"],字串,cookie位置與檔案位置.
7176
		#$conf["cookie"]="";
7177
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7178
		#$conf["forceNewCookie"]="";
7179
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7180
		#$conf["inBg"]="true";
7181
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7182
		#$conf["bgInProc"]="false";
7183
		#參考資料:
7184
		#無.
7185
		#備註:
7186
		#無.
7187
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7188
		unset($conf["catchWebContent::curlCmd"]);
7189
 
7190
		#如果異常
7191
		if($curlCmd["status"]==="false"){
7192
 
7193
			#設置錯誤識別
7194
			$result["status"]="false";
7195
 
7196
			#設置錯誤訊息
7197
			$result["error"]=$curlCmd;
7198
 
7199
			#回傳結果
7200
			return $result;
7201
 
7202
			}#if end
7203
 
7204
		#設置curl的詳細資訊
7205
		$result["curl_verbose_info"]=$curlCmd;
7206
 
255 liveuser 7207
		#驗證結果是否為 json
7208
		$json_validate=json_validate($curlCmd["fullContent"]);
7209
 
7210
		#如果回應不是 json
7211
		if(!$json_validate){
249 liveuser 7212
 
255 liveuser 7213
			#設置錯誤識別
7214
			$result["status"]="false";
7215
 
7216
			#設置錯誤訊息
7217
			$result["error"]=$curlCmd;
7218
 
7219
			#回傳結果
7220
			return $result;
7221
 
7222
			}#if end
7223
 
7224
		#設置json string結果
7225
		$result["content"]=$curlCmd["fullContent"];
7226
 
7227
		#解析json
7228
		$jsonRes=json_decode($result["content"]);
7229
 
293 liveuser 7230
		#如果有 success 資訊
7231
		if(isset($jsonRes->success)){
255 liveuser 7232
 
293 liveuser 7233
			#do nothing
7234
 
7235
			}#if end
7236
 
7237
		#反之如果沒有 status
7238
		else if(!isset($jsonRes->status)){
7239
 
255 liveuser 7240
			#設置錯誤識別
7241
			$result["status"]="false";
7242
 
7243
			#設置錯誤訊息
7244
			$result["error"]=$curlCmd;
7245
 
7246
			#回傳結果
7247
			return $result;
7248
 
7249
			}#if end
7250
 
293 liveuser 7251
		#反之有 status 資訊
7252
		else{
255 liveuser 7253
 
293 liveuser 7254
			#如果是 "pending_validation"
7255
			if($jsonRes->status==="pending_validation"){
255 liveuser 7256
 
293 liveuser 7257
				#do nothing
255 liveuser 7258
 
293 liveuser 7259
				}#if end
7260
 
7261
			#反之如果為 "issued"
7262
			else if($jsonRes->status==="issued"){
7263
 
7264
				#do nothing
7265
 
7266
				}#else 
7267
 
7268
			#反之
7269
			else{
7270
 
7271
				#設置錯誤識別
7272
				$result["status"]="false";
255 liveuser 7273
 
293 liveuser 7274
				#設置錯誤訊息
7275
				$result["error"]=$curlCmd;
255 liveuser 7276
 
293 liveuser 7277
				#回傳結果
7278
				return $result;
7279
 
7280
				}#else end
255 liveuser 7281
 
7282
			}#else end
7283
 
7284
		#設置執行正常
7285
		$result["status"]="true";
7286
 
7287
		#回傳結果
7288
		return $result;
7289
 
7290
		}#function verifyDomain end
7291
 
7292
	/*
7293
	#函式說明:
7294
	#取得CSR在zerossl上的狀態
7295
	#回傳結果:
7296
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7297
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7298
	#$result["function"],當前執行的函式名稱.
7299
	#$result["argu"],所使用的參數.
7300
	#$result["curl_verbose_info"],curl執行的詳細資訊.
7301
	#$result["content"],結果json字串.
7302
	#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7303
	#必填參數:
7304
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
7305
	$conf["id"]="";
7306
	#可省略參數:
7307
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7308
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7309
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7310
	#$conf["key"]=self::getApiInfo()["apiKey"];
7311
	#參考資料:
7312
	#https://zerossl.com/documentation/api/get-certificate/
7313
	#備註:
7314
	#無.
7315
	*/
7316
	public static function getCertSta(&$conf){
7317
 
7318
		#初始化要回傳的結果
7319
		$result=array();
7320
 
7321
		#設置當其函數名稱
7322
		$result["function"]=__FUNCTION__;
7323
 
7324
		#如果 $conf 不為陣列
7325
		if(gettype($conf)!="array"){
7326
 
7327
			#設置執行失敗
7328
			$result["status"]="false";
7329
 
7330
			#設置執行錯誤訊息
7331
			$result["error"][]="\$conf變數須為陣列形態";
7332
 
7333
			#如果傳入的參數為 null
7334
			if($conf==null){
7335
 
7336
				#設置執行錯誤訊息
7337
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7338
 
7339
				}#if end
7340
 
7341
			#回傳結果
7342
			return $result;
7343
 
7344
			}#if end
7345
 
7346
		#取得參數
7347
		$result["argu"]=$conf;
291 liveuser 7348
 
7349
		#DEBUG
7350
		#var_dump(__LINE__,self::getApiInfo());exit;
255 liveuser 7351
 
7352
		#檢查參數
7353
		#函式說明:
7354
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7355
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7356
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7357
		#$result["function"],當前執行的函式名稱.
7358
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7359
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7360
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7361
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7362
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7363
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7364
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7365
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7366
		#必填寫的參數:
7367
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7368
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7369
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7370
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
7371
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7372
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7373
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7374
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7375
		#可以省略的參數:
7376
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7377
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7378
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7379
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7380
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7381
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
7382
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7383
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
7384
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7385
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
7386
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7387
		#$conf["arrayCountEqualCheck"][]=array();
7388
		#參考資料來源:
7389
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7390
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7391
		unset($conf["variableCheck::checkArguments"]);
7392
 
7393
		#如果檢查失敗
7394
		if($checkArguments["status"]==="false"){
7395
 
7396
			#設置錯誤識別
7397
			$result["status"]="false";
7398
 
7399
			#設置錯誤訊息
7400
			$result["error"]=$checkArguments;
7401
 
7402
			#回傳結果
7403
			return $result;
7404
 
7405
			}#if end
7406
 
7407
		#如果檢查不通過
7408
		if($checkArguments["passed"]==="false"){
7409
 
7410
			#設置錯誤識別
7411
			$result["status"]="false";
7412
 
7413
			#設置錯誤訊息
7414
			$result["error"]=$checkArguments;
7415
 
7416
			#回傳結果
7417
			return $result;
7418
 
7419
			}#if end
7420
 
7421
		#函式說明:
7422
		#運行curl cmd
7423
		#回傳結果:
7424
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7425
		#$result["error"],錯誤訊息陣列.
7426
		#$result["function"],當前執行的函式名稱.
7427
		#$result["founded"],識別網址找不找得到.
7428
		#$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"代表程序的資訊.
7429
		#$result["fullContent"],取得回應的完整字串內容.
7430
		#$result["cookie"],cookie檔案的位置與名稱.
7431
		#$result["cmd"],執行的command.
7432
		#$result["argu],使用的參數.
7433
		#必填參數:
7434
		#$conf["url"],字串,目標url.
7435
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
7436
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7437
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7438
		#可省略參數:
7439
		#$conf["header"],字串陣列,要傳送的header.
7440
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7441
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7442
		#$conf["allowAnySSLcertificate"]="";
7443
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7444
		#$conf["postVar"]=array();
7445
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7446
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7447
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7448
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7449
		#$conf["agent"],字串,user agent的名稱.
7450
		#$conf["agent"]="";
7451
		#$conf["cookie"],字串,cookie位置與檔案位置.
7452
		#$conf["cookie"]="";
7453
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7454
		#$conf["forceNewCookie"]="";
7455
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7456
		#$conf["inBg"]="true";
7457
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7458
		#$conf["bgInProc"]="false";
7459
		#參考資料:
7460
		#無.
7461
		#備註:
7462
		#無.
7463
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7464
		unset($conf["catchWebContent::curlCmd"]);
7465
 
7466
		#如果異常
7467
		if($curlCmd["status"]==="false"){
7468
 
7469
			#設置錯誤識別
7470
			$result["status"]="false";
7471
 
7472
			#設置錯誤訊息
7473
			$result["error"]=$curlCmd;
7474
 
7475
			#回傳結果
7476
			return $result;
7477
 
7478
			}#if end
7479
 
7480
		#設置curl的詳細資訊
7481
		$result["curl_verbose_info"]=$curlCmd;
7482
 
7483
		#驗證結果是否為 json
7484
		$json_validate=json_validate($curlCmd["fullContent"]);
7485
 
7486
		#如果回應不是 json
7487
		if(!$json_validate){
7488
 
7489
			#設置錯誤識別
7490
			$result["status"]="false";
7491
 
7492
			#設置錯誤訊息
7493
			$result["error"]=$curlCmd;
7494
 
7495
			#回傳結果
7496
			return $result;
7497
 
7498
			}#if end
7499
 
7500
		#設置json string結果
7501
		$result["content"]=$curlCmd["fullContent"];
7502
 
7503
		#解析json
7504
		$jsonRes=json_decode($result["content"]);
7505
 
7506
		#如果沒有 status
7507
		if(!isset($jsonRes->status)){
7508
 
7509
			#設置錯誤識別
7510
			$result["status"]="false";
7511
 
7512
			#設置錯誤訊息
7513
			$result["error"]=$curlCmd;
7514
 
7515
			#回傳結果
7516
			return $result;
7517
 
7518
			}#if end
7519
 
7520
		#取得csr在zerossl上的狀態
7521
		$result["cerStatus"]=$jsonRes->status;
7522
 
7523
		#設置執行正常
7524
		$result["status"]="true";
7525
 
7526
		#回傳結果
7527
		return $result;
7528
 
7529
		}#function getCertSta end
7530
 
7531
	/*
7532
	#函式說明:
7533
	#取得在zerossl上的CSR清單
7534
	#回傳結果:
7535
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7536
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7537
	#$result["function"],當前執行的函式名稱.
7538
	#$result["argu"],所使用的參數.
7539
	#$result["curl_verbose_info"],curl執行的詳細資訊.
7540
	#$result["content"],結果json字串.
7541
	#$result["tCount"],總共的資料筆數.
7542
	#$result["count"],該頁的筆數.
7543
	#$result["page"],當前的頁碼.
7544
	#$result["certs"],陣列,certificates清單,key為certificate的id.
7545
	#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
7546
	#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
7547
	#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
7548
	#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
7549
	#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7550
	#必填參數:
7551
	#無
7552
	#可省略參數:
7553
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7554
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7555
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7556
	#$conf["key"]=self::getApiInfo()["apiKey"];
7557
	#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7558
	#$conf["cerStatus"]="";
309 liveuser 7559
	#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;"multiDomain90Days"多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
255 liveuser 7560
	#$conf["cerType"]="";
7561
	#$conf["search"],字串,透過certificate包含的domain來搜尋.
7562
	#$conf["search"]="";
7563
	#$conf["limit"],字串,一頁要多少筆,預設為100筆.
7564
	#$conf["limit"]="";
7565
	#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
7566
	#$conf["page"]="";
7567
	#參考資料:
7568
	#https://zerossl.com/documentation/api/list-certificates/
7569
	#備註:
7570
	#無.
7571
	*/
7572
	public static function getCertList(&$conf){
7573
 
7574
		#初始化要回傳的結果
7575
		$result=array();
7576
 
7577
		#設置當其函數名稱
7578
		$result["function"]=__FUNCTION__;
7579
 
7580
		#如果 $conf 不為陣列
7581
		if(gettype($conf)!="array"){
7582
 
7583
			#設置執行失敗
7584
			$result["status"]="false";
7585
 
7586
			#設置執行錯誤訊息
7587
			$result["error"][]="\$conf變數須為陣列形態";
7588
 
7589
			#如果傳入的參數為 null
7590
			if($conf==null){
7591
 
7592
				#設置執行錯誤訊息
7593
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7594
 
7595
				}#if end
7596
 
7597
			#回傳結果
7598
			return $result;
7599
 
7600
			}#if end
7601
 
7602
		#取得參數
7603
		$result["argu"]=$conf;
7604
 
7605
		#檢查參數
7606
		#函式說明:
7607
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7608
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7609
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7610
		#$result["function"],當前執行的函式名稱.
7611
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7612
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7613
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7614
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7615
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7616
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7617
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7618
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7619
		#必填寫的參數:
7620
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7621
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7622
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7623
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
7624
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7625
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7626
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7627
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7628
		#可以省略的參數:
7629
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7630
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7631
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7632
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7633
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7634
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
7635
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7636
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
7637
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7638
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
7639
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7640
		#$conf["arrayCountEqualCheck"][]=array();
7641
		#參考資料來源:
7642
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7643
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7644
		unset($conf["variableCheck::checkArguments"]);
7645
 
7646
		#如果檢查失敗
7647
		if($checkArguments["status"]==="false"){
7648
 
7649
			#設置錯誤識別
7650
			$result["status"]="false";
7651
 
7652
			#設置錯誤訊息
7653
			$result["error"]=$checkArguments;
7654
 
7655
			#回傳結果
7656
			return $result;
7657
 
7658
			}#if end
7659
 
7660
		#如果檢查不通過
7661
		if($checkArguments["passed"]==="false"){
7662
 
7663
			#設置錯誤識別
7664
			$result["status"]="false";
7665
 
7666
			#設置錯誤訊息
7667
			$result["error"]=$checkArguments;
7668
 
7669
			#回傳結果
7670
			return $result;
7671
 
7672
			}#if end
7673
 
7674
		#預設網址
291 liveuser 7675
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."?access_key=".$conf["key"];
255 liveuser 7676
 
7677
		#如果有設置 cerStatus
7678
		if(isset($conf["cerStatus"])){
7679
 
7680
			#設置 certificate_status 
291 liveuser 7681
			$url=$url."&certificate_status=".urlencode($conf["cerStatus"]);
255 liveuser 7682
 
7683
			}#if end
7684
 
7685
		#如果有設置 cerType
7686
		if(isset($conf["cerType"])){
7687
 
7688
			#設置 certificate_type
291 liveuser 7689
			$url=$url."&certificate_type=".urlencode($conf["cerType"]);
255 liveuser 7690
 
7691
			}#if end
7692
 
7693
		#如果有設置 search
7694
		if(isset($conf["search"])){
7695
 
7696
			#設置 search
291 liveuser 7697
			$url=$url."&search=".urlencode($conf["search"]);
255 liveuser 7698
 
7699
			}#if end
7700
 
7701
		#如果有設置 limit
7702
		if(isset($conf["limit"])){
7703
 
7704
			#設置 search
291 liveuser 7705
			$url=$url."&limit=".urlencode($conf["limit"]);
255 liveuser 7706
 
7707
			}#if end
7708
 
7709
		#如果有設置 page
7710
		if(isset($conf["page"])){
7711
 
7712
			#設置 search
291 liveuser 7713
			$url=$url."&"."page=".urlencode($conf["page"]);
255 liveuser 7714
 
7715
			}#if end
7716
 
7717
		#函式說明:
7718
		#運行curl cmd
7719
		#回傳結果:
7720
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7721
		#$result["error"],錯誤訊息陣列.
7722
		#$result["function"],當前執行的函式名稱.
7723
		#$result["founded"],識別網址找不找得到.
7724
		#$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"代表程序的資訊.
7725
		#$result["fullContent"],取得回應的完整字串內容.
7726
		#$result["cookie"],cookie檔案的位置與名稱.
7727
		#$result["cmd"],執行的command.
7728
		#$result["argu],使用的參數.
7729
		#必填參數:
7730
		#$conf["url"],字串,目標url.
7731
		$conf["catchWebContent::curlCmd"]["url"]=$url;
7732
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7733
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7734
		#可省略參數:
7735
		#$conf["header"],字串陣列,要傳送的header.
7736
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7737
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7738
		#$conf["allowAnySSLcertificate"]="";
7739
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7740
		#$conf["postVar"]=array();
7741
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7742
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7743
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7744
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7745
		#$conf["agent"],字串,user agent的名稱.
7746
		#$conf["agent"]="";
7747
		#$conf["cookie"],字串,cookie位置與檔案位置.
7748
		#$conf["cookie"]="";
7749
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7750
		#$conf["forceNewCookie"]="";
7751
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7752
		#$conf["inBg"]="true";
7753
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7754
		#$conf["bgInProc"]="false";
7755
		#參考資料:
7756
		#無.
7757
		#備註:
7758
		#無.
7759
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7760
		unset($conf["catchWebContent::curlCmd"]);
7761
 
7762
		#如果異常
7763
		if($curlCmd["status"]==="false"){
7764
 
7765
			#設置錯誤識別
7766
			$result["status"]="false";
7767
 
7768
			#設置錯誤訊息
7769
			$result["error"]=$curlCmd;
7770
 
7771
			#回傳結果
7772
			return $result;
7773
 
7774
			}#if end
7775
 
7776
		#設置curl的詳細資訊
7777
		$result["curl_verbose_info"]=$curlCmd;
7778
 
7779
		#驗證結果是否為 json
7780
		$json_validate=json_validate($curlCmd["fullContent"]);
7781
 
7782
		#如果回應不是 json
7783
		if(!$json_validate){
7784
 
7785
			#設置錯誤識別
7786
			$result["status"]="false";
7787
 
7788
			#設置錯誤訊息
7789
			$result["error"]=$curlCmd;
7790
 
7791
			#回傳結果
7792
			return $result;
7793
 
7794
			}#if end
7795
 
7796
		#設置json string結果
7797
		$result["content"]=$curlCmd["fullContent"];
7798
 
7799
		/* json response 範例
7800
		{
7801
			"total_count": 11,
7802
			"result_count": 10,
7803
			"page": 1,
7804
			"limit": 10,
7805
			"acmeUsageLevel": "LOW",
7806
			"isAcmeLocked": false,
7807
			"results": 
7808
			[
7809
				{
7810
					"id": "a856a39a1c3ad0s8asa606g37667d221",
7811
					"type": "1",
7812
					"common_name": "domain.com",
7813
					"additional_domains": "www.domain.com",
7814
					"created": "2020-04-29 09:04:19",
7815
					"expires": "2020-07-28 00:00:00",
7816
					"status": "draft",
7817
					"validation_type": null,
7818
					"validation_emails": null,
7819
					"replacement_for": "",
7820
					"fingerprint_sha1": null,
7821
					"brand_validation": null,
7822
					"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
7823
					"validation":
7824
					{
7825
						"email_validation":
7826
						{
7827
							"domain.com":
7828
							[
7829
								"admin@domain.com",
7830
								"administrator@domain.com",
7831
								"hostmaster@domain.com",
7832
								"postmaster@domain.com",
7833
								"webmaster@domain.com"
7834
							]
7835
						},
7836
						"other_methods": 
7837
						{
7838
							"domain.com":
7839
							{
7840
								"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
7841
								"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
7842
								"file_validation_content":
7843
								[
7844
									"2B449B722B449B729394793947",
7845
									"comodoca.com",
7846
									"4bad7360c7076ba"
7847
								],
7848
								"cname_validation_p1": "2B449B7293947.domain.com",
7849
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
7850
							},
7851
							"www.domain.com":
7852
							{
7853
								"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
7854
								"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",   
7855
								"file_validation_content":
7856
								[
7857
									"2B449B722B449B729394793947",
7858
									"comodoca.com",
7859
									"4bad7360c7076ba"
7860
								],
7861
								"cname_validation_p1": "2B449B7293947.www.domain.com",
7862
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
7863
							}
7864
						}
7865
					}
7866
				},
7867
				{
7868
					...
7869
				}
7870
			]
7871
		}
249 liveuser 7872
		*/
7873
 
255 liveuser 7874
		#解析json
7875
		$jsonRes=json_decode($result["content"]);
7876
 
7877
		#總共的資料筆數
7878
		$result["tCount"]=$jsonRes->total_count;
7879
 
7880
		#取得該頁的筆數
7881
		$result["count"]=$jsonRes->result_count;
7882
 
7883
		#取得certificate清單
291 liveuser 7884
		$certs=$jsonRes->results;
255 liveuser 7885
 
7886
		#針對每個certificate
7887
		foreach($certs as $index => $cert){
7888
 
7889
			#初始化暫存的陣列
7890
			$tmpA=array();
7891
 
7892
			#儲存 cert id
7893
			#$tmpA["id"]=$cert->id;
7894
 
7895
			#儲存 主要包含的 domain name
7896
			$tmpA["cname"]=$cert->common_name;
7897
 
7898
			#儲存額外包含的 domain name
7899
			$tmpA["anames"]=$cert->additional_domains;
7900
 
7901
			#最後有效年月日,格式為"2020-07-28 00:00:00".
7902
			$tmpA["expiresYMD"]=$cert->expires;
7903
 
7904
			#產生對於當前系統時間的差距(秒數)
7905
			#函式說明:
7906
			#計算時間點距離1970/01/01多少秒,亦即unixtime.
7907
			#回傳結果:
7908
			#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
7909
			#$result["error"],錯誤訊息陣列.
7910
			#$result["content"],時間點距離1970/01/01的多少秒.
7911
			#$result["argu"],使用的參數.
7912
			#$result["unixtime"],執行本函式時的unixtime.
7913
			#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
7914
			#必填參數:
7915
			#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
7916
			$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
7917
			#可省略參數:
7918
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
7919
			#$conf["UTC"]="false";
7920
			#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
7921
			$conf["time::caculateTimeAmount"]["replace0"]="false";
7922
			#參考資料:
7923
			#無.
7924
			#備註:
7925
			#無.
7926
			$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
7927
			unset($conf["time::caculateTimeAmount"]);
7928
 
7929
			#如果執行異常
291 liveuser 7930
			if($caculateTimeAmount["status"]==="false"){
255 liveuser 7931
 
7932
				#設置錯誤識別
7933
				$result["status"]="false";
7934
 
7935
				#設置錯誤訊息
7936
				$result["error"]=$caculateTimeAmount;
7937
 
7938
				#回傳結果
7939
				return $result;
7940
 
7941
				}#if end
7942
 
7943
			#儲存還要多少秒要過期
291 liveuser 7944
			$tmpA["expiresIn"]=$caculateTimeAmount["content"]-time();
255 liveuser 7945
 
7946
			#憑證的狀態
7947
			$tmpA["status"]=$cert->status;
7948
 
291 liveuser 7949
			#儲存要回傳的 certs 清單,key為cert的id.
7950
			$result["certs"][$cert->id]=$tmpA;
255 liveuser 7951
 
7952
			}#foreach end
7953
 
7954
		#設置執行正常
7955
		$result["status"]="true";
7956
 
7957
		#回傳結果
7958
		return $result;
7959
 
7960
		}#function getCertList end
7961
 
7962
	/*
7963
	#函式說明:
7964
	#下載certificate.
7965
	#回傳結果:
7966
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7967
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7968
	#$result["function"],當前執行的函式名稱.
7969
	#$result["argu"],所使用的參數.
7970
	#$result["curl_verbose_info"],curl執行的詳細資訊.
7971
	#$result["content"],結果json字串.
7972
	#$result["certificate.crt"],字串,certificate.crt的內容.
7973
	#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
7974
	#必填參數:
7975
	#無.
7976
	#可省略參數:
7977
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7978
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7979
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7980
	#$conf["key"]=self::getApiInfo()["apiKey"];
7981
	#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
7982
	#$conf["id"]="";
7983
	#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
7984
	#$conf["cname"]="";
7985
	#參考資料:
7986
	#https://zerossl.com/documentation/api/download-certificate-inline/
7987
	#備註:
7988
	#無.
7989
	*/
7990
	public static function getCert(&$conf){
7991
 
7992
		#初始化要回傳的結果
7993
		$result=array();
7994
 
7995
		#設置當其函數名稱
7996
		$result["function"]=__FUNCTION__;
7997
 
7998
		#如果 $conf 不為陣列
7999
		if(gettype($conf)!="array"){
8000
 
8001
			#設置執行失敗
8002
			$result["status"]="false";
8003
 
8004
			#設置執行錯誤訊息
8005
			$result["error"][]="\$conf變數須為陣列形態";
8006
 
8007
			#如果傳入的參數為 null
8008
			if($conf==null){
8009
 
8010
				#設置執行錯誤訊息
8011
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8012
 
8013
				}#if end
8014
 
8015
			#回傳結果
8016
			return $result;
8017
 
8018
			}#if end
8019
 
8020
		#取得參數
8021
		$result["argu"]=$conf;
8022
 
8023
		#檢查參數
8024
		#函式說明:
8025
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8026
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8027
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8028
		#$result["function"],當前執行的函式名稱.
8029
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8030
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8031
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8032
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8033
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8034
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8035
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8036
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8037
		#必填寫的參數:
8038
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8039
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8040
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8041
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
8042
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
8043
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
8044
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8045
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8046
		#可以省略的參數:
8047
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8048
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8049
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
8050
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8051
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8052
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
8053
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8054
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
8055
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8056
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
8057
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8058
		#$conf["arrayCountEqualCheck"][]=array();
8059
		#參考資料來源:
8060
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8061
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8062
		unset($conf["variableCheck::checkArguments"]);
8063
 
8064
		#如果檢查失敗
8065
		if($checkArguments["status"]==="false"){
8066
 
8067
			#設置錯誤識別
8068
			$result["status"]="false";
8069
 
8070
			#設置錯誤訊息
8071
			$result["error"]=$checkArguments;
8072
 
8073
			#回傳結果
8074
			return $result;
8075
 
8076
			}#if end
8077
 
8078
		#如果檢查不通過
8079
		if($checkArguments["passed"]==="false"){
8080
 
8081
			#設置錯誤識別
8082
			$result["status"]="false";
8083
 
8084
			#設置錯誤訊息
8085
			$result["error"]=$checkArguments;
8086
 
8087
			#回傳結果
8088
			return $result;
8089
 
8090
			}#if end
8091
 
8092
		#如果有設置 id
8093
		if(isset($conf["id"])){
8094
 
8095
			#設置 id
8096
			$id=$conf["id"];
8097
 
8098
			}#if end
8099
 
8100
		#反之如果有設置 cname
8101
		else if(isset($conf["cname"])){
8102
 
8103
			#函式說明:
8104
			#取得在zerossl上的CSR清單
8105
			#回傳結果:
8106
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8107
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
8108
			#$result["function"],當前執行的函式名稱.
8109
			#$result["argu"],所使用的參數.
8110
			#$result["curl_verbose_info"],curl執行的詳細資訊.
8111
			#$result["content"],結果json字串.
8112
			#$result["tCound"],總共的資料筆數.
8113
			#$result["count"],該頁的筆數.
8114
			#$result["page"],當前的頁碼.
8115
			#$result["certs"],陣列,certificates清單,key為certificate的id.
8116
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
8117
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
8118
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
8119
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
8120
			#必填參數:
8121
			#無
8122
			#可省略參數:
8123
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8124
			#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8125
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8126
			#$conf["key"]=self::getApiInfo()["apiKey"];
8127
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
8128
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
8129
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
8130
			#$conf["cerType"]="";
8131
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
8132
			$conf["zerossl::getCertList"]["search"]=$conf["cname"];
8133
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
8134
			#$conf["limit"]="";
8135
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
8136
			#$conf["page"]="";
8137
			#參考資料:
8138
			#https://zerossl.com/documentation/api/get-certificate/
8139
			#備註:
8140
			#無.
8141
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
8142
			unset($conf["zerossl::getCertList"]);
8143
 
8144
			#如果檢查失敗
8145
			if($getCertList["status"]==="false"){
8146
 
8147
				#設置錯誤識別
8148
				$result["status"]="false";
8149
 
8150
				#設置錯誤訊息
8151
				$result["error"]=$getCertList;
8152
 
8153
				#回傳結果
8154
				return $result;
8155
 
8156
				}#if end
8157
 
8158
			#如果資料筆數大於0
8159
			if($getCertList["count"]>0){
8160
 
8161
				#取得第一筆
8162
				foreach($getCertList["certs"] as $cerId => $detail){
8163
 
8164
					#取得cettificate id
8165
					$id=$cerId;
8166
 
8167
					}#foreach end
8168
 
8169
				}#if end
8170
 
8171
			}#if end
8172
 
8173
		#預設網址
8174
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
8175
 
8176
		#函式說明:
8177
		#運行curl cmd
8178
		#回傳結果:
8179
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8180
		#$result["error"],錯誤訊息陣列.
8181
		#$result["function"],當前執行的函式名稱.
8182
		#$result["founded"],識別網址找不找得到.
8183
		#$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"代表程序的資訊.
8184
		#$result["fullContent"],取得回應的完整字串內容.
8185
		#$result["cookie"],cookie檔案的位置與名稱.
8186
		#$result["cmd"],執行的command.
8187
		#$result["argu],使用的參數.
8188
		#必填參數:
8189
		#$conf["url"],字串,目標url.
8190
		$conf["catchWebContent::curlCmd"]["url"]=$url;
8191
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8192
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
8193
		#可省略參數:
8194
		#$conf["header"],字串陣列,要傳送的header.
8195
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
8196
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
8197
		#$conf["allowAnySSLcertificate"]="";
8198
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
8199
		#$conf["postVar"]=array();
8200
		#$conf["rawPost"]="字串",要傳送的raw post內容.
8201
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
8202
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
8203
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
8204
		#$conf["agent"],字串,user agent的名稱.
8205
		#$conf["agent"]="";
8206
		#$conf["cookie"],字串,cookie位置與檔案位置.
8207
		#$conf["cookie"]="";
8208
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
8209
		#$conf["forceNewCookie"]="";
8210
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
8211
		#$conf["inBg"]="true";
8212
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
8213
		#$conf["bgInProc"]="false";
8214
		#參考資料:
8215
		#無.
8216
		#備註:
8217
		#無.
8218
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
8219
		unset($conf["catchWebContent::curlCmd"]);
8220
 
8221
		#如果異常
8222
		if($curlCmd["status"]==="false"){
8223
 
8224
			#設置錯誤識別
8225
			$result["status"]="false";
8226
 
8227
			#設置錯誤訊息
8228
			$result["error"]=$curlCmd;
8229
 
8230
			#回傳結果
8231
			return $result;
8232
 
8233
			}#if end
8234
 
8235
		#設置curl的詳細資訊
8236
		$result["curl_verbose_info"]=$curlCmd;
8237
 
249 liveuser 8238
		#驗證結果是否為 json
8239
		$json_validate=json_validate($curlCmd["fullContent"]);
8240
 
8241
		#如果回應不是 json
8242
		if(!$json_validate){
8243
 
8244
			#設置錯誤識別
8245
			$result["status"]="false";
8246
 
8247
			#設置錯誤訊息
8248
			$result["error"]=$curlCmd;
8249
 
8250
			#回傳結果
8251
			return $result;
8252
 
8253
			}#if end
8254
 
8255
		#設置json string結果
8256
		$result["content"]=$curlCmd["fullContent"];
255 liveuser 8257
 
8258
		#取得 json
8259
		$json=json_decode($curlCmd["fullContent"]);
8260
 
291 liveuser 8261
		#儲存成變數以便透過object呼叫
8262
		$c_crt="certificate.crt";
8263
 
8264
		#儲存成變數以便透過object呼叫
8265
		$ca_crt="ca_bundle.crt";
8266
 
294 liveuser 8267
		#如果沒有該有的 certificate.crt 跟 ca_bundle.crt 物件
8268
		if(!isset($json->$c_crt) || !isset($json->$ca_crt)){
8269
 
8270
			#設置錯誤識別
8271
			$result["status"]="false";
8272
 
8273
			#設置錯誤訊息
8274
			$result["error"]=$json;
8275
 
8276
			#回傳結果
8277
			return $result;
8278
 
8279
			}#if end
8280
 
255 liveuser 8281
		#取得certificate.crt的內容
291 liveuser 8282
		$result["certificate.crt"]=$json->$c_crt;
255 liveuser 8283
 
8284
		#取得ca_bundle.crt的內容
291 liveuser 8285
		$result["ca_bundle.crt"]=$json->$ca_crt;
255 liveuser 8286
 
8287
		#設置執行正常
8288
		$result["status"]="true";
8289
 
8290
		#回傳結果
8291
		return $result;
8292
 
8293
		}#function getCert end
8294
 
8295
	/*
8296
	#函式說明:
8297
	#請求廢除 issued zerossl certificate.
8298
	#回傳結果:
8299
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8300
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
8301
	#$result["function"],當前執行的函式名稱.
8302
	#$result["argu"],所使用的參數.
8303
	#$result["curl_verbose_info"],curl執行的詳細資訊.
8304
	#$result["content"],結果json字串.
341 liveuser 8305
	#$result["busy"],若content結果含有busy屬性,且為1,則為"true";反之為"false".
255 liveuser 8306
	#必填參數:
8307
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
8308
	$conf["id"]="";
8309
	#可省略參數:
8310
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8311
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8312
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8313
	#$conf["key"]=self::getApiInfo()["apiKey"];
8314
	#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
8315
	#$conf["reason"]="";
8316
	#參考資料:
8317
	#https://zerossl.com/documentation/api/revoke-certificate/
8318
	#備註:
338 liveuser 8319
	#跟api頁面的描述不同,access_key參數實際上要用get方式傳遞.
341 liveuser 8320
	#跟api頁面的描述不同,api point忙碌中,無法回應時,回應會為空.
255 liveuser 8321
	*/
8322
	public static function revokeCert(&$conf){
8323
 
8324
		#初始化要回傳的結果
8325
		$result=array();
249 liveuser 8326
 
255 liveuser 8327
		#設置當其函數名稱
8328
		$result["function"]=__FUNCTION__;
8329
 
8330
		#如果 $conf 不為陣列
8331
		if(gettype($conf)!="array"){
8332
 
8333
			#設置執行失敗
8334
			$result["status"]="false";
8335
 
8336
			#設置執行錯誤訊息
8337
			$result["error"][]="\$conf變數須為陣列形態";
8338
 
8339
			#如果傳入的參數為 null
8340
			if($conf==null){
8341
 
8342
				#設置執行錯誤訊息
8343
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8344
 
8345
				}#if end
8346
 
8347
			#回傳結果
8348
			return $result;
8349
 
8350
			}#if end
8351
 
8352
		#取得參數
8353
		$result["argu"]=$conf;
8354
 
8355
		#檢查參數
8356
		#函式說明:
8357
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8358
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8359
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8360
		#$result["function"],當前執行的函式名稱.
8361
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8362
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8363
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8364
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8365
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8366
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8367
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8368
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8369
		#必填寫的參數:
8370
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8371
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8372
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8373
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
8374
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
8375
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
8376
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8377
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8378
		#可以省略的參數:
8379
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8380
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8381
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
8382
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8383
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8384
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
8385
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
334 liveuser 8386
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
255 liveuser 8387
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8388
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
8389
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8390
		#$conf["arrayCountEqualCheck"][]=array();
8391
		#參考資料來源:
8392
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8393
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8394
		unset($conf["variableCheck::checkArguments"]);
8395
 
8396
		#如果檢查失敗
8397
		if($checkArguments["status"]==="false"){
8398
 
8399
			#設置錯誤識別
8400
			$result["status"]="false";
8401
 
8402
			#設置錯誤訊息
8403
			$result["error"]=$checkArguments;
8404
 
8405
			#回傳結果
8406
			return $result;
8407
 
8408
			}#if end
8409
 
8410
		#如果檢查不通過
8411
		if($checkArguments["passed"]==="false"){
8412
 
8413
			#設置錯誤識別
8414
			$result["status"]="false";
8415
 
8416
			#設置錯誤訊息
8417
			$result["error"]=$checkArguments;
8418
 
8419
			#回傳結果
8420
			return $result;
8421
 
8422
			}#if end
8423
 
338 liveuser 8424
		#url to call,含api key,跟 api 頁面不一致.
8425
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
255 liveuser 8426
 
337 liveuser 8427
		#初始化要post的變數陣列
8428
		$postVar=array();
8429
 
338 liveuser 8430
		#設置  api key,跟 api 頁面不一致.
8431
		#$postVar["access_key"]=$conf["key"];
337 liveuser 8432
 
255 liveuser 8433
		#如果有設置 reason
8434
		if(isset($conf["reason"])){
8435
 
8436
			#設置reason
337 liveuser 8437
			$postVar["reason"]=$conf["reason"];
255 liveuser 8438
 
8439
			}#if end
337 liveuser 8440
 
255 liveuser 8441
		#函式說明:
8442
		#運行curl cmd
8443
		#回傳結果:
8444
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8445
		#$result["error"],錯誤訊息陣列.
8446
		#$result["function"],當前執行的函式名稱.
8447
		#$result["founded"],識別網址找不找得到.
8448
		#$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"代表程序的資訊.
8449
		#$result["fullContent"],取得回應的完整字串內容.
8450
		#$result["cookie"],cookie檔案的位置與名稱.
8451
		#$result["cmd"],執行的command.
8452
		#$result["argu],使用的參數.
8453
		#必填參數:
8454
		#$conf["url"],字串,目標url.
8455
		$conf["catchWebContent::curlCmd"]["url"]=$url;
8456
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8457
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
8458
		#可省略參數:
8459
		#$conf["header"],字串陣列,要傳送的header.
338 liveuser 8460
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
255 liveuser 8461
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
8462
		#$conf["allowAnySSLcertificate"]="";
338 liveuser 8463
 
8464
		#如果有資料
8465
		if(!empty($postVar)){
8466
 
8467
			#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
8468
			$conf["catchWebContent::curlCmd"]["postVar"]=$postVar;
8469
 
8470
			}#if end
8471
 
255 liveuser 8472
		#$conf["rawPost"]="字串",要傳送的raw post內容.
8473
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
8474
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
338 liveuser 8475
		$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
255 liveuser 8476
		#$conf["agent"],字串,user agent的名稱.
8477
		#$conf["agent"]="";
8478
		#$conf["cookie"],字串,cookie位置與檔案位置.
8479
		#$conf["cookie"]="";
8480
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
8481
		#$conf["forceNewCookie"]="";
8482
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
8483
		#$conf["inBg"]="true";
8484
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
8485
		#$conf["bgInProc"]="false";
8486
		#參考資料:
8487
		#無.
8488
		#備註:
8489
		#無.
8490
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
8491
		unset($conf["catchWebContent::curlCmd"]);
8492
 
8493
		#如果異常
8494
		if($curlCmd["status"]==="false"){
8495
 
8496
			#設置錯誤識別
8497
			$result["status"]="false";
8498
 
8499
			#設置錯誤訊息
8500
			$result["error"]=$curlCmd;
8501
 
8502
			#回傳結果
8503
			return $result;
8504
 
8505
			}#if end
8506
 
8507
		#設置curl的詳細資訊
8508
		$result["curl_verbose_info"]=$curlCmd;
8509
 
341 liveuser 8510
		#如果 server 的回應為空
8511
		if(empty($curlCmd["fullContent"])){
8512
 
8513
			#初始化json回應
8514
			$jsonRes=array();
8515
 
8516
			#設置不成功
8517
			$jsonRes["success"]=0;
8518
 
8519
			#設置server忙碌中,贊述無法處理要求.
8520
			$jsonRes["busy"]=1;
8521
 
8522
			#設置json結果
8523
			$curlCmd["fullContent"]=json_encode($jsonRes);
8524
 
8525
			}#if end
8526
 
255 liveuser 8527
		#驗證結果是否為 json
8528
		$json_validate=json_validate($curlCmd["fullContent"]);
8529
 
8530
		#如果回應不是 json
8531
		if(!$json_validate){
8532
 
8533
			#設置錯誤識別
8534
			$result["status"]="false";
8535
 
8536
			#設置錯誤訊息
8537
			$result["error"]=$curlCmd;
8538
 
8539
			#回傳結果
8540
			return $result;
8541
 
8542
			}#if end
341 liveuser 8543
 
255 liveuser 8544
		#設置json string結果
8545
		$result["content"]=$curlCmd["fullContent"];
8546
 
249 liveuser 8547
		#解析json
8548
		$jsonRes=json_decode($result["content"]);
8549
 
255 liveuser 8550
		#如果沒有要有的attr
8551
		if(!isset($jsonRes->success)){
8552
 
8553
			#設置錯誤識別
8554
			$result["status"]="false";
8555
 
8556
			#設置錯誤訊息
8557
			$result["error"]=$curlCmd;
8558
 
8559
			#回傳結果
8560
			return $result;
8561
 
8562
			}#if end
341 liveuser 8563
 
255 liveuser 8564
		#如果 success 不等於 1
8565
		if($jsonRes->success!==1){
8566
 
341 liveuser 8567
			#如果有 busy 屬性
8568
			if(isset($jsonRes->busy)){
8569
 
8570
				#如果busy為1
8571
				if($jsonRes->busy===1){
8572
 
8573
					#設置sever忙碌中,無法回應.
8574
					$result["busy"]="true";
8575
 
8576
					}#if end
8577
 
8578
				}#if end
8579
 
255 liveuser 8580
			#設置錯誤識別
8581
			$result["status"]="false";
8582
 
8583
			#設置錯誤訊息
8584
			$result["error"]=$curlCmd;
8585
 
8586
			#回傳結果
8587
			return $result;
8588
 
8589
			}#if end
8590
 
341 liveuser 8591
		#如果回應結果不含busy元素
8592
		if(!isset($result["busy"])){
8593
 
8594
			#設置其為"false",代表server沒有忙碌中,無法回應.
8595
			$result["busy"]="false";
8596
 
8597
			}#else end
8598
 
249 liveuser 8599
		#設置執行正常
8600
		$result["status"]="true";
8601
 
8602
		#回傳結果
8603
		return $result;
8604
 
255 liveuser 8605
		}#function revokeCert end
8606
 
8607
	/*
8608
	#函式說明:
8609
	#請求取消 draft or unvalidated zerossl certificate.
8610
	#回傳結果:
8611
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8612
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
8613
	#$result["function"],當前執行的函式名稱.
8614
	#$result["argu"],所使用的參數.
8615
	#$result["curl_verbose_info"],curl執行的詳細資訊.
8616
	#$result["content"],結果json字串.
8617
	#必填參數:
8618
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
8619
	$conf["id"]="";
8620
	#可省略參數:
8621
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8622
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8623
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8624
	#$conf["key"]=self::getApiInfo()["apiKey"];
8625
	#參考資料:
8626
	#https://zerossl.com/documentation/api/revoke-certificate/
8627
	#備註:
8628
	#無.
8629
	*/
8630
	public static function cancelCert(&$conf){
8631
 
8632
		#初始化要回傳的結果
8633
		$result=array();
249 liveuser 8634
 
255 liveuser 8635
		#設置當其函數名稱
8636
		$result["function"]=__FUNCTION__;
8637
 
8638
		#如果 $conf 不為陣列
8639
		if(gettype($conf)!="array"){
8640
 
8641
			#設置執行失敗
8642
			$result["status"]="false";
8643
 
8644
			#設置執行錯誤訊息
8645
			$result["error"][]="\$conf變數須為陣列形態";
8646
 
8647
			#如果傳入的參數為 null
8648
			if($conf==null){
8649
 
8650
				#設置執行錯誤訊息
8651
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8652
 
8653
				}#if end
8654
 
8655
			#回傳結果
8656
			return $result;
8657
 
8658
			}#if end
8659
 
8660
		#取得參數
8661
		$result["argu"]=$conf;
8662
 
8663
		#檢查參數
8664
		#函式說明:
8665
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8666
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8667
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8668
		#$result["function"],當前執行的函式名稱.
8669
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8670
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8671
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8672
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8673
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8674
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8675
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8676
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8677
		#必填寫的參數:
8678
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8679
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8680
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8681
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
8682
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
8683
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
8684
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8685
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8686
		#可以省略的參數:
8687
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8688
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8689
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
8690
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8691
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8692
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
8693
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8694
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
8695
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8696
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
8697
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8698
		#$conf["arrayCountEqualCheck"][]=array();
8699
		#參考資料來源:
8700
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8701
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8702
		unset($conf["variableCheck::checkArguments"]);
8703
 
8704
		#如果檢查失敗
8705
		if($checkArguments["status"]==="false"){
8706
 
8707
			#設置錯誤識別
8708
			$result["status"]="false";
8709
 
8710
			#設置錯誤訊息
8711
			$result["error"]=$checkArguments;
8712
 
8713
			#回傳結果
8714
			return $result;
8715
 
8716
			}#if end
8717
 
8718
		#如果檢查不通過
8719
		if($checkArguments["passed"]==="false"){
8720
 
8721
			#設置錯誤識別
8722
			$result["status"]="false";
8723
 
8724
			#設置錯誤訊息
8725
			$result["error"]=$checkArguments;
8726
 
8727
			#回傳結果
8728
			return $result;
8729
 
8730
			}#if end
8731
 
8732
		#url to call
8733
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
8734
 
8735
		#函式說明:
8736
		#運行curl cmd
8737
		#回傳結果:
8738
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8739
		#$result["error"],錯誤訊息陣列.
8740
		#$result["function"],當前執行的函式名稱.
8741
		#$result["founded"],識別網址找不找得到.
8742
		#$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"代表程序的資訊.
8743
		#$result["fullContent"],取得回應的完整字串內容.
8744
		#$result["cookie"],cookie檔案的位置與名稱.
8745
		#$result["cmd"],執行的command.
8746
		#$result["argu],使用的參數.
8747
		#必填參數:
8748
		#$conf["url"],字串,目標url.
8749
		$conf["catchWebContent::curlCmd"]["url"]=$url;
8750
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8751
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
8752
		#可省略參數:
8753
		#$conf["header"],字串陣列,要傳送的header.
8754
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
8755
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
8756
		#$conf["allowAnySSLcertificate"]="";
8757
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
8758
		#$conf["postVar"]=array();
8759
		#$conf["rawPost"]="字串",要傳送的raw post內容.
8760
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
8761
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
8762
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
8763
		#$conf["agent"],字串,user agent的名稱.
8764
		#$conf["agent"]="";
8765
		#$conf["cookie"],字串,cookie位置與檔案位置.
8766
		#$conf["cookie"]="";
8767
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
8768
		#$conf["forceNewCookie"]="";
8769
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
8770
		#$conf["inBg"]="true";
8771
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
8772
		#$conf["bgInProc"]="false";
8773
		#參考資料:
8774
		#無.
8775
		#備註:
8776
		#無.
8777
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
8778
		unset($conf["catchWebContent::curlCmd"]);
8779
 
8780
		#如果異常
8781
		if($curlCmd["status"]==="false"){
8782
 
8783
			#設置錯誤識別
8784
			$result["status"]="false";
8785
 
8786
			#設置錯誤訊息
8787
			$result["error"]=$curlCmd;
8788
 
8789
			#回傳結果
8790
			return $result;
8791
 
8792
			}#if end
8793
 
8794
		#設置curl的詳細資訊
8795
		$result["curl_verbose_info"]=$curlCmd;
8796
 
8797
		#驗證結果是否為 json
8798
		$json_validate=json_validate($curlCmd["fullContent"]);
8799
 
8800
		#如果回應不是 json
8801
		if(!$json_validate){
8802
 
8803
			#設置錯誤識別
8804
			$result["status"]="false";
8805
 
8806
			#設置錯誤訊息
8807
			$result["error"]=$curlCmd;
8808
 
8809
			#回傳結果
8810
			return $result;
8811
 
8812
			}#if end
8813
 
8814
		#設置json string結果
8815
		$result["content"]=$curlCmd["fullContent"];
8816
 
8817
		#解析json
8818
		$jsonRes=json_decode($result["content"]);
8819
 
8820
		#如果沒有要有的attr
8821
		if(!isset($jsonRes->success)){
8822
 
8823
			#設置錯誤識別
8824
			$result["status"]="false";
8825
 
8826
			#設置錯誤訊息
8827
			$result["error"]=$curlCmd;
8828
 
8829
			#回傳結果
8830
			return $result;
8831
 
8832
			}#if end
8833
 
8834
		#如果 success 不等於 1
8835
		if($jsonRes->success!==1){
8836
 
8837
			#設置錯誤識別
8838
			$result["status"]="false";
8839
 
8840
			#設置錯誤訊息
8841
			$result["error"]=$curlCmd;
8842
 
8843
			#回傳結果
8844
			return $result;
8845
 
8846
			}#if end
8847
 
8848
		#設置執行正常
8849
		$result["status"]="true";
8850
 
8851
		#回傳結果
8852
		return $result;
8853
 
8854
		}#function cancelCert end
8855
 
8856
	/*
8857
	#函式說明:
8858
	#透過zerossl api確保ssl沒有過期.
8859
	#回傳結果:
8860
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8861
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
8862
	#$result["function"],當前執行的函式名稱.
8863
	#$result["argu"],所使用的參數.
8864
	#必填參數:
8865
	#$conf["cName"],陣列,每個ssl的common domain name.
8866
	$conf["cName"]=array();
8867
	#$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內容合併後的檔案位置與名稱.
8868
	$conf["certInfo"]=array();
8869
	#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
8870
	$conf["rrFile"]=array();
8871
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
8872
	$conf["dnsSerAddr"]=array();
8873
	#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
8874
	$conf["actionAfterUpdateCert"]=array();
8875
	#可省略參數:
288 liveuser 8876
	#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/sslUpdater.sock
8877
	#$conf["sock"]="";
281 liveuser 8878
	#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
8879
	#$conf["debug"]="";
255 liveuser 8880
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8881
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8882
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8883
	#$conf["key"]=self::getApiInfo()["apiKey"];
293 liveuser 8884
	#$conf["multiThreads"],字串,預設為"false"代表不使用多執行序;"true"代表要用多執行序.
8885
	#$conf["multiThreads"]=""
255 liveuser 8886
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
8887
	#$conf["debug"]="";
8888
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
8889
	#$conf["addOnProcessFunc"]=array();
8890
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
8891
	#$conf["funcToRunWhenIdle"]=array();
8892
	#參考資料:
8893
	#無.
8894
	#備註:
8895
	#無.
8896
	*/
8897
	public static function sslUpdater(&$conf){
8898
 
8899
		#初始化要回傳的結果
8900
		$result=array();
8901
 
8902
		#設置當其函數名稱
8903
		$result["function"]=__FUNCTION__;
8904
 
8905
		#如果 $conf 不為陣列
8906
		if(gettype($conf)!="array"){
8907
 
8908
			#設置執行失敗
8909
			$result["status"]="false";
8910
 
8911
			#設置執行錯誤訊息
8912
			$result["error"][]="\$conf變數須為陣列形態";
8913
 
8914
			#如果傳入的參數為 null
8915
			if($conf==null){
8916
 
8917
				#設置執行錯誤訊息
8918
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8919
 
8920
				}#if end
8921
 
8922
			#回傳結果
8923
			return $result;
8924
 
8925
			}#if end
8926
 
8927
		#取得參數
8928
		$result["argu"]=$conf;
288 liveuser 8929
 
8930
		#初始化預設的 unix domain socket 路徑
8931
		$defaultSocket=pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/sslUpdater.sock";
255 liveuser 8932
 
8933
		#檢查參數
8934
		#函式說明:
8935
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8936
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8937
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8938
		#$result["function"],當前執行的函式名稱.
8939
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8940
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8941
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8942
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8943
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8944
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8945
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8946
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8947
		#必填寫的參數:
8948
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8949
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8950
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8951
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
8952
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
8953
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
8954
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8955
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8956
		#可以省略的參數:
8957
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8958
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8959
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
293 liveuser 8960
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("multiThreads","sock","debug","apiDomain","key");
255 liveuser 8961
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 8962
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("multiThreads","sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
255 liveuser 8963
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
293 liveuser 8964
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array","array");
255 liveuser 8965
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
293 liveuser 8966
		$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 8967
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8968
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
8969
		#參考資料來源:
8970
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8971
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8972
		unset($conf["variableCheck::checkArguments"]);
8973
 
8974
		#如果檢查失敗
8975
		if($checkArguments["status"]==="false"){
8976
 
8977
			#設置錯誤識別
8978
			$result["status"]="false";
8979
 
8980
			#設置錯誤訊息
8981
			$result["error"]=$checkArguments;
8982
 
8983
			#回傳結果
8984
			return $result;
8985
 
8986
			}#if end
8987
 
8988
		#如果檢查不通過
8989
		if($checkArguments["passed"]==="false"){
8990
 
8991
			#設置錯誤識別
8992
			$result["status"]="false";
8993
 
8994
			#設置錯誤訊息
8995
			$result["error"]=$checkArguments;
8996
 
8997
			#回傳結果
8998
			return $result;
8999
 
9000
			}#if end
9001
 
9002
		#取得key
9003
		$share["key"]=$conf["key"];
9004
 
9005
		#取得apiDomain
9006
		$share["apiDomain"]=$conf["apiDomain"];
9007
 
281 liveuser 9008
		#設置debug flag
9009
		$share["debug"]=$conf["debug"];
9010
 
293 liveuser 9011
		#設置 multiThreads 
9012
		$share["multiThreads"]=$conf["multiThreads"];
9013
 
255 liveuser 9014
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
9015
		$share["certInfo"]=array();
9016
 
9017
		#針對每個 domain
9018
		foreach($conf["cName"] as $index=>$cName ){
9019
 
9020
			#如果沒有對應的certInfo
9021
			if(!isset($conf["certInfo"][$index])){
9022
 
9023
				#設置錯誤識別
9024
				$result["status"]="false";
9025
 
9026
				#設置錯誤訊息
9027
				$result["error"][]="missing certInfo";
9028
 
9029
				#設置錯誤訊息
9030
				$result["error"][]=$checkArguments;
9031
 
9032
				#回傳結果
9033
				return $result;
9034
 
9035
				}#if end
9036
 
291 liveuser 9037
			#檢查 $conf["certInfo"][$index] 是否資訊都有存在
9038
			#函式說明:
9039
			#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
9040
			#回傳結果:
9041
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9042
			#$result["error"],執行不正常結束的錯訊息陣列.
9043
			#$result["simpleError"],簡單表示的錯誤訊息.
9044
			#$result["function"],當前執行的函式名稱.
9045
			#$result["argu"],設置給予的參數.
9046
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9047
			#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9048
			#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9049
			#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
9050
			#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
9051
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9052
			#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9053
			#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9054
			#必填參數:
9055
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9056
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["certInfo"][$index];
9057
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9058
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9059
			#可省略參數:
9060
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9061
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
9062
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
9063
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
9064
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
9065
			#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9066
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
9067
			#$conf["canNotBeEmpty"]=array();
9068
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
9069
			#$conf["canBeEmpty"]=array();
9070
			#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
9071
			$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("true","true","true","true");
9072
			#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9073
			$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
9074
			#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
9075
			$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
9076
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9077
			$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");
9078
			#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
9079
			#$conf["disallowAllSkipableVarIsEmpty"]="";
9080
			#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
9081
			#$conf["disallowAllSkipableVarIsEmptyArray"]="";
9082
			#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
9083
			#$conf["disallowAllSkipableVarNotExist"]="";
9084
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9085
			#$conf["arrayCountEqualCheck"][]=array();
9086
			#參考資料:
9087
			#array_keys=>http://php.net/manual/en/function.array-keys.php
9088
			#備註:
9089
			#無.
9090
			$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9091
			unset($conf["variableCheck::checkArguments"]);
9092
 
9093
			#如果檢查失敗
9094
			if($checkArguments["status"]==="false"){
9095
 
9096
				#設置錯誤識別
9097
				$result["status"]="false";
9098
 
9099
				#設置錯誤訊息
9100
				$result["error"]=$checkArguments;
9101
 
9102
				#回傳結果
9103
				return $result;
9104
 
9105
				}#if end
9106
 
9107
			#如果檢查不通過
9108
			if($checkArguments["passed"]==="false"){
9109
 
9110
				#設置錯誤識別
9111
				$result["status"]="false";
9112
 
9113
				#設置錯誤訊息
9114
				$result["error"]=$checkArguments;
9115
 
9116
				#回傳結果
9117
				return $result;
9118
 
9119
				}#if end
9120
 
9121
			#儲存 cName
9122
			$cInfo["cName"]=$cName;
255 liveuser 9123
 
291 liveuser 9124
			#儲存 RR 檔案的路徑與名稱
9125
			$cInfo["rrFile"]=$conf["rrFile"][$index];
255 liveuser 9126
 
291 liveuser 9127
			#儲存 cName 對應的 dns server addr
9128
			$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
255 liveuser 9129
 
291 liveuser 9130
			#儲存 cName 的憑證更新後要做的事情.
9131
			$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
255 liveuser 9132
 
294 liveuser 9133
			#用 ";" 分割來取得有多少個動作要依序執行
9134
			#函式說明:
9135
			#將固定格式的字串分開,並回傳分開的結果.
9136
			#回傳結果:
9137
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9138
			#$result["error"],錯誤訊息陣列
9139
			#$result["function"],當前執行的函數名稱.
9140
			#$result["argu"],使用的參數.
9141
			#$result["oriStr"],要分割的原始字串內容
9142
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9143
			#$result["dataCounts"],爲總共分成幾段
9144
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9145
			#必填參數:
9146
			#$conf["stringIn"],字串,要處理的字串.
9147
			$conf["stringProcess::spiltString"]["stringIn"]=$cInfo["actionAfterUpdateCert"];
9148
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9149
			$conf["stringProcess::spiltString"]["spiltSymbol"]=";";
9150
			#可省略參數:
9151
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9152
			#$conf["allowEmptyStr"]="false";
9153
			#參考資料:
9154
			#無.
9155
			#備註:
9156
			#無.
9157
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
9158
			unset($conf["stringProcess::spiltString"]);
9159
 
9160
			#如果執行異常
9161
			if($spiltString["status"]==="false"){
9162
 
9163
				#設置錯誤識別
9164
				$result["status"]="false";
9165
 
9166
				#設置錯誤訊息
9167
				$result["error"]=$spiltString;
9168
 
9169
				#回傳結果
9170
				return $result;
9171
 
9172
				}#if end
9173
 
9174
			#如果沒有";"存在,代表格式不對
9175
			if($spiltString["found"]==="false"){
9176
 
9177
				#設置錯誤識別
9178
				$result["status"]="false";
9179
 
9180
				#設置錯誤訊息
9181
				$result["error"]=$spiltString;
9182
 
9183
				#回傳結果
9184
				return $result;
9185
 
9186
				}#if end
9187
 
9188
			#取得每個動作
9189
			$cInfo["actionAfterUpdateCert"]=$spiltString["dataArray"];
9190
 
291 liveuser 9191
			#設置 certPath
9192
			$cInfo["ssl"]["certPath"]=$conf["certInfo"][$index]["certPath"];
255 liveuser 9193
 
291 liveuser 9194
			#設置 pKey
9195
			$cInfo["ssl"]["pKey"]=$conf["certInfo"][$index]["pKey"];
9196
 
9197
			#設置 caPath
9198
			$cInfo["ssl"]["caPath"]=$conf["certInfo"][$index]["caPath"];
9199
 
9200
			#設置 certWithCaPath
9201
			$cInfo["ssl"]["certWithCaPath"]=$conf["certInfo"][$index]["certWithCaPath"];
9202
 
9203
			#儲存 certInfo
9204
			$share["certInfo"][]=$cInfo;
9205
 
255 liveuser 9206
			}#foreach end
9207
 
9208
		#如果為空
9209
		if(empty($share["certInfo"])){
9210
 
9211
			#設置錯誤識別
9212
			$result["status"]="false";
9213
 
9214
			#設置錯誤訊息
9215
			$result["error"][]="certInfo 參數有缺";
9216
 
9217
			#設置錯誤訊息
9218
			$result["error"][]=$checkArguments;
9219
 
9220
			#回傳結果
9221
			return $result;
9222
 
9223
			}#if end
9224
 
9225
		#函式說明:
9226
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
9227
		#回傳結果:
9228
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
9229
		#$result["error"],錯誤訊息陣列.
9230
		#$result["function"],當前執行的函式名稱.
9231
		#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
9232
		#$result["serverCache"]["serverSide"],server side 的 cache.
9233
		#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
9234
		#$result["serverCache"]["clientSide"],client site 的 cache.
9235
		#必填參數:
9236
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
291 liveuser 9237
		$conf["sock::unixDomainSockServer"]["sock"]=$conf["sock"];
255 liveuser 9238
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9239
		$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
9240
		#可省略參數:
9241
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
9242
		$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
9243
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
9244
		$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
9245
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
9246
		#$conf["sessionTimeout"]="300";
9247
		#$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 9248
		$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("\qbpwcf\zerossl::sslUpdater_cmd");
255 liveuser 9249
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
291 liveuser 9250
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\qbpwcf\zerossl::sslUpdater_idle");
255 liveuser 9251
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
9252
		#$conf["paramsForFuncToRunWhenIdle"]=array();
9253
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
9254
		$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
9255
		#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
9256
		#$conf["shutdownStrAddr"]="";
9257
		#參考資料:
9258
		#http://php.net/manual/en/function.stream-socket-server.php
9259
		#備註:
9260
		#無.
9261
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
9262
		unset($conf["sock::unixDomainSockServer"]);
9263
 
9264
		#執行異常
9265
		if($unixDomainSockServer["status"]==="false"){
9266
 
9267
			#設置錯誤識別
9268
			$result["status"]="false";
9269
 
9270
			#設置錯誤訊息
9271
			$result["error"]=$unixDomainSockServer;
9272
 
9273
			#回傳結果
9274
			return $result;
9275
 
9276
			}#if end
9277
 
9278
		#設置執行正常
9279
		$result["status"]="true";
9280
 
9281
		#回傳結果
9282
		return $result;
9283
 
9284
		}#function sslUpdater end
9285
 
9286
	/*
9287
	#函式說明:
9288
	#funcion sslUpdater 於收到訊息時要做的事情.
9289
	#回傳結果:
9290
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9291
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
9292
	#$result["function"],當前執行的函式名稱.
9293
	#$result["argu"],所使用的參數.
9294
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
9295
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
9296
	#必填參數:
9297
	#$conf["request"],字串,收到的json訊息.
9298
	$conf["request"]="";
9299
	#$conf["sock"],resource,用戶的socket.
9300
	$conf["sock"]="";
9301
	#$conf["clientCache"],陣列,給予所有用戶的cache.
9302
	$conf["clientCache"]=array();
9303
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
9304
	$conf["info"]=array();
9305
	#可省略參數:
9306
	#無.
9307
	#參考資料:
9308
	#無.
9309
	#備註:
9310
	#建構中...
9311
	*/
9312
	public static function sslUpdater_cmd(&$conf){
9313
 
9314
		#debug
9315
		var_dump($conf);
9316
 
9317
		}#function sslUpdater_cmd end
9318
 
9319
	/*
9320
	#函式說明:
9321
	#funcion sslUpdater 於閒置時要做的事情
9322
	#回傳結果:
9323
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9324
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
9325
	#$result["function"],當前執行的函式名稱.
9326
	#$result["argu"],所使用的參數.
9327
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
9328
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
9329
	#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
9330
	#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
9331
	#必填參數:
9332
	#$conf["client"],陣列,所有用戶的資訊.
9333
	$conf["client"]=array();
9334
	#$conf["clientCache"],陣列,給予所有用戶的cache.
9335
	$conf["clientCache"]=array();
9336
	#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
9337
	$conf["serverCache"]=array();
9338
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
9339
	$conf["info"]=array();
9340
	#可省略參數:
9341
	#無.
9342
	#參考資料:
9343
	#無.
9344
	#備註:
291 liveuser 9345
	#無.
255 liveuser 9346
	*/
9347
	public static function sslUpdater_idle(&$conf){
9348
 
9349
		#初始化要回傳的結果
9350
		$result=array();
9351
 
9352
		#設置當其函數名稱
9353
		$result["function"]=__FUNCTION__;
9354
 
9355
		#如果 $conf 不為陣列
9356
		if(gettype($conf)!="array"){
9357
 
9358
			#設置執行失敗
9359
			$result["status"]="false";
9360
 
9361
			#設置執行錯誤訊息
9362
			$result["error"][]="\$conf變數須為陣列形態";
9363
 
9364
			#如果傳入的參數為 null
9365
			if($conf==null){
9366
 
9367
				#設置執行錯誤訊息
9368
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
9369
 
9370
				}#if end
9371
 
9372
			#回傳結果
9373
			return $result;
9374
 
9375
			}#if end
9376
 
9377
		#取得參數
9378
		$result["argu"]=$conf;
9379
 
9380
		#檢查參數
9381
		#函式說明:
9382
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9383
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9384
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9385
		#$result["function"],當前執行的函式名稱.
9386
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9387
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9388
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9389
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
9390
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
9391
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9392
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9393
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9394
		#必填寫的參數:
9395
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9396
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9397
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
291 liveuser 9398
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","serverCache","info");
255 liveuser 9399
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
291 liveuser 9400
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
255 liveuser 9401
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9402
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9403
		#可以省略的參數:
9404
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
9405
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9406
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
9407
		#$conf["skipableVariableCanNotBeEmpty"]=array();
9408
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9409
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
9410
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
9411
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
9412
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9413
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
9414
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9415
		#$conf["arrayCountEqualCheck"][]=array();
9416
		#參考資料來源:
9417
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9418
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9419
		unset($conf["variableCheck::checkArguments"]);
9420
 
9421
		#如果檢查失敗
9422
		if($checkArguments["status"]==="false"){
9423
 
9424
			#設置錯誤識別
9425
			$result["status"]="false";
9426
 
9427
			#設置錯誤訊息
9428
			$result["error"]=$checkArguments;
9429
 
9430
			#回傳結果
9431
			return $result;
9432
 
9433
			}#if end
9434
 
9435
		#如果檢查不通過
9436
		if($checkArguments["passed"]==="false"){
9437
 
9438
			#設置錯誤識別
9439
			$result["status"]="false";
9440
 
9441
			#設置錯誤訊息
9442
			$result["error"]=$checkArguments;
9443
 
9444
			#回傳結果
9445
			return $result;
9446
 
9447
			}#if end
281 liveuser 9448
 
9449
		#預設不開啟 debug flag
9450
		$debug=false;
9451
 
9452
		#如果有設置 debug 為 "true"
291 liveuser 9453
		if($conf["info"]["share"]["debug"]==="true"){
281 liveuser 9454
 
9455
			#設置 debug flag
9456
			$debug=true;
9457
 
9458
			}#if end
9459
 
293 liveuser 9460
		#如果有啟用 multiThreads
9461
		if($conf["info"]["share"]["multiThreads"]==="true"){
9462
 
9463
			#設置 multiThreads flag
9464
			$multiThreads=true;
9465
 
9466
			}#if end
9467
 
261 liveuser 9468
		#另存 server cache 的參考
9469
		$serverCache=&$conf["serverCache"];
9470
 
255 liveuser 9471
		#針對每個 domain name
291 liveuser 9472
		foreach($conf["info"]["share"]["certInfo"] as $certInfoIndex=>$cInfo){
255 liveuser 9473
 
9474
			#取得domain name
9475
			$cName=$cInfo["cName"];
9476
 
261 liveuser 9477
			#如果尚無對應domain name的記錄
9478
			if(!isset($serverCache[$cName])){
9479
 
9480
				#設置最新一次檢測的unixtime
9481
				$serverCache[$cName]["lastCheckUnixTime"]=time();
291 liveuser 9482
 
261 liveuser 9483
				}#if end
9484
 
9485
			#反之距離上次檢查不滿一天
291 liveuser 9486
			else{
261 liveuser 9487
 
291 liveuser 9488
				#計算距離上次檢查多少秒
9489
				$checkedAfter=time()-$serverCache[$cName]["lastCheckUnixTime"];
261 liveuser 9490
 
291 liveuser 9491
				#若距離上次檢查不滿一天
9492
				if($checkedAfter<86400){
9493
 
9494
					#if enable debug
9495
					if($debug){
9496
 
9497
						#debug msg
9498
						echo "Domain name(".$cName.") on zerossl require to check in ".(86400-$checkedAfter)." second(s).".PHP_EOL;
9499
 
9500
						}#if end
9501
 
9502
					#跳過該 domain name 的檢查
9503
					continue;
9504
 
9505
					}#if end
346 liveuser 9506
 
9507
				#反之
9508
				else{
291 liveuser 9509
 
346 liveuser 9510
					#重新設置上次檢查時間為當前時間
9511
					$serverCache[$cName]["lastCheckUnixTime"]=time();
9512
 
9513
					}#else end
9514
 
291 liveuser 9515
				}#else end
261 liveuser 9516
 
281 liveuser 9517
			#if enable debug
9518
			if($debug){
9519
 
9520
				#debug msg
291 liveuser 9521
				echo "Checking domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 9522
 
9523
				}#if end
9524
 
291 liveuser 9525
			#certPath
9526
			#$cInfo["ssl"]["certPath"];
9527
 
9528
			#pKey
9529
			#$cInfo["ssl"]["pKey"];
9530
 
9531
			#caPath
9532
			#$cInfo["ssl"]["caPath"]=;
9533
 
9534
			#certWithCaPath
9535
			#$cInfo["ssl"]["certWithCaPath"];
9536
 
255 liveuser 9537
			#嘗試取得 domain name 對應的可用憑證
9538
			#函式說明:
9539
			#取得在zerossl上的CSR清單
9540
			#回傳結果:
9541
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9542
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
9543
			#$result["function"],當前執行的函式名稱.
9544
			#$result["argu"],所使用的參數.
9545
			#$result["curl_verbose_info"],curl執行的詳細資訊.
9546
			#$result["content"],結果json字串.
9547
			#$result["tCount"],總共的資料筆數.
9548
			#$result["count"],該頁的筆數.
9549
			#$result["page"],當前的頁碼.
9550
			#$result["certs"],陣列,certificates清單,key為certificate的id.
9551
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
9552
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
9553
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
9554
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9555
			#必填參數:
9556
			#無
9557
			#可省略參數:
9558
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9559
			$conf["zerossl::getCertList"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9560
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9561
			$conf["zerossl::getCertList"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9562
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9563
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
9564
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
9565
			$conf["zerossl::getCertList"]["cerType"]="single90Days";
9566
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
9567
			$conf["zerossl::getCertList"]["search"]=$cName;
9568
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
9569
			#$conf["limit"]="";
9570
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
9571
			#$conf["page"]="";
9572
			#參考資料:
9573
			#https://zerossl.com/documentation/api/list-certificates/
9574
			#備註:
9575
			#無.
9576
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
9577
			unset($conf["zerossl::getCertList"]);
9578
 
9579
			#符合條件的數量
9580
			#$getCertList["tCount"];
9581
 
9582
			#符合條件的當頁數量
9583
			#$getCertList["count"];
9584
 
9585
			#如果執行異常
9586
			if($getCertList["status"]==="false"){
9587
 
9588
				#設置錯誤識別
9589
				$result["status"]="false";
9590
 
9591
				#設置錯誤訊息
9592
				$result["error"]=$getCertList;
9593
 
9594
				#回傳結果
9595
				return $result;
9596
 
9597
				}#if end
291 liveuser 9598
 
294 liveuser 9599
			#如果有資料
9600
			if($getCertList["count"]>0){
9601
 
9602
				#檢查 common name
9603
				foreach($getCertList["certs"] as $certId=>$certInfo){
9604
 
9605
					#如果 common name 不符合
9606
					if($certInfo["cname"]!==$cName){
9607
 
9608
						#移除之
9609
						unset($getCertList["certs"][$certId]);
9610
 
9611
						#當頁筆數-1
9612
						$getCertList["count"]--;
9613
 
9614
						#總共筆數減少1
9615
						$getCertList["tCount"]--;
9616
 
9617
						}#if end
9618
 
9619
					}#foreach end
9620
 
9621
				}#if end
9622
 
255 liveuser 9623
			#如果沒有憑證
291 liveuser 9624
			if($getCertList["count"]===0){
255 liveuser 9625
 
281 liveuser 9626
				#if enable debug
9627
				if($debug){
9628
 
9629
					#debug msg
291 liveuser 9630
					echo "There is not valid ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 9631
 
9632
					}#if end
9633
 
9634
				#if enable debug
9635
				if($debug){
9636
 
9637
					#debug msg
291 liveuser 9638
					echo "Checking ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9639
 
9640
					}#if end
9641
 
255 liveuser 9642
				#確認有無對應 cName 的 private key
9643
				#函式說明:
9644
				#檢查多個檔案與資料夾是否存在.
9645
				#回傳的結果:
9646
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9647
				#$result["error"],錯誤訊息陣列.
9648
				#$resutl["function"],當前執行的涵式名稱.
9649
				#$result["argu"],使用的參數.
9650
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9651
				#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9652
				#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
9653
				#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
9654
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9655
				#必填參數:
9656
				#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
292 liveuser 9657
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 9658
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9659
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
9660
				#可省略參數:
9661
				#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9662
				#$conf["disableWebSearch"]="false";
9663
				#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9664
				$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
9665
				#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
9666
				$conf["fileAccess::checkMultiFileExist"]["web"]="false";
9667
				#參考資料:
9668
				#http://php.net/manual/en/function.file-exists.php
9669
				#http://php.net/manual/en/control-structures.foreach.php
9670
				#備註:
9671
				#函數file_exists檢查的路徑為檔案系統的路徑
9672
				#$result["varName"][$i]結果未實作
9673
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9674
				unset($conf["fileAccess::checkMultiFileExist"]);
9675
 
9676
				#如果運行異常
9677
				if($checkMultiFileExist["status"]==="false"){
9678
 
9679
					#設置錯誤識別
9680
					$result["status"]="false";
9681
 
9682
					#設置錯誤訊息
9683
					$result["error"]=$getCertList;
9684
 
9685
					#回傳結果
9686
					return $result;
9687
 
9688
					}#if end
9689
 
9690
				#如果沒有 private key
9691
				if($checkMultiFileExist["allExist"]==="false"){
9692
 
281 liveuser 9693
					#if enable debug
9694
					if($debug){
9695
 
9696
						#debug msg
291 liveuser 9697
						echo "there is no ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9698
 
9699
						}#if end
9700
 
9701
					#if enable debug
9702
					if($debug){
9703
 
9704
						#debug msg
291 liveuser 9705
						echo "creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9706
 
9707
						}#if end
9708
 
255 liveuser 9709
					#建立 private key
9710
					#函式說明:
9711
					#產生ssl private key.
9712
					#回傳結果:
9713
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9714
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9715
					#$result["function"],當前執行的函式名稱.
9716
					#$result["argu"],所使用的參數.
9717
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9718
					#$result["content"],ssl用的private key.
9719
					#必填參數:
9720
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9721
					$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
9722
					#可省略參數:
9723
					#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
9724
					#$conf["length"]=4096';
9725
					#參考資料:
9726
					#無.
9727
					#備註:
9728
					#key generated by openssl with RSA.
291 liveuser 9729
					$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 9730
					unset($conf["openssl::createPrivateKey"]);
9731
 
9732
					#如果運行異常
9733
					if($createPrivateKey["status"]==="false"){
9734
 
9735
						#設置錯誤識別
9736
						$result["status"]="false";
9737
 
9738
						#設置錯誤訊息
9739
						$result["error"]=$createPrivateKey;
9740
 
9741
						#回傳結果
9742
						return $result;
9743
 
9744
						}#if end
9745
 
9746
					#另存private key的字串
9747
					$pKeyStr=$createPrivateKey["content"];
9748
 
9749
					#建立private key檔案
9750
					#函式說明:
9751
					#將字串寫入到檔案
9752
					#回傳結果:
9753
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9754
					#$result["error"],錯誤訊息陣列.
9755
					#$result["function"],當前執行的函數名稱.
9756
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
9757
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
9758
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
9759
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
9760
					#$result["argu"],使用的參數.
9761
					#必填參數:
9762
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9763
					$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
9764
					#可省略參數:
9765
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
292 liveuser 9766
					$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 9767
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
9768
					$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
9769
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
9770
					#$conf["writeMethod"]="a";
9771
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
9772
					#$conf["checkRepeat"]="";
9773
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
9774
					#$conf["filenameExtensionStartPoint"]="";
9775
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
9776
					#$conf["repeatNameRule"]="";
9777
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
9778
					$conf["zerossl::writeTextIntoFile"]["web"]="false";
9779
					#參考資料:
9780
					#無.
9781
					#備註:
9782
					#無.
291 liveuser 9783
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
255 liveuser 9784
					unset($conf["zerossl::writeTextIntoFile"]);
9785
 
9786
					#如果運行異常
9787
					if($writeTextIntoFile["status"]==="false"){
9788
 
9789
						#設置錯誤識別
9790
						$result["status"]="false";
9791
 
9792
						#設置錯誤訊息
9793
						$result["error"]=$writeTextIntoFile;
9794
 
9795
						#回傳結果
9796
						return $result;
9797
 
9798
						}#if end
9799
 
9800
					}#if end
9801
 
281 liveuser 9802
				#if enable debug
9803
				if($debug){
9804
 
9805
					#debug msg
291 liveuser 9806
					echo "Creating domain name(".$conf["info"]["share"]["apiDomain"].") csr for zerossl...".PHP_EOL;
281 liveuser 9807
 
9808
					}#if end
9809
 
255 liveuser 9810
				#建立準備給zerossl的csr
9811
				#函式說明:
9812
				#產生certificate sign request(CSR).
9813
				#回傳結果:
9814
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9815
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9816
				#$result["function"],當前執行的函式名稱.
9817
				#$result["argu"],所使用的參數.
9818
				#$result["content"],csr內容.
9819
				#$result["curl_verbose_info"],curl執行的詳細資訊.
9820
				#$result["privateKey"], private key 的內容.
9821
				#必填參數:
9822
				#$conf["domain"],字串,csr內容的網域名稱.
9823
				$conf["zerossl::createCSR"]["domain"]=$cName;
9824
				#可省略參數:
9825
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 9826
				$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 9827
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
9828
				#$conf["country"]="";
9829
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
9830
				#$conf["state"]="";
9831
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
9832
				#$conf["org"]="";
9833
				#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
9834
				#$conf["unit"]="";
9835
				#參考資料:
9836
				#無.
9837
				#備註:
9838
				#無.
9839
				$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
9840
				unset($conf["zerossl::createCSR"]);
9841
 
9842
				#如果運行異常
9843
				if($createCSR["status"]==="false"){
9844
 
9845
					#設置錯誤識別
9846
					$result["status"]="false";
9847
 
9848
					#設置錯誤訊息
9849
					$result["error"]=$createCSR;
9850
 
9851
					#回傳結果
9852
					return $result;
9853
 
9854
					}#if end
9855
 
9856
				#取得本地端產生的csr內容
9857
				$csrLocal=$createCSR["content"];
9858
 
281 liveuser 9859
				#if enable debug
9860
				if($debug){
9861
 
9862
					#debug msg
291 liveuser 9863
					echo "Creating certificate for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 9864
 
9865
					}#if end
9866
 
255 liveuser 9867
				#函式說明:
281 liveuser 9868
				#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 9869
				#回傳結果:
9870
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9871
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9872
				#$result["function"],當前執行的函式名稱.
9873
				#$result["argu"],所使用的參數.
9874
				#$result["curl_verbose_info"],curl執行的詳細資訊.
9875
				#$result["id"],用於zerossl api驗證domain的id.
9876
				#$result["content"],字串,得到的json字串回應.
9877
				#$result["cnameKey"],用於dns CNAME驗證鍵名.
9878
				#$result["cnameVal"],用於dms CNAME驗證鍵值.
9879
				#必填參數:
9880
				#$conf["certificate_domains"],字串,要簽署的doamin名稱.
9881
				$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
9882
				#$conf["certificate_csr"],字串,簽署的資訊.
9883
				$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
9884
				#$conf["fileArgu"],字串,變數__FILE__的內容.
9885
				$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
9886
				#可省略參數:
9887
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9888
				$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9889
				#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
9890
				#$conf["path"]=self::getApiInfo()["csrPath"];
9891
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9892
				$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9893
				#參考資料:
9894
				#無.
9895
				#備註:
9896
				#無.
9897
				$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
9898
				unset($conf["zerossl::createCertificate"]);
9899
 
9900
				#如果執行異常
9901
				if($createCertificate["status"]==="false"){
9902
 
9903
					#設置錯誤識別
9904
					$result["status"]="false";
9905
 
9906
					#設置錯誤訊息
9907
					$result["error"]=$createCertificate;
9908
 
9909
					#回傳結果
9910
					return $result;
9911
 
9912
					}#if end
9913
 
9914
				#取得csr在zerossl上的id
9915
				$csrId=$createCertificate["id"];
9916
 
9917
				#取得cname key
9918
				$cNameKey=$createCertificate["cnameKey"];
9919
 
9920
				#取得cname val
9921
				$cNameVal=$createCertificate["cnameVal"];
9922
 
9923
				#初始化要增加的RR記錄
9924
				$rr2add=array();
9925
 
9926
				#設置CNAME的查詢
9927
				$rr2add["query"]=$cNameKey;
9928
 
9929
				#設置CNAME的value
9930
				$rr2add["value"]=$cNameVal;
9931
 
9932
				#設置類型為 CNAME
9933
				$rr2add["type"]="CNAME";
9934
 
9935
				#設置註解
9936
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
9937
 
281 liveuser 9938
				#if enable debug
9939
				if($debug){
9940
 
9941
					#debug msg
291 liveuser 9942
					echo "Adding DNS record to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9943
 
9944
					}#if end
9945
 
255 liveuser 9946
				#函式說明:
9947
				#新增DNS記錄到檔案裡面.
9948
				#回傳結果:
9949
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9950
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9951
				#$result["function"],當前執行的函式名稱.
9952
				#$result["argu"],所使用的參數.
9953
				#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
9954
				#$result["domain"],字串,RR所屬domain.
9955
				#$result["defaultTTL"],字串,預設的RR更新時間.
9956
				#$result["comment"],字串陣列,逐行的註解.
9957
				#必填參數:
9958
				#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
291 liveuser 9959
				$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 9960
				#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
9961
				$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
9962
				#可省略參數:
9963
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
9964
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
9965
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
9966
				#$conf["debug"]="false";
293 liveuser 9967
 
9968
				#如果有啟用多執行序
9969
				if($conf["info"]["share"]["multiThreads"]==="true"){
9970
 
9971
					#設置要多執行序
9972
					$conf["zerossl::updateDnsRecordFile"]["multiThreads"]="true";
9973
 
9974
					}#if end
9975
 
255 liveuser 9976
				#參考資料:
9977
				#無.
9978
				#備註:
9979
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
9980
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
9981
				#php-pear上的Net_DNS2也可以解析RR.
9982
				$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
9983
				unset($conf["zerossl::updateDnsRecordFile"]);
9984
 
9985
				#如果執行異常
9986
				if($updateDnsRecordFile["status"]==="false"){
9987
 
9988
					#設置錯誤識別
9989
					$result["status"]="false";
9990
 
9991
					#設置錯誤訊息
9992
					$result["error"]=$updateDnsRecordFile;
9993
 
9994
					#回傳結果
9995
					return $result;
9996
 
9997
					}#if end
281 liveuser 9998
 
9999
				#if enable debug
10000
				if($debug){
10001
 
10002
					#debug msg
291 liveuser 10003
					echo "Restart DNS service to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10004
 
10005
					}#if end
10006
 
255 liveuser 10007
				#重新啟動dns伺服器
10008
				#函式說明:
10009
				#呼叫shell執行系統命令,並取得回傳的內容.
10010
				#回傳結果:
10011
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10012
				#$result["error"],錯誤訊息陣列.
10013
				#$result["function"],當前執行的函數名稱.
10014
				#$result["argu"],使用的參數.
10015
				#$result["cmd"],執行的指令內容.
10016
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10017
				#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10018
				#$result["content"],為執行完後的輸出字串.
10019
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10020
				#$result["running"],是否還在執行.
10021
				#$result["pid"],pid.
10022
				#$result["statusCode"],執行結束後的代碼.
10023
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10024
				#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10025
				#必填參數:
10026
				#$conf["command"],字串,要執行的指令.
291 liveuser 10027
				$conf["external::callShell"]["command"]="systemctl";
255 liveuser 10028
				#$conf["fileArgu"],字串,變數__FILE__的內容.
10029
				$conf["external::callShell"]["fileArgu"]=__FILE__;
10030
				#可省略參數:
10031
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
10032
				$conf["external::callShell"]["argu"]=array("restart","named");
10033
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10034
				#$conf["arguIsAddr"]=array();
10035
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10036
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10037
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10038
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10039
				#$conf["enablePrintDescription"]="true";
10040
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10041
				#$conf["printDescription"]="";
10042
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10043
				#$conf["escapeshellarg"]="false";
10044
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10045
				#$conf["thereIsShellVar"]=array();
10046
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10047
				#$conf["username"]="";
10048
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10049
				#$conf["password"]="";
10050
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10051
				#$conf["useScript"]="";
10052
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10053
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10054
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10055
				#$conf["inBackGround"]="";
10056
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10057
				#$conf["getErr"]="false";
10058
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10059
				#$conf["doNotRun"]="false";
10060
				#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10061
				$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
10062
				#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10063
				#$conf["remoteUser"]="root";
10064
				#參考資料:
10065
				#exec=>http://php.net/manual/en/function.exec.php
10066
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10067
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10068
				#備註:
10069
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10070
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10071
				$callShell=external::callShell($conf["external::callShell"]);
10072
				unset($conf["external::callShell"]);
10073
 
10074
				#如果執行異常
10075
				if($callShell["status"]==="false"){
10076
 
10077
					#設置錯誤識別
10078
					$result["status"]="false";
10079
 
10080
					#設置錯誤訊息
10081
					$result["error"]=$callShell;
10082
 
10083
					#回傳結果
10084
					return $result;
10085
 
10086
					}#if end
281 liveuser 10087
 
10088
				#if enable debug
10089
				if($debug){
10090
 
10091
					#debug msg
291 liveuser 10092
					echo "Request zerossl to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10093
 
10094
					}#if end
10095
 
292 liveuser 10096
				#無窮迴圈
10097
				while(true){
255 liveuser 10098
 
292 liveuser 10099
					#函式說明:
10100
					#請求驗證已經透過zerossl::createCertificate要求的domain.
10101
					#回傳結果:
10102
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10103
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10104
					#$result["function"],當前執行的函式名稱.
10105
					#$result["argu"],所使用的參數.
10106
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10107
					#$result["content"],結果json字串.
10108
					#必填參數:
10109
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
10110
					$conf["zerossl::verifyDomain"]["id"]=$csrId;
10111
					#可省略參數:
10112
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
10113
					$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
10114
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
10115
					$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
10116
					#參考資料:
10117
					#https://zerossl.com/documentation/api/verify-domains/
10118
					#備註:
10119
					#無.
10120
					$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
10121
					unset($conf["zerossl::verifyDomain"]);
291 liveuser 10122
 
292 liveuser 10123
					#如果執行異常
10124
					if($verifyDomain["status"]==="false"){
10125
 
10126
						#設置錯誤識別
10127
						$result["status"]="false";
291 liveuser 10128
 
292 liveuser 10129
						#設置錯誤訊息
10130
						$result["error"]=$verifyDomain;
291 liveuser 10131
 
292 liveuser 10132
						#回傳結果
10133
						return $result;
291 liveuser 10134
 
10135
						}#if end
10136
 
292 liveuser 10137
					#如果沒有回內容
293 liveuser 10138
					if(!isset($verifyDomain["content"])){
292 liveuser 10139
 
10140
						#設置錯誤識別
10141
						$result["status"]="false";
291 liveuser 10142
 
292 liveuser 10143
						#設置錯誤訊息
10144
						$result["error"]=$verifyDomain;
291 liveuser 10145
 
292 liveuser 10146
						#回傳結果
10147
						return $result;
10148
 
10149
						}#if end
10150
 
10151
					#如果回應不是 json
293 liveuser 10152
					if(!(json_validate($verifyDomain["content"]))){
292 liveuser 10153
 
10154
						#設置錯誤識別
10155
						$result["status"]="false";
291 liveuser 10156
 
292 liveuser 10157
						#設置錯誤訊息
10158
						$result["error"]=$verifyDomain;
291 liveuser 10159
 
292 liveuser 10160
						#回傳結果
10161
						return $result;
10162
 
10163
						}#if end
10164
 
294 liveuser 10165
					#if enable debug
10166
					if($debug){
10167
 
10168
						#debug msg
10169
						echo "Response of validating certificate for domain name(".$cName.") on zerossl".PHP_EOL;
10170
 
10171
						#debug msg
10172
						var_dump(__LINE__,$verifyDomain);
10173
 
10174
						}#if end
10175
 
292 liveuser 10176
					/*
10177
					範例json:
10178
					{"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}
10179
					*/
10180
 
10181
					#解析json回應
293 liveuser 10182
					$verifyDomainRes=json_decode($verifyDomain["content"]);
291 liveuser 10183
 
293 liveuser 10184
					#如果回應含有 success
10185
					if(isset($verifyDomainRes->success)){
292 liveuser 10186
 
293 liveuser 10187
						#如果是 zerossl 驗證失敗
294 liveuser 10188
						if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
291 liveuser 10189
 
293 liveuser 10190
							#如果是 CNAME 記錄找不到
10191
							if($verifyDomainRes->error->code===0){
291 liveuser 10192
 
293 liveuser 10193
								#取得錯誤訊息
10194
								#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
10195
 
10196
								#if enable debug
10197
								if($debug){
10198
 
10199
									#debug msg
10200
									echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
10201
 
10202
									}#if end
10203
 
10204
								#if enable debug
10205
								if($debug){
10206
 
10207
									#debug msg
10208
									echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
10209
 
10210
									}#if end
10211
 
10212
								#休息60秒
10213
								sleep(60);
294 liveuser 10214
 
10215
								#再跑一次要求認證
10216
								continue;
291 liveuser 10217
 
10218
								}#if end
293 liveuser 10219
 
10220
							#反之為不接受的錯誤訊息
10221
							else{
291 liveuser 10222
 
293 liveuser 10223
								#設置錯誤識別
10224
								$result["status"]="false";
10225
 
10226
								#設置錯誤訊息
10227
								$result["error"]=$verifyDomain;
10228
 
10229
								#回傳結果
10230
								return $result;
291 liveuser 10231
 
293 liveuser 10232
								}#else end
291 liveuser 10233
 
10234
							}#if end
292 liveuser 10235
 
10236
						}#if end
293 liveuser 10237
 
10238
					#反之如果回應含有 status
10239
					else if(isset($verifyDomainRes->status)){
292 liveuser 10240
 
293 liveuser 10241
						#如果是 zerossl 尚在驗證中
10242
						if($verifyDomainRes->status==="pending_validation"){
292 liveuser 10243
 
293 liveuser 10244
							#if enable debug
10245
							if($debug){
292 liveuser 10246
 
293 liveuser 10247
								#debug msg
10248
								echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
292 liveuser 10249
 
10250
								}#if end
10251
 
293 liveuser 10252
							#無窮迴圈
10253
							while(true){
10254
 
10255
								#查詢驗證狀況
10256
								#函式說明:
10257
								#取得CSR在zerossl上的狀態
10258
								#回傳結果:
10259
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10260
								#$reuslt["error"],執行不正常結束的錯訊息陣列.
10261
								#$result["function"],當前執行的函式名稱.
10262
								#$result["argu"],所使用的參數.
10263
								#$result["curl_verbose_info"],curl執行的詳細資訊.
10264
								#$result["content"],結果json字串.
10265
								#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
10266
								#必填參數:
10267
								#$conf["id"],字串,zerossl::createCertificate回傳的id.
10268
								$conf["zerossl::getCertSta"]["id"]=$csrId;
10269
								#可省略參數:
10270
								#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
10271
								$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
10272
								#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
10273
								$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
10274
								#參考資料:
10275
								#https://zerossl.com/documentation/api/get-certificate/
10276
								#備註:
10277
								#無.
10278
								$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
10279
								unset($conf["zerossl::getCertSta"]);
10280
 
10281
								#如果執行異常
10282
								if($getCertSta["status"]==="false"){
10283
 
10284
									#設置錯誤識別
10285
									$result["status"]="false";
292 liveuser 10286
 
293 liveuser 10287
									#設置錯誤訊息
10288
									$result["error"]=$getCertSta;
292 liveuser 10289
 
293 liveuser 10290
									#回傳結果
10291
									return $result;
292 liveuser 10292
 
293 liveuser 10293
									}#if end
10294
 
10295
								#如果沒有回應內容
10296
								if(!isset($getCertSta["content"])){
10297
 
10298
									#設置錯誤識別
10299
									$result["status"]="false";
292 liveuser 10300
 
293 liveuser 10301
									#設置錯誤訊息
10302
									$result["error"]=$getCertSta;
292 liveuser 10303
 
293 liveuser 10304
									#回傳結果
10305
									return $result;
292 liveuser 10306
 
293 liveuser 10307
									}#if end
10308
 
10309
								#如果回應不是 json
10310
								if(!(json_validate($getCertSta["content"]))){
292 liveuser 10311
 
293 liveuser 10312
									#設置錯誤識別
10313
									$result["status"]="false";
10314
 
10315
									#設置錯誤訊息
10316
									$result["error"]=$getCertSta;
10317
 
10318
									#回傳結果
10319
									return $result;
292 liveuser 10320
 
10321
									}#if end
293 liveuser 10322
 
10323
								#解析json回應
10324
								$getCertStaRes=json_decode($getCertSta["content"]);
292 liveuser 10325
 
293 liveuser 10326
								#如果憑證已經驗證通過了
10327
								if($getCertStaRes->status==="issued"){
292 liveuser 10328
 
293 liveuser 10329
									#if enable debug
10330
									if($debug){
10331
 
10332
										#debug msg
10333
										echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
10334
 
10335
										}#if end
292 liveuser 10336
 
294 liveuser 10337
									#結束等待,跳出 while
293 liveuser 10338
									break 2;
10339
 
292 liveuser 10340
									}#if end
10341
 
293 liveuser 10342
								#如果 zerossl 尚在處理中
10343
								else if($getCertStaRes->status==="pending_validation"){
292 liveuser 10344
 
293 liveuser 10345
									#if enable debug
10346
									if($debug){
10347
 
10348
										#debug msg
10349
										echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
10350
 
10351
										}#if end
10352
 
10353
									#休息1分鐘
10354
									sleep(60);
294 liveuser 10355
 
10356
									#再跑一次取得憑證狀態
10357
									continue;
293 liveuser 10358
 
10359
									}#if end
10360
 
10361
								#反之
10362
								else{
10363
 
10364
									#例外狀況
10365
 
10366
									#設置錯誤識別
10367
									$result["status"]="false";
292 liveuser 10368
 
293 liveuser 10369
									#設置錯誤訊息
10370
									$result["error"]=$getCertSta;
292 liveuser 10371
 
293 liveuser 10372
									#回傳結果
10373
									return $result;
10374
 
10375
									}#else end
292 liveuser 10376
 
293 liveuser 10377
								}#while end
10378
 
10379
							}#if end
10380
 
292 liveuser 10381
						}#if end
294 liveuser 10382
 
10383
					#反之.不應該執行到這邊
10384
					else{
10385
 
10386
						#設置錯誤識別
10387
						$result["status"]="false";
10388
 
10389
						#設置錯誤訊息
10390
						$result["error"]=$verifyDomain;
10391
 
10392
						#回傳結果
10393
						return $result;
10394
 
10395
						}#else 	
291 liveuser 10396
 
292 liveuser 10397
					}#while end
294 liveuser 10398
 
281 liveuser 10399
				#if enable debug
10400
				if($debug){
10401
 
10402
					#debug msg
291 liveuser 10403
					echo "Downloading certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10404
 
10405
					}#if end
10406
 
255 liveuser 10407
				#函式說明:
10408
				#下載certificate.
10409
				#回傳結果:
10410
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10411
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
10412
				#$result["function"],當前執行的函式名稱.
10413
				#$result["argu"],所使用的參數.
10414
				#$result["curl_verbose_info"],curl執行的詳細資訊.
10415
				#$result["content"],結果json字串.
10416
				#$result["certificate.crt"],字串,certificate.crt的內容.
10417
				#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
10418
				#必填參數:
10419
				#無.
10420
				#可省略參數:
10421
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 10422
				$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 10423
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 10424
				$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 10425
				#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
10426
				$conf["zerossl::getCert"]["id"]=$csrId;
10427
				#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
10428
				#$conf["zerossl::getCert"]["cname"]="";
10429
				#參考資料:
10430
				#https://zerossl.com/documentation/api/download-certificate-inline/
10431
				#備註:
10432
				#無.
10433
				$getCert=zerossl::getCert($conf["zerossl::getCert"]);
10434
				unset($conf["zerossl::getCert"]);
10435
 
10436
				#如果執行異常
10437
				if($getCert["status"]==="false"){
10438
 
10439
					#設置錯誤識別
10440
					$result["status"]="false";
10441
 
10442
					#設置錯誤訊息
10443
					$result["error"]=$getCert;
10444
 
10445
					#回傳結果
10446
					return $result;
10447
 
10448
					}#if end
281 liveuser 10449
 
10450
				#if enable debug
10451
				if($debug){
10452
 
10453
					#debug msg
291 liveuser 10454
					echo "Creating certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10455
 
10456
					}#if end
10457
 
293 liveuser 10458
				#certPath
10459
				#$cInfo["ssl"]["certPath"];
255 liveuser 10460
 
293 liveuser 10461
				#pKey
10462
				#$cInfo["ssl"]["pKey"];
255 liveuser 10463
 
293 liveuser 10464
				#caPath
10465
				#$cInfo["ssl"]["caPath"]=;
255 liveuser 10466
 
293 liveuser 10467
				#certWithCaPath
10468
				#$cInfo["ssl"]["certWithCaPath"];
10469
 
255 liveuser 10470
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
10471
				#函式說明:
10472
				#一次建立多個檔案,並寫入內容.
10473
				#回傳結果:
10474
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10475
				#$result["error"],錯誤訊息陣列.
10476
				#$result["function"],當前執行的函數名稱.
10477
				#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10478
				#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10479
				#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10480
				#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10481
				#$result["argu"],使用的參數.
10482
				#必填參數:
10483
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10484
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10485
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
293 liveuser 10486
				$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 10487
				#可省略參數:
10488
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10489
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
10490
				#參考資料:
10491
				#無.
10492
				#備註:
10493
				#無.
293 liveuser 10494
				$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10495
				unset($conf["zerossl::writeMultiFile"]);
10496
 
10497
				#如果執行異常
10498
				if($writeMultiFile["status"]==="false"){
10499
 
10500
					#設置錯誤識別
10501
					$result["status"]="false";
10502
 
10503
					#設置錯誤訊息
10504
					$result["error"]=$writeMultiFile;
10505
 
10506
					#回傳結果
10507
					return $result;
10508
 
10509
					}#if end
10510
 
10511
				#儲存 actionAfterUpdateCert
10512
				$action=$cInfo["actionAfterUpdateCert"];
10513
 
10514
				#如果有多個指令要執行
294 liveuser 10515
				if(count($action)>1){
255 liveuser 10516
 
281 liveuser 10517
					#if enable debug
10518
					if($debug){
10519
 
10520
						#debug msg
291 liveuser 10521
						echo "There are many cmds to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10522
 
10523
						}#if end
10524
 
10525
					#if enable debug
10526
					if($debug){
10527
 
10528
						#debug msg
291 liveuser 10529
						echo "Running cmd to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10530
 
10531
						}#if end
10532
 
255 liveuser 10533
					#針對每的指令
10534
					foreach($action as $ac){
10535
 
281 liveuser 10536
						#if enable debug
10537
						if($debug){
10538
 
10539
							#debug msg
10540
							echo ".".PHP_EOL;
10541
 
10542
							}#if end
10543
 
255 liveuser 10544
						#函式說明:
10545
						#呼叫shell執行系統命令,並取得回傳的內容.
10546
						#回傳結果:
10547
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10548
						#$result["error"],錯誤訊息陣列.
10549
						#$result["function"],當前執行的函數名稱.
10550
						#$result["argu"],使用的參數.
10551
						#$result["cmd"],執行的指令內容.
10552
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10553
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10554
						#$result["content"],為執行完後的輸出字串.
10555
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10556
						#$result["running"],是否還在執行.
10557
						#$result["pid"],pid.
10558
						#$result["statusCode"],執行結束後的代碼.
10559
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10560
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10561
						#必填參數:
10562
						#$conf["command"],字串,要執行的指令.
294 liveuser 10563
						$conf["external::callShell"]["command"]=$ac;
255 liveuser 10564
						#$conf["fileArgu"],字串,變數__FILE__的內容.
10565
						$conf["external::callShell"]["fileArgu"]=__FILE__;
10566
						#可省略參數:
10567
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
294 liveuser 10568
						#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 10569
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10570
						#$conf["arguIsAddr"]=array();
10571
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10572
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10573
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10574
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10575
						#$conf["enablePrintDescription"]="true";
10576
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10577
						#$conf["printDescription"]="";
10578
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10579
						$conf["external::callShell"]["escapeshellarg"]="true";
10580
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10581
						#$conf["thereIsShellVar"]=array();
10582
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10583
						#$conf["username"]="";
10584
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10585
						#$conf["password"]="";
10586
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10587
						#$conf["useScript"]="";
10588
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10589
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10590
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10591
						#$conf["inBackGround"]="";
10592
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10593
						#$conf["getErr"]="false";
294 liveuser 10594
						#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10595
						$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10596
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10597
						#$conf["doNotRun"]="false";
10598
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10599
						#$conf["remoteIp"]="";
10600
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10601
						#$conf["remoteUser"]="";
10602
						#參考資料:
10603
						#exec=>http://php.net/manual/en/function.exec.php
10604
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10605
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10606
						#備註:
10607
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10608
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10609
						$callShell=external::callShell($conf["external::callShell"]);
10610
						unset($conf["external::callShell"]);
10611
 
10612
						#如果執行異常
294 liveuser 10613
						if($callShell["status"]==="false"){
255 liveuser 10614
 
10615
							#設置錯誤識別
10616
							$result["status"]="false";
10617
 
10618
							#設置錯誤訊息
10619
							$result["error"]=$callShell;
10620
 
10621
							#回傳結果
10622
							return $result;
10623
 
10624
							}#if end
10625
 
10626
						}#foreach end
10627
 
10628
					}#if end
10629
 
10630
				#反之
10631
				else{
10632
 
281 liveuser 10633
					#if enable debug
10634
					if($debug){
10635
 
10636
						#debug msg
291 liveuser 10637
						echo "There is only one cmd to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10638
 
10639
						}#if end
10640
 
10641
					#if enable debug
10642
					if($debug){
10643
 
10644
						#debug msg
10645
						echo ".".PHP_EOL;
10646
 
10647
						}#if end
10648
 
255 liveuser 10649
					#函式說明:
10650
					#呼叫shell執行系統命令,並取得回傳的內容.
10651
					#回傳結果:
10652
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10653
					#$result["error"],錯誤訊息陣列.
10654
					#$result["function"],當前執行的函數名稱.
10655
					#$result["argu"],使用的參數.
10656
					#$result["cmd"],執行的指令內容.
10657
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10658
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10659
					#$result["content"],為執行完後的輸出字串.
10660
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10661
					#$result["running"],是否還在執行.
10662
					#$result["pid"],pid.
10663
					#$result["statusCode"],執行結束後的代碼.
10664
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10665
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10666
					#必填參數:
10667
					#$conf["command"],字串,要執行的指令.
302 liveuser 10668
					$conf["external::callShell"]["command"]=$action[0];
255 liveuser 10669
					#$conf["fileArgu"],字串,變數__FILE__的內容.
10670
					$conf["external::callShell"]["fileArgu"]=__FILE__;
10671
					#可省略參數:
10672
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10673
					#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 10674
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10675
					#$conf["arguIsAddr"]=array();
10676
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10677
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10678
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10679
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10680
					#$conf["enablePrintDescription"]="true";
10681
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10682
					#$conf["printDescription"]="";
10683
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10684
					$conf["external::callShell"]["escapeshellarg"]="true";
10685
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10686
					#$conf["thereIsShellVar"]=array();
10687
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10688
					#$conf["username"]="";
10689
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10690
					#$conf["password"]="";
10691
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10692
					#$conf["useScript"]="";
10693
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10694
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10695
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10696
					#$conf["inBackGround"]="";
10697
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10698
					#$conf["getErr"]="false";
10699
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10700
					#$conf["doNotRun"]="false";
294 liveuser 10701
					#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10702
					$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10703
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10704
					#$conf["remoteIp"]="";
10705
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10706
					#$conf["remoteUser"]="";
10707
					#參考資料:
10708
					#exec=>http://php.net/manual/en/function.exec.php
10709
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10710
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10711
					#備註:
10712
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10713
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10714
					$callShell=external::callShell($conf["external::callShell"]);
10715
					unset($conf["external::callShell"]);
294 liveuser 10716
 
255 liveuser 10717
					#如果執行異常
294 liveuser 10718
					if($callShell["status"]==="false"){
255 liveuser 10719
 
10720
						#設置錯誤識別
10721
						$result["status"]="false";
10722
 
10723
						#設置錯誤訊息
10724
						$result["error"]=$callShell;
10725
 
10726
						#回傳結果
10727
						return $result;
10728
 
10729
						}#if end
10730
 
10731
					}#else end
10732
 
10733
				}#if end
10734
 
10735
			#反之
10736
			else{
10737
 
281 liveuser 10738
				#if enable debug
10739
				if($debug){
10740
 
10741
					#debug msg
291 liveuser 10742
					echo "There is already valid ssl for domain name(".$cName.") on zerossl".PHP_EOL;
281 liveuser 10743
 
10744
					}#if end
10745
 
291 liveuser 10746
				#debug
10747
				#var_dump(__LINE__,$getCertList);
10748
 
255 liveuser 10749
				#有 issued 的憑證
10750
 
291 liveuser 10751
				#if enable debug
10752
				if($debug){
10753
 
10754
					#debug msg
10755
					echo "Downloading ssl for domain name(".$cName.") on zerossl".PHP_EOL;
10756
 
10757
					}#if end
10758
 
255 liveuser 10759
				#取得 certificate id at zerossl
10760
				#函式說明:
10761
				#將陣列轉換成存有key與value的陣列
10762
				#回傳的結果:
10763
				#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
10764
				#$result["function"],當前執行的函數
10765
				#$result["error"],錯誤訊息.
10766
				#$result[$i]["key"],原先$i+1個元素的key.
10767
				#$result[$i]["value"],原先$i+1個元素的value.
10768
				#必填參數:
10769
				#$conf["rawInputArray"],陣列,要轉換的陣列變數.
10770
				$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
10771
				#可省略參數:
10772
				#無.
10773
				#參考資料:
10774
				#無.
10775
				#備註:
10776
				#無.
10777
				$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
10778
				unset($conf["arrays::getKeyAndValue"]);
10779
 
10780
				#如果執行異常
10781
				if($getKeyAndValue["status"]==="false"){
10782
 
10783
					#設置錯誤識別
10784
					$result["status"]="false";
10785
 
10786
					#設置錯誤訊息
10787
					$result["error"]=$getKeyAndValue;
10788
 
10789
					#回傳結果
10790
					return $result;
10791
 
10792
					}#if end
10793
 
291 liveuser 10794
				#debug
10795
				#var_dump($getKeyAndValue);exit;
10796
 
255 liveuser 10797
				#儲存 certificate id at zerossl
291 liveuser 10798
				$csrId=$getKeyAndValue[1]["key"];
255 liveuser 10799
 
10800
				#檢查憑證是否已經快過期
10801
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
10802
 
10803
				#如果距離當下不到2個星期就要過期
10804
				if($expiresIn<=86400*14){
291 liveuser 10805
 
281 liveuser 10806
					#if enable debug
10807
					if($debug){
10808
 
10809
						#debug msg
291 liveuser 10810
						echo "Valid ssl for domain name(".$cName.") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
281 liveuser 10811
 
10812
						}#if end
10813
 
291 liveuser 10814
					#debug
10815
					#var_dump($expiresIn);exit;
10816
 
255 liveuser 10817
					#另存舊的憑證id,最後要revoke之.
10818
					$oldCsrId=$csrId;
10819
 
281 liveuser 10820
					#if enable debug
10821
					if($debug){
10822
 
10823
						#debug msg
294 liveuser 10824
						echo "Start request new ssl process for domain name(".$cName.").".PHP_EOL;
281 liveuser 10825
 
10826
						}#if end
10827
 
10828
					#if enable debug
10829
					if($debug){
10830
 
10831
						#debug msg
291 liveuser 10832
						echo "Finding ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10833
 
10834
						}#if end
10835
 
255 liveuser 10836
					#確認有無對應 cName 的 private key
10837
					#函式說明:
10838
					#檢查多個檔案與資料夾是否存在.
10839
					#回傳的結果:
10840
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
10841
					#$result["error"],錯誤訊息陣列.
10842
					#$resutl["function"],當前執行的涵式名稱.
10843
					#$result["argu"],使用的參數.
10844
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
10845
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
10846
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
10847
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
10848
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
10849
					#必填參數:
10850
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
291 liveuser 10851
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 10852
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10853
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
10854
					#可省略參數:
10855
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
10856
					#$conf["disableWebSearch"]="false";
10857
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
10858
					$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
10859
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
10860
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
10861
					#參考資料:
10862
					#http://php.net/manual/en/function.file-exists.php
10863
					#http://php.net/manual/en/control-structures.foreach.php
10864
					#備註:
10865
					#函數file_exists檢查的路徑為檔案系統的路徑
10866
					#$result["varName"][$i]結果未實作
10867
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
10868
					unset($conf["fileAccess::checkMultiFileExist"]);
10869
 
10870
					#如果運行異常
10871
					if($checkMultiFileExist["status"]==="false"){
10872
 
10873
						#設置錯誤識別
10874
						$result["status"]="false";
10875
 
10876
						#設置錯誤訊息
10877
						$result["error"]=$getCertList;
10878
 
10879
						#回傳結果
10880
						return $result;
10881
 
10882
						}#if end
10883
 
10884
					#如果沒有 private key
10885
					if($checkMultiFileExist["allExist"]==="false"){
10886
 
281 liveuser 10887
						#if enable debug
10888
						if($debug){
10889
 
10890
							#debug msg
291 liveuser 10891
							echo "Thers is no ssl private key for domain name(".$cName.").".PHP_EOL;
281 liveuser 10892
 
10893
							}#if end
10894
 
10895
						#if enable debug
10896
						if($debug){
10897
 
10898
							#debug msg
291 liveuser 10899
							echo "Creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10900
 
10901
							}#if end
10902
 
255 liveuser 10903
						#建立 private key
10904
						#函式說明:
10905
						#產生ssl private key.
10906
						#回傳結果:
10907
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10908
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
10909
						#$result["function"],當前執行的函式名稱.
10910
						#$result["argu"],所使用的參數.
10911
						#$result["curl_verbose_info"],curl執行的詳細資訊.
10912
						#$result["content"],ssl用的private key.
10913
						#必填參數:
10914
						#$conf["fileArgu"],字串,變數__FILE__的內容.
10915
						$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
10916
						#可省略參數:
10917
						#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
10918
						#$conf["length"]=4096';
10919
						#參考資料:
10920
						#無.
10921
						#備註:
10922
						#key generated by openssl with RSA.
291 liveuser 10923
						$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 10924
						unset($conf["openssl::createPrivateKey"]);
10925
 
10926
						#如果運行異常
10927
						if($createPrivateKey["status"]==="false"){
10928
 
10929
							#設置錯誤識別
10930
							$result["status"]="false";
10931
 
10932
							#設置錯誤訊息
10933
							$result["error"]=$createPrivateKey;
10934
 
10935
							#回傳結果
10936
							return $result;
10937
 
10938
							}#if end
10939
 
10940
						#另存private key的字串
10941
						$pKeyStr=$createPrivateKey["content"];
10942
 
281 liveuser 10943
						#if enable debug
10944
						if($debug){
10945
 
10946
							#debug msg
291 liveuser 10947
							echo "Writing ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10948
 
10949
							}#if end
10950
 
255 liveuser 10951
						#建立private key檔案
10952
						#函式說明:
10953
						#將字串寫入到檔案
10954
						#回傳結果:
10955
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10956
						#$result["error"],錯誤訊息陣列.
10957
						#$result["function"],當前執行的函數名稱.
10958
						#$result["fileInfo"],實際上寫入的檔案資訊陣列.
10959
						#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
10960
						#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
10961
						#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
10962
						#$result["argu"],使用的參數.
10963
						#必填參數:
10964
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10965
						$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
10966
						#可省略參數:
10967
						#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
291 liveuser 10968
						$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 10969
						#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
10970
						$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
10971
						#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
10972
						#$conf["writeMethod"]="a";
10973
						#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
10974
						#$conf["checkRepeat"]="";
10975
						#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
10976
						#$conf["filenameExtensionStartPoint"]="";
10977
						#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
10978
						#$conf["repeatNameRule"]="";
10979
						#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
10980
						$conf["zerossl::writeTextIntoFile"]["web"]="false";
10981
						#參考資料:
10982
						#無.
10983
						#備註:
10984
						#無.
10985
						$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
10986
						unset($conf["zerossl::writeTextIntoFile"]);
10987
 
10988
						#如果運行異常
10989
						if($writeTextIntoFile["status"]==="false"){
10990
 
10991
							#設置錯誤識別
10992
							$result["status"]="false";
10993
 
10994
							#設置錯誤訊息
10995
							$result["error"]=$writeTextIntoFile;
10996
 
10997
							#回傳結果
10998
							return $result;
10999
 
11000
							}#if end
11001
 
11002
						}#if end
11003
 
281 liveuser 11004
					#if enable debug
11005
					if($debug){
11006
 
11007
						#debug msg
291 liveuser 11008
						echo "Creating CSR for domain name(".$cName.") to zerossl.".PHP_EOL;
281 liveuser 11009
 
11010
						}#if end
11011
 
255 liveuser 11012
					#建立準備給zerossl的csr
11013
					#函式說明:
11014
					#產生certificate sign request(CSR).
11015
					#回傳結果:
11016
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11017
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11018
					#$result["function"],當前執行的函式名稱.
11019
					#$result["argu"],所使用的參數.
11020
					#$result["content"],csr內容.
11021
					#$result["curl_verbose_info"],curl執行的詳細資訊.
11022
					#$result["privateKey"], private key 的內容.
11023
					#必填參數:
11024
					#$conf["domain"],字串,csr內容的網域名稱.
11025
					$conf["zerossl::createCSR"]["domain"]=$cName;
11026
					#可省略參數:
11027
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 11028
					$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 11029
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
11030
					#$conf["country"]="";
11031
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
11032
					#$conf["state"]="";
11033
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
11034
					#$conf["org"]="";
11035
					#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
11036
					#$conf["unit"]="";
11037
					#參考資料:
11038
					#無.
11039
					#備註:
11040
					#無.
11041
					$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
11042
					unset($conf["zerossl::createCSR"]);
11043
 
11044
					#如果運行異常
11045
					if($createCSR["status"]==="false"){
11046
 
11047
						#設置錯誤識別
11048
						$result["status"]="false";
11049
 
11050
						#設置錯誤訊息
11051
						$result["error"]=$createCSR;
11052
 
11053
						#回傳結果
11054
						return $result;
11055
 
11056
						}#if end
11057
 
11058
					#取得本地端產生的csr內容
11059
					$csrLocal=$createCSR["content"];
11060
 
281 liveuser 11061
					#if enable debug
11062
					if($debug){
11063
 
11064
						#debug msg
291 liveuser 11065
						echo "Providing CSR for domain name(".$cName.") to zerossl".PHP_EOL;
281 liveuser 11066
 
11067
						}#if end
11068
 
255 liveuser 11069
					#函式說明:
281 liveuser 11070
					#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 11071
					#回傳結果:
11072
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11073
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11074
					#$result["function"],當前執行的函式名稱.
11075
					#$result["argu"],所使用的參數.
11076
					#$result["curl_verbose_info"],curl執行的詳細資訊.
11077
					#$result["id"],用於zerossl api驗證domain的id.
11078
					#$result["content"],字串,得到的json字串回應.
11079
					#$result["cnameKey"],用於dns CNAME驗證鍵名.
11080
					#$result["cnameVal"],用於dms CNAME驗證鍵值.
11081
					#必填參數:
11082
					#$conf["certificate_domains"],字串,要簽署的doamin名稱.
11083
					$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
11084
					#$conf["certificate_csr"],字串,簽署的資訊.
11085
					$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
11086
					#$conf["fileArgu"],字串,變數__FILE__的內容.
11087
					$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
11088
					#可省略參數:
11089
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 11090
					$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 11091
					#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
11092
					#$conf["path"]=self::getApiInfo()["csrPath"];
11093
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 11094
					$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 11095
					#參考資料:
11096
					#無.
11097
					#備註:
11098
					#無.
11099
					$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
11100
					unset($conf["zerossl::createCertificate"]);
11101
 
11102
					#如果執行異常
11103
					if($createCertificate["status"]==="false"){
11104
 
11105
						#設置錯誤識別
11106
						$result["status"]="false";
11107
 
11108
						#設置錯誤訊息
11109
						$result["error"]=$createCertificate;
11110
 
11111
						#回傳結果
11112
						return $result;
11113
 
11114
						}#if end
11115
 
11116
					#取得csr在zerossl上的id
11117
					$csrId=$createCertificate["id"];
11118
 
11119
					#取得cname key
11120
					$cNameKey=$createCertificate["cnameKey"];
11121
 
11122
					#取得cname val
11123
					$cNameVal=$createCertificate["cnameVal"];
11124
 
11125
					#初始化要增加的RR記錄
11126
					$rr2add=array();
11127
 
11128
					#設置CNAME的查詢
11129
					$rr2add["query"]=$cNameKey;
11130
 
11131
					#設置CNAME的value
11132
					$rr2add["value"]=$cNameVal;
11133
 
11134
					#設置類型為 CNAME
11135
					$rr2add["type"]="CNAME";
11136
 
11137
					#設置註解
11138
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
11139
 
281 liveuser 11140
					#if enable debug
11141
					if($debug){
11142
 
11143
						#debug msg
335 liveuser 11144
						echo "Adding DNS record to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 11145
 
11146
						}#if end
11147
 
255 liveuser 11148
					#函式說明:
11149
					#新增DNS記錄到檔案裡面.
11150
					#回傳結果:
11151
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11152
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11153
					#$result["function"],當前執行的函式名稱.
11154
					#$result["argu"],所使用的參數.
11155
					#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
11156
					#$result["domain"],字串,RR所屬domain.
11157
					#$result["defaultTTL"],字串,預設的RR更新時間.
11158
					#$result["comment"],字串陣列,逐行的註解.
11159
					#必填參數:
11160
					#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
333 liveuser 11161
					$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 11162
					#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
11163
					$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
11164
					#可省略參數:
11165
					#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
11166
					$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
11167
					#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
11168
					#$conf["debug"]="false";
11169
					#參考資料:
11170
					#無.
11171
					#備註:
11172
					#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
11173
					#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
11174
					#php-pear上的Net_DNS2也可以解析RR.
11175
					$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
11176
					unset($conf["zerossl::updateDnsRecordFile"]);
11177
 
11178
					#如果執行異常
11179
					if($updateDnsRecordFile["status"]==="false"){
11180
 
11181
						#設置錯誤識別
11182
						$result["status"]="false";
11183
 
11184
						#設置錯誤訊息
11185
						$result["error"]=$updateDnsRecordFile;
11186
 
11187
						#回傳結果
11188
						return $result;
11189
 
11190
						}#if end
281 liveuser 11191
 
11192
					#if enable debug
11193
					if($debug){
11194
 
11195
						#debug msg
336 liveuser 11196
						echo "Restarting DNS service to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 11197
 
11198
						}#if end
11199
 
255 liveuser 11200
					#重新啟動dns伺服器
11201
					#函式說明:
11202
					#呼叫shell執行系統命令,並取得回傳的內容.
11203
					#回傳結果:
11204
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11205
					#$result["error"],錯誤訊息陣列.
11206
					#$result["function"],當前執行的函數名稱.
11207
					#$result["argu"],使用的參數.
11208
					#$result["cmd"],執行的指令內容.
11209
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11210
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11211
					#$result["content"],為執行完後的輸出字串.
11212
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11213
					#$result["running"],是否還在執行.
11214
					#$result["pid"],pid.
11215
					#$result["statusCode"],執行結束後的代碼.
11216
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11217
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11218
					#必填參數:
11219
					#$conf["command"],字串,要執行的指令.
291 liveuser 11220
					$conf["external::callShell"]["command"]="systemctl";
255 liveuser 11221
					#$conf["fileArgu"],字串,變數__FILE__的內容.
11222
					$conf["external::callShell"]["fileArgu"]=__FILE__;
11223
					#可省略參數:
11224
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11225
					$conf["external::callShell"]["argu"]=array("restart","named");
11226
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11227
					#$conf["arguIsAddr"]=array();
11228
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11229
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11230
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11231
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11232
					#$conf["enablePrintDescription"]="true";
11233
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11234
					#$conf["printDescription"]="";
11235
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11236
					#$conf["escapeshellarg"]="false";
11237
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11238
					#$conf["thereIsShellVar"]=array();
11239
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11240
					#$conf["username"]="";
11241
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11242
					#$conf["password"]="";
11243
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11244
					#$conf["useScript"]="";
11245
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11246
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11247
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11248
					#$conf["inBackGround"]="";
11249
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11250
					#$conf["getErr"]="false";
11251
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11252
					#$conf["doNotRun"]="false";
302 liveuser 11253
					#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
11254
					#$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 11255
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
11256
					$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
11257
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
11258
					#$conf["remoteUser"]="root";
11259
					#參考資料:
11260
					#exec=>http://php.net/manual/en/function.exec.php
11261
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11262
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11263
					#備註:
11264
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11265
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11266
					$callShell=external::callShell($conf["external::callShell"]);
11267
					unset($conf["external::callShell"]);
11268
 
11269
					#如果執行異常
11270
					if($callShell["status"]==="false"){
11271
 
11272
						#設置錯誤識別
11273
						$result["status"]="false";
11274
 
11275
						#設置錯誤訊息
11276
						$result["error"]=$callShell;
11277
 
11278
						#回傳結果
11279
						return $result;
11280
 
11281
						}#if end
281 liveuser 11282
 
11283
					#if enable debug
11284
					if($debug){
11285
 
11286
						#debug msg
336 liveuser 11287
						echo "Request zerossl to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 11288
 
11289
						}#if end
11290
 
294 liveuser 11291
					#無窮迴圈
11292
					while(true){
255 liveuser 11293
 
294 liveuser 11294
						#函式說明:
11295
						#請求驗證已經透過zerossl::createCertificate要求的domain.
11296
						#回傳結果:
11297
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11298
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
11299
						#$result["function"],當前執行的函式名稱.
11300
						#$result["argu"],所使用的參數.
11301
						#$result["curl_verbose_info"],curl執行的詳細資訊.
11302
						#$result["content"],結果json字串.
11303
						#必填參數:
11304
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
11305
						$conf["zerossl::verifyDomain"]["id"]=$csrId;
11306
						#可省略參數:
11307
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
11308
						$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
11309
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
11310
						$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
11311
						#參考資料:
11312
						#https://zerossl.com/documentation/api/verify-domains/
11313
						#備註:
11314
						#無.
11315
						$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
11316
						unset($conf["zerossl::verifyDomain"]);
11317
 
11318
						#如果執行異常
11319
						if($verifyDomain["status"]==="false"){
11320
 
11321
							#設置錯誤識別
11322
							$result["status"]="false";
255 liveuser 11323
 
294 liveuser 11324
							#設置錯誤訊息
11325
							$result["error"]=$verifyDomain;
255 liveuser 11326
 
294 liveuser 11327
							#回傳結果
11328
							return $result;
11329
 
11330
							}#if end
11331
 
11332
						#如果沒有回內容
11333
						if(!isset($verifyDomain["content"])){
11334
 
11335
							#設置錯誤識別
11336
							$result["status"]="false";
11337
 
11338
							#設置錯誤訊息
11339
							$result["error"]=$verifyDomain;
11340
 
11341
							#回傳結果
11342
							return $result;
11343
 
11344
							}#if end
11345
 
11346
						#如果回應不是 json
11347
						if(!(json_validate($verifyDomain["content"]))){
11348
 
11349
							#設置錯誤識別
11350
							$result["status"]="false";
11351
 
11352
							#設置錯誤訊息
11353
							$result["error"]=$verifyDomain;
11354
 
11355
							#回傳結果
11356
							return $result;
11357
 
11358
							}#if end
11359
 
11360
						/*
11361
						範例json:
11362
						{"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}
11363
						*/
11364
 
11365
						#解析json回應
11366
						$verifyDomainRes=json_decode($verifyDomain["content"]);
11367
 
11368
						#如果回應含有 success
11369
						if(isset($verifyDomainRes->success)){
11370
 
11371
							#如果是 zerossl 驗證失敗
11372
							if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
11373
 
11374
								#如果是 CNAME 記錄找不到
11375
								if($verifyDomainRes->error->code===0){
11376
 
11377
									#取得錯誤訊息
11378
									#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
11379
 
11380
									#if enable debug
11381
									if($debug){
11382
 
11383
										#debug msg
11384
										echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
11385
 
11386
										}#if end
11387
 
11388
									#if enable debug
11389
									if($debug){
11390
 
11391
										#debug msg
11392
										echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
11393
 
11394
										}#if end
11395
 
11396
									#休息60秒
11397
									sleep(60);
11398
 
11399
									#再跑一次要求認證憑證
11400
									continue;
11401
 
11402
									}#if end
11403
 
11404
								#反之為不接受的錯誤訊息
11405
								else{
11406
 
11407
									#設置錯誤識別
11408
									$result["status"]="false";
11409
 
11410
									#設置錯誤訊息
11411
									$result["error"]=$verifyDomain;
11412
 
11413
									#回傳結果
11414
									return $result;
11415
 
11416
									}#else end
11417
 
11418
								}#if end
11419
 
11420
							}#if end
11421
 
11422
						#反之如果回應含有 status
11423
						else if(isset($verifyDomainRes->status)){
11424
 
11425
							#如果是 zerossl 尚在驗證中
11426
							if($verifyDomainRes->status==="pending_validation"){
11427
 
11428
								#if enable debug
11429
								if($debug){
11430
 
11431
									#debug msg
11432
									echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
11433
 
11434
									}#if end
11435
 
11436
								#無窮迴圈
11437
								while(true){
11438
 
11439
									#查詢驗證狀況
11440
									#函式說明:
11441
									#取得CSR在zerossl上的狀態
11442
									#回傳結果:
11443
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11444
									#$reuslt["error"],執行不正常結束的錯訊息陣列.
11445
									#$result["function"],當前執行的函式名稱.
11446
									#$result["argu"],所使用的參數.
11447
									#$result["curl_verbose_info"],curl執行的詳細資訊.
11448
									#$result["content"],結果json字串.
11449
									#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
11450
									#必填參數:
11451
									#$conf["id"],字串,zerossl::createCertificate回傳的id.
11452
									$conf["zerossl::getCertSta"]["id"]=$csrId;
11453
									#可省略參數:
11454
									#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
11455
									$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
11456
									#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
11457
									$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
11458
									#參考資料:
11459
									#https://zerossl.com/documentation/api/get-certificate/
11460
									#備註:
11461
									#無.
11462
									$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
11463
									unset($conf["zerossl::getCertSta"]);
11464
 
11465
									#如果執行異常
11466
									if($getCertSta["status"]==="false"){
11467
 
11468
										#設置錯誤識別
11469
										$result["status"]="false";
11470
 
11471
										#設置錯誤訊息
11472
										$result["error"]=$getCertSta;
11473
 
11474
										#回傳結果
11475
										return $result;
11476
 
11477
										}#if end
11478
 
11479
									#如果沒有回應內容
11480
									if(!isset($getCertSta["content"])){
11481
 
11482
										#設置錯誤識別
11483
										$result["status"]="false";
11484
 
11485
										#設置錯誤訊息
11486
										$result["error"]=$getCertSta;
11487
 
11488
										#回傳結果
11489
										return $result;
11490
 
11491
										}#if end
11492
 
11493
									#如果回應不是 json
11494
									if(!(json_validate($getCertSta["content"]))){
11495
 
11496
										#設置錯誤識別
11497
										$result["status"]="false";
11498
 
11499
										#設置錯誤訊息
11500
										$result["error"]=$getCertSta;
11501
 
11502
										#回傳結果
11503
										return $result;
11504
 
11505
										}#if end
11506
 
11507
									#解析json回應
11508
									$getCertStaRes=json_decode($getCertSta["content"]);
11509
 
11510
									#如果憑證已經驗證通過了
11511
									if($getCertStaRes->status==="issued"){
11512
 
11513
										#if enable debug
11514
										if($debug){
11515
 
11516
											#debug msg
11517
											echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
11518
 
11519
											}#if end
11520
 
11521
										#結束等待,離開while
11522
										break 2;
11523
 
11524
										}#if end
11525
 
11526
									#如果 zerossl 尚在處理中
11527
									else if($getCertStaRes->status==="pending_validation"){
11528
 
11529
										#if enable debug
11530
										if($debug){
11531
 
11532
											#debug msg
11533
											echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
11534
 
11535
											}#if end
11536
 
11537
										#休息1分鐘
11538
										sleep(60);
11539
 
11540
										#再次確認憑證的狀態
11541
										continue;
11542
 
11543
										}#if end
11544
 
11545
									#反之
11546
									else{
11547
 
11548
										#例外狀況
11549
 
11550
										#設置錯誤識別
11551
										$result["status"]="false";
11552
 
11553
										#設置錯誤訊息
11554
										$result["error"]=$getCertSta;
11555
 
11556
										#回傳結果
11557
										return $result;
11558
 
11559
										}#else end
11560
 
11561
									}#while end
11562
 
11563
								}#if end
11564
 
11565
							}#if end
255 liveuser 11566
 
294 liveuser 11567
						}#while end
281 liveuser 11568
 
294 liveuser 11569
 
281 liveuser 11570
					#if enable debug
11571
					if($debug){
11572
 
11573
						#debug msg
291 liveuser 11574
						echo "Downling ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 11575
 
11576
						}#if end
11577
 
255 liveuser 11578
					#函式說明:
11579
					#下載certificate.
11580
					#回傳結果:
11581
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11582
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11583
					#$result["function"],當前執行的函式名稱.
11584
					#$result["argu"],所使用的參數.
11585
					#$result["curl_verbose_info"],curl執行的詳細資訊.
11586
					#$result["content"],結果json字串.
11587
					#$result["certificate.crt"],字串,certificate.crt的內容.
11588
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
11589
					#必填參數:
11590
					#無.
11591
					#可省略參數:
11592
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 11593
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 11594
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 11595
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 11596
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
11597
					$conf["zerossl::getCert"]["id"]=$csrId;
11598
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
11599
					#$conf["zerossl::getCert"]["cname"]="";
11600
					#參考資料:
11601
					#https://zerossl.com/documentation/api/download-certificate-inline/
11602
					#備註:
11603
					#無.
11604
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
11605
					unset($conf["zerossl::getCert"]);
11606
 
11607
					#如果執行異常
11608
					if($getCert["status"]==="false"){
11609
 
11610
						#設置錯誤識別
11611
						$result["status"]="false";
11612
 
11613
						#設置錯誤訊息
11614
						$result["error"]=$getCert;
11615
 
11616
						#回傳結果
11617
						return $result;
11618
 
11619
						}#if end
281 liveuser 11620
 
11621
					#if enable debug
11622
					if($debug){
11623
 
11624
						#debug msg
291 liveuser 11625
						echo "Creating ssl for domain name(".$cName.").".PHP_EOL;
281 liveuser 11626
 
11627
						}#if end
11628
 
255 liveuser 11629
					#建立 certificate.crt 檔案
11630
					#$cInfo["certPath"];
11631
 
11632
					#建立 ca_bundle.crt 檔案
11633
					#$cInfo["caPath"];
11634
 
11635
					#建立 certAndCa.crt 檔案
11636
					#$cInfo["certWithCaPath"];
11637
 
11638
					#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
11639
					#函式說明:
11640
					#一次建立多個檔案,並寫入內容.
11641
					#回傳結果:
11642
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
11643
					#$result["error"],錯誤訊息陣列.
11644
					#$result["function"],當前執行的函數名稱.
11645
					#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
11646
					#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
11647
					#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
11648
					#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
11649
					#$result["argu"],使用的參數.
11650
					#必填參數:
11651
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11652
					$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
11653
					#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 11654
					$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 11655
					#可省略參數:
11656
					#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
11657
					$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
11658
					#參考資料:
11659
					#無.
11660
					#備註:
11661
					#無.
333 liveuser 11662
					$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 11663
					unset($conf["zerossl::writeMultiFile"]);
11664
 
11665
					#如果執行異常
11666
					if($writeMultiFile["status"]==="false"){
11667
 
11668
						#設置錯誤識別
11669
						$result["status"]="false";
11670
 
11671
						#設置錯誤訊息
11672
						$result["error"]=$writeMultiFile;
11673
 
11674
						#回傳結果
11675
						return $result;
11676
 
11677
						}#if end
11678
 
11679
					#儲存 actionAfterUpdateCert
11680
					$action=$cInfo["actionAfterUpdateCert"];
11681
 
11682
					#如果有多個指令要執行
294 liveuser 11683
					if(count($action)>0){
255 liveuser 11684
 
281 liveuser 11685
						#if enable debug
11686
						if($debug){
11687
 
11688
							#debug msg
338 liveuser 11689
							echo "There many cmd to run to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 11690
 
11691
							}#if end
11692
 
294 liveuser 11693
						#針對每個指令
255 liveuser 11694
						foreach($action as $ac){
11695
 
281 liveuser 11696
							#if enable debug
11697
							if($debug){
11698
 
11699
								#debug msg
11700
								echo ".".PHP_EOL;
11701
 
11702
								}#if end
11703
 
255 liveuser 11704
							#函式說明:
11705
							#呼叫shell執行系統命令,並取得回傳的內容.
11706
							#回傳結果:
11707
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11708
							#$result["error"],錯誤訊息陣列.
11709
							#$result["function"],當前執行的函數名稱.
11710
							#$result["argu"],使用的參數.
11711
							#$result["cmd"],執行的指令內容.
11712
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11713
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11714
							#$result["content"],為執行完後的輸出字串.
11715
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11716
							#$result["running"],是否還在執行.
11717
							#$result["pid"],pid.
11718
							#$result["statusCode"],執行結束後的代碼.
11719
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11720
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11721
							#必填參數:
11722
							#$conf["command"],字串,要執行的指令.
302 liveuser 11723
							$conf["external::callShell"]["command"]=$ac;
255 liveuser 11724
							#$conf["fileArgu"],字串,變數__FILE__的內容.
11725
							$conf["external::callShell"]["fileArgu"]=__FILE__;
11726
							#可省略參數:
11727
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 11728
							#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 11729
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11730
							#$conf["arguIsAddr"]=array();
11731
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11732
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11733
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11734
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11735
							#$conf["enablePrintDescription"]="true";
11736
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11737
							#$conf["printDescription"]="";
11738
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11739
							$conf["external::callShell"]["escapeshellarg"]="true";
11740
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11741
							#$conf["thereIsShellVar"]=array();
11742
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11743
							#$conf["username"]="";
11744
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11745
							#$conf["password"]="";
11746
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11747
							#$conf["useScript"]="";
11748
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11749
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11750
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11751
							#$conf["inBackGround"]="";
11752
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11753
							#$conf["getErr"]="false";
11754
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11755
							#$conf["doNotRun"]="false";
302 liveuser 11756
							#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
11757
							$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 11758
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
11759
							#$conf["remoteIp"]="";
11760
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
11761
							#$conf["remoteUser"]="";
11762
							#參考資料:
11763
							#exec=>http://php.net/manual/en/function.exec.php
11764
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11765
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11766
							#備註:
11767
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11768
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11769
							$callShell=external::callShell($conf["external::callShell"]);
11770
							unset($conf["external::callShell"]);
294 liveuser 11771
 
255 liveuser 11772
							#如果執行異常
294 liveuser 11773
							if($callShell["status"]==="false"){
255 liveuser 11774
 
11775
								#設置錯誤識別
11776
								$result["status"]="false";
11777
 
11778
								#設置錯誤訊息
11779
								$result["error"]=$callShell;
11780
 
11781
								#回傳結果
11782
								return $result;
11783
 
11784
								}#if end
11785
 
11786
							}#foreach end
11787
 
11788
						}#if end
11789
 
11790
					#反之
11791
					else{
11792
 
281 liveuser 11793
						#if enable debug
11794
						if($debug){
11795
 
11796
							#debug msg
291 liveuser 11797
							echo "There is only one cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 11798
 
11799
							}#if end
11800
 
11801
						#if enable debug
11802
						if($debug){
11803
 
11804
							#debug msg
11805
							echo ".".PHP_EOL;
11806
 
11807
							}#if end
11808
 
255 liveuser 11809
						#函式說明:
11810
						#呼叫shell執行系統命令,並取得回傳的內容.
11811
						#回傳結果:
11812
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11813
						#$result["error"],錯誤訊息陣列.
11814
						#$result["function"],當前執行的函數名稱.
11815
						#$result["argu"],使用的參數.
11816
						#$result["cmd"],執行的指令內容.
11817
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11818
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11819
						#$result["content"],為執行完後的輸出字串.
11820
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11821
						#$result["running"],是否還在執行.
11822
						#$result["pid"],pid.
11823
						#$result["statusCode"],執行結束後的代碼.
11824
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11825
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11826
						#必填參數:
11827
						#$conf["command"],字串,要執行的指令.
302 liveuser 11828
						$conf["external::callShell"]["command"]=$action[0];
255 liveuser 11829
						#$conf["fileArgu"],字串,變數__FILE__的內容.
11830
						$conf["external::callShell"]["fileArgu"]=__FILE__;
11831
						#可省略參數:
11832
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 11833
						#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 11834
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11835
						#$conf["arguIsAddr"]=array();
11836
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11837
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11838
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11839
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11840
						#$conf["enablePrintDescription"]="true";
11841
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11842
						#$conf["printDescription"]="";
11843
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11844
						$conf["external::callShell"]["escapeshellarg"]="true";
11845
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11846
						#$conf["thereIsShellVar"]=array();
11847
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11848
						#$conf["username"]="";
11849
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11850
						#$conf["password"]="";
11851
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11852
						#$conf["useScript"]="";
11853
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11854
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11855
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11856
						#$conf["inBackGround"]="";
11857
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11858
						#$conf["getErr"]="false";
11859
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11860
						#$conf["doNotRun"]="false";
302 liveuser 11861
						#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
11862
						$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 11863
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
11864
						#$conf["remoteIp"]="";
11865
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
11866
						#$conf["remoteUser"]="";
11867
						#參考資料:
11868
						#exec=>http://php.net/manual/en/function.exec.php
11869
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11870
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11871
						#備註:
11872
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11873
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11874
						$callShell=external::callShell($conf["external::callShell"]);
11875
						unset($conf["external::callShell"]);
294 liveuser 11876
 
255 liveuser 11877
						#如果執行異常
294 liveuser 11878
						if($callShell["status"]==="false"){
255 liveuser 11879
 
11880
							#設置錯誤識別
11881
							$result["status"]="false";
11882
 
11883
							#設置錯誤訊息
11884
							$result["error"]=$callShell;
11885
 
11886
							#回傳結果
11887
							return $result;
11888
 
11889
							}#if end
11890
 
11891
						}#else end
11892
 
11893
					#要移除舊的憑證 
11894
 
281 liveuser 11895
					#if enable debug
11896
					if($debug){
11897
 
11898
						#debug msg
341 liveuser 11899
						echo "Revoke old ssl(".$conf["info"]["share"]["apiDomain"].") on zerossl".PHP_EOL;
281 liveuser 11900
 
11901
						}#if end
11902
 
255 liveuser 11903
					#舊憑證於zerossl上的id
11904
					#$oldCsrId
11905
 
341 liveuser 11906
					#無窮迴圈
11907
					while(true){
255 liveuser 11908
 
341 liveuser 11909
						#移除舊的憑證
11910
						#函式說明:
11911
						#請求廢除 issued zerossl certificate.
11912
						#回傳結果:
11913
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11914
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
11915
						#$result["function"],當前執行的函式名稱.
11916
						#$result["argu"],所使用的參數.
11917
						#$result["curl_verbose_info"],curl執行的詳細資訊.
11918
						#$result["content"],結果json字串.
11919
						#$result["busy"],若content結果含有busy屬性,且為1,則為"true";反之為"false".
11920
						#必填參數:
11921
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
11922
						$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
11923
						#可省略參數:
11924
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
11925
						$conf["zerosssl::revokeCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
11926
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
11927
						$conf["zerosssl::revokeCert"]["key"]=$conf["info"]["share"]["key"];
11928
						#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
11929
						$conf["zerosssl::revokeCert"]["reason"]="Superseded";
11930
						#參考資料:
11931
						#https://zerossl.com/documentation/api/revoke-certificate/
11932
						#備註:
11933
						#無.
11934
						$revokeCert=zerossl::revokeCert($conf["zerosssl::revokeCert"]);
11935
						unset($conf["zerosssl::revokeCert"]);
11936
 
11937
						#如果執行異常
11938
						if($revokeCert["status"]==="false"){
11939
 
11940
							#如果是 api endpoint busy
11941
							if($revokeCert["busy"]==="true"){
11942
 
11943
								#if enable debug
11944
								if($debug){
11945
 
11946
									#debug msg
11947
									echo "Api endpoint busy, retry revoke old ssl(".$conf["info"]["share"]["apiDomain"].") on zerossl in 60 seconds".PHP_EOL;
11948
 
11949
									}#if end
11950
 
11951
								#休息1分鐘
11952
								sleep(60);
11953
 
11954
								#再執行一次
11955
								continue;
11956
 
11957
								}#if end
11958
 
11959
							#設置錯誤識別
11960
							$result["status"]="false";
255 liveuser 11961
 
341 liveuser 11962
							#設置錯誤訊息
11963
							$result["error"]=$revokeCert;
255 liveuser 11964
 
341 liveuser 11965
							#回傳結果
11966
							return $result;
11967
 
11968
							}#if end
11969
 
11970
						#revoke 成功,跳出 while loop.
11971
						break;
11972
 
11973
						}#while end
11974
 
11975
					#if enable debug
11976
					if($debug){
11977
 
11978
						#debug msg
11979
						echo "Old ssl on zerossl(".$conf["info"]["share"]["apiDomain"].") revoked".PHP_EOL;
11980
 
291 liveuser 11981
						}#if end
11982
 
255 liveuser 11983
					}#if end
11984
 
11985
				#反之,尚不需要提前申請新的憑證
11986
				else{
11987
 
291 liveuser 11988
					#debug
11989
					#var_dump(__LINE__,"尚不需要提前申請新的憑證");exit;
11990
 
281 liveuser 11991
					#if enable debug
11992
					if($debug){
11993
 
11994
						#debug msg
291 liveuser 11995
						echo "ssl for domain name(".$cName.") is valid ".PHP_EOL;
281 liveuser 11996
 
11997
						}#if end
11998
 
11999
					#if enable debug
12000
					if($debug){
12001
 
12002
						#debug msg
291 liveuser 12003
						echo "Downling ssl for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 12004
 
12005
						}#if end
12006
 
310 liveuser 12007
					#if enable debug
12008
					if($debug){
12009
 
12010
						#debug msg
12011
						echo "ID for domain name(".$cName.") on zerossl is ".$csrId.".".PHP_EOL;
12012
 
12013
						}#if end
12014
 
255 liveuser 12015
					#下載憑證
12016
					#函式說明:
12017
					#下載certificate.
12018
					#回傳結果:
12019
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12020
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
12021
					#$result["function"],當前執行的函式名稱.
12022
					#$result["argu"],所使用的參數.
12023
					#$result["curl_verbose_info"],curl執行的詳細資訊.
12024
					#$result["content"],結果json字串.
12025
					#$result["certificate.crt"],字串,certificate.crt的內容.
12026
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
12027
					#必填參數:
12028
					#無.
12029
					#可省略參數:
12030
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 12031
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 12032
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 12033
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 12034
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
12035
					$conf["zerossl::getCert"]["id"]=$csrId;
12036
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
12037
					#$conf["zerossl::getCert"]["cname"]="";
12038
					#參考資料:
12039
					#https://zerossl.com/documentation/api/download-certificate-inline/
12040
					#備註:
12041
					#無.
12042
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
12043
					unset($conf["zerossl::getCert"]);
12044
 
12045
					#如果執行異常
12046
					if($getCert["status"]==="false"){
12047
 
12048
						#設置錯誤識別
12049
						$result["status"]="false";
12050
 
12051
						#設置錯誤訊息
12052
						$result["error"]=$getCert;
12053
 
12054
						#回傳結果
12055
						return $result;
12056
 
12057
						}#if end
281 liveuser 12058
 
12059
					#if enable debug
12060
					if($debug){
12061
 
12062
						#debug msg
291 liveuser 12063
						echo "Getting host ssl for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12064
 
12065
						}#if end
12066
 
255 liveuser 12067
					#zerossl上的certificate.crt內容
12068
					#$getCert["certificate.crt"];
310 liveuser 12069
 
255 liveuser 12070
					#zerossl上的ca_bundle.crt內容
12071
					#$getCert["ca_bundle.crt"];
12072
 
12073
					#certificate.crt and ca_bundle.crt 合併後的檔案內容
12074
					#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
12075
 
12076
					#certificate.crt 檔案
12077
					#$cInfo["certPath"];
12078
 
12079
					#ca_bundle.crt 檔案
12080
					#$cInfo["caPath"];
12081
 
12082
					#certAndCa.crt 檔案
12083
					#$cInfo["certWithCaPath"];
281 liveuser 12084
 
12085
					#if enable debug
12086
					if($debug){
12087
 
12088
						#debug msg
310 liveuser 12089
						echo "Getting host ssl(certificate.crt) which path is ".$cInfo["ssl"]["certPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12090
 
12091
						}#if end
255 liveuser 12092
 
12093
					#取得既有的 certificate.crt 檔案內容
12094
					#函式說明:
12095
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
12096
					#回傳的變數說明:
12097
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
12098
					#$result["error"],錯誤訊息提示.
12099
					#$result["warning"],警告訊息.
12100
					#$result["function"],當前執行的函數名稱.
12101
					#$result["fileContent"],爲檔案的內容陣列.
12102
					#$result["lineCount"],爲檔案內容總共的行數.
12103
					#$result["fullContent"],為檔案的完整內容.
12104
					#$result["base64dataOnly"],檔案的base64data.
12105
					#$result["base64data"],為在網頁上給予src參數的數值.
12106
					#$result["mimeType"],為檔案的mime type.
12107
					#必填參數:
12108
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 12109
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certPath"];
255 liveuser 12110
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12111
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
12112
					#可省略參數:
12113
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
12114
					#$conf["web"]="true";
12115
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 12116
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 12117
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
12118
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
12119
					#參考資料:
12120
					#file(),取得檔案內容的行數.
12121
					#file=>http:#php.net/manual/en/function.file.php
12122
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
12123
					#filesize=>http://php.net/manual/en/function.filesize.php
12124
					#參考資料:
12125
					#無.
12126
					#備註:
12127
					#無.
291 liveuser 12128
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 12129
					unset($conf["fileAccesss::getFileContent"]);
12130
 
12131
					#如果執行異常
12132
					if($getFileContent["status"]==="false"){
12133
 
12134
						#設置錯誤識別
12135
						$result["status"]="false";
12136
 
12137
						#設置錯誤訊息
12138
						$result["error"]=$getFileContent;
12139
 
12140
						#回傳結果
12141
						return $result;
12142
 
12143
						}#if end
12144
 
281 liveuser 12145
					#if enable debug
12146
					if($debug){
12147
 
12148
						#debug msg
291 liveuser 12149
						echo "Checking host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12150
 
12151
						}#if end
12152
 
291 liveuser 12153
					#預設 certificate.crt 不用更新
12154
					$certificate_need_update="false";
12155
 
255 liveuser 12156
					#如果既有憑證跟剛下載的憑證不一樣
12157
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
12158
 
12159
						#識別要改成下載好的憑證
12160
						$certificate_need_update="true";
281 liveuser 12161
 
12162
						#if enable debug
12163
						if($debug){
12164
 
12165
							#debug msg
291 liveuser 12166
							echo "SSL(certificate.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 12167
 
12168
							}#if end
255 liveuser 12169
 
12170
						}#if end
281 liveuser 12171
 
12172
					#if enable debug
12173
					if($debug){
12174
 
12175
						#debug msg
310 liveuser 12176
						echo "Getting host ssl(ca_bundle.crt) which path is ".$cInfo["ssl"]["caPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12177
 
12178
						}#if end
12179
 
255 liveuser 12180
					#取得既有的 ca_bundle.crt 檔案內容
12181
					#函式說明:
12182
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
12183
					#回傳的變數說明:
12184
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
12185
					#$result["error"],錯誤訊息提示.
12186
					#$result["warning"],警告訊息.
12187
					#$result["function"],當前執行的函數名稱.
12188
					#$result["fileContent"],爲檔案的內容陣列.
12189
					#$result["lineCount"],爲檔案內容總共的行數.
12190
					#$result["fullContent"],為檔案的完整內容.
12191
					#$result["base64dataOnly"],檔案的base64data.
12192
					#$result["base64data"],為在網頁上給予src參數的數值.
12193
					#$result["mimeType"],為檔案的mime type.
12194
					#必填參數:
12195
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 12196
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["caPath"];
255 liveuser 12197
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12198
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
12199
					#可省略參數:
12200
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
12201
					#$conf["web"]="true";
12202
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 12203
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 12204
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
12205
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
12206
					#參考資料:
12207
					#file(),取得檔案內容的行數.
12208
					#file=>http:#php.net/manual/en/function.file.php
12209
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
12210
					#filesize=>http://php.net/manual/en/function.filesize.php
12211
					#參考資料:
12212
					#無.
12213
					#備註:
12214
					#無.
291 liveuser 12215
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 12216
					unset($conf["fileAccesss::getFileContent"]);
12217
 
12218
					#如果執行異常
12219
					if($getFileContent["status"]==="false"){
12220
 
12221
						#設置錯誤識別
12222
						$result["status"]="false";
12223
 
12224
						#設置錯誤訊息
12225
						$result["error"]=$getFileContent;
12226
 
12227
						#回傳結果
12228
						return $result;
12229
 
12230
						}#if end
12231
 
281 liveuser 12232
					#if enable debug
12233
					if($debug){
12234
 
12235
						#debug msg
291 liveuser 12236
						echo "Checking host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12237
 
12238
						}#if end
12239
 
291 liveuser 12240
					#預設 ca_bundle.crt 不用更新
12241
					$ca_bundle_need_update="false";
12242
 
255 liveuser 12243
					#如果既有憑證跟剛下載的憑證不一樣
12244
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
12245
 
12246
						#識別要改成下載好的憑證
12247
						$ca_bundle_need_update="true";
281 liveuser 12248
 
12249
						#if enable debug
12250
						if($debug){
12251
 
12252
							#debug msg
291 liveuser 12253
							echo "SSL(ca_bundle.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 12254
 
12255
							}#if end
255 liveuser 12256
 
12257
						}#if end
12258
 
281 liveuser 12259
					#if enable debug
12260
					if($debug){
12261
 
12262
						#debug msg
310 liveuser 12263
						echo "Getting host ssl(cert and ca_bundle) which path is ".$cInfo["ssl"]["certWithCaPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12264
 
12265
						}#if end
12266
 
255 liveuser 12267
					#取得既有的 certWithCa 檔案內容
12268
					#函式說明:
12269
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
12270
					#回傳的變數說明:
12271
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
12272
					#$result["error"],錯誤訊息提示.
12273
					#$result["warning"],警告訊息.
12274
					#$result["function"],當前執行的函數名稱.
12275
					#$result["fileContent"],爲檔案的內容陣列.
12276
					#$result["lineCount"],爲檔案內容總共的行數.
12277
					#$result["fullContent"],為檔案的完整內容.
12278
					#$result["base64dataOnly"],檔案的base64data.
12279
					#$result["base64data"],為在網頁上給予src參數的數值.
12280
					#$result["mimeType"],為檔案的mime type.
12281
					#必填參數:
12282
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 12283
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certWithCaPath"];
255 liveuser 12284
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12285
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
12286
					#可省略參數:
12287
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
12288
					#$conf["web"]="true";
12289
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 12290
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 12291
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
12292
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
12293
					#參考資料:
12294
					#file(),取得檔案內容的行數.
12295
					#file=>http:#php.net/manual/en/function.file.php
12296
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
12297
					#filesize=>http://php.net/manual/en/function.filesize.php
12298
					#參考資料:
12299
					#無.
12300
					#備註:
12301
					#無.
291 liveuser 12302
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 12303
					unset($conf["fileAccesss::getFileContent"]);
12304
 
12305
					#如果執行異常
12306
					if($getFileContent["status"]==="false"){
12307
 
12308
						#設置錯誤識別
12309
						$result["status"]="false";
12310
 
12311
						#設置錯誤訊息
12312
						$result["error"]=$getFileContent;
12313
 
12314
						#回傳結果
12315
						return $result;
12316
 
12317
						}#if end
12318
 
281 liveuser 12319
					#if enable debug
12320
					if($debug){
12321
 
12322
						#debug msg
291 liveuser 12323
						echo "Checking host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12324
 
12325
						}#if end
12326
 
291 liveuser 12327
					#預設 cert_and_ca_bundle.crt 不用更新
12328
					$cert_and_ca_bundle_need_update="false";
12329
 
255 liveuser 12330
					#如果既有憑證跟剛下載的憑證不一樣
12331
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
12332
 
12333
						#識別要改成下載好的憑證
12334
						$cert_and_ca_bundle_need_update="true";
281 liveuser 12335
 
12336
						#if enable debug
12337
						if($debug){
12338
 
12339
							#debug msg
291 liveuser 12340
							echo "SSL(cert and ca_bundle) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 12341
 
12342
							}#if end
255 liveuser 12343
 
12344
						}#if end
12345
 
12346
					#預設不需要執行更新憑證後的動作
12347
					$requireActionAfterUpdateCert="false";
12348
 
12349
					#如果 certificate 需要更新
12350
					if($certificate_need_update==="true"){
12351
 
281 liveuser 12352
						#if enable debug
12353
						if($debug){
12354
 
12355
							#debug msg
291 liveuser 12356
							echo "Updating host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12357
 
12358
							}#if end
12359
 
255 liveuser 12360
						#更新之
12361
						#函式說明:
12362
						#一次建立多個檔案,並寫入內容.
12363
						#回傳結果:
12364
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
12365
						#$result["error"],錯誤訊息陣列.
12366
						#$result["function"],當前執行的函數名稱.
12367
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
12368
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
12369
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
12370
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
12371
						#$result["argu"],使用的參數.
12372
						#必填參數:
12373
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12374
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
12375
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 12376
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"]);
255 liveuser 12377
						#可省略參數:
12378
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
12379
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
12380
						#參考資料:
12381
						#無.
12382
						#備註:
12383
						#無.
291 liveuser 12384
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 12385
						unset($conf["zerossl::writeMultiFile"]);
12386
 
12387
						#如果執行異常
12388
						if($writeMultiFile["status"]==="false"){
12389
 
12390
							#設置錯誤識別
12391
							$result["status"]="false";
12392
 
12393
							#設置錯誤訊息
12394
							$result["error"]=$writeMultiFile;
12395
 
12396
							#回傳結果
12397
							return $result;
12398
 
12399
							}#if end
293 liveuser 12400
 
12401
						#設置需要執行指令來生效憑證
12402
						$requireActionAfterUpdateCert="true";
255 liveuser 12403
 
12404
						}#if end
12405
 
12406
					#如果 ca_bunle 需要更新
12407
					if($ca_bundle_need_update==="true"){
12408
 
281 liveuser 12409
						#if enable debug
12410
						if($debug){
12411
 
12412
							#debug msg
291 liveuser 12413
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12414
 
12415
							}#if end
293 liveuser 12416
 
12417
						#設置需要執行指令來生效憑證
12418
						$requireActionAfterUpdateCert="true";
281 liveuser 12419
 
255 liveuser 12420
						#更新之
12421
						#函式說明:
12422
						#一次建立多個檔案,並寫入內容.
12423
						#回傳結果:
12424
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
12425
						#$result["error"],錯誤訊息陣列.
12426
						#$result["function"],當前執行的函數名稱.
12427
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
12428
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
12429
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
12430
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
12431
						#$result["argu"],使用的參數.
12432
						#必填參數:
12433
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12434
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
12435
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 12436
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["caPath"]);
255 liveuser 12437
						#可省略參數:
12438
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
12439
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
12440
						#參考資料:
12441
						#無.
12442
						#備註:
12443
						#無.
291 liveuser 12444
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 12445
						unset($conf["zerossl::writeMultiFile"]);
12446
 
12447
						#如果執行異常
12448
						if($writeMultiFile["status"]==="false"){
12449
 
12450
							#設置錯誤識別
12451
							$result["status"]="false";
12452
 
12453
							#設置錯誤訊息
12454
							$result["error"]=$writeMultiFile;
12455
 
12456
							#回傳結果
12457
							return $result;
12458
 
12459
							}#if end
293 liveuser 12460
 
12461
						#設置需要執行指令來生效憑證
12462
						$requireActionAfterUpdateCert="true";
255 liveuser 12463
 
12464
						}#if end
12465
 
12466
					#如果 certificate and ca_bundle 需要更新
12467
					if($cert_and_ca_bundle_need_update==="true"){
12468
 
281 liveuser 12469
						#if enable debug
12470
						if($debug){
12471
 
12472
							#debug msg
291 liveuser 12473
							echo "Updating host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12474
 
12475
							}#if end
12476
 
255 liveuser 12477
						#更新之
12478
						#函式說明:
12479
						#一次建立多個檔案,並寫入內容.
12480
						#回傳結果:
12481
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
12482
						#$result["error"],錯誤訊息陣列.
12483
						#$result["function"],當前執行的函數名稱.
12484
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
12485
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
12486
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
12487
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
12488
						#$result["argu"],使用的參數.
12489
						#必填參數:
12490
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12491
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
12492
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 12493
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certWithCaPath"]);
255 liveuser 12494
						#可省略參數:
12495
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
12496
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
12497
						#參考資料:
12498
						#無.
12499
						#備註:
12500
						#無.
291 liveuser 12501
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 12502
						unset($conf["zerossl::writeMultiFile"]);
12503
 
12504
						#如果執行異常
12505
						if($writeMultiFile["status"]==="false"){
12506
 
12507
							#設置錯誤識別
12508
							$result["status"]="false";
12509
 
12510
							#設置錯誤訊息
12511
							$result["error"]=$writeMultiFile;
12512
 
12513
							#回傳結果
12514
							return $result;
12515
 
12516
							}#if end
12517
 
293 liveuser 12518
						#設置需要執行指令來生效憑證
12519
						$requireActionAfterUpdateCert="true";
12520
 
255 liveuser 12521
						}#if end
12522
 
12523
					#如果有需要執行指令來生效憑證
12524
					if($requireActionAfterUpdateCert==="true"){
12525
 
281 liveuser 12526
						#if enable debug
12527
						if($debug){
12528
 
12529
							#debug msg
291 liveuser 12530
							echo "Action required to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 12531
 
12532
							}#if end
12533
 
255 liveuser 12534
						#儲存 actionAfterUpdateCert
12535
						$action=$cInfo["actionAfterUpdateCert"];
12536
 
12537
						#如果有多個指令要執行
310 liveuser 12538
						if(count($action)>0){
255 liveuser 12539
 
281 liveuser 12540
							#if enable debug
12541
							if($debug){
12542
 
12543
								#debug msg
291 liveuser 12544
								echo "There are many cmds to run to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 12545
 
12546
								}#if end
12547
 
255 liveuser 12548
							#針對每的指令
12549
							foreach($action as $ac){
12550
 
281 liveuser 12551
								#if enable debug
12552
								if($debug){
12553
 
12554
									#debug msg
12555
									echo ".".PHP_EOL;
12556
 
12557
									}#if end
293 liveuser 12558
 
12559
								#函式說明:
255 liveuser 12560
								#呼叫shell執行系統命令,並取得回傳的內容.
12561
								#回傳結果:
12562
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12563
								#$result["error"],錯誤訊息陣列.
12564
								#$result["function"],當前執行的函數名稱.
12565
								#$result["argu"],使用的參數.
12566
								#$result["cmd"],執行的指令內容.
12567
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12568
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12569
								#$result["content"],為執行完後的輸出字串.
12570
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12571
								#$result["running"],是否還在執行.
12572
								#$result["pid"],pid.
12573
								#$result["statusCode"],執行結束後的代碼.
12574
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12575
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12576
								#必填參數:
12577
								#$conf["command"],字串,要執行的指令.
302 liveuser 12578
								$conf["external::callShell"]["command"]=$ac;
255 liveuser 12579
								#$conf["fileArgu"],字串,變數__FILE__的內容.
12580
								$conf["external::callShell"]["fileArgu"]=__FILE__;
12581
								#可省略參數:
12582
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 12583
								#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
255 liveuser 12584
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12585
								#$conf["arguIsAddr"]=array();
12586
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
12587
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
12588
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
12589
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12590
								#$conf["enablePrintDescription"]="true";
12591
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
12592
								#$conf["printDescription"]="";
12593
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
12594
								$conf["external::callShell"]["escapeshellarg"]="true";
12595
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
12596
								#$conf["thereIsShellVar"]=array();
12597
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12598
								#$conf["username"]="";
12599
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12600
								#$conf["password"]="";
12601
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12602
								#$conf["useScript"]="";
12603
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12604
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12605
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12606
								#$conf["inBackGround"]="";
12607
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
12608
								#$conf["getErr"]="false";
12609
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
12610
								#$conf["doNotRun"]="false";
302 liveuser 12611
								#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
12612
								$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 12613
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
12614
								#$conf["remoteIp"]="";
12615
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
12616
								#$conf["remoteUser"]="";
12617
								#參考資料:
12618
								#exec=>http://php.net/manual/en/function.exec.php
12619
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12620
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12621
								#備註:
12622
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12623
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
12624
								$callShell=external::callShell($conf["external::callShell"]);
12625
								unset($conf["external::callShell"]);
12626
 
12627
								#如果執行異常
310 liveuser 12628
								if($callShell["status"]==="false"){
255 liveuser 12629
 
12630
									#設置錯誤識別
12631
									$result["status"]="false";
12632
 
12633
									#設置錯誤訊息
12634
									$result["error"]=$callShell;
12635
 
12636
									#回傳結果
12637
									return $result;
12638
 
12639
									}#if end
12640
 
12641
								}#foreach end
12642
 
12643
							}#if end
12644
 
291 liveuser 12645
						#反之
12646
						else{
12647
 
12648
							#if enable debug
12649
							if($debug){
12650
 
12651
								#debug msg
12652
								echo "There is only one cmd to run to apply ssl for domain name(".$cName.")".PHP_EOL;
255 liveuser 12653
 
291 liveuser 12654
								}#if end
281 liveuser 12655
 
291 liveuser 12656
							#函式說明:
12657
							#呼叫shell執行系統命令,並取得回傳的內容.
12658
							#回傳結果:
12659
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12660
							#$result["error"],錯誤訊息陣列.
12661
							#$result["function"],當前執行的函數名稱.
12662
							#$result["argu"],使用的參數.
12663
							#$result["cmd"],執行的指令內容.
12664
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12665
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12666
							#$result["content"],為執行完後的輸出字串.
12667
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12668
							#$result["running"],是否還在執行.
12669
							#$result["pid"],pid.
12670
							#$result["statusCode"],執行結束後的代碼.
12671
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12672
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12673
							#必填參數:
12674
							#$conf["command"],字串,要執行的指令.
302 liveuser 12675
							$conf["external::callShell"]["command"]=$action;
291 liveuser 12676
							#$conf["fileArgu"],字串,變數__FILE__的內容.
12677
							$conf["external::callShell"]["fileArgu"]=__FILE__;
12678
							#可省略參數:
12679
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 12680
							#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
291 liveuser 12681
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12682
							#$conf["arguIsAddr"]=array();
12683
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
12684
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
12685
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
12686
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12687
							#$conf["enablePrintDescription"]="true";
12688
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
12689
							#$conf["printDescription"]="";
12690
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
12691
							$conf["external::callShell"]["escapeshellarg"]="true";
12692
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
12693
							#$conf["thereIsShellVar"]=array();
12694
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12695
							#$conf["username"]="";
12696
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12697
							#$conf["password"]="";
12698
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12699
							#$conf["useScript"]="";
12700
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12701
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12702
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12703
							#$conf["inBackGround"]="";
12704
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
12705
							#$conf["getErr"]="false";
12706
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
12707
							#$conf["doNotRun"]="false";
302 liveuser 12708
							#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
12709
							$conf["external::callShell"]["cmdContainArgu"]="true";
291 liveuser 12710
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
12711
							#$conf["remoteIp"]="";
12712
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
12713
							#$conf["remoteUser"]="";
12714
							#參考資料:
12715
							#exec=>http://php.net/manual/en/function.exec.php
12716
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12717
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12718
							#備註:
12719
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12720
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
12721
							$callShell=external::callShell($conf["external::callShell"]);
12722
							unset($conf["external::callShell"]);
12723
 
12724
							#如果執行異常
310 liveuser 12725
							if($callShell["status"]==="false"){
255 liveuser 12726
 
291 liveuser 12727
								#設置錯誤識別
12728
								$result["status"]="false";
255 liveuser 12729
 
291 liveuser 12730
								#設置錯誤訊息
12731
								$result["error"]=$callShell;
255 liveuser 12732
 
291 liveuser 12733
								#回傳結果
12734
								return $result;
255 liveuser 12735
 
291 liveuser 12736
								}#if end
12737
 
12738
							}#else end
12739
 
12740
						}#if end
255 liveuser 12741
 
12742
					}#else end
12743
 
12744
				}#else end
291 liveuser 12745
 
255 liveuser 12746
			}#foreach end
12747
 
12748
		}#function sslUpdater_idle end
12749
 
226 liveuser 12750
	}#class zerossl end
255 liveuser 12751