Subversion Repositories php-qbpwcf

Rev

Rev 249 | Rev 255 | 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執行的詳細資訊.
153
	#必填參數:
154
	#$conf["fileArgu"],字串,變數__FILE__的內容.
155
	$conf["fileArgu"]=__FILE__;
156
	#可省略參數:
157
	#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
158
	#$conf["length"]=4096';
159
	#參考資料:
160
	#無.
161
	#備註:
162
	#key generated by openssl with RSA.
163
	*/
164
	public static function createPrivateKey(&$conf){
226 liveuser 165
 
3 liveuser 166
		#初始化要回傳的結果
167
		$result=array();
226 liveuser 168
 
3 liveuser 169
		#取得當前執行的函數名稱
170
		$result["function"]=__FUNCTION__;
226 liveuser 171
 
3 liveuser 172
		#如果 $conf 不為陣列
173
		if(gettype($conf)!="array"){
226 liveuser 174
 
3 liveuser 175
			#設置執行失敗
176
			$result["status"]="false";
226 liveuser 177
 
3 liveuser 178
			#設置執行錯誤訊息
179
			$result["error"][]="\$conf變數須為陣列形態";
180
 
181
			#如果傳入的參數為 null
182
			if($conf==null){
226 liveuser 183
 
3 liveuser 184
				#設置執行錯誤訊息
185
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 186
 
3 liveuser 187
				}#if end
188
 
189
			#回傳結果
190
			return $result;
226 liveuser 191
 
3 liveuser 192
			}#if end
226 liveuser 193
 
3 liveuser 194
		#取得參數
195
		$result["argu"]=$conf;
226 liveuser 196
 
3 liveuser 197
		#函式說明:
198
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
199
		#回傳結果:
200
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
201
		#$result["error"],執行不正常結束的錯訊息陣列.
202
		#$result["simpleError"],簡單表示的錯誤訊息.
203
		#$result["function"],當前執行的函式名稱.
204
		#$result["argu"],設置給予的參數.
205
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
206
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
207
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
208
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
209
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
210
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
211
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
212
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
213
		#必填參數:
214
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
215
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
216
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
217
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
218
		#可省略參數:
219
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
220
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
221
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
222
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
223
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
224
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
225
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
226
		#$conf["canNotBeEmpty"]=array();
227
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
228
		#$conf["canBeEmpty"]=array();
229
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
230
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("length");
231
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
232
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
233
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
234
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer");
235
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
236
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(4096);
237
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
238
		#$conf["disallowAllSkipableVarIsEmpty"]="";
239
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
240
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
241
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
242
		#$conf["disallowAllSkipableVarNotExist"]="";
243
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
244
		#$conf["arrayCountEqualCheck"][]=array();
245
		#參考資料:
246
		#array_keys=>http://php.net/manual/en/function.array-keys.php
247
		#備註:
248
		#無.
249
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
250
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 251
 
3 liveuser 252
		#如果 $checkArguments["status"]等於 "false"
253
		if($checkArguments["status"]==="false"){
254
 
255
			#設置執行錯誤的識別
256
			$result["status"]="false";
257
 
258
			#設置錯誤訊息
259
			$result["error"]=$checkArguments;
260
 
261
			#回傳結果
262
			return $result;
263
 
264
			}#if end
265
 
266
		#如果 $checkArguments["passed"]等於 "false"
267
		if($checkArguments["passed"]==="false"){
268
 
269
			#設置執行錯誤的識別
270
			$result["status"]="false";
271
 
272
			#設置錯誤訊息
273
			$result["error"]=$checkArguments;
274
 
275
			#回傳結果
276
			return $result;
277
 
278
			}#if end
226 liveuser 279
 
3 liveuser 280
		#函式說明:
281
		#呼叫shell執行系統命令,並取得回傳的內容.
282
		#回傳結果:
283
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
284
		#$result["error"],錯誤訊息陣列.
285
		#$result["function"],當前執行的函數名稱.
286
		#$result["argu"],使用的參數.
287
		#$result["cmd"],執行的指令內容.
288
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
289
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
290
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
291
		#$result["running"],是否還在執行.
292
		#$result["pid"],pid.
293
		#$result["statusCode"],執行結束後的代碼.
294
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
295
		#必填參數:
296
		#$conf["command"],字串,要執行的指令.
297
		$conf["external::callShell"]["command"]="openssl";
298
		#$conf["fileArgu"],字串,變數__FILE__的內容.
299
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
300
		#可省略參數:
301
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302
		$conf["external::callShell"]["argu"]=array("genrsa",$conf["length"]);
303
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
304
		#$conf["arguIsAddr"]=array();
305
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
306
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
307
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
308
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
309
		#$conf["enablePrintDescription"]="true";
310
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
311
		#$conf["printDescription"]="";
312
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
313
		$conf["external::callShell"]["escapeshellarg"]="true";
314
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
315
		#$conf["thereIsShellVar"]=array();
316
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
317
		#$conf["username"]="";
318
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
319
		#$conf["password"]="";
320
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
321
		#$conf["useScript"]="";
322
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
323
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
324
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
325
		#$conf["inBackGround"]="";
326
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
327
		#$conf["getErr"]="false";
328
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
329
		#$conf["doNotRun"]="false";
330
		#參考資料:
331
		#exec=>http://php.net/manual/en/function.exec.php
332
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
333
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
334
		#備註:
335
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
336
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
337
		$callShell=external::callShell($conf["external::callShell"]);
338
		unset($conf["external::callShell"]);
226 liveuser 339
 
3 liveuser 340
		#如果異常
341
		if($callShell["status"]==="false"){
226 liveuser 342
 
3 liveuser 343
			#設置錯誤識別
344
			$result["status"]="false";
226 liveuser 345
 
3 liveuser 346
			#設置錯誤訊息
347
			$result["error"]=$callShell;
226 liveuser 348
 
3 liveuser 349
			#回傳結果
350
			return $result;
226 liveuser 351
 
3 liveuser 352
			}#if end
226 liveuser 353
 
3 liveuser 354
		#函式說明:
355
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
356
		#回傳的結果:
357
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
358
		#$result["function"],當前執行的function名稱
359
		#$result["error"],錯誤訊息陣列.
360
		#$result["content"],處理好的字串.
361
		#$result["argu"],使用的參數.
362
		#必填參數:
363
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
364
		$conf["arrays::arrayToString"]["inputArray"]=$callShell["output"];
365
		#可省略參數:
366
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
367
		$conf["arrays::arrayToString"]["spiltSymbol"]="";
368
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
369
		$conf["arrays::arrayToString"]["skipEnd"]="true";
370
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
371
		#$conf["spiltSymbolAtStart"]="";
372
		#參考資料:
373
		#無.
374
		#備註:
375
		#無.
376
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
377
		unset($conf["arrays::arrayToString"]);
226 liveuser 378
 
3 liveuser 379
		#如果異常
380
		if($arrayToString["status"]==="false"){
226 liveuser 381
 
3 liveuser 382
			#設置錯誤識別
383
			$result["status"]="false";
226 liveuser 384
 
3 liveuser 385
			#設置錯誤訊息
386
			$result["error"]=$arrayToString;
226 liveuser 387
 
3 liveuser 388
			#回傳結果
389
			return $result;
226 liveuser 390
 
3 liveuser 391
			}#if end
226 liveuser 392
 
3 liveuser 393
		#取得 private key 字串
394
		$result["content"]=$arrayToString["content"];
226 liveuser 395
 
3 liveuser 396
		#設置執行正常
397
		$result["status"]="true";
226 liveuser 398
 
3 liveuser 399
		#回傳結果
400
		return $result;
226 liveuser 401
 
3 liveuser 402
		}#function createPrivateKey end
226 liveuser 403
 
3 liveuser 404
	/*
405
	#函式說明:
249 liveuser 406
	#產生certificate sign request(CSR).
3 liveuser 407
	#回傳結果:
408
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
409
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
410
	#$result["function"],當前執行的函式名稱.
411
	#$result["argu"],所使用的參數.
412
	#$result["curl_verbose_info"],curl執行的詳細資訊.
413
	#必填參數:
249 liveuser 414
	#$conf["domain"],字串,csr內容的網域名稱.
415
	#$conf["domain"]="";
416
	#可省略參數:
417
	#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
418
	#$conf["country"]="";
419
	#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
420
	#$conf["state"]="";
421
	#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
422
	#$conf["org"]="";
423
	#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
424
	#$conf["unit"]="";
425
	#參考資料:
426
	#無.
427
	#備註:
428
	#無.
429
	*/
430
	public static function createCSR(&$conf){
431
 
432
		#初始化要回傳的結果
433
		$result=array();
434
 
435
		#設置當其函數名稱
436
		$result["function"]=__FUNCTION__;
437
 
438
		#如果 $conf 不為陣列
439
		if(gettype($conf)!="array"){
440
 
441
			#設置執行失敗
442
			$result["status"]="false";
443
 
444
			#設置執行錯誤訊息
445
			$result["error"][]="\$conf變數須為陣列形態";
446
 
447
			#如果傳入的參數為 null
448
			if($conf==null){
449
 
450
				#設置執行錯誤訊息
451
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
452
 
453
				}#if end
454
 
455
			#回傳結果
456
			return $result;
457
 
458
			}#if end
459
 
460
		#取得參數
461
		$result["argu"]=$conf;
462
 
463
		#檢查參數
464
		#函式說明:
465
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
466
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
467
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
468
		#$result["function"],當前執行的函式名稱.
469
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
470
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
471
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
472
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
473
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
474
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
475
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
476
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
477
		#必填寫的參數:
478
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
479
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
480
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
481
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("domain");
482
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
483
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
484
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
485
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
486
		#可以省略的參數:
487
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
488
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
489
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
490
		#$conf["skipableVariableCanNotBeEmpty"]=array();
491
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
492
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("country","state","city","org","unit");
493
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
494
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string");
495
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
496
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("TW","Taiwan","Taoyuan City","QBPWCF","RD");
497
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
498
		#$conf["arrayCountEqualCheck"][]=array();
499
		#參考資料來源:
500
		#array_keys=>http://php.net/manual/en/function.array-keys.php
501
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
502
		unset($conf["variableCheck::checkArguments"]);
503
 
504
		#如果檢查失敗
505
		if($checkArguments["status"]==="false"){
506
 
507
			#設置錯誤識別
508
			$result["status"]="false";
509
 
510
			#設置錯誤訊息
511
			$result["error"]=$checkArguments;
512
 
513
			#回傳結果
514
			return $result;
515
 
516
			}#if end
517
 
518
		#如果檢查不通過
519
		if($checkArguments["passed"]==="false"){
520
 
521
			#設置錯誤識別
522
			$result["status"]="false";
523
 
524
			#設置錯誤訊息
525
			$result["error"]=$checkArguments;
526
 
527
			#回傳結果
528
			return $result;
529
 
530
			}#if end
531
 
532
		#產生uuid名稱
533
		#函式說明:
534
		#使用 linux 的 uuid 指令來產生 uuid 字串
535
		#回傳結果:
536
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
537
		#$result["error"],錯誤訊息.
538
		#$result["function"],當前執行的函式名稱.
539
		#$result["content"],uuid.
540
		#必填參數:
541
		#無.
542
		#可省略參數:
543
		#無.
544
		#參考資料:
545
		#無.
546
		#備註:
547
		#無.
548
		$uuid=cmd::uuid();
549
 
550
		#如果執行異常
551
		if($uuid["status"]==="false"){
552
 
553
			#設置錯誤識別
554
			$result["status"]="false";
555
 
556
			#設置錯誤訊息
557
			$result["error"]=$uuid;
558
 
559
			#回傳結果
560
			return $result;
561
 
562
			}#if end
563
 
564
		#取得暫存的檔案名稱
565
		$TFN=$uuid["content"];
566
 
567
		#函式說明:
568
		#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
569
		#回傳結果:
570
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
571
		#$result["error"],錯誤訊息.
572
		#$result["function"],當前執行的函數名稱.
573
		#$result["content"],暫存檔案的路徑與名稱.
574
		#$result["fileName"],暫存檔案的名稱.
575
		#$result["path"],暫存檔案的路徑.
576
		#必填參數:
577
		#無.
578
		#可省略參數:
579
		#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
580
		#$conf["contant"]=array();
581
		#參考資料:
582
		#無.
583
		#備註:
584
		#無.
585
		$conf["fileAccess::createTempFile"]=array();
586
		$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
587
		unset($conf["fileAccess::createTempFile"]);
588
 
589
		#如果執行異常
590
		if($createTempFile["status"]==="false"){
591
 
592
			#設置錯誤識別
593
			$result["status"]="false";
594
 
595
			#設置錯誤訊息
596
			$result["error"]=$createTempFile;
597
 
598
			#回傳結果
599
			return $result;
600
 
601
			}#if end
602
 
603
		#暫存的檔案路徑與名稱
604
		$TFN=$createTempFile["content"];
605
 
606
		#產生 privae key
607
		#openssl genrsa -out output.key 4096 
608
 
609
		#函式說明:
610
		#呼叫shell執行系統命令,並取得回傳的內容.
611
		#回傳結果:
612
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
613
		#$result["error"],錯誤訊息陣列.
614
		#$result["function"],當前執行的函數名稱.
615
		#$result["argu"],使用的參數.
616
		#$result["cmd"],執行的指令內容.
617
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
618
		#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
619
		#$result["content"],為執行完後的輸出字串.
620
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
621
		#$result["running"],是否還在執行.
622
		#$result["pid"],pid.
623
		#$result["statusCode"],執行結束後的代碼.
624
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
625
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
626
		#必填參數:
627
		#$conf["command"],字串,要執行的指令.
628
		$conf["external::callShell"]["command"]="openssl";
629
		#$conf["fileArgu"],字串,變數__FILE__的內容.
630
		$conf["external::callShell"]["fileArgu"]=__FILE__;
631
		#可省略參數:
632
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
633
		$conf["external::callShell"]["argu"]=array("genrsa","-out",$TFN,"4096");
634
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
635
		#$conf["arguIsAddr"]=array();
636
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
637
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
638
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
639
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
640
		#$conf["enablePrintDescription"]="true";
641
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
642
		#$conf["printDescription"]="";
643
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
644
		#$conf["escapeshellarg"]="false";
645
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
646
		#$conf["thereIsShellVar"]=array();
647
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
648
		#$conf["username"]="";
649
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
650
		#$conf["password"]="";
651
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
652
		#$conf["useScript"]="";
653
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
654
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
655
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
656
		#$conf["inBackGround"]="";
657
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
658
		#$conf["getErr"]="false";
659
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
660
		$conf["external::callShell"]["doNotRun"]="true";
661
		#參考資料:
662
		#exec=>http://php.net/manual/en/function.exec.php
663
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
664
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
665
		#備註:
666
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
667
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
668
		$callShell=external::callShell($conf["external::callShell"]);
669
		unset($conf["external::callShell"]);
670
 
671
		#如果執行異常
672
		if($callShell["status"]==="false"){
673
 
674
			#設置錯誤識別
675
			$result["status"]="false";
676
 
677
			#設置錯誤訊息
678
			$result["error"]=$callShell;
679
 
680
			#回傳結果
681
			return $result;
682
 
683
			}#if end
684
 
685
		#debug
686
		#var_dump(__LINE__,$callShell);exit;
687
 
688
		#函式說明:
689
		#透過proc來多執行序運作.
690
		#回傳結果:
691
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
692
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
693
		#$result["function"],當前執行的函式名稱.
694
		#$result["argu"],使用的參數.
695
		#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
696
		#必填參數:
697
		#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
698
		$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
699
		#可省略參數:
700
		#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
701
		$conf["threads::proc"]["wait"]="true";
702
		#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
703
		#$conf["timeout"]=array("10");
704
		#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
705
		#$conf["workingDir"]=array("path");
706
		#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
707
		#$conf["envs"]=array(array("key"=>"value"));
708
		#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
709
		#$conf["executeBy"]=array("bash");
710
		#參考資料:
711
		#https://www.php.net/manual/en/function.proc-open.php
712
		#https://www.php.net/manual/en/function.proc-get-status.php
713
		#https://www.php.net/manual/en/function.proc-terminate.php
714
		#備註:
715
		#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
716
		$proc=threads::proc($conf["threads::proc"]);
717
		unset($conf["threads::proc"]);
718
 
719
		#如果執行異常
720
		if($proc["status"]==="false"){
721
 
722
			#設置錯誤識別
723
			$result["status"]="false";
724
 
725
			#設置錯誤訊息
726
			$result["error"]=$proc;
727
 
728
			#回傳結果
729
			return $result;
730
 
731
			}#if end
732
 
733
		#debug
734
		#var_dump(__LINE__,$proc);exit;
735
 
736
		#如果執行異常
737
		if($proc["content"][0]["status"]==="false"){
738
 
739
			#設置錯誤識別
740
			$result["status"]="false";
741
 
742
			#設置錯誤訊息
743
			$result["error"]=$proc["content"][0]["error"];
744
 
745
			#回傳結果
746
			return $result;
747
 
748
			}#if end
749
 
750
		#儲存錯誤訊息
751
		$errorMsg=$proc["content"][0]["error"];
752
 
753
		#如果有錯誤訊息
754
		if(!empty($errorMsg)){
755
 
756
			#設置錯誤識別
757
			$result["status"]="false";
758
 
759
			#設置錯誤訊息
760
			$result["error"]=$errorMsg;
761
 
762
			#回傳結果
763
			return $result;
764
 
765
			}#if end
766
 
767
		#範例指令
768
		#C,國家,例如TW,代表Taiwan
769
		#ST,州、省,要完整名稱,例如:Taiwan
770
		#L,城市名稱,例如Taoyuan City.
771
		#O=,組織或公司名稱,例如QBPWCF.
772
		#OU,單位名稱,例如RD.
773
		#CN,網域名稱,例如www.qbpwcf.org
774
		#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/"
775
 
776
		#初始化subj參數
777
		$subjStr="-subj=/";
778
 
779
		#設置 Country 參數
780
		$subjStr=$subjStr."C=".$conf["country"]."/";
781
 
782
		#設置 State 參數
783
		$subjStr=$subjStr."ST=".$conf["state"]."/";
784
 
785
		#設置 city 參數
786
		$subjStr=$subjStr."L=".$conf["city"]."/";
787
 
788
		#設置 Org 參數
789
		$subjStr=$subjStr."O=".$conf["org"]."/";
790
 
791
		#設置 Unit 參數
792
		$subjStr=$subjStr."OU=".$conf["unit"]."/";
793
 
794
		#設置 domain name 參數
795
		$subjStr=$subjStr."CN=".$conf["domain"]."/";
796
 
797
		#函式說明:
798
		#呼叫shell執行系統命令,並取得回傳的內容.
799
		#回傳結果:
800
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
801
		#$result["error"],錯誤訊息陣列.
802
		#$result["function"],當前執行的函數名稱.
803
		#$result["argu"],使用的參數.
804
		#$result["cmd"],執行的指令內容.
805
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
806
		#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
807
		#$result["content"],為執行完後的輸出字串.
808
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
809
		#$result["running"],是否還在執行.
810
		#$result["pid"],pid.
811
		#$result["statusCode"],執行結束後的代碼.
812
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
813
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
814
		#必填參數:
815
		#$conf["command"],字串,要執行的指令.
816
		$conf["external::callShell"]["command"]="openssl";
817
		#$conf["fileArgu"],字串,變數__FILE__的內容.
818
		$conf["external::callShell"]["fileArgu"]=__FILE__;
819
		#可省略參數:
820
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
821
		$conf["external::callShell"]["argu"]=array("req","-new","-key",$TFN,$subjStr);
822
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
823
		#$conf["arguIsAddr"]=array();
824
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
825
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
826
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
827
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
828
		#$conf["enablePrintDescription"]="true";
829
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
830
		#$conf["printDescription"]="";
831
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
832
		$conf["external::callShell"]["escapeshellarg"]="true";
833
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
834
		#$conf["thereIsShellVar"]=array();
835
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
836
		#$conf["username"]="";
837
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
838
		#$conf["password"]="";
839
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
840
		#$conf["useScript"]="";
841
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
842
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
843
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
844
		#$conf["inBackGround"]="";
845
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
846
		#$conf["getErr"]="false";
847
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
848
		$conf["external::callShell"]["doNotRun"]="true";
849
		#參考資料:
850
		#exec=>http://php.net/manual/en/function.exec.php
851
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
852
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
853
		#備註:
854
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
855
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
856
		$callShell=external::callShell($conf["external::callShell"]);
857
		unset($conf["external::callShell"]);
858
 
859
		#如果執行異常
860
		if($callShell["status"]==="false"){
861
 
862
			#設置錯誤識別
863
			$result["status"]="false";
864
 
865
			#設置錯誤訊息
866
			$result["error"]=$callShell;
867
 
868
			#回傳結果
869
			return $result;
870
 
871
			}#if end
872
 
873
		#debug
874
		#var_dump(__LINE__,$callShell);exit;
875
 
876
		#函式說明:
877
		#透過proc來多執行序運作.
878
		#回傳結果:
879
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
880
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
881
		#$result["function"],當前執行的函式名稱.
882
		#$result["argu"],使用的參數.
883
		#$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"代表程序的資訊.
884
		#必填參數:
885
		#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
886
		$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
887
		#可省略參數:
888
		#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
889
		$conf["threads::proc"]["wait"]="true";
890
		#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
891
		#$conf["timeout"]=array("10");
892
		#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
893
		#$conf["workingDir"]=array("path");
894
		#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
895
		#$conf["envs"]=array(array("key"=>"value"));
896
		#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
897
		#$conf["executeBy"]=array("bash");
898
		#參考資料:
899
		#https://www.php.net/manual/en/function.proc-open.php
900
		#https://www.php.net/manual/en/function.proc-get-status.php
901
		#https://www.php.net/manual/en/function.proc-terminate.php
902
		#備註:
903
		#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
904
		$proc=threads::proc($conf["threads::proc"]);
905
		unset($conf["threads::proc"]);
906
 
907
		#如果執行異常
908
		if($proc["status"]==="false"){
909
 
910
			#設置錯誤識別
911
			$result["status"]="false";
912
 
913
			#設置錯誤訊息
914
			$result["error"]=$proc;
915
 
916
			#回傳結果
917
			return $result;
918
 
919
			}#if end
920
 
921
		#如果執行異常
922
		if($proc["content"][0]["status"]==="false"){
923
 
924
			#設置錯誤識別
925
			$result["status"]="false";
926
 
927
			#設置錯誤訊息
928
			$result["error"]=$proc["content"][0]["error"];
929
 
930
			#回傳結果
931
			return $result;
932
 
933
			}#if end
934
 
935
		#debug
936
		#var_dump(__LINE__,$proc);exit;
937
 
938
		#儲存csr
939
		$csr=$proc["content"][0]["content"];
940
 
941
		#取得 csr 內容
942
		$result["content"]=$csr;
943
 
944
		#移除private key
945
		#函式說明:
946
		#移除檔案
947
		#回傳結果:
948
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
949
		#$result["error"],錯誤訊息陣列.
950
		#$result["warning"],警告訊息陣列.
951
		#$result["function"],當前執行的函數名稱.
952
		#$result["argu"],當前函式使用的參數.
953
		#必填參數:
954
		#$conf["fileAddress"],字串,要移除檔案的位置.
955
		$conf["fileAccess::delFile"]["fileAddress"]=$TFN;
956
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
957
		$conf["fileAccess::delFile"]["fileArgu"]=__FILE__;
958
		#可省略參數:
959
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
960
		#$conf["commentsArray"]=array("");
961
		#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
962
		#$conf["allowDelSymlink"]="true";
963
		#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
964
		#$conf["allowDelFolder"]="true";
965
		#參考資料:
966
		#無.
967
		#備註:
968
		#無.
969
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
970
		unset($conf["fileAccess::delFile"]);
971
 
972
		#如果執行異常
973
		if($delFile["status"]==="false"){
974
 
975
			#設置錯誤識別
976
			$result["status"]="false";
977
 
978
			#設置錯誤訊息
979
			$result["error"]=$delFile;
980
 
981
			#回傳結果
982
			return $result;
983
 
984
			}#if end
985
 
986
		#設置執行正常
987
		$result["status"]="true";
988
 
989
		#回傳結果
990
		return $result;
991
 
992
		}#function createCSR end
993
 
994
	/*
995
	#函式說明:
996
	#提供certificate sign request(CSR)透過zerossl產生cergificate.
997
	#回傳結果:
998
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
999
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1000
	#$result["function"],當前執行的函式名稱.
1001
	#$result["argu"],所使用的參數.
1002
	#$result["curl_verbose_info"],curl執行的詳細資訊.
1003
	#$result["id"],用於zerossl api驗證domain的id.
1004
	#$result["content"],字串,得到的json字串回應.
1005
	#$result["cnameKey"],用於dns CNAME驗證鍵名.
1006
	#$result["cnameVal"],用於dms CNAME驗證鍵值.
1007
	#必填參數:
3 liveuser 1008
	#$conf["certificate_domains"],字串,要簽署的doamin名稱.
1009
	$conf["certificate_domains"]="";
1010
	#$conf["certificate_csr"],字串,簽署的資訊.
1011
	$conf["certificate_csr"]="";
1012
	#$conf["fileArgu"],字串,變數__FILE__的內容.
1013
	$conf["fileArgu"]=__FILE__;
1014
	#可省略參數:
1015
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
1016
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
1017
	#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
1018
	#$conf["path"]=self::getApiInfo()["csrPath"];
1019
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
1020
	#$conf["key"]=self::getApiInfo()["apiKey"];
1021
	#參考資料:
1022
	#無.
1023
	#備註:
1024
	#無.
1025
	*/
249 liveuser 1026
	public static function createCertificate(&$conf){
226 liveuser 1027
 
3 liveuser 1028
		#break point
1029
		#var_dump(self::getApiInfo());exit;
226 liveuser 1030
 
3 liveuser 1031
		#初始化要回傳的結果
1032
		$result=array();
226 liveuser 1033
 
3 liveuser 1034
		#設置當其函數名稱
1035
		$result["function"]=__FUNCTION__;
226 liveuser 1036
 
3 liveuser 1037
		#如果 $conf 不為陣列
1038
		if(gettype($conf)!="array"){
226 liveuser 1039
 
3 liveuser 1040
			#設置執行失敗
1041
			$result["status"]="false";
226 liveuser 1042
 
3 liveuser 1043
			#設置執行錯誤訊息
1044
			$result["error"][]="\$conf變數須為陣列形態";
1045
 
1046
			#如果傳入的參數為 null
1047
			if($conf==null){
226 liveuser 1048
 
3 liveuser 1049
				#設置執行錯誤訊息
1050
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1051
 
3 liveuser 1052
				}#if end
1053
 
1054
			#回傳結果
1055
			return $result;
226 liveuser 1056
 
3 liveuser 1057
			}#if end
226 liveuser 1058
 
3 liveuser 1059
		#取得參數
1060
		$result["argu"]=$conf;
226 liveuser 1061
 
3 liveuser 1062
		#檢查參數
1063
		#函式說明:
1064
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1065
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1066
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1067
		#$result["function"],當前執行的函式名稱.
1068
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1069
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1070
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1071
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1072
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1073
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1074
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1075
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1076
		#必填寫的參數:
1077
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1078
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1079
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1080
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","certificate_domains","certificate_csr");
226 liveuser 1081
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 1082
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
1083
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1084
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1085
		#可以省略的參數:
1086
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1087
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1088
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
1089
		#$conf["skipableVariableCanNotBeEmpty"]=array();
1090
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1091
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","path","key");
226 liveuser 1092
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1093
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1094
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1095
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["csrPath"],self::getApiInfo()["apiKey"]);
1096
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1097
		#$conf["arrayCountEqualCheck"][]=array();
1098
		#參考資料來源:
1099
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1100
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1101
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1102
 
3 liveuser 1103
		#如果檢查失敗
249 liveuser 1104
		if($checkArguments["status"]==="false"){
226 liveuser 1105
 
3 liveuser 1106
			#設置錯誤識別
1107
			$result["status"]="false";
226 liveuser 1108
 
3 liveuser 1109
			#設置錯誤訊息
1110
			$result["error"]=$checkArguments;
226 liveuser 1111
 
3 liveuser 1112
			#回傳結果
1113
			return $result;
226 liveuser 1114
 
3 liveuser 1115
			}#if end
226 liveuser 1116
 
3 liveuser 1117
		#如果檢查不通過
249 liveuser 1118
		if($checkArguments["passed"]==="false"){
226 liveuser 1119
 
3 liveuser 1120
			#設置錯誤識別
1121
			$result["status"]="false";
226 liveuser 1122
 
3 liveuser 1123
			#設置錯誤訊息
1124
			$result["error"]=$checkArguments;
226 liveuser 1125
 
3 liveuser 1126
			#回傳結果
1127
			return $result;
226 liveuser 1128
 
3 liveuser 1129
			}#if end
226 liveuser 1130
 
3 liveuser 1131
		#要傳送的 key -> value
1132
		$postArray=array();
226 liveuser 1133
 
3 liveuser 1134
		#設置要簽署的domain
1135
		$postArray["certificate_domains"]=$conf["certificate_domains"];
226 liveuser 1136
 
3 liveuser 1137
		#設置csr
1138
		$postArray["certificate_csr"]=$conf["certificate_csr"];
226 liveuser 1139
 
3 liveuser 1140
		#預設為 90 天的憑證
1141
		$postArray["certificate_validity_days"]=90;
226 liveuser 1142
 
3 liveuser 1143
		#強制讓 要簽署的domain 為 $postArray["certificate_domains"]
1144
		$postArray["strict_domains"]=1;
226 liveuser 1145
 
3 liveuser 1146
		#設置要傳送的 json
1147
		$postJson=json_encode($postArray);
226 liveuser 1148
 
3 liveuser 1149
		#函式說明:
1150
		#運行curl cmd
1151
		#回傳結果:
1152
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1153
		#$result["error"],錯誤訊息陣列.
1154
		#$result["function"],當前執行的函式名稱.
1155
		#$result["founded"],識別網址找不找得到.
1156
		#$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"代表程序的資訊.
1157
		#$result["fullContent"],取得回應的完整字串內容.
1158
		#$result["cookie"],cookie檔案的位置與名稱.
1159
		#$result["cmd"],執行的command.
1160
		#$result["argu],使用的參數.
1161
		#必填參數:
1162
		#$conf["url"],字串,目標url.
1163
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].$conf["path"]."?access_key=".$conf["key"];
1164
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1165
		$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
1166
		#可省略參數:
1167
		#$conf["header"],字串陣列,要傳送的header.
1168
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
1169
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
1170
		#$conf["allowAnySSLcertificate"]="";
1171
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
1172
		#$conf["postVar"]=array();
1173
		#$conf["rawPost"]="字串",要傳送的raw post內容.
1174
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
1175
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
1176
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
1177
		#$conf["agent"],字串,user agent的名稱.
1178
		#$conf["agent"]="";
1179
		#$conf["cookie"],字串,cookie位置與檔案位置.
1180
		#$conf["cookie"]="";
1181
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
1182
		#$conf["forceNewCookie"]="";
1183
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
1184
		#$conf["inBg"]="true";
1185
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
1186
		#$conf["bgInProc"]="false";
1187
		#參考資料:
1188
		#無.
1189
		#備註:
1190
		#無.
1191
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
1192
		unset($conf["catchWebContent::curlCmd"]);
226 liveuser 1193
 
3 liveuser 1194
		#如果異常
1195
		if($curlCmd["status"]==="false"){
226 liveuser 1196
 
3 liveuser 1197
			#設置錯誤識別
1198
			$result["status"]="false";
226 liveuser 1199
 
3 liveuser 1200
			#設置錯誤訊息
1201
			$result["error"]=$curlCmd;
226 liveuser 1202
 
3 liveuser 1203
			#回傳結果
1204
			return $result;
226 liveuser 1205
 
3 liveuser 1206
			}#if end
226 liveuser 1207
 
3 liveuser 1208
		#設置curl的詳細資訊
1209
		$result["curl_verbose_info"]=$curlCmd;
226 liveuser 1210
 
3 liveuser 1211
		/* 範例 json content
249 liveuser 1212
		{"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 1213
		*/
226 liveuser 1214
 
249 liveuser 1215
		#驗證結果是否為 json
1216
		$json_validate=json_validate($curlCmd["fullContent"]);
226 liveuser 1217
 
249 liveuser 1218
		#如果回應不是 json
1219
		if(!$json_validate){
1220
 
1221
			#設置錯誤識別
1222
			$result["status"]="false";
1223
 
1224
			#設置錯誤訊息
1225
			$result["error"]=$curlCmd;
1226
 
1227
			#回傳結果
1228
			return $result;
1229
 
1230
			}#if end
1231
 
1232
		#設置json string結果
1233
		$result["content"]=$curlCmd["fullContent"];
1234
 
1235
		#解析json
1236
		$jsonRes=json_decode($result["content"]);
1237
 
1238
		#取得用於 dns CNAME 驗證的名稱
1239
		$result["cnameKey"]=$jsonRes->validation->other_methods->$conf["certificate_domains"]->cname_validation_p1;
1240
 
1241
		#取得用於 dns CNAME 驗證的數值
1242
		$result["cnameVal"]=$jsonRes->validation->other_methods->$conf["certificate_domains"]->cname_validation_p2;
1243
 
1244
		#取得用於認證domain時識別用的id
1245
		$result["id"]=$jsonRes->id;
1246
 
3 liveuser 1247
		#設置執行正常
1248
		$result["status"]="true";
226 liveuser 1249
 
3 liveuser 1250
		#回傳結果
1251
		return $result;
226 liveuser 1252
 
249 liveuser 1253
		}#function createCertificate end
3 liveuser 1254
 
249 liveuser 1255
	/*
1256
	#函式說明:
1257
	#新增DNS記錄到檔案裡面.
1258
	#回傳結果:
1259
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1260
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1261
	#$result["function"],當前執行的函式名稱.
1262
	#$result["argu"],所使用的參數.
1263
	#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
1264
	#$result["content"]["domain"],字串,RR所屬domain.
1265
	#$result["content"]["defaultTTL"],字串,預設的RR更新時間.
1266
	#$result["comment"],字串陣列,逐行的註解.
1267
	#必填參數:
1268
	#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
1269
	$conf["add"]=array();
1270
	#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
1271
	$conf["dnsRecordFile"]="";
1272
	#可省略參數:
1273
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
1274
	#$conf["writeNow"]="false";
253 liveuser 1275
	#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
1276
	#$conf["debug"]="false";
249 liveuser 1277
	#參考資料:
1278
	#無.
1279
	#備註:
1280
	#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
1281
	#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
1282
	#php-pear上的Net_DNS2也可以解析RR.
1283
	*/
1284
	public static function updateDnsRecordFile(&$conf){
1285
 
1286
		#初始化要回傳的結果
1287
		$result=array();
1288
 
1289
		#設置當其函數名稱
1290
		$result["function"]=__FUNCTION__;
1291
 
1292
		#如果 $conf 不為陣列
1293
		if(gettype($conf)!="array"){
1294
 
1295
			#設置執行失敗
1296
			$result["status"]="false";
1297
 
1298
			#設置執行錯誤訊息
1299
			$result["error"][]="\$conf變數須為陣列形態";
1300
 
1301
			#如果傳入的參數為 null
1302
			if($conf==null){
1303
 
1304
				#設置執行錯誤訊息
1305
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1306
 
1307
				}#if end
1308
 
1309
			#回傳結果
1310
			return $result;
1311
 
1312
			}#if end
1313
 
1314
		#取得參數
1315
		$result["argu"]=$conf;
1316
 
1317
		#檢查參數
1318
		#函式說明:
1319
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1320
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1321
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1322
		#$result["function"],當前執行的函式名稱.
1323
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1324
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1325
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1326
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1327
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1328
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1329
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1330
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1331
		#必填寫的參數:
1332
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1333
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1334
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1335
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("add","dnsRecordFile");
1336
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
1337
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
1338
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1339
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1340
		#可以省略的參數:
1341
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1342
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1343
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
1344
		#$conf["skipableVariableCanNotBeEmpty"]=array();
1345
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
253 liveuser 1346
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug");
249 liveuser 1347
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
253 liveuser 1348
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
249 liveuser 1349
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
253 liveuser 1350
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
249 liveuser 1351
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1352
		#$conf["arrayCountEqualCheck"][]=array();
1353
		#參考資料來源:
1354
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1355
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1356
		unset($conf["variableCheck::checkArguments"]);
1357
 
1358
		#如果檢查失敗
1359
		if($checkArguments["status"]==="false"){
1360
 
1361
			#設置錯誤識別
1362
			$result["status"]="false";
1363
 
1364
			#設置錯誤訊息
1365
			$result["error"]=$checkArguments;
1366
 
1367
			#回傳結果
1368
			return $result;
1369
 
1370
			}#if end
1371
 
1372
		#如果檢查不通過
1373
		if($checkArguments["passed"]==="false"){
1374
 
1375
			#設置錯誤識別
1376
			$result["status"]="false";
1377
 
1378
			#設置錯誤訊息
1379
			$result["error"]=$checkArguments;
1380
 
1381
			#回傳結果
1382
			return $result;
1383
 
1384
			}#if end
1385
 
1386
		#初始化要回傳的content
1387
		$result["content"]=array();
1388
 
1389
		#初始化儲存逐行的註解.
1390
		$result["comment"]=array();
1391
 
1392
		#預設的zone file domain為空
1393
		$result["domain"]="";
1394
 
1395
		#預設的 update 時間
1396
		$result["defaultTTL"]=3600;
1397
 
1398
		#取得 dns 記錄檔案的內容
1399
		#函式說明:
1400
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1401
		#回傳的變數說明:
1402
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1403
		#$result["error"],錯誤訊息提示.
1404
		#$result["warning"],警告訊息.
1405
		#$result["function"],當前執行的函數名稱.
1406
		#$result["fileContent"],爲檔案的內容陣列.
1407
		#$result["lineCount"],爲檔案內容總共的行數.
1408
		#$result["fullContent"],為檔案的完整內容.
1409
		#$result["base64dataOnly"],檔案的base64data.
1410
		#$result["base64data"],為在網頁上給予src參數的數值.
1411
		#$result["mimeType"],為檔案的mime type.
1412
		#必填參數:
1413
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1414
		$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$conf["dnsRecordFile"];
1415
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1416
		$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
1417
		#可省略參數:
1418
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
1419
		$conf["fileAccesss::getFileContent"]["web"]="false";
1420
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1421
		#$conf["createIfnotExist"]="false";
1422
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
1423
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
1424
		#參考資料:
1425
		#file(),取得檔案內容的行數.
1426
		#file=>http:#php.net/manual/en/function.file.php
1427
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1428
		#filesize=>http://php.net/manual/en/function.filesize.php
1429
		#參考資料:
1430
		#無.
1431
		#備註:
1432
		#無.
1433
		$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
1434
		unset($conf["fileAccesss::getFileContent"]);
1435
 
1436
		#如果檢查失敗
1437
		if($getFileContent["status"]==="false"){
1438
 
1439
			#設置錯誤識別
1440
			$result["status"]="false";
1441
 
1442
			#設置錯誤訊息
1443
			$result["error"]=$getFileContent;
1444
 
1445
			#回傳結果
1446
			return $result;
1447
 
1448
			}#if end
1449
 
1450
		#取得每行內容
1451
		$lines=$getFileContent["fileContent"];
1452
 
1453
		/*
1454
		範例每行內容:
1455
		$ORIGIN server.domain.	;base domain-name,in this Resource Records (RR) file,"@" equal to base domain-name.
1456
		$TTL 86400	;default TTL for zone
1457
		@	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
1458
		@	3600	IN	TXT	"v=spf1 a mx ~all"
1459
		@	86400	IN	MX	1 mail.server.domain.
1460
		@	86400	IN	A	1.1.1.1
1461
		mail.server.domain.	IN	1.1.1.1
1462
		10-42-0-1	IN	A	10.42.0.1
1463
		101-free        IN      A	101.101.101.101
1464
		127-0-0-1	IN	A	127.0.0.1
1465
		_dmarc	IN	TXT	"v=DMARC1;p=reject;sp=reject;pct=100;adkim=r;aspf=r;fo=1;ri=86400;rua=mailto:admin@server.domain"
1466
		default._domainkey	IN	TXT	( "v=DKIM1; k=rsa;" "p=MIGfMA0GCSqG/SIb3DQEBAQQAB" )  ; ----- DKIM key default for qbpwcf.org
1467
		...
1468
		*/
1469
 
1470
		#針對每行內容
1471
		foreach($lines as $lineNo => $line){
1472
 
1473
			#另存一份要處理的RR
1474
			$unFormatStr=$line;
1475
 
253 liveuser 1476
			#如果要debug
1477
			if($conf["debug"]==="true"){
1478
 
1479
				#函式說明:
1480
				#撰寫log
1481
				#回傳結果:
1482
				#$result["status"],狀態,"true"或"false".
1483
				#$result["error"],錯誤訊息陣列.
1484
				#$result["function"],當前函式的名稱.
1485
				#$result["argu"],使用的參數.
1486
				#$result["content"],要寫入log的內容字串.
1487
				#必填參數:
1488
				#$conf["path"],字串,log檔案的路徑與名稱.
1489
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
1490
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1491
				$conf["logs::record"]["content"]="processing lineNo:".$lineNo." content:".$line.PHP_EOL;
1492
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1493
				$conf["logs::record"]["fileArgu"]=__FILE__;
1494
				#可省略參數:
1495
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1496
				#$conf["rewrite"]="false";
1497
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
1498
				#$conf["returnOnly"]="true";
1499
				#參考資料:
1500
				#無.
1501
				#備註:
1502
				#無.
1503
				$record=logs::record($conf["logs::record"]);
1504
				unset($conf["logs::record"]);
1505
 
1506
				}#if end
1507
 
249 liveuser 1508
			#初始化該行的資訊陣列
1509
			$info=array();
1510
 
1511
			#尋找";"開頭的內容,亦即整行都是註解.
1512
			#函式說明:
1513
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1514
			#回傳結果:
1515
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1516
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1517
			#$result["function"],當前執行的函式名稱.
1518
			#$result["argu"],所使用的參數.
1519
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1520
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1521
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1522
			#必填參數:
1523
			#$conf["input"],字串,要檢查的字串.
1524
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1525
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1526
			$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
1527
			#可省略參數:
1528
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1529
			#$conf["varEqual"]=array(null,"found");
1530
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1531
			#$conf["varCon"]=array("no_tail"=>" not");
1532
			#參考資料:
1533
			#無.
1534
			#備註:
1535
			#無.
1536
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1537
			unset($conf["search::findSpecifyStrFormat"]);
1538
 
1539
			#如果執行異常
1540
			if($findSpecifyStrFormat["status"]==="false"){
1541
 
1542
				#設置錯誤識別
1543
				$result["status"]="false";
1544
 
1545
				#設置錯誤訊息
1546
				$result["error"]=$findSpecifyStrFormat;
1547
 
1548
				#回傳結果
1549
				return $result;
1550
 
1551
				}#if end
1552
 
1553
			#如果有找到符合格式的內容
1554
			if($findSpecifyStrFormat["found"]==="true"){
1555
 
1556
				#儲存為註解
1557
				$result["comment"][]=$unFormatStr;
1558
 
1559
				#換下一行
1560
				continue;
1561
 
1562
				}#if end
1563
 
1564
			#函式說明:
1565
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1566
			#回傳結果:
1567
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1568
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1569
			#$result["function"],當前執行的函式名稱.
1570
			#$result["argu"],所使用的參數.
1571
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1572
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1573
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1574
			#必填參數:
1575
			#$conf["input"],字串,要檢查的字串.
1576
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1577
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1578
			$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
1579
			#可省略參數:
1580
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1581
			#$conf["varEqual"]=array(null,"found");
1582
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1583
			#$conf["varCon"]=array("no_tail"=>" not");
1584
			#參考資料:
1585
			#無.
1586
			#備註:
1587
			#無.
1588
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1589
			unset($conf["search::findSpecifyStrFormat"]);
1590
 
1591
			#如果執行異常
1592
			if($findSpecifyStrFormat["status"]==="false"){
1593
 
1594
				#設置錯誤識別
1595
				$result["status"]="false";
1596
 
1597
				#設置錯誤訊息
1598
				$result["error"]=$findSpecifyStrFormat;
1599
 
1600
				#回傳結果
1601
				return $result;
1602
 
1603
				}#if end
1604
 
1605
			#如果有找到符合格式的內容
1606
			if($findSpecifyStrFormat["found"]==="true"){
1607
 
1608
				#設置 type 的數值
1609
				$info["type"]="\$ORIGIN";
1610
 
1611
				#取得後面待處理的內容
1612
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
1613
 
1614
				#函式說明:
1615
				#將字串開頭的特定關鍵字移除.
1616
				#回傳結果:
1617
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1618
				#$result["error"],錯誤訊息陣列.
1619
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
1620
				#$result["function"],當前執行的函數名稱.
1621
				#$result["argu"],使用的參數.
1622
				#$result["content"],處理好的的字串內容.
1623
				#$result["deleted"],被移除的內容.
1624
				#必填參數:
1625
				#$conf["stringIn"],字串,要處理的字串.
1626
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
1627
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
1628
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
1629
				#可省略參數:
1630
				#無.
1631
				#參考資料:
1632
				#無.
1633
				#備註:
1634
				#無.
1635
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
1636
				unset($conf["stringProcess::delHeadStr"]);
1637
 
1638
				#如果執行異常
1639
				if($delHeadStr["status"]==="false"){
1640
 
1641
					#設置錯誤識別
1642
					$result["status"]="false";
1643
 
1644
					#設置錯誤訊息
1645
					$result["error"]=$delHeadStr;
1646
 
1647
					#回傳結果
1648
					return $result;
1649
 
1650
					}#if end
1651
 
1652
				#如果有移除開頭的字串
1653
				if($delHeadStr["founded"]==="true"){
1654
 
1655
					#取得處理後的結果
1656
					$unFormatStr=$delHeadStr["content"];
1657
 
1658
					}#if end
1659
 
253 liveuser 1660
 
1661
 
249 liveuser 1662
				#解析 $ORIGN 的數值, 以及後面是否有註解...
1663
				#函式說明:
1664
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1665
				#回傳結果:
1666
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1667
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
1668
				#$result["function"],當前執行的函式名稱.
1669
				#$result["argu"],所使用的參數.
1670
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1671
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1672
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1673
				#必填參數:
1674
				#$conf["input"],字串,要檢查的字串.
1675
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1676
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1677
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
1678
				#可省略參數:
1679
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1680
				#$conf["varEqual"]=array(null,"found");
1681
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1682
				#$conf["varCon"]=array("no_tail"=>" not");
1683
				#參考資料:
1684
				#無.
1685
				#備註:
1686
				#無.
1687
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1688
				unset($conf["search::findSpecifyStrFormat"]);
1689
 
1690
				#如果執行異常
1691
				if($findSpecifyStrFormat["status"]==="false"){
1692
 
1693
					#設置錯誤識別
1694
					$result["status"]="false";
1695
 
1696
					#設置錯誤訊息
1697
					$result["error"]=$findSpecifyStrFormat;
1698
 
1699
					#回傳結果
1700
					return $result;
1701
 
1702
					}#if end
1703
 
1704
				#如果有數值跟註解
1705
				if($findSpecifyStrFormat["found"]==="true"){
1706
 
1707
					#儲存數值
1708
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
1709
 
1710
					#儲存zone domain
1711
					$result["domain"]=trim($info["value"]);
1712
 
1713
					#儲存註解
253 liveuser 1714
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
249 liveuser 1715
 
1716
					#儲存解析好的RR
1717
					$result["content"][]=$info;
1718
 
1719
					#換下一行
1720
					continue;
1721
 
1722
					}#if end
1723
 
1724
				#執行到這邊代表剩下的內容都是 value
1725
				$info["value"]=$unFormatStr;
1726
 
1727
				#儲存zone domain
1728
				$result["domain"]=trim($info["value"]);
1729
 
1730
				#儲存解析好的RR
1731
				$result["content"][]=$info;
1732
 
1733
				#換下一行
1734
				continue;
1735
 
1736
				}#if end
1737
 
1738
			#檢查是否為 $TTL 開頭
1739
			#函式說明:
1740
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1741
			#回傳結果:
1742
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1743
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1744
			#$result["function"],當前執行的函式名稱.
1745
			#$result["argu"],所使用的參數.
1746
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1747
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1748
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1749
			#必填參數:
1750
			#$conf["input"],字串,要檢查的字串.
1751
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1752
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1753
			$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
1754
			#可省略參數:
1755
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1756
			#$conf["varEqual"]=array(null,"found");
1757
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1758
			#$conf["varCon"]=array("no_tail"=>" not");
1759
			#參考資料:
1760
			#無.
1761
			#備註:
1762
			#無.
1763
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1764
			unset($conf["search::findSpecifyStrFormat"]);
1765
 
1766
			#如果執行異常
1767
			if($findSpecifyStrFormat["status"]==="false"){
1768
 
1769
				#設置錯誤識別
1770
				$result["status"]="false";
1771
 
1772
				#設置錯誤訊息
1773
				$result["error"]=$findSpecifyStrFormat;
1774
 
1775
				#回傳結果
1776
				return $result;
1777
 
1778
				}#if end
1779
 
1780
			#如果有找到符合格式的內容
1781
			if($findSpecifyStrFormat["found"]==="true"){
1782
 
1783
				#設置 type 的數值
1784
				$info["type"]="\$TTL";
1785
 
1786
				#取得後面待處理的內容
1787
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
1788
 
1789
				#函式說明:
1790
				#將字串開頭的特定關鍵字移除.
1791
				#回傳結果:
1792
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1793
				#$result["error"],錯誤訊息陣列.
1794
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
1795
				#$result["function"],當前執行的函數名稱.
1796
				#$result["argu"],使用的參數.
1797
				#$result["content"],處理好的的字串內容.
1798
				#$result["deleted"],被移除的內容.
1799
				#必填參數:
1800
				#$conf["stringIn"],字串,要處理的字串.
1801
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
1802
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
1803
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
1804
				#可省略參數:
1805
				#無.
1806
				#參考資料:
1807
				#無.
1808
				#備註:
1809
				#無.
1810
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
1811
				unset($conf["stringProcess::delHeadStr"]);
1812
 
1813
				#如果執行異常
1814
				if($delHeadStr["status"]==="false"){
1815
 
1816
					#設置錯誤識別
1817
					$result["status"]="false";
1818
 
1819
					#設置錯誤訊息
1820
					$result["error"]=$delHeadStr;
1821
 
1822
					#回傳結果
1823
					return $result;
1824
 
1825
					}#if end
1826
 
1827
				#如果有移除開頭的字串
1828
				if($delHeadStr["founded"]==="true"){
1829
 
1830
					#取得處理後的結果
1831
					$unFormatStr=$delHeadStr["content"];
1832
 
1833
					}#if end
1834
 
1835
				#解析 $TTL 的數值, 以及後面是否有註解...
1836
				#函式說明:
1837
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1838
				#回傳結果:
1839
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1840
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
1841
				#$result["function"],當前執行的函式名稱.
1842
				#$result["argu"],所使用的參數.
1843
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1844
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1845
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1846
				#必填參數:
1847
				#$conf["input"],字串,要檢查的字串.
1848
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1849
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1850
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
1851
				#可省略參數:
1852
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1853
				#$conf["varEqual"]=array(null,"found");
1854
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1855
				#$conf["varCon"]=array("no_tail"=>" not");
1856
				#參考資料:
1857
				#無.
1858
				#備註:
1859
				#無.
1860
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1861
				unset($conf["search::findSpecifyStrFormat"]);
1862
 
1863
				#如果執行異常
1864
				if($findSpecifyStrFormat["status"]==="false"){
1865
 
1866
					#設置錯誤識別
1867
					$result["status"]="false";
1868
 
1869
					#設置錯誤訊息
1870
					$result["error"]=$findSpecifyStrFormat;
1871
 
1872
					#回傳結果
1873
					return $result;
1874
 
1875
					}#if end
1876
 
1877
				#如果有數值跟註解
1878
				if($findSpecifyStrFormat["found"]==="true"){
1879
 
1880
					#儲存數值
1881
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
1882
 
1883
					#儲存註解
253 liveuser 1884
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
249 liveuser 1885
 
1886
					#儲存預設的 TTL
1887
					$result["defaultTTL"]=trim($info["value"]);
1888
 
1889
					#儲存解析好的RR
1890
					$result["content"][]=$info;
1891
 
1892
					#換下一行
1893
					continue;
1894
 
1895
					}#if end
1896
 
1897
				#執行到這邊代表剩下的內容都是 value
1898
				$info["value"]=$unFormatStr;
1899
 
1900
				#儲存預設的 TTL
1901
				$result["defaultTTL"]=trim($info["value"]);
1902
 
1903
				#儲存解析好的RR
1904
				$result["content"][]=$info;
1905
 
1906
				#換下一行
1907
				continue;
1908
 
1909
				}#if end
1910
 
1911
			#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
1912
 
1913
			#函式說明:
1914
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1915
			#回傳結果:
1916
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1917
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1918
			#$result["function"],當前執行的函式名稱.
1919
			#$result["argu"],所使用的參數.
1920
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1921
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1922
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
1923
			#必填參數:
1924
			#$conf["input"],字串,要檢查的字串.
1925
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1926
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1927
			$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
1928
			#可省略參數:
1929
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1930
			#$conf["varEqual"]=array(null,"found");
1931
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1932
			#$conf["varCon"]=array("no_tail"=>" not");
1933
			#參考資料:
1934
			#無.
1935
			#備註:
1936
			#無.
1937
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1938
			unset($conf["search::findSpecifyStrFormat"]);
1939
 
1940
			#如果執行異常
1941
			if($findSpecifyStrFormat["status"]==="false"){
1942
 
1943
				#設置錯誤識別
1944
				$result["status"]="false";
1945
 
1946
				#設置錯誤訊息
1947
				$result["error"]=$findSpecifyStrFormat;
1948
 
1949
				#回傳結果
1950
				return $result;
1951
 
1952
				}#if end
1953
 
1954
			#如果存在"("
1955
			if($findSpecifyStrFormat["found"]==="true"){
1956
 
1957
				#取得無"("的內容
1958
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
1959
 
1960
				#取得拆下來的含開頭"("內容
1961
				$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
1962
 
1963
				}#if end
1964
 
1965
			#反之
1966
			else{
1967
 
1968
				#函式說明:
1969
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1970
				#回傳結果:
1971
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1972
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
1973
				#$result["function"],當前執行的函式名稱.
1974
				#$result["argu"],所使用的參數.
1975
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1976
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1977
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
1978
				#必填參數:
1979
				#$conf["input"],字串,要檢查的字串.
1980
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1981
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1982
				$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
1983
				#可省略參數:
1984
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1985
				#$conf["varEqual"]=array(null,"found");
1986
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1987
				#$conf["varCon"]=array("no_tail"=>" not");
1988
				#參考資料:
1989
				#無.
1990
				#備註:
1991
				#無.
1992
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1993
				unset($conf["search::findSpecifyStrFormat"]);
1994
 
1995
				#如果執行異常
1996
				if($findSpecifyStrFormat["status"]==="false"){
1997
 
1998
					#設置錯誤識別
1999
					$result["status"]="false";
2000
 
2001
					#設置錯誤訊息
2002
					$result["error"]=$findSpecifyStrFormat;
2003
 
2004
					#回傳結果
2005
					return $result;
2006
 
2007
					}#if end
2008
 
2009
				#如果存在"
2010
				if($findSpecifyStrFormat["found"]==="true"){
2011
 
2012
					#取得無"的內容
2013
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2014
 
2015
					#取得拆下來的含開頭"內容
2016
					$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
2017
 
2018
					}#if end
2019
 
2020
				#反之
2021
				else{
2022
 
2023
					#函式說明:
2024
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2025
					#回傳結果:
2026
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2027
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2028
					#$result["function"],當前執行的函式名稱.
2029
					#$result["argu"],所使用的參數.
2030
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2031
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2032
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2033
					#必填參數:
2034
					#$conf["input"],字串,要檢查的字串.
2035
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2036
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2037
					$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
2038
					#可省略參數:
2039
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2040
					#$conf["varEqual"]=array(null,"found");
2041
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2042
					#$conf["varCon"]=array("no_tail"=>" not");
2043
					#參考資料:
2044
					#無.
2045
					#備註:
2046
					#無.
2047
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2048
					unset($conf["search::findSpecifyStrFormat"]);
2049
 
2050
					#如果執行異常
2051
					if($findSpecifyStrFormat["status"]==="false"){
2052
 
2053
						#設置錯誤識別
2054
						$result["status"]="false";
2055
 
2056
						#設置錯誤訊息
2057
						$result["error"]=$findSpecifyStrFormat;
2058
 
2059
						#回傳結果
2060
						return $result;
2061
 
2062
						}#if end
2063
 
2064
					#如果存在";"
2065
					if($findSpecifyStrFormat["found"]==="true"){
2066
 
2067
						#取得無";"的內容
2068
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2069
 
2070
						#取得拆下來的含開頭";"內容
2071
						$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
2072
 
2073
						}#if end
2074
 
2075
					}#else end
2076
 
2077
				}#else end
2078
 
2079
			#檢查是否為 @ 開頭
2080
			#函式說明:
2081
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2082
			#回傳結果:
2083
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2084
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2085
			#$result["function"],當前執行的函式名稱.
2086
			#$result["argu"],所使用的參數.
2087
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2088
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2089
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2090
			#必填參數:
2091
			#$conf["input"],字串,要檢查的字串.
2092
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2093
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2094
			$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
2095
			#可省略參數:
2096
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2097
			#$conf["varEqual"]=array(null,"found");
2098
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2099
			#$conf["varCon"]=array("no_tail"=>" not");
2100
			#參考資料:
2101
			#無.
2102
			#備註:
2103
			#無.
2104
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2105
			unset($conf["search::findSpecifyStrFormat"]);
2106
 
2107
			#如果執行異常
2108
			if($findSpecifyStrFormat["status"]==="false"){
2109
 
2110
				#設置錯誤識別
2111
				$result["status"]="false";
2112
 
2113
				#設置錯誤訊息
2114
				$result["error"]=$findSpecifyStrFormat;
2115
 
2116
				#回傳結果
2117
				return $result;
2118
 
2119
				}#if end
2120
 
2121
			#如果有找到符合格式的內容
2122
			if($findSpecifyStrFormat["found"]==="true"){
2123
 
2124
				#設置 query 的數值
2125
				$info["query"]="@";
2126
 
2127
				#取得後面待處理的內容
2128
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
2129
 
2130
				#函式說明:
2131
				#將字串開頭的特定關鍵字移除.
2132
				#回傳結果:
2133
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2134
				#$result["error"],錯誤訊息陣列.
2135
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2136
				#$result["function"],當前執行的函數名稱.
2137
				#$result["argu"],使用的參數.
2138
				#$result["content"],處理好的的字串內容.
2139
				#$result["deleted"],被移除的內容.
2140
				#必填參數:
2141
				#$conf["stringIn"],字串,要處理的字串.
2142
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2143
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2144
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
2145
				#可省略參數:
2146
				#無.
2147
				#參考資料:
2148
				#無.
2149
				#備註:
2150
				#無.
2151
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2152
				unset($conf["stringProcess::delHeadStr"]);
2153
 
2154
				#如果執行異常
2155
				if($delHeadStr["status"]==="false"){
2156
 
2157
					#設置錯誤識別
2158
					$result["status"]="false";
2159
 
2160
					#設置錯誤訊息
2161
					$result["error"]=$delHeadStr;
2162
 
2163
					#回傳結果
2164
					return $result;
2165
 
2166
					}#if end
2167
 
2168
				#如果有移除開頭的字串
2169
				if($delHeadStr["founded"]==="true"){
2170
 
2171
					#取得處理後的結果 update time..IN..type...value;comment
2172
					$unFormatStr=$delHeadStr["content"];
2173
 
2174
					}#if end
2175
 
2176
				#debug
2177
				#var_dump(__LINE__,$delHeadStr);
2178
 
2179
				}#if end
2180
 
2181
			#反之
2182
			else{
2183
 
2184
				#執行到這邊,代表 query 為一非 @ 的字串
2185
				#函式說明:
2186
				#將指令字串解析成陣列,方便給予 external::callShell 使用
2187
				#回傳結果:
2188
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2189
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2190
				#$result["function"],當前執行的函式名稱.
2191
				#$result["content"],解析好的指令陣列.
2192
				#$result["cmd"],解析好的指令名稱.
2193
				#$result["argus"],解析好的參數陣列.
2194
				#$result["argu"],所使用的參數.
2195
				#必填參數
2196
				#$conf["cmdStr"],字串,要解析的指令字串
2197
				$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
2198
				#可省略參數:
2199
				#無.
2200
				#參考資料:
2201
				#無.
2202
				#備註:
2203
				#無.
2204
				$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
2205
				unset($conf["stringProcess::parseCmdString"]);
2206
 
2207
				#如果執行失敗
2208
				if($parseCmdString["status"]==="false"){
2209
 
2210
					#設置錯誤識別
2211
					$result["status"]="false";
2212
 
2213
					#設置錯誤訊息
2214
					$result["error"]=$parseCmdString;
2215
 
2216
					#debug
2217
					#$result["errorProcessLine"]=$line;
2218
 
2219
					#回傳結果
2220
					return $result;
2221
 
2222
					}#if end
2223
 
2224
				#取得 query 的內容
2225
				$info["query"]=$parseCmdString["content"][0];
2226
 
2227
				#剔除 query以及後面的" "跟\t
2228
				#函式說明:
2229
				#將字串開頭的特定關鍵字移除.
2230
				#回傳結果:
2231
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2232
				#$result["error"],錯誤訊息陣列.
2233
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2234
				#$result["function"],當前執行的函數名稱.
2235
				#$result["argu"],使用的參數.
2236
				#$result["content"],處理好的的字串內容.
2237
				#$result["deleted"],被移除的內容.
2238
				#必填參數:
2239
				#$conf["stringIn"],字串,要處理的字串.
2240
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2241
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2242
				$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
2243
				#可省略參數:
2244
				#無.
2245
				#參考資料:
2246
				#無.
2247
				#備註:
2248
				#無.
2249
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2250
				unset($conf["stringProcess::delHeadStr"]);
2251
 
2252
				#如果執行異常
2253
				if($delHeadStr["status"]==="false"){
2254
 
2255
					#設置錯誤識別
2256
					$result["status"]="false";
2257
 
2258
					#設置錯誤訊息
2259
					$result["error"]=$delHeadStr;
2260
 
2261
					#回傳結果
2262
					return $result;
2263
 
2264
					}#if end
2265
 
2266
				#取得update time..IN..type...value;comment
2267
				$unFormatStr=$delHeadStr["content"];
2268
 
2269
				}#else end
2270
 
2271
			#無窮迴圈
2272
			while(true){
2273
 
253 liveuser 2274
				#如果要debug
2275
				if($conf["debug"]==="true"){
249 liveuser 2276
 
253 liveuser 2277
					#函式說明:
2278
					#撰寫log
2279
					#回傳結果:
2280
					#$result["status"],狀態,"true"或"false".
2281
					#$result["error"],錯誤訊息陣列.
2282
					#$result["function"],當前函式的名稱.
2283
					#$result["argu"],使用的參數.
2284
					#$result["content"],要寫入log的內容字串.
2285
					#必填參數:
2286
					#$conf["path"],字串,log檔案的路徑與名稱.
2287
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2288
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2289
					$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
2290
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2291
					$conf["logs::record"]["fileArgu"]=__FILE__;
2292
					#可省略參數:
2293
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2294
					#$conf["rewrite"]="false";
2295
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2296
					#$conf["returnOnly"]="true";
2297
					#參考資料:
2298
					#無.
2299
					#備註:
2300
					#無.
2301
					$record=logs::record($conf["logs::record"]);
2302
					unset($conf["logs::record"]);
2303
 
2304
					}#if end
2305
 
249 liveuser 2306
				#解析 updateTime..IN..type...value...comment
2307
 
2308
				#判斷是否無 update time
2309
 
2310
				#函式說明:
2311
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2312
				#回傳結果:
2313
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2314
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2315
				#$result["function"],當前執行的函式名稱.
2316
				#$result["argu"],所使用的參數.
2317
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2318
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2319
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2320
				#必填參數:
2321
				#$conf["input"],字串,要檢查的字串.
2322
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2323
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2324
				$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
2325
				#可省略參數:
2326
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2327
				#$conf["varEqual"]=array(null,"found");
2328
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2329
				#$conf["varCon"]=array("no_tail"=>" not");
2330
				#參考資料:
2331
				#無.
2332
				#備註:
2333
				#無.
2334
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2335
				unset($conf["search::findSpecifyStrFormat"]);
2336
 
2337
				#如果執行異常
2338
				if($findSpecifyStrFormat["status"]==="false"){
2339
 
2340
					#設置錯誤識別
2341
					$result["status"]="false";
2342
 
2343
					#設置錯誤訊息
2344
					$result["error"]=$findSpecifyStrFormat;
2345
 
2346
					#回傳結果
2347
					return $result;
2348
 
2349
					}#if end
2350
 
2351
				#如果有找到符合格式的內容
2352
				if($findSpecifyStrFormat["found"]==="true"){
2353
 
2354
					#代表沒有 update time 欄位,因此儲存預設的TTL
2355
					$info["update"]=&$result["defaultTTL"];
2356
 
2357
					#取得剩下的 ...type...value;comment
2358
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
2359
 
2360
					#設置該行沒有指定 update time
2361
					$noUpdateTime="true";
2362
 
253 liveuser 2363
					#如果要debug
2364
					if($conf["debug"]==="true"){
2365
 
2366
						#函式說明:
2367
						#撰寫log
2368
						#回傳結果:
2369
						#$result["status"],狀態,"true"或"false".
2370
						#$result["error"],錯誤訊息陣列.
2371
						#$result["function"],當前函式的名稱.
2372
						#$result["argu"],使用的參數.
2373
						#$result["content"],要寫入log的內容字串.
2374
						#必填參數:
2375
						#$conf["path"],字串,log檔案的路徑與名稱.
2376
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2377
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2378
						$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
2379
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2380
						$conf["logs::record"]["fileArgu"]=__FILE__;
2381
						#可省略參數:
2382
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2383
						#$conf["rewrite"]="false";
2384
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2385
						#$conf["returnOnly"]="true";
2386
						#參考資料:
2387
						#無.
2388
						#備註:
2389
						#無.
2390
						$record=logs::record($conf["logs::record"]);
2391
						unset($conf["logs::record"]);
2392
 
2393
						}#if end
249 liveuser 2394
 
2395
					}#if end
2396
 
2397
				#反之
2398
				else{
2399
 
2400
					#設置該行有指定 update time
2401
					$noUpdateTime="false";
2402
 
2403
					#如果有指定 update time
2404
					if($noUpdateTime==="false"){
2405
 
2406
						#要來解析 update time
2407
						#函式說明:
2408
						#將字串進行解析,變成多個參數.
2409
						#回傳結果:
2410
						#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2411
						#$result["function"],當前執行的函式內容.
2412
						#$result["error"],錯誤訊息陣列.
2413
						#$result["content"],參數陣列.
2414
						#$result["count"],總共有幾個參數.
2415
						#必填參數:
2416
						#$conf["input"],字串,要解析成參數的字串.
2417
						$conf["stringProcess::parse"]["input"]=$unFormatStr;
2418
						#可省略參數:
2419
						#無.
2420
						#參考資料:
2421
						#無.
2422
						#備註:
2423
						#無.
2424
						$parse=stringProcess::parse($conf["stringProcess::parse"]);
2425
						unset($conf["stringProcess::parse"]);
2426
 
2427
						#如果執行異常
2428
						if($parse["status"]==="false"){
2429
 
2430
							#設置錯誤識別
2431
							$result["status"]="false";
2432
 
2433
							#設置錯誤訊息
2434
							$result["error"]=$parse;
2435
 
2436
							#回傳結果
2437
							return $result;
2438
 
2439
							}#if end
2440
 
2441
						#取得更新時間
2442
						$info["update"]=$parse["content"][0];
2443
 
2444
						#取得 update time 後面的內容
2445
						#函式說明:
2446
						#將字串開頭的特定關鍵字移除.
2447
						#回傳結果:
2448
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2449
						#$result["error"],錯誤訊息陣列.
2450
						#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2451
						#$result["function"],當前執行的函數名稱.
2452
						#$result["argu"],使用的參數.
2453
						#$result["content"],處理好的的字串內容.
2454
						#$result["deleted"],被移除的內容.
2455
						#必填參數:
2456
						#$conf["stringIn"],字串,要處理的字串.
2457
						$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2458
						#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2459
						$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
2460
						#可省略參數:
2461
						#無.
2462
						#參考資料:
2463
						#無.
2464
						#備註:
2465
						#無.
2466
						$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2467
						unset($conf["stringProcess::delHeadStr"]);
2468
 
2469
						#如果執行異常
2470
						if($delHeadStr["status"]==="false"){
2471
 
2472
							#設置錯誤識別
2473
							$result["status"]="false";
2474
 
2475
							#設置錯誤訊息
2476
							$result["error"]=$delHeadStr;
2477
 
2478
							#回傳結果
2479
							return $result;
2480
 
2481
							}#if end
2482
 
2483
						#取得...IN...value;comment
2484
						$unFormatStr=$delHeadStr["content"];
2485
 
2486
						}#if end
2487
 
2488
					#取得 ...IN... 後面的內容
2489
					#函式說明:
2490
					#將字串開頭的特定關鍵字移除.
2491
					#回傳結果:
2492
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2493
					#$result["error"],錯誤訊息陣列.
2494
					#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2495
					#$result["function"],當前執行的函數名稱.
2496
					#$result["argu"],使用的參數.
2497
					#$result["content"],處理好的的字串內容.
2498
					#$result["deleted"],被移除的內容.
2499
					#必填參數:
2500
					#$conf["stringIn"],字串,要處理的字串.
2501
					$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2502
					#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2503
					$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
2504
					#可省略參數:
2505
					#無.
2506
					#參考資料:
2507
					#無.
2508
					#備註:
2509
					#無.
2510
					$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2511
					unset($conf["stringProcess::delHeadStr"]);
2512
 
2513
					#如果執行異常
2514
					if($delHeadStr["status"]==="false"){
2515
 
2516
						#設置錯誤識別
2517
						$result["status"]="false";
2518
 
2519
						#設置錯誤訊息
2520
						$result["error"]=$delHeadStr;
2521
 
2522
						#回傳結果
2523
						return $result;
2524
 
2525
						}#if end
2526
 
2527
					#取得IN...value;comment
2528
					$unFormatStr=$delHeadStr["content"];
2529
 
253 liveuser 2530
					#如果要debug
2531
					if($conf["debug"]==="true"){
249 liveuser 2532
 
253 liveuser 2533
						#函式說明:
2534
						#撰寫log
2535
						#回傳結果:
2536
						#$result["status"],狀態,"true"或"false".
2537
						#$result["error"],錯誤訊息陣列.
2538
						#$result["function"],當前函式的名稱.
2539
						#$result["argu"],使用的參數.
2540
						#$result["content"],要寫入log的內容字串.
2541
						#必填參數:
2542
						#$conf["path"],字串,log檔案的路徑與名稱.
2543
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2544
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2545
						$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
2546
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2547
						$conf["logs::record"]["fileArgu"]=__FILE__;
2548
						#可省略參數:
2549
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2550
						#$conf["rewrite"]="false";
2551
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2552
						#$conf["returnOnly"]="true";
2553
						#參考資料:
2554
						#無.
2555
						#備註:
2556
						#無.
2557
						$record=logs::record($conf["logs::record"]);
2558
						unset($conf["logs::record"]);
2559
 
2560
						}#if end
2561
 
249 liveuser 2562
					}#else end
2563
 
2564
				#解析 type...value;comment
2565
				#函式說明:
2566
				#將字串進行解析,變成多個參數.
2567
				#回傳結果:
2568
				#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2569
				#$result["function"],當前執行的函式內容.
2570
				#$result["error"],錯誤訊息陣列.
2571
				#$result["content"],參數陣列.
2572
				#$result["count"],總共有幾個參數.
2573
				#必填參數:
2574
				#$conf["input"],字串,要解析成參數的字串.
2575
				$conf["stringProcess::parse"]["input"]=$unFormatStr;
2576
				#可省略參數:
2577
				#無.
2578
				#參考資料:
2579
				#無.
2580
				#備註:
2581
				#無.
2582
				$parse=stringProcess::parse($conf["stringProcess::parse"]);
2583
				unset($conf["stringProcess::parse"]);
2584
 
2585
				#如果執行異常
2586
				if($parse["status"]==="false"){
2587
 
2588
					#設置錯誤識別
2589
					$result["status"]="false";
2590
 
2591
					#設置錯誤訊息
2592
					$result["error"]=$parse;
2593
 
2594
					#回傳結果
2595
					return $result;
2596
 
2597
					}#if end
2598
 
2599
				#取得 type
2600
				$info["type"]=$parse["content"][0];
2601
 
2602
				#取得 type...後面的value;comment內容
2603
				#函式說明:
2604
				#將字串開頭的特定關鍵字移除.
2605
				#回傳結果:
2606
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2607
				#$result["error"],錯誤訊息陣列.
2608
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2609
				#$result["function"],當前執行的函數名稱.
2610
				#$result["argu"],使用的參數.
2611
				#$result["content"],處理好的的字串內容.
2612
				#$result["deleted"],被移除的內容.
2613
				#必填參數:
2614
				#$conf["stringIn"],字串,要處理的字串.
2615
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2616
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2617
				$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
2618
				#可省略參數:
2619
				#無.
2620
				#參考資料:
2621
				#無.
2622
				#備註:
2623
				#無.
2624
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2625
				unset($conf["stringProcess::delHeadStr"]);
2626
 
2627
				#如果執行異常
2628
				if($delHeadStr["status"]==="false"){
2629
 
2630
					#設置錯誤識別
2631
					$result["status"]="false";
2632
 
2633
					#設置錯誤訊息
2634
					$result["error"]=$delHeadStr;
2635
 
2636
					#回傳結果
2637
					return $result;
2638
 
2639
					}#if end
2640
 
2641
				#取得 value;comment
2642
				$unFormatStr=$delHeadStr["content"];
2643
 
2644
				#如果有要合併回去的內容
2645
				if(isset($unFormatStr2add)){
2646
 
2647
					#合併回去內容
2648
					$unFormatStr=$unFormatStr.$unFormatStr2add;
2649
 
2650
					#移除用不到的變數
2651
					unset($unFormatStr2add);
2652
 
2653
					}#if end
2654
 
253 liveuser 2655
				#如果要debug
2656
				if($conf["debug"]==="true"){
249 liveuser 2657
 
253 liveuser 2658
					#函式說明:
2659
					#撰寫log
2660
					#回傳結果:
2661
					#$result["status"],狀態,"true"或"false".
2662
					#$result["error"],錯誤訊息陣列.
2663
					#$result["function"],當前函式的名稱.
2664
					#$result["argu"],使用的參數.
2665
					#$result["content"],要寫入log的內容字串.
2666
					#必填參數:
2667
					#$conf["path"],字串,log檔案的路徑與名稱.
2668
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2669
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2670
					$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
2671
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2672
					$conf["logs::record"]["fileArgu"]=__FILE__;
2673
					#可省略參數:
2674
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2675
					#$conf["rewrite"]="false";
2676
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2677
					#$conf["returnOnly"]="true";
2678
					#參考資料:
2679
					#無.
2680
					#備註:
2681
					#無.
2682
					$record=logs::record($conf["logs::record"]);
2683
					unset($conf["logs::record"]);
2684
 
2685
					}#if end
2686
 
249 liveuser 2687
				#如果type不為 CNAME 跟 TXT 跟 SOA
2688
				if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" ){
2689
 
2690
					#儲存value
2691
					$info["value"]=$unFormatStr;
2692
 
2693
					#判斷是否有 ";" 存在
2694
					#函式說明:
2695
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2696
					#回傳結果:
2697
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2698
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2699
					#$result["function"],當前執行的函式名稱.
2700
					#$result["argu"],所使用的參數.
2701
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2702
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2703
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2704
					#必填參數:
2705
					#$conf["input"],字串,要檢查的字串.
2706
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2707
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2708
					$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
2709
					#可省略參數:
2710
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2711
					#$conf["varEqual"]=array(null,"found");
2712
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2713
					#$conf["varCon"]=array("no_tail"=>" not");
2714
					#參考資料:
2715
					#無.
2716
					#備註:
2717
					#無.
2718
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2719
					unset($conf["search::findSpecifyStrFormat"]);
2720
 
2721
					#如果執行異常
2722
					if($findSpecifyStrFormat["status"]==="false"){
2723
 
2724
						#設置錯誤識別
2725
						$result["status"]="false";
2726
 
2727
						#設置錯誤訊息
2728
						$result["error"]=$findSpecifyStrFormat;
2729
 
2730
						#回傳結果
2731
						return $result;
2732
 
2733
						}#if end
2734
 
2735
					#如果有 ";"
2736
					if($findSpecifyStrFormat["found"]==="true"){
2737
 
2738
						#儲存value
2739
						$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
2740
 
2741
						#儲存comment
2742
						$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
2743
 
2744
						}#if end
2745
 
2746
					#儲存該筆RR
2747
					$result["content"][]=$info;
2748
 
2749
					#解析完畢換下一行
2750
					continue 2;
2751
 
2752
					}#if end
2753
 
2754
				#執行到這邊,代表type為CNAME或TXT或SOA
2755
 
2756
				#如果 type 是 SOA
2757
				if($info["type"]==="SOA"){
2758
 
253 liveuser 2759
					#如果要debug
2760
					if($conf["debug"]==="true"){
2761
 
2762
						#函式說明:
2763
						#撰寫log
2764
						#回傳結果:
2765
						#$result["status"],狀態,"true"或"false".
2766
						#$result["error"],錯誤訊息陣列.
2767
						#$result["function"],當前函式的名稱.
2768
						#$result["argu"],使用的參數.
2769
						#$result["content"],要寫入log的內容字串.
2770
						#必填參數:
2771
						#$conf["path"],字串,log檔案的路徑與名稱.
2772
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2773
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2774
						$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
2775
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2776
						$conf["logs::record"]["fileArgu"]=__FILE__;
2777
						#可省略參數:
2778
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2779
						#$conf["rewrite"]="false";
2780
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2781
						#$conf["returnOnly"]="true";
2782
						#參考資料:
2783
						#無.
2784
						#備註:
2785
						#無.
2786
						$record=logs::record($conf["logs::record"]);
2787
						unset($conf["logs::record"]);
2788
 
2789
						}#if end
2790
 
249 liveuser 2791
					#SOA 範例
2792
					#@	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
2793
 
2794
					#再度嘗試分割
2795
					#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
2796
 
2797
					#函式說明:
2798
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2799
					#回傳結果:
2800
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2801
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2802
					#$result["function"],當前執行的函式名稱.
2803
					#$result["argu"],所使用的參數.
2804
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2805
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2806
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2807
					#必填參數:
2808
					#$conf["input"],字串,要檢查的字串.
2809
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2810
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2811
					$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
2812
					#可省略參數:
2813
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2814
					#$conf["varEqual"]=array(null,"found");
2815
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2816
					#$conf["varCon"]=array("no_tail"=>" not");
2817
					#參考資料:
2818
					#無.
2819
					#備註:
2820
					#無.
2821
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2822
					unset($conf["search::findSpecifyStrFormat"]);
2823
 
2824
					#如果執行異常
2825
					if($findSpecifyStrFormat["status"]==="false"){
2826
 
2827
						#設置錯誤識別
2828
						$result["status"]="false";
2829
 
2830
						#設置錯誤訊息
2831
						$result["error"]=$findSpecifyStrFormat;
2832
 
2833
						#回傳結果
2834
						return $result;
2835
 
2836
						}#if end
2837
 
2838
					#如果存在"("
2839
					if($findSpecifyStrFormat["found"]==="true"){
2840
 
2841
						#取得無"("的內容
2842
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2843
 
2844
						#取得拆下來的含開頭"("內容
2845
						$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
2846
 
2847
						}#if end
2848
 
2849
					#反之
2850
					else{
2851
 
2852
						#函式說明:
2853
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2854
						#回傳結果:
2855
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2856
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
2857
						#$result["function"],當前執行的函式名稱.
2858
						#$result["argu"],所使用的參數.
2859
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2860
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2861
						#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2862
						#必填參數:
2863
						#$conf["input"],字串,要檢查的字串.
2864
						$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2865
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2866
						$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
2867
						#可省略參數:
2868
						#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2869
						#$conf["varEqual"]=array(null,"found");
2870
						#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2871
						#$conf["varCon"]=array("no_tail"=>" not");
2872
						#參考資料:
2873
						#無.
2874
						#備註:
2875
						#無.
2876
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2877
						unset($conf["search::findSpecifyStrFormat"]);
2878
 
2879
						#如果執行異常
2880
						if($findSpecifyStrFormat["status"]==="false"){
2881
 
2882
							#設置錯誤識別
2883
							$result["status"]="false";
2884
 
2885
							#設置錯誤訊息
2886
							$result["error"]=$findSpecifyStrFormat;
2887
 
2888
							#回傳結果
2889
							return $result;
2890
 
2891
							}#if end
2892
 
2893
						#如果存在"
2894
						if($findSpecifyStrFormat["found"]==="true"){
2895
 
2896
							#取得無"的內容
2897
							$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2898
 
2899
							#取得拆下來的含開頭"內容
2900
							$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
2901
 
2902
							}#if end
2903
 
2904
						#反之
2905
						else{
2906
 
2907
							#函式說明:
2908
							#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2909
							#回傳結果:
2910
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2911
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
2912
							#$result["function"],當前執行的函式名稱.
2913
							#$result["argu"],所使用的參數.
2914
							#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2915
							#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2916
							#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2917
							#必填參數:
2918
							#$conf["input"],字串,要檢查的字串.
2919
							$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2920
							#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2921
							$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
2922
							#可省略參數:
2923
							#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2924
							#$conf["varEqual"]=array(null,"found");
2925
							#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2926
							#$conf["varCon"]=array("no_tail"=>" not");
2927
							#參考資料:
2928
							#無.
2929
							#備註:
2930
							#無.
2931
							$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2932
							unset($conf["search::findSpecifyStrFormat"]);
2933
 
2934
							#如果執行異常
2935
							if($findSpecifyStrFormat["status"]==="false"){
2936
 
2937
								#設置錯誤識別
2938
								$result["status"]="false";
2939
 
2940
								#設置錯誤訊息
2941
								$result["error"]=$findSpecifyStrFormat;
2942
 
2943
								#回傳結果
2944
								return $result;
2945
 
2946
								}#if end
2947
 
2948
							#如果存在";"
2949
							if($findSpecifyStrFormat["found"]==="true"){
2950
 
2951
								#取得無";"的內容
2952
								$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2953
 
2954
								#取得拆下來的含開頭";"內容
2955
								$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
2956
 
2957
								}#if end
2958
 
2959
							}#else end
2960
 
2961
						}#else end
2962
 
2963
					#取得 serial number
2964
					#函式說明:
2965
					#將字串進行解析,變成多個參數.
2966
					#回傳結果:
2967
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2968
					#$result["function"],當前執行的函式內容.
2969
					#$result["error"],錯誤訊息陣列.
2970
					#$result["content"],參數陣列.
2971
					#$result["count"],總共有幾個參數.
2972
					#必填參數:
2973
					#$conf["input"],字串,要解析成參數的字串.
2974
					$conf["stringProcess::parse"]["input"]=$unFormatStr;
2975
					#可省略參數:
2976
					#無.
2977
					#參考資料:
2978
					#無.
2979
					#備註:
2980
					#無.
2981
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
2982
					unset($conf["stringProcess::parse"]);
2983
 
2984
					#如果執行異常
2985
					if($parse["status"]==="false"){
2986
 
2987
						#設置錯誤識別
2988
						$result["status"]="false";
2989
 
2990
						#設置錯誤訊息
2991
						$result["error"]=$parse;
2992
 
2993
						#回傳結果
2994
						return $result;
2995
 
2996
						}#if end
2997
 
2998
					#取得serial number
2999
					$serialNo=$parse["content"][2];
3000
 
3001
					#serialNo+1
3002
					$serialNo++;
3003
 
3004
					#回存
3005
					$parse["content"][2]=(string)$serialNo;
3006
 
3007
					#函式說明:
3008
					#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
3009
					#回傳的結果:
3010
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3011
					#$result["function"],當前執行的function名稱
3012
					#$result["error"],錯誤訊息陣列.
3013
					#$result["content"],處理好的字串.
3014
					#$result["argu"],使用的參數.
3015
					#必填參數:
3016
					#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
3017
					$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
3018
					#可省略參數:
3019
					#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
3020
					$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
3021
					#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
3022
					$conf["arrays::arrayToString"]["skipEnd"]="true";
3023
					#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
3024
					#$conf["spiltSymbolAtStart"]="";
3025
					#參考資料:
3026
					#無.
3027
					#備註:
3028
					#無.
3029
					$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
3030
					unset($conf["arrays::arrayToString"]);
3031
 
3032
					#如果執行異常
3033
					if($arrayToString["status"]==="false"){
3034
 
3035
						#設置錯誤識別
3036
						$result["status"]="false";
3037
 
3038
						#設置錯誤訊息
3039
						$result["error"]=$arrayToString;
3040
 
3041
						#回傳結果
3042
						return $result;
3043
 
3044
						}#if end
3045
 
3046
					#取得更新 serial number 後的 SOA value string
3047
					$unFormatStr=$arrayToString["content"];
3048
 
3049
					#如果有要合併回去的內容
3050
					if(isset($unFormatStr2add)){
3051
 
3052
						#合併回去內容
3053
						$unFormatStr=$unFormatStr.$unFormatStr2add;
3054
 
3055
						#移除用不到的變數
3056
						unset($unFormatStr2add);
3057
 
3058
						}#if end
3059
 
3060
					#假設剩下的沒有註解都是 value
3061
					$info["value"]=$unFormatStr;
3062
 
3063
					#函式說明:
3064
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3065
					#回傳結果:
3066
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3067
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
3068
					#$result["function"],當前執行的函式名稱.
3069
					#$result["argu"],所使用的參數.
3070
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3071
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3072
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3073
					#必填參數:
3074
					#$conf["input"],字串,要檢查的字串.
3075
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3076
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3077
					$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3078
					#可省略參數:
3079
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3080
					#$conf["varEqual"]=array(null,"found");
3081
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3082
					#$conf["varCon"]=array("no_tail"=>" not");
3083
					#參考資料:
3084
					#無.
3085
					#備註:
3086
					#無.
3087
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3088
					unset($conf["search::findSpecifyStrFormat"]);
3089
 
3090
					#如果執行異常
3091
					if($findSpecifyStrFormat["status"]==="false"){
3092
 
3093
						#設置錯誤識別
3094
						$result["status"]="false";
3095
 
3096
						#設置錯誤訊息
3097
						$result["error"]=$findSpecifyStrFormat;
3098
 
3099
						#回傳結果
3100
						return $result;
3101
 
3102
						}#if end
3103
 
3104
					#如果有符合格式
3105
					if($findSpecifyStrFormat["found"]==="true"){
3106
 
3107
						#儲存 value
3108
						$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3109
 
3110
						#儲存 comment
3111
						$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3112
 
3113
						}#if end
3114
 
3115
					#儲存該筆RR
3116
					$result["content"][]=$info;
3117
 
3118
					#換下解析下筆RR
3119
					continue 2;
3120
 
3121
					}#if end
3122
 
3123
				#執行到這邊代表不是 SOA
3124
 
3125
				#尋找是否有(...)...的內容存在
3126
				#函式說明:
3127
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3128
				#回傳結果:
3129
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3130
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3131
				#$result["function"],當前執行的函式名稱.
3132
				#$result["argu"],所使用的參數.
3133
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3134
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3135
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3136
				#必填參數:
3137
				#$conf["input"],字串,要檢查的字串.
3138
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3139
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3140
				$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
3141
				#可省略參數:
3142
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3143
				#$conf["varEqual"]=array(null,"found");
3144
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3145
				#$conf["varCon"]=array("no_tail"=>" not");
3146
				#參考資料:
3147
				#無.
3148
				#備註:
3149
				#無.
3150
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3151
				unset($conf["search::findSpecifyStrFormat"]);
3152
 
3153
				#如果執行異常
3154
				if($findSpecifyStrFormat["status"]==="false"){
3155
 
3156
					#設置錯誤識別
3157
					$result["status"]="false";
3158
 
3159
					#設置錯誤訊息
3160
					$result["error"]=$findSpecifyStrFormat;
3161
 
3162
					#回傳結果
3163
					return $result;
3164
 
3165
					}#if end
3166
 
3167
				#如果有 有符合 ($value);${comment} 的格式
3168
				if($findSpecifyStrFormat["found"]==="true"){
3169
 
3170
					#儲存value
3171
					$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
3172
 
3173
					#儲存comment
3174
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3175
 
3176
					#儲存 RR 的記錄
3177
					$result["content"][]=$info;
3178
 
3179
					#跳到下一筆要解析的RR
3180
					continue 2;
3181
 
3182
					}#if end
3183
 
3184
				#執行到這邊代表沒有 (...)... 的內容存在
3185
 
3186
				#尋找是否有 (...) 的內容存在
3187
				#函式說明:
3188
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3189
				#回傳結果:
3190
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3191
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3192
				#$result["function"],當前執行的函式名稱.
3193
				#$result["argu"],所使用的參數.
3194
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3195
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3196
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3197
				#必填參數:
3198
				#$conf["input"],字串,要檢查的字串.
3199
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3200
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3201
				$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
3202
				#可省略參數:
3203
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3204
				#$conf["varEqual"]=array(null,"found");
3205
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3206
				#$conf["varCon"]=array("no_tail"=>" not");
3207
				#參考資料:
3208
				#無.
3209
				#備註:
3210
				#無.
3211
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3212
				unset($conf["search::findSpecifyStrFormat"]);
3213
 
3214
				#如果執行異常
3215
				if($findSpecifyStrFormat["status"]==="false"){
3216
 
3217
					#設置錯誤識別
3218
					$result["status"]="false";
3219
 
3220
					#設置錯誤訊息
3221
					$result["error"]=$findSpecifyStrFormat;
3222
 
3223
					#回傳結果
3224
					return $result;
3225
 
3226
					}#if end
3227
 
3228
				#如果有 有符合 ($value);${comment} 的格式
3229
				if($findSpecifyStrFormat["found"]==="true"){
3230
 
3231
					#儲存value
3232
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3233
 
3234
					#儲存 RR 的記錄
3235
					$result["content"][]=$info;
3236
 
3237
					#跳到下一筆要解析的RR
3238
					continue 2;
3239
 
3240
					}#if end
3241
 
3242
				#執行到這邊代表沒有 (...) 的內容存在
3243
 
3244
				#尋找有無 "...";... 的內容存在
3245
				#函式說明:
3246
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3247
				#回傳結果:
3248
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3249
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3250
				#$result["function"],當前執行的函式名稱.
3251
				#$result["argu"],所使用的參數.
3252
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3253
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3254
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3255
				#必填參數:
3256
				#$conf["input"],字串,要檢查的字串.
3257
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3258
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3259
				$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
3260
				#可省略參數:
3261
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3262
				#$conf["varEqual"]=array(null,"found");
3263
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3264
				#$conf["varCon"]=array("no_tail"=>" not");
3265
				#參考資料:
3266
				#無.
3267
				#備註:
3268
				#無.
3269
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3270
				unset($conf["search::findSpecifyStrFormat"]);
3271
 
3272
				#如果執行異常
3273
				if($findSpecifyStrFormat["status"]==="false"){
3274
 
3275
					#設置錯誤識別
3276
					$result["status"]="false";
3277
 
3278
					#設置錯誤訊息
3279
					$result["error"]=$findSpecifyStrFormat;
3280
 
3281
					#回傳結果
3282
					return $result;
3283
 
3284
					}#if end
3285
 
3286
				#如果有 有符合 "$value";${comment} 的格式
3287
				if($findSpecifyStrFormat["found"]==="true"){
3288
 
3289
					#儲存value
3290
					$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
3291
 
3292
					#儲存comment
3293
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3294
 
3295
					#儲存 RR 的記錄
3296
					$result["content"][]=$info;
3297
 
3298
					#跳到下一筆要解析的RR
3299
					continue 2;
3300
 
3301
					}#if end
3302
 
3303
				#執行到這邊代表沒有 "$value";${comment} 的格式
3304
 
3305
				#尋找有無 "..." 的內容存在
3306
				#函式說明:
3307
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3308
				#回傳結果:
3309
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3310
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3311
				#$result["function"],當前執行的函式名稱.
3312
				#$result["argu"],所使用的參數.
3313
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3314
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3315
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3316
				#必填參數:
3317
				#$conf["input"],字串,要檢查的字串.
3318
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3319
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3320
				$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
3321
				#可省略參數:
3322
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3323
				#$conf["varEqual"]=array(null,"found");
3324
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3325
				#$conf["varCon"]=array("no_tail"=>" not");
3326
				#參考資料:
3327
				#無.
3328
				#備註:
3329
				#無.
3330
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3331
				unset($conf["search::findSpecifyStrFormat"]);
3332
 
3333
				#如果執行異常
3334
				if($findSpecifyStrFormat["status"]==="false"){
3335
 
3336
					#設置錯誤識別
3337
					$result["status"]="false";
3338
 
3339
					#設置錯誤訊息
3340
					$result["error"]=$findSpecifyStrFormat;
3341
 
3342
					#回傳結果
3343
					return $result;
3344
 
3345
					}#if end
3346
 
3347
				#如果有 有符合 "$value" 的格式
3348
				if($findSpecifyStrFormat["found"]==="true"){
3349
 
3350
					#儲存value
3351
					$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
3352
 
3353
					#儲存 RR 的記錄
3354
					$result["content"][]=$info;
3355
 
3356
					#跳到下一筆要解析的RR
3357
					continue 2;
3358
 
3359
					}#if end
3360
 
3361
				#執行到這邊代表沒有 "$value" 格式的內容
3362
 
3363
				#檢查是否有 $value;$comment 格式的內容
3364
				#函式說明:
3365
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3366
				#回傳結果:
3367
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3368
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3369
				#$result["function"],當前執行的函式名稱.
3370
				#$result["argu"],所使用的參數.
3371
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3372
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3373
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3374
				#必填參數:
3375
				#$conf["input"],字串,要檢查的字串.
3376
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3377
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3378
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3379
				#可省略參數:
3380
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3381
				#$conf["varEqual"]=array(null,"found");
3382
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3383
				#$conf["varCon"]=array("no_tail"=>" not");
3384
				#參考資料:
3385
				#無.
3386
				#備註:
3387
				#無.
3388
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3389
				unset($conf["search::findSpecifyStrFormat"]);
3390
 
3391
				#如果執行異常
3392
				if($findSpecifyStrFormat["status"]==="false"){
3393
 
3394
					#設置錯誤識別
3395
					$result["status"]="false";
3396
 
3397
					#設置錯誤訊息
3398
					$result["error"]=$findSpecifyStrFormat;
3399
 
3400
					#回傳結果
3401
					return $result;
3402
 
3403
					}#if end
3404
 
3405
				#如果有 有符合 "$value" 的格式
3406
				if($findSpecifyStrFormat["found"]==="true"){
3407
 
3408
					#儲存value
3409
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3410
 
3411
					#儲存comment
3412
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3413
 
3414
					#儲存 RR 的記錄
3415
					$result["content"][]=$info;
3416
 
3417
					#跳到下一筆要解析的RR
3418
					continue 2;
3419
 
3420
					}#if end
3421
 
3422
				#執行到這邊代表沒有 ${value};${comment} 格式的內容
3423
 
3424
				#亦即剩下的內容都是 value
3425
 
3426
				#儲存value
3427
				$info["value"]=$unFormatStr;
3428
 
3429
				#儲存 RR 的記錄
3430
				$result["content"][]=$info;
3431
 
3432
				#跳到下一筆要解析的RR
3433
				continue 2;
3434
 
3435
				}#while end
3436
 
3437
			}#foreach end
3438
 
253 liveuser 3439
		#如果要debug
3440
		if($conf["debug"]==="true"){
249 liveuser 3441
 
253 liveuser 3442
			#函式說明:
3443
			#撰寫log
3444
			#回傳結果:
3445
			#$result["status"],狀態,"true"或"false".
3446
			#$result["error"],錯誤訊息陣列.
3447
			#$result["function"],當前函式的名稱.
3448
			#$result["argu"],使用的參數.
3449
			#$result["content"],要寫入log的內容字串.
3450
			#必填參數:
3451
			#$conf["path"],字串,log檔案的路徑與名稱.
3452
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3453
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3454
			$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR fin.".PHP_EOL;
3455
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3456
			$conf["logs::record"]["fileArgu"]=__FILE__;
3457
			#可省略參數:
3458
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3459
			#$conf["rewrite"]="false";
3460
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3461
			#$conf["returnOnly"]="true";
3462
			#參考資料:
3463
			#無.
3464
			#備註:
3465
			#無.
3466
			$record=logs::record($conf["logs::record"]);
3467
			unset($conf["logs::record"]);
3468
 
3469
			}#if end
3470
 
249 liveuser 3471
		#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
3472
 
3473
		#針對每個要新增的RR記錄
3474
		foreach($conf["add"] as $newRR){
3475
 
3476
			#針對 zone file 中既有的每個RR記錄
3477
			foreach($result["content"] as $index => $oldRR){
3478
 
3479
				#如果既有的跟新的RR都為 $ORIGIN
3480
				if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
3481
 
3482
					#取代既有的 RR
3483
					$result["content"][$index]=$newRR;
3484
 
3485
					#換看下一筆newRR
3486
					continue 2;
3487
 
3488
					}#if end
3489
 
3490
				#如果既有的跟新的RR都為 $TTL
3491
				if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
3492
 
3493
					#取代既有的 RR
3494
					$result["content"][$index]=$newRR;
3495
 
3496
					#換看下一筆newRR
3497
					continue 2;
3498
 
3499
					}#if end
3500
 
253 liveuser 3501
				#如果新舊資料都有query資訊
3502
				if( isset($newRR["query"]) && isset($oldRR["query"]) ){
249 liveuser 3503
 
253 liveuser 3504
					#如果跟既有的 query、type、value 有相同
3505
					if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
249 liveuser 3506
 
253 liveuser 3507
						#如果新 RR 有 update time
3508
						if(isset($newRR["update"])){
249 liveuser 3509
 
253 liveuser 3510
							#如果新舊 update time 不相同
3511
							if( $newRR["update"] !== $oldRR["update"] ){
249 liveuser 3512
 
253 liveuser 3513
								#取代既有的 RR
3514
								$result["content"][$index]=$newRR;
3515
 
3516
								#換看下一筆newRR
3517
								continue 2;
3518
 
3519
								}#if end
3520
 
3521
							}#if end
249 liveuser 3522
 
253 liveuser 3523
						#反之既有的 update time 若跟 global TTL 不一樣
3524
						else if( $oldRR["update"] !== $result["defaultTTL"] ){
3525
 
3526
							#更新為 global TTL
3527
							$result["content"][$index]["update"]=$result["defaultTTL"];
3528
 
249 liveuser 3529
							}#if end
253 liveuser 3530
 
3531
						#如果新 RR 有 comment
3532
						if( isset($newRR["comment"]) ){
249 liveuser 3533
 
253 liveuser 3534
							#更新既有 RR 的 comment
3535
							$result["content"][$index]["comment"]=$newRR["comment"];
249 liveuser 3536
 
253 liveuser 3537
							#換看下一筆newRR
3538
							continue 2;
249 liveuser 3539
 
253 liveuser 3540
							}#if end
3541
 
3542
						#反之,如果有既有 comment
3543
						else if(isset($result["content"][$index]["comment"])){
249 liveuser 3544
 
253 liveuser 3545
							#移除既有 comment
3546
							unset($result["content"][$index]["comment"]);
3547
 
3548
							#換看下一筆newRR
3549
							continue 2;
249 liveuser 3550
 
253 liveuser 3551
							}#else end
249 liveuser 3552
 
253 liveuser 3553
						}#if end
249 liveuser 3554
 
3555
					}#if end
253 liveuser 3556
 
249 liveuser 3557
				}#foreach end
3558
 
3559
			#儲存確定要新增的RR
3560
			$result["content"][]=$newRR;
3561
 
3562
			}#foreach end
3563
 
3564
		#/*
3565
		#debug
3566
		#函式說明:
3567
		#撰寫log
3568
		#回傳結果:
3569
		#$result["status"],狀態,"true"或"false".
3570
		#$result["error"],錯誤訊息陣列.
3571
		#$result["function"],當前函式的名稱.
3572
		#$result["argu"],使用的參數.
3573
		#$result["content"],要寫入log的內容字串.
3574
		#必填參數:
3575
		#$conf["path"],字串,log檔案的路徑與名稱.
3576
		$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3577
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3578
		$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
3579
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3580
		$conf["logs::record"]["fileArgu"]=__FILE__;
3581
		#可省略參數:
3582
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3583
		#$conf["rewrite"]="false";
3584
		#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3585
		#$conf["returnOnly"]="true";
3586
		#參考資料:
3587
		#無.
3588
		#備註:
3589
		#無.
3590
		$record=logs::record($conf["logs::record"]);
3591
		unset($conf["logs::record"]);
3592
		#*/
3593
 
3594
		#/*
3595
		#debug
3596
		#函式說明:
3597
		#撰寫log
3598
		#回傳結果:
3599
		#$result["status"],狀態,"true"或"false".
3600
		#$result["error"],錯誤訊息陣列.
3601
		#$result["function"],當前函式的名稱.
3602
		#$result["argu"],使用的參數.
3603
		#$result["content"],要寫入log的內容字串.
3604
		#必填參數:
3605
		#$conf["path"],字串,log檔案的路徑與名稱.
3606
		$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3607
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3608
		$conf["logs::record"]["content"]=$result["content"];
3609
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3610
		$conf["logs::record"]["fileArgu"]=__FILE__;
3611
		#可省略參數:
3612
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3613
		#$conf["rewrite"]="false";
3614
		#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3615
		#$conf["returnOnly"]="true";
3616
		#參考資料:
3617
		#無.
3618
		#備註:
3619
		#無.
3620
		$record=logs::record($conf["logs::record"]);
3621
		unset($conf["logs::record"]);
3622
		#*/
3623
 
3624
		#初始化要寫入的內容
3625
		$strs2write=array();
3626
 
3627
		#針對每個RR記錄
3628
		foreach($result["content"] as $RR){
3629
 
3630
			#初始化暫存要寫入的行內容
3631
			$str2write="";
3632
 
3633
			#如果是
3634
			if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
3635
 
3636
				#組合變數名稱與數值
3637
				$str2write=$str2write.$RR["type"]."\t".$RR["value"];
3638
 
3639
				}#if end
3640
 
3641
			#反之
3642
			else{
3643
 
3644
				#加上查詢的字句
3645
				$str2write=$str2write.$RR["query"];
3646
 
3647
				#如果該筆RR有指定update time該ZONE具備 global TTL.
3648
				if(isset($RR["update"])){
3649
 
3650
					#如果 該ZONE具備 global TTL.
3651
					if(isset($result["defaultTTL"])){
3652
 
3653
						#如果該筆 RR 的 update time 不等於 global TTL
3654
						if($RR["update"]!==$result["defaultTTL"]){
3655
 
3656
							#加上TTL的字句
3657
							$str2write=$str2write."\t".$RR["update"];
3658
 
3659
							}#if end
3660
 
3661
						}#if end
3662
 
3663
					#反之
3664
					else{
3665
 
3666
						#加上TTL的字句
3667
						$str2write=$str2write."\t".$RR["update"];
3668
 
3669
						}#else end
3670
 
3671
					}#if end
3672
 
253 liveuser 3673
				#反之且該ZONE不具備 global TTL.
3674
				else if(!isset($result["defaultTTL"])){
249 liveuser 3675
 
3676
					#加上global TTL的字句
3677
					$str2write=$str2write."\t".$result["defaultTTL"];
3678
 
253 liveuser 3679
					}#if end
249 liveuser 3680
 
3681
				#加上IN跟TYPE跟value
3682
				$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
3683
 
3684
				}#else end
3685
 
3686
			#如果有註解
3687
			if(isset($RR["comment"])){
3688
 
3689
				#加上comment
3690
				$str2write=$str2write.";".$RR["comment"];
3691
 
3692
				}#if end
3693
 
253 liveuser 3694
			#如果要 debug
3695
			if($conf["debug"]==="true"){
249 liveuser 3696
 
253 liveuser 3697
				#函式說明:
3698
				#撰寫log
3699
				#回傳結果:
3700
				#$result["status"],狀態,"true"或"false".
3701
				#$result["error"],錯誤訊息陣列.
3702
				#$result["function"],當前函式的名稱.
3703
				#$result["argu"],使用的參數.
3704
				#$result["content"],要寫入log的內容字串.
3705
				#必填參數:
3706
				#$conf["path"],字串,log檔案的路徑與名稱.
3707
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3708
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3709
				$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
3710
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3711
				$conf["logs::record"]["fileArgu"]=__FILE__;
3712
				#可省略參數:
3713
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3714
				#$conf["rewrite"]="false";
3715
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3716
				#$conf["returnOnly"]="true";
3717
				#參考資料:
3718
				#無.
3719
				#備註:
3720
				#無.
3721
				$record=logs::record($conf["logs::record"]);
3722
				unset($conf["logs::record"]);
3723
 
3724
				}#if end
3725
 
249 liveuser 3726
			#加上要寫入的元素
3727
			$strs2write[]=$str2write;
3728
 
3729
			}#foreach end
3730
 
3731
		#如果有逐行註解
3732
		if(count($result["comment"])>0){
3733
 
3734
			#加到結尾
3735
			#函式說明:
3736
			#將多個一維陣列串聯起來,key從0開始排序.
3737
			#回傳的結果:
3738
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
3739
			#$result["error"],錯誤訊息陣列.
3740
			#$result["function"],當前執行的函數.
3741
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3742
			#$result["content"],合併好的一維陣列.
3743
			#必填參數
3744
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
3745
			$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
3746
			#可省略參數:
3747
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
3748
			#$conf["allowRepeat"]="true";
3749
			#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
3750
			#$conf["looseDiff"]="false";
3751
			#參考資料:
3752
			#無.
3753
			#備註:
3754
			#無.
3755
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
3756
			unset($conf["arrays::mergeArray"]);
3757
 
3758
			#如果執行異常
3759
			if($mergeArray["status"]==="false"){
3760
 
3761
				#設置錯誤識別
3762
				$result["status"]="false";
3763
 
3764
				#設置錯誤訊息
3765
				$result["error"]=$mergeArray;
3766
 
3767
				#回傳結果
3768
				return $result;
3769
 
3770
				}#if end
3771
 
3772
			#取得合併好的陣列
3773
			$strs2write=$mergeArray["content"];
3774
 
3775
			}#if end
3776
 
253 liveuser 3777
		#如果要 debug
3778
		if($conf["debug"]==="true"){
249 liveuser 3779
 
253 liveuser 3780
			#函式說明:
3781
			#撰寫log
3782
			#回傳結果:
3783
			#$result["status"],狀態,"true"或"false".
3784
			#$result["error"],錯誤訊息陣列.
3785
			#$result["function"],當前函式的名稱.
3786
			#$result["argu"],使用的參數.
3787
			#$result["content"],要寫入log的內容字串.
3788
			#必填參數:
3789
			#$conf["path"],字串,log檔案的路徑與名稱.
3790
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3791
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3792
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
3793
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3794
			$conf["logs::record"]["fileArgu"]=__FILE__;
3795
			#可省略參數:
3796
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3797
			#$conf["rewrite"]="false";
3798
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3799
			#$conf["returnOnly"]="true";
3800
			#參考資料:
3801
			#無.
3802
			#備註:
3803
			#無.
3804
			$record=logs::record($conf["logs::record"]);
3805
			unset($conf["logs::record"]);
3806
 
3807
			}#if end
3808
 
249 liveuser 3809
		#儲存新zone file每行的內容
3810
		$result["newZoneFileContent"]=$strs2write;
3811
 
3812
		#如果要寫入ZONE檔案
3813
		if($conf["writeNow"]==="true"){
3814
 
3815
			#覆寫 ZONE file
3816
			#函式說明:
3817
			#更新檔案的內容.
3818
			#回傳結果:
3819
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3820
			#$result["error"],錯誤訊息.
3821
			#$result["function"],當前執行的函數名稱.
3822
			#$result["content"],更新的資訊.
3823
			#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
3824
			#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
3825
			#必填參數:
3826
			#$conf["fileArgu"],字串,變數__FILE__的內容.
3827
			$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
3828
			#$conf["file"],字串,要更新的檔案位置與名稱.
3829
			$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
3830
			#可省略參數:
3831
			#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
3832
			$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
3833
			#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
3834
			#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
3835
			#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
3836
			#$conf["replaceLike"]="false";
3837
			#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
3838
			#$conf["addToTailWhenNoMatch"]="false";
3839
			#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
3840
			#$conf["addToTailBeforeThat"]="?\>";
3841
			#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
3842
			#$conf["replaceSpecifyLine"]=array();
3843
			#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
3844
			#$conf["outputPath"]="";
3845
			#參考資料:
3846
			#無.
3847
			#備註:
3848
			#無.
3849
			$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
3850
			unset($conf["fileAccess::updateFile"]);
3851
 
3852
			#如果執行異常
3853
			if($updateFile["status"]==="false"){
3854
 
3855
				#設置錯誤識別
3856
				$result["status"]="false";
3857
 
3858
				#設置錯誤訊息
3859
				$result["error"]=$updateFile;
3860
 
3861
				#回傳結果
3862
				return $result;
3863
 
3864
				}#if end
3865
 
3866
			}#if end
3867
 
3868
		#設置執行正常
3869
		$result["status"]="true";
3870
 
3871
		#回傳結果
3872
		return $result;
3873
 
3874
		}#function updateDnsRecordFile end
3875
 
3876
	/*
3877
	#函式說明:
3878
	#驗證已經透過zerossl::createCertificate要求的domain,並取得ssl憑證.
3879
	#回傳結果:
3880
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3881
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
3882
	#$result["function"],當前執行的函式名稱.
3883
	#$result["argu"],所使用的參數.
3884
	#$result["curl_verbose_info"],curl執行的詳細資訊.
3885
	#$result["content"],字串,得到的json字串回應.
3886
	#必填參數:
3887
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
3888
	$conf["id"]="";
3889
	#可省略參數:
3890
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
3891
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
3892
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
3893
	#$conf["key"]=self::getApiInfo()["apiKey"];
3894
	#參考資料:
3895
	#無.
3896
	#備註:
3897
	#無.
3898
	*/
3899
	public static function verifyDomain(&$conf){
3900
 
3901
		#初始化要回傳的結果
3902
		$result=array();
3903
 
3904
		#設置當其函數名稱
3905
		$result["function"]=__FUNCTION__;
3906
 
3907
		#如果 $conf 不為陣列
3908
		if(gettype($conf)!="array"){
3909
 
3910
			#設置執行失敗
3911
			$result["status"]="false";
3912
 
3913
			#設置執行錯誤訊息
3914
			$result["error"][]="\$conf變數須為陣列形態";
3915
 
3916
			#如果傳入的參數為 null
3917
			if($conf==null){
3918
 
3919
				#設置執行錯誤訊息
3920
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3921
 
3922
				}#if end
3923
 
3924
			#回傳結果
3925
			return $result;
3926
 
3927
			}#if end
3928
 
3929
		#取得參數
3930
		$result["argu"]=$conf;
3931
 
3932
		#檢查參數
3933
		#函式說明:
3934
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3935
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3936
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3937
		#$result["function"],當前執行的函式名稱.
3938
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3939
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3940
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3941
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
3942
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
3943
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3944
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3945
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3946
		#必填寫的參數:
3947
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3948
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3949
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3950
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
3951
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3952
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
3953
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3954
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3955
		#可以省略的參數:
3956
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3957
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3958
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
3959
		#$conf["skipableVariableCanNotBeEmpty"]=array();
3960
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3961
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
3962
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3963
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3964
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3965
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["csrPath"],self::getApiInfo()["apiKey"]);
3966
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3967
		#$conf["arrayCountEqualCheck"][]=array();
3968
		#參考資料來源:
3969
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3970
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3971
		unset($conf["variableCheck::checkArguments"]);
3972
 
3973
		#如果檢查失敗
3974
		if($checkArguments["status"]==="false"){
3975
 
3976
			#設置錯誤識別
3977
			$result["status"]="false";
3978
 
3979
			#設置錯誤訊息
3980
			$result["error"]=$checkArguments;
3981
 
3982
			#回傳結果
3983
			return $result;
3984
 
3985
			}#if end
3986
 
3987
		#如果檢查不通過
3988
		if($checkArguments["passed"]==="false"){
3989
 
3990
			#設置錯誤識別
3991
			$result["status"]="false";
3992
 
3993
			#設置錯誤訊息
3994
			$result["error"]=$checkArguments;
3995
 
3996
			#回傳結果
3997
			return $result;
3998
 
3999
			}#if end
4000
 
4001
		#要傳送的 key -> value
4002
		$postArray=array();
4003
 
4004
		#設置要簽署的domain
4005
		$postArray["validation_method"]="CNAME_CSR_HASH";
4006
 
4007
		#設置要傳送的 json
4008
		$postJson=json_encode($postArray);
4009
 
4010
		#函式說明:
4011
		#運行curl cmd
4012
		#回傳結果:
4013
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4014
		#$result["error"],錯誤訊息陣列.
4015
		#$result["function"],當前執行的函式名稱.
4016
		#$result["founded"],識別網址找不找得到.
4017
		#$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"代表程序的資訊.
4018
		#$result["fullContent"],取得回應的完整字串內容.
4019
		#$result["cookie"],cookie檔案的位置與名稱.
4020
		#$result["cmd"],執行的command.
4021
		#$result["argu],使用的參數.
4022
		#必填參數:
4023
		#$conf["url"],字串,目標url.
4024
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"]."/".$conf["id"]."/challenges";
4025
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4026
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
4027
		#可省略參數:
4028
		#$conf["header"],字串陣列,要傳送的header.
4029
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
4030
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
4031
		#$conf["allowAnySSLcertificate"]="";
4032
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
4033
		#$conf["postVar"]=array();
4034
		#$conf["rawPost"]="字串",要傳送的raw post內容.
4035
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
4036
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
4037
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
4038
		#$conf["agent"],字串,user agent的名稱.
4039
		#$conf["agent"]="";
4040
		#$conf["cookie"],字串,cookie位置與檔案位置.
4041
		#$conf["cookie"]="";
4042
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
4043
		#$conf["forceNewCookie"]="";
4044
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
4045
		#$conf["inBg"]="true";
4046
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
4047
		#$conf["bgInProc"]="false";
4048
		#參考資料:
4049
		#無.
4050
		#備註:
4051
		#無.
4052
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
4053
		unset($conf["catchWebContent::curlCmd"]);
4054
 
4055
		#如果異常
4056
		if($curlCmd["status"]==="false"){
4057
 
4058
			#設置錯誤識別
4059
			$result["status"]="false";
4060
 
4061
			#設置錯誤訊息
4062
			$result["error"]=$curlCmd;
4063
 
4064
			#回傳結果
4065
			return $result;
4066
 
4067
			}#if end
4068
 
4069
		#設置curl的詳細資訊
4070
		$result["curl_verbose_info"]=$curlCmd;
4071
 
4072
		/* 範例 response json content
4073
 
4074
		*/
4075
 
4076
		#驗證結果是否為 json
4077
		$json_validate=json_validate($curlCmd["fullContent"]);
4078
 
4079
		#如果回應不是 json
4080
		if(!$json_validate){
4081
 
4082
			#設置錯誤識別
4083
			$result["status"]="false";
4084
 
4085
			#設置錯誤訊息
4086
			$result["error"]=$curlCmd;
4087
 
4088
			#回傳結果
4089
			return $result;
4090
 
4091
			}#if end
4092
 
4093
		#設置json string結果
4094
		$result["content"]=$curlCmd["fullContent"];
4095
 
4096
		#解析json
4097
		$jsonRes=json_decode($result["content"]);
4098
 
4099
		#設置執行正常
4100
		$result["status"]="true";
4101
 
4102
		#回傳結果
4103
		return $result;
4104
 
4105
		}#function verifyDomain end
4106
 
226 liveuser 4107
	}#class zerossl end