Subversion Repositories php-qbpwcf

Rev

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

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
27
類別說明:
28
應用 zerossl 的類別.
29
備註:
30
無.
31
*/
32
class zerossl{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	#備註:
47
	#無.
48
	*/
49
	public function __call($method,$arguments){
226 liveuser 50
 
3 liveuser 51
		#取得當前執行的函式
52
		$result["function"]=__FUNCTION__;
226 liveuser 53
 
3 liveuser 54
		#設置執行不正常
55
		$result["status"]="false";
226 liveuser 56
 
3 liveuser 57
		#設置執行錯誤
58
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 59
 
3 liveuser 60
		#設置所丟入的參數
61
		$result["error"][]=$arguments;
226 liveuser 62
 
3 liveuser 63
		#回傳結果
64
		return $result;
226 liveuser 65
 
3 liveuser 66
		}#function __call end
226 liveuser 67
 
3 liveuser 68
	/*
69
	#函式說明:
70
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
71
	#回傳結果:
72
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
73
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
74
	#$result["function"],當前執行的函式名稱.
75
	#必填參數:
76
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
77
	#$arguments,陣列,為呼叫方法時所用的參數.
78
	#參考資料:
79
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
80
	#備註:
81
	#無.
82
	*/
83
	public static function __callStatic($method,$arguments){
226 liveuser 84
 
3 liveuser 85
		#取得當前執行的函式
86
		$result["function"]=__FUNCTION__;
226 liveuser 87
 
3 liveuser 88
		#設置執行不正常
89
		$result["status"]="false";
226 liveuser 90
 
3 liveuser 91
		#設置執行錯誤
92
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 93
 
3 liveuser 94
		#設置所丟入的參數
95
		$result["error"][]=$arguments;
226 liveuser 96
 
3 liveuser 97
		#回傳結果
98
		return $result;
226 liveuser 99
 
3 liveuser 100
		}#function __callStatic end
226 liveuser 101
 
3 liveuser 102
	/*
103
	#函式說明:
104
	#取得api的資訊
105
	#回傳結果:
106
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
107
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
108
	#$result["function"],當前執行的函式名稱.
109
	#$result["content"],api資訊陣列.
110
	#必填參數:
111
	#無
112
	#可省略參數:
113
	#無
114
	#參考資料:
115
	#無.
116
	#備註:
117
	#無.
118
	*/
119
	public static function getApiInfo(){
226 liveuser 120
 
3 liveuser 121
		#初始化要回傳的陣列
122
		$result=array();
226 liveuser 123
 
3 liveuser 124
		#api domain
125
		$result["apiDomain"]="api.zerossl.com";
226 liveuser 126
 
249 liveuser 127
		#create certificate api path
3 liveuser 128
		$result["csrPath"]="/certificates";
226 liveuser 129
 
3 liveuser 130
		#create certificate url
131
		$result["csrUrl"]=$result["apiDomain"].$result["csrPath"];
226 liveuser 132
 
3 liveuser 133
		#api access key
134
		$result["apiKey"]=zeroSSLapiKey;
226 liveuser 135
 
3 liveuser 136
		#設置執行正常
137
		$result["status"]="true";
226 liveuser 138
 
3 liveuser 139
		#回傳結果
140
		return $result;
226 liveuser 141
 
3 liveuser 142
		}#function getApiInfo end
226 liveuser 143
 
3 liveuser 144
	/*
145
	#函式說明:
146
	#產生ssl private key.
147
	#回傳結果:
148
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
149
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
150
	#$result["function"],當前執行的函式名稱.
151
	#$result["argu"],所使用的參數.
152
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 153
	#$result["content"],ssl用的private key.
3 liveuser 154
	#必填參數:
155
	#$conf["fileArgu"],字串,變數__FILE__的內容.
156
	$conf["fileArgu"]=__FILE__;
157
	#可省略參數:
158
	#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
159
	#$conf["length"]=4096';
160
	#參考資料:
161
	#無.
162
	#備註:
163
	#key generated by openssl with RSA.
164
	*/
165
	public static function createPrivateKey(&$conf){
226 liveuser 166
 
3 liveuser 167
		#初始化要回傳的結果
168
		$result=array();
226 liveuser 169
 
3 liveuser 170
		#取得當前執行的函數名稱
171
		$result["function"]=__FUNCTION__;
226 liveuser 172
 
3 liveuser 173
		#如果 $conf 不為陣列
174
		if(gettype($conf)!="array"){
226 liveuser 175
 
3 liveuser 176
			#設置執行失敗
177
			$result["status"]="false";
226 liveuser 178
 
3 liveuser 179
			#設置執行錯誤訊息
180
			$result["error"][]="\$conf變數須為陣列形態";
181
 
182
			#如果傳入的參數為 null
183
			if($conf==null){
226 liveuser 184
 
3 liveuser 185
				#設置執行錯誤訊息
186
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 187
 
3 liveuser 188
				}#if end
189
 
190
			#回傳結果
191
			return $result;
226 liveuser 192
 
3 liveuser 193
			}#if end
226 liveuser 194
 
3 liveuser 195
		#取得參數
196
		$result["argu"]=$conf;
226 liveuser 197
 
3 liveuser 198
		#函式說明:
199
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
200
		#回傳結果:
201
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
202
		#$result["error"],執行不正常結束的錯訊息陣列.
203
		#$result["simpleError"],簡單表示的錯誤訊息.
204
		#$result["function"],當前執行的函式名稱.
205
		#$result["argu"],設置給予的參數.
206
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
207
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
208
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
209
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
210
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
211
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
212
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
213
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
214
		#必填參數:
215
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
216
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
217
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
218
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
219
		#可省略參數:
220
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
221
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
222
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
223
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
224
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
225
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
226
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
227
		#$conf["canNotBeEmpty"]=array();
228
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
229
		#$conf["canBeEmpty"]=array();
230
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
231
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("length");
232
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
233
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
234
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
235
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer");
236
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
237
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(4096);
238
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
239
		#$conf["disallowAllSkipableVarIsEmpty"]="";
240
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
241
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
242
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
243
		#$conf["disallowAllSkipableVarNotExist"]="";
244
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
245
		#$conf["arrayCountEqualCheck"][]=array();
246
		#參考資料:
247
		#array_keys=>http://php.net/manual/en/function.array-keys.php
248
		#備註:
249
		#無.
250
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
251
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 252
 
3 liveuser 253
		#如果 $checkArguments["status"]等於 "false"
254
		if($checkArguments["status"]==="false"){
255
 
256
			#設置執行錯誤的識別
257
			$result["status"]="false";
258
 
259
			#設置錯誤訊息
260
			$result["error"]=$checkArguments;
261
 
262
			#回傳結果
263
			return $result;
264
 
265
			}#if end
266
 
267
		#如果 $checkArguments["passed"]等於 "false"
268
		if($checkArguments["passed"]==="false"){
269
 
270
			#設置執行錯誤的識別
271
			$result["status"]="false";
272
 
273
			#設置錯誤訊息
274
			$result["error"]=$checkArguments;
275
 
276
			#回傳結果
277
			return $result;
278
 
279
			}#if end
226 liveuser 280
 
3 liveuser 281
		#函式說明:
282
		#呼叫shell執行系統命令,並取得回傳的內容.
283
		#回傳結果:
284
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
285
		#$result["error"],錯誤訊息陣列.
286
		#$result["function"],當前執行的函數名稱.
287
		#$result["argu"],使用的參數.
288
		#$result["cmd"],執行的指令內容.
289
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
290
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
291
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
292
		#$result["running"],是否還在執行.
293
		#$result["pid"],pid.
294
		#$result["statusCode"],執行結束後的代碼.
295
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
296
		#必填參數:
297
		#$conf["command"],字串,要執行的指令.
298
		$conf["external::callShell"]["command"]="openssl";
299
		#$conf["fileArgu"],字串,變數__FILE__的內容.
300
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
301
		#可省略參數:
302
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
303
		$conf["external::callShell"]["argu"]=array("genrsa",$conf["length"]);
304
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
305
		#$conf["arguIsAddr"]=array();
306
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
307
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
308
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
309
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
310
		#$conf["enablePrintDescription"]="true";
311
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
312
		#$conf["printDescription"]="";
313
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
314
		$conf["external::callShell"]["escapeshellarg"]="true";
315
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
316
		#$conf["thereIsShellVar"]=array();
317
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
318
		#$conf["username"]="";
319
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
320
		#$conf["password"]="";
321
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
322
		#$conf["useScript"]="";
323
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
324
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
325
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
326
		#$conf["inBackGround"]="";
327
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
328
		#$conf["getErr"]="false";
329
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
330
		#$conf["doNotRun"]="false";
331
		#參考資料:
332
		#exec=>http://php.net/manual/en/function.exec.php
333
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
334
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
335
		#備註:
336
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
337
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
338
		$callShell=external::callShell($conf["external::callShell"]);
339
		unset($conf["external::callShell"]);
226 liveuser 340
 
3 liveuser 341
		#如果異常
342
		if($callShell["status"]==="false"){
226 liveuser 343
 
3 liveuser 344
			#設置錯誤識別
345
			$result["status"]="false";
226 liveuser 346
 
3 liveuser 347
			#設置錯誤訊息
348
			$result["error"]=$callShell;
226 liveuser 349
 
3 liveuser 350
			#回傳結果
351
			return $result;
226 liveuser 352
 
3 liveuser 353
			}#if end
226 liveuser 354
 
3 liveuser 355
		#函式說明:
356
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
357
		#回傳的結果:
358
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
359
		#$result["function"],當前執行的function名稱
360
		#$result["error"],錯誤訊息陣列.
361
		#$result["content"],處理好的字串.
362
		#$result["argu"],使用的參數.
363
		#必填參數:
364
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
365
		$conf["arrays::arrayToString"]["inputArray"]=$callShell["output"];
366
		#可省略參數:
367
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
255 liveuser 368
		$conf["arrays::arrayToString"]["spiltSymbol"]=PHP_EOL;
3 liveuser 369
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
370
		$conf["arrays::arrayToString"]["skipEnd"]="true";
371
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
372
		#$conf["spiltSymbolAtStart"]="";
373
		#參考資料:
374
		#無.
375
		#備註:
376
		#無.
377
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
378
		unset($conf["arrays::arrayToString"]);
226 liveuser 379
 
3 liveuser 380
		#如果異常
381
		if($arrayToString["status"]==="false"){
226 liveuser 382
 
3 liveuser 383
			#設置錯誤識別
384
			$result["status"]="false";
226 liveuser 385
 
3 liveuser 386
			#設置錯誤訊息
387
			$result["error"]=$arrayToString;
226 liveuser 388
 
3 liveuser 389
			#回傳結果
390
			return $result;
226 liveuser 391
 
3 liveuser 392
			}#if end
226 liveuser 393
 
3 liveuser 394
		#取得 private key 字串
395
		$result["content"]=$arrayToString["content"];
226 liveuser 396
 
3 liveuser 397
		#設置執行正常
398
		$result["status"]="true";
226 liveuser 399
 
3 liveuser 400
		#回傳結果
401
		return $result;
226 liveuser 402
 
3 liveuser 403
		}#function createPrivateKey end
226 liveuser 404
 
3 liveuser 405
	/*
406
	#函式說明:
249 liveuser 407
	#產生certificate sign request(CSR).
3 liveuser 408
	#回傳結果:
409
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
410
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
411
	#$result["function"],當前執行的函式名稱.
412
	#$result["argu"],所使用的參數.
255 liveuser 413
	#$result["content"],csr內容.
3 liveuser 414
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 415
	#$result["privateKey"], private key 的內容.
3 liveuser 416
	#必填參數:
249 liveuser 417
	#$conf["domain"],字串,csr內容的網域名稱.
418
	#$conf["domain"]="";
419
	#可省略參數:
255 liveuser 420
	#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
421
	#$conf["pKey"]="";
249 liveuser 422
	#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
423
	#$conf["country"]="";
424
	#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
425
	#$conf["state"]="";
426
	#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
427
	#$conf["org"]="";
428
	#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
429
	#$conf["unit"]="";
430
	#參考資料:
431
	#無.
432
	#備註:
433
	#無.
434
	*/
435
	public static function createCSR(&$conf){
436
 
437
		#初始化要回傳的結果
438
		$result=array();
439
 
440
		#設置當其函數名稱
441
		$result["function"]=__FUNCTION__;
442
 
443
		#如果 $conf 不為陣列
444
		if(gettype($conf)!="array"){
445
 
446
			#設置執行失敗
447
			$result["status"]="false";
448
 
449
			#設置執行錯誤訊息
450
			$result["error"][]="\$conf變數須為陣列形態";
451
 
452
			#如果傳入的參數為 null
453
			if($conf==null){
454
 
455
				#設置執行錯誤訊息
456
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
457
 
458
				}#if end
459
 
460
			#回傳結果
461
			return $result;
462
 
463
			}#if end
464
 
465
		#取得參數
466
		$result["argu"]=$conf;
467
 
468
		#檢查參數
469
		#函式說明:
470
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
471
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
472
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
473
		#$result["function"],當前執行的函式名稱.
474
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
475
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
476
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
477
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
478
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
479
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
480
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
481
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
482
		#必填寫的參數:
483
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
484
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
485
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
486
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("domain");
487
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
488
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
489
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
490
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
491
		#可以省略的參數:
492
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
493
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
494
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
495
		#$conf["skipableVariableCanNotBeEmpty"]=array();
496
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
255 liveuser 497
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pKey","country","state","city","org","unit");
249 liveuser 498
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
255 liveuser 499
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
249 liveuser 500
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 501
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"TW","Taiwan","Taoyuan City","QBPWCF","RD");
249 liveuser 502
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
503
		#$conf["arrayCountEqualCheck"][]=array();
504
		#參考資料來源:
505
		#array_keys=>http://php.net/manual/en/function.array-keys.php
506
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
507
		unset($conf["variableCheck::checkArguments"]);
508
 
509
		#如果檢查失敗
510
		if($checkArguments["status"]==="false"){
511
 
512
			#設置錯誤識別
513
			$result["status"]="false";
514
 
515
			#設置錯誤訊息
516
			$result["error"]=$checkArguments;
517
 
518
			#回傳結果
519
			return $result;
520
 
521
			}#if end
522
 
523
		#如果檢查不通過
524
		if($checkArguments["passed"]==="false"){
525
 
526
			#設置錯誤識別
527
			$result["status"]="false";
528
 
529
			#設置錯誤訊息
530
			$result["error"]=$checkArguments;
531
 
532
			#回傳結果
533
			return $result;
534
 
535
			}#if end
536
 
255 liveuser 537
		#如果沒有指定 pKey
538
		if(!isset($conf["pKey"])){
249 liveuser 539
 
255 liveuser 540
			#產生uuid名稱
541
			#函式說明:
542
			#使用 linux 的 uuid 指令來產生 uuid 字串
543
			#回傳結果:
544
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
545
			#$result["error"],錯誤訊息.
546
			#$result["function"],當前執行的函式名稱.
547
			#$result["content"],uuid.
548
			#必填參數:
549
			#無.
550
			#可省略參數:
551
			#無.
552
			#參考資料:
553
			#無.
554
			#備註:
555
			#無.
556
			$uuid=cmd::uuid();
557
 
558
			#如果執行異常
559
			if($uuid["status"]==="false"){
249 liveuser 560
 
255 liveuser 561
				#設置錯誤識別
562
				$result["status"]="false";
249 liveuser 563
 
255 liveuser 564
				#設置錯誤訊息
565
				$result["error"]=$uuid;
249 liveuser 566
 
255 liveuser 567
				#回傳結果
568
				return $result;
249 liveuser 569
 
255 liveuser 570
				}#if end
571
 
572
			#取得暫存的檔案名稱
573
			$TFN=$uuid["content"];
574
 
575
			#函式說明:
576
			#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
577
			#回傳結果:
578
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
579
			#$result["error"],錯誤訊息.
580
			#$result["function"],當前執行的函數名稱.
581
			#$result["content"],暫存檔案的路徑與名稱.
582
			#$result["fileName"],暫存檔案的名稱.
583
			#$result["path"],暫存檔案的路徑.
584
			#必填參數:
585
			#無.
586
			#可省略參數:
587
			#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
588
			#$conf["contant"]=array();
589
			#參考資料:
590
			#無.
591
			#備註:
592
			#無.
593
			$conf["fileAccess::createTempFile"]=array();
594
			$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
595
			unset($conf["fileAccess::createTempFile"]);
596
 
597
			#如果執行異常
598
			if($createTempFile["status"]==="false"){
249 liveuser 599
 
255 liveuser 600
				#設置錯誤識別
601
				$result["status"]="false";
249 liveuser 602
 
255 liveuser 603
				#設置錯誤訊息
604
				$result["error"]=$createTempFile;
249 liveuser 605
 
255 liveuser 606
				#回傳結果
607
				return $result;
249 liveuser 608
 
255 liveuser 609
				}#if end
610
 
611
			#暫存的檔案路徑與名稱
612
			$TFN=$createTempFile["content"];
613
 
614
			#產生 privae key
615
			#openssl genrsa -out output.key 4096 
616
 
617
			#函式說明:
618
			#呼叫shell執行系統命令,並取得回傳的內容.
619
			#回傳結果:
620
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
621
			#$result["error"],錯誤訊息陣列.
622
			#$result["function"],當前執行的函數名稱.
623
			#$result["argu"],使用的參數.
624
			#$result["cmd"],執行的指令內容.
625
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
626
			#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
627
			#$result["content"],為執行完後的輸出字串.
628
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
629
			#$result["running"],是否還在執行.
630
			#$result["pid"],pid.
631
			#$result["statusCode"],執行結束後的代碼.
632
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
633
			#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
634
			#必填參數:
635
			#$conf["command"],字串,要執行的指令.
636
			$conf["external::callShell"]["command"]="openssl";
637
			#$conf["fileArgu"],字串,變數__FILE__的內容.
638
			$conf["external::callShell"]["fileArgu"]=__FILE__;
639
			#可省略參數:
640
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
641
			$conf["external::callShell"]["argu"]=array("genrsa","-out",$TFN,"4096");
642
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
643
			#$conf["arguIsAddr"]=array();
644
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
645
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
646
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
647
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
648
			#$conf["enablePrintDescription"]="true";
649
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
650
			#$conf["printDescription"]="";
651
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
652
			#$conf["escapeshellarg"]="false";
653
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
654
			#$conf["thereIsShellVar"]=array();
655
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
656
			#$conf["username"]="";
657
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
658
			#$conf["password"]="";
659
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
660
			#$conf["useScript"]="";
661
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
662
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
663
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
664
			#$conf["inBackGround"]="";
665
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
666
			#$conf["getErr"]="false";
667
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
668
			$conf["external::callShell"]["doNotRun"]="true";
669
			#參考資料:
670
			#exec=>http://php.net/manual/en/function.exec.php
671
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
672
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
673
			#備註:
674
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
675
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
676
			$callShell=external::callShell($conf["external::callShell"]);
677
			unset($conf["external::callShell"]);
678
 
679
			#如果執行異常
680
			if($callShell["status"]==="false"){
249 liveuser 681
 
255 liveuser 682
				#設置錯誤識別
683
				$result["status"]="false";
249 liveuser 684
 
255 liveuser 685
				#設置錯誤訊息
686
				$result["error"]=$callShell;
249 liveuser 687
 
255 liveuser 688
				#回傳結果
689
				return $result;
249 liveuser 690
 
255 liveuser 691
				}#if end
692
 
693
			#debug
694
			#var_dump(__LINE__,$callShell);exit;
695
 
696
			#函式說明:
697
			#透過proc來多執行序運作.
698
			#回傳結果:
699
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
700
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
701
			#$result["function"],當前執行的函式名稱.
702
			#$result["argu"],使用的參數.
703
			#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
704
			#必填參數:
705
			#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
706
			$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
707
			#可省略參數:
708
			#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
709
			$conf["threads::proc"]["wait"]="true";
710
			#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
711
			#$conf["timeout"]=array("10");
712
			#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
713
			#$conf["workingDir"]=array("path");
714
			#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
715
			#$conf["envs"]=array(array("key"=>"value"));
716
			#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
717
			#$conf["executeBy"]=array("bash");
718
			#參考資料:
719
			#https://www.php.net/manual/en/function.proc-open.php
720
			#https://www.php.net/manual/en/function.proc-get-status.php
721
			#https://www.php.net/manual/en/function.proc-terminate.php
722
			#備註:
723
			#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
724
			$proc=threads::proc($conf["threads::proc"]);
725
			unset($conf["threads::proc"]);
726
 
727
			#如果執行異常
728
			if($proc["status"]==="false"){
249 liveuser 729
 
255 liveuser 730
				#設置錯誤識別
731
				$result["status"]="false";
249 liveuser 732
 
255 liveuser 733
				#設置錯誤訊息
734
				$result["error"]=$proc;
249 liveuser 735
 
255 liveuser 736
				#回傳結果
737
				return $result;
249 liveuser 738
 
255 liveuser 739
				}#if end
740
 
741
			#debug
742
			#var_dump(__LINE__,$proc);exit;
743
 
744
			#如果執行異常
745
			if($proc["content"][0]["status"]==="false"){
746
 
747
				#設置錯誤識別
748
				$result["status"]="false";
249 liveuser 749
 
255 liveuser 750
				#設置錯誤訊息
751
				$result["error"]=$proc["content"][0]["error"];
249 liveuser 752
 
255 liveuser 753
				#回傳結果
754
				return $result;
755
 
756
				}#if end
757
 
758
			#儲存錯誤訊息
759
			$errorMsg=$proc["content"][0]["error"];
760
 
761
			#如果有錯誤訊息
762
			if(!empty($errorMsg)){
763
 
764
				#設置錯誤識別
765
				$result["status"]="false";
766
 
767
				#設置錯誤訊息
768
				$result["error"]=$errorMsg;
769
 
770
				#回傳結果
771
				return $result;
772
 
773
				}#if end
249 liveuser 774
 
775
			}#if end
776
 
255 liveuser 777
		#反之
778
		else{
249 liveuser 779
 
255 liveuser 780
			#檢查 pKey 是否存在
781
			#函式說明:
782
			#檢查多個檔案與資料夾是否存在.
783
			#回傳的結果:
784
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
785
			#$result["error"],錯誤訊息陣列.
786
			#$resutl["function"],當前執行的涵式名稱.
787
			#$result["argu"],使用的參數.
788
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
789
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
790
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
791
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
792
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
793
			#必填參數:
794
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
293 liveuser 795
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["pKey"]);
255 liveuser 796
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
797
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
798
			#可省略參數:
799
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
800
			#$conf["disableWebSearch"]="false";
801
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
802
			$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
803
			#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
804
			$conf["fileAccess::checkMultiFileExist"]["web"]="false";
805
			#參考資料:
806
			#http://php.net/manual/en/function.file-exists.php
807
			#http://php.net/manual/en/control-structures.foreach.php
808
			#備註:
809
			#函數file_exists檢查的路徑為檔案系統的路徑
810
			#$result["varName"][$i]結果未實作
811
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
812
			unset($conf["fileAccess::checkMultiFileExist"]);
249 liveuser 813
 
255 liveuser 814
			#如果執行異常
815
			if($checkMultiFileExist["status"]==="false"){
249 liveuser 816
 
255 liveuser 817
				#設置錯誤識別
818
				$result["status"]="false";
249 liveuser 819
 
255 liveuser 820
				#設置錯誤訊息
821
				$result["error"]=$checkMultiFileExist;
822
 
823
				#回傳結果
824
				return $result;
825
 
826
				}#if end
249 liveuser 827
 
255 liveuser 828
			#設置pKey
829
			$TFN=$conf["pKey"];
249 liveuser 830
 
255 liveuser 831
			}#else
832
 
249 liveuser 833
		#範例指令
834
		#C,國家,例如TW,代表Taiwan
835
		#ST,州、省,要完整名稱,例如:Taiwan
836
		#L,城市名稱,例如Taoyuan City.
837
		#O=,組織或公司名稱,例如QBPWCF.
838
		#OU,單位名稱,例如RD.
839
		#CN,網域名稱,例如www.qbpwcf.org
840
		#openssl req -new -key qbpwcf.org.key -out qbpwcf.org.csr "-subj=/C=TW/ST=Taiwan/L=Taoyuan City/O=QBPWCF/OU=RD/CN=www.qbpwcf.org/"
841
 
842
		#初始化subj參數
843
		$subjStr="-subj=/";
844
 
845
		#設置 Country 參數
846
		$subjStr=$subjStr."C=".$conf["country"]."/";
847
 
848
		#設置 State 參數
849
		$subjStr=$subjStr."ST=".$conf["state"]."/";
850
 
851
		#設置 city 參數
852
		$subjStr=$subjStr."L=".$conf["city"]."/";
853
 
854
		#設置 Org 參數
855
		$subjStr=$subjStr."O=".$conf["org"]."/";
856
 
857
		#設置 Unit 參數
858
		$subjStr=$subjStr."OU=".$conf["unit"]."/";
859
 
860
		#設置 domain name 參數
861
		$subjStr=$subjStr."CN=".$conf["domain"]."/";
862
 
863
		#函式說明:
864
		#呼叫shell執行系統命令,並取得回傳的內容.
865
		#回傳結果:
866
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
867
		#$result["error"],錯誤訊息陣列.
868
		#$result["function"],當前執行的函數名稱.
869
		#$result["argu"],使用的參數.
870
		#$result["cmd"],執行的指令內容.
871
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
872
		#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
873
		#$result["content"],為執行完後的輸出字串.
874
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
875
		#$result["running"],是否還在執行.
876
		#$result["pid"],pid.
877
		#$result["statusCode"],執行結束後的代碼.
878
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
879
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
880
		#必填參數:
881
		#$conf["command"],字串,要執行的指令.
882
		$conf["external::callShell"]["command"]="openssl";
883
		#$conf["fileArgu"],字串,變數__FILE__的內容.
884
		$conf["external::callShell"]["fileArgu"]=__FILE__;
885
		#可省略參數:
886
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
887
		$conf["external::callShell"]["argu"]=array("req","-new","-key",$TFN,$subjStr);
888
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
889
		#$conf["arguIsAddr"]=array();
890
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
891
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
892
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
893
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
894
		#$conf["enablePrintDescription"]="true";
895
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
896
		#$conf["printDescription"]="";
897
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
898
		$conf["external::callShell"]["escapeshellarg"]="true";
899
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
900
		#$conf["thereIsShellVar"]=array();
901
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
902
		#$conf["username"]="";
903
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
904
		#$conf["password"]="";
905
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
906
		#$conf["useScript"]="";
907
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
908
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
909
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
910
		#$conf["inBackGround"]="";
911
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
912
		#$conf["getErr"]="false";
913
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
914
		$conf["external::callShell"]["doNotRun"]="true";
915
		#參考資料:
916
		#exec=>http://php.net/manual/en/function.exec.php
917
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
918
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
919
		#備註:
920
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
921
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
922
		$callShell=external::callShell($conf["external::callShell"]);
923
		unset($conf["external::callShell"]);
924
 
925
		#如果執行異常
926
		if($callShell["status"]==="false"){
927
 
928
			#設置錯誤識別
929
			$result["status"]="false";
930
 
931
			#設置錯誤訊息
932
			$result["error"]=$callShell;
933
 
934
			#回傳結果
935
			return $result;
936
 
937
			}#if end
938
 
939
		#debug
940
		#var_dump(__LINE__,$callShell);exit;
941
 
942
		#函式說明:
943
		#透過proc來多執行序運作.
944
		#回傳結果:
945
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
946
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
947
		#$result["function"],當前執行的函式名稱.
948
		#$result["argu"],使用的參數.
949
		#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
950
		#必填參數:
951
		#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
952
		$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
953
		#可省略參數:
954
		#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
955
		$conf["threads::proc"]["wait"]="true";
956
		#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
957
		#$conf["timeout"]=array("10");
958
		#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
959
		#$conf["workingDir"]=array("path");
960
		#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
961
		#$conf["envs"]=array(array("key"=>"value"));
962
		#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
963
		#$conf["executeBy"]=array("bash");
964
		#參考資料:
965
		#https://www.php.net/manual/en/function.proc-open.php
966
		#https://www.php.net/manual/en/function.proc-get-status.php
967
		#https://www.php.net/manual/en/function.proc-terminate.php
968
		#備註:
969
		#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
970
		$proc=threads::proc($conf["threads::proc"]);
971
		unset($conf["threads::proc"]);
972
 
973
		#如果執行異常
974
		if($proc["status"]==="false"){
975
 
976
			#設置錯誤識別
977
			$result["status"]="false";
978
 
979
			#設置錯誤訊息
980
			$result["error"]=$proc;
981
 
982
			#回傳結果
983
			return $result;
984
 
985
			}#if end
986
 
987
		#如果執行異常
988
		if($proc["content"][0]["status"]==="false"){
989
 
990
			#設置錯誤識別
991
			$result["status"]="false";
992
 
993
			#設置錯誤訊息
994
			$result["error"]=$proc["content"][0]["error"];
995
 
996
			#回傳結果
997
			return $result;
998
 
999
			}#if end
1000
 
1001
		#debug
1002
		#var_dump(__LINE__,$proc);exit;
1003
 
1004
		#儲存csr
1005
		$csr=$proc["content"][0]["content"];
1006
 
1007
		#取得 csr 內容
1008
		$result["content"]=$csr;
1009
 
255 liveuser 1010
		#取得 private key 的內容
249 liveuser 1011
		#函式說明:
255 liveuser 1012
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1013
		#回傳的變數說明:
1014
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1015
		#$result["error"],錯誤訊息提示.
1016
		#$result["warning"],警告訊息.
249 liveuser 1017
		#$result["function"],當前執行的函數名稱.
255 liveuser 1018
		#$result["fileContent"],爲檔案的內容陣列.
1019
		#$result["lineCount"],爲檔案內容總共的行數.
1020
		#$result["fullContent"],為檔案的完整內容.
1021
		#$result["base64dataOnly"],檔案的base64data.
1022
		#$result["base64data"],為在網頁上給予src參數的數值.
1023
		#$result["mimeType"],為檔案的mime type.
249 liveuser 1024
		#必填參數:
255 liveuser 1025
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1026
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$TFN;
1027
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1028
		$conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
249 liveuser 1029
		#可省略參數:
255 liveuser 1030
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
1031
		#$conf["web"]="true";
1032
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1033
		#$conf["createIfnotExist"]="false";
1034
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
1035
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
1036
		#參考資料:
1037
		#file(),取得檔案內容的行數.
1038
		#file=>http:#php.net/manual/en/function.file.php
1039
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1040
		#filesize=>http://php.net/manual/en/function.filesize.php
249 liveuser 1041
		#參考資料:
1042
		#無.
1043
		#備註:
1044
		#無.
255 liveuser 1045
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
1046
		unset($conf["fileAccess::getFileContent"]);
249 liveuser 1047
 
1048
		#如果執行異常
255 liveuser 1049
		if($getFileContent["status"]==="false"){
249 liveuser 1050
 
1051
			#設置錯誤識別
1052
			$result["status"]="false";
1053
 
1054
			#設置錯誤訊息
255 liveuser 1055
			$result["error"]=$getFileContent;
249 liveuser 1056
 
1057
			#回傳結果
1058
			return $result;
1059
 
1060
			}#if end
255 liveuser 1061
 
1062
		#設置要回傳的 private key 的內容
1063
		$result["privateKey"]=$getFileContent["fullContent"];
249 liveuser 1064
 
255 liveuser 1065
		#如果沒有設置 pKey
1066
		if(!isset($conf["pKey"])){
1067
 
1068
			#移除private key
1069
			#函式說明:
1070
			#移除檔案
1071
			#回傳結果:
1072
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
1073
			#$result["error"],錯誤訊息陣列.
1074
			#$result["warning"],警告訊息陣列.
1075
			#$result["function"],當前執行的函數名稱.
1076
			#$result["argu"],當前函式使用的參數.
1077
			#必填參數:
1078
			#$conf["fileAddress"],字串,要移除檔案的位置.
1079
			$conf["fileAccess::delFile"]["fileAddress"]=$TFN;
1080
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1081
			$conf["fileAccess::delFile"]["fileArgu"]=__FILE__;
1082
			#可省略參數:
1083
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1084
			#$conf["commentsArray"]=array("");
1085
			#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
1086
			#$conf["allowDelSymlink"]="true";
1087
			#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
1088
			#$conf["allowDelFolder"]="true";
1089
			#參考資料:
1090
			#無.
1091
			#備註:
1092
			#無.
1093
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
1094
			unset($conf["fileAccess::delFile"]);
1095
 
1096
			#如果執行異常
1097
			if($delFile["status"]==="false"){
1098
 
1099
				#設置錯誤識別
1100
				$result["status"]="false";
1101
 
1102
				#設置錯誤訊息
1103
				$result["error"]=$delFile;
1104
 
1105
				#回傳結果
1106
				return $result;
1107
 
1108
				}#if end
1109
 
1110
			}#if end
1111
 
249 liveuser 1112
		#設置執行正常
1113
		$result["status"]="true";
1114
 
1115
		#回傳結果
1116
		return $result;
1117
 
1118
		}#function createCSR end
1119
 
1120
	/*
1121
	#函式說明:
281 liveuser 1122
	#提供certificate sign request(CSR)透過zerossl產生certificate.
249 liveuser 1123
	#回傳結果:
1124
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1125
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1126
	#$result["function"],當前執行的函式名稱.
1127
	#$result["argu"],所使用的參數.
1128
	#$result["curl_verbose_info"],curl執行的詳細資訊.
1129
	#$result["id"],用於zerossl api驗證domain的id.
1130
	#$result["content"],字串,得到的json字串回應.
1131
	#$result["cnameKey"],用於dns CNAME驗證鍵名.
1132
	#$result["cnameVal"],用於dms CNAME驗證鍵值.
1133
	#必填參數:
3 liveuser 1134
	#$conf["certificate_domains"],字串,要簽署的doamin名稱.
1135
	$conf["certificate_domains"]="";
1136
	#$conf["certificate_csr"],字串,簽署的資訊.
1137
	$conf["certificate_csr"]="";
1138
	#$conf["fileArgu"],字串,變數__FILE__的內容.
1139
	$conf["fileArgu"]=__FILE__;
1140
	#可省略參數:
1141
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
1142
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
1143
	#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
1144
	#$conf["path"]=self::getApiInfo()["csrPath"];
1145
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
1146
	#$conf["key"]=self::getApiInfo()["apiKey"];
1147
	#參考資料:
1148
	#無.
1149
	#備註:
1150
	#無.
1151
	*/
249 liveuser 1152
	public static function createCertificate(&$conf){
226 liveuser 1153
 
3 liveuser 1154
		#break point
1155
		#var_dump(self::getApiInfo());exit;
226 liveuser 1156
 
3 liveuser 1157
		#初始化要回傳的結果
1158
		$result=array();
226 liveuser 1159
 
3 liveuser 1160
		#設置當其函數名稱
1161
		$result["function"]=__FUNCTION__;
226 liveuser 1162
 
3 liveuser 1163
		#如果 $conf 不為陣列
1164
		if(gettype($conf)!="array"){
226 liveuser 1165
 
3 liveuser 1166
			#設置執行失敗
1167
			$result["status"]="false";
226 liveuser 1168
 
3 liveuser 1169
			#設置執行錯誤訊息
1170
			$result["error"][]="\$conf變數須為陣列形態";
1171
 
1172
			#如果傳入的參數為 null
1173
			if($conf==null){
226 liveuser 1174
 
3 liveuser 1175
				#設置執行錯誤訊息
1176
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1177
 
3 liveuser 1178
				}#if end
1179
 
1180
			#回傳結果
1181
			return $result;
226 liveuser 1182
 
3 liveuser 1183
			}#if end
226 liveuser 1184
 
3 liveuser 1185
		#取得參數
1186
		$result["argu"]=$conf;
226 liveuser 1187
 
3 liveuser 1188
		#檢查參數
1189
		#函式說明:
1190
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1191
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1192
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1193
		#$result["function"],當前執行的函式名稱.
1194
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1195
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1196
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1197
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1198
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1199
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1200
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1201
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1202
		#必填寫的參數:
1203
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1204
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1205
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1206
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","certificate_domains","certificate_csr");
226 liveuser 1207
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 1208
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
1209
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1210
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1211
		#可以省略的參數:
1212
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1213
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1214
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
1215
		#$conf["skipableVariableCanNotBeEmpty"]=array();
1216
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1217
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","path","key");
226 liveuser 1218
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1219
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1220
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1221
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["csrPath"],self::getApiInfo()["apiKey"]);
1222
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1223
		#$conf["arrayCountEqualCheck"][]=array();
1224
		#參考資料來源:
1225
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1226
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1227
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1228
 
3 liveuser 1229
		#如果檢查失敗
249 liveuser 1230
		if($checkArguments["status"]==="false"){
226 liveuser 1231
 
3 liveuser 1232
			#設置錯誤識別
1233
			$result["status"]="false";
226 liveuser 1234
 
3 liveuser 1235
			#設置錯誤訊息
1236
			$result["error"]=$checkArguments;
226 liveuser 1237
 
3 liveuser 1238
			#回傳結果
1239
			return $result;
226 liveuser 1240
 
3 liveuser 1241
			}#if end
226 liveuser 1242
 
3 liveuser 1243
		#如果檢查不通過
249 liveuser 1244
		if($checkArguments["passed"]==="false"){
226 liveuser 1245
 
3 liveuser 1246
			#設置錯誤識別
1247
			$result["status"]="false";
226 liveuser 1248
 
3 liveuser 1249
			#設置錯誤訊息
1250
			$result["error"]=$checkArguments;
226 liveuser 1251
 
3 liveuser 1252
			#回傳結果
1253
			return $result;
226 liveuser 1254
 
3 liveuser 1255
			}#if end
226 liveuser 1256
 
3 liveuser 1257
		#要傳送的 key -> value
1258
		$postArray=array();
226 liveuser 1259
 
3 liveuser 1260
		#設置要簽署的domain
1261
		$postArray["certificate_domains"]=$conf["certificate_domains"];
226 liveuser 1262
 
3 liveuser 1263
		#設置csr
1264
		$postArray["certificate_csr"]=$conf["certificate_csr"];
226 liveuser 1265
 
3 liveuser 1266
		#預設為 90 天的憑證
1267
		$postArray["certificate_validity_days"]=90;
226 liveuser 1268
 
3 liveuser 1269
		#強制讓 要簽署的domain 為 $postArray["certificate_domains"]
1270
		$postArray["strict_domains"]=1;
226 liveuser 1271
 
3 liveuser 1272
		#設置要傳送的 json
1273
		$postJson=json_encode($postArray);
226 liveuser 1274
 
3 liveuser 1275
		#函式說明:
1276
		#運行curl cmd
1277
		#回傳結果:
1278
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1279
		#$result["error"],錯誤訊息陣列.
1280
		#$result["function"],當前執行的函式名稱.
1281
		#$result["founded"],識別網址找不找得到.
1282
		#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
1283
		#$result["fullContent"],取得回應的完整字串內容.
1284
		#$result["cookie"],cookie檔案的位置與名稱.
1285
		#$result["cmd"],執行的command.
1286
		#$result["argu],使用的參數.
1287
		#必填參數:
1288
		#$conf["url"],字串,目標url.
1289
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].$conf["path"]."?access_key=".$conf["key"];
1290
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1291
		$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
1292
		#可省略參數:
1293
		#$conf["header"],字串陣列,要傳送的header.
1294
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
1295
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
1296
		#$conf["allowAnySSLcertificate"]="";
1297
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
1298
		#$conf["postVar"]=array();
1299
		#$conf["rawPost"]="字串",要傳送的raw post內容.
1300
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
1301
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
1302
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
1303
		#$conf["agent"],字串,user agent的名稱.
1304
		#$conf["agent"]="";
1305
		#$conf["cookie"],字串,cookie位置與檔案位置.
1306
		#$conf["cookie"]="";
1307
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
1308
		#$conf["forceNewCookie"]="";
1309
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
1310
		#$conf["inBg"]="true";
1311
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
1312
		#$conf["bgInProc"]="false";
1313
		#參考資料:
1314
		#無.
1315
		#備註:
1316
		#無.
1317
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
1318
		unset($conf["catchWebContent::curlCmd"]);
226 liveuser 1319
 
3 liveuser 1320
		#如果異常
1321
		if($curlCmd["status"]==="false"){
226 liveuser 1322
 
3 liveuser 1323
			#設置錯誤識別
1324
			$result["status"]="false";
226 liveuser 1325
 
3 liveuser 1326
			#設置錯誤訊息
1327
			$result["error"]=$curlCmd;
226 liveuser 1328
 
3 liveuser 1329
			#回傳結果
1330
			return $result;
226 liveuser 1331
 
3 liveuser 1332
			}#if end
226 liveuser 1333
 
3 liveuser 1334
		#設置curl的詳細資訊
1335
		$result["curl_verbose_info"]=$curlCmd;
226 liveuser 1336
 
3 liveuser 1337
		/* 範例 json content
249 liveuser 1338
		{"id":"de9bfbbc78ad2b04323ac0670efefe58","type":"1","common_name":"qbpwcf.org","additional_domains":"","created":"2026-01-19 11:47:13","expires":"2026-04-19 23:59:59","status":"draft","validation_type":null,"validation_emails":null,"replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"qbpwcf.org":["admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"qbpwcf.org":{"file_validation_url_http":"http:\/\/qbpwcf.org\/.well-known\/pki-validation\/3FE7CA1D6DA057FB40FDD333B4C105F9.txt","file_validation_url_https":"https:\/\/qbpwcf.org\/.well-known\/pki-validation\/3FE7CA1D6DA057FB40FDD333B4C105F9.txt","file_validation_content":["7B29341B7148276F5025CE90FC1138037871040E5B7FBDB8E7EEF7CC8DAA4A56","comodoca.com","2e85598b7f1b864"],"cname_validation_p1":"_3FE7CA1D6DA057FB40FDD333B4C105F9.qbpwcf.org","cname_validation_p2":"7B29341B7148276F5025CE90FC113803.7871040E5B7FBDB8E7EEF7CC8DAA4A56.2e85598b7f1b864.comodoca.com"}}},"signature_algorithm_properties":null}
3 liveuser 1339
		*/
226 liveuser 1340
 
249 liveuser 1341
		#驗證結果是否為 json
1342
		$json_validate=json_validate($curlCmd["fullContent"]);
226 liveuser 1343
 
249 liveuser 1344
		#如果回應不是 json
1345
		if(!$json_validate){
1346
 
1347
			#設置錯誤識別
1348
			$result["status"]="false";
1349
 
1350
			#設置錯誤訊息
1351
			$result["error"]=$curlCmd;
1352
 
1353
			#回傳結果
1354
			return $result;
1355
 
1356
			}#if end
1357
 
1358
		#設置json string結果
1359
		$result["content"]=$curlCmd["fullContent"];
1360
 
1361
		#解析json
1362
		$jsonRes=json_decode($result["content"]);
255 liveuser 1363
 
1364
		#另存 certifucate domain
1365
		$cerDomain=$conf["certificate_domains"];
1366
 
1367
		#如果缺少必備的資訊
1368
		if(!isset($jsonRes->validation)){
1369
 
1370
			#設置錯誤識別
1371
			$result["status"]="false";
249 liveuser 1372
 
255 liveuser 1373
			#設置錯誤訊息
1374
			$result["error"]=$curlCmd;
1375
 
1376
			#回傳結果
1377
			return $result;
1378
 
1379
			}#if end
1380
 
249 liveuser 1381
		#取得用於 dns CNAME 驗證的名稱
255 liveuser 1382
		$result["cnameKey"]=$jsonRes->validation->other_methods->$cerDomain->cname_validation_p1;
249 liveuser 1383
 
1384
		#取得用於 dns CNAME 驗證的數值
255 liveuser 1385
		$result["cnameVal"]=$jsonRes->validation->other_methods->$cerDomain->cname_validation_p2;
249 liveuser 1386
 
1387
		#取得用於認證domain時識別用的id
1388
		$result["id"]=$jsonRes->id;
1389
 
3 liveuser 1390
		#設置執行正常
1391
		$result["status"]="true";
226 liveuser 1392
 
3 liveuser 1393
		#回傳結果
1394
		return $result;
226 liveuser 1395
 
249 liveuser 1396
		}#function createCertificate end
3 liveuser 1397
 
249 liveuser 1398
	/*
1399
	#函式說明:
291 liveuser 1400
	#解析RR檔案中其中的一行內容,回傳結果.
1401
	#回傳結果:
1402
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1403
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1404
	#$result["function"],當前執行的函式名稱.
1405
	#$result["argu"],所使用的參數.
404 liveuser 1406
	#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列,"type"的數值可能為"A"、"AAAA"、"$TTL"、"$ORIGIN"、"CNAME"、"TXT"、"NS"、"SOA".
291 liveuser 1407
	#$result["domain"],字串,RR所屬domain.
404 liveuser 1408
	#$result["defaultTTL"],字串,預設的RR更新時間,若line參數解析後type不為$TTL,則不會有該回傳結果.
291 liveuser 1409
	#$result["comment"],字串,一行的註解.
1410
	#必填參數:
1411
	#$conf["line"],字串,要解析的行內容.
1412
	$conf["line"]="";
1413
	#可省略參數:
1414
	#無.
1415
	#參考資料:
1416
	#無.
1417
	#備註:
1418
	#無.
1419
	*/
1420
	public static function parseRRline(&$conf){
1421
 
1422
		#初始化要回傳的結果
1423
		$result=array();
1424
 
1425
		#設置當其函數名稱
1426
		$result["function"]=__FUNCTION__;
1427
 
1428
		#如果 $conf 不為陣列
1429
		if(gettype($conf)!="array"){
1430
 
1431
			#設置執行失敗
1432
			$result["status"]="false";
1433
 
1434
			#設置執行錯誤訊息
1435
			$result["error"][]="\$conf變數須為陣列形態";
1436
 
1437
			#如果傳入的參數為 null
1438
			if($conf==null){
1439
 
1440
				#設置執行錯誤訊息
1441
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1442
 
1443
				}#if end
1444
 
1445
			#回傳結果
1446
			return $result;
1447
 
1448
			}#if end
1449
 
1450
		#取得參數
1451
		$result["argu"]=$conf;
1452
 
1453
		#檢查參數
1454
		#函式說明:
1455
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1456
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1457
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1458
		#$result["function"],當前執行的函式名稱.
1459
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1460
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1461
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1462
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1463
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1464
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1465
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1466
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1467
		#必填寫的參數:
1468
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1469
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1470
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1471
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("line");
1472
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
1473
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
1474
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1475
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1476
		#可以省略的參數:
1477
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1478
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1479
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
1480
		#$conf["skipableVariableCanNotBeEmpty"]=array();
1481
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1482
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThread");
1483
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1484
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1485
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1486
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
1487
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1488
		#$conf["arrayCountEqualCheck"][]=array();
1489
		#參考資料來源:
1490
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1491
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1492
		unset($conf["variableCheck::checkArguments"]);
1493
 
1494
		#如果檢查失敗
1495
		if($checkArguments["status"]==="false"){
1496
 
1497
			#設置錯誤識別
1498
			$result["status"]="false";
1499
 
1500
			#設置錯誤訊息
1501
			$result["error"]=$checkArguments;
1502
 
1503
			#回傳結果
1504
			return $result;
1505
 
1506
			}#if end
1507
 
1508
		#如果檢查不通過
1509
		if($checkArguments["passed"]==="false"){
1510
 
1511
			#設置錯誤識別
1512
			$result["status"]="false";
1513
 
1514
			#設置錯誤訊息
1515
			$result["error"]=$checkArguments;
1516
 
1517
			#回傳結果
1518
			return $result;
1519
 
1520
			}#if end
1521
 
1522
		#初始化要回傳的content
1523
		$result["content"]=array();
1524
 
1525
		#另存一份要處理的RR
1526
		$unFormatStr=$conf["line"];
1527
 
1528
		#初始化該行的資訊陣列
1529
		$info=array();
1530
 
1531
		#尋找";"開頭的內容,亦即整行都是註解.
1532
		#函式說明:
1533
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1534
		#回傳結果:
1535
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1536
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1537
		#$result["function"],當前執行的函式名稱.
1538
		#$result["argu"],所使用的參數.
1539
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1540
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1541
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1542
		#必填參數:
1543
		#$conf["input"],字串,要檢查的字串.
1544
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1545
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1546
		$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
1547
		#可省略參數:
1548
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1549
		#$conf["varEqual"]=array(null,"found");
1550
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1551
		#$conf["varCon"]=array("no_tail"=>" not");
1552
		#參考資料:
1553
		#無.
1554
		#備註:
1555
		#無.
1556
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1557
		unset($conf["search::findSpecifyStrFormat"]);
1558
 
1559
		#如果執行異常
1560
		if($findSpecifyStrFormat["status"]==="false"){
1561
 
1562
			#設置錯誤識別
1563
			$result["status"]="false";
1564
 
1565
			#設置錯誤訊息
1566
			$result["error"]=$findSpecifyStrFormat;
1567
 
1568
			#回傳結果
1569
			return $result;
1570
 
1571
			}#if end
1572
 
1573
		#如果有找到符合格式的內容
1574
		if($findSpecifyStrFormat["found"]==="true"){
1575
 
1576
			#儲存為註解
1577
			$result["comment"]=$unFormatStr;
1578
 
1579
			#設置執行正常
1580
			$result["status"]="true";
1581
 
1582
			#回傳結果
1583
			return $result;
1584
 
1585
			}#if end
1586
 
1587
		#函式說明:
1588
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1589
		#回傳結果:
1590
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1591
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1592
		#$result["function"],當前執行的函式名稱.
1593
		#$result["argu"],所使用的參數.
1594
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1595
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1596
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1597
		#必填參數:
1598
		#$conf["input"],字串,要檢查的字串.
1599
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1600
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1601
		$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
1602
		#可省略參數:
1603
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1604
		#$conf["varEqual"]=array(null,"found");
1605
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1606
		#$conf["varCon"]=array("no_tail"=>" not");
1607
		#參考資料:
1608
		#無.
1609
		#備註:
1610
		#無.
1611
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1612
		unset($conf["search::findSpecifyStrFormat"]);
1613
 
1614
		#如果執行異常
1615
		if($findSpecifyStrFormat["status"]==="false"){
1616
 
1617
			#設置錯誤識別
1618
			$result["status"]="false";
1619
 
1620
			#設置錯誤訊息
1621
			$result["error"]=$findSpecifyStrFormat;
1622
 
1623
			#回傳結果
1624
			return $result;
1625
 
1626
			}#if end
1627
 
1628
		#如果有找到符合格式的內容
1629
		if($findSpecifyStrFormat["found"]==="true"){
1630
 
1631
			#設置 type 的數值
1632
			$info["type"]="\$ORIGIN";
1633
 
1634
			#取得後面待處理的內容
1635
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
1636
 
1637
			#函式說明:
1638
			#將字串開頭的特定關鍵字移除.
1639
			#回傳結果:
1640
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1641
			#$result["error"],錯誤訊息陣列.
1642
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
1643
			#$result["function"],當前執行的函數名稱.
1644
			#$result["argu"],使用的參數.
1645
			#$result["content"],處理好的的字串內容.
1646
			#$result["deleted"],被移除的內容.
1647
			#必填參數:
1648
			#$conf["stringIn"],字串,要處理的字串.
1649
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
1650
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
1651
			$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
1652
			#可省略參數:
1653
			#無.
1654
			#參考資料:
1655
			#無.
1656
			#備註:
1657
			#無.
1658
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
1659
			unset($conf["stringProcess::delHeadStr"]);
1660
 
1661
			#如果執行異常
1662
			if($delHeadStr["status"]==="false"){
1663
 
1664
				#設置錯誤識別
1665
				$result["status"]="false";
1666
 
1667
				#設置錯誤訊息
1668
				$result["error"]=$delHeadStr;
1669
 
1670
				#回傳結果
1671
				return $result;
1672
 
1673
				}#if end
1674
 
1675
			#如果有移除開頭的字串
1676
			if($delHeadStr["founded"]==="true"){
1677
 
1678
				#取得處理後的結果
1679
				$unFormatStr=$delHeadStr["content"];
1680
 
1681
				}#if end
1682
 
1683
			#解析 $ORIGN 的數值, 以及後面是否有註解...
1684
			#函式說明:
1685
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1686
			#回傳結果:
1687
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1688
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1689
			#$result["function"],當前執行的函式名稱.
1690
			#$result["argu"],所使用的參數.
1691
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1692
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1693
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1694
			#必填參數:
1695
			#$conf["input"],字串,要檢查的字串.
1696
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1697
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1698
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
1699
			#可省略參數:
1700
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1701
			#$conf["varEqual"]=array(null,"found");
1702
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1703
			#$conf["varCon"]=array("no_tail"=>" not");
1704
			#參考資料:
1705
			#無.
1706
			#備註:
1707
			#無.
1708
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1709
			unset($conf["search::findSpecifyStrFormat"]);
1710
 
1711
			#如果執行異常
1712
			if($findSpecifyStrFormat["status"]==="false"){
1713
 
1714
				#設置錯誤識別
1715
				$result["status"]="false";
1716
 
1717
				#設置錯誤訊息
1718
				$result["error"]=$findSpecifyStrFormat;
1719
 
1720
				#回傳結果
1721
				return $result;
1722
 
1723
				}#if end
1724
 
1725
			#如果有數值跟註解
1726
			if($findSpecifyStrFormat["found"]==="true"){
1727
 
1728
				#儲存數值
1729
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
1730
 
1731
				#儲存zone domain
1732
				$result["domain"]=trim($info["value"]);
1733
 
1734
				#儲存註解
1735
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
1736
 
1737
				#儲存 RR 的記錄
1738
				$result["content"]=$info;
1739
 
1740
				#設置執行正常
1741
				$result["status"]="true";
1742
 
1743
				#回傳結果
1744
				return $result;
1745
 
1746
				}#if end
1747
 
1748
			#執行到這邊代表剩下的內容都是 value
1749
			$info["value"]=$unFormatStr;
1750
 
1751
			#儲存zone domain
1752
			$result["domain"]=trim($info["value"]);
1753
 
1754
			#儲存 RR 的記錄
1755
			$result["content"]=$info;
1756
 
1757
			#設置執行正常
1758
			$result["status"]="true";
1759
 
1760
			#回傳結果
1761
			return $result;
1762
 
1763
			}#if end
1764
 
1765
		#檢查是否為 $TTL 開頭
1766
		#函式說明:
1767
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1768
		#回傳結果:
1769
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1770
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1771
		#$result["function"],當前執行的函式名稱.
1772
		#$result["argu"],所使用的參數.
1773
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1774
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1775
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1776
		#必填參數:
1777
		#$conf["input"],字串,要檢查的字串.
1778
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1779
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1780
		$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
1781
		#可省略參數:
1782
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1783
		#$conf["varEqual"]=array(null,"found");
1784
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1785
		#$conf["varCon"]=array("no_tail"=>" not");
1786
		#參考資料:
1787
		#無.
1788
		#備註:
1789
		#無.
1790
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1791
		unset($conf["search::findSpecifyStrFormat"]);
1792
 
1793
		#如果執行異常
1794
		if($findSpecifyStrFormat["status"]==="false"){
1795
 
1796
			#設置錯誤識別
1797
			$result["status"]="false";
1798
 
1799
			#設置錯誤訊息
1800
			$result["error"]=$findSpecifyStrFormat;
1801
 
1802
			#回傳結果
1803
			return $result;
1804
 
1805
			}#if end
1806
 
1807
		#如果有找到符合格式的內容
1808
		if($findSpecifyStrFormat["found"]==="true"){
1809
 
1810
			#設置 type 的數值
1811
			$info["type"]="\$TTL";
1812
 
1813
			#取得後面待處理的內容
1814
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
1815
 
1816
			#函式說明:
1817
			#將字串開頭的特定關鍵字移除.
1818
			#回傳結果:
1819
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1820
			#$result["error"],錯誤訊息陣列.
1821
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
1822
			#$result["function"],當前執行的函數名稱.
1823
			#$result["argu"],使用的參數.
1824
			#$result["content"],處理好的的字串內容.
1825
			#$result["deleted"],被移除的內容.
1826
			#必填參數:
1827
			#$conf["stringIn"],字串,要處理的字串.
1828
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
1829
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
1830
			$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
1831
			#可省略參數:
1832
			#無.
1833
			#參考資料:
1834
			#無.
1835
			#備註:
1836
			#無.
1837
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
1838
			unset($conf["stringProcess::delHeadStr"]);
1839
 
1840
			#如果執行異常
1841
			if($delHeadStr["status"]==="false"){
1842
 
1843
				#設置錯誤識別
1844
				$result["status"]="false";
1845
 
1846
				#設置錯誤訊息
1847
				$result["error"]=$delHeadStr;
1848
 
1849
				#回傳結果
1850
				return $result;
1851
 
1852
				}#if end
1853
 
1854
			#如果有移除開頭的字串
1855
			if($delHeadStr["founded"]==="true"){
1856
 
1857
				#取得處理後的結果
1858
				$unFormatStr=$delHeadStr["content"];
1859
 
1860
				}#if end
1861
 
1862
			#解析 $TTL 的數值, 以及後面是否有註解...
1863
			#函式說明:
1864
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1865
			#回傳結果:
1866
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1867
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1868
			#$result["function"],當前執行的函式名稱.
1869
			#$result["argu"],所使用的參數.
1870
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1871
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1872
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1873
			#必填參數:
1874
			#$conf["input"],字串,要檢查的字串.
1875
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1876
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1877
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
1878
			#可省略參數:
1879
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1880
			#$conf["varEqual"]=array(null,"found");
1881
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1882
			#$conf["varCon"]=array("no_tail"=>" not");
1883
			#參考資料:
1884
			#無.
1885
			#備註:
1886
			#無.
1887
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1888
			unset($conf["search::findSpecifyStrFormat"]);
1889
 
1890
			#如果執行異常
1891
			if($findSpecifyStrFormat["status"]==="false"){
1892
 
1893
				#設置錯誤識別
1894
				$result["status"]="false";
1895
 
1896
				#設置錯誤訊息
1897
				$result["error"]=$findSpecifyStrFormat;
1898
 
1899
				#回傳結果
1900
				return $result;
1901
 
1902
				}#if end
1903
 
1904
			#如果有數值跟註解
1905
			if($findSpecifyStrFormat["found"]==="true"){
1906
 
1907
				#儲存數值
1908
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
1909
 
1910
				#儲存註解
1911
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
1912
 
1913
				#儲存預設的 TTL
1914
				$result["defaultTTL"]=trim($info["value"]);
1915
 
1916
				#儲存 RR 的記錄
1917
				$result["content"]=$info;
1918
 
1919
				#設置執行正常
1920
				$result["status"]="true";
1921
 
1922
				#回傳結果
1923
				return $result;
1924
 
1925
				}#if end
1926
 
1927
			#執行到這邊代表剩下的內容都是 value
1928
			$info["value"]=$unFormatStr;
1929
 
1930
			#儲存預設的 TTL
1931
			$result["defaultTTL"]=trim($info["value"]);
1932
 
1933
			#儲存 RR 的記錄
1934
			$result["content"]=$info;
1935
 
1936
			#設置執行正常
1937
			$result["status"]="true";
1938
 
1939
			#回傳結果
1940
			return $result;
1941
 
1942
			}#if end
1943
 
1944
		#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
1945
 
1946
		#函式說明:
1947
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1948
		#回傳結果:
1949
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1950
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1951
		#$result["function"],當前執行的函式名稱.
1952
		#$result["argu"],所使用的參數.
1953
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1954
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1955
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
1956
		#必填參數:
1957
		#$conf["input"],字串,要檢查的字串.
1958
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1959
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1960
		$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
1961
		#可省略參數:
1962
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1963
		#$conf["varEqual"]=array(null,"found");
1964
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1965
		#$conf["varCon"]=array("no_tail"=>" not");
1966
		#參考資料:
1967
		#無.
1968
		#備註:
1969
		#無.
1970
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1971
		unset($conf["search::findSpecifyStrFormat"]);
1972
 
1973
		#如果執行異常
1974
		if($findSpecifyStrFormat["status"]==="false"){
1975
 
1976
			#設置錯誤識別
1977
			$result["status"]="false";
1978
 
1979
			#設置錯誤訊息
1980
			$result["error"]=$findSpecifyStrFormat;
1981
 
1982
			#回傳結果
1983
			return $result;
1984
 
1985
			}#if end
1986
 
1987
		#如果存在"("
1988
		if($findSpecifyStrFormat["found"]==="true"){
1989
 
1990
			#取得無"("的內容
1991
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
1992
 
1993
			#取得拆下來的含開頭"("內容
1994
			$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
1995
 
1996
			}#if end
1997
 
1998
		#反之
1999
		else{
2000
 
2001
			#函式說明:
2002
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2003
			#回傳結果:
2004
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2005
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2006
			#$result["function"],當前執行的函式名稱.
2007
			#$result["argu"],所使用的參數.
2008
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2009
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2010
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2011
			#必填參數:
2012
			#$conf["input"],字串,要檢查的字串.
2013
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2014
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2015
			$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
2016
			#可省略參數:
2017
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2018
			#$conf["varEqual"]=array(null,"found");
2019
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2020
			#$conf["varCon"]=array("no_tail"=>" not");
2021
			#參考資料:
2022
			#無.
2023
			#備註:
2024
			#無.
2025
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2026
			unset($conf["search::findSpecifyStrFormat"]);
2027
 
2028
			#如果執行異常
2029
			if($findSpecifyStrFormat["status"]==="false"){
2030
 
2031
				#設置錯誤識別
2032
				$result["status"]="false";
2033
 
2034
				#設置錯誤訊息
2035
				$result["error"]=$findSpecifyStrFormat;
2036
 
2037
				#回傳結果
2038
				return $result;
2039
 
2040
				}#if end
2041
 
2042
			#如果存在"
2043
			if($findSpecifyStrFormat["found"]==="true"){
2044
 
2045
				#取得無"的內容
2046
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2047
 
2048
				#取得拆下來的含開頭"內容
2049
				$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
2050
 
2051
				}#if end
2052
 
2053
			#反之
2054
			else{
2055
 
2056
				#函式說明:
2057
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2058
				#回傳結果:
2059
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2060
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2061
				#$result["function"],當前執行的函式名稱.
2062
				#$result["argu"],所使用的參數.
2063
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2064
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2065
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2066
				#必填參數:
2067
				#$conf["input"],字串,要檢查的字串.
2068
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2069
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2070
				$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
2071
				#可省略參數:
2072
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2073
				#$conf["varEqual"]=array(null,"found");
2074
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2075
				#$conf["varCon"]=array("no_tail"=>" not");
2076
				#參考資料:
2077
				#無.
2078
				#備註:
2079
				#無.
2080
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2081
				unset($conf["search::findSpecifyStrFormat"]);
2082
 
2083
				#如果執行異常
2084
				if($findSpecifyStrFormat["status"]==="false"){
2085
 
2086
					#設置錯誤識別
2087
					$result["status"]="false";
2088
 
2089
					#設置錯誤訊息
2090
					$result["error"]=$findSpecifyStrFormat;
2091
 
2092
					#回傳結果
2093
					return $result;
2094
 
2095
					}#if end
2096
 
2097
				#如果存在";"
2098
				if($findSpecifyStrFormat["found"]==="true"){
2099
 
2100
					#取得無";"的內容
2101
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2102
 
2103
					#取得拆下來的含開頭";"內容
2104
					$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
2105
 
2106
					}#if end
2107
 
2108
				}#else end
2109
 
2110
			}#else end
2111
 
2112
		#檢查是否為 @ 開頭
2113
		#函式說明:
2114
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2115
		#回傳結果:
2116
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2117
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2118
		#$result["function"],當前執行的函式名稱.
2119
		#$result["argu"],所使用的參數.
2120
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2121
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2122
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2123
		#必填參數:
2124
		#$conf["input"],字串,要檢查的字串.
2125
		$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2126
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2127
		$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
2128
		#可省略參數:
2129
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2130
		#$conf["varEqual"]=array(null,"found");
2131
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2132
		#$conf["varCon"]=array("no_tail"=>" not");
2133
		#參考資料:
2134
		#無.
2135
		#備註:
2136
		#無.
2137
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2138
		unset($conf["search::findSpecifyStrFormat"]);
2139
 
2140
		#如果執行異常
2141
		if($findSpecifyStrFormat["status"]==="false"){
2142
 
2143
			#設置錯誤識別
2144
			$result["status"]="false";
2145
 
2146
			#設置錯誤訊息
2147
			$result["error"]=$findSpecifyStrFormat;
2148
 
2149
			#回傳結果
2150
			return $result;
2151
 
2152
			}#if end
2153
 
2154
		#如果有找到符合格式的內容
2155
		if($findSpecifyStrFormat["found"]==="true"){
2156
 
2157
			#設置 query 的數值
2158
			$info["query"]="@";
2159
 
2160
			#取得後面待處理的內容
2161
			$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
2162
 
2163
			#函式說明:
2164
			#將字串開頭的特定關鍵字移除.
2165
			#回傳結果:
2166
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2167
			#$result["error"],錯誤訊息陣列.
2168
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2169
			#$result["function"],當前執行的函數名稱.
2170
			#$result["argu"],使用的參數.
2171
			#$result["content"],處理好的的字串內容.
2172
			#$result["deleted"],被移除的內容.
2173
			#必填參數:
2174
			#$conf["stringIn"],字串,要處理的字串.
2175
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2176
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2177
			$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
2178
			#可省略參數:
2179
			#無.
2180
			#參考資料:
2181
			#無.
2182
			#備註:
2183
			#無.
2184
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2185
			unset($conf["stringProcess::delHeadStr"]);
2186
 
2187
			#如果執行異常
2188
			if($delHeadStr["status"]==="false"){
2189
 
2190
				#設置錯誤識別
2191
				$result["status"]="false";
2192
 
2193
				#設置錯誤訊息
2194
				$result["error"]=$delHeadStr;
2195
 
2196
				#回傳結果
2197
				return $result;
2198
 
2199
				}#if end
2200
 
2201
			#如果有移除開頭的字串
2202
			if($delHeadStr["founded"]==="true"){
2203
 
2204
				#取得處理後的結果 update time..IN..type...value;comment
2205
				$unFormatStr=$delHeadStr["content"];
2206
 
2207
				}#if end
2208
 
2209
			#debug
2210
			#var_dump(__LINE__,$delHeadStr);
2211
 
2212
			}#if end
2213
 
2214
		#反之
2215
		else{
2216
 
2217
			#執行到這邊,代表 query 為一非 @ 的字串
2218
			#函式說明:
2219
			#將指令字串解析成陣列,方便給予 external::callShell 使用
2220
			#回傳結果:
2221
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2222
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2223
			#$result["function"],當前執行的函式名稱.
2224
			#$result["content"],解析好的指令陣列.
2225
			#$result["cmd"],解析好的指令名稱.
2226
			#$result["argus"],解析好的參數陣列.
2227
			#$result["argu"],所使用的參數.
2228
			#必填參數
2229
			#$conf["cmdStr"],字串,要解析的指令字串
2230
			$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
2231
			#可省略參數:
2232
			#無.
2233
			#參考資料:
2234
			#無.
2235
			#備註:
2236
			#無.
2237
			$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
2238
			unset($conf["stringProcess::parseCmdString"]);
2239
 
2240
			#如果執行失敗
2241
			if($parseCmdString["status"]==="false"){
2242
 
2243
				#設置錯誤識別
2244
				$result["status"]="false";
2245
 
2246
				#設置錯誤訊息
2247
				$result["error"]=$parseCmdString;
2248
 
2249
				#debug
2250
				#$result["errorProcessLine"]=$line;
2251
 
2252
				#回傳結果
2253
				return $result;
2254
 
2255
				}#if end
2256
 
2257
			#取得 query 的內容
2258
			$info["query"]=$parseCmdString["content"][0];
2259
 
2260
			#剔除 query以及後面的" "跟\t
2261
			#函式說明:
2262
			#將字串開頭的特定關鍵字移除.
2263
			#回傳結果:
2264
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2265
			#$result["error"],錯誤訊息陣列.
2266
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2267
			#$result["function"],當前執行的函數名稱.
2268
			#$result["argu"],使用的參數.
2269
			#$result["content"],處理好的的字串內容.
2270
			#$result["deleted"],被移除的內容.
2271
			#必填參數:
2272
			#$conf["stringIn"],字串,要處理的字串.
2273
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2274
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2275
			$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
2276
			#可省略參數:
2277
			#無.
2278
			#參考資料:
2279
			#無.
2280
			#備註:
2281
			#無.
2282
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2283
			unset($conf["stringProcess::delHeadStr"]);
2284
 
2285
			#如果執行異常
2286
			if($delHeadStr["status"]==="false"){
2287
 
2288
				#設置錯誤識別
2289
				$result["status"]="false";
2290
 
2291
				#設置錯誤訊息
2292
				$result["error"]=$delHeadStr;
2293
 
2294
				#回傳結果
2295
				return $result;
2296
 
2297
				}#if end
2298
 
2299
			#取得update time..IN..type...value;comment
2300
			$unFormatStr=$delHeadStr["content"];
2301
 
2302
			}#else end
2303
 
2304
		#無窮迴圈
2305
		while(true){
2306
 
2307
			#解析 updateTime..IN..type...value...comment
2308
 
2309
			#判斷是否無 update time
2310
 
2311
			#函式說明:
2312
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2313
			#回傳結果:
2314
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2315
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2316
			#$result["function"],當前執行的函式名稱.
2317
			#$result["argu"],所使用的參數.
2318
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2319
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2320
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2321
			#必填參數:
2322
			#$conf["input"],字串,要檢查的字串.
2323
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2324
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2325
			$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
2326
			#可省略參數:
2327
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2328
			#$conf["varEqual"]=array(null,"found");
2329
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2330
			#$conf["varCon"]=array("no_tail"=>" not");
2331
			#參考資料:
2332
			#無.
2333
			#備註:
2334
			#無.
2335
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2336
			unset($conf["search::findSpecifyStrFormat"]);
2337
 
2338
			#如果執行異常
2339
			if($findSpecifyStrFormat["status"]==="false"){
2340
 
2341
				#設置錯誤識別
2342
				$result["status"]="false";
2343
 
2344
				#設置錯誤訊息
2345
				$result["error"]=$findSpecifyStrFormat;
2346
 
2347
				#回傳結果
2348
				return $result;
2349
 
2350
				}#if end
2351
 
2352
			#如果有找到符合格式的內容
2353
			if($findSpecifyStrFormat["found"]==="true"){
2354
 
2355
				#代表沒有 update time 欄位,因此儲存預設的TTL
2356
				$info["update"]=&$result["defaultTTL"];
2357
 
2358
				#取得剩下的 ...type...value;comment
2359
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
2360
 
2361
				#設置該行沒有指定 update time
2362
				$noUpdateTime="true";
2363
 
2364
				}#if end
2365
 
2366
			#反之
2367
			else{
2368
 
2369
				#設置該行有指定 update time
2370
				$noUpdateTime="false";
2371
 
2372
				#如果有指定 update time
2373
				if($noUpdateTime==="false"){
2374
 
2375
					#要來解析 update time
2376
					#函式說明:
2377
					#將字串進行解析,變成多個參數.
2378
					#回傳結果:
2379
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2380
					#$result["function"],當前執行的函式內容.
2381
					#$result["error"],錯誤訊息陣列.
2382
					#$result["content"],參數陣列.
2383
					#$result["count"],總共有幾個參數.
2384
					#必填參數:
2385
					#$conf["input"],字串,要解析成參數的字串.
2386
					$conf["stringProcess::parse"]["input"]=$unFormatStr;
2387
					#可省略參數:
2388
					#無.
2389
					#參考資料:
2390
					#無.
2391
					#備註:
2392
					#無.
2393
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
2394
					unset($conf["stringProcess::parse"]);
2395
 
2396
					#如果執行異常
2397
					if($parse["status"]==="false"){
2398
 
2399
						#設置錯誤識別
2400
						$result["status"]="false";
2401
 
2402
						#設置錯誤訊息
2403
						$result["error"]=$parse;
2404
 
2405
						#回傳結果
2406
						return $result;
2407
 
2408
						}#if end
2409
 
2410
					#取得更新時間
2411
					$info["update"]=$parse["content"][0];
2412
 
2413
					#取得 update time 後面的內容
2414
					#函式說明:
2415
					#將字串開頭的特定關鍵字移除.
2416
					#回傳結果:
2417
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2418
					#$result["error"],錯誤訊息陣列.
2419
					#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2420
					#$result["function"],當前執行的函數名稱.
2421
					#$result["argu"],使用的參數.
2422
					#$result["content"],處理好的的字串內容.
2423
					#$result["deleted"],被移除的內容.
2424
					#必填參數:
2425
					#$conf["stringIn"],字串,要處理的字串.
2426
					$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2427
					#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2428
					$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
2429
					#可省略參數:
2430
					#無.
2431
					#參考資料:
2432
					#無.
2433
					#備註:
2434
					#無.
2435
					$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2436
					unset($conf["stringProcess::delHeadStr"]);
2437
 
2438
					#如果執行異常
2439
					if($delHeadStr["status"]==="false"){
2440
 
2441
						#設置錯誤識別
2442
						$result["status"]="false";
2443
 
2444
						#設置錯誤訊息
2445
						$result["error"]=$delHeadStr;
2446
 
2447
						#回傳結果
2448
						return $result;
2449
 
2450
						}#if end
2451
 
2452
					#取得...IN...value;comment
2453
					$unFormatStr=$delHeadStr["content"];
2454
 
2455
					}#if end
2456
 
2457
				#取得 ...IN... 後面的內容
2458
				#函式說明:
2459
				#將字串開頭的特定關鍵字移除.
2460
				#回傳結果:
2461
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2462
				#$result["error"],錯誤訊息陣列.
2463
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2464
				#$result["function"],當前執行的函數名稱.
2465
				#$result["argu"],使用的參數.
2466
				#$result["content"],處理好的的字串內容.
2467
				#$result["deleted"],被移除的內容.
2468
				#必填參數:
2469
				#$conf["stringIn"],字串,要處理的字串.
2470
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2471
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2472
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
2473
				#可省略參數:
2474
				#無.
2475
				#參考資料:
2476
				#無.
2477
				#備註:
2478
				#無.
2479
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2480
				unset($conf["stringProcess::delHeadStr"]);
2481
 
2482
				#如果執行異常
2483
				if($delHeadStr["status"]==="false"){
2484
 
2485
					#設置錯誤識別
2486
					$result["status"]="false";
2487
 
2488
					#設置錯誤訊息
2489
					$result["error"]=$delHeadStr;
2490
 
2491
					#回傳結果
2492
					return $result;
2493
 
2494
					}#if end
2495
 
2496
				#取得IN...value;comment
2497
				$unFormatStr=$delHeadStr["content"];
2498
 
2499
				}#else end
2500
 
2501
			#解析 type...value;comment
2502
			#函式說明:
2503
			#將字串進行解析,變成多個參數.
2504
			#回傳結果:
2505
			#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2506
			#$result["function"],當前執行的函式內容.
2507
			#$result["error"],錯誤訊息陣列.
2508
			#$result["content"],參數陣列.
2509
			#$result["count"],總共有幾個參數.
2510
			#必填參數:
2511
			#$conf["input"],字串,要解析成參數的字串.
2512
			$conf["stringProcess::parse"]["input"]=$unFormatStr;
2513
			#可省略參數:
2514
			#無.
2515
			#參考資料:
2516
			#無.
2517
			#備註:
2518
			#無.
2519
			$parse=stringProcess::parse($conf["stringProcess::parse"]);
2520
			unset($conf["stringProcess::parse"]);
2521
 
2522
			#如果執行異常
2523
			if($parse["status"]==="false"){
2524
 
2525
				#設置錯誤識別
2526
				$result["status"]="false";
2527
 
2528
				#設置錯誤訊息
2529
				$result["error"]=$parse;
2530
 
2531
				#回傳結果
2532
				return $result;
2533
 
2534
				}#if end
2535
 
2536
			#取得 type
2537
			$info["type"]=$parse["content"][0];
2538
 
2539
			#取得 type...後面的value;comment內容
2540
			#函式說明:
2541
			#將字串開頭的特定關鍵字移除.
2542
			#回傳結果:
2543
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2544
			#$result["error"],錯誤訊息陣列.
2545
			#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2546
			#$result["function"],當前執行的函數名稱.
2547
			#$result["argu"],使用的參數.
2548
			#$result["content"],處理好的的字串內容.
2549
			#$result["deleted"],被移除的內容.
2550
			#必填參數:
2551
			#$conf["stringIn"],字串,要處理的字串.
2552
			$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2553
			#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2554
			$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
2555
			#可省略參數:
2556
			#無.
2557
			#參考資料:
2558
			#無.
2559
			#備註:
2560
			#無.
2561
			$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2562
			unset($conf["stringProcess::delHeadStr"]);
2563
 
2564
			#如果執行異常
2565
			if($delHeadStr["status"]==="false"){
2566
 
2567
				#設置錯誤識別
2568
				$result["status"]="false";
2569
 
2570
				#設置錯誤訊息
2571
				$result["error"]=$delHeadStr;
2572
 
2573
				#回傳結果
2574
				return $result;
2575
 
2576
				}#if end
2577
 
2578
			#取得 value;comment
2579
			$unFormatStr=$delHeadStr["content"];
2580
 
2581
			#如果有要合併回去的內容
2582
			if(isset($unFormatStr2add)){
2583
 
2584
				#合併回去內容
2585
				$unFormatStr=$unFormatStr.$unFormatStr2add;
2586
 
2587
				#移除用不到的變數
2588
				unset($unFormatStr2add);
2589
 
2590
				}#if end
2591
 
2592
			#如果type不為 CNAME 跟 TXT 跟 SOA
404 liveuser 2593
			if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" && $info["type"]!=="CAA"){
291 liveuser 2594
 
2595
				#儲存value
2596
				$info["value"]=$unFormatStr;
2597
 
2598
				#判斷是否有 ";" 存在
2599
				#函式說明:
2600
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2601
				#回傳結果:
2602
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2603
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2604
				#$result["function"],當前執行的函式名稱.
2605
				#$result["argu"],所使用的參數.
2606
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2607
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2608
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2609
				#必填參數:
2610
				#$conf["input"],字串,要檢查的字串.
2611
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2612
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2613
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
2614
				#可省略參數:
2615
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2616
				#$conf["varEqual"]=array(null,"found");
2617
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2618
				#$conf["varCon"]=array("no_tail"=>" not");
2619
				#參考資料:
2620
				#無.
2621
				#備註:
2622
				#無.
2623
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2624
				unset($conf["search::findSpecifyStrFormat"]);
2625
 
2626
				#如果執行異常
2627
				if($findSpecifyStrFormat["status"]==="false"){
2628
 
2629
					#設置錯誤識別
2630
					$result["status"]="false";
2631
 
2632
					#設置錯誤訊息
2633
					$result["error"]=$findSpecifyStrFormat;
2634
 
2635
					#回傳結果
2636
					return $result;
2637
 
2638
					}#if end
2639
 
2640
				#如果有 ";"
2641
				if($findSpecifyStrFormat["found"]==="true"){
2642
 
2643
					#儲存value
2644
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
2645
 
2646
					#儲存comment
2647
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
2648
 
2649
					}#if end
2650
 
2651
				#儲存 RR 的記錄
2652
				$result["content"]=$info;
2653
 
2654
				#設置執行正常
2655
				$result["status"]="true";
2656
 
2657
				#回傳結果
2658
				return $result;
2659
 
2660
				}#if end
2661
 
404 liveuser 2662
			#執行到這邊,代表type為CNAME或TXT或SOA或CAA
291 liveuser 2663
 
2664
			#如果 type 是 SOA
2665
			if($info["type"]==="SOA"){
2666
 
2667
				#如果要debug
2668
				if($conf["debug"]==="true"){
2669
 
2670
					#函式說明:
2671
					#撰寫log
2672
					#回傳結果:
2673
					#$result["status"],狀態,"true"或"false".
2674
					#$result["error"],錯誤訊息陣列.
2675
					#$result["function"],當前函式的名稱.
2676
					#$result["argu"],使用的參數.
2677
					#$result["content"],要寫入log的內容字串.
2678
					#必填參數:
2679
					#$conf["path"],字串,log檔案的路徑與名稱.
2680
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2681
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2682
					$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
2683
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2684
					$conf["logs::record"]["fileArgu"]=__FILE__;
2685
					#可省略參數:
2686
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2687
					#$conf["rewrite"]="false";
2688
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2689
					#$conf["returnOnly"]="true";
2690
					#參考資料:
2691
					#無.
2692
					#備註:
2693
					#無.
2694
					$record=logs::record($conf["logs::record"]);
2695
					unset($conf["logs::record"]);
2696
 
2697
					}#if end
2698
 
2699
				#SOA 範例
2700
				#@	1200	IN	SOA	dns.qbpwcf.org. liveuser.qbpwcf.org. 2026012205 10800 1800 1728000 1200 ;domain name server, admin mail, serial, refresh time, expire, Negative Caching, https://bind9.readthedocs.io/en/latest/chapter3.html#term-SOA-minimum
2701
 
2702
				#再度嘗試分割
2703
				#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
2704
 
2705
				#函式說明:
2706
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2707
				#回傳結果:
2708
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2709
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2710
				#$result["function"],當前執行的函式名稱.
2711
				#$result["argu"],所使用的參數.
2712
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2713
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2714
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2715
				#必填參數:
2716
				#$conf["input"],字串,要檢查的字串.
2717
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2718
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2719
				$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
2720
				#可省略參數:
2721
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2722
				#$conf["varEqual"]=array(null,"found");
2723
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2724
				#$conf["varCon"]=array("no_tail"=>" not");
2725
				#參考資料:
2726
				#無.
2727
				#備註:
2728
				#無.
2729
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2730
				unset($conf["search::findSpecifyStrFormat"]);
2731
 
2732
				#如果執行異常
2733
				if($findSpecifyStrFormat["status"]==="false"){
2734
 
2735
					#設置錯誤識別
2736
					$result["status"]="false";
2737
 
2738
					#設置錯誤訊息
2739
					$result["error"]=$findSpecifyStrFormat;
2740
 
2741
					#回傳結果
2742
					return $result;
2743
 
2744
					}#if end
2745
 
2746
				#如果存在"("
2747
				if($findSpecifyStrFormat["found"]==="true"){
2748
 
2749
					#取得無"("的內容
2750
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2751
 
2752
					#取得拆下來的含開頭"("內容
2753
					$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
2754
 
2755
					}#if end
2756
 
2757
				#反之
2758
				else{
2759
 
2760
					#函式說明:
2761
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2762
					#回傳結果:
2763
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2764
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2765
					#$result["function"],當前執行的函式名稱.
2766
					#$result["argu"],所使用的參數.
2767
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2768
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2769
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2770
					#必填參數:
2771
					#$conf["input"],字串,要檢查的字串.
2772
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2773
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2774
					$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
2775
					#可省略參數:
2776
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2777
					#$conf["varEqual"]=array(null,"found");
2778
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2779
					#$conf["varCon"]=array("no_tail"=>" not");
2780
					#參考資料:
2781
					#無.
2782
					#備註:
2783
					#無.
2784
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2785
					unset($conf["search::findSpecifyStrFormat"]);
2786
 
2787
					#如果執行異常
2788
					if($findSpecifyStrFormat["status"]==="false"){
2789
 
2790
						#設置錯誤識別
2791
						$result["status"]="false";
2792
 
2793
						#設置錯誤訊息
2794
						$result["error"]=$findSpecifyStrFormat;
2795
 
2796
						#回傳結果
2797
						return $result;
2798
 
2799
						}#if end
2800
 
2801
					#如果存在"
2802
					if($findSpecifyStrFormat["found"]==="true"){
2803
 
2804
						#取得無"的內容
2805
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2806
 
2807
						#取得拆下來的含開頭"內容
2808
						$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
2809
 
2810
						}#if end
2811
 
2812
					#反之
2813
					else{
2814
 
2815
						#函式說明:
2816
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2817
						#回傳結果:
2818
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2819
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
2820
						#$result["function"],當前執行的函式名稱.
2821
						#$result["argu"],所使用的參數.
2822
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2823
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2824
						#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2825
						#必填參數:
2826
						#$conf["input"],字串,要檢查的字串.
2827
						$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2828
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2829
						$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
2830
						#可省略參數:
2831
						#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2832
						#$conf["varEqual"]=array(null,"found");
2833
						#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2834
						#$conf["varCon"]=array("no_tail"=>" not");
2835
						#參考資料:
2836
						#無.
2837
						#備註:
2838
						#無.
2839
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2840
						unset($conf["search::findSpecifyStrFormat"]);
2841
 
2842
						#如果執行異常
2843
						if($findSpecifyStrFormat["status"]==="false"){
2844
 
2845
							#設置錯誤識別
2846
							$result["status"]="false";
2847
 
2848
							#設置錯誤訊息
2849
							$result["error"]=$findSpecifyStrFormat;
2850
 
2851
							#回傳結果
2852
							return $result;
2853
 
2854
							}#if end
2855
 
2856
						#如果存在";"
2857
						if($findSpecifyStrFormat["found"]==="true"){
2858
 
2859
							#取得無";"的內容
2860
							$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2861
 
2862
							#取得拆下來的含開頭";"內容
2863
							$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
2864
 
2865
							}#if end
2866
 
2867
						}#else end
2868
 
2869
					}#else end
2870
 
2871
				#取得 serial number
2872
				#函式說明:
2873
				#將字串進行解析,變成多個參數.
2874
				#回傳結果:
2875
				#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2876
				#$result["function"],當前執行的函式內容.
2877
				#$result["error"],錯誤訊息陣列.
2878
				#$result["content"],參數陣列.
2879
				#$result["count"],總共有幾個參數.
2880
				#必填參數:
2881
				#$conf["input"],字串,要解析成參數的字串.
2882
				$conf["stringProcess::parse"]["input"]=$unFormatStr;
2883
				#可省略參數:
2884
				#無.
2885
				#參考資料:
2886
				#無.
2887
				#備註:
2888
				#無.
2889
				$parse=stringProcess::parse($conf["stringProcess::parse"]);
2890
				unset($conf["stringProcess::parse"]);
2891
 
2892
				#如果執行異常
2893
				if($parse["status"]==="false"){
2894
 
2895
					#設置錯誤識別
2896
					$result["status"]="false";
2897
 
2898
					#設置錯誤訊息
2899
					$result["error"]=$parse;
2900
 
2901
					#回傳結果
2902
					return $result;
2903
 
2904
					}#if end
2905
 
2906
				#取得serial number
2907
				$serialNo=$parse["content"][2];
2908
 
2909
				#serialNo+1
2910
				$serialNo++;
2911
 
2912
				#回存
2913
				$parse["content"][2]=(string)$serialNo;
2914
 
2915
				#函式說明:
2916
				#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
2917
				#回傳的結果:
2918
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2919
				#$result["function"],當前執行的function名稱
2920
				#$result["error"],錯誤訊息陣列.
2921
				#$result["content"],處理好的字串.
2922
				#$result["argu"],使用的參數.
2923
				#必填參數:
2924
				#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
2925
				$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
2926
				#可省略參數:
2927
				#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
2928
				$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
2929
				#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
2930
				$conf["arrays::arrayToString"]["skipEnd"]="true";
2931
				#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
2932
				#$conf["spiltSymbolAtStart"]="";
2933
				#參考資料:
2934
				#無.
2935
				#備註:
2936
				#無.
2937
				$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
2938
				unset($conf["arrays::arrayToString"]);
2939
 
2940
				#如果執行異常
2941
				if($arrayToString["status"]==="false"){
2942
 
2943
					#設置錯誤識別
2944
					$result["status"]="false";
2945
 
2946
					#設置錯誤訊息
2947
					$result["error"]=$arrayToString;
2948
 
2949
					#回傳結果
2950
					return $result;
2951
 
2952
					}#if end
2953
 
2954
				#取得更新 serial number 後的 SOA value string
2955
				$unFormatStr=$arrayToString["content"];
2956
 
2957
				#如果有要合併回去的內容
2958
				if(isset($unFormatStr2add)){
2959
 
2960
					#合併回去內容
2961
					$unFormatStr=$unFormatStr.$unFormatStr2add;
2962
 
2963
					#移除用不到的變數
2964
					unset($unFormatStr2add);
2965
 
2966
					}#if end
2967
 
2968
				#假設剩下的沒有註解都是 value
2969
				$info["value"]=$unFormatStr;
2970
 
2971
				#函式說明:
2972
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2973
				#回傳結果:
2974
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2975
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2976
				#$result["function"],當前執行的函式名稱.
2977
				#$result["argu"],所使用的參數.
2978
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2979
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2980
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2981
				#必填參數:
2982
				#$conf["input"],字串,要檢查的字串.
2983
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2984
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2985
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
2986
				#可省略參數:
2987
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2988
				#$conf["varEqual"]=array(null,"found");
2989
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2990
				#$conf["varCon"]=array("no_tail"=>" not");
2991
				#參考資料:
2992
				#無.
2993
				#備註:
2994
				#無.
2995
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2996
				unset($conf["search::findSpecifyStrFormat"]);
2997
 
2998
				#如果執行異常
2999
				if($findSpecifyStrFormat["status"]==="false"){
3000
 
3001
					#設置錯誤識別
3002
					$result["status"]="false";
3003
 
3004
					#設置錯誤訊息
3005
					$result["error"]=$findSpecifyStrFormat;
3006
 
3007
					#回傳結果
3008
					return $result;
3009
 
3010
					}#if end
3011
 
3012
				#如果有符合格式
3013
				if($findSpecifyStrFormat["found"]==="true"){
3014
 
3015
					#儲存 value
3016
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3017
 
3018
					#儲存 comment
3019
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3020
 
3021
					}#if end
3022
 
3023
				#儲存 RR 的記錄
3024
				$result["content"]=$info;
3025
 
3026
				#設置執行正常
3027
				$result["status"]="true";
3028
 
3029
				#回傳結果
3030
				return $result;
3031
 
3032
				}#if end
3033
 
3034
			#執行到這邊代表不是 SOA
3035
 
404 liveuser 3036
			#如果是 CAA
3037
			if($info["type"]!=="CAA"){
3038
 
3039
				#判斷內容是否為合法的 CAA value
3040
				#0 issue ";";comment
3041
				#0 issue "domain.name";comment
3042
				#函式說明:
3043
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3044
				#回傳結果:
3045
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3046
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3047
				#$result["function"],當前執行的函式名稱.
3048
				#$result["argu"],所使用的參數.
3049
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3050
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3051
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3052
				#必填參數:
3053
				#$conf["input"],字串,要檢查的字串.
3054
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3055
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3056
				$conf["search::findSpecifyStrFormat"]["format"]="0 issue \"\${domain}\";\${comment}";
3057
				#可省略參數:
3058
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3059
				#$conf["varEqual"]=array(null,"found");
3060
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3061
				#$conf["varCon"]=array("no_tail"=>" not");
3062
				#參考資料:
3063
				#無.
3064
				#備註:
3065
				#無.
3066
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3067
				unset($conf["search::findSpecifyStrFormat"]);
3068
 
3069
				#如果執行異常
3070
				if($findSpecifyStrFormat["status"]==="false"){
3071
 
3072
					#設置錯誤識別
3073
					$result["status"]="false";
3074
 
3075
					#設置錯誤訊息
3076
					$result["error"]=$findSpecifyStrFormat;
3077
 
3078
					#回傳結果
3079
					return $result;
3080
 
3081
					}#if end
3082
 
3083
				#如果有 有符合 "0 issue \"\${domain}\";\${comment}" 的格式
3084
				if($findSpecifyStrFormat["found"]==="true"){
3085
 
3086
					#儲存value
3087
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3088
 
3089
					#儲存comment
3090
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3091
 
3092
					#儲存 RR 的記錄
3093
					$result["content"]=$info;
3094
 
3095
					#設置執行正常
3096
					$result["status"]="true";
3097
 
3098
					#回傳結果
3099
					return $result;
3100
 
3101
					}#if end
3102
 
3103
				#判斷內容是否為合法的 CAA value
3104
				#0 issue ";"
3105
				#0 issue "domain.name"
3106
				#函式說明:
3107
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3108
				#回傳結果:
3109
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3110
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3111
				#$result["function"],當前執行的函式名稱.
3112
				#$result["argu"],所使用的參數.
3113
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3114
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3115
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3116
				#必填參數:
3117
				#$conf["input"],字串,要檢查的字串.
3118
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3119
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3120
				$conf["search::findSpecifyStrFormat"]["format"]="0 issue \"\${domain}\"";
3121
				#可省略參數:
3122
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3123
				#$conf["varEqual"]=array(null,"found");
3124
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3125
				#$conf["varCon"]=array("no_tail"=>" not");
3126
				#參考資料:
3127
				#無.
3128
				#備註:
3129
				#無.
3130
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3131
				unset($conf["search::findSpecifyStrFormat"]);
3132
 
3133
				#如果執行異常
3134
				if($findSpecifyStrFormat["status"]==="false"){
3135
 
3136
					#設置錯誤識別
3137
					$result["status"]="false";
3138
 
3139
					#設置錯誤訊息
3140
					$result["error"]=$findSpecifyStrFormat;
3141
 
3142
					#回傳結果
3143
					return $result;
3144
 
3145
					}#if end
3146
 
3147
				#如果有 有符合 "0 issue \"\${domain}\"" 的格式
3148
				if($findSpecifyStrFormat["found"]==="true"){
3149
 
3150
					#儲存value
3151
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3152
 
3153
					#儲存 RR 的記錄
3154
					$result["content"]=$info;
3155
 
3156
					#設置執行正常
3157
					$result["status"]="true";
3158
 
3159
					#回傳結果
3160
					return $result;
3161
 
3162
					}#if end
3163
 
3164
				}#if end
3165
 
3166
			#執行到這邊代表不是 CAA
3167
 
291 liveuser 3168
			#尋找是否有(...)...的內容存在
3169
			#函式說明:
3170
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3171
			#回傳結果:
3172
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3173
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3174
			#$result["function"],當前執行的函式名稱.
3175
			#$result["argu"],所使用的參數.
3176
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3177
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3178
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3179
			#必填參數:
3180
			#$conf["input"],字串,要檢查的字串.
3181
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3182
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3183
			$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
3184
			#可省略參數:
3185
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3186
			#$conf["varEqual"]=array(null,"found");
3187
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3188
			#$conf["varCon"]=array("no_tail"=>" not");
3189
			#參考資料:
3190
			#無.
3191
			#備註:
3192
			#無.
3193
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3194
			unset($conf["search::findSpecifyStrFormat"]);
3195
 
3196
			#如果執行異常
3197
			if($findSpecifyStrFormat["status"]==="false"){
3198
 
3199
				#設置錯誤識別
3200
				$result["status"]="false";
3201
 
3202
				#設置錯誤訊息
3203
				$result["error"]=$findSpecifyStrFormat;
3204
 
3205
				#回傳結果
3206
				return $result;
3207
 
3208
				}#if end
3209
 
3210
			#如果有 有符合 ($value);${comment} 的格式
3211
			if($findSpecifyStrFormat["found"]==="true"){
3212
 
3213
				#儲存value
3214
				$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
3215
 
3216
				#儲存comment
3217
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3218
 
3219
				#儲存 RR 的記錄
3220
				$result["content"]=$info;
3221
 
3222
				#設置執行正常
3223
				$result["status"]="true";
3224
 
3225
				#回傳結果
3226
				return $result;
3227
 
3228
				}#if end
3229
 
3230
			#執行到這邊代表沒有 (...)... 的內容存在
3231
 
3232
			#尋找是否有 (...) 的內容存在
3233
			#函式說明:
3234
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3235
			#回傳結果:
3236
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3237
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3238
			#$result["function"],當前執行的函式名稱.
3239
			#$result["argu"],所使用的參數.
3240
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3241
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3242
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3243
			#必填參數:
3244
			#$conf["input"],字串,要檢查的字串.
3245
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3246
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3247
			$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
3248
			#可省略參數:
3249
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3250
			#$conf["varEqual"]=array(null,"found");
3251
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3252
			#$conf["varCon"]=array("no_tail"=>" not");
3253
			#參考資料:
3254
			#無.
3255
			#備註:
3256
			#無.
3257
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3258
			unset($conf["search::findSpecifyStrFormat"]);
3259
 
3260
			#如果執行異常
3261
			if($findSpecifyStrFormat["status"]==="false"){
3262
 
3263
				#設置錯誤識別
3264
				$result["status"]="false";
3265
 
3266
				#設置錯誤訊息
3267
				$result["error"]=$findSpecifyStrFormat;
3268
 
3269
				#回傳結果
3270
				return $result;
3271
 
3272
				}#if end
3273
 
3274
			#如果有 有符合 ($value);${comment} 的格式
3275
			if($findSpecifyStrFormat["found"]==="true"){
3276
 
3277
				#儲存value
3278
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3279
 
3280
				#儲存 RR 的記錄
3281
				$result["content"]=$info;
3282
 
3283
				#設置執行正常
3284
				$result["status"]="true";
3285
 
3286
				#回傳結果
3287
				return $result;
3288
 
3289
				}#if end
3290
 
3291
			#執行到這邊代表沒有 (...) 的內容存在
3292
 
3293
			#尋找有無 "...";... 的內容存在
3294
			#函式說明:
3295
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3296
			#回傳結果:
3297
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3298
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3299
			#$result["function"],當前執行的函式名稱.
3300
			#$result["argu"],所使用的參數.
3301
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3302
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3303
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3304
			#必填參數:
3305
			#$conf["input"],字串,要檢查的字串.
3306
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3307
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3308
			$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
3309
			#可省略參數:
3310
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3311
			#$conf["varEqual"]=array(null,"found");
3312
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3313
			#$conf["varCon"]=array("no_tail"=>" not");
3314
			#參考資料:
3315
			#無.
3316
			#備註:
3317
			#無.
3318
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3319
			unset($conf["search::findSpecifyStrFormat"]);
3320
 
3321
			#如果執行異常
3322
			if($findSpecifyStrFormat["status"]==="false"){
3323
 
3324
				#設置錯誤識別
3325
				$result["status"]="false";
3326
 
3327
				#設置錯誤訊息
3328
				$result["error"]=$findSpecifyStrFormat;
3329
 
3330
				#回傳結果
3331
				return $result;
3332
 
3333
				}#if end
3334
 
3335
			#如果有 有符合 "$value";${comment} 的格式
3336
			if($findSpecifyStrFormat["found"]==="true"){
3337
 
3338
				#儲存value
3339
				$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
3340
 
3341
				#儲存comment
3342
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3343
 
3344
				#儲存 RR 的記錄
3345
				$result["content"]=$info;
3346
 
3347
				#設置執行正常
3348
				$result["status"]="true";
3349
 
3350
				#回傳結果
3351
				return $result;
3352
 
3353
				}#if end
3354
 
3355
			#執行到這邊代表沒有 "$value";${comment} 的格式
3356
 
3357
			#尋找有無 "..." 的內容存在
3358
			#函式說明:
3359
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3360
			#回傳結果:
3361
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3362
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3363
			#$result["function"],當前執行的函式名稱.
3364
			#$result["argu"],所使用的參數.
3365
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3366
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3367
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3368
			#必填參數:
3369
			#$conf["input"],字串,要檢查的字串.
3370
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3371
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3372
			$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
3373
			#可省略參數:
3374
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3375
			#$conf["varEqual"]=array(null,"found");
3376
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3377
			#$conf["varCon"]=array("no_tail"=>" not");
3378
			#參考資料:
3379
			#無.
3380
			#備註:
3381
			#無.
3382
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3383
			unset($conf["search::findSpecifyStrFormat"]);
3384
 
3385
			#如果執行異常
3386
			if($findSpecifyStrFormat["status"]==="false"){
3387
 
3388
				#設置錯誤識別
3389
				$result["status"]="false";
3390
 
3391
				#設置錯誤訊息
3392
				$result["error"]=$findSpecifyStrFormat;
3393
 
3394
				#回傳結果
3395
				return $result;
3396
 
3397
				}#if end
3398
 
3399
			#如果有 有符合 "$value" 的格式
3400
			if($findSpecifyStrFormat["found"]==="true"){
3401
 
3402
				#儲存value
3403
				$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
3404
 
3405
				#儲存 RR 的記錄
3406
				$result["content"]=$info;
3407
 
3408
				#設置執行正常
3409
				$result["status"]="true";
3410
 
3411
				#回傳結果
3412
				return $result;
3413
 
3414
				}#if end
3415
 
3416
			#執行到這邊代表沒有 "$value" 格式的內容
3417
 
3418
			#檢查是否有 $value;$comment 格式的內容
3419
			#函式說明:
3420
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3421
			#回傳結果:
3422
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3423
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3424
			#$result["function"],當前執行的函式名稱.
3425
			#$result["argu"],所使用的參數.
3426
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3427
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3428
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3429
			#必填參數:
3430
			#$conf["input"],字串,要檢查的字串.
3431
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3432
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3433
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3434
			#可省略參數:
3435
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3436
			#$conf["varEqual"]=array(null,"found");
3437
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3438
			#$conf["varCon"]=array("no_tail"=>" not");
3439
			#參考資料:
3440
			#無.
3441
			#備註:
3442
			#無.
3443
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3444
			unset($conf["search::findSpecifyStrFormat"]);
3445
 
3446
			#如果執行異常
3447
			if($findSpecifyStrFormat["status"]==="false"){
3448
 
3449
				#設置錯誤識別
3450
				$result["status"]="false";
3451
 
3452
				#設置錯誤訊息
3453
				$result["error"]=$findSpecifyStrFormat;
3454
 
3455
				#回傳結果
3456
				return $result;
3457
 
3458
				}#if end
3459
 
3460
			#如果有 有符合 "$value" 的格式
3461
			if($findSpecifyStrFormat["found"]==="true"){
3462
 
3463
				#儲存value
3464
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3465
 
3466
				#儲存comment
3467
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3468
 
3469
				#儲存 RR 的記錄
3470
				$result["content"]=$info;
3471
 
3472
				#設置執行正常
3473
				$result["status"]="true";
3474
 
3475
				#回傳結果
3476
				return $result;
3477
 
3478
				}#if end
3479
 
3480
			#執行到這邊代表沒有 ${value};${comment} 格式的內容
3481
 
3482
			#亦即剩下的內容都是 value
3483
 
3484
			#儲存value
3485
			$info["value"]=$unFormatStr;
3486
 
3487
			#儲存 RR 的記錄
3488
			$result["content"]=$info;
3489
 
3490
			#設置執行正常
3491
			$result["status"]="true";
3492
 
3493
			#回傳結果
3494
			return $result;
3495
 
3496
			}#while end
3497
 
3498
		}#function parseRRline end
3499
 
3500
	/*
3501
	#函式說明:
249 liveuser 3502
	#新增DNS記錄到檔案裡面.
3503
	#回傳結果:
3504
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3505
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
3506
	#$result["function"],當前執行的函式名稱.
3507
	#$result["argu"],所使用的參數.
3508
	#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
255 liveuser 3509
	#$result["domain"],字串,RR所屬domain.
3510
	#$result["defaultTTL"],字串,預設的RR更新時間.
249 liveuser 3511
	#$result["comment"],字串陣列,逐行的註解.
3512
	#必填參數:
255 liveuser 3513
	#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型(支援的有"A","TXT","CNAME","SOA","$TTL","$ORIGIN")、答案、註解.
249 liveuser 3514
	$conf["add"]=array();
3515
	#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
3516
	$conf["dnsRecordFile"]="";
3517
	#可省略參數:
3518
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
3519
	#$conf["writeNow"]="false";
253 liveuser 3520
	#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
3521
	#$conf["debug"]="false";
293 liveuser 3522
	#$conf["multiThreads"],字串,是否啟動多執行序加快執行速度,預設為"false"代表不要;反之為"true"代表要.
3523
	#$conf["multiThreads"]="false";
249 liveuser 3524
	#參考資料:
3525
	#無.
3526
	#備註:
3527
	#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
291 liveuser 3528
	#本套件是透過sshfs掛載來存取RR(dns記錄檔案),其檔案建議的擁有者權限為 root:qbpwcf,權限代碼為 774.
249 liveuser 3529
	#php-pear上的Net_DNS2也可以解析RR.
293 liveuser 3530
	#參數 multiThreads 目前有 bug.
249 liveuser 3531
	*/
3532
	public static function updateDnsRecordFile(&$conf){
3533
 
3534
		#初始化要回傳的結果
3535
		$result=array();
3536
 
3537
		#設置當其函數名稱
3538
		$result["function"]=__FUNCTION__;
3539
 
3540
		#如果 $conf 不為陣列
3541
		if(gettype($conf)!="array"){
3542
 
3543
			#設置執行失敗
3544
			$result["status"]="false";
3545
 
3546
			#設置執行錯誤訊息
3547
			$result["error"][]="\$conf變數須為陣列形態";
3548
 
3549
			#如果傳入的參數為 null
3550
			if($conf==null){
3551
 
3552
				#設置執行錯誤訊息
3553
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3554
 
3555
				}#if end
3556
 
3557
			#回傳結果
3558
			return $result;
3559
 
3560
			}#if end
3561
 
3562
		#取得參數
3563
		$result["argu"]=$conf;
3564
 
3565
		#檢查參數
3566
		#函式說明:
3567
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3568
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3569
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3570
		#$result["function"],當前執行的函式名稱.
3571
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3572
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3573
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3574
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
3575
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
3576
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3577
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3578
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3579
		#必填寫的參數:
3580
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3581
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3582
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3583
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("add","dnsRecordFile");
3584
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3585
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
3586
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3587
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3588
		#可以省略的參數:
3589
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3590
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3591
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
3592
		#$conf["skipableVariableCanNotBeEmpty"]=array();
3593
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 3594
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThreads");
249 liveuser 3595
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
291 liveuser 3596
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
249 liveuser 3597
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
291 liveuser 3598
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
249 liveuser 3599
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3600
		#$conf["arrayCountEqualCheck"][]=array();
3601
		#參考資料來源:
3602
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3603
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3604
		unset($conf["variableCheck::checkArguments"]);
3605
 
3606
		#如果檢查失敗
3607
		if($checkArguments["status"]==="false"){
3608
 
3609
			#設置錯誤識別
3610
			$result["status"]="false";
3611
 
3612
			#設置錯誤訊息
3613
			$result["error"]=$checkArguments;
3614
 
3615
			#回傳結果
3616
			return $result;
3617
 
3618
			}#if end
3619
 
3620
		#如果檢查不通過
3621
		if($checkArguments["passed"]==="false"){
3622
 
3623
			#設置錯誤識別
3624
			$result["status"]="false";
3625
 
3626
			#設置錯誤訊息
3627
			$result["error"]=$checkArguments;
3628
 
3629
			#回傳結果
3630
			return $result;
3631
 
3632
			}#if end
3633
 
3634
		#初始化要回傳的content
3635
		$result["content"]=array();
3636
 
3637
		#初始化儲存逐行的註解.
3638
		$result["comment"]=array();
3639
 
3640
		#預設的zone file domain為空
3641
		$result["domain"]="";
3642
 
3643
		#預設的 update 時間
3644
		$result["defaultTTL"]=3600;
3645
 
3646
		#取得 dns 記錄檔案的內容
3647
		#函式說明:
3648
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
3649
		#回傳的變數說明:
3650
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
3651
		#$result["error"],錯誤訊息提示.
3652
		#$result["warning"],警告訊息.
3653
		#$result["function"],當前執行的函數名稱.
3654
		#$result["fileContent"],爲檔案的內容陣列.
3655
		#$result["lineCount"],爲檔案內容總共的行數.
3656
		#$result["fullContent"],為檔案的完整內容.
3657
		#$result["base64dataOnly"],檔案的base64data.
3658
		#$result["base64data"],為在網頁上給予src參數的數值.
3659
		#$result["mimeType"],為檔案的mime type.
3660
		#必填參數:
3661
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
3662
		$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$conf["dnsRecordFile"];
3663
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3664
		$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
3665
		#可省略參數:
3666
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
3667
		$conf["fileAccesss::getFileContent"]["web"]="false";
3668
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
3669
		#$conf["createIfnotExist"]="false";
3670
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
3671
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
3672
		#參考資料:
3673
		#file(),取得檔案內容的行數.
3674
		#file=>http:#php.net/manual/en/function.file.php
3675
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
3676
		#filesize=>http://php.net/manual/en/function.filesize.php
3677
		#參考資料:
3678
		#無.
3679
		#備註:
3680
		#無.
3681
		$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
3682
		unset($conf["fileAccesss::getFileContent"]);
3683
 
3684
		#如果檢查失敗
3685
		if($getFileContent["status"]==="false"){
3686
 
3687
			#設置錯誤識別
3688
			$result["status"]="false";
3689
 
3690
			#設置錯誤訊息
3691
			$result["error"]=$getFileContent;
3692
 
3693
			#回傳結果
3694
			return $result;
3695
 
3696
			}#if end
3697
 
3698
		#取得每行內容
3699
		$lines=$getFileContent["fileContent"];
3700
 
3701
		/*
3702
		範例每行內容:
3703
		$ORIGIN server.domain.	;base domain-name,in this Resource Records (RR) file,"@" equal to base domain-name.
3704
		$TTL 86400	;default TTL for zone
3705
		@	1200	IN	SOA	dns.server.domain. admin.server.domain. 2026012205 10800 1800 1728000 1200 ;domain name server, admin mail, serial, refresh time, expire, Negative Caching, https://bind9.readthedocs.io/en/latest/chapter3.html#term-SOA-minimum
3706
		@	3600	IN	TXT	"v=spf1 a mx ~all"
3707
		@	86400	IN	MX	1 mail.server.domain.
3708
		@	86400	IN	A	1.1.1.1
404 liveuser 3709
		@		IN	CAA	0 issue ";"
249 liveuser 3710
		mail.server.domain.	IN	1.1.1.1
3711
		10-42-0-1	IN	A	10.42.0.1
3712
		101-free        IN      A	101.101.101.101
3713
		127-0-0-1	IN	A	127.0.0.1
3714
		_dmarc	IN	TXT	"v=DMARC1;p=reject;sp=reject;pct=100;adkim=r;aspf=r;fo=1;ri=86400;rua=mailto:admin@server.domain"
3715
		default._domainkey	IN	TXT	( "v=DKIM1; k=rsa;" "p=MIGfMA0GCSqG/SIb3DQEBAQQAB" )  ; ----- DKIM key default for qbpwcf.org
3716
		...
3717
		*/
3718
 
3719
		#針對每行內容
3720
		foreach($lines as $lineNo => $line){
3721
 
291 liveuser 3722
			#如果要啟用多執行序
293 liveuser 3723
			if($conf["multiThreads"]==="true"){
291 liveuser 3724
 
293 liveuser 3725
				#如果要debug
3726
				if($conf["debug"]==="true"){
291 liveuser 3727
 
293 liveuser 3728
					#函式說明:
3729
					#撰寫log
3730
					#回傳結果:
3731
					#$result["status"],狀態,"true"或"false".
3732
					#$result["error"],錯誤訊息陣列.
3733
					#$result["function"],當前函式的名稱.
3734
					#$result["argu"],使用的參數.
3735
					#$result["content"],要寫入log的內容字串.
3736
					#必填參數:
3737
					#$conf["path"],字串,log檔案的路徑與名稱.
3738
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3739
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3740
					$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR through multi threads.".PHP_EOL;
3741
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3742
					$conf["logs::record"]["fileArgu"]=__FILE__;
3743
					#可省略參數:
3744
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3745
					#$conf["rewrite"]="false";
3746
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3747
					#$conf["returnOnly"]="true";
3748
					#參考資料:
3749
					#無.
3750
					#備註:
3751
					#無.
3752
					$record=logs::record($conf["logs::record"]);
3753
					unset($conf["logs::record"]);
291 liveuser 3754
 
293 liveuser 3755
					}#if end
3756
 
3757
				#初始化要執行的 php 程式
3758
				$phpCode2run="php -r ";
291 liveuser 3759
 
293 liveuser 3760
				#php code not escaped
3761
				$phpCode2escaped=<<<'PHP'
3762
/*
291 liveuser 3763
 
293 liveuser 3764
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
3765
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3766
 
3767
    This file is part of QBPWCF.
3768
 
3769
    QBPWCF is free software: you can redistribute it and/or modify
3770
    it under the terms of the GNU General Public License as published by
3771
    the Free Software Foundation, either version 3 of the License, or
3772
    (at your option) any later version.
3773
 
3774
    QBPWCF is distributed in the hope that it will be useful,
3775
    but WITHOUT ANY WARRANTY; without even the implied warranty of
3776
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3777
    GNU General Public License for more details.
3778
 
3779
    You should have received a copy of the GNU General Public License
3780
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
3781
 
3782
*/
3783
 
3784
#使用命名空間qbpwcf
3785
namespace qbpwcf;
3786
 
3787
#匯入套件
3788
PHP;
3789
 
3790
#設置 lib root path
3791
$libPath=pathinfo(__FILE__)["dirname"]."/..";
3792
 
3793
#串接匯入QBPWCF套件
3794
$phpCode2escaped=$phpCode2escaped.PHP_EOL."require_once(\"".$libPath."/qbpwcf/allInOne.php\");";
3795
 
3796
#串接php程式
3797
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
291 liveuser 3798
#函式說明:
3799
#解析RR檔案中其中的一行內容.
3800
#回傳結果:
3801
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3802
#$reuslt["error"],執行不正常結束的錯訊息陣列.
3803
#$result["function"],當前執行的函式名稱.
3804
#$result["argu"],所使用的參數.
293 liveuser 3805
#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
291 liveuser 3806
#$result["domain"],字串,RR所屬domain.
3807
#$result["defaultTTL"],字串,預設的RR更新時間.
293 liveuser 3808
#$result["comment"],字串,一行的註解.
291 liveuser 3809
#必填參數:
3810
#$conf["line"],字串,要解析的行內容.
293 liveuser 3811
PHP;
3812
 
3813
#串接變數
3814
$phpCode2escaped=$phpCode2escaped.PHP_EOL."\$conf[\"line\"]=base64_decode(\"".base64_encode($line)."\");";
3815
 
3816
#串接php程式
3817
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
291 liveuser 3818
#可省略參數:
3819
#無.
3820
#參考資料:
3821
#無.
3822
#備註:
3823
#無.
3824
$parseRRline=zerossl::parseRRline($conf);
3825
unset($conf);
3826
 
3827
#如果執行異常 
3828
if($parseRRline["status"]==="false"){
3829
 
3830
	#設置錯誤識別
3831
	$result["status"]="false";
3832
 
3833
	#設置錯誤訊息
3834
	$result["error"]=$parseRRline;
3835
 
3836
	#印出 json 結果
3837
	echo json_encode($result);
3838
 
3839
	#結束執行,回傳1.
3840
	exit(1);
3841
 
3842
	}#if end
3843
 
3844
#印出json
3845
echo json_encode($parseRRline);
3846
PHP;
3847
 
293 liveuser 3848
				#串接要執行的參數
3849
				$phpCode2run=$phpCode2run.escapeshellarg($phpCode2escaped);
3850
 
291 liveuser 3851
				#函式說明:
3852
				#透過proc來多執行序運作.
3853
				#回傳結果:
3854
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3855
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3856
				#$result["function"],當前執行的函式名稱.
3857
				#$result["argu"],使用的參數.
3858
				#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
3859
				#必填參數:
3860
				#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
293 liveuser 3861
				$conf["threads::proc"]["cmds"]=array($phpCode2run);
291 liveuser 3862
				#可省略參數:
3863
				#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
3864
				$conf["threads::proc"]["wait"]="false";
3865
				#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
3866
				#$conf["timeout"]=array("10");
3867
				#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
293 liveuser 3868
				#$conf["threads::proc"]["workingDir"]=array(pathinfo(__FILE__)["dirname"]);
291 liveuser 3869
				#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
3870
				#$conf["envs"]=array(array("key"=>"value"));
3871
				#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
3872
				#$conf["executeBy"]=array("bash");
3873
				#參考資料:
3874
				#https://www.php.net/manual/en/function.proc-open.php
3875
				#https://www.php.net/manual/en/function.proc-get-status.php
3876
				#https://www.php.net/manual/en/function.proc-terminate.php
3877
				#備註:
3878
				#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
3879
				#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
3880
				$proc=threads::proc($conf["threads::proc"]);
3881
				unset($conf["threads::proc"]);
3882
 
293 liveuser 3883
				#debug
3884
				#var_dump($proc);exit;
3885
 
291 liveuser 3886
				#如果檢查失敗
3887
				if($proc["status"]==="false"){
3888
 
3889
					#設置錯誤識別
3890
					$result["status"]="false";
3891
 
3892
					#設置錯誤訊息
3893
					$result["error"]=$proc;
3894
 
3895
					#回傳結果
3896
					return $result;
3897
 
3898
					}#if end
3899
 
3900
				#儲存程序資訊
294 liveuser 3901
				$procs[$lineNo]=$proc;	
291 liveuser 3902
 
3903
				#換解析下一行
3904
				continue;
3905
 
3906
				}#if end
3907
 
249 liveuser 3908
			#另存一份要處理的RR
404 liveuser 3909
			#$unFormatStr=$line;
249 liveuser 3910
 
253 liveuser 3911
			#如果要debug
3912
			if($conf["debug"]==="true"){
3913
 
3914
				#函式說明:
3915
				#撰寫log
3916
				#回傳結果:
3917
				#$result["status"],狀態,"true"或"false".
3918
				#$result["error"],錯誤訊息陣列.
3919
				#$result["function"],當前函式的名稱.
3920
				#$result["argu"],使用的參數.
3921
				#$result["content"],要寫入log的內容字串.
3922
				#必填參數:
3923
				#$conf["path"],字串,log檔案的路徑與名稱.
3924
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3925
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3926
				$conf["logs::record"]["content"]="processing lineNo:".$lineNo." content:".$line.PHP_EOL;
3927
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3928
				$conf["logs::record"]["fileArgu"]=__FILE__;
3929
				#可省略參數:
3930
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3931
				#$conf["rewrite"]="false";
3932
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3933
				#$conf["returnOnly"]="true";
3934
				#參考資料:
3935
				#無.
3936
				#備註:
3937
				#無.
3938
				$record=logs::record($conf["logs::record"]);
3939
				unset($conf["logs::record"]);
3940
 
3941
				}#if end
3942
 
404 liveuser 3943
			#函式說明:
3944
			#解析RR檔案中其中的一行內容,回傳結果.
249 liveuser 3945
			#回傳結果:
3946
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3947
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3948
			#$result["function"],當前執行的函式名稱.
3949
			#$result["argu"],所使用的參數.
404 liveuser 3950
			#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
3951
			#$result["domain"],字串,RR所屬domain.
3952
			#$result["defaultTTL"],字串,預設的RR更新時間.
3953
			#$result["comment"],字串,一行的註解.
249 liveuser 3954
			#必填參數:
404 liveuser 3955
			#$conf["line"],字串,要解析的行內容.
3956
			$conf["zerossl::parseRRline"]["line"]=$line;
249 liveuser 3957
			#可省略參數:
3958
			#無.
3959
			#參考資料:
3960
			#無.
3961
			#備註:
3962
			#無.
404 liveuser 3963
			$parseRRline=zerossl::parseRRline($conf["zerossl::parseRRline"]);
3964
			unset($conf["zerossl::parseRRline"]);
249 liveuser 3965
 
404 liveuser 3966
			#如果解析異常 
3967
			if($parseRRline["status"]==="false"){
249 liveuser 3968
 
3969
				#設置錯誤識別
3970
				$result["status"]="false";
3971
 
3972
				#設置錯誤訊息
404 liveuser 3973
				$result["error"]=$proc;
249 liveuser 3974
 
3975
				#回傳結果
3976
				return $result;
3977
 
404 liveuser 3978
				}#iif end
249 liveuser 3979
 
404 liveuser 3980
			#取得該RR的解析結果
3981
			$info=$parseRRline["content"];
249 liveuser 3982
 
404 liveuser 3983
			#如果是TTL列
3984
			if($info["type"]==="\$TTL"){
249 liveuser 3985
 
404 liveuser 3986
				#設置預設的TTL
3987
				$result["defaultTTL"]=$info["defaultTTL"];
249 liveuser 3988
 
3989
				}#if end
3990
 
404 liveuser 3991
			#如果是ORIGIN列
3992
			if($info["type"]==="\$ORIGIN"){	
249 liveuser 3993
 
404 liveuser 3994
				#設置RR所屬的domain
3995
				$result["domain"]=$info["domain"];
249 liveuser 3996
 
3997
				}#if end
3998
 
404 liveuser 3999
			#儲存 RR 的記錄
4000
			$result["content"][]=$info;
249 liveuser 4001
 
4002
			}#foreach end
291 liveuser 4003
 
4004
		#如果要啟用多執行序
293 liveuser 4005
		if($conf["multiThreads"]==="true"){
249 liveuser 4006
 
293 liveuser 4007
			#如果要debug
4008
			if($conf["debug"]==="true"){
4009
 
4010
				#函式說明:
4011
				#撰寫log
4012
				#回傳結果:
4013
				#$result["status"],狀態,"true"或"false".
4014
				#$result["error"],錯誤訊息陣列.
4015
				#$result["function"],當前函式的名稱.
4016
				#$result["argu"],使用的參數.
4017
				#$result["content"],要寫入log的內容字串.
4018
				#必填參數:
4019
				#$conf["path"],字串,log檔案的路徑與名稱.
4020
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4021
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4022
				$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR result through multi threads.".PHP_EOL;
4023
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4024
				$conf["logs::record"]["fileArgu"]=__FILE__;
4025
				#可省略參數:
4026
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4027
				#$conf["rewrite"]="false";
4028
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4029
				#$conf["returnOnly"]="true";
4030
				#參考資料:
4031
				#無.
4032
				#備註:
4033
				#無.
4034
				$record=logs::record($conf["logs::record"]);
4035
				unset($conf["logs::record"]);
4036
 
4037
				}#if end
291 liveuser 4038
 
293 liveuser 4039
			#無窮迴圈
4040
			while(true){
4041
 
4042
				#等後1秒
4043
				sleep(1);
4044
 
4045
				#針對每行處理的狀況
4046
				foreach($procs as $procIndex => $proc){
4047
 
4048
					#如果要debug
4049
					if($conf["debug"]==="true"){
4050
 
4051
						#函式說明:
4052
						#撰寫log
4053
						#回傳結果:
4054
						#$result["status"],狀態,"true"或"false".
4055
						#$result["error"],錯誤訊息陣列.
4056
						#$result["function"],當前函式的名稱.
4057
						#$result["argu"],使用的參數.
4058
						#$result["content"],要寫入log的內容字串.
4059
						#必填參數:
4060
						#$conf["path"],字串,log檔案的路徑與名稱.
4061
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4062
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4063
						$conf["logs::record"]["content"]="lineNo:".__LINE__." Try get result of parsing RR line ".($procIndex+1)." through multi threads.".PHP_EOL;
4064
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4065
						$conf["logs::record"]["fileArgu"]=__FILE__;
4066
						#可省略參數:
4067
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4068
						#$conf["rewrite"]="false";
4069
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4070
						#$conf["returnOnly"]="true";
4071
						#參考資料:
4072
						#無.
4073
						#備註:
4074
						#無.
4075
						$record=logs::record($conf["logs::record"]);
4076
						unset($conf["logs::record"]);
4077
 
4078
						}#if end
4079
 
4080
					#函式說明:
4081
					#更新透過proc執行的多程序資訊.
4082
					#回傳結果:
4083
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4084
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
4085
					#$result["function"],當前執行的函式名稱.
4086
					#$result["argu"],使用的參數.
4087
					#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
4088
					#必填參數:
4089
					#$conf["procs"],陣列,運行self::proc後回傳的content.
4090
					$conf["threads::proc_update"]["procs"]=$proc["content"];
4091
					#可省略參數:
4092
					#無.
4093
					#參考資料:
4094
					#無.
4095
					#備註:
4096
					#無.
4097
					$proc_update=threads::proc_update($conf["threads::proc_update"]);
4098
					unset($conf["threads::proc_update"]);
4099
 
4100
					#debug
4101
					#var_dump($proc_update);exit;
4102
 
4103
					#如果執行異常
4104
					if($proc_update["status"]==="false"){
4105
 
4106
						#設置執行異常
4107
						$result["status"]="false";
4108
 
4109
						#設置執行錯誤
4110
						$result["error"]=$proc_update;
4111
 
4112
						#回傳結果
4113
						return $result;
4114
 
4115
						}#if end
4116
 
4117
					#另存結果
4118
					$procRes=$proc_update["content"][0];
4119
 
4120
					#如果程序執行異常
4121
					if($procRes["status"]==="false"){
4122
 
4123
						#設置執行異常
4124
						$result["status"]="false";
4125
 
4126
						#設置執行錯誤
4127
						$result["error"]=$procRes;
4128
 
4129
						#回傳結果
4130
						return $result;
4131
 
4132
						}#if end
4133
 
4134
					#如果程序尚在執行
4135
					if($procRes["statusCode"]==="?"){
4136
 
4137
						#換看下一列的執行狀況
4138
						continue;
4139
 
4140
						}#if end
4141
 
4142
					#如果輸出內容不是 json
4143
					if(!(json_validate($procRes["content"]))){
4144
 
4145
						#設置執行異常
4146
						$result["status"]="false";
4147
 
4148
						#設置執行錯誤
4149
						$result["error"]=$procRes;
4150
 
4151
						#回傳結果
4152
						return $result;
4153
 
4154
						}#if end
4155
 
4156
					#解析json
4157
					$jsonRes=json_decode($procRes["content"]);
4158
 
4159
					#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","query","update",也可能為空陣列.
4160
					#$result["domain"],字串,RR所屬domain.
4161
					#$result["defaultTTL"],字串,預設的RR更新時間.
4162
					#$result["comment"],字串,一行的註解.
4163
 
4164
					#如果有 content->type 存在
4165
					if(isset($jsonRes->content->type)){
4166
 
4167
						#儲存value
4168
						$info["type"]=$jsonRes->content->type;
4169
 
4170
						}#if end
4171
 
4172
					#如果有 content->value 存在
4173
					if(isset($jsonRes->content->value)){
4174
 
4175
						#儲存value
4176
						$info["value"]=$jsonRes->content->value;
4177
 
4178
						}#if end
4179
 
4180
					#如果有 content->query 存在
4181
					if(isset($jsonRes->content->query)){
4182
 
4183
						#儲存query
4184
						$info["query"]=$jsonRes->content->query;
4185
 
4186
						}#if end
4187
 
4188
					#如果有 content->update 存在
4189
					if(isset($jsonRes->content->update)){
4190
 
4191
						#儲存query
4192
						$info["update"]=$jsonRes->content->update;
4193
 
4194
						}#if end
4195
 
4196
					#如果有 domain 存在
4197
					if(isset($jsonRes->domain)){
4198
 
4199
						#儲存domain
4200
						$result["domain"]=$jsonRes->domain;
4201
 
4202
						}#if end
4203
 
4204
					#如果有 defaultTTL 存在
4205
					if(isset($jsonRes->defaultTTL)){
4206
 
4207
						#儲存domain
404 liveuser 4208
						$result["defaultTTL"]=$jsonRes->defaultTTL;
293 liveuser 4209
 
4210
						}#if end
4211
 
4212
					#如果有 comment 存在
4213
					if(isset($jsonRes->comment)){
4214
 
4215
						#儲存comment,用$procIndex作為先後順率的識別
4216
						$result["comment"][$procIndex]=$jsonRes->comment;
4217
 
4218
						}#if end
4219
 
4220
					#儲存 RR 的記錄
4221
					$result["content"][$procIndex]=$info;
4222
 
4223
					#移除解析好的行號
4224
					unset($procs[$procIndex]);
4225
 
4226
					#如果要debug
4227
					if($conf["debug"]==="true"){
4228
 
4229
						#函式說明:
4230
						#撰寫log
4231
						#回傳結果:
4232
						#$result["status"],狀態,"true"或"false".
4233
						#$result["error"],錯誤訊息陣列.
4234
						#$result["function"],當前函式的名稱.
4235
						#$result["argu"],使用的參數.
4236
						#$result["content"],要寫入log的內容字串.
4237
						#必填參數:
4238
						#$conf["path"],字串,log檔案的路徑與名稱.
4239
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4240
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4241
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR line ".($procIndex+1)." through multi threads fin.".PHP_EOL;
4242
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4243
						$conf["logs::record"]["fileArgu"]=__FILE__;
4244
						#可省略參數:
4245
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4246
						#$conf["rewrite"]="false";
4247
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4248
						#$conf["returnOnly"]="true";
4249
						#參考資料:
4250
						#無.
4251
						#備註:
4252
						#無.
4253
						$record=logs::record($conf["logs::record"]);
4254
						unset($conf["logs::record"]);
4255
 
4256
						}#if end
4257
 
4258
					}#foreach end
4259
 
4260
				#如果每行都已經解析好了
4261
				if(count($procs)===0){
4262
 
4263
					#如果要debug
4264
					if($conf["debug"]==="true"){
4265
 
4266
						#函式說明:
4267
						#撰寫log
4268
						#回傳結果:
4269
						#$result["status"],狀態,"true"或"false".
4270
						#$result["error"],錯誤訊息陣列.
4271
						#$result["function"],當前函式的名稱.
4272
						#$result["argu"],使用的參數.
4273
						#$result["content"],要寫入log的內容字串.
4274
						#必填參數:
4275
						#$conf["path"],字串,log檔案的路徑與名稱.
4276
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4277
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4278
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR through multi threads fin.".PHP_EOL;
4279
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4280
						$conf["logs::record"]["fileArgu"]=__FILE__;
4281
						#可省略參數:
4282
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4283
						#$conf["rewrite"]="false";
4284
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4285
						#$conf["returnOnly"]="true";
4286
						#參考資料:
4287
						#無.
4288
						#備註:
4289
						#無.
4290
						$record=logs::record($conf["logs::record"]);
4291
						unset($conf["logs::record"]);
4292
 
4293
						}#if end
4294
 
4295
					#跳出 while
4296
					break;
4297
 
4298
					}#if end
4299
 
4300
				}#while end
4301
 
291 liveuser 4302
			}#if end
4303
 
253 liveuser 4304
		#如果要debug
4305
		if($conf["debug"]==="true"){
249 liveuser 4306
 
253 liveuser 4307
			#函式說明:
4308
			#撰寫log
4309
			#回傳結果:
4310
			#$result["status"],狀態,"true"或"false".
4311
			#$result["error"],錯誤訊息陣列.
4312
			#$result["function"],當前函式的名稱.
4313
			#$result["argu"],使用的參數.
4314
			#$result["content"],要寫入log的內容字串.
4315
			#必填參數:
4316
			#$conf["path"],字串,log檔案的路徑與名稱.
4317
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4318
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4319
			$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR fin.".PHP_EOL;
4320
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4321
			$conf["logs::record"]["fileArgu"]=__FILE__;
4322
			#可省略參數:
4323
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4324
			#$conf["rewrite"]="false";
4325
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4326
			#$conf["returnOnly"]="true";
4327
			#參考資料:
4328
			#無.
4329
			#備註:
4330
			#無.
4331
			$record=logs::record($conf["logs::record"]);
4332
			unset($conf["logs::record"]);
4333
 
4334
			}#if end
4335
 
249 liveuser 4336
		#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
4337
 
4338
		#針對每個要新增的RR記錄
255 liveuser 4339
		foreach($conf["add"] as $nri => $newRR){
249 liveuser 4340
 
255 liveuser 4341
			#如果要debug
4342
			if($conf["debug"]==="true"){
4343
 
4344
				#函式說明:
4345
				#撰寫log
4346
				#回傳結果:
4347
				#$result["status"],狀態,"true"或"false".
4348
				#$result["error"],錯誤訊息陣列.
4349
				#$result["function"],當前函式的名稱.
4350
				#$result["argu"],使用的參數.
4351
				#$result["content"],要寫入log的內容字串.
4352
				#必填參數:
4353
				#$conf["path"],字串,log檔案的路徑與名稱.
4354
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4355
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4356
				$conf["logs::record"]["content"]="lineNo:".__LINE__." ori newRR:".PHP_EOL;
4357
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4358
				$conf["logs::record"]["fileArgu"]=__FILE__;
4359
				#可省略參數:
4360
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4361
				#$conf["rewrite"]="false";
4362
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4363
				#$conf["returnOnly"]="true";
4364
				#參考資料:
4365
				#無.
4366
				#備註:
4367
				#無.
4368
				$record=logs::record($conf["logs::record"]);
4369
				unset($conf["logs::record"]);
4370
 
4371
				#函式說明:
4372
				#撰寫log
4373
				#回傳結果:
4374
				#$result["status"],狀態,"true"或"false".
4375
				#$result["error"],錯誤訊息陣列.
4376
				#$result["function"],當前函式的名稱.
4377
				#$result["argu"],使用的參數.
4378
				#$result["content"],要寫入log的內容字串.
4379
				#必填參數:
4380
				#$conf["path"],字串,log檔案的路徑與名稱.
4381
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4382
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4383
				$conf["logs::record"]["content"]=$newRR;
4384
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4385
				$conf["logs::record"]["fileArgu"]=__FILE__;
4386
				#可省略參數:
4387
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4388
				#$conf["rewrite"]="false";
4389
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4390
				#$conf["returnOnly"]="true";
4391
				#參考資料:
4392
				#無.
4393
				#備註:
4394
				#無.
4395
				$record=logs::record($conf["logs::record"]);
4396
				unset($conf["logs::record"]);
4397
 
4398
				}#if end
4399
 
4400
			#如果新的 RR 缺少必備的資訊
4401
			if(!isset($newRR["type"])){
4402
 
4403
				#設置執行異常
4404
				$result["status"]="false";
4405
 
4406
				#設置執行錯誤
4407
				$result["error"]="add參數的格式缺少type";
4408
 
4409
				#回傳結果
4410
				return $result;
4411
 
4412
				}#if end
4413
 
404 liveuser 4414
			#如果 query 不是"@"也不為"."結尾
255 liveuser 4415
			if( ($newRR["query"]!=="@") && ($newRR["query"][strlen($newRR["query"])-1]!==".") ){
4416
 
4417
				#加上 "."
4418
				$conf["add"][$nri]["query"]=$newRR["query"]=$newRR["query"].".";
4419
 
4420
				}#if end
4421
 
4422
			#如果新的 query 為 $ORGIN 結尾
4423
			#函式說明:
4424
			#將字串特定關鍵字與其後面的內容剔除
4425
			#回傳結果:
4426
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4427
			#$result["error"],錯誤訊息陣列.
4428
			#$result["warning"],警告訊息鎮列.
4429
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4430
			#$result["function"],當前執行的函數名稱.
4431
			#$result["oriStr"],要處理的原始字串內容.
4432
			#$result["content"],處理好的的字串內容.
4433
			#$result["deleted"],被移除的內容.
4434
			#$result["argu"],使用的參數.
4435
			#必填參數:
4436
			#$conf["stringIn"],字串,要處理的字串.
4437
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
4438
			#$conf["keyWord"],字串,特定字串.
4439
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["domain"];
4440
			#可省略參數:
4441
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
4442
			#$conf["deleteLastRepeatedOne"]="";
4443
			#參考資料:
4444
			#無.
4445
			#備註:
4446
			#無.
4447
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
4448
			unset($conf["stringProcess::delStrAfterKeyWord"]);
4449
 
4450
			#如果要debug
4451
			if($conf["debug"]==="true"){
4452
 
4453
				#函式說明:
4454
				#撰寫log
4455
				#回傳結果:
4456
				#$result["status"],狀態,"true"或"false".
4457
				#$result["error"],錯誤訊息陣列.
4458
				#$result["function"],當前函式的名稱.
4459
				#$result["argu"],使用的參數.
4460
				#$result["content"],要寫入log的內容字串.
4461
				#必填參數:
4462
				#$conf["path"],字串,log檔案的路徑與名稱.
4463
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4464
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4465
				$conf["logs::record"]["content"]="lineNo:".__LINE__." try process newRR with \$ORIGIN end".PHP_EOL;
4466
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4467
				$conf["logs::record"]["fileArgu"]=__FILE__;
4468
				#可省略參數:
4469
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4470
				#$conf["rewrite"]="false";
4471
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4472
				#$conf["returnOnly"]="true";
4473
				#參考資料:
4474
				#無.
4475
				#備註:
4476
				#無.
4477
				$record=logs::record($conf["logs::record"]);
4478
				unset($conf["logs::record"]);
4479
 
4480
				#函式說明:
4481
				#撰寫log
4482
				#回傳結果:
4483
				#$result["status"],狀態,"true"或"false".
4484
				#$result["error"],錯誤訊息陣列.
4485
				#$result["function"],當前函式的名稱.
4486
				#$result["argu"],使用的參數.
4487
				#$result["content"],要寫入log的內容字串.
4488
				#必填參數:
4489
				#$conf["path"],字串,log檔案的路徑與名稱.
4490
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4491
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4492
				$conf["logs::record"]["content"]=$delStrAfterKeyWord;
4493
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4494
				$conf["logs::record"]["fileArgu"]=__FILE__;
4495
				#可省略參數:
4496
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4497
				#$conf["rewrite"]="false";
4498
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4499
				#$conf["returnOnly"]="true";
4500
				#參考資料:
4501
				#無.
4502
				#備註:
4503
				#無.
4504
				$record=logs::record($conf["logs::record"]);
4505
				unset($conf["logs::record"]);
4506
 
4507
				}#if end
4508
 
4509
			#如果異常
4510
			if($delStrAfterKeyWord["status"]==="false"){
4511
 
4512
				#設置執行異常
4513
				$result["status"]="false";
4514
 
4515
				#設置執行錯誤
4516
				$result["error"]=$delStrAfterKeyWord;
4517
 
4518
				#回傳結果
4519
				return $result;
4520
 
4521
				}#if end
4522
 
4523
			#如果有找到 $ORIGIN 結尾
4524
			if($delStrAfterKeyWord["founded"]==="true"){
4525
 
4526
				#更新 query
4527
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
4528
 
4529
				#如果$newRR["query"] 變成 ""
4530
				if(empty($newRR["query"])){
4531
 
4532
					#變成 zone domain,亦即 $result["domain"]
4533
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
4534
 
4535
					}#if end
4536
 
4537
				#如果要debug
4538
				if($conf["debug"]==="true"){
4539
 
4540
					#函式說明:
4541
					#撰寫log
4542
					#回傳結果:
4543
					#$result["status"],狀態,"true"或"false".
4544
					#$result["error"],錯誤訊息陣列.
4545
					#$result["function"],當前函式的名稱.
4546
					#$result["argu"],使用的參數.
4547
					#$result["content"],要寫入log的內容字串.
4548
					#必填參數:
4549
					#$conf["path"],字串,log檔案的路徑與名稱.
4550
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4551
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4552
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4553
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4554
					$conf["logs::record"]["fileArgu"]=__FILE__;
4555
					#可省略參數:
4556
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4557
					#$conf["rewrite"]="false";
4558
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4559
					#$conf["returnOnly"]="true";
4560
					#參考資料:
4561
					#無.
4562
					#備註:
4563
					#無.
4564
					$record=logs::record($conf["logs::record"]);
4565
					unset($conf["logs::record"]);
4566
 
4567
					#函式說明:
4568
					#撰寫log
4569
					#回傳結果:
4570
					#$result["status"],狀態,"true"或"false".
4571
					#$result["error"],錯誤訊息陣列.
4572
					#$result["function"],當前函式的名稱.
4573
					#$result["argu"],使用的參數.
4574
					#$result["content"],要寫入log的內容字串.
4575
					#必填參數:
4576
					#$conf["path"],字串,log檔案的路徑與名稱.
4577
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4578
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4579
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4580
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4581
					$conf["logs::record"]["fileArgu"]=__FILE__;
4582
					#可省略參數:
4583
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4584
					#$conf["rewrite"]="false";
4585
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4586
					#$conf["returnOnly"]="true";
4587
					#參考資料:
4588
					#無.
4589
					#備註:
4590
					#無.
4591
					$record=logs::record($conf["logs::record"]);
4592
					unset($conf["logs::record"]);
4593
 
4594
					}#if end
4595
 
4596
				}#if end
4597
 
4598
			#如果新的 query 為 "." 結尾
4599
			#函式說明:
4600
			#將字串特定關鍵字與其後面的內容剔除
4601
			#回傳結果:
4602
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4603
			#$result["error"],錯誤訊息陣列.
4604
			#$result["warning"],警告訊息鎮列.
4605
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4606
			#$result["function"],當前執行的函數名稱.
4607
			#$result["oriStr"],要處理的原始字串內容.
4608
			#$result["content"],處理好的的字串內容.
4609
			#$result["deleted"],被移除的內容.
4610
			#$result["argu"],使用的參數.
4611
			#必填參數:
4612
			#$conf["stringIn"],字串,要處理的字串.
4613
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
4614
			#$conf["keyWord"],字串,特定字串.
4615
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".";
4616
			#可省略參數:
4617
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
4618
			#$conf["deleteLastRepeatedOne"]="";
4619
			#參考資料:
4620
			#無.
4621
			#備註:
4622
			#無.
4623
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
4624
			unset($conf["stringProcess::delStrAfterKeyWord"]);
4625
 
4626
			#如果異常
4627
			if($delStrAfterKeyWord["status"]==="false"){
4628
 
4629
				#設置執行異常
4630
				$result["status"]="false";
4631
 
4632
				#設置執行錯誤
4633
				$result["error"]=$delStrAfterKeyWord;
4634
 
4635
				#回傳結果
4636
				return $result;
4637
 
4638
				}#if end
4639
 
4640
			#如果有找到 "." 結尾
4641
			if($delStrAfterKeyWord["founded"]==="true"){
4642
 
4643
				#更新 query
4644
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
4645
 
4646
				#如果 $newRR["query"] 變成 ""
4647
				if(empty($newRR["query"])){
4648
 
4649
					#變成 zone domain,亦即 $result["domain"]
4650
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
4651
 
4652
					}#if end
4653
 
4654
				#如果要debug
4655
				if($conf["debug"]==="true"){
4656
 
4657
					#函式說明:
4658
					#撰寫log
4659
					#回傳結果:
4660
					#$result["status"],狀態,"true"或"false".
4661
					#$result["error"],錯誤訊息陣列.
4662
					#$result["function"],當前函式的名稱.
4663
					#$result["argu"],使用的參數.
4664
					#$result["content"],要寫入log的內容字串.
4665
					#必填參數:
4666
					#$conf["path"],字串,log檔案的路徑與名稱.
4667
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4668
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4669
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4670
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4671
					$conf["logs::record"]["fileArgu"]=__FILE__;
4672
					#可省略參數:
4673
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4674
					#$conf["rewrite"]="false";
4675
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4676
					#$conf["returnOnly"]="true";
4677
					#參考資料:
4678
					#無.
4679
					#備註:
4680
					#無.
4681
					$record=logs::record($conf["logs::record"]);
4682
					unset($conf["logs::record"]);
4683
 
4684
					#函式說明:
4685
					#撰寫log
4686
					#回傳結果:
4687
					#$result["status"],狀態,"true"或"false".
4688
					#$result["error"],錯誤訊息陣列.
4689
					#$result["function"],當前函式的名稱.
4690
					#$result["argu"],使用的參數.
4691
					#$result["content"],要寫入log的內容字串.
4692
					#必填參數:
4693
					#$conf["path"],字串,log檔案的路徑與名稱.
4694
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4695
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4696
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4697
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4698
					$conf["logs::record"]["fileArgu"]=__FILE__;
4699
					#可省略參數:
4700
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4701
					#$conf["rewrite"]="false";
4702
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4703
					#$conf["returnOnly"]="true";
4704
					#參考資料:
4705
					#無.
4706
					#備註:
4707
					#無.
4708
					$record=logs::record($conf["logs::record"]);
4709
					unset($conf["logs::record"]);
4710
 
4711
					}#if end
4712
 
4713
				}#if end
4714
 
404 liveuser 4715
			/* 看起來怪怪的
4716
 
255 liveuser 4717
			#如果新 RR 的 type 不是 A 且 value 不為 "." 結尾.
4718
			if( $newRR["type"]!=="A" && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
4719
 
4720
				#new RR add dot to value end.
4721
				$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
4722
 
4723
				#如果要debug
4724
				if($conf["debug"]==="true"){
4725
 
4726
					#函式說明:
4727
					#撰寫log
4728
					#回傳結果:
4729
					#$result["status"],狀態,"true"或"false".
4730
					#$result["error"],錯誤訊息陣列.
4731
					#$result["function"],當前函式的名稱.
4732
					#$result["argu"],使用的參數.
4733
					#$result["content"],要寫入log的內容字串.
4734
					#必填參數:
4735
					#$conf["path"],字串,log檔案的路徑與名稱.
4736
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4737
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4738
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4739
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4740
					$conf["logs::record"]["fileArgu"]=__FILE__;
4741
					#可省略參數:
4742
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4743
					#$conf["rewrite"]="false";
4744
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4745
					#$conf["returnOnly"]="true";
4746
					#參考資料:
4747
					#無.
4748
					#備註:
4749
					#無.
4750
					$record=logs::record($conf["logs::record"]);
4751
					unset($conf["logs::record"]);
4752
 
4753
					#函式說明:
4754
					#撰寫log
4755
					#回傳結果:
4756
					#$result["status"],狀態,"true"或"false".
4757
					#$result["error"],錯誤訊息陣列.
4758
					#$result["function"],當前函式的名稱.
4759
					#$result["argu"],使用的參數.
4760
					#$result["content"],要寫入log的內容字串.
4761
					#必填參數:
4762
					#$conf["path"],字串,log檔案的路徑與名稱.
4763
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4764
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4765
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4766
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4767
					$conf["logs::record"]["fileArgu"]=__FILE__;
4768
					#可省略參數:
4769
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4770
					#$conf["rewrite"]="false";
4771
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4772
					#$conf["returnOnly"]="true";
4773
					#參考資料:
4774
					#無.
4775
					#備註:
4776
					#無.
4777
					$record=logs::record($conf["logs::record"]);
4778
					unset($conf["logs::record"]);
4779
 
4780
					}#if end
4781
 
4782
				}#if end
4783
 
404 liveuser 4784
			*/
4785
 
249 liveuser 4786
			#針對 zone file 中既有的每個RR記錄
4787
			foreach($result["content"] as $index => $oldRR){
4788
 
4789
				#如果既有的跟新的RR都為 $ORIGIN
4790
				if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
4791
 
4792
					#取代既有的 RR
4793
					$result["content"][$index]=$newRR;
4794
 
4795
					#換看下一筆newRR
4796
					continue 2;
4797
 
4798
					}#if end
4799
 
4800
				#如果既有的跟新的RR都為 $TTL
4801
				if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
4802
 
4803
					#取代既有的 RR
4804
					$result["content"][$index]=$newRR;
4805
 
4806
					#換看下一筆newRR
4807
					continue 2;
4808
 
4809
					}#if end
4810
 
253 liveuser 4811
				#如果新舊資料都有query資訊
4812
				if( isset($newRR["query"]) && isset($oldRR["query"]) ){
249 liveuser 4813
 
253 liveuser 4814
					#如果跟既有的 query、type、value 有相同
4815
					if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
249 liveuser 4816
 
253 liveuser 4817
						#如果新 RR 有 update time
4818
						if(isset($newRR["update"])){
249 liveuser 4819
 
253 liveuser 4820
							#如果新舊 update time 不相同
4821
							if( $newRR["update"] !== $oldRR["update"] ){
249 liveuser 4822
 
253 liveuser 4823
								#取代既有的 RR
4824
								$result["content"][$index]=$newRR;
4825
 
4826
								#換看下一筆newRR
4827
								continue 2;
4828
 
4829
								}#if end
4830
 
4831
							}#if end
249 liveuser 4832
 
253 liveuser 4833
						#反之既有的 update time 若跟 global TTL 不一樣
4834
						else if( $oldRR["update"] !== $result["defaultTTL"] ){
4835
 
4836
							#更新為 global TTL
4837
							$result["content"][$index]["update"]=$result["defaultTTL"];
4838
 
249 liveuser 4839
							}#if end
253 liveuser 4840
 
4841
						#如果新 RR 有 comment
4842
						if( isset($newRR["comment"]) ){
249 liveuser 4843
 
253 liveuser 4844
							#更新既有 RR 的 comment
4845
							$result["content"][$index]["comment"]=$newRR["comment"];
249 liveuser 4846
 
253 liveuser 4847
							#換看下一筆newRR
4848
							continue 2;
249 liveuser 4849
 
253 liveuser 4850
							}#if end
4851
 
4852
						#反之,如果有既有 comment
4853
						else if(isset($result["content"][$index]["comment"])){
249 liveuser 4854
 
253 liveuser 4855
							#移除既有 comment
4856
							unset($result["content"][$index]["comment"]);
4857
 
4858
							#換看下一筆newRR
4859
							continue 2;
249 liveuser 4860
 
253 liveuser 4861
							}#else end
249 liveuser 4862
 
253 liveuser 4863
						}#if end
294 liveuser 4864
 
404 liveuser 4865
					#反之如果跟既有的 query、type有相同,且type 為 "CNAME" 或 "CAA"
4866
					else if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && ( $newRR["type"]==="CNAME" || $newRR["type"]==="CAA" ) ){
294 liveuser 4867
 
4868
						#更新既有 RR 的 value
4869
						$result["content"][$index]["value"]=$newRR["value"];
4870
 
4871
						#換看下一筆newRR
4872
						continue 2;
4873
 
4874
						}#if end
4875
 
249 liveuser 4876
					}#if end
253 liveuser 4877
 
249 liveuser 4878
				}#foreach end
4879
 
4880
			#儲存確定要新增的RR
4881
			$result["content"][]=$newRR;
4882
 
4883
			}#foreach end
4884
 
255 liveuser 4885
		#如果要debug
4886
		if($conf["debug"]==="true"){
249 liveuser 4887
 
255 liveuser 4888
			#函式說明:
4889
			#撰寫log
4890
			#回傳結果:
4891
			#$result["status"],狀態,"true"或"false".
4892
			#$result["error"],錯誤訊息陣列.
4893
			#$result["function"],當前函式的名稱.
4894
			#$result["argu"],使用的參數.
4895
			#$result["content"],要寫入log的內容字串.
4896
			#必填參數:
4897
			#$conf["path"],字串,log檔案的路徑與名稱.
4898
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4899
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4900
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
4901
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4902
			$conf["logs::record"]["fileArgu"]=__FILE__;
4903
			#可省略參數:
4904
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4905
			#$conf["rewrite"]="false";
4906
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4907
			#$conf["returnOnly"]="true";
4908
			#參考資料:
4909
			#無.
4910
			#備註:
4911
			#無.
4912
			$record=logs::record($conf["logs::record"]);
4913
			unset($conf["logs::record"]);
249 liveuser 4914
 
255 liveuser 4915
			}#if end
4916
 
4917
		#如果要debug
4918
		if($conf["debug"]==="true"){
4919
 
4920
			#函式說明:
4921
			#撰寫log
4922
			#回傳結果:
4923
			#$result["status"],狀態,"true"或"false".
4924
			#$result["error"],錯誤訊息陣列.
4925
			#$result["function"],當前函式的名稱.
4926
			#$result["argu"],使用的參數.
4927
			#$result["content"],要寫入log的內容字串.
4928
			#必填參數:
4929
			#$conf["path"],字串,log檔案的路徑與名稱.
4930
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4931
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4932
			$conf["logs::record"]["content"]=$result["content"];
4933
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4934
			$conf["logs::record"]["fileArgu"]=__FILE__;
4935
			#可省略參數:
4936
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4937
			#$conf["rewrite"]="false";
4938
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4939
			#$conf["returnOnly"]="true";
4940
			#參考資料:
4941
			#無.
4942
			#備註:
4943
			#無.
4944
			$record=logs::record($conf["logs::record"]);
4945
			unset($conf["logs::record"]);
4946
 
4947
			}#if end
4948
 
249 liveuser 4949
		#初始化要寫入的內容
4950
		$strs2write=array();
4951
 
4952
		#針對每個RR記錄
4953
		foreach($result["content"] as $RR){
4954
 
4955
			#初始化暫存要寫入的行內容
4956
			$str2write="";
4957
 
4958
			#如果是
4959
			if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
4960
 
4961
				#組合變數名稱與數值
4962
				$str2write=$str2write.$RR["type"]."\t".$RR["value"];
4963
 
4964
				}#if end
4965
 
4966
			#反之
4967
			else{
4968
 
4969
				#加上查詢的字句
4970
				$str2write=$str2write.$RR["query"];
4971
 
4972
				#如果該筆RR有指定update time該ZONE具備 global TTL.
4973
				if(isset($RR["update"])){
4974
 
4975
					#如果 該ZONE具備 global TTL.
4976
					if(isset($result["defaultTTL"])){
4977
 
4978
						#如果該筆 RR 的 update time 不等於 global TTL
4979
						if($RR["update"]!==$result["defaultTTL"]){
4980
 
4981
							#加上TTL的字句
4982
							$str2write=$str2write."\t".$RR["update"];
4983
 
4984
							}#if end
4985
 
4986
						}#if end
4987
 
4988
					#反之
4989
					else{
4990
 
4991
						#加上TTL的字句
4992
						$str2write=$str2write."\t".$RR["update"];
4993
 
4994
						}#else end
4995
 
4996
					}#if end
4997
 
253 liveuser 4998
				#反之且該ZONE不具備 global TTL.
4999
				else if(!isset($result["defaultTTL"])){
249 liveuser 5000
 
5001
					#加上global TTL的字句
5002
					$str2write=$str2write."\t".$result["defaultTTL"];
5003
 
253 liveuser 5004
					}#if end
249 liveuser 5005
 
5006
				#加上IN跟TYPE跟value
5007
				$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
5008
 
5009
				}#else end
5010
 
5011
			#如果有註解
5012
			if(isset($RR["comment"])){
5013
 
5014
				#加上comment
5015
				$str2write=$str2write.";".$RR["comment"];
5016
 
5017
				}#if end
5018
 
253 liveuser 5019
			#如果要 debug
5020
			if($conf["debug"]==="true"){
249 liveuser 5021
 
253 liveuser 5022
				#函式說明:
5023
				#撰寫log
5024
				#回傳結果:
5025
				#$result["status"],狀態,"true"或"false".
5026
				#$result["error"],錯誤訊息陣列.
5027
				#$result["function"],當前函式的名稱.
5028
				#$result["argu"],使用的參數.
5029
				#$result["content"],要寫入log的內容字串.
5030
				#必填參數:
5031
				#$conf["path"],字串,log檔案的路徑與名稱.
5032
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5033
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5034
				$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
5035
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5036
				$conf["logs::record"]["fileArgu"]=__FILE__;
5037
				#可省略參數:
5038
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5039
				#$conf["rewrite"]="false";
5040
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5041
				#$conf["returnOnly"]="true";
5042
				#參考資料:
5043
				#無.
5044
				#備註:
5045
				#無.
5046
				$record=logs::record($conf["logs::record"]);
5047
				unset($conf["logs::record"]);
5048
 
5049
				}#if end
5050
 
249 liveuser 5051
			#加上要寫入的元素
5052
			$strs2write[]=$str2write;
5053
 
5054
			}#foreach end
5055
 
5056
		#如果有逐行註解
5057
		if(count($result["comment"])>0){
5058
 
5059
			#加到結尾
5060
			#函式說明:
5061
			#將多個一維陣列串聯起來,key從0開始排序.
5062
			#回傳的結果:
5063
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
5064
			#$result["error"],錯誤訊息陣列.
5065
			#$result["function"],當前執行的函數.
5066
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5067
			#$result["content"],合併好的一維陣列.
5068
			#必填參數
5069
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
5070
			$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
5071
			#可省略參數:
5072
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
5073
			#$conf["allowRepeat"]="true";
5074
			#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
5075
			#$conf["looseDiff"]="false";
5076
			#參考資料:
5077
			#無.
5078
			#備註:
5079
			#無.
5080
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
5081
			unset($conf["arrays::mergeArray"]);
5082
 
5083
			#如果執行異常
5084
			if($mergeArray["status"]==="false"){
5085
 
5086
				#設置錯誤識別
5087
				$result["status"]="false";
5088
 
5089
				#設置錯誤訊息
5090
				$result["error"]=$mergeArray;
5091
 
5092
				#回傳結果
5093
				return $result;
5094
 
5095
				}#if end
5096
 
5097
			#取得合併好的陣列
5098
			$strs2write=$mergeArray["content"];
5099
 
5100
			}#if end
5101
 
253 liveuser 5102
		#如果要 debug
5103
		if($conf["debug"]==="true"){
249 liveuser 5104
 
253 liveuser 5105
			#函式說明:
5106
			#撰寫log
5107
			#回傳結果:
5108
			#$result["status"],狀態,"true"或"false".
5109
			#$result["error"],錯誤訊息陣列.
5110
			#$result["function"],當前函式的名稱.
5111
			#$result["argu"],使用的參數.
5112
			#$result["content"],要寫入log的內容字串.
5113
			#必填參數:
5114
			#$conf["path"],字串,log檔案的路徑與名稱.
5115
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5116
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5117
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
5118
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5119
			$conf["logs::record"]["fileArgu"]=__FILE__;
5120
			#可省略參數:
5121
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5122
			#$conf["rewrite"]="false";
5123
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5124
			#$conf["returnOnly"]="true";
5125
			#參考資料:
5126
			#無.
5127
			#備註:
5128
			#無.
5129
			$record=logs::record($conf["logs::record"]);
5130
			unset($conf["logs::record"]);
5131
 
5132
			}#if end
5133
 
249 liveuser 5134
		#儲存新zone file每行的內容
5135
		$result["newZoneFileContent"]=$strs2write;
5136
 
5137
		#如果要寫入ZONE檔案
5138
		if($conf["writeNow"]==="true"){
5139
 
5140
			#覆寫 ZONE file
5141
			#函式說明:
5142
			#更新檔案的內容.
5143
			#回傳結果:
5144
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5145
			#$result["error"],錯誤訊息.
5146
			#$result["function"],當前執行的函數名稱.
5147
			#$result["content"],更新的資訊.
5148
			#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
5149
			#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
5150
			#必填參數:
5151
			#$conf["fileArgu"],字串,變數__FILE__的內容.
5152
			$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
5153
			#$conf["file"],字串,要更新的檔案位置與名稱.
5154
			$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
5155
			#可省略參數:
5156
			#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
5157
			$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
5158
			#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
5159
			#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
5160
			#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
5161
			#$conf["replaceLike"]="false";
5162
			#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
5163
			#$conf["addToTailWhenNoMatch"]="false";
5164
			#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
5165
			#$conf["addToTailBeforeThat"]="?\>";
5166
			#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
5167
			#$conf["replaceSpecifyLine"]=array();
5168
			#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
5169
			#$conf["outputPath"]="";
5170
			#參考資料:
5171
			#無.
5172
			#備註:
5173
			#無.
5174
			$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
5175
			unset($conf["fileAccess::updateFile"]);
5176
 
5177
			#如果執行異常
5178
			if($updateFile["status"]==="false"){
5179
 
5180
				#設置錯誤識別
5181
				$result["status"]="false";
5182
 
5183
				#設置錯誤訊息
5184
				$result["error"]=$updateFile;
5185
 
5186
				#回傳結果
5187
				return $result;
5188
 
5189
				}#if end
291 liveuser 5190
 
5191
			#修正 zone file 的權限
5192
			#函式說明:
5193
			#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
5194
			#回傳結果:
5195
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5196
			#$result["error"],錯誤訊息.
5197
			#$result["function"],當前執行的函式名稱.
5198
			#$result["cmd"],執行的指令.
5199
			#必填參數:
5200
			#$conf["owner"],字串,要變哪個使用者擁有.
5201
			$conf["cmd::chown"]["owner"]="root";
5202
			#$conf["target"],字串,需要變更擁有者、 群組的目標.
5203
			$conf["cmd::chown"]["target"]=$conf["dnsRecordFile"];
5204
			#可省略參數:
5205
			#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
5206
			$conf["cmd::chown"]["group"]=webUser;
5207
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
5208
			#$conf["recursive"]="true";
5209
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
5210
			#$conf["excludeSelf"]="true";
5211
			#參考資料:
5212
			#無.
5213
			#備註:
5214
			#無.
5215
			$chown=cmd::chown($conf["cmd::chown"]);
5216
			unset($conf["cmd::chown"]);
249 liveuser 5217
 
291 liveuser 5218
			#如果執行異常
5219
			if($chown["status"]==="false"){
5220
 
5221
				#設置錯誤識別
5222
				$result["status"]="false";
5223
 
5224
				#設置錯誤訊息
5225
				$result["error"]=$chown;
5226
 
5227
				#回傳結果
5228
				return $result;
5229
 
5230
				}#if end
5231
 
5232
			#函式說明:
5233
			#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
5234
			#回傳結果:
5235
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5236
			#$result["error"],錯誤訊息.
5237
			#$result["function"],當前執行的函式名稱.
5238
			#$result["cmd"],執行的指令.
5239
			#必填參數:
5240
			#$conf["mode"],字串,要變成什麼權限.
5241
			$conf["cmd::chmod"]["mode"]="774";
5242
			#$conf["target"],字串,需要變更權限的目標.
5243
			$conf["cmd::chmod"]["target"]=$conf["dnsRecordFile"];
5244
			#可省略參數:
5245
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
5246
			#$conf["recursive"]="true";
5247
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
5248
			#$conf["excludeSelf"]="true";
5249
			#參考資料:
5250
			#無.
5251
			#備註:
5252
			#無.
5253
			$chmod=cmd::chmod($conf["cmd::chmod"]);
5254
			unset($conf["cmd::chmod"]);
5255
 
5256
			#如果執行異常
5257
			if($chmod["status"]==="false"){
5258
 
5259
				#設置錯誤識別
5260
				$result["status"]="false";
5261
 
5262
				#設置錯誤訊息
5263
				$result["error"]=$chmod;
5264
 
5265
				#回傳結果
5266
				return $result;
5267
 
5268
				}#if end
5269
 
249 liveuser 5270
			}#if end
5271
 
5272
		#設置執行正常
5273
		$result["status"]="true";
5274
 
5275
		#回傳結果
5276
		return $result;
5277
 
5278
		}#function updateDnsRecordFile end
5279
 
5280
	/*
5281
	#函式說明:
255 liveuser 5282
	#請求驗證已經透過zerossl::createCertificate要求的domain.
249 liveuser 5283
	#回傳結果:
5284
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5285
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5286
	#$result["function"],當前執行的函式名稱.
5287
	#$result["argu"],所使用的參數.
5288
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 5289
	#$result["content"],結果json字串.
249 liveuser 5290
	#必填參數:
5291
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
5292
	$conf["id"]="";
5293
	#可省略參數:
5294
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5295
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5296
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5297
	#$conf["key"]=self::getApiInfo()["apiKey"];
5298
	#參考資料:
255 liveuser 5299
	#https://zerossl.com/documentation/api/verify-domains/
249 liveuser 5300
	#備註:
5301
	#無.
5302
	*/
5303
	public static function verifyDomain(&$conf){
5304
 
5305
		#初始化要回傳的結果
5306
		$result=array();
5307
 
5308
		#設置當其函數名稱
5309
		$result["function"]=__FUNCTION__;
5310
 
5311
		#如果 $conf 不為陣列
5312
		if(gettype($conf)!="array"){
5313
 
5314
			#設置執行失敗
5315
			$result["status"]="false";
5316
 
5317
			#設置執行錯誤訊息
5318
			$result["error"][]="\$conf變數須為陣列形態";
5319
 
5320
			#如果傳入的參數為 null
5321
			if($conf==null){
5322
 
5323
				#設置執行錯誤訊息
5324
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5325
 
5326
				}#if end
5327
 
5328
			#回傳結果
5329
			return $result;
5330
 
5331
			}#if end
5332
 
5333
		#取得參數
5334
		$result["argu"]=$conf;
5335
 
5336
		#檢查參數
5337
		#函式說明:
5338
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5339
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5340
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5341
		#$result["function"],當前執行的函式名稱.
5342
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5343
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5344
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5345
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5346
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5347
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5348
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5349
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5350
		#必填寫的參數:
5351
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5352
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5353
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5354
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5355
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5356
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5357
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5358
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5359
		#可以省略的參數:
5360
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5361
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5362
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5363
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5364
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5365
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
5366
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5367
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5368
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 5369
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
249 liveuser 5370
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5371
		#$conf["arrayCountEqualCheck"][]=array();
5372
		#參考資料來源:
5373
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5374
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5375
		unset($conf["variableCheck::checkArguments"]);
5376
 
5377
		#如果檢查失敗
5378
		if($checkArguments["status"]==="false"){
5379
 
5380
			#設置錯誤識別
5381
			$result["status"]="false";
5382
 
5383
			#設置錯誤訊息
5384
			$result["error"]=$checkArguments;
5385
 
5386
			#回傳結果
5387
			return $result;
5388
 
5389
			}#if end
5390
 
5391
		#如果檢查不通過
5392
		if($checkArguments["passed"]==="false"){
5393
 
5394
			#設置錯誤識別
5395
			$result["status"]="false";
5396
 
5397
			#設置錯誤訊息
5398
			$result["error"]=$checkArguments;
5399
 
5400
			#回傳結果
5401
			return $result;
5402
 
5403
			}#if end
5404
 
5405
		#要傳送的 key -> value
5406
		$postArray=array();
5407
 
5408
		#設置要簽署的domain
5409
		$postArray["validation_method"]="CNAME_CSR_HASH";
5410
 
5411
		#設置要傳送的 json
5412
		$postJson=json_encode($postArray);
5413
 
5414
		#函式說明:
5415
		#運行curl cmd
5416
		#回傳結果:
5417
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5418
		#$result["error"],錯誤訊息陣列.
5419
		#$result["function"],當前執行的函式名稱.
5420
		#$result["founded"],識別網址找不找得到.
5421
		#$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"代表程序的資訊.
5422
		#$result["fullContent"],取得回應的完整字串內容.
5423
		#$result["cookie"],cookie檔案的位置與名稱.
5424
		#$result["cmd"],執行的command.
5425
		#$result["argu],使用的參數.
5426
		#必填參數:
5427
		#$conf["url"],字串,目標url.
255 liveuser 5428
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
249 liveuser 5429
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5430
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5431
		#可省略參數:
5432
		#$conf["header"],字串陣列,要傳送的header.
5433
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5434
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5435
		#$conf["allowAnySSLcertificate"]="";
5436
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5437
		#$conf["postVar"]=array();
5438
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5439
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5440
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5441
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5442
		#$conf["agent"],字串,user agent的名稱.
5443
		#$conf["agent"]="";
5444
		#$conf["cookie"],字串,cookie位置與檔案位置.
5445
		#$conf["cookie"]="";
5446
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5447
		#$conf["forceNewCookie"]="";
5448
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5449
		#$conf["inBg"]="true";
5450
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5451
		#$conf["bgInProc"]="false";
5452
		#參考資料:
5453
		#無.
5454
		#備註:
5455
		#無.
5456
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5457
		unset($conf["catchWebContent::curlCmd"]);
5458
 
5459
		#如果異常
5460
		if($curlCmd["status"]==="false"){
5461
 
5462
			#設置錯誤識別
5463
			$result["status"]="false";
5464
 
5465
			#設置錯誤訊息
5466
			$result["error"]=$curlCmd;
5467
 
5468
			#回傳結果
5469
			return $result;
5470
 
5471
			}#if end
5472
 
5473
		#設置curl的詳細資訊
5474
		$result["curl_verbose_info"]=$curlCmd;
5475
 
255 liveuser 5476
		#驗證結果是否為 json
5477
		$json_validate=json_validate($curlCmd["fullContent"]);
5478
 
5479
		#如果回應不是 json
5480
		if(!$json_validate){
249 liveuser 5481
 
255 liveuser 5482
			#設置錯誤識別
5483
			$result["status"]="false";
5484
 
5485
			#設置錯誤訊息
5486
			$result["error"]=$curlCmd;
5487
 
5488
			#回傳結果
5489
			return $result;
5490
 
5491
			}#if end
5492
 
5493
		#設置json string結果
5494
		$result["content"]=$curlCmd["fullContent"];
5495
 
5496
		#解析json
5497
		$jsonRes=json_decode($result["content"]);
5498
 
293 liveuser 5499
		#如果有 success 資訊
5500
		if(isset($jsonRes->success)){
255 liveuser 5501
 
293 liveuser 5502
			#do nothing
5503
 
5504
			}#if end
5505
 
5506
		#反之如果沒有 status
5507
		else if(!isset($jsonRes->status)){
5508
 
255 liveuser 5509
			#設置錯誤識別
5510
			$result["status"]="false";
5511
 
5512
			#設置錯誤訊息
5513
			$result["error"]=$curlCmd;
5514
 
5515
			#回傳結果
5516
			return $result;
5517
 
5518
			}#if end
5519
 
293 liveuser 5520
		#反之有 status 資訊
5521
		else{
255 liveuser 5522
 
293 liveuser 5523
			#如果是 "pending_validation"
5524
			if($jsonRes->status==="pending_validation"){
255 liveuser 5525
 
293 liveuser 5526
				#do nothing
255 liveuser 5527
 
293 liveuser 5528
				}#if end
5529
 
5530
			#反之如果為 "issued"
5531
			else if($jsonRes->status==="issued"){
5532
 
5533
				#do nothing
5534
 
5535
				}#else 
5536
 
5537
			#反之
5538
			else{
5539
 
5540
				#設置錯誤識別
5541
				$result["status"]="false";
255 liveuser 5542
 
293 liveuser 5543
				#設置錯誤訊息
5544
				$result["error"]=$curlCmd;
255 liveuser 5545
 
293 liveuser 5546
				#回傳結果
5547
				return $result;
5548
 
5549
				}#else end
255 liveuser 5550
 
5551
			}#else end
5552
 
5553
		#設置執行正常
5554
		$result["status"]="true";
5555
 
5556
		#回傳結果
5557
		return $result;
5558
 
5559
		}#function verifyDomain end
5560
 
5561
	/*
5562
	#函式說明:
5563
	#取得CSR在zerossl上的狀態
5564
	#回傳結果:
5565
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5566
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5567
	#$result["function"],當前執行的函式名稱.
5568
	#$result["argu"],所使用的參數.
5569
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5570
	#$result["content"],結果json字串.
5571
	#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5572
	#必填參數:
5573
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
5574
	$conf["id"]="";
5575
	#可省略參數:
5576
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5577
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5578
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5579
	#$conf["key"]=self::getApiInfo()["apiKey"];
5580
	#參考資料:
5581
	#https://zerossl.com/documentation/api/get-certificate/
5582
	#備註:
5583
	#無.
5584
	*/
5585
	public static function getCertSta(&$conf){
5586
 
5587
		#初始化要回傳的結果
5588
		$result=array();
5589
 
5590
		#設置當其函數名稱
5591
		$result["function"]=__FUNCTION__;
5592
 
5593
		#如果 $conf 不為陣列
5594
		if(gettype($conf)!="array"){
5595
 
5596
			#設置執行失敗
5597
			$result["status"]="false";
5598
 
5599
			#設置執行錯誤訊息
5600
			$result["error"][]="\$conf變數須為陣列形態";
5601
 
5602
			#如果傳入的參數為 null
5603
			if($conf==null){
5604
 
5605
				#設置執行錯誤訊息
5606
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5607
 
5608
				}#if end
5609
 
5610
			#回傳結果
5611
			return $result;
5612
 
5613
			}#if end
5614
 
5615
		#取得參數
5616
		$result["argu"]=$conf;
291 liveuser 5617
 
5618
		#DEBUG
5619
		#var_dump(__LINE__,self::getApiInfo());exit;
255 liveuser 5620
 
5621
		#檢查參數
5622
		#函式說明:
5623
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5624
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5625
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5626
		#$result["function"],當前執行的函式名稱.
5627
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5628
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5629
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5630
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5631
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5632
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5633
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5634
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5635
		#必填寫的參數:
5636
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5637
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5638
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5639
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5640
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5641
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5642
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5643
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5644
		#可以省略的參數:
5645
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5646
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5647
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5648
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5649
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5650
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
5651
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5652
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5653
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5654
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
5655
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5656
		#$conf["arrayCountEqualCheck"][]=array();
5657
		#參考資料來源:
5658
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5659
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5660
		unset($conf["variableCheck::checkArguments"]);
5661
 
5662
		#如果檢查失敗
5663
		if($checkArguments["status"]==="false"){
5664
 
5665
			#設置錯誤識別
5666
			$result["status"]="false";
5667
 
5668
			#設置錯誤訊息
5669
			$result["error"]=$checkArguments;
5670
 
5671
			#回傳結果
5672
			return $result;
5673
 
5674
			}#if end
5675
 
5676
		#如果檢查不通過
5677
		if($checkArguments["passed"]==="false"){
5678
 
5679
			#設置錯誤識別
5680
			$result["status"]="false";
5681
 
5682
			#設置錯誤訊息
5683
			$result["error"]=$checkArguments;
5684
 
5685
			#回傳結果
5686
			return $result;
5687
 
5688
			}#if end
5689
 
5690
		#函式說明:
5691
		#運行curl cmd
5692
		#回傳結果:
5693
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5694
		#$result["error"],錯誤訊息陣列.
5695
		#$result["function"],當前執行的函式名稱.
5696
		#$result["founded"],識別網址找不找得到.
5697
		#$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"代表程序的資訊.
5698
		#$result["fullContent"],取得回應的完整字串內容.
5699
		#$result["cookie"],cookie檔案的位置與名稱.
5700
		#$result["cmd"],執行的command.
5701
		#$result["argu],使用的參數.
5702
		#必填參數:
5703
		#$conf["url"],字串,目標url.
5704
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
5705
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5706
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5707
		#可省略參數:
5708
		#$conf["header"],字串陣列,要傳送的header.
5709
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5710
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5711
		#$conf["allowAnySSLcertificate"]="";
5712
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5713
		#$conf["postVar"]=array();
5714
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5715
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5716
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5717
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5718
		#$conf["agent"],字串,user agent的名稱.
5719
		#$conf["agent"]="";
5720
		#$conf["cookie"],字串,cookie位置與檔案位置.
5721
		#$conf["cookie"]="";
5722
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5723
		#$conf["forceNewCookie"]="";
5724
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5725
		#$conf["inBg"]="true";
5726
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5727
		#$conf["bgInProc"]="false";
5728
		#參考資料:
5729
		#無.
5730
		#備註:
5731
		#無.
5732
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5733
		unset($conf["catchWebContent::curlCmd"]);
5734
 
5735
		#如果異常
5736
		if($curlCmd["status"]==="false"){
5737
 
5738
			#設置錯誤識別
5739
			$result["status"]="false";
5740
 
5741
			#設置錯誤訊息
5742
			$result["error"]=$curlCmd;
5743
 
5744
			#回傳結果
5745
			return $result;
5746
 
5747
			}#if end
5748
 
5749
		#設置curl的詳細資訊
5750
		$result["curl_verbose_info"]=$curlCmd;
5751
 
5752
		#驗證結果是否為 json
5753
		$json_validate=json_validate($curlCmd["fullContent"]);
5754
 
5755
		#如果回應不是 json
5756
		if(!$json_validate){
5757
 
5758
			#設置錯誤識別
5759
			$result["status"]="false";
5760
 
5761
			#設置錯誤訊息
5762
			$result["error"]=$curlCmd;
5763
 
5764
			#回傳結果
5765
			return $result;
5766
 
5767
			}#if end
5768
 
5769
		#設置json string結果
5770
		$result["content"]=$curlCmd["fullContent"];
5771
 
5772
		#解析json
5773
		$jsonRes=json_decode($result["content"]);
5774
 
5775
		#如果沒有 status
5776
		if(!isset($jsonRes->status)){
5777
 
5778
			#設置錯誤識別
5779
			$result["status"]="false";
5780
 
5781
			#設置錯誤訊息
5782
			$result["error"]=$curlCmd;
5783
 
5784
			#回傳結果
5785
			return $result;
5786
 
5787
			}#if end
5788
 
5789
		#取得csr在zerossl上的狀態
5790
		$result["cerStatus"]=$jsonRes->status;
5791
 
5792
		#設置執行正常
5793
		$result["status"]="true";
5794
 
5795
		#回傳結果
5796
		return $result;
5797
 
5798
		}#function getCertSta end
5799
 
5800
	/*
5801
	#函式說明:
5802
	#取得在zerossl上的CSR清單
5803
	#回傳結果:
5804
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5805
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5806
	#$result["function"],當前執行的函式名稱.
5807
	#$result["argu"],所使用的參數.
5808
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5809
	#$result["content"],結果json字串.
5810
	#$result["tCount"],總共的資料筆數.
5811
	#$result["count"],該頁的筆數.
5812
	#$result["page"],當前的頁碼.
5813
	#$result["certs"],陣列,certificates清單,key為certificate的id.
5814
	#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
5815
	#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
5816
	#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
5817
	#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
5818
	#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5819
	#必填參數:
5820
	#無
5821
	#可省略參數:
5822
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5823
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5824
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5825
	#$conf["key"]=self::getApiInfo()["apiKey"];
5826
	#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5827
	#$conf["cerStatus"]="";
309 liveuser 5828
	#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;"multiDomain90Days"多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
255 liveuser 5829
	#$conf["cerType"]="";
5830
	#$conf["search"],字串,透過certificate包含的domain來搜尋.
5831
	#$conf["search"]="";
5832
	#$conf["limit"],字串,一頁要多少筆,預設為100筆.
5833
	#$conf["limit"]="";
5834
	#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
5835
	#$conf["page"]="";
5836
	#參考資料:
5837
	#https://zerossl.com/documentation/api/list-certificates/
5838
	#備註:
5839
	#無.
5840
	*/
5841
	public static function getCertList(&$conf){
5842
 
5843
		#初始化要回傳的結果
5844
		$result=array();
5845
 
5846
		#設置當其函數名稱
5847
		$result["function"]=__FUNCTION__;
5848
 
5849
		#如果 $conf 不為陣列
5850
		if(gettype($conf)!="array"){
5851
 
5852
			#設置執行失敗
5853
			$result["status"]="false";
5854
 
5855
			#設置執行錯誤訊息
5856
			$result["error"][]="\$conf變數須為陣列形態";
5857
 
5858
			#如果傳入的參數為 null
5859
			if($conf==null){
5860
 
5861
				#設置執行錯誤訊息
5862
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5863
 
5864
				}#if end
5865
 
5866
			#回傳結果
5867
			return $result;
5868
 
5869
			}#if end
5870
 
5871
		#取得參數
5872
		$result["argu"]=$conf;
5873
 
5874
		#檢查參數
5875
		#函式說明:
5876
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5877
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5878
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5879
		#$result["function"],當前執行的函式名稱.
5880
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5881
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5882
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5883
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5884
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5885
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5886
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5887
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5888
		#必填寫的參數:
5889
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5890
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5891
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5892
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5893
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5894
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5895
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5896
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5897
		#可以省略的參數:
5898
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5899
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5900
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5901
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5902
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5903
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
5904
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5905
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
5906
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5907
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
5908
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5909
		#$conf["arrayCountEqualCheck"][]=array();
5910
		#參考資料來源:
5911
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5912
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5913
		unset($conf["variableCheck::checkArguments"]);
5914
 
5915
		#如果檢查失敗
5916
		if($checkArguments["status"]==="false"){
5917
 
5918
			#設置錯誤識別
5919
			$result["status"]="false";
5920
 
5921
			#設置錯誤訊息
5922
			$result["error"]=$checkArguments;
5923
 
5924
			#回傳結果
5925
			return $result;
5926
 
5927
			}#if end
5928
 
5929
		#如果檢查不通過
5930
		if($checkArguments["passed"]==="false"){
5931
 
5932
			#設置錯誤識別
5933
			$result["status"]="false";
5934
 
5935
			#設置錯誤訊息
5936
			$result["error"]=$checkArguments;
5937
 
5938
			#回傳結果
5939
			return $result;
5940
 
5941
			}#if end
5942
 
5943
		#預設網址
291 liveuser 5944
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."?access_key=".$conf["key"];
255 liveuser 5945
 
5946
		#如果有設置 cerStatus
5947
		if(isset($conf["cerStatus"])){
5948
 
5949
			#設置 certificate_status 
291 liveuser 5950
			$url=$url."&certificate_status=".urlencode($conf["cerStatus"]);
255 liveuser 5951
 
5952
			}#if end
5953
 
5954
		#如果有設置 cerType
5955
		if(isset($conf["cerType"])){
5956
 
5957
			#設置 certificate_type
291 liveuser 5958
			$url=$url."&certificate_type=".urlencode($conf["cerType"]);
255 liveuser 5959
 
5960
			}#if end
5961
 
5962
		#如果有設置 search
5963
		if(isset($conf["search"])){
5964
 
5965
			#設置 search
291 liveuser 5966
			$url=$url."&search=".urlencode($conf["search"]);
255 liveuser 5967
 
5968
			}#if end
5969
 
5970
		#如果有設置 limit
5971
		if(isset($conf["limit"])){
5972
 
5973
			#設置 search
291 liveuser 5974
			$url=$url."&limit=".urlencode($conf["limit"]);
255 liveuser 5975
 
5976
			}#if end
5977
 
5978
		#如果有設置 page
5979
		if(isset($conf["page"])){
5980
 
5981
			#設置 search
291 liveuser 5982
			$url=$url."&"."page=".urlencode($conf["page"]);
255 liveuser 5983
 
5984
			}#if end
5985
 
5986
		#函式說明:
5987
		#運行curl cmd
5988
		#回傳結果:
5989
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5990
		#$result["error"],錯誤訊息陣列.
5991
		#$result["function"],當前執行的函式名稱.
5992
		#$result["founded"],識別網址找不找得到.
5993
		#$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"代表程序的資訊.
5994
		#$result["fullContent"],取得回應的完整字串內容.
5995
		#$result["cookie"],cookie檔案的位置與名稱.
5996
		#$result["cmd"],執行的command.
5997
		#$result["argu],使用的參數.
5998
		#必填參數:
5999
		#$conf["url"],字串,目標url.
6000
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6001
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6002
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6003
		#可省略參數:
6004
		#$conf["header"],字串陣列,要傳送的header.
6005
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
6006
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6007
		#$conf["allowAnySSLcertificate"]="";
6008
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6009
		#$conf["postVar"]=array();
6010
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6011
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6012
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
6013
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
6014
		#$conf["agent"],字串,user agent的名稱.
6015
		#$conf["agent"]="";
6016
		#$conf["cookie"],字串,cookie位置與檔案位置.
6017
		#$conf["cookie"]="";
6018
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6019
		#$conf["forceNewCookie"]="";
6020
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6021
		#$conf["inBg"]="true";
6022
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6023
		#$conf["bgInProc"]="false";
6024
		#參考資料:
6025
		#無.
6026
		#備註:
6027
		#無.
6028
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6029
		unset($conf["catchWebContent::curlCmd"]);
6030
 
6031
		#如果異常
6032
		if($curlCmd["status"]==="false"){
6033
 
6034
			#設置錯誤識別
6035
			$result["status"]="false";
6036
 
6037
			#設置錯誤訊息
6038
			$result["error"]=$curlCmd;
6039
 
6040
			#回傳結果
6041
			return $result;
6042
 
6043
			}#if end
6044
 
6045
		#設置curl的詳細資訊
6046
		$result["curl_verbose_info"]=$curlCmd;
6047
 
6048
		#驗證結果是否為 json
6049
		$json_validate=json_validate($curlCmd["fullContent"]);
6050
 
6051
		#如果回應不是 json
6052
		if(!$json_validate){
6053
 
6054
			#設置錯誤識別
6055
			$result["status"]="false";
6056
 
6057
			#設置錯誤訊息
6058
			$result["error"]=$curlCmd;
6059
 
6060
			#回傳結果
6061
			return $result;
6062
 
6063
			}#if end
6064
 
6065
		#設置json string結果
6066
		$result["content"]=$curlCmd["fullContent"];
6067
 
6068
		/* json response 範例
6069
		{
6070
			"total_count": 11,
6071
			"result_count": 10,
6072
			"page": 1,
6073
			"limit": 10,
6074
			"acmeUsageLevel": "LOW",
6075
			"isAcmeLocked": false,
6076
			"results": 
6077
			[
6078
				{
6079
					"id": "a856a39a1c3ad0s8asa606g37667d221",
6080
					"type": "1",
6081
					"common_name": "domain.com",
6082
					"additional_domains": "www.domain.com",
6083
					"created": "2020-04-29 09:04:19",
6084
					"expires": "2020-07-28 00:00:00",
6085
					"status": "draft",
6086
					"validation_type": null,
6087
					"validation_emails": null,
6088
					"replacement_for": "",
6089
					"fingerprint_sha1": null,
6090
					"brand_validation": null,
6091
					"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
6092
					"validation":
6093
					{
6094
						"email_validation":
6095
						{
6096
							"domain.com":
6097
							[
6098
								"admin@domain.com",
6099
								"administrator@domain.com",
6100
								"hostmaster@domain.com",
6101
								"postmaster@domain.com",
6102
								"webmaster@domain.com"
6103
							]
6104
						},
6105
						"other_methods": 
6106
						{
6107
							"domain.com":
6108
							{
6109
								"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
6110
								"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
6111
								"file_validation_content":
6112
								[
6113
									"2B449B722B449B729394793947",
6114
									"comodoca.com",
6115
									"4bad7360c7076ba"
6116
								],
6117
								"cname_validation_p1": "2B449B7293947.domain.com",
6118
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
6119
							},
6120
							"www.domain.com":
6121
							{
6122
								"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
6123
								"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",   
6124
								"file_validation_content":
6125
								[
6126
									"2B449B722B449B729394793947",
6127
									"comodoca.com",
6128
									"4bad7360c7076ba"
6129
								],
6130
								"cname_validation_p1": "2B449B7293947.www.domain.com",
6131
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
6132
							}
6133
						}
6134
					}
6135
				},
6136
				{
6137
					...
6138
				}
6139
			]
6140
		}
249 liveuser 6141
		*/
6142
 
255 liveuser 6143
		#解析json
6144
		$jsonRes=json_decode($result["content"]);
6145
 
6146
		#總共的資料筆數
6147
		$result["tCount"]=$jsonRes->total_count;
6148
 
6149
		#取得該頁的筆數
6150
		$result["count"]=$jsonRes->result_count;
6151
 
6152
		#取得certificate清單
291 liveuser 6153
		$certs=$jsonRes->results;
255 liveuser 6154
 
6155
		#針對每個certificate
6156
		foreach($certs as $index => $cert){
6157
 
6158
			#初始化暫存的陣列
6159
			$tmpA=array();
6160
 
6161
			#儲存 cert id
6162
			#$tmpA["id"]=$cert->id;
6163
 
6164
			#儲存 主要包含的 domain name
6165
			$tmpA["cname"]=$cert->common_name;
6166
 
6167
			#儲存額外包含的 domain name
6168
			$tmpA["anames"]=$cert->additional_domains;
6169
 
6170
			#最後有效年月日,格式為"2020-07-28 00:00:00".
6171
			$tmpA["expiresYMD"]=$cert->expires;
6172
 
6173
			#產生對於當前系統時間的差距(秒數)
6174
			#函式說明:
6175
			#計算時間點距離1970/01/01多少秒,亦即unixtime.
6176
			#回傳結果:
6177
			#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
6178
			#$result["error"],錯誤訊息陣列.
6179
			#$result["content"],時間點距離1970/01/01的多少秒.
6180
			#$result["argu"],使用的參數.
6181
			#$result["unixtime"],執行本函式時的unixtime.
6182
			#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
6183
			#必填參數:
6184
			#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
6185
			$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
6186
			#可省略參數:
6187
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
6188
			#$conf["UTC"]="false";
6189
			#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
6190
			$conf["time::caculateTimeAmount"]["replace0"]="false";
6191
			#參考資料:
6192
			#無.
6193
			#備註:
6194
			#無.
6195
			$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
6196
			unset($conf["time::caculateTimeAmount"]);
6197
 
6198
			#如果執行異常
291 liveuser 6199
			if($caculateTimeAmount["status"]==="false"){
255 liveuser 6200
 
6201
				#設置錯誤識別
6202
				$result["status"]="false";
6203
 
6204
				#設置錯誤訊息
6205
				$result["error"]=$caculateTimeAmount;
6206
 
6207
				#回傳結果
6208
				return $result;
6209
 
6210
				}#if end
6211
 
6212
			#儲存還要多少秒要過期
291 liveuser 6213
			$tmpA["expiresIn"]=$caculateTimeAmount["content"]-time();
255 liveuser 6214
 
6215
			#憑證的狀態
6216
			$tmpA["status"]=$cert->status;
6217
 
291 liveuser 6218
			#儲存要回傳的 certs 清單,key為cert的id.
6219
			$result["certs"][$cert->id]=$tmpA;
255 liveuser 6220
 
6221
			}#foreach end
6222
 
6223
		#設置執行正常
6224
		$result["status"]="true";
6225
 
6226
		#回傳結果
6227
		return $result;
6228
 
6229
		}#function getCertList end
6230
 
6231
	/*
6232
	#函式說明:
6233
	#下載certificate.
6234
	#回傳結果:
6235
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6236
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6237
	#$result["function"],當前執行的函式名稱.
6238
	#$result["argu"],所使用的參數.
6239
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6240
	#$result["content"],結果json字串.
6241
	#$result["certificate.crt"],字串,certificate.crt的內容.
6242
	#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
6243
	#必填參數:
6244
	#無.
6245
	#可省略參數:
6246
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6247
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6248
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6249
	#$conf["key"]=self::getApiInfo()["apiKey"];
6250
	#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
6251
	#$conf["id"]="";
6252
	#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
6253
	#$conf["cname"]="";
6254
	#參考資料:
6255
	#https://zerossl.com/documentation/api/download-certificate-inline/
6256
	#備註:
6257
	#無.
6258
	*/
6259
	public static function getCert(&$conf){
6260
 
6261
		#初始化要回傳的結果
6262
		$result=array();
6263
 
6264
		#設置當其函數名稱
6265
		$result["function"]=__FUNCTION__;
6266
 
6267
		#如果 $conf 不為陣列
6268
		if(gettype($conf)!="array"){
6269
 
6270
			#設置執行失敗
6271
			$result["status"]="false";
6272
 
6273
			#設置執行錯誤訊息
6274
			$result["error"][]="\$conf變數須為陣列形態";
6275
 
6276
			#如果傳入的參數為 null
6277
			if($conf==null){
6278
 
6279
				#設置執行錯誤訊息
6280
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6281
 
6282
				}#if end
6283
 
6284
			#回傳結果
6285
			return $result;
6286
 
6287
			}#if end
6288
 
6289
		#取得參數
6290
		$result["argu"]=$conf;
6291
 
6292
		#檢查參數
6293
		#函式說明:
6294
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6295
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6296
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6297
		#$result["function"],當前執行的函式名稱.
6298
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6299
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6300
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6301
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6302
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6303
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6304
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6305
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6306
		#必填寫的參數:
6307
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6308
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6309
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6310
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6311
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6312
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6313
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6314
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6315
		#可以省略的參數:
6316
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6317
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6318
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6319
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6320
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6321
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
6322
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6323
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
6324
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6325
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
6326
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6327
		#$conf["arrayCountEqualCheck"][]=array();
6328
		#參考資料來源:
6329
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6330
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6331
		unset($conf["variableCheck::checkArguments"]);
6332
 
6333
		#如果檢查失敗
6334
		if($checkArguments["status"]==="false"){
6335
 
6336
			#設置錯誤識別
6337
			$result["status"]="false";
6338
 
6339
			#設置錯誤訊息
6340
			$result["error"]=$checkArguments;
6341
 
6342
			#回傳結果
6343
			return $result;
6344
 
6345
			}#if end
6346
 
6347
		#如果檢查不通過
6348
		if($checkArguments["passed"]==="false"){
6349
 
6350
			#設置錯誤識別
6351
			$result["status"]="false";
6352
 
6353
			#設置錯誤訊息
6354
			$result["error"]=$checkArguments;
6355
 
6356
			#回傳結果
6357
			return $result;
6358
 
6359
			}#if end
6360
 
6361
		#如果有設置 id
6362
		if(isset($conf["id"])){
6363
 
6364
			#設置 id
6365
			$id=$conf["id"];
6366
 
6367
			}#if end
6368
 
6369
		#反之如果有設置 cname
6370
		else if(isset($conf["cname"])){
6371
 
6372
			#函式說明:
6373
			#取得在zerossl上的CSR清單
6374
			#回傳結果:
6375
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6376
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
6377
			#$result["function"],當前執行的函式名稱.
6378
			#$result["argu"],所使用的參數.
6379
			#$result["curl_verbose_info"],curl執行的詳細資訊.
6380
			#$result["content"],結果json字串.
6381
			#$result["tCound"],總共的資料筆數.
6382
			#$result["count"],該頁的筆數.
6383
			#$result["page"],當前的頁碼.
6384
			#$result["certs"],陣列,certificates清單,key為certificate的id.
6385
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
6386
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
6387
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
6388
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6389
			#必填參數:
6390
			#無
6391
			#可省略參數:
6392
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6393
			#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6394
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6395
			#$conf["key"]=self::getApiInfo()["apiKey"];
6396
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6397
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
6398
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
6399
			#$conf["cerType"]="";
6400
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
6401
			$conf["zerossl::getCertList"]["search"]=$conf["cname"];
6402
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
6403
			#$conf["limit"]="";
6404
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
6405
			#$conf["page"]="";
6406
			#參考資料:
6407
			#https://zerossl.com/documentation/api/get-certificate/
6408
			#備註:
6409
			#無.
6410
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
6411
			unset($conf["zerossl::getCertList"]);
6412
 
6413
			#如果檢查失敗
6414
			if($getCertList["status"]==="false"){
6415
 
6416
				#設置錯誤識別
6417
				$result["status"]="false";
6418
 
6419
				#設置錯誤訊息
6420
				$result["error"]=$getCertList;
6421
 
6422
				#回傳結果
6423
				return $result;
6424
 
6425
				}#if end
6426
 
6427
			#如果資料筆數大於0
6428
			if($getCertList["count"]>0){
6429
 
6430
				#取得第一筆
6431
				foreach($getCertList["certs"] as $cerId => $detail){
6432
 
6433
					#取得cettificate id
6434
					$id=$cerId;
6435
 
6436
					}#foreach end
6437
 
6438
				}#if end
6439
 
6440
			}#if end
6441
 
6442
		#預設網址
6443
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
6444
 
6445
		#函式說明:
6446
		#運行curl cmd
6447
		#回傳結果:
6448
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6449
		#$result["error"],錯誤訊息陣列.
6450
		#$result["function"],當前執行的函式名稱.
6451
		#$result["founded"],識別網址找不找得到.
6452
		#$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"代表程序的資訊.
6453
		#$result["fullContent"],取得回應的完整字串內容.
6454
		#$result["cookie"],cookie檔案的位置與名稱.
6455
		#$result["cmd"],執行的command.
6456
		#$result["argu],使用的參數.
6457
		#必填參數:
6458
		#$conf["url"],字串,目標url.
6459
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6460
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6461
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6462
		#可省略參數:
6463
		#$conf["header"],字串陣列,要傳送的header.
6464
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
6465
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6466
		#$conf["allowAnySSLcertificate"]="";
6467
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6468
		#$conf["postVar"]=array();
6469
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6470
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6471
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
6472
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
6473
		#$conf["agent"],字串,user agent的名稱.
6474
		#$conf["agent"]="";
6475
		#$conf["cookie"],字串,cookie位置與檔案位置.
6476
		#$conf["cookie"]="";
6477
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6478
		#$conf["forceNewCookie"]="";
6479
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6480
		#$conf["inBg"]="true";
6481
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6482
		#$conf["bgInProc"]="false";
6483
		#參考資料:
6484
		#無.
6485
		#備註:
6486
		#無.
6487
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6488
		unset($conf["catchWebContent::curlCmd"]);
6489
 
6490
		#如果異常
6491
		if($curlCmd["status"]==="false"){
6492
 
6493
			#設置錯誤識別
6494
			$result["status"]="false";
6495
 
6496
			#設置錯誤訊息
6497
			$result["error"]=$curlCmd;
6498
 
6499
			#回傳結果
6500
			return $result;
6501
 
6502
			}#if end
6503
 
6504
		#設置curl的詳細資訊
6505
		$result["curl_verbose_info"]=$curlCmd;
6506
 
249 liveuser 6507
		#驗證結果是否為 json
6508
		$json_validate=json_validate($curlCmd["fullContent"]);
6509
 
6510
		#如果回應不是 json
6511
		if(!$json_validate){
6512
 
6513
			#設置錯誤識別
6514
			$result["status"]="false";
6515
 
6516
			#設置錯誤訊息
6517
			$result["error"]=$curlCmd;
6518
 
6519
			#回傳結果
6520
			return $result;
6521
 
6522
			}#if end
6523
 
6524
		#設置json string結果
6525
		$result["content"]=$curlCmd["fullContent"];
255 liveuser 6526
 
6527
		#取得 json
6528
		$json=json_decode($curlCmd["fullContent"]);
6529
 
291 liveuser 6530
		#儲存成變數以便透過object呼叫
6531
		$c_crt="certificate.crt";
6532
 
6533
		#儲存成變數以便透過object呼叫
6534
		$ca_crt="ca_bundle.crt";
6535
 
294 liveuser 6536
		#如果沒有該有的 certificate.crt 跟 ca_bundle.crt 物件
6537
		if(!isset($json->$c_crt) || !isset($json->$ca_crt)){
6538
 
6539
			#設置錯誤識別
6540
			$result["status"]="false";
6541
 
6542
			#設置錯誤訊息
6543
			$result["error"]=$json;
6544
 
6545
			#回傳結果
6546
			return $result;
6547
 
6548
			}#if end
6549
 
255 liveuser 6550
		#取得certificate.crt的內容
291 liveuser 6551
		$result["certificate.crt"]=$json->$c_crt;
255 liveuser 6552
 
6553
		#取得ca_bundle.crt的內容
291 liveuser 6554
		$result["ca_bundle.crt"]=$json->$ca_crt;
255 liveuser 6555
 
6556
		#設置執行正常
6557
		$result["status"]="true";
6558
 
6559
		#回傳結果
6560
		return $result;
6561
 
6562
		}#function getCert end
6563
 
6564
	/*
6565
	#函式說明:
6566
	#請求廢除 issued zerossl certificate.
6567
	#回傳結果:
6568
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6569
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6570
	#$result["function"],當前執行的函式名稱.
6571
	#$result["argu"],所使用的參數.
6572
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6573
	#$result["content"],結果json字串.
341 liveuser 6574
	#$result["busy"],若content結果含有busy屬性,且為1,則為"true";反之為"false".
255 liveuser 6575
	#必填參數:
6576
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
6577
	$conf["id"]="";
6578
	#可省略參數:
6579
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6580
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6581
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6582
	#$conf["key"]=self::getApiInfo()["apiKey"];
6583
	#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
6584
	#$conf["reason"]="";
6585
	#參考資料:
6586
	#https://zerossl.com/documentation/api/revoke-certificate/
6587
	#備註:
338 liveuser 6588
	#跟api頁面的描述不同,access_key參數實際上要用get方式傳遞.
341 liveuser 6589
	#跟api頁面的描述不同,api point忙碌中,無法回應時,回應會為空.
255 liveuser 6590
	*/
6591
	public static function revokeCert(&$conf){
6592
 
6593
		#初始化要回傳的結果
6594
		$result=array();
249 liveuser 6595
 
255 liveuser 6596
		#設置當其函數名稱
6597
		$result["function"]=__FUNCTION__;
6598
 
6599
		#如果 $conf 不為陣列
6600
		if(gettype($conf)!="array"){
6601
 
6602
			#設置執行失敗
6603
			$result["status"]="false";
6604
 
6605
			#設置執行錯誤訊息
6606
			$result["error"][]="\$conf變數須為陣列形態";
6607
 
6608
			#如果傳入的參數為 null
6609
			if($conf==null){
6610
 
6611
				#設置執行錯誤訊息
6612
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6613
 
6614
				}#if end
6615
 
6616
			#回傳結果
6617
			return $result;
6618
 
6619
			}#if end
6620
 
6621
		#取得參數
6622
		$result["argu"]=$conf;
6623
 
6624
		#檢查參數
6625
		#函式說明:
6626
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6627
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6628
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6629
		#$result["function"],當前執行的函式名稱.
6630
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6631
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6632
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6633
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6634
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6635
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6636
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6637
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6638
		#必填寫的參數:
6639
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6640
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6641
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6642
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6643
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6644
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6645
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6646
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6647
		#可以省略的參數:
6648
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6649
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6650
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6651
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6652
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6653
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
6654
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
334 liveuser 6655
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
255 liveuser 6656
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6657
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
6658
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6659
		#$conf["arrayCountEqualCheck"][]=array();
6660
		#參考資料來源:
6661
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6662
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6663
		unset($conf["variableCheck::checkArguments"]);
6664
 
6665
		#如果檢查失敗
6666
		if($checkArguments["status"]==="false"){
6667
 
6668
			#設置錯誤識別
6669
			$result["status"]="false";
6670
 
6671
			#設置錯誤訊息
6672
			$result["error"]=$checkArguments;
6673
 
6674
			#回傳結果
6675
			return $result;
6676
 
6677
			}#if end
6678
 
6679
		#如果檢查不通過
6680
		if($checkArguments["passed"]==="false"){
6681
 
6682
			#設置錯誤識別
6683
			$result["status"]="false";
6684
 
6685
			#設置錯誤訊息
6686
			$result["error"]=$checkArguments;
6687
 
6688
			#回傳結果
6689
			return $result;
6690
 
6691
			}#if end
6692
 
338 liveuser 6693
		#url to call,含api key,跟 api 頁面不一致.
6694
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
255 liveuser 6695
 
337 liveuser 6696
		#初始化要post的變數陣列
6697
		$postVar=array();
6698
 
338 liveuser 6699
		#設置  api key,跟 api 頁面不一致.
6700
		#$postVar["access_key"]=$conf["key"];
337 liveuser 6701
 
255 liveuser 6702
		#如果有設置 reason
6703
		if(isset($conf["reason"])){
6704
 
6705
			#設置reason
337 liveuser 6706
			$postVar["reason"]=$conf["reason"];
255 liveuser 6707
 
6708
			}#if end
337 liveuser 6709
 
255 liveuser 6710
		#函式說明:
6711
		#運行curl cmd
6712
		#回傳結果:
6713
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6714
		#$result["error"],錯誤訊息陣列.
6715
		#$result["function"],當前執行的函式名稱.
6716
		#$result["founded"],識別網址找不找得到.
6717
		#$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"代表程序的資訊.
6718
		#$result["fullContent"],取得回應的完整字串內容.
6719
		#$result["cookie"],cookie檔案的位置與名稱.
6720
		#$result["cmd"],執行的command.
6721
		#$result["argu],使用的參數.
6722
		#必填參數:
6723
		#$conf["url"],字串,目標url.
6724
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6725
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6726
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6727
		#可省略參數:
6728
		#$conf["header"],字串陣列,要傳送的header.
338 liveuser 6729
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
255 liveuser 6730
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6731
		#$conf["allowAnySSLcertificate"]="";
338 liveuser 6732
 
6733
		#如果有資料
6734
		if(!empty($postVar)){
6735
 
6736
			#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6737
			$conf["catchWebContent::curlCmd"]["postVar"]=$postVar;
6738
 
6739
			}#if end
6740
 
255 liveuser 6741
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6742
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6743
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
338 liveuser 6744
		$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
255 liveuser 6745
		#$conf["agent"],字串,user agent的名稱.
6746
		#$conf["agent"]="";
6747
		#$conf["cookie"],字串,cookie位置與檔案位置.
6748
		#$conf["cookie"]="";
6749
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6750
		#$conf["forceNewCookie"]="";
6751
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6752
		#$conf["inBg"]="true";
6753
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6754
		#$conf["bgInProc"]="false";
6755
		#參考資料:
6756
		#無.
6757
		#備註:
6758
		#無.
6759
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6760
		unset($conf["catchWebContent::curlCmd"]);
6761
 
6762
		#如果異常
6763
		if($curlCmd["status"]==="false"){
6764
 
6765
			#設置錯誤識別
6766
			$result["status"]="false";
6767
 
6768
			#設置錯誤訊息
6769
			$result["error"]=$curlCmd;
6770
 
6771
			#回傳結果
6772
			return $result;
6773
 
6774
			}#if end
6775
 
6776
		#設置curl的詳細資訊
6777
		$result["curl_verbose_info"]=$curlCmd;
6778
 
341 liveuser 6779
		#如果 server 的回應為空
6780
		if(empty($curlCmd["fullContent"])){
6781
 
6782
			#初始化json回應
6783
			$jsonRes=array();
6784
 
6785
			#設置不成功
6786
			$jsonRes["success"]=0;
6787
 
6788
			#設置server忙碌中,贊述無法處理要求.
6789
			$jsonRes["busy"]=1;
6790
 
6791
			#設置json結果
6792
			$curlCmd["fullContent"]=json_encode($jsonRes);
6793
 
6794
			}#if end
6795
 
255 liveuser 6796
		#驗證結果是否為 json
6797
		$json_validate=json_validate($curlCmd["fullContent"]);
6798
 
6799
		#如果回應不是 json
6800
		if(!$json_validate){
6801
 
6802
			#設置錯誤識別
6803
			$result["status"]="false";
6804
 
6805
			#設置錯誤訊息
6806
			$result["error"]=$curlCmd;
6807
 
6808
			#回傳結果
6809
			return $result;
6810
 
6811
			}#if end
341 liveuser 6812
 
255 liveuser 6813
		#設置json string結果
6814
		$result["content"]=$curlCmd["fullContent"];
6815
 
249 liveuser 6816
		#解析json
6817
		$jsonRes=json_decode($result["content"]);
6818
 
255 liveuser 6819
		#如果沒有要有的attr
6820
		if(!isset($jsonRes->success)){
6821
 
6822
			#設置錯誤識別
6823
			$result["status"]="false";
6824
 
6825
			#設置錯誤訊息
6826
			$result["error"]=$curlCmd;
6827
 
6828
			#回傳結果
6829
			return $result;
6830
 
6831
			}#if end
341 liveuser 6832
 
255 liveuser 6833
		#如果 success 不等於 1
6834
		if($jsonRes->success!==1){
6835
 
341 liveuser 6836
			#如果有 busy 屬性
6837
			if(isset($jsonRes->busy)){
6838
 
6839
				#如果busy為1
6840
				if($jsonRes->busy===1){
6841
 
6842
					#設置sever忙碌中,無法回應.
6843
					$result["busy"]="true";
6844
 
6845
					}#if end
6846
 
6847
				}#if end
6848
 
255 liveuser 6849
			#設置錯誤識別
6850
			$result["status"]="false";
6851
 
6852
			#設置錯誤訊息
6853
			$result["error"]=$curlCmd;
6854
 
6855
			#回傳結果
6856
			return $result;
6857
 
6858
			}#if end
6859
 
341 liveuser 6860
		#如果回應結果不含busy元素
6861
		if(!isset($result["busy"])){
6862
 
6863
			#設置其為"false",代表server沒有忙碌中,無法回應.
6864
			$result["busy"]="false";
6865
 
6866
			}#else end
6867
 
249 liveuser 6868
		#設置執行正常
6869
		$result["status"]="true";
6870
 
6871
		#回傳結果
6872
		return $result;
6873
 
255 liveuser 6874
		}#function revokeCert end
6875
 
6876
	/*
6877
	#函式說明:
6878
	#請求取消 draft or unvalidated zerossl certificate.
6879
	#回傳結果:
6880
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6881
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6882
	#$result["function"],當前執行的函式名稱.
6883
	#$result["argu"],所使用的參數.
6884
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6885
	#$result["content"],結果json字串.
6886
	#必填參數:
6887
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
6888
	$conf["id"]="";
6889
	#可省略參數:
6890
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6891
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6892
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6893
	#$conf["key"]=self::getApiInfo()["apiKey"];
6894
	#參考資料:
6895
	#https://zerossl.com/documentation/api/revoke-certificate/
6896
	#備註:
6897
	#無.
6898
	*/
6899
	public static function cancelCert(&$conf){
6900
 
6901
		#初始化要回傳的結果
6902
		$result=array();
249 liveuser 6903
 
255 liveuser 6904
		#設置當其函數名稱
6905
		$result["function"]=__FUNCTION__;
6906
 
6907
		#如果 $conf 不為陣列
6908
		if(gettype($conf)!="array"){
6909
 
6910
			#設置執行失敗
6911
			$result["status"]="false";
6912
 
6913
			#設置執行錯誤訊息
6914
			$result["error"][]="\$conf變數須為陣列形態";
6915
 
6916
			#如果傳入的參數為 null
6917
			if($conf==null){
6918
 
6919
				#設置執行錯誤訊息
6920
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6921
 
6922
				}#if end
6923
 
6924
			#回傳結果
6925
			return $result;
6926
 
6927
			}#if end
6928
 
6929
		#取得參數
6930
		$result["argu"]=$conf;
6931
 
6932
		#檢查參數
6933
		#函式說明:
6934
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6935
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6936
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6937
		#$result["function"],當前執行的函式名稱.
6938
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6939
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6940
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6941
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6942
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6943
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6944
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6945
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6946
		#必填寫的參數:
6947
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6948
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6949
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6950
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6951
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6952
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6953
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6954
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6955
		#可以省略的參數:
6956
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6957
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6958
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6959
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6960
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6961
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
6962
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6963
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
6964
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6965
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
6966
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6967
		#$conf["arrayCountEqualCheck"][]=array();
6968
		#參考資料來源:
6969
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6970
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6971
		unset($conf["variableCheck::checkArguments"]);
6972
 
6973
		#如果檢查失敗
6974
		if($checkArguments["status"]==="false"){
6975
 
6976
			#設置錯誤識別
6977
			$result["status"]="false";
6978
 
6979
			#設置錯誤訊息
6980
			$result["error"]=$checkArguments;
6981
 
6982
			#回傳結果
6983
			return $result;
6984
 
6985
			}#if end
6986
 
6987
		#如果檢查不通過
6988
		if($checkArguments["passed"]==="false"){
6989
 
6990
			#設置錯誤識別
6991
			$result["status"]="false";
6992
 
6993
			#設置錯誤訊息
6994
			$result["error"]=$checkArguments;
6995
 
6996
			#回傳結果
6997
			return $result;
6998
 
6999
			}#if end
7000
 
7001
		#url to call
7002
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
7003
 
7004
		#函式說明:
7005
		#運行curl cmd
7006
		#回傳結果:
7007
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7008
		#$result["error"],錯誤訊息陣列.
7009
		#$result["function"],當前執行的函式名稱.
7010
		#$result["founded"],識別網址找不找得到.
7011
		#$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"代表程序的資訊.
7012
		#$result["fullContent"],取得回應的完整字串內容.
7013
		#$result["cookie"],cookie檔案的位置與名稱.
7014
		#$result["cmd"],執行的command.
7015
		#$result["argu],使用的參數.
7016
		#必填參數:
7017
		#$conf["url"],字串,目標url.
7018
		$conf["catchWebContent::curlCmd"]["url"]=$url;
7019
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7020
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7021
		#可省略參數:
7022
		#$conf["header"],字串陣列,要傳送的header.
7023
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7024
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7025
		#$conf["allowAnySSLcertificate"]="";
7026
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7027
		#$conf["postVar"]=array();
7028
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7029
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7030
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7031
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7032
		#$conf["agent"],字串,user agent的名稱.
7033
		#$conf["agent"]="";
7034
		#$conf["cookie"],字串,cookie位置與檔案位置.
7035
		#$conf["cookie"]="";
7036
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7037
		#$conf["forceNewCookie"]="";
7038
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7039
		#$conf["inBg"]="true";
7040
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7041
		#$conf["bgInProc"]="false";
7042
		#參考資料:
7043
		#無.
7044
		#備註:
7045
		#無.
7046
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7047
		unset($conf["catchWebContent::curlCmd"]);
7048
 
7049
		#如果異常
7050
		if($curlCmd["status"]==="false"){
7051
 
7052
			#設置錯誤識別
7053
			$result["status"]="false";
7054
 
7055
			#設置錯誤訊息
7056
			$result["error"]=$curlCmd;
7057
 
7058
			#回傳結果
7059
			return $result;
7060
 
7061
			}#if end
7062
 
7063
		#設置curl的詳細資訊
7064
		$result["curl_verbose_info"]=$curlCmd;
7065
 
7066
		#驗證結果是否為 json
7067
		$json_validate=json_validate($curlCmd["fullContent"]);
7068
 
7069
		#如果回應不是 json
7070
		if(!$json_validate){
7071
 
7072
			#設置錯誤識別
7073
			$result["status"]="false";
7074
 
7075
			#設置錯誤訊息
7076
			$result["error"]=$curlCmd;
7077
 
7078
			#回傳結果
7079
			return $result;
7080
 
7081
			}#if end
7082
 
7083
		#設置json string結果
7084
		$result["content"]=$curlCmd["fullContent"];
7085
 
7086
		#解析json
7087
		$jsonRes=json_decode($result["content"]);
7088
 
7089
		#如果沒有要有的attr
7090
		if(!isset($jsonRes->success)){
7091
 
7092
			#設置錯誤識別
7093
			$result["status"]="false";
7094
 
7095
			#設置錯誤訊息
7096
			$result["error"]=$curlCmd;
7097
 
7098
			#回傳結果
7099
			return $result;
7100
 
7101
			}#if end
7102
 
7103
		#如果 success 不等於 1
7104
		if($jsonRes->success!==1){
7105
 
7106
			#設置錯誤識別
7107
			$result["status"]="false";
7108
 
7109
			#設置錯誤訊息
7110
			$result["error"]=$curlCmd;
7111
 
7112
			#回傳結果
7113
			return $result;
7114
 
7115
			}#if end
7116
 
7117
		#設置執行正常
7118
		$result["status"]="true";
7119
 
7120
		#回傳結果
7121
		return $result;
7122
 
7123
		}#function cancelCert end
7124
 
7125
	/*
7126
	#函式說明:
7127
	#透過zerossl api確保ssl沒有過期.
7128
	#回傳結果:
7129
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7130
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7131
	#$result["function"],當前執行的函式名稱.
7132
	#$result["argu"],所使用的參數.
7133
	#必填參數:
7134
	#$conf["cName"],陣列,每個ssl的common domain name.
7135
	$conf["cName"]=array();
7136
	#$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內容合併後的檔案位置與名稱.
7137
	$conf["certInfo"]=array();
7138
	#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
7139
	$conf["rrFile"]=array();
7140
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
7141
	$conf["dnsSerAddr"]=array();
7142
	#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
7143
	$conf["actionAfterUpdateCert"]=array();
7144
	#可省略參數:
288 liveuser 7145
	#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/sslUpdater.sock
7146
	#$conf["sock"]="";
281 liveuser 7147
	#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
7148
	#$conf["debug"]="";
255 liveuser 7149
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7150
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7151
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7152
	#$conf["key"]=self::getApiInfo()["apiKey"];
293 liveuser 7153
	#$conf["multiThreads"],字串,預設為"false"代表不使用多執行序;"true"代表要用多執行序.
7154
	#$conf["multiThreads"]=""
255 liveuser 7155
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
7156
	#$conf["debug"]="";
7157
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
7158
	#$conf["addOnProcessFunc"]=array();
7159
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
7160
	#$conf["funcToRunWhenIdle"]=array();
7161
	#參考資料:
7162
	#無.
7163
	#備註:
7164
	#無.
7165
	*/
7166
	public static function sslUpdater(&$conf){
7167
 
7168
		#初始化要回傳的結果
7169
		$result=array();
7170
 
7171
		#設置當其函數名稱
7172
		$result["function"]=__FUNCTION__;
7173
 
7174
		#如果 $conf 不為陣列
7175
		if(gettype($conf)!="array"){
7176
 
7177
			#設置執行失敗
7178
			$result["status"]="false";
7179
 
7180
			#設置執行錯誤訊息
7181
			$result["error"][]="\$conf變數須為陣列形態";
7182
 
7183
			#如果傳入的參數為 null
7184
			if($conf==null){
7185
 
7186
				#設置執行錯誤訊息
7187
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7188
 
7189
				}#if end
7190
 
7191
			#回傳結果
7192
			return $result;
7193
 
7194
			}#if end
7195
 
7196
		#取得參數
7197
		$result["argu"]=$conf;
288 liveuser 7198
 
7199
		#初始化預設的 unix domain socket 路徑
7200
		$defaultSocket=pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/sslUpdater.sock";
255 liveuser 7201
 
7202
		#檢查參數
7203
		#函式說明:
7204
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7205
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7206
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7207
		#$result["function"],當前執行的函式名稱.
7208
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7209
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7210
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7211
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7212
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7213
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7214
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7215
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7216
		#必填寫的參數:
7217
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7218
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7219
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7220
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
7221
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7222
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
7223
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7224
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7225
		#可以省略的參數:
7226
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7227
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7228
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
293 liveuser 7229
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("multiThreads","sock","debug","apiDomain","key");
255 liveuser 7230
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 7231
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("multiThreads","sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
255 liveuser 7232
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
293 liveuser 7233
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array","array");
255 liveuser 7234
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
293 liveuser 7235
		$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 7236
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7237
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
7238
		#參考資料來源:
7239
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7240
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7241
		unset($conf["variableCheck::checkArguments"]);
7242
 
7243
		#如果檢查失敗
7244
		if($checkArguments["status"]==="false"){
7245
 
7246
			#設置錯誤識別
7247
			$result["status"]="false";
7248
 
7249
			#設置錯誤訊息
7250
			$result["error"]=$checkArguments;
7251
 
7252
			#回傳結果
7253
			return $result;
7254
 
7255
			}#if end
7256
 
7257
		#如果檢查不通過
7258
		if($checkArguments["passed"]==="false"){
7259
 
7260
			#設置錯誤識別
7261
			$result["status"]="false";
7262
 
7263
			#設置錯誤訊息
7264
			$result["error"]=$checkArguments;
7265
 
7266
			#回傳結果
7267
			return $result;
7268
 
7269
			}#if end
7270
 
7271
		#取得key
7272
		$share["key"]=$conf["key"];
7273
 
7274
		#取得apiDomain
7275
		$share["apiDomain"]=$conf["apiDomain"];
7276
 
281 liveuser 7277
		#設置debug flag
7278
		$share["debug"]=$conf["debug"];
7279
 
293 liveuser 7280
		#設置 multiThreads 
7281
		$share["multiThreads"]=$conf["multiThreads"];
7282
 
255 liveuser 7283
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
7284
		$share["certInfo"]=array();
7285
 
7286
		#針對每個 domain
7287
		foreach($conf["cName"] as $index=>$cName ){
7288
 
7289
			#如果沒有對應的certInfo
7290
			if(!isset($conf["certInfo"][$index])){
7291
 
7292
				#設置錯誤識別
7293
				$result["status"]="false";
7294
 
7295
				#設置錯誤訊息
7296
				$result["error"][]="missing certInfo";
7297
 
7298
				#設置錯誤訊息
7299
				$result["error"][]=$checkArguments;
7300
 
7301
				#回傳結果
7302
				return $result;
7303
 
7304
				}#if end
7305
 
291 liveuser 7306
			#檢查 $conf["certInfo"][$index] 是否資訊都有存在
7307
			#函式說明:
7308
			#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
7309
			#回傳結果:
7310
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7311
			#$result["error"],執行不正常結束的錯訊息陣列.
7312
			#$result["simpleError"],簡單表示的錯誤訊息.
7313
			#$result["function"],當前執行的函式名稱.
7314
			#$result["argu"],設置給予的參數.
7315
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7316
			#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7317
			#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7318
			#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7319
			#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7320
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7321
			#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7322
			#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7323
			#必填參數:
7324
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7325
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["certInfo"][$index];
7326
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7327
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7328
			#可省略參數:
7329
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7330
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
7331
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
7332
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
7333
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7334
			#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7335
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
7336
			#$conf["canNotBeEmpty"]=array();
7337
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
7338
			#$conf["canBeEmpty"]=array();
7339
			#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
7340
			$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("true","true","true","true");
7341
			#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7342
			$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
7343
			#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7344
			$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
7345
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7346
			$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");
7347
			#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
7348
			#$conf["disallowAllSkipableVarIsEmpty"]="";
7349
			#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
7350
			#$conf["disallowAllSkipableVarIsEmptyArray"]="";
7351
			#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
7352
			#$conf["disallowAllSkipableVarNotExist"]="";
7353
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7354
			#$conf["arrayCountEqualCheck"][]=array();
7355
			#參考資料:
7356
			#array_keys=>http://php.net/manual/en/function.array-keys.php
7357
			#備註:
7358
			#無.
7359
			$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7360
			unset($conf["variableCheck::checkArguments"]);
7361
 
7362
			#如果檢查失敗
7363
			if($checkArguments["status"]==="false"){
7364
 
7365
				#設置錯誤識別
7366
				$result["status"]="false";
7367
 
7368
				#設置錯誤訊息
7369
				$result["error"]=$checkArguments;
7370
 
7371
				#回傳結果
7372
				return $result;
7373
 
7374
				}#if end
7375
 
7376
			#如果檢查不通過
7377
			if($checkArguments["passed"]==="false"){
7378
 
7379
				#設置錯誤識別
7380
				$result["status"]="false";
7381
 
7382
				#設置錯誤訊息
7383
				$result["error"]=$checkArguments;
7384
 
7385
				#回傳結果
7386
				return $result;
7387
 
7388
				}#if end
7389
 
7390
			#儲存 cName
7391
			$cInfo["cName"]=$cName;
255 liveuser 7392
 
291 liveuser 7393
			#儲存 RR 檔案的路徑與名稱
7394
			$cInfo["rrFile"]=$conf["rrFile"][$index];
255 liveuser 7395
 
291 liveuser 7396
			#儲存 cName 對應的 dns server addr
7397
			$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
255 liveuser 7398
 
291 liveuser 7399
			#儲存 cName 的憑證更新後要做的事情.
7400
			$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
255 liveuser 7401
 
294 liveuser 7402
			#用 ";" 分割來取得有多少個動作要依序執行
7403
			#函式說明:
7404
			#將固定格式的字串分開,並回傳分開的結果.
7405
			#回傳結果:
7406
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7407
			#$result["error"],錯誤訊息陣列
7408
			#$result["function"],當前執行的函數名稱.
7409
			#$result["argu"],使用的參數.
7410
			#$result["oriStr"],要分割的原始字串內容
7411
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7412
			#$result["dataCounts"],爲總共分成幾段
7413
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
7414
			#必填參數:
7415
			#$conf["stringIn"],字串,要處理的字串.
7416
			$conf["stringProcess::spiltString"]["stringIn"]=$cInfo["actionAfterUpdateCert"];
7417
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
7418
			$conf["stringProcess::spiltString"]["spiltSymbol"]=";";
7419
			#可省略參數:
7420
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
7421
			#$conf["allowEmptyStr"]="false";
7422
			#參考資料:
7423
			#無.
7424
			#備註:
7425
			#無.
7426
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
7427
			unset($conf["stringProcess::spiltString"]);
7428
 
7429
			#如果執行異常
7430
			if($spiltString["status"]==="false"){
7431
 
7432
				#設置錯誤識別
7433
				$result["status"]="false";
7434
 
7435
				#設置錯誤訊息
7436
				$result["error"]=$spiltString;
7437
 
7438
				#回傳結果
7439
				return $result;
7440
 
7441
				}#if end
7442
 
7443
			#如果沒有";"存在,代表格式不對
7444
			if($spiltString["found"]==="false"){
7445
 
7446
				#設置錯誤識別
7447
				$result["status"]="false";
7448
 
7449
				#設置錯誤訊息
7450
				$result["error"]=$spiltString;
7451
 
7452
				#回傳結果
7453
				return $result;
7454
 
7455
				}#if end
7456
 
7457
			#取得每個動作
7458
			$cInfo["actionAfterUpdateCert"]=$spiltString["dataArray"];
7459
 
291 liveuser 7460
			#設置 certPath
7461
			$cInfo["ssl"]["certPath"]=$conf["certInfo"][$index]["certPath"];
255 liveuser 7462
 
291 liveuser 7463
			#設置 pKey
7464
			$cInfo["ssl"]["pKey"]=$conf["certInfo"][$index]["pKey"];
7465
 
7466
			#設置 caPath
7467
			$cInfo["ssl"]["caPath"]=$conf["certInfo"][$index]["caPath"];
7468
 
7469
			#設置 certWithCaPath
7470
			$cInfo["ssl"]["certWithCaPath"]=$conf["certInfo"][$index]["certWithCaPath"];
7471
 
7472
			#儲存 certInfo
7473
			$share["certInfo"][]=$cInfo;
7474
 
255 liveuser 7475
			}#foreach end
7476
 
7477
		#如果為空
7478
		if(empty($share["certInfo"])){
7479
 
7480
			#設置錯誤識別
7481
			$result["status"]="false";
7482
 
7483
			#設置錯誤訊息
7484
			$result["error"][]="certInfo 參數有缺";
7485
 
7486
			#設置錯誤訊息
7487
			$result["error"][]=$checkArguments;
7488
 
7489
			#回傳結果
7490
			return $result;
7491
 
7492
			}#if end
7493
 
7494
		#函式說明:
7495
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
7496
		#回傳結果:
7497
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
7498
		#$result["error"],錯誤訊息陣列.
7499
		#$result["function"],當前執行的函式名稱.
7500
		#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
7501
		#$result["serverCache"]["serverSide"],server side 的 cache.
7502
		#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
7503
		#$result["serverCache"]["clientSide"],client site 的 cache.
7504
		#必填參數:
7505
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
291 liveuser 7506
		$conf["sock::unixDomainSockServer"]["sock"]=$conf["sock"];
255 liveuser 7507
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7508
		$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
7509
		#可省略參數:
7510
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
7511
		$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
7512
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
7513
		$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
7514
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
7515
		#$conf["sessionTimeout"]="300";
7516
		#$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 7517
		$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("\qbpwcf\zerossl::sslUpdater_cmd");
255 liveuser 7518
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
291 liveuser 7519
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\qbpwcf\zerossl::sslUpdater_idle");
255 liveuser 7520
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
7521
		#$conf["paramsForFuncToRunWhenIdle"]=array();
7522
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7523
		$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
7524
		#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
7525
		#$conf["shutdownStrAddr"]="";
7526
		#參考資料:
7527
		#http://php.net/manual/en/function.stream-socket-server.php
7528
		#備註:
7529
		#無.
7530
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
7531
		unset($conf["sock::unixDomainSockServer"]);
7532
 
7533
		#執行異常
7534
		if($unixDomainSockServer["status"]==="false"){
7535
 
7536
			#設置錯誤識別
7537
			$result["status"]="false";
7538
 
7539
			#設置錯誤訊息
7540
			$result["error"]=$unixDomainSockServer;
7541
 
7542
			#回傳結果
7543
			return $result;
7544
 
7545
			}#if end
7546
 
7547
		#設置執行正常
7548
		$result["status"]="true";
7549
 
7550
		#回傳結果
7551
		return $result;
7552
 
7553
		}#function sslUpdater end
7554
 
7555
	/*
7556
	#函式說明:
7557
	#funcion sslUpdater 於收到訊息時要做的事情.
7558
	#回傳結果:
7559
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7560
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7561
	#$result["function"],當前執行的函式名稱.
7562
	#$result["argu"],所使用的參數.
7563
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
7564
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
7565
	#必填參數:
7566
	#$conf["request"],字串,收到的json訊息.
7567
	$conf["request"]="";
7568
	#$conf["sock"],resource,用戶的socket.
7569
	$conf["sock"]="";
7570
	#$conf["clientCache"],陣列,給予所有用戶的cache.
7571
	$conf["clientCache"]=array();
7572
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7573
	$conf["info"]=array();
7574
	#可省略參數:
7575
	#無.
7576
	#參考資料:
7577
	#無.
7578
	#備註:
7579
	#建構中...
7580
	*/
7581
	public static function sslUpdater_cmd(&$conf){
7582
 
7583
		#debug
7584
		var_dump($conf);
7585
 
7586
		}#function sslUpdater_cmd end
7587
 
7588
	/*
7589
	#函式說明:
7590
	#funcion sslUpdater 於閒置時要做的事情
7591
	#回傳結果:
7592
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7593
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7594
	#$result["function"],當前執行的函式名稱.
7595
	#$result["argu"],所使用的參數.
7596
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
7597
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
7598
	#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
7599
	#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
7600
	#必填參數:
7601
	#$conf["client"],陣列,所有用戶的資訊.
7602
	$conf["client"]=array();
7603
	#$conf["clientCache"],陣列,給予所有用戶的cache.
7604
	$conf["clientCache"]=array();
7605
	#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
7606
	$conf["serverCache"]=array();
7607
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7608
	$conf["info"]=array();
7609
	#可省略參數:
7610
	#無.
7611
	#參考資料:
7612
	#無.
7613
	#備註:
291 liveuser 7614
	#無.
255 liveuser 7615
	*/
7616
	public static function sslUpdater_idle(&$conf){
7617
 
7618
		#初始化要回傳的結果
7619
		$result=array();
7620
 
7621
		#設置當其函數名稱
7622
		$result["function"]=__FUNCTION__;
7623
 
7624
		#如果 $conf 不為陣列
7625
		if(gettype($conf)!="array"){
7626
 
7627
			#設置執行失敗
7628
			$result["status"]="false";
7629
 
7630
			#設置執行錯誤訊息
7631
			$result["error"][]="\$conf變數須為陣列形態";
7632
 
7633
			#如果傳入的參數為 null
7634
			if($conf==null){
7635
 
7636
				#設置執行錯誤訊息
7637
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7638
 
7639
				}#if end
7640
 
7641
			#回傳結果
7642
			return $result;
7643
 
7644
			}#if end
7645
 
7646
		#取得參數
7647
		$result["argu"]=$conf;
7648
 
7649
		#檢查參數
7650
		#函式說明:
7651
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7652
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7653
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7654
		#$result["function"],當前執行的函式名稱.
7655
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7656
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7657
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7658
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7659
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7660
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7661
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7662
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7663
		#必填寫的參數:
7664
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7665
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7666
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
291 liveuser 7667
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","serverCache","info");
255 liveuser 7668
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
291 liveuser 7669
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
255 liveuser 7670
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7671
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7672
		#可以省略的參數:
7673
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7674
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7675
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7676
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7677
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7678
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
7679
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7680
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
7681
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7682
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
7683
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7684
		#$conf["arrayCountEqualCheck"][]=array();
7685
		#參考資料來源:
7686
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7687
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7688
		unset($conf["variableCheck::checkArguments"]);
7689
 
7690
		#如果檢查失敗
7691
		if($checkArguments["status"]==="false"){
7692
 
7693
			#設置錯誤識別
7694
			$result["status"]="false";
7695
 
7696
			#設置錯誤訊息
7697
			$result["error"]=$checkArguments;
7698
 
7699
			#回傳結果
7700
			return $result;
7701
 
7702
			}#if end
7703
 
7704
		#如果檢查不通過
7705
		if($checkArguments["passed"]==="false"){
7706
 
7707
			#設置錯誤識別
7708
			$result["status"]="false";
7709
 
7710
			#設置錯誤訊息
7711
			$result["error"]=$checkArguments;
7712
 
7713
			#回傳結果
7714
			return $result;
7715
 
7716
			}#if end
281 liveuser 7717
 
7718
		#預設不開啟 debug flag
7719
		$debug=false;
7720
 
7721
		#如果有設置 debug 為 "true"
291 liveuser 7722
		if($conf["info"]["share"]["debug"]==="true"){
281 liveuser 7723
 
7724
			#設置 debug flag
7725
			$debug=true;
7726
 
7727
			}#if end
7728
 
293 liveuser 7729
		#如果有啟用 multiThreads
7730
		if($conf["info"]["share"]["multiThreads"]==="true"){
7731
 
7732
			#設置 multiThreads flag
7733
			$multiThreads=true;
7734
 
7735
			}#if end
7736
 
261 liveuser 7737
		#另存 server cache 的參考
7738
		$serverCache=&$conf["serverCache"];
7739
 
255 liveuser 7740
		#針對每個 domain name
291 liveuser 7741
		foreach($conf["info"]["share"]["certInfo"] as $certInfoIndex=>$cInfo){
255 liveuser 7742
 
7743
			#取得domain name
7744
			$cName=$cInfo["cName"];
7745
 
261 liveuser 7746
			#如果尚無對應domain name的記錄
7747
			if(!isset($serverCache[$cName])){
7748
 
7749
				#設置最新一次檢測的unixtime
7750
				$serverCache[$cName]["lastCheckUnixTime"]=time();
291 liveuser 7751
 
261 liveuser 7752
				}#if end
7753
 
7754
			#反之距離上次檢查不滿一天
291 liveuser 7755
			else{
261 liveuser 7756
 
291 liveuser 7757
				#計算距離上次檢查多少秒
7758
				$checkedAfter=time()-$serverCache[$cName]["lastCheckUnixTime"];
261 liveuser 7759
 
291 liveuser 7760
				#若距離上次檢查不滿一天
7761
				if($checkedAfter<86400){
7762
 
7763
					#if enable debug
7764
					if($debug){
7765
 
7766
						#debug msg
7767
						echo "Domain name(".$cName.") on zerossl require to check in ".(86400-$checkedAfter)." second(s).".PHP_EOL;
7768
 
7769
						}#if end
7770
 
7771
					#跳過該 domain name 的檢查
7772
					continue;
7773
 
7774
					}#if end
346 liveuser 7775
 
7776
				#反之
7777
				else{
291 liveuser 7778
 
346 liveuser 7779
					#重新設置上次檢查時間為當前時間
7780
					$serverCache[$cName]["lastCheckUnixTime"]=time();
7781
 
7782
					}#else end
7783
 
291 liveuser 7784
				}#else end
261 liveuser 7785
 
281 liveuser 7786
			#if enable debug
7787
			if($debug){
7788
 
7789
				#debug msg
291 liveuser 7790
				echo "Checking domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 7791
 
7792
				}#if end
7793
 
291 liveuser 7794
			#certPath
7795
			#$cInfo["ssl"]["certPath"];
7796
 
7797
			#pKey
7798
			#$cInfo["ssl"]["pKey"];
7799
 
7800
			#caPath
7801
			#$cInfo["ssl"]["caPath"]=;
7802
 
7803
			#certWithCaPath
7804
			#$cInfo["ssl"]["certWithCaPath"];
7805
 
255 liveuser 7806
			#嘗試取得 domain name 對應的可用憑證
7807
			#函式說明:
7808
			#取得在zerossl上的CSR清單
7809
			#回傳結果:
7810
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7811
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
7812
			#$result["function"],當前執行的函式名稱.
7813
			#$result["argu"],所使用的參數.
7814
			#$result["curl_verbose_info"],curl執行的詳細資訊.
7815
			#$result["content"],結果json字串.
7816
			#$result["tCount"],總共的資料筆數.
7817
			#$result["count"],該頁的筆數.
7818
			#$result["page"],當前的頁碼.
7819
			#$result["certs"],陣列,certificates清單,key為certificate的id.
7820
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
7821
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
7822
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
7823
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7824
			#必填參數:
7825
			#無
7826
			#可省略參數:
7827
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 7828
			$conf["zerossl::getCertList"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 7829
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 7830
			$conf["zerossl::getCertList"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 7831
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7832
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
7833
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
7834
			$conf["zerossl::getCertList"]["cerType"]="single90Days";
7835
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
7836
			$conf["zerossl::getCertList"]["search"]=$cName;
7837
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
7838
			#$conf["limit"]="";
7839
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
7840
			#$conf["page"]="";
7841
			#參考資料:
7842
			#https://zerossl.com/documentation/api/list-certificates/
7843
			#備註:
7844
			#無.
7845
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
7846
			unset($conf["zerossl::getCertList"]);
7847
 
7848
			#符合條件的數量
7849
			#$getCertList["tCount"];
7850
 
7851
			#符合條件的當頁數量
7852
			#$getCertList["count"];
7853
 
7854
			#如果執行異常
7855
			if($getCertList["status"]==="false"){
7856
 
7857
				#設置錯誤識別
7858
				$result["status"]="false";
7859
 
7860
				#設置錯誤訊息
7861
				$result["error"]=$getCertList;
7862
 
7863
				#回傳結果
7864
				return $result;
7865
 
7866
				}#if end
291 liveuser 7867
 
294 liveuser 7868
			#如果有資料
7869
			if($getCertList["count"]>0){
7870
 
7871
				#檢查 common name
7872
				foreach($getCertList["certs"] as $certId=>$certInfo){
7873
 
7874
					#如果 common name 不符合
7875
					if($certInfo["cname"]!==$cName){
7876
 
7877
						#移除之
7878
						unset($getCertList["certs"][$certId]);
7879
 
7880
						#當頁筆數-1
7881
						$getCertList["count"]--;
7882
 
7883
						#總共筆數減少1
7884
						$getCertList["tCount"]--;
7885
 
7886
						}#if end
7887
 
7888
					}#foreach end
7889
 
7890
				}#if end
7891
 
255 liveuser 7892
			#如果沒有憑證
291 liveuser 7893
			if($getCertList["count"]===0){
255 liveuser 7894
 
281 liveuser 7895
				#if enable debug
7896
				if($debug){
7897
 
7898
					#debug msg
291 liveuser 7899
					echo "There is not valid ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 7900
 
7901
					}#if end
7902
 
7903
				#if enable debug
7904
				if($debug){
7905
 
7906
					#debug msg
291 liveuser 7907
					echo "Checking ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7908
 
7909
					}#if end
7910
 
255 liveuser 7911
				#確認有無對應 cName 的 private key
7912
				#函式說明:
7913
				#檢查多個檔案與資料夾是否存在.
7914
				#回傳的結果:
7915
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7916
				#$result["error"],錯誤訊息陣列.
7917
				#$resutl["function"],當前執行的涵式名稱.
7918
				#$result["argu"],使用的參數.
7919
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
7920
				#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
7921
				#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
7922
				#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
7923
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
7924
				#必填參數:
7925
				#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
292 liveuser 7926
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 7927
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7928
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
7929
				#可省略參數:
7930
				#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
7931
				#$conf["disableWebSearch"]="false";
7932
				#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
7933
				$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
7934
				#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
7935
				$conf["fileAccess::checkMultiFileExist"]["web"]="false";
7936
				#參考資料:
7937
				#http://php.net/manual/en/function.file-exists.php
7938
				#http://php.net/manual/en/control-structures.foreach.php
7939
				#備註:
7940
				#函數file_exists檢查的路徑為檔案系統的路徑
7941
				#$result["varName"][$i]結果未實作
7942
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
7943
				unset($conf["fileAccess::checkMultiFileExist"]);
7944
 
7945
				#如果運行異常
7946
				if($checkMultiFileExist["status"]==="false"){
7947
 
7948
					#設置錯誤識別
7949
					$result["status"]="false";
7950
 
7951
					#設置錯誤訊息
7952
					$result["error"]=$getCertList;
7953
 
7954
					#回傳結果
7955
					return $result;
7956
 
7957
					}#if end
7958
 
7959
				#如果沒有 private key
7960
				if($checkMultiFileExist["allExist"]==="false"){
7961
 
281 liveuser 7962
					#if enable debug
7963
					if($debug){
7964
 
7965
						#debug msg
291 liveuser 7966
						echo "there is no ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7967
 
7968
						}#if end
7969
 
7970
					#if enable debug
7971
					if($debug){
7972
 
7973
						#debug msg
291 liveuser 7974
						echo "creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7975
 
7976
						}#if end
7977
 
255 liveuser 7978
					#建立 private key
7979
					#函式說明:
7980
					#產生ssl private key.
7981
					#回傳結果:
7982
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7983
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
7984
					#$result["function"],當前執行的函式名稱.
7985
					#$result["argu"],所使用的參數.
7986
					#$result["curl_verbose_info"],curl執行的詳細資訊.
7987
					#$result["content"],ssl用的private key.
7988
					#必填參數:
7989
					#$conf["fileArgu"],字串,變數__FILE__的內容.
7990
					$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
7991
					#可省略參數:
7992
					#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
7993
					#$conf["length"]=4096';
7994
					#參考資料:
7995
					#無.
7996
					#備註:
7997
					#key generated by openssl with RSA.
291 liveuser 7998
					$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 7999
					unset($conf["openssl::createPrivateKey"]);
8000
 
8001
					#如果運行異常
8002
					if($createPrivateKey["status"]==="false"){
8003
 
8004
						#設置錯誤識別
8005
						$result["status"]="false";
8006
 
8007
						#設置錯誤訊息
8008
						$result["error"]=$createPrivateKey;
8009
 
8010
						#回傳結果
8011
						return $result;
8012
 
8013
						}#if end
8014
 
8015
					#另存private key的字串
8016
					$pKeyStr=$createPrivateKey["content"];
8017
 
8018
					#建立private key檔案
8019
					#函式說明:
8020
					#將字串寫入到檔案
8021
					#回傳結果:
8022
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
8023
					#$result["error"],錯誤訊息陣列.
8024
					#$result["function"],當前執行的函數名稱.
8025
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
8026
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
8027
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
8028
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
8029
					#$result["argu"],使用的參數.
8030
					#必填參數:
8031
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8032
					$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
8033
					#可省略參數:
8034
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
292 liveuser 8035
					$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 8036
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
8037
					$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
8038
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
8039
					#$conf["writeMethod"]="a";
8040
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
8041
					#$conf["checkRepeat"]="";
8042
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
8043
					#$conf["filenameExtensionStartPoint"]="";
8044
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
8045
					#$conf["repeatNameRule"]="";
8046
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
8047
					$conf["zerossl::writeTextIntoFile"]["web"]="false";
8048
					#參考資料:
8049
					#無.
8050
					#備註:
8051
					#無.
291 liveuser 8052
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
255 liveuser 8053
					unset($conf["zerossl::writeTextIntoFile"]);
8054
 
8055
					#如果運行異常
8056
					if($writeTextIntoFile["status"]==="false"){
8057
 
8058
						#設置錯誤識別
8059
						$result["status"]="false";
8060
 
8061
						#設置錯誤訊息
8062
						$result["error"]=$writeTextIntoFile;
8063
 
8064
						#回傳結果
8065
						return $result;
8066
 
8067
						}#if end
8068
 
8069
					}#if end
8070
 
281 liveuser 8071
				#if enable debug
8072
				if($debug){
8073
 
8074
					#debug msg
291 liveuser 8075
					echo "Creating domain name(".$conf["info"]["share"]["apiDomain"].") csr for zerossl...".PHP_EOL;
281 liveuser 8076
 
8077
					}#if end
8078
 
255 liveuser 8079
				#建立準備給zerossl的csr
8080
				#函式說明:
8081
				#產生certificate sign request(CSR).
8082
				#回傳結果:
8083
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8084
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8085
				#$result["function"],當前執行的函式名稱.
8086
				#$result["argu"],所使用的參數.
8087
				#$result["content"],csr內容.
8088
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8089
				#$result["privateKey"], private key 的內容.
8090
				#必填參數:
8091
				#$conf["domain"],字串,csr內容的網域名稱.
8092
				$conf["zerossl::createCSR"]["domain"]=$cName;
8093
				#可省略參數:
8094
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 8095
				$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 8096
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
8097
				#$conf["country"]="";
8098
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
8099
				#$conf["state"]="";
8100
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
8101
				#$conf["org"]="";
8102
				#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
8103
				#$conf["unit"]="";
8104
				#參考資料:
8105
				#無.
8106
				#備註:
8107
				#無.
8108
				$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
8109
				unset($conf["zerossl::createCSR"]);
8110
 
8111
				#如果運行異常
8112
				if($createCSR["status"]==="false"){
8113
 
8114
					#設置錯誤識別
8115
					$result["status"]="false";
8116
 
8117
					#設置錯誤訊息
8118
					$result["error"]=$createCSR;
8119
 
8120
					#回傳結果
8121
					return $result;
8122
 
8123
					}#if end
8124
 
8125
				#取得本地端產生的csr內容
8126
				$csrLocal=$createCSR["content"];
8127
 
281 liveuser 8128
				#if enable debug
8129
				if($debug){
8130
 
8131
					#debug msg
291 liveuser 8132
					echo "Creating certificate for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 8133
 
8134
					}#if end
8135
 
255 liveuser 8136
				#函式說明:
281 liveuser 8137
				#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 8138
				#回傳結果:
8139
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8140
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8141
				#$result["function"],當前執行的函式名稱.
8142
				#$result["argu"],所使用的參數.
8143
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8144
				#$result["id"],用於zerossl api驗證domain的id.
8145
				#$result["content"],字串,得到的json字串回應.
8146
				#$result["cnameKey"],用於dns CNAME驗證鍵名.
8147
				#$result["cnameVal"],用於dms CNAME驗證鍵值.
8148
				#必填參數:
8149
				#$conf["certificate_domains"],字串,要簽署的doamin名稱.
8150
				$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
8151
				#$conf["certificate_csr"],字串,簽署的資訊.
8152
				$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
8153
				#$conf["fileArgu"],字串,變數__FILE__的內容.
8154
				$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
8155
				#可省略參數:
8156
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 8157
				$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 8158
				#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
8159
				#$conf["path"]=self::getApiInfo()["csrPath"];
8160
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 8161
				$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 8162
				#參考資料:
8163
				#無.
8164
				#備註:
8165
				#無.
8166
				$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
8167
				unset($conf["zerossl::createCertificate"]);
8168
 
8169
				#如果執行異常
8170
				if($createCertificate["status"]==="false"){
8171
 
8172
					#設置錯誤識別
8173
					$result["status"]="false";
8174
 
8175
					#設置錯誤訊息
8176
					$result["error"]=$createCertificate;
8177
 
8178
					#回傳結果
8179
					return $result;
8180
 
8181
					}#if end
8182
 
8183
				#取得csr在zerossl上的id
8184
				$csrId=$createCertificate["id"];
8185
 
8186
				#取得cname key
8187
				$cNameKey=$createCertificate["cnameKey"];
8188
 
8189
				#取得cname val
8190
				$cNameVal=$createCertificate["cnameVal"];
8191
 
8192
				#初始化要增加的RR記錄
8193
				$rr2add=array();
8194
 
8195
				#設置CNAME的查詢
8196
				$rr2add["query"]=$cNameKey;
8197
 
8198
				#設置CNAME的value
8199
				$rr2add["value"]=$cNameVal;
8200
 
8201
				#設置類型為 CNAME
8202
				$rr2add["type"]="CNAME";
8203
 
8204
				#設置註解
8205
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
8206
 
281 liveuser 8207
				#if enable debug
8208
				if($debug){
8209
 
8210
					#debug msg
291 liveuser 8211
					echo "Adding DNS record to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8212
 
8213
					}#if end
8214
 
255 liveuser 8215
				#函式說明:
8216
				#新增DNS記錄到檔案裡面.
8217
				#回傳結果:
8218
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8219
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8220
				#$result["function"],當前執行的函式名稱.
8221
				#$result["argu"],所使用的參數.
8222
				#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
8223
				#$result["domain"],字串,RR所屬domain.
8224
				#$result["defaultTTL"],字串,預設的RR更新時間.
8225
				#$result["comment"],字串陣列,逐行的註解.
8226
				#必填參數:
8227
				#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
291 liveuser 8228
				$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 8229
				#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
8230
				$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
8231
				#可省略參數:
8232
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
8233
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
8234
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
8235
				#$conf["debug"]="false";
293 liveuser 8236
 
8237
				#如果有啟用多執行序
8238
				if($conf["info"]["share"]["multiThreads"]==="true"){
8239
 
8240
					#設置要多執行序
8241
					$conf["zerossl::updateDnsRecordFile"]["multiThreads"]="true";
8242
 
8243
					}#if end
8244
 
255 liveuser 8245
				#參考資料:
8246
				#無.
8247
				#備註:
8248
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
8249
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
8250
				#php-pear上的Net_DNS2也可以解析RR.
8251
				$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
8252
				unset($conf["zerossl::updateDnsRecordFile"]);
8253
 
8254
				#如果執行異常
8255
				if($updateDnsRecordFile["status"]==="false"){
8256
 
8257
					#設置錯誤識別
8258
					$result["status"]="false";
8259
 
8260
					#設置錯誤訊息
8261
					$result["error"]=$updateDnsRecordFile;
8262
 
8263
					#回傳結果
8264
					return $result;
8265
 
8266
					}#if end
281 liveuser 8267
 
8268
				#if enable debug
8269
				if($debug){
8270
 
8271
					#debug msg
291 liveuser 8272
					echo "Restart DNS service to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8273
 
8274
					}#if end
8275
 
255 liveuser 8276
				#重新啟動dns伺服器
8277
				#函式說明:
8278
				#呼叫shell執行系統命令,並取得回傳的內容.
8279
				#回傳結果:
8280
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8281
				#$result["error"],錯誤訊息陣列.
8282
				#$result["function"],當前執行的函數名稱.
8283
				#$result["argu"],使用的參數.
8284
				#$result["cmd"],執行的指令內容.
8285
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8286
				#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8287
				#$result["content"],為執行完後的輸出字串.
8288
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8289
				#$result["running"],是否還在執行.
8290
				#$result["pid"],pid.
8291
				#$result["statusCode"],執行結束後的代碼.
8292
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8293
				#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8294
				#必填參數:
8295
				#$conf["command"],字串,要執行的指令.
291 liveuser 8296
				$conf["external::callShell"]["command"]="systemctl";
255 liveuser 8297
				#$conf["fileArgu"],字串,變數__FILE__的內容.
8298
				$conf["external::callShell"]["fileArgu"]=__FILE__;
8299
				#可省略參數:
8300
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8301
				$conf["external::callShell"]["argu"]=array("restart","named");
8302
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8303
				#$conf["arguIsAddr"]=array();
8304
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8305
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8306
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8307
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8308
				#$conf["enablePrintDescription"]="true";
8309
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8310
				#$conf["printDescription"]="";
8311
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8312
				#$conf["escapeshellarg"]="false";
8313
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8314
				#$conf["thereIsShellVar"]=array();
8315
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8316
				#$conf["username"]="";
8317
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8318
				#$conf["password"]="";
8319
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8320
				#$conf["useScript"]="";
8321
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8322
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8323
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8324
				#$conf["inBackGround"]="";
8325
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8326
				#$conf["getErr"]="false";
8327
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8328
				#$conf["doNotRun"]="false";
8329
				#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8330
				$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
8331
				#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8332
				#$conf["remoteUser"]="root";
8333
				#參考資料:
8334
				#exec=>http://php.net/manual/en/function.exec.php
8335
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8336
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8337
				#備註:
8338
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8339
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8340
				$callShell=external::callShell($conf["external::callShell"]);
8341
				unset($conf["external::callShell"]);
8342
 
8343
				#如果執行異常
8344
				if($callShell["status"]==="false"){
8345
 
8346
					#設置錯誤識別
8347
					$result["status"]="false";
8348
 
8349
					#設置錯誤訊息
8350
					$result["error"]=$callShell;
8351
 
8352
					#回傳結果
8353
					return $result;
8354
 
8355
					}#if end
281 liveuser 8356
 
8357
				#if enable debug
8358
				if($debug){
8359
 
8360
					#debug msg
291 liveuser 8361
					echo "Request zerossl to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8362
 
8363
					}#if end
8364
 
292 liveuser 8365
				#無窮迴圈
8366
				while(true){
255 liveuser 8367
 
292 liveuser 8368
					#函式說明:
8369
					#請求驗證已經透過zerossl::createCertificate要求的domain.
8370
					#回傳結果:
8371
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8372
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8373
					#$result["function"],當前執行的函式名稱.
8374
					#$result["argu"],所使用的參數.
8375
					#$result["curl_verbose_info"],curl執行的詳細資訊.
8376
					#$result["content"],結果json字串.
8377
					#必填參數:
8378
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
8379
					$conf["zerossl::verifyDomain"]["id"]=$csrId;
8380
					#可省略參數:
8381
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8382
					$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
8383
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8384
					$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
8385
					#參考資料:
8386
					#https://zerossl.com/documentation/api/verify-domains/
8387
					#備註:
8388
					#無.
8389
					$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
8390
					unset($conf["zerossl::verifyDomain"]);
291 liveuser 8391
 
292 liveuser 8392
					#如果執行異常
8393
					if($verifyDomain["status"]==="false"){
8394
 
8395
						#設置錯誤識別
8396
						$result["status"]="false";
291 liveuser 8397
 
292 liveuser 8398
						#設置錯誤訊息
8399
						$result["error"]=$verifyDomain;
291 liveuser 8400
 
292 liveuser 8401
						#回傳結果
8402
						return $result;
291 liveuser 8403
 
8404
						}#if end
8405
 
292 liveuser 8406
					#如果沒有回內容
293 liveuser 8407
					if(!isset($verifyDomain["content"])){
292 liveuser 8408
 
8409
						#設置錯誤識別
8410
						$result["status"]="false";
291 liveuser 8411
 
292 liveuser 8412
						#設置錯誤訊息
8413
						$result["error"]=$verifyDomain;
291 liveuser 8414
 
292 liveuser 8415
						#回傳結果
8416
						return $result;
8417
 
8418
						}#if end
8419
 
8420
					#如果回應不是 json
293 liveuser 8421
					if(!(json_validate($verifyDomain["content"]))){
292 liveuser 8422
 
8423
						#設置錯誤識別
8424
						$result["status"]="false";
291 liveuser 8425
 
292 liveuser 8426
						#設置錯誤訊息
8427
						$result["error"]=$verifyDomain;
291 liveuser 8428
 
292 liveuser 8429
						#回傳結果
8430
						return $result;
8431
 
8432
						}#if end
8433
 
294 liveuser 8434
					#if enable debug
8435
					if($debug){
8436
 
8437
						#debug msg
8438
						echo "Response of validating certificate for domain name(".$cName.") on zerossl".PHP_EOL;
8439
 
8440
						#debug msg
8441
						var_dump(__LINE__,$verifyDomain);
8442
 
8443
						}#if end
8444
 
292 liveuser 8445
					/*
8446
					範例json:
8447
					{"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}
8448
					*/
8449
 
8450
					#解析json回應
293 liveuser 8451
					$verifyDomainRes=json_decode($verifyDomain["content"]);
291 liveuser 8452
 
293 liveuser 8453
					#如果回應含有 success
8454
					if(isset($verifyDomainRes->success)){
292 liveuser 8455
 
293 liveuser 8456
						#如果是 zerossl 驗證失敗
294 liveuser 8457
						if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
291 liveuser 8458
 
293 liveuser 8459
							#如果是 CNAME 記錄找不到
8460
							if($verifyDomainRes->error->code===0){
291 liveuser 8461
 
293 liveuser 8462
								#取得錯誤訊息
8463
								#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
8464
 
8465
								#if enable debug
8466
								if($debug){
8467
 
8468
									#debug msg
8469
									echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
8470
 
8471
									}#if end
8472
 
8473
								#if enable debug
8474
								if($debug){
8475
 
8476
									#debug msg
8477
									echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
8478
 
8479
									}#if end
8480
 
8481
								#休息60秒
8482
								sleep(60);
294 liveuser 8483
 
8484
								#再跑一次要求認證
8485
								continue;
291 liveuser 8486
 
8487
								}#if end
293 liveuser 8488
 
8489
							#反之為不接受的錯誤訊息
8490
							else{
291 liveuser 8491
 
293 liveuser 8492
								#設置錯誤識別
8493
								$result["status"]="false";
8494
 
8495
								#設置錯誤訊息
8496
								$result["error"]=$verifyDomain;
8497
 
8498
								#回傳結果
8499
								return $result;
291 liveuser 8500
 
293 liveuser 8501
								}#else end
291 liveuser 8502
 
8503
							}#if end
292 liveuser 8504
 
8505
						}#if end
293 liveuser 8506
 
8507
					#反之如果回應含有 status
8508
					else if(isset($verifyDomainRes->status)){
292 liveuser 8509
 
293 liveuser 8510
						#如果是 zerossl 尚在驗證中
8511
						if($verifyDomainRes->status==="pending_validation"){
292 liveuser 8512
 
293 liveuser 8513
							#if enable debug
8514
							if($debug){
292 liveuser 8515
 
293 liveuser 8516
								#debug msg
8517
								echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
292 liveuser 8518
 
8519
								}#if end
8520
 
293 liveuser 8521
							#無窮迴圈
8522
							while(true){
8523
 
8524
								#查詢驗證狀況
8525
								#函式說明:
8526
								#取得CSR在zerossl上的狀態
8527
								#回傳結果:
8528
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8529
								#$reuslt["error"],執行不正常結束的錯訊息陣列.
8530
								#$result["function"],當前執行的函式名稱.
8531
								#$result["argu"],所使用的參數.
8532
								#$result["curl_verbose_info"],curl執行的詳細資訊.
8533
								#$result["content"],結果json字串.
8534
								#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
8535
								#必填參數:
8536
								#$conf["id"],字串,zerossl::createCertificate回傳的id.
8537
								$conf["zerossl::getCertSta"]["id"]=$csrId;
8538
								#可省略參數:
8539
								#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8540
								$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
8541
								#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8542
								$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
8543
								#參考資料:
8544
								#https://zerossl.com/documentation/api/get-certificate/
8545
								#備註:
8546
								#無.
8547
								$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
8548
								unset($conf["zerossl::getCertSta"]);
8549
 
8550
								#如果執行異常
8551
								if($getCertSta["status"]==="false"){
8552
 
8553
									#設置錯誤識別
8554
									$result["status"]="false";
292 liveuser 8555
 
293 liveuser 8556
									#設置錯誤訊息
8557
									$result["error"]=$getCertSta;
292 liveuser 8558
 
293 liveuser 8559
									#回傳結果
8560
									return $result;
292 liveuser 8561
 
293 liveuser 8562
									}#if end
8563
 
8564
								#如果沒有回應內容
8565
								if(!isset($getCertSta["content"])){
8566
 
8567
									#設置錯誤識別
8568
									$result["status"]="false";
292 liveuser 8569
 
293 liveuser 8570
									#設置錯誤訊息
8571
									$result["error"]=$getCertSta;
292 liveuser 8572
 
293 liveuser 8573
									#回傳結果
8574
									return $result;
292 liveuser 8575
 
293 liveuser 8576
									}#if end
8577
 
8578
								#如果回應不是 json
8579
								if(!(json_validate($getCertSta["content"]))){
292 liveuser 8580
 
293 liveuser 8581
									#設置錯誤識別
8582
									$result["status"]="false";
8583
 
8584
									#設置錯誤訊息
8585
									$result["error"]=$getCertSta;
8586
 
8587
									#回傳結果
8588
									return $result;
292 liveuser 8589
 
8590
									}#if end
293 liveuser 8591
 
8592
								#解析json回應
8593
								$getCertStaRes=json_decode($getCertSta["content"]);
292 liveuser 8594
 
293 liveuser 8595
								#如果憑證已經驗證通過了
8596
								if($getCertStaRes->status==="issued"){
292 liveuser 8597
 
293 liveuser 8598
									#if enable debug
8599
									if($debug){
8600
 
8601
										#debug msg
8602
										echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
8603
 
8604
										}#if end
292 liveuser 8605
 
294 liveuser 8606
									#結束等待,跳出 while
293 liveuser 8607
									break 2;
8608
 
292 liveuser 8609
									}#if end
8610
 
293 liveuser 8611
								#如果 zerossl 尚在處理中
8612
								else if($getCertStaRes->status==="pending_validation"){
292 liveuser 8613
 
293 liveuser 8614
									#if enable debug
8615
									if($debug){
8616
 
8617
										#debug msg
8618
										echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
8619
 
8620
										}#if end
8621
 
8622
									#休息1分鐘
8623
									sleep(60);
294 liveuser 8624
 
8625
									#再跑一次取得憑證狀態
8626
									continue;
293 liveuser 8627
 
8628
									}#if end
8629
 
8630
								#反之
8631
								else{
8632
 
8633
									#例外狀況
8634
 
8635
									#設置錯誤識別
8636
									$result["status"]="false";
292 liveuser 8637
 
293 liveuser 8638
									#設置錯誤訊息
8639
									$result["error"]=$getCertSta;
292 liveuser 8640
 
293 liveuser 8641
									#回傳結果
8642
									return $result;
8643
 
8644
									}#else end
292 liveuser 8645
 
293 liveuser 8646
								}#while end
8647
 
8648
							}#if end
8649
 
292 liveuser 8650
						}#if end
294 liveuser 8651
 
8652
					#反之.不應該執行到這邊
8653
					else{
8654
 
8655
						#設置錯誤識別
8656
						$result["status"]="false";
8657
 
8658
						#設置錯誤訊息
8659
						$result["error"]=$verifyDomain;
8660
 
8661
						#回傳結果
8662
						return $result;
8663
 
8664
						}#else 	
291 liveuser 8665
 
292 liveuser 8666
					}#while end
294 liveuser 8667
 
281 liveuser 8668
				#if enable debug
8669
				if($debug){
8670
 
8671
					#debug msg
291 liveuser 8672
					echo "Downloading certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8673
 
8674
					}#if end
8675
 
255 liveuser 8676
				#函式說明:
8677
				#下載certificate.
8678
				#回傳結果:
8679
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8680
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8681
				#$result["function"],當前執行的函式名稱.
8682
				#$result["argu"],所使用的參數.
8683
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8684
				#$result["content"],結果json字串.
8685
				#$result["certificate.crt"],字串,certificate.crt的內容.
8686
				#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
8687
				#必填參數:
8688
				#無.
8689
				#可省略參數:
8690
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 8691
				$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 8692
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 8693
				$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 8694
				#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
8695
				$conf["zerossl::getCert"]["id"]=$csrId;
8696
				#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
8697
				#$conf["zerossl::getCert"]["cname"]="";
8698
				#參考資料:
8699
				#https://zerossl.com/documentation/api/download-certificate-inline/
8700
				#備註:
8701
				#無.
8702
				$getCert=zerossl::getCert($conf["zerossl::getCert"]);
8703
				unset($conf["zerossl::getCert"]);
8704
 
8705
				#如果執行異常
8706
				if($getCert["status"]==="false"){
8707
 
8708
					#設置錯誤識別
8709
					$result["status"]="false";
8710
 
8711
					#設置錯誤訊息
8712
					$result["error"]=$getCert;
8713
 
8714
					#回傳結果
8715
					return $result;
8716
 
8717
					}#if end
281 liveuser 8718
 
8719
				#if enable debug
8720
				if($debug){
8721
 
8722
					#debug msg
291 liveuser 8723
					echo "Creating certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8724
 
8725
					}#if end
8726
 
293 liveuser 8727
				#certPath
8728
				#$cInfo["ssl"]["certPath"];
255 liveuser 8729
 
293 liveuser 8730
				#pKey
8731
				#$cInfo["ssl"]["pKey"];
255 liveuser 8732
 
293 liveuser 8733
				#caPath
8734
				#$cInfo["ssl"]["caPath"]=;
255 liveuser 8735
 
293 liveuser 8736
				#certWithCaPath
8737
				#$cInfo["ssl"]["certWithCaPath"];
8738
 
255 liveuser 8739
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
8740
				#函式說明:
8741
				#一次建立多個檔案,並寫入內容.
8742
				#回傳結果:
8743
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
8744
				#$result["error"],錯誤訊息陣列.
8745
				#$result["function"],當前執行的函數名稱.
8746
				#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
8747
				#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
8748
				#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
8749
				#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
8750
				#$result["argu"],使用的參數.
8751
				#必填參數:
8752
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8753
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
8754
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
293 liveuser 8755
				$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 8756
				#可省略參數:
8757
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
8758
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
8759
				#參考資料:
8760
				#無.
8761
				#備註:
8762
				#無.
293 liveuser 8763
				$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 8764
				unset($conf["zerossl::writeMultiFile"]);
8765
 
8766
				#如果執行異常
8767
				if($writeMultiFile["status"]==="false"){
8768
 
8769
					#設置錯誤識別
8770
					$result["status"]="false";
8771
 
8772
					#設置錯誤訊息
8773
					$result["error"]=$writeMultiFile;
8774
 
8775
					#回傳結果
8776
					return $result;
8777
 
8778
					}#if end
8779
 
8780
				#儲存 actionAfterUpdateCert
8781
				$action=$cInfo["actionAfterUpdateCert"];
8782
 
8783
				#如果有多個指令要執行
294 liveuser 8784
				if(count($action)>1){
255 liveuser 8785
 
281 liveuser 8786
					#if enable debug
8787
					if($debug){
8788
 
8789
						#debug msg
291 liveuser 8790
						echo "There are many cmds to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8791
 
8792
						}#if end
8793
 
8794
					#if enable debug
8795
					if($debug){
8796
 
8797
						#debug msg
291 liveuser 8798
						echo "Running cmd to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8799
 
8800
						}#if end
8801
 
255 liveuser 8802
					#針對每的指令
8803
					foreach($action as $ac){
8804
 
281 liveuser 8805
						#if enable debug
8806
						if($debug){
8807
 
8808
							#debug msg
8809
							echo ".".PHP_EOL;
8810
 
8811
							}#if end
8812
 
255 liveuser 8813
						#函式說明:
8814
						#呼叫shell執行系統命令,並取得回傳的內容.
8815
						#回傳結果:
8816
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8817
						#$result["error"],錯誤訊息陣列.
8818
						#$result["function"],當前執行的函數名稱.
8819
						#$result["argu"],使用的參數.
8820
						#$result["cmd"],執行的指令內容.
8821
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8822
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8823
						#$result["content"],為執行完後的輸出字串.
8824
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8825
						#$result["running"],是否還在執行.
8826
						#$result["pid"],pid.
8827
						#$result["statusCode"],執行結束後的代碼.
8828
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8829
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8830
						#必填參數:
8831
						#$conf["command"],字串,要執行的指令.
294 liveuser 8832
						$conf["external::callShell"]["command"]=$ac;
255 liveuser 8833
						#$conf["fileArgu"],字串,變數__FILE__的內容.
8834
						$conf["external::callShell"]["fileArgu"]=__FILE__;
8835
						#可省略參數:
8836
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
294 liveuser 8837
						#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 8838
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8839
						#$conf["arguIsAddr"]=array();
8840
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8841
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8842
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8843
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8844
						#$conf["enablePrintDescription"]="true";
8845
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8846
						#$conf["printDescription"]="";
8847
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8848
						$conf["external::callShell"]["escapeshellarg"]="true";
8849
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8850
						#$conf["thereIsShellVar"]=array();
8851
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8852
						#$conf["username"]="";
8853
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8854
						#$conf["password"]="";
8855
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8856
						#$conf["useScript"]="";
8857
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8858
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8859
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8860
						#$conf["inBackGround"]="";
8861
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8862
						#$conf["getErr"]="false";
294 liveuser 8863
						#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
8864
						$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 8865
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8866
						#$conf["doNotRun"]="false";
8867
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8868
						#$conf["remoteIp"]="";
8869
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8870
						#$conf["remoteUser"]="";
8871
						#參考資料:
8872
						#exec=>http://php.net/manual/en/function.exec.php
8873
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8874
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8875
						#備註:
8876
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8877
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8878
						$callShell=external::callShell($conf["external::callShell"]);
8879
						unset($conf["external::callShell"]);
8880
 
8881
						#如果執行異常
294 liveuser 8882
						if($callShell["status"]==="false"){
255 liveuser 8883
 
8884
							#設置錯誤識別
8885
							$result["status"]="false";
8886
 
8887
							#設置錯誤訊息
8888
							$result["error"]=$callShell;
8889
 
8890
							#回傳結果
8891
							return $result;
8892
 
8893
							}#if end
8894
 
8895
						}#foreach end
8896
 
8897
					}#if end
8898
 
8899
				#反之
8900
				else{
8901
 
281 liveuser 8902
					#if enable debug
8903
					if($debug){
8904
 
8905
						#debug msg
291 liveuser 8906
						echo "There is only one cmd to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8907
 
8908
						}#if end
8909
 
8910
					#if enable debug
8911
					if($debug){
8912
 
8913
						#debug msg
8914
						echo ".".PHP_EOL;
8915
 
8916
						}#if end
8917
 
255 liveuser 8918
					#函式說明:
8919
					#呼叫shell執行系統命令,並取得回傳的內容.
8920
					#回傳結果:
8921
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8922
					#$result["error"],錯誤訊息陣列.
8923
					#$result["function"],當前執行的函數名稱.
8924
					#$result["argu"],使用的參數.
8925
					#$result["cmd"],執行的指令內容.
8926
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8927
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8928
					#$result["content"],為執行完後的輸出字串.
8929
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8930
					#$result["running"],是否還在執行.
8931
					#$result["pid"],pid.
8932
					#$result["statusCode"],執行結束後的代碼.
8933
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8934
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8935
					#必填參數:
8936
					#$conf["command"],字串,要執行的指令.
302 liveuser 8937
					$conf["external::callShell"]["command"]=$action[0];
255 liveuser 8938
					#$conf["fileArgu"],字串,變數__FILE__的內容.
8939
					$conf["external::callShell"]["fileArgu"]=__FILE__;
8940
					#可省略參數:
8941
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 8942
					#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 8943
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8944
					#$conf["arguIsAddr"]=array();
8945
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8946
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8947
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8948
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8949
					#$conf["enablePrintDescription"]="true";
8950
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8951
					#$conf["printDescription"]="";
8952
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8953
					$conf["external::callShell"]["escapeshellarg"]="true";
8954
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8955
					#$conf["thereIsShellVar"]=array();
8956
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8957
					#$conf["username"]="";
8958
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8959
					#$conf["password"]="";
8960
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8961
					#$conf["useScript"]="";
8962
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8963
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8964
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8965
					#$conf["inBackGround"]="";
8966
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8967
					#$conf["getErr"]="false";
8968
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8969
					#$conf["doNotRun"]="false";
294 liveuser 8970
					#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
8971
					$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 8972
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8973
					#$conf["remoteIp"]="";
8974
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8975
					#$conf["remoteUser"]="";
8976
					#參考資料:
8977
					#exec=>http://php.net/manual/en/function.exec.php
8978
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8979
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8980
					#備註:
8981
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8982
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8983
					$callShell=external::callShell($conf["external::callShell"]);
8984
					unset($conf["external::callShell"]);
294 liveuser 8985
 
255 liveuser 8986
					#如果執行異常
294 liveuser 8987
					if($callShell["status"]==="false"){
255 liveuser 8988
 
8989
						#設置錯誤識別
8990
						$result["status"]="false";
8991
 
8992
						#設置錯誤訊息
8993
						$result["error"]=$callShell;
8994
 
8995
						#回傳結果
8996
						return $result;
8997
 
8998
						}#if end
8999
 
9000
					}#else end
9001
 
9002
				}#if end
9003
 
9004
			#反之
9005
			else{
9006
 
281 liveuser 9007
				#if enable debug
9008
				if($debug){
9009
 
9010
					#debug msg
291 liveuser 9011
					echo "There is already valid ssl for domain name(".$cName.") on zerossl".PHP_EOL;
281 liveuser 9012
 
9013
					}#if end
9014
 
291 liveuser 9015
				#debug
9016
				#var_dump(__LINE__,$getCertList);
9017
 
255 liveuser 9018
				#有 issued 的憑證
9019
 
291 liveuser 9020
				#if enable debug
9021
				if($debug){
9022
 
9023
					#debug msg
9024
					echo "Downloading ssl for domain name(".$cName.") on zerossl".PHP_EOL;
9025
 
9026
					}#if end
9027
 
255 liveuser 9028
				#取得 certificate id at zerossl
9029
				#函式說明:
9030
				#將陣列轉換成存有key與value的陣列
9031
				#回傳的結果:
9032
				#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
9033
				#$result["function"],當前執行的函數
9034
				#$result["error"],錯誤訊息.
9035
				#$result[$i]["key"],原先$i+1個元素的key.
9036
				#$result[$i]["value"],原先$i+1個元素的value.
9037
				#必填參數:
9038
				#$conf["rawInputArray"],陣列,要轉換的陣列變數.
9039
				$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
9040
				#可省略參數:
9041
				#無.
9042
				#參考資料:
9043
				#無.
9044
				#備註:
9045
				#無.
9046
				$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
9047
				unset($conf["arrays::getKeyAndValue"]);
9048
 
9049
				#如果執行異常
9050
				if($getKeyAndValue["status"]==="false"){
9051
 
9052
					#設置錯誤識別
9053
					$result["status"]="false";
9054
 
9055
					#設置錯誤訊息
9056
					$result["error"]=$getKeyAndValue;
9057
 
9058
					#回傳結果
9059
					return $result;
9060
 
9061
					}#if end
9062
 
291 liveuser 9063
				#debug
9064
				#var_dump($getKeyAndValue);exit;
9065
 
255 liveuser 9066
				#儲存 certificate id at zerossl
291 liveuser 9067
				$csrId=$getKeyAndValue[1]["key"];
255 liveuser 9068
 
9069
				#檢查憑證是否已經快過期
9070
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
9071
 
9072
				#如果距離當下不到2個星期就要過期
9073
				if($expiresIn<=86400*14){
291 liveuser 9074
 
281 liveuser 9075
					#if enable debug
9076
					if($debug){
9077
 
9078
						#debug msg
291 liveuser 9079
						echo "Valid ssl for domain name(".$cName.") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
281 liveuser 9080
 
9081
						}#if end
9082
 
291 liveuser 9083
					#debug
9084
					#var_dump($expiresIn);exit;
9085
 
255 liveuser 9086
					#另存舊的憑證id,最後要revoke之.
9087
					$oldCsrId=$csrId;
9088
 
281 liveuser 9089
					#if enable debug
9090
					if($debug){
9091
 
9092
						#debug msg
294 liveuser 9093
						echo "Start request new ssl process for domain name(".$cName.").".PHP_EOL;
281 liveuser 9094
 
9095
						}#if end
9096
 
9097
					#if enable debug
9098
					if($debug){
9099
 
9100
						#debug msg
291 liveuser 9101
						echo "Finding ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9102
 
9103
						}#if end
9104
 
255 liveuser 9105
					#確認有無對應 cName 的 private key
9106
					#函式說明:
9107
					#檢查多個檔案與資料夾是否存在.
9108
					#回傳的結果:
9109
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9110
					#$result["error"],錯誤訊息陣列.
9111
					#$resutl["function"],當前執行的涵式名稱.
9112
					#$result["argu"],使用的參數.
9113
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9114
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9115
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
9116
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
9117
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9118
					#必填參數:
9119
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
291 liveuser 9120
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 9121
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9122
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
9123
					#可省略參數:
9124
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9125
					#$conf["disableWebSearch"]="false";
9126
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9127
					$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
9128
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
9129
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
9130
					#參考資料:
9131
					#http://php.net/manual/en/function.file-exists.php
9132
					#http://php.net/manual/en/control-structures.foreach.php
9133
					#備註:
9134
					#函數file_exists檢查的路徑為檔案系統的路徑
9135
					#$result["varName"][$i]結果未實作
9136
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9137
					unset($conf["fileAccess::checkMultiFileExist"]);
9138
 
9139
					#如果運行異常
9140
					if($checkMultiFileExist["status"]==="false"){
9141
 
9142
						#設置錯誤識別
9143
						$result["status"]="false";
9144
 
9145
						#設置錯誤訊息
9146
						$result["error"]=$getCertList;
9147
 
9148
						#回傳結果
9149
						return $result;
9150
 
9151
						}#if end
9152
 
9153
					#如果沒有 private key
9154
					if($checkMultiFileExist["allExist"]==="false"){
9155
 
281 liveuser 9156
						#if enable debug
9157
						if($debug){
9158
 
9159
							#debug msg
291 liveuser 9160
							echo "Thers is no ssl private key for domain name(".$cName.").".PHP_EOL;
281 liveuser 9161
 
9162
							}#if end
9163
 
9164
						#if enable debug
9165
						if($debug){
9166
 
9167
							#debug msg
291 liveuser 9168
							echo "Creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9169
 
9170
							}#if end
9171
 
255 liveuser 9172
						#建立 private key
9173
						#函式說明:
9174
						#產生ssl private key.
9175
						#回傳結果:
9176
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9177
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
9178
						#$result["function"],當前執行的函式名稱.
9179
						#$result["argu"],所使用的參數.
9180
						#$result["curl_verbose_info"],curl執行的詳細資訊.
9181
						#$result["content"],ssl用的private key.
9182
						#必填參數:
9183
						#$conf["fileArgu"],字串,變數__FILE__的內容.
9184
						$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
9185
						#可省略參數:
9186
						#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
9187
						#$conf["length"]=4096';
9188
						#參考資料:
9189
						#無.
9190
						#備註:
9191
						#key generated by openssl with RSA.
291 liveuser 9192
						$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 9193
						unset($conf["openssl::createPrivateKey"]);
9194
 
9195
						#如果運行異常
9196
						if($createPrivateKey["status"]==="false"){
9197
 
9198
							#設置錯誤識別
9199
							$result["status"]="false";
9200
 
9201
							#設置錯誤訊息
9202
							$result["error"]=$createPrivateKey;
9203
 
9204
							#回傳結果
9205
							return $result;
9206
 
9207
							}#if end
9208
 
9209
						#另存private key的字串
9210
						$pKeyStr=$createPrivateKey["content"];
9211
 
281 liveuser 9212
						#if enable debug
9213
						if($debug){
9214
 
9215
							#debug msg
291 liveuser 9216
							echo "Writing ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9217
 
9218
							}#if end
9219
 
255 liveuser 9220
						#建立private key檔案
9221
						#函式說明:
9222
						#將字串寫入到檔案
9223
						#回傳結果:
9224
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9225
						#$result["error"],錯誤訊息陣列.
9226
						#$result["function"],當前執行的函數名稱.
9227
						#$result["fileInfo"],實際上寫入的檔案資訊陣列.
9228
						#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
9229
						#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
9230
						#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
9231
						#$result["argu"],使用的參數.
9232
						#必填參數:
9233
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9234
						$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
9235
						#可省略參數:
9236
						#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
291 liveuser 9237
						$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 9238
						#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
9239
						$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
9240
						#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
9241
						#$conf["writeMethod"]="a";
9242
						#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
9243
						#$conf["checkRepeat"]="";
9244
						#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
9245
						#$conf["filenameExtensionStartPoint"]="";
9246
						#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
9247
						#$conf["repeatNameRule"]="";
9248
						#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
9249
						$conf["zerossl::writeTextIntoFile"]["web"]="false";
9250
						#參考資料:
9251
						#無.
9252
						#備註:
9253
						#無.
9254
						$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
9255
						unset($conf["zerossl::writeTextIntoFile"]);
9256
 
9257
						#如果運行異常
9258
						if($writeTextIntoFile["status"]==="false"){
9259
 
9260
							#設置錯誤識別
9261
							$result["status"]="false";
9262
 
9263
							#設置錯誤訊息
9264
							$result["error"]=$writeTextIntoFile;
9265
 
9266
							#回傳結果
9267
							return $result;
9268
 
9269
							}#if end
9270
 
9271
						}#if end
9272
 
281 liveuser 9273
					#if enable debug
9274
					if($debug){
9275
 
9276
						#debug msg
291 liveuser 9277
						echo "Creating CSR for domain name(".$cName.") to zerossl.".PHP_EOL;
281 liveuser 9278
 
9279
						}#if end
9280
 
255 liveuser 9281
					#建立準備給zerossl的csr
9282
					#函式說明:
9283
					#產生certificate sign request(CSR).
9284
					#回傳結果:
9285
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9286
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9287
					#$result["function"],當前執行的函式名稱.
9288
					#$result["argu"],所使用的參數.
9289
					#$result["content"],csr內容.
9290
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9291
					#$result["privateKey"], private key 的內容.
9292
					#必填參數:
9293
					#$conf["domain"],字串,csr內容的網域名稱.
9294
					$conf["zerossl::createCSR"]["domain"]=$cName;
9295
					#可省略參數:
9296
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 9297
					$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 9298
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
9299
					#$conf["country"]="";
9300
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
9301
					#$conf["state"]="";
9302
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
9303
					#$conf["org"]="";
9304
					#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
9305
					#$conf["unit"]="";
9306
					#參考資料:
9307
					#無.
9308
					#備註:
9309
					#無.
9310
					$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
9311
					unset($conf["zerossl::createCSR"]);
9312
 
9313
					#如果運行異常
9314
					if($createCSR["status"]==="false"){
9315
 
9316
						#設置錯誤識別
9317
						$result["status"]="false";
9318
 
9319
						#設置錯誤訊息
9320
						$result["error"]=$createCSR;
9321
 
9322
						#回傳結果
9323
						return $result;
9324
 
9325
						}#if end
9326
 
9327
					#取得本地端產生的csr內容
9328
					$csrLocal=$createCSR["content"];
9329
 
281 liveuser 9330
					#if enable debug
9331
					if($debug){
9332
 
9333
						#debug msg
291 liveuser 9334
						echo "Providing CSR for domain name(".$cName.") to zerossl".PHP_EOL;
281 liveuser 9335
 
9336
						}#if end
9337
 
255 liveuser 9338
					#函式說明:
281 liveuser 9339
					#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 9340
					#回傳結果:
9341
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9342
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9343
					#$result["function"],當前執行的函式名稱.
9344
					#$result["argu"],所使用的參數.
9345
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9346
					#$result["id"],用於zerossl api驗證domain的id.
9347
					#$result["content"],字串,得到的json字串回應.
9348
					#$result["cnameKey"],用於dns CNAME驗證鍵名.
9349
					#$result["cnameVal"],用於dms CNAME驗證鍵值.
9350
					#必填參數:
9351
					#$conf["certificate_domains"],字串,要簽署的doamin名稱.
9352
					$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
9353
					#$conf["certificate_csr"],字串,簽署的資訊.
9354
					$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
9355
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9356
					$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
9357
					#可省略參數:
9358
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9359
					$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9360
					#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
9361
					#$conf["path"]=self::getApiInfo()["csrPath"];
9362
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9363
					$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9364
					#參考資料:
9365
					#無.
9366
					#備註:
9367
					#無.
9368
					$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
9369
					unset($conf["zerossl::createCertificate"]);
9370
 
9371
					#如果執行異常
9372
					if($createCertificate["status"]==="false"){
9373
 
9374
						#設置錯誤識別
9375
						$result["status"]="false";
9376
 
9377
						#設置錯誤訊息
9378
						$result["error"]=$createCertificate;
9379
 
9380
						#回傳結果
9381
						return $result;
9382
 
9383
						}#if end
9384
 
9385
					#取得csr在zerossl上的id
9386
					$csrId=$createCertificate["id"];
9387
 
9388
					#取得cname key
9389
					$cNameKey=$createCertificate["cnameKey"];
9390
 
9391
					#取得cname val
9392
					$cNameVal=$createCertificate["cnameVal"];
9393
 
9394
					#初始化要增加的RR記錄
9395
					$rr2add=array();
9396
 
9397
					#設置CNAME的查詢
9398
					$rr2add["query"]=$cNameKey;
9399
 
9400
					#設置CNAME的value
9401
					$rr2add["value"]=$cNameVal;
9402
 
9403
					#設置類型為 CNAME
9404
					$rr2add["type"]="CNAME";
9405
 
9406
					#設置註解
9407
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
9408
 
281 liveuser 9409
					#if enable debug
9410
					if($debug){
9411
 
9412
						#debug msg
335 liveuser 9413
						echo "Adding DNS record to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9414
 
9415
						}#if end
9416
 
255 liveuser 9417
					#函式說明:
9418
					#新增DNS記錄到檔案裡面.
9419
					#回傳結果:
9420
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9421
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9422
					#$result["function"],當前執行的函式名稱.
9423
					#$result["argu"],所使用的參數.
9424
					#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
9425
					#$result["domain"],字串,RR所屬domain.
9426
					#$result["defaultTTL"],字串,預設的RR更新時間.
9427
					#$result["comment"],字串陣列,逐行的註解.
9428
					#必填參數:
9429
					#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
333 liveuser 9430
					$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 9431
					#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
9432
					$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
9433
					#可省略參數:
9434
					#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
9435
					$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
9436
					#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
9437
					#$conf["debug"]="false";
9438
					#參考資料:
9439
					#無.
9440
					#備註:
9441
					#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
9442
					#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
9443
					#php-pear上的Net_DNS2也可以解析RR.
9444
					$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
9445
					unset($conf["zerossl::updateDnsRecordFile"]);
9446
 
9447
					#如果執行異常
9448
					if($updateDnsRecordFile["status"]==="false"){
9449
 
9450
						#設置錯誤識別
9451
						$result["status"]="false";
9452
 
9453
						#設置錯誤訊息
9454
						$result["error"]=$updateDnsRecordFile;
9455
 
9456
						#回傳結果
9457
						return $result;
9458
 
9459
						}#if end
281 liveuser 9460
 
9461
					#if enable debug
9462
					if($debug){
9463
 
9464
						#debug msg
336 liveuser 9465
						echo "Restarting DNS service to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9466
 
9467
						}#if end
9468
 
255 liveuser 9469
					#重新啟動dns伺服器
9470
					#函式說明:
9471
					#呼叫shell執行系統命令,並取得回傳的內容.
9472
					#回傳結果:
9473
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9474
					#$result["error"],錯誤訊息陣列.
9475
					#$result["function"],當前執行的函數名稱.
9476
					#$result["argu"],使用的參數.
9477
					#$result["cmd"],執行的指令內容.
9478
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9479
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9480
					#$result["content"],為執行完後的輸出字串.
9481
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9482
					#$result["running"],是否還在執行.
9483
					#$result["pid"],pid.
9484
					#$result["statusCode"],執行結束後的代碼.
9485
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9486
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9487
					#必填參數:
9488
					#$conf["command"],字串,要執行的指令.
291 liveuser 9489
					$conf["external::callShell"]["command"]="systemctl";
255 liveuser 9490
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9491
					$conf["external::callShell"]["fileArgu"]=__FILE__;
9492
					#可省略參數:
9493
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9494
					$conf["external::callShell"]["argu"]=array("restart","named");
9495
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9496
					#$conf["arguIsAddr"]=array();
9497
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9498
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9499
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9500
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9501
					#$conf["enablePrintDescription"]="true";
9502
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9503
					#$conf["printDescription"]="";
9504
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9505
					#$conf["escapeshellarg"]="false";
9506
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9507
					#$conf["thereIsShellVar"]=array();
9508
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9509
					#$conf["username"]="";
9510
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9511
					#$conf["password"]="";
9512
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9513
					#$conf["useScript"]="";
9514
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9515
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9516
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9517
					#$conf["inBackGround"]="";
9518
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9519
					#$conf["getErr"]="false";
9520
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9521
					#$conf["doNotRun"]="false";
302 liveuser 9522
					#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
9523
					#$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 9524
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
9525
					$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
9526
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
9527
					#$conf["remoteUser"]="root";
9528
					#參考資料:
9529
					#exec=>http://php.net/manual/en/function.exec.php
9530
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9531
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9532
					#備註:
9533
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9534
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9535
					$callShell=external::callShell($conf["external::callShell"]);
9536
					unset($conf["external::callShell"]);
9537
 
9538
					#如果執行異常
9539
					if($callShell["status"]==="false"){
9540
 
9541
						#設置錯誤識別
9542
						$result["status"]="false";
9543
 
9544
						#設置錯誤訊息
9545
						$result["error"]=$callShell;
9546
 
9547
						#回傳結果
9548
						return $result;
9549
 
9550
						}#if end
281 liveuser 9551
 
9552
					#if enable debug
9553
					if($debug){
9554
 
9555
						#debug msg
336 liveuser 9556
						echo "Request zerossl to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9557
 
9558
						}#if end
9559
 
294 liveuser 9560
					#無窮迴圈
9561
					while(true){
255 liveuser 9562
 
294 liveuser 9563
						#函式說明:
9564
						#請求驗證已經透過zerossl::createCertificate要求的domain.
9565
						#回傳結果:
9566
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9567
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
9568
						#$result["function"],當前執行的函式名稱.
9569
						#$result["argu"],所使用的參數.
9570
						#$result["curl_verbose_info"],curl執行的詳細資訊.
9571
						#$result["content"],結果json字串.
9572
						#必填參數:
9573
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
9574
						$conf["zerossl::verifyDomain"]["id"]=$csrId;
9575
						#可省略參數:
9576
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
9577
						$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
9578
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
9579
						$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
9580
						#參考資料:
9581
						#https://zerossl.com/documentation/api/verify-domains/
9582
						#備註:
9583
						#無.
9584
						$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
9585
						unset($conf["zerossl::verifyDomain"]);
9586
 
9587
						#如果執行異常
9588
						if($verifyDomain["status"]==="false"){
9589
 
9590
							#設置錯誤識別
9591
							$result["status"]="false";
255 liveuser 9592
 
294 liveuser 9593
							#設置錯誤訊息
9594
							$result["error"]=$verifyDomain;
255 liveuser 9595
 
294 liveuser 9596
							#回傳結果
9597
							return $result;
9598
 
9599
							}#if end
9600
 
9601
						#如果沒有回內容
9602
						if(!isset($verifyDomain["content"])){
9603
 
9604
							#設置錯誤識別
9605
							$result["status"]="false";
9606
 
9607
							#設置錯誤訊息
9608
							$result["error"]=$verifyDomain;
9609
 
9610
							#回傳結果
9611
							return $result;
9612
 
9613
							}#if end
9614
 
9615
						#如果回應不是 json
9616
						if(!(json_validate($verifyDomain["content"]))){
9617
 
9618
							#設置錯誤識別
9619
							$result["status"]="false";
9620
 
9621
							#設置錯誤訊息
9622
							$result["error"]=$verifyDomain;
9623
 
9624
							#回傳結果
9625
							return $result;
9626
 
9627
							}#if end
9628
 
9629
						/*
9630
						範例json:
9631
						{"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}
9632
						*/
9633
 
9634
						#解析json回應
9635
						$verifyDomainRes=json_decode($verifyDomain["content"]);
9636
 
9637
						#如果回應含有 success
9638
						if(isset($verifyDomainRes->success)){
9639
 
9640
							#如果是 zerossl 驗證失敗
9641
							if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
9642
 
9643
								#如果是 CNAME 記錄找不到
9644
								if($verifyDomainRes->error->code===0){
9645
 
9646
									#取得錯誤訊息
9647
									#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
9648
 
9649
									#if enable debug
9650
									if($debug){
9651
 
9652
										#debug msg
9653
										echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
9654
 
9655
										}#if end
9656
 
9657
									#if enable debug
9658
									if($debug){
9659
 
9660
										#debug msg
9661
										echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
9662
 
9663
										}#if end
9664
 
9665
									#休息60秒
9666
									sleep(60);
9667
 
9668
									#再跑一次要求認證憑證
9669
									continue;
9670
 
9671
									}#if end
9672
 
9673
								#反之為不接受的錯誤訊息
9674
								else{
9675
 
9676
									#設置錯誤識別
9677
									$result["status"]="false";
9678
 
9679
									#設置錯誤訊息
9680
									$result["error"]=$verifyDomain;
9681
 
9682
									#回傳結果
9683
									return $result;
9684
 
9685
									}#else end
9686
 
9687
								}#if end
9688
 
9689
							}#if end
9690
 
9691
						#反之如果回應含有 status
9692
						else if(isset($verifyDomainRes->status)){
9693
 
9694
							#如果是 zerossl 尚在驗證中
9695
							if($verifyDomainRes->status==="pending_validation"){
9696
 
9697
								#if enable debug
9698
								if($debug){
9699
 
9700
									#debug msg
9701
									echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9702
 
9703
									}#if end
9704
 
9705
								#無窮迴圈
9706
								while(true){
9707
 
9708
									#查詢驗證狀況
9709
									#函式說明:
9710
									#取得CSR在zerossl上的狀態
9711
									#回傳結果:
9712
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9713
									#$reuslt["error"],執行不正常結束的錯訊息陣列.
9714
									#$result["function"],當前執行的函式名稱.
9715
									#$result["argu"],所使用的參數.
9716
									#$result["curl_verbose_info"],curl執行的詳細資訊.
9717
									#$result["content"],結果json字串.
9718
									#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9719
									#必填參數:
9720
									#$conf["id"],字串,zerossl::createCertificate回傳的id.
9721
									$conf["zerossl::getCertSta"]["id"]=$csrId;
9722
									#可省略參數:
9723
									#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
9724
									$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
9725
									#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
9726
									$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
9727
									#參考資料:
9728
									#https://zerossl.com/documentation/api/get-certificate/
9729
									#備註:
9730
									#無.
9731
									$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
9732
									unset($conf["zerossl::getCertSta"]);
9733
 
9734
									#如果執行異常
9735
									if($getCertSta["status"]==="false"){
9736
 
9737
										#設置錯誤識別
9738
										$result["status"]="false";
9739
 
9740
										#設置錯誤訊息
9741
										$result["error"]=$getCertSta;
9742
 
9743
										#回傳結果
9744
										return $result;
9745
 
9746
										}#if end
9747
 
9748
									#如果沒有回應內容
9749
									if(!isset($getCertSta["content"])){
9750
 
9751
										#設置錯誤識別
9752
										$result["status"]="false";
9753
 
9754
										#設置錯誤訊息
9755
										$result["error"]=$getCertSta;
9756
 
9757
										#回傳結果
9758
										return $result;
9759
 
9760
										}#if end
9761
 
9762
									#如果回應不是 json
9763
									if(!(json_validate($getCertSta["content"]))){
9764
 
9765
										#設置錯誤識別
9766
										$result["status"]="false";
9767
 
9768
										#設置錯誤訊息
9769
										$result["error"]=$getCertSta;
9770
 
9771
										#回傳結果
9772
										return $result;
9773
 
9774
										}#if end
9775
 
9776
									#解析json回應
9777
									$getCertStaRes=json_decode($getCertSta["content"]);
9778
 
9779
									#如果憑證已經驗證通過了
9780
									if($getCertStaRes->status==="issued"){
9781
 
9782
										#if enable debug
9783
										if($debug){
9784
 
9785
											#debug msg
9786
											echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
9787
 
9788
											}#if end
9789
 
9790
										#結束等待,離開while
9791
										break 2;
9792
 
9793
										}#if end
9794
 
9795
									#如果 zerossl 尚在處理中
9796
									else if($getCertStaRes->status==="pending_validation"){
9797
 
9798
										#if enable debug
9799
										if($debug){
9800
 
9801
											#debug msg
9802
											echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9803
 
9804
											}#if end
9805
 
9806
										#休息1分鐘
9807
										sleep(60);
9808
 
9809
										#再次確認憑證的狀態
9810
										continue;
9811
 
9812
										}#if end
9813
 
9814
									#反之
9815
									else{
9816
 
9817
										#例外狀況
9818
 
9819
										#設置錯誤識別
9820
										$result["status"]="false";
9821
 
9822
										#設置錯誤訊息
9823
										$result["error"]=$getCertSta;
9824
 
9825
										#回傳結果
9826
										return $result;
9827
 
9828
										}#else end
9829
 
9830
									}#while end
9831
 
9832
								}#if end
9833
 
9834
							}#if end
255 liveuser 9835
 
294 liveuser 9836
						}#while end
281 liveuser 9837
 
294 liveuser 9838
 
281 liveuser 9839
					#if enable debug
9840
					if($debug){
9841
 
9842
						#debug msg
291 liveuser 9843
						echo "Downling ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 9844
 
9845
						}#if end
9846
 
255 liveuser 9847
					#函式說明:
9848
					#下載certificate.
9849
					#回傳結果:
9850
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9851
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9852
					#$result["function"],當前執行的函式名稱.
9853
					#$result["argu"],所使用的參數.
9854
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9855
					#$result["content"],結果json字串.
9856
					#$result["certificate.crt"],字串,certificate.crt的內容.
9857
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
9858
					#必填參數:
9859
					#無.
9860
					#可省略參數:
9861
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9862
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9863
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9864
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9865
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
9866
					$conf["zerossl::getCert"]["id"]=$csrId;
9867
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
9868
					#$conf["zerossl::getCert"]["cname"]="";
9869
					#參考資料:
9870
					#https://zerossl.com/documentation/api/download-certificate-inline/
9871
					#備註:
9872
					#無.
9873
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
9874
					unset($conf["zerossl::getCert"]);
9875
 
9876
					#如果執行異常
9877
					if($getCert["status"]==="false"){
9878
 
9879
						#設置錯誤識別
9880
						$result["status"]="false";
9881
 
9882
						#設置錯誤訊息
9883
						$result["error"]=$getCert;
9884
 
9885
						#回傳結果
9886
						return $result;
9887
 
9888
						}#if end
281 liveuser 9889
 
9890
					#if enable debug
9891
					if($debug){
9892
 
9893
						#debug msg
291 liveuser 9894
						echo "Creating ssl for domain name(".$cName.").".PHP_EOL;
281 liveuser 9895
 
9896
						}#if end
9897
 
255 liveuser 9898
					#建立 certificate.crt 檔案
9899
					#$cInfo["certPath"];
9900
 
9901
					#建立 ca_bundle.crt 檔案
9902
					#$cInfo["caPath"];
9903
 
9904
					#建立 certAndCa.crt 檔案
9905
					#$cInfo["certWithCaPath"];
9906
 
9907
					#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
9908
					#函式說明:
9909
					#一次建立多個檔案,並寫入內容.
9910
					#回傳結果:
9911
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9912
					#$result["error"],錯誤訊息陣列.
9913
					#$result["function"],當前執行的函數名稱.
9914
					#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
9915
					#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
9916
					#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
9917
					#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
9918
					#$result["argu"],使用的參數.
9919
					#必填參數:
9920
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9921
					$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
9922
					#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 9923
					$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 9924
					#可省略參數:
9925
					#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
9926
					$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
9927
					#參考資料:
9928
					#無.
9929
					#備註:
9930
					#無.
333 liveuser 9931
					$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 9932
					unset($conf["zerossl::writeMultiFile"]);
9933
 
9934
					#如果執行異常
9935
					if($writeMultiFile["status"]==="false"){
9936
 
9937
						#設置錯誤識別
9938
						$result["status"]="false";
9939
 
9940
						#設置錯誤訊息
9941
						$result["error"]=$writeMultiFile;
9942
 
9943
						#回傳結果
9944
						return $result;
9945
 
9946
						}#if end
9947
 
9948
					#儲存 actionAfterUpdateCert
9949
					$action=$cInfo["actionAfterUpdateCert"];
9950
 
9951
					#如果有多個指令要執行
294 liveuser 9952
					if(count($action)>0){
255 liveuser 9953
 
281 liveuser 9954
						#if enable debug
9955
						if($debug){
9956
 
9957
							#debug msg
338 liveuser 9958
							echo "There many cmd to run to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9959
 
9960
							}#if end
9961
 
294 liveuser 9962
						#針對每個指令
255 liveuser 9963
						foreach($action as $ac){
9964
 
281 liveuser 9965
							#if enable debug
9966
							if($debug){
9967
 
9968
								#debug msg
9969
								echo ".".PHP_EOL;
9970
 
9971
								}#if end
9972
 
255 liveuser 9973
							#函式說明:
9974
							#呼叫shell執行系統命令,並取得回傳的內容.
9975
							#回傳結果:
9976
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9977
							#$result["error"],錯誤訊息陣列.
9978
							#$result["function"],當前執行的函數名稱.
9979
							#$result["argu"],使用的參數.
9980
							#$result["cmd"],執行的指令內容.
9981
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9982
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9983
							#$result["content"],為執行完後的輸出字串.
9984
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9985
							#$result["running"],是否還在執行.
9986
							#$result["pid"],pid.
9987
							#$result["statusCode"],執行結束後的代碼.
9988
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9989
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9990
							#必填參數:
9991
							#$conf["command"],字串,要執行的指令.
302 liveuser 9992
							$conf["external::callShell"]["command"]=$ac;
255 liveuser 9993
							#$conf["fileArgu"],字串,變數__FILE__的內容.
9994
							$conf["external::callShell"]["fileArgu"]=__FILE__;
9995
							#可省略參數:
9996
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 9997
							#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 9998
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9999
							#$conf["arguIsAddr"]=array();
10000
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10001
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10002
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10003
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10004
							#$conf["enablePrintDescription"]="true";
10005
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10006
							#$conf["printDescription"]="";
10007
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10008
							$conf["external::callShell"]["escapeshellarg"]="true";
10009
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10010
							#$conf["thereIsShellVar"]=array();
10011
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10012
							#$conf["username"]="";
10013
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10014
							#$conf["password"]="";
10015
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10016
							#$conf["useScript"]="";
10017
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10018
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10019
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10020
							#$conf["inBackGround"]="";
10021
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10022
							#$conf["getErr"]="false";
10023
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10024
							#$conf["doNotRun"]="false";
302 liveuser 10025
							#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10026
							$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10027
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10028
							#$conf["remoteIp"]="";
10029
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10030
							#$conf["remoteUser"]="";
10031
							#參考資料:
10032
							#exec=>http://php.net/manual/en/function.exec.php
10033
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10034
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10035
							#備註:
10036
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10037
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10038
							$callShell=external::callShell($conf["external::callShell"]);
10039
							unset($conf["external::callShell"]);
294 liveuser 10040
 
255 liveuser 10041
							#如果執行異常
294 liveuser 10042
							if($callShell["status"]==="false"){
255 liveuser 10043
 
10044
								#設置錯誤識別
10045
								$result["status"]="false";
10046
 
10047
								#設置錯誤訊息
10048
								$result["error"]=$callShell;
10049
 
10050
								#回傳結果
10051
								return $result;
10052
 
10053
								}#if end
10054
 
10055
							}#foreach end
10056
 
10057
						}#if end
10058
 
10059
					#反之
10060
					else{
10061
 
281 liveuser 10062
						#if enable debug
10063
						if($debug){
10064
 
10065
							#debug msg
291 liveuser 10066
							echo "There is only one cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 10067
 
10068
							}#if end
10069
 
10070
						#if enable debug
10071
						if($debug){
10072
 
10073
							#debug msg
10074
							echo ".".PHP_EOL;
10075
 
10076
							}#if end
10077
 
255 liveuser 10078
						#函式說明:
10079
						#呼叫shell執行系統命令,並取得回傳的內容.
10080
						#回傳結果:
10081
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10082
						#$result["error"],錯誤訊息陣列.
10083
						#$result["function"],當前執行的函數名稱.
10084
						#$result["argu"],使用的參數.
10085
						#$result["cmd"],執行的指令內容.
10086
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10087
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10088
						#$result["content"],為執行完後的輸出字串.
10089
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10090
						#$result["running"],是否還在執行.
10091
						#$result["pid"],pid.
10092
						#$result["statusCode"],執行結束後的代碼.
10093
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10094
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10095
						#必填參數:
10096
						#$conf["command"],字串,要執行的指令.
302 liveuser 10097
						$conf["external::callShell"]["command"]=$action[0];
255 liveuser 10098
						#$conf["fileArgu"],字串,變數__FILE__的內容.
10099
						$conf["external::callShell"]["fileArgu"]=__FILE__;
10100
						#可省略參數:
10101
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10102
						#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 10103
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10104
						#$conf["arguIsAddr"]=array();
10105
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10106
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10107
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10108
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10109
						#$conf["enablePrintDescription"]="true";
10110
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10111
						#$conf["printDescription"]="";
10112
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10113
						$conf["external::callShell"]["escapeshellarg"]="true";
10114
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10115
						#$conf["thereIsShellVar"]=array();
10116
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10117
						#$conf["username"]="";
10118
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10119
						#$conf["password"]="";
10120
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10121
						#$conf["useScript"]="";
10122
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10123
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10124
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10125
						#$conf["inBackGround"]="";
10126
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10127
						#$conf["getErr"]="false";
10128
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10129
						#$conf["doNotRun"]="false";
302 liveuser 10130
						#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10131
						$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10132
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10133
						#$conf["remoteIp"]="";
10134
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10135
						#$conf["remoteUser"]="";
10136
						#參考資料:
10137
						#exec=>http://php.net/manual/en/function.exec.php
10138
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10139
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10140
						#備註:
10141
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10142
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10143
						$callShell=external::callShell($conf["external::callShell"]);
10144
						unset($conf["external::callShell"]);
294 liveuser 10145
 
255 liveuser 10146
						#如果執行異常
294 liveuser 10147
						if($callShell["status"]==="false"){
255 liveuser 10148
 
10149
							#設置錯誤識別
10150
							$result["status"]="false";
10151
 
10152
							#設置錯誤訊息
10153
							$result["error"]=$callShell;
10154
 
10155
							#回傳結果
10156
							return $result;
10157
 
10158
							}#if end
10159
 
10160
						}#else end
10161
 
10162
					#要移除舊的憑證 
10163
 
281 liveuser 10164
					#if enable debug
10165
					if($debug){
10166
 
10167
						#debug msg
341 liveuser 10168
						echo "Revoke old ssl(".$conf["info"]["share"]["apiDomain"].") on zerossl".PHP_EOL;
281 liveuser 10169
 
10170
						}#if end
10171
 
255 liveuser 10172
					#舊憑證於zerossl上的id
10173
					#$oldCsrId
10174
 
341 liveuser 10175
					#無窮迴圈
10176
					while(true){
255 liveuser 10177
 
341 liveuser 10178
						#移除舊的憑證
10179
						#函式說明:
10180
						#請求廢除 issued zerossl certificate.
10181
						#回傳結果:
10182
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10183
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
10184
						#$result["function"],當前執行的函式名稱.
10185
						#$result["argu"],所使用的參數.
10186
						#$result["curl_verbose_info"],curl執行的詳細資訊.
10187
						#$result["content"],結果json字串.
10188
						#$result["busy"],若content結果含有busy屬性,且為1,則為"true";反之為"false".
10189
						#必填參數:
10190
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
10191
						$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
10192
						#可省略參數:
10193
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
10194
						$conf["zerosssl::revokeCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
10195
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
10196
						$conf["zerosssl::revokeCert"]["key"]=$conf["info"]["share"]["key"];
10197
						#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
10198
						$conf["zerosssl::revokeCert"]["reason"]="Superseded";
10199
						#參考資料:
10200
						#https://zerossl.com/documentation/api/revoke-certificate/
10201
						#備註:
10202
						#無.
10203
						$revokeCert=zerossl::revokeCert($conf["zerosssl::revokeCert"]);
10204
						unset($conf["zerosssl::revokeCert"]);
10205
 
10206
						#如果執行異常
10207
						if($revokeCert["status"]==="false"){
10208
 
10209
							#如果是 api endpoint busy
10210
							if($revokeCert["busy"]==="true"){
10211
 
10212
								#if enable debug
10213
								if($debug){
10214
 
10215
									#debug msg
10216
									echo "Api endpoint busy, retry revoke old ssl(".$conf["info"]["share"]["apiDomain"].") on zerossl in 60 seconds".PHP_EOL;
10217
 
10218
									}#if end
10219
 
10220
								#休息1分鐘
10221
								sleep(60);
10222
 
10223
								#再執行一次
10224
								continue;
10225
 
10226
								}#if end
10227
 
10228
							#設置錯誤識別
10229
							$result["status"]="false";
255 liveuser 10230
 
341 liveuser 10231
							#設置錯誤訊息
10232
							$result["error"]=$revokeCert;
255 liveuser 10233
 
341 liveuser 10234
							#回傳結果
10235
							return $result;
10236
 
10237
							}#if end
10238
 
10239
						#revoke 成功,跳出 while loop.
10240
						break;
10241
 
10242
						}#while end
10243
 
10244
					#if enable debug
10245
					if($debug){
10246
 
10247
						#debug msg
10248
						echo "Old ssl on zerossl(".$conf["info"]["share"]["apiDomain"].") revoked".PHP_EOL;
10249
 
291 liveuser 10250
						}#if end
10251
 
255 liveuser 10252
					}#if end
10253
 
10254
				#反之,尚不需要提前申請新的憑證
10255
				else{
10256
 
291 liveuser 10257
					#debug
10258
					#var_dump(__LINE__,"尚不需要提前申請新的憑證");exit;
10259
 
281 liveuser 10260
					#if enable debug
10261
					if($debug){
10262
 
10263
						#debug msg
291 liveuser 10264
						echo "ssl for domain name(".$cName.") is valid ".PHP_EOL;
281 liveuser 10265
 
10266
						}#if end
10267
 
10268
					#if enable debug
10269
					if($debug){
10270
 
10271
						#debug msg
291 liveuser 10272
						echo "Downling ssl for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 10273
 
10274
						}#if end
10275
 
310 liveuser 10276
					#if enable debug
10277
					if($debug){
10278
 
10279
						#debug msg
10280
						echo "ID for domain name(".$cName.") on zerossl is ".$csrId.".".PHP_EOL;
10281
 
10282
						}#if end
10283
 
255 liveuser 10284
					#下載憑證
10285
					#函式說明:
10286
					#下載certificate.
10287
					#回傳結果:
10288
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10289
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10290
					#$result["function"],當前執行的函式名稱.
10291
					#$result["argu"],所使用的參數.
10292
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10293
					#$result["content"],結果json字串.
10294
					#$result["certificate.crt"],字串,certificate.crt的內容.
10295
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
10296
					#必填參數:
10297
					#無.
10298
					#可省略參數:
10299
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 10300
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 10301
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 10302
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 10303
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
10304
					$conf["zerossl::getCert"]["id"]=$csrId;
10305
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
10306
					#$conf["zerossl::getCert"]["cname"]="";
10307
					#參考資料:
10308
					#https://zerossl.com/documentation/api/download-certificate-inline/
10309
					#備註:
10310
					#無.
10311
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
10312
					unset($conf["zerossl::getCert"]);
10313
 
10314
					#如果執行異常
10315
					if($getCert["status"]==="false"){
10316
 
10317
						#設置錯誤識別
10318
						$result["status"]="false";
10319
 
10320
						#設置錯誤訊息
10321
						$result["error"]=$getCert;
10322
 
10323
						#回傳結果
10324
						return $result;
10325
 
10326
						}#if end
281 liveuser 10327
 
10328
					#if enable debug
10329
					if($debug){
10330
 
10331
						#debug msg
291 liveuser 10332
						echo "Getting host ssl for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10333
 
10334
						}#if end
10335
 
255 liveuser 10336
					#zerossl上的certificate.crt內容
10337
					#$getCert["certificate.crt"];
310 liveuser 10338
 
255 liveuser 10339
					#zerossl上的ca_bundle.crt內容
10340
					#$getCert["ca_bundle.crt"];
10341
 
10342
					#certificate.crt and ca_bundle.crt 合併後的檔案內容
10343
					#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
10344
 
10345
					#certificate.crt 檔案
10346
					#$cInfo["certPath"];
10347
 
10348
					#ca_bundle.crt 檔案
10349
					#$cInfo["caPath"];
10350
 
10351
					#certAndCa.crt 檔案
10352
					#$cInfo["certWithCaPath"];
281 liveuser 10353
 
10354
					#if enable debug
10355
					if($debug){
10356
 
10357
						#debug msg
310 liveuser 10358
						echo "Getting host ssl(certificate.crt) which path is ".$cInfo["ssl"]["certPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10359
 
10360
						}#if end
255 liveuser 10361
 
10362
					#取得既有的 certificate.crt 檔案內容
10363
					#函式說明:
10364
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10365
					#回傳的變數說明:
10366
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10367
					#$result["error"],錯誤訊息提示.
10368
					#$result["warning"],警告訊息.
10369
					#$result["function"],當前執行的函數名稱.
10370
					#$result["fileContent"],爲檔案的內容陣列.
10371
					#$result["lineCount"],爲檔案內容總共的行數.
10372
					#$result["fullContent"],為檔案的完整內容.
10373
					#$result["base64dataOnly"],檔案的base64data.
10374
					#$result["base64data"],為在網頁上給予src參數的數值.
10375
					#$result["mimeType"],為檔案的mime type.
10376
					#必填參數:
10377
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10378
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certPath"];
255 liveuser 10379
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10380
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10381
					#可省略參數:
10382
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10383
					#$conf["web"]="true";
10384
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10385
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10386
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10387
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10388
					#參考資料:
10389
					#file(),取得檔案內容的行數.
10390
					#file=>http:#php.net/manual/en/function.file.php
10391
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10392
					#filesize=>http://php.net/manual/en/function.filesize.php
10393
					#參考資料:
10394
					#無.
10395
					#備註:
10396
					#無.
291 liveuser 10397
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10398
					unset($conf["fileAccesss::getFileContent"]);
10399
 
10400
					#如果執行異常
10401
					if($getFileContent["status"]==="false"){
10402
 
10403
						#設置錯誤識別
10404
						$result["status"]="false";
10405
 
10406
						#設置錯誤訊息
10407
						$result["error"]=$getFileContent;
10408
 
10409
						#回傳結果
10410
						return $result;
10411
 
10412
						}#if end
10413
 
281 liveuser 10414
					#if enable debug
10415
					if($debug){
10416
 
10417
						#debug msg
291 liveuser 10418
						echo "Checking host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10419
 
10420
						}#if end
10421
 
291 liveuser 10422
					#預設 certificate.crt 不用更新
10423
					$certificate_need_update="false";
10424
 
255 liveuser 10425
					#如果既有憑證跟剛下載的憑證不一樣
10426
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
10427
 
10428
						#識別要改成下載好的憑證
10429
						$certificate_need_update="true";
281 liveuser 10430
 
10431
						#if enable debug
10432
						if($debug){
10433
 
10434
							#debug msg
291 liveuser 10435
							echo "SSL(certificate.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10436
 
10437
							}#if end
255 liveuser 10438
 
10439
						}#if end
281 liveuser 10440
 
10441
					#if enable debug
10442
					if($debug){
10443
 
10444
						#debug msg
310 liveuser 10445
						echo "Getting host ssl(ca_bundle.crt) which path is ".$cInfo["ssl"]["caPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10446
 
10447
						}#if end
10448
 
255 liveuser 10449
					#取得既有的 ca_bundle.crt 檔案內容
10450
					#函式說明:
10451
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10452
					#回傳的變數說明:
10453
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10454
					#$result["error"],錯誤訊息提示.
10455
					#$result["warning"],警告訊息.
10456
					#$result["function"],當前執行的函數名稱.
10457
					#$result["fileContent"],爲檔案的內容陣列.
10458
					#$result["lineCount"],爲檔案內容總共的行數.
10459
					#$result["fullContent"],為檔案的完整內容.
10460
					#$result["base64dataOnly"],檔案的base64data.
10461
					#$result["base64data"],為在網頁上給予src參數的數值.
10462
					#$result["mimeType"],為檔案的mime type.
10463
					#必填參數:
10464
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10465
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["caPath"];
255 liveuser 10466
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10467
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10468
					#可省略參數:
10469
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10470
					#$conf["web"]="true";
10471
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10472
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10473
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10474
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10475
					#參考資料:
10476
					#file(),取得檔案內容的行數.
10477
					#file=>http:#php.net/manual/en/function.file.php
10478
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10479
					#filesize=>http://php.net/manual/en/function.filesize.php
10480
					#參考資料:
10481
					#無.
10482
					#備註:
10483
					#無.
291 liveuser 10484
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10485
					unset($conf["fileAccesss::getFileContent"]);
10486
 
10487
					#如果執行異常
10488
					if($getFileContent["status"]==="false"){
10489
 
10490
						#設置錯誤識別
10491
						$result["status"]="false";
10492
 
10493
						#設置錯誤訊息
10494
						$result["error"]=$getFileContent;
10495
 
10496
						#回傳結果
10497
						return $result;
10498
 
10499
						}#if end
10500
 
281 liveuser 10501
					#if enable debug
10502
					if($debug){
10503
 
10504
						#debug msg
291 liveuser 10505
						echo "Checking host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10506
 
10507
						}#if end
10508
 
291 liveuser 10509
					#預設 ca_bundle.crt 不用更新
10510
					$ca_bundle_need_update="false";
10511
 
255 liveuser 10512
					#如果既有憑證跟剛下載的憑證不一樣
10513
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
10514
 
10515
						#識別要改成下載好的憑證
10516
						$ca_bundle_need_update="true";
281 liveuser 10517
 
10518
						#if enable debug
10519
						if($debug){
10520
 
10521
							#debug msg
291 liveuser 10522
							echo "SSL(ca_bundle.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10523
 
10524
							}#if end
255 liveuser 10525
 
10526
						}#if end
10527
 
281 liveuser 10528
					#if enable debug
10529
					if($debug){
10530
 
10531
						#debug msg
310 liveuser 10532
						echo "Getting host ssl(cert and ca_bundle) which path is ".$cInfo["ssl"]["certWithCaPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10533
 
10534
						}#if end
10535
 
255 liveuser 10536
					#取得既有的 certWithCa 檔案內容
10537
					#函式說明:
10538
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10539
					#回傳的變數說明:
10540
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10541
					#$result["error"],錯誤訊息提示.
10542
					#$result["warning"],警告訊息.
10543
					#$result["function"],當前執行的函數名稱.
10544
					#$result["fileContent"],爲檔案的內容陣列.
10545
					#$result["lineCount"],爲檔案內容總共的行數.
10546
					#$result["fullContent"],為檔案的完整內容.
10547
					#$result["base64dataOnly"],檔案的base64data.
10548
					#$result["base64data"],為在網頁上給予src參數的數值.
10549
					#$result["mimeType"],為檔案的mime type.
10550
					#必填參數:
10551
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10552
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certWithCaPath"];
255 liveuser 10553
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10554
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10555
					#可省略參數:
10556
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10557
					#$conf["web"]="true";
10558
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10559
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10560
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10561
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10562
					#參考資料:
10563
					#file(),取得檔案內容的行數.
10564
					#file=>http:#php.net/manual/en/function.file.php
10565
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10566
					#filesize=>http://php.net/manual/en/function.filesize.php
10567
					#參考資料:
10568
					#無.
10569
					#備註:
10570
					#無.
291 liveuser 10571
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10572
					unset($conf["fileAccesss::getFileContent"]);
10573
 
10574
					#如果執行異常
10575
					if($getFileContent["status"]==="false"){
10576
 
10577
						#設置錯誤識別
10578
						$result["status"]="false";
10579
 
10580
						#設置錯誤訊息
10581
						$result["error"]=$getFileContent;
10582
 
10583
						#回傳結果
10584
						return $result;
10585
 
10586
						}#if end
10587
 
281 liveuser 10588
					#if enable debug
10589
					if($debug){
10590
 
10591
						#debug msg
291 liveuser 10592
						echo "Checking host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10593
 
10594
						}#if end
10595
 
291 liveuser 10596
					#預設 cert_and_ca_bundle.crt 不用更新
10597
					$cert_and_ca_bundle_need_update="false";
10598
 
255 liveuser 10599
					#如果既有憑證跟剛下載的憑證不一樣
10600
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
10601
 
10602
						#識別要改成下載好的憑證
10603
						$cert_and_ca_bundle_need_update="true";
281 liveuser 10604
 
10605
						#if enable debug
10606
						if($debug){
10607
 
10608
							#debug msg
291 liveuser 10609
							echo "SSL(cert and ca_bundle) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10610
 
10611
							}#if end
255 liveuser 10612
 
10613
						}#if end
10614
 
10615
					#預設不需要執行更新憑證後的動作
10616
					$requireActionAfterUpdateCert="false";
10617
 
10618
					#如果 certificate 需要更新
10619
					if($certificate_need_update==="true"){
10620
 
281 liveuser 10621
						#if enable debug
10622
						if($debug){
10623
 
10624
							#debug msg
291 liveuser 10625
							echo "Updating host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10626
 
10627
							}#if end
10628
 
255 liveuser 10629
						#更新之
10630
						#函式說明:
10631
						#一次建立多個檔案,並寫入內容.
10632
						#回傳結果:
10633
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10634
						#$result["error"],錯誤訊息陣列.
10635
						#$result["function"],當前執行的函數名稱.
10636
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10637
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10638
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10639
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10640
						#$result["argu"],使用的參數.
10641
						#必填參數:
10642
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10643
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10644
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10645
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"]);
255 liveuser 10646
						#可省略參數:
10647
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10648
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
10649
						#參考資料:
10650
						#無.
10651
						#備註:
10652
						#無.
291 liveuser 10653
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10654
						unset($conf["zerossl::writeMultiFile"]);
10655
 
10656
						#如果執行異常
10657
						if($writeMultiFile["status"]==="false"){
10658
 
10659
							#設置錯誤識別
10660
							$result["status"]="false";
10661
 
10662
							#設置錯誤訊息
10663
							$result["error"]=$writeMultiFile;
10664
 
10665
							#回傳結果
10666
							return $result;
10667
 
10668
							}#if end
293 liveuser 10669
 
10670
						#設置需要執行指令來生效憑證
10671
						$requireActionAfterUpdateCert="true";
255 liveuser 10672
 
10673
						}#if end
10674
 
10675
					#如果 ca_bunle 需要更新
10676
					if($ca_bundle_need_update==="true"){
10677
 
281 liveuser 10678
						#if enable debug
10679
						if($debug){
10680
 
10681
							#debug msg
291 liveuser 10682
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10683
 
10684
							}#if end
293 liveuser 10685
 
10686
						#設置需要執行指令來生效憑證
10687
						$requireActionAfterUpdateCert="true";
281 liveuser 10688
 
255 liveuser 10689
						#更新之
10690
						#函式說明:
10691
						#一次建立多個檔案,並寫入內容.
10692
						#回傳結果:
10693
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10694
						#$result["error"],錯誤訊息陣列.
10695
						#$result["function"],當前執行的函數名稱.
10696
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10697
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10698
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10699
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10700
						#$result["argu"],使用的參數.
10701
						#必填參數:
10702
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10703
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10704
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10705
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["caPath"]);
255 liveuser 10706
						#可省略參數:
10707
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10708
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
10709
						#參考資料:
10710
						#無.
10711
						#備註:
10712
						#無.
291 liveuser 10713
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10714
						unset($conf["zerossl::writeMultiFile"]);
10715
 
10716
						#如果執行異常
10717
						if($writeMultiFile["status"]==="false"){
10718
 
10719
							#設置錯誤識別
10720
							$result["status"]="false";
10721
 
10722
							#設置錯誤訊息
10723
							$result["error"]=$writeMultiFile;
10724
 
10725
							#回傳結果
10726
							return $result;
10727
 
10728
							}#if end
293 liveuser 10729
 
10730
						#設置需要執行指令來生效憑證
10731
						$requireActionAfterUpdateCert="true";
255 liveuser 10732
 
10733
						}#if end
10734
 
10735
					#如果 certificate and ca_bundle 需要更新
10736
					if($cert_and_ca_bundle_need_update==="true"){
10737
 
281 liveuser 10738
						#if enable debug
10739
						if($debug){
10740
 
10741
							#debug msg
291 liveuser 10742
							echo "Updating host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10743
 
10744
							}#if end
10745
 
255 liveuser 10746
						#更新之
10747
						#函式說明:
10748
						#一次建立多個檔案,並寫入內容.
10749
						#回傳結果:
10750
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10751
						#$result["error"],錯誤訊息陣列.
10752
						#$result["function"],當前執行的函數名稱.
10753
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10754
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10755
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10756
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10757
						#$result["argu"],使用的參數.
10758
						#必填參數:
10759
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10760
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10761
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10762
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certWithCaPath"]);
255 liveuser 10763
						#可省略參數:
10764
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10765
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
10766
						#參考資料:
10767
						#無.
10768
						#備註:
10769
						#無.
291 liveuser 10770
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10771
						unset($conf["zerossl::writeMultiFile"]);
10772
 
10773
						#如果執行異常
10774
						if($writeMultiFile["status"]==="false"){
10775
 
10776
							#設置錯誤識別
10777
							$result["status"]="false";
10778
 
10779
							#設置錯誤訊息
10780
							$result["error"]=$writeMultiFile;
10781
 
10782
							#回傳結果
10783
							return $result;
10784
 
10785
							}#if end
10786
 
293 liveuser 10787
						#設置需要執行指令來生效憑證
10788
						$requireActionAfterUpdateCert="true";
10789
 
255 liveuser 10790
						}#if end
10791
 
10792
					#如果有需要執行指令來生效憑證
10793
					if($requireActionAfterUpdateCert==="true"){
10794
 
281 liveuser 10795
						#if enable debug
10796
						if($debug){
10797
 
10798
							#debug msg
291 liveuser 10799
							echo "Action required to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 10800
 
10801
							}#if end
10802
 
255 liveuser 10803
						#儲存 actionAfterUpdateCert
10804
						$action=$cInfo["actionAfterUpdateCert"];
10805
 
10806
						#如果有多個指令要執行
310 liveuser 10807
						if(count($action)>0){
255 liveuser 10808
 
281 liveuser 10809
							#if enable debug
10810
							if($debug){
10811
 
10812
								#debug msg
291 liveuser 10813
								echo "There are many cmds to run to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 10814
 
10815
								}#if end
10816
 
255 liveuser 10817
							#針對每的指令
10818
							foreach($action as $ac){
10819
 
281 liveuser 10820
								#if enable debug
10821
								if($debug){
10822
 
10823
									#debug msg
10824
									echo ".".PHP_EOL;
10825
 
10826
									}#if end
293 liveuser 10827
 
10828
								#函式說明:
255 liveuser 10829
								#呼叫shell執行系統命令,並取得回傳的內容.
10830
								#回傳結果:
10831
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10832
								#$result["error"],錯誤訊息陣列.
10833
								#$result["function"],當前執行的函數名稱.
10834
								#$result["argu"],使用的參數.
10835
								#$result["cmd"],執行的指令內容.
10836
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10837
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10838
								#$result["content"],為執行完後的輸出字串.
10839
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10840
								#$result["running"],是否還在執行.
10841
								#$result["pid"],pid.
10842
								#$result["statusCode"],執行結束後的代碼.
10843
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10844
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10845
								#必填參數:
10846
								#$conf["command"],字串,要執行的指令.
302 liveuser 10847
								$conf["external::callShell"]["command"]=$ac;
255 liveuser 10848
								#$conf["fileArgu"],字串,變數__FILE__的內容.
10849
								$conf["external::callShell"]["fileArgu"]=__FILE__;
10850
								#可省略參數:
10851
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10852
								#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
255 liveuser 10853
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10854
								#$conf["arguIsAddr"]=array();
10855
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10856
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10857
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10858
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10859
								#$conf["enablePrintDescription"]="true";
10860
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10861
								#$conf["printDescription"]="";
10862
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10863
								$conf["external::callShell"]["escapeshellarg"]="true";
10864
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10865
								#$conf["thereIsShellVar"]=array();
10866
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10867
								#$conf["username"]="";
10868
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10869
								#$conf["password"]="";
10870
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10871
								#$conf["useScript"]="";
10872
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10873
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10874
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10875
								#$conf["inBackGround"]="";
10876
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10877
								#$conf["getErr"]="false";
10878
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10879
								#$conf["doNotRun"]="false";
302 liveuser 10880
								#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10881
								$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10882
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10883
								#$conf["remoteIp"]="";
10884
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10885
								#$conf["remoteUser"]="";
10886
								#參考資料:
10887
								#exec=>http://php.net/manual/en/function.exec.php
10888
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10889
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10890
								#備註:
10891
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10892
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10893
								$callShell=external::callShell($conf["external::callShell"]);
10894
								unset($conf["external::callShell"]);
10895
 
10896
								#如果執行異常
310 liveuser 10897
								if($callShell["status"]==="false"){
255 liveuser 10898
 
10899
									#設置錯誤識別
10900
									$result["status"]="false";
10901
 
10902
									#設置錯誤訊息
10903
									$result["error"]=$callShell;
10904
 
10905
									#回傳結果
10906
									return $result;
10907
 
10908
									}#if end
10909
 
10910
								}#foreach end
10911
 
10912
							}#if end
10913
 
291 liveuser 10914
						#反之
10915
						else{
10916
 
10917
							#if enable debug
10918
							if($debug){
10919
 
10920
								#debug msg
10921
								echo "There is only one cmd to run to apply ssl for domain name(".$cName.")".PHP_EOL;
255 liveuser 10922
 
291 liveuser 10923
								}#if end
281 liveuser 10924
 
291 liveuser 10925
							#函式說明:
10926
							#呼叫shell執行系統命令,並取得回傳的內容.
10927
							#回傳結果:
10928
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10929
							#$result["error"],錯誤訊息陣列.
10930
							#$result["function"],當前執行的函數名稱.
10931
							#$result["argu"],使用的參數.
10932
							#$result["cmd"],執行的指令內容.
10933
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10934
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10935
							#$result["content"],為執行完後的輸出字串.
10936
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10937
							#$result["running"],是否還在執行.
10938
							#$result["pid"],pid.
10939
							#$result["statusCode"],執行結束後的代碼.
10940
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10941
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10942
							#必填參數:
10943
							#$conf["command"],字串,要執行的指令.
302 liveuser 10944
							$conf["external::callShell"]["command"]=$action;
291 liveuser 10945
							#$conf["fileArgu"],字串,變數__FILE__的內容.
10946
							$conf["external::callShell"]["fileArgu"]=__FILE__;
10947
							#可省略參數:
10948
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10949
							#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
291 liveuser 10950
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10951
							#$conf["arguIsAddr"]=array();
10952
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10953
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10954
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10955
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10956
							#$conf["enablePrintDescription"]="true";
10957
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10958
							#$conf["printDescription"]="";
10959
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10960
							$conf["external::callShell"]["escapeshellarg"]="true";
10961
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10962
							#$conf["thereIsShellVar"]=array();
10963
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10964
							#$conf["username"]="";
10965
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10966
							#$conf["password"]="";
10967
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10968
							#$conf["useScript"]="";
10969
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10970
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10971
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10972
							#$conf["inBackGround"]="";
10973
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10974
							#$conf["getErr"]="false";
10975
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10976
							#$conf["doNotRun"]="false";
302 liveuser 10977
							#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10978
							$conf["external::callShell"]["cmdContainArgu"]="true";
291 liveuser 10979
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10980
							#$conf["remoteIp"]="";
10981
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10982
							#$conf["remoteUser"]="";
10983
							#參考資料:
10984
							#exec=>http://php.net/manual/en/function.exec.php
10985
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10986
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10987
							#備註:
10988
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10989
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10990
							$callShell=external::callShell($conf["external::callShell"]);
10991
							unset($conf["external::callShell"]);
10992
 
10993
							#如果執行異常
310 liveuser 10994
							if($callShell["status"]==="false"){
255 liveuser 10995
 
291 liveuser 10996
								#設置錯誤識別
10997
								$result["status"]="false";
255 liveuser 10998
 
291 liveuser 10999
								#設置錯誤訊息
11000
								$result["error"]=$callShell;
255 liveuser 11001
 
291 liveuser 11002
								#回傳結果
11003
								return $result;
255 liveuser 11004
 
291 liveuser 11005
								}#if end
11006
 
11007
							}#else end
11008
 
11009
						}#if end
255 liveuser 11010
 
11011
					}#else end
11012
 
11013
				}#else end
291 liveuser 11014
 
255 liveuser 11015
			}#foreach end
11016
 
11017
		}#function sslUpdater_idle end
11018
 
226 liveuser 11019
	}#class zerossl end
255 liveuser 11020