Subversion Repositories php-qbpwcf

Rev

Rev 288 | Rev 292 | 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"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
795
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["pKey"];
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";
291 liveuser 3390
	#$conf["multiThread"],字串,是否啟動多執行序加快執行速度,預設為"false"代表不要;反之為"true"代表要.
3391
	#$conf["multiThread"]="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.
3398
	*/
3399
	public static function updateDnsRecordFile(&$conf){
3400
 
3401
		#初始化要回傳的結果
3402
		$result=array();
3403
 
3404
		#設置當其函數名稱
3405
		$result["function"]=__FUNCTION__;
3406
 
3407
		#如果 $conf 不為陣列
3408
		if(gettype($conf)!="array"){
3409
 
3410
			#設置執行失敗
3411
			$result["status"]="false";
3412
 
3413
			#設置執行錯誤訊息
3414
			$result["error"][]="\$conf變數須為陣列形態";
3415
 
3416
			#如果傳入的參數為 null
3417
			if($conf==null){
3418
 
3419
				#設置執行錯誤訊息
3420
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3421
 
3422
				}#if end
3423
 
3424
			#回傳結果
3425
			return $result;
3426
 
3427
			}#if end
3428
 
3429
		#取得參數
3430
		$result["argu"]=$conf;
3431
 
3432
		#檢查參數
3433
		#函式說明:
3434
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3435
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3436
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3437
		#$result["function"],當前執行的函式名稱.
3438
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3439
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3440
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3441
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
3442
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
3443
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3444
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3445
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3446
		#必填寫的參數:
3447
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3448
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3449
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3450
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("add","dnsRecordFile");
3451
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3452
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
3453
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3454
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3455
		#可以省略的參數:
3456
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3457
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3458
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
3459
		#$conf["skipableVariableCanNotBeEmpty"]=array();
3460
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
291 liveuser 3461
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThread");
249 liveuser 3462
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
291 liveuser 3463
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
249 liveuser 3464
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
291 liveuser 3465
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
249 liveuser 3466
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3467
		#$conf["arrayCountEqualCheck"][]=array();
3468
		#參考資料來源:
3469
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3470
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3471
		unset($conf["variableCheck::checkArguments"]);
3472
 
3473
		#如果檢查失敗
3474
		if($checkArguments["status"]==="false"){
3475
 
3476
			#設置錯誤識別
3477
			$result["status"]="false";
3478
 
3479
			#設置錯誤訊息
3480
			$result["error"]=$checkArguments;
3481
 
3482
			#回傳結果
3483
			return $result;
3484
 
3485
			}#if end
3486
 
3487
		#如果檢查不通過
3488
		if($checkArguments["passed"]==="false"){
3489
 
3490
			#設置錯誤識別
3491
			$result["status"]="false";
3492
 
3493
			#設置錯誤訊息
3494
			$result["error"]=$checkArguments;
3495
 
3496
			#回傳結果
3497
			return $result;
3498
 
3499
			}#if end
3500
 
3501
		#初始化要回傳的content
3502
		$result["content"]=array();
3503
 
3504
		#初始化儲存逐行的註解.
3505
		$result["comment"]=array();
3506
 
3507
		#預設的zone file domain為空
3508
		$result["domain"]="";
3509
 
3510
		#預設的 update 時間
3511
		$result["defaultTTL"]=3600;
3512
 
3513
		#取得 dns 記錄檔案的內容
3514
		#函式說明:
3515
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
3516
		#回傳的變數說明:
3517
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
3518
		#$result["error"],錯誤訊息提示.
3519
		#$result["warning"],警告訊息.
3520
		#$result["function"],當前執行的函數名稱.
3521
		#$result["fileContent"],爲檔案的內容陣列.
3522
		#$result["lineCount"],爲檔案內容總共的行數.
3523
		#$result["fullContent"],為檔案的完整內容.
3524
		#$result["base64dataOnly"],檔案的base64data.
3525
		#$result["base64data"],為在網頁上給予src參數的數值.
3526
		#$result["mimeType"],為檔案的mime type.
3527
		#必填參數:
3528
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
3529
		$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$conf["dnsRecordFile"];
3530
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3531
		$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
3532
		#可省略參數:
3533
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
3534
		$conf["fileAccesss::getFileContent"]["web"]="false";
3535
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
3536
		#$conf["createIfnotExist"]="false";
3537
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
3538
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
3539
		#參考資料:
3540
		#file(),取得檔案內容的行數.
3541
		#file=>http:#php.net/manual/en/function.file.php
3542
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
3543
		#filesize=>http://php.net/manual/en/function.filesize.php
3544
		#參考資料:
3545
		#無.
3546
		#備註:
3547
		#無.
3548
		$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
3549
		unset($conf["fileAccesss::getFileContent"]);
3550
 
3551
		#如果檢查失敗
3552
		if($getFileContent["status"]==="false"){
3553
 
3554
			#設置錯誤識別
3555
			$result["status"]="false";
3556
 
3557
			#設置錯誤訊息
3558
			$result["error"]=$getFileContent;
3559
 
3560
			#回傳結果
3561
			return $result;
3562
 
3563
			}#if end
3564
 
3565
		#取得每行內容
3566
		$lines=$getFileContent["fileContent"];
3567
 
3568
		/*
3569
		範例每行內容:
3570
		$ORIGIN server.domain.	;base domain-name,in this Resource Records (RR) file,"@" equal to base domain-name.
3571
		$TTL 86400	;default TTL for zone
3572
		@	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
3573
		@	3600	IN	TXT	"v=spf1 a mx ~all"
3574
		@	86400	IN	MX	1 mail.server.domain.
3575
		@	86400	IN	A	1.1.1.1
3576
		mail.server.domain.	IN	1.1.1.1
3577
		10-42-0-1	IN	A	10.42.0.1
3578
		101-free        IN      A	101.101.101.101
3579
		127-0-0-1	IN	A	127.0.0.1
3580
		_dmarc	IN	TXT	"v=DMARC1;p=reject;sp=reject;pct=100;adkim=r;aspf=r;fo=1;ri=86400;rua=mailto:admin@server.domain"
3581
		default._domainkey	IN	TXT	( "v=DKIM1; k=rsa;" "p=MIGfMA0GCSqG/SIb3DQEBAQQAB" )  ; ----- DKIM key default for qbpwcf.org
3582
		...
3583
		*/
3584
 
3585
		#針對每行內容
3586
		foreach($lines as $lineNo => $line){
3587
 
291 liveuser 3588
			#如果要啟用多執行序
3589
			if($conf["multiThread"]==="true"){
3590
 
3591
				#初始化要執行的 php 程式
3592
				$phpCode2run=array();
3593
 
3594
				#用 php 執行
3595
				$phpCode2run[]="php";
3596
 
3597
				#用 "-r" 參數
3598
				$phpCode2run[]="-r";
3599
 
3600
				#用 "-r" 參數
3601
				$phpCode2run[]=<<<'PHP'
3602
#匯入QBPWCF套件
3603
include("allInOne.php");
3604
 
3605
#函式說明:
3606
#解析RR檔案中其中的一行內容.
3607
#回傳結果:
3608
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3609
#$reuslt["error"],執行不正常結束的錯訊息陣列.
3610
#$result["function"],當前執行的函式名稱.
3611
#$result["argu"],所使用的參數.
3612
#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
3613
#$result["domain"],字串,RR所屬domain.
3614
#$result["defaultTTL"],字串,預設的RR更新時間.
3615
#$result["comment"],字串陣列,逐行的註解.
3616
#必填參數:
3617
#$conf["line"],字串,要解析的行內容.
3618
$conf["line"]=$line;
3619
#可省略參數:
3620
#無.
3621
#參考資料:
3622
#無.
3623
#備註:
3624
#無.
3625
$parseRRline=zerossl::parseRRline($conf);
3626
unset($conf);
3627
 
3628
#如果執行異常 
3629
if($parseRRline["status"]==="false"){
3630
 
3631
	#設置錯誤識別
3632
	$result["status"]="false";
3633
 
3634
	#設置錯誤訊息
3635
	$result["error"]=$parseRRline;
3636
 
3637
	#印出 json 結果
3638
	echo json_encode($result);
3639
 
3640
	#結束執行,回傳1.
3641
	exit(1);
3642
 
3643
	}#if end
3644
 
3645
#印出json
3646
echo json_encode($parseRRline);
3647
 
3648
PHP;
3649
 
3650
				#函式說明:
3651
				#透過proc來多執行序運作.
3652
				#回傳結果:
3653
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3654
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3655
				#$result["function"],當前執行的函式名稱.
3656
				#$result["argu"],使用的參數.
3657
				#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
3658
				#必填參數:
3659
				#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
3660
				$conf["threads::proc"]["cmds"]=$phpCode2run;
3661
				#可省略參數:
3662
				#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
3663
				$conf["threads::proc"]["wait"]="false";
3664
				#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
3665
				#$conf["timeout"]=array("10");
3666
				#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
3667
				$conf["threads::proc"]["workingDir"]=array(pathinfo(__FILE__)["driname"]);
3668
				#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
3669
				#$conf["envs"]=array(array("key"=>"value"));
3670
				#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
3671
				#$conf["executeBy"]=array("bash");
3672
				#參考資料:
3673
				#https://www.php.net/manual/en/function.proc-open.php
3674
				#https://www.php.net/manual/en/function.proc-get-status.php
3675
				#https://www.php.net/manual/en/function.proc-terminate.php
3676
				#備註:
3677
				#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
3678
				#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
3679
				$proc=threads::proc($conf["threads::proc"]);
3680
				unset($conf["threads::proc"]);
3681
 
3682
				#如果檢查失敗
3683
				if($proc["status"]==="false"){
3684
 
3685
					#設置錯誤識別
3686
					$result["status"]="false";
3687
 
3688
					#設置錯誤訊息
3689
					$result["error"]=$proc;
3690
 
3691
					#回傳結果
3692
					return $result;
3693
 
3694
					}#if end
3695
 
3696
				#儲存程序資訊
3697
				$procs[]=$proc;	
3698
 
3699
				#換解析下一行
3700
				continue;
3701
 
3702
				}#if end
3703
 
249 liveuser 3704
			#另存一份要處理的RR
3705
			$unFormatStr=$line;
3706
 
253 liveuser 3707
			#如果要debug
3708
			if($conf["debug"]==="true"){
3709
 
3710
				#函式說明:
3711
				#撰寫log
3712
				#回傳結果:
3713
				#$result["status"],狀態,"true"或"false".
3714
				#$result["error"],錯誤訊息陣列.
3715
				#$result["function"],當前函式的名稱.
3716
				#$result["argu"],使用的參數.
3717
				#$result["content"],要寫入log的內容字串.
3718
				#必填參數:
3719
				#$conf["path"],字串,log檔案的路徑與名稱.
3720
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3721
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3722
				$conf["logs::record"]["content"]="processing lineNo:".$lineNo." content:".$line.PHP_EOL;
3723
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3724
				$conf["logs::record"]["fileArgu"]=__FILE__;
3725
				#可省略參數:
3726
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3727
				#$conf["rewrite"]="false";
3728
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3729
				#$conf["returnOnly"]="true";
3730
				#參考資料:
3731
				#無.
3732
				#備註:
3733
				#無.
3734
				$record=logs::record($conf["logs::record"]);
3735
				unset($conf["logs::record"]);
3736
 
3737
				}#if end
3738
 
249 liveuser 3739
			#初始化該行的資訊陣列
3740
			$info=array();
3741
 
3742
			#尋找";"開頭的內容,亦即整行都是註解.
3743
			#函式說明:
3744
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3745
			#回傳結果:
3746
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3747
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3748
			#$result["function"],當前執行的函式名稱.
3749
			#$result["argu"],所使用的參數.
3750
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3751
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3752
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3753
			#必填參數:
3754
			#$conf["input"],字串,要檢查的字串.
3755
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3756
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3757
			$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
3758
			#可省略參數:
3759
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3760
			#$conf["varEqual"]=array(null,"found");
3761
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3762
			#$conf["varCon"]=array("no_tail"=>" not");
3763
			#參考資料:
3764
			#無.
3765
			#備註:
3766
			#無.
3767
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3768
			unset($conf["search::findSpecifyStrFormat"]);
3769
 
3770
			#如果執行異常
3771
			if($findSpecifyStrFormat["status"]==="false"){
3772
 
3773
				#設置錯誤識別
3774
				$result["status"]="false";
3775
 
3776
				#設置錯誤訊息
3777
				$result["error"]=$findSpecifyStrFormat;
3778
 
3779
				#回傳結果
3780
				return $result;
3781
 
3782
				}#if end
3783
 
3784
			#如果有找到符合格式的內容
3785
			if($findSpecifyStrFormat["found"]==="true"){
3786
 
3787
				#儲存為註解
3788
				$result["comment"][]=$unFormatStr;
3789
 
3790
				#換下一行
3791
				continue;
3792
 
3793
				}#if end
3794
 
3795
			#函式說明:
3796
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3797
			#回傳結果:
3798
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3799
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3800
			#$result["function"],當前執行的函式名稱.
3801
			#$result["argu"],所使用的參數.
3802
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3803
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3804
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3805
			#必填參數:
3806
			#$conf["input"],字串,要檢查的字串.
3807
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3808
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3809
			$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
3810
			#可省略參數:
3811
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3812
			#$conf["varEqual"]=array(null,"found");
3813
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3814
			#$conf["varCon"]=array("no_tail"=>" not");
3815
			#參考資料:
3816
			#無.
3817
			#備註:
3818
			#無.
3819
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3820
			unset($conf["search::findSpecifyStrFormat"]);
3821
 
3822
			#如果執行異常
3823
			if($findSpecifyStrFormat["status"]==="false"){
3824
 
3825
				#設置錯誤識別
3826
				$result["status"]="false";
3827
 
3828
				#設置錯誤訊息
3829
				$result["error"]=$findSpecifyStrFormat;
3830
 
3831
				#回傳結果
3832
				return $result;
3833
 
3834
				}#if end
3835
 
3836
			#如果有找到符合格式的內容
3837
			if($findSpecifyStrFormat["found"]==="true"){
3838
 
3839
				#設置 type 的數值
3840
				$info["type"]="\$ORIGIN";
3841
 
3842
				#取得後面待處理的內容
3843
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
3844
 
3845
				#函式說明:
3846
				#將字串開頭的特定關鍵字移除.
3847
				#回傳結果:
3848
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3849
				#$result["error"],錯誤訊息陣列.
3850
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
3851
				#$result["function"],當前執行的函數名稱.
3852
				#$result["argu"],使用的參數.
3853
				#$result["content"],處理好的的字串內容.
3854
				#$result["deleted"],被移除的內容.
3855
				#必填參數:
3856
				#$conf["stringIn"],字串,要處理的字串.
3857
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
3858
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
3859
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
3860
				#可省略參數:
3861
				#無.
3862
				#參考資料:
3863
				#無.
3864
				#備註:
3865
				#無.
3866
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
3867
				unset($conf["stringProcess::delHeadStr"]);
3868
 
3869
				#如果執行異常
3870
				if($delHeadStr["status"]==="false"){
3871
 
3872
					#設置錯誤識別
3873
					$result["status"]="false";
3874
 
3875
					#設置錯誤訊息
3876
					$result["error"]=$delHeadStr;
3877
 
3878
					#回傳結果
3879
					return $result;
3880
 
3881
					}#if end
3882
 
3883
				#如果有移除開頭的字串
3884
				if($delHeadStr["founded"]==="true"){
3885
 
3886
					#取得處理後的結果
3887
					$unFormatStr=$delHeadStr["content"];
3888
 
3889
					}#if end
3890
 
253 liveuser 3891
 
3892
 
249 liveuser 3893
				#解析 $ORIGN 的數值, 以及後面是否有註解...
3894
				#函式說明:
3895
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3896
				#回傳結果:
3897
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3898
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3899
				#$result["function"],當前執行的函式名稱.
3900
				#$result["argu"],所使用的參數.
3901
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3902
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3903
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3904
				#必填參數:
3905
				#$conf["input"],字串,要檢查的字串.
3906
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3907
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3908
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3909
				#可省略參數:
3910
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3911
				#$conf["varEqual"]=array(null,"found");
3912
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3913
				#$conf["varCon"]=array("no_tail"=>" not");
3914
				#參考資料:
3915
				#無.
3916
				#備註:
3917
				#無.
3918
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3919
				unset($conf["search::findSpecifyStrFormat"]);
3920
 
3921
				#如果執行異常
3922
				if($findSpecifyStrFormat["status"]==="false"){
3923
 
3924
					#設置錯誤識別
3925
					$result["status"]="false";
3926
 
3927
					#設置錯誤訊息
3928
					$result["error"]=$findSpecifyStrFormat;
3929
 
3930
					#回傳結果
3931
					return $result;
3932
 
3933
					}#if end
3934
 
3935
				#如果有數值跟註解
3936
				if($findSpecifyStrFormat["found"]==="true"){
3937
 
3938
					#儲存數值
3939
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3940
 
3941
					#儲存zone domain
3942
					$result["domain"]=trim($info["value"]);
3943
 
3944
					#儲存註解
253 liveuser 3945
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
249 liveuser 3946
 
3947
					#儲存解析好的RR
3948
					$result["content"][]=$info;
3949
 
3950
					#換下一行
3951
					continue;
3952
 
3953
					}#if end
3954
 
3955
				#執行到這邊代表剩下的內容都是 value
3956
				$info["value"]=$unFormatStr;
3957
 
3958
				#儲存zone domain
3959
				$result["domain"]=trim($info["value"]);
3960
 
3961
				#儲存解析好的RR
3962
				$result["content"][]=$info;
3963
 
3964
				#換下一行
3965
				continue;
3966
 
3967
				}#if end
3968
 
3969
			#檢查是否為 $TTL 開頭
3970
			#函式說明:
3971
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3972
			#回傳結果:
3973
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3974
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3975
			#$result["function"],當前執行的函式名稱.
3976
			#$result["argu"],所使用的參數.
3977
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3978
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3979
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3980
			#必填參數:
3981
			#$conf["input"],字串,要檢查的字串.
3982
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3983
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3984
			$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
3985
			#可省略參數:
3986
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3987
			#$conf["varEqual"]=array(null,"found");
3988
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3989
			#$conf["varCon"]=array("no_tail"=>" not");
3990
			#參考資料:
3991
			#無.
3992
			#備註:
3993
			#無.
3994
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3995
			unset($conf["search::findSpecifyStrFormat"]);
3996
 
3997
			#如果執行異常
3998
			if($findSpecifyStrFormat["status"]==="false"){
3999
 
4000
				#設置錯誤識別
4001
				$result["status"]="false";
4002
 
4003
				#設置錯誤訊息
4004
				$result["error"]=$findSpecifyStrFormat;
4005
 
4006
				#回傳結果
4007
				return $result;
4008
 
4009
				}#if end
4010
 
4011
			#如果有找到符合格式的內容
4012
			if($findSpecifyStrFormat["found"]==="true"){
4013
 
4014
				#設置 type 的數值
4015
				$info["type"]="\$TTL";
4016
 
4017
				#取得後面待處理的內容
4018
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
4019
 
4020
				#函式說明:
4021
				#將字串開頭的特定關鍵字移除.
4022
				#回傳結果:
4023
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4024
				#$result["error"],錯誤訊息陣列.
4025
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4026
				#$result["function"],當前執行的函數名稱.
4027
				#$result["argu"],使用的參數.
4028
				#$result["content"],處理好的的字串內容.
4029
				#$result["deleted"],被移除的內容.
4030
				#必填參數:
4031
				#$conf["stringIn"],字串,要處理的字串.
4032
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4033
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4034
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
4035
				#可省略參數:
4036
				#無.
4037
				#參考資料:
4038
				#無.
4039
				#備註:
4040
				#無.
4041
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4042
				unset($conf["stringProcess::delHeadStr"]);
4043
 
4044
				#如果執行異常
4045
				if($delHeadStr["status"]==="false"){
4046
 
4047
					#設置錯誤識別
4048
					$result["status"]="false";
4049
 
4050
					#設置錯誤訊息
4051
					$result["error"]=$delHeadStr;
4052
 
4053
					#回傳結果
4054
					return $result;
4055
 
4056
					}#if end
4057
 
4058
				#如果有移除開頭的字串
4059
				if($delHeadStr["founded"]==="true"){
4060
 
4061
					#取得處理後的結果
4062
					$unFormatStr=$delHeadStr["content"];
4063
 
4064
					}#if end
4065
 
4066
				#解析 $TTL 的數值, 以及後面是否有註解...
4067
				#函式說明:
4068
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4069
				#回傳結果:
4070
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4071
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4072
				#$result["function"],當前執行的函式名稱.
4073
				#$result["argu"],所使用的參數.
4074
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4075
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4076
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4077
				#必填參數:
4078
				#$conf["input"],字串,要檢查的字串.
4079
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4080
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4081
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
4082
				#可省略參數:
4083
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4084
				#$conf["varEqual"]=array(null,"found");
4085
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4086
				#$conf["varCon"]=array("no_tail"=>" not");
4087
				#參考資料:
4088
				#無.
4089
				#備註:
4090
				#無.
4091
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4092
				unset($conf["search::findSpecifyStrFormat"]);
4093
 
4094
				#如果執行異常
4095
				if($findSpecifyStrFormat["status"]==="false"){
4096
 
4097
					#設置錯誤識別
4098
					$result["status"]="false";
4099
 
4100
					#設置錯誤訊息
4101
					$result["error"]=$findSpecifyStrFormat;
4102
 
4103
					#回傳結果
4104
					return $result;
4105
 
4106
					}#if end
4107
 
4108
				#如果有數值跟註解
4109
				if($findSpecifyStrFormat["found"]==="true"){
4110
 
4111
					#儲存數值
4112
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
4113
 
4114
					#儲存註解
253 liveuser 4115
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
249 liveuser 4116
 
4117
					#儲存預設的 TTL
4118
					$result["defaultTTL"]=trim($info["value"]);
4119
 
4120
					#儲存解析好的RR
4121
					$result["content"][]=$info;
4122
 
4123
					#換下一行
4124
					continue;
4125
 
4126
					}#if end
4127
 
4128
				#執行到這邊代表剩下的內容都是 value
4129
				$info["value"]=$unFormatStr;
4130
 
4131
				#儲存預設的 TTL
4132
				$result["defaultTTL"]=trim($info["value"]);
4133
 
4134
				#儲存解析好的RR
4135
				$result["content"][]=$info;
4136
 
4137
				#換下一行
4138
				continue;
4139
 
4140
				}#if end
4141
 
4142
			#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
4143
 
4144
			#函式說明:
4145
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4146
			#回傳結果:
4147
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4148
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
4149
			#$result["function"],當前執行的函式名稱.
4150
			#$result["argu"],所使用的參數.
4151
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4152
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4153
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
4154
			#必填參數:
4155
			#$conf["input"],字串,要檢查的字串.
4156
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4157
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4158
			$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
4159
			#可省略參數:
4160
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4161
			#$conf["varEqual"]=array(null,"found");
4162
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4163
			#$conf["varCon"]=array("no_tail"=>" not");
4164
			#參考資料:
4165
			#無.
4166
			#備註:
4167
			#無.
4168
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4169
			unset($conf["search::findSpecifyStrFormat"]);
4170
 
4171
			#如果執行異常
4172
			if($findSpecifyStrFormat["status"]==="false"){
4173
 
4174
				#設置錯誤識別
4175
				$result["status"]="false";
4176
 
4177
				#設置錯誤訊息
4178
				$result["error"]=$findSpecifyStrFormat;
4179
 
4180
				#回傳結果
4181
				return $result;
4182
 
4183
				}#if end
4184
 
4185
			#如果存在"("
4186
			if($findSpecifyStrFormat["found"]==="true"){
4187
 
4188
				#取得無"("的內容
4189
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
4190
 
4191
				#取得拆下來的含開頭"("內容
4192
				$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
4193
 
4194
				}#if end
4195
 
4196
			#反之
4197
			else{
4198
 
4199
				#函式說明:
4200
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4201
				#回傳結果:
4202
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4203
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4204
				#$result["function"],當前執行的函式名稱.
4205
				#$result["argu"],所使用的參數.
4206
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4207
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4208
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
4209
				#必填參數:
4210
				#$conf["input"],字串,要檢查的字串.
4211
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4212
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4213
				$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
4214
				#可省略參數:
4215
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4216
				#$conf["varEqual"]=array(null,"found");
4217
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4218
				#$conf["varCon"]=array("no_tail"=>" not");
4219
				#參考資料:
4220
				#無.
4221
				#備註:
4222
				#無.
4223
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4224
				unset($conf["search::findSpecifyStrFormat"]);
4225
 
4226
				#如果執行異常
4227
				if($findSpecifyStrFormat["status"]==="false"){
4228
 
4229
					#設置錯誤識別
4230
					$result["status"]="false";
4231
 
4232
					#設置錯誤訊息
4233
					$result["error"]=$findSpecifyStrFormat;
4234
 
4235
					#回傳結果
4236
					return $result;
4237
 
4238
					}#if end
4239
 
4240
				#如果存在"
4241
				if($findSpecifyStrFormat["found"]==="true"){
4242
 
4243
					#取得無"的內容
4244
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
4245
 
4246
					#取得拆下來的含開頭"內容
4247
					$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
4248
 
4249
					}#if end
4250
 
4251
				#反之
4252
				else{
4253
 
4254
					#函式說明:
4255
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4256
					#回傳結果:
4257
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4258
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
4259
					#$result["function"],當前執行的函式名稱.
4260
					#$result["argu"],所使用的參數.
4261
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4262
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4263
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
4264
					#必填參數:
4265
					#$conf["input"],字串,要檢查的字串.
4266
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4267
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4268
					$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
4269
					#可省略參數:
4270
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4271
					#$conf["varEqual"]=array(null,"found");
4272
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4273
					#$conf["varCon"]=array("no_tail"=>" not");
4274
					#參考資料:
4275
					#無.
4276
					#備註:
4277
					#無.
4278
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4279
					unset($conf["search::findSpecifyStrFormat"]);
4280
 
4281
					#如果執行異常
4282
					if($findSpecifyStrFormat["status"]==="false"){
4283
 
4284
						#設置錯誤識別
4285
						$result["status"]="false";
4286
 
4287
						#設置錯誤訊息
4288
						$result["error"]=$findSpecifyStrFormat;
4289
 
4290
						#回傳結果
4291
						return $result;
4292
 
4293
						}#if end
4294
 
4295
					#如果存在";"
4296
					if($findSpecifyStrFormat["found"]==="true"){
4297
 
4298
						#取得無";"的內容
4299
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
4300
 
4301
						#取得拆下來的含開頭";"內容
4302
						$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
4303
 
4304
						}#if end
4305
 
4306
					}#else end
4307
 
4308
				}#else end
4309
 
4310
			#檢查是否為 @ 開頭
4311
			#函式說明:
4312
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4313
			#回傳結果:
4314
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4315
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
4316
			#$result["function"],當前執行的函式名稱.
4317
			#$result["argu"],所使用的參數.
4318
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4319
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4320
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4321
			#必填參數:
4322
			#$conf["input"],字串,要檢查的字串.
4323
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4324
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4325
			$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
4326
			#可省略參數:
4327
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4328
			#$conf["varEqual"]=array(null,"found");
4329
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4330
			#$conf["varCon"]=array("no_tail"=>" not");
4331
			#參考資料:
4332
			#無.
4333
			#備註:
4334
			#無.
4335
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4336
			unset($conf["search::findSpecifyStrFormat"]);
4337
 
4338
			#如果執行異常
4339
			if($findSpecifyStrFormat["status"]==="false"){
4340
 
4341
				#設置錯誤識別
4342
				$result["status"]="false";
4343
 
4344
				#設置錯誤訊息
4345
				$result["error"]=$findSpecifyStrFormat;
4346
 
4347
				#回傳結果
4348
				return $result;
4349
 
4350
				}#if end
4351
 
4352
			#如果有找到符合格式的內容
4353
			if($findSpecifyStrFormat["found"]==="true"){
4354
 
4355
				#設置 query 的數值
4356
				$info["query"]="@";
4357
 
4358
				#取得後面待處理的內容
4359
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
4360
 
4361
				#函式說明:
4362
				#將字串開頭的特定關鍵字移除.
4363
				#回傳結果:
4364
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4365
				#$result["error"],錯誤訊息陣列.
4366
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4367
				#$result["function"],當前執行的函數名稱.
4368
				#$result["argu"],使用的參數.
4369
				#$result["content"],處理好的的字串內容.
4370
				#$result["deleted"],被移除的內容.
4371
				#必填參數:
4372
				#$conf["stringIn"],字串,要處理的字串.
4373
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4374
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4375
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
4376
				#可省略參數:
4377
				#無.
4378
				#參考資料:
4379
				#無.
4380
				#備註:
4381
				#無.
4382
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4383
				unset($conf["stringProcess::delHeadStr"]);
4384
 
4385
				#如果執行異常
4386
				if($delHeadStr["status"]==="false"){
4387
 
4388
					#設置錯誤識別
4389
					$result["status"]="false";
4390
 
4391
					#設置錯誤訊息
4392
					$result["error"]=$delHeadStr;
4393
 
4394
					#回傳結果
4395
					return $result;
4396
 
4397
					}#if end
4398
 
4399
				#如果有移除開頭的字串
4400
				if($delHeadStr["founded"]==="true"){
4401
 
4402
					#取得處理後的結果 update time..IN..type...value;comment
4403
					$unFormatStr=$delHeadStr["content"];
4404
 
4405
					}#if end
4406
 
4407
				#debug
4408
				#var_dump(__LINE__,$delHeadStr);
4409
 
4410
				}#if end
4411
 
4412
			#反之
4413
			else{
4414
 
4415
				#執行到這邊,代表 query 為一非 @ 的字串
4416
				#函式說明:
4417
				#將指令字串解析成陣列,方便給予 external::callShell 使用
4418
				#回傳結果:
4419
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4420
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4421
				#$result["function"],當前執行的函式名稱.
4422
				#$result["content"],解析好的指令陣列.
4423
				#$result["cmd"],解析好的指令名稱.
4424
				#$result["argus"],解析好的參數陣列.
4425
				#$result["argu"],所使用的參數.
4426
				#必填參數
4427
				#$conf["cmdStr"],字串,要解析的指令字串
4428
				$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
4429
				#可省略參數:
4430
				#無.
4431
				#參考資料:
4432
				#無.
4433
				#備註:
4434
				#無.
4435
				$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
4436
				unset($conf["stringProcess::parseCmdString"]);
4437
 
4438
				#如果執行失敗
4439
				if($parseCmdString["status"]==="false"){
4440
 
4441
					#設置錯誤識別
4442
					$result["status"]="false";
4443
 
4444
					#設置錯誤訊息
4445
					$result["error"]=$parseCmdString;
4446
 
4447
					#debug
4448
					#$result["errorProcessLine"]=$line;
4449
 
4450
					#回傳結果
4451
					return $result;
4452
 
4453
					}#if end
4454
 
4455
				#取得 query 的內容
4456
				$info["query"]=$parseCmdString["content"][0];
4457
 
4458
				#剔除 query以及後面的" "跟\t
4459
				#函式說明:
4460
				#將字串開頭的特定關鍵字移除.
4461
				#回傳結果:
4462
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4463
				#$result["error"],錯誤訊息陣列.
4464
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4465
				#$result["function"],當前執行的函數名稱.
4466
				#$result["argu"],使用的參數.
4467
				#$result["content"],處理好的的字串內容.
4468
				#$result["deleted"],被移除的內容.
4469
				#必填參數:
4470
				#$conf["stringIn"],字串,要處理的字串.
4471
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4472
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4473
				$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
4474
				#可省略參數:
4475
				#無.
4476
				#參考資料:
4477
				#無.
4478
				#備註:
4479
				#無.
4480
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4481
				unset($conf["stringProcess::delHeadStr"]);
4482
 
4483
				#如果執行異常
4484
				if($delHeadStr["status"]==="false"){
4485
 
4486
					#設置錯誤識別
4487
					$result["status"]="false";
4488
 
4489
					#設置錯誤訊息
4490
					$result["error"]=$delHeadStr;
4491
 
4492
					#回傳結果
4493
					return $result;
4494
 
4495
					}#if end
4496
 
4497
				#取得update time..IN..type...value;comment
4498
				$unFormatStr=$delHeadStr["content"];
4499
 
4500
				}#else end
4501
 
4502
			#無窮迴圈
4503
			while(true){
4504
 
253 liveuser 4505
				#如果要debug
4506
				if($conf["debug"]==="true"){
249 liveuser 4507
 
253 liveuser 4508
					#函式說明:
4509
					#撰寫log
4510
					#回傳結果:
4511
					#$result["status"],狀態,"true"或"false".
4512
					#$result["error"],錯誤訊息陣列.
4513
					#$result["function"],當前函式的名稱.
4514
					#$result["argu"],使用的參數.
4515
					#$result["content"],要寫入log的內容字串.
4516
					#必填參數:
4517
					#$conf["path"],字串,log檔案的路徑與名稱.
4518
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4519
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4520
					$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4521
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4522
					$conf["logs::record"]["fileArgu"]=__FILE__;
4523
					#可省略參數:
4524
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4525
					#$conf["rewrite"]="false";
4526
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4527
					#$conf["returnOnly"]="true";
4528
					#參考資料:
4529
					#無.
4530
					#備註:
4531
					#無.
4532
					$record=logs::record($conf["logs::record"]);
4533
					unset($conf["logs::record"]);
4534
 
4535
					}#if end
4536
 
249 liveuser 4537
				#解析 updateTime..IN..type...value...comment
4538
 
4539
				#判斷是否無 update time
4540
 
4541
				#函式說明:
4542
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4543
				#回傳結果:
4544
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4545
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4546
				#$result["function"],當前執行的函式名稱.
4547
				#$result["argu"],所使用的參數.
4548
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4549
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4550
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4551
				#必填參數:
4552
				#$conf["input"],字串,要檢查的字串.
4553
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4554
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4555
				$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
4556
				#可省略參數:
4557
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4558
				#$conf["varEqual"]=array(null,"found");
4559
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4560
				#$conf["varCon"]=array("no_tail"=>" not");
4561
				#參考資料:
4562
				#無.
4563
				#備註:
4564
				#無.
4565
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4566
				unset($conf["search::findSpecifyStrFormat"]);
4567
 
4568
				#如果執行異常
4569
				if($findSpecifyStrFormat["status"]==="false"){
4570
 
4571
					#設置錯誤識別
4572
					$result["status"]="false";
4573
 
4574
					#設置錯誤訊息
4575
					$result["error"]=$findSpecifyStrFormat;
4576
 
4577
					#回傳結果
4578
					return $result;
4579
 
4580
					}#if end
4581
 
4582
				#如果有找到符合格式的內容
4583
				if($findSpecifyStrFormat["found"]==="true"){
4584
 
4585
					#代表沒有 update time 欄位,因此儲存預設的TTL
4586
					$info["update"]=&$result["defaultTTL"];
4587
 
4588
					#取得剩下的 ...type...value;comment
4589
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
4590
 
4591
					#設置該行沒有指定 update time
4592
					$noUpdateTime="true";
4593
 
253 liveuser 4594
					#如果要debug
4595
					if($conf["debug"]==="true"){
4596
 
4597
						#函式說明:
4598
						#撰寫log
4599
						#回傳結果:
4600
						#$result["status"],狀態,"true"或"false".
4601
						#$result["error"],錯誤訊息陣列.
4602
						#$result["function"],當前函式的名稱.
4603
						#$result["argu"],使用的參數.
4604
						#$result["content"],要寫入log的內容字串.
4605
						#必填參數:
4606
						#$conf["path"],字串,log檔案的路徑與名稱.
4607
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4608
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4609
						$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4610
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4611
						$conf["logs::record"]["fileArgu"]=__FILE__;
4612
						#可省略參數:
4613
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4614
						#$conf["rewrite"]="false";
4615
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4616
						#$conf["returnOnly"]="true";
4617
						#參考資料:
4618
						#無.
4619
						#備註:
4620
						#無.
4621
						$record=logs::record($conf["logs::record"]);
4622
						unset($conf["logs::record"]);
4623
 
4624
						}#if end
249 liveuser 4625
 
4626
					}#if end
4627
 
4628
				#反之
4629
				else{
4630
 
4631
					#設置該行有指定 update time
4632
					$noUpdateTime="false";
4633
 
4634
					#如果有指定 update time
4635
					if($noUpdateTime==="false"){
4636
 
4637
						#要來解析 update time
4638
						#函式說明:
4639
						#將字串進行解析,變成多個參數.
4640
						#回傳結果:
4641
						#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
4642
						#$result["function"],當前執行的函式內容.
4643
						#$result["error"],錯誤訊息陣列.
4644
						#$result["content"],參數陣列.
4645
						#$result["count"],總共有幾個參數.
4646
						#必填參數:
4647
						#$conf["input"],字串,要解析成參數的字串.
4648
						$conf["stringProcess::parse"]["input"]=$unFormatStr;
4649
						#可省略參數:
4650
						#無.
4651
						#參考資料:
4652
						#無.
4653
						#備註:
4654
						#無.
4655
						$parse=stringProcess::parse($conf["stringProcess::parse"]);
4656
						unset($conf["stringProcess::parse"]);
4657
 
4658
						#如果執行異常
4659
						if($parse["status"]==="false"){
4660
 
4661
							#設置錯誤識別
4662
							$result["status"]="false";
4663
 
4664
							#設置錯誤訊息
4665
							$result["error"]=$parse;
4666
 
4667
							#回傳結果
4668
							return $result;
4669
 
4670
							}#if end
4671
 
4672
						#取得更新時間
4673
						$info["update"]=$parse["content"][0];
4674
 
4675
						#取得 update time 後面的內容
4676
						#函式說明:
4677
						#將字串開頭的特定關鍵字移除.
4678
						#回傳結果:
4679
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4680
						#$result["error"],錯誤訊息陣列.
4681
						#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4682
						#$result["function"],當前執行的函數名稱.
4683
						#$result["argu"],使用的參數.
4684
						#$result["content"],處理好的的字串內容.
4685
						#$result["deleted"],被移除的內容.
4686
						#必填參數:
4687
						#$conf["stringIn"],字串,要處理的字串.
4688
						$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4689
						#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4690
						$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
4691
						#可省略參數:
4692
						#無.
4693
						#參考資料:
4694
						#無.
4695
						#備註:
4696
						#無.
4697
						$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4698
						unset($conf["stringProcess::delHeadStr"]);
4699
 
4700
						#如果執行異常
4701
						if($delHeadStr["status"]==="false"){
4702
 
4703
							#設置錯誤識別
4704
							$result["status"]="false";
4705
 
4706
							#設置錯誤訊息
4707
							$result["error"]=$delHeadStr;
4708
 
4709
							#回傳結果
4710
							return $result;
4711
 
4712
							}#if end
4713
 
4714
						#取得...IN...value;comment
4715
						$unFormatStr=$delHeadStr["content"];
4716
 
4717
						}#if end
4718
 
4719
					#取得 ...IN... 後面的內容
4720
					#函式說明:
4721
					#將字串開頭的特定關鍵字移除.
4722
					#回傳結果:
4723
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4724
					#$result["error"],錯誤訊息陣列.
4725
					#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4726
					#$result["function"],當前執行的函數名稱.
4727
					#$result["argu"],使用的參數.
4728
					#$result["content"],處理好的的字串內容.
4729
					#$result["deleted"],被移除的內容.
4730
					#必填參數:
4731
					#$conf["stringIn"],字串,要處理的字串.
4732
					$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4733
					#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4734
					$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
4735
					#可省略參數:
4736
					#無.
4737
					#參考資料:
4738
					#無.
4739
					#備註:
4740
					#無.
4741
					$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4742
					unset($conf["stringProcess::delHeadStr"]);
4743
 
4744
					#如果執行異常
4745
					if($delHeadStr["status"]==="false"){
4746
 
4747
						#設置錯誤識別
4748
						$result["status"]="false";
4749
 
4750
						#設置錯誤訊息
4751
						$result["error"]=$delHeadStr;
4752
 
4753
						#回傳結果
4754
						return $result;
4755
 
4756
						}#if end
4757
 
4758
					#取得IN...value;comment
4759
					$unFormatStr=$delHeadStr["content"];
4760
 
253 liveuser 4761
					#如果要debug
4762
					if($conf["debug"]==="true"){
249 liveuser 4763
 
253 liveuser 4764
						#函式說明:
4765
						#撰寫log
4766
						#回傳結果:
4767
						#$result["status"],狀態,"true"或"false".
4768
						#$result["error"],錯誤訊息陣列.
4769
						#$result["function"],當前函式的名稱.
4770
						#$result["argu"],使用的參數.
4771
						#$result["content"],要寫入log的內容字串.
4772
						#必填參數:
4773
						#$conf["path"],字串,log檔案的路徑與名稱.
4774
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4775
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4776
						$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4777
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4778
						$conf["logs::record"]["fileArgu"]=__FILE__;
4779
						#可省略參數:
4780
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4781
						#$conf["rewrite"]="false";
4782
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4783
						#$conf["returnOnly"]="true";
4784
						#參考資料:
4785
						#無.
4786
						#備註:
4787
						#無.
4788
						$record=logs::record($conf["logs::record"]);
4789
						unset($conf["logs::record"]);
4790
 
4791
						}#if end
4792
 
249 liveuser 4793
					}#else end
4794
 
4795
				#解析 type...value;comment
4796
				#函式說明:
4797
				#將字串進行解析,變成多個參數.
4798
				#回傳結果:
4799
				#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
4800
				#$result["function"],當前執行的函式內容.
4801
				#$result["error"],錯誤訊息陣列.
4802
				#$result["content"],參數陣列.
4803
				#$result["count"],總共有幾個參數.
4804
				#必填參數:
4805
				#$conf["input"],字串,要解析成參數的字串.
4806
				$conf["stringProcess::parse"]["input"]=$unFormatStr;
4807
				#可省略參數:
4808
				#無.
4809
				#參考資料:
4810
				#無.
4811
				#備註:
4812
				#無.
4813
				$parse=stringProcess::parse($conf["stringProcess::parse"]);
4814
				unset($conf["stringProcess::parse"]);
4815
 
4816
				#如果執行異常
4817
				if($parse["status"]==="false"){
4818
 
4819
					#設置錯誤識別
4820
					$result["status"]="false";
4821
 
4822
					#設置錯誤訊息
4823
					$result["error"]=$parse;
4824
 
4825
					#回傳結果
4826
					return $result;
4827
 
4828
					}#if end
4829
 
4830
				#取得 type
4831
				$info["type"]=$parse["content"][0];
4832
 
4833
				#取得 type...後面的value;comment內容
4834
				#函式說明:
4835
				#將字串開頭的特定關鍵字移除.
4836
				#回傳結果:
4837
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4838
				#$result["error"],錯誤訊息陣列.
4839
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4840
				#$result["function"],當前執行的函數名稱.
4841
				#$result["argu"],使用的參數.
4842
				#$result["content"],處理好的的字串內容.
4843
				#$result["deleted"],被移除的內容.
4844
				#必填參數:
4845
				#$conf["stringIn"],字串,要處理的字串.
4846
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4847
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4848
				$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
4849
				#可省略參數:
4850
				#無.
4851
				#參考資料:
4852
				#無.
4853
				#備註:
4854
				#無.
4855
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4856
				unset($conf["stringProcess::delHeadStr"]);
4857
 
4858
				#如果執行異常
4859
				if($delHeadStr["status"]==="false"){
4860
 
4861
					#設置錯誤識別
4862
					$result["status"]="false";
4863
 
4864
					#設置錯誤訊息
4865
					$result["error"]=$delHeadStr;
4866
 
4867
					#回傳結果
4868
					return $result;
4869
 
4870
					}#if end
4871
 
4872
				#取得 value;comment
4873
				$unFormatStr=$delHeadStr["content"];
4874
 
4875
				#如果有要合併回去的內容
4876
				if(isset($unFormatStr2add)){
4877
 
4878
					#合併回去內容
4879
					$unFormatStr=$unFormatStr.$unFormatStr2add;
4880
 
4881
					#移除用不到的變數
4882
					unset($unFormatStr2add);
4883
 
4884
					}#if end
4885
 
253 liveuser 4886
				#如果要debug
4887
				if($conf["debug"]==="true"){
249 liveuser 4888
 
253 liveuser 4889
					#函式說明:
4890
					#撰寫log
4891
					#回傳結果:
4892
					#$result["status"],狀態,"true"或"false".
4893
					#$result["error"],錯誤訊息陣列.
4894
					#$result["function"],當前函式的名稱.
4895
					#$result["argu"],使用的參數.
4896
					#$result["content"],要寫入log的內容字串.
4897
					#必填參數:
4898
					#$conf["path"],字串,log檔案的路徑與名稱.
4899
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4900
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4901
					$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4902
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4903
					$conf["logs::record"]["fileArgu"]=__FILE__;
4904
					#可省略參數:
4905
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4906
					#$conf["rewrite"]="false";
4907
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4908
					#$conf["returnOnly"]="true";
4909
					#參考資料:
4910
					#無.
4911
					#備註:
4912
					#無.
4913
					$record=logs::record($conf["logs::record"]);
4914
					unset($conf["logs::record"]);
4915
 
4916
					}#if end
4917
 
249 liveuser 4918
				#如果type不為 CNAME 跟 TXT 跟 SOA
4919
				if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" ){
4920
 
4921
					#儲存value
4922
					$info["value"]=$unFormatStr;
4923
 
4924
					#判斷是否有 ";" 存在
4925
					#函式說明:
4926
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4927
					#回傳結果:
4928
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4929
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
4930
					#$result["function"],當前執行的函式名稱.
4931
					#$result["argu"],所使用的參數.
4932
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4933
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4934
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4935
					#必填參數:
4936
					#$conf["input"],字串,要檢查的字串.
4937
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4938
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4939
					$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
4940
					#可省略參數:
4941
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4942
					#$conf["varEqual"]=array(null,"found");
4943
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4944
					#$conf["varCon"]=array("no_tail"=>" not");
4945
					#參考資料:
4946
					#無.
4947
					#備註:
4948
					#無.
4949
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4950
					unset($conf["search::findSpecifyStrFormat"]);
4951
 
4952
					#如果執行異常
4953
					if($findSpecifyStrFormat["status"]==="false"){
4954
 
4955
						#設置錯誤識別
4956
						$result["status"]="false";
4957
 
4958
						#設置錯誤訊息
4959
						$result["error"]=$findSpecifyStrFormat;
4960
 
4961
						#回傳結果
4962
						return $result;
4963
 
4964
						}#if end
4965
 
4966
					#如果有 ";"
4967
					if($findSpecifyStrFormat["found"]==="true"){
4968
 
4969
						#儲存value
4970
						$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
4971
 
4972
						#儲存comment
4973
						$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
4974
 
4975
						}#if end
4976
 
4977
					#儲存該筆RR
4978
					$result["content"][]=$info;
4979
 
4980
					#解析完畢換下一行
4981
					continue 2;
4982
 
4983
					}#if end
291 liveuser 4984
 
249 liveuser 4985
				#執行到這邊,代表type為CNAME或TXT或SOA
4986
 
4987
				#如果 type 是 SOA
4988
				if($info["type"]==="SOA"){
4989
 
253 liveuser 4990
					#如果要debug
4991
					if($conf["debug"]==="true"){
4992
 
4993
						#函式說明:
4994
						#撰寫log
4995
						#回傳結果:
4996
						#$result["status"],狀態,"true"或"false".
4997
						#$result["error"],錯誤訊息陣列.
4998
						#$result["function"],當前函式的名稱.
4999
						#$result["argu"],使用的參數.
5000
						#$result["content"],要寫入log的內容字串.
5001
						#必填參數:
5002
						#$conf["path"],字串,log檔案的路徑與名稱.
5003
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5004
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5005
						$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
5006
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5007
						$conf["logs::record"]["fileArgu"]=__FILE__;
5008
						#可省略參數:
5009
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5010
						#$conf["rewrite"]="false";
5011
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5012
						#$conf["returnOnly"]="true";
5013
						#參考資料:
5014
						#無.
5015
						#備註:
5016
						#無.
5017
						$record=logs::record($conf["logs::record"]);
5018
						unset($conf["logs::record"]);
5019
 
5020
						}#if end
5021
 
249 liveuser 5022
					#SOA 範例
5023
					#@	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
5024
 
5025
					#再度嘗試分割
5026
					#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
5027
 
5028
					#函式說明:
5029
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5030
					#回傳結果:
5031
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5032
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
5033
					#$result["function"],當前執行的函式名稱.
5034
					#$result["argu"],所使用的參數.
5035
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5036
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5037
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
5038
					#必填參數:
5039
					#$conf["input"],字串,要檢查的字串.
5040
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5041
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5042
					$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
5043
					#可省略參數:
5044
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5045
					#$conf["varEqual"]=array(null,"found");
5046
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5047
					#$conf["varCon"]=array("no_tail"=>" not");
5048
					#參考資料:
5049
					#無.
5050
					#備註:
5051
					#無.
5052
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5053
					unset($conf["search::findSpecifyStrFormat"]);
5054
 
5055
					#如果執行異常
5056
					if($findSpecifyStrFormat["status"]==="false"){
5057
 
5058
						#設置錯誤識別
5059
						$result["status"]="false";
5060
 
5061
						#設置錯誤訊息
5062
						$result["error"]=$findSpecifyStrFormat;
5063
 
5064
						#回傳結果
5065
						return $result;
5066
 
5067
						}#if end
5068
 
5069
					#如果存在"("
5070
					if($findSpecifyStrFormat["found"]==="true"){
5071
 
5072
						#取得無"("的內容
5073
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
5074
 
5075
						#取得拆下來的含開頭"("內容
5076
						$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
5077
 
5078
						}#if end
5079
 
5080
					#反之
5081
					else{
5082
 
5083
						#函式說明:
5084
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5085
						#回傳結果:
5086
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5087
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
5088
						#$result["function"],當前執行的函式名稱.
5089
						#$result["argu"],所使用的參數.
5090
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5091
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5092
						#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
5093
						#必填參數:
5094
						#$conf["input"],字串,要檢查的字串.
5095
						$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5096
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5097
						$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
5098
						#可省略參數:
5099
						#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5100
						#$conf["varEqual"]=array(null,"found");
5101
						#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5102
						#$conf["varCon"]=array("no_tail"=>" not");
5103
						#參考資料:
5104
						#無.
5105
						#備註:
5106
						#無.
5107
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5108
						unset($conf["search::findSpecifyStrFormat"]);
5109
 
5110
						#如果執行異常
5111
						if($findSpecifyStrFormat["status"]==="false"){
5112
 
5113
							#設置錯誤識別
5114
							$result["status"]="false";
5115
 
5116
							#設置錯誤訊息
5117
							$result["error"]=$findSpecifyStrFormat;
5118
 
5119
							#回傳結果
5120
							return $result;
5121
 
5122
							}#if end
5123
 
5124
						#如果存在"
5125
						if($findSpecifyStrFormat["found"]==="true"){
5126
 
5127
							#取得無"的內容
5128
							$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
5129
 
5130
							#取得拆下來的含開頭"內容
5131
							$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
5132
 
5133
							}#if end
5134
 
5135
						#反之
5136
						else{
5137
 
5138
							#函式說明:
5139
							#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5140
							#回傳結果:
5141
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5142
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
5143
							#$result["function"],當前執行的函式名稱.
5144
							#$result["argu"],所使用的參數.
5145
							#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5146
							#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5147
							#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
5148
							#必填參數:
5149
							#$conf["input"],字串,要檢查的字串.
5150
							$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5151
							#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5152
							$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
5153
							#可省略參數:
5154
							#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5155
							#$conf["varEqual"]=array(null,"found");
5156
							#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5157
							#$conf["varCon"]=array("no_tail"=>" not");
5158
							#參考資料:
5159
							#無.
5160
							#備註:
5161
							#無.
5162
							$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5163
							unset($conf["search::findSpecifyStrFormat"]);
5164
 
5165
							#如果執行異常
5166
							if($findSpecifyStrFormat["status"]==="false"){
5167
 
5168
								#設置錯誤識別
5169
								$result["status"]="false";
5170
 
5171
								#設置錯誤訊息
5172
								$result["error"]=$findSpecifyStrFormat;
5173
 
5174
								#回傳結果
5175
								return $result;
5176
 
5177
								}#if end
5178
 
5179
							#如果存在";"
5180
							if($findSpecifyStrFormat["found"]==="true"){
5181
 
5182
								#取得無";"的內容
5183
								$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
5184
 
5185
								#取得拆下來的含開頭";"內容
5186
								$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
5187
 
5188
								}#if end
5189
 
5190
							}#else end
5191
 
5192
						}#else end
5193
 
5194
					#取得 serial number
5195
					#函式說明:
5196
					#將字串進行解析,變成多個參數.
5197
					#回傳結果:
5198
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
5199
					#$result["function"],當前執行的函式內容.
5200
					#$result["error"],錯誤訊息陣列.
5201
					#$result["content"],參數陣列.
5202
					#$result["count"],總共有幾個參數.
5203
					#必填參數:
5204
					#$conf["input"],字串,要解析成參數的字串.
5205
					$conf["stringProcess::parse"]["input"]=$unFormatStr;
5206
					#可省略參數:
5207
					#無.
5208
					#參考資料:
5209
					#無.
5210
					#備註:
5211
					#無.
5212
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
5213
					unset($conf["stringProcess::parse"]);
5214
 
5215
					#如果執行異常
5216
					if($parse["status"]==="false"){
5217
 
5218
						#設置錯誤識別
5219
						$result["status"]="false";
5220
 
5221
						#設置錯誤訊息
5222
						$result["error"]=$parse;
5223
 
5224
						#回傳結果
5225
						return $result;
5226
 
5227
						}#if end
5228
 
5229
					#取得serial number
5230
					$serialNo=$parse["content"][2];
5231
 
5232
					#serialNo+1
5233
					$serialNo++;
5234
 
5235
					#回存
5236
					$parse["content"][2]=(string)$serialNo;
5237
 
5238
					#函式說明:
5239
					#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
5240
					#回傳的結果:
5241
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5242
					#$result["function"],當前執行的function名稱
5243
					#$result["error"],錯誤訊息陣列.
5244
					#$result["content"],處理好的字串.
5245
					#$result["argu"],使用的參數.
5246
					#必填參數:
5247
					#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
5248
					$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
5249
					#可省略參數:
5250
					#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
5251
					$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
5252
					#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
5253
					$conf["arrays::arrayToString"]["skipEnd"]="true";
5254
					#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
5255
					#$conf["spiltSymbolAtStart"]="";
5256
					#參考資料:
5257
					#無.
5258
					#備註:
5259
					#無.
5260
					$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
5261
					unset($conf["arrays::arrayToString"]);
5262
 
5263
					#如果執行異常
5264
					if($arrayToString["status"]==="false"){
5265
 
5266
						#設置錯誤識別
5267
						$result["status"]="false";
5268
 
5269
						#設置錯誤訊息
5270
						$result["error"]=$arrayToString;
5271
 
5272
						#回傳結果
5273
						return $result;
5274
 
5275
						}#if end
5276
 
5277
					#取得更新 serial number 後的 SOA value string
5278
					$unFormatStr=$arrayToString["content"];
5279
 
5280
					#如果有要合併回去的內容
5281
					if(isset($unFormatStr2add)){
5282
 
5283
						#合併回去內容
5284
						$unFormatStr=$unFormatStr.$unFormatStr2add;
5285
 
5286
						#移除用不到的變數
5287
						unset($unFormatStr2add);
5288
 
5289
						}#if end
5290
 
5291
					#假設剩下的沒有註解都是 value
5292
					$info["value"]=$unFormatStr;
5293
 
5294
					#函式說明:
5295
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5296
					#回傳結果:
5297
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5298
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
5299
					#$result["function"],當前執行的函式名稱.
5300
					#$result["argu"],所使用的參數.
5301
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5302
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5303
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5304
					#必填參數:
5305
					#$conf["input"],字串,要檢查的字串.
5306
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5307
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5308
					$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
5309
					#可省略參數:
5310
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5311
					#$conf["varEqual"]=array(null,"found");
5312
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5313
					#$conf["varCon"]=array("no_tail"=>" not");
5314
					#參考資料:
5315
					#無.
5316
					#備註:
5317
					#無.
5318
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5319
					unset($conf["search::findSpecifyStrFormat"]);
5320
 
5321
					#如果執行異常
5322
					if($findSpecifyStrFormat["status"]==="false"){
5323
 
5324
						#設置錯誤識別
5325
						$result["status"]="false";
5326
 
5327
						#設置錯誤訊息
5328
						$result["error"]=$findSpecifyStrFormat;
5329
 
5330
						#回傳結果
5331
						return $result;
5332
 
5333
						}#if end
5334
 
5335
					#如果有符合格式
5336
					if($findSpecifyStrFormat["found"]==="true"){
5337
 
5338
						#儲存 value
5339
						$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5340
 
5341
						#儲存 comment
5342
						$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5343
 
5344
						}#if end
5345
 
5346
					#儲存該筆RR
5347
					$result["content"][]=$info;
5348
 
5349
					#換下解析下筆RR
5350
					continue 2;
5351
 
5352
					}#if end
5353
 
5354
				#執行到這邊代表不是 SOA
5355
 
5356
				#尋找是否有(...)...的內容存在
5357
				#函式說明:
5358
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5359
				#回傳結果:
5360
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5361
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5362
				#$result["function"],當前執行的函式名稱.
5363
				#$result["argu"],所使用的參數.
5364
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5365
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5366
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5367
				#必填參數:
5368
				#$conf["input"],字串,要檢查的字串.
5369
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5370
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5371
				$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
5372
				#可省略參數:
5373
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5374
				#$conf["varEqual"]=array(null,"found");
5375
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5376
				#$conf["varCon"]=array("no_tail"=>" not");
5377
				#參考資料:
5378
				#無.
5379
				#備註:
5380
				#無.
5381
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5382
				unset($conf["search::findSpecifyStrFormat"]);
5383
 
5384
				#如果執行異常
5385
				if($findSpecifyStrFormat["status"]==="false"){
5386
 
5387
					#設置錯誤識別
5388
					$result["status"]="false";
5389
 
5390
					#設置錯誤訊息
5391
					$result["error"]=$findSpecifyStrFormat;
5392
 
5393
					#回傳結果
5394
					return $result;
5395
 
5396
					}#if end
5397
 
5398
				#如果有 有符合 ($value);${comment} 的格式
5399
				if($findSpecifyStrFormat["found"]==="true"){
5400
 
5401
					#儲存value
5402
					$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
5403
 
5404
					#儲存comment
5405
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5406
 
5407
					#儲存 RR 的記錄
5408
					$result["content"][]=$info;
5409
 
5410
					#跳到下一筆要解析的RR
5411
					continue 2;
5412
 
5413
					}#if end
5414
 
5415
				#執行到這邊代表沒有 (...)... 的內容存在
5416
 
5417
				#尋找是否有 (...) 的內容存在
5418
				#函式說明:
5419
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5420
				#回傳結果:
5421
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5422
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5423
				#$result["function"],當前執行的函式名稱.
5424
				#$result["argu"],所使用的參數.
5425
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5426
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5427
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5428
				#必填參數:
5429
				#$conf["input"],字串,要檢查的字串.
5430
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5431
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5432
				$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
5433
				#可省略參數:
5434
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5435
				#$conf["varEqual"]=array(null,"found");
5436
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5437
				#$conf["varCon"]=array("no_tail"=>" not");
5438
				#參考資料:
5439
				#無.
5440
				#備註:
5441
				#無.
5442
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5443
				unset($conf["search::findSpecifyStrFormat"]);
5444
 
5445
				#如果執行異常
5446
				if($findSpecifyStrFormat["status"]==="false"){
5447
 
5448
					#設置錯誤識別
5449
					$result["status"]="false";
5450
 
5451
					#設置錯誤訊息
5452
					$result["error"]=$findSpecifyStrFormat;
5453
 
5454
					#回傳結果
5455
					return $result;
5456
 
5457
					}#if end
5458
 
5459
				#如果有 有符合 ($value);${comment} 的格式
5460
				if($findSpecifyStrFormat["found"]==="true"){
5461
 
5462
					#儲存value
5463
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5464
 
5465
					#儲存 RR 的記錄
5466
					$result["content"][]=$info;
5467
 
5468
					#跳到下一筆要解析的RR
5469
					continue 2;
5470
 
5471
					}#if end
5472
 
5473
				#執行到這邊代表沒有 (...) 的內容存在
5474
 
5475
				#尋找有無 "...";... 的內容存在
5476
				#函式說明:
5477
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5478
				#回傳結果:
5479
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5480
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5481
				#$result["function"],當前執行的函式名稱.
5482
				#$result["argu"],所使用的參數.
5483
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5484
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5485
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5486
				#必填參數:
5487
				#$conf["input"],字串,要檢查的字串.
5488
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5489
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5490
				$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
5491
				#可省略參數:
5492
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5493
				#$conf["varEqual"]=array(null,"found");
5494
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5495
				#$conf["varCon"]=array("no_tail"=>" not");
5496
				#參考資料:
5497
				#無.
5498
				#備註:
5499
				#無.
5500
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5501
				unset($conf["search::findSpecifyStrFormat"]);
5502
 
5503
				#如果執行異常
5504
				if($findSpecifyStrFormat["status"]==="false"){
5505
 
5506
					#設置錯誤識別
5507
					$result["status"]="false";
5508
 
5509
					#設置錯誤訊息
5510
					$result["error"]=$findSpecifyStrFormat;
5511
 
5512
					#回傳結果
5513
					return $result;
5514
 
5515
					}#if end
5516
 
5517
				#如果有 有符合 "$value";${comment} 的格式
5518
				if($findSpecifyStrFormat["found"]==="true"){
5519
 
5520
					#儲存value
5521
					$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
5522
 
5523
					#儲存comment
5524
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5525
 
5526
					#儲存 RR 的記錄
5527
					$result["content"][]=$info;
5528
 
5529
					#跳到下一筆要解析的RR
5530
					continue 2;
5531
 
5532
					}#if end
5533
 
5534
				#執行到這邊代表沒有 "$value";${comment} 的格式
5535
 
5536
				#尋找有無 "..." 的內容存在
5537
				#函式說明:
5538
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5539
				#回傳結果:
5540
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5541
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5542
				#$result["function"],當前執行的函式名稱.
5543
				#$result["argu"],所使用的參數.
5544
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5545
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5546
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5547
				#必填參數:
5548
				#$conf["input"],字串,要檢查的字串.
5549
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5550
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5551
				$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
5552
				#可省略參數:
5553
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5554
				#$conf["varEqual"]=array(null,"found");
5555
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5556
				#$conf["varCon"]=array("no_tail"=>" not");
5557
				#參考資料:
5558
				#無.
5559
				#備註:
5560
				#無.
5561
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5562
				unset($conf["search::findSpecifyStrFormat"]);
5563
 
5564
				#如果執行異常
5565
				if($findSpecifyStrFormat["status"]==="false"){
5566
 
5567
					#設置錯誤識別
5568
					$result["status"]="false";
5569
 
5570
					#設置錯誤訊息
5571
					$result["error"]=$findSpecifyStrFormat;
5572
 
5573
					#回傳結果
5574
					return $result;
5575
 
5576
					}#if end
5577
 
5578
				#如果有 有符合 "$value" 的格式
5579
				if($findSpecifyStrFormat["found"]==="true"){
5580
 
5581
					#儲存value
5582
					$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
5583
 
5584
					#儲存 RR 的記錄
5585
					$result["content"][]=$info;
5586
 
5587
					#跳到下一筆要解析的RR
5588
					continue 2;
5589
 
5590
					}#if end
5591
 
5592
				#執行到這邊代表沒有 "$value" 格式的內容
5593
 
5594
				#檢查是否有 $value;$comment 格式的內容
5595
				#函式說明:
5596
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5597
				#回傳結果:
5598
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5599
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5600
				#$result["function"],當前執行的函式名稱.
5601
				#$result["argu"],所使用的參數.
5602
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5603
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5604
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5605
				#必填參數:
5606
				#$conf["input"],字串,要檢查的字串.
5607
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5608
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5609
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
5610
				#可省略參數:
5611
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5612
				#$conf["varEqual"]=array(null,"found");
5613
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5614
				#$conf["varCon"]=array("no_tail"=>" not");
5615
				#參考資料:
5616
				#無.
5617
				#備註:
5618
				#無.
5619
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5620
				unset($conf["search::findSpecifyStrFormat"]);
5621
 
5622
				#如果執行異常
5623
				if($findSpecifyStrFormat["status"]==="false"){
5624
 
5625
					#設置錯誤識別
5626
					$result["status"]="false";
5627
 
5628
					#設置錯誤訊息
5629
					$result["error"]=$findSpecifyStrFormat;
5630
 
5631
					#回傳結果
5632
					return $result;
5633
 
5634
					}#if end
5635
 
5636
				#如果有 有符合 "$value" 的格式
5637
				if($findSpecifyStrFormat["found"]==="true"){
5638
 
5639
					#儲存value
5640
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5641
 
5642
					#儲存comment
5643
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5644
 
5645
					#儲存 RR 的記錄
5646
					$result["content"][]=$info;
5647
 
5648
					#跳到下一筆要解析的RR
5649
					continue 2;
5650
 
5651
					}#if end
5652
 
5653
				#執行到這邊代表沒有 ${value};${comment} 格式的內容
5654
 
5655
				#亦即剩下的內容都是 value
5656
 
5657
				#儲存value
5658
				$info["value"]=$unFormatStr;
5659
 
5660
				#儲存 RR 的記錄
5661
				$result["content"][]=$info;
5662
 
5663
				#跳到下一筆要解析的RR
5664
				continue 2;
5665
 
5666
				}#while end
5667
 
5668
			}#foreach end
291 liveuser 5669
 
5670
		#如果要啟用多執行序
5671
		if($conf["multiThread"]==="true"){
249 liveuser 5672
 
291 liveuser 5673
			#debug
5674
			var_dump($procs);
5675
 
5676
			#結束執行,回傳shell 1.
5677
			exit(1);
5678
 
5679
			}#if end
5680
 
253 liveuser 5681
		#如果要debug
5682
		if($conf["debug"]==="true"){
249 liveuser 5683
 
253 liveuser 5684
			#函式說明:
5685
			#撰寫log
5686
			#回傳結果:
5687
			#$result["status"],狀態,"true"或"false".
5688
			#$result["error"],錯誤訊息陣列.
5689
			#$result["function"],當前函式的名稱.
5690
			#$result["argu"],使用的參數.
5691
			#$result["content"],要寫入log的內容字串.
5692
			#必填參數:
5693
			#$conf["path"],字串,log檔案的路徑與名稱.
5694
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5695
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5696
			$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR fin.".PHP_EOL;
5697
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5698
			$conf["logs::record"]["fileArgu"]=__FILE__;
5699
			#可省略參數:
5700
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5701
			#$conf["rewrite"]="false";
5702
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5703
			#$conf["returnOnly"]="true";
5704
			#參考資料:
5705
			#無.
5706
			#備註:
5707
			#無.
5708
			$record=logs::record($conf["logs::record"]);
5709
			unset($conf["logs::record"]);
5710
 
5711
			}#if end
5712
 
249 liveuser 5713
		#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
5714
 
5715
		#針對每個要新增的RR記錄
255 liveuser 5716
		foreach($conf["add"] as $nri => $newRR){
249 liveuser 5717
 
255 liveuser 5718
			#如果要debug
5719
			if($conf["debug"]==="true"){
5720
 
5721
				#函式說明:
5722
				#撰寫log
5723
				#回傳結果:
5724
				#$result["status"],狀態,"true"或"false".
5725
				#$result["error"],錯誤訊息陣列.
5726
				#$result["function"],當前函式的名稱.
5727
				#$result["argu"],使用的參數.
5728
				#$result["content"],要寫入log的內容字串.
5729
				#必填參數:
5730
				#$conf["path"],字串,log檔案的路徑與名稱.
5731
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5732
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5733
				$conf["logs::record"]["content"]="lineNo:".__LINE__." ori newRR:".PHP_EOL;
5734
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5735
				$conf["logs::record"]["fileArgu"]=__FILE__;
5736
				#可省略參數:
5737
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5738
				#$conf["rewrite"]="false";
5739
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5740
				#$conf["returnOnly"]="true";
5741
				#參考資料:
5742
				#無.
5743
				#備註:
5744
				#無.
5745
				$record=logs::record($conf["logs::record"]);
5746
				unset($conf["logs::record"]);
5747
 
5748
				#函式說明:
5749
				#撰寫log
5750
				#回傳結果:
5751
				#$result["status"],狀態,"true"或"false".
5752
				#$result["error"],錯誤訊息陣列.
5753
				#$result["function"],當前函式的名稱.
5754
				#$result["argu"],使用的參數.
5755
				#$result["content"],要寫入log的內容字串.
5756
				#必填參數:
5757
				#$conf["path"],字串,log檔案的路徑與名稱.
5758
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5759
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5760
				$conf["logs::record"]["content"]=$newRR;
5761
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5762
				$conf["logs::record"]["fileArgu"]=__FILE__;
5763
				#可省略參數:
5764
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5765
				#$conf["rewrite"]="false";
5766
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5767
				#$conf["returnOnly"]="true";
5768
				#參考資料:
5769
				#無.
5770
				#備註:
5771
				#無.
5772
				$record=logs::record($conf["logs::record"]);
5773
				unset($conf["logs::record"]);
5774
 
5775
				}#if end
5776
 
5777
			#如果新的 RR 缺少必備的資訊
5778
			if(!isset($newRR["type"])){
5779
 
5780
				#設置執行異常
5781
				$result["status"]="false";
5782
 
5783
				#設置執行錯誤
5784
				$result["error"]="add參數的格式缺少type";
5785
 
5786
				#回傳結果
5787
				return $result;
5788
 
5789
				}#if end
5790
 
5791
			#如果 query 結尾不是"@"也不為"."結尾
5792
			if( ($newRR["query"]!=="@") && ($newRR["query"][strlen($newRR["query"])-1]!==".") ){
5793
 
5794
				#加上 "."
5795
				$conf["add"][$nri]["query"]=$newRR["query"]=$newRR["query"].".";
5796
 
5797
				}#if end
5798
 
5799
			#如果新的 query 為 $ORGIN 結尾
5800
			#函式說明:
5801
			#將字串特定關鍵字與其後面的內容剔除
5802
			#回傳結果:
5803
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5804
			#$result["error"],錯誤訊息陣列.
5805
			#$result["warning"],警告訊息鎮列.
5806
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
5807
			#$result["function"],當前執行的函數名稱.
5808
			#$result["oriStr"],要處理的原始字串內容.
5809
			#$result["content"],處理好的的字串內容.
5810
			#$result["deleted"],被移除的內容.
5811
			#$result["argu"],使用的參數.
5812
			#必填參數:
5813
			#$conf["stringIn"],字串,要處理的字串.
5814
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
5815
			#$conf["keyWord"],字串,特定字串.
5816
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["domain"];
5817
			#可省略參數:
5818
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
5819
			#$conf["deleteLastRepeatedOne"]="";
5820
			#參考資料:
5821
			#無.
5822
			#備註:
5823
			#無.
5824
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
5825
			unset($conf["stringProcess::delStrAfterKeyWord"]);
5826
 
5827
			#如果要debug
5828
			if($conf["debug"]==="true"){
5829
 
5830
				#函式說明:
5831
				#撰寫log
5832
				#回傳結果:
5833
				#$result["status"],狀態,"true"或"false".
5834
				#$result["error"],錯誤訊息陣列.
5835
				#$result["function"],當前函式的名稱.
5836
				#$result["argu"],使用的參數.
5837
				#$result["content"],要寫入log的內容字串.
5838
				#必填參數:
5839
				#$conf["path"],字串,log檔案的路徑與名稱.
5840
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5841
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5842
				$conf["logs::record"]["content"]="lineNo:".__LINE__." try process newRR with \$ORIGIN end".PHP_EOL;
5843
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5844
				$conf["logs::record"]["fileArgu"]=__FILE__;
5845
				#可省略參數:
5846
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5847
				#$conf["rewrite"]="false";
5848
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5849
				#$conf["returnOnly"]="true";
5850
				#參考資料:
5851
				#無.
5852
				#備註:
5853
				#無.
5854
				$record=logs::record($conf["logs::record"]);
5855
				unset($conf["logs::record"]);
5856
 
5857
				#函式說明:
5858
				#撰寫log
5859
				#回傳結果:
5860
				#$result["status"],狀態,"true"或"false".
5861
				#$result["error"],錯誤訊息陣列.
5862
				#$result["function"],當前函式的名稱.
5863
				#$result["argu"],使用的參數.
5864
				#$result["content"],要寫入log的內容字串.
5865
				#必填參數:
5866
				#$conf["path"],字串,log檔案的路徑與名稱.
5867
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5868
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5869
				$conf["logs::record"]["content"]=$delStrAfterKeyWord;
5870
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5871
				$conf["logs::record"]["fileArgu"]=__FILE__;
5872
				#可省略參數:
5873
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5874
				#$conf["rewrite"]="false";
5875
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5876
				#$conf["returnOnly"]="true";
5877
				#參考資料:
5878
				#無.
5879
				#備註:
5880
				#無.
5881
				$record=logs::record($conf["logs::record"]);
5882
				unset($conf["logs::record"]);
5883
 
5884
				}#if end
5885
 
5886
			#如果異常
5887
			if($delStrAfterKeyWord["status"]==="false"){
5888
 
5889
				#設置執行異常
5890
				$result["status"]="false";
5891
 
5892
				#設置執行錯誤
5893
				$result["error"]=$delStrAfterKeyWord;
5894
 
5895
				#回傳結果
5896
				return $result;
5897
 
5898
				}#if end
5899
 
5900
			#如果有找到 $ORIGIN 結尾
5901
			if($delStrAfterKeyWord["founded"]==="true"){
5902
 
5903
				#更新 query
5904
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
5905
 
5906
				#如果$newRR["query"] 變成 ""
5907
				if(empty($newRR["query"])){
5908
 
5909
					#變成 zone domain,亦即 $result["domain"]
5910
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
5911
 
5912
					}#if end
5913
 
5914
				#如果要debug
5915
				if($conf["debug"]==="true"){
5916
 
5917
					#函式說明:
5918
					#撰寫log
5919
					#回傳結果:
5920
					#$result["status"],狀態,"true"或"false".
5921
					#$result["error"],錯誤訊息陣列.
5922
					#$result["function"],當前函式的名稱.
5923
					#$result["argu"],使用的參數.
5924
					#$result["content"],要寫入log的內容字串.
5925
					#必填參數:
5926
					#$conf["path"],字串,log檔案的路徑與名稱.
5927
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5928
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5929
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
5930
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5931
					$conf["logs::record"]["fileArgu"]=__FILE__;
5932
					#可省略參數:
5933
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5934
					#$conf["rewrite"]="false";
5935
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5936
					#$conf["returnOnly"]="true";
5937
					#參考資料:
5938
					#無.
5939
					#備註:
5940
					#無.
5941
					$record=logs::record($conf["logs::record"]);
5942
					unset($conf["logs::record"]);
5943
 
5944
					#函式說明:
5945
					#撰寫log
5946
					#回傳結果:
5947
					#$result["status"],狀態,"true"或"false".
5948
					#$result["error"],錯誤訊息陣列.
5949
					#$result["function"],當前函式的名稱.
5950
					#$result["argu"],使用的參數.
5951
					#$result["content"],要寫入log的內容字串.
5952
					#必填參數:
5953
					#$conf["path"],字串,log檔案的路徑與名稱.
5954
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5955
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5956
					$conf["logs::record"]["content"]=$conf["add"][$nri];
5957
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5958
					$conf["logs::record"]["fileArgu"]=__FILE__;
5959
					#可省略參數:
5960
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5961
					#$conf["rewrite"]="false";
5962
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5963
					#$conf["returnOnly"]="true";
5964
					#參考資料:
5965
					#無.
5966
					#備註:
5967
					#無.
5968
					$record=logs::record($conf["logs::record"]);
5969
					unset($conf["logs::record"]);
5970
 
5971
					}#if end
5972
 
5973
				}#if end
5974
 
5975
			#如果新的 query 為 "." 結尾
5976
			#函式說明:
5977
			#將字串特定關鍵字與其後面的內容剔除
5978
			#回傳結果:
5979
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5980
			#$result["error"],錯誤訊息陣列.
5981
			#$result["warning"],警告訊息鎮列.
5982
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
5983
			#$result["function"],當前執行的函數名稱.
5984
			#$result["oriStr"],要處理的原始字串內容.
5985
			#$result["content"],處理好的的字串內容.
5986
			#$result["deleted"],被移除的內容.
5987
			#$result["argu"],使用的參數.
5988
			#必填參數:
5989
			#$conf["stringIn"],字串,要處理的字串.
5990
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
5991
			#$conf["keyWord"],字串,特定字串.
5992
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".";
5993
			#可省略參數:
5994
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
5995
			#$conf["deleteLastRepeatedOne"]="";
5996
			#參考資料:
5997
			#無.
5998
			#備註:
5999
			#無.
6000
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
6001
			unset($conf["stringProcess::delStrAfterKeyWord"]);
6002
 
6003
			#如果異常
6004
			if($delStrAfterKeyWord["status"]==="false"){
6005
 
6006
				#設置執行異常
6007
				$result["status"]="false";
6008
 
6009
				#設置執行錯誤
6010
				$result["error"]=$delStrAfterKeyWord;
6011
 
6012
				#回傳結果
6013
				return $result;
6014
 
6015
				}#if end
6016
 
6017
			#如果有找到 "." 結尾
6018
			if($delStrAfterKeyWord["founded"]==="true"){
6019
 
6020
				#更新 query
6021
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
6022
 
6023
				#如果 $newRR["query"] 變成 ""
6024
				if(empty($newRR["query"])){
6025
 
6026
					#變成 zone domain,亦即 $result["domain"]
6027
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
6028
 
6029
					}#if end
6030
 
6031
				#如果要debug
6032
				if($conf["debug"]==="true"){
6033
 
6034
					#函式說明:
6035
					#撰寫log
6036
					#回傳結果:
6037
					#$result["status"],狀態,"true"或"false".
6038
					#$result["error"],錯誤訊息陣列.
6039
					#$result["function"],當前函式的名稱.
6040
					#$result["argu"],使用的參數.
6041
					#$result["content"],要寫入log的內容字串.
6042
					#必填參數:
6043
					#$conf["path"],字串,log檔案的路徑與名稱.
6044
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6045
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6046
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
6047
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6048
					$conf["logs::record"]["fileArgu"]=__FILE__;
6049
					#可省略參數:
6050
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6051
					#$conf["rewrite"]="false";
6052
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6053
					#$conf["returnOnly"]="true";
6054
					#參考資料:
6055
					#無.
6056
					#備註:
6057
					#無.
6058
					$record=logs::record($conf["logs::record"]);
6059
					unset($conf["logs::record"]);
6060
 
6061
					#函式說明:
6062
					#撰寫log
6063
					#回傳結果:
6064
					#$result["status"],狀態,"true"或"false".
6065
					#$result["error"],錯誤訊息陣列.
6066
					#$result["function"],當前函式的名稱.
6067
					#$result["argu"],使用的參數.
6068
					#$result["content"],要寫入log的內容字串.
6069
					#必填參數:
6070
					#$conf["path"],字串,log檔案的路徑與名稱.
6071
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6072
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6073
					$conf["logs::record"]["content"]=$conf["add"][$nri];
6074
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6075
					$conf["logs::record"]["fileArgu"]=__FILE__;
6076
					#可省略參數:
6077
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6078
					#$conf["rewrite"]="false";
6079
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6080
					#$conf["returnOnly"]="true";
6081
					#參考資料:
6082
					#無.
6083
					#備註:
6084
					#無.
6085
					$record=logs::record($conf["logs::record"]);
6086
					unset($conf["logs::record"]);
6087
 
6088
					}#if end
6089
 
6090
				}#if end
6091
 
6092
			#如果新 RR 的 type 不是 A 且 value 不為 "." 結尾.
6093
			if( $newRR["type"]!=="A" && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
6094
 
6095
				#new RR add dot to value end.
6096
				$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
6097
 
6098
				#如果要debug
6099
				if($conf["debug"]==="true"){
6100
 
6101
					#函式說明:
6102
					#撰寫log
6103
					#回傳結果:
6104
					#$result["status"],狀態,"true"或"false".
6105
					#$result["error"],錯誤訊息陣列.
6106
					#$result["function"],當前函式的名稱.
6107
					#$result["argu"],使用的參數.
6108
					#$result["content"],要寫入log的內容字串.
6109
					#必填參數:
6110
					#$conf["path"],字串,log檔案的路徑與名稱.
6111
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6112
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6113
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
6114
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6115
					$conf["logs::record"]["fileArgu"]=__FILE__;
6116
					#可省略參數:
6117
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6118
					#$conf["rewrite"]="false";
6119
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6120
					#$conf["returnOnly"]="true";
6121
					#參考資料:
6122
					#無.
6123
					#備註:
6124
					#無.
6125
					$record=logs::record($conf["logs::record"]);
6126
					unset($conf["logs::record"]);
6127
 
6128
					#函式說明:
6129
					#撰寫log
6130
					#回傳結果:
6131
					#$result["status"],狀態,"true"或"false".
6132
					#$result["error"],錯誤訊息陣列.
6133
					#$result["function"],當前函式的名稱.
6134
					#$result["argu"],使用的參數.
6135
					#$result["content"],要寫入log的內容字串.
6136
					#必填參數:
6137
					#$conf["path"],字串,log檔案的路徑與名稱.
6138
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6139
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6140
					$conf["logs::record"]["content"]=$conf["add"][$nri];
6141
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6142
					$conf["logs::record"]["fileArgu"]=__FILE__;
6143
					#可省略參數:
6144
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6145
					#$conf["rewrite"]="false";
6146
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6147
					#$conf["returnOnly"]="true";
6148
					#參考資料:
6149
					#無.
6150
					#備註:
6151
					#無.
6152
					$record=logs::record($conf["logs::record"]);
6153
					unset($conf["logs::record"]);
6154
 
6155
					}#if end
6156
 
6157
				}#if end
6158
 
249 liveuser 6159
			#針對 zone file 中既有的每個RR記錄
6160
			foreach($result["content"] as $index => $oldRR){
6161
 
6162
				#如果既有的跟新的RR都為 $ORIGIN
6163
				if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
6164
 
6165
					#取代既有的 RR
6166
					$result["content"][$index]=$newRR;
6167
 
6168
					#換看下一筆newRR
6169
					continue 2;
6170
 
6171
					}#if end
6172
 
6173
				#如果既有的跟新的RR都為 $TTL
6174
				if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
6175
 
6176
					#取代既有的 RR
6177
					$result["content"][$index]=$newRR;
6178
 
6179
					#換看下一筆newRR
6180
					continue 2;
6181
 
6182
					}#if end
6183
 
253 liveuser 6184
				#如果新舊資料都有query資訊
6185
				if( isset($newRR["query"]) && isset($oldRR["query"]) ){
249 liveuser 6186
 
253 liveuser 6187
					#如果跟既有的 query、type、value 有相同
6188
					if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
249 liveuser 6189
 
253 liveuser 6190
						#如果新 RR 有 update time
6191
						if(isset($newRR["update"])){
249 liveuser 6192
 
253 liveuser 6193
							#如果新舊 update time 不相同
6194
							if( $newRR["update"] !== $oldRR["update"] ){
249 liveuser 6195
 
253 liveuser 6196
								#取代既有的 RR
6197
								$result["content"][$index]=$newRR;
6198
 
6199
								#換看下一筆newRR
6200
								continue 2;
6201
 
6202
								}#if end
6203
 
6204
							}#if end
249 liveuser 6205
 
253 liveuser 6206
						#反之既有的 update time 若跟 global TTL 不一樣
6207
						else if( $oldRR["update"] !== $result["defaultTTL"] ){
6208
 
6209
							#更新為 global TTL
6210
							$result["content"][$index]["update"]=$result["defaultTTL"];
6211
 
249 liveuser 6212
							}#if end
253 liveuser 6213
 
6214
						#如果新 RR 有 comment
6215
						if( isset($newRR["comment"]) ){
249 liveuser 6216
 
253 liveuser 6217
							#更新既有 RR 的 comment
6218
							$result["content"][$index]["comment"]=$newRR["comment"];
249 liveuser 6219
 
253 liveuser 6220
							#換看下一筆newRR
6221
							continue 2;
249 liveuser 6222
 
253 liveuser 6223
							}#if end
6224
 
6225
						#反之,如果有既有 comment
6226
						else if(isset($result["content"][$index]["comment"])){
249 liveuser 6227
 
253 liveuser 6228
							#移除既有 comment
6229
							unset($result["content"][$index]["comment"]);
6230
 
6231
							#換看下一筆newRR
6232
							continue 2;
249 liveuser 6233
 
253 liveuser 6234
							}#else end
249 liveuser 6235
 
253 liveuser 6236
						}#if end
249 liveuser 6237
 
6238
					}#if end
253 liveuser 6239
 
249 liveuser 6240
				}#foreach end
6241
 
6242
			#儲存確定要新增的RR
6243
			$result["content"][]=$newRR;
6244
 
6245
			}#foreach end
6246
 
255 liveuser 6247
		#如果要debug
6248
		if($conf["debug"]==="true"){
249 liveuser 6249
 
255 liveuser 6250
			#函式說明:
6251
			#撰寫log
6252
			#回傳結果:
6253
			#$result["status"],狀態,"true"或"false".
6254
			#$result["error"],錯誤訊息陣列.
6255
			#$result["function"],當前函式的名稱.
6256
			#$result["argu"],使用的參數.
6257
			#$result["content"],要寫入log的內容字串.
6258
			#必填參數:
6259
			#$conf["path"],字串,log檔案的路徑與名稱.
6260
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6261
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6262
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
6263
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6264
			$conf["logs::record"]["fileArgu"]=__FILE__;
6265
			#可省略參數:
6266
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6267
			#$conf["rewrite"]="false";
6268
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6269
			#$conf["returnOnly"]="true";
6270
			#參考資料:
6271
			#無.
6272
			#備註:
6273
			#無.
6274
			$record=logs::record($conf["logs::record"]);
6275
			unset($conf["logs::record"]);
249 liveuser 6276
 
255 liveuser 6277
			}#if end
6278
 
6279
		#如果要debug
6280
		if($conf["debug"]==="true"){
6281
 
6282
			#函式說明:
6283
			#撰寫log
6284
			#回傳結果:
6285
			#$result["status"],狀態,"true"或"false".
6286
			#$result["error"],錯誤訊息陣列.
6287
			#$result["function"],當前函式的名稱.
6288
			#$result["argu"],使用的參數.
6289
			#$result["content"],要寫入log的內容字串.
6290
			#必填參數:
6291
			#$conf["path"],字串,log檔案的路徑與名稱.
6292
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6293
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6294
			$conf["logs::record"]["content"]=$result["content"];
6295
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6296
			$conf["logs::record"]["fileArgu"]=__FILE__;
6297
			#可省略參數:
6298
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6299
			#$conf["rewrite"]="false";
6300
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6301
			#$conf["returnOnly"]="true";
6302
			#參考資料:
6303
			#無.
6304
			#備註:
6305
			#無.
6306
			$record=logs::record($conf["logs::record"]);
6307
			unset($conf["logs::record"]);
6308
 
6309
			}#if end
6310
 
249 liveuser 6311
		#初始化要寫入的內容
6312
		$strs2write=array();
6313
 
6314
		#針對每個RR記錄
6315
		foreach($result["content"] as $RR){
6316
 
6317
			#初始化暫存要寫入的行內容
6318
			$str2write="";
6319
 
6320
			#如果是
6321
			if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
6322
 
6323
				#組合變數名稱與數值
6324
				$str2write=$str2write.$RR["type"]."\t".$RR["value"];
6325
 
6326
				}#if end
6327
 
6328
			#反之
6329
			else{
6330
 
6331
				#加上查詢的字句
6332
				$str2write=$str2write.$RR["query"];
6333
 
6334
				#如果該筆RR有指定update time該ZONE具備 global TTL.
6335
				if(isset($RR["update"])){
6336
 
6337
					#如果 該ZONE具備 global TTL.
6338
					if(isset($result["defaultTTL"])){
6339
 
6340
						#如果該筆 RR 的 update time 不等於 global TTL
6341
						if($RR["update"]!==$result["defaultTTL"]){
6342
 
6343
							#加上TTL的字句
6344
							$str2write=$str2write."\t".$RR["update"];
6345
 
6346
							}#if end
6347
 
6348
						}#if end
6349
 
6350
					#反之
6351
					else{
6352
 
6353
						#加上TTL的字句
6354
						$str2write=$str2write."\t".$RR["update"];
6355
 
6356
						}#else end
6357
 
6358
					}#if end
6359
 
253 liveuser 6360
				#反之且該ZONE不具備 global TTL.
6361
				else if(!isset($result["defaultTTL"])){
249 liveuser 6362
 
6363
					#加上global TTL的字句
6364
					$str2write=$str2write."\t".$result["defaultTTL"];
6365
 
253 liveuser 6366
					}#if end
249 liveuser 6367
 
6368
				#加上IN跟TYPE跟value
6369
				$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
6370
 
6371
				}#else end
6372
 
6373
			#如果有註解
6374
			if(isset($RR["comment"])){
6375
 
6376
				#加上comment
6377
				$str2write=$str2write.";".$RR["comment"];
6378
 
6379
				}#if end
6380
 
253 liveuser 6381
			#如果要 debug
6382
			if($conf["debug"]==="true"){
249 liveuser 6383
 
253 liveuser 6384
				#函式說明:
6385
				#撰寫log
6386
				#回傳結果:
6387
				#$result["status"],狀態,"true"或"false".
6388
				#$result["error"],錯誤訊息陣列.
6389
				#$result["function"],當前函式的名稱.
6390
				#$result["argu"],使用的參數.
6391
				#$result["content"],要寫入log的內容字串.
6392
				#必填參數:
6393
				#$conf["path"],字串,log檔案的路徑與名稱.
6394
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6395
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6396
				$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
6397
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6398
				$conf["logs::record"]["fileArgu"]=__FILE__;
6399
				#可省略參數:
6400
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6401
				#$conf["rewrite"]="false";
6402
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6403
				#$conf["returnOnly"]="true";
6404
				#參考資料:
6405
				#無.
6406
				#備註:
6407
				#無.
6408
				$record=logs::record($conf["logs::record"]);
6409
				unset($conf["logs::record"]);
6410
 
6411
				}#if end
6412
 
249 liveuser 6413
			#加上要寫入的元素
6414
			$strs2write[]=$str2write;
6415
 
6416
			}#foreach end
6417
 
6418
		#如果有逐行註解
6419
		if(count($result["comment"])>0){
6420
 
6421
			#加到結尾
6422
			#函式說明:
6423
			#將多個一維陣列串聯起來,key從0開始排序.
6424
			#回傳的結果:
6425
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
6426
			#$result["error"],錯誤訊息陣列.
6427
			#$result["function"],當前執行的函數.
6428
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6429
			#$result["content"],合併好的一維陣列.
6430
			#必填參數
6431
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
6432
			$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
6433
			#可省略參數:
6434
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
6435
			#$conf["allowRepeat"]="true";
6436
			#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
6437
			#$conf["looseDiff"]="false";
6438
			#參考資料:
6439
			#無.
6440
			#備註:
6441
			#無.
6442
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
6443
			unset($conf["arrays::mergeArray"]);
6444
 
6445
			#如果執行異常
6446
			if($mergeArray["status"]==="false"){
6447
 
6448
				#設置錯誤識別
6449
				$result["status"]="false";
6450
 
6451
				#設置錯誤訊息
6452
				$result["error"]=$mergeArray;
6453
 
6454
				#回傳結果
6455
				return $result;
6456
 
6457
				}#if end
6458
 
6459
			#取得合併好的陣列
6460
			$strs2write=$mergeArray["content"];
6461
 
6462
			}#if end
6463
 
253 liveuser 6464
		#如果要 debug
6465
		if($conf["debug"]==="true"){
249 liveuser 6466
 
253 liveuser 6467
			#函式說明:
6468
			#撰寫log
6469
			#回傳結果:
6470
			#$result["status"],狀態,"true"或"false".
6471
			#$result["error"],錯誤訊息陣列.
6472
			#$result["function"],當前函式的名稱.
6473
			#$result["argu"],使用的參數.
6474
			#$result["content"],要寫入log的內容字串.
6475
			#必填參數:
6476
			#$conf["path"],字串,log檔案的路徑與名稱.
6477
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6478
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6479
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
6480
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6481
			$conf["logs::record"]["fileArgu"]=__FILE__;
6482
			#可省略參數:
6483
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6484
			#$conf["rewrite"]="false";
6485
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6486
			#$conf["returnOnly"]="true";
6487
			#參考資料:
6488
			#無.
6489
			#備註:
6490
			#無.
6491
			$record=logs::record($conf["logs::record"]);
6492
			unset($conf["logs::record"]);
6493
 
6494
			}#if end
6495
 
249 liveuser 6496
		#儲存新zone file每行的內容
6497
		$result["newZoneFileContent"]=$strs2write;
6498
 
6499
		#如果要寫入ZONE檔案
6500
		if($conf["writeNow"]==="true"){
6501
 
6502
			#覆寫 ZONE file
6503
			#函式說明:
6504
			#更新檔案的內容.
6505
			#回傳結果:
6506
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6507
			#$result["error"],錯誤訊息.
6508
			#$result["function"],當前執行的函數名稱.
6509
			#$result["content"],更新的資訊.
6510
			#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
6511
			#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
6512
			#必填參數:
6513
			#$conf["fileArgu"],字串,變數__FILE__的內容.
6514
			$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
6515
			#$conf["file"],字串,要更新的檔案位置與名稱.
6516
			$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
6517
			#可省略參數:
6518
			#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
6519
			$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
6520
			#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
6521
			#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
6522
			#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
6523
			#$conf["replaceLike"]="false";
6524
			#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
6525
			#$conf["addToTailWhenNoMatch"]="false";
6526
			#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
6527
			#$conf["addToTailBeforeThat"]="?\>";
6528
			#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
6529
			#$conf["replaceSpecifyLine"]=array();
6530
			#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
6531
			#$conf["outputPath"]="";
6532
			#參考資料:
6533
			#無.
6534
			#備註:
6535
			#無.
6536
			$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
6537
			unset($conf["fileAccess::updateFile"]);
6538
 
6539
			#如果執行異常
6540
			if($updateFile["status"]==="false"){
6541
 
6542
				#設置錯誤識別
6543
				$result["status"]="false";
6544
 
6545
				#設置錯誤訊息
6546
				$result["error"]=$updateFile;
6547
 
6548
				#回傳結果
6549
				return $result;
6550
 
6551
				}#if end
291 liveuser 6552
 
6553
			#修正 zone file 的權限
6554
			#函式說明:
6555
			#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
6556
			#回傳結果:
6557
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6558
			#$result["error"],錯誤訊息.
6559
			#$result["function"],當前執行的函式名稱.
6560
			#$result["cmd"],執行的指令.
6561
			#必填參數:
6562
			#$conf["owner"],字串,要變哪個使用者擁有.
6563
			$conf["cmd::chown"]["owner"]="root";
6564
			#$conf["target"],字串,需要變更擁有者、 群組的目標.
6565
			$conf["cmd::chown"]["target"]=$conf["dnsRecordFile"];
6566
			#可省略參數:
6567
			#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
6568
			$conf["cmd::chown"]["group"]=webUser;
6569
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
6570
			#$conf["recursive"]="true";
6571
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
6572
			#$conf["excludeSelf"]="true";
6573
			#參考資料:
6574
			#無.
6575
			#備註:
6576
			#無.
6577
			$chown=cmd::chown($conf["cmd::chown"]);
6578
			unset($conf["cmd::chown"]);
249 liveuser 6579
 
291 liveuser 6580
			#如果執行異常
6581
			if($chown["status"]==="false"){
6582
 
6583
				#設置錯誤識別
6584
				$result["status"]="false";
6585
 
6586
				#設置錯誤訊息
6587
				$result["error"]=$chown;
6588
 
6589
				#回傳結果
6590
				return $result;
6591
 
6592
				}#if end
6593
 
6594
			#函式說明:
6595
			#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
6596
			#回傳結果:
6597
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6598
			#$result["error"],錯誤訊息.
6599
			#$result["function"],當前執行的函式名稱.
6600
			#$result["cmd"],執行的指令.
6601
			#必填參數:
6602
			#$conf["mode"],字串,要變成什麼權限.
6603
			$conf["cmd::chmod"]["mode"]="774";
6604
			#$conf["target"],字串,需要變更權限的目標.
6605
			$conf["cmd::chmod"]["target"]=$conf["dnsRecordFile"];
6606
			#可省略參數:
6607
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
6608
			#$conf["recursive"]="true";
6609
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
6610
			#$conf["excludeSelf"]="true";
6611
			#參考資料:
6612
			#無.
6613
			#備註:
6614
			#無.
6615
			$chmod=cmd::chmod($conf["cmd::chmod"]);
6616
			unset($conf["cmd::chmod"]);
6617
 
6618
			#如果執行異常
6619
			if($chmod["status"]==="false"){
6620
 
6621
				#設置錯誤識別
6622
				$result["status"]="false";
6623
 
6624
				#設置錯誤訊息
6625
				$result["error"]=$chmod;
6626
 
6627
				#回傳結果
6628
				return $result;
6629
 
6630
				}#if end
6631
 
249 liveuser 6632
			}#if end
6633
 
6634
		#設置執行正常
6635
		$result["status"]="true";
6636
 
6637
		#回傳結果
6638
		return $result;
6639
 
6640
		}#function updateDnsRecordFile end
6641
 
6642
	/*
6643
	#函式說明:
255 liveuser 6644
	#請求驗證已經透過zerossl::createCertificate要求的domain.
249 liveuser 6645
	#回傳結果:
6646
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6647
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6648
	#$result["function"],當前執行的函式名稱.
6649
	#$result["argu"],所使用的參數.
6650
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 6651
	#$result["content"],結果json字串.
249 liveuser 6652
	#必填參數:
6653
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
6654
	$conf["id"]="";
6655
	#可省略參數:
6656
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6657
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6658
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6659
	#$conf["key"]=self::getApiInfo()["apiKey"];
6660
	#參考資料:
255 liveuser 6661
	#https://zerossl.com/documentation/api/verify-domains/
249 liveuser 6662
	#備註:
6663
	#無.
6664
	*/
6665
	public static function verifyDomain(&$conf){
6666
 
6667
		#初始化要回傳的結果
6668
		$result=array();
6669
 
6670
		#設置當其函數名稱
6671
		$result["function"]=__FUNCTION__;
6672
 
6673
		#如果 $conf 不為陣列
6674
		if(gettype($conf)!="array"){
6675
 
6676
			#設置執行失敗
6677
			$result["status"]="false";
6678
 
6679
			#設置執行錯誤訊息
6680
			$result["error"][]="\$conf變數須為陣列形態";
6681
 
6682
			#如果傳入的參數為 null
6683
			if($conf==null){
6684
 
6685
				#設置執行錯誤訊息
6686
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6687
 
6688
				}#if end
6689
 
6690
			#回傳結果
6691
			return $result;
6692
 
6693
			}#if end
6694
 
6695
		#取得參數
6696
		$result["argu"]=$conf;
6697
 
6698
		#檢查參數
6699
		#函式說明:
6700
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6701
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6702
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6703
		#$result["function"],當前執行的函式名稱.
6704
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6705
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6706
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6707
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6708
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6709
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6710
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6711
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6712
		#必填寫的參數:
6713
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6714
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6715
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6716
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6717
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6718
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6719
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6720
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6721
		#可以省略的參數:
6722
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6723
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6724
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6725
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6726
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6727
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
6728
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6729
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
6730
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 6731
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
249 liveuser 6732
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6733
		#$conf["arrayCountEqualCheck"][]=array();
6734
		#參考資料來源:
6735
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6736
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6737
		unset($conf["variableCheck::checkArguments"]);
6738
 
6739
		#如果檢查失敗
6740
		if($checkArguments["status"]==="false"){
6741
 
6742
			#設置錯誤識別
6743
			$result["status"]="false";
6744
 
6745
			#設置錯誤訊息
6746
			$result["error"]=$checkArguments;
6747
 
6748
			#回傳結果
6749
			return $result;
6750
 
6751
			}#if end
6752
 
6753
		#如果檢查不通過
6754
		if($checkArguments["passed"]==="false"){
6755
 
6756
			#設置錯誤識別
6757
			$result["status"]="false";
6758
 
6759
			#設置錯誤訊息
6760
			$result["error"]=$checkArguments;
6761
 
6762
			#回傳結果
6763
			return $result;
6764
 
6765
			}#if end
6766
 
6767
		#要傳送的 key -> value
6768
		$postArray=array();
6769
 
6770
		#設置要簽署的domain
6771
		$postArray["validation_method"]="CNAME_CSR_HASH";
6772
 
6773
		#設置要傳送的 json
6774
		$postJson=json_encode($postArray);
6775
 
6776
		#函式說明:
6777
		#運行curl cmd
6778
		#回傳結果:
6779
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6780
		#$result["error"],錯誤訊息陣列.
6781
		#$result["function"],當前執行的函式名稱.
6782
		#$result["founded"],識別網址找不找得到.
6783
		#$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"代表程序的資訊.
6784
		#$result["fullContent"],取得回應的完整字串內容.
6785
		#$result["cookie"],cookie檔案的位置與名稱.
6786
		#$result["cmd"],執行的command.
6787
		#$result["argu],使用的參數.
6788
		#必填參數:
6789
		#$conf["url"],字串,目標url.
255 liveuser 6790
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
249 liveuser 6791
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6792
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6793
		#可省略參數:
6794
		#$conf["header"],字串陣列,要傳送的header.
6795
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
6796
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6797
		#$conf["allowAnySSLcertificate"]="";
6798
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6799
		#$conf["postVar"]=array();
6800
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6801
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6802
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
6803
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
6804
		#$conf["agent"],字串,user agent的名稱.
6805
		#$conf["agent"]="";
6806
		#$conf["cookie"],字串,cookie位置與檔案位置.
6807
		#$conf["cookie"]="";
6808
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6809
		#$conf["forceNewCookie"]="";
6810
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6811
		#$conf["inBg"]="true";
6812
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6813
		#$conf["bgInProc"]="false";
6814
		#參考資料:
6815
		#無.
6816
		#備註:
6817
		#無.
6818
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6819
		unset($conf["catchWebContent::curlCmd"]);
6820
 
6821
		#如果異常
6822
		if($curlCmd["status"]==="false"){
6823
 
6824
			#設置錯誤識別
6825
			$result["status"]="false";
6826
 
6827
			#設置錯誤訊息
6828
			$result["error"]=$curlCmd;
6829
 
6830
			#回傳結果
6831
			return $result;
6832
 
6833
			}#if end
6834
 
6835
		#設置curl的詳細資訊
6836
		$result["curl_verbose_info"]=$curlCmd;
6837
 
255 liveuser 6838
		#驗證結果是否為 json
6839
		$json_validate=json_validate($curlCmd["fullContent"]);
6840
 
6841
		#如果回應不是 json
6842
		if(!$json_validate){
249 liveuser 6843
 
255 liveuser 6844
			#設置錯誤識別
6845
			$result["status"]="false";
6846
 
6847
			#設置錯誤訊息
6848
			$result["error"]=$curlCmd;
6849
 
6850
			#回傳結果
6851
			return $result;
6852
 
6853
			}#if end
6854
 
6855
		#設置json string結果
6856
		$result["content"]=$curlCmd["fullContent"];
6857
 
6858
		#解析json
6859
		$jsonRes=json_decode($result["content"]);
6860
 
6861
		#如果沒有 status
6862
		if(!isset($jsonRes->status)){
6863
 
6864
			#設置錯誤識別
6865
			$result["status"]="false";
6866
 
6867
			#設置錯誤訊息
6868
			$result["error"]=$curlCmd;
6869
 
6870
			#回傳結果
6871
			return $result;
6872
 
6873
			}#if end
6874
 
6875
		#如果是 "pending_validation"
6876
		if($json->status==="pending_validation"){
6877
 
6878
			#do nothing
6879
 
6880
			}#if end
6881
 
6882
		#反之如果為 "issued"
6883
		else if($json->status==="issued"){
6884
 
6885
			#do nothing
6886
 
6887
			}#else 
6888
 
6889
		#反之
6890
		else{
6891
 
6892
			#設置錯誤識別
6893
			$result["status"]="false";
6894
 
6895
			#設置錯誤訊息
6896
			$result["error"]=$curlCmd;
6897
 
6898
			#回傳結果
6899
			return $result;
6900
 
6901
			}#else end
6902
 
6903
 
6904
		#設置執行正常
6905
		$result["status"]="true";
6906
 
6907
		#回傳結果
6908
		return $result;
6909
 
6910
		}#function verifyDomain end
6911
 
6912
	/*
6913
	#函式說明:
6914
	#取得CSR在zerossl上的狀態
6915
	#回傳結果:
6916
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6917
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6918
	#$result["function"],當前執行的函式名稱.
6919
	#$result["argu"],所使用的參數.
6920
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6921
	#$result["content"],結果json字串.
6922
	#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6923
	#必填參數:
6924
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
6925
	$conf["id"]="";
6926
	#可省略參數:
6927
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6928
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6929
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6930
	#$conf["key"]=self::getApiInfo()["apiKey"];
6931
	#參考資料:
6932
	#https://zerossl.com/documentation/api/get-certificate/
6933
	#備註:
6934
	#無.
6935
	*/
6936
	public static function getCertSta(&$conf){
6937
 
6938
		#初始化要回傳的結果
6939
		$result=array();
6940
 
6941
		#設置當其函數名稱
6942
		$result["function"]=__FUNCTION__;
6943
 
6944
		#如果 $conf 不為陣列
6945
		if(gettype($conf)!="array"){
6946
 
6947
			#設置執行失敗
6948
			$result["status"]="false";
6949
 
6950
			#設置執行錯誤訊息
6951
			$result["error"][]="\$conf變數須為陣列形態";
6952
 
6953
			#如果傳入的參數為 null
6954
			if($conf==null){
6955
 
6956
				#設置執行錯誤訊息
6957
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6958
 
6959
				}#if end
6960
 
6961
			#回傳結果
6962
			return $result;
6963
 
6964
			}#if end
6965
 
6966
		#取得參數
6967
		$result["argu"]=$conf;
291 liveuser 6968
 
6969
		#DEBUG
6970
		#var_dump(__LINE__,self::getApiInfo());exit;
255 liveuser 6971
 
6972
		#檢查參數
6973
		#函式說明:
6974
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6975
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6976
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6977
		#$result["function"],當前執行的函式名稱.
6978
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6979
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6980
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6981
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6982
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6983
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6984
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6985
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6986
		#必填寫的參數:
6987
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6988
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6989
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6990
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6991
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6992
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6993
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6994
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6995
		#可以省略的參數:
6996
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6997
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6998
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6999
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7000
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7001
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
7002
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7003
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
7004
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7005
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
7006
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7007
		#$conf["arrayCountEqualCheck"][]=array();
7008
		#參考資料來源:
7009
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7010
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7011
		unset($conf["variableCheck::checkArguments"]);
7012
 
7013
		#如果檢查失敗
7014
		if($checkArguments["status"]==="false"){
7015
 
7016
			#設置錯誤識別
7017
			$result["status"]="false";
7018
 
7019
			#設置錯誤訊息
7020
			$result["error"]=$checkArguments;
7021
 
7022
			#回傳結果
7023
			return $result;
7024
 
7025
			}#if end
7026
 
7027
		#如果檢查不通過
7028
		if($checkArguments["passed"]==="false"){
7029
 
7030
			#設置錯誤識別
7031
			$result["status"]="false";
7032
 
7033
			#設置錯誤訊息
7034
			$result["error"]=$checkArguments;
7035
 
7036
			#回傳結果
7037
			return $result;
7038
 
7039
			}#if end
7040
 
7041
		#函式說明:
7042
		#運行curl cmd
7043
		#回傳結果:
7044
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7045
		#$result["error"],錯誤訊息陣列.
7046
		#$result["function"],當前執行的函式名稱.
7047
		#$result["founded"],識別網址找不找得到.
7048
		#$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"代表程序的資訊.
7049
		#$result["fullContent"],取得回應的完整字串內容.
7050
		#$result["cookie"],cookie檔案的位置與名稱.
7051
		#$result["cmd"],執行的command.
7052
		#$result["argu],使用的參數.
7053
		#必填參數:
7054
		#$conf["url"],字串,目標url.
7055
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
7056
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7057
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7058
		#可省略參數:
7059
		#$conf["header"],字串陣列,要傳送的header.
7060
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7061
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7062
		#$conf["allowAnySSLcertificate"]="";
7063
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7064
		#$conf["postVar"]=array();
7065
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7066
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7067
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7068
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7069
		#$conf["agent"],字串,user agent的名稱.
7070
		#$conf["agent"]="";
7071
		#$conf["cookie"],字串,cookie位置與檔案位置.
7072
		#$conf["cookie"]="";
7073
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7074
		#$conf["forceNewCookie"]="";
7075
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7076
		#$conf["inBg"]="true";
7077
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7078
		#$conf["bgInProc"]="false";
7079
		#參考資料:
7080
		#無.
7081
		#備註:
7082
		#無.
7083
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7084
		unset($conf["catchWebContent::curlCmd"]);
7085
 
7086
		#如果異常
7087
		if($curlCmd["status"]==="false"){
7088
 
7089
			#設置錯誤識別
7090
			$result["status"]="false";
7091
 
7092
			#設置錯誤訊息
7093
			$result["error"]=$curlCmd;
7094
 
7095
			#回傳結果
7096
			return $result;
7097
 
7098
			}#if end
7099
 
7100
		#設置curl的詳細資訊
7101
		$result["curl_verbose_info"]=$curlCmd;
7102
 
7103
		#驗證結果是否為 json
7104
		$json_validate=json_validate($curlCmd["fullContent"]);
7105
 
7106
		#如果回應不是 json
7107
		if(!$json_validate){
7108
 
7109
			#設置錯誤識別
7110
			$result["status"]="false";
7111
 
7112
			#設置錯誤訊息
7113
			$result["error"]=$curlCmd;
7114
 
7115
			#回傳結果
7116
			return $result;
7117
 
7118
			}#if end
7119
 
7120
		#設置json string結果
7121
		$result["content"]=$curlCmd["fullContent"];
7122
 
7123
		#解析json
7124
		$jsonRes=json_decode($result["content"]);
7125
 
7126
		#如果沒有 status
7127
		if(!isset($jsonRes->status)){
7128
 
7129
			#設置錯誤識別
7130
			$result["status"]="false";
7131
 
7132
			#設置錯誤訊息
7133
			$result["error"]=$curlCmd;
7134
 
7135
			#回傳結果
7136
			return $result;
7137
 
7138
			}#if end
7139
 
7140
		#取得csr在zerossl上的狀態
7141
		$result["cerStatus"]=$jsonRes->status;
7142
 
7143
		#設置執行正常
7144
		$result["status"]="true";
7145
 
7146
		#回傳結果
7147
		return $result;
7148
 
7149
		}#function getCertSta end
7150
 
7151
	/*
7152
	#函式說明:
7153
	#取得在zerossl上的CSR清單
7154
	#回傳結果:
7155
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7156
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7157
	#$result["function"],當前執行的函式名稱.
7158
	#$result["argu"],所使用的參數.
7159
	#$result["curl_verbose_info"],curl執行的詳細資訊.
7160
	#$result["content"],結果json字串.
7161
	#$result["tCount"],總共的資料筆數.
7162
	#$result["count"],該頁的筆數.
7163
	#$result["page"],當前的頁碼.
7164
	#$result["certs"],陣列,certificates清單,key為certificate的id.
7165
	#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
7166
	#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
7167
	#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
7168
	#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
7169
	#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7170
	#必填參數:
7171
	#無
7172
	#可省略參數:
7173
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7174
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7175
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7176
	#$conf["key"]=self::getApiInfo()["apiKey"];
7177
	#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7178
	#$conf["cerStatus"]="";
7179
	#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
7180
	#$conf["cerType"]="";
7181
	#$conf["search"],字串,透過certificate包含的domain來搜尋.
7182
	#$conf["search"]="";
7183
	#$conf["limit"],字串,一頁要多少筆,預設為100筆.
7184
	#$conf["limit"]="";
7185
	#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
7186
	#$conf["page"]="";
7187
	#參考資料:
7188
	#https://zerossl.com/documentation/api/list-certificates/
7189
	#備註:
7190
	#無.
7191
	*/
7192
	public static function getCertList(&$conf){
7193
 
7194
		#初始化要回傳的結果
7195
		$result=array();
7196
 
7197
		#設置當其函數名稱
7198
		$result["function"]=__FUNCTION__;
7199
 
7200
		#如果 $conf 不為陣列
7201
		if(gettype($conf)!="array"){
7202
 
7203
			#設置執行失敗
7204
			$result["status"]="false";
7205
 
7206
			#設置執行錯誤訊息
7207
			$result["error"][]="\$conf變數須為陣列形態";
7208
 
7209
			#如果傳入的參數為 null
7210
			if($conf==null){
7211
 
7212
				#設置執行錯誤訊息
7213
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7214
 
7215
				}#if end
7216
 
7217
			#回傳結果
7218
			return $result;
7219
 
7220
			}#if end
7221
 
7222
		#取得參數
7223
		$result["argu"]=$conf;
7224
 
7225
		#檢查參數
7226
		#函式說明:
7227
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7228
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7229
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7230
		#$result["function"],當前執行的函式名稱.
7231
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7232
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7233
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7234
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7235
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7236
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7237
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7238
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7239
		#必填寫的參數:
7240
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7241
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7242
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7243
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
7244
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7245
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7246
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7247
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7248
		#可以省略的參數:
7249
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7250
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7251
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7252
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7253
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7254
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
7255
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7256
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
7257
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7258
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
7259
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7260
		#$conf["arrayCountEqualCheck"][]=array();
7261
		#參考資料來源:
7262
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7263
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7264
		unset($conf["variableCheck::checkArguments"]);
7265
 
7266
		#如果檢查失敗
7267
		if($checkArguments["status"]==="false"){
7268
 
7269
			#設置錯誤識別
7270
			$result["status"]="false";
7271
 
7272
			#設置錯誤訊息
7273
			$result["error"]=$checkArguments;
7274
 
7275
			#回傳結果
7276
			return $result;
7277
 
7278
			}#if end
7279
 
7280
		#如果檢查不通過
7281
		if($checkArguments["passed"]==="false"){
7282
 
7283
			#設置錯誤識別
7284
			$result["status"]="false";
7285
 
7286
			#設置錯誤訊息
7287
			$result["error"]=$checkArguments;
7288
 
7289
			#回傳結果
7290
			return $result;
7291
 
7292
			}#if end
7293
 
7294
		#預設網址
291 liveuser 7295
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."?access_key=".$conf["key"];
255 liveuser 7296
 
7297
		#如果有設置 cerStatus
7298
		if(isset($conf["cerStatus"])){
7299
 
7300
			#設置 certificate_status 
291 liveuser 7301
			$url=$url."&certificate_status=".urlencode($conf["cerStatus"]);
255 liveuser 7302
 
7303
			}#if end
7304
 
7305
		#如果有設置 cerType
7306
		if(isset($conf["cerType"])){
7307
 
7308
			#設置 certificate_type
291 liveuser 7309
			$url=$url."&certificate_type=".urlencode($conf["cerType"]);
255 liveuser 7310
 
7311
			}#if end
7312
 
7313
		#如果有設置 search
7314
		if(isset($conf["search"])){
7315
 
7316
			#設置 search
291 liveuser 7317
			$url=$url."&search=".urlencode($conf["search"]);
255 liveuser 7318
 
7319
			}#if end
7320
 
7321
		#如果有設置 limit
7322
		if(isset($conf["limit"])){
7323
 
7324
			#設置 search
291 liveuser 7325
			$url=$url."&limit=".urlencode($conf["limit"]);
255 liveuser 7326
 
7327
			}#if end
7328
 
7329
		#如果有設置 page
7330
		if(isset($conf["page"])){
7331
 
7332
			#設置 search
291 liveuser 7333
			$url=$url."&"."page=".urlencode($conf["page"]);
255 liveuser 7334
 
7335
			}#if end
7336
 
7337
		#函式說明:
7338
		#運行curl cmd
7339
		#回傳結果:
7340
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7341
		#$result["error"],錯誤訊息陣列.
7342
		#$result["function"],當前執行的函式名稱.
7343
		#$result["founded"],識別網址找不找得到.
7344
		#$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"代表程序的資訊.
7345
		#$result["fullContent"],取得回應的完整字串內容.
7346
		#$result["cookie"],cookie檔案的位置與名稱.
7347
		#$result["cmd"],執行的command.
7348
		#$result["argu],使用的參數.
7349
		#必填參數:
7350
		#$conf["url"],字串,目標url.
7351
		$conf["catchWebContent::curlCmd"]["url"]=$url;
7352
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7353
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7354
		#可省略參數:
7355
		#$conf["header"],字串陣列,要傳送的header.
7356
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7357
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7358
		#$conf["allowAnySSLcertificate"]="";
7359
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7360
		#$conf["postVar"]=array();
7361
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7362
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7363
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7364
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7365
		#$conf["agent"],字串,user agent的名稱.
7366
		#$conf["agent"]="";
7367
		#$conf["cookie"],字串,cookie位置與檔案位置.
7368
		#$conf["cookie"]="";
7369
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7370
		#$conf["forceNewCookie"]="";
7371
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7372
		#$conf["inBg"]="true";
7373
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7374
		#$conf["bgInProc"]="false";
7375
		#參考資料:
7376
		#無.
7377
		#備註:
7378
		#無.
7379
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7380
		unset($conf["catchWebContent::curlCmd"]);
7381
 
7382
		#如果異常
7383
		if($curlCmd["status"]==="false"){
7384
 
7385
			#設置錯誤識別
7386
			$result["status"]="false";
7387
 
7388
			#設置錯誤訊息
7389
			$result["error"]=$curlCmd;
7390
 
7391
			#回傳結果
7392
			return $result;
7393
 
7394
			}#if end
7395
 
7396
		#設置curl的詳細資訊
7397
		$result["curl_verbose_info"]=$curlCmd;
7398
 
7399
		#驗證結果是否為 json
7400
		$json_validate=json_validate($curlCmd["fullContent"]);
7401
 
7402
		#如果回應不是 json
7403
		if(!$json_validate){
7404
 
7405
			#設置錯誤識別
7406
			$result["status"]="false";
7407
 
7408
			#設置錯誤訊息
7409
			$result["error"]=$curlCmd;
7410
 
7411
			#回傳結果
7412
			return $result;
7413
 
7414
			}#if end
7415
 
7416
		#設置json string結果
7417
		$result["content"]=$curlCmd["fullContent"];
7418
 
7419
		/* json response 範例
7420
		{
7421
			"total_count": 11,
7422
			"result_count": 10,
7423
			"page": 1,
7424
			"limit": 10,
7425
			"acmeUsageLevel": "LOW",
7426
			"isAcmeLocked": false,
7427
			"results": 
7428
			[
7429
				{
7430
					"id": "a856a39a1c3ad0s8asa606g37667d221",
7431
					"type": "1",
7432
					"common_name": "domain.com",
7433
					"additional_domains": "www.domain.com",
7434
					"created": "2020-04-29 09:04:19",
7435
					"expires": "2020-07-28 00:00:00",
7436
					"status": "draft",
7437
					"validation_type": null,
7438
					"validation_emails": null,
7439
					"replacement_for": "",
7440
					"fingerprint_sha1": null,
7441
					"brand_validation": null,
7442
					"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
7443
					"validation":
7444
					{
7445
						"email_validation":
7446
						{
7447
							"domain.com":
7448
							[
7449
								"admin@domain.com",
7450
								"administrator@domain.com",
7451
								"hostmaster@domain.com",
7452
								"postmaster@domain.com",
7453
								"webmaster@domain.com"
7454
							]
7455
						},
7456
						"other_methods": 
7457
						{
7458
							"domain.com":
7459
							{
7460
								"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
7461
								"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
7462
								"file_validation_content":
7463
								[
7464
									"2B449B722B449B729394793947",
7465
									"comodoca.com",
7466
									"4bad7360c7076ba"
7467
								],
7468
								"cname_validation_p1": "2B449B7293947.domain.com",
7469
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
7470
							},
7471
							"www.domain.com":
7472
							{
7473
								"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
7474
								"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",   
7475
								"file_validation_content":
7476
								[
7477
									"2B449B722B449B729394793947",
7478
									"comodoca.com",
7479
									"4bad7360c7076ba"
7480
								],
7481
								"cname_validation_p1": "2B449B7293947.www.domain.com",
7482
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
7483
							}
7484
						}
7485
					}
7486
				},
7487
				{
7488
					...
7489
				}
7490
			]
7491
		}
249 liveuser 7492
		*/
7493
 
255 liveuser 7494
		#解析json
7495
		$jsonRes=json_decode($result["content"]);
7496
 
7497
		#總共的資料筆數
7498
		$result["tCount"]=$jsonRes->total_count;
7499
 
7500
		#取得該頁的筆數
7501
		$result["count"]=$jsonRes->result_count;
7502
 
7503
		#取得certificate清單
291 liveuser 7504
		$certs=$jsonRes->results;
255 liveuser 7505
 
7506
		#針對每個certificate
7507
		foreach($certs as $index => $cert){
7508
 
7509
			#初始化暫存的陣列
7510
			$tmpA=array();
7511
 
7512
			#儲存 cert id
7513
			#$tmpA["id"]=$cert->id;
7514
 
7515
			#儲存 主要包含的 domain name
7516
			$tmpA["cname"]=$cert->common_name;
7517
 
7518
			#儲存額外包含的 domain name
7519
			$tmpA["anames"]=$cert->additional_domains;
7520
 
7521
			#最後有效年月日,格式為"2020-07-28 00:00:00".
7522
			$tmpA["expiresYMD"]=$cert->expires;
7523
 
7524
			#產生對於當前系統時間的差距(秒數)
7525
			#函式說明:
7526
			#計算時間點距離1970/01/01多少秒,亦即unixtime.
7527
			#回傳結果:
7528
			#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
7529
			#$result["error"],錯誤訊息陣列.
7530
			#$result["content"],時間點距離1970/01/01的多少秒.
7531
			#$result["argu"],使用的參數.
7532
			#$result["unixtime"],執行本函式時的unixtime.
7533
			#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
7534
			#必填參數:
7535
			#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
7536
			$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
7537
			#可省略參數:
7538
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
7539
			#$conf["UTC"]="false";
7540
			#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
7541
			$conf["time::caculateTimeAmount"]["replace0"]="false";
7542
			#參考資料:
7543
			#無.
7544
			#備註:
7545
			#無.
7546
			$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
7547
			unset($conf["time::caculateTimeAmount"]);
7548
 
7549
			#如果執行異常
291 liveuser 7550
			if($caculateTimeAmount["status"]==="false"){
255 liveuser 7551
 
7552
				#設置錯誤識別
7553
				$result["status"]="false";
7554
 
7555
				#設置錯誤訊息
7556
				$result["error"]=$caculateTimeAmount;
7557
 
7558
				#回傳結果
7559
				return $result;
7560
 
7561
				}#if end
7562
 
7563
			#儲存還要多少秒要過期
291 liveuser 7564
			$tmpA["expiresIn"]=$caculateTimeAmount["content"]-time();
255 liveuser 7565
 
7566
			#憑證的狀態
7567
			$tmpA["status"]=$cert->status;
7568
 
291 liveuser 7569
			#儲存要回傳的 certs 清單,key為cert的id.
7570
			$result["certs"][$cert->id]=$tmpA;
255 liveuser 7571
 
7572
			}#foreach end
7573
 
7574
		#設置執行正常
7575
		$result["status"]="true";
7576
 
7577
		#回傳結果
7578
		return $result;
7579
 
7580
		}#function getCertList end
7581
 
7582
	/*
7583
	#函式說明:
7584
	#下載certificate.
7585
	#回傳結果:
7586
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7587
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7588
	#$result["function"],當前執行的函式名稱.
7589
	#$result["argu"],所使用的參數.
7590
	#$result["curl_verbose_info"],curl執行的詳細資訊.
7591
	#$result["content"],結果json字串.
7592
	#$result["certificate.crt"],字串,certificate.crt的內容.
7593
	#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
7594
	#必填參數:
7595
	#無.
7596
	#可省略參數:
7597
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7598
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7599
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7600
	#$conf["key"]=self::getApiInfo()["apiKey"];
7601
	#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
7602
	#$conf["id"]="";
7603
	#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
7604
	#$conf["cname"]="";
7605
	#參考資料:
7606
	#https://zerossl.com/documentation/api/download-certificate-inline/
7607
	#備註:
7608
	#無.
7609
	*/
7610
	public static function getCert(&$conf){
7611
 
7612
		#初始化要回傳的結果
7613
		$result=array();
7614
 
7615
		#設置當其函數名稱
7616
		$result["function"]=__FUNCTION__;
7617
 
7618
		#如果 $conf 不為陣列
7619
		if(gettype($conf)!="array"){
7620
 
7621
			#設置執行失敗
7622
			$result["status"]="false";
7623
 
7624
			#設置執行錯誤訊息
7625
			$result["error"][]="\$conf變數須為陣列形態";
7626
 
7627
			#如果傳入的參數為 null
7628
			if($conf==null){
7629
 
7630
				#設置執行錯誤訊息
7631
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7632
 
7633
				}#if end
7634
 
7635
			#回傳結果
7636
			return $result;
7637
 
7638
			}#if end
7639
 
7640
		#取得參數
7641
		$result["argu"]=$conf;
7642
 
7643
		#檢查參數
7644
		#函式說明:
7645
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7646
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7647
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7648
		#$result["function"],當前執行的函式名稱.
7649
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7650
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7651
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7652
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7653
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7654
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7655
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7656
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7657
		#必填寫的參數:
7658
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7659
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7660
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7661
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
7662
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7663
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7664
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7665
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7666
		#可以省略的參數:
7667
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7668
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7669
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7670
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7671
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7672
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
7673
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7674
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
7675
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7676
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
7677
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7678
		#$conf["arrayCountEqualCheck"][]=array();
7679
		#參考資料來源:
7680
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7681
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7682
		unset($conf["variableCheck::checkArguments"]);
7683
 
7684
		#如果檢查失敗
7685
		if($checkArguments["status"]==="false"){
7686
 
7687
			#設置錯誤識別
7688
			$result["status"]="false";
7689
 
7690
			#設置錯誤訊息
7691
			$result["error"]=$checkArguments;
7692
 
7693
			#回傳結果
7694
			return $result;
7695
 
7696
			}#if end
7697
 
7698
		#如果檢查不通過
7699
		if($checkArguments["passed"]==="false"){
7700
 
7701
			#設置錯誤識別
7702
			$result["status"]="false";
7703
 
7704
			#設置錯誤訊息
7705
			$result["error"]=$checkArguments;
7706
 
7707
			#回傳結果
7708
			return $result;
7709
 
7710
			}#if end
7711
 
7712
		#如果有設置 id
7713
		if(isset($conf["id"])){
7714
 
7715
			#設置 id
7716
			$id=$conf["id"];
7717
 
7718
			}#if end
7719
 
7720
		#反之如果有設置 cname
7721
		else if(isset($conf["cname"])){
7722
 
7723
			#函式說明:
7724
			#取得在zerossl上的CSR清單
7725
			#回傳結果:
7726
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7727
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
7728
			#$result["function"],當前執行的函式名稱.
7729
			#$result["argu"],所使用的參數.
7730
			#$result["curl_verbose_info"],curl執行的詳細資訊.
7731
			#$result["content"],結果json字串.
7732
			#$result["tCound"],總共的資料筆數.
7733
			#$result["count"],該頁的筆數.
7734
			#$result["page"],當前的頁碼.
7735
			#$result["certs"],陣列,certificates清單,key為certificate的id.
7736
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
7737
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
7738
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
7739
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7740
			#必填參數:
7741
			#無
7742
			#可省略參數:
7743
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7744
			#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7745
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7746
			#$conf["key"]=self::getApiInfo()["apiKey"];
7747
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7748
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
7749
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
7750
			#$conf["cerType"]="";
7751
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
7752
			$conf["zerossl::getCertList"]["search"]=$conf["cname"];
7753
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
7754
			#$conf["limit"]="";
7755
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
7756
			#$conf["page"]="";
7757
			#參考資料:
7758
			#https://zerossl.com/documentation/api/get-certificate/
7759
			#備註:
7760
			#無.
7761
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
7762
			unset($conf["zerossl::getCertList"]);
7763
 
7764
			#如果檢查失敗
7765
			if($getCertList["status"]==="false"){
7766
 
7767
				#設置錯誤識別
7768
				$result["status"]="false";
7769
 
7770
				#設置錯誤訊息
7771
				$result["error"]=$getCertList;
7772
 
7773
				#回傳結果
7774
				return $result;
7775
 
7776
				}#if end
7777
 
7778
			#如果資料筆數大於0
7779
			if($getCertList["count"]>0){
7780
 
7781
				#取得第一筆
7782
				foreach($getCertList["certs"] as $cerId => $detail){
7783
 
7784
					#取得cettificate id
7785
					$id=$cerId;
7786
 
7787
					}#foreach end
7788
 
7789
				}#if end
7790
 
7791
			}#if end
7792
 
7793
		#預設網址
7794
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
7795
 
7796
		#函式說明:
7797
		#運行curl cmd
7798
		#回傳結果:
7799
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7800
		#$result["error"],錯誤訊息陣列.
7801
		#$result["function"],當前執行的函式名稱.
7802
		#$result["founded"],識別網址找不找得到.
7803
		#$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"代表程序的資訊.
7804
		#$result["fullContent"],取得回應的完整字串內容.
7805
		#$result["cookie"],cookie檔案的位置與名稱.
7806
		#$result["cmd"],執行的command.
7807
		#$result["argu],使用的參數.
7808
		#必填參數:
7809
		#$conf["url"],字串,目標url.
7810
		$conf["catchWebContent::curlCmd"]["url"]=$url;
7811
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7812
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7813
		#可省略參數:
7814
		#$conf["header"],字串陣列,要傳送的header.
7815
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7816
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7817
		#$conf["allowAnySSLcertificate"]="";
7818
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7819
		#$conf["postVar"]=array();
7820
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7821
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7822
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7823
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7824
		#$conf["agent"],字串,user agent的名稱.
7825
		#$conf["agent"]="";
7826
		#$conf["cookie"],字串,cookie位置與檔案位置.
7827
		#$conf["cookie"]="";
7828
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7829
		#$conf["forceNewCookie"]="";
7830
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7831
		#$conf["inBg"]="true";
7832
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7833
		#$conf["bgInProc"]="false";
7834
		#參考資料:
7835
		#無.
7836
		#備註:
7837
		#無.
7838
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7839
		unset($conf["catchWebContent::curlCmd"]);
7840
 
7841
		#如果異常
7842
		if($curlCmd["status"]==="false"){
7843
 
7844
			#設置錯誤識別
7845
			$result["status"]="false";
7846
 
7847
			#設置錯誤訊息
7848
			$result["error"]=$curlCmd;
7849
 
7850
			#回傳結果
7851
			return $result;
7852
 
7853
			}#if end
7854
 
7855
		#設置curl的詳細資訊
7856
		$result["curl_verbose_info"]=$curlCmd;
7857
 
249 liveuser 7858
		#驗證結果是否為 json
7859
		$json_validate=json_validate($curlCmd["fullContent"]);
7860
 
7861
		#如果回應不是 json
7862
		if(!$json_validate){
7863
 
7864
			#設置錯誤識別
7865
			$result["status"]="false";
7866
 
7867
			#設置錯誤訊息
7868
			$result["error"]=$curlCmd;
7869
 
7870
			#回傳結果
7871
			return $result;
7872
 
7873
			}#if end
7874
 
7875
		#設置json string結果
7876
		$result["content"]=$curlCmd["fullContent"];
255 liveuser 7877
 
7878
		#取得 json
7879
		$json=json_decode($curlCmd["fullContent"]);
7880
 
291 liveuser 7881
		#儲存成變數以便透過object呼叫
7882
		$c_crt="certificate.crt";
7883
 
7884
		#儲存成變數以便透過object呼叫
7885
		$ca_crt="ca_bundle.crt";
7886
 
255 liveuser 7887
		#取得certificate.crt的內容
291 liveuser 7888
		$result["certificate.crt"]=$json->$c_crt;
255 liveuser 7889
 
7890
		#取得ca_bundle.crt的內容
291 liveuser 7891
		$result["ca_bundle.crt"]=$json->$ca_crt;
255 liveuser 7892
 
7893
		#設置執行正常
7894
		$result["status"]="true";
7895
 
7896
		#回傳結果
7897
		return $result;
7898
 
7899
		}#function getCert end
7900
 
7901
	/*
7902
	#函式說明:
7903
	#請求廢除 issued zerossl certificate.
7904
	#回傳結果:
7905
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7906
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7907
	#$result["function"],當前執行的函式名稱.
7908
	#$result["argu"],所使用的參數.
7909
	#$result["curl_verbose_info"],curl執行的詳細資訊.
7910
	#$result["content"],結果json字串.
7911
	#必填參數:
7912
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
7913
	$conf["id"]="";
7914
	#可省略參數:
7915
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7916
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7917
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7918
	#$conf["key"]=self::getApiInfo()["apiKey"];
7919
	#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
7920
	#$conf["reason"]="";
7921
	#參考資料:
7922
	#https://zerossl.com/documentation/api/revoke-certificate/
7923
	#備註:
7924
	#無.
7925
	*/
7926
	public static function revokeCert(&$conf){
7927
 
7928
		#初始化要回傳的結果
7929
		$result=array();
249 liveuser 7930
 
255 liveuser 7931
		#設置當其函數名稱
7932
		$result["function"]=__FUNCTION__;
7933
 
7934
		#如果 $conf 不為陣列
7935
		if(gettype($conf)!="array"){
7936
 
7937
			#設置執行失敗
7938
			$result["status"]="false";
7939
 
7940
			#設置執行錯誤訊息
7941
			$result["error"][]="\$conf變數須為陣列形態";
7942
 
7943
			#如果傳入的參數為 null
7944
			if($conf==null){
7945
 
7946
				#設置執行錯誤訊息
7947
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7948
 
7949
				}#if end
7950
 
7951
			#回傳結果
7952
			return $result;
7953
 
7954
			}#if end
7955
 
7956
		#取得參數
7957
		$result["argu"]=$conf;
7958
 
7959
		#檢查參數
7960
		#函式說明:
7961
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7962
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7963
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7964
		#$result["function"],當前執行的函式名稱.
7965
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7966
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7967
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7968
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7969
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7970
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7971
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7972
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7973
		#必填寫的參數:
7974
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7975
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7976
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7977
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
7978
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7979
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7980
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7981
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7982
		#可以省略的參數:
7983
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7984
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7985
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7986
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7987
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7988
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
7989
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7990
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","status");
7991
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7992
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
7993
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7994
		#$conf["arrayCountEqualCheck"][]=array();
7995
		#參考資料來源:
7996
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7997
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7998
		unset($conf["variableCheck::checkArguments"]);
7999
 
8000
		#如果檢查失敗
8001
		if($checkArguments["status"]==="false"){
8002
 
8003
			#設置錯誤識別
8004
			$result["status"]="false";
8005
 
8006
			#設置錯誤訊息
8007
			$result["error"]=$checkArguments;
8008
 
8009
			#回傳結果
8010
			return $result;
8011
 
8012
			}#if end
8013
 
8014
		#如果檢查不通過
8015
		if($checkArguments["passed"]==="false"){
8016
 
8017
			#設置錯誤識別
8018
			$result["status"]="false";
8019
 
8020
			#設置錯誤訊息
8021
			$result["error"]=$checkArguments;
8022
 
8023
			#回傳結果
8024
			return $result;
8025
 
8026
			}#if end
8027
 
8028
		#url to call
8029
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
8030
 
8031
		#如果有設置 reason
8032
		if(isset($conf["reason"])){
8033
 
8034
			#設置reason
8035
			$reason="&reason=".$conf["reason"];
8036
 
8037
			#串接reason
8038
			$url=$url.$reason;
8039
 
8040
			}#if end
8041
 
8042
		#函式說明:
8043
		#運行curl cmd
8044
		#回傳結果:
8045
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8046
		#$result["error"],錯誤訊息陣列.
8047
		#$result["function"],當前執行的函式名稱.
8048
		#$result["founded"],識別網址找不找得到.
8049
		#$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"代表程序的資訊.
8050
		#$result["fullContent"],取得回應的完整字串內容.
8051
		#$result["cookie"],cookie檔案的位置與名稱.
8052
		#$result["cmd"],執行的command.
8053
		#$result["argu],使用的參數.
8054
		#必填參數:
8055
		#$conf["url"],字串,目標url.
8056
		$conf["catchWebContent::curlCmd"]["url"]=$url;
8057
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8058
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
8059
		#可省略參數:
8060
		#$conf["header"],字串陣列,要傳送的header.
8061
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
8062
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
8063
		#$conf["allowAnySSLcertificate"]="";
8064
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
8065
		#$conf["postVar"]=array();
8066
		#$conf["rawPost"]="字串",要傳送的raw post內容.
8067
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
8068
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
8069
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
8070
		#$conf["agent"],字串,user agent的名稱.
8071
		#$conf["agent"]="";
8072
		#$conf["cookie"],字串,cookie位置與檔案位置.
8073
		#$conf["cookie"]="";
8074
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
8075
		#$conf["forceNewCookie"]="";
8076
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
8077
		#$conf["inBg"]="true";
8078
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
8079
		#$conf["bgInProc"]="false";
8080
		#參考資料:
8081
		#無.
8082
		#備註:
8083
		#無.
8084
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
8085
		unset($conf["catchWebContent::curlCmd"]);
8086
 
8087
		#如果異常
8088
		if($curlCmd["status"]==="false"){
8089
 
8090
			#設置錯誤識別
8091
			$result["status"]="false";
8092
 
8093
			#設置錯誤訊息
8094
			$result["error"]=$curlCmd;
8095
 
8096
			#回傳結果
8097
			return $result;
8098
 
8099
			}#if end
8100
 
8101
		#設置curl的詳細資訊
8102
		$result["curl_verbose_info"]=$curlCmd;
8103
 
8104
		#驗證結果是否為 json
8105
		$json_validate=json_validate($curlCmd["fullContent"]);
8106
 
8107
		#如果回應不是 json
8108
		if(!$json_validate){
8109
 
8110
			#設置錯誤識別
8111
			$result["status"]="false";
8112
 
8113
			#設置錯誤訊息
8114
			$result["error"]=$curlCmd;
8115
 
8116
			#回傳結果
8117
			return $result;
8118
 
8119
			}#if end
8120
 
8121
		#設置json string結果
8122
		$result["content"]=$curlCmd["fullContent"];
8123
 
249 liveuser 8124
		#解析json
8125
		$jsonRes=json_decode($result["content"]);
8126
 
255 liveuser 8127
		#如果沒有要有的attr
8128
		if(!isset($jsonRes->success)){
8129
 
8130
			#設置錯誤識別
8131
			$result["status"]="false";
8132
 
8133
			#設置錯誤訊息
8134
			$result["error"]=$curlCmd;
8135
 
8136
			#回傳結果
8137
			return $result;
8138
 
8139
			}#if end
8140
 
8141
		#如果 success 不等於 1
8142
		if($jsonRes->success!==1){
8143
 
8144
			#設置錯誤識別
8145
			$result["status"]="false";
8146
 
8147
			#設置錯誤訊息
8148
			$result["error"]=$curlCmd;
8149
 
8150
			#回傳結果
8151
			return $result;
8152
 
8153
			}#if end
8154
 
249 liveuser 8155
		#設置執行正常
8156
		$result["status"]="true";
8157
 
8158
		#回傳結果
8159
		return $result;
8160
 
255 liveuser 8161
		}#function revokeCert end
8162
 
8163
	/*
8164
	#函式說明:
8165
	#請求取消 draft or unvalidated zerossl certificate.
8166
	#回傳結果:
8167
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8168
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
8169
	#$result["function"],當前執行的函式名稱.
8170
	#$result["argu"],所使用的參數.
8171
	#$result["curl_verbose_info"],curl執行的詳細資訊.
8172
	#$result["content"],結果json字串.
8173
	#必填參數:
8174
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
8175
	$conf["id"]="";
8176
	#可省略參數:
8177
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8178
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8179
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8180
	#$conf["key"]=self::getApiInfo()["apiKey"];
8181
	#參考資料:
8182
	#https://zerossl.com/documentation/api/revoke-certificate/
8183
	#備註:
8184
	#無.
8185
	*/
8186
	public static function cancelCert(&$conf){
8187
 
8188
		#初始化要回傳的結果
8189
		$result=array();
249 liveuser 8190
 
255 liveuser 8191
		#設置當其函數名稱
8192
		$result["function"]=__FUNCTION__;
8193
 
8194
		#如果 $conf 不為陣列
8195
		if(gettype($conf)!="array"){
8196
 
8197
			#設置執行失敗
8198
			$result["status"]="false";
8199
 
8200
			#設置執行錯誤訊息
8201
			$result["error"][]="\$conf變數須為陣列形態";
8202
 
8203
			#如果傳入的參數為 null
8204
			if($conf==null){
8205
 
8206
				#設置執行錯誤訊息
8207
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8208
 
8209
				}#if end
8210
 
8211
			#回傳結果
8212
			return $result;
8213
 
8214
			}#if end
8215
 
8216
		#取得參數
8217
		$result["argu"]=$conf;
8218
 
8219
		#檢查參數
8220
		#函式說明:
8221
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8222
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8223
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8224
		#$result["function"],當前執行的函式名稱.
8225
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8226
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8227
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8228
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8229
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8230
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8231
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8232
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8233
		#必填寫的參數:
8234
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8235
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8236
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8237
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
8238
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
8239
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
8240
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8241
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8242
		#可以省略的參數:
8243
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8244
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8245
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
8246
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8247
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8248
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
8249
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8250
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
8251
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8252
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
8253
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8254
		#$conf["arrayCountEqualCheck"][]=array();
8255
		#參考資料來源:
8256
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8257
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8258
		unset($conf["variableCheck::checkArguments"]);
8259
 
8260
		#如果檢查失敗
8261
		if($checkArguments["status"]==="false"){
8262
 
8263
			#設置錯誤識別
8264
			$result["status"]="false";
8265
 
8266
			#設置錯誤訊息
8267
			$result["error"]=$checkArguments;
8268
 
8269
			#回傳結果
8270
			return $result;
8271
 
8272
			}#if end
8273
 
8274
		#如果檢查不通過
8275
		if($checkArguments["passed"]==="false"){
8276
 
8277
			#設置錯誤識別
8278
			$result["status"]="false";
8279
 
8280
			#設置錯誤訊息
8281
			$result["error"]=$checkArguments;
8282
 
8283
			#回傳結果
8284
			return $result;
8285
 
8286
			}#if end
8287
 
8288
		#url to call
8289
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
8290
 
8291
		#函式說明:
8292
		#運行curl cmd
8293
		#回傳結果:
8294
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8295
		#$result["error"],錯誤訊息陣列.
8296
		#$result["function"],當前執行的函式名稱.
8297
		#$result["founded"],識別網址找不找得到.
8298
		#$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"代表程序的資訊.
8299
		#$result["fullContent"],取得回應的完整字串內容.
8300
		#$result["cookie"],cookie檔案的位置與名稱.
8301
		#$result["cmd"],執行的command.
8302
		#$result["argu],使用的參數.
8303
		#必填參數:
8304
		#$conf["url"],字串,目標url.
8305
		$conf["catchWebContent::curlCmd"]["url"]=$url;
8306
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8307
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
8308
		#可省略參數:
8309
		#$conf["header"],字串陣列,要傳送的header.
8310
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
8311
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
8312
		#$conf["allowAnySSLcertificate"]="";
8313
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
8314
		#$conf["postVar"]=array();
8315
		#$conf["rawPost"]="字串",要傳送的raw post內容.
8316
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
8317
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
8318
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
8319
		#$conf["agent"],字串,user agent的名稱.
8320
		#$conf["agent"]="";
8321
		#$conf["cookie"],字串,cookie位置與檔案位置.
8322
		#$conf["cookie"]="";
8323
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
8324
		#$conf["forceNewCookie"]="";
8325
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
8326
		#$conf["inBg"]="true";
8327
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
8328
		#$conf["bgInProc"]="false";
8329
		#參考資料:
8330
		#無.
8331
		#備註:
8332
		#無.
8333
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
8334
		unset($conf["catchWebContent::curlCmd"]);
8335
 
8336
		#如果異常
8337
		if($curlCmd["status"]==="false"){
8338
 
8339
			#設置錯誤識別
8340
			$result["status"]="false";
8341
 
8342
			#設置錯誤訊息
8343
			$result["error"]=$curlCmd;
8344
 
8345
			#回傳結果
8346
			return $result;
8347
 
8348
			}#if end
8349
 
8350
		#設置curl的詳細資訊
8351
		$result["curl_verbose_info"]=$curlCmd;
8352
 
8353
		#驗證結果是否為 json
8354
		$json_validate=json_validate($curlCmd["fullContent"]);
8355
 
8356
		#如果回應不是 json
8357
		if(!$json_validate){
8358
 
8359
			#設置錯誤識別
8360
			$result["status"]="false";
8361
 
8362
			#設置錯誤訊息
8363
			$result["error"]=$curlCmd;
8364
 
8365
			#回傳結果
8366
			return $result;
8367
 
8368
			}#if end
8369
 
8370
		#設置json string結果
8371
		$result["content"]=$curlCmd["fullContent"];
8372
 
8373
		#解析json
8374
		$jsonRes=json_decode($result["content"]);
8375
 
8376
		#如果沒有要有的attr
8377
		if(!isset($jsonRes->success)){
8378
 
8379
			#設置錯誤識別
8380
			$result["status"]="false";
8381
 
8382
			#設置錯誤訊息
8383
			$result["error"]=$curlCmd;
8384
 
8385
			#回傳結果
8386
			return $result;
8387
 
8388
			}#if end
8389
 
8390
		#如果 success 不等於 1
8391
		if($jsonRes->success!==1){
8392
 
8393
			#設置錯誤識別
8394
			$result["status"]="false";
8395
 
8396
			#設置錯誤訊息
8397
			$result["error"]=$curlCmd;
8398
 
8399
			#回傳結果
8400
			return $result;
8401
 
8402
			}#if end
8403
 
8404
		#設置執行正常
8405
		$result["status"]="true";
8406
 
8407
		#回傳結果
8408
		return $result;
8409
 
8410
		}#function cancelCert end
8411
 
8412
	/*
8413
	#函式說明:
8414
	#透過zerossl api確保ssl沒有過期.
8415
	#回傳結果:
8416
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8417
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
8418
	#$result["function"],當前執行的函式名稱.
8419
	#$result["argu"],所使用的參數.
8420
	#必填參數:
8421
	#$conf["cName"],陣列,每個ssl的common domain name.
8422
	$conf["cName"]=array();
8423
	#$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內容合併後的檔案位置與名稱.
8424
	$conf["certInfo"]=array();
8425
	#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
8426
	$conf["rrFile"]=array();
8427
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
8428
	$conf["dnsSerAddr"]=array();
8429
	#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
8430
	$conf["actionAfterUpdateCert"]=array();
8431
	#可省略參數:
288 liveuser 8432
	#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/sslUpdater.sock
8433
	#$conf["sock"]="";
281 liveuser 8434
	#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
8435
	#$conf["debug"]="";
255 liveuser 8436
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8437
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8438
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8439
	#$conf["key"]=self::getApiInfo()["apiKey"];
8440
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
8441
	#$conf["debug"]="";
8442
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
8443
	#$conf["addOnProcessFunc"]=array();
8444
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
8445
	#$conf["funcToRunWhenIdle"]=array();
8446
	#參考資料:
8447
	#無.
8448
	#備註:
8449
	#無.
8450
	*/
8451
	public static function sslUpdater(&$conf){
8452
 
8453
		#初始化要回傳的結果
8454
		$result=array();
8455
 
8456
		#設置當其函數名稱
8457
		$result["function"]=__FUNCTION__;
8458
 
8459
		#如果 $conf 不為陣列
8460
		if(gettype($conf)!="array"){
8461
 
8462
			#設置執行失敗
8463
			$result["status"]="false";
8464
 
8465
			#設置執行錯誤訊息
8466
			$result["error"][]="\$conf變數須為陣列形態";
8467
 
8468
			#如果傳入的參數為 null
8469
			if($conf==null){
8470
 
8471
				#設置執行錯誤訊息
8472
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8473
 
8474
				}#if end
8475
 
8476
			#回傳結果
8477
			return $result;
8478
 
8479
			}#if end
8480
 
8481
		#取得參數
8482
		$result["argu"]=$conf;
288 liveuser 8483
 
8484
		#初始化預設的 unix domain socket 路徑
8485
		$defaultSocket=pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/sslUpdater.sock";
255 liveuser 8486
 
8487
		#檢查參數
8488
		#函式說明:
8489
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8490
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8491
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8492
		#$result["function"],當前執行的函式名稱.
8493
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8494
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8495
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8496
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8497
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8498
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8499
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8500
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8501
		#必填寫的參數:
8502
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8503
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8504
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8505
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
8506
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
8507
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
8508
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8509
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8510
		#可以省略的參數:
8511
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8512
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8513
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
288 liveuser 8514
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock","debug","apiDomain","key");
255 liveuser 8515
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
288 liveuser 8516
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
255 liveuser 8517
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
281 liveuser 8518
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","array","array");
255 liveuser 8519
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
291 liveuser 8520
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($defaultSocket,"false",self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
255 liveuser 8521
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8522
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
8523
		#參考資料來源:
8524
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8525
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8526
		unset($conf["variableCheck::checkArguments"]);
8527
 
8528
		#如果檢查失敗
8529
		if($checkArguments["status"]==="false"){
8530
 
8531
			#設置錯誤識別
8532
			$result["status"]="false";
8533
 
8534
			#設置錯誤訊息
8535
			$result["error"]=$checkArguments;
8536
 
8537
			#回傳結果
8538
			return $result;
8539
 
8540
			}#if end
8541
 
8542
		#如果檢查不通過
8543
		if($checkArguments["passed"]==="false"){
8544
 
8545
			#設置錯誤識別
8546
			$result["status"]="false";
8547
 
8548
			#設置錯誤訊息
8549
			$result["error"]=$checkArguments;
8550
 
8551
			#回傳結果
8552
			return $result;
8553
 
8554
			}#if end
8555
 
8556
		#取得key
8557
		$share["key"]=$conf["key"];
8558
 
8559
		#取得apiDomain
8560
		$share["apiDomain"]=$conf["apiDomain"];
8561
 
281 liveuser 8562
		#設置debug flag
8563
		$share["debug"]=$conf["debug"];
8564
 
255 liveuser 8565
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
8566
		$share["certInfo"]=array();
8567
 
8568
		#針對每個 domain
8569
		foreach($conf["cName"] as $index=>$cName ){
8570
 
8571
			#如果沒有對應的certInfo
8572
			if(!isset($conf["certInfo"][$index])){
8573
 
8574
				#設置錯誤識別
8575
				$result["status"]="false";
8576
 
8577
				#設置錯誤訊息
8578
				$result["error"][]="missing certInfo";
8579
 
8580
				#設置錯誤訊息
8581
				$result["error"][]=$checkArguments;
8582
 
8583
				#回傳結果
8584
				return $result;
8585
 
8586
				}#if end
8587
 
291 liveuser 8588
			#檢查 $conf["certInfo"][$index] 是否資訊都有存在
8589
			#函式說明:
8590
			#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
8591
			#回傳結果:
8592
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8593
			#$result["error"],執行不正常結束的錯訊息陣列.
8594
			#$result["simpleError"],簡單表示的錯誤訊息.
8595
			#$result["function"],當前執行的函式名稱.
8596
			#$result["argu"],設置給予的參數.
8597
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8598
			#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8599
			#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8600
			#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8601
			#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8602
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8603
			#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8604
			#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8605
			#必填參數:
8606
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8607
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["certInfo"][$index];
8608
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8609
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8610
			#可省略參數:
8611
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8612
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
8613
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
8614
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
8615
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8616
			#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8617
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8618
			#$conf["canNotBeEmpty"]=array();
8619
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8620
			#$conf["canBeEmpty"]=array();
8621
			#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8622
			$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("true","true","true","true");
8623
			#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8624
			$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
8625
			#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8626
			$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
8627
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8628
			$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");
8629
			#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
8630
			#$conf["disallowAllSkipableVarIsEmpty"]="";
8631
			#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
8632
			#$conf["disallowAllSkipableVarIsEmptyArray"]="";
8633
			#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
8634
			#$conf["disallowAllSkipableVarNotExist"]="";
8635
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8636
			#$conf["arrayCountEqualCheck"][]=array();
8637
			#參考資料:
8638
			#array_keys=>http://php.net/manual/en/function.array-keys.php
8639
			#備註:
8640
			#無.
8641
			$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8642
			unset($conf["variableCheck::checkArguments"]);
8643
 
8644
			#如果檢查失敗
8645
			if($checkArguments["status"]==="false"){
8646
 
8647
				#設置錯誤識別
8648
				$result["status"]="false";
8649
 
8650
				#設置錯誤訊息
8651
				$result["error"]=$checkArguments;
8652
 
8653
				#回傳結果
8654
				return $result;
8655
 
8656
				}#if end
8657
 
8658
			#如果檢查不通過
8659
			if($checkArguments["passed"]==="false"){
8660
 
8661
				#設置錯誤識別
8662
				$result["status"]="false";
8663
 
8664
				#設置錯誤訊息
8665
				$result["error"]=$checkArguments;
8666
 
8667
				#回傳結果
8668
				return $result;
8669
 
8670
				}#if end
8671
 
8672
			#儲存 cName
8673
			$cInfo["cName"]=$cName;
255 liveuser 8674
 
291 liveuser 8675
			#儲存 RR 檔案的路徑與名稱
8676
			$cInfo["rrFile"]=$conf["rrFile"][$index];
255 liveuser 8677
 
291 liveuser 8678
			#儲存 cName 對應的 dns server addr
8679
			$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
255 liveuser 8680
 
291 liveuser 8681
			#儲存 cName 的憑證更新後要做的事情.
8682
			$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
255 liveuser 8683
 
291 liveuser 8684
			#設置 certPath
8685
			$cInfo["ssl"]["certPath"]=$conf["certInfo"][$index]["certPath"];
255 liveuser 8686
 
291 liveuser 8687
			#設置 pKey
8688
			$cInfo["ssl"]["pKey"]=$conf["certInfo"][$index]["pKey"];
8689
 
8690
			#設置 caPath
8691
			$cInfo["ssl"]["caPath"]=$conf["certInfo"][$index]["caPath"];
8692
 
8693
			#設置 certWithCaPath
8694
			$cInfo["ssl"]["certWithCaPath"]=$conf["certInfo"][$index]["certWithCaPath"];
8695
 
8696
			#儲存 certInfo
8697
			$share["certInfo"][]=$cInfo;
8698
 
255 liveuser 8699
			}#foreach end
8700
 
8701
		#如果為空
8702
		if(empty($share["certInfo"])){
8703
 
8704
			#設置錯誤識別
8705
			$result["status"]="false";
8706
 
8707
			#設置錯誤訊息
8708
			$result["error"][]="certInfo 參數有缺";
8709
 
8710
			#設置錯誤訊息
8711
			$result["error"][]=$checkArguments;
8712
 
8713
			#回傳結果
8714
			return $result;
8715
 
8716
			}#if end
8717
 
8718
		#函式說明:
8719
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
8720
		#回傳結果:
8721
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
8722
		#$result["error"],錯誤訊息陣列.
8723
		#$result["function"],當前執行的函式名稱.
8724
		#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
8725
		#$result["serverCache"]["serverSide"],server side 的 cache.
8726
		#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
8727
		#$result["serverCache"]["clientSide"],client site 的 cache.
8728
		#必填參數:
8729
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
291 liveuser 8730
		$conf["sock::unixDomainSockServer"]["sock"]=$conf["sock"];
255 liveuser 8731
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8732
		$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
8733
		#可省略參數:
8734
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
8735
		$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
8736
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
8737
		$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
8738
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
8739
		#$conf["sessionTimeout"]="300";
8740
		#$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 8741
		$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("\qbpwcf\zerossl::sslUpdater_cmd");
255 liveuser 8742
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
291 liveuser 8743
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\qbpwcf\zerossl::sslUpdater_idle");
255 liveuser 8744
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
8745
		#$conf["paramsForFuncToRunWhenIdle"]=array();
8746
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
8747
		$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
8748
		#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
8749
		#$conf["shutdownStrAddr"]="";
8750
		#參考資料:
8751
		#http://php.net/manual/en/function.stream-socket-server.php
8752
		#備註:
8753
		#無.
8754
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
8755
		unset($conf["sock::unixDomainSockServer"]);
8756
 
8757
		#執行異常
8758
		if($unixDomainSockServer["status"]==="false"){
8759
 
8760
			#設置錯誤識別
8761
			$result["status"]="false";
8762
 
8763
			#設置錯誤訊息
8764
			$result["error"]=$unixDomainSockServer;
8765
 
8766
			#回傳結果
8767
			return $result;
8768
 
8769
			}#if end
8770
 
8771
		#設置執行正常
8772
		$result["status"]="true";
8773
 
8774
		#回傳結果
8775
		return $result;
8776
 
8777
		}#function sslUpdater end
8778
 
8779
	/*
8780
	#函式說明:
8781
	#funcion sslUpdater 於收到訊息時要做的事情.
8782
	#回傳結果:
8783
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8784
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
8785
	#$result["function"],當前執行的函式名稱.
8786
	#$result["argu"],所使用的參數.
8787
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
8788
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
8789
	#必填參數:
8790
	#$conf["request"],字串,收到的json訊息.
8791
	$conf["request"]="";
8792
	#$conf["sock"],resource,用戶的socket.
8793
	$conf["sock"]="";
8794
	#$conf["clientCache"],陣列,給予所有用戶的cache.
8795
	$conf["clientCache"]=array();
8796
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
8797
	$conf["info"]=array();
8798
	#可省略參數:
8799
	#無.
8800
	#參考資料:
8801
	#無.
8802
	#備註:
8803
	#建構中...
8804
	*/
8805
	public static function sslUpdater_cmd(&$conf){
8806
 
8807
		#debug
8808
		var_dump($conf);
8809
 
8810
		}#function sslUpdater_cmd end
8811
 
8812
	/*
8813
	#函式說明:
8814
	#funcion sslUpdater 於閒置時要做的事情
8815
	#回傳結果:
8816
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8817
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
8818
	#$result["function"],當前執行的函式名稱.
8819
	#$result["argu"],所使用的參數.
8820
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
8821
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
8822
	#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
8823
	#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
8824
	#必填參數:
8825
	#$conf["client"],陣列,所有用戶的資訊.
8826
	$conf["client"]=array();
8827
	#$conf["clientCache"],陣列,給予所有用戶的cache.
8828
	$conf["clientCache"]=array();
8829
	#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
8830
	$conf["serverCache"]=array();
8831
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
8832
	$conf["info"]=array();
8833
	#可省略參數:
8834
	#無.
8835
	#參考資料:
8836
	#無.
8837
	#備註:
291 liveuser 8838
	#無.
255 liveuser 8839
	*/
8840
	public static function sslUpdater_idle(&$conf){
8841
 
8842
		#初始化要回傳的結果
8843
		$result=array();
8844
 
8845
		#設置當其函數名稱
8846
		$result["function"]=__FUNCTION__;
8847
 
8848
		#如果 $conf 不為陣列
8849
		if(gettype($conf)!="array"){
8850
 
8851
			#設置執行失敗
8852
			$result["status"]="false";
8853
 
8854
			#設置執行錯誤訊息
8855
			$result["error"][]="\$conf變數須為陣列形態";
8856
 
8857
			#如果傳入的參數為 null
8858
			if($conf==null){
8859
 
8860
				#設置執行錯誤訊息
8861
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8862
 
8863
				}#if end
8864
 
8865
			#回傳結果
8866
			return $result;
8867
 
8868
			}#if end
8869
 
8870
		#取得參數
8871
		$result["argu"]=$conf;
8872
 
8873
		#檢查參數
8874
		#函式說明:
8875
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8876
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8877
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8878
		#$result["function"],當前執行的函式名稱.
8879
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8880
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8881
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8882
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8883
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8884
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8885
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8886
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8887
		#必填寫的參數:
8888
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8889
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8890
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
291 liveuser 8891
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","serverCache","info");
255 liveuser 8892
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
291 liveuser 8893
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
255 liveuser 8894
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8895
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8896
		#可以省略的參數:
8897
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8898
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8899
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
8900
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8901
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8902
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
8903
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8904
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
8905
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8906
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
8907
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8908
		#$conf["arrayCountEqualCheck"][]=array();
8909
		#參考資料來源:
8910
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8911
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8912
		unset($conf["variableCheck::checkArguments"]);
8913
 
8914
		#如果檢查失敗
8915
		if($checkArguments["status"]==="false"){
8916
 
8917
			#設置錯誤識別
8918
			$result["status"]="false";
8919
 
8920
			#設置錯誤訊息
8921
			$result["error"]=$checkArguments;
8922
 
8923
			#回傳結果
8924
			return $result;
8925
 
8926
			}#if end
8927
 
8928
		#如果檢查不通過
8929
		if($checkArguments["passed"]==="false"){
8930
 
8931
			#設置錯誤識別
8932
			$result["status"]="false";
8933
 
8934
			#設置錯誤訊息
8935
			$result["error"]=$checkArguments;
8936
 
8937
			#回傳結果
8938
			return $result;
8939
 
8940
			}#if end
281 liveuser 8941
 
8942
		#預設不開啟 debug flag
8943
		$debug=false;
8944
 
8945
		#如果有設置 debug 為 "true"
291 liveuser 8946
		if($conf["info"]["share"]["debug"]==="true"){
281 liveuser 8947
 
8948
			#設置 debug flag
8949
			$debug=true;
8950
 
8951
			}#if end
8952
 
261 liveuser 8953
		#另存 server cache 的參考
8954
		$serverCache=&$conf["serverCache"];
8955
 
255 liveuser 8956
		#針對每個 domain name
291 liveuser 8957
		foreach($conf["info"]["share"]["certInfo"] as $certInfoIndex=>$cInfo){
255 liveuser 8958
 
8959
			#取得domain name
8960
			$cName=$cInfo["cName"];
8961
 
261 liveuser 8962
			#如果尚無對應domain name的記錄
8963
			if(!isset($serverCache[$cName])){
8964
 
8965
				#設置最新一次檢測的unixtime
8966
				$serverCache[$cName]["lastCheckUnixTime"]=time();
291 liveuser 8967
 
261 liveuser 8968
				}#if end
8969
 
8970
			#反之距離上次檢查不滿一天
291 liveuser 8971
			else{
261 liveuser 8972
 
291 liveuser 8973
				#計算距離上次檢查多少秒
8974
				$checkedAfter=time()-$serverCache[$cName]["lastCheckUnixTime"];
261 liveuser 8975
 
291 liveuser 8976
				#若距離上次檢查不滿一天
8977
				if($checkedAfter<86400){
8978
 
8979
					#if enable debug
8980
					if($debug){
8981
 
8982
						#debug msg
8983
						echo "Domain name(".$cName.") on zerossl require to check in ".(86400-$checkedAfter)." second(s).".PHP_EOL;
8984
 
8985
						}#if end
8986
 
8987
					#跳過該 domain name 的檢查
8988
					continue;
8989
 
8990
					}#if end
8991
 
8992
				}#else end
261 liveuser 8993
 
281 liveuser 8994
			#if enable debug
8995
			if($debug){
8996
 
8997
				#debug msg
291 liveuser 8998
				echo "Checking domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 8999
 
9000
				}#if end
9001
 
291 liveuser 9002
			#certPath
9003
			#$cInfo["ssl"]["certPath"];
9004
 
9005
			#pKey
9006
			#$cInfo["ssl"]["pKey"];
9007
 
9008
			#caPath
9009
			#$cInfo["ssl"]["caPath"]=;
9010
 
9011
			#certWithCaPath
9012
			#$cInfo["ssl"]["certWithCaPath"];
9013
 
255 liveuser 9014
			#嘗試取得 domain name 對應的可用憑證
9015
			#函式說明:
9016
			#取得在zerossl上的CSR清單
9017
			#回傳結果:
9018
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9019
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
9020
			#$result["function"],當前執行的函式名稱.
9021
			#$result["argu"],所使用的參數.
9022
			#$result["curl_verbose_info"],curl執行的詳細資訊.
9023
			#$result["content"],結果json字串.
9024
			#$result["tCount"],總共的資料筆數.
9025
			#$result["count"],該頁的筆數.
9026
			#$result["page"],當前的頁碼.
9027
			#$result["certs"],陣列,certificates清單,key為certificate的id.
9028
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
9029
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
9030
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
9031
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9032
			#必填參數:
9033
			#無
9034
			#可省略參數:
9035
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9036
			$conf["zerossl::getCertList"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9037
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9038
			$conf["zerossl::getCertList"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9039
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9040
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
9041
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
9042
			$conf["zerossl::getCertList"]["cerType"]="single90Days";
9043
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
9044
			$conf["zerossl::getCertList"]["search"]=$cName;
9045
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
9046
			#$conf["limit"]="";
9047
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
9048
			#$conf["page"]="";
9049
			#參考資料:
9050
			#https://zerossl.com/documentation/api/list-certificates/
9051
			#備註:
9052
			#無.
9053
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
9054
			unset($conf["zerossl::getCertList"]);
9055
 
9056
			#符合條件的數量
9057
			#$getCertList["tCount"];
9058
 
9059
			#符合條件的當頁數量
9060
			#$getCertList["count"];
9061
 
9062
			#如果執行異常
9063
			if($getCertList["status"]==="false"){
9064
 
9065
				#設置錯誤識別
9066
				$result["status"]="false";
9067
 
9068
				#設置錯誤訊息
9069
				$result["error"]=$getCertList;
9070
 
9071
				#回傳結果
9072
				return $result;
9073
 
9074
				}#if end
291 liveuser 9075
 
255 liveuser 9076
			#如果沒有憑證
291 liveuser 9077
			if($getCertList["count"]===0){
255 liveuser 9078
 
281 liveuser 9079
				#if enable debug
9080
				if($debug){
9081
 
9082
					#debug msg
291 liveuser 9083
					echo "There is not valid ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 9084
 
9085
					}#if end
9086
 
9087
				#if enable debug
9088
				if($debug){
9089
 
9090
					#debug msg
291 liveuser 9091
					echo "Checking ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9092
 
9093
					}#if end
9094
 
255 liveuser 9095
				#確認有無對應 cName 的 private key
9096
				#函式說明:
9097
				#檢查多個檔案與資料夾是否存在.
9098
				#回傳的結果:
9099
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9100
				#$result["error"],錯誤訊息陣列.
9101
				#$resutl["function"],當前執行的涵式名稱.
9102
				#$result["argu"],使用的參數.
9103
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9104
				#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9105
				#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
9106
				#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
9107
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9108
				#必填參數:
9109
				#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
291 liveuser 9110
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["info"]["share"]["ssl"]["pKey"]);
255 liveuser 9111
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9112
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
9113
				#可省略參數:
9114
				#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9115
				#$conf["disableWebSearch"]="false";
9116
				#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9117
				$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
9118
				#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
9119
				$conf["fileAccess::checkMultiFileExist"]["web"]="false";
9120
				#參考資料:
9121
				#http://php.net/manual/en/function.file-exists.php
9122
				#http://php.net/manual/en/control-structures.foreach.php
9123
				#備註:
9124
				#函數file_exists檢查的路徑為檔案系統的路徑
9125
				#$result["varName"][$i]結果未實作
9126
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9127
				unset($conf["fileAccess::checkMultiFileExist"]);
9128
 
9129
				#如果運行異常
9130
				if($checkMultiFileExist["status"]==="false"){
9131
 
9132
					#設置錯誤識別
9133
					$result["status"]="false";
9134
 
9135
					#設置錯誤訊息
9136
					$result["error"]=$getCertList;
9137
 
9138
					#回傳結果
9139
					return $result;
9140
 
9141
					}#if end
9142
 
9143
				#如果沒有 private key
9144
				if($checkMultiFileExist["allExist"]==="false"){
9145
 
281 liveuser 9146
					#if enable debug
9147
					if($debug){
9148
 
9149
						#debug msg
291 liveuser 9150
						echo "there is no ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9151
 
9152
						}#if end
9153
 
9154
					#if enable debug
9155
					if($debug){
9156
 
9157
						#debug msg
291 liveuser 9158
						echo "creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9159
 
9160
						}#if end
9161
 
255 liveuser 9162
					#建立 private key
9163
					#函式說明:
9164
					#產生ssl private key.
9165
					#回傳結果:
9166
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9167
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9168
					#$result["function"],當前執行的函式名稱.
9169
					#$result["argu"],所使用的參數.
9170
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9171
					#$result["content"],ssl用的private key.
9172
					#必填參數:
9173
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9174
					$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
9175
					#可省略參數:
9176
					#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
9177
					#$conf["length"]=4096';
9178
					#參考資料:
9179
					#無.
9180
					#備註:
9181
					#key generated by openssl with RSA.
291 liveuser 9182
					$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 9183
					unset($conf["openssl::createPrivateKey"]);
9184
 
9185
					#如果運行異常
9186
					if($createPrivateKey["status"]==="false"){
9187
 
9188
						#設置錯誤識別
9189
						$result["status"]="false";
9190
 
9191
						#設置錯誤訊息
9192
						$result["error"]=$createPrivateKey;
9193
 
9194
						#回傳結果
9195
						return $result;
9196
 
9197
						}#if end
9198
 
9199
					#另存private key的字串
9200
					$pKeyStr=$createPrivateKey["content"];
9201
 
9202
					#建立private key檔案
9203
					#函式說明:
9204
					#將字串寫入到檔案
9205
					#回傳結果:
9206
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9207
					#$result["error"],錯誤訊息陣列.
9208
					#$result["function"],當前執行的函數名稱.
9209
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
9210
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
9211
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
9212
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
9213
					#$result["argu"],使用的參數.
9214
					#必填參數:
9215
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9216
					$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
9217
					#可省略參數:
9218
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
291 liveuser 9219
					$conf["zerossl::writeTextIntoFile"]["fileName"]=$conf["info"]["share"]["ssl"]["pKey"];
255 liveuser 9220
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
9221
					$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
9222
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
9223
					#$conf["writeMethod"]="a";
9224
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
9225
					#$conf["checkRepeat"]="";
9226
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
9227
					#$conf["filenameExtensionStartPoint"]="";
9228
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
9229
					#$conf["repeatNameRule"]="";
9230
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
9231
					$conf["zerossl::writeTextIntoFile"]["web"]="false";
9232
					#參考資料:
9233
					#無.
9234
					#備註:
9235
					#無.
291 liveuser 9236
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
255 liveuser 9237
					unset($conf["zerossl::writeTextIntoFile"]);
9238
 
9239
					#如果運行異常
9240
					if($writeTextIntoFile["status"]==="false"){
9241
 
9242
						#設置錯誤識別
9243
						$result["status"]="false";
9244
 
9245
						#設置錯誤訊息
9246
						$result["error"]=$writeTextIntoFile;
9247
 
9248
						#回傳結果
9249
						return $result;
9250
 
9251
						}#if end
9252
 
9253
					}#if end
9254
 
281 liveuser 9255
				#if enable debug
9256
				if($debug){
9257
 
9258
					#debug msg
291 liveuser 9259
					echo "Creating domain name(".$conf["info"]["share"]["apiDomain"].") csr for zerossl...".PHP_EOL;
281 liveuser 9260
 
9261
					}#if end
9262
 
255 liveuser 9263
				#建立準備給zerossl的csr
9264
				#函式說明:
9265
				#產生certificate sign request(CSR).
9266
				#回傳結果:
9267
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9268
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9269
				#$result["function"],當前執行的函式名稱.
9270
				#$result["argu"],所使用的參數.
9271
				#$result["content"],csr內容.
9272
				#$result["curl_verbose_info"],curl執行的詳細資訊.
9273
				#$result["privateKey"], private key 的內容.
9274
				#必填參數:
9275
				#$conf["domain"],字串,csr內容的網域名稱.
9276
				$conf["zerossl::createCSR"]["domain"]=$cName;
9277
				#可省略參數:
9278
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
9279
				#$conf["pKey"]="";
9280
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
9281
				#$conf["country"]="";
9282
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
9283
				#$conf["state"]="";
9284
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
9285
				#$conf["org"]="";
9286
				#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
9287
				#$conf["unit"]="";
9288
				#參考資料:
9289
				#無.
9290
				#備註:
9291
				#無.
9292
				$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
9293
				unset($conf["zerossl::createCSR"]);
9294
 
9295
				#如果運行異常
9296
				if($createCSR["status"]==="false"){
9297
 
9298
					#設置錯誤識別
9299
					$result["status"]="false";
9300
 
9301
					#設置錯誤訊息
9302
					$result["error"]=$createCSR;
9303
 
9304
					#回傳結果
9305
					return $result;
9306
 
9307
					}#if end
9308
 
9309
				#取得本地端產生的csr內容
9310
				$csrLocal=$createCSR["content"];
9311
 
281 liveuser 9312
				#if enable debug
9313
				if($debug){
9314
 
9315
					#debug msg
291 liveuser 9316
					echo "Creating certificate for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 9317
 
9318
					}#if end
9319
 
255 liveuser 9320
				#函式說明:
281 liveuser 9321
				#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 9322
				#回傳結果:
9323
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9324
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9325
				#$result["function"],當前執行的函式名稱.
9326
				#$result["argu"],所使用的參數.
9327
				#$result["curl_verbose_info"],curl執行的詳細資訊.
9328
				#$result["id"],用於zerossl api驗證domain的id.
9329
				#$result["content"],字串,得到的json字串回應.
9330
				#$result["cnameKey"],用於dns CNAME驗證鍵名.
9331
				#$result["cnameVal"],用於dms CNAME驗證鍵值.
9332
				#必填參數:
9333
				#$conf["certificate_domains"],字串,要簽署的doamin名稱.
9334
				$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
9335
				#$conf["certificate_csr"],字串,簽署的資訊.
9336
				$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
9337
				#$conf["fileArgu"],字串,變數__FILE__的內容.
9338
				$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
9339
				#可省略參數:
9340
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9341
				$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9342
				#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
9343
				#$conf["path"]=self::getApiInfo()["csrPath"];
9344
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9345
				$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9346
				#參考資料:
9347
				#無.
9348
				#備註:
9349
				#無.
9350
				$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
9351
				unset($conf["zerossl::createCertificate"]);
9352
 
9353
				#如果執行異常
9354
				if($createCertificate["status"]==="false"){
9355
 
9356
					#設置錯誤識別
9357
					$result["status"]="false";
9358
 
9359
					#設置錯誤訊息
9360
					$result["error"]=$createCertificate;
9361
 
9362
					#回傳結果
9363
					return $result;
9364
 
9365
					}#if end
9366
 
9367
				#取得csr在zerossl上的id
9368
				$csrId=$createCertificate["id"];
9369
 
9370
				#取得cname key
9371
				$cNameKey=$createCertificate["cnameKey"];
9372
 
9373
				#取得cname val
9374
				$cNameVal=$createCertificate["cnameVal"];
9375
 
9376
				#初始化要增加的RR記錄
9377
				$rr2add=array();
9378
 
9379
				#設置CNAME的查詢
9380
				$rr2add["query"]=$cNameKey;
9381
 
9382
				#設置CNAME的value
9383
				$rr2add["value"]=$cNameVal;
9384
 
9385
				#設置類型為 CNAME
9386
				$rr2add["type"]="CNAME";
9387
 
9388
				#設置註解
9389
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
9390
 
281 liveuser 9391
				#if enable debug
9392
				if($debug){
9393
 
9394
					#debug msg
291 liveuser 9395
					echo "Adding DNS record to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9396
 
9397
					}#if end
9398
 
255 liveuser 9399
				#函式說明:
9400
				#新增DNS記錄到檔案裡面.
9401
				#回傳結果:
9402
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9403
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9404
				#$result["function"],當前執行的函式名稱.
9405
				#$result["argu"],所使用的參數.
9406
				#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
9407
				#$result["domain"],字串,RR所屬domain.
9408
				#$result["defaultTTL"],字串,預設的RR更新時間.
9409
				#$result["comment"],字串陣列,逐行的註解.
9410
				#必填參數:
9411
				#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
291 liveuser 9412
				$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 9413
				#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
9414
				$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
9415
				#可省略參數:
9416
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
9417
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
9418
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
9419
				#$conf["debug"]="false";
9420
				#參考資料:
9421
				#無.
9422
				#備註:
9423
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
9424
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
9425
				#php-pear上的Net_DNS2也可以解析RR.
9426
				$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
9427
				unset($conf["zerossl::updateDnsRecordFile"]);
9428
 
9429
				#如果執行異常
9430
				if($updateDnsRecordFile["status"]==="false"){
9431
 
9432
					#設置錯誤識別
9433
					$result["status"]="false";
9434
 
9435
					#設置錯誤訊息
9436
					$result["error"]=$updateDnsRecordFile;
9437
 
9438
					#回傳結果
9439
					return $result;
9440
 
9441
					}#if end
281 liveuser 9442
 
9443
				#if enable debug
9444
				if($debug){
9445
 
9446
					#debug msg
291 liveuser 9447
					echo "Restart DNS service to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9448
 
9449
					}#if end
9450
 
255 liveuser 9451
				#重新啟動dns伺服器
9452
				#函式說明:
9453
				#呼叫shell執行系統命令,並取得回傳的內容.
9454
				#回傳結果:
9455
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9456
				#$result["error"],錯誤訊息陣列.
9457
				#$result["function"],當前執行的函數名稱.
9458
				#$result["argu"],使用的參數.
9459
				#$result["cmd"],執行的指令內容.
9460
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9461
				#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9462
				#$result["content"],為執行完後的輸出字串.
9463
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9464
				#$result["running"],是否還在執行.
9465
				#$result["pid"],pid.
9466
				#$result["statusCode"],執行結束後的代碼.
9467
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9468
				#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9469
				#必填參數:
9470
				#$conf["command"],字串,要執行的指令.
291 liveuser 9471
				$conf["external::callShell"]["command"]="systemctl";
255 liveuser 9472
				#$conf["fileArgu"],字串,變數__FILE__的內容.
9473
				$conf["external::callShell"]["fileArgu"]=__FILE__;
9474
				#可省略參數:
9475
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9476
				$conf["external::callShell"]["argu"]=array("restart","named");
9477
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9478
				#$conf["arguIsAddr"]=array();
9479
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9480
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9481
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9482
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9483
				#$conf["enablePrintDescription"]="true";
9484
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9485
				#$conf["printDescription"]="";
9486
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9487
				#$conf["escapeshellarg"]="false";
9488
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9489
				#$conf["thereIsShellVar"]=array();
9490
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9491
				#$conf["username"]="";
9492
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9493
				#$conf["password"]="";
9494
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9495
				#$conf["useScript"]="";
9496
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9497
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9498
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9499
				#$conf["inBackGround"]="";
9500
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9501
				#$conf["getErr"]="false";
9502
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9503
				#$conf["doNotRun"]="false";
9504
				#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
9505
				$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
9506
				#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
9507
				#$conf["remoteUser"]="root";
9508
				#參考資料:
9509
				#exec=>http://php.net/manual/en/function.exec.php
9510
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9511
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9512
				#備註:
9513
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9514
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9515
				$callShell=external::callShell($conf["external::callShell"]);
9516
				unset($conf["external::callShell"]);
9517
 
9518
				#如果執行異常
9519
				if($callShell["status"]==="false"){
9520
 
9521
					#設置錯誤識別
9522
					$result["status"]="false";
9523
 
9524
					#設置錯誤訊息
9525
					$result["error"]=$callShell;
9526
 
9527
					#回傳結果
9528
					return $result;
9529
 
9530
					}#if end
281 liveuser 9531
 
9532
				#if enable debug
9533
				if($debug){
9534
 
9535
					#debug msg
291 liveuser 9536
					echo "Request zerossl to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9537
 
9538
					}#if end
9539
 
255 liveuser 9540
				#函式說明:
9541
				#請求驗證已經透過zerossl::createCertificate要求的domain.
9542
				#回傳結果:
9543
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9544
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9545
				#$result["function"],當前執行的函式名稱.
9546
				#$result["argu"],所使用的參數.
9547
				#$result["curl_verbose_info"],curl執行的詳細資訊.
9548
				#$result["content"],結果json字串.
9549
				#必填參數:
9550
				#$conf["id"],字串,zerossl::createCertificate回傳的id.
9551
				$conf["zerossl::verifyDomain"]["id"]=$csrId;
9552
				#可省略參數:
9553
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9554
				$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9555
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9556
				$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9557
				#參考資料:
9558
				#https://zerossl.com/documentation/api/verify-domains/
9559
				#備註:
9560
				#無.
9561
				$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
9562
				unset($conf["zerossl::verifyDomain"]);
9563
 
9564
				#如果執行異常
9565
				if($verifyDomain["status"]==="false"){
9566
 
9567
					#設置錯誤識別
9568
					$result["status"]="false";
9569
 
9570
					#設置錯誤訊息
9571
					$result["error"]=$verifyDomain;
9572
 
9573
					#回傳結果
9574
					return $result;
9575
 
9576
					}#if end
291 liveuser 9577
 
9578
				#如果沒有回內容
9579
				if(!isset($verifyDomain["content"][0])){
281 liveuser 9580
 
291 liveuser 9581
					#設置錯誤識別
9582
					$result["status"]="false";
9583
 
9584
					#設置錯誤訊息
9585
					$result["error"]=$verifyDomain;
9586
 
9587
					#回傳結果
9588
					return $result;
9589
 
9590
					}#if end
9591
 
9592
				#如果回應不是 json
9593
				if(!(json_validate($verifyDomain["content"][0]))){
9594
 
9595
					#設置錯誤識別
9596
					$result["status"]="false";
9597
 
9598
					#設置錯誤訊息
9599
					$result["error"]=$verifyDomain;
9600
 
9601
					#回傳結果
9602
					return $result;
9603
 
9604
					}#if end
9605
 
9606
				/*
9607
				範例json:
9608
				{"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}
9609
				*/
9610
 
9611
				#解析json回應
9612
				$verifyDomainRes=json_decode($verifyDomain["content"][0]);
9613
 
9614
				#如果是 zerossl 驗證失敗
9615
				if($verifyDomainRes->status==="false"){
9616
 
9617
					#如果是 CNAME 記錄找不到...
9618
 
9619
					#設置錯誤識別
9620
					$result["status"]="false";
9621
 
9622
					#設置錯誤訊息
9623
					$result["error"]=$verifyDomain;
9624
 
9625
					#回傳結果
9626
					return $result;
9627
 
9628
					}#if end
9629
 
9630
				#如果是 zerossl 尚在驗證中
9631
				if($verifyDomainRes->status==="pending_validation"){
9632
 
9633
					#if enable debug
9634
					if($debug){
9635
 
9636
						#debug msg
9637
						echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9638
 
9639
						}#if end
9640
 
9641
					#無窮迴圈
9642
					while(true){
9643
 
9644
						#查詢驗證狀況
9645
						#函式說明:
9646
						#取得CSR在zerossl上的狀態
9647
						#回傳結果:
9648
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9649
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
9650
						#$result["function"],當前執行的函式名稱.
9651
						#$result["argu"],所使用的參數.
9652
						#$result["curl_verbose_info"],curl執行的詳細資訊.
9653
						#$result["content"],結果json字串.
9654
						#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9655
						#必填參數:
9656
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
9657
						$conf["zerossl::getCertSta"]["id"]=$csrId;
9658
						#可省略參數:
9659
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
9660
						$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
9661
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
9662
						$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
9663
						#參考資料:
9664
						#https://zerossl.com/documentation/api/get-certificate/
9665
						#備註:
9666
						#無.
9667
						$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
9668
						unset($conf["zerossl::getCertSta"]);
9669
 
9670
						#如果執行異常
9671
						if($getCertSta["status"]==="false"){
9672
 
9673
							#設置錯誤識別
9674
							$result["status"]="false";
9675
 
9676
							#設置錯誤訊息
9677
							$result["error"]=$getCertSta;
9678
 
9679
							#回傳結果
9680
							return $result;
9681
 
9682
							}#if end
9683
 
9684
						#如果沒有回應內容
9685
						if(!isset($getCertSta["content"][0])){
9686
 
9687
							#設置錯誤識別
9688
							$result["status"]="false";
9689
 
9690
							#設置錯誤訊息
9691
							$result["error"]=$getCertSta;
9692
 
9693
							#回傳結果
9694
							return $result;
9695
 
9696
							}#if end
9697
 
9698
						#如果回應不是 json
9699
						if(!(json_validate($getCertSta["content"][0]))){
9700
 
9701
							#設置錯誤識別
9702
							$result["status"]="false";
9703
 
9704
							#設置錯誤訊息
9705
							$result["error"]=$getCertSta;
9706
 
9707
							#回傳結果
9708
							return $result;
9709
 
9710
							}#if end
9711
 
9712
						#解析json回應
9713
						$getCertStaRes=json_decode($getCertSta["content"][0]);
9714
 
9715
						#如果憑證已經驗證通過了
9716
						if($getCertStaRes->status==="issued"){
9717
 
9718
							#if enable debug
9719
							if($debug){
9720
 
9721
								#debug msg
9722
								echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
9723
 
9724
								}#if end
9725
 
9726
							#結束等待
9727
							break;
9728
 
9729
							}#if end
9730
 
9731
						#如果 zerossl 尚在處理中
9732
						else if($getCertStaRes->status==="pending_validation"){
9733
 
9734
							#if enable debug
9735
							if($debug){
9736
 
9737
								#debug msg
9738
								echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9739
 
9740
								}#if end
9741
 
9742
							#休息1分鐘
9743
							sleep(60);
9744
 
9745
							}#if end
9746
 
9747
						#反之
9748
						else{
9749
 
9750
							#例外狀況
9751
 
9752
							#設置錯誤識別
9753
							$result["status"]="false";
9754
 
9755
							#設置錯誤訊息
9756
							$result["error"]=$getCertSta;
9757
 
9758
							#回傳結果
9759
							return $result;
9760
 
9761
							}#else end
9762
 
9763
						}#while end
9764
 
9765
					}#if end
9766
 
281 liveuser 9767
				#if enable debug
9768
				if($debug){
9769
 
9770
					#debug msg
291 liveuser 9771
					echo "Downloading certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9772
 
9773
					}#if end
9774
 
255 liveuser 9775
				#函式說明:
9776
				#下載certificate.
9777
				#回傳結果:
9778
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9779
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9780
				#$result["function"],當前執行的函式名稱.
9781
				#$result["argu"],所使用的參數.
9782
				#$result["curl_verbose_info"],curl執行的詳細資訊.
9783
				#$result["content"],結果json字串.
9784
				#$result["certificate.crt"],字串,certificate.crt的內容.
9785
				#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
9786
				#必填參數:
9787
				#無.
9788
				#可省略參數:
9789
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9790
				$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9791
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9792
				$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9793
				#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
9794
				$conf["zerossl::getCert"]["id"]=$csrId;
9795
				#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
9796
				#$conf["zerossl::getCert"]["cname"]="";
9797
				#參考資料:
9798
				#https://zerossl.com/documentation/api/download-certificate-inline/
9799
				#備註:
9800
				#無.
9801
				$getCert=zerossl::getCert($conf["zerossl::getCert"]);
9802
				unset($conf["zerossl::getCert"]);
9803
 
9804
				#如果執行異常
9805
				if($getCert["status"]==="false"){
9806
 
9807
					#設置錯誤識別
9808
					$result["status"]="false";
9809
 
9810
					#設置錯誤訊息
9811
					$result["error"]=$getCert;
9812
 
9813
					#回傳結果
9814
					return $result;
9815
 
9816
					}#if end
281 liveuser 9817
 
9818
				#if enable debug
9819
				if($debug){
9820
 
9821
					#debug msg
291 liveuser 9822
					echo "Creating certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9823
 
9824
					}#if end
9825
 
255 liveuser 9826
				#建立 certificate.crt 檔案
9827
				#$cInfo["certPath"];
9828
 
9829
				#建立 ca_bundle.crt 檔案
9830
				#$cInfo["caPath"];
9831
 
9832
				#建立 certAndCa.crt 檔案
9833
				#$cInfo["certWithCaPath"];
9834
 
9835
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
9836
				#函式說明:
9837
				#一次建立多個檔案,並寫入內容.
9838
				#回傳結果:
9839
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9840
				#$result["error"],錯誤訊息陣列.
9841
				#$result["function"],當前執行的函數名稱.
9842
				#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
9843
				#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
9844
				#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
9845
				#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
9846
				#$result["argu"],使用的參數.
9847
				#必填參數:
9848
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9849
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
9850
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 9851
				$conf["zerossl::writeMultiFile"]["fileName"]=array($conf["info"]["share"]["certPath"],$conf["info"]["share"]["caPath"],$conf["info"]["share"]["certWithCaPath"]);
255 liveuser 9852
				#可省略參數:
9853
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
9854
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
9855
				#參考資料:
9856
				#無.
9857
				#備註:
9858
				#無.
9859
				$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
9860
				unset($conf["zerossl::writeMultiFile"]);
9861
 
9862
				#如果執行異常
9863
				if($writeMultiFile["status"]==="false"){
9864
 
9865
					#設置錯誤識別
9866
					$result["status"]="false";
9867
 
9868
					#設置錯誤訊息
9869
					$result["error"]=$writeMultiFile;
9870
 
9871
					#回傳結果
9872
					return $result;
9873
 
9874
					}#if end
9875
 
9876
				#儲存 actionAfterUpdateCert
9877
				$action=$cInfo["actionAfterUpdateCert"];
9878
 
9879
				#如果有多個指令要執行
9880
				if(gettype($action[0])==="array"){
9881
 
281 liveuser 9882
					#if enable debug
9883
					if($debug){
9884
 
9885
						#debug msg
291 liveuser 9886
						echo "There are many cmds to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9887
 
9888
						}#if end
9889
 
9890
					#if enable debug
9891
					if($debug){
9892
 
9893
						#debug msg
291 liveuser 9894
						echo "Running cmd to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9895
 
9896
						}#if end
9897
 
255 liveuser 9898
					#針對每的指令
9899
					foreach($action as $ac){
9900
 
281 liveuser 9901
						#if enable debug
9902
						if($debug){
9903
 
9904
							#debug msg
9905
							echo ".".PHP_EOL;
9906
 
9907
							}#if end
9908
 
255 liveuser 9909
						#函式說明:
9910
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
9911
						#回傳結果:
9912
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9913
						#$result["error"],錯誤訊息陣列.
9914
						#$result["function"],當前執行的函數名稱.
9915
						#$result["argu"],使用的參數.
9916
						#$result["cmd"],執行的指令名稱.
9917
						#$result["params"],執行指令伴隨的參數.
9918
						#必填參數:
9919
						#$conf["cmdArray"],字串陣列,要執行的指令字串.
9920
						$conf["external::callShellHelper"]["cmdArray"]=$ac;
9921
						#可省略參數:
9922
						#無.
9923
						#參考資料:
9924
						#array_shift=>https://www.php.net/manual/en/function.array-shift.php
9925
						#備註:
9926
						#無.
9927
						$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
9928
						unset($conf["external::callShellHelper"]);
9929
 
9930
						#如果執行異常
9931
						if($callShellHelper["status"]==="false"){
9932
 
9933
							#設置錯誤識別
9934
							$result["status"]="false";
9935
 
9936
							#設置錯誤訊息
9937
							$result["error"]=$callShellHelper;
9938
 
9939
							#回傳結果
9940
							return $result;
9941
 
9942
							}#if end
9943
 
9944
						#函式說明:
9945
						#呼叫shell執行系統命令,並取得回傳的內容.
9946
						#回傳結果:
9947
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9948
						#$result["error"],錯誤訊息陣列.
9949
						#$result["function"],當前執行的函數名稱.
9950
						#$result["argu"],使用的參數.
9951
						#$result["cmd"],執行的指令內容.
9952
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9953
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9954
						#$result["content"],為執行完後的輸出字串.
9955
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9956
						#$result["running"],是否還在執行.
9957
						#$result["pid"],pid.
9958
						#$result["statusCode"],執行結束後的代碼.
9959
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9960
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9961
						#必填參數:
9962
						#$conf["command"],字串,要執行的指令.
9963
						$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
9964
						#$conf["fileArgu"],字串,變數__FILE__的內容.
9965
						$conf["external::callShell"]["fileArgu"]=__FILE__;
9966
						#可省略參數:
9967
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9968
						$conf["external::callShell"]["argu"]=$callShellHelper["params"];
9969
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9970
						#$conf["arguIsAddr"]=array();
9971
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9972
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9973
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9974
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9975
						#$conf["enablePrintDescription"]="true";
9976
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9977
						#$conf["printDescription"]="";
9978
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9979
						$conf["external::callShell"]["escapeshellarg"]="true";
9980
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9981
						#$conf["thereIsShellVar"]=array();
9982
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9983
						#$conf["username"]="";
9984
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9985
						#$conf["password"]="";
9986
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9987
						#$conf["useScript"]="";
9988
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9989
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9990
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9991
						#$conf["inBackGround"]="";
9992
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9993
						#$conf["getErr"]="false";
9994
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9995
						#$conf["doNotRun"]="false";
9996
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
9997
						#$conf["remoteIp"]="";
9998
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
9999
						#$conf["remoteUser"]="";
10000
						#參考資料:
10001
						#exec=>http://php.net/manual/en/function.exec.php
10002
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10003
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10004
						#備註:
10005
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10006
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10007
						$callShell=external::callShell($conf["external::callShell"]);
10008
						unset($conf["external::callShell"]);
10009
 
10010
						#如果執行異常
10011
						if($callShellHelper["status"]==="false"){
10012
 
10013
							#設置錯誤識別
10014
							$result["status"]="false";
10015
 
10016
							#設置錯誤訊息
10017
							$result["error"]=$callShell;
10018
 
10019
							#回傳結果
10020
							return $result;
10021
 
10022
							}#if end
10023
 
10024
						}#foreach end
10025
 
10026
					}#if end
10027
 
10028
				#反之
10029
				else{
10030
 
281 liveuser 10031
					#if enable debug
10032
					if($debug){
10033
 
10034
						#debug msg
291 liveuser 10035
						echo "There is only one cmd to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10036
 
10037
						}#if end
10038
 
10039
					#if enable debug
10040
					if($debug){
10041
 
10042
						#debug msg
10043
						echo ".".PHP_EOL;
10044
 
10045
						}#if end
10046
 
255 liveuser 10047
					#函式說明:
10048
					#解析指令與參數,回傳指令與參數給 callShell 函式使用.
10049
					#回傳結果:
10050
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10051
					#$result["error"],錯誤訊息陣列.
10052
					#$result["function"],當前執行的函數名稱.
10053
					#$result["argu"],使用的參數.
10054
					#$result["cmd"],執行的指令名稱.
10055
					#$result["params"],執行指令伴隨的參數.
10056
					#必填參數:
10057
					#$conf["cmdArray"],字串陣列,要執行的指令字串.
10058
					$conf["external::callShellHelper"]["cmdArray"]=$action;
10059
					#可省略參數:
10060
					#無.
10061
					#參考資料:
10062
					#array_shift=>https://www.php.net/manual/en/function.array-shift.php
10063
					#備註:
10064
					#無.
10065
					$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
10066
					unset($conf["external::callShellHelper"]);
10067
 
10068
					#如果執行異常
10069
					if($callShellHelper["status"]==="false"){
10070
 
10071
						#設置錯誤識別
10072
						$result["status"]="false";
10073
 
10074
						#設置錯誤訊息
10075
						$result["error"]=$callShellHelper;
10076
 
10077
						#回傳結果
10078
						return $result;
10079
 
10080
						}#if end
10081
 
10082
					#函式說明:
10083
					#呼叫shell執行系統命令,並取得回傳的內容.
10084
					#回傳結果:
10085
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10086
					#$result["error"],錯誤訊息陣列.
10087
					#$result["function"],當前執行的函數名稱.
10088
					#$result["argu"],使用的參數.
10089
					#$result["cmd"],執行的指令內容.
10090
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10091
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10092
					#$result["content"],為執行完後的輸出字串.
10093
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10094
					#$result["running"],是否還在執行.
10095
					#$result["pid"],pid.
10096
					#$result["statusCode"],執行結束後的代碼.
10097
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10098
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10099
					#必填參數:
10100
					#$conf["command"],字串,要執行的指令.
10101
					$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
10102
					#$conf["fileArgu"],字串,變數__FILE__的內容.
10103
					$conf["external::callShell"]["fileArgu"]=__FILE__;
10104
					#可省略參數:
10105
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
10106
					$conf["external::callShell"]["argu"]=$callShellHelper["params"];
10107
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10108
					#$conf["arguIsAddr"]=array();
10109
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10110
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10111
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10112
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10113
					#$conf["enablePrintDescription"]="true";
10114
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10115
					#$conf["printDescription"]="";
10116
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10117
					$conf["external::callShell"]["escapeshellarg"]="true";
10118
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10119
					#$conf["thereIsShellVar"]=array();
10120
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10121
					#$conf["username"]="";
10122
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10123
					#$conf["password"]="";
10124
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10125
					#$conf["useScript"]="";
10126
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10127
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10128
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10129
					#$conf["inBackGround"]="";
10130
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10131
					#$conf["getErr"]="false";
10132
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10133
					#$conf["doNotRun"]="false";
10134
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10135
					#$conf["remoteIp"]="";
10136
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10137
					#$conf["remoteUser"]="";
10138
					#參考資料:
10139
					#exec=>http://php.net/manual/en/function.exec.php
10140
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10141
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10142
					#備註:
10143
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10144
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10145
					$callShell=external::callShell($conf["external::callShell"]);
10146
					unset($conf["external::callShell"]);
10147
 
10148
					#如果執行異常
10149
					if($callShellHelper["status"]==="false"){
10150
 
10151
						#設置錯誤識別
10152
						$result["status"]="false";
10153
 
10154
						#設置錯誤訊息
10155
						$result["error"]=$callShell;
10156
 
10157
						#回傳結果
10158
						return $result;
10159
 
10160
						}#if end
10161
 
10162
					}#else end
10163
 
10164
				}#if end
10165
 
10166
			#反之
10167
			else{
10168
 
281 liveuser 10169
				#if enable debug
10170
				if($debug){
10171
 
10172
					#debug msg
291 liveuser 10173
					echo "There is already valid ssl for domain name(".$cName.") on zerossl".PHP_EOL;
281 liveuser 10174
 
10175
					}#if end
10176
 
291 liveuser 10177
				#debug
10178
				#var_dump(__LINE__,$getCertList);
10179
 
255 liveuser 10180
				#有 issued 的憑證
10181
 
291 liveuser 10182
				#if enable debug
10183
				if($debug){
10184
 
10185
					#debug msg
10186
					echo "Downloading ssl for domain name(".$cName.") on zerossl".PHP_EOL;
10187
 
10188
					}#if end
10189
 
255 liveuser 10190
				#取得 certificate id at zerossl
10191
				#函式說明:
10192
				#將陣列轉換成存有key與value的陣列
10193
				#回傳的結果:
10194
				#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
10195
				#$result["function"],當前執行的函數
10196
				#$result["error"],錯誤訊息.
10197
				#$result[$i]["key"],原先$i+1個元素的key.
10198
				#$result[$i]["value"],原先$i+1個元素的value.
10199
				#必填參數:
10200
				#$conf["rawInputArray"],陣列,要轉換的陣列變數.
10201
				$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
10202
				#可省略參數:
10203
				#無.
10204
				#參考資料:
10205
				#無.
10206
				#備註:
10207
				#無.
10208
				$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
10209
				unset($conf["arrays::getKeyAndValue"]);
10210
 
10211
				#如果執行異常
10212
				if($getKeyAndValue["status"]==="false"){
10213
 
10214
					#設置錯誤識別
10215
					$result["status"]="false";
10216
 
10217
					#設置錯誤訊息
10218
					$result["error"]=$getKeyAndValue;
10219
 
10220
					#回傳結果
10221
					return $result;
10222
 
10223
					}#if end
10224
 
291 liveuser 10225
				#debug
10226
				#var_dump($getKeyAndValue);exit;
10227
 
255 liveuser 10228
				#儲存 certificate id at zerossl
291 liveuser 10229
				$csrId=$getKeyAndValue[1]["key"];
255 liveuser 10230
 
10231
				#檢查憑證是否已經快過期
10232
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
10233
 
10234
				#如果距離當下不到2個星期就要過期
10235
				if($expiresIn<=86400*14){
291 liveuser 10236
 
281 liveuser 10237
					#if enable debug
10238
					if($debug){
10239
 
10240
						#debug msg
291 liveuser 10241
						echo "Valid ssl for domain name(".$cName.") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
281 liveuser 10242
 
10243
						}#if end
10244
 
291 liveuser 10245
					#debug
10246
					#var_dump($expiresIn);exit;
10247
 
255 liveuser 10248
					#另存舊的憑證id,最後要revoke之.
10249
					$oldCsrId=$csrId;
10250
 
281 liveuser 10251
					#if enable debug
10252
					if($debug){
10253
 
10254
						#debug msg
291 liveuser 10255
						echo "Start requst new ssl process for domain name(".$cName.").".PHP_EOL;
281 liveuser 10256
 
10257
						}#if end
10258
 
10259
					#if enable debug
10260
					if($debug){
10261
 
10262
						#debug msg
291 liveuser 10263
						echo "Finding ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10264
 
10265
						}#if end
10266
 
255 liveuser 10267
					#確認有無對應 cName 的 private key
10268
					#函式說明:
10269
					#檢查多個檔案與資料夾是否存在.
10270
					#回傳的結果:
10271
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
10272
					#$result["error"],錯誤訊息陣列.
10273
					#$resutl["function"],當前執行的涵式名稱.
10274
					#$result["argu"],使用的參數.
10275
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
10276
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
10277
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
10278
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
10279
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
10280
					#必填參數:
10281
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
291 liveuser 10282
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 10283
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10284
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
10285
					#可省略參數:
10286
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
10287
					#$conf["disableWebSearch"]="false";
10288
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
10289
					$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
10290
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
10291
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
10292
					#參考資料:
10293
					#http://php.net/manual/en/function.file-exists.php
10294
					#http://php.net/manual/en/control-structures.foreach.php
10295
					#備註:
10296
					#函數file_exists檢查的路徑為檔案系統的路徑
10297
					#$result["varName"][$i]結果未實作
10298
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
10299
					unset($conf["fileAccess::checkMultiFileExist"]);
10300
 
10301
					#如果運行異常
10302
					if($checkMultiFileExist["status"]==="false"){
10303
 
10304
						#設置錯誤識別
10305
						$result["status"]="false";
10306
 
10307
						#設置錯誤訊息
10308
						$result["error"]=$getCertList;
10309
 
10310
						#回傳結果
10311
						return $result;
10312
 
10313
						}#if end
10314
 
10315
					#如果沒有 private key
10316
					if($checkMultiFileExist["allExist"]==="false"){
10317
 
281 liveuser 10318
						#if enable debug
10319
						if($debug){
10320
 
10321
							#debug msg
291 liveuser 10322
							echo "Thers is no ssl private key for domain name(".$cName.").".PHP_EOL;
281 liveuser 10323
 
10324
							}#if end
10325
 
10326
						#if enable debug
10327
						if($debug){
10328
 
10329
							#debug msg
291 liveuser 10330
							echo "Creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10331
 
10332
							}#if end
10333
 
255 liveuser 10334
						#建立 private key
10335
						#函式說明:
10336
						#產生ssl private key.
10337
						#回傳結果:
10338
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10339
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
10340
						#$result["function"],當前執行的函式名稱.
10341
						#$result["argu"],所使用的參數.
10342
						#$result["curl_verbose_info"],curl執行的詳細資訊.
10343
						#$result["content"],ssl用的private key.
10344
						#必填參數:
10345
						#$conf["fileArgu"],字串,變數__FILE__的內容.
10346
						$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
10347
						#可省略參數:
10348
						#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
10349
						#$conf["length"]=4096';
10350
						#參考資料:
10351
						#無.
10352
						#備註:
10353
						#key generated by openssl with RSA.
291 liveuser 10354
						$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 10355
						unset($conf["openssl::createPrivateKey"]);
10356
 
10357
						#如果運行異常
10358
						if($createPrivateKey["status"]==="false"){
10359
 
10360
							#設置錯誤識別
10361
							$result["status"]="false";
10362
 
10363
							#設置錯誤訊息
10364
							$result["error"]=$createPrivateKey;
10365
 
10366
							#回傳結果
10367
							return $result;
10368
 
10369
							}#if end
10370
 
10371
						#另存private key的字串
10372
						$pKeyStr=$createPrivateKey["content"];
10373
 
281 liveuser 10374
						#if enable debug
10375
						if($debug){
10376
 
10377
							#debug msg
291 liveuser 10378
							echo "Writing ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10379
 
10380
							}#if end
10381
 
255 liveuser 10382
						#建立private key檔案
10383
						#函式說明:
10384
						#將字串寫入到檔案
10385
						#回傳結果:
10386
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10387
						#$result["error"],錯誤訊息陣列.
10388
						#$result["function"],當前執行的函數名稱.
10389
						#$result["fileInfo"],實際上寫入的檔案資訊陣列.
10390
						#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
10391
						#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
10392
						#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
10393
						#$result["argu"],使用的參數.
10394
						#必填參數:
10395
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10396
						$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
10397
						#可省略參數:
10398
						#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
291 liveuser 10399
						$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 10400
						#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
10401
						$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
10402
						#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
10403
						#$conf["writeMethod"]="a";
10404
						#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
10405
						#$conf["checkRepeat"]="";
10406
						#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
10407
						#$conf["filenameExtensionStartPoint"]="";
10408
						#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
10409
						#$conf["repeatNameRule"]="";
10410
						#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
10411
						$conf["zerossl::writeTextIntoFile"]["web"]="false";
10412
						#參考資料:
10413
						#無.
10414
						#備註:
10415
						#無.
10416
						$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
10417
						unset($conf["zerossl::writeTextIntoFile"]);
10418
 
10419
						#如果運行異常
10420
						if($writeTextIntoFile["status"]==="false"){
10421
 
10422
							#設置錯誤識別
10423
							$result["status"]="false";
10424
 
10425
							#設置錯誤訊息
10426
							$result["error"]=$writeTextIntoFile;
10427
 
10428
							#回傳結果
10429
							return $result;
10430
 
10431
							}#if end
10432
 
10433
						}#if end
10434
 
281 liveuser 10435
					#if enable debug
10436
					if($debug){
10437
 
10438
						#debug msg
291 liveuser 10439
						echo "Creating CSR for domain name(".$cName.") to zerossl.".PHP_EOL;
281 liveuser 10440
 
10441
						}#if end
10442
 
255 liveuser 10443
					#建立準備給zerossl的csr
10444
					#函式說明:
10445
					#產生certificate sign request(CSR).
10446
					#回傳結果:
10447
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10448
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10449
					#$result["function"],當前執行的函式名稱.
10450
					#$result["argu"],所使用的參數.
10451
					#$result["content"],csr內容.
10452
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10453
					#$result["privateKey"], private key 的內容.
10454
					#必填參數:
10455
					#$conf["domain"],字串,csr內容的網域名稱.
10456
					$conf["zerossl::createCSR"]["domain"]=$cName;
10457
					#可省略參數:
10458
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
10459
					#$conf["pKey"]="";
10460
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
10461
					#$conf["country"]="";
10462
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
10463
					#$conf["state"]="";
10464
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
10465
					#$conf["org"]="";
10466
					#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
10467
					#$conf["unit"]="";
10468
					#參考資料:
10469
					#無.
10470
					#備註:
10471
					#無.
10472
					$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
10473
					unset($conf["zerossl::createCSR"]);
10474
 
10475
					#如果運行異常
10476
					if($createCSR["status"]==="false"){
10477
 
10478
						#設置錯誤識別
10479
						$result["status"]="false";
10480
 
10481
						#設置錯誤訊息
10482
						$result["error"]=$createCSR;
10483
 
10484
						#回傳結果
10485
						return $result;
10486
 
10487
						}#if end
10488
 
10489
					#取得本地端產生的csr內容
10490
					$csrLocal=$createCSR["content"];
10491
 
281 liveuser 10492
					#if enable debug
10493
					if($debug){
10494
 
10495
						#debug msg
291 liveuser 10496
						echo "Providing CSR for domain name(".$cName.") to zerossl".PHP_EOL;
281 liveuser 10497
 
10498
						}#if end
10499
 
255 liveuser 10500
					#函式說明:
281 liveuser 10501
					#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 10502
					#回傳結果:
10503
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10504
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10505
					#$result["function"],當前執行的函式名稱.
10506
					#$result["argu"],所使用的參數.
10507
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10508
					#$result["id"],用於zerossl api驗證domain的id.
10509
					#$result["content"],字串,得到的json字串回應.
10510
					#$result["cnameKey"],用於dns CNAME驗證鍵名.
10511
					#$result["cnameVal"],用於dms CNAME驗證鍵值.
10512
					#必填參數:
10513
					#$conf["certificate_domains"],字串,要簽署的doamin名稱.
10514
					$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
10515
					#$conf["certificate_csr"],字串,簽署的資訊.
10516
					$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
10517
					#$conf["fileArgu"],字串,變數__FILE__的內容.
10518
					$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
10519
					#可省略參數:
10520
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 10521
					$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 10522
					#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
10523
					#$conf["path"]=self::getApiInfo()["csrPath"];
10524
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 10525
					$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 10526
					#參考資料:
10527
					#無.
10528
					#備註:
10529
					#無.
10530
					$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
10531
					unset($conf["zerossl::createCertificate"]);
10532
 
10533
					#如果執行異常
10534
					if($createCertificate["status"]==="false"){
10535
 
10536
						#設置錯誤識別
10537
						$result["status"]="false";
10538
 
10539
						#設置錯誤訊息
10540
						$result["error"]=$createCertificate;
10541
 
10542
						#回傳結果
10543
						return $result;
10544
 
10545
						}#if end
10546
 
10547
					#取得csr在zerossl上的id
10548
					$csrId=$createCertificate["id"];
10549
 
10550
					#取得cname key
10551
					$cNameKey=$createCertificate["cnameKey"];
10552
 
10553
					#取得cname val
10554
					$cNameVal=$createCertificate["cnameVal"];
10555
 
10556
					#初始化要增加的RR記錄
10557
					$rr2add=array();
10558
 
10559
					#設置CNAME的查詢
10560
					$rr2add["query"]=$cNameKey;
10561
 
10562
					#設置CNAME的value
10563
					$rr2add["value"]=$cNameVal;
10564
 
10565
					#設置類型為 CNAME
10566
					$rr2add["type"]="CNAME";
10567
 
10568
					#設置註解
10569
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
10570
 
281 liveuser 10571
					#if enable debug
10572
					if($debug){
10573
 
10574
						#debug msg
291 liveuser 10575
						echo "Adding DNS record to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 10576
 
10577
						}#if end
10578
 
255 liveuser 10579
					#函式說明:
10580
					#新增DNS記錄到檔案裡面.
10581
					#回傳結果:
10582
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10583
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10584
					#$result["function"],當前執行的函式名稱.
10585
					#$result["argu"],所使用的參數.
10586
					#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
10587
					#$result["domain"],字串,RR所屬domain.
10588
					#$result["defaultTTL"],字串,預設的RR更新時間.
10589
					#$result["comment"],字串陣列,逐行的註解.
10590
					#必填參數:
10591
					#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
10592
					$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2ad);
10593
					#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
10594
					$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
10595
					#可省略參數:
10596
					#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
10597
					$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
10598
					#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
10599
					#$conf["debug"]="false";
10600
					#參考資料:
10601
					#無.
10602
					#備註:
10603
					#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
10604
					#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
10605
					#php-pear上的Net_DNS2也可以解析RR.
10606
					$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
10607
					unset($conf["zerossl::updateDnsRecordFile"]);
10608
 
10609
					#如果執行異常
10610
					if($updateDnsRecordFile["status"]==="false"){
10611
 
10612
						#設置錯誤識別
10613
						$result["status"]="false";
10614
 
10615
						#設置錯誤訊息
10616
						$result["error"]=$updateDnsRecordFile;
10617
 
10618
						#回傳結果
10619
						return $result;
10620
 
10621
						}#if end
281 liveuser 10622
 
10623
					#if enable debug
10624
					if($debug){
10625
 
10626
						#debug msg
291 liveuser 10627
						echo "Restarting DNS service to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 10628
 
10629
						}#if end
10630
 
255 liveuser 10631
					#重新啟動dns伺服器
10632
					#函式說明:
10633
					#呼叫shell執行系統命令,並取得回傳的內容.
10634
					#回傳結果:
10635
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10636
					#$result["error"],錯誤訊息陣列.
10637
					#$result["function"],當前執行的函數名稱.
10638
					#$result["argu"],使用的參數.
10639
					#$result["cmd"],執行的指令內容.
10640
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10641
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10642
					#$result["content"],為執行完後的輸出字串.
10643
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10644
					#$result["running"],是否還在執行.
10645
					#$result["pid"],pid.
10646
					#$result["statusCode"],執行結束後的代碼.
10647
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10648
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10649
					#必填參數:
10650
					#$conf["command"],字串,要執行的指令.
291 liveuser 10651
					$conf["external::callShell"]["command"]="systemctl";
255 liveuser 10652
					#$conf["fileArgu"],字串,變數__FILE__的內容.
10653
					$conf["external::callShell"]["fileArgu"]=__FILE__;
10654
					#可省略參數:
10655
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
10656
					$conf["external::callShell"]["argu"]=array("restart","named");
10657
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10658
					#$conf["arguIsAddr"]=array();
10659
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10660
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10661
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10662
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10663
					#$conf["enablePrintDescription"]="true";
10664
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10665
					#$conf["printDescription"]="";
10666
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10667
					#$conf["escapeshellarg"]="false";
10668
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10669
					#$conf["thereIsShellVar"]=array();
10670
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10671
					#$conf["username"]="";
10672
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10673
					#$conf["password"]="";
10674
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10675
					#$conf["useScript"]="";
10676
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10677
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10678
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10679
					#$conf["inBackGround"]="";
10680
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10681
					#$conf["getErr"]="false";
10682
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10683
					#$conf["doNotRun"]="false";
10684
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10685
					$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
10686
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10687
					#$conf["remoteUser"]="root";
10688
					#參考資料:
10689
					#exec=>http://php.net/manual/en/function.exec.php
10690
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10691
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10692
					#備註:
10693
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10694
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10695
					$callShell=external::callShell($conf["external::callShell"]);
10696
					unset($conf["external::callShell"]);
10697
 
10698
					#如果執行異常
10699
					if($callShell["status"]==="false"){
10700
 
10701
						#設置錯誤識別
10702
						$result["status"]="false";
10703
 
10704
						#設置錯誤訊息
10705
						$result["error"]=$callShell;
10706
 
10707
						#回傳結果
10708
						return $result;
10709
 
10710
						}#if end
281 liveuser 10711
 
10712
					#if enable debug
10713
					if($debug){
10714
 
10715
						#debug msg
291 liveuser 10716
						echo "Request zerossl to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 10717
 
10718
						}#if end
10719
 
255 liveuser 10720
					#函式說明:
10721
					#請求驗證已經透過zerossl::createCertificate要求的domain.
10722
					#回傳結果:
10723
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10724
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10725
					#$result["function"],當前執行的函式名稱.
10726
					#$result["argu"],所使用的參數.
10727
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10728
					#$result["content"],結果json字串.
10729
					#必填參數:
10730
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
10731
					$conf["zerossl::verifyDomain"]["id"]=$csrId;
10732
					#可省略參數:
10733
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 10734
					$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 10735
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 10736
					$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 10737
					#參考資料:
10738
					#https://zerossl.com/documentation/api/verify-domains/
10739
					#備註:
10740
					#無.
10741
					$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
10742
					unset($conf["zerossl::verifyDomain"]);
10743
 
10744
					#如果執行異常
10745
					if($verifyDomain["status"]==="false"){
10746
 
10747
						#設置錯誤識別
10748
						$result["status"]="false";
10749
 
10750
						#設置錯誤訊息
10751
						$result["error"]=$verifyDomain;
10752
 
10753
						#回傳結果
10754
						return $result;
10755
 
10756
						}#if end
281 liveuser 10757
 
10758
					#if enable debug
10759
					if($debug){
10760
 
10761
						#debug msg
291 liveuser 10762
						echo "Downling ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 10763
 
10764
						}#if end
10765
 
255 liveuser 10766
					#函式說明:
10767
					#下載certificate.
10768
					#回傳結果:
10769
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10770
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10771
					#$result["function"],當前執行的函式名稱.
10772
					#$result["argu"],所使用的參數.
10773
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10774
					#$result["content"],結果json字串.
10775
					#$result["certificate.crt"],字串,certificate.crt的內容.
10776
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
10777
					#必填參數:
10778
					#無.
10779
					#可省略參數:
10780
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 10781
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 10782
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 10783
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 10784
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
10785
					$conf["zerossl::getCert"]["id"]=$csrId;
10786
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
10787
					#$conf["zerossl::getCert"]["cname"]="";
10788
					#參考資料:
10789
					#https://zerossl.com/documentation/api/download-certificate-inline/
10790
					#備註:
10791
					#無.
10792
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
10793
					unset($conf["zerossl::getCert"]);
10794
 
10795
					#如果執行異常
10796
					if($getCert["status"]==="false"){
10797
 
10798
						#設置錯誤識別
10799
						$result["status"]="false";
10800
 
10801
						#設置錯誤訊息
10802
						$result["error"]=$getCert;
10803
 
10804
						#回傳結果
10805
						return $result;
10806
 
10807
						}#if end
281 liveuser 10808
 
10809
					#if enable debug
10810
					if($debug){
10811
 
10812
						#debug msg
291 liveuser 10813
						echo "Creating ssl for domain name(".$cName.").".PHP_EOL;
281 liveuser 10814
 
10815
						}#if end
10816
 
255 liveuser 10817
					#建立 certificate.crt 檔案
10818
					#$cInfo["certPath"];
10819
 
10820
					#建立 ca_bundle.crt 檔案
10821
					#$cInfo["caPath"];
10822
 
10823
					#建立 certAndCa.crt 檔案
10824
					#$cInfo["certWithCaPath"];
10825
 
10826
					#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
10827
					#函式說明:
10828
					#一次建立多個檔案,並寫入內容.
10829
					#回傳結果:
10830
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10831
					#$result["error"],錯誤訊息陣列.
10832
					#$result["function"],當前執行的函數名稱.
10833
					#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10834
					#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10835
					#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10836
					#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10837
					#$result["argu"],使用的參數.
10838
					#必填參數:
10839
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10840
					$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10841
					#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10842
					$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 10843
					#可省略參數:
10844
					#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10845
					$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
10846
					#參考資料:
10847
					#無.
10848
					#備註:
10849
					#無.
10850
					$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
10851
					unset($conf["zerossl::writeMultiFile"]);
10852
 
10853
					#如果執行異常
10854
					if($writeMultiFile["status"]==="false"){
10855
 
10856
						#設置錯誤識別
10857
						$result["status"]="false";
10858
 
10859
						#設置錯誤訊息
10860
						$result["error"]=$writeMultiFile;
10861
 
10862
						#回傳結果
10863
						return $result;
10864
 
10865
						}#if end
10866
 
10867
					#儲存 actionAfterUpdateCert
10868
					$action=$cInfo["actionAfterUpdateCert"];
10869
 
10870
					#如果有多個指令要執行
10871
					if(gettype($action[0])==="array"){
10872
 
281 liveuser 10873
						#if enable debug
10874
						if($debug){
10875
 
10876
							#debug msg
291 liveuser 10877
							echo "There many cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 10878
 
10879
							}#if end
10880
 
255 liveuser 10881
						#針對每的指令
10882
						foreach($action as $ac){
10883
 
281 liveuser 10884
							#if enable debug
10885
							if($debug){
10886
 
10887
								#debug msg
10888
								echo ".".PHP_EOL;
10889
 
10890
								}#if end
10891
 
255 liveuser 10892
							#函式說明:
10893
							#解析指令與參數,回傳指令與參數給 callShell 函式使用.
10894
							#回傳結果:
10895
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10896
							#$result["error"],錯誤訊息陣列.
10897
							#$result["function"],當前執行的函數名稱.
10898
							#$result["argu"],使用的參數.
10899
							#$result["cmd"],執行的指令名稱.
10900
							#$result["params"],執行指令伴隨的參數.
10901
							#必填參數:
10902
							#$conf["cmdArray"],字串陣列,要執行的指令字串.
10903
							$conf["external::callShellHelper"]["cmdArray"]=$ac;
10904
							#可省略參數:
10905
							#無.
10906
							#參考資料:
10907
							#array_shift=>https://www.php.net/manual/en/function.array-shift.php
10908
							#備註:
10909
							#無.
10910
							$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
10911
							unset($conf["external::callShellHelper"]);
10912
 
10913
							#如果執行異常
10914
							if($callShellHelper["status"]==="false"){
10915
 
10916
								#設置錯誤識別
10917
								$result["status"]="false";
10918
 
10919
								#設置錯誤訊息
10920
								$result["error"]=$callShellHelper;
10921
 
10922
								#回傳結果
10923
								return $result;
10924
 
10925
								}#if end
10926
 
10927
							#函式說明:
10928
							#呼叫shell執行系統命令,並取得回傳的內容.
10929
							#回傳結果:
10930
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10931
							#$result["error"],錯誤訊息陣列.
10932
							#$result["function"],當前執行的函數名稱.
10933
							#$result["argu"],使用的參數.
10934
							#$result["cmd"],執行的指令內容.
10935
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10936
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10937
							#$result["content"],為執行完後的輸出字串.
10938
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10939
							#$result["running"],是否還在執行.
10940
							#$result["pid"],pid.
10941
							#$result["statusCode"],執行結束後的代碼.
10942
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10943
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10944
							#必填參數:
10945
							#$conf["command"],字串,要執行的指令.
10946
							$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
10947
							#$conf["fileArgu"],字串,變數__FILE__的內容.
10948
							$conf["external::callShell"]["fileArgu"]=__FILE__;
10949
							#可省略參數:
10950
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
10951
							$conf["external::callShell"]["argu"]=$callShellHelper["params"];
10952
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10953
							#$conf["arguIsAddr"]=array();
10954
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10955
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10956
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10957
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10958
							#$conf["enablePrintDescription"]="true";
10959
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10960
							#$conf["printDescription"]="";
10961
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10962
							$conf["external::callShell"]["escapeshellarg"]="true";
10963
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10964
							#$conf["thereIsShellVar"]=array();
10965
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10966
							#$conf["username"]="";
10967
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10968
							#$conf["password"]="";
10969
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10970
							#$conf["useScript"]="";
10971
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10972
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10973
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10974
							#$conf["inBackGround"]="";
10975
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10976
							#$conf["getErr"]="false";
10977
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10978
							#$conf["doNotRun"]="false";
10979
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10980
							#$conf["remoteIp"]="";
10981
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10982
							#$conf["remoteUser"]="";
10983
							#參考資料:
10984
							#exec=>http://php.net/manual/en/function.exec.php
10985
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10986
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10987
							#備註:
10988
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10989
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10990
							$callShell=external::callShell($conf["external::callShell"]);
10991
							unset($conf["external::callShell"]);
10992
 
10993
							#如果執行異常
10994
							if($callShellHelper["status"]==="false"){
10995
 
10996
								#設置錯誤識別
10997
								$result["status"]="false";
10998
 
10999
								#設置錯誤訊息
11000
								$result["error"]=$callShell;
11001
 
11002
								#回傳結果
11003
								return $result;
11004
 
11005
								}#if end
11006
 
11007
							}#foreach end
11008
 
11009
						}#if end
11010
 
11011
					#反之
11012
					else{
11013
 
281 liveuser 11014
						#if enable debug
11015
						if($debug){
11016
 
11017
							#debug msg
291 liveuser 11018
							echo "There is only one cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 11019
 
11020
							}#if end
11021
 
11022
						#if enable debug
11023
						if($debug){
11024
 
11025
							#debug msg
11026
							echo ".".PHP_EOL;
11027
 
11028
							}#if end
11029
 
255 liveuser 11030
						#函式說明:
11031
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
11032
						#回傳結果:
11033
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11034
						#$result["error"],錯誤訊息陣列.
11035
						#$result["function"],當前執行的函數名稱.
11036
						#$result["argu"],使用的參數.
11037
						#$result["cmd"],執行的指令名稱.
11038
						#$result["params"],執行指令伴隨的參數.
11039
						#必填參數:
11040
						#$conf["cmdArray"],字串陣列,要執行的指令字串.
11041
						$conf["external::callShellHelper"]["cmdArray"]=$action;
11042
						#可省略參數:
11043
						#無.
11044
						#參考資料:
11045
						#array_shift=>https://www.php.net/manual/en/function.array-shift.php
11046
						#備註:
11047
						#無.
11048
						$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
11049
						unset($conf["external::callShellHelper"]);
11050
 
11051
						#如果執行異常
11052
						if($callShellHelper["status"]==="false"){
11053
 
11054
							#設置錯誤識別
11055
							$result["status"]="false";
11056
 
11057
							#設置錯誤訊息
11058
							$result["error"]=$callShellHelper;
11059
 
11060
							#回傳結果
11061
							return $result;
11062
 
11063
							}#if end
11064
 
11065
						#函式說明:
11066
						#呼叫shell執行系統命令,並取得回傳的內容.
11067
						#回傳結果:
11068
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11069
						#$result["error"],錯誤訊息陣列.
11070
						#$result["function"],當前執行的函數名稱.
11071
						#$result["argu"],使用的參數.
11072
						#$result["cmd"],執行的指令內容.
11073
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11074
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11075
						#$result["content"],為執行完後的輸出字串.
11076
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11077
						#$result["running"],是否還在執行.
11078
						#$result["pid"],pid.
11079
						#$result["statusCode"],執行結束後的代碼.
11080
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11081
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11082
						#必填參數:
11083
						#$conf["command"],字串,要執行的指令.
11084
						$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
11085
						#$conf["fileArgu"],字串,變數__FILE__的內容.
11086
						$conf["external::callShell"]["fileArgu"]=__FILE__;
11087
						#可省略參數:
11088
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11089
						$conf["external::callShell"]["argu"]=$callShellHelper["params"];
11090
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11091
						#$conf["arguIsAddr"]=array();
11092
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11093
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11094
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11095
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11096
						#$conf["enablePrintDescription"]="true";
11097
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11098
						#$conf["printDescription"]="";
11099
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11100
						$conf["external::callShell"]["escapeshellarg"]="true";
11101
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11102
						#$conf["thereIsShellVar"]=array();
11103
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11104
						#$conf["username"]="";
11105
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11106
						#$conf["password"]="";
11107
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11108
						#$conf["useScript"]="";
11109
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11110
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11111
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11112
						#$conf["inBackGround"]="";
11113
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11114
						#$conf["getErr"]="false";
11115
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11116
						#$conf["doNotRun"]="false";
11117
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
11118
						#$conf["remoteIp"]="";
11119
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
11120
						#$conf["remoteUser"]="";
11121
						#參考資料:
11122
						#exec=>http://php.net/manual/en/function.exec.php
11123
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11124
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11125
						#備註:
11126
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11127
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11128
						$callShell=external::callShell($conf["external::callShell"]);
11129
						unset($conf["external::callShell"]);
11130
 
11131
						#如果執行異常
11132
						if($callShellHelper["status"]==="false"){
11133
 
11134
							#設置錯誤識別
11135
							$result["status"]="false";
11136
 
11137
							#設置錯誤訊息
11138
							$result["error"]=$callShell;
11139
 
11140
							#回傳結果
11141
							return $result;
11142
 
11143
							}#if end
11144
 
11145
						}#else end
11146
 
11147
					#要移除舊的憑證 
11148
 
281 liveuser 11149
					#if enable debug
11150
					if($debug){
11151
 
11152
						#debug msg
11153
						echo "Removing old ssl file".PHP_EOL;
11154
 
11155
						}#if end
11156
 
255 liveuser 11157
					#舊憑證於zerossl上的id
11158
					#$oldCsrId
11159
 
11160
					#移除舊的憑證
11161
					#函式說明:
11162
					#請求廢除 issued zerossl certificate.
11163
					#回傳結果:
11164
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11165
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11166
					#$result["function"],當前執行的函式名稱.
11167
					#$result["argu"],所使用的參數.
11168
					#$result["curl_verbose_info"],curl執行的詳細資訊.
11169
					#$result["content"],結果json字串.
11170
					#必填參數:
11171
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
11172
					$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
11173
					#可省略參數:
11174
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 11175
					$conf["zerosssl::revokeCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 11176
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 11177
					$conf["zerosssl::revokeCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 11178
					#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
11179
					$conf["zerosssl::revokeCert"]["reason"]="Superseded";
11180
					#參考資料:
11181
					#https://zerossl.com/documentation/api/revoke-certificate/
11182
					#備註:
11183
					#無.
11184
					$revokeCert=zerosssl::revokeCert($conf["zerosssl::revokeCert"]);
11185
					unset($conf["zerosssl::revokeCert"]);
11186
 
11187
					#如果執行異常
11188
					if($revokeCert["status"]==="false"){
11189
 
11190
						#設置錯誤識別
11191
						$result["status"]="false";
11192
 
11193
						#設置錯誤訊息
11194
						$result["error"]=$revokeCert;
11195
 
11196
						#回傳結果
11197
						return $result;
11198
 
291 liveuser 11199
						}#if end
11200
 
255 liveuser 11201
					}#if end
11202
 
11203
				#反之,尚不需要提前申請新的憑證
11204
				else{
11205
 
291 liveuser 11206
					#debug
11207
					#var_dump(__LINE__,"尚不需要提前申請新的憑證");exit;
11208
 
281 liveuser 11209
					#if enable debug
11210
					if($debug){
11211
 
11212
						#debug msg
291 liveuser 11213
						echo "ssl for domain name(".$cName.") is valid ".PHP_EOL;
281 liveuser 11214
 
11215
						}#if end
11216
 
11217
					#if enable debug
11218
					if($debug){
11219
 
11220
						#debug msg
291 liveuser 11221
						echo "Downling ssl for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 11222
 
11223
						}#if end
11224
 
255 liveuser 11225
					#下載憑證
11226
					#函式說明:
11227
					#下載certificate.
11228
					#回傳結果:
11229
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11230
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11231
					#$result["function"],當前執行的函式名稱.
11232
					#$result["argu"],所使用的參數.
11233
					#$result["curl_verbose_info"],curl執行的詳細資訊.
11234
					#$result["content"],結果json字串.
11235
					#$result["certificate.crt"],字串,certificate.crt的內容.
11236
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
11237
					#必填參數:
11238
					#無.
11239
					#可省略參數:
11240
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 11241
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 11242
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 11243
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 11244
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
11245
					$conf["zerossl::getCert"]["id"]=$csrId;
11246
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
11247
					#$conf["zerossl::getCert"]["cname"]="";
11248
					#參考資料:
11249
					#https://zerossl.com/documentation/api/download-certificate-inline/
11250
					#備註:
11251
					#無.
11252
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
11253
					unset($conf["zerossl::getCert"]);
11254
 
11255
					#如果執行異常
11256
					if($getCert["status"]==="false"){
11257
 
11258
						#設置錯誤識別
11259
						$result["status"]="false";
11260
 
11261
						#設置錯誤訊息
11262
						$result["error"]=$getCert;
11263
 
11264
						#回傳結果
11265
						return $result;
11266
 
11267
						}#if end
281 liveuser 11268
 
11269
					#if enable debug
11270
					if($debug){
11271
 
11272
						#debug msg
291 liveuser 11273
						echo "Getting host ssl for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11274
 
11275
						}#if end
11276
 
255 liveuser 11277
					#zerossl上的certificate.crt內容
11278
					#$getCert["certificate.crt"];
11279
 
11280
					#zerossl上的ca_bundle.crt內容
11281
					#$getCert["ca_bundle.crt"];
11282
 
11283
					#certificate.crt and ca_bundle.crt 合併後的檔案內容
11284
					#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
11285
 
11286
					#certificate.crt 檔案
11287
					#$cInfo["certPath"];
11288
 
11289
					#ca_bundle.crt 檔案
11290
					#$cInfo["caPath"];
11291
 
11292
					#certAndCa.crt 檔案
11293
					#$cInfo["certWithCaPath"];
281 liveuser 11294
 
11295
					#if enable debug
11296
					if($debug){
11297
 
11298
						#debug msg
291 liveuser 11299
						echo "Getting host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11300
 
11301
						}#if end
255 liveuser 11302
 
11303
					#取得既有的 certificate.crt 檔案內容
11304
					#函式說明:
11305
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
11306
					#回傳的變數說明:
11307
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
11308
					#$result["error"],錯誤訊息提示.
11309
					#$result["warning"],警告訊息.
11310
					#$result["function"],當前執行的函數名稱.
11311
					#$result["fileContent"],爲檔案的內容陣列.
11312
					#$result["lineCount"],爲檔案內容總共的行數.
11313
					#$result["fullContent"],為檔案的完整內容.
11314
					#$result["base64dataOnly"],檔案的base64data.
11315
					#$result["base64data"],為在網頁上給予src參數的數值.
11316
					#$result["mimeType"],為檔案的mime type.
11317
					#必填參數:
11318
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 11319
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certPath"];
255 liveuser 11320
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11321
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
11322
					#可省略參數:
11323
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
11324
					#$conf["web"]="true";
11325
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 11326
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 11327
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
11328
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
11329
					#參考資料:
11330
					#file(),取得檔案內容的行數.
11331
					#file=>http:#php.net/manual/en/function.file.php
11332
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
11333
					#filesize=>http://php.net/manual/en/function.filesize.php
11334
					#參考資料:
11335
					#無.
11336
					#備註:
11337
					#無.
291 liveuser 11338
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 11339
					unset($conf["fileAccesss::getFileContent"]);
11340
 
11341
					#如果執行異常
11342
					if($getFileContent["status"]==="false"){
11343
 
11344
						#設置錯誤識別
11345
						$result["status"]="false";
11346
 
11347
						#設置錯誤訊息
11348
						$result["error"]=$getFileContent;
11349
 
11350
						#回傳結果
11351
						return $result;
11352
 
11353
						}#if end
11354
 
281 liveuser 11355
					#if enable debug
11356
					if($debug){
11357
 
11358
						#debug msg
291 liveuser 11359
						echo "Checking host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11360
 
11361
						}#if end
11362
 
291 liveuser 11363
					#預設 certificate.crt 不用更新
11364
					$certificate_need_update="false";
11365
 
255 liveuser 11366
					#如果既有憑證跟剛下載的憑證不一樣
11367
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
11368
 
11369
						#識別要改成下載好的憑證
11370
						$certificate_need_update="true";
281 liveuser 11371
 
11372
						#if enable debug
11373
						if($debug){
11374
 
11375
							#debug msg
291 liveuser 11376
							echo "SSL(certificate.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 11377
 
11378
							}#if end
255 liveuser 11379
 
11380
						}#if end
281 liveuser 11381
 
11382
					#if enable debug
11383
					if($debug){
11384
 
11385
						#debug msg
291 liveuser 11386
						echo "Getting host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11387
 
11388
						}#if end
11389
 
255 liveuser 11390
					#取得既有的 ca_bundle.crt 檔案內容
11391
					#函式說明:
11392
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
11393
					#回傳的變數說明:
11394
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
11395
					#$result["error"],錯誤訊息提示.
11396
					#$result["warning"],警告訊息.
11397
					#$result["function"],當前執行的函數名稱.
11398
					#$result["fileContent"],爲檔案的內容陣列.
11399
					#$result["lineCount"],爲檔案內容總共的行數.
11400
					#$result["fullContent"],為檔案的完整內容.
11401
					#$result["base64dataOnly"],檔案的base64data.
11402
					#$result["base64data"],為在網頁上給予src參數的數值.
11403
					#$result["mimeType"],為檔案的mime type.
11404
					#必填參數:
11405
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 11406
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["caPath"];
255 liveuser 11407
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11408
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
11409
					#可省略參數:
11410
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
11411
					#$conf["web"]="true";
11412
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 11413
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 11414
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
11415
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
11416
					#參考資料:
11417
					#file(),取得檔案內容的行數.
11418
					#file=>http:#php.net/manual/en/function.file.php
11419
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
11420
					#filesize=>http://php.net/manual/en/function.filesize.php
11421
					#參考資料:
11422
					#無.
11423
					#備註:
11424
					#無.
291 liveuser 11425
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 11426
					unset($conf["fileAccesss::getFileContent"]);
11427
 
11428
					#如果執行異常
11429
					if($getFileContent["status"]==="false"){
11430
 
11431
						#設置錯誤識別
11432
						$result["status"]="false";
11433
 
11434
						#設置錯誤訊息
11435
						$result["error"]=$getFileContent;
11436
 
11437
						#回傳結果
11438
						return $result;
11439
 
11440
						}#if end
11441
 
281 liveuser 11442
					#if enable debug
11443
					if($debug){
11444
 
11445
						#debug msg
291 liveuser 11446
						echo "Checking host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11447
 
11448
						}#if end
11449
 
291 liveuser 11450
					#預設 ca_bundle.crt 不用更新
11451
					$ca_bundle_need_update="false";
11452
 
255 liveuser 11453
					#如果既有憑證跟剛下載的憑證不一樣
11454
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
11455
 
11456
						#識別要改成下載好的憑證
11457
						$ca_bundle_need_update="true";
281 liveuser 11458
 
11459
						#if enable debug
11460
						if($debug){
11461
 
11462
							#debug msg
291 liveuser 11463
							echo "SSL(ca_bundle.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 11464
 
11465
							}#if end
255 liveuser 11466
 
11467
						}#if end
11468
 
281 liveuser 11469
					#if enable debug
11470
					if($debug){
11471
 
11472
						#debug msg
291 liveuser 11473
						echo "Getting host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11474
 
11475
						}#if end
11476
 
255 liveuser 11477
					#取得既有的 certWithCa 檔案內容
11478
					#函式說明:
11479
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
11480
					#回傳的變數說明:
11481
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
11482
					#$result["error"],錯誤訊息提示.
11483
					#$result["warning"],警告訊息.
11484
					#$result["function"],當前執行的函數名稱.
11485
					#$result["fileContent"],爲檔案的內容陣列.
11486
					#$result["lineCount"],爲檔案內容總共的行數.
11487
					#$result["fullContent"],為檔案的完整內容.
11488
					#$result["base64dataOnly"],檔案的base64data.
11489
					#$result["base64data"],為在網頁上給予src參數的數值.
11490
					#$result["mimeType"],為檔案的mime type.
11491
					#必填參數:
11492
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 11493
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certWithCaPath"];
255 liveuser 11494
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11495
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
11496
					#可省略參數:
11497
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
11498
					#$conf["web"]="true";
11499
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 11500
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 11501
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
11502
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
11503
					#參考資料:
11504
					#file(),取得檔案內容的行數.
11505
					#file=>http:#php.net/manual/en/function.file.php
11506
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
11507
					#filesize=>http://php.net/manual/en/function.filesize.php
11508
					#參考資料:
11509
					#無.
11510
					#備註:
11511
					#無.
291 liveuser 11512
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 11513
					unset($conf["fileAccesss::getFileContent"]);
11514
 
11515
					#如果執行異常
11516
					if($getFileContent["status"]==="false"){
11517
 
11518
						#設置錯誤識別
11519
						$result["status"]="false";
11520
 
11521
						#設置錯誤訊息
11522
						$result["error"]=$getFileContent;
11523
 
11524
						#回傳結果
11525
						return $result;
11526
 
11527
						}#if end
11528
 
281 liveuser 11529
					#if enable debug
11530
					if($debug){
11531
 
11532
						#debug msg
291 liveuser 11533
						echo "Checking host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11534
 
11535
						}#if end
11536
 
291 liveuser 11537
					#預設 cert_and_ca_bundle.crt 不用更新
11538
					$cert_and_ca_bundle_need_update="false";
11539
 
255 liveuser 11540
					#如果既有憑證跟剛下載的憑證不一樣
11541
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
11542
 
11543
						#識別要改成下載好的憑證
11544
						$cert_and_ca_bundle_need_update="true";
281 liveuser 11545
 
11546
						#if enable debug
11547
						if($debug){
11548
 
11549
							#debug msg
291 liveuser 11550
							echo "SSL(cert and ca_bundle) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 11551
 
11552
							}#if end
255 liveuser 11553
 
11554
						}#if end
11555
 
11556
					#預設不需要執行更新憑證後的動作
11557
					$requireActionAfterUpdateCert="false";
11558
 
11559
					#如果 certificate 需要更新
11560
					if($certificate_need_update==="true"){
11561
 
281 liveuser 11562
						#if enable debug
11563
						if($debug){
11564
 
11565
							#debug msg
291 liveuser 11566
							echo "Updating host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11567
 
11568
							}#if end
11569
 
255 liveuser 11570
						#更新之
11571
						#函式說明:
11572
						#一次建立多個檔案,並寫入內容.
11573
						#回傳結果:
11574
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
11575
						#$result["error"],錯誤訊息陣列.
11576
						#$result["function"],當前執行的函數名稱.
11577
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
11578
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
11579
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
11580
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
11581
						#$result["argu"],使用的參數.
11582
						#必填參數:
11583
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11584
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
11585
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 11586
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"]);
255 liveuser 11587
						#可省略參數:
11588
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
11589
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
11590
						#參考資料:
11591
						#無.
11592
						#備註:
11593
						#無.
291 liveuser 11594
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 11595
						unset($conf["zerossl::writeMultiFile"]);
11596
 
11597
						#如果執行異常
11598
						if($writeMultiFile["status"]==="false"){
11599
 
11600
							#設置錯誤識別
11601
							$result["status"]="false";
11602
 
11603
							#設置錯誤訊息
11604
							$result["error"]=$writeMultiFile;
11605
 
11606
							#回傳結果
11607
							return $result;
11608
 
11609
							}#if end
11610
 
11611
						}#if end
11612
 
11613
					#如果 ca_bunle 需要更新
11614
					if($ca_bundle_need_update==="true"){
11615
 
281 liveuser 11616
						#if enable debug
11617
						if($debug){
11618
 
11619
							#debug msg
291 liveuser 11620
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11621
 
11622
							}#if end
11623
 
255 liveuser 11624
						#更新之
11625
						#函式說明:
11626
						#一次建立多個檔案,並寫入內容.
11627
						#回傳結果:
11628
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
11629
						#$result["error"],錯誤訊息陣列.
11630
						#$result["function"],當前執行的函數名稱.
11631
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
11632
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
11633
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
11634
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
11635
						#$result["argu"],使用的參數.
11636
						#必填參數:
11637
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11638
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
11639
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 11640
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["caPath"]);
255 liveuser 11641
						#可省略參數:
11642
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
11643
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
11644
						#參考資料:
11645
						#無.
11646
						#備註:
11647
						#無.
291 liveuser 11648
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 11649
						unset($conf["zerossl::writeMultiFile"]);
11650
 
11651
						#如果執行異常
11652
						if($writeMultiFile["status"]==="false"){
11653
 
11654
							#設置錯誤識別
11655
							$result["status"]="false";
11656
 
11657
							#設置錯誤訊息
11658
							$result["error"]=$writeMultiFile;
11659
 
11660
							#回傳結果
11661
							return $result;
11662
 
11663
							}#if end
11664
 
11665
						}#if end
11666
 
11667
					#如果 certificate and ca_bundle 需要更新
11668
					if($cert_and_ca_bundle_need_update==="true"){
11669
 
281 liveuser 11670
						#if enable debug
11671
						if($debug){
11672
 
11673
							#debug msg
291 liveuser 11674
							echo "Updating host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11675
 
11676
							}#if end
11677
 
255 liveuser 11678
						#更新之
11679
						#函式說明:
11680
						#一次建立多個檔案,並寫入內容.
11681
						#回傳結果:
11682
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
11683
						#$result["error"],錯誤訊息陣列.
11684
						#$result["function"],當前執行的函數名稱.
11685
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
11686
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
11687
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
11688
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
11689
						#$result["argu"],使用的參數.
11690
						#必填參數:
11691
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11692
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
11693
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 11694
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certWithCaPath"]);
255 liveuser 11695
						#可省略參數:
11696
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
11697
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
11698
						#參考資料:
11699
						#無.
11700
						#備註:
11701
						#無.
291 liveuser 11702
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 11703
						unset($conf["zerossl::writeMultiFile"]);
11704
 
11705
						#如果執行異常
11706
						if($writeMultiFile["status"]==="false"){
11707
 
11708
							#設置錯誤識別
11709
							$result["status"]="false";
11710
 
11711
							#設置錯誤訊息
11712
							$result["error"]=$writeMultiFile;
11713
 
11714
							#回傳結果
11715
							return $result;
11716
 
11717
							}#if end
11718
 
11719
						}#if end
11720
 
11721
					#如果有需要執行指令來生效憑證
11722
					if($requireActionAfterUpdateCert==="true"){
11723
 
281 liveuser 11724
						#if enable debug
11725
						if($debug){
11726
 
11727
							#debug msg
291 liveuser 11728
							echo "Action required to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 11729
 
11730
							}#if end
11731
 
255 liveuser 11732
						#儲存 actionAfterUpdateCert
11733
						$action=$cInfo["actionAfterUpdateCert"];
11734
 
11735
						#如果有多個指令要執行
11736
						if(gettype($action[0])==="array"){
11737
 
281 liveuser 11738
							#if enable debug
11739
							if($debug){
11740
 
11741
								#debug msg
291 liveuser 11742
								echo "There are many cmds to run to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 11743
 
11744
								}#if end
11745
 
255 liveuser 11746
							#針對每的指令
11747
							foreach($action as $ac){
11748
 
281 liveuser 11749
								#if enable debug
11750
								if($debug){
11751
 
11752
									#debug msg
11753
									echo ".".PHP_EOL;
11754
 
11755
									}#if end
11756
 
255 liveuser 11757
								#函式說明:
11758
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
11759
								#回傳結果:
11760
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11761
								#$result["error"],錯誤訊息陣列.
11762
								#$result["function"],當前執行的函數名稱.
11763
								#$result["argu"],使用的參數.
11764
								#$result["cmd"],執行的指令名稱.
11765
								#$result["params"],執行指令伴隨的參數.
11766
								#必填參數:
11767
								#$conf["cmdArray"],字串陣列,要執行的指令字串.
11768
								$conf["external::callShellHelper"]["cmdArray"]=$ac;
11769
								#可省略參數:
11770
								#無.
11771
								#參考資料:
11772
								#array_shift=>https://www.php.net/manual/en/function.array-shift.php
11773
								#備註:
11774
								#無.
11775
								$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
11776
								unset($conf["external::callShellHelper"]);
11777
 
11778
								#如果執行異常
11779
								if($callShellHelper["status"]==="false"){
11780
 
11781
									#設置錯誤識別
11782
									$result["status"]="false";
11783
 
11784
									#設置錯誤訊息
11785
									$result["error"]=$callShellHelper;
11786
 
11787
									#回傳結果
11788
									return $result;
11789
 
11790
									}#if end
11791
 
11792
								#函式說明:
11793
								#呼叫shell執行系統命令,並取得回傳的內容.
11794
								#回傳結果:
11795
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11796
								#$result["error"],錯誤訊息陣列.
11797
								#$result["function"],當前執行的函數名稱.
11798
								#$result["argu"],使用的參數.
11799
								#$result["cmd"],執行的指令內容.
11800
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11801
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11802
								#$result["content"],為執行完後的輸出字串.
11803
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11804
								#$result["running"],是否還在執行.
11805
								#$result["pid"],pid.
11806
								#$result["statusCode"],執行結束後的代碼.
11807
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11808
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11809
								#必填參數:
11810
								#$conf["command"],字串,要執行的指令.
11811
								$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
11812
								#$conf["fileArgu"],字串,變數__FILE__的內容.
11813
								$conf["external::callShell"]["fileArgu"]=__FILE__;
11814
								#可省略參數:
11815
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11816
								$conf["external::callShell"]["argu"]=$callShellHelper["params"];
11817
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11818
								#$conf["arguIsAddr"]=array();
11819
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11820
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11821
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11822
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11823
								#$conf["enablePrintDescription"]="true";
11824
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11825
								#$conf["printDescription"]="";
11826
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11827
								$conf["external::callShell"]["escapeshellarg"]="true";
11828
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11829
								#$conf["thereIsShellVar"]=array();
11830
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11831
								#$conf["username"]="";
11832
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11833
								#$conf["password"]="";
11834
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11835
								#$conf["useScript"]="";
11836
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11837
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11838
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11839
								#$conf["inBackGround"]="";
11840
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11841
								#$conf["getErr"]="false";
11842
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11843
								#$conf["doNotRun"]="false";
11844
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
11845
								#$conf["remoteIp"]="";
11846
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
11847
								#$conf["remoteUser"]="";
11848
								#參考資料:
11849
								#exec=>http://php.net/manual/en/function.exec.php
11850
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11851
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11852
								#備註:
11853
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11854
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11855
								$callShell=external::callShell($conf["external::callShell"]);
11856
								unset($conf["external::callShell"]);
11857
 
11858
								#如果執行異常
11859
								if($callShellHelper["status"]==="false"){
11860
 
11861
									#設置錯誤識別
11862
									$result["status"]="false";
11863
 
11864
									#設置錯誤訊息
11865
									$result["error"]=$callShell;
11866
 
11867
									#回傳結果
11868
									return $result;
11869
 
11870
									}#if end
11871
 
11872
								}#foreach end
11873
 
11874
							}#if end
11875
 
291 liveuser 11876
						#反之
11877
						else{
11878
 
11879
							#if enable debug
11880
							if($debug){
11881
 
11882
								#debug msg
11883
								echo "There is only one cmd to run to apply ssl for domain name(".$cName.")".PHP_EOL;
255 liveuser 11884
 
291 liveuser 11885
								}#if end
281 liveuser 11886
 
291 liveuser 11887
							#函式說明:
11888
							#解析指令與參數,回傳指令與參數給 callShell 函式使用.
11889
							#回傳結果:
11890
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11891
							#$result["error"],錯誤訊息陣列.
11892
							#$result["function"],當前執行的函數名稱.
11893
							#$result["argu"],使用的參數.
11894
							#$result["cmd"],執行的指令名稱.
11895
							#$result["params"],執行指令伴隨的參數.
11896
							#必填參數:
11897
							#$conf["cmdArray"],字串陣列,要執行的指令字串.
11898
							$conf["external::callShellHelper"]["cmdArray"]=$action;
11899
							#可省略參數:
11900
							#無.
11901
							#參考資料:
11902
							#array_shift=>https://www.php.net/manual/en/function.array-shift.php
11903
							#備註:
11904
							#無.
11905
							$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
11906
							unset($conf["external::callShellHelper"]);
11907
 
11908
							#如果執行異常
11909
							if($callShellHelper["status"]==="false"){
281 liveuser 11910
 
291 liveuser 11911
								#設置錯誤識別
11912
								$result["status"]="false";
255 liveuser 11913
 
291 liveuser 11914
								#設置錯誤訊息
11915
								$result["error"]=$callShellHelper;
255 liveuser 11916
 
291 liveuser 11917
								#回傳結果
11918
								return $result;
11919
 
11920
								}#if end
255 liveuser 11921
 
291 liveuser 11922
							#函式說明:
11923
							#呼叫shell執行系統命令,並取得回傳的內容.
11924
							#回傳結果:
11925
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11926
							#$result["error"],錯誤訊息陣列.
11927
							#$result["function"],當前執行的函數名稱.
11928
							#$result["argu"],使用的參數.
11929
							#$result["cmd"],執行的指令內容.
11930
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11931
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11932
							#$result["content"],為執行完後的輸出字串.
11933
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11934
							#$result["running"],是否還在執行.
11935
							#$result["pid"],pid.
11936
							#$result["statusCode"],執行結束後的代碼.
11937
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11938
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11939
							#必填參數:
11940
							#$conf["command"],字串,要執行的指令.
11941
							$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
11942
							#$conf["fileArgu"],字串,變數__FILE__的內容.
11943
							$conf["external::callShell"]["fileArgu"]=__FILE__;
11944
							#可省略參數:
11945
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11946
							$conf["external::callShell"]["argu"]=$callShellHelper["params"];
11947
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11948
							#$conf["arguIsAddr"]=array();
11949
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11950
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11951
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11952
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11953
							#$conf["enablePrintDescription"]="true";
11954
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11955
							#$conf["printDescription"]="";
11956
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11957
							$conf["external::callShell"]["escapeshellarg"]="true";
11958
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11959
							#$conf["thereIsShellVar"]=array();
11960
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11961
							#$conf["username"]="";
11962
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11963
							#$conf["password"]="";
11964
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11965
							#$conf["useScript"]="";
11966
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11967
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11968
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11969
							#$conf["inBackGround"]="";
11970
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11971
							#$conf["getErr"]="false";
11972
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11973
							#$conf["doNotRun"]="false";
11974
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
11975
							#$conf["remoteIp"]="";
11976
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
11977
							#$conf["remoteUser"]="";
11978
							#參考資料:
11979
							#exec=>http://php.net/manual/en/function.exec.php
11980
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11981
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11982
							#備註:
11983
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11984
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11985
							$callShell=external::callShell($conf["external::callShell"]);
11986
							unset($conf["external::callShell"]);
11987
 
11988
							#如果執行異常
11989
							if($callShellHelper["status"]==="false"){
255 liveuser 11990
 
291 liveuser 11991
								#設置錯誤識別
11992
								$result["status"]="false";
255 liveuser 11993
 
291 liveuser 11994
								#設置錯誤訊息
11995
								$result["error"]=$callShell;
255 liveuser 11996
 
291 liveuser 11997
								#回傳結果
11998
								return $result;
255 liveuser 11999
 
291 liveuser 12000
								}#if end
12001
 
12002
							}#else end
12003
 
12004
						}#if end
255 liveuser 12005
 
12006
					}#else end
12007
 
12008
				}#else end
291 liveuser 12009
 
255 liveuser 12010
			}#foreach end
12011
 
12012
		}#function sslUpdater_idle end
12013
 
226 liveuser 12014
	}#class zerossl end
255 liveuser 12015