Subversion Repositories php-qbpwcf

Rev

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

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
27
類別說明:
28
應用 zerossl 的類別.
29
備註:
30
無.
31
*/
32
class zerossl{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	#備註:
47
	#無.
48
	*/
49
	public function __call($method,$arguments){
226 liveuser 50
 
3 liveuser 51
		#取得當前執行的函式
52
		$result["function"]=__FUNCTION__;
226 liveuser 53
 
3 liveuser 54
		#設置執行不正常
55
		$result["status"]="false";
226 liveuser 56
 
3 liveuser 57
		#設置執行錯誤
58
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 59
 
3 liveuser 60
		#設置所丟入的參數
61
		$result["error"][]=$arguments;
226 liveuser 62
 
3 liveuser 63
		#回傳結果
64
		return $result;
226 liveuser 65
 
3 liveuser 66
		}#function __call end
226 liveuser 67
 
3 liveuser 68
	/*
69
	#函式說明:
70
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
71
	#回傳結果:
72
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
73
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
74
	#$result["function"],當前執行的函式名稱.
75
	#必填參數:
76
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
77
	#$arguments,陣列,為呼叫方法時所用的參數.
78
	#參考資料:
79
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
80
	#備註:
81
	#無.
82
	*/
83
	public static function __callStatic($method,$arguments){
226 liveuser 84
 
3 liveuser 85
		#取得當前執行的函式
86
		$result["function"]=__FUNCTION__;
226 liveuser 87
 
3 liveuser 88
		#設置執行不正常
89
		$result["status"]="false";
226 liveuser 90
 
3 liveuser 91
		#設置執行錯誤
92
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 93
 
3 liveuser 94
		#設置所丟入的參數
95
		$result["error"][]=$arguments;
226 liveuser 96
 
3 liveuser 97
		#回傳結果
98
		return $result;
226 liveuser 99
 
3 liveuser 100
		}#function __callStatic end
226 liveuser 101
 
3 liveuser 102
	/*
103
	#函式說明:
104
	#取得api的資訊
105
	#回傳結果:
106
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
107
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
108
	#$result["function"],當前執行的函式名稱.
109
	#$result["content"],api資訊陣列.
110
	#必填參數:
111
	#無
112
	#可省略參數:
113
	#無
114
	#參考資料:
115
	#無.
116
	#備註:
117
	#無.
118
	*/
119
	public static function getApiInfo(){
226 liveuser 120
 
3 liveuser 121
		#初始化要回傳的陣列
122
		$result=array();
226 liveuser 123
 
3 liveuser 124
		#api domain
125
		$result["apiDomain"]="api.zerossl.com";
226 liveuser 126
 
249 liveuser 127
		#create certificate api path
3 liveuser 128
		$result["csrPath"]="/certificates";
226 liveuser 129
 
3 liveuser 130
		#create certificate url
131
		$result["csrUrl"]=$result["apiDomain"].$result["csrPath"];
226 liveuser 132
 
3 liveuser 133
		#api access key
134
		$result["apiKey"]=zeroSSLapiKey;
226 liveuser 135
 
3 liveuser 136
		#設置執行正常
137
		$result["status"]="true";
226 liveuser 138
 
3 liveuser 139
		#回傳結果
140
		return $result;
226 liveuser 141
 
3 liveuser 142
		}#function getApiInfo end
226 liveuser 143
 
3 liveuser 144
	/*
145
	#函式說明:
146
	#產生ssl private key.
147
	#回傳結果:
148
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
149
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
150
	#$result["function"],當前執行的函式名稱.
151
	#$result["argu"],所使用的參數.
152
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 153
	#$result["content"],ssl用的private key.
3 liveuser 154
	#必填參數:
155
	#$conf["fileArgu"],字串,變數__FILE__的內容.
156
	$conf["fileArgu"]=__FILE__;
157
	#可省略參數:
158
	#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
159
	#$conf["length"]=4096';
160
	#參考資料:
161
	#無.
162
	#備註:
163
	#key generated by openssl with RSA.
164
	*/
165
	public static function createPrivateKey(&$conf){
226 liveuser 166
 
3 liveuser 167
		#初始化要回傳的結果
168
		$result=array();
226 liveuser 169
 
3 liveuser 170
		#取得當前執行的函數名稱
171
		$result["function"]=__FUNCTION__;
226 liveuser 172
 
3 liveuser 173
		#如果 $conf 不為陣列
174
		if(gettype($conf)!="array"){
226 liveuser 175
 
3 liveuser 176
			#設置執行失敗
177
			$result["status"]="false";
226 liveuser 178
 
3 liveuser 179
			#設置執行錯誤訊息
180
			$result["error"][]="\$conf變數須為陣列形態";
181
 
182
			#如果傳入的參數為 null
183
			if($conf==null){
226 liveuser 184
 
3 liveuser 185
				#設置執行錯誤訊息
186
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 187
 
3 liveuser 188
				}#if end
189
 
190
			#回傳結果
191
			return $result;
226 liveuser 192
 
3 liveuser 193
			}#if end
226 liveuser 194
 
3 liveuser 195
		#取得參數
196
		$result["argu"]=$conf;
226 liveuser 197
 
3 liveuser 198
		#函式說明:
199
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
200
		#回傳結果:
201
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
202
		#$result["error"],執行不正常結束的錯訊息陣列.
203
		#$result["simpleError"],簡單表示的錯誤訊息.
204
		#$result["function"],當前執行的函式名稱.
205
		#$result["argu"],設置給予的參數.
206
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
207
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
208
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
209
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
210
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
211
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
212
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
213
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
214
		#必填參數:
215
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
216
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
217
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
218
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
219
		#可省略參數:
220
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
221
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
222
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
223
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
224
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
225
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
226
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
227
		#$conf["canNotBeEmpty"]=array();
228
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
229
		#$conf["canBeEmpty"]=array();
230
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
231
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("length");
232
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
233
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
234
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
235
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer");
236
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
237
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(4096);
238
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
239
		#$conf["disallowAllSkipableVarIsEmpty"]="";
240
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
241
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
242
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
243
		#$conf["disallowAllSkipableVarNotExist"]="";
244
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
245
		#$conf["arrayCountEqualCheck"][]=array();
246
		#參考資料:
247
		#array_keys=>http://php.net/manual/en/function.array-keys.php
248
		#備註:
249
		#無.
250
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
251
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 252
 
3 liveuser 253
		#如果 $checkArguments["status"]等於 "false"
254
		if($checkArguments["status"]==="false"){
255
 
256
			#設置執行錯誤的識別
257
			$result["status"]="false";
258
 
259
			#設置錯誤訊息
260
			$result["error"]=$checkArguments;
261
 
262
			#回傳結果
263
			return $result;
264
 
265
			}#if end
266
 
267
		#如果 $checkArguments["passed"]等於 "false"
268
		if($checkArguments["passed"]==="false"){
269
 
270
			#設置執行錯誤的識別
271
			$result["status"]="false";
272
 
273
			#設置錯誤訊息
274
			$result["error"]=$checkArguments;
275
 
276
			#回傳結果
277
			return $result;
278
 
279
			}#if end
226 liveuser 280
 
3 liveuser 281
		#函式說明:
282
		#呼叫shell執行系統命令,並取得回傳的內容.
283
		#回傳結果:
284
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
285
		#$result["error"],錯誤訊息陣列.
286
		#$result["function"],當前執行的函數名稱.
287
		#$result["argu"],使用的參數.
288
		#$result["cmd"],執行的指令內容.
289
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
290
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
291
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
292
		#$result["running"],是否還在執行.
293
		#$result["pid"],pid.
294
		#$result["statusCode"],執行結束後的代碼.
295
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
296
		#必填參數:
297
		#$conf["command"],字串,要執行的指令.
298
		$conf["external::callShell"]["command"]="openssl";
299
		#$conf["fileArgu"],字串,變數__FILE__的內容.
300
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
301
		#可省略參數:
302
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
303
		$conf["external::callShell"]["argu"]=array("genrsa",$conf["length"]);
304
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
305
		#$conf["arguIsAddr"]=array();
306
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
307
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
308
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
309
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
310
		#$conf["enablePrintDescription"]="true";
311
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
312
		#$conf["printDescription"]="";
313
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
314
		$conf["external::callShell"]["escapeshellarg"]="true";
315
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
316
		#$conf["thereIsShellVar"]=array();
317
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
318
		#$conf["username"]="";
319
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
320
		#$conf["password"]="";
321
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
322
		#$conf["useScript"]="";
323
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
324
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
325
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
326
		#$conf["inBackGround"]="";
327
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
328
		#$conf["getErr"]="false";
329
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
330
		#$conf["doNotRun"]="false";
331
		#參考資料:
332
		#exec=>http://php.net/manual/en/function.exec.php
333
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
334
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
335
		#備註:
336
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
337
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
338
		$callShell=external::callShell($conf["external::callShell"]);
339
		unset($conf["external::callShell"]);
226 liveuser 340
 
3 liveuser 341
		#如果異常
342
		if($callShell["status"]==="false"){
226 liveuser 343
 
3 liveuser 344
			#設置錯誤識別
345
			$result["status"]="false";
226 liveuser 346
 
3 liveuser 347
			#設置錯誤訊息
348
			$result["error"]=$callShell;
226 liveuser 349
 
3 liveuser 350
			#回傳結果
351
			return $result;
226 liveuser 352
 
3 liveuser 353
			}#if end
226 liveuser 354
 
3 liveuser 355
		#函式說明:
356
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
357
		#回傳的結果:
358
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
359
		#$result["function"],當前執行的function名稱
360
		#$result["error"],錯誤訊息陣列.
361
		#$result["content"],處理好的字串.
362
		#$result["argu"],使用的參數.
363
		#必填參數:
364
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
365
		$conf["arrays::arrayToString"]["inputArray"]=$callShell["output"];
366
		#可省略參數:
367
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
255 liveuser 368
		$conf["arrays::arrayToString"]["spiltSymbol"]=PHP_EOL;
3 liveuser 369
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
370
		$conf["arrays::arrayToString"]["skipEnd"]="true";
371
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
372
		#$conf["spiltSymbolAtStart"]="";
373
		#參考資料:
374
		#無.
375
		#備註:
376
		#無.
377
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
378
		unset($conf["arrays::arrayToString"]);
226 liveuser 379
 
3 liveuser 380
		#如果異常
381
		if($arrayToString["status"]==="false"){
226 liveuser 382
 
3 liveuser 383
			#設置錯誤識別
384
			$result["status"]="false";
226 liveuser 385
 
3 liveuser 386
			#設置錯誤訊息
387
			$result["error"]=$arrayToString;
226 liveuser 388
 
3 liveuser 389
			#回傳結果
390
			return $result;
226 liveuser 391
 
3 liveuser 392
			}#if end
226 liveuser 393
 
3 liveuser 394
		#取得 private key 字串
395
		$result["content"]=$arrayToString["content"];
226 liveuser 396
 
3 liveuser 397
		#設置執行正常
398
		$result["status"]="true";
226 liveuser 399
 
3 liveuser 400
		#回傳結果
401
		return $result;
226 liveuser 402
 
3 liveuser 403
		}#function createPrivateKey end
226 liveuser 404
 
3 liveuser 405
	/*
406
	#函式說明:
249 liveuser 407
	#產生certificate sign request(CSR).
3 liveuser 408
	#回傳結果:
409
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
410
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
411
	#$result["function"],當前執行的函式名稱.
412
	#$result["argu"],所使用的參數.
255 liveuser 413
	#$result["content"],csr內容.
3 liveuser 414
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 415
	#$result["privateKey"], private key 的內容.
3 liveuser 416
	#必填參數:
249 liveuser 417
	#$conf["domain"],字串,csr內容的網域名稱.
418
	#$conf["domain"]="";
419
	#可省略參數:
255 liveuser 420
	#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
421
	#$conf["pKey"]="";
249 liveuser 422
	#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
423
	#$conf["country"]="";
424
	#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
425
	#$conf["state"]="";
426
	#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
427
	#$conf["org"]="";
428
	#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
429
	#$conf["unit"]="";
430
	#參考資料:
431
	#無.
432
	#備註:
433
	#無.
434
	*/
435
	public static function createCSR(&$conf){
436
 
437
		#初始化要回傳的結果
438
		$result=array();
439
 
440
		#設置當其函數名稱
441
		$result["function"]=__FUNCTION__;
442
 
443
		#如果 $conf 不為陣列
444
		if(gettype($conf)!="array"){
445
 
446
			#設置執行失敗
447
			$result["status"]="false";
448
 
449
			#設置執行錯誤訊息
450
			$result["error"][]="\$conf變數須為陣列形態";
451
 
452
			#如果傳入的參數為 null
453
			if($conf==null){
454
 
455
				#設置執行錯誤訊息
456
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
457
 
458
				}#if end
459
 
460
			#回傳結果
461
			return $result;
462
 
463
			}#if end
464
 
465
		#取得參數
466
		$result["argu"]=$conf;
467
 
468
		#檢查參數
469
		#函式說明:
470
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
471
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
472
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
473
		#$result["function"],當前執行的函式名稱.
474
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
475
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
476
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
477
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
478
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
479
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
480
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
481
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
482
		#必填寫的參數:
483
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
484
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
485
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
486
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("domain");
487
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
488
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
489
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
490
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
491
		#可以省略的參數:
492
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
493
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
494
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
495
		#$conf["skipableVariableCanNotBeEmpty"]=array();
496
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
255 liveuser 497
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pKey","country","state","city","org","unit");
249 liveuser 498
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
255 liveuser 499
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
249 liveuser 500
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 501
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"TW","Taiwan","Taoyuan City","QBPWCF","RD");
249 liveuser 502
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
503
		#$conf["arrayCountEqualCheck"][]=array();
504
		#參考資料來源:
505
		#array_keys=>http://php.net/manual/en/function.array-keys.php
506
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
507
		unset($conf["variableCheck::checkArguments"]);
508
 
509
		#如果檢查失敗
510
		if($checkArguments["status"]==="false"){
511
 
512
			#設置錯誤識別
513
			$result["status"]="false";
514
 
515
			#設置錯誤訊息
516
			$result["error"]=$checkArguments;
517
 
518
			#回傳結果
519
			return $result;
520
 
521
			}#if end
522
 
523
		#如果檢查不通過
524
		if($checkArguments["passed"]==="false"){
525
 
526
			#設置錯誤識別
527
			$result["status"]="false";
528
 
529
			#設置錯誤訊息
530
			$result["error"]=$checkArguments;
531
 
532
			#回傳結果
533
			return $result;
534
 
535
			}#if end
536
 
255 liveuser 537
		#如果沒有指定 pKey
538
		if(!isset($conf["pKey"])){
249 liveuser 539
 
255 liveuser 540
			#產生uuid名稱
541
			#函式說明:
542
			#使用 linux 的 uuid 指令來產生 uuid 字串
543
			#回傳結果:
544
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
545
			#$result["error"],錯誤訊息.
546
			#$result["function"],當前執行的函式名稱.
547
			#$result["content"],uuid.
548
			#必填參數:
549
			#無.
550
			#可省略參數:
551
			#無.
552
			#參考資料:
553
			#無.
554
			#備註:
555
			#無.
556
			$uuid=cmd::uuid();
557
 
558
			#如果執行異常
559
			if($uuid["status"]==="false"){
249 liveuser 560
 
255 liveuser 561
				#設置錯誤識別
562
				$result["status"]="false";
249 liveuser 563
 
255 liveuser 564
				#設置錯誤訊息
565
				$result["error"]=$uuid;
249 liveuser 566
 
255 liveuser 567
				#回傳結果
568
				return $result;
249 liveuser 569
 
255 liveuser 570
				}#if end
571
 
572
			#取得暫存的檔案名稱
573
			$TFN=$uuid["content"];
574
 
575
			#函式說明:
576
			#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
577
			#回傳結果:
578
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
579
			#$result["error"],錯誤訊息.
580
			#$result["function"],當前執行的函數名稱.
581
			#$result["content"],暫存檔案的路徑與名稱.
582
			#$result["fileName"],暫存檔案的名稱.
583
			#$result["path"],暫存檔案的路徑.
584
			#必填參數:
585
			#無.
586
			#可省略參數:
587
			#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
588
			#$conf["contant"]=array();
589
			#參考資料:
590
			#無.
591
			#備註:
592
			#無.
593
			$conf["fileAccess::createTempFile"]=array();
594
			$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
595
			unset($conf["fileAccess::createTempFile"]);
596
 
597
			#如果執行異常
598
			if($createTempFile["status"]==="false"){
249 liveuser 599
 
255 liveuser 600
				#設置錯誤識別
601
				$result["status"]="false";
249 liveuser 602
 
255 liveuser 603
				#設置錯誤訊息
604
				$result["error"]=$createTempFile;
249 liveuser 605
 
255 liveuser 606
				#回傳結果
607
				return $result;
249 liveuser 608
 
255 liveuser 609
				}#if end
610
 
611
			#暫存的檔案路徑與名稱
612
			$TFN=$createTempFile["content"];
613
 
614
			#產生 privae key
615
			#openssl genrsa -out output.key 4096 
616
 
617
			#函式說明:
618
			#呼叫shell執行系統命令,並取得回傳的內容.
619
			#回傳結果:
620
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
621
			#$result["error"],錯誤訊息陣列.
622
			#$result["function"],當前執行的函數名稱.
623
			#$result["argu"],使用的參數.
624
			#$result["cmd"],執行的指令內容.
625
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
626
			#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
627
			#$result["content"],為執行完後的輸出字串.
628
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
629
			#$result["running"],是否還在執行.
630
			#$result["pid"],pid.
631
			#$result["statusCode"],執行結束後的代碼.
632
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
633
			#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
634
			#必填參數:
635
			#$conf["command"],字串,要執行的指令.
636
			$conf["external::callShell"]["command"]="openssl";
637
			#$conf["fileArgu"],字串,變數__FILE__的內容.
638
			$conf["external::callShell"]["fileArgu"]=__FILE__;
639
			#可省略參數:
640
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
641
			$conf["external::callShell"]["argu"]=array("genrsa","-out",$TFN,"4096");
642
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
643
			#$conf["arguIsAddr"]=array();
644
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
645
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
646
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
647
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
648
			#$conf["enablePrintDescription"]="true";
649
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
650
			#$conf["printDescription"]="";
651
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
652
			#$conf["escapeshellarg"]="false";
653
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
654
			#$conf["thereIsShellVar"]=array();
655
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
656
			#$conf["username"]="";
657
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
658
			#$conf["password"]="";
659
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
660
			#$conf["useScript"]="";
661
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
662
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
663
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
664
			#$conf["inBackGround"]="";
665
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
666
			#$conf["getErr"]="false";
667
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
668
			$conf["external::callShell"]["doNotRun"]="true";
669
			#參考資料:
670
			#exec=>http://php.net/manual/en/function.exec.php
671
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
672
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
673
			#備註:
674
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
675
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
676
			$callShell=external::callShell($conf["external::callShell"]);
677
			unset($conf["external::callShell"]);
678
 
679
			#如果執行異常
680
			if($callShell["status"]==="false"){
249 liveuser 681
 
255 liveuser 682
				#設置錯誤識別
683
				$result["status"]="false";
249 liveuser 684
 
255 liveuser 685
				#設置錯誤訊息
686
				$result["error"]=$callShell;
249 liveuser 687
 
255 liveuser 688
				#回傳結果
689
				return $result;
249 liveuser 690
 
255 liveuser 691
				}#if end
692
 
693
			#debug
694
			#var_dump(__LINE__,$callShell);exit;
695
 
696
			#函式說明:
697
			#透過proc來多執行序運作.
698
			#回傳結果:
699
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
700
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
701
			#$result["function"],當前執行的函式名稱.
702
			#$result["argu"],使用的參數.
703
			#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
704
			#必填參數:
705
			#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
706
			$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
707
			#可省略參數:
708
			#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
709
			$conf["threads::proc"]["wait"]="true";
710
			#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
711
			#$conf["timeout"]=array("10");
712
			#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
713
			#$conf["workingDir"]=array("path");
714
			#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
715
			#$conf["envs"]=array(array("key"=>"value"));
716
			#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
717
			#$conf["executeBy"]=array("bash");
718
			#參考資料:
719
			#https://www.php.net/manual/en/function.proc-open.php
720
			#https://www.php.net/manual/en/function.proc-get-status.php
721
			#https://www.php.net/manual/en/function.proc-terminate.php
722
			#備註:
723
			#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
724
			$proc=threads::proc($conf["threads::proc"]);
725
			unset($conf["threads::proc"]);
726
 
727
			#如果執行異常
728
			if($proc["status"]==="false"){
249 liveuser 729
 
255 liveuser 730
				#設置錯誤識別
731
				$result["status"]="false";
249 liveuser 732
 
255 liveuser 733
				#設置錯誤訊息
734
				$result["error"]=$proc;
249 liveuser 735
 
255 liveuser 736
				#回傳結果
737
				return $result;
249 liveuser 738
 
255 liveuser 739
				}#if end
740
 
741
			#debug
742
			#var_dump(__LINE__,$proc);exit;
743
 
744
			#如果執行異常
745
			if($proc["content"][0]["status"]==="false"){
746
 
747
				#設置錯誤識別
748
				$result["status"]="false";
249 liveuser 749
 
255 liveuser 750
				#設置錯誤訊息
751
				$result["error"]=$proc["content"][0]["error"];
249 liveuser 752
 
255 liveuser 753
				#回傳結果
754
				return $result;
755
 
756
				}#if end
757
 
758
			#儲存錯誤訊息
759
			$errorMsg=$proc["content"][0]["error"];
760
 
761
			#如果有錯誤訊息
762
			if(!empty($errorMsg)){
763
 
764
				#設置錯誤識別
765
				$result["status"]="false";
766
 
767
				#設置錯誤訊息
768
				$result["error"]=$errorMsg;
769
 
770
				#回傳結果
771
				return $result;
772
 
773
				}#if end
249 liveuser 774
 
775
			}#if end
776
 
255 liveuser 777
		#反之
778
		else{
249 liveuser 779
 
255 liveuser 780
			#檢查 pKey 是否存在
781
			#函式說明:
782
			#檢查多個檔案與資料夾是否存在.
783
			#回傳的結果:
784
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
785
			#$result["error"],錯誤訊息陣列.
786
			#$resutl["function"],當前執行的涵式名稱.
787
			#$result["argu"],使用的參數.
788
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
789
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
790
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
791
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
792
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
793
			#必填參數:
794
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
293 liveuser 795
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["pKey"]);
255 liveuser 796
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
797
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
798
			#可省略參數:
799
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
800
			#$conf["disableWebSearch"]="false";
801
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
802
			$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
803
			#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
804
			$conf["fileAccess::checkMultiFileExist"]["web"]="false";
805
			#參考資料:
806
			#http://php.net/manual/en/function.file-exists.php
807
			#http://php.net/manual/en/control-structures.foreach.php
808
			#備註:
809
			#函數file_exists檢查的路徑為檔案系統的路徑
810
			#$result["varName"][$i]結果未實作
811
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
812
			unset($conf["fileAccess::checkMultiFileExist"]);
249 liveuser 813
 
255 liveuser 814
			#如果執行異常
815
			if($checkMultiFileExist["status"]==="false"){
249 liveuser 816
 
255 liveuser 817
				#設置錯誤識別
818
				$result["status"]="false";
249 liveuser 819
 
255 liveuser 820
				#設置錯誤訊息
821
				$result["error"]=$checkMultiFileExist;
822
 
823
				#回傳結果
824
				return $result;
825
 
826
				}#if end
249 liveuser 827
 
255 liveuser 828
			#設置pKey
829
			$TFN=$conf["pKey"];
249 liveuser 830
 
255 liveuser 831
			}#else
832
 
249 liveuser 833
		#範例指令
834
		#C,國家,例如TW,代表Taiwan
835
		#ST,州、省,要完整名稱,例如:Taiwan
836
		#L,城市名稱,例如Taoyuan City.
837
		#O=,組織或公司名稱,例如QBPWCF.
838
		#OU,單位名稱,例如RD.
839
		#CN,網域名稱,例如www.qbpwcf.org
840
		#openssl req -new -key qbpwcf.org.key -out qbpwcf.org.csr "-subj=/C=TW/ST=Taiwan/L=Taoyuan City/O=QBPWCF/OU=RD/CN=www.qbpwcf.org/"
841
 
842
		#初始化subj參數
843
		$subjStr="-subj=/";
844
 
845
		#設置 Country 參數
846
		$subjStr=$subjStr."C=".$conf["country"]."/";
847
 
848
		#設置 State 參數
849
		$subjStr=$subjStr."ST=".$conf["state"]."/";
850
 
851
		#設置 city 參數
852
		$subjStr=$subjStr."L=".$conf["city"]."/";
853
 
854
		#設置 Org 參數
855
		$subjStr=$subjStr."O=".$conf["org"]."/";
856
 
857
		#設置 Unit 參數
858
		$subjStr=$subjStr."OU=".$conf["unit"]."/";
859
 
860
		#設置 domain name 參數
861
		$subjStr=$subjStr."CN=".$conf["domain"]."/";
862
 
863
		#函式說明:
864
		#呼叫shell執行系統命令,並取得回傳的內容.
865
		#回傳結果:
866
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
867
		#$result["error"],錯誤訊息陣列.
868
		#$result["function"],當前執行的函數名稱.
869
		#$result["argu"],使用的參數.
870
		#$result["cmd"],執行的指令內容.
871
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
872
		#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
873
		#$result["content"],為執行完後的輸出字串.
874
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
875
		#$result["running"],是否還在執行.
876
		#$result["pid"],pid.
877
		#$result["statusCode"],執行結束後的代碼.
878
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
879
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
880
		#必填參數:
881
		#$conf["command"],字串,要執行的指令.
882
		$conf["external::callShell"]["command"]="openssl";
883
		#$conf["fileArgu"],字串,變數__FILE__的內容.
884
		$conf["external::callShell"]["fileArgu"]=__FILE__;
885
		#可省略參數:
886
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
887
		$conf["external::callShell"]["argu"]=array("req","-new","-key",$TFN,$subjStr);
888
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
889
		#$conf["arguIsAddr"]=array();
890
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
891
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
892
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
893
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
894
		#$conf["enablePrintDescription"]="true";
895
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
896
		#$conf["printDescription"]="";
897
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
898
		$conf["external::callShell"]["escapeshellarg"]="true";
899
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
900
		#$conf["thereIsShellVar"]=array();
901
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
902
		#$conf["username"]="";
903
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
904
		#$conf["password"]="";
905
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
906
		#$conf["useScript"]="";
907
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
908
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
909
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
910
		#$conf["inBackGround"]="";
911
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
912
		#$conf["getErr"]="false";
913
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
914
		$conf["external::callShell"]["doNotRun"]="true";
915
		#參考資料:
916
		#exec=>http://php.net/manual/en/function.exec.php
917
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
918
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
919
		#備註:
920
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
921
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
922
		$callShell=external::callShell($conf["external::callShell"]);
923
		unset($conf["external::callShell"]);
924
 
925
		#如果執行異常
926
		if($callShell["status"]==="false"){
927
 
928
			#設置錯誤識別
929
			$result["status"]="false";
930
 
931
			#設置錯誤訊息
932
			$result["error"]=$callShell;
933
 
934
			#回傳結果
935
			return $result;
936
 
937
			}#if end
938
 
939
		#debug
940
		#var_dump(__LINE__,$callShell);exit;
941
 
942
		#函式說明:
943
		#透過proc來多執行序運作.
944
		#回傳結果:
945
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
946
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
947
		#$result["function"],當前執行的函式名稱.
948
		#$result["argu"],使用的參數.
949
		#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
950
		#必填參數:
951
		#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
952
		$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
953
		#可省略參數:
954
		#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
955
		$conf["threads::proc"]["wait"]="true";
956
		#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
957
		#$conf["timeout"]=array("10");
958
		#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
959
		#$conf["workingDir"]=array("path");
960
		#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
961
		#$conf["envs"]=array(array("key"=>"value"));
962
		#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
963
		#$conf["executeBy"]=array("bash");
964
		#參考資料:
965
		#https://www.php.net/manual/en/function.proc-open.php
966
		#https://www.php.net/manual/en/function.proc-get-status.php
967
		#https://www.php.net/manual/en/function.proc-terminate.php
968
		#備註:
969
		#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
970
		$proc=threads::proc($conf["threads::proc"]);
971
		unset($conf["threads::proc"]);
972
 
973
		#如果執行異常
974
		if($proc["status"]==="false"){
975
 
976
			#設置錯誤識別
977
			$result["status"]="false";
978
 
979
			#設置錯誤訊息
980
			$result["error"]=$proc;
981
 
982
			#回傳結果
983
			return $result;
984
 
985
			}#if end
986
 
987
		#如果執行異常
988
		if($proc["content"][0]["status"]==="false"){
989
 
990
			#設置錯誤識別
991
			$result["status"]="false";
992
 
993
			#設置錯誤訊息
994
			$result["error"]=$proc["content"][0]["error"];
995
 
996
			#回傳結果
997
			return $result;
998
 
999
			}#if end
1000
 
1001
		#debug
1002
		#var_dump(__LINE__,$proc);exit;
1003
 
1004
		#儲存csr
1005
		$csr=$proc["content"][0]["content"];
1006
 
1007
		#取得 csr 內容
1008
		$result["content"]=$csr;
1009
 
255 liveuser 1010
		#取得 private key 的內容
249 liveuser 1011
		#函式說明:
255 liveuser 1012
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1013
		#回傳的變數說明:
1014
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1015
		#$result["error"],錯誤訊息提示.
1016
		#$result["warning"],警告訊息.
249 liveuser 1017
		#$result["function"],當前執行的函數名稱.
255 liveuser 1018
		#$result["fileContent"],爲檔案的內容陣列.
1019
		#$result["lineCount"],爲檔案內容總共的行數.
1020
		#$result["fullContent"],為檔案的完整內容.
1021
		#$result["base64dataOnly"],檔案的base64data.
1022
		#$result["base64data"],為在網頁上給予src參數的數值.
1023
		#$result["mimeType"],為檔案的mime type.
249 liveuser 1024
		#必填參數:
255 liveuser 1025
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1026
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$TFN;
1027
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1028
		$conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
249 liveuser 1029
		#可省略參數:
255 liveuser 1030
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
1031
		#$conf["web"]="true";
1032
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1033
		#$conf["createIfnotExist"]="false";
1034
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
1035
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
1036
		#參考資料:
1037
		#file(),取得檔案內容的行數.
1038
		#file=>http:#php.net/manual/en/function.file.php
1039
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1040
		#filesize=>http://php.net/manual/en/function.filesize.php
249 liveuser 1041
		#參考資料:
1042
		#無.
1043
		#備註:
1044
		#無.
255 liveuser 1045
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
1046
		unset($conf["fileAccess::getFileContent"]);
249 liveuser 1047
 
1048
		#如果執行異常
255 liveuser 1049
		if($getFileContent["status"]==="false"){
249 liveuser 1050
 
1051
			#設置錯誤識別
1052
			$result["status"]="false";
1053
 
1054
			#設置錯誤訊息
255 liveuser 1055
			$result["error"]=$getFileContent;
249 liveuser 1056
 
1057
			#回傳結果
1058
			return $result;
1059
 
1060
			}#if end
255 liveuser 1061
 
1062
		#設置要回傳的 private key 的內容
1063
		$result["privateKey"]=$getFileContent["fullContent"];
249 liveuser 1064
 
255 liveuser 1065
		#如果沒有設置 pKey
1066
		if(!isset($conf["pKey"])){
1067
 
1068
			#移除private key
1069
			#函式說明:
1070
			#移除檔案
1071
			#回傳結果:
1072
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
1073
			#$result["error"],錯誤訊息陣列.
1074
			#$result["warning"],警告訊息陣列.
1075
			#$result["function"],當前執行的函數名稱.
1076
			#$result["argu"],當前函式使用的參數.
1077
			#必填參數:
1078
			#$conf["fileAddress"],字串,要移除檔案的位置.
1079
			$conf["fileAccess::delFile"]["fileAddress"]=$TFN;
1080
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1081
			$conf["fileAccess::delFile"]["fileArgu"]=__FILE__;
1082
			#可省略參數:
1083
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1084
			#$conf["commentsArray"]=array("");
1085
			#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
1086
			#$conf["allowDelSymlink"]="true";
1087
			#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
1088
			#$conf["allowDelFolder"]="true";
1089
			#參考資料:
1090
			#無.
1091
			#備註:
1092
			#無.
1093
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
1094
			unset($conf["fileAccess::delFile"]);
1095
 
1096
			#如果執行異常
1097
			if($delFile["status"]==="false"){
1098
 
1099
				#設置錯誤識別
1100
				$result["status"]="false";
1101
 
1102
				#設置錯誤訊息
1103
				$result["error"]=$delFile;
1104
 
1105
				#回傳結果
1106
				return $result;
1107
 
1108
				}#if end
1109
 
1110
			}#if end
1111
 
249 liveuser 1112
		#設置執行正常
1113
		$result["status"]="true";
1114
 
1115
		#回傳結果
1116
		return $result;
1117
 
1118
		}#function createCSR end
1119
 
1120
	/*
1121
	#函式說明:
281 liveuser 1122
	#提供certificate sign request(CSR)透過zerossl產生certificate.
249 liveuser 1123
	#回傳結果:
1124
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1125
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1126
	#$result["function"],當前執行的函式名稱.
1127
	#$result["argu"],所使用的參數.
1128
	#$result["curl_verbose_info"],curl執行的詳細資訊.
1129
	#$result["id"],用於zerossl api驗證domain的id.
1130
	#$result["content"],字串,得到的json字串回應.
1131
	#$result["cnameKey"],用於dns CNAME驗證鍵名.
1132
	#$result["cnameVal"],用於dms CNAME驗證鍵值.
1133
	#必填參數:
3 liveuser 1134
	#$conf["certificate_domains"],字串,要簽署的doamin名稱.
1135
	$conf["certificate_domains"]="";
1136
	#$conf["certificate_csr"],字串,簽署的資訊.
1137
	$conf["certificate_csr"]="";
1138
	#$conf["fileArgu"],字串,變數__FILE__的內容.
1139
	$conf["fileArgu"]=__FILE__;
1140
	#可省略參數:
1141
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
1142
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
1143
	#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
1144
	#$conf["path"]=self::getApiInfo()["csrPath"];
1145
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
1146
	#$conf["key"]=self::getApiInfo()["apiKey"];
1147
	#參考資料:
1148
	#無.
1149
	#備註:
1150
	#無.
1151
	*/
249 liveuser 1152
	public static function createCertificate(&$conf){
226 liveuser 1153
 
3 liveuser 1154
		#break point
1155
		#var_dump(self::getApiInfo());exit;
226 liveuser 1156
 
3 liveuser 1157
		#初始化要回傳的結果
1158
		$result=array();
226 liveuser 1159
 
3 liveuser 1160
		#設置當其函數名稱
1161
		$result["function"]=__FUNCTION__;
226 liveuser 1162
 
3 liveuser 1163
		#如果 $conf 不為陣列
1164
		if(gettype($conf)!="array"){
226 liveuser 1165
 
3 liveuser 1166
			#設置執行失敗
1167
			$result["status"]="false";
226 liveuser 1168
 
3 liveuser 1169
			#設置執行錯誤訊息
1170
			$result["error"][]="\$conf變數須為陣列形態";
1171
 
1172
			#如果傳入的參數為 null
1173
			if($conf==null){
226 liveuser 1174
 
3 liveuser 1175
				#設置執行錯誤訊息
1176
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1177
 
3 liveuser 1178
				}#if end
1179
 
1180
			#回傳結果
1181
			return $result;
226 liveuser 1182
 
3 liveuser 1183
			}#if end
226 liveuser 1184
 
3 liveuser 1185
		#取得參數
1186
		$result["argu"]=$conf;
226 liveuser 1187
 
3 liveuser 1188
		#檢查參數
1189
		#函式說明:
1190
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1191
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1192
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1193
		#$result["function"],當前執行的函式名稱.
1194
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1195
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1196
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1197
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1198
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1199
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1200
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1201
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1202
		#必填寫的參數:
1203
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1204
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1205
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1206
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","certificate_domains","certificate_csr");
226 liveuser 1207
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 1208
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
1209
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1210
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1211
		#可以省略的參數:
1212
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1213
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1214
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
1215
		#$conf["skipableVariableCanNotBeEmpty"]=array();
1216
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1217
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","path","key");
226 liveuser 1218
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1219
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1220
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1221
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["csrPath"],self::getApiInfo()["apiKey"]);
1222
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1223
		#$conf["arrayCountEqualCheck"][]=array();
1224
		#參考資料來源:
1225
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1226
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1227
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1228
 
3 liveuser 1229
		#如果檢查失敗
249 liveuser 1230
		if($checkArguments["status"]==="false"){
226 liveuser 1231
 
3 liveuser 1232
			#設置錯誤識別
1233
			$result["status"]="false";
226 liveuser 1234
 
3 liveuser 1235
			#設置錯誤訊息
1236
			$result["error"]=$checkArguments;
226 liveuser 1237
 
3 liveuser 1238
			#回傳結果
1239
			return $result;
226 liveuser 1240
 
3 liveuser 1241
			}#if end
226 liveuser 1242
 
3 liveuser 1243
		#如果檢查不通過
249 liveuser 1244
		if($checkArguments["passed"]==="false"){
226 liveuser 1245
 
3 liveuser 1246
			#設置錯誤識別
1247
			$result["status"]="false";
226 liveuser 1248
 
3 liveuser 1249
			#設置錯誤訊息
1250
			$result["error"]=$checkArguments;
226 liveuser 1251
 
3 liveuser 1252
			#回傳結果
1253
			return $result;
226 liveuser 1254
 
3 liveuser 1255
			}#if end
226 liveuser 1256
 
3 liveuser 1257
		#要傳送的 key -> value
1258
		$postArray=array();
226 liveuser 1259
 
3 liveuser 1260
		#設置要簽署的domain
1261
		$postArray["certificate_domains"]=$conf["certificate_domains"];
226 liveuser 1262
 
3 liveuser 1263
		#設置csr
1264
		$postArray["certificate_csr"]=$conf["certificate_csr"];
226 liveuser 1265
 
3 liveuser 1266
		#預設為 90 天的憑證
1267
		$postArray["certificate_validity_days"]=90;
226 liveuser 1268
 
3 liveuser 1269
		#強制讓 要簽署的domain 為 $postArray["certificate_domains"]
1270
		$postArray["strict_domains"]=1;
226 liveuser 1271
 
3 liveuser 1272
		#設置要傳送的 json
1273
		$postJson=json_encode($postArray);
226 liveuser 1274
 
3 liveuser 1275
		#函式說明:
1276
		#運行curl cmd
1277
		#回傳結果:
1278
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1279
		#$result["error"],錯誤訊息陣列.
1280
		#$result["function"],當前執行的函式名稱.
1281
		#$result["founded"],識別網址找不找得到.
1282
		#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
1283
		#$result["fullContent"],取得回應的完整字串內容.
1284
		#$result["cookie"],cookie檔案的位置與名稱.
1285
		#$result["cmd"],執行的command.
1286
		#$result["argu],使用的參數.
1287
		#必填參數:
1288
		#$conf["url"],字串,目標url.
1289
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].$conf["path"]."?access_key=".$conf["key"];
1290
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1291
		$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
1292
		#可省略參數:
1293
		#$conf["header"],字串陣列,要傳送的header.
1294
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
1295
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
1296
		#$conf["allowAnySSLcertificate"]="";
1297
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
1298
		#$conf["postVar"]=array();
1299
		#$conf["rawPost"]="字串",要傳送的raw post內容.
1300
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
1301
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
1302
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
1303
		#$conf["agent"],字串,user agent的名稱.
1304
		#$conf["agent"]="";
1305
		#$conf["cookie"],字串,cookie位置與檔案位置.
1306
		#$conf["cookie"]="";
1307
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
1308
		#$conf["forceNewCookie"]="";
1309
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
1310
		#$conf["inBg"]="true";
1311
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
1312
		#$conf["bgInProc"]="false";
1313
		#參考資料:
1314
		#無.
1315
		#備註:
1316
		#無.
1317
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
1318
		unset($conf["catchWebContent::curlCmd"]);
226 liveuser 1319
 
3 liveuser 1320
		#如果異常
1321
		if($curlCmd["status"]==="false"){
226 liveuser 1322
 
3 liveuser 1323
			#設置錯誤識別
1324
			$result["status"]="false";
226 liveuser 1325
 
3 liveuser 1326
			#設置錯誤訊息
1327
			$result["error"]=$curlCmd;
226 liveuser 1328
 
3 liveuser 1329
			#回傳結果
1330
			return $result;
226 liveuser 1331
 
3 liveuser 1332
			}#if end
226 liveuser 1333
 
3 liveuser 1334
		#設置curl的詳細資訊
1335
		$result["curl_verbose_info"]=$curlCmd;
226 liveuser 1336
 
3 liveuser 1337
		/* 範例 json content
249 liveuser 1338
		{"id":"de9bfbbc78ad2b04323ac0670efefe58","type":"1","common_name":"qbpwcf.org","additional_domains":"","created":"2026-01-19 11:47:13","expires":"2026-04-19 23:59:59","status":"draft","validation_type":null,"validation_emails":null,"replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"qbpwcf.org":["admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"qbpwcf.org":{"file_validation_url_http":"http:\/\/qbpwcf.org\/.well-known\/pki-validation\/3FE7CA1D6DA057FB40FDD333B4C105F9.txt","file_validation_url_https":"https:\/\/qbpwcf.org\/.well-known\/pki-validation\/3FE7CA1D6DA057FB40FDD333B4C105F9.txt","file_validation_content":["7B29341B7148276F5025CE90FC1138037871040E5B7FBDB8E7EEF7CC8DAA4A56","comodoca.com","2e85598b7f1b864"],"cname_validation_p1":"_3FE7CA1D6DA057FB40FDD333B4C105F9.qbpwcf.org","cname_validation_p2":"7B29341B7148276F5025CE90FC113803.7871040E5B7FBDB8E7EEF7CC8DAA4A56.2e85598b7f1b864.comodoca.com"}}},"signature_algorithm_properties":null}
3 liveuser 1339
		*/
226 liveuser 1340
 
249 liveuser 1341
		#驗證結果是否為 json
1342
		$json_validate=json_validate($curlCmd["fullContent"]);
226 liveuser 1343
 
249 liveuser 1344
		#如果回應不是 json
1345
		if(!$json_validate){
1346
 
1347
			#設置錯誤識別
1348
			$result["status"]="false";
1349
 
1350
			#設置錯誤訊息
1351
			$result["error"]=$curlCmd;
1352
 
1353
			#回傳結果
1354
			return $result;
1355
 
1356
			}#if end
1357
 
1358
		#設置json string結果
1359
		$result["content"]=$curlCmd["fullContent"];
1360
 
1361
		#解析json
1362
		$jsonRes=json_decode($result["content"]);
255 liveuser 1363
 
1364
		#另存 certifucate domain
1365
		$cerDomain=$conf["certificate_domains"];
1366
 
1367
		#如果缺少必備的資訊
1368
		if(!isset($jsonRes->validation)){
1369
 
1370
			#設置錯誤識別
1371
			$result["status"]="false";
249 liveuser 1372
 
255 liveuser 1373
			#設置錯誤訊息
1374
			$result["error"]=$curlCmd;
1375
 
1376
			#回傳結果
1377
			return $result;
1378
 
1379
			}#if end
1380
 
249 liveuser 1381
		#取得用於 dns CNAME 驗證的名稱
255 liveuser 1382
		$result["cnameKey"]=$jsonRes->validation->other_methods->$cerDomain->cname_validation_p1;
249 liveuser 1383
 
1384
		#取得用於 dns CNAME 驗證的數值
255 liveuser 1385
		$result["cnameVal"]=$jsonRes->validation->other_methods->$cerDomain->cname_validation_p2;
249 liveuser 1386
 
1387
		#取得用於認證domain時識別用的id
1388
		$result["id"]=$jsonRes->id;
1389
 
3 liveuser 1390
		#設置執行正常
1391
		$result["status"]="true";
226 liveuser 1392
 
3 liveuser 1393
		#回傳結果
1394
		return $result;
226 liveuser 1395
 
249 liveuser 1396
		}#function createCertificate end
3 liveuser 1397
 
249 liveuser 1398
	/*
1399
	#函式說明:
291 liveuser 1400
	#解析RR檔案中其中的一行內容,回傳結果.
1401
	#回傳結果:
1402
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1403
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1404
	#$result["function"],當前執行的函式名稱.
1405
	#$result["argu"],所使用的參數.
1406
	#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
1407
	#$result["domain"],字串,RR所屬domain.
1408
	#$result["defaultTTL"],字串,預設的RR更新時間.
1409
	#$result["comment"],字串,一行的註解.
1410
	#必填參數:
1411
	#$conf["line"],字串,要解析的行內容.
1412
	$conf["line"]="";
1413
	#可省略參數:
1414
	#無.
1415
	#參考資料:
1416
	#無.
1417
	#備註:
1418
	#無.
1419
	*/
1420
	public static function parseRRline(&$conf){
1421
 
1422
		#初始化要回傳的結果
1423
		$result=array();
1424
 
1425
		#設置當其函數名稱
1426
		$result["function"]=__FUNCTION__;
1427
 
1428
		#如果 $conf 不為陣列
1429
		if(gettype($conf)!="array"){
1430
 
1431
			#設置執行失敗
1432
			$result["status"]="false";
1433
 
1434
			#設置執行錯誤訊息
1435
			$result["error"][]="\$conf變數須為陣列形態";
1436
 
1437
			#如果傳入的參數為 null
1438
			if($conf==null){
1439
 
1440
				#設置執行錯誤訊息
1441
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1442
 
1443
				}#if end
1444
 
1445
			#回傳結果
1446
			return $result;
1447
 
1448
			}#if end
1449
 
1450
		#取得參數
1451
		$result["argu"]=$conf;
1452
 
1453
		#檢查參數
1454
		#函式說明:
1455
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1456
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1457
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1458
		#$result["function"],當前執行的函式名稱.
1459
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1460
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1461
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1462
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1463
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1464
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1465
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1466
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1467
		#必填寫的參數:
1468
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1469
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1470
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1471
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("line");
1472
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
1473
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
1474
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1475
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1476
		#可以省略的參數:
1477
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1478
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1479
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
1480
		#$conf["skipableVariableCanNotBeEmpty"]=array();
1481
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1482
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThread");
1483
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1484
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1485
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1486
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
1487
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1488
		#$conf["arrayCountEqualCheck"][]=array();
1489
		#參考資料來源:
1490
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1491
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1492
		unset($conf["variableCheck::checkArguments"]);
1493
 
1494
		#如果檢查失敗
1495
		if($checkArguments["status"]==="false"){
1496
 
1497
			#設置錯誤識別
1498
			$result["status"]="false";
1499
 
1500
			#設置錯誤訊息
1501
			$result["error"]=$checkArguments;
1502
 
1503
			#回傳結果
1504
			return $result;
1505
 
1506
			}#if end
1507
 
1508
		#如果檢查不通過
1509
		if($checkArguments["passed"]==="false"){
1510
 
1511
			#設置錯誤識別
1512
			$result["status"]="false";
1513
 
1514
			#設置錯誤訊息
1515
			$result["error"]=$checkArguments;
1516
 
1517
			#回傳結果
1518
			return $result;
1519
 
1520
			}#if end
1521
 
1522
		#初始化要回傳的content
1523
		$result["content"]=array();
1524
 
1525
		#另存一份要處理的RR
1526
		$unFormatStr=$conf["line"];
1527
 
1528
		#初始化該行的資訊陣列
1529
		$info=array();
1530
 
1531
		#尋找";"開頭的內容,亦即整行都是註解.
1532
		#函式說明:
1533
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1534
		#回傳結果:
1535
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1536
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1537
		#$result["function"],當前執行的函式名稱.
1538
		#$result["argu"],所使用的參數.
1539
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1540
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1541
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1542
		#必填參數:
1543
		#$conf["input"],字串,要檢查的字串.
1544
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1545
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1546
		$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
1547
		#可省略參數:
1548
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1549
		#$conf["varEqual"]=array(null,"found");
1550
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1551
		#$conf["varCon"]=array("no_tail"=>" not");
1552
		#參考資料:
1553
		#無.
1554
		#備註:
1555
		#無.
1556
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1557
		unset($conf["search::findSpecifyStrFormat"]);
1558
 
1559
		#如果執行異常
1560
		if($findSpecifyStrFormat["status"]==="false"){
1561
 
1562
			#設置錯誤識別
1563
			$result["status"]="false";
1564
 
1565
			#設置錯誤訊息
1566
			$result["error"]=$findSpecifyStrFormat;
1567
 
1568
			#回傳結果
1569
			return $result;
1570
 
1571
			}#if end
1572
 
1573
		#如果有找到符合格式的內容
1574
		if($findSpecifyStrFormat["found"]==="true"){
1575
 
1576
			#儲存為註解
1577
			$result["comment"]=$unFormatStr;
1578
 
1579
			#設置執行正常
1580
			$result["status"]="true";
1581
 
1582
			#回傳結果
1583
			return $result;
1584
 
1585
			}#if end
1586
 
1587
		#函式說明:
1588
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1589
		#回傳結果:
1590
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1591
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1592
		#$result["function"],當前執行的函式名稱.
1593
		#$result["argu"],所使用的參數.
1594
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1595
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1596
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1597
		#必填參數:
1598
		#$conf["input"],字串,要檢查的字串.
1599
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1600
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1601
		$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
1602
		#可省略參數:
1603
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1604
		#$conf["varEqual"]=array(null,"found");
1605
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1606
		#$conf["varCon"]=array("no_tail"=>" not");
1607
		#參考資料:
1608
		#無.
1609
		#備註:
1610
		#無.
1611
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1612
		unset($conf["search::findSpecifyStrFormat"]);
1613
 
1614
		#如果執行異常
1615
		if($findSpecifyStrFormat["status"]==="false"){
1616
 
1617
			#設置錯誤識別
1618
			$result["status"]="false";
1619
 
1620
			#設置錯誤訊息
1621
			$result["error"]=$findSpecifyStrFormat;
1622
 
1623
			#回傳結果
1624
			return $result;
1625
 
1626
			}#if end
1627
 
1628
		#如果有找到符合格式的內容
1629
		if($findSpecifyStrFormat["found"]==="true"){
1630
 
1631
			#設置 type 的數值
1632
			$info["type"]="\$ORIGIN";
1633
 
1634
			#取得後面待處理的內容
1635
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
1636
 
1637
			#函式說明:
1638
			#將字串開頭的特定關鍵字移除.
1639
			#回傳結果:
1640
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1641
			#$result["error"],錯誤訊息陣列.
1642
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
1643
			#$result["function"],當前執行的函數名稱.
1644
			#$result["argu"],使用的參數.
1645
			#$result["content"],處理好的的字串內容.
1646
			#$result["deleted"],被移除的內容.
1647
			#必填參數:
1648
			#$conf["stringIn"],字串,要處理的字串.
1649
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
1650
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
1651
			$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
1652
			#可省略參數:
1653
			#無.
1654
			#參考資料:
1655
			#無.
1656
			#備註:
1657
			#無.
1658
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
1659
			unset($conf["stringProcess::delHeadStr"]);
1660
 
1661
			#如果執行異常
1662
			if($delHeadStr["status"]==="false"){
1663
 
1664
				#設置錯誤識別
1665
				$result["status"]="false";
1666
 
1667
				#設置錯誤訊息
1668
				$result["error"]=$delHeadStr;
1669
 
1670
				#回傳結果
1671
				return $result;
1672
 
1673
				}#if end
1674
 
1675
			#如果有移除開頭的字串
1676
			if($delHeadStr["founded"]==="true"){
1677
 
1678
				#取得處理後的結果
1679
				$unFormatStr=$delHeadStr["content"];
1680
 
1681
				}#if end
1682
 
1683
			#解析 $ORIGN 的數值, 以及後面是否有註解...
1684
			#函式說明:
1685
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1686
			#回傳結果:
1687
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1688
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1689
			#$result["function"],當前執行的函式名稱.
1690
			#$result["argu"],所使用的參數.
1691
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1692
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1693
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1694
			#必填參數:
1695
			#$conf["input"],字串,要檢查的字串.
1696
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1697
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1698
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
1699
			#可省略參數:
1700
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1701
			#$conf["varEqual"]=array(null,"found");
1702
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1703
			#$conf["varCon"]=array("no_tail"=>" not");
1704
			#參考資料:
1705
			#無.
1706
			#備註:
1707
			#無.
1708
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1709
			unset($conf["search::findSpecifyStrFormat"]);
1710
 
1711
			#如果執行異常
1712
			if($findSpecifyStrFormat["status"]==="false"){
1713
 
1714
				#設置錯誤識別
1715
				$result["status"]="false";
1716
 
1717
				#設置錯誤訊息
1718
				$result["error"]=$findSpecifyStrFormat;
1719
 
1720
				#回傳結果
1721
				return $result;
1722
 
1723
				}#if end
1724
 
1725
			#如果有數值跟註解
1726
			if($findSpecifyStrFormat["found"]==="true"){
1727
 
1728
				#儲存數值
1729
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
1730
 
1731
				#儲存zone domain
1732
				$result["domain"]=trim($info["value"]);
1733
 
1734
				#儲存註解
1735
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
1736
 
1737
				#儲存 RR 的記錄
1738
				$result["content"]=$info;
1739
 
1740
				#設置執行正常
1741
				$result["status"]="true";
1742
 
1743
				#回傳結果
1744
				return $result;
1745
 
1746
				}#if end
1747
 
1748
			#執行到這邊代表剩下的內容都是 value
1749
			$info["value"]=$unFormatStr;
1750
 
1751
			#儲存zone domain
1752
			$result["domain"]=trim($info["value"]);
1753
 
1754
			#儲存 RR 的記錄
1755
			$result["content"]=$info;
1756
 
1757
			#設置執行正常
1758
			$result["status"]="true";
1759
 
1760
			#回傳結果
1761
			return $result;
1762
 
1763
			}#if end
1764
 
1765
		#檢查是否為 $TTL 開頭
1766
		#函式說明:
1767
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1768
		#回傳結果:
1769
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1770
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1771
		#$result["function"],當前執行的函式名稱.
1772
		#$result["argu"],所使用的參數.
1773
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1774
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1775
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1776
		#必填參數:
1777
		#$conf["input"],字串,要檢查的字串.
1778
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1779
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1780
		$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
1781
		#可省略參數:
1782
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1783
		#$conf["varEqual"]=array(null,"found");
1784
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1785
		#$conf["varCon"]=array("no_tail"=>" not");
1786
		#參考資料:
1787
		#無.
1788
		#備註:
1789
		#無.
1790
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1791
		unset($conf["search::findSpecifyStrFormat"]);
1792
 
1793
		#如果執行異常
1794
		if($findSpecifyStrFormat["status"]==="false"){
1795
 
1796
			#設置錯誤識別
1797
			$result["status"]="false";
1798
 
1799
			#設置錯誤訊息
1800
			$result["error"]=$findSpecifyStrFormat;
1801
 
1802
			#回傳結果
1803
			return $result;
1804
 
1805
			}#if end
1806
 
1807
		#如果有找到符合格式的內容
1808
		if($findSpecifyStrFormat["found"]==="true"){
1809
 
1810
			#設置 type 的數值
1811
			$info["type"]="\$TTL";
1812
 
1813
			#取得後面待處理的內容
1814
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
1815
 
1816
			#函式說明:
1817
			#將字串開頭的特定關鍵字移除.
1818
			#回傳結果:
1819
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1820
			#$result["error"],錯誤訊息陣列.
1821
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
1822
			#$result["function"],當前執行的函數名稱.
1823
			#$result["argu"],使用的參數.
1824
			#$result["content"],處理好的的字串內容.
1825
			#$result["deleted"],被移除的內容.
1826
			#必填參數:
1827
			#$conf["stringIn"],字串,要處理的字串.
1828
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
1829
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
1830
			$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
1831
			#可省略參數:
1832
			#無.
1833
			#參考資料:
1834
			#無.
1835
			#備註:
1836
			#無.
1837
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
1838
			unset($conf["stringProcess::delHeadStr"]);
1839
 
1840
			#如果執行異常
1841
			if($delHeadStr["status"]==="false"){
1842
 
1843
				#設置錯誤識別
1844
				$result["status"]="false";
1845
 
1846
				#設置錯誤訊息
1847
				$result["error"]=$delHeadStr;
1848
 
1849
				#回傳結果
1850
				return $result;
1851
 
1852
				}#if end
1853
 
1854
			#如果有移除開頭的字串
1855
			if($delHeadStr["founded"]==="true"){
1856
 
1857
				#取得處理後的結果
1858
				$unFormatStr=$delHeadStr["content"];
1859
 
1860
				}#if end
1861
 
1862
			#解析 $TTL 的數值, 以及後面是否有註解...
1863
			#函式說明:
1864
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1865
			#回傳結果:
1866
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1867
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1868
			#$result["function"],當前執行的函式名稱.
1869
			#$result["argu"],所使用的參數.
1870
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1871
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1872
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1873
			#必填參數:
1874
			#$conf["input"],字串,要檢查的字串.
1875
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1876
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1877
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
1878
			#可省略參數:
1879
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1880
			#$conf["varEqual"]=array(null,"found");
1881
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1882
			#$conf["varCon"]=array("no_tail"=>" not");
1883
			#參考資料:
1884
			#無.
1885
			#備註:
1886
			#無.
1887
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1888
			unset($conf["search::findSpecifyStrFormat"]);
1889
 
1890
			#如果執行異常
1891
			if($findSpecifyStrFormat["status"]==="false"){
1892
 
1893
				#設置錯誤識別
1894
				$result["status"]="false";
1895
 
1896
				#設置錯誤訊息
1897
				$result["error"]=$findSpecifyStrFormat;
1898
 
1899
				#回傳結果
1900
				return $result;
1901
 
1902
				}#if end
1903
 
1904
			#如果有數值跟註解
1905
			if($findSpecifyStrFormat["found"]==="true"){
1906
 
1907
				#儲存數值
1908
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
1909
 
1910
				#儲存註解
1911
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
1912
 
1913
				#儲存預設的 TTL
1914
				$result["defaultTTL"]=trim($info["value"]);
1915
 
1916
				#儲存 RR 的記錄
1917
				$result["content"]=$info;
1918
 
1919
				#設置執行正常
1920
				$result["status"]="true";
1921
 
1922
				#回傳結果
1923
				return $result;
1924
 
1925
				}#if end
1926
 
1927
			#執行到這邊代表剩下的內容都是 value
1928
			$info["value"]=$unFormatStr;
1929
 
1930
			#儲存預設的 TTL
1931
			$result["defaultTTL"]=trim($info["value"]);
1932
 
1933
			#儲存 RR 的記錄
1934
			$result["content"]=$info;
1935
 
1936
			#設置執行正常
1937
			$result["status"]="true";
1938
 
1939
			#回傳結果
1940
			return $result;
1941
 
1942
			}#if end
1943
 
1944
		#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
1945
 
1946
		#函式說明:
1947
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1948
		#回傳結果:
1949
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1950
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1951
		#$result["function"],當前執行的函式名稱.
1952
		#$result["argu"],所使用的參數.
1953
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1954
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1955
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
1956
		#必填參數:
1957
		#$conf["input"],字串,要檢查的字串.
1958
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1959
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1960
		$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
1961
		#可省略參數:
1962
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1963
		#$conf["varEqual"]=array(null,"found");
1964
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1965
		#$conf["varCon"]=array("no_tail"=>" not");
1966
		#參考資料:
1967
		#無.
1968
		#備註:
1969
		#無.
1970
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1971
		unset($conf["search::findSpecifyStrFormat"]);
1972
 
1973
		#如果執行異常
1974
		if($findSpecifyStrFormat["status"]==="false"){
1975
 
1976
			#設置錯誤識別
1977
			$result["status"]="false";
1978
 
1979
			#設置錯誤訊息
1980
			$result["error"]=$findSpecifyStrFormat;
1981
 
1982
			#回傳結果
1983
			return $result;
1984
 
1985
			}#if end
1986
 
1987
		#如果存在"("
1988
		if($findSpecifyStrFormat["found"]==="true"){
1989
 
1990
			#取得無"("的內容
1991
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
1992
 
1993
			#取得拆下來的含開頭"("內容
1994
			$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
1995
 
1996
			}#if end
1997
 
1998
		#反之
1999
		else{
2000
 
2001
			#函式說明:
2002
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2003
			#回傳結果:
2004
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2005
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2006
			#$result["function"],當前執行的函式名稱.
2007
			#$result["argu"],所使用的參數.
2008
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2009
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2010
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2011
			#必填參數:
2012
			#$conf["input"],字串,要檢查的字串.
2013
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2014
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2015
			$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
2016
			#可省略參數:
2017
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2018
			#$conf["varEqual"]=array(null,"found");
2019
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2020
			#$conf["varCon"]=array("no_tail"=>" not");
2021
			#參考資料:
2022
			#無.
2023
			#備註:
2024
			#無.
2025
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2026
			unset($conf["search::findSpecifyStrFormat"]);
2027
 
2028
			#如果執行異常
2029
			if($findSpecifyStrFormat["status"]==="false"){
2030
 
2031
				#設置錯誤識別
2032
				$result["status"]="false";
2033
 
2034
				#設置錯誤訊息
2035
				$result["error"]=$findSpecifyStrFormat;
2036
 
2037
				#回傳結果
2038
				return $result;
2039
 
2040
				}#if end
2041
 
2042
			#如果存在"
2043
			if($findSpecifyStrFormat["found"]==="true"){
2044
 
2045
				#取得無"的內容
2046
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2047
 
2048
				#取得拆下來的含開頭"內容
2049
				$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
2050
 
2051
				}#if end
2052
 
2053
			#反之
2054
			else{
2055
 
2056
				#函式說明:
2057
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2058
				#回傳結果:
2059
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2060
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2061
				#$result["function"],當前執行的函式名稱.
2062
				#$result["argu"],所使用的參數.
2063
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2064
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2065
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2066
				#必填參數:
2067
				#$conf["input"],字串,要檢查的字串.
2068
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2069
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2070
				$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
2071
				#可省略參數:
2072
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2073
				#$conf["varEqual"]=array(null,"found");
2074
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2075
				#$conf["varCon"]=array("no_tail"=>" not");
2076
				#參考資料:
2077
				#無.
2078
				#備註:
2079
				#無.
2080
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2081
				unset($conf["search::findSpecifyStrFormat"]);
2082
 
2083
				#如果執行異常
2084
				if($findSpecifyStrFormat["status"]==="false"){
2085
 
2086
					#設置錯誤識別
2087
					$result["status"]="false";
2088
 
2089
					#設置錯誤訊息
2090
					$result["error"]=$findSpecifyStrFormat;
2091
 
2092
					#回傳結果
2093
					return $result;
2094
 
2095
					}#if end
2096
 
2097
				#如果存在";"
2098
				if($findSpecifyStrFormat["found"]==="true"){
2099
 
2100
					#取得無";"的內容
2101
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2102
 
2103
					#取得拆下來的含開頭";"內容
2104
					$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
2105
 
2106
					}#if end
2107
 
2108
				}#else end
2109
 
2110
			}#else end
2111
 
2112
		#檢查是否為 @ 開頭
2113
		#函式說明:
2114
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2115
		#回傳結果:
2116
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2117
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2118
		#$result["function"],當前執行的函式名稱.
2119
		#$result["argu"],所使用的參數.
2120
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2121
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2122
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2123
		#必填參數:
2124
		#$conf["input"],字串,要檢查的字串.
2125
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2126
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2127
		$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
2128
		#可省略參數:
2129
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2130
		#$conf["varEqual"]=array(null,"found");
2131
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2132
		#$conf["varCon"]=array("no_tail"=>" not");
2133
		#參考資料:
2134
		#無.
2135
		#備註:
2136
		#無.
2137
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2138
		unset($conf["search::findSpecifyStrFormat"]);
2139
 
2140
		#如果執行異常
2141
		if($findSpecifyStrFormat["status"]==="false"){
2142
 
2143
			#設置錯誤識別
2144
			$result["status"]="false";
2145
 
2146
			#設置錯誤訊息
2147
			$result["error"]=$findSpecifyStrFormat;
2148
 
2149
			#回傳結果
2150
			return $result;
2151
 
2152
			}#if end
2153
 
2154
		#如果有找到符合格式的內容
2155
		if($findSpecifyStrFormat["found"]==="true"){
2156
 
2157
			#設置 query 的數值
2158
			$info["query"]="@";
2159
 
2160
			#取得後面待處理的內容
2161
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
2162
 
2163
			#函式說明:
2164
			#將字串開頭的特定關鍵字移除.
2165
			#回傳結果:
2166
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2167
			#$result["error"],錯誤訊息陣列.
2168
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2169
			#$result["function"],當前執行的函數名稱.
2170
			#$result["argu"],使用的參數.
2171
			#$result["content"],處理好的的字串內容.
2172
			#$result["deleted"],被移除的內容.
2173
			#必填參數:
2174
			#$conf["stringIn"],字串,要處理的字串.
2175
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2176
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2177
			$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
2178
			#可省略參數:
2179
			#無.
2180
			#參考資料:
2181
			#無.
2182
			#備註:
2183
			#無.
2184
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2185
			unset($conf["stringProcess::delHeadStr"]);
2186
 
2187
			#如果執行異常
2188
			if($delHeadStr["status"]==="false"){
2189
 
2190
				#設置錯誤識別
2191
				$result["status"]="false";
2192
 
2193
				#設置錯誤訊息
2194
				$result["error"]=$delHeadStr;
2195
 
2196
				#回傳結果
2197
				return $result;
2198
 
2199
				}#if end
2200
 
2201
			#如果有移除開頭的字串
2202
			if($delHeadStr["founded"]==="true"){
2203
 
2204
				#取得處理後的結果 update time..IN..type...value;comment
2205
				$unFormatStr=$delHeadStr["content"];
2206
 
2207
				}#if end
2208
 
2209
			#debug
2210
			#var_dump(__LINE__,$delHeadStr);
2211
 
2212
			}#if end
2213
 
2214
		#反之
2215
		else{
2216
 
2217
			#執行到這邊,代表 query 為一非 @ 的字串
2218
			#函式說明:
2219
			#將指令字串解析成陣列,方便給予 external::callShell 使用
2220
			#回傳結果:
2221
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2222
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2223
			#$result["function"],當前執行的函式名稱.
2224
			#$result["content"],解析好的指令陣列.
2225
			#$result["cmd"],解析好的指令名稱.
2226
			#$result["argus"],解析好的參數陣列.
2227
			#$result["argu"],所使用的參數.
2228
			#必填參數
2229
			#$conf["cmdStr"],字串,要解析的指令字串
2230
			$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
2231
			#可省略參數:
2232
			#無.
2233
			#參考資料:
2234
			#無.
2235
			#備註:
2236
			#無.
2237
			$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
2238
			unset($conf["stringProcess::parseCmdString"]);
2239
 
2240
			#如果執行失敗
2241
			if($parseCmdString["status"]==="false"){
2242
 
2243
				#設置錯誤識別
2244
				$result["status"]="false";
2245
 
2246
				#設置錯誤訊息
2247
				$result["error"]=$parseCmdString;
2248
 
2249
				#debug
2250
				#$result["errorProcessLine"]=$line;
2251
 
2252
				#回傳結果
2253
				return $result;
2254
 
2255
				}#if end
2256
 
2257
			#取得 query 的內容
2258
			$info["query"]=$parseCmdString["content"][0];
2259
 
2260
			#剔除 query以及後面的" "跟\t
2261
			#函式說明:
2262
			#將字串開頭的特定關鍵字移除.
2263
			#回傳結果:
2264
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2265
			#$result["error"],錯誤訊息陣列.
2266
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2267
			#$result["function"],當前執行的函數名稱.
2268
			#$result["argu"],使用的參數.
2269
			#$result["content"],處理好的的字串內容.
2270
			#$result["deleted"],被移除的內容.
2271
			#必填參數:
2272
			#$conf["stringIn"],字串,要處理的字串.
2273
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2274
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2275
			$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
2276
			#可省略參數:
2277
			#無.
2278
			#參考資料:
2279
			#無.
2280
			#備註:
2281
			#無.
2282
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2283
			unset($conf["stringProcess::delHeadStr"]);
2284
 
2285
			#如果執行異常
2286
			if($delHeadStr["status"]==="false"){
2287
 
2288
				#設置錯誤識別
2289
				$result["status"]="false";
2290
 
2291
				#設置錯誤訊息
2292
				$result["error"]=$delHeadStr;
2293
 
2294
				#回傳結果
2295
				return $result;
2296
 
2297
				}#if end
2298
 
2299
			#取得update time..IN..type...value;comment
2300
			$unFormatStr=$delHeadStr["content"];
2301
 
2302
			}#else end
2303
 
2304
		#無窮迴圈
2305
		while(true){
2306
 
2307
			#解析 updateTime..IN..type...value...comment
2308
 
2309
			#判斷是否無 update time
2310
 
2311
			#函式說明:
2312
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2313
			#回傳結果:
2314
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2315
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2316
			#$result["function"],當前執行的函式名稱.
2317
			#$result["argu"],所使用的參數.
2318
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2319
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2320
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2321
			#必填參數:
2322
			#$conf["input"],字串,要檢查的字串.
2323
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2324
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2325
			$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
2326
			#可省略參數:
2327
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2328
			#$conf["varEqual"]=array(null,"found");
2329
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2330
			#$conf["varCon"]=array("no_tail"=>" not");
2331
			#參考資料:
2332
			#無.
2333
			#備註:
2334
			#無.
2335
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2336
			unset($conf["search::findSpecifyStrFormat"]);
2337
 
2338
			#如果執行異常
2339
			if($findSpecifyStrFormat["status"]==="false"){
2340
 
2341
				#設置錯誤識別
2342
				$result["status"]="false";
2343
 
2344
				#設置錯誤訊息
2345
				$result["error"]=$findSpecifyStrFormat;
2346
 
2347
				#回傳結果
2348
				return $result;
2349
 
2350
				}#if end
2351
 
2352
			#如果有找到符合格式的內容
2353
			if($findSpecifyStrFormat["found"]==="true"){
2354
 
2355
				#代表沒有 update time 欄位,因此儲存預設的TTL
2356
				$info["update"]=&$result["defaultTTL"];
2357
 
2358
				#取得剩下的 ...type...value;comment
2359
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
2360
 
2361
				#設置該行沒有指定 update time
2362
				$noUpdateTime="true";
2363
 
2364
				}#if end
2365
 
2366
			#反之
2367
			else{
2368
 
2369
				#設置該行有指定 update time
2370
				$noUpdateTime="false";
2371
 
2372
				#如果有指定 update time
2373
				if($noUpdateTime==="false"){
2374
 
2375
					#要來解析 update time
2376
					#函式說明:
2377
					#將字串進行解析,變成多個參數.
2378
					#回傳結果:
2379
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2380
					#$result["function"],當前執行的函式內容.
2381
					#$result["error"],錯誤訊息陣列.
2382
					#$result["content"],參數陣列.
2383
					#$result["count"],總共有幾個參數.
2384
					#必填參數:
2385
					#$conf["input"],字串,要解析成參數的字串.
2386
					$conf["stringProcess::parse"]["input"]=$unFormatStr;
2387
					#可省略參數:
2388
					#無.
2389
					#參考資料:
2390
					#無.
2391
					#備註:
2392
					#無.
2393
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
2394
					unset($conf["stringProcess::parse"]);
2395
 
2396
					#如果執行異常
2397
					if($parse["status"]==="false"){
2398
 
2399
						#設置錯誤識別
2400
						$result["status"]="false";
2401
 
2402
						#設置錯誤訊息
2403
						$result["error"]=$parse;
2404
 
2405
						#回傳結果
2406
						return $result;
2407
 
2408
						}#if end
2409
 
2410
					#取得更新時間
2411
					$info["update"]=$parse["content"][0];
2412
 
2413
					#取得 update time 後面的內容
2414
					#函式說明:
2415
					#將字串開頭的特定關鍵字移除.
2416
					#回傳結果:
2417
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2418
					#$result["error"],錯誤訊息陣列.
2419
					#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2420
					#$result["function"],當前執行的函數名稱.
2421
					#$result["argu"],使用的參數.
2422
					#$result["content"],處理好的的字串內容.
2423
					#$result["deleted"],被移除的內容.
2424
					#必填參數:
2425
					#$conf["stringIn"],字串,要處理的字串.
2426
					$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2427
					#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2428
					$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
2429
					#可省略參數:
2430
					#無.
2431
					#參考資料:
2432
					#無.
2433
					#備註:
2434
					#無.
2435
					$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2436
					unset($conf["stringProcess::delHeadStr"]);
2437
 
2438
					#如果執行異常
2439
					if($delHeadStr["status"]==="false"){
2440
 
2441
						#設置錯誤識別
2442
						$result["status"]="false";
2443
 
2444
						#設置錯誤訊息
2445
						$result["error"]=$delHeadStr;
2446
 
2447
						#回傳結果
2448
						return $result;
2449
 
2450
						}#if end
2451
 
2452
					#取得...IN...value;comment
2453
					$unFormatStr=$delHeadStr["content"];
2454
 
2455
					}#if end
2456
 
2457
				#取得 ...IN... 後面的內容
2458
				#函式說明:
2459
				#將字串開頭的特定關鍵字移除.
2460
				#回傳結果:
2461
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2462
				#$result["error"],錯誤訊息陣列.
2463
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2464
				#$result["function"],當前執行的函數名稱.
2465
				#$result["argu"],使用的參數.
2466
				#$result["content"],處理好的的字串內容.
2467
				#$result["deleted"],被移除的內容.
2468
				#必填參數:
2469
				#$conf["stringIn"],字串,要處理的字串.
2470
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2471
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2472
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
2473
				#可省略參數:
2474
				#無.
2475
				#參考資料:
2476
				#無.
2477
				#備註:
2478
				#無.
2479
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2480
				unset($conf["stringProcess::delHeadStr"]);
2481
 
2482
				#如果執行異常
2483
				if($delHeadStr["status"]==="false"){
2484
 
2485
					#設置錯誤識別
2486
					$result["status"]="false";
2487
 
2488
					#設置錯誤訊息
2489
					$result["error"]=$delHeadStr;
2490
 
2491
					#回傳結果
2492
					return $result;
2493
 
2494
					}#if end
2495
 
2496
				#取得IN...value;comment
2497
				$unFormatStr=$delHeadStr["content"];
2498
 
2499
				}#else end
2500
 
2501
			#解析 type...value;comment
2502
			#函式說明:
2503
			#將字串進行解析,變成多個參數.
2504
			#回傳結果:
2505
			#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2506
			#$result["function"],當前執行的函式內容.
2507
			#$result["error"],錯誤訊息陣列.
2508
			#$result["content"],參數陣列.
2509
			#$result["count"],總共有幾個參數.
2510
			#必填參數:
2511
			#$conf["input"],字串,要解析成參數的字串.
2512
			$conf["stringProcess::parse"]["input"]=$unFormatStr;
2513
			#可省略參數:
2514
			#無.
2515
			#參考資料:
2516
			#無.
2517
			#備註:
2518
			#無.
2519
			$parse=stringProcess::parse($conf["stringProcess::parse"]);
2520
			unset($conf["stringProcess::parse"]);
2521
 
2522
			#如果執行異常
2523
			if($parse["status"]==="false"){
2524
 
2525
				#設置錯誤識別
2526
				$result["status"]="false";
2527
 
2528
				#設置錯誤訊息
2529
				$result["error"]=$parse;
2530
 
2531
				#回傳結果
2532
				return $result;
2533
 
2534
				}#if end
2535
 
2536
			#取得 type
2537
			$info["type"]=$parse["content"][0];
2538
 
2539
			#取得 type...後面的value;comment內容
2540
			#函式說明:
2541
			#將字串開頭的特定關鍵字移除.
2542
			#回傳結果:
2543
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2544
			#$result["error"],錯誤訊息陣列.
2545
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2546
			#$result["function"],當前執行的函數名稱.
2547
			#$result["argu"],使用的參數.
2548
			#$result["content"],處理好的的字串內容.
2549
			#$result["deleted"],被移除的內容.
2550
			#必填參數:
2551
			#$conf["stringIn"],字串,要處理的字串.
2552
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2553
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2554
			$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
2555
			#可省略參數:
2556
			#無.
2557
			#參考資料:
2558
			#無.
2559
			#備註:
2560
			#無.
2561
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2562
			unset($conf["stringProcess::delHeadStr"]);
2563
 
2564
			#如果執行異常
2565
			if($delHeadStr["status"]==="false"){
2566
 
2567
				#設置錯誤識別
2568
				$result["status"]="false";
2569
 
2570
				#設置錯誤訊息
2571
				$result["error"]=$delHeadStr;
2572
 
2573
				#回傳結果
2574
				return $result;
2575
 
2576
				}#if end
2577
 
2578
			#取得 value;comment
2579
			$unFormatStr=$delHeadStr["content"];
2580
 
2581
			#如果有要合併回去的內容
2582
			if(isset($unFormatStr2add)){
2583
 
2584
				#合併回去內容
2585
				$unFormatStr=$unFormatStr.$unFormatStr2add;
2586
 
2587
				#移除用不到的變數
2588
				unset($unFormatStr2add);
2589
 
2590
				}#if end
2591
 
2592
			#如果type不為 CNAME 跟 TXT 跟 SOA
2593
			if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" ){
2594
 
2595
				#儲存value
2596
				$info["value"]=$unFormatStr;
2597
 
2598
				#判斷是否有 ";" 存在
2599
				#函式說明:
2600
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2601
				#回傳結果:
2602
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2603
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2604
				#$result["function"],當前執行的函式名稱.
2605
				#$result["argu"],所使用的參數.
2606
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2607
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2608
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2609
				#必填參數:
2610
				#$conf["input"],字串,要檢查的字串.
2611
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2612
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2613
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
2614
				#可省略參數:
2615
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2616
				#$conf["varEqual"]=array(null,"found");
2617
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2618
				#$conf["varCon"]=array("no_tail"=>" not");
2619
				#參考資料:
2620
				#無.
2621
				#備註:
2622
				#無.
2623
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2624
				unset($conf["search::findSpecifyStrFormat"]);
2625
 
2626
				#如果執行異常
2627
				if($findSpecifyStrFormat["status"]==="false"){
2628
 
2629
					#設置錯誤識別
2630
					$result["status"]="false";
2631
 
2632
					#設置錯誤訊息
2633
					$result["error"]=$findSpecifyStrFormat;
2634
 
2635
					#回傳結果
2636
					return $result;
2637
 
2638
					}#if end
2639
 
2640
				#如果有 ";"
2641
				if($findSpecifyStrFormat["found"]==="true"){
2642
 
2643
					#儲存value
2644
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
2645
 
2646
					#儲存comment
2647
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
2648
 
2649
					}#if end
2650
 
2651
				#儲存 RR 的記錄
2652
				$result["content"]=$info;
2653
 
2654
				#設置執行正常
2655
				$result["status"]="true";
2656
 
2657
				#回傳結果
2658
				return $result;
2659
 
2660
				}#if end
2661
 
2662
			#執行到這邊,代表type為CNAME或TXT或SOA
2663
 
2664
			#如果 type 是 SOA
2665
			if($info["type"]==="SOA"){
2666
 
2667
				#如果要debug
2668
				if($conf["debug"]==="true"){
2669
 
2670
					#函式說明:
2671
					#撰寫log
2672
					#回傳結果:
2673
					#$result["status"],狀態,"true"或"false".
2674
					#$result["error"],錯誤訊息陣列.
2675
					#$result["function"],當前函式的名稱.
2676
					#$result["argu"],使用的參數.
2677
					#$result["content"],要寫入log的內容字串.
2678
					#必填參數:
2679
					#$conf["path"],字串,log檔案的路徑與名稱.
2680
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2681
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2682
					$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
2683
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2684
					$conf["logs::record"]["fileArgu"]=__FILE__;
2685
					#可省略參數:
2686
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2687
					#$conf["rewrite"]="false";
2688
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2689
					#$conf["returnOnly"]="true";
2690
					#參考資料:
2691
					#無.
2692
					#備註:
2693
					#無.
2694
					$record=logs::record($conf["logs::record"]);
2695
					unset($conf["logs::record"]);
2696
 
2697
					}#if end
2698
 
2699
				#SOA 範例
2700
				#@	1200	IN	SOA	dns.qbpwcf.org. liveuser.qbpwcf.org. 2026012205 10800 1800 1728000 1200 ;domain name server, admin mail, serial, refresh time, expire, Negative Caching, https://bind9.readthedocs.io/en/latest/chapter3.html#term-SOA-minimum
2701
 
2702
				#再度嘗試分割
2703
				#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
2704
 
2705
				#函式說明:
2706
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2707
				#回傳結果:
2708
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2709
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2710
				#$result["function"],當前執行的函式名稱.
2711
				#$result["argu"],所使用的參數.
2712
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2713
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2714
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2715
				#必填參數:
2716
				#$conf["input"],字串,要檢查的字串.
2717
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2718
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2719
				$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
2720
				#可省略參數:
2721
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2722
				#$conf["varEqual"]=array(null,"found");
2723
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2724
				#$conf["varCon"]=array("no_tail"=>" not");
2725
				#參考資料:
2726
				#無.
2727
				#備註:
2728
				#無.
2729
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2730
				unset($conf["search::findSpecifyStrFormat"]);
2731
 
2732
				#如果執行異常
2733
				if($findSpecifyStrFormat["status"]==="false"){
2734
 
2735
					#設置錯誤識別
2736
					$result["status"]="false";
2737
 
2738
					#設置錯誤訊息
2739
					$result["error"]=$findSpecifyStrFormat;
2740
 
2741
					#回傳結果
2742
					return $result;
2743
 
2744
					}#if end
2745
 
2746
				#如果存在"("
2747
				if($findSpecifyStrFormat["found"]==="true"){
2748
 
2749
					#取得無"("的內容
2750
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2751
 
2752
					#取得拆下來的含開頭"("內容
2753
					$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
2754
 
2755
					}#if end
2756
 
2757
				#反之
2758
				else{
2759
 
2760
					#函式說明:
2761
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2762
					#回傳結果:
2763
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2764
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2765
					#$result["function"],當前執行的函式名稱.
2766
					#$result["argu"],所使用的參數.
2767
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2768
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2769
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2770
					#必填參數:
2771
					#$conf["input"],字串,要檢查的字串.
2772
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2773
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2774
					$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
2775
					#可省略參數:
2776
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2777
					#$conf["varEqual"]=array(null,"found");
2778
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2779
					#$conf["varCon"]=array("no_tail"=>" not");
2780
					#參考資料:
2781
					#無.
2782
					#備註:
2783
					#無.
2784
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2785
					unset($conf["search::findSpecifyStrFormat"]);
2786
 
2787
					#如果執行異常
2788
					if($findSpecifyStrFormat["status"]==="false"){
2789
 
2790
						#設置錯誤識別
2791
						$result["status"]="false";
2792
 
2793
						#設置錯誤訊息
2794
						$result["error"]=$findSpecifyStrFormat;
2795
 
2796
						#回傳結果
2797
						return $result;
2798
 
2799
						}#if end
2800
 
2801
					#如果存在"
2802
					if($findSpecifyStrFormat["found"]==="true"){
2803
 
2804
						#取得無"的內容
2805
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2806
 
2807
						#取得拆下來的含開頭"內容
2808
						$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
2809
 
2810
						}#if end
2811
 
2812
					#反之
2813
					else{
2814
 
2815
						#函式說明:
2816
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2817
						#回傳結果:
2818
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2819
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
2820
						#$result["function"],當前執行的函式名稱.
2821
						#$result["argu"],所使用的參數.
2822
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2823
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2824
						#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2825
						#必填參數:
2826
						#$conf["input"],字串,要檢查的字串.
2827
						$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2828
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2829
						$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
2830
						#可省略參數:
2831
						#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2832
						#$conf["varEqual"]=array(null,"found");
2833
						#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2834
						#$conf["varCon"]=array("no_tail"=>" not");
2835
						#參考資料:
2836
						#無.
2837
						#備註:
2838
						#無.
2839
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2840
						unset($conf["search::findSpecifyStrFormat"]);
2841
 
2842
						#如果執行異常
2843
						if($findSpecifyStrFormat["status"]==="false"){
2844
 
2845
							#設置錯誤識別
2846
							$result["status"]="false";
2847
 
2848
							#設置錯誤訊息
2849
							$result["error"]=$findSpecifyStrFormat;
2850
 
2851
							#回傳結果
2852
							return $result;
2853
 
2854
							}#if end
2855
 
2856
						#如果存在";"
2857
						if($findSpecifyStrFormat["found"]==="true"){
2858
 
2859
							#取得無";"的內容
2860
							$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2861
 
2862
							#取得拆下來的含開頭";"內容
2863
							$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
2864
 
2865
							}#if end
2866
 
2867
						}#else end
2868
 
2869
					}#else end
2870
 
2871
				#取得 serial number
2872
				#函式說明:
2873
				#將字串進行解析,變成多個參數.
2874
				#回傳結果:
2875
				#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2876
				#$result["function"],當前執行的函式內容.
2877
				#$result["error"],錯誤訊息陣列.
2878
				#$result["content"],參數陣列.
2879
				#$result["count"],總共有幾個參數.
2880
				#必填參數:
2881
				#$conf["input"],字串,要解析成參數的字串.
2882
				$conf["stringProcess::parse"]["input"]=$unFormatStr;
2883
				#可省略參數:
2884
				#無.
2885
				#參考資料:
2886
				#無.
2887
				#備註:
2888
				#無.
2889
				$parse=stringProcess::parse($conf["stringProcess::parse"]);
2890
				unset($conf["stringProcess::parse"]);
2891
 
2892
				#如果執行異常
2893
				if($parse["status"]==="false"){
2894
 
2895
					#設置錯誤識別
2896
					$result["status"]="false";
2897
 
2898
					#設置錯誤訊息
2899
					$result["error"]=$parse;
2900
 
2901
					#回傳結果
2902
					return $result;
2903
 
2904
					}#if end
2905
 
2906
				#取得serial number
2907
				$serialNo=$parse["content"][2];
2908
 
2909
				#serialNo+1
2910
				$serialNo++;
2911
 
2912
				#回存
2913
				$parse["content"][2]=(string)$serialNo;
2914
 
2915
				#函式說明:
2916
				#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
2917
				#回傳的結果:
2918
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2919
				#$result["function"],當前執行的function名稱
2920
				#$result["error"],錯誤訊息陣列.
2921
				#$result["content"],處理好的字串.
2922
				#$result["argu"],使用的參數.
2923
				#必填參數:
2924
				#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
2925
				$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
2926
				#可省略參數:
2927
				#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
2928
				$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
2929
				#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
2930
				$conf["arrays::arrayToString"]["skipEnd"]="true";
2931
				#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
2932
				#$conf["spiltSymbolAtStart"]="";
2933
				#參考資料:
2934
				#無.
2935
				#備註:
2936
				#無.
2937
				$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
2938
				unset($conf["arrays::arrayToString"]);
2939
 
2940
				#如果執行異常
2941
				if($arrayToString["status"]==="false"){
2942
 
2943
					#設置錯誤識別
2944
					$result["status"]="false";
2945
 
2946
					#設置錯誤訊息
2947
					$result["error"]=$arrayToString;
2948
 
2949
					#回傳結果
2950
					return $result;
2951
 
2952
					}#if end
2953
 
2954
				#取得更新 serial number 後的 SOA value string
2955
				$unFormatStr=$arrayToString["content"];
2956
 
2957
				#如果有要合併回去的內容
2958
				if(isset($unFormatStr2add)){
2959
 
2960
					#合併回去內容
2961
					$unFormatStr=$unFormatStr.$unFormatStr2add;
2962
 
2963
					#移除用不到的變數
2964
					unset($unFormatStr2add);
2965
 
2966
					}#if end
2967
 
2968
				#假設剩下的沒有註解都是 value
2969
				$info["value"]=$unFormatStr;
2970
 
2971
				#函式說明:
2972
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2973
				#回傳結果:
2974
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2975
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2976
				#$result["function"],當前執行的函式名稱.
2977
				#$result["argu"],所使用的參數.
2978
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2979
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2980
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2981
				#必填參數:
2982
				#$conf["input"],字串,要檢查的字串.
2983
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2984
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2985
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
2986
				#可省略參數:
2987
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2988
				#$conf["varEqual"]=array(null,"found");
2989
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2990
				#$conf["varCon"]=array("no_tail"=>" not");
2991
				#參考資料:
2992
				#無.
2993
				#備註:
2994
				#無.
2995
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2996
				unset($conf["search::findSpecifyStrFormat"]);
2997
 
2998
				#如果執行異常
2999
				if($findSpecifyStrFormat["status"]==="false"){
3000
 
3001
					#設置錯誤識別
3002
					$result["status"]="false";
3003
 
3004
					#設置錯誤訊息
3005
					$result["error"]=$findSpecifyStrFormat;
3006
 
3007
					#回傳結果
3008
					return $result;
3009
 
3010
					}#if end
3011
 
3012
				#如果有符合格式
3013
				if($findSpecifyStrFormat["found"]==="true"){
3014
 
3015
					#儲存 value
3016
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3017
 
3018
					#儲存 comment
3019
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3020
 
3021
					}#if end
3022
 
3023
				#儲存 RR 的記錄
3024
				$result["content"]=$info;
3025
 
3026
				#設置執行正常
3027
				$result["status"]="true";
3028
 
3029
				#回傳結果
3030
				return $result;
3031
 
3032
				}#if end
3033
 
3034
			#執行到這邊代表不是 SOA
3035
 
3036
			#尋找是否有(...)...的內容存在
3037
			#函式說明:
3038
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3039
			#回傳結果:
3040
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3041
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3042
			#$result["function"],當前執行的函式名稱.
3043
			#$result["argu"],所使用的參數.
3044
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3045
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3046
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3047
			#必填參數:
3048
			#$conf["input"],字串,要檢查的字串.
3049
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3050
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3051
			$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
3052
			#可省略參數:
3053
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3054
			#$conf["varEqual"]=array(null,"found");
3055
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3056
			#$conf["varCon"]=array("no_tail"=>" not");
3057
			#參考資料:
3058
			#無.
3059
			#備註:
3060
			#無.
3061
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3062
			unset($conf["search::findSpecifyStrFormat"]);
3063
 
3064
			#如果執行異常
3065
			if($findSpecifyStrFormat["status"]==="false"){
3066
 
3067
				#設置錯誤識別
3068
				$result["status"]="false";
3069
 
3070
				#設置錯誤訊息
3071
				$result["error"]=$findSpecifyStrFormat;
3072
 
3073
				#回傳結果
3074
				return $result;
3075
 
3076
				}#if end
3077
 
3078
			#如果有 有符合 ($value);${comment} 的格式
3079
			if($findSpecifyStrFormat["found"]==="true"){
3080
 
3081
				#儲存value
3082
				$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
3083
 
3084
				#儲存comment
3085
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3086
 
3087
				#儲存 RR 的記錄
3088
				$result["content"]=$info;
3089
 
3090
				#設置執行正常
3091
				$result["status"]="true";
3092
 
3093
				#回傳結果
3094
				return $result;
3095
 
3096
				}#if end
3097
 
3098
			#執行到這邊代表沒有 (...)... 的內容存在
3099
 
3100
			#尋找是否有 (...) 的內容存在
3101
			#函式說明:
3102
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3103
			#回傳結果:
3104
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3105
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3106
			#$result["function"],當前執行的函式名稱.
3107
			#$result["argu"],所使用的參數.
3108
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3109
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3110
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3111
			#必填參數:
3112
			#$conf["input"],字串,要檢查的字串.
3113
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3114
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3115
			$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
3116
			#可省略參數:
3117
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3118
			#$conf["varEqual"]=array(null,"found");
3119
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3120
			#$conf["varCon"]=array("no_tail"=>" not");
3121
			#參考資料:
3122
			#無.
3123
			#備註:
3124
			#無.
3125
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3126
			unset($conf["search::findSpecifyStrFormat"]);
3127
 
3128
			#如果執行異常
3129
			if($findSpecifyStrFormat["status"]==="false"){
3130
 
3131
				#設置錯誤識別
3132
				$result["status"]="false";
3133
 
3134
				#設置錯誤訊息
3135
				$result["error"]=$findSpecifyStrFormat;
3136
 
3137
				#回傳結果
3138
				return $result;
3139
 
3140
				}#if end
3141
 
3142
			#如果有 有符合 ($value);${comment} 的格式
3143
			if($findSpecifyStrFormat["found"]==="true"){
3144
 
3145
				#儲存value
3146
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3147
 
3148
				#儲存 RR 的記錄
3149
				$result["content"]=$info;
3150
 
3151
				#設置執行正常
3152
				$result["status"]="true";
3153
 
3154
				#回傳結果
3155
				return $result;
3156
 
3157
				}#if end
3158
 
3159
			#執行到這邊代表沒有 (...) 的內容存在
3160
 
3161
			#尋找有無 "...";... 的內容存在
3162
			#函式說明:
3163
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3164
			#回傳結果:
3165
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3166
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3167
			#$result["function"],當前執行的函式名稱.
3168
			#$result["argu"],所使用的參數.
3169
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3170
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3171
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3172
			#必填參數:
3173
			#$conf["input"],字串,要檢查的字串.
3174
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3175
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3176
			$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
3177
			#可省略參數:
3178
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3179
			#$conf["varEqual"]=array(null,"found");
3180
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3181
			#$conf["varCon"]=array("no_tail"=>" not");
3182
			#參考資料:
3183
			#無.
3184
			#備註:
3185
			#無.
3186
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3187
			unset($conf["search::findSpecifyStrFormat"]);
3188
 
3189
			#如果執行異常
3190
			if($findSpecifyStrFormat["status"]==="false"){
3191
 
3192
				#設置錯誤識別
3193
				$result["status"]="false";
3194
 
3195
				#設置錯誤訊息
3196
				$result["error"]=$findSpecifyStrFormat;
3197
 
3198
				#回傳結果
3199
				return $result;
3200
 
3201
				}#if end
3202
 
3203
			#如果有 有符合 "$value";${comment} 的格式
3204
			if($findSpecifyStrFormat["found"]==="true"){
3205
 
3206
				#儲存value
3207
				$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
3208
 
3209
				#儲存comment
3210
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3211
 
3212
				#儲存 RR 的記錄
3213
				$result["content"]=$info;
3214
 
3215
				#設置執行正常
3216
				$result["status"]="true";
3217
 
3218
				#回傳結果
3219
				return $result;
3220
 
3221
				}#if end
3222
 
3223
			#執行到這邊代表沒有 "$value";${comment} 的格式
3224
 
3225
			#尋找有無 "..." 的內容存在
3226
			#函式說明:
3227
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3228
			#回傳結果:
3229
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3230
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3231
			#$result["function"],當前執行的函式名稱.
3232
			#$result["argu"],所使用的參數.
3233
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3234
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3235
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3236
			#必填參數:
3237
			#$conf["input"],字串,要檢查的字串.
3238
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3239
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3240
			$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
3241
			#可省略參數:
3242
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3243
			#$conf["varEqual"]=array(null,"found");
3244
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3245
			#$conf["varCon"]=array("no_tail"=>" not");
3246
			#參考資料:
3247
			#無.
3248
			#備註:
3249
			#無.
3250
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3251
			unset($conf["search::findSpecifyStrFormat"]);
3252
 
3253
			#如果執行異常
3254
			if($findSpecifyStrFormat["status"]==="false"){
3255
 
3256
				#設置錯誤識別
3257
				$result["status"]="false";
3258
 
3259
				#設置錯誤訊息
3260
				$result["error"]=$findSpecifyStrFormat;
3261
 
3262
				#回傳結果
3263
				return $result;
3264
 
3265
				}#if end
3266
 
3267
			#如果有 有符合 "$value" 的格式
3268
			if($findSpecifyStrFormat["found"]==="true"){
3269
 
3270
				#儲存value
3271
				$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
3272
 
3273
				#儲存 RR 的記錄
3274
				$result["content"]=$info;
3275
 
3276
				#設置執行正常
3277
				$result["status"]="true";
3278
 
3279
				#回傳結果
3280
				return $result;
3281
 
3282
				}#if end
3283
 
3284
			#執行到這邊代表沒有 "$value" 格式的內容
3285
 
3286
			#檢查是否有 $value;$comment 格式的內容
3287
			#函式說明:
3288
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3289
			#回傳結果:
3290
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3291
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3292
			#$result["function"],當前執行的函式名稱.
3293
			#$result["argu"],所使用的參數.
3294
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3295
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3296
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3297
			#必填參數:
3298
			#$conf["input"],字串,要檢查的字串.
3299
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3300
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3301
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3302
			#可省略參數:
3303
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3304
			#$conf["varEqual"]=array(null,"found");
3305
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3306
			#$conf["varCon"]=array("no_tail"=>" not");
3307
			#參考資料:
3308
			#無.
3309
			#備註:
3310
			#無.
3311
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3312
			unset($conf["search::findSpecifyStrFormat"]);
3313
 
3314
			#如果執行異常
3315
			if($findSpecifyStrFormat["status"]==="false"){
3316
 
3317
				#設置錯誤識別
3318
				$result["status"]="false";
3319
 
3320
				#設置錯誤訊息
3321
				$result["error"]=$findSpecifyStrFormat;
3322
 
3323
				#回傳結果
3324
				return $result;
3325
 
3326
				}#if end
3327
 
3328
			#如果有 有符合 "$value" 的格式
3329
			if($findSpecifyStrFormat["found"]==="true"){
3330
 
3331
				#儲存value
3332
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3333
 
3334
				#儲存comment
3335
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3336
 
3337
				#儲存 RR 的記錄
3338
				$result["content"]=$info;
3339
 
3340
				#設置執行正常
3341
				$result["status"]="true";
3342
 
3343
				#回傳結果
3344
				return $result;
3345
 
3346
				}#if end
3347
 
3348
			#執行到這邊代表沒有 ${value};${comment} 格式的內容
3349
 
3350
			#亦即剩下的內容都是 value
3351
 
3352
			#儲存value
3353
			$info["value"]=$unFormatStr;
3354
 
3355
			#儲存 RR 的記錄
3356
			$result["content"]=$info;
3357
 
3358
			#設置執行正常
3359
			$result["status"]="true";
3360
 
3361
			#回傳結果
3362
			return $result;
3363
 
3364
			}#while end
3365
 
3366
		}#function parseRRline end
3367
 
3368
	/*
3369
	#函式說明:
249 liveuser 3370
	#新增DNS記錄到檔案裡面.
3371
	#回傳結果:
3372
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3373
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
3374
	#$result["function"],當前執行的函式名稱.
3375
	#$result["argu"],所使用的參數.
3376
	#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
255 liveuser 3377
	#$result["domain"],字串,RR所屬domain.
3378
	#$result["defaultTTL"],字串,預設的RR更新時間.
249 liveuser 3379
	#$result["comment"],字串陣列,逐行的註解.
3380
	#必填參數:
255 liveuser 3381
	#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型(支援的有"A","TXT","CNAME","SOA","$TTL","$ORIGIN")、答案、註解.
249 liveuser 3382
	$conf["add"]=array();
3383
	#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
3384
	$conf["dnsRecordFile"]="";
3385
	#可省略參數:
3386
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
3387
	#$conf["writeNow"]="false";
253 liveuser 3388
	#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
3389
	#$conf["debug"]="false";
293 liveuser 3390
	#$conf["multiThreads"],字串,是否啟動多執行序加快執行速度,預設為"false"代表不要;反之為"true"代表要.
3391
	#$conf["multiThreads"]="false";
249 liveuser 3392
	#參考資料:
3393
	#無.
3394
	#備註:
3395
	#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
291 liveuser 3396
	#本套件是透過sshfs掛載來存取RR(dns記錄檔案),其檔案建議的擁有者權限為 root:qbpwcf,權限代碼為 774.
249 liveuser 3397
	#php-pear上的Net_DNS2也可以解析RR.
293 liveuser 3398
	#參數 multiThreads 目前有 bug.
249 liveuser 3399
	*/
3400
	public static function updateDnsRecordFile(&$conf){
3401
 
3402
		#初始化要回傳的結果
3403
		$result=array();
3404
 
3405
		#設置當其函數名稱
3406
		$result["function"]=__FUNCTION__;
3407
 
3408
		#如果 $conf 不為陣列
3409
		if(gettype($conf)!="array"){
3410
 
3411
			#設置執行失敗
3412
			$result["status"]="false";
3413
 
3414
			#設置執行錯誤訊息
3415
			$result["error"][]="\$conf變數須為陣列形態";
3416
 
3417
			#如果傳入的參數為 null
3418
			if($conf==null){
3419
 
3420
				#設置執行錯誤訊息
3421
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3422
 
3423
				}#if end
3424
 
3425
			#回傳結果
3426
			return $result;
3427
 
3428
			}#if end
3429
 
3430
		#取得參數
3431
		$result["argu"]=$conf;
3432
 
3433
		#檢查參數
3434
		#函式說明:
3435
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3436
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3437
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3438
		#$result["function"],當前執行的函式名稱.
3439
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3440
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3441
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3442
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
3443
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
3444
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3445
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3446
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3447
		#必填寫的參數:
3448
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3449
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3450
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3451
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("add","dnsRecordFile");
3452
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3453
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
3454
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3455
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3456
		#可以省略的參數:
3457
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3458
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3459
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
3460
		#$conf["skipableVariableCanNotBeEmpty"]=array();
3461
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 3462
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThreads");
249 liveuser 3463
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
291 liveuser 3464
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
249 liveuser 3465
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
291 liveuser 3466
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
249 liveuser 3467
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3468
		#$conf["arrayCountEqualCheck"][]=array();
3469
		#參考資料來源:
3470
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3471
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3472
		unset($conf["variableCheck::checkArguments"]);
3473
 
3474
		#如果檢查失敗
3475
		if($checkArguments["status"]==="false"){
3476
 
3477
			#設置錯誤識別
3478
			$result["status"]="false";
3479
 
3480
			#設置錯誤訊息
3481
			$result["error"]=$checkArguments;
3482
 
3483
			#回傳結果
3484
			return $result;
3485
 
3486
			}#if end
3487
 
3488
		#如果檢查不通過
3489
		if($checkArguments["passed"]==="false"){
3490
 
3491
			#設置錯誤識別
3492
			$result["status"]="false";
3493
 
3494
			#設置錯誤訊息
3495
			$result["error"]=$checkArguments;
3496
 
3497
			#回傳結果
3498
			return $result;
3499
 
3500
			}#if end
3501
 
3502
		#初始化要回傳的content
3503
		$result["content"]=array();
3504
 
3505
		#初始化儲存逐行的註解.
3506
		$result["comment"]=array();
3507
 
3508
		#預設的zone file domain為空
3509
		$result["domain"]="";
3510
 
3511
		#預設的 update 時間
3512
		$result["defaultTTL"]=3600;
3513
 
3514
		#取得 dns 記錄檔案的內容
3515
		#函式說明:
3516
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
3517
		#回傳的變數說明:
3518
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
3519
		#$result["error"],錯誤訊息提示.
3520
		#$result["warning"],警告訊息.
3521
		#$result["function"],當前執行的函數名稱.
3522
		#$result["fileContent"],爲檔案的內容陣列.
3523
		#$result["lineCount"],爲檔案內容總共的行數.
3524
		#$result["fullContent"],為檔案的完整內容.
3525
		#$result["base64dataOnly"],檔案的base64data.
3526
		#$result["base64data"],為在網頁上給予src參數的數值.
3527
		#$result["mimeType"],為檔案的mime type.
3528
		#必填參數:
3529
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
3530
		$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$conf["dnsRecordFile"];
3531
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3532
		$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
3533
		#可省略參數:
3534
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
3535
		$conf["fileAccesss::getFileContent"]["web"]="false";
3536
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
3537
		#$conf["createIfnotExist"]="false";
3538
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
3539
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
3540
		#參考資料:
3541
		#file(),取得檔案內容的行數.
3542
		#file=>http:#php.net/manual/en/function.file.php
3543
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
3544
		#filesize=>http://php.net/manual/en/function.filesize.php
3545
		#參考資料:
3546
		#無.
3547
		#備註:
3548
		#無.
3549
		$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
3550
		unset($conf["fileAccesss::getFileContent"]);
3551
 
3552
		#如果檢查失敗
3553
		if($getFileContent["status"]==="false"){
3554
 
3555
			#設置錯誤識別
3556
			$result["status"]="false";
3557
 
3558
			#設置錯誤訊息
3559
			$result["error"]=$getFileContent;
3560
 
3561
			#回傳結果
3562
			return $result;
3563
 
3564
			}#if end
3565
 
3566
		#取得每行內容
3567
		$lines=$getFileContent["fileContent"];
3568
 
3569
		/*
3570
		範例每行內容:
3571
		$ORIGIN server.domain.	;base domain-name,in this Resource Records (RR) file,"@" equal to base domain-name.
3572
		$TTL 86400	;default TTL for zone
3573
		@	1200	IN	SOA	dns.server.domain. admin.server.domain. 2026012205 10800 1800 1728000 1200 ;domain name server, admin mail, serial, refresh time, expire, Negative Caching, https://bind9.readthedocs.io/en/latest/chapter3.html#term-SOA-minimum
3574
		@	3600	IN	TXT	"v=spf1 a mx ~all"
3575
		@	86400	IN	MX	1 mail.server.domain.
3576
		@	86400	IN	A	1.1.1.1
3577
		mail.server.domain.	IN	1.1.1.1
3578
		10-42-0-1	IN	A	10.42.0.1
3579
		101-free        IN      A	101.101.101.101
3580
		127-0-0-1	IN	A	127.0.0.1
3581
		_dmarc	IN	TXT	"v=DMARC1;p=reject;sp=reject;pct=100;adkim=r;aspf=r;fo=1;ri=86400;rua=mailto:admin@server.domain"
3582
		default._domainkey	IN	TXT	( "v=DKIM1; k=rsa;" "p=MIGfMA0GCSqG/SIb3DQEBAQQAB" )  ; ----- DKIM key default for qbpwcf.org
3583
		...
3584
		*/
3585
 
3586
		#針對每行內容
3587
		foreach($lines as $lineNo => $line){
3588
 
291 liveuser 3589
			#如果要啟用多執行序
293 liveuser 3590
			if($conf["multiThreads"]==="true"){
291 liveuser 3591
 
293 liveuser 3592
				#如果要debug
3593
				if($conf["debug"]==="true"){
291 liveuser 3594
 
293 liveuser 3595
					#函式說明:
3596
					#撰寫log
3597
					#回傳結果:
3598
					#$result["status"],狀態,"true"或"false".
3599
					#$result["error"],錯誤訊息陣列.
3600
					#$result["function"],當前函式的名稱.
3601
					#$result["argu"],使用的參數.
3602
					#$result["content"],要寫入log的內容字串.
3603
					#必填參數:
3604
					#$conf["path"],字串,log檔案的路徑與名稱.
3605
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3606
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3607
					$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR through multi threads.".PHP_EOL;
3608
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3609
					$conf["logs::record"]["fileArgu"]=__FILE__;
3610
					#可省略參數:
3611
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3612
					#$conf["rewrite"]="false";
3613
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3614
					#$conf["returnOnly"]="true";
3615
					#參考資料:
3616
					#無.
3617
					#備註:
3618
					#無.
3619
					$record=logs::record($conf["logs::record"]);
3620
					unset($conf["logs::record"]);
291 liveuser 3621
 
293 liveuser 3622
					}#if end
3623
 
3624
				#初始化要執行的 php 程式
3625
				$phpCode2run="php -r ";
291 liveuser 3626
 
293 liveuser 3627
				#php code not escaped
3628
				$phpCode2escaped=<<<'PHP'
3629
/*
291 liveuser 3630
 
293 liveuser 3631
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
3632
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3633
 
3634
    This file is part of QBPWCF.
3635
 
3636
    QBPWCF is free software: you can redistribute it and/or modify
3637
    it under the terms of the GNU General Public License as published by
3638
    the Free Software Foundation, either version 3 of the License, or
3639
    (at your option) any later version.
3640
 
3641
    QBPWCF is distributed in the hope that it will be useful,
3642
    but WITHOUT ANY WARRANTY; without even the implied warranty of
3643
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3644
    GNU General Public License for more details.
3645
 
3646
    You should have received a copy of the GNU General Public License
3647
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
3648
 
3649
*/
3650
 
3651
#使用命名空間qbpwcf
3652
namespace qbpwcf;
3653
 
3654
#匯入套件
3655
PHP;
3656
 
3657
#設置 lib root path
3658
$libPath=pathinfo(__FILE__)["dirname"]."/..";
3659
 
3660
#串接匯入QBPWCF套件
3661
$phpCode2escaped=$phpCode2escaped.PHP_EOL."require_once(\"".$libPath."/qbpwcf/allInOne.php\");";
3662
 
3663
#串接php程式
3664
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
291 liveuser 3665
#函式說明:
3666
#解析RR檔案中其中的一行內容.
3667
#回傳結果:
3668
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3669
#$reuslt["error"],執行不正常結束的錯訊息陣列.
3670
#$result["function"],當前執行的函式名稱.
3671
#$result["argu"],所使用的參數.
293 liveuser 3672
#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
291 liveuser 3673
#$result["domain"],字串,RR所屬domain.
3674
#$result["defaultTTL"],字串,預設的RR更新時間.
293 liveuser 3675
#$result["comment"],字串,一行的註解.
291 liveuser 3676
#必填參數:
3677
#$conf["line"],字串,要解析的行內容.
293 liveuser 3678
PHP;
3679
 
3680
#串接變數
3681
$phpCode2escaped=$phpCode2escaped.PHP_EOL."\$conf[\"line\"]=base64_decode(\"".base64_encode($line)."\");";
3682
 
3683
#串接php程式
3684
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
291 liveuser 3685
#可省略參數:
3686
#無.
3687
#參考資料:
3688
#無.
3689
#備註:
3690
#無.
3691
$parseRRline=zerossl::parseRRline($conf);
3692
unset($conf);
3693
 
3694
#如果執行異常 
3695
if($parseRRline["status"]==="false"){
3696
 
3697
	#設置錯誤識別
3698
	$result["status"]="false";
3699
 
3700
	#設置錯誤訊息
3701
	$result["error"]=$parseRRline;
3702
 
3703
	#印出 json 結果
3704
	echo json_encode($result);
3705
 
3706
	#結束執行,回傳1.
3707
	exit(1);
3708
 
3709
	}#if end
3710
 
3711
#印出json
3712
echo json_encode($parseRRline);
3713
PHP;
3714
 
293 liveuser 3715
				#串接要執行的參數
3716
				$phpCode2run=$phpCode2run.escapeshellarg($phpCode2escaped);
3717
 
291 liveuser 3718
				#函式說明:
3719
				#透過proc來多執行序運作.
3720
				#回傳結果:
3721
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3722
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3723
				#$result["function"],當前執行的函式名稱.
3724
				#$result["argu"],使用的參數.
3725
				#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
3726
				#必填參數:
3727
				#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
293 liveuser 3728
				$conf["threads::proc"]["cmds"]=array($phpCode2run);
291 liveuser 3729
				#可省略參數:
3730
				#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
3731
				$conf["threads::proc"]["wait"]="false";
3732
				#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
3733
				#$conf["timeout"]=array("10");
3734
				#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
293 liveuser 3735
				#$conf["threads::proc"]["workingDir"]=array(pathinfo(__FILE__)["dirname"]);
291 liveuser 3736
				#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
3737
				#$conf["envs"]=array(array("key"=>"value"));
3738
				#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
3739
				#$conf["executeBy"]=array("bash");
3740
				#參考資料:
3741
				#https://www.php.net/manual/en/function.proc-open.php
3742
				#https://www.php.net/manual/en/function.proc-get-status.php
3743
				#https://www.php.net/manual/en/function.proc-terminate.php
3744
				#備註:
3745
				#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
3746
				#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
3747
				$proc=threads::proc($conf["threads::proc"]);
3748
				unset($conf["threads::proc"]);
3749
 
293 liveuser 3750
				#debug
3751
				#var_dump($proc);exit;
3752
 
291 liveuser 3753
				#如果檢查失敗
3754
				if($proc["status"]==="false"){
3755
 
3756
					#設置錯誤識別
3757
					$result["status"]="false";
3758
 
3759
					#設置錯誤訊息
3760
					$result["error"]=$proc;
3761
 
3762
					#回傳結果
3763
					return $result;
3764
 
3765
					}#if end
3766
 
3767
				#儲存程序資訊
3768
				$procs[]=$proc;	
3769
 
3770
				#換解析下一行
3771
				continue;
3772
 
3773
				}#if end
3774
 
249 liveuser 3775
			#另存一份要處理的RR
3776
			$unFormatStr=$line;
3777
 
253 liveuser 3778
			#如果要debug
3779
			if($conf["debug"]==="true"){
3780
 
3781
				#函式說明:
3782
				#撰寫log
3783
				#回傳結果:
3784
				#$result["status"],狀態,"true"或"false".
3785
				#$result["error"],錯誤訊息陣列.
3786
				#$result["function"],當前函式的名稱.
3787
				#$result["argu"],使用的參數.
3788
				#$result["content"],要寫入log的內容字串.
3789
				#必填參數:
3790
				#$conf["path"],字串,log檔案的路徑與名稱.
3791
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3792
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3793
				$conf["logs::record"]["content"]="processing lineNo:".$lineNo." content:".$line.PHP_EOL;
3794
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3795
				$conf["logs::record"]["fileArgu"]=__FILE__;
3796
				#可省略參數:
3797
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3798
				#$conf["rewrite"]="false";
3799
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3800
				#$conf["returnOnly"]="true";
3801
				#參考資料:
3802
				#無.
3803
				#備註:
3804
				#無.
3805
				$record=logs::record($conf["logs::record"]);
3806
				unset($conf["logs::record"]);
3807
 
3808
				}#if end
3809
 
249 liveuser 3810
			#初始化該行的資訊陣列
3811
			$info=array();
3812
 
3813
			#尋找";"開頭的內容,亦即整行都是註解.
3814
			#函式說明:
3815
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3816
			#回傳結果:
3817
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3818
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3819
			#$result["function"],當前執行的函式名稱.
3820
			#$result["argu"],所使用的參數.
3821
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3822
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3823
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3824
			#必填參數:
3825
			#$conf["input"],字串,要檢查的字串.
3826
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3827
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3828
			$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
3829
			#可省略參數:
3830
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3831
			#$conf["varEqual"]=array(null,"found");
3832
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3833
			#$conf["varCon"]=array("no_tail"=>" not");
3834
			#參考資料:
3835
			#無.
3836
			#備註:
3837
			#無.
3838
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3839
			unset($conf["search::findSpecifyStrFormat"]);
3840
 
3841
			#如果執行異常
3842
			if($findSpecifyStrFormat["status"]==="false"){
3843
 
3844
				#設置錯誤識別
3845
				$result["status"]="false";
3846
 
3847
				#設置錯誤訊息
3848
				$result["error"]=$findSpecifyStrFormat;
3849
 
3850
				#回傳結果
3851
				return $result;
3852
 
3853
				}#if end
3854
 
3855
			#如果有找到符合格式的內容
3856
			if($findSpecifyStrFormat["found"]==="true"){
3857
 
3858
				#儲存為註解
3859
				$result["comment"][]=$unFormatStr;
3860
 
3861
				#換下一行
3862
				continue;
3863
 
3864
				}#if end
3865
 
3866
			#函式說明:
3867
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3868
			#回傳結果:
3869
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3870
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3871
			#$result["function"],當前執行的函式名稱.
3872
			#$result["argu"],所使用的參數.
3873
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3874
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3875
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3876
			#必填參數:
3877
			#$conf["input"],字串,要檢查的字串.
3878
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3879
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3880
			$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
3881
			#可省略參數:
3882
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3883
			#$conf["varEqual"]=array(null,"found");
3884
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3885
			#$conf["varCon"]=array("no_tail"=>" not");
3886
			#參考資料:
3887
			#無.
3888
			#備註:
3889
			#無.
3890
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3891
			unset($conf["search::findSpecifyStrFormat"]);
3892
 
3893
			#如果執行異常
3894
			if($findSpecifyStrFormat["status"]==="false"){
3895
 
3896
				#設置錯誤識別
3897
				$result["status"]="false";
3898
 
3899
				#設置錯誤訊息
3900
				$result["error"]=$findSpecifyStrFormat;
3901
 
3902
				#回傳結果
3903
				return $result;
3904
 
3905
				}#if end
3906
 
3907
			#如果有找到符合格式的內容
3908
			if($findSpecifyStrFormat["found"]==="true"){
3909
 
3910
				#設置 type 的數值
3911
				$info["type"]="\$ORIGIN";
3912
 
3913
				#取得後面待處理的內容
3914
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
3915
 
3916
				#函式說明:
3917
				#將字串開頭的特定關鍵字移除.
3918
				#回傳結果:
3919
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3920
				#$result["error"],錯誤訊息陣列.
3921
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
3922
				#$result["function"],當前執行的函數名稱.
3923
				#$result["argu"],使用的參數.
3924
				#$result["content"],處理好的的字串內容.
3925
				#$result["deleted"],被移除的內容.
3926
				#必填參數:
3927
				#$conf["stringIn"],字串,要處理的字串.
3928
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
3929
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
3930
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
3931
				#可省略參數:
3932
				#無.
3933
				#參考資料:
3934
				#無.
3935
				#備註:
3936
				#無.
3937
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
3938
				unset($conf["stringProcess::delHeadStr"]);
3939
 
3940
				#如果執行異常
3941
				if($delHeadStr["status"]==="false"){
3942
 
3943
					#設置錯誤識別
3944
					$result["status"]="false";
3945
 
3946
					#設置錯誤訊息
3947
					$result["error"]=$delHeadStr;
3948
 
3949
					#回傳結果
3950
					return $result;
3951
 
3952
					}#if end
3953
 
3954
				#如果有移除開頭的字串
3955
				if($delHeadStr["founded"]==="true"){
3956
 
3957
					#取得處理後的結果
3958
					$unFormatStr=$delHeadStr["content"];
3959
 
3960
					}#if end
253 liveuser 3961
 
249 liveuser 3962
				#解析 $ORIGN 的數值, 以及後面是否有註解...
3963
				#函式說明:
3964
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3965
				#回傳結果:
3966
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3967
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3968
				#$result["function"],當前執行的函式名稱.
3969
				#$result["argu"],所使用的參數.
3970
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3971
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3972
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3973
				#必填參數:
3974
				#$conf["input"],字串,要檢查的字串.
3975
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3976
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3977
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3978
				#可省略參數:
3979
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3980
				#$conf["varEqual"]=array(null,"found");
3981
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3982
				#$conf["varCon"]=array("no_tail"=>" not");
3983
				#參考資料:
3984
				#無.
3985
				#備註:
3986
				#無.
3987
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3988
				unset($conf["search::findSpecifyStrFormat"]);
3989
 
3990
				#如果執行異常
3991
				if($findSpecifyStrFormat["status"]==="false"){
3992
 
3993
					#設置錯誤識別
3994
					$result["status"]="false";
3995
 
3996
					#設置錯誤訊息
3997
					$result["error"]=$findSpecifyStrFormat;
3998
 
3999
					#回傳結果
4000
					return $result;
4001
 
4002
					}#if end
4003
 
4004
				#如果有數值跟註解
4005
				if($findSpecifyStrFormat["found"]==="true"){
4006
 
4007
					#儲存數值
4008
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
4009
 
4010
					#儲存zone domain
4011
					$result["domain"]=trim($info["value"]);
4012
 
4013
					#儲存註解
253 liveuser 4014
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
249 liveuser 4015
 
4016
					#儲存解析好的RR
4017
					$result["content"][]=$info;
4018
 
4019
					#換下一行
4020
					continue;
4021
 
4022
					}#if end
4023
 
4024
				#執行到這邊代表剩下的內容都是 value
4025
				$info["value"]=$unFormatStr;
4026
 
4027
				#儲存zone domain
4028
				$result["domain"]=trim($info["value"]);
4029
 
4030
				#儲存解析好的RR
4031
				$result["content"][]=$info;
4032
 
4033
				#換下一行
4034
				continue;
4035
 
4036
				}#if end
4037
 
4038
			#檢查是否為 $TTL 開頭
4039
			#函式說明:
4040
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4041
			#回傳結果:
4042
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4043
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
4044
			#$result["function"],當前執行的函式名稱.
4045
			#$result["argu"],所使用的參數.
4046
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4047
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4048
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4049
			#必填參數:
4050
			#$conf["input"],字串,要檢查的字串.
4051
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4052
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4053
			$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
4054
			#可省略參數:
4055
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4056
			#$conf["varEqual"]=array(null,"found");
4057
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4058
			#$conf["varCon"]=array("no_tail"=>" not");
4059
			#參考資料:
4060
			#無.
4061
			#備註:
4062
			#無.
4063
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4064
			unset($conf["search::findSpecifyStrFormat"]);
4065
 
4066
			#如果執行異常
4067
			if($findSpecifyStrFormat["status"]==="false"){
4068
 
4069
				#設置錯誤識別
4070
				$result["status"]="false";
4071
 
4072
				#設置錯誤訊息
4073
				$result["error"]=$findSpecifyStrFormat;
4074
 
4075
				#回傳結果
4076
				return $result;
4077
 
4078
				}#if end
4079
 
4080
			#如果有找到符合格式的內容
4081
			if($findSpecifyStrFormat["found"]==="true"){
4082
 
4083
				#設置 type 的數值
4084
				$info["type"]="\$TTL";
4085
 
4086
				#取得後面待處理的內容
4087
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
4088
 
4089
				#函式說明:
4090
				#將字串開頭的特定關鍵字移除.
4091
				#回傳結果:
4092
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4093
				#$result["error"],錯誤訊息陣列.
4094
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4095
				#$result["function"],當前執行的函數名稱.
4096
				#$result["argu"],使用的參數.
4097
				#$result["content"],處理好的的字串內容.
4098
				#$result["deleted"],被移除的內容.
4099
				#必填參數:
4100
				#$conf["stringIn"],字串,要處理的字串.
4101
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4102
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4103
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
4104
				#可省略參數:
4105
				#無.
4106
				#參考資料:
4107
				#無.
4108
				#備註:
4109
				#無.
4110
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4111
				unset($conf["stringProcess::delHeadStr"]);
293 liveuser 4112
 
249 liveuser 4113
				#如果執行異常
4114
				if($delHeadStr["status"]==="false"){
4115
 
4116
					#設置錯誤識別
4117
					$result["status"]="false";
4118
 
4119
					#設置錯誤訊息
4120
					$result["error"]=$delHeadStr;
4121
 
4122
					#回傳結果
4123
					return $result;
4124
 
4125
					}#if end
4126
 
4127
				#如果有移除開頭的字串
4128
				if($delHeadStr["founded"]==="true"){
4129
 
4130
					#取得處理後的結果
4131
					$unFormatStr=$delHeadStr["content"];
4132
 
4133
					}#if end
4134
 
4135
				#解析 $TTL 的數值, 以及後面是否有註解...
4136
				#函式說明:
4137
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4138
				#回傳結果:
4139
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4140
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4141
				#$result["function"],當前執行的函式名稱.
4142
				#$result["argu"],所使用的參數.
4143
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4144
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4145
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4146
				#必填參數:
4147
				#$conf["input"],字串,要檢查的字串.
4148
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4149
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4150
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
4151
				#可省略參數:
4152
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4153
				#$conf["varEqual"]=array(null,"found");
4154
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4155
				#$conf["varCon"]=array("no_tail"=>" not");
4156
				#參考資料:
4157
				#無.
4158
				#備註:
4159
				#無.
4160
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4161
				unset($conf["search::findSpecifyStrFormat"]);
4162
 
4163
				#如果執行異常
4164
				if($findSpecifyStrFormat["status"]==="false"){
4165
 
4166
					#設置錯誤識別
4167
					$result["status"]="false";
4168
 
4169
					#設置錯誤訊息
4170
					$result["error"]=$findSpecifyStrFormat;
4171
 
4172
					#回傳結果
4173
					return $result;
4174
 
4175
					}#if end
4176
 
4177
				#如果有數值跟註解
4178
				if($findSpecifyStrFormat["found"]==="true"){
4179
 
4180
					#儲存數值
4181
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
4182
 
4183
					#儲存註解
253 liveuser 4184
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
249 liveuser 4185
 
4186
					#儲存預設的 TTL
4187
					$result["defaultTTL"]=trim($info["value"]);
4188
 
4189
					#儲存解析好的RR
4190
					$result["content"][]=$info;
4191
 
4192
					#換下一行
4193
					continue;
4194
 
4195
					}#if end
4196
 
4197
				#執行到這邊代表剩下的內容都是 value
4198
				$info["value"]=$unFormatStr;
4199
 
4200
				#儲存預設的 TTL
4201
				$result["defaultTTL"]=trim($info["value"]);
4202
 
4203
				#儲存解析好的RR
4204
				$result["content"][]=$info;
4205
 
4206
				#換下一行
4207
				continue;
4208
 
4209
				}#if end
4210
 
4211
			#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
4212
 
4213
			#函式說明:
4214
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4215
			#回傳結果:
4216
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4217
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
4218
			#$result["function"],當前執行的函式名稱.
4219
			#$result["argu"],所使用的參數.
4220
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4221
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4222
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
4223
			#必填參數:
4224
			#$conf["input"],字串,要檢查的字串.
4225
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4226
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4227
			$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
4228
			#可省略參數:
4229
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4230
			#$conf["varEqual"]=array(null,"found");
4231
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4232
			#$conf["varCon"]=array("no_tail"=>" not");
4233
			#參考資料:
4234
			#無.
4235
			#備註:
4236
			#無.
4237
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4238
			unset($conf["search::findSpecifyStrFormat"]);
4239
 
4240
			#如果執行異常
4241
			if($findSpecifyStrFormat["status"]==="false"){
4242
 
4243
				#設置錯誤識別
4244
				$result["status"]="false";
4245
 
4246
				#設置錯誤訊息
4247
				$result["error"]=$findSpecifyStrFormat;
4248
 
4249
				#回傳結果
4250
				return $result;
4251
 
4252
				}#if end
4253
 
4254
			#如果存在"("
4255
			if($findSpecifyStrFormat["found"]==="true"){
4256
 
4257
				#取得無"("的內容
4258
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
4259
 
4260
				#取得拆下來的含開頭"("內容
4261
				$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
4262
 
4263
				}#if end
4264
 
4265
			#反之
4266
			else{
4267
 
4268
				#函式說明:
4269
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4270
				#回傳結果:
4271
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4272
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4273
				#$result["function"],當前執行的函式名稱.
4274
				#$result["argu"],所使用的參數.
4275
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4276
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4277
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
4278
				#必填參數:
4279
				#$conf["input"],字串,要檢查的字串.
4280
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4281
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4282
				$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
4283
				#可省略參數:
4284
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4285
				#$conf["varEqual"]=array(null,"found");
4286
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4287
				#$conf["varCon"]=array("no_tail"=>" not");
4288
				#參考資料:
4289
				#無.
4290
				#備註:
4291
				#無.
4292
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4293
				unset($conf["search::findSpecifyStrFormat"]);
4294
 
4295
				#如果執行異常
4296
				if($findSpecifyStrFormat["status"]==="false"){
4297
 
4298
					#設置錯誤識別
4299
					$result["status"]="false";
4300
 
4301
					#設置錯誤訊息
4302
					$result["error"]=$findSpecifyStrFormat;
4303
 
4304
					#回傳結果
4305
					return $result;
4306
 
4307
					}#if end
4308
 
4309
				#如果存在"
4310
				if($findSpecifyStrFormat["found"]==="true"){
4311
 
4312
					#取得無"的內容
4313
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
4314
 
4315
					#取得拆下來的含開頭"內容
4316
					$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
4317
 
4318
					}#if end
4319
 
4320
				#反之
4321
				else{
4322
 
4323
					#函式說明:
4324
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4325
					#回傳結果:
4326
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4327
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
4328
					#$result["function"],當前執行的函式名稱.
4329
					#$result["argu"],所使用的參數.
4330
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4331
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4332
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
4333
					#必填參數:
4334
					#$conf["input"],字串,要檢查的字串.
4335
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4336
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4337
					$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
4338
					#可省略參數:
4339
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4340
					#$conf["varEqual"]=array(null,"found");
4341
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4342
					#$conf["varCon"]=array("no_tail"=>" not");
4343
					#參考資料:
4344
					#無.
4345
					#備註:
4346
					#無.
4347
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4348
					unset($conf["search::findSpecifyStrFormat"]);
4349
 
4350
					#如果執行異常
4351
					if($findSpecifyStrFormat["status"]==="false"){
4352
 
4353
						#設置錯誤識別
4354
						$result["status"]="false";
4355
 
4356
						#設置錯誤訊息
4357
						$result["error"]=$findSpecifyStrFormat;
4358
 
4359
						#回傳結果
4360
						return $result;
4361
 
4362
						}#if end
4363
 
4364
					#如果存在";"
4365
					if($findSpecifyStrFormat["found"]==="true"){
4366
 
4367
						#取得無";"的內容
4368
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
4369
 
4370
						#取得拆下來的含開頭";"內容
4371
						$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
4372
 
4373
						}#if end
4374
 
4375
					}#else end
4376
 
4377
				}#else end
4378
 
4379
			#檢查是否為 @ 開頭
4380
			#函式說明:
4381
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4382
			#回傳結果:
4383
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4384
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
4385
			#$result["function"],當前執行的函式名稱.
4386
			#$result["argu"],所使用的參數.
4387
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4388
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4389
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4390
			#必填參數:
4391
			#$conf["input"],字串,要檢查的字串.
4392
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4393
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4394
			$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
4395
			#可省略參數:
4396
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4397
			#$conf["varEqual"]=array(null,"found");
4398
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4399
			#$conf["varCon"]=array("no_tail"=>" not");
4400
			#參考資料:
4401
			#無.
4402
			#備註:
4403
			#無.
4404
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4405
			unset($conf["search::findSpecifyStrFormat"]);
4406
 
4407
			#如果執行異常
4408
			if($findSpecifyStrFormat["status"]==="false"){
4409
 
4410
				#設置錯誤識別
4411
				$result["status"]="false";
4412
 
4413
				#設置錯誤訊息
4414
				$result["error"]=$findSpecifyStrFormat;
4415
 
4416
				#回傳結果
4417
				return $result;
4418
 
4419
				}#if end
4420
 
4421
			#如果有找到符合格式的內容
4422
			if($findSpecifyStrFormat["found"]==="true"){
4423
 
4424
				#設置 query 的數值
4425
				$info["query"]="@";
4426
 
4427
				#取得後面待處理的內容
4428
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
4429
 
4430
				#函式說明:
4431
				#將字串開頭的特定關鍵字移除.
4432
				#回傳結果:
4433
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4434
				#$result["error"],錯誤訊息陣列.
4435
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4436
				#$result["function"],當前執行的函數名稱.
4437
				#$result["argu"],使用的參數.
4438
				#$result["content"],處理好的的字串內容.
4439
				#$result["deleted"],被移除的內容.
4440
				#必填參數:
4441
				#$conf["stringIn"],字串,要處理的字串.
4442
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4443
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4444
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
4445
				#可省略參數:
4446
				#無.
4447
				#參考資料:
4448
				#無.
4449
				#備註:
4450
				#無.
4451
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4452
				unset($conf["stringProcess::delHeadStr"]);
4453
 
4454
				#如果執行異常
4455
				if($delHeadStr["status"]==="false"){
4456
 
4457
					#設置錯誤識別
4458
					$result["status"]="false";
4459
 
4460
					#設置錯誤訊息
4461
					$result["error"]=$delHeadStr;
4462
 
4463
					#回傳結果
4464
					return $result;
4465
 
4466
					}#if end
4467
 
4468
				#如果有移除開頭的字串
4469
				if($delHeadStr["founded"]==="true"){
4470
 
4471
					#取得處理後的結果 update time..IN..type...value;comment
4472
					$unFormatStr=$delHeadStr["content"];
4473
 
4474
					}#if end
4475
 
4476
				#debug
4477
				#var_dump(__LINE__,$delHeadStr);
4478
 
4479
				}#if end
4480
 
4481
			#反之
4482
			else{
4483
 
4484
				#執行到這邊,代表 query 為一非 @ 的字串
4485
				#函式說明:
4486
				#將指令字串解析成陣列,方便給予 external::callShell 使用
4487
				#回傳結果:
4488
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4489
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4490
				#$result["function"],當前執行的函式名稱.
4491
				#$result["content"],解析好的指令陣列.
4492
				#$result["cmd"],解析好的指令名稱.
4493
				#$result["argus"],解析好的參數陣列.
4494
				#$result["argu"],所使用的參數.
4495
				#必填參數
4496
				#$conf["cmdStr"],字串,要解析的指令字串
4497
				$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
4498
				#可省略參數:
4499
				#無.
4500
				#參考資料:
4501
				#無.
4502
				#備註:
4503
				#無.
4504
				$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
4505
				unset($conf["stringProcess::parseCmdString"]);
4506
 
4507
				#如果執行失敗
4508
				if($parseCmdString["status"]==="false"){
4509
 
4510
					#設置錯誤識別
4511
					$result["status"]="false";
4512
 
4513
					#設置錯誤訊息
4514
					$result["error"]=$parseCmdString;
4515
 
4516
					#debug
4517
					#$result["errorProcessLine"]=$line;
4518
 
4519
					#回傳結果
4520
					return $result;
4521
 
4522
					}#if end
4523
 
4524
				#取得 query 的內容
4525
				$info["query"]=$parseCmdString["content"][0];
4526
 
4527
				#剔除 query以及後面的" "跟\t
4528
				#函式說明:
4529
				#將字串開頭的特定關鍵字移除.
4530
				#回傳結果:
4531
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4532
				#$result["error"],錯誤訊息陣列.
4533
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4534
				#$result["function"],當前執行的函數名稱.
4535
				#$result["argu"],使用的參數.
4536
				#$result["content"],處理好的的字串內容.
4537
				#$result["deleted"],被移除的內容.
4538
				#必填參數:
4539
				#$conf["stringIn"],字串,要處理的字串.
4540
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4541
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4542
				$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
4543
				#可省略參數:
4544
				#無.
4545
				#參考資料:
4546
				#無.
4547
				#備註:
4548
				#無.
4549
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4550
				unset($conf["stringProcess::delHeadStr"]);
4551
 
4552
				#如果執行異常
4553
				if($delHeadStr["status"]==="false"){
4554
 
4555
					#設置錯誤識別
4556
					$result["status"]="false";
4557
 
4558
					#設置錯誤訊息
4559
					$result["error"]=$delHeadStr;
4560
 
4561
					#回傳結果
4562
					return $result;
4563
 
4564
					}#if end
4565
 
4566
				#取得update time..IN..type...value;comment
4567
				$unFormatStr=$delHeadStr["content"];
4568
 
4569
				}#else end
4570
 
4571
			#無窮迴圈
4572
			while(true){
4573
 
253 liveuser 4574
				#如果要debug
4575
				if($conf["debug"]==="true"){
249 liveuser 4576
 
253 liveuser 4577
					#函式說明:
4578
					#撰寫log
4579
					#回傳結果:
4580
					#$result["status"],狀態,"true"或"false".
4581
					#$result["error"],錯誤訊息陣列.
4582
					#$result["function"],當前函式的名稱.
4583
					#$result["argu"],使用的參數.
4584
					#$result["content"],要寫入log的內容字串.
4585
					#必填參數:
4586
					#$conf["path"],字串,log檔案的路徑與名稱.
4587
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4588
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4589
					$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4590
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4591
					$conf["logs::record"]["fileArgu"]=__FILE__;
4592
					#可省略參數:
4593
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4594
					#$conf["rewrite"]="false";
4595
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4596
					#$conf["returnOnly"]="true";
4597
					#參考資料:
4598
					#無.
4599
					#備註:
4600
					#無.
4601
					$record=logs::record($conf["logs::record"]);
4602
					unset($conf["logs::record"]);
4603
 
4604
					}#if end
4605
 
249 liveuser 4606
				#解析 updateTime..IN..type...value...comment
4607
 
4608
				#判斷是否無 update time
4609
 
4610
				#函式說明:
4611
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4612
				#回傳結果:
4613
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4614
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4615
				#$result["function"],當前執行的函式名稱.
4616
				#$result["argu"],所使用的參數.
4617
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4618
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4619
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4620
				#必填參數:
4621
				#$conf["input"],字串,要檢查的字串.
4622
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
4623
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4624
				$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
4625
				#可省略參數:
4626
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4627
				#$conf["varEqual"]=array(null,"found");
4628
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4629
				#$conf["varCon"]=array("no_tail"=>" not");
4630
				#參考資料:
4631
				#無.
4632
				#備註:
4633
				#無.
4634
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4635
				unset($conf["search::findSpecifyStrFormat"]);
4636
 
4637
				#如果執行異常
4638
				if($findSpecifyStrFormat["status"]==="false"){
4639
 
4640
					#設置錯誤識別
4641
					$result["status"]="false";
4642
 
4643
					#設置錯誤訊息
4644
					$result["error"]=$findSpecifyStrFormat;
4645
 
4646
					#回傳結果
4647
					return $result;
4648
 
4649
					}#if end
4650
 
4651
				#如果有找到符合格式的內容
4652
				if($findSpecifyStrFormat["found"]==="true"){
4653
 
4654
					#代表沒有 update time 欄位,因此儲存預設的TTL
4655
					$info["update"]=&$result["defaultTTL"];
4656
 
4657
					#取得剩下的 ...type...value;comment
4658
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
4659
 
4660
					#設置該行沒有指定 update time
4661
					$noUpdateTime="true";
4662
 
253 liveuser 4663
					#如果要debug
4664
					if($conf["debug"]==="true"){
4665
 
4666
						#函式說明:
4667
						#撰寫log
4668
						#回傳結果:
4669
						#$result["status"],狀態,"true"或"false".
4670
						#$result["error"],錯誤訊息陣列.
4671
						#$result["function"],當前函式的名稱.
4672
						#$result["argu"],使用的參數.
4673
						#$result["content"],要寫入log的內容字串.
4674
						#必填參數:
4675
						#$conf["path"],字串,log檔案的路徑與名稱.
4676
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4677
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4678
						$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4679
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4680
						$conf["logs::record"]["fileArgu"]=__FILE__;
4681
						#可省略參數:
4682
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4683
						#$conf["rewrite"]="false";
4684
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4685
						#$conf["returnOnly"]="true";
4686
						#參考資料:
4687
						#無.
4688
						#備註:
4689
						#無.
4690
						$record=logs::record($conf["logs::record"]);
4691
						unset($conf["logs::record"]);
4692
 
4693
						}#if end
249 liveuser 4694
 
4695
					}#if end
4696
 
4697
				#反之
4698
				else{
4699
 
4700
					#設置該行有指定 update time
4701
					$noUpdateTime="false";
4702
 
4703
					#如果有指定 update time
4704
					if($noUpdateTime==="false"){
4705
 
4706
						#要來解析 update time
4707
						#函式說明:
4708
						#將字串進行解析,變成多個參數.
4709
						#回傳結果:
4710
						#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
4711
						#$result["function"],當前執行的函式內容.
4712
						#$result["error"],錯誤訊息陣列.
4713
						#$result["content"],參數陣列.
4714
						#$result["count"],總共有幾個參數.
4715
						#必填參數:
4716
						#$conf["input"],字串,要解析成參數的字串.
4717
						$conf["stringProcess::parse"]["input"]=$unFormatStr;
4718
						#可省略參數:
4719
						#無.
4720
						#參考資料:
4721
						#無.
4722
						#備註:
4723
						#無.
4724
						$parse=stringProcess::parse($conf["stringProcess::parse"]);
4725
						unset($conf["stringProcess::parse"]);
4726
 
4727
						#如果執行異常
4728
						if($parse["status"]==="false"){
4729
 
4730
							#設置錯誤識別
4731
							$result["status"]="false";
4732
 
4733
							#設置錯誤訊息
4734
							$result["error"]=$parse;
4735
 
4736
							#回傳結果
4737
							return $result;
4738
 
4739
							}#if end
4740
 
4741
						#取得更新時間
4742
						$info["update"]=$parse["content"][0];
4743
 
4744
						#取得 update time 後面的內容
4745
						#函式說明:
4746
						#將字串開頭的特定關鍵字移除.
4747
						#回傳結果:
4748
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4749
						#$result["error"],錯誤訊息陣列.
4750
						#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4751
						#$result["function"],當前執行的函數名稱.
4752
						#$result["argu"],使用的參數.
4753
						#$result["content"],處理好的的字串內容.
4754
						#$result["deleted"],被移除的內容.
4755
						#必填參數:
4756
						#$conf["stringIn"],字串,要處理的字串.
4757
						$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4758
						#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4759
						$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
4760
						#可省略參數:
4761
						#無.
4762
						#參考資料:
4763
						#無.
4764
						#備註:
4765
						#無.
4766
						$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4767
						unset($conf["stringProcess::delHeadStr"]);
4768
 
4769
						#如果執行異常
4770
						if($delHeadStr["status"]==="false"){
4771
 
4772
							#設置錯誤識別
4773
							$result["status"]="false";
4774
 
4775
							#設置錯誤訊息
4776
							$result["error"]=$delHeadStr;
4777
 
4778
							#回傳結果
4779
							return $result;
4780
 
4781
							}#if end
4782
 
4783
						#取得...IN...value;comment
4784
						$unFormatStr=$delHeadStr["content"];
4785
 
4786
						}#if end
4787
 
4788
					#取得 ...IN... 後面的內容
4789
					#函式說明:
4790
					#將字串開頭的特定關鍵字移除.
4791
					#回傳結果:
4792
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4793
					#$result["error"],錯誤訊息陣列.
4794
					#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4795
					#$result["function"],當前執行的函數名稱.
4796
					#$result["argu"],使用的參數.
4797
					#$result["content"],處理好的的字串內容.
4798
					#$result["deleted"],被移除的內容.
4799
					#必填參數:
4800
					#$conf["stringIn"],字串,要處理的字串.
4801
					$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4802
					#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4803
					$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
4804
					#可省略參數:
4805
					#無.
4806
					#參考資料:
4807
					#無.
4808
					#備註:
4809
					#無.
4810
					$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4811
					unset($conf["stringProcess::delHeadStr"]);
4812
 
4813
					#如果執行異常
4814
					if($delHeadStr["status"]==="false"){
4815
 
4816
						#設置錯誤識別
4817
						$result["status"]="false";
4818
 
4819
						#設置錯誤訊息
4820
						$result["error"]=$delHeadStr;
4821
 
4822
						#回傳結果
4823
						return $result;
4824
 
4825
						}#if end
4826
 
4827
					#取得IN...value;comment
4828
					$unFormatStr=$delHeadStr["content"];
4829
 
253 liveuser 4830
					#如果要debug
4831
					if($conf["debug"]==="true"){
249 liveuser 4832
 
253 liveuser 4833
						#函式說明:
4834
						#撰寫log
4835
						#回傳結果:
4836
						#$result["status"],狀態,"true"或"false".
4837
						#$result["error"],錯誤訊息陣列.
4838
						#$result["function"],當前函式的名稱.
4839
						#$result["argu"],使用的參數.
4840
						#$result["content"],要寫入log的內容字串.
4841
						#必填參數:
4842
						#$conf["path"],字串,log檔案的路徑與名稱.
4843
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4844
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4845
						$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4846
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4847
						$conf["logs::record"]["fileArgu"]=__FILE__;
4848
						#可省略參數:
4849
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4850
						#$conf["rewrite"]="false";
4851
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4852
						#$conf["returnOnly"]="true";
4853
						#參考資料:
4854
						#無.
4855
						#備註:
4856
						#無.
4857
						$record=logs::record($conf["logs::record"]);
4858
						unset($conf["logs::record"]);
4859
 
4860
						}#if end
4861
 
249 liveuser 4862
					}#else end
4863
 
4864
				#解析 type...value;comment
4865
				#函式說明:
4866
				#將字串進行解析,變成多個參數.
4867
				#回傳結果:
4868
				#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
4869
				#$result["function"],當前執行的函式內容.
4870
				#$result["error"],錯誤訊息陣列.
4871
				#$result["content"],參數陣列.
4872
				#$result["count"],總共有幾個參數.
4873
				#必填參數:
4874
				#$conf["input"],字串,要解析成參數的字串.
4875
				$conf["stringProcess::parse"]["input"]=$unFormatStr;
4876
				#可省略參數:
4877
				#無.
4878
				#參考資料:
4879
				#無.
4880
				#備註:
4881
				#無.
4882
				$parse=stringProcess::parse($conf["stringProcess::parse"]);
4883
				unset($conf["stringProcess::parse"]);
4884
 
4885
				#如果執行異常
4886
				if($parse["status"]==="false"){
4887
 
4888
					#設置錯誤識別
4889
					$result["status"]="false";
4890
 
4891
					#設置錯誤訊息
4892
					$result["error"]=$parse;
4893
 
4894
					#回傳結果
4895
					return $result;
4896
 
4897
					}#if end
4898
 
4899
				#取得 type
4900
				$info["type"]=$parse["content"][0];
4901
 
4902
				#取得 type...後面的value;comment內容
4903
				#函式說明:
4904
				#將字串開頭的特定關鍵字移除.
4905
				#回傳結果:
4906
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4907
				#$result["error"],錯誤訊息陣列.
4908
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
4909
				#$result["function"],當前執行的函數名稱.
4910
				#$result["argu"],使用的參數.
4911
				#$result["content"],處理好的的字串內容.
4912
				#$result["deleted"],被移除的內容.
4913
				#必填參數:
4914
				#$conf["stringIn"],字串,要處理的字串.
4915
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
4916
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
4917
				$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
4918
				#可省略參數:
4919
				#無.
4920
				#參考資料:
4921
				#無.
4922
				#備註:
4923
				#無.
4924
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
4925
				unset($conf["stringProcess::delHeadStr"]);
4926
 
4927
				#如果執行異常
4928
				if($delHeadStr["status"]==="false"){
4929
 
4930
					#設置錯誤識別
4931
					$result["status"]="false";
4932
 
4933
					#設置錯誤訊息
4934
					$result["error"]=$delHeadStr;
4935
 
4936
					#回傳結果
4937
					return $result;
4938
 
4939
					}#if end
4940
 
4941
				#取得 value;comment
4942
				$unFormatStr=$delHeadStr["content"];
4943
 
4944
				#如果有要合併回去的內容
4945
				if(isset($unFormatStr2add)){
4946
 
4947
					#合併回去內容
4948
					$unFormatStr=$unFormatStr.$unFormatStr2add;
4949
 
4950
					#移除用不到的變數
4951
					unset($unFormatStr2add);
4952
 
4953
					}#if end
4954
 
253 liveuser 4955
				#如果要debug
4956
				if($conf["debug"]==="true"){
249 liveuser 4957
 
253 liveuser 4958
					#函式說明:
4959
					#撰寫log
4960
					#回傳結果:
4961
					#$result["status"],狀態,"true"或"false".
4962
					#$result["error"],錯誤訊息陣列.
4963
					#$result["function"],當前函式的名稱.
4964
					#$result["argu"],使用的參數.
4965
					#$result["content"],要寫入log的內容字串.
4966
					#必填參數:
4967
					#$conf["path"],字串,log檔案的路徑與名稱.
4968
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4969
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4970
					$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
4971
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4972
					$conf["logs::record"]["fileArgu"]=__FILE__;
4973
					#可省略參數:
4974
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4975
					#$conf["rewrite"]="false";
4976
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4977
					#$conf["returnOnly"]="true";
4978
					#參考資料:
4979
					#無.
4980
					#備註:
4981
					#無.
4982
					$record=logs::record($conf["logs::record"]);
4983
					unset($conf["logs::record"]);
4984
 
4985
					}#if end
4986
 
249 liveuser 4987
				#如果type不為 CNAME 跟 TXT 跟 SOA
4988
				if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" ){
4989
 
4990
					#儲存value
4991
					$info["value"]=$unFormatStr;
4992
 
4993
					#判斷是否有 ";" 存在
4994
					#函式說明:
4995
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4996
					#回傳結果:
4997
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4998
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
4999
					#$result["function"],當前執行的函式名稱.
5000
					#$result["argu"],所使用的參數.
5001
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5002
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5003
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5004
					#必填參數:
5005
					#$conf["input"],字串,要檢查的字串.
5006
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5007
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5008
					$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
5009
					#可省略參數:
5010
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5011
					#$conf["varEqual"]=array(null,"found");
5012
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5013
					#$conf["varCon"]=array("no_tail"=>" not");
5014
					#參考資料:
5015
					#無.
5016
					#備註:
5017
					#無.
5018
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5019
					unset($conf["search::findSpecifyStrFormat"]);
5020
 
5021
					#如果執行異常
5022
					if($findSpecifyStrFormat["status"]==="false"){
5023
 
5024
						#設置錯誤識別
5025
						$result["status"]="false";
5026
 
5027
						#設置錯誤訊息
5028
						$result["error"]=$findSpecifyStrFormat;
5029
 
5030
						#回傳結果
5031
						return $result;
5032
 
5033
						}#if end
5034
 
5035
					#如果有 ";"
5036
					if($findSpecifyStrFormat["found"]==="true"){
5037
 
5038
						#儲存value
5039
						$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5040
 
5041
						#儲存comment
5042
						$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5043
 
5044
						}#if end
5045
 
5046
					#儲存該筆RR
5047
					$result["content"][]=$info;
5048
 
5049
					#解析完畢換下一行
5050
					continue 2;
5051
 
5052
					}#if end
291 liveuser 5053
 
249 liveuser 5054
				#執行到這邊,代表type為CNAME或TXT或SOA
5055
 
5056
				#如果 type 是 SOA
5057
				if($info["type"]==="SOA"){
5058
 
253 liveuser 5059
					#如果要debug
5060
					if($conf["debug"]==="true"){
5061
 
5062
						#函式說明:
5063
						#撰寫log
5064
						#回傳結果:
5065
						#$result["status"],狀態,"true"或"false".
5066
						#$result["error"],錯誤訊息陣列.
5067
						#$result["function"],當前函式的名稱.
5068
						#$result["argu"],使用的參數.
5069
						#$result["content"],要寫入log的內容字串.
5070
						#必填參數:
5071
						#$conf["path"],字串,log檔案的路徑與名稱.
5072
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5073
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5074
						$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
5075
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5076
						$conf["logs::record"]["fileArgu"]=__FILE__;
5077
						#可省略參數:
5078
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5079
						#$conf["rewrite"]="false";
5080
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5081
						#$conf["returnOnly"]="true";
5082
						#參考資料:
5083
						#無.
5084
						#備註:
5085
						#無.
5086
						$record=logs::record($conf["logs::record"]);
5087
						unset($conf["logs::record"]);
5088
 
5089
						}#if end
5090
 
249 liveuser 5091
					#SOA 範例
5092
					#@	1200	IN	SOA	dns.qbpwcf.org. liveuser.qbpwcf.org. 2026012205 10800 1800 1728000 1200 ;domain name server, admin mail, serial, refresh time, expire, Negative Caching, https://bind9.readthedocs.io/en/latest/chapter3.html#term-SOA-minimum
5093
 
5094
					#再度嘗試分割
5095
					#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
5096
 
5097
					#函式說明:
5098
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5099
					#回傳結果:
5100
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5101
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
5102
					#$result["function"],當前執行的函式名稱.
5103
					#$result["argu"],所使用的參數.
5104
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5105
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5106
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
5107
					#必填參數:
5108
					#$conf["input"],字串,要檢查的字串.
5109
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5110
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5111
					$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
5112
					#可省略參數:
5113
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5114
					#$conf["varEqual"]=array(null,"found");
5115
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5116
					#$conf["varCon"]=array("no_tail"=>" not");
5117
					#參考資料:
5118
					#無.
5119
					#備註:
5120
					#無.
5121
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5122
					unset($conf["search::findSpecifyStrFormat"]);
5123
 
5124
					#如果執行異常
5125
					if($findSpecifyStrFormat["status"]==="false"){
5126
 
5127
						#設置錯誤識別
5128
						$result["status"]="false";
5129
 
5130
						#設置錯誤訊息
5131
						$result["error"]=$findSpecifyStrFormat;
5132
 
5133
						#回傳結果
5134
						return $result;
5135
 
5136
						}#if end
5137
 
5138
					#如果存在"("
5139
					if($findSpecifyStrFormat["found"]==="true"){
5140
 
5141
						#取得無"("的內容
5142
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
5143
 
5144
						#取得拆下來的含開頭"("內容
5145
						$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
5146
 
5147
						}#if end
5148
 
5149
					#反之
5150
					else{
5151
 
5152
						#函式說明:
5153
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5154
						#回傳結果:
5155
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5156
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
5157
						#$result["function"],當前執行的函式名稱.
5158
						#$result["argu"],所使用的參數.
5159
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5160
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5161
						#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
5162
						#必填參數:
5163
						#$conf["input"],字串,要檢查的字串.
5164
						$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5165
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5166
						$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
5167
						#可省略參數:
5168
						#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5169
						#$conf["varEqual"]=array(null,"found");
5170
						#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5171
						#$conf["varCon"]=array("no_tail"=>" not");
5172
						#參考資料:
5173
						#無.
5174
						#備註:
5175
						#無.
5176
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5177
						unset($conf["search::findSpecifyStrFormat"]);
5178
 
5179
						#如果執行異常
5180
						if($findSpecifyStrFormat["status"]==="false"){
5181
 
5182
							#設置錯誤識別
5183
							$result["status"]="false";
5184
 
5185
							#設置錯誤訊息
5186
							$result["error"]=$findSpecifyStrFormat;
5187
 
5188
							#回傳結果
5189
							return $result;
5190
 
5191
							}#if end
5192
 
5193
						#如果存在"
5194
						if($findSpecifyStrFormat["found"]==="true"){
5195
 
5196
							#取得無"的內容
5197
							$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
5198
 
5199
							#取得拆下來的含開頭"內容
5200
							$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
5201
 
5202
							}#if end
5203
 
5204
						#反之
5205
						else{
5206
 
5207
							#函式說明:
5208
							#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5209
							#回傳結果:
5210
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5211
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
5212
							#$result["function"],當前執行的函式名稱.
5213
							#$result["argu"],所使用的參數.
5214
							#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5215
							#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5216
							#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
5217
							#必填參數:
5218
							#$conf["input"],字串,要檢查的字串.
5219
							$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5220
							#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5221
							$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
5222
							#可省略參數:
5223
							#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5224
							#$conf["varEqual"]=array(null,"found");
5225
							#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5226
							#$conf["varCon"]=array("no_tail"=>" not");
5227
							#參考資料:
5228
							#無.
5229
							#備註:
5230
							#無.
5231
							$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5232
							unset($conf["search::findSpecifyStrFormat"]);
5233
 
5234
							#如果執行異常
5235
							if($findSpecifyStrFormat["status"]==="false"){
5236
 
5237
								#設置錯誤識別
5238
								$result["status"]="false";
5239
 
5240
								#設置錯誤訊息
5241
								$result["error"]=$findSpecifyStrFormat;
5242
 
5243
								#回傳結果
5244
								return $result;
5245
 
5246
								}#if end
5247
 
5248
							#如果存在";"
5249
							if($findSpecifyStrFormat["found"]==="true"){
5250
 
5251
								#取得無";"的內容
5252
								$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
5253
 
5254
								#取得拆下來的含開頭";"內容
5255
								$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
5256
 
5257
								}#if end
5258
 
5259
							}#else end
5260
 
5261
						}#else end
5262
 
5263
					#取得 serial number
5264
					#函式說明:
5265
					#將字串進行解析,變成多個參數.
5266
					#回傳結果:
5267
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
5268
					#$result["function"],當前執行的函式內容.
5269
					#$result["error"],錯誤訊息陣列.
5270
					#$result["content"],參數陣列.
5271
					#$result["count"],總共有幾個參數.
5272
					#必填參數:
5273
					#$conf["input"],字串,要解析成參數的字串.
5274
					$conf["stringProcess::parse"]["input"]=$unFormatStr;
5275
					#可省略參數:
5276
					#無.
5277
					#參考資料:
5278
					#無.
5279
					#備註:
5280
					#無.
5281
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
5282
					unset($conf["stringProcess::parse"]);
5283
 
5284
					#如果執行異常
5285
					if($parse["status"]==="false"){
5286
 
5287
						#設置錯誤識別
5288
						$result["status"]="false";
5289
 
5290
						#設置錯誤訊息
5291
						$result["error"]=$parse;
5292
 
5293
						#回傳結果
5294
						return $result;
5295
 
5296
						}#if end
5297
 
5298
					#取得serial number
5299
					$serialNo=$parse["content"][2];
5300
 
5301
					#serialNo+1
5302
					$serialNo++;
5303
 
5304
					#回存
5305
					$parse["content"][2]=(string)$serialNo;
5306
 
5307
					#函式說明:
5308
					#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
5309
					#回傳的結果:
5310
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5311
					#$result["function"],當前執行的function名稱
5312
					#$result["error"],錯誤訊息陣列.
5313
					#$result["content"],處理好的字串.
5314
					#$result["argu"],使用的參數.
5315
					#必填參數:
5316
					#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
5317
					$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
5318
					#可省略參數:
5319
					#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
5320
					$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
5321
					#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
5322
					$conf["arrays::arrayToString"]["skipEnd"]="true";
5323
					#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
5324
					#$conf["spiltSymbolAtStart"]="";
5325
					#參考資料:
5326
					#無.
5327
					#備註:
5328
					#無.
5329
					$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
5330
					unset($conf["arrays::arrayToString"]);
5331
 
5332
					#如果執行異常
5333
					if($arrayToString["status"]==="false"){
5334
 
5335
						#設置錯誤識別
5336
						$result["status"]="false";
5337
 
5338
						#設置錯誤訊息
5339
						$result["error"]=$arrayToString;
5340
 
5341
						#回傳結果
5342
						return $result;
5343
 
5344
						}#if end
5345
 
5346
					#取得更新 serial number 後的 SOA value string
5347
					$unFormatStr=$arrayToString["content"];
5348
 
5349
					#如果有要合併回去的內容
5350
					if(isset($unFormatStr2add)){
5351
 
5352
						#合併回去內容
5353
						$unFormatStr=$unFormatStr.$unFormatStr2add;
5354
 
5355
						#移除用不到的變數
5356
						unset($unFormatStr2add);
5357
 
5358
						}#if end
5359
 
5360
					#假設剩下的沒有註解都是 value
5361
					$info["value"]=$unFormatStr;
5362
 
5363
					#函式說明:
5364
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5365
					#回傳結果:
5366
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5367
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
5368
					#$result["function"],當前執行的函式名稱.
5369
					#$result["argu"],所使用的參數.
5370
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5371
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5372
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5373
					#必填參數:
5374
					#$conf["input"],字串,要檢查的字串.
5375
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5376
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5377
					$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
5378
					#可省略參數:
5379
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5380
					#$conf["varEqual"]=array(null,"found");
5381
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5382
					#$conf["varCon"]=array("no_tail"=>" not");
5383
					#參考資料:
5384
					#無.
5385
					#備註:
5386
					#無.
5387
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5388
					unset($conf["search::findSpecifyStrFormat"]);
5389
 
5390
					#如果執行異常
5391
					if($findSpecifyStrFormat["status"]==="false"){
5392
 
5393
						#設置錯誤識別
5394
						$result["status"]="false";
5395
 
5396
						#設置錯誤訊息
5397
						$result["error"]=$findSpecifyStrFormat;
5398
 
5399
						#回傳結果
5400
						return $result;
5401
 
5402
						}#if end
5403
 
5404
					#如果有符合格式
5405
					if($findSpecifyStrFormat["found"]==="true"){
5406
 
5407
						#儲存 value
5408
						$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5409
 
5410
						#儲存 comment
5411
						$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5412
 
5413
						}#if end
5414
 
5415
					#儲存該筆RR
5416
					$result["content"][]=$info;
5417
 
5418
					#換下解析下筆RR
5419
					continue 2;
5420
 
5421
					}#if end
5422
 
5423
				#執行到這邊代表不是 SOA
5424
 
5425
				#尋找是否有(...)...的內容存在
5426
				#函式說明:
5427
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5428
				#回傳結果:
5429
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5430
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5431
				#$result["function"],當前執行的函式名稱.
5432
				#$result["argu"],所使用的參數.
5433
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5434
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5435
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5436
				#必填參數:
5437
				#$conf["input"],字串,要檢查的字串.
5438
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5439
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5440
				$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
5441
				#可省略參數:
5442
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5443
				#$conf["varEqual"]=array(null,"found");
5444
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5445
				#$conf["varCon"]=array("no_tail"=>" not");
5446
				#參考資料:
5447
				#無.
5448
				#備註:
5449
				#無.
5450
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5451
				unset($conf["search::findSpecifyStrFormat"]);
5452
 
5453
				#如果執行異常
5454
				if($findSpecifyStrFormat["status"]==="false"){
5455
 
5456
					#設置錯誤識別
5457
					$result["status"]="false";
5458
 
5459
					#設置錯誤訊息
5460
					$result["error"]=$findSpecifyStrFormat;
5461
 
5462
					#回傳結果
5463
					return $result;
5464
 
5465
					}#if end
5466
 
5467
				#如果有 有符合 ($value);${comment} 的格式
5468
				if($findSpecifyStrFormat["found"]==="true"){
5469
 
5470
					#儲存value
5471
					$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
5472
 
5473
					#儲存comment
5474
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5475
 
5476
					#儲存 RR 的記錄
5477
					$result["content"][]=$info;
5478
 
5479
					#跳到下一筆要解析的RR
5480
					continue 2;
5481
 
5482
					}#if end
5483
 
5484
				#執行到這邊代表沒有 (...)... 的內容存在
5485
 
5486
				#尋找是否有 (...) 的內容存在
5487
				#函式說明:
5488
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5489
				#回傳結果:
5490
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5491
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5492
				#$result["function"],當前執行的函式名稱.
5493
				#$result["argu"],所使用的參數.
5494
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5495
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5496
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5497
				#必填參數:
5498
				#$conf["input"],字串,要檢查的字串.
5499
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5500
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5501
				$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
5502
				#可省略參數:
5503
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5504
				#$conf["varEqual"]=array(null,"found");
5505
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5506
				#$conf["varCon"]=array("no_tail"=>" not");
5507
				#參考資料:
5508
				#無.
5509
				#備註:
5510
				#無.
5511
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5512
				unset($conf["search::findSpecifyStrFormat"]);
5513
 
5514
				#如果執行異常
5515
				if($findSpecifyStrFormat["status"]==="false"){
5516
 
5517
					#設置錯誤識別
5518
					$result["status"]="false";
5519
 
5520
					#設置錯誤訊息
5521
					$result["error"]=$findSpecifyStrFormat;
5522
 
5523
					#回傳結果
5524
					return $result;
5525
 
5526
					}#if end
5527
 
5528
				#如果有 有符合 ($value);${comment} 的格式
5529
				if($findSpecifyStrFormat["found"]==="true"){
5530
 
5531
					#儲存value
5532
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5533
 
5534
					#儲存 RR 的記錄
5535
					$result["content"][]=$info;
5536
 
5537
					#跳到下一筆要解析的RR
5538
					continue 2;
5539
 
5540
					}#if end
5541
 
5542
				#執行到這邊代表沒有 (...) 的內容存在
5543
 
5544
				#尋找有無 "...";... 的內容存在
5545
				#函式說明:
5546
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5547
				#回傳結果:
5548
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5549
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5550
				#$result["function"],當前執行的函式名稱.
5551
				#$result["argu"],所使用的參數.
5552
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5553
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5554
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5555
				#必填參數:
5556
				#$conf["input"],字串,要檢查的字串.
5557
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5558
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5559
				$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
5560
				#可省略參數:
5561
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5562
				#$conf["varEqual"]=array(null,"found");
5563
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5564
				#$conf["varCon"]=array("no_tail"=>" not");
5565
				#參考資料:
5566
				#無.
5567
				#備註:
5568
				#無.
5569
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5570
				unset($conf["search::findSpecifyStrFormat"]);
5571
 
5572
				#如果執行異常
5573
				if($findSpecifyStrFormat["status"]==="false"){
5574
 
5575
					#設置錯誤識別
5576
					$result["status"]="false";
5577
 
5578
					#設置錯誤訊息
5579
					$result["error"]=$findSpecifyStrFormat;
5580
 
5581
					#回傳結果
5582
					return $result;
5583
 
5584
					}#if end
5585
 
5586
				#如果有 有符合 "$value";${comment} 的格式
5587
				if($findSpecifyStrFormat["found"]==="true"){
5588
 
5589
					#儲存value
5590
					$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
5591
 
5592
					#儲存comment
5593
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5594
 
5595
					#儲存 RR 的記錄
5596
					$result["content"][]=$info;
5597
 
5598
					#跳到下一筆要解析的RR
5599
					continue 2;
5600
 
5601
					}#if end
5602
 
5603
				#執行到這邊代表沒有 "$value";${comment} 的格式
5604
 
5605
				#尋找有無 "..." 的內容存在
5606
				#函式說明:
5607
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5608
				#回傳結果:
5609
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5610
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5611
				#$result["function"],當前執行的函式名稱.
5612
				#$result["argu"],所使用的參數.
5613
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5614
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5615
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5616
				#必填參數:
5617
				#$conf["input"],字串,要檢查的字串.
5618
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5619
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5620
				$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
5621
				#可省略參數:
5622
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5623
				#$conf["varEqual"]=array(null,"found");
5624
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5625
				#$conf["varCon"]=array("no_tail"=>" not");
5626
				#參考資料:
5627
				#無.
5628
				#備註:
5629
				#無.
5630
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5631
				unset($conf["search::findSpecifyStrFormat"]);
5632
 
5633
				#如果執行異常
5634
				if($findSpecifyStrFormat["status"]==="false"){
5635
 
5636
					#設置錯誤識別
5637
					$result["status"]="false";
5638
 
5639
					#設置錯誤訊息
5640
					$result["error"]=$findSpecifyStrFormat;
5641
 
5642
					#回傳結果
5643
					return $result;
5644
 
5645
					}#if end
5646
 
5647
				#如果有 有符合 "$value" 的格式
5648
				if($findSpecifyStrFormat["found"]==="true"){
5649
 
5650
					#儲存value
5651
					$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
5652
 
5653
					#儲存 RR 的記錄
5654
					$result["content"][]=$info;
5655
 
5656
					#跳到下一筆要解析的RR
5657
					continue 2;
5658
 
5659
					}#if end
5660
 
5661
				#執行到這邊代表沒有 "$value" 格式的內容
5662
 
5663
				#檢查是否有 $value;$comment 格式的內容
5664
				#函式說明:
5665
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
5666
				#回傳結果:
5667
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5668
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
5669
				#$result["function"],當前執行的函式名稱.
5670
				#$result["argu"],所使用的參數.
5671
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
5672
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
5673
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
5674
				#必填參數:
5675
				#$conf["input"],字串,要檢查的字串.
5676
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
5677
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
5678
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
5679
				#可省略參數:
5680
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
5681
				#$conf["varEqual"]=array(null,"found");
5682
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
5683
				#$conf["varCon"]=array("no_tail"=>" not");
5684
				#參考資料:
5685
				#無.
5686
				#備註:
5687
				#無.
5688
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
5689
				unset($conf["search::findSpecifyStrFormat"]);
5690
 
5691
				#如果執行異常
5692
				if($findSpecifyStrFormat["status"]==="false"){
5693
 
5694
					#設置錯誤識別
5695
					$result["status"]="false";
5696
 
5697
					#設置錯誤訊息
5698
					$result["error"]=$findSpecifyStrFormat;
5699
 
5700
					#回傳結果
5701
					return $result;
5702
 
5703
					}#if end
5704
 
5705
				#如果有 有符合 "$value" 的格式
5706
				if($findSpecifyStrFormat["found"]==="true"){
5707
 
5708
					#儲存value
5709
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
5710
 
5711
					#儲存comment
5712
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
5713
 
5714
					#儲存 RR 的記錄
5715
					$result["content"][]=$info;
5716
 
5717
					#跳到下一筆要解析的RR
5718
					continue 2;
5719
 
5720
					}#if end
5721
 
5722
				#執行到這邊代表沒有 ${value};${comment} 格式的內容
5723
 
5724
				#亦即剩下的內容都是 value
5725
 
5726
				#儲存value
5727
				$info["value"]=$unFormatStr;
5728
 
5729
				#儲存 RR 的記錄
5730
				$result["content"][]=$info;
5731
 
5732
				#跳到下一筆要解析的RR
5733
				continue 2;
5734
 
5735
				}#while end
5736
 
5737
			}#foreach end
291 liveuser 5738
 
5739
		#如果要啟用多執行序
293 liveuser 5740
		if($conf["multiThreads"]==="true"){
249 liveuser 5741
 
293 liveuser 5742
			#如果要debug
5743
			if($conf["debug"]==="true"){
5744
 
5745
				#函式說明:
5746
				#撰寫log
5747
				#回傳結果:
5748
				#$result["status"],狀態,"true"或"false".
5749
				#$result["error"],錯誤訊息陣列.
5750
				#$result["function"],當前函式的名稱.
5751
				#$result["argu"],使用的參數.
5752
				#$result["content"],要寫入log的內容字串.
5753
				#必填參數:
5754
				#$conf["path"],字串,log檔案的路徑與名稱.
5755
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5756
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5757
				$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR result through multi threads.".PHP_EOL;
5758
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5759
				$conf["logs::record"]["fileArgu"]=__FILE__;
5760
				#可省略參數:
5761
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5762
				#$conf["rewrite"]="false";
5763
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5764
				#$conf["returnOnly"]="true";
5765
				#參考資料:
5766
				#無.
5767
				#備註:
5768
				#無.
5769
				$record=logs::record($conf["logs::record"]);
5770
				unset($conf["logs::record"]);
5771
 
5772
				}#if end
291 liveuser 5773
 
293 liveuser 5774
			#無窮迴圈
5775
			while(true){
5776
 
5777
				#等後1秒
5778
				sleep(1);
5779
 
5780
				#針對每行處理的狀況
5781
				foreach($procs as $procIndex => $proc){
5782
 
5783
					#如果要debug
5784
					if($conf["debug"]==="true"){
5785
 
5786
						#函式說明:
5787
						#撰寫log
5788
						#回傳結果:
5789
						#$result["status"],狀態,"true"或"false".
5790
						#$result["error"],錯誤訊息陣列.
5791
						#$result["function"],當前函式的名稱.
5792
						#$result["argu"],使用的參數.
5793
						#$result["content"],要寫入log的內容字串.
5794
						#必填參數:
5795
						#$conf["path"],字串,log檔案的路徑與名稱.
5796
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5797
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5798
						$conf["logs::record"]["content"]="lineNo:".__LINE__." Try get result of parsing RR line ".($procIndex+1)." through multi threads.".PHP_EOL;
5799
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5800
						$conf["logs::record"]["fileArgu"]=__FILE__;
5801
						#可省略參數:
5802
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5803
						#$conf["rewrite"]="false";
5804
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5805
						#$conf["returnOnly"]="true";
5806
						#參考資料:
5807
						#無.
5808
						#備註:
5809
						#無.
5810
						$record=logs::record($conf["logs::record"]);
5811
						unset($conf["logs::record"]);
5812
 
5813
						}#if end
5814
 
5815
					#函式說明:
5816
					#更新透過proc執行的多程序資訊.
5817
					#回傳結果:
5818
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5819
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
5820
					#$result["function"],當前執行的函式名稱.
5821
					#$result["argu"],使用的參數.
5822
					#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
5823
					#必填參數:
5824
					#$conf["procs"],陣列,運行self::proc後回傳的content.
5825
					$conf["threads::proc_update"]["procs"]=$proc["content"];
5826
					#可省略參數:
5827
					#無.
5828
					#參考資料:
5829
					#無.
5830
					#備註:
5831
					#無.
5832
					$proc_update=threads::proc_update($conf["threads::proc_update"]);
5833
					unset($conf["threads::proc_update"]);
5834
 
5835
					#debug
5836
					#var_dump($proc_update);exit;
5837
 
5838
					#如果執行異常
5839
					if($proc_update["status"]==="false"){
5840
 
5841
						#設置執行異常
5842
						$result["status"]="false";
5843
 
5844
						#設置執行錯誤
5845
						$result["error"]=$proc_update;
5846
 
5847
						#回傳結果
5848
						return $result;
5849
 
5850
						}#if end
5851
 
5852
					#另存結果
5853
					$procRes=$proc_update["content"][0];
5854
 
5855
					#如果程序執行異常
5856
					if($procRes["status"]==="false"){
5857
 
5858
						#設置執行異常
5859
						$result["status"]="false";
5860
 
5861
						#設置執行錯誤
5862
						$result["error"]=$procRes;
5863
 
5864
						#回傳結果
5865
						return $result;
5866
 
5867
						}#if end
5868
 
5869
					#如果程序尚在執行
5870
					if($procRes["statusCode"]==="?"){
5871
 
5872
						#換看下一列的執行狀況
5873
						continue;
5874
 
5875
						}#if end
5876
 
5877
					#如果輸出內容不是 json
5878
					if(!(json_validate($procRes["content"]))){
5879
 
5880
						#設置執行異常
5881
						$result["status"]="false";
5882
 
5883
						#設置執行錯誤
5884
						$result["error"]=$procRes;
5885
 
5886
						#回傳結果
5887
						return $result;
5888
 
5889
						}#if end
5890
 
5891
					#解析json
5892
					$jsonRes=json_decode($procRes["content"]);
5893
 
5894
					#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","query","update",也可能為空陣列.
5895
					#$result["domain"],字串,RR所屬domain.
5896
					#$result["defaultTTL"],字串,預設的RR更新時間.
5897
					#$result["comment"],字串,一行的註解.
5898
 
5899
					#如果有 content->type 存在
5900
					if(isset($jsonRes->content->type)){
5901
 
5902
						#儲存value
5903
						$info["type"]=$jsonRes->content->type;
5904
 
5905
						}#if end
5906
 
5907
					#如果有 content->value 存在
5908
					if(isset($jsonRes->content->value)){
5909
 
5910
						#儲存value
5911
						$info["value"]=$jsonRes->content->value;
5912
 
5913
						}#if end
5914
 
5915
					#如果有 content->query 存在
5916
					if(isset($jsonRes->content->query)){
5917
 
5918
						#儲存query
5919
						$info["query"]=$jsonRes->content->query;
5920
 
5921
						}#if end
5922
 
5923
					#如果有 content->update 存在
5924
					if(isset($jsonRes->content->update)){
5925
 
5926
						#儲存query
5927
						$info["update"]=$jsonRes->content->update;
5928
 
5929
						}#if end
5930
 
5931
					#如果有 domain 存在
5932
					if(isset($jsonRes->domain)){
5933
 
5934
						#儲存domain
5935
						$result["domain"]=$jsonRes->domain;
5936
 
5937
						}#if end
5938
 
5939
					#如果有 defaultTTL 存在
5940
					if(isset($jsonRes->defaultTTL)){
5941
 
5942
						#儲存domain
5943
						$result["domain"]=$jsonRes->defaultTTL;
5944
 
5945
						}#if end
5946
 
5947
					#如果有 comment 存在
5948
					if(isset($jsonRes->comment)){
5949
 
5950
						#儲存comment,用$procIndex作為先後順率的識別
5951
						$result["comment"][$procIndex]=$jsonRes->comment;
5952
 
5953
						}#if end
5954
 
5955
					#儲存 RR 的記錄
5956
					$result["content"][$procIndex]=$info;
5957
 
5958
					#移除解析好的行號
5959
					unset($procs[$procIndex]);
5960
 
5961
					#如果要debug
5962
					if($conf["debug"]==="true"){
5963
 
5964
						#函式說明:
5965
						#撰寫log
5966
						#回傳結果:
5967
						#$result["status"],狀態,"true"或"false".
5968
						#$result["error"],錯誤訊息陣列.
5969
						#$result["function"],當前函式的名稱.
5970
						#$result["argu"],使用的參數.
5971
						#$result["content"],要寫入log的內容字串.
5972
						#必填參數:
5973
						#$conf["path"],字串,log檔案的路徑與名稱.
5974
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5975
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5976
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR line ".($procIndex+1)." through multi threads fin.".PHP_EOL;
5977
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5978
						$conf["logs::record"]["fileArgu"]=__FILE__;
5979
						#可省略參數:
5980
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5981
						#$conf["rewrite"]="false";
5982
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5983
						#$conf["returnOnly"]="true";
5984
						#參考資料:
5985
						#無.
5986
						#備註:
5987
						#無.
5988
						$record=logs::record($conf["logs::record"]);
5989
						unset($conf["logs::record"]);
5990
 
5991
						}#if end
5992
 
5993
					}#foreach end
5994
 
5995
				#如果每行都已經解析好了
5996
				if(count($procs)===0){
5997
 
5998
					#如果要debug
5999
					if($conf["debug"]==="true"){
6000
 
6001
						#函式說明:
6002
						#撰寫log
6003
						#回傳結果:
6004
						#$result["status"],狀態,"true"或"false".
6005
						#$result["error"],錯誤訊息陣列.
6006
						#$result["function"],當前函式的名稱.
6007
						#$result["argu"],使用的參數.
6008
						#$result["content"],要寫入log的內容字串.
6009
						#必填參數:
6010
						#$conf["path"],字串,log檔案的路徑與名稱.
6011
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6012
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6013
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR through multi threads fin.".PHP_EOL;
6014
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6015
						$conf["logs::record"]["fileArgu"]=__FILE__;
6016
						#可省略參數:
6017
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6018
						#$conf["rewrite"]="false";
6019
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6020
						#$conf["returnOnly"]="true";
6021
						#參考資料:
6022
						#無.
6023
						#備註:
6024
						#無.
6025
						$record=logs::record($conf["logs::record"]);
6026
						unset($conf["logs::record"]);
6027
 
6028
						}#if end
6029
 
6030
					#跳出 while
6031
					break;
6032
 
6033
					}#if end
6034
 
6035
				}#while end
6036
 
291 liveuser 6037
			}#if end
6038
 
253 liveuser 6039
		#如果要debug
6040
		if($conf["debug"]==="true"){
249 liveuser 6041
 
253 liveuser 6042
			#函式說明:
6043
			#撰寫log
6044
			#回傳結果:
6045
			#$result["status"],狀態,"true"或"false".
6046
			#$result["error"],錯誤訊息陣列.
6047
			#$result["function"],當前函式的名稱.
6048
			#$result["argu"],使用的參數.
6049
			#$result["content"],要寫入log的內容字串.
6050
			#必填參數:
6051
			#$conf["path"],字串,log檔案的路徑與名稱.
6052
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6053
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6054
			$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR fin.".PHP_EOL;
6055
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6056
			$conf["logs::record"]["fileArgu"]=__FILE__;
6057
			#可省略參數:
6058
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6059
			#$conf["rewrite"]="false";
6060
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6061
			#$conf["returnOnly"]="true";
6062
			#參考資料:
6063
			#無.
6064
			#備註:
6065
			#無.
6066
			$record=logs::record($conf["logs::record"]);
6067
			unset($conf["logs::record"]);
6068
 
6069
			}#if end
6070
 
249 liveuser 6071
		#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
6072
 
6073
		#針對每個要新增的RR記錄
255 liveuser 6074
		foreach($conf["add"] as $nri => $newRR){
249 liveuser 6075
 
255 liveuser 6076
			#如果要debug
6077
			if($conf["debug"]==="true"){
6078
 
6079
				#函式說明:
6080
				#撰寫log
6081
				#回傳結果:
6082
				#$result["status"],狀態,"true"或"false".
6083
				#$result["error"],錯誤訊息陣列.
6084
				#$result["function"],當前函式的名稱.
6085
				#$result["argu"],使用的參數.
6086
				#$result["content"],要寫入log的內容字串.
6087
				#必填參數:
6088
				#$conf["path"],字串,log檔案的路徑與名稱.
6089
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6090
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6091
				$conf["logs::record"]["content"]="lineNo:".__LINE__." ori newRR:".PHP_EOL;
6092
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6093
				$conf["logs::record"]["fileArgu"]=__FILE__;
6094
				#可省略參數:
6095
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6096
				#$conf["rewrite"]="false";
6097
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6098
				#$conf["returnOnly"]="true";
6099
				#參考資料:
6100
				#無.
6101
				#備註:
6102
				#無.
6103
				$record=logs::record($conf["logs::record"]);
6104
				unset($conf["logs::record"]);
6105
 
6106
				#函式說明:
6107
				#撰寫log
6108
				#回傳結果:
6109
				#$result["status"],狀態,"true"或"false".
6110
				#$result["error"],錯誤訊息陣列.
6111
				#$result["function"],當前函式的名稱.
6112
				#$result["argu"],使用的參數.
6113
				#$result["content"],要寫入log的內容字串.
6114
				#必填參數:
6115
				#$conf["path"],字串,log檔案的路徑與名稱.
6116
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6117
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6118
				$conf["logs::record"]["content"]=$newRR;
6119
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6120
				$conf["logs::record"]["fileArgu"]=__FILE__;
6121
				#可省略參數:
6122
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6123
				#$conf["rewrite"]="false";
6124
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6125
				#$conf["returnOnly"]="true";
6126
				#參考資料:
6127
				#無.
6128
				#備註:
6129
				#無.
6130
				$record=logs::record($conf["logs::record"]);
6131
				unset($conf["logs::record"]);
6132
 
6133
				}#if end
6134
 
6135
			#如果新的 RR 缺少必備的資訊
6136
			if(!isset($newRR["type"])){
6137
 
6138
				#設置執行異常
6139
				$result["status"]="false";
6140
 
6141
				#設置執行錯誤
6142
				$result["error"]="add參數的格式缺少type";
6143
 
6144
				#回傳結果
6145
				return $result;
6146
 
6147
				}#if end
6148
 
6149
			#如果 query 結尾不是"@"也不為"."結尾
6150
			if( ($newRR["query"]!=="@") && ($newRR["query"][strlen($newRR["query"])-1]!==".") ){
6151
 
6152
				#加上 "."
6153
				$conf["add"][$nri]["query"]=$newRR["query"]=$newRR["query"].".";
6154
 
6155
				}#if end
6156
 
6157
			#如果新的 query 為 $ORGIN 結尾
6158
			#函式說明:
6159
			#將字串特定關鍵字與其後面的內容剔除
6160
			#回傳結果:
6161
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6162
			#$result["error"],錯誤訊息陣列.
6163
			#$result["warning"],警告訊息鎮列.
6164
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
6165
			#$result["function"],當前執行的函數名稱.
6166
			#$result["oriStr"],要處理的原始字串內容.
6167
			#$result["content"],處理好的的字串內容.
6168
			#$result["deleted"],被移除的內容.
6169
			#$result["argu"],使用的參數.
6170
			#必填參數:
6171
			#$conf["stringIn"],字串,要處理的字串.
6172
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
6173
			#$conf["keyWord"],字串,特定字串.
6174
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["domain"];
6175
			#可省略參數:
6176
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
6177
			#$conf["deleteLastRepeatedOne"]="";
6178
			#參考資料:
6179
			#無.
6180
			#備註:
6181
			#無.
6182
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
6183
			unset($conf["stringProcess::delStrAfterKeyWord"]);
6184
 
6185
			#如果要debug
6186
			if($conf["debug"]==="true"){
6187
 
6188
				#函式說明:
6189
				#撰寫log
6190
				#回傳結果:
6191
				#$result["status"],狀態,"true"或"false".
6192
				#$result["error"],錯誤訊息陣列.
6193
				#$result["function"],當前函式的名稱.
6194
				#$result["argu"],使用的參數.
6195
				#$result["content"],要寫入log的內容字串.
6196
				#必填參數:
6197
				#$conf["path"],字串,log檔案的路徑與名稱.
6198
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6199
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6200
				$conf["logs::record"]["content"]="lineNo:".__LINE__." try process newRR with \$ORIGIN end".PHP_EOL;
6201
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6202
				$conf["logs::record"]["fileArgu"]=__FILE__;
6203
				#可省略參數:
6204
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6205
				#$conf["rewrite"]="false";
6206
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6207
				#$conf["returnOnly"]="true";
6208
				#參考資料:
6209
				#無.
6210
				#備註:
6211
				#無.
6212
				$record=logs::record($conf["logs::record"]);
6213
				unset($conf["logs::record"]);
6214
 
6215
				#函式說明:
6216
				#撰寫log
6217
				#回傳結果:
6218
				#$result["status"],狀態,"true"或"false".
6219
				#$result["error"],錯誤訊息陣列.
6220
				#$result["function"],當前函式的名稱.
6221
				#$result["argu"],使用的參數.
6222
				#$result["content"],要寫入log的內容字串.
6223
				#必填參數:
6224
				#$conf["path"],字串,log檔案的路徑與名稱.
6225
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6226
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6227
				$conf["logs::record"]["content"]=$delStrAfterKeyWord;
6228
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6229
				$conf["logs::record"]["fileArgu"]=__FILE__;
6230
				#可省略參數:
6231
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6232
				#$conf["rewrite"]="false";
6233
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6234
				#$conf["returnOnly"]="true";
6235
				#參考資料:
6236
				#無.
6237
				#備註:
6238
				#無.
6239
				$record=logs::record($conf["logs::record"]);
6240
				unset($conf["logs::record"]);
6241
 
6242
				}#if end
6243
 
6244
			#如果異常
6245
			if($delStrAfterKeyWord["status"]==="false"){
6246
 
6247
				#設置執行異常
6248
				$result["status"]="false";
6249
 
6250
				#設置執行錯誤
6251
				$result["error"]=$delStrAfterKeyWord;
6252
 
6253
				#回傳結果
6254
				return $result;
6255
 
6256
				}#if end
6257
 
6258
			#如果有找到 $ORIGIN 結尾
6259
			if($delStrAfterKeyWord["founded"]==="true"){
6260
 
6261
				#更新 query
6262
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
6263
 
6264
				#如果$newRR["query"] 變成 ""
6265
				if(empty($newRR["query"])){
6266
 
6267
					#變成 zone domain,亦即 $result["domain"]
6268
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
6269
 
6270
					}#if end
6271
 
6272
				#如果要debug
6273
				if($conf["debug"]==="true"){
6274
 
6275
					#函式說明:
6276
					#撰寫log
6277
					#回傳結果:
6278
					#$result["status"],狀態,"true"或"false".
6279
					#$result["error"],錯誤訊息陣列.
6280
					#$result["function"],當前函式的名稱.
6281
					#$result["argu"],使用的參數.
6282
					#$result["content"],要寫入log的內容字串.
6283
					#必填參數:
6284
					#$conf["path"],字串,log檔案的路徑與名稱.
6285
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6286
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6287
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
6288
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6289
					$conf["logs::record"]["fileArgu"]=__FILE__;
6290
					#可省略參數:
6291
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6292
					#$conf["rewrite"]="false";
6293
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6294
					#$conf["returnOnly"]="true";
6295
					#參考資料:
6296
					#無.
6297
					#備註:
6298
					#無.
6299
					$record=logs::record($conf["logs::record"]);
6300
					unset($conf["logs::record"]);
6301
 
6302
					#函式說明:
6303
					#撰寫log
6304
					#回傳結果:
6305
					#$result["status"],狀態,"true"或"false".
6306
					#$result["error"],錯誤訊息陣列.
6307
					#$result["function"],當前函式的名稱.
6308
					#$result["argu"],使用的參數.
6309
					#$result["content"],要寫入log的內容字串.
6310
					#必填參數:
6311
					#$conf["path"],字串,log檔案的路徑與名稱.
6312
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6313
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6314
					$conf["logs::record"]["content"]=$conf["add"][$nri];
6315
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6316
					$conf["logs::record"]["fileArgu"]=__FILE__;
6317
					#可省略參數:
6318
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6319
					#$conf["rewrite"]="false";
6320
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6321
					#$conf["returnOnly"]="true";
6322
					#參考資料:
6323
					#無.
6324
					#備註:
6325
					#無.
6326
					$record=logs::record($conf["logs::record"]);
6327
					unset($conf["logs::record"]);
6328
 
6329
					}#if end
6330
 
6331
				}#if end
6332
 
6333
			#如果新的 query 為 "." 結尾
6334
			#函式說明:
6335
			#將字串特定關鍵字與其後面的內容剔除
6336
			#回傳結果:
6337
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6338
			#$result["error"],錯誤訊息陣列.
6339
			#$result["warning"],警告訊息鎮列.
6340
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
6341
			#$result["function"],當前執行的函數名稱.
6342
			#$result["oriStr"],要處理的原始字串內容.
6343
			#$result["content"],處理好的的字串內容.
6344
			#$result["deleted"],被移除的內容.
6345
			#$result["argu"],使用的參數.
6346
			#必填參數:
6347
			#$conf["stringIn"],字串,要處理的字串.
6348
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
6349
			#$conf["keyWord"],字串,特定字串.
6350
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".";
6351
			#可省略參數:
6352
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
6353
			#$conf["deleteLastRepeatedOne"]="";
6354
			#參考資料:
6355
			#無.
6356
			#備註:
6357
			#無.
6358
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
6359
			unset($conf["stringProcess::delStrAfterKeyWord"]);
6360
 
6361
			#如果異常
6362
			if($delStrAfterKeyWord["status"]==="false"){
6363
 
6364
				#設置執行異常
6365
				$result["status"]="false";
6366
 
6367
				#設置執行錯誤
6368
				$result["error"]=$delStrAfterKeyWord;
6369
 
6370
				#回傳結果
6371
				return $result;
6372
 
6373
				}#if end
6374
 
6375
			#如果有找到 "." 結尾
6376
			if($delStrAfterKeyWord["founded"]==="true"){
6377
 
6378
				#更新 query
6379
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
6380
 
6381
				#如果 $newRR["query"] 變成 ""
6382
				if(empty($newRR["query"])){
6383
 
6384
					#變成 zone domain,亦即 $result["domain"]
6385
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
6386
 
6387
					}#if end
6388
 
6389
				#如果要debug
6390
				if($conf["debug"]==="true"){
6391
 
6392
					#函式說明:
6393
					#撰寫log
6394
					#回傳結果:
6395
					#$result["status"],狀態,"true"或"false".
6396
					#$result["error"],錯誤訊息陣列.
6397
					#$result["function"],當前函式的名稱.
6398
					#$result["argu"],使用的參數.
6399
					#$result["content"],要寫入log的內容字串.
6400
					#必填參數:
6401
					#$conf["path"],字串,log檔案的路徑與名稱.
6402
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6403
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6404
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
6405
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6406
					$conf["logs::record"]["fileArgu"]=__FILE__;
6407
					#可省略參數:
6408
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6409
					#$conf["rewrite"]="false";
6410
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6411
					#$conf["returnOnly"]="true";
6412
					#參考資料:
6413
					#無.
6414
					#備註:
6415
					#無.
6416
					$record=logs::record($conf["logs::record"]);
6417
					unset($conf["logs::record"]);
6418
 
6419
					#函式說明:
6420
					#撰寫log
6421
					#回傳結果:
6422
					#$result["status"],狀態,"true"或"false".
6423
					#$result["error"],錯誤訊息陣列.
6424
					#$result["function"],當前函式的名稱.
6425
					#$result["argu"],使用的參數.
6426
					#$result["content"],要寫入log的內容字串.
6427
					#必填參數:
6428
					#$conf["path"],字串,log檔案的路徑與名稱.
6429
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6430
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6431
					$conf["logs::record"]["content"]=$conf["add"][$nri];
6432
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6433
					$conf["logs::record"]["fileArgu"]=__FILE__;
6434
					#可省略參數:
6435
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6436
					#$conf["rewrite"]="false";
6437
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6438
					#$conf["returnOnly"]="true";
6439
					#參考資料:
6440
					#無.
6441
					#備註:
6442
					#無.
6443
					$record=logs::record($conf["logs::record"]);
6444
					unset($conf["logs::record"]);
6445
 
6446
					}#if end
6447
 
6448
				}#if end
6449
 
6450
			#如果新 RR 的 type 不是 A 且 value 不為 "." 結尾.
6451
			if( $newRR["type"]!=="A" && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
6452
 
6453
				#new RR add dot to value end.
6454
				$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
6455
 
6456
				#如果要debug
6457
				if($conf["debug"]==="true"){
6458
 
6459
					#函式說明:
6460
					#撰寫log
6461
					#回傳結果:
6462
					#$result["status"],狀態,"true"或"false".
6463
					#$result["error"],錯誤訊息陣列.
6464
					#$result["function"],當前函式的名稱.
6465
					#$result["argu"],使用的參數.
6466
					#$result["content"],要寫入log的內容字串.
6467
					#必填參數:
6468
					#$conf["path"],字串,log檔案的路徑與名稱.
6469
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6470
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6471
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
6472
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6473
					$conf["logs::record"]["fileArgu"]=__FILE__;
6474
					#可省略參數:
6475
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6476
					#$conf["rewrite"]="false";
6477
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6478
					#$conf["returnOnly"]="true";
6479
					#參考資料:
6480
					#無.
6481
					#備註:
6482
					#無.
6483
					$record=logs::record($conf["logs::record"]);
6484
					unset($conf["logs::record"]);
6485
 
6486
					#函式說明:
6487
					#撰寫log
6488
					#回傳結果:
6489
					#$result["status"],狀態,"true"或"false".
6490
					#$result["error"],錯誤訊息陣列.
6491
					#$result["function"],當前函式的名稱.
6492
					#$result["argu"],使用的參數.
6493
					#$result["content"],要寫入log的內容字串.
6494
					#必填參數:
6495
					#$conf["path"],字串,log檔案的路徑與名稱.
6496
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6497
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6498
					$conf["logs::record"]["content"]=$conf["add"][$nri];
6499
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6500
					$conf["logs::record"]["fileArgu"]=__FILE__;
6501
					#可省略參數:
6502
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6503
					#$conf["rewrite"]="false";
6504
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6505
					#$conf["returnOnly"]="true";
6506
					#參考資料:
6507
					#無.
6508
					#備註:
6509
					#無.
6510
					$record=logs::record($conf["logs::record"]);
6511
					unset($conf["logs::record"]);
6512
 
6513
					}#if end
6514
 
6515
				}#if end
6516
 
249 liveuser 6517
			#針對 zone file 中既有的每個RR記錄
6518
			foreach($result["content"] as $index => $oldRR){
6519
 
6520
				#如果既有的跟新的RR都為 $ORIGIN
6521
				if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
6522
 
6523
					#取代既有的 RR
6524
					$result["content"][$index]=$newRR;
6525
 
6526
					#換看下一筆newRR
6527
					continue 2;
6528
 
6529
					}#if end
6530
 
6531
				#如果既有的跟新的RR都為 $TTL
6532
				if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
6533
 
6534
					#取代既有的 RR
6535
					$result["content"][$index]=$newRR;
6536
 
6537
					#換看下一筆newRR
6538
					continue 2;
6539
 
6540
					}#if end
6541
 
253 liveuser 6542
				#如果新舊資料都有query資訊
6543
				if( isset($newRR["query"]) && isset($oldRR["query"]) ){
249 liveuser 6544
 
253 liveuser 6545
					#如果跟既有的 query、type、value 有相同
6546
					if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
249 liveuser 6547
 
253 liveuser 6548
						#如果新 RR 有 update time
6549
						if(isset($newRR["update"])){
249 liveuser 6550
 
253 liveuser 6551
							#如果新舊 update time 不相同
6552
							if( $newRR["update"] !== $oldRR["update"] ){
249 liveuser 6553
 
253 liveuser 6554
								#取代既有的 RR
6555
								$result["content"][$index]=$newRR;
6556
 
6557
								#換看下一筆newRR
6558
								continue 2;
6559
 
6560
								}#if end
6561
 
6562
							}#if end
249 liveuser 6563
 
253 liveuser 6564
						#反之既有的 update time 若跟 global TTL 不一樣
6565
						else if( $oldRR["update"] !== $result["defaultTTL"] ){
6566
 
6567
							#更新為 global TTL
6568
							$result["content"][$index]["update"]=$result["defaultTTL"];
6569
 
249 liveuser 6570
							}#if end
253 liveuser 6571
 
6572
						#如果新 RR 有 comment
6573
						if( isset($newRR["comment"]) ){
249 liveuser 6574
 
253 liveuser 6575
							#更新既有 RR 的 comment
6576
							$result["content"][$index]["comment"]=$newRR["comment"];
249 liveuser 6577
 
253 liveuser 6578
							#換看下一筆newRR
6579
							continue 2;
249 liveuser 6580
 
253 liveuser 6581
							}#if end
6582
 
6583
						#反之,如果有既有 comment
6584
						else if(isset($result["content"][$index]["comment"])){
249 liveuser 6585
 
253 liveuser 6586
							#移除既有 comment
6587
							unset($result["content"][$index]["comment"]);
6588
 
6589
							#換看下一筆newRR
6590
							continue 2;
249 liveuser 6591
 
253 liveuser 6592
							}#else end
249 liveuser 6593
 
253 liveuser 6594
						}#if end
249 liveuser 6595
 
6596
					}#if end
253 liveuser 6597
 
249 liveuser 6598
				}#foreach end
6599
 
6600
			#儲存確定要新增的RR
6601
			$result["content"][]=$newRR;
6602
 
6603
			}#foreach end
6604
 
255 liveuser 6605
		#如果要debug
6606
		if($conf["debug"]==="true"){
249 liveuser 6607
 
255 liveuser 6608
			#函式說明:
6609
			#撰寫log
6610
			#回傳結果:
6611
			#$result["status"],狀態,"true"或"false".
6612
			#$result["error"],錯誤訊息陣列.
6613
			#$result["function"],當前函式的名稱.
6614
			#$result["argu"],使用的參數.
6615
			#$result["content"],要寫入log的內容字串.
6616
			#必填參數:
6617
			#$conf["path"],字串,log檔案的路徑與名稱.
6618
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6619
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6620
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
6621
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6622
			$conf["logs::record"]["fileArgu"]=__FILE__;
6623
			#可省略參數:
6624
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6625
			#$conf["rewrite"]="false";
6626
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6627
			#$conf["returnOnly"]="true";
6628
			#參考資料:
6629
			#無.
6630
			#備註:
6631
			#無.
6632
			$record=logs::record($conf["logs::record"]);
6633
			unset($conf["logs::record"]);
249 liveuser 6634
 
255 liveuser 6635
			}#if end
6636
 
6637
		#如果要debug
6638
		if($conf["debug"]==="true"){
6639
 
6640
			#函式說明:
6641
			#撰寫log
6642
			#回傳結果:
6643
			#$result["status"],狀態,"true"或"false".
6644
			#$result["error"],錯誤訊息陣列.
6645
			#$result["function"],當前函式的名稱.
6646
			#$result["argu"],使用的參數.
6647
			#$result["content"],要寫入log的內容字串.
6648
			#必填參數:
6649
			#$conf["path"],字串,log檔案的路徑與名稱.
6650
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6651
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6652
			$conf["logs::record"]["content"]=$result["content"];
6653
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6654
			$conf["logs::record"]["fileArgu"]=__FILE__;
6655
			#可省略參數:
6656
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6657
			#$conf["rewrite"]="false";
6658
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6659
			#$conf["returnOnly"]="true";
6660
			#參考資料:
6661
			#無.
6662
			#備註:
6663
			#無.
6664
			$record=logs::record($conf["logs::record"]);
6665
			unset($conf["logs::record"]);
6666
 
6667
			}#if end
6668
 
249 liveuser 6669
		#初始化要寫入的內容
6670
		$strs2write=array();
6671
 
6672
		#針對每個RR記錄
6673
		foreach($result["content"] as $RR){
6674
 
6675
			#初始化暫存要寫入的行內容
6676
			$str2write="";
6677
 
6678
			#如果是
6679
			if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
6680
 
6681
				#組合變數名稱與數值
6682
				$str2write=$str2write.$RR["type"]."\t".$RR["value"];
6683
 
6684
				}#if end
6685
 
6686
			#反之
6687
			else{
6688
 
6689
				#加上查詢的字句
6690
				$str2write=$str2write.$RR["query"];
6691
 
6692
				#如果該筆RR有指定update time該ZONE具備 global TTL.
6693
				if(isset($RR["update"])){
6694
 
6695
					#如果 該ZONE具備 global TTL.
6696
					if(isset($result["defaultTTL"])){
6697
 
6698
						#如果該筆 RR 的 update time 不等於 global TTL
6699
						if($RR["update"]!==$result["defaultTTL"]){
6700
 
6701
							#加上TTL的字句
6702
							$str2write=$str2write."\t".$RR["update"];
6703
 
6704
							}#if end
6705
 
6706
						}#if end
6707
 
6708
					#反之
6709
					else{
6710
 
6711
						#加上TTL的字句
6712
						$str2write=$str2write."\t".$RR["update"];
6713
 
6714
						}#else end
6715
 
6716
					}#if end
6717
 
253 liveuser 6718
				#反之且該ZONE不具備 global TTL.
6719
				else if(!isset($result["defaultTTL"])){
249 liveuser 6720
 
6721
					#加上global TTL的字句
6722
					$str2write=$str2write."\t".$result["defaultTTL"];
6723
 
253 liveuser 6724
					}#if end
249 liveuser 6725
 
6726
				#加上IN跟TYPE跟value
6727
				$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
6728
 
6729
				}#else end
6730
 
6731
			#如果有註解
6732
			if(isset($RR["comment"])){
6733
 
6734
				#加上comment
6735
				$str2write=$str2write.";".$RR["comment"];
6736
 
6737
				}#if end
6738
 
253 liveuser 6739
			#如果要 debug
6740
			if($conf["debug"]==="true"){
249 liveuser 6741
 
253 liveuser 6742
				#函式說明:
6743
				#撰寫log
6744
				#回傳結果:
6745
				#$result["status"],狀態,"true"或"false".
6746
				#$result["error"],錯誤訊息陣列.
6747
				#$result["function"],當前函式的名稱.
6748
				#$result["argu"],使用的參數.
6749
				#$result["content"],要寫入log的內容字串.
6750
				#必填參數:
6751
				#$conf["path"],字串,log檔案的路徑與名稱.
6752
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6753
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6754
				$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
6755
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6756
				$conf["logs::record"]["fileArgu"]=__FILE__;
6757
				#可省略參數:
6758
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6759
				#$conf["rewrite"]="false";
6760
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6761
				#$conf["returnOnly"]="true";
6762
				#參考資料:
6763
				#無.
6764
				#備註:
6765
				#無.
6766
				$record=logs::record($conf["logs::record"]);
6767
				unset($conf["logs::record"]);
6768
 
6769
				}#if end
6770
 
249 liveuser 6771
			#加上要寫入的元素
6772
			$strs2write[]=$str2write;
6773
 
6774
			}#foreach end
6775
 
6776
		#如果有逐行註解
6777
		if(count($result["comment"])>0){
6778
 
6779
			#加到結尾
6780
			#函式說明:
6781
			#將多個一維陣列串聯起來,key從0開始排序.
6782
			#回傳的結果:
6783
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
6784
			#$result["error"],錯誤訊息陣列.
6785
			#$result["function"],當前執行的函數.
6786
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6787
			#$result["content"],合併好的一維陣列.
6788
			#必填參數
6789
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
6790
			$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
6791
			#可省略參數:
6792
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
6793
			#$conf["allowRepeat"]="true";
6794
			#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
6795
			#$conf["looseDiff"]="false";
6796
			#參考資料:
6797
			#無.
6798
			#備註:
6799
			#無.
6800
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
6801
			unset($conf["arrays::mergeArray"]);
6802
 
6803
			#如果執行異常
6804
			if($mergeArray["status"]==="false"){
6805
 
6806
				#設置錯誤識別
6807
				$result["status"]="false";
6808
 
6809
				#設置錯誤訊息
6810
				$result["error"]=$mergeArray;
6811
 
6812
				#回傳結果
6813
				return $result;
6814
 
6815
				}#if end
6816
 
6817
			#取得合併好的陣列
6818
			$strs2write=$mergeArray["content"];
6819
 
6820
			}#if end
6821
 
253 liveuser 6822
		#如果要 debug
6823
		if($conf["debug"]==="true"){
249 liveuser 6824
 
253 liveuser 6825
			#函式說明:
6826
			#撰寫log
6827
			#回傳結果:
6828
			#$result["status"],狀態,"true"或"false".
6829
			#$result["error"],錯誤訊息陣列.
6830
			#$result["function"],當前函式的名稱.
6831
			#$result["argu"],使用的參數.
6832
			#$result["content"],要寫入log的內容字串.
6833
			#必填參數:
6834
			#$conf["path"],字串,log檔案的路徑與名稱.
6835
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
6836
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
6837
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
6838
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6839
			$conf["logs::record"]["fileArgu"]=__FILE__;
6840
			#可省略參數:
6841
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
6842
			#$conf["rewrite"]="false";
6843
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
6844
			#$conf["returnOnly"]="true";
6845
			#參考資料:
6846
			#無.
6847
			#備註:
6848
			#無.
6849
			$record=logs::record($conf["logs::record"]);
6850
			unset($conf["logs::record"]);
6851
 
6852
			}#if end
6853
 
249 liveuser 6854
		#儲存新zone file每行的內容
6855
		$result["newZoneFileContent"]=$strs2write;
6856
 
6857
		#如果要寫入ZONE檔案
6858
		if($conf["writeNow"]==="true"){
6859
 
6860
			#覆寫 ZONE file
6861
			#函式說明:
6862
			#更新檔案的內容.
6863
			#回傳結果:
6864
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6865
			#$result["error"],錯誤訊息.
6866
			#$result["function"],當前執行的函數名稱.
6867
			#$result["content"],更新的資訊.
6868
			#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
6869
			#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
6870
			#必填參數:
6871
			#$conf["fileArgu"],字串,變數__FILE__的內容.
6872
			$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
6873
			#$conf["file"],字串,要更新的檔案位置與名稱.
6874
			$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
6875
			#可省略參數:
6876
			#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
6877
			$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
6878
			#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
6879
			#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
6880
			#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
6881
			#$conf["replaceLike"]="false";
6882
			#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
6883
			#$conf["addToTailWhenNoMatch"]="false";
6884
			#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
6885
			#$conf["addToTailBeforeThat"]="?\>";
6886
			#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
6887
			#$conf["replaceSpecifyLine"]=array();
6888
			#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
6889
			#$conf["outputPath"]="";
6890
			#參考資料:
6891
			#無.
6892
			#備註:
6893
			#無.
6894
			$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
6895
			unset($conf["fileAccess::updateFile"]);
6896
 
6897
			#如果執行異常
6898
			if($updateFile["status"]==="false"){
6899
 
6900
				#設置錯誤識別
6901
				$result["status"]="false";
6902
 
6903
				#設置錯誤訊息
6904
				$result["error"]=$updateFile;
6905
 
6906
				#回傳結果
6907
				return $result;
6908
 
6909
				}#if end
291 liveuser 6910
 
6911
			#修正 zone file 的權限
6912
			#函式說明:
6913
			#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
6914
			#回傳結果:
6915
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6916
			#$result["error"],錯誤訊息.
6917
			#$result["function"],當前執行的函式名稱.
6918
			#$result["cmd"],執行的指令.
6919
			#必填參數:
6920
			#$conf["owner"],字串,要變哪個使用者擁有.
6921
			$conf["cmd::chown"]["owner"]="root";
6922
			#$conf["target"],字串,需要變更擁有者、 群組的目標.
6923
			$conf["cmd::chown"]["target"]=$conf["dnsRecordFile"];
6924
			#可省略參數:
6925
			#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
6926
			$conf["cmd::chown"]["group"]=webUser;
6927
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
6928
			#$conf["recursive"]="true";
6929
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
6930
			#$conf["excludeSelf"]="true";
6931
			#參考資料:
6932
			#無.
6933
			#備註:
6934
			#無.
6935
			$chown=cmd::chown($conf["cmd::chown"]);
6936
			unset($conf["cmd::chown"]);
249 liveuser 6937
 
291 liveuser 6938
			#如果執行異常
6939
			if($chown["status"]==="false"){
6940
 
6941
				#設置錯誤識別
6942
				$result["status"]="false";
6943
 
6944
				#設置錯誤訊息
6945
				$result["error"]=$chown;
6946
 
6947
				#回傳結果
6948
				return $result;
6949
 
6950
				}#if end
6951
 
6952
			#函式說明:
6953
			#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
6954
			#回傳結果:
6955
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6956
			#$result["error"],錯誤訊息.
6957
			#$result["function"],當前執行的函式名稱.
6958
			#$result["cmd"],執行的指令.
6959
			#必填參數:
6960
			#$conf["mode"],字串,要變成什麼權限.
6961
			$conf["cmd::chmod"]["mode"]="774";
6962
			#$conf["target"],字串,需要變更權限的目標.
6963
			$conf["cmd::chmod"]["target"]=$conf["dnsRecordFile"];
6964
			#可省略參數:
6965
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
6966
			#$conf["recursive"]="true";
6967
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
6968
			#$conf["excludeSelf"]="true";
6969
			#參考資料:
6970
			#無.
6971
			#備註:
6972
			#無.
6973
			$chmod=cmd::chmod($conf["cmd::chmod"]);
6974
			unset($conf["cmd::chmod"]);
6975
 
6976
			#如果執行異常
6977
			if($chmod["status"]==="false"){
6978
 
6979
				#設置錯誤識別
6980
				$result["status"]="false";
6981
 
6982
				#設置錯誤訊息
6983
				$result["error"]=$chmod;
6984
 
6985
				#回傳結果
6986
				return $result;
6987
 
6988
				}#if end
6989
 
249 liveuser 6990
			}#if end
6991
 
6992
		#設置執行正常
6993
		$result["status"]="true";
6994
 
6995
		#回傳結果
6996
		return $result;
6997
 
6998
		}#function updateDnsRecordFile end
6999
 
7000
	/*
7001
	#函式說明:
255 liveuser 7002
	#請求驗證已經透過zerossl::createCertificate要求的domain.
249 liveuser 7003
	#回傳結果:
7004
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7005
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7006
	#$result["function"],當前執行的函式名稱.
7007
	#$result["argu"],所使用的參數.
7008
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 7009
	#$result["content"],結果json字串.
249 liveuser 7010
	#必填參數:
7011
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
7012
	$conf["id"]="";
7013
	#可省略參數:
7014
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7015
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7016
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7017
	#$conf["key"]=self::getApiInfo()["apiKey"];
7018
	#參考資料:
255 liveuser 7019
	#https://zerossl.com/documentation/api/verify-domains/
249 liveuser 7020
	#備註:
7021
	#無.
7022
	*/
7023
	public static function verifyDomain(&$conf){
7024
 
7025
		#初始化要回傳的結果
7026
		$result=array();
7027
 
7028
		#設置當其函數名稱
7029
		$result["function"]=__FUNCTION__;
7030
 
7031
		#如果 $conf 不為陣列
7032
		if(gettype($conf)!="array"){
7033
 
7034
			#設置執行失敗
7035
			$result["status"]="false";
7036
 
7037
			#設置執行錯誤訊息
7038
			$result["error"][]="\$conf變數須為陣列形態";
7039
 
7040
			#如果傳入的參數為 null
7041
			if($conf==null){
7042
 
7043
				#設置執行錯誤訊息
7044
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7045
 
7046
				}#if end
7047
 
7048
			#回傳結果
7049
			return $result;
7050
 
7051
			}#if end
7052
 
7053
		#取得參數
7054
		$result["argu"]=$conf;
7055
 
7056
		#檢查參數
7057
		#函式說明:
7058
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7059
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7060
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7061
		#$result["function"],當前執行的函式名稱.
7062
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7063
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7064
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7065
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7066
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7067
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7068
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7069
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7070
		#必填寫的參數:
7071
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7072
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7073
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7074
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
7075
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7076
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7077
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7078
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7079
		#可以省略的參數:
7080
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7081
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7082
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7083
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7084
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7085
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
7086
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7087
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
7088
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 7089
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
249 liveuser 7090
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7091
		#$conf["arrayCountEqualCheck"][]=array();
7092
		#參考資料來源:
7093
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7094
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7095
		unset($conf["variableCheck::checkArguments"]);
7096
 
7097
		#如果檢查失敗
7098
		if($checkArguments["status"]==="false"){
7099
 
7100
			#設置錯誤識別
7101
			$result["status"]="false";
7102
 
7103
			#設置錯誤訊息
7104
			$result["error"]=$checkArguments;
7105
 
7106
			#回傳結果
7107
			return $result;
7108
 
7109
			}#if end
7110
 
7111
		#如果檢查不通過
7112
		if($checkArguments["passed"]==="false"){
7113
 
7114
			#設置錯誤識別
7115
			$result["status"]="false";
7116
 
7117
			#設置錯誤訊息
7118
			$result["error"]=$checkArguments;
7119
 
7120
			#回傳結果
7121
			return $result;
7122
 
7123
			}#if end
7124
 
7125
		#要傳送的 key -> value
7126
		$postArray=array();
7127
 
7128
		#設置要簽署的domain
7129
		$postArray["validation_method"]="CNAME_CSR_HASH";
7130
 
7131
		#設置要傳送的 json
7132
		$postJson=json_encode($postArray);
7133
 
7134
		#函式說明:
7135
		#運行curl cmd
7136
		#回傳結果:
7137
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7138
		#$result["error"],錯誤訊息陣列.
7139
		#$result["function"],當前執行的函式名稱.
7140
		#$result["founded"],識別網址找不找得到.
7141
		#$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"代表程序的資訊.
7142
		#$result["fullContent"],取得回應的完整字串內容.
7143
		#$result["cookie"],cookie檔案的位置與名稱.
7144
		#$result["cmd"],執行的command.
7145
		#$result["argu],使用的參數.
7146
		#必填參數:
7147
		#$conf["url"],字串,目標url.
255 liveuser 7148
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
249 liveuser 7149
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7150
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7151
		#可省略參數:
7152
		#$conf["header"],字串陣列,要傳送的header.
7153
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7154
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7155
		#$conf["allowAnySSLcertificate"]="";
7156
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7157
		#$conf["postVar"]=array();
7158
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7159
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7160
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7161
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7162
		#$conf["agent"],字串,user agent的名稱.
7163
		#$conf["agent"]="";
7164
		#$conf["cookie"],字串,cookie位置與檔案位置.
7165
		#$conf["cookie"]="";
7166
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7167
		#$conf["forceNewCookie"]="";
7168
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7169
		#$conf["inBg"]="true";
7170
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7171
		#$conf["bgInProc"]="false";
7172
		#參考資料:
7173
		#無.
7174
		#備註:
7175
		#無.
7176
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7177
		unset($conf["catchWebContent::curlCmd"]);
7178
 
7179
		#如果異常
7180
		if($curlCmd["status"]==="false"){
7181
 
7182
			#設置錯誤識別
7183
			$result["status"]="false";
7184
 
7185
			#設置錯誤訊息
7186
			$result["error"]=$curlCmd;
7187
 
7188
			#回傳結果
7189
			return $result;
7190
 
7191
			}#if end
7192
 
7193
		#設置curl的詳細資訊
7194
		$result["curl_verbose_info"]=$curlCmd;
7195
 
255 liveuser 7196
		#驗證結果是否為 json
7197
		$json_validate=json_validate($curlCmd["fullContent"]);
7198
 
7199
		#如果回應不是 json
7200
		if(!$json_validate){
249 liveuser 7201
 
255 liveuser 7202
			#設置錯誤識別
7203
			$result["status"]="false";
7204
 
7205
			#設置錯誤訊息
7206
			$result["error"]=$curlCmd;
7207
 
7208
			#回傳結果
7209
			return $result;
7210
 
7211
			}#if end
7212
 
7213
		#設置json string結果
7214
		$result["content"]=$curlCmd["fullContent"];
7215
 
7216
		#解析json
7217
		$jsonRes=json_decode($result["content"]);
7218
 
293 liveuser 7219
		#如果有 success 資訊
7220
		if(isset($jsonRes->success)){
255 liveuser 7221
 
293 liveuser 7222
			#do nothing
7223
 
7224
			}#if end
7225
 
7226
		#反之如果沒有 status
7227
		else if(!isset($jsonRes->status)){
7228
 
255 liveuser 7229
			#設置錯誤識別
7230
			$result["status"]="false";
7231
 
7232
			#設置錯誤訊息
7233
			$result["error"]=$curlCmd;
7234
 
7235
			#回傳結果
7236
			return $result;
7237
 
7238
			}#if end
7239
 
293 liveuser 7240
		#反之有 status 資訊
7241
		else{
255 liveuser 7242
 
293 liveuser 7243
			#如果是 "pending_validation"
7244
			if($jsonRes->status==="pending_validation"){
255 liveuser 7245
 
293 liveuser 7246
				#do nothing
255 liveuser 7247
 
293 liveuser 7248
				}#if end
7249
 
7250
			#反之如果為 "issued"
7251
			else if($jsonRes->status==="issued"){
7252
 
7253
				#do nothing
7254
 
7255
				}#else 
7256
 
7257
			#反之
7258
			else{
7259
 
7260
				#設置錯誤識別
7261
				$result["status"]="false";
255 liveuser 7262
 
293 liveuser 7263
				#設置錯誤訊息
7264
				$result["error"]=$curlCmd;
255 liveuser 7265
 
293 liveuser 7266
				#回傳結果
7267
				return $result;
7268
 
7269
				}#else end
255 liveuser 7270
 
7271
			}#else end
7272
 
7273
		#設置執行正常
7274
		$result["status"]="true";
7275
 
7276
		#回傳結果
7277
		return $result;
7278
 
7279
		}#function verifyDomain end
7280
 
7281
	/*
7282
	#函式說明:
7283
	#取得CSR在zerossl上的狀態
7284
	#回傳結果:
7285
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7286
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7287
	#$result["function"],當前執行的函式名稱.
7288
	#$result["argu"],所使用的參數.
7289
	#$result["curl_verbose_info"],curl執行的詳細資訊.
7290
	#$result["content"],結果json字串.
7291
	#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7292
	#必填參數:
7293
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
7294
	$conf["id"]="";
7295
	#可省略參數:
7296
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7297
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7298
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7299
	#$conf["key"]=self::getApiInfo()["apiKey"];
7300
	#參考資料:
7301
	#https://zerossl.com/documentation/api/get-certificate/
7302
	#備註:
7303
	#無.
7304
	*/
7305
	public static function getCertSta(&$conf){
7306
 
7307
		#初始化要回傳的結果
7308
		$result=array();
7309
 
7310
		#設置當其函數名稱
7311
		$result["function"]=__FUNCTION__;
7312
 
7313
		#如果 $conf 不為陣列
7314
		if(gettype($conf)!="array"){
7315
 
7316
			#設置執行失敗
7317
			$result["status"]="false";
7318
 
7319
			#設置執行錯誤訊息
7320
			$result["error"][]="\$conf變數須為陣列形態";
7321
 
7322
			#如果傳入的參數為 null
7323
			if($conf==null){
7324
 
7325
				#設置執行錯誤訊息
7326
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7327
 
7328
				}#if end
7329
 
7330
			#回傳結果
7331
			return $result;
7332
 
7333
			}#if end
7334
 
7335
		#取得參數
7336
		$result["argu"]=$conf;
291 liveuser 7337
 
7338
		#DEBUG
7339
		#var_dump(__LINE__,self::getApiInfo());exit;
255 liveuser 7340
 
7341
		#檢查參數
7342
		#函式說明:
7343
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7344
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7345
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7346
		#$result["function"],當前執行的函式名稱.
7347
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7348
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7349
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7350
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7351
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7352
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7353
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7354
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7355
		#必填寫的參數:
7356
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7357
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7358
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7359
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
7360
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7361
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7362
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7363
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7364
		#可以省略的參數:
7365
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7366
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7367
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7368
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7369
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7370
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
7371
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7372
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
7373
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7374
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
7375
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7376
		#$conf["arrayCountEqualCheck"][]=array();
7377
		#參考資料來源:
7378
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7379
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7380
		unset($conf["variableCheck::checkArguments"]);
7381
 
7382
		#如果檢查失敗
7383
		if($checkArguments["status"]==="false"){
7384
 
7385
			#設置錯誤識別
7386
			$result["status"]="false";
7387
 
7388
			#設置錯誤訊息
7389
			$result["error"]=$checkArguments;
7390
 
7391
			#回傳結果
7392
			return $result;
7393
 
7394
			}#if end
7395
 
7396
		#如果檢查不通過
7397
		if($checkArguments["passed"]==="false"){
7398
 
7399
			#設置錯誤識別
7400
			$result["status"]="false";
7401
 
7402
			#設置錯誤訊息
7403
			$result["error"]=$checkArguments;
7404
 
7405
			#回傳結果
7406
			return $result;
7407
 
7408
			}#if end
7409
 
7410
		#函式說明:
7411
		#運行curl cmd
7412
		#回傳結果:
7413
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7414
		#$result["error"],錯誤訊息陣列.
7415
		#$result["function"],當前執行的函式名稱.
7416
		#$result["founded"],識別網址找不找得到.
7417
		#$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"代表程序的資訊.
7418
		#$result["fullContent"],取得回應的完整字串內容.
7419
		#$result["cookie"],cookie檔案的位置與名稱.
7420
		#$result["cmd"],執行的command.
7421
		#$result["argu],使用的參數.
7422
		#必填參數:
7423
		#$conf["url"],字串,目標url.
7424
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
7425
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7426
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7427
		#可省略參數:
7428
		#$conf["header"],字串陣列,要傳送的header.
7429
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7430
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7431
		#$conf["allowAnySSLcertificate"]="";
7432
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7433
		#$conf["postVar"]=array();
7434
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7435
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7436
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7437
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7438
		#$conf["agent"],字串,user agent的名稱.
7439
		#$conf["agent"]="";
7440
		#$conf["cookie"],字串,cookie位置與檔案位置.
7441
		#$conf["cookie"]="";
7442
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7443
		#$conf["forceNewCookie"]="";
7444
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7445
		#$conf["inBg"]="true";
7446
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7447
		#$conf["bgInProc"]="false";
7448
		#參考資料:
7449
		#無.
7450
		#備註:
7451
		#無.
7452
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7453
		unset($conf["catchWebContent::curlCmd"]);
7454
 
7455
		#如果異常
7456
		if($curlCmd["status"]==="false"){
7457
 
7458
			#設置錯誤識別
7459
			$result["status"]="false";
7460
 
7461
			#設置錯誤訊息
7462
			$result["error"]=$curlCmd;
7463
 
7464
			#回傳結果
7465
			return $result;
7466
 
7467
			}#if end
7468
 
7469
		#設置curl的詳細資訊
7470
		$result["curl_verbose_info"]=$curlCmd;
7471
 
7472
		#驗證結果是否為 json
7473
		$json_validate=json_validate($curlCmd["fullContent"]);
7474
 
7475
		#如果回應不是 json
7476
		if(!$json_validate){
7477
 
7478
			#設置錯誤識別
7479
			$result["status"]="false";
7480
 
7481
			#設置錯誤訊息
7482
			$result["error"]=$curlCmd;
7483
 
7484
			#回傳結果
7485
			return $result;
7486
 
7487
			}#if end
7488
 
7489
		#設置json string結果
7490
		$result["content"]=$curlCmd["fullContent"];
7491
 
7492
		#解析json
7493
		$jsonRes=json_decode($result["content"]);
7494
 
7495
		#如果沒有 status
7496
		if(!isset($jsonRes->status)){
7497
 
7498
			#設置錯誤識別
7499
			$result["status"]="false";
7500
 
7501
			#設置錯誤訊息
7502
			$result["error"]=$curlCmd;
7503
 
7504
			#回傳結果
7505
			return $result;
7506
 
7507
			}#if end
7508
 
7509
		#取得csr在zerossl上的狀態
7510
		$result["cerStatus"]=$jsonRes->status;
7511
 
7512
		#設置執行正常
7513
		$result["status"]="true";
7514
 
7515
		#回傳結果
7516
		return $result;
7517
 
7518
		}#function getCertSta end
7519
 
7520
	/*
7521
	#函式說明:
7522
	#取得在zerossl上的CSR清單
7523
	#回傳結果:
7524
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7525
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7526
	#$result["function"],當前執行的函式名稱.
7527
	#$result["argu"],所使用的參數.
7528
	#$result["curl_verbose_info"],curl執行的詳細資訊.
7529
	#$result["content"],結果json字串.
7530
	#$result["tCount"],總共的資料筆數.
7531
	#$result["count"],該頁的筆數.
7532
	#$result["page"],當前的頁碼.
7533
	#$result["certs"],陣列,certificates清單,key為certificate的id.
7534
	#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
7535
	#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
7536
	#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
7537
	#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
7538
	#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7539
	#必填參數:
7540
	#無
7541
	#可省略參數:
7542
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7543
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7544
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7545
	#$conf["key"]=self::getApiInfo()["apiKey"];
7546
	#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7547
	#$conf["cerStatus"]="";
7548
	#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
7549
	#$conf["cerType"]="";
7550
	#$conf["search"],字串,透過certificate包含的domain來搜尋.
7551
	#$conf["search"]="";
7552
	#$conf["limit"],字串,一頁要多少筆,預設為100筆.
7553
	#$conf["limit"]="";
7554
	#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
7555
	#$conf["page"]="";
7556
	#參考資料:
7557
	#https://zerossl.com/documentation/api/list-certificates/
7558
	#備註:
7559
	#無.
7560
	*/
7561
	public static function getCertList(&$conf){
7562
 
7563
		#初始化要回傳的結果
7564
		$result=array();
7565
 
7566
		#設置當其函數名稱
7567
		$result["function"]=__FUNCTION__;
7568
 
7569
		#如果 $conf 不為陣列
7570
		if(gettype($conf)!="array"){
7571
 
7572
			#設置執行失敗
7573
			$result["status"]="false";
7574
 
7575
			#設置執行錯誤訊息
7576
			$result["error"][]="\$conf變數須為陣列形態";
7577
 
7578
			#如果傳入的參數為 null
7579
			if($conf==null){
7580
 
7581
				#設置執行錯誤訊息
7582
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7583
 
7584
				}#if end
7585
 
7586
			#回傳結果
7587
			return $result;
7588
 
7589
			}#if end
7590
 
7591
		#取得參數
7592
		$result["argu"]=$conf;
7593
 
7594
		#檢查參數
7595
		#函式說明:
7596
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7597
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7598
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7599
		#$result["function"],當前執行的函式名稱.
7600
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7601
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7602
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7603
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7604
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7605
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7606
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7607
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7608
		#必填寫的參數:
7609
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7610
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7611
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7612
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
7613
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7614
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7615
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7616
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7617
		#可以省略的參數:
7618
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7619
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7620
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7621
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7622
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7623
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
7624
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7625
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
7626
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7627
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
7628
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7629
		#$conf["arrayCountEqualCheck"][]=array();
7630
		#參考資料來源:
7631
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7632
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7633
		unset($conf["variableCheck::checkArguments"]);
7634
 
7635
		#如果檢查失敗
7636
		if($checkArguments["status"]==="false"){
7637
 
7638
			#設置錯誤識別
7639
			$result["status"]="false";
7640
 
7641
			#設置錯誤訊息
7642
			$result["error"]=$checkArguments;
7643
 
7644
			#回傳結果
7645
			return $result;
7646
 
7647
			}#if end
7648
 
7649
		#如果檢查不通過
7650
		if($checkArguments["passed"]==="false"){
7651
 
7652
			#設置錯誤識別
7653
			$result["status"]="false";
7654
 
7655
			#設置錯誤訊息
7656
			$result["error"]=$checkArguments;
7657
 
7658
			#回傳結果
7659
			return $result;
7660
 
7661
			}#if end
7662
 
7663
		#預設網址
291 liveuser 7664
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."?access_key=".$conf["key"];
255 liveuser 7665
 
7666
		#如果有設置 cerStatus
7667
		if(isset($conf["cerStatus"])){
7668
 
7669
			#設置 certificate_status 
291 liveuser 7670
			$url=$url."&certificate_status=".urlencode($conf["cerStatus"]);
255 liveuser 7671
 
7672
			}#if end
7673
 
7674
		#如果有設置 cerType
7675
		if(isset($conf["cerType"])){
7676
 
7677
			#設置 certificate_type
291 liveuser 7678
			$url=$url."&certificate_type=".urlencode($conf["cerType"]);
255 liveuser 7679
 
7680
			}#if end
7681
 
7682
		#如果有設置 search
7683
		if(isset($conf["search"])){
7684
 
7685
			#設置 search
291 liveuser 7686
			$url=$url."&search=".urlencode($conf["search"]);
255 liveuser 7687
 
7688
			}#if end
7689
 
7690
		#如果有設置 limit
7691
		if(isset($conf["limit"])){
7692
 
7693
			#設置 search
291 liveuser 7694
			$url=$url."&limit=".urlencode($conf["limit"]);
255 liveuser 7695
 
7696
			}#if end
7697
 
7698
		#如果有設置 page
7699
		if(isset($conf["page"])){
7700
 
7701
			#設置 search
291 liveuser 7702
			$url=$url."&"."page=".urlencode($conf["page"]);
255 liveuser 7703
 
7704
			}#if end
7705
 
7706
		#函式說明:
7707
		#運行curl cmd
7708
		#回傳結果:
7709
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7710
		#$result["error"],錯誤訊息陣列.
7711
		#$result["function"],當前執行的函式名稱.
7712
		#$result["founded"],識別網址找不找得到.
7713
		#$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"代表程序的資訊.
7714
		#$result["fullContent"],取得回應的完整字串內容.
7715
		#$result["cookie"],cookie檔案的位置與名稱.
7716
		#$result["cmd"],執行的command.
7717
		#$result["argu],使用的參數.
7718
		#必填參數:
7719
		#$conf["url"],字串,目標url.
7720
		$conf["catchWebContent::curlCmd"]["url"]=$url;
7721
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7722
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7723
		#可省略參數:
7724
		#$conf["header"],字串陣列,要傳送的header.
7725
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7726
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7727
		#$conf["allowAnySSLcertificate"]="";
7728
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7729
		#$conf["postVar"]=array();
7730
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7731
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7732
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7733
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7734
		#$conf["agent"],字串,user agent的名稱.
7735
		#$conf["agent"]="";
7736
		#$conf["cookie"],字串,cookie位置與檔案位置.
7737
		#$conf["cookie"]="";
7738
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7739
		#$conf["forceNewCookie"]="";
7740
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7741
		#$conf["inBg"]="true";
7742
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7743
		#$conf["bgInProc"]="false";
7744
		#參考資料:
7745
		#無.
7746
		#備註:
7747
		#無.
7748
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7749
		unset($conf["catchWebContent::curlCmd"]);
7750
 
7751
		#如果異常
7752
		if($curlCmd["status"]==="false"){
7753
 
7754
			#設置錯誤識別
7755
			$result["status"]="false";
7756
 
7757
			#設置錯誤訊息
7758
			$result["error"]=$curlCmd;
7759
 
7760
			#回傳結果
7761
			return $result;
7762
 
7763
			}#if end
7764
 
7765
		#設置curl的詳細資訊
7766
		$result["curl_verbose_info"]=$curlCmd;
7767
 
7768
		#驗證結果是否為 json
7769
		$json_validate=json_validate($curlCmd["fullContent"]);
7770
 
7771
		#如果回應不是 json
7772
		if(!$json_validate){
7773
 
7774
			#設置錯誤識別
7775
			$result["status"]="false";
7776
 
7777
			#設置錯誤訊息
7778
			$result["error"]=$curlCmd;
7779
 
7780
			#回傳結果
7781
			return $result;
7782
 
7783
			}#if end
7784
 
7785
		#設置json string結果
7786
		$result["content"]=$curlCmd["fullContent"];
7787
 
7788
		/* json response 範例
7789
		{
7790
			"total_count": 11,
7791
			"result_count": 10,
7792
			"page": 1,
7793
			"limit": 10,
7794
			"acmeUsageLevel": "LOW",
7795
			"isAcmeLocked": false,
7796
			"results": 
7797
			[
7798
				{
7799
					"id": "a856a39a1c3ad0s8asa606g37667d221",
7800
					"type": "1",
7801
					"common_name": "domain.com",
7802
					"additional_domains": "www.domain.com",
7803
					"created": "2020-04-29 09:04:19",
7804
					"expires": "2020-07-28 00:00:00",
7805
					"status": "draft",
7806
					"validation_type": null,
7807
					"validation_emails": null,
7808
					"replacement_for": "",
7809
					"fingerprint_sha1": null,
7810
					"brand_validation": null,
7811
					"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
7812
					"validation":
7813
					{
7814
						"email_validation":
7815
						{
7816
							"domain.com":
7817
							[
7818
								"admin@domain.com",
7819
								"administrator@domain.com",
7820
								"hostmaster@domain.com",
7821
								"postmaster@domain.com",
7822
								"webmaster@domain.com"
7823
							]
7824
						},
7825
						"other_methods": 
7826
						{
7827
							"domain.com":
7828
							{
7829
								"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
7830
								"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
7831
								"file_validation_content":
7832
								[
7833
									"2B449B722B449B729394793947",
7834
									"comodoca.com",
7835
									"4bad7360c7076ba"
7836
								],
7837
								"cname_validation_p1": "2B449B7293947.domain.com",
7838
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
7839
							},
7840
							"www.domain.com":
7841
							{
7842
								"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
7843
								"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",   
7844
								"file_validation_content":
7845
								[
7846
									"2B449B722B449B729394793947",
7847
									"comodoca.com",
7848
									"4bad7360c7076ba"
7849
								],
7850
								"cname_validation_p1": "2B449B7293947.www.domain.com",
7851
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
7852
							}
7853
						}
7854
					}
7855
				},
7856
				{
7857
					...
7858
				}
7859
			]
7860
		}
249 liveuser 7861
		*/
7862
 
255 liveuser 7863
		#解析json
7864
		$jsonRes=json_decode($result["content"]);
7865
 
7866
		#總共的資料筆數
7867
		$result["tCount"]=$jsonRes->total_count;
7868
 
7869
		#取得該頁的筆數
7870
		$result["count"]=$jsonRes->result_count;
7871
 
7872
		#取得certificate清單
291 liveuser 7873
		$certs=$jsonRes->results;
255 liveuser 7874
 
7875
		#針對每個certificate
7876
		foreach($certs as $index => $cert){
7877
 
7878
			#初始化暫存的陣列
7879
			$tmpA=array();
7880
 
7881
			#儲存 cert id
7882
			#$tmpA["id"]=$cert->id;
7883
 
7884
			#儲存 主要包含的 domain name
7885
			$tmpA["cname"]=$cert->common_name;
7886
 
7887
			#儲存額外包含的 domain name
7888
			$tmpA["anames"]=$cert->additional_domains;
7889
 
7890
			#最後有效年月日,格式為"2020-07-28 00:00:00".
7891
			$tmpA["expiresYMD"]=$cert->expires;
7892
 
7893
			#產生對於當前系統時間的差距(秒數)
7894
			#函式說明:
7895
			#計算時間點距離1970/01/01多少秒,亦即unixtime.
7896
			#回傳結果:
7897
			#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
7898
			#$result["error"],錯誤訊息陣列.
7899
			#$result["content"],時間點距離1970/01/01的多少秒.
7900
			#$result["argu"],使用的參數.
7901
			#$result["unixtime"],執行本函式時的unixtime.
7902
			#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
7903
			#必填參數:
7904
			#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
7905
			$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
7906
			#可省略參數:
7907
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
7908
			#$conf["UTC"]="false";
7909
			#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
7910
			$conf["time::caculateTimeAmount"]["replace0"]="false";
7911
			#參考資料:
7912
			#無.
7913
			#備註:
7914
			#無.
7915
			$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
7916
			unset($conf["time::caculateTimeAmount"]);
7917
 
7918
			#如果執行異常
291 liveuser 7919
			if($caculateTimeAmount["status"]==="false"){
255 liveuser 7920
 
7921
				#設置錯誤識別
7922
				$result["status"]="false";
7923
 
7924
				#設置錯誤訊息
7925
				$result["error"]=$caculateTimeAmount;
7926
 
7927
				#回傳結果
7928
				return $result;
7929
 
7930
				}#if end
7931
 
7932
			#儲存還要多少秒要過期
291 liveuser 7933
			$tmpA["expiresIn"]=$caculateTimeAmount["content"]-time();
255 liveuser 7934
 
7935
			#憑證的狀態
7936
			$tmpA["status"]=$cert->status;
7937
 
291 liveuser 7938
			#儲存要回傳的 certs 清單,key為cert的id.
7939
			$result["certs"][$cert->id]=$tmpA;
255 liveuser 7940
 
7941
			}#foreach end
7942
 
7943
		#設置執行正常
7944
		$result["status"]="true";
7945
 
7946
		#回傳結果
7947
		return $result;
7948
 
7949
		}#function getCertList end
7950
 
7951
	/*
7952
	#函式說明:
7953
	#下載certificate.
7954
	#回傳結果:
7955
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7956
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7957
	#$result["function"],當前執行的函式名稱.
7958
	#$result["argu"],所使用的參數.
7959
	#$result["curl_verbose_info"],curl執行的詳細資訊.
7960
	#$result["content"],結果json字串.
7961
	#$result["certificate.crt"],字串,certificate.crt的內容.
7962
	#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
7963
	#必填參數:
7964
	#無.
7965
	#可省略參數:
7966
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7967
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7968
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7969
	#$conf["key"]=self::getApiInfo()["apiKey"];
7970
	#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
7971
	#$conf["id"]="";
7972
	#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
7973
	#$conf["cname"]="";
7974
	#參考資料:
7975
	#https://zerossl.com/documentation/api/download-certificate-inline/
7976
	#備註:
7977
	#無.
7978
	*/
7979
	public static function getCert(&$conf){
7980
 
7981
		#初始化要回傳的結果
7982
		$result=array();
7983
 
7984
		#設置當其函數名稱
7985
		$result["function"]=__FUNCTION__;
7986
 
7987
		#如果 $conf 不為陣列
7988
		if(gettype($conf)!="array"){
7989
 
7990
			#設置執行失敗
7991
			$result["status"]="false";
7992
 
7993
			#設置執行錯誤訊息
7994
			$result["error"][]="\$conf變數須為陣列形態";
7995
 
7996
			#如果傳入的參數為 null
7997
			if($conf==null){
7998
 
7999
				#設置執行錯誤訊息
8000
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8001
 
8002
				}#if end
8003
 
8004
			#回傳結果
8005
			return $result;
8006
 
8007
			}#if end
8008
 
8009
		#取得參數
8010
		$result["argu"]=$conf;
8011
 
8012
		#檢查參數
8013
		#函式說明:
8014
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8015
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8016
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8017
		#$result["function"],當前執行的函式名稱.
8018
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8019
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8020
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8021
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8022
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8023
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8024
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8025
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8026
		#必填寫的參數:
8027
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8028
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8029
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8030
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
8031
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
8032
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
8033
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8034
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8035
		#可以省略的參數:
8036
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8037
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8038
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
8039
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8040
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8041
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
8042
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8043
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
8044
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8045
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
8046
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8047
		#$conf["arrayCountEqualCheck"][]=array();
8048
		#參考資料來源:
8049
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8050
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8051
		unset($conf["variableCheck::checkArguments"]);
8052
 
8053
		#如果檢查失敗
8054
		if($checkArguments["status"]==="false"){
8055
 
8056
			#設置錯誤識別
8057
			$result["status"]="false";
8058
 
8059
			#設置錯誤訊息
8060
			$result["error"]=$checkArguments;
8061
 
8062
			#回傳結果
8063
			return $result;
8064
 
8065
			}#if end
8066
 
8067
		#如果檢查不通過
8068
		if($checkArguments["passed"]==="false"){
8069
 
8070
			#設置錯誤識別
8071
			$result["status"]="false";
8072
 
8073
			#設置錯誤訊息
8074
			$result["error"]=$checkArguments;
8075
 
8076
			#回傳結果
8077
			return $result;
8078
 
8079
			}#if end
8080
 
8081
		#如果有設置 id
8082
		if(isset($conf["id"])){
8083
 
8084
			#設置 id
8085
			$id=$conf["id"];
8086
 
8087
			}#if end
8088
 
8089
		#反之如果有設置 cname
8090
		else if(isset($conf["cname"])){
8091
 
8092
			#函式說明:
8093
			#取得在zerossl上的CSR清單
8094
			#回傳結果:
8095
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8096
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
8097
			#$result["function"],當前執行的函式名稱.
8098
			#$result["argu"],所使用的參數.
8099
			#$result["curl_verbose_info"],curl執行的詳細資訊.
8100
			#$result["content"],結果json字串.
8101
			#$result["tCound"],總共的資料筆數.
8102
			#$result["count"],該頁的筆數.
8103
			#$result["page"],當前的頁碼.
8104
			#$result["certs"],陣列,certificates清單,key為certificate的id.
8105
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
8106
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
8107
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
8108
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
8109
			#必填參數:
8110
			#無
8111
			#可省略參數:
8112
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8113
			#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8114
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8115
			#$conf["key"]=self::getApiInfo()["apiKey"];
8116
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
8117
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
8118
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
8119
			#$conf["cerType"]="";
8120
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
8121
			$conf["zerossl::getCertList"]["search"]=$conf["cname"];
8122
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
8123
			#$conf["limit"]="";
8124
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
8125
			#$conf["page"]="";
8126
			#參考資料:
8127
			#https://zerossl.com/documentation/api/get-certificate/
8128
			#備註:
8129
			#無.
8130
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
8131
			unset($conf["zerossl::getCertList"]);
8132
 
8133
			#如果檢查失敗
8134
			if($getCertList["status"]==="false"){
8135
 
8136
				#設置錯誤識別
8137
				$result["status"]="false";
8138
 
8139
				#設置錯誤訊息
8140
				$result["error"]=$getCertList;
8141
 
8142
				#回傳結果
8143
				return $result;
8144
 
8145
				}#if end
8146
 
8147
			#如果資料筆數大於0
8148
			if($getCertList["count"]>0){
8149
 
8150
				#取得第一筆
8151
				foreach($getCertList["certs"] as $cerId => $detail){
8152
 
8153
					#取得cettificate id
8154
					$id=$cerId;
8155
 
8156
					}#foreach end
8157
 
8158
				}#if end
8159
 
8160
			}#if end
8161
 
8162
		#預設網址
8163
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
8164
 
8165
		#函式說明:
8166
		#運行curl cmd
8167
		#回傳結果:
8168
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8169
		#$result["error"],錯誤訊息陣列.
8170
		#$result["function"],當前執行的函式名稱.
8171
		#$result["founded"],識別網址找不找得到.
8172
		#$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"代表程序的資訊.
8173
		#$result["fullContent"],取得回應的完整字串內容.
8174
		#$result["cookie"],cookie檔案的位置與名稱.
8175
		#$result["cmd"],執行的command.
8176
		#$result["argu],使用的參數.
8177
		#必填參數:
8178
		#$conf["url"],字串,目標url.
8179
		$conf["catchWebContent::curlCmd"]["url"]=$url;
8180
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8181
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
8182
		#可省略參數:
8183
		#$conf["header"],字串陣列,要傳送的header.
8184
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
8185
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
8186
		#$conf["allowAnySSLcertificate"]="";
8187
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
8188
		#$conf["postVar"]=array();
8189
		#$conf["rawPost"]="字串",要傳送的raw post內容.
8190
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
8191
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
8192
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
8193
		#$conf["agent"],字串,user agent的名稱.
8194
		#$conf["agent"]="";
8195
		#$conf["cookie"],字串,cookie位置與檔案位置.
8196
		#$conf["cookie"]="";
8197
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
8198
		#$conf["forceNewCookie"]="";
8199
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
8200
		#$conf["inBg"]="true";
8201
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
8202
		#$conf["bgInProc"]="false";
8203
		#參考資料:
8204
		#無.
8205
		#備註:
8206
		#無.
8207
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
8208
		unset($conf["catchWebContent::curlCmd"]);
8209
 
8210
		#如果異常
8211
		if($curlCmd["status"]==="false"){
8212
 
8213
			#設置錯誤識別
8214
			$result["status"]="false";
8215
 
8216
			#設置錯誤訊息
8217
			$result["error"]=$curlCmd;
8218
 
8219
			#回傳結果
8220
			return $result;
8221
 
8222
			}#if end
8223
 
8224
		#設置curl的詳細資訊
8225
		$result["curl_verbose_info"]=$curlCmd;
8226
 
249 liveuser 8227
		#驗證結果是否為 json
8228
		$json_validate=json_validate($curlCmd["fullContent"]);
8229
 
8230
		#如果回應不是 json
8231
		if(!$json_validate){
8232
 
8233
			#設置錯誤識別
8234
			$result["status"]="false";
8235
 
8236
			#設置錯誤訊息
8237
			$result["error"]=$curlCmd;
8238
 
8239
			#回傳結果
8240
			return $result;
8241
 
8242
			}#if end
8243
 
8244
		#設置json string結果
8245
		$result["content"]=$curlCmd["fullContent"];
255 liveuser 8246
 
8247
		#取得 json
8248
		$json=json_decode($curlCmd["fullContent"]);
8249
 
291 liveuser 8250
		#儲存成變數以便透過object呼叫
8251
		$c_crt="certificate.crt";
8252
 
8253
		#儲存成變數以便透過object呼叫
8254
		$ca_crt="ca_bundle.crt";
8255
 
255 liveuser 8256
		#取得certificate.crt的內容
291 liveuser 8257
		$result["certificate.crt"]=$json->$c_crt;
255 liveuser 8258
 
8259
		#取得ca_bundle.crt的內容
291 liveuser 8260
		$result["ca_bundle.crt"]=$json->$ca_crt;
255 liveuser 8261
 
8262
		#設置執行正常
8263
		$result["status"]="true";
8264
 
8265
		#回傳結果
8266
		return $result;
8267
 
8268
		}#function getCert end
8269
 
8270
	/*
8271
	#函式說明:
8272
	#請求廢除 issued zerossl certificate.
8273
	#回傳結果:
8274
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8275
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
8276
	#$result["function"],當前執行的函式名稱.
8277
	#$result["argu"],所使用的參數.
8278
	#$result["curl_verbose_info"],curl執行的詳細資訊.
8279
	#$result["content"],結果json字串.
8280
	#必填參數:
8281
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
8282
	$conf["id"]="";
8283
	#可省略參數:
8284
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8285
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8286
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8287
	#$conf["key"]=self::getApiInfo()["apiKey"];
8288
	#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
8289
	#$conf["reason"]="";
8290
	#參考資料:
8291
	#https://zerossl.com/documentation/api/revoke-certificate/
8292
	#備註:
8293
	#無.
8294
	*/
8295
	public static function revokeCert(&$conf){
8296
 
8297
		#初始化要回傳的結果
8298
		$result=array();
249 liveuser 8299
 
255 liveuser 8300
		#設置當其函數名稱
8301
		$result["function"]=__FUNCTION__;
8302
 
8303
		#如果 $conf 不為陣列
8304
		if(gettype($conf)!="array"){
8305
 
8306
			#設置執行失敗
8307
			$result["status"]="false";
8308
 
8309
			#設置執行錯誤訊息
8310
			$result["error"][]="\$conf變數須為陣列形態";
8311
 
8312
			#如果傳入的參數為 null
8313
			if($conf==null){
8314
 
8315
				#設置執行錯誤訊息
8316
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8317
 
8318
				}#if end
8319
 
8320
			#回傳結果
8321
			return $result;
8322
 
8323
			}#if end
8324
 
8325
		#取得參數
8326
		$result["argu"]=$conf;
8327
 
8328
		#檢查參數
8329
		#函式說明:
8330
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8331
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8332
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8333
		#$result["function"],當前執行的函式名稱.
8334
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8335
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8336
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8337
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8338
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8339
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8340
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8341
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8342
		#必填寫的參數:
8343
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8344
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8345
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8346
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
8347
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
8348
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
8349
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8350
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8351
		#可以省略的參數:
8352
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8353
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8354
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
8355
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8356
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8357
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
8358
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8359
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","status");
8360
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8361
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
8362
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8363
		#$conf["arrayCountEqualCheck"][]=array();
8364
		#參考資料來源:
8365
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8366
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8367
		unset($conf["variableCheck::checkArguments"]);
8368
 
8369
		#如果檢查失敗
8370
		if($checkArguments["status"]==="false"){
8371
 
8372
			#設置錯誤識別
8373
			$result["status"]="false";
8374
 
8375
			#設置錯誤訊息
8376
			$result["error"]=$checkArguments;
8377
 
8378
			#回傳結果
8379
			return $result;
8380
 
8381
			}#if end
8382
 
8383
		#如果檢查不通過
8384
		if($checkArguments["passed"]==="false"){
8385
 
8386
			#設置錯誤識別
8387
			$result["status"]="false";
8388
 
8389
			#設置錯誤訊息
8390
			$result["error"]=$checkArguments;
8391
 
8392
			#回傳結果
8393
			return $result;
8394
 
8395
			}#if end
8396
 
8397
		#url to call
8398
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
8399
 
8400
		#如果有設置 reason
8401
		if(isset($conf["reason"])){
8402
 
8403
			#設置reason
8404
			$reason="&reason=".$conf["reason"];
8405
 
8406
			#串接reason
8407
			$url=$url.$reason;
8408
 
8409
			}#if end
8410
 
8411
		#函式說明:
8412
		#運行curl cmd
8413
		#回傳結果:
8414
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8415
		#$result["error"],錯誤訊息陣列.
8416
		#$result["function"],當前執行的函式名稱.
8417
		#$result["founded"],識別網址找不找得到.
8418
		#$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"代表程序的資訊.
8419
		#$result["fullContent"],取得回應的完整字串內容.
8420
		#$result["cookie"],cookie檔案的位置與名稱.
8421
		#$result["cmd"],執行的command.
8422
		#$result["argu],使用的參數.
8423
		#必填參數:
8424
		#$conf["url"],字串,目標url.
8425
		$conf["catchWebContent::curlCmd"]["url"]=$url;
8426
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8427
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
8428
		#可省略參數:
8429
		#$conf["header"],字串陣列,要傳送的header.
8430
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
8431
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
8432
		#$conf["allowAnySSLcertificate"]="";
8433
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
8434
		#$conf["postVar"]=array();
8435
		#$conf["rawPost"]="字串",要傳送的raw post內容.
8436
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
8437
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
8438
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
8439
		#$conf["agent"],字串,user agent的名稱.
8440
		#$conf["agent"]="";
8441
		#$conf["cookie"],字串,cookie位置與檔案位置.
8442
		#$conf["cookie"]="";
8443
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
8444
		#$conf["forceNewCookie"]="";
8445
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
8446
		#$conf["inBg"]="true";
8447
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
8448
		#$conf["bgInProc"]="false";
8449
		#參考資料:
8450
		#無.
8451
		#備註:
8452
		#無.
8453
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
8454
		unset($conf["catchWebContent::curlCmd"]);
8455
 
8456
		#如果異常
8457
		if($curlCmd["status"]==="false"){
8458
 
8459
			#設置錯誤識別
8460
			$result["status"]="false";
8461
 
8462
			#設置錯誤訊息
8463
			$result["error"]=$curlCmd;
8464
 
8465
			#回傳結果
8466
			return $result;
8467
 
8468
			}#if end
8469
 
8470
		#設置curl的詳細資訊
8471
		$result["curl_verbose_info"]=$curlCmd;
8472
 
8473
		#驗證結果是否為 json
8474
		$json_validate=json_validate($curlCmd["fullContent"]);
8475
 
8476
		#如果回應不是 json
8477
		if(!$json_validate){
8478
 
8479
			#設置錯誤識別
8480
			$result["status"]="false";
8481
 
8482
			#設置錯誤訊息
8483
			$result["error"]=$curlCmd;
8484
 
8485
			#回傳結果
8486
			return $result;
8487
 
8488
			}#if end
8489
 
8490
		#設置json string結果
8491
		$result["content"]=$curlCmd["fullContent"];
8492
 
249 liveuser 8493
		#解析json
8494
		$jsonRes=json_decode($result["content"]);
8495
 
255 liveuser 8496
		#如果沒有要有的attr
8497
		if(!isset($jsonRes->success)){
8498
 
8499
			#設置錯誤識別
8500
			$result["status"]="false";
8501
 
8502
			#設置錯誤訊息
8503
			$result["error"]=$curlCmd;
8504
 
8505
			#回傳結果
8506
			return $result;
8507
 
8508
			}#if end
8509
 
8510
		#如果 success 不等於 1
8511
		if($jsonRes->success!==1){
8512
 
8513
			#設置錯誤識別
8514
			$result["status"]="false";
8515
 
8516
			#設置錯誤訊息
8517
			$result["error"]=$curlCmd;
8518
 
8519
			#回傳結果
8520
			return $result;
8521
 
8522
			}#if end
8523
 
249 liveuser 8524
		#設置執行正常
8525
		$result["status"]="true";
8526
 
8527
		#回傳結果
8528
		return $result;
8529
 
255 liveuser 8530
		}#function revokeCert end
8531
 
8532
	/*
8533
	#函式說明:
8534
	#請求取消 draft or unvalidated zerossl certificate.
8535
	#回傳結果:
8536
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8537
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
8538
	#$result["function"],當前執行的函式名稱.
8539
	#$result["argu"],所使用的參數.
8540
	#$result["curl_verbose_info"],curl執行的詳細資訊.
8541
	#$result["content"],結果json字串.
8542
	#必填參數:
8543
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
8544
	$conf["id"]="";
8545
	#可省略參數:
8546
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8547
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8548
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8549
	#$conf["key"]=self::getApiInfo()["apiKey"];
8550
	#參考資料:
8551
	#https://zerossl.com/documentation/api/revoke-certificate/
8552
	#備註:
8553
	#無.
8554
	*/
8555
	public static function cancelCert(&$conf){
8556
 
8557
		#初始化要回傳的結果
8558
		$result=array();
249 liveuser 8559
 
255 liveuser 8560
		#設置當其函數名稱
8561
		$result["function"]=__FUNCTION__;
8562
 
8563
		#如果 $conf 不為陣列
8564
		if(gettype($conf)!="array"){
8565
 
8566
			#設置執行失敗
8567
			$result["status"]="false";
8568
 
8569
			#設置執行錯誤訊息
8570
			$result["error"][]="\$conf變數須為陣列形態";
8571
 
8572
			#如果傳入的參數為 null
8573
			if($conf==null){
8574
 
8575
				#設置執行錯誤訊息
8576
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8577
 
8578
				}#if end
8579
 
8580
			#回傳結果
8581
			return $result;
8582
 
8583
			}#if end
8584
 
8585
		#取得參數
8586
		$result["argu"]=$conf;
8587
 
8588
		#檢查參數
8589
		#函式說明:
8590
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8591
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8592
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8593
		#$result["function"],當前執行的函式名稱.
8594
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8595
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8596
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8597
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8598
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8599
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8600
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8601
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8602
		#必填寫的參數:
8603
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8604
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8605
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8606
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
8607
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
8608
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
8609
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8610
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8611
		#可以省略的參數:
8612
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8613
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8614
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
8615
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8616
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8617
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
8618
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8619
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
8620
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8621
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
8622
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8623
		#$conf["arrayCountEqualCheck"][]=array();
8624
		#參考資料來源:
8625
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8626
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8627
		unset($conf["variableCheck::checkArguments"]);
8628
 
8629
		#如果檢查失敗
8630
		if($checkArguments["status"]==="false"){
8631
 
8632
			#設置錯誤識別
8633
			$result["status"]="false";
8634
 
8635
			#設置錯誤訊息
8636
			$result["error"]=$checkArguments;
8637
 
8638
			#回傳結果
8639
			return $result;
8640
 
8641
			}#if end
8642
 
8643
		#如果檢查不通過
8644
		if($checkArguments["passed"]==="false"){
8645
 
8646
			#設置錯誤識別
8647
			$result["status"]="false";
8648
 
8649
			#設置錯誤訊息
8650
			$result["error"]=$checkArguments;
8651
 
8652
			#回傳結果
8653
			return $result;
8654
 
8655
			}#if end
8656
 
8657
		#url to call
8658
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
8659
 
8660
		#函式說明:
8661
		#運行curl cmd
8662
		#回傳結果:
8663
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8664
		#$result["error"],錯誤訊息陣列.
8665
		#$result["function"],當前執行的函式名稱.
8666
		#$result["founded"],識別網址找不找得到.
8667
		#$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"代表程序的資訊.
8668
		#$result["fullContent"],取得回應的完整字串內容.
8669
		#$result["cookie"],cookie檔案的位置與名稱.
8670
		#$result["cmd"],執行的command.
8671
		#$result["argu],使用的參數.
8672
		#必填參數:
8673
		#$conf["url"],字串,目標url.
8674
		$conf["catchWebContent::curlCmd"]["url"]=$url;
8675
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8676
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
8677
		#可省略參數:
8678
		#$conf["header"],字串陣列,要傳送的header.
8679
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
8680
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
8681
		#$conf["allowAnySSLcertificate"]="";
8682
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
8683
		#$conf["postVar"]=array();
8684
		#$conf["rawPost"]="字串",要傳送的raw post內容.
8685
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
8686
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
8687
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
8688
		#$conf["agent"],字串,user agent的名稱.
8689
		#$conf["agent"]="";
8690
		#$conf["cookie"],字串,cookie位置與檔案位置.
8691
		#$conf["cookie"]="";
8692
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
8693
		#$conf["forceNewCookie"]="";
8694
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
8695
		#$conf["inBg"]="true";
8696
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
8697
		#$conf["bgInProc"]="false";
8698
		#參考資料:
8699
		#無.
8700
		#備註:
8701
		#無.
8702
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
8703
		unset($conf["catchWebContent::curlCmd"]);
8704
 
8705
		#如果異常
8706
		if($curlCmd["status"]==="false"){
8707
 
8708
			#設置錯誤識別
8709
			$result["status"]="false";
8710
 
8711
			#設置錯誤訊息
8712
			$result["error"]=$curlCmd;
8713
 
8714
			#回傳結果
8715
			return $result;
8716
 
8717
			}#if end
8718
 
8719
		#設置curl的詳細資訊
8720
		$result["curl_verbose_info"]=$curlCmd;
8721
 
8722
		#驗證結果是否為 json
8723
		$json_validate=json_validate($curlCmd["fullContent"]);
8724
 
8725
		#如果回應不是 json
8726
		if(!$json_validate){
8727
 
8728
			#設置錯誤識別
8729
			$result["status"]="false";
8730
 
8731
			#設置錯誤訊息
8732
			$result["error"]=$curlCmd;
8733
 
8734
			#回傳結果
8735
			return $result;
8736
 
8737
			}#if end
8738
 
8739
		#設置json string結果
8740
		$result["content"]=$curlCmd["fullContent"];
8741
 
8742
		#解析json
8743
		$jsonRes=json_decode($result["content"]);
8744
 
8745
		#如果沒有要有的attr
8746
		if(!isset($jsonRes->success)){
8747
 
8748
			#設置錯誤識別
8749
			$result["status"]="false";
8750
 
8751
			#設置錯誤訊息
8752
			$result["error"]=$curlCmd;
8753
 
8754
			#回傳結果
8755
			return $result;
8756
 
8757
			}#if end
8758
 
8759
		#如果 success 不等於 1
8760
		if($jsonRes->success!==1){
8761
 
8762
			#設置錯誤識別
8763
			$result["status"]="false";
8764
 
8765
			#設置錯誤訊息
8766
			$result["error"]=$curlCmd;
8767
 
8768
			#回傳結果
8769
			return $result;
8770
 
8771
			}#if end
8772
 
8773
		#設置執行正常
8774
		$result["status"]="true";
8775
 
8776
		#回傳結果
8777
		return $result;
8778
 
8779
		}#function cancelCert end
8780
 
8781
	/*
8782
	#函式說明:
8783
	#透過zerossl api確保ssl沒有過期.
8784
	#回傳結果:
8785
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8786
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
8787
	#$result["function"],當前執行的函式名稱.
8788
	#$result["argu"],所使用的參數.
8789
	#必填參數:
8790
	#$conf["cName"],陣列,每個ssl的common domain name.
8791
	$conf["cName"]=array();
8792
	#$conf["certInfo"],陣列,每個cName參數對應的憑證資訊,$conf["certInfo"][$i]["certPath"]為第$+1個cName的certifate.crt的檔案位置與名稱;$conf["certInfo"][$i]["pKey"]為第$i+1個cName的private key;$conf["certInfo"][$i]["caPath"]為第$i+1個cName的ca_bundle.crt的檔案位置與名稱;$conf["certInfo"][$i]["certWithCaPath"]為第$+1個cName的certifate.crt跟ca_bundle.crt內容合併後的檔案位置與名稱.
8793
	$conf["certInfo"]=array();
8794
	#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
8795
	$conf["rrFile"]=array();
8796
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
8797
	$conf["dnsSerAddr"]=array();
8798
	#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
8799
	$conf["actionAfterUpdateCert"]=array();
8800
	#可省略參數:
288 liveuser 8801
	#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/sslUpdater.sock
8802
	#$conf["sock"]="";
281 liveuser 8803
	#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
8804
	#$conf["debug"]="";
255 liveuser 8805
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8806
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
8807
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8808
	#$conf["key"]=self::getApiInfo()["apiKey"];
293 liveuser 8809
	#$conf["multiThreads"],字串,預設為"false"代表不使用多執行序;"true"代表要用多執行序.
8810
	#$conf["multiThreads"]=""
255 liveuser 8811
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
8812
	#$conf["debug"]="";
8813
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
8814
	#$conf["addOnProcessFunc"]=array();
8815
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
8816
	#$conf["funcToRunWhenIdle"]=array();
8817
	#參考資料:
8818
	#無.
8819
	#備註:
8820
	#無.
8821
	*/
8822
	public static function sslUpdater(&$conf){
8823
 
8824
		#初始化要回傳的結果
8825
		$result=array();
8826
 
8827
		#設置當其函數名稱
8828
		$result["function"]=__FUNCTION__;
8829
 
8830
		#如果 $conf 不為陣列
8831
		if(gettype($conf)!="array"){
8832
 
8833
			#設置執行失敗
8834
			$result["status"]="false";
8835
 
8836
			#設置執行錯誤訊息
8837
			$result["error"][]="\$conf變數須為陣列形態";
8838
 
8839
			#如果傳入的參數為 null
8840
			if($conf==null){
8841
 
8842
				#設置執行錯誤訊息
8843
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8844
 
8845
				}#if end
8846
 
8847
			#回傳結果
8848
			return $result;
8849
 
8850
			}#if end
8851
 
8852
		#取得參數
8853
		$result["argu"]=$conf;
288 liveuser 8854
 
8855
		#初始化預設的 unix domain socket 路徑
8856
		$defaultSocket=pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/sslUpdater.sock";
255 liveuser 8857
 
8858
		#檢查參數
8859
		#函式說明:
8860
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8861
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8862
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8863
		#$result["function"],當前執行的函式名稱.
8864
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8865
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8866
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8867
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8868
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8869
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8870
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8871
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8872
		#必填寫的參數:
8873
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8874
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8875
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8876
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
8877
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
8878
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
8879
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8880
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8881
		#可以省略的參數:
8882
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8883
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8884
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
293 liveuser 8885
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("multiThreads","sock","debug","apiDomain","key");
255 liveuser 8886
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 8887
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("multiThreads","sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
255 liveuser 8888
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
293 liveuser 8889
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array","array");
255 liveuser 8890
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
293 liveuser 8891
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",$defaultSocket,"false",self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
255 liveuser 8892
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8893
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
8894
		#參考資料來源:
8895
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8896
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8897
		unset($conf["variableCheck::checkArguments"]);
8898
 
8899
		#如果檢查失敗
8900
		if($checkArguments["status"]==="false"){
8901
 
8902
			#設置錯誤識別
8903
			$result["status"]="false";
8904
 
8905
			#設置錯誤訊息
8906
			$result["error"]=$checkArguments;
8907
 
8908
			#回傳結果
8909
			return $result;
8910
 
8911
			}#if end
8912
 
8913
		#如果檢查不通過
8914
		if($checkArguments["passed"]==="false"){
8915
 
8916
			#設置錯誤識別
8917
			$result["status"]="false";
8918
 
8919
			#設置錯誤訊息
8920
			$result["error"]=$checkArguments;
8921
 
8922
			#回傳結果
8923
			return $result;
8924
 
8925
			}#if end
8926
 
8927
		#取得key
8928
		$share["key"]=$conf["key"];
8929
 
8930
		#取得apiDomain
8931
		$share["apiDomain"]=$conf["apiDomain"];
8932
 
281 liveuser 8933
		#設置debug flag
8934
		$share["debug"]=$conf["debug"];
8935
 
293 liveuser 8936
		#設置 multiThreads 
8937
		$share["multiThreads"]=$conf["multiThreads"];
8938
 
255 liveuser 8939
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
8940
		$share["certInfo"]=array();
8941
 
8942
		#針對每個 domain
8943
		foreach($conf["cName"] as $index=>$cName ){
8944
 
8945
			#如果沒有對應的certInfo
8946
			if(!isset($conf["certInfo"][$index])){
8947
 
8948
				#設置錯誤識別
8949
				$result["status"]="false";
8950
 
8951
				#設置錯誤訊息
8952
				$result["error"][]="missing certInfo";
8953
 
8954
				#設置錯誤訊息
8955
				$result["error"][]=$checkArguments;
8956
 
8957
				#回傳結果
8958
				return $result;
8959
 
8960
				}#if end
8961
 
291 liveuser 8962
			#檢查 $conf["certInfo"][$index] 是否資訊都有存在
8963
			#函式說明:
8964
			#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
8965
			#回傳結果:
8966
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8967
			#$result["error"],執行不正常結束的錯訊息陣列.
8968
			#$result["simpleError"],簡單表示的錯誤訊息.
8969
			#$result["function"],當前執行的函式名稱.
8970
			#$result["argu"],設置給予的參數.
8971
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8972
			#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8973
			#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8974
			#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8975
			#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8976
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8977
			#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8978
			#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8979
			#必填參數:
8980
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8981
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["certInfo"][$index];
8982
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8983
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8984
			#可省略參數:
8985
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8986
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
8987
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
8988
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
8989
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8990
			#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8991
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8992
			#$conf["canNotBeEmpty"]=array();
8993
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8994
			#$conf["canBeEmpty"]=array();
8995
			#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8996
			$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("true","true","true","true");
8997
			#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8998
			$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
8999
			#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
9000
			$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
9001
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9002
			$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($conf["cName"][$index]."-certificate.crt",$conf["cName"][$index]."-private.key",$conf["cName"][$index]."-ca_bundle.crt",$conf["cName"][$index]."-certWithCaPath.crt");
9003
			#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
9004
			#$conf["disallowAllSkipableVarIsEmpty"]="";
9005
			#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
9006
			#$conf["disallowAllSkipableVarIsEmptyArray"]="";
9007
			#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
9008
			#$conf["disallowAllSkipableVarNotExist"]="";
9009
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9010
			#$conf["arrayCountEqualCheck"][]=array();
9011
			#參考資料:
9012
			#array_keys=>http://php.net/manual/en/function.array-keys.php
9013
			#備註:
9014
			#無.
9015
			$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9016
			unset($conf["variableCheck::checkArguments"]);
9017
 
9018
			#如果檢查失敗
9019
			if($checkArguments["status"]==="false"){
9020
 
9021
				#設置錯誤識別
9022
				$result["status"]="false";
9023
 
9024
				#設置錯誤訊息
9025
				$result["error"]=$checkArguments;
9026
 
9027
				#回傳結果
9028
				return $result;
9029
 
9030
				}#if end
9031
 
9032
			#如果檢查不通過
9033
			if($checkArguments["passed"]==="false"){
9034
 
9035
				#設置錯誤識別
9036
				$result["status"]="false";
9037
 
9038
				#設置錯誤訊息
9039
				$result["error"]=$checkArguments;
9040
 
9041
				#回傳結果
9042
				return $result;
9043
 
9044
				}#if end
9045
 
9046
			#儲存 cName
9047
			$cInfo["cName"]=$cName;
255 liveuser 9048
 
291 liveuser 9049
			#儲存 RR 檔案的路徑與名稱
9050
			$cInfo["rrFile"]=$conf["rrFile"][$index];
255 liveuser 9051
 
291 liveuser 9052
			#儲存 cName 對應的 dns server addr
9053
			$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
255 liveuser 9054
 
291 liveuser 9055
			#儲存 cName 的憑證更新後要做的事情.
9056
			$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
255 liveuser 9057
 
291 liveuser 9058
			#設置 certPath
9059
			$cInfo["ssl"]["certPath"]=$conf["certInfo"][$index]["certPath"];
255 liveuser 9060
 
291 liveuser 9061
			#設置 pKey
9062
			$cInfo["ssl"]["pKey"]=$conf["certInfo"][$index]["pKey"];
9063
 
9064
			#設置 caPath
9065
			$cInfo["ssl"]["caPath"]=$conf["certInfo"][$index]["caPath"];
9066
 
9067
			#設置 certWithCaPath
9068
			$cInfo["ssl"]["certWithCaPath"]=$conf["certInfo"][$index]["certWithCaPath"];
9069
 
9070
			#儲存 certInfo
9071
			$share["certInfo"][]=$cInfo;
9072
 
255 liveuser 9073
			}#foreach end
9074
 
9075
		#如果為空
9076
		if(empty($share["certInfo"])){
9077
 
9078
			#設置錯誤識別
9079
			$result["status"]="false";
9080
 
9081
			#設置錯誤訊息
9082
			$result["error"][]="certInfo 參數有缺";
9083
 
9084
			#設置錯誤訊息
9085
			$result["error"][]=$checkArguments;
9086
 
9087
			#回傳結果
9088
			return $result;
9089
 
9090
			}#if end
9091
 
9092
		#函式說明:
9093
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
9094
		#回傳結果:
9095
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
9096
		#$result["error"],錯誤訊息陣列.
9097
		#$result["function"],當前執行的函式名稱.
9098
		#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
9099
		#$result["serverCache"]["serverSide"],server side 的 cache.
9100
		#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
9101
		#$result["serverCache"]["clientSide"],client site 的 cache.
9102
		#必填參數:
9103
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
291 liveuser 9104
		$conf["sock::unixDomainSockServer"]["sock"]=$conf["sock"];
255 liveuser 9105
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9106
		$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
9107
		#可省略參數:
9108
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
9109
		$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
9110
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
9111
		$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
9112
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
9113
		#$conf["sessionTimeout"]="300";
9114
		#$conf["addOnProcessFunc"],字串陣列,增加用於處理 json request 的函式名稱,給予的參數為array("request"=>收到的json訊息,"sock"=>用戶的socket,"clientCache"=>給予所有用戶的cache),若收到的不是json而是"quit"則代表用戶要結束連線;若收到的是$shutdownStr則代表要結束本函式.回傳的內容必須為陣列,例如 $res["continue"]="true"代表要繼續執行下一個addOnProcessFunc;"false"代表代表到此為止. $res["content"]="replaced content";代表要將收到的訊息取代成"replaced content". 最少要有回傳 $res["status"]數值"true"代表執行正常;"false"代表執行不正常.
291 liveuser 9115
		$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("\qbpwcf\zerossl::sslUpdater_cmd");
255 liveuser 9116
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
291 liveuser 9117
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\qbpwcf\zerossl::sslUpdater_idle");
255 liveuser 9118
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
9119
		#$conf["paramsForFuncToRunWhenIdle"]=array();
9120
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
9121
		$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
9122
		#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
9123
		#$conf["shutdownStrAddr"]="";
9124
		#參考資料:
9125
		#http://php.net/manual/en/function.stream-socket-server.php
9126
		#備註:
9127
		#無.
9128
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
9129
		unset($conf["sock::unixDomainSockServer"]);
9130
 
9131
		#執行異常
9132
		if($unixDomainSockServer["status"]==="false"){
9133
 
9134
			#設置錯誤識別
9135
			$result["status"]="false";
9136
 
9137
			#設置錯誤訊息
9138
			$result["error"]=$unixDomainSockServer;
9139
 
9140
			#回傳結果
9141
			return $result;
9142
 
9143
			}#if end
9144
 
9145
		#設置執行正常
9146
		$result["status"]="true";
9147
 
9148
		#回傳結果
9149
		return $result;
9150
 
9151
		}#function sslUpdater end
9152
 
9153
	/*
9154
	#函式說明:
9155
	#funcion sslUpdater 於收到訊息時要做的事情.
9156
	#回傳結果:
9157
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9158
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
9159
	#$result["function"],當前執行的函式名稱.
9160
	#$result["argu"],所使用的參數.
9161
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
9162
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
9163
	#必填參數:
9164
	#$conf["request"],字串,收到的json訊息.
9165
	$conf["request"]="";
9166
	#$conf["sock"],resource,用戶的socket.
9167
	$conf["sock"]="";
9168
	#$conf["clientCache"],陣列,給予所有用戶的cache.
9169
	$conf["clientCache"]=array();
9170
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
9171
	$conf["info"]=array();
9172
	#可省略參數:
9173
	#無.
9174
	#參考資料:
9175
	#無.
9176
	#備註:
9177
	#建構中...
9178
	*/
9179
	public static function sslUpdater_cmd(&$conf){
9180
 
9181
		#debug
9182
		var_dump($conf);
9183
 
9184
		}#function sslUpdater_cmd end
9185
 
9186
	/*
9187
	#函式說明:
9188
	#funcion sslUpdater 於閒置時要做的事情
9189
	#回傳結果:
9190
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9191
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
9192
	#$result["function"],當前執行的函式名稱.
9193
	#$result["argu"],所使用的參數.
9194
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
9195
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
9196
	#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
9197
	#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
9198
	#必填參數:
9199
	#$conf["client"],陣列,所有用戶的資訊.
9200
	$conf["client"]=array();
9201
	#$conf["clientCache"],陣列,給予所有用戶的cache.
9202
	$conf["clientCache"]=array();
9203
	#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
9204
	$conf["serverCache"]=array();
9205
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
9206
	$conf["info"]=array();
9207
	#可省略參數:
9208
	#無.
9209
	#參考資料:
9210
	#無.
9211
	#備註:
291 liveuser 9212
	#無.
255 liveuser 9213
	*/
9214
	public static function sslUpdater_idle(&$conf){
9215
 
9216
		#初始化要回傳的結果
9217
		$result=array();
9218
 
9219
		#設置當其函數名稱
9220
		$result["function"]=__FUNCTION__;
9221
 
9222
		#如果 $conf 不為陣列
9223
		if(gettype($conf)!="array"){
9224
 
9225
			#設置執行失敗
9226
			$result["status"]="false";
9227
 
9228
			#設置執行錯誤訊息
9229
			$result["error"][]="\$conf變數須為陣列形態";
9230
 
9231
			#如果傳入的參數為 null
9232
			if($conf==null){
9233
 
9234
				#設置執行錯誤訊息
9235
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
9236
 
9237
				}#if end
9238
 
9239
			#回傳結果
9240
			return $result;
9241
 
9242
			}#if end
9243
 
9244
		#取得參數
9245
		$result["argu"]=$conf;
9246
 
9247
		#檢查參數
9248
		#函式說明:
9249
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9250
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9251
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9252
		#$result["function"],當前執行的函式名稱.
9253
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9254
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9255
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9256
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
9257
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
9258
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9259
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9260
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9261
		#必填寫的參數:
9262
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9263
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9264
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
291 liveuser 9265
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","serverCache","info");
255 liveuser 9266
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
291 liveuser 9267
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
255 liveuser 9268
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9269
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9270
		#可以省略的參數:
9271
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
9272
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9273
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
9274
		#$conf["skipableVariableCanNotBeEmpty"]=array();
9275
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9276
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
9277
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
9278
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
9279
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9280
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
9281
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9282
		#$conf["arrayCountEqualCheck"][]=array();
9283
		#參考資料來源:
9284
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9285
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9286
		unset($conf["variableCheck::checkArguments"]);
9287
 
9288
		#如果檢查失敗
9289
		if($checkArguments["status"]==="false"){
9290
 
9291
			#設置錯誤識別
9292
			$result["status"]="false";
9293
 
9294
			#設置錯誤訊息
9295
			$result["error"]=$checkArguments;
9296
 
9297
			#回傳結果
9298
			return $result;
9299
 
9300
			}#if end
9301
 
9302
		#如果檢查不通過
9303
		if($checkArguments["passed"]==="false"){
9304
 
9305
			#設置錯誤識別
9306
			$result["status"]="false";
9307
 
9308
			#設置錯誤訊息
9309
			$result["error"]=$checkArguments;
9310
 
9311
			#回傳結果
9312
			return $result;
9313
 
9314
			}#if end
281 liveuser 9315
 
9316
		#預設不開啟 debug flag
9317
		$debug=false;
9318
 
9319
		#如果有設置 debug 為 "true"
291 liveuser 9320
		if($conf["info"]["share"]["debug"]==="true"){
281 liveuser 9321
 
9322
			#設置 debug flag
9323
			$debug=true;
9324
 
9325
			}#if end
9326
 
293 liveuser 9327
		#如果有啟用 multiThreads
9328
		if($conf["info"]["share"]["multiThreads"]==="true"){
9329
 
9330
			#設置 multiThreads flag
9331
			$multiThreads=true;
9332
 
9333
			}#if end
9334
 
261 liveuser 9335
		#另存 server cache 的參考
9336
		$serverCache=&$conf["serverCache"];
9337
 
255 liveuser 9338
		#針對每個 domain name
291 liveuser 9339
		foreach($conf["info"]["share"]["certInfo"] as $certInfoIndex=>$cInfo){
255 liveuser 9340
 
9341
			#取得domain name
9342
			$cName=$cInfo["cName"];
9343
 
261 liveuser 9344
			#如果尚無對應domain name的記錄
9345
			if(!isset($serverCache[$cName])){
9346
 
9347
				#設置最新一次檢測的unixtime
9348
				$serverCache[$cName]["lastCheckUnixTime"]=time();
291 liveuser 9349
 
261 liveuser 9350
				}#if end
9351
 
9352
			#反之距離上次檢查不滿一天
291 liveuser 9353
			else{
261 liveuser 9354
 
291 liveuser 9355
				#計算距離上次檢查多少秒
9356
				$checkedAfter=time()-$serverCache[$cName]["lastCheckUnixTime"];
261 liveuser 9357
 
291 liveuser 9358
				#若距離上次檢查不滿一天
9359
				if($checkedAfter<86400){
9360
 
9361
					#if enable debug
9362
					if($debug){
9363
 
9364
						#debug msg
9365
						echo "Domain name(".$cName.") on zerossl require to check in ".(86400-$checkedAfter)." second(s).".PHP_EOL;
9366
 
9367
						}#if end
9368
 
9369
					#跳過該 domain name 的檢查
9370
					continue;
9371
 
9372
					}#if end
9373
 
9374
				}#else end
261 liveuser 9375
 
281 liveuser 9376
			#if enable debug
9377
			if($debug){
9378
 
9379
				#debug msg
291 liveuser 9380
				echo "Checking domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 9381
 
9382
				}#if end
9383
 
291 liveuser 9384
			#certPath
9385
			#$cInfo["ssl"]["certPath"];
9386
 
9387
			#pKey
9388
			#$cInfo["ssl"]["pKey"];
9389
 
9390
			#caPath
9391
			#$cInfo["ssl"]["caPath"]=;
9392
 
9393
			#certWithCaPath
9394
			#$cInfo["ssl"]["certWithCaPath"];
9395
 
255 liveuser 9396
			#嘗試取得 domain name 對應的可用憑證
9397
			#函式說明:
9398
			#取得在zerossl上的CSR清單
9399
			#回傳結果:
9400
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9401
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
9402
			#$result["function"],當前執行的函式名稱.
9403
			#$result["argu"],所使用的參數.
9404
			#$result["curl_verbose_info"],curl執行的詳細資訊.
9405
			#$result["content"],結果json字串.
9406
			#$result["tCount"],總共的資料筆數.
9407
			#$result["count"],該頁的筆數.
9408
			#$result["page"],當前的頁碼.
9409
			#$result["certs"],陣列,certificates清單,key為certificate的id.
9410
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
9411
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
9412
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
9413
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9414
			#必填參數:
9415
			#無
9416
			#可省略參數:
9417
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9418
			$conf["zerossl::getCertList"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9419
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9420
			$conf["zerossl::getCertList"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9421
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9422
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
9423
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
9424
			$conf["zerossl::getCertList"]["cerType"]="single90Days";
9425
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
9426
			$conf["zerossl::getCertList"]["search"]=$cName;
9427
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
9428
			#$conf["limit"]="";
9429
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
9430
			#$conf["page"]="";
9431
			#參考資料:
9432
			#https://zerossl.com/documentation/api/list-certificates/
9433
			#備註:
9434
			#無.
9435
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
9436
			unset($conf["zerossl::getCertList"]);
9437
 
9438
			#符合條件的數量
9439
			#$getCertList["tCount"];
9440
 
9441
			#符合條件的當頁數量
9442
			#$getCertList["count"];
9443
 
9444
			#如果執行異常
9445
			if($getCertList["status"]==="false"){
9446
 
9447
				#設置錯誤識別
9448
				$result["status"]="false";
9449
 
9450
				#設置錯誤訊息
9451
				$result["error"]=$getCertList;
9452
 
9453
				#回傳結果
9454
				return $result;
9455
 
9456
				}#if end
291 liveuser 9457
 
255 liveuser 9458
			#如果沒有憑證
291 liveuser 9459
			if($getCertList["count"]===0){
255 liveuser 9460
 
281 liveuser 9461
				#if enable debug
9462
				if($debug){
9463
 
9464
					#debug msg
291 liveuser 9465
					echo "There is not valid ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 9466
 
9467
					}#if end
9468
 
9469
				#if enable debug
9470
				if($debug){
9471
 
9472
					#debug msg
291 liveuser 9473
					echo "Checking ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9474
 
9475
					}#if end
9476
 
255 liveuser 9477
				#確認有無對應 cName 的 private key
9478
				#函式說明:
9479
				#檢查多個檔案與資料夾是否存在.
9480
				#回傳的結果:
9481
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9482
				#$result["error"],錯誤訊息陣列.
9483
				#$resutl["function"],當前執行的涵式名稱.
9484
				#$result["argu"],使用的參數.
9485
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9486
				#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9487
				#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
9488
				#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
9489
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9490
				#必填參數:
9491
				#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
292 liveuser 9492
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 9493
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9494
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
9495
				#可省略參數:
9496
				#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9497
				#$conf["disableWebSearch"]="false";
9498
				#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9499
				$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
9500
				#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
9501
				$conf["fileAccess::checkMultiFileExist"]["web"]="false";
9502
				#參考資料:
9503
				#http://php.net/manual/en/function.file-exists.php
9504
				#http://php.net/manual/en/control-structures.foreach.php
9505
				#備註:
9506
				#函數file_exists檢查的路徑為檔案系統的路徑
9507
				#$result["varName"][$i]結果未實作
9508
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9509
				unset($conf["fileAccess::checkMultiFileExist"]);
9510
 
9511
				#如果運行異常
9512
				if($checkMultiFileExist["status"]==="false"){
9513
 
9514
					#設置錯誤識別
9515
					$result["status"]="false";
9516
 
9517
					#設置錯誤訊息
9518
					$result["error"]=$getCertList;
9519
 
9520
					#回傳結果
9521
					return $result;
9522
 
9523
					}#if end
9524
 
9525
				#如果沒有 private key
9526
				if($checkMultiFileExist["allExist"]==="false"){
9527
 
281 liveuser 9528
					#if enable debug
9529
					if($debug){
9530
 
9531
						#debug msg
291 liveuser 9532
						echo "there is no ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9533
 
9534
						}#if end
9535
 
9536
					#if enable debug
9537
					if($debug){
9538
 
9539
						#debug msg
291 liveuser 9540
						echo "creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9541
 
9542
						}#if end
9543
 
255 liveuser 9544
					#建立 private key
9545
					#函式說明:
9546
					#產生ssl private key.
9547
					#回傳結果:
9548
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9549
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9550
					#$result["function"],當前執行的函式名稱.
9551
					#$result["argu"],所使用的參數.
9552
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9553
					#$result["content"],ssl用的private key.
9554
					#必填參數:
9555
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9556
					$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
9557
					#可省略參數:
9558
					#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
9559
					#$conf["length"]=4096';
9560
					#參考資料:
9561
					#無.
9562
					#備註:
9563
					#key generated by openssl with RSA.
291 liveuser 9564
					$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 9565
					unset($conf["openssl::createPrivateKey"]);
9566
 
9567
					#如果運行異常
9568
					if($createPrivateKey["status"]==="false"){
9569
 
9570
						#設置錯誤識別
9571
						$result["status"]="false";
9572
 
9573
						#設置錯誤訊息
9574
						$result["error"]=$createPrivateKey;
9575
 
9576
						#回傳結果
9577
						return $result;
9578
 
9579
						}#if end
9580
 
9581
					#另存private key的字串
9582
					$pKeyStr=$createPrivateKey["content"];
9583
 
9584
					#建立private key檔案
9585
					#函式說明:
9586
					#將字串寫入到檔案
9587
					#回傳結果:
9588
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9589
					#$result["error"],錯誤訊息陣列.
9590
					#$result["function"],當前執行的函數名稱.
9591
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
9592
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
9593
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
9594
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
9595
					#$result["argu"],使用的參數.
9596
					#必填參數:
9597
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9598
					$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
9599
					#可省略參數:
9600
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
292 liveuser 9601
					$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 9602
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
9603
					$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
9604
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
9605
					#$conf["writeMethod"]="a";
9606
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
9607
					#$conf["checkRepeat"]="";
9608
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
9609
					#$conf["filenameExtensionStartPoint"]="";
9610
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
9611
					#$conf["repeatNameRule"]="";
9612
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
9613
					$conf["zerossl::writeTextIntoFile"]["web"]="false";
9614
					#參考資料:
9615
					#無.
9616
					#備註:
9617
					#無.
291 liveuser 9618
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
255 liveuser 9619
					unset($conf["zerossl::writeTextIntoFile"]);
9620
 
9621
					#如果運行異常
9622
					if($writeTextIntoFile["status"]==="false"){
9623
 
9624
						#設置錯誤識別
9625
						$result["status"]="false";
9626
 
9627
						#設置錯誤訊息
9628
						$result["error"]=$writeTextIntoFile;
9629
 
9630
						#回傳結果
9631
						return $result;
9632
 
9633
						}#if end
9634
 
9635
					}#if end
9636
 
281 liveuser 9637
				#if enable debug
9638
				if($debug){
9639
 
9640
					#debug msg
291 liveuser 9641
					echo "Creating domain name(".$conf["info"]["share"]["apiDomain"].") csr for zerossl...".PHP_EOL;
281 liveuser 9642
 
9643
					}#if end
9644
 
255 liveuser 9645
				#建立準備給zerossl的csr
9646
				#函式說明:
9647
				#產生certificate sign request(CSR).
9648
				#回傳結果:
9649
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9650
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9651
				#$result["function"],當前執行的函式名稱.
9652
				#$result["argu"],所使用的參數.
9653
				#$result["content"],csr內容.
9654
				#$result["curl_verbose_info"],curl執行的詳細資訊.
9655
				#$result["privateKey"], private key 的內容.
9656
				#必填參數:
9657
				#$conf["domain"],字串,csr內容的網域名稱.
9658
				$conf["zerossl::createCSR"]["domain"]=$cName;
9659
				#可省略參數:
9660
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 9661
				$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 9662
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
9663
				#$conf["country"]="";
9664
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
9665
				#$conf["state"]="";
9666
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
9667
				#$conf["org"]="";
9668
				#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
9669
				#$conf["unit"]="";
9670
				#參考資料:
9671
				#無.
9672
				#備註:
9673
				#無.
9674
				$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
9675
				unset($conf["zerossl::createCSR"]);
9676
 
9677
				#如果運行異常
9678
				if($createCSR["status"]==="false"){
9679
 
9680
					#設置錯誤識別
9681
					$result["status"]="false";
9682
 
9683
					#設置錯誤訊息
9684
					$result["error"]=$createCSR;
9685
 
9686
					#回傳結果
9687
					return $result;
9688
 
9689
					}#if end
9690
 
9691
				#取得本地端產生的csr內容
9692
				$csrLocal=$createCSR["content"];
9693
 
281 liveuser 9694
				#if enable debug
9695
				if($debug){
9696
 
9697
					#debug msg
291 liveuser 9698
					echo "Creating certificate for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 9699
 
9700
					}#if end
9701
 
255 liveuser 9702
				#函式說明:
281 liveuser 9703
				#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 9704
				#回傳結果:
9705
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9706
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9707
				#$result["function"],當前執行的函式名稱.
9708
				#$result["argu"],所使用的參數.
9709
				#$result["curl_verbose_info"],curl執行的詳細資訊.
9710
				#$result["id"],用於zerossl api驗證domain的id.
9711
				#$result["content"],字串,得到的json字串回應.
9712
				#$result["cnameKey"],用於dns CNAME驗證鍵名.
9713
				#$result["cnameVal"],用於dms CNAME驗證鍵值.
9714
				#必填參數:
9715
				#$conf["certificate_domains"],字串,要簽署的doamin名稱.
9716
				$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
9717
				#$conf["certificate_csr"],字串,簽署的資訊.
9718
				$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
9719
				#$conf["fileArgu"],字串,變數__FILE__的內容.
9720
				$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
9721
				#可省略參數:
9722
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9723
				$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9724
				#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
9725
				#$conf["path"]=self::getApiInfo()["csrPath"];
9726
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9727
				$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9728
				#參考資料:
9729
				#無.
9730
				#備註:
9731
				#無.
9732
				$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
9733
				unset($conf["zerossl::createCertificate"]);
9734
 
9735
				#如果執行異常
9736
				if($createCertificate["status"]==="false"){
9737
 
9738
					#設置錯誤識別
9739
					$result["status"]="false";
9740
 
9741
					#設置錯誤訊息
9742
					$result["error"]=$createCertificate;
9743
 
9744
					#回傳結果
9745
					return $result;
9746
 
9747
					}#if end
9748
 
9749
				#取得csr在zerossl上的id
9750
				$csrId=$createCertificate["id"];
9751
 
9752
				#取得cname key
9753
				$cNameKey=$createCertificate["cnameKey"];
9754
 
9755
				#取得cname val
9756
				$cNameVal=$createCertificate["cnameVal"];
9757
 
9758
				#初始化要增加的RR記錄
9759
				$rr2add=array();
9760
 
9761
				#設置CNAME的查詢
9762
				$rr2add["query"]=$cNameKey;
9763
 
9764
				#設置CNAME的value
9765
				$rr2add["value"]=$cNameVal;
9766
 
9767
				#設置類型為 CNAME
9768
				$rr2add["type"]="CNAME";
9769
 
9770
				#設置註解
9771
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
9772
 
281 liveuser 9773
				#if enable debug
9774
				if($debug){
9775
 
9776
					#debug msg
291 liveuser 9777
					echo "Adding DNS record to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9778
 
9779
					}#if end
9780
 
255 liveuser 9781
				#函式說明:
9782
				#新增DNS記錄到檔案裡面.
9783
				#回傳結果:
9784
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9785
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
9786
				#$result["function"],當前執行的函式名稱.
9787
				#$result["argu"],所使用的參數.
9788
				#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
9789
				#$result["domain"],字串,RR所屬domain.
9790
				#$result["defaultTTL"],字串,預設的RR更新時間.
9791
				#$result["comment"],字串陣列,逐行的註解.
9792
				#必填參數:
9793
				#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
291 liveuser 9794
				$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 9795
				#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
9796
				$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
9797
				#可省略參數:
9798
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
9799
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
9800
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
9801
				#$conf["debug"]="false";
293 liveuser 9802
 
9803
				#如果有啟用多執行序
9804
				if($conf["info"]["share"]["multiThreads"]==="true"){
9805
 
9806
					#設置要多執行序
9807
					$conf["zerossl::updateDnsRecordFile"]["multiThreads"]="true";
9808
 
9809
					}#if end
9810
 
255 liveuser 9811
				#參考資料:
9812
				#無.
9813
				#備註:
9814
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
9815
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
9816
				#php-pear上的Net_DNS2也可以解析RR.
9817
				$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
9818
				unset($conf["zerossl::updateDnsRecordFile"]);
9819
 
9820
				#如果執行異常
9821
				if($updateDnsRecordFile["status"]==="false"){
9822
 
9823
					#設置錯誤識別
9824
					$result["status"]="false";
9825
 
9826
					#設置錯誤訊息
9827
					$result["error"]=$updateDnsRecordFile;
9828
 
9829
					#回傳結果
9830
					return $result;
9831
 
9832
					}#if end
281 liveuser 9833
 
9834
				#if enable debug
9835
				if($debug){
9836
 
9837
					#debug msg
291 liveuser 9838
					echo "Restart DNS service to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9839
 
9840
					}#if end
9841
 
255 liveuser 9842
				#重新啟動dns伺服器
9843
				#函式說明:
9844
				#呼叫shell執行系統命令,並取得回傳的內容.
9845
				#回傳結果:
9846
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9847
				#$result["error"],錯誤訊息陣列.
9848
				#$result["function"],當前執行的函數名稱.
9849
				#$result["argu"],使用的參數.
9850
				#$result["cmd"],執行的指令內容.
9851
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9852
				#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9853
				#$result["content"],為執行完後的輸出字串.
9854
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9855
				#$result["running"],是否還在執行.
9856
				#$result["pid"],pid.
9857
				#$result["statusCode"],執行結束後的代碼.
9858
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9859
				#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9860
				#必填參數:
9861
				#$conf["command"],字串,要執行的指令.
291 liveuser 9862
				$conf["external::callShell"]["command"]="systemctl";
255 liveuser 9863
				#$conf["fileArgu"],字串,變數__FILE__的內容.
9864
				$conf["external::callShell"]["fileArgu"]=__FILE__;
9865
				#可省略參數:
9866
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9867
				$conf["external::callShell"]["argu"]=array("restart","named");
9868
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9869
				#$conf["arguIsAddr"]=array();
9870
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9871
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9872
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9873
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9874
				#$conf["enablePrintDescription"]="true";
9875
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9876
				#$conf["printDescription"]="";
9877
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9878
				#$conf["escapeshellarg"]="false";
9879
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9880
				#$conf["thereIsShellVar"]=array();
9881
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9882
				#$conf["username"]="";
9883
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9884
				#$conf["password"]="";
9885
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9886
				#$conf["useScript"]="";
9887
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9888
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9889
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9890
				#$conf["inBackGround"]="";
9891
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9892
				#$conf["getErr"]="false";
9893
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9894
				#$conf["doNotRun"]="false";
9895
				#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
9896
				$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
9897
				#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
9898
				#$conf["remoteUser"]="root";
9899
				#參考資料:
9900
				#exec=>http://php.net/manual/en/function.exec.php
9901
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9902
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9903
				#備註:
9904
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9905
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9906
				$callShell=external::callShell($conf["external::callShell"]);
9907
				unset($conf["external::callShell"]);
9908
 
9909
				#如果執行異常
9910
				if($callShell["status"]==="false"){
9911
 
9912
					#設置錯誤識別
9913
					$result["status"]="false";
9914
 
9915
					#設置錯誤訊息
9916
					$result["error"]=$callShell;
9917
 
9918
					#回傳結果
9919
					return $result;
9920
 
9921
					}#if end
281 liveuser 9922
 
9923
				#if enable debug
9924
				if($debug){
9925
 
9926
					#debug msg
291 liveuser 9927
					echo "Request zerossl to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 9928
 
9929
					}#if end
9930
 
292 liveuser 9931
				#無窮迴圈
9932
				while(true){
255 liveuser 9933
 
292 liveuser 9934
					#函式說明:
9935
					#請求驗證已經透過zerossl::createCertificate要求的domain.
9936
					#回傳結果:
9937
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9938
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9939
					#$result["function"],當前執行的函式名稱.
9940
					#$result["argu"],所使用的參數.
9941
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9942
					#$result["content"],結果json字串.
9943
					#必填參數:
9944
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
9945
					$conf["zerossl::verifyDomain"]["id"]=$csrId;
9946
					#可省略參數:
9947
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
9948
					$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
9949
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
9950
					$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
9951
					#參考資料:
9952
					#https://zerossl.com/documentation/api/verify-domains/
9953
					#備註:
9954
					#無.
9955
					$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
9956
					unset($conf["zerossl::verifyDomain"]);
291 liveuser 9957
 
292 liveuser 9958
					#如果執行異常
9959
					if($verifyDomain["status"]==="false"){
9960
 
9961
						#設置錯誤識別
9962
						$result["status"]="false";
291 liveuser 9963
 
292 liveuser 9964
						#設置錯誤訊息
9965
						$result["error"]=$verifyDomain;
291 liveuser 9966
 
292 liveuser 9967
						#回傳結果
9968
						return $result;
291 liveuser 9969
 
9970
						}#if end
9971
 
292 liveuser 9972
					#如果沒有回內容
293 liveuser 9973
					if(!isset($verifyDomain["content"])){
292 liveuser 9974
 
9975
						#設置錯誤識別
9976
						$result["status"]="false";
291 liveuser 9977
 
292 liveuser 9978
						#設置錯誤訊息
9979
						$result["error"]=$verifyDomain;
291 liveuser 9980
 
292 liveuser 9981
						#回傳結果
9982
						return $result;
9983
 
9984
						}#if end
9985
 
9986
					#如果回應不是 json
293 liveuser 9987
					if(!(json_validate($verifyDomain["content"]))){
292 liveuser 9988
 
9989
						#設置錯誤識別
9990
						$result["status"]="false";
291 liveuser 9991
 
292 liveuser 9992
						#設置錯誤訊息
9993
						$result["error"]=$verifyDomain;
291 liveuser 9994
 
292 liveuser 9995
						#回傳結果
9996
						return $result;
9997
 
9998
						}#if end
9999
 
10000
					/*
10001
					範例json:
10002
					{"id":"51cff04454e6a6860abfecc8072db602","type":"1","common_name":"silverblue-guest.qbpwcf.org","additional_domains":"","created":"2026-03-06 13:45:39","expires":"2026-06-04 23:59:59","status":"pending_validation","validation_type":"CNAME_CSR_HASH","validation_emails":"","replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"silverblue-guest.qbpwcf.org":["admin@silverblue-guest.qbpwcf.org","administrator@silverblue-guest.qbpwcf.org","hostmaster@silverblue-guest.qbpwcf.org","postmaster@silverblue-guest.qbpwcf.org","webmaster@silverblue-guest.qbpwcf.org","admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"silverblue-guest.qbpwcf.org":{"file_validation_url_http":"http:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_url_https":"https:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_content":["58B9EB7890F754D041698170B22D22205D710ED09B419A809E5C92C38195DD36","comodoca.com","627e45f007045f0"],"cname_validation_p1":"_383346FA54F492EC8B2A6C421A052827.silverblue-guest.qbpwcf.org","cname_validation_p2":"58B9EB7890F754D041698170B22D2220.5D710ED09B419A809E5C92C38195DD36.627e45f007045f0.comodoca.com"}}},"signature_algorithm_properties":null}
10003
					*/
10004
 
10005
					#解析json回應
293 liveuser 10006
					$verifyDomainRes=json_decode($verifyDomain["content"]);
291 liveuser 10007
 
293 liveuser 10008
					#如果回應含有 success
10009
					if(isset($verifyDomainRes->success)){
292 liveuser 10010
 
293 liveuser 10011
						#如果是 zerossl 驗證失敗
10012
						if($verifyDomainRes->success==="false"){
291 liveuser 10013
 
293 liveuser 10014
							#如果是 CNAME 記錄找不到
10015
							if($verifyDomainRes->error->code===0){
291 liveuser 10016
 
293 liveuser 10017
								#取得錯誤訊息
10018
								#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
10019
 
10020
								#if enable debug
10021
								if($debug){
10022
 
10023
									#debug msg
10024
									echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
10025
 
10026
									}#if end
10027
 
10028
								#if enable debug
10029
								if($debug){
10030
 
10031
									#debug msg
10032
									echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
10033
 
10034
									}#if end
10035
 
10036
								#休息60秒
10037
								sleep(60);
291 liveuser 10038
 
10039
								}#if end
293 liveuser 10040
 
10041
							#反之為不接受的錯誤訊息
10042
							else{
291 liveuser 10043
 
293 liveuser 10044
								#設置錯誤識別
10045
								$result["status"]="false";
10046
 
10047
								#設置錯誤訊息
10048
								$result["error"]=$verifyDomain;
10049
 
10050
								#回傳結果
10051
								return $result;
291 liveuser 10052
 
293 liveuser 10053
								}#else end
291 liveuser 10054
 
10055
							}#if end
292 liveuser 10056
 
10057
						}#if end
293 liveuser 10058
 
10059
					#反之如果回應含有 status
10060
					else if(isset($verifyDomainRes->status)){
292 liveuser 10061
 
293 liveuser 10062
						#如果是 zerossl 尚在驗證中
10063
						if($verifyDomainRes->status==="pending_validation"){
292 liveuser 10064
 
293 liveuser 10065
							#if enable debug
10066
							if($debug){
292 liveuser 10067
 
293 liveuser 10068
								#debug msg
10069
								echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
292 liveuser 10070
 
10071
								}#if end
10072
 
293 liveuser 10073
							#無窮迴圈
10074
							while(true){
10075
 
10076
								#查詢驗證狀況
10077
								#函式說明:
10078
								#取得CSR在zerossl上的狀態
10079
								#回傳結果:
10080
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10081
								#$reuslt["error"],執行不正常結束的錯訊息陣列.
10082
								#$result["function"],當前執行的函式名稱.
10083
								#$result["argu"],所使用的參數.
10084
								#$result["curl_verbose_info"],curl執行的詳細資訊.
10085
								#$result["content"],結果json字串.
10086
								#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
10087
								#必填參數:
10088
								#$conf["id"],字串,zerossl::createCertificate回傳的id.
10089
								$conf["zerossl::getCertSta"]["id"]=$csrId;
10090
								#可省略參數:
10091
								#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
10092
								$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
10093
								#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
10094
								$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
10095
								#參考資料:
10096
								#https://zerossl.com/documentation/api/get-certificate/
10097
								#備註:
10098
								#無.
10099
								$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
10100
								unset($conf["zerossl::getCertSta"]);
10101
 
10102
								#如果執行異常
10103
								if($getCertSta["status"]==="false"){
10104
 
10105
									#設置錯誤識別
10106
									$result["status"]="false";
292 liveuser 10107
 
293 liveuser 10108
									#設置錯誤訊息
10109
									$result["error"]=$getCertSta;
292 liveuser 10110
 
293 liveuser 10111
									#回傳結果
10112
									return $result;
292 liveuser 10113
 
293 liveuser 10114
									}#if end
10115
 
10116
								#如果沒有回應內容
10117
								if(!isset($getCertSta["content"])){
10118
 
10119
									#設置錯誤識別
10120
									$result["status"]="false";
292 liveuser 10121
 
293 liveuser 10122
									#設置錯誤訊息
10123
									$result["error"]=$getCertSta;
292 liveuser 10124
 
293 liveuser 10125
									#回傳結果
10126
									return $result;
292 liveuser 10127
 
293 liveuser 10128
									}#if end
10129
 
10130
								#如果回應不是 json
10131
								if(!(json_validate($getCertSta["content"]))){
292 liveuser 10132
 
293 liveuser 10133
									#設置錯誤識別
10134
									$result["status"]="false";
10135
 
10136
									#設置錯誤訊息
10137
									$result["error"]=$getCertSta;
10138
 
10139
									#回傳結果
10140
									return $result;
292 liveuser 10141
 
10142
									}#if end
293 liveuser 10143
 
10144
								#解析json回應
10145
								$getCertStaRes=json_decode($getCertSta["content"]);
292 liveuser 10146
 
293 liveuser 10147
								#如果憑證已經驗證通過了
10148
								if($getCertStaRes->status==="issued"){
292 liveuser 10149
 
293 liveuser 10150
									#if enable debug
10151
									if($debug){
10152
 
10153
										#debug msg
10154
										echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
10155
 
10156
										}#if end
292 liveuser 10157
 
293 liveuser 10158
									#結束等待
10159
									break 2;
10160
 
292 liveuser 10161
									}#if end
10162
 
293 liveuser 10163
								#如果 zerossl 尚在處理中
10164
								else if($getCertStaRes->status==="pending_validation"){
292 liveuser 10165
 
293 liveuser 10166
									#if enable debug
10167
									if($debug){
10168
 
10169
										#debug msg
10170
										echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
10171
 
10172
										}#if end
10173
 
10174
									#休息1分鐘
10175
									sleep(60);
10176
 
10177
									}#if end
10178
 
10179
								#反之
10180
								else{
10181
 
10182
									#例外狀況
10183
 
10184
									#設置錯誤識別
10185
									$result["status"]="false";
292 liveuser 10186
 
293 liveuser 10187
									#設置錯誤訊息
10188
									$result["error"]=$getCertSta;
292 liveuser 10189
 
293 liveuser 10190
									#回傳結果
10191
									return $result;
10192
 
10193
									}#else end
292 liveuser 10194
 
293 liveuser 10195
								}#while end
10196
 
10197
							}#if end
10198
 
292 liveuser 10199
						}#if end
291 liveuser 10200
 
292 liveuser 10201
					}#while end
291 liveuser 10202
 
281 liveuser 10203
				#if enable debug
10204
				if($debug){
10205
 
10206
					#debug msg
291 liveuser 10207
					echo "Downloading certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10208
 
10209
					}#if end
10210
 
255 liveuser 10211
				#函式說明:
10212
				#下載certificate.
10213
				#回傳結果:
10214
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10215
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
10216
				#$result["function"],當前執行的函式名稱.
10217
				#$result["argu"],所使用的參數.
10218
				#$result["curl_verbose_info"],curl執行的詳細資訊.
10219
				#$result["content"],結果json字串.
10220
				#$result["certificate.crt"],字串,certificate.crt的內容.
10221
				#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
10222
				#必填參數:
10223
				#無.
10224
				#可省略參數:
10225
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 10226
				$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 10227
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 10228
				$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 10229
				#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
10230
				$conf["zerossl::getCert"]["id"]=$csrId;
10231
				#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
10232
				#$conf["zerossl::getCert"]["cname"]="";
10233
				#參考資料:
10234
				#https://zerossl.com/documentation/api/download-certificate-inline/
10235
				#備註:
10236
				#無.
10237
				$getCert=zerossl::getCert($conf["zerossl::getCert"]);
10238
				unset($conf["zerossl::getCert"]);
10239
 
10240
				#如果執行異常
10241
				if($getCert["status"]==="false"){
10242
 
10243
					#設置錯誤識別
10244
					$result["status"]="false";
10245
 
10246
					#設置錯誤訊息
10247
					$result["error"]=$getCert;
10248
 
10249
					#回傳結果
10250
					return $result;
10251
 
10252
					}#if end
281 liveuser 10253
 
10254
				#if enable debug
10255
				if($debug){
10256
 
10257
					#debug msg
291 liveuser 10258
					echo "Creating certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10259
 
10260
					}#if end
10261
 
293 liveuser 10262
				#certPath
10263
				#$cInfo["ssl"]["certPath"];
255 liveuser 10264
 
293 liveuser 10265
				#pKey
10266
				#$cInfo["ssl"]["pKey"];
255 liveuser 10267
 
293 liveuser 10268
				#caPath
10269
				#$cInfo["ssl"]["caPath"]=;
255 liveuser 10270
 
293 liveuser 10271
				#certWithCaPath
10272
				#$cInfo["ssl"]["certWithCaPath"];
10273
 
255 liveuser 10274
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
10275
				#函式說明:
10276
				#一次建立多個檔案,並寫入內容.
10277
				#回傳結果:
10278
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10279
				#$result["error"],錯誤訊息陣列.
10280
				#$result["function"],當前執行的函數名稱.
10281
				#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10282
				#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10283
				#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10284
				#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10285
				#$result["argu"],使用的參數.
10286
				#必填參數:
10287
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10288
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10289
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
293 liveuser 10290
				$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 10291
				#可省略參數:
10292
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10293
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
10294
				#參考資料:
10295
				#無.
10296
				#備註:
10297
				#無.
293 liveuser 10298
				$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10299
				unset($conf["zerossl::writeMultiFile"]);
10300
 
10301
				#如果執行異常
10302
				if($writeMultiFile["status"]==="false"){
10303
 
10304
					#設置錯誤識別
10305
					$result["status"]="false";
10306
 
10307
					#設置錯誤訊息
10308
					$result["error"]=$writeMultiFile;
10309
 
10310
					#回傳結果
10311
					return $result;
10312
 
10313
					}#if end
10314
 
10315
				#儲存 actionAfterUpdateCert
10316
				$action=$cInfo["actionAfterUpdateCert"];
10317
 
10318
				#如果有多個指令要執行
10319
				if(gettype($action[0])==="array"){
10320
 
281 liveuser 10321
					#if enable debug
10322
					if($debug){
10323
 
10324
						#debug msg
291 liveuser 10325
						echo "There are many cmds to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10326
 
10327
						}#if end
10328
 
10329
					#if enable debug
10330
					if($debug){
10331
 
10332
						#debug msg
291 liveuser 10333
						echo "Running cmd to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10334
 
10335
						}#if end
10336
 
255 liveuser 10337
					#針對每的指令
10338
					foreach($action as $ac){
10339
 
281 liveuser 10340
						#if enable debug
10341
						if($debug){
10342
 
10343
							#debug msg
10344
							echo ".".PHP_EOL;
10345
 
10346
							}#if end
10347
 
255 liveuser 10348
						#函式說明:
10349
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
10350
						#回傳結果:
10351
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10352
						#$result["error"],錯誤訊息陣列.
10353
						#$result["function"],當前執行的函數名稱.
10354
						#$result["argu"],使用的參數.
10355
						#$result["cmd"],執行的指令名稱.
10356
						#$result["params"],執行指令伴隨的參數.
10357
						#必填參數:
10358
						#$conf["cmdArray"],字串陣列,要執行的指令字串.
10359
						$conf["external::callShellHelper"]["cmdArray"]=$ac;
10360
						#可省略參數:
10361
						#無.
10362
						#參考資料:
10363
						#array_shift=>https://www.php.net/manual/en/function.array-shift.php
10364
						#備註:
10365
						#無.
10366
						$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
10367
						unset($conf["external::callShellHelper"]);
10368
 
10369
						#如果執行異常
10370
						if($callShellHelper["status"]==="false"){
10371
 
10372
							#設置錯誤識別
10373
							$result["status"]="false";
10374
 
10375
							#設置錯誤訊息
10376
							$result["error"]=$callShellHelper;
10377
 
10378
							#回傳結果
10379
							return $result;
10380
 
10381
							}#if end
10382
 
10383
						#函式說明:
10384
						#呼叫shell執行系統命令,並取得回傳的內容.
10385
						#回傳結果:
10386
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10387
						#$result["error"],錯誤訊息陣列.
10388
						#$result["function"],當前執行的函數名稱.
10389
						#$result["argu"],使用的參數.
10390
						#$result["cmd"],執行的指令內容.
10391
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10392
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10393
						#$result["content"],為執行完後的輸出字串.
10394
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10395
						#$result["running"],是否還在執行.
10396
						#$result["pid"],pid.
10397
						#$result["statusCode"],執行結束後的代碼.
10398
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10399
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10400
						#必填參數:
10401
						#$conf["command"],字串,要執行的指令.
10402
						$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
10403
						#$conf["fileArgu"],字串,變數__FILE__的內容.
10404
						$conf["external::callShell"]["fileArgu"]=__FILE__;
10405
						#可省略參數:
10406
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
10407
						$conf["external::callShell"]["argu"]=$callShellHelper["params"];
10408
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10409
						#$conf["arguIsAddr"]=array();
10410
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10411
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10412
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10413
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10414
						#$conf["enablePrintDescription"]="true";
10415
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10416
						#$conf["printDescription"]="";
10417
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10418
						$conf["external::callShell"]["escapeshellarg"]="true";
10419
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10420
						#$conf["thereIsShellVar"]=array();
10421
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10422
						#$conf["username"]="";
10423
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10424
						#$conf["password"]="";
10425
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10426
						#$conf["useScript"]="";
10427
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10428
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10429
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10430
						#$conf["inBackGround"]="";
10431
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10432
						#$conf["getErr"]="false";
10433
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10434
						#$conf["doNotRun"]="false";
10435
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10436
						#$conf["remoteIp"]="";
10437
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10438
						#$conf["remoteUser"]="";
10439
						#參考資料:
10440
						#exec=>http://php.net/manual/en/function.exec.php
10441
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10442
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10443
						#備註:
10444
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10445
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10446
						$callShell=external::callShell($conf["external::callShell"]);
10447
						unset($conf["external::callShell"]);
10448
 
10449
						#如果執行異常
10450
						if($callShellHelper["status"]==="false"){
10451
 
10452
							#設置錯誤識別
10453
							$result["status"]="false";
10454
 
10455
							#設置錯誤訊息
10456
							$result["error"]=$callShell;
10457
 
10458
							#回傳結果
10459
							return $result;
10460
 
10461
							}#if end
10462
 
10463
						}#foreach end
10464
 
10465
					}#if end
10466
 
10467
				#反之
10468
				else{
10469
 
281 liveuser 10470
					#if enable debug
10471
					if($debug){
10472
 
10473
						#debug msg
291 liveuser 10474
						echo "There is only one cmd to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 10475
 
10476
						}#if end
10477
 
10478
					#if enable debug
10479
					if($debug){
10480
 
10481
						#debug msg
10482
						echo ".".PHP_EOL;
10483
 
10484
						}#if end
10485
 
255 liveuser 10486
					#函式說明:
293 liveuser 10487
					#將字串進行解析,變成多個參數.
10488
					#回傳結果:
10489
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
10490
					#$result["function"],當前執行的函式內容.
10491
					#$result["error"],錯誤訊息陣列.
10492
					#$result["content"],參數陣列.
10493
					#$result["count"],總共有幾個參數.
10494
					#必填參數:
10495
					#$conf["input"],字串,要解析成參數的字串.
10496
					$conf["stringProcess::parse"]["input"]=$action;
10497
					#可省略參數:
10498
					#無.
10499
					#參考資料:
10500
					#無.
10501
					#備註:
10502
					#無.
10503
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
10504
					unset($conf["stringProcess::parse"]);
10505
 
10506
					#如果執行異常
10507
					if($parse["status"]==="false"){
10508
 
10509
						#設置錯誤識別
10510
						$result["status"]="false";
10511
 
10512
						#設置錯誤訊息
10513
						$result["error"]=$parse;
10514
 
10515
						#回傳結果
10516
						return $result;
10517
 
10518
						}#if end
10519
 
10520
					#函式說明:
255 liveuser 10521
					#解析指令與參數,回傳指令與參數給 callShell 函式使用.
10522
					#回傳結果:
10523
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10524
					#$result["error"],錯誤訊息陣列.
10525
					#$result["function"],當前執行的函數名稱.
10526
					#$result["argu"],使用的參數.
10527
					#$result["cmd"],執行的指令名稱.
10528
					#$result["params"],執行指令伴隨的參數.
10529
					#必填參數:
10530
					#$conf["cmdArray"],字串陣列,要執行的指令字串.
293 liveuser 10531
					$conf["external::callShellHelper"]["cmdArray"]=$parse["content"];
255 liveuser 10532
					#可省略參數:
10533
					#無.
10534
					#參考資料:
10535
					#array_shift=>https://www.php.net/manual/en/function.array-shift.php
10536
					#備註:
10537
					#無.
10538
					$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
10539
					unset($conf["external::callShellHelper"]);
10540
 
10541
					#如果執行異常
10542
					if($callShellHelper["status"]==="false"){
10543
 
10544
						#設置錯誤識別
10545
						$result["status"]="false";
10546
 
10547
						#設置錯誤訊息
10548
						$result["error"]=$callShellHelper;
10549
 
10550
						#回傳結果
10551
						return $result;
10552
 
10553
						}#if end
10554
 
10555
					#函式說明:
10556
					#呼叫shell執行系統命令,並取得回傳的內容.
10557
					#回傳結果:
10558
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10559
					#$result["error"],錯誤訊息陣列.
10560
					#$result["function"],當前執行的函數名稱.
10561
					#$result["argu"],使用的參數.
10562
					#$result["cmd"],執行的指令內容.
10563
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10564
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10565
					#$result["content"],為執行完後的輸出字串.
10566
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10567
					#$result["running"],是否還在執行.
10568
					#$result["pid"],pid.
10569
					#$result["statusCode"],執行結束後的代碼.
10570
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10571
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10572
					#必填參數:
10573
					#$conf["command"],字串,要執行的指令.
10574
					$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
10575
					#$conf["fileArgu"],字串,變數__FILE__的內容.
10576
					$conf["external::callShell"]["fileArgu"]=__FILE__;
10577
					#可省略參數:
10578
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
10579
					$conf["external::callShell"]["argu"]=$callShellHelper["params"];
10580
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10581
					#$conf["arguIsAddr"]=array();
10582
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10583
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10584
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10585
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10586
					#$conf["enablePrintDescription"]="true";
10587
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10588
					#$conf["printDescription"]="";
10589
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10590
					$conf["external::callShell"]["escapeshellarg"]="true";
10591
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10592
					#$conf["thereIsShellVar"]=array();
10593
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10594
					#$conf["username"]="";
10595
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10596
					#$conf["password"]="";
10597
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10598
					#$conf["useScript"]="";
10599
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10600
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10601
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10602
					#$conf["inBackGround"]="";
10603
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10604
					#$conf["getErr"]="false";
10605
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10606
					#$conf["doNotRun"]="false";
10607
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10608
					#$conf["remoteIp"]="";
10609
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10610
					#$conf["remoteUser"]="";
10611
					#參考資料:
10612
					#exec=>http://php.net/manual/en/function.exec.php
10613
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10614
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10615
					#備註:
10616
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10617
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10618
					$callShell=external::callShell($conf["external::callShell"]);
10619
					unset($conf["external::callShell"]);
10620
 
10621
					#如果執行異常
10622
					if($callShellHelper["status"]==="false"){
10623
 
10624
						#設置錯誤識別
10625
						$result["status"]="false";
10626
 
10627
						#設置錯誤訊息
10628
						$result["error"]=$callShell;
10629
 
10630
						#回傳結果
10631
						return $result;
10632
 
10633
						}#if end
10634
 
10635
					}#else end
10636
 
10637
				}#if end
10638
 
10639
			#反之
10640
			else{
10641
 
281 liveuser 10642
				#if enable debug
10643
				if($debug){
10644
 
10645
					#debug msg
291 liveuser 10646
					echo "There is already valid ssl for domain name(".$cName.") on zerossl".PHP_EOL;
281 liveuser 10647
 
10648
					}#if end
10649
 
291 liveuser 10650
				#debug
10651
				#var_dump(__LINE__,$getCertList);
10652
 
255 liveuser 10653
				#有 issued 的憑證
10654
 
291 liveuser 10655
				#if enable debug
10656
				if($debug){
10657
 
10658
					#debug msg
10659
					echo "Downloading ssl for domain name(".$cName.") on zerossl".PHP_EOL;
10660
 
10661
					}#if end
10662
 
255 liveuser 10663
				#取得 certificate id at zerossl
10664
				#函式說明:
10665
				#將陣列轉換成存有key與value的陣列
10666
				#回傳的結果:
10667
				#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
10668
				#$result["function"],當前執行的函數
10669
				#$result["error"],錯誤訊息.
10670
				#$result[$i]["key"],原先$i+1個元素的key.
10671
				#$result[$i]["value"],原先$i+1個元素的value.
10672
				#必填參數:
10673
				#$conf["rawInputArray"],陣列,要轉換的陣列變數.
10674
				$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
10675
				#可省略參數:
10676
				#無.
10677
				#參考資料:
10678
				#無.
10679
				#備註:
10680
				#無.
10681
				$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
10682
				unset($conf["arrays::getKeyAndValue"]);
10683
 
10684
				#如果執行異常
10685
				if($getKeyAndValue["status"]==="false"){
10686
 
10687
					#設置錯誤識別
10688
					$result["status"]="false";
10689
 
10690
					#設置錯誤訊息
10691
					$result["error"]=$getKeyAndValue;
10692
 
10693
					#回傳結果
10694
					return $result;
10695
 
10696
					}#if end
10697
 
291 liveuser 10698
				#debug
10699
				#var_dump($getKeyAndValue);exit;
10700
 
255 liveuser 10701
				#儲存 certificate id at zerossl
291 liveuser 10702
				$csrId=$getKeyAndValue[1]["key"];
255 liveuser 10703
 
10704
				#檢查憑證是否已經快過期
10705
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
10706
 
10707
				#如果距離當下不到2個星期就要過期
10708
				if($expiresIn<=86400*14){
291 liveuser 10709
 
281 liveuser 10710
					#if enable debug
10711
					if($debug){
10712
 
10713
						#debug msg
291 liveuser 10714
						echo "Valid ssl for domain name(".$cName.") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
281 liveuser 10715
 
10716
						}#if end
10717
 
291 liveuser 10718
					#debug
10719
					#var_dump($expiresIn);exit;
10720
 
255 liveuser 10721
					#另存舊的憑證id,最後要revoke之.
10722
					$oldCsrId=$csrId;
10723
 
281 liveuser 10724
					#if enable debug
10725
					if($debug){
10726
 
10727
						#debug msg
291 liveuser 10728
						echo "Start requst new ssl process for domain name(".$cName.").".PHP_EOL;
281 liveuser 10729
 
10730
						}#if end
10731
 
10732
					#if enable debug
10733
					if($debug){
10734
 
10735
						#debug msg
291 liveuser 10736
						echo "Finding ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10737
 
10738
						}#if end
10739
 
255 liveuser 10740
					#確認有無對應 cName 的 private key
10741
					#函式說明:
10742
					#檢查多個檔案與資料夾是否存在.
10743
					#回傳的結果:
10744
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
10745
					#$result["error"],錯誤訊息陣列.
10746
					#$resutl["function"],當前執行的涵式名稱.
10747
					#$result["argu"],使用的參數.
10748
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
10749
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
10750
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
10751
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
10752
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
10753
					#必填參數:
10754
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
291 liveuser 10755
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 10756
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10757
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
10758
					#可省略參數:
10759
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
10760
					#$conf["disableWebSearch"]="false";
10761
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
10762
					$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
10763
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
10764
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
10765
					#參考資料:
10766
					#http://php.net/manual/en/function.file-exists.php
10767
					#http://php.net/manual/en/control-structures.foreach.php
10768
					#備註:
10769
					#函數file_exists檢查的路徑為檔案系統的路徑
10770
					#$result["varName"][$i]結果未實作
10771
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
10772
					unset($conf["fileAccess::checkMultiFileExist"]);
10773
 
10774
					#如果運行異常
10775
					if($checkMultiFileExist["status"]==="false"){
10776
 
10777
						#設置錯誤識別
10778
						$result["status"]="false";
10779
 
10780
						#設置錯誤訊息
10781
						$result["error"]=$getCertList;
10782
 
10783
						#回傳結果
10784
						return $result;
10785
 
10786
						}#if end
10787
 
10788
					#如果沒有 private key
10789
					if($checkMultiFileExist["allExist"]==="false"){
10790
 
281 liveuser 10791
						#if enable debug
10792
						if($debug){
10793
 
10794
							#debug msg
291 liveuser 10795
							echo "Thers is no ssl private key for domain name(".$cName.").".PHP_EOL;
281 liveuser 10796
 
10797
							}#if end
10798
 
10799
						#if enable debug
10800
						if($debug){
10801
 
10802
							#debug msg
291 liveuser 10803
							echo "Creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10804
 
10805
							}#if end
10806
 
255 liveuser 10807
						#建立 private key
10808
						#函式說明:
10809
						#產生ssl private key.
10810
						#回傳結果:
10811
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10812
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
10813
						#$result["function"],當前執行的函式名稱.
10814
						#$result["argu"],所使用的參數.
10815
						#$result["curl_verbose_info"],curl執行的詳細資訊.
10816
						#$result["content"],ssl用的private key.
10817
						#必填參數:
10818
						#$conf["fileArgu"],字串,變數__FILE__的內容.
10819
						$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
10820
						#可省略參數:
10821
						#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
10822
						#$conf["length"]=4096';
10823
						#參考資料:
10824
						#無.
10825
						#備註:
10826
						#key generated by openssl with RSA.
291 liveuser 10827
						$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 10828
						unset($conf["openssl::createPrivateKey"]);
10829
 
10830
						#如果運行異常
10831
						if($createPrivateKey["status"]==="false"){
10832
 
10833
							#設置錯誤識別
10834
							$result["status"]="false";
10835
 
10836
							#設置錯誤訊息
10837
							$result["error"]=$createPrivateKey;
10838
 
10839
							#回傳結果
10840
							return $result;
10841
 
10842
							}#if end
10843
 
10844
						#另存private key的字串
10845
						$pKeyStr=$createPrivateKey["content"];
10846
 
281 liveuser 10847
						#if enable debug
10848
						if($debug){
10849
 
10850
							#debug msg
291 liveuser 10851
							echo "Writing ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10852
 
10853
							}#if end
10854
 
255 liveuser 10855
						#建立private key檔案
10856
						#函式說明:
10857
						#將字串寫入到檔案
10858
						#回傳結果:
10859
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10860
						#$result["error"],錯誤訊息陣列.
10861
						#$result["function"],當前執行的函數名稱.
10862
						#$result["fileInfo"],實際上寫入的檔案資訊陣列.
10863
						#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
10864
						#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
10865
						#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
10866
						#$result["argu"],使用的參數.
10867
						#必填參數:
10868
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10869
						$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
10870
						#可省略參數:
10871
						#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
291 liveuser 10872
						$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 10873
						#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
10874
						$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
10875
						#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
10876
						#$conf["writeMethod"]="a";
10877
						#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
10878
						#$conf["checkRepeat"]="";
10879
						#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
10880
						#$conf["filenameExtensionStartPoint"]="";
10881
						#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
10882
						#$conf["repeatNameRule"]="";
10883
						#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
10884
						$conf["zerossl::writeTextIntoFile"]["web"]="false";
10885
						#參考資料:
10886
						#無.
10887
						#備註:
10888
						#無.
10889
						$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
10890
						unset($conf["zerossl::writeTextIntoFile"]);
10891
 
10892
						#如果運行異常
10893
						if($writeTextIntoFile["status"]==="false"){
10894
 
10895
							#設置錯誤識別
10896
							$result["status"]="false";
10897
 
10898
							#設置錯誤訊息
10899
							$result["error"]=$writeTextIntoFile;
10900
 
10901
							#回傳結果
10902
							return $result;
10903
 
10904
							}#if end
10905
 
10906
						}#if end
10907
 
281 liveuser 10908
					#if enable debug
10909
					if($debug){
10910
 
10911
						#debug msg
291 liveuser 10912
						echo "Creating CSR for domain name(".$cName.") to zerossl.".PHP_EOL;
281 liveuser 10913
 
10914
						}#if end
10915
 
255 liveuser 10916
					#建立準備給zerossl的csr
10917
					#函式說明:
10918
					#產生certificate sign request(CSR).
10919
					#回傳結果:
10920
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10921
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10922
					#$result["function"],當前執行的函式名稱.
10923
					#$result["argu"],所使用的參數.
10924
					#$result["content"],csr內容.
10925
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10926
					#$result["privateKey"], private key 的內容.
10927
					#必填參數:
10928
					#$conf["domain"],字串,csr內容的網域名稱.
10929
					$conf["zerossl::createCSR"]["domain"]=$cName;
10930
					#可省略參數:
10931
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 10932
					$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 10933
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
10934
					#$conf["country"]="";
10935
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
10936
					#$conf["state"]="";
10937
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
10938
					#$conf["org"]="";
10939
					#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
10940
					#$conf["unit"]="";
10941
					#參考資料:
10942
					#無.
10943
					#備註:
10944
					#無.
10945
					$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
10946
					unset($conf["zerossl::createCSR"]);
10947
 
10948
					#如果運行異常
10949
					if($createCSR["status"]==="false"){
10950
 
10951
						#設置錯誤識別
10952
						$result["status"]="false";
10953
 
10954
						#設置錯誤訊息
10955
						$result["error"]=$createCSR;
10956
 
10957
						#回傳結果
10958
						return $result;
10959
 
10960
						}#if end
10961
 
10962
					#取得本地端產生的csr內容
10963
					$csrLocal=$createCSR["content"];
10964
 
281 liveuser 10965
					#if enable debug
10966
					if($debug){
10967
 
10968
						#debug msg
291 liveuser 10969
						echo "Providing CSR for domain name(".$cName.") to zerossl".PHP_EOL;
281 liveuser 10970
 
10971
						}#if end
10972
 
255 liveuser 10973
					#函式說明:
281 liveuser 10974
					#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 10975
					#回傳結果:
10976
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10977
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10978
					#$result["function"],當前執行的函式名稱.
10979
					#$result["argu"],所使用的參數.
10980
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10981
					#$result["id"],用於zerossl api驗證domain的id.
10982
					#$result["content"],字串,得到的json字串回應.
10983
					#$result["cnameKey"],用於dns CNAME驗證鍵名.
10984
					#$result["cnameVal"],用於dms CNAME驗證鍵值.
10985
					#必填參數:
10986
					#$conf["certificate_domains"],字串,要簽署的doamin名稱.
10987
					$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
10988
					#$conf["certificate_csr"],字串,簽署的資訊.
10989
					$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
10990
					#$conf["fileArgu"],字串,變數__FILE__的內容.
10991
					$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
10992
					#可省略參數:
10993
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 10994
					$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 10995
					#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
10996
					#$conf["path"]=self::getApiInfo()["csrPath"];
10997
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 10998
					$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 10999
					#參考資料:
11000
					#無.
11001
					#備註:
11002
					#無.
11003
					$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
11004
					unset($conf["zerossl::createCertificate"]);
11005
 
11006
					#如果執行異常
11007
					if($createCertificate["status"]==="false"){
11008
 
11009
						#設置錯誤識別
11010
						$result["status"]="false";
11011
 
11012
						#設置錯誤訊息
11013
						$result["error"]=$createCertificate;
11014
 
11015
						#回傳結果
11016
						return $result;
11017
 
11018
						}#if end
11019
 
11020
					#取得csr在zerossl上的id
11021
					$csrId=$createCertificate["id"];
11022
 
11023
					#取得cname key
11024
					$cNameKey=$createCertificate["cnameKey"];
11025
 
11026
					#取得cname val
11027
					$cNameVal=$createCertificate["cnameVal"];
11028
 
11029
					#初始化要增加的RR記錄
11030
					$rr2add=array();
11031
 
11032
					#設置CNAME的查詢
11033
					$rr2add["query"]=$cNameKey;
11034
 
11035
					#設置CNAME的value
11036
					$rr2add["value"]=$cNameVal;
11037
 
11038
					#設置類型為 CNAME
11039
					$rr2add["type"]="CNAME";
11040
 
11041
					#設置註解
11042
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
11043
 
281 liveuser 11044
					#if enable debug
11045
					if($debug){
11046
 
11047
						#debug msg
291 liveuser 11048
						echo "Adding DNS record to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 11049
 
11050
						}#if end
11051
 
255 liveuser 11052
					#函式說明:
11053
					#新增DNS記錄到檔案裡面.
11054
					#回傳結果:
11055
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11056
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11057
					#$result["function"],當前執行的函式名稱.
11058
					#$result["argu"],所使用的參數.
11059
					#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
11060
					#$result["domain"],字串,RR所屬domain.
11061
					#$result["defaultTTL"],字串,預設的RR更新時間.
11062
					#$result["comment"],字串陣列,逐行的註解.
11063
					#必填參數:
11064
					#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
11065
					$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2ad);
11066
					#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
11067
					$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
11068
					#可省略參數:
11069
					#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
11070
					$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
11071
					#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
11072
					#$conf["debug"]="false";
11073
					#參考資料:
11074
					#無.
11075
					#備註:
11076
					#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
11077
					#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
11078
					#php-pear上的Net_DNS2也可以解析RR.
11079
					$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
11080
					unset($conf["zerossl::updateDnsRecordFile"]);
11081
 
11082
					#如果執行異常
11083
					if($updateDnsRecordFile["status"]==="false"){
11084
 
11085
						#設置錯誤識別
11086
						$result["status"]="false";
11087
 
11088
						#設置錯誤訊息
11089
						$result["error"]=$updateDnsRecordFile;
11090
 
11091
						#回傳結果
11092
						return $result;
11093
 
11094
						}#if end
281 liveuser 11095
 
11096
					#if enable debug
11097
					if($debug){
11098
 
11099
						#debug msg
291 liveuser 11100
						echo "Restarting DNS service to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 11101
 
11102
						}#if end
11103
 
255 liveuser 11104
					#重新啟動dns伺服器
11105
					#函式說明:
11106
					#呼叫shell執行系統命令,並取得回傳的內容.
11107
					#回傳結果:
11108
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11109
					#$result["error"],錯誤訊息陣列.
11110
					#$result["function"],當前執行的函數名稱.
11111
					#$result["argu"],使用的參數.
11112
					#$result["cmd"],執行的指令內容.
11113
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11114
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11115
					#$result["content"],為執行完後的輸出字串.
11116
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11117
					#$result["running"],是否還在執行.
11118
					#$result["pid"],pid.
11119
					#$result["statusCode"],執行結束後的代碼.
11120
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11121
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11122
					#必填參數:
11123
					#$conf["command"],字串,要執行的指令.
291 liveuser 11124
					$conf["external::callShell"]["command"]="systemctl";
255 liveuser 11125
					#$conf["fileArgu"],字串,變數__FILE__的內容.
11126
					$conf["external::callShell"]["fileArgu"]=__FILE__;
11127
					#可省略參數:
11128
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11129
					$conf["external::callShell"]["argu"]=array("restart","named");
11130
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11131
					#$conf["arguIsAddr"]=array();
11132
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11133
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11134
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11135
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11136
					#$conf["enablePrintDescription"]="true";
11137
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11138
					#$conf["printDescription"]="";
11139
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11140
					#$conf["escapeshellarg"]="false";
11141
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11142
					#$conf["thereIsShellVar"]=array();
11143
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11144
					#$conf["username"]="";
11145
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11146
					#$conf["password"]="";
11147
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11148
					#$conf["useScript"]="";
11149
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11150
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11151
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11152
					#$conf["inBackGround"]="";
11153
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11154
					#$conf["getErr"]="false";
11155
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11156
					#$conf["doNotRun"]="false";
11157
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
11158
					$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
11159
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
11160
					#$conf["remoteUser"]="root";
11161
					#參考資料:
11162
					#exec=>http://php.net/manual/en/function.exec.php
11163
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11164
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11165
					#備註:
11166
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11167
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11168
					$callShell=external::callShell($conf["external::callShell"]);
11169
					unset($conf["external::callShell"]);
11170
 
11171
					#如果執行異常
11172
					if($callShell["status"]==="false"){
11173
 
11174
						#設置錯誤識別
11175
						$result["status"]="false";
11176
 
11177
						#設置錯誤訊息
11178
						$result["error"]=$callShell;
11179
 
11180
						#回傳結果
11181
						return $result;
11182
 
11183
						}#if end
281 liveuser 11184
 
11185
					#if enable debug
11186
					if($debug){
11187
 
11188
						#debug msg
291 liveuser 11189
						echo "Request zerossl to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 11190
 
11191
						}#if end
11192
 
255 liveuser 11193
					#函式說明:
11194
					#請求驗證已經透過zerossl::createCertificate要求的domain.
11195
					#回傳結果:
11196
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11197
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11198
					#$result["function"],當前執行的函式名稱.
11199
					#$result["argu"],所使用的參數.
11200
					#$result["curl_verbose_info"],curl執行的詳細資訊.
11201
					#$result["content"],結果json字串.
11202
					#必填參數:
11203
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
11204
					$conf["zerossl::verifyDomain"]["id"]=$csrId;
11205
					#可省略參數:
11206
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 11207
					$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 11208
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 11209
					$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 11210
					#參考資料:
11211
					#https://zerossl.com/documentation/api/verify-domains/
11212
					#備註:
11213
					#無.
11214
					$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
11215
					unset($conf["zerossl::verifyDomain"]);
11216
 
11217
					#如果執行異常
11218
					if($verifyDomain["status"]==="false"){
11219
 
11220
						#設置錯誤識別
11221
						$result["status"]="false";
11222
 
11223
						#設置錯誤訊息
11224
						$result["error"]=$verifyDomain;
11225
 
11226
						#回傳結果
11227
						return $result;
11228
 
11229
						}#if end
281 liveuser 11230
 
11231
					#if enable debug
11232
					if($debug){
11233
 
11234
						#debug msg
291 liveuser 11235
						echo "Downling ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 11236
 
11237
						}#if end
11238
 
255 liveuser 11239
					#函式說明:
11240
					#下載certificate.
11241
					#回傳結果:
11242
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11243
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11244
					#$result["function"],當前執行的函式名稱.
11245
					#$result["argu"],所使用的參數.
11246
					#$result["curl_verbose_info"],curl執行的詳細資訊.
11247
					#$result["content"],結果json字串.
11248
					#$result["certificate.crt"],字串,certificate.crt的內容.
11249
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
11250
					#必填參數:
11251
					#無.
11252
					#可省略參數:
11253
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 11254
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 11255
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 11256
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 11257
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
11258
					$conf["zerossl::getCert"]["id"]=$csrId;
11259
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
11260
					#$conf["zerossl::getCert"]["cname"]="";
11261
					#參考資料:
11262
					#https://zerossl.com/documentation/api/download-certificate-inline/
11263
					#備註:
11264
					#無.
11265
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
11266
					unset($conf["zerossl::getCert"]);
11267
 
11268
					#如果執行異常
11269
					if($getCert["status"]==="false"){
11270
 
11271
						#設置錯誤識別
11272
						$result["status"]="false";
11273
 
11274
						#設置錯誤訊息
11275
						$result["error"]=$getCert;
11276
 
11277
						#回傳結果
11278
						return $result;
11279
 
11280
						}#if end
281 liveuser 11281
 
11282
					#if enable debug
11283
					if($debug){
11284
 
11285
						#debug msg
291 liveuser 11286
						echo "Creating ssl for domain name(".$cName.").".PHP_EOL;
281 liveuser 11287
 
11288
						}#if end
11289
 
255 liveuser 11290
					#建立 certificate.crt 檔案
11291
					#$cInfo["certPath"];
11292
 
11293
					#建立 ca_bundle.crt 檔案
11294
					#$cInfo["caPath"];
11295
 
11296
					#建立 certAndCa.crt 檔案
11297
					#$cInfo["certWithCaPath"];
11298
 
11299
					#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
11300
					#函式說明:
11301
					#一次建立多個檔案,並寫入內容.
11302
					#回傳結果:
11303
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
11304
					#$result["error"],錯誤訊息陣列.
11305
					#$result["function"],當前執行的函數名稱.
11306
					#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
11307
					#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
11308
					#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
11309
					#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
11310
					#$result["argu"],使用的參數.
11311
					#必填參數:
11312
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11313
					$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
11314
					#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 11315
					$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 11316
					#可省略參數:
11317
					#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
11318
					$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
11319
					#參考資料:
11320
					#無.
11321
					#備註:
11322
					#無.
11323
					$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
11324
					unset($conf["zerossl::writeMultiFile"]);
11325
 
11326
					#如果執行異常
11327
					if($writeMultiFile["status"]==="false"){
11328
 
11329
						#設置錯誤識別
11330
						$result["status"]="false";
11331
 
11332
						#設置錯誤訊息
11333
						$result["error"]=$writeMultiFile;
11334
 
11335
						#回傳結果
11336
						return $result;
11337
 
11338
						}#if end
11339
 
11340
					#儲存 actionAfterUpdateCert
11341
					$action=$cInfo["actionAfterUpdateCert"];
11342
 
11343
					#如果有多個指令要執行
11344
					if(gettype($action[0])==="array"){
11345
 
281 liveuser 11346
						#if enable debug
11347
						if($debug){
11348
 
11349
							#debug msg
291 liveuser 11350
							echo "There many cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 11351
 
11352
							}#if end
11353
 
255 liveuser 11354
						#針對每的指令
11355
						foreach($action as $ac){
11356
 
281 liveuser 11357
							#if enable debug
11358
							if($debug){
11359
 
11360
								#debug msg
11361
								echo ".".PHP_EOL;
11362
 
11363
								}#if end
11364
 
255 liveuser 11365
							#函式說明:
11366
							#解析指令與參數,回傳指令與參數給 callShell 函式使用.
11367
							#回傳結果:
11368
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11369
							#$result["error"],錯誤訊息陣列.
11370
							#$result["function"],當前執行的函數名稱.
11371
							#$result["argu"],使用的參數.
11372
							#$result["cmd"],執行的指令名稱.
11373
							#$result["params"],執行指令伴隨的參數.
11374
							#必填參數:
11375
							#$conf["cmdArray"],字串陣列,要執行的指令字串.
11376
							$conf["external::callShellHelper"]["cmdArray"]=$ac;
11377
							#可省略參數:
11378
							#無.
11379
							#參考資料:
11380
							#array_shift=>https://www.php.net/manual/en/function.array-shift.php
11381
							#備註:
11382
							#無.
11383
							$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
11384
							unset($conf["external::callShellHelper"]);
11385
 
11386
							#如果執行異常
11387
							if($callShellHelper["status"]==="false"){
11388
 
11389
								#設置錯誤識別
11390
								$result["status"]="false";
11391
 
11392
								#設置錯誤訊息
11393
								$result["error"]=$callShellHelper;
11394
 
11395
								#回傳結果
11396
								return $result;
11397
 
11398
								}#if end
11399
 
11400
							#函式說明:
11401
							#呼叫shell執行系統命令,並取得回傳的內容.
11402
							#回傳結果:
11403
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11404
							#$result["error"],錯誤訊息陣列.
11405
							#$result["function"],當前執行的函數名稱.
11406
							#$result["argu"],使用的參數.
11407
							#$result["cmd"],執行的指令內容.
11408
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11409
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11410
							#$result["content"],為執行完後的輸出字串.
11411
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11412
							#$result["running"],是否還在執行.
11413
							#$result["pid"],pid.
11414
							#$result["statusCode"],執行結束後的代碼.
11415
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11416
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11417
							#必填參數:
11418
							#$conf["command"],字串,要執行的指令.
11419
							$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
11420
							#$conf["fileArgu"],字串,變數__FILE__的內容.
11421
							$conf["external::callShell"]["fileArgu"]=__FILE__;
11422
							#可省略參數:
11423
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11424
							$conf["external::callShell"]["argu"]=$callShellHelper["params"];
11425
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11426
							#$conf["arguIsAddr"]=array();
11427
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11428
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11429
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11430
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11431
							#$conf["enablePrintDescription"]="true";
11432
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11433
							#$conf["printDescription"]="";
11434
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11435
							$conf["external::callShell"]["escapeshellarg"]="true";
11436
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11437
							#$conf["thereIsShellVar"]=array();
11438
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11439
							#$conf["username"]="";
11440
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11441
							#$conf["password"]="";
11442
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11443
							#$conf["useScript"]="";
11444
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11445
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11446
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11447
							#$conf["inBackGround"]="";
11448
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11449
							#$conf["getErr"]="false";
11450
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11451
							#$conf["doNotRun"]="false";
11452
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
11453
							#$conf["remoteIp"]="";
11454
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
11455
							#$conf["remoteUser"]="";
11456
							#參考資料:
11457
							#exec=>http://php.net/manual/en/function.exec.php
11458
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11459
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11460
							#備註:
11461
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11462
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11463
							$callShell=external::callShell($conf["external::callShell"]);
11464
							unset($conf["external::callShell"]);
11465
 
11466
							#如果執行異常
11467
							if($callShellHelper["status"]==="false"){
11468
 
11469
								#設置錯誤識別
11470
								$result["status"]="false";
11471
 
11472
								#設置錯誤訊息
11473
								$result["error"]=$callShell;
11474
 
11475
								#回傳結果
11476
								return $result;
11477
 
11478
								}#if end
11479
 
11480
							}#foreach end
11481
 
11482
						}#if end
11483
 
11484
					#反之
11485
					else{
11486
 
281 liveuser 11487
						#if enable debug
11488
						if($debug){
11489
 
11490
							#debug msg
291 liveuser 11491
							echo "There is only one cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 11492
 
11493
							}#if end
11494
 
11495
						#if enable debug
11496
						if($debug){
11497
 
11498
							#debug msg
11499
							echo ".".PHP_EOL;
11500
 
11501
							}#if end
11502
 
255 liveuser 11503
						#函式說明:
11504
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
11505
						#回傳結果:
11506
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11507
						#$result["error"],錯誤訊息陣列.
11508
						#$result["function"],當前執行的函數名稱.
11509
						#$result["argu"],使用的參數.
11510
						#$result["cmd"],執行的指令名稱.
11511
						#$result["params"],執行指令伴隨的參數.
11512
						#必填參數:
11513
						#$conf["cmdArray"],字串陣列,要執行的指令字串.
11514
						$conf["external::callShellHelper"]["cmdArray"]=$action;
11515
						#可省略參數:
11516
						#無.
11517
						#參考資料:
11518
						#array_shift=>https://www.php.net/manual/en/function.array-shift.php
11519
						#備註:
11520
						#無.
11521
						$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
11522
						unset($conf["external::callShellHelper"]);
11523
 
11524
						#如果執行異常
11525
						if($callShellHelper["status"]==="false"){
11526
 
11527
							#設置錯誤識別
11528
							$result["status"]="false";
11529
 
11530
							#設置錯誤訊息
11531
							$result["error"]=$callShellHelper;
11532
 
11533
							#回傳結果
11534
							return $result;
11535
 
11536
							}#if end
11537
 
11538
						#函式說明:
11539
						#呼叫shell執行系統命令,並取得回傳的內容.
11540
						#回傳結果:
11541
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11542
						#$result["error"],錯誤訊息陣列.
11543
						#$result["function"],當前執行的函數名稱.
11544
						#$result["argu"],使用的參數.
11545
						#$result["cmd"],執行的指令內容.
11546
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11547
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11548
						#$result["content"],為執行完後的輸出字串.
11549
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11550
						#$result["running"],是否還在執行.
11551
						#$result["pid"],pid.
11552
						#$result["statusCode"],執行結束後的代碼.
11553
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11554
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11555
						#必填參數:
11556
						#$conf["command"],字串,要執行的指令.
11557
						$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
11558
						#$conf["fileArgu"],字串,變數__FILE__的內容.
11559
						$conf["external::callShell"]["fileArgu"]=__FILE__;
11560
						#可省略參數:
11561
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11562
						$conf["external::callShell"]["argu"]=$callShellHelper["params"];
11563
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11564
						#$conf["arguIsAddr"]=array();
11565
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11566
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11567
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11568
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11569
						#$conf["enablePrintDescription"]="true";
11570
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11571
						#$conf["printDescription"]="";
11572
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11573
						$conf["external::callShell"]["escapeshellarg"]="true";
11574
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11575
						#$conf["thereIsShellVar"]=array();
11576
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11577
						#$conf["username"]="";
11578
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11579
						#$conf["password"]="";
11580
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11581
						#$conf["useScript"]="";
11582
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11583
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11584
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11585
						#$conf["inBackGround"]="";
11586
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11587
						#$conf["getErr"]="false";
11588
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11589
						#$conf["doNotRun"]="false";
11590
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
11591
						#$conf["remoteIp"]="";
11592
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
11593
						#$conf["remoteUser"]="";
11594
						#參考資料:
11595
						#exec=>http://php.net/manual/en/function.exec.php
11596
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11597
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11598
						#備註:
11599
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11600
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11601
						$callShell=external::callShell($conf["external::callShell"]);
11602
						unset($conf["external::callShell"]);
11603
 
11604
						#如果執行異常
11605
						if($callShellHelper["status"]==="false"){
11606
 
11607
							#設置錯誤識別
11608
							$result["status"]="false";
11609
 
11610
							#設置錯誤訊息
11611
							$result["error"]=$callShell;
11612
 
11613
							#回傳結果
11614
							return $result;
11615
 
11616
							}#if end
11617
 
11618
						}#else end
11619
 
11620
					#要移除舊的憑證 
11621
 
281 liveuser 11622
					#if enable debug
11623
					if($debug){
11624
 
11625
						#debug msg
11626
						echo "Removing old ssl file".PHP_EOL;
11627
 
11628
						}#if end
11629
 
255 liveuser 11630
					#舊憑證於zerossl上的id
11631
					#$oldCsrId
11632
 
11633
					#移除舊的憑證
11634
					#函式說明:
11635
					#請求廢除 issued zerossl certificate.
11636
					#回傳結果:
11637
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11638
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11639
					#$result["function"],當前執行的函式名稱.
11640
					#$result["argu"],所使用的參數.
11641
					#$result["curl_verbose_info"],curl執行的詳細資訊.
11642
					#$result["content"],結果json字串.
11643
					#必填參數:
11644
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
11645
					$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
11646
					#可省略參數:
11647
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 11648
					$conf["zerosssl::revokeCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 11649
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 11650
					$conf["zerosssl::revokeCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 11651
					#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
11652
					$conf["zerosssl::revokeCert"]["reason"]="Superseded";
11653
					#參考資料:
11654
					#https://zerossl.com/documentation/api/revoke-certificate/
11655
					#備註:
11656
					#無.
11657
					$revokeCert=zerosssl::revokeCert($conf["zerosssl::revokeCert"]);
11658
					unset($conf["zerosssl::revokeCert"]);
11659
 
11660
					#如果執行異常
11661
					if($revokeCert["status"]==="false"){
11662
 
11663
						#設置錯誤識別
11664
						$result["status"]="false";
11665
 
11666
						#設置錯誤訊息
11667
						$result["error"]=$revokeCert;
11668
 
11669
						#回傳結果
11670
						return $result;
11671
 
291 liveuser 11672
						}#if end
11673
 
255 liveuser 11674
					}#if end
11675
 
11676
				#反之,尚不需要提前申請新的憑證
11677
				else{
11678
 
291 liveuser 11679
					#debug
11680
					#var_dump(__LINE__,"尚不需要提前申請新的憑證");exit;
11681
 
281 liveuser 11682
					#if enable debug
11683
					if($debug){
11684
 
11685
						#debug msg
291 liveuser 11686
						echo "ssl for domain name(".$cName.") is valid ".PHP_EOL;
281 liveuser 11687
 
11688
						}#if end
11689
 
11690
					#if enable debug
11691
					if($debug){
11692
 
11693
						#debug msg
291 liveuser 11694
						echo "Downling ssl for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 11695
 
11696
						}#if end
11697
 
255 liveuser 11698
					#下載憑證
11699
					#函式說明:
11700
					#下載certificate.
11701
					#回傳結果:
11702
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11703
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
11704
					#$result["function"],當前執行的函式名稱.
11705
					#$result["argu"],所使用的參數.
11706
					#$result["curl_verbose_info"],curl執行的詳細資訊.
11707
					#$result["content"],結果json字串.
11708
					#$result["certificate.crt"],字串,certificate.crt的內容.
11709
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
11710
					#必填參數:
11711
					#無.
11712
					#可省略參數:
11713
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 11714
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 11715
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 11716
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 11717
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
11718
					$conf["zerossl::getCert"]["id"]=$csrId;
11719
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
11720
					#$conf["zerossl::getCert"]["cname"]="";
11721
					#參考資料:
11722
					#https://zerossl.com/documentation/api/download-certificate-inline/
11723
					#備註:
11724
					#無.
11725
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
11726
					unset($conf["zerossl::getCert"]);
11727
 
11728
					#如果執行異常
11729
					if($getCert["status"]==="false"){
11730
 
11731
						#設置錯誤識別
11732
						$result["status"]="false";
11733
 
11734
						#設置錯誤訊息
11735
						$result["error"]=$getCert;
11736
 
11737
						#回傳結果
11738
						return $result;
11739
 
11740
						}#if end
281 liveuser 11741
 
11742
					#if enable debug
11743
					if($debug){
11744
 
11745
						#debug msg
291 liveuser 11746
						echo "Getting host ssl for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11747
 
11748
						}#if end
11749
 
255 liveuser 11750
					#zerossl上的certificate.crt內容
11751
					#$getCert["certificate.crt"];
11752
 
11753
					#zerossl上的ca_bundle.crt內容
11754
					#$getCert["ca_bundle.crt"];
11755
 
11756
					#certificate.crt and ca_bundle.crt 合併後的檔案內容
11757
					#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
11758
 
11759
					#certificate.crt 檔案
11760
					#$cInfo["certPath"];
11761
 
11762
					#ca_bundle.crt 檔案
11763
					#$cInfo["caPath"];
11764
 
11765
					#certAndCa.crt 檔案
11766
					#$cInfo["certWithCaPath"];
281 liveuser 11767
 
11768
					#if enable debug
11769
					if($debug){
11770
 
11771
						#debug msg
291 liveuser 11772
						echo "Getting host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11773
 
11774
						}#if end
255 liveuser 11775
 
11776
					#取得既有的 certificate.crt 檔案內容
11777
					#函式說明:
11778
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
11779
					#回傳的變數說明:
11780
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
11781
					#$result["error"],錯誤訊息提示.
11782
					#$result["warning"],警告訊息.
11783
					#$result["function"],當前執行的函數名稱.
11784
					#$result["fileContent"],爲檔案的內容陣列.
11785
					#$result["lineCount"],爲檔案內容總共的行數.
11786
					#$result["fullContent"],為檔案的完整內容.
11787
					#$result["base64dataOnly"],檔案的base64data.
11788
					#$result["base64data"],為在網頁上給予src參數的數值.
11789
					#$result["mimeType"],為檔案的mime type.
11790
					#必填參數:
11791
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 11792
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certPath"];
255 liveuser 11793
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11794
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
11795
					#可省略參數:
11796
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
11797
					#$conf["web"]="true";
11798
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 11799
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 11800
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
11801
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
11802
					#參考資料:
11803
					#file(),取得檔案內容的行數.
11804
					#file=>http:#php.net/manual/en/function.file.php
11805
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
11806
					#filesize=>http://php.net/manual/en/function.filesize.php
11807
					#參考資料:
11808
					#無.
11809
					#備註:
11810
					#無.
291 liveuser 11811
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 11812
					unset($conf["fileAccesss::getFileContent"]);
11813
 
11814
					#如果執行異常
11815
					if($getFileContent["status"]==="false"){
11816
 
11817
						#設置錯誤識別
11818
						$result["status"]="false";
11819
 
11820
						#設置錯誤訊息
11821
						$result["error"]=$getFileContent;
11822
 
11823
						#回傳結果
11824
						return $result;
11825
 
11826
						}#if end
11827
 
281 liveuser 11828
					#if enable debug
11829
					if($debug){
11830
 
11831
						#debug msg
291 liveuser 11832
						echo "Checking host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11833
 
11834
						}#if end
11835
 
291 liveuser 11836
					#預設 certificate.crt 不用更新
11837
					$certificate_need_update="false";
11838
 
255 liveuser 11839
					#如果既有憑證跟剛下載的憑證不一樣
11840
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
11841
 
11842
						#識別要改成下載好的憑證
11843
						$certificate_need_update="true";
281 liveuser 11844
 
11845
						#if enable debug
11846
						if($debug){
11847
 
11848
							#debug msg
291 liveuser 11849
							echo "SSL(certificate.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 11850
 
11851
							}#if end
255 liveuser 11852
 
11853
						}#if end
281 liveuser 11854
 
11855
					#if enable debug
11856
					if($debug){
11857
 
11858
						#debug msg
291 liveuser 11859
						echo "Getting host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11860
 
11861
						}#if end
11862
 
255 liveuser 11863
					#取得既有的 ca_bundle.crt 檔案內容
11864
					#函式說明:
11865
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
11866
					#回傳的變數說明:
11867
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
11868
					#$result["error"],錯誤訊息提示.
11869
					#$result["warning"],警告訊息.
11870
					#$result["function"],當前執行的函數名稱.
11871
					#$result["fileContent"],爲檔案的內容陣列.
11872
					#$result["lineCount"],爲檔案內容總共的行數.
11873
					#$result["fullContent"],為檔案的完整內容.
11874
					#$result["base64dataOnly"],檔案的base64data.
11875
					#$result["base64data"],為在網頁上給予src參數的數值.
11876
					#$result["mimeType"],為檔案的mime type.
11877
					#必填參數:
11878
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 11879
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["caPath"];
255 liveuser 11880
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11881
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
11882
					#可省略參數:
11883
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
11884
					#$conf["web"]="true";
11885
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 11886
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 11887
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
11888
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
11889
					#參考資料:
11890
					#file(),取得檔案內容的行數.
11891
					#file=>http:#php.net/manual/en/function.file.php
11892
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
11893
					#filesize=>http://php.net/manual/en/function.filesize.php
11894
					#參考資料:
11895
					#無.
11896
					#備註:
11897
					#無.
291 liveuser 11898
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 11899
					unset($conf["fileAccesss::getFileContent"]);
11900
 
11901
					#如果執行異常
11902
					if($getFileContent["status"]==="false"){
11903
 
11904
						#設置錯誤識別
11905
						$result["status"]="false";
11906
 
11907
						#設置錯誤訊息
11908
						$result["error"]=$getFileContent;
11909
 
11910
						#回傳結果
11911
						return $result;
11912
 
11913
						}#if end
11914
 
281 liveuser 11915
					#if enable debug
11916
					if($debug){
11917
 
11918
						#debug msg
291 liveuser 11919
						echo "Checking host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11920
 
11921
						}#if end
11922
 
291 liveuser 11923
					#預設 ca_bundle.crt 不用更新
11924
					$ca_bundle_need_update="false";
11925
 
255 liveuser 11926
					#如果既有憑證跟剛下載的憑證不一樣
11927
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
11928
 
11929
						#識別要改成下載好的憑證
11930
						$ca_bundle_need_update="true";
281 liveuser 11931
 
11932
						#if enable debug
11933
						if($debug){
11934
 
11935
							#debug msg
291 liveuser 11936
							echo "SSL(ca_bundle.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 11937
 
11938
							}#if end
255 liveuser 11939
 
11940
						}#if end
11941
 
281 liveuser 11942
					#if enable debug
11943
					if($debug){
11944
 
11945
						#debug msg
291 liveuser 11946
						echo "Getting host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 11947
 
11948
						}#if end
11949
 
255 liveuser 11950
					#取得既有的 certWithCa 檔案內容
11951
					#函式說明:
11952
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
11953
					#回傳的變數說明:
11954
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
11955
					#$result["error"],錯誤訊息提示.
11956
					#$result["warning"],警告訊息.
11957
					#$result["function"],當前執行的函數名稱.
11958
					#$result["fileContent"],爲檔案的內容陣列.
11959
					#$result["lineCount"],爲檔案內容總共的行數.
11960
					#$result["fullContent"],為檔案的完整內容.
11961
					#$result["base64dataOnly"],檔案的base64data.
11962
					#$result["base64data"],為在網頁上給予src參數的數值.
11963
					#$result["mimeType"],為檔案的mime type.
11964
					#必填參數:
11965
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 11966
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certWithCaPath"];
255 liveuser 11967
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11968
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
11969
					#可省略參數:
11970
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
11971
					#$conf["web"]="true";
11972
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 11973
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 11974
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
11975
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
11976
					#參考資料:
11977
					#file(),取得檔案內容的行數.
11978
					#file=>http:#php.net/manual/en/function.file.php
11979
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
11980
					#filesize=>http://php.net/manual/en/function.filesize.php
11981
					#參考資料:
11982
					#無.
11983
					#備註:
11984
					#無.
291 liveuser 11985
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 11986
					unset($conf["fileAccesss::getFileContent"]);
11987
 
11988
					#如果執行異常
11989
					if($getFileContent["status"]==="false"){
11990
 
11991
						#設置錯誤識別
11992
						$result["status"]="false";
11993
 
11994
						#設置錯誤訊息
11995
						$result["error"]=$getFileContent;
11996
 
11997
						#回傳結果
11998
						return $result;
11999
 
12000
						}#if end
12001
 
281 liveuser 12002
					#if enable debug
12003
					if($debug){
12004
 
12005
						#debug msg
291 liveuser 12006
						echo "Checking host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12007
 
12008
						}#if end
12009
 
291 liveuser 12010
					#預設 cert_and_ca_bundle.crt 不用更新
12011
					$cert_and_ca_bundle_need_update="false";
12012
 
255 liveuser 12013
					#如果既有憑證跟剛下載的憑證不一樣
12014
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
12015
 
12016
						#識別要改成下載好的憑證
12017
						$cert_and_ca_bundle_need_update="true";
281 liveuser 12018
 
12019
						#if enable debug
12020
						if($debug){
12021
 
12022
							#debug msg
291 liveuser 12023
							echo "SSL(cert and ca_bundle) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 12024
 
12025
							}#if end
255 liveuser 12026
 
12027
						}#if end
12028
 
12029
					#預設不需要執行更新憑證後的動作
12030
					$requireActionAfterUpdateCert="false";
12031
 
12032
					#如果 certificate 需要更新
12033
					if($certificate_need_update==="true"){
12034
 
281 liveuser 12035
						#if enable debug
12036
						if($debug){
12037
 
12038
							#debug msg
291 liveuser 12039
							echo "Updating host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12040
 
12041
							}#if end
12042
 
255 liveuser 12043
						#更新之
12044
						#函式說明:
12045
						#一次建立多個檔案,並寫入內容.
12046
						#回傳結果:
12047
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
12048
						#$result["error"],錯誤訊息陣列.
12049
						#$result["function"],當前執行的函數名稱.
12050
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
12051
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
12052
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
12053
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
12054
						#$result["argu"],使用的參數.
12055
						#必填參數:
12056
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12057
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
12058
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 12059
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"]);
255 liveuser 12060
						#可省略參數:
12061
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
12062
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
12063
						#參考資料:
12064
						#無.
12065
						#備註:
12066
						#無.
291 liveuser 12067
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 12068
						unset($conf["zerossl::writeMultiFile"]);
12069
 
12070
						#如果執行異常
12071
						if($writeMultiFile["status"]==="false"){
12072
 
12073
							#設置錯誤識別
12074
							$result["status"]="false";
12075
 
12076
							#設置錯誤訊息
12077
							$result["error"]=$writeMultiFile;
12078
 
12079
							#回傳結果
12080
							return $result;
12081
 
12082
							}#if end
293 liveuser 12083
 
12084
						#設置需要執行指令來生效憑證
12085
						$requireActionAfterUpdateCert="true";
255 liveuser 12086
 
12087
						}#if end
12088
 
12089
					#如果 ca_bunle 需要更新
12090
					if($ca_bundle_need_update==="true"){
12091
 
281 liveuser 12092
						#if enable debug
12093
						if($debug){
12094
 
12095
							#debug msg
291 liveuser 12096
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12097
 
12098
							}#if end
293 liveuser 12099
 
12100
						#設置需要執行指令來生效憑證
12101
						$requireActionAfterUpdateCert="true";
281 liveuser 12102
 
255 liveuser 12103
						#更新之
12104
						#函式說明:
12105
						#一次建立多個檔案,並寫入內容.
12106
						#回傳結果:
12107
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
12108
						#$result["error"],錯誤訊息陣列.
12109
						#$result["function"],當前執行的函數名稱.
12110
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
12111
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
12112
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
12113
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
12114
						#$result["argu"],使用的參數.
12115
						#必填參數:
12116
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12117
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
12118
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 12119
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["caPath"]);
255 liveuser 12120
						#可省略參數:
12121
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
12122
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
12123
						#參考資料:
12124
						#無.
12125
						#備註:
12126
						#無.
291 liveuser 12127
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 12128
						unset($conf["zerossl::writeMultiFile"]);
12129
 
12130
						#如果執行異常
12131
						if($writeMultiFile["status"]==="false"){
12132
 
12133
							#設置錯誤識別
12134
							$result["status"]="false";
12135
 
12136
							#設置錯誤訊息
12137
							$result["error"]=$writeMultiFile;
12138
 
12139
							#回傳結果
12140
							return $result;
12141
 
12142
							}#if end
293 liveuser 12143
 
12144
						#設置需要執行指令來生效憑證
12145
						$requireActionAfterUpdateCert="true";
255 liveuser 12146
 
12147
						}#if end
12148
 
12149
					#如果 certificate and ca_bundle 需要更新
12150
					if($cert_and_ca_bundle_need_update==="true"){
12151
 
281 liveuser 12152
						#if enable debug
12153
						if($debug){
12154
 
12155
							#debug msg
291 liveuser 12156
							echo "Updating host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 12157
 
12158
							}#if end
12159
 
255 liveuser 12160
						#更新之
12161
						#函式說明:
12162
						#一次建立多個檔案,並寫入內容.
12163
						#回傳結果:
12164
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
12165
						#$result["error"],錯誤訊息陣列.
12166
						#$result["function"],當前執行的函數名稱.
12167
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
12168
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
12169
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
12170
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
12171
						#$result["argu"],使用的參數.
12172
						#必填參數:
12173
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12174
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
12175
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 12176
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certWithCaPath"]);
255 liveuser 12177
						#可省略參數:
12178
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
12179
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
12180
						#參考資料:
12181
						#無.
12182
						#備註:
12183
						#無.
291 liveuser 12184
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 12185
						unset($conf["zerossl::writeMultiFile"]);
12186
 
12187
						#如果執行異常
12188
						if($writeMultiFile["status"]==="false"){
12189
 
12190
							#設置錯誤識別
12191
							$result["status"]="false";
12192
 
12193
							#設置錯誤訊息
12194
							$result["error"]=$writeMultiFile;
12195
 
12196
							#回傳結果
12197
							return $result;
12198
 
12199
							}#if end
12200
 
293 liveuser 12201
						#設置需要執行指令來生效憑證
12202
						$requireActionAfterUpdateCert="true";
12203
 
255 liveuser 12204
						}#if end
12205
 
12206
					#如果有需要執行指令來生效憑證
12207
					if($requireActionAfterUpdateCert==="true"){
12208
 
281 liveuser 12209
						#if enable debug
12210
						if($debug){
12211
 
12212
							#debug msg
291 liveuser 12213
							echo "Action required to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 12214
 
12215
							}#if end
12216
 
255 liveuser 12217
						#儲存 actionAfterUpdateCert
12218
						$action=$cInfo["actionAfterUpdateCert"];
12219
 
12220
						#如果有多個指令要執行
12221
						if(gettype($action[0])==="array"){
12222
 
281 liveuser 12223
							#if enable debug
12224
							if($debug){
12225
 
12226
								#debug msg
291 liveuser 12227
								echo "There are many cmds to run to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 12228
 
12229
								}#if end
12230
 
255 liveuser 12231
							#針對每的指令
12232
							foreach($action as $ac){
12233
 
281 liveuser 12234
								#if enable debug
12235
								if($debug){
12236
 
12237
									#debug msg
12238
									echo ".".PHP_EOL;
12239
 
12240
									}#if end
12241
 
255 liveuser 12242
								#函式說明:
293 liveuser 12243
								#將字串進行解析,變成多個參數.
12244
								#回傳結果:
12245
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
12246
								#$result["function"],當前執行的函式內容.
12247
								#$result["error"],錯誤訊息陣列.
12248
								#$result["content"],參數陣列.
12249
								#$result["count"],總共有幾個參數.
12250
								#必填參數:
12251
								#$conf["input"],字串,要解析成參數的字串.
12252
								$conf["stringProcess::parse"]["input"]=$ac;
12253
								#可省略參數:
12254
								#無.
12255
								#參考資料:
12256
								#無.
12257
								#備註:
12258
								#無.
12259
								$parse=stringProcess::parse($conf["stringProcess::parse"]);
12260
								unset($conf["stringProcess::parse"]);
12261
 
12262
								#如果執行異常
12263
								if($parse["status"]==="false"){
12264
 
12265
									#設置錯誤識別
12266
									$result["status"]="false";
12267
 
12268
									#設置錯誤訊息
12269
									$result["error"]=$parse;
12270
 
12271
									#回傳結果
12272
									return $result;
12273
 
12274
									}#if end
12275
 
12276
								#debug
12277
								#var_dump(__LINE__,$parse);
12278
 
12279
								#函式說明:
255 liveuser 12280
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
12281
								#回傳結果:
12282
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12283
								#$result["error"],錯誤訊息陣列.
12284
								#$result["function"],當前執行的函數名稱.
12285
								#$result["argu"],使用的參數.
12286
								#$result["cmd"],執行的指令名稱.
12287
								#$result["params"],執行指令伴隨的參數.
12288
								#必填參數:
12289
								#$conf["cmdArray"],字串陣列,要執行的指令字串.
293 liveuser 12290
								$conf["external::callShellHelper"]["cmdArray"]=$parse["content"];
255 liveuser 12291
								#可省略參數:
12292
								#無.
12293
								#參考資料:
12294
								#array_shift=>https://www.php.net/manual/en/function.array-shift.php
12295
								#備註:
12296
								#無.
12297
								$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
12298
								unset($conf["external::callShellHelper"]);
12299
 
12300
								#如果執行異常
12301
								if($callShellHelper["status"]==="false"){
12302
 
12303
									#設置錯誤識別
12304
									$result["status"]="false";
12305
 
12306
									#設置錯誤訊息
12307
									$result["error"]=$callShellHelper;
12308
 
12309
									#回傳結果
12310
									return $result;
12311
 
12312
									}#if end
12313
 
12314
								#函式說明:
12315
								#呼叫shell執行系統命令,並取得回傳的內容.
12316
								#回傳結果:
12317
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12318
								#$result["error"],錯誤訊息陣列.
12319
								#$result["function"],當前執行的函數名稱.
12320
								#$result["argu"],使用的參數.
12321
								#$result["cmd"],執行的指令內容.
12322
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12323
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12324
								#$result["content"],為執行完後的輸出字串.
12325
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12326
								#$result["running"],是否還在執行.
12327
								#$result["pid"],pid.
12328
								#$result["statusCode"],執行結束後的代碼.
12329
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12330
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12331
								#必填參數:
12332
								#$conf["command"],字串,要執行的指令.
12333
								$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
12334
								#$conf["fileArgu"],字串,變數__FILE__的內容.
12335
								$conf["external::callShell"]["fileArgu"]=__FILE__;
12336
								#可省略參數:
12337
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12338
								$conf["external::callShell"]["argu"]=$callShellHelper["params"];
12339
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12340
								#$conf["arguIsAddr"]=array();
12341
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
12342
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
12343
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
12344
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12345
								#$conf["enablePrintDescription"]="true";
12346
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
12347
								#$conf["printDescription"]="";
12348
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
12349
								$conf["external::callShell"]["escapeshellarg"]="true";
12350
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
12351
								#$conf["thereIsShellVar"]=array();
12352
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12353
								#$conf["username"]="";
12354
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12355
								#$conf["password"]="";
12356
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12357
								#$conf["useScript"]="";
12358
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12359
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12360
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12361
								#$conf["inBackGround"]="";
12362
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
12363
								#$conf["getErr"]="false";
12364
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
12365
								#$conf["doNotRun"]="false";
12366
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
12367
								#$conf["remoteIp"]="";
12368
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
12369
								#$conf["remoteUser"]="";
12370
								#參考資料:
12371
								#exec=>http://php.net/manual/en/function.exec.php
12372
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12373
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12374
								#備註:
12375
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12376
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
12377
								$callShell=external::callShell($conf["external::callShell"]);
12378
								unset($conf["external::callShell"]);
12379
 
12380
								#如果執行異常
12381
								if($callShellHelper["status"]==="false"){
12382
 
12383
									#設置錯誤識別
12384
									$result["status"]="false";
12385
 
12386
									#設置錯誤訊息
12387
									$result["error"]=$callShell;
12388
 
12389
									#回傳結果
12390
									return $result;
12391
 
12392
									}#if end
12393
 
12394
								}#foreach end
12395
 
12396
							}#if end
12397
 
291 liveuser 12398
						#反之
12399
						else{
12400
 
12401
							#if enable debug
12402
							if($debug){
12403
 
12404
								#debug msg
12405
								echo "There is only one cmd to run to apply ssl for domain name(".$cName.")".PHP_EOL;
255 liveuser 12406
 
291 liveuser 12407
								}#if end
281 liveuser 12408
 
291 liveuser 12409
							#函式說明:
293 liveuser 12410
							#將字串進行解析,變成多個參數.
12411
							#回傳結果:
12412
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
12413
							#$result["function"],當前執行的函式內容.
12414
							#$result["error"],錯誤訊息陣列.
12415
							#$result["content"],參數陣列.
12416
							#$result["count"],總共有幾個參數.
12417
							#必填參數:
12418
							#$conf["input"],字串,要解析成參數的字串.
12419
							$conf["stringProcess::parse"]["input"]=$action;
12420
							#可省略參數:
12421
							#無.
12422
							#參考資料:
12423
							#無.
12424
							#備註:
12425
							#無.
12426
							$parse=stringProcess::parse($conf["stringProcess::parse"]);
12427
							unset($conf["stringProcess::parse"]);
12428
 
12429
							#如果執行異常
12430
							if($parse["status"]==="false"){
12431
 
12432
								#設置錯誤識別
12433
								$result["status"]="false";
12434
 
12435
								#設置錯誤訊息
12436
								$result["error"]=$parse;
12437
 
12438
								#回傳結果
12439
								return $result;
12440
 
12441
								}#if end
12442
 
12443
							#debug
12444
							#var_dump(__LINE__,$parse);
12445
 
12446
							#函式說明:
291 liveuser 12447
							#解析指令與參數,回傳指令與參數給 callShell 函式使用.
12448
							#回傳結果:
12449
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12450
							#$result["error"],錯誤訊息陣列.
12451
							#$result["function"],當前執行的函數名稱.
12452
							#$result["argu"],使用的參數.
12453
							#$result["cmd"],執行的指令名稱.
12454
							#$result["params"],執行指令伴隨的參數.
12455
							#必填參數:
12456
							#$conf["cmdArray"],字串陣列,要執行的指令字串.
293 liveuser 12457
							$conf["external::callShellHelper"]["cmdArray"]=$parse["content"];
291 liveuser 12458
							#可省略參數:
12459
							#無.
12460
							#參考資料:
12461
							#array_shift=>https://www.php.net/manual/en/function.array-shift.php
12462
							#備註:
12463
							#無.
12464
							$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
12465
							unset($conf["external::callShellHelper"]);
12466
 
12467
							#如果執行異常
12468
							if($callShellHelper["status"]==="false"){
281 liveuser 12469
 
291 liveuser 12470
								#設置錯誤識別
12471
								$result["status"]="false";
255 liveuser 12472
 
291 liveuser 12473
								#設置錯誤訊息
12474
								$result["error"]=$callShellHelper;
255 liveuser 12475
 
291 liveuser 12476
								#回傳結果
12477
								return $result;
12478
 
12479
								}#if end
255 liveuser 12480
 
291 liveuser 12481
							#函式說明:
12482
							#呼叫shell執行系統命令,並取得回傳的內容.
12483
							#回傳結果:
12484
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12485
							#$result["error"],錯誤訊息陣列.
12486
							#$result["function"],當前執行的函數名稱.
12487
							#$result["argu"],使用的參數.
12488
							#$result["cmd"],執行的指令內容.
12489
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12490
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12491
							#$result["content"],為執行完後的輸出字串.
12492
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12493
							#$result["running"],是否還在執行.
12494
							#$result["pid"],pid.
12495
							#$result["statusCode"],執行結束後的代碼.
12496
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12497
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12498
							#必填參數:
12499
							#$conf["command"],字串,要執行的指令.
12500
							$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
12501
							#$conf["fileArgu"],字串,變數__FILE__的內容.
12502
							$conf["external::callShell"]["fileArgu"]=__FILE__;
12503
							#可省略參數:
12504
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12505
							$conf["external::callShell"]["argu"]=$callShellHelper["params"];
12506
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12507
							#$conf["arguIsAddr"]=array();
12508
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
12509
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
12510
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
12511
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12512
							#$conf["enablePrintDescription"]="true";
12513
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
12514
							#$conf["printDescription"]="";
12515
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
12516
							$conf["external::callShell"]["escapeshellarg"]="true";
12517
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
12518
							#$conf["thereIsShellVar"]=array();
12519
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12520
							#$conf["username"]="";
12521
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12522
							#$conf["password"]="";
12523
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12524
							#$conf["useScript"]="";
12525
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12526
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12527
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12528
							#$conf["inBackGround"]="";
12529
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
12530
							#$conf["getErr"]="false";
12531
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
12532
							#$conf["doNotRun"]="false";
12533
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
12534
							#$conf["remoteIp"]="";
12535
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
12536
							#$conf["remoteUser"]="";
12537
							#參考資料:
12538
							#exec=>http://php.net/manual/en/function.exec.php
12539
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12540
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12541
							#備註:
12542
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12543
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
12544
							$callShell=external::callShell($conf["external::callShell"]);
12545
							unset($conf["external::callShell"]);
12546
 
12547
							#如果執行異常
12548
							if($callShellHelper["status"]==="false"){
255 liveuser 12549
 
291 liveuser 12550
								#設置錯誤識別
12551
								$result["status"]="false";
255 liveuser 12552
 
291 liveuser 12553
								#設置錯誤訊息
12554
								$result["error"]=$callShell;
255 liveuser 12555
 
291 liveuser 12556
								#回傳結果
12557
								return $result;
255 liveuser 12558
 
291 liveuser 12559
								}#if end
12560
 
12561
							}#else end
12562
 
12563
						}#if end
255 liveuser 12564
 
12565
					}#else end
12566
 
12567
				}#else end
291 liveuser 12568
 
255 liveuser 12569
			}#foreach end
12570
 
12571
		}#function sslUpdater_idle end
12572
 
226 liveuser 12573
	}#class zerossl end
255 liveuser 12574