Subversion Repositories php-qbpwcf

Rev

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
 
406 liveuser 2592
			#如果type不為 CNAME 跟 TXT 跟 SOA 跟 CAA
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
				#SOA 範例
2668
				#@	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
2669
 
2670
				#再度嘗試分割
2671
				#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
2672
 
2673
				#函式說明:
2674
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2675
				#回傳結果:
2676
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2677
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2678
				#$result["function"],當前執行的函式名稱.
2679
				#$result["argu"],所使用的參數.
2680
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2681
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2682
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2683
				#必填參數:
2684
				#$conf["input"],字串,要檢查的字串.
2685
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2686
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2687
				$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
2688
				#可省略參數:
2689
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2690
				#$conf["varEqual"]=array(null,"found");
2691
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2692
				#$conf["varCon"]=array("no_tail"=>" not");
2693
				#參考資料:
2694
				#無.
2695
				#備註:
2696
				#無.
2697
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2698
				unset($conf["search::findSpecifyStrFormat"]);
2699
 
2700
				#如果執行異常
2701
				if($findSpecifyStrFormat["status"]==="false"){
2702
 
2703
					#設置錯誤識別
2704
					$result["status"]="false";
2705
 
2706
					#設置錯誤訊息
2707
					$result["error"]=$findSpecifyStrFormat;
2708
 
2709
					#回傳結果
2710
					return $result;
2711
 
2712
					}#if end
2713
 
2714
				#如果存在"("
2715
				if($findSpecifyStrFormat["found"]==="true"){
2716
 
2717
					#取得無"("的內容
2718
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2719
 
2720
					#取得拆下來的含開頭"("內容
2721
					$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
2722
 
2723
					}#if end
2724
 
2725
				#反之
2726
				else{
2727
 
2728
					#函式說明:
2729
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2730
					#回傳結果:
2731
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2732
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2733
					#$result["function"],當前執行的函式名稱.
2734
					#$result["argu"],所使用的參數.
2735
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2736
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2737
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2738
					#必填參數:
2739
					#$conf["input"],字串,要檢查的字串.
2740
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2741
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2742
					$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
2743
					#可省略參數:
2744
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2745
					#$conf["varEqual"]=array(null,"found");
2746
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2747
					#$conf["varCon"]=array("no_tail"=>" not");
2748
					#參考資料:
2749
					#無.
2750
					#備註:
2751
					#無.
2752
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2753
					unset($conf["search::findSpecifyStrFormat"]);
2754
 
2755
					#如果執行異常
2756
					if($findSpecifyStrFormat["status"]==="false"){
2757
 
2758
						#設置錯誤識別
2759
						$result["status"]="false";
2760
 
2761
						#設置錯誤訊息
2762
						$result["error"]=$findSpecifyStrFormat;
2763
 
2764
						#回傳結果
2765
						return $result;
2766
 
2767
						}#if end
2768
 
2769
					#如果存在"
2770
					if($findSpecifyStrFormat["found"]==="true"){
2771
 
2772
						#取得無"的內容
2773
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2774
 
2775
						#取得拆下來的含開頭"內容
2776
						$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
2777
 
2778
						}#if end
2779
 
2780
					#反之
2781
					else{
2782
 
2783
						#函式說明:
2784
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2785
						#回傳結果:
2786
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2787
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
2788
						#$result["function"],當前執行的函式名稱.
2789
						#$result["argu"],所使用的參數.
2790
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2791
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2792
						#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2793
						#必填參數:
2794
						#$conf["input"],字串,要檢查的字串.
2795
						$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2796
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2797
						$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
2798
						#可省略參數:
2799
						#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2800
						#$conf["varEqual"]=array(null,"found");
2801
						#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2802
						#$conf["varCon"]=array("no_tail"=>" not");
2803
						#參考資料:
2804
						#無.
2805
						#備註:
2806
						#無.
2807
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2808
						unset($conf["search::findSpecifyStrFormat"]);
2809
 
2810
						#如果執行異常
2811
						if($findSpecifyStrFormat["status"]==="false"){
2812
 
2813
							#設置錯誤識別
2814
							$result["status"]="false";
2815
 
2816
							#設置錯誤訊息
2817
							$result["error"]=$findSpecifyStrFormat;
2818
 
2819
							#回傳結果
2820
							return $result;
2821
 
2822
							}#if end
2823
 
2824
						#如果存在";"
2825
						if($findSpecifyStrFormat["found"]==="true"){
2826
 
2827
							#取得無";"的內容
2828
							$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2829
 
2830
							#取得拆下來的含開頭";"內容
2831
							$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
2832
 
2833
							}#if end
2834
 
2835
						}#else end
2836
 
2837
					}#else end
2838
 
2839
				#取得 serial number
2840
				#函式說明:
2841
				#將字串進行解析,變成多個參數.
2842
				#回傳結果:
2843
				#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2844
				#$result["function"],當前執行的函式內容.
2845
				#$result["error"],錯誤訊息陣列.
2846
				#$result["content"],參數陣列.
2847
				#$result["count"],總共有幾個參數.
2848
				#必填參數:
2849
				#$conf["input"],字串,要解析成參數的字串.
2850
				$conf["stringProcess::parse"]["input"]=$unFormatStr;
2851
				#可省略參數:
2852
				#無.
2853
				#參考資料:
2854
				#無.
2855
				#備註:
2856
				#無.
2857
				$parse=stringProcess::parse($conf["stringProcess::parse"]);
2858
				unset($conf["stringProcess::parse"]);
2859
 
2860
				#如果執行異常
2861
				if($parse["status"]==="false"){
2862
 
2863
					#設置錯誤識別
2864
					$result["status"]="false";
2865
 
2866
					#設置錯誤訊息
2867
					$result["error"]=$parse;
2868
 
2869
					#回傳結果
2870
					return $result;
2871
 
2872
					}#if end
2873
 
2874
				#取得serial number
2875
				$serialNo=$parse["content"][2];
2876
 
2877
				#serialNo+1
2878
				$serialNo++;
2879
 
2880
				#回存
2881
				$parse["content"][2]=(string)$serialNo;
2882
 
2883
				#函式說明:
2884
				#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
2885
				#回傳的結果:
2886
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2887
				#$result["function"],當前執行的function名稱
2888
				#$result["error"],錯誤訊息陣列.
2889
				#$result["content"],處理好的字串.
2890
				#$result["argu"],使用的參數.
2891
				#必填參數:
2892
				#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
2893
				$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
2894
				#可省略參數:
2895
				#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
2896
				$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
2897
				#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
2898
				$conf["arrays::arrayToString"]["skipEnd"]="true";
2899
				#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
2900
				#$conf["spiltSymbolAtStart"]="";
2901
				#參考資料:
2902
				#無.
2903
				#備註:
2904
				#無.
2905
				$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
2906
				unset($conf["arrays::arrayToString"]);
2907
 
2908
				#如果執行異常
2909
				if($arrayToString["status"]==="false"){
2910
 
2911
					#設置錯誤識別
2912
					$result["status"]="false";
2913
 
2914
					#設置錯誤訊息
2915
					$result["error"]=$arrayToString;
2916
 
2917
					#回傳結果
2918
					return $result;
2919
 
2920
					}#if end
2921
 
2922
				#取得更新 serial number 後的 SOA value string
2923
				$unFormatStr=$arrayToString["content"];
2924
 
2925
				#如果有要合併回去的內容
2926
				if(isset($unFormatStr2add)){
2927
 
2928
					#合併回去內容
2929
					$unFormatStr=$unFormatStr.$unFormatStr2add;
2930
 
2931
					#移除用不到的變數
2932
					unset($unFormatStr2add);
2933
 
2934
					}#if end
2935
 
2936
				#假設剩下的沒有註解都是 value
2937
				$info["value"]=$unFormatStr;
2938
 
2939
				#函式說明:
2940
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2941
				#回傳結果:
2942
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2943
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2944
				#$result["function"],當前執行的函式名稱.
2945
				#$result["argu"],所使用的參數.
2946
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2947
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2948
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2949
				#必填參數:
2950
				#$conf["input"],字串,要檢查的字串.
2951
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2952
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2953
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
2954
				#可省略參數:
2955
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2956
				#$conf["varEqual"]=array(null,"found");
2957
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2958
				#$conf["varCon"]=array("no_tail"=>" not");
2959
				#參考資料:
2960
				#無.
2961
				#備註:
2962
				#無.
2963
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2964
				unset($conf["search::findSpecifyStrFormat"]);
2965
 
2966
				#如果執行異常
2967
				if($findSpecifyStrFormat["status"]==="false"){
2968
 
2969
					#設置錯誤識別
2970
					$result["status"]="false";
2971
 
2972
					#設置錯誤訊息
2973
					$result["error"]=$findSpecifyStrFormat;
2974
 
2975
					#回傳結果
2976
					return $result;
2977
 
2978
					}#if end
2979
 
2980
				#如果有符合格式
2981
				if($findSpecifyStrFormat["found"]==="true"){
2982
 
2983
					#儲存 value
2984
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
2985
 
2986
					#儲存 comment
2987
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
2988
 
2989
					}#if end
2990
 
2991
				#儲存 RR 的記錄
2992
				$result["content"]=$info;
2993
 
2994
				#設置執行正常
2995
				$result["status"]="true";
2996
 
2997
				#回傳結果
2998
				return $result;
2999
 
3000
				}#if end
3001
 
3002
			#執行到這邊代表不是 SOA
3003
 
404 liveuser 3004
			#如果是 CAA
406 liveuser 3005
			if($info["type"]==="CAA"){
404 liveuser 3006
 
3007
				#判斷內容是否為合法的 CAA value
3008
				#0 issue ";";comment
3009
				#0 issue "domain.name";comment
3010
				#函式說明:
3011
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3012
				#回傳結果:
3013
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3014
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3015
				#$result["function"],當前執行的函式名稱.
3016
				#$result["argu"],所使用的參數.
3017
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3018
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3019
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3020
				#必填參數:
3021
				#$conf["input"],字串,要檢查的字串.
3022
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3023
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3024
				$conf["search::findSpecifyStrFormat"]["format"]="0 issue \"\${domain}\";\${comment}";
3025
				#可省略參數:
3026
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3027
				#$conf["varEqual"]=array(null,"found");
3028
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3029
				#$conf["varCon"]=array("no_tail"=>" not");
3030
				#參考資料:
3031
				#無.
3032
				#備註:
3033
				#無.
3034
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3035
				unset($conf["search::findSpecifyStrFormat"]);
3036
 
3037
				#如果執行異常
3038
				if($findSpecifyStrFormat["status"]==="false"){
3039
 
3040
					#設置錯誤識別
3041
					$result["status"]="false";
3042
 
3043
					#設置錯誤訊息
3044
					$result["error"]=$findSpecifyStrFormat;
3045
 
3046
					#回傳結果
3047
					return $result;
3048
 
3049
					}#if end
3050
 
3051
				#如果有 有符合 "0 issue \"\${domain}\";\${comment}" 的格式
3052
				if($findSpecifyStrFormat["found"]==="true"){
3053
 
3054
					#儲存value
3055
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3056
 
3057
					#儲存comment
3058
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3059
 
3060
					#儲存 RR 的記錄
3061
					$result["content"]=$info;
3062
 
3063
					#設置執行正常
3064
					$result["status"]="true";
3065
 
3066
					#回傳結果
3067
					return $result;
3068
 
3069
					}#if end
406 liveuser 3070
 
404 liveuser 3071
				#判斷內容是否為合法的 CAA value
3072
				#0 issue ";"
3073
				#0 issue "domain.name"
3074
				#函式說明:
3075
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3076
				#回傳結果:
3077
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3078
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3079
				#$result["function"],當前執行的函式名稱.
3080
				#$result["argu"],所使用的參數.
3081
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3082
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3083
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3084
				#必填參數:
3085
				#$conf["input"],字串,要檢查的字串.
3086
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3087
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3088
				$conf["search::findSpecifyStrFormat"]["format"]="0 issue \"\${domain}\"";
3089
				#可省略參數:
3090
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3091
				#$conf["varEqual"]=array(null,"found");
3092
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3093
				#$conf["varCon"]=array("no_tail"=>" not");
3094
				#參考資料:
3095
				#無.
3096
				#備註:
3097
				#無.
3098
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3099
				unset($conf["search::findSpecifyStrFormat"]);
3100
 
3101
				#如果執行異常
3102
				if($findSpecifyStrFormat["status"]==="false"){
3103
 
3104
					#設置錯誤識別
3105
					$result["status"]="false";
3106
 
3107
					#設置錯誤訊息
3108
					$result["error"]=$findSpecifyStrFormat;
3109
 
3110
					#回傳結果
3111
					return $result;
3112
 
3113
					}#if end
3114
 
3115
				#如果有 有符合 "0 issue \"\${domain}\"" 的格式
3116
				if($findSpecifyStrFormat["found"]==="true"){
3117
 
3118
					#儲存value
406 liveuser 3119
					$info["value"]=$unFormatStr;
404 liveuser 3120
 
3121
					#儲存 RR 的記錄
3122
					$result["content"]=$info;
3123
 
3124
					#設置執行正常
3125
					$result["status"]="true";
3126
 
3127
					#回傳結果
3128
					return $result;
3129
 
3130
					}#if end
3131
 
3132
				}#if end
3133
 
3134
			#執行到這邊代表不是 CAA
3135
 
291 liveuser 3136
			#尋找是否有(...)...的內容存在
3137
			#函式說明:
3138
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3139
			#回傳結果:
3140
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3141
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3142
			#$result["function"],當前執行的函式名稱.
3143
			#$result["argu"],所使用的參數.
3144
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3145
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3146
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3147
			#必填參數:
3148
			#$conf["input"],字串,要檢查的字串.
3149
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3150
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3151
			$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
3152
			#可省略參數:
3153
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3154
			#$conf["varEqual"]=array(null,"found");
3155
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3156
			#$conf["varCon"]=array("no_tail"=>" not");
3157
			#參考資料:
3158
			#無.
3159
			#備註:
3160
			#無.
3161
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3162
			unset($conf["search::findSpecifyStrFormat"]);
3163
 
3164
			#如果執行異常
3165
			if($findSpecifyStrFormat["status"]==="false"){
3166
 
3167
				#設置錯誤識別
3168
				$result["status"]="false";
3169
 
3170
				#設置錯誤訊息
3171
				$result["error"]=$findSpecifyStrFormat;
3172
 
3173
				#回傳結果
3174
				return $result;
3175
 
3176
				}#if end
3177
 
3178
			#如果有 有符合 ($value);${comment} 的格式
3179
			if($findSpecifyStrFormat["found"]==="true"){
3180
 
3181
				#儲存value
3182
				$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
3183
 
3184
				#儲存comment
3185
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3186
 
3187
				#儲存 RR 的記錄
3188
				$result["content"]=$info;
3189
 
3190
				#設置執行正常
3191
				$result["status"]="true";
3192
 
3193
				#回傳結果
3194
				return $result;
3195
 
3196
				}#if end
3197
 
3198
			#執行到這邊代表沒有 (...)... 的內容存在
3199
 
3200
			#尋找是否有 (...) 的內容存在
3201
			#函式說明:
3202
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3203
			#回傳結果:
3204
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3205
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3206
			#$result["function"],當前執行的函式名稱.
3207
			#$result["argu"],所使用的參數.
3208
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3209
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3210
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3211
			#必填參數:
3212
			#$conf["input"],字串,要檢查的字串.
3213
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3214
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3215
			$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
3216
			#可省略參數:
3217
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3218
			#$conf["varEqual"]=array(null,"found");
3219
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3220
			#$conf["varCon"]=array("no_tail"=>" not");
3221
			#參考資料:
3222
			#無.
3223
			#備註:
3224
			#無.
3225
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3226
			unset($conf["search::findSpecifyStrFormat"]);
3227
 
3228
			#如果執行異常
3229
			if($findSpecifyStrFormat["status"]==="false"){
3230
 
3231
				#設置錯誤識別
3232
				$result["status"]="false";
3233
 
3234
				#設置錯誤訊息
3235
				$result["error"]=$findSpecifyStrFormat;
3236
 
3237
				#回傳結果
3238
				return $result;
3239
 
3240
				}#if end
3241
 
3242
			#如果有 有符合 ($value);${comment} 的格式
3243
			if($findSpecifyStrFormat["found"]==="true"){
3244
 
3245
				#儲存value
3246
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3247
 
3248
				#儲存 RR 的記錄
3249
				$result["content"]=$info;
3250
 
3251
				#設置執行正常
3252
				$result["status"]="true";
3253
 
3254
				#回傳結果
3255
				return $result;
3256
 
3257
				}#if end
3258
 
3259
			#執行到這邊代表沒有 (...) 的內容存在
3260
 
3261
			#尋找有無 "...";... 的內容存在
3262
			#函式說明:
3263
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3264
			#回傳結果:
3265
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3266
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3267
			#$result["function"],當前執行的函式名稱.
3268
			#$result["argu"],所使用的參數.
3269
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3270
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3271
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3272
			#必填參數:
3273
			#$conf["input"],字串,要檢查的字串.
3274
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3275
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3276
			$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
3277
			#可省略參數:
3278
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3279
			#$conf["varEqual"]=array(null,"found");
3280
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3281
			#$conf["varCon"]=array("no_tail"=>" not");
3282
			#參考資料:
3283
			#無.
3284
			#備註:
3285
			#無.
3286
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3287
			unset($conf["search::findSpecifyStrFormat"]);
3288
 
3289
			#如果執行異常
3290
			if($findSpecifyStrFormat["status"]==="false"){
3291
 
3292
				#設置錯誤識別
3293
				$result["status"]="false";
3294
 
3295
				#設置錯誤訊息
3296
				$result["error"]=$findSpecifyStrFormat;
3297
 
3298
				#回傳結果
3299
				return $result;
3300
 
3301
				}#if end
3302
 
3303
			#如果有 有符合 "$value";${comment} 的格式
3304
			if($findSpecifyStrFormat["found"]==="true"){
3305
 
3306
				#儲存value
3307
				$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
3308
 
3309
				#儲存comment
3310
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3311
 
3312
				#儲存 RR 的記錄
3313
				$result["content"]=$info;
3314
 
3315
				#設置執行正常
3316
				$result["status"]="true";
3317
 
3318
				#回傳結果
3319
				return $result;
3320
 
3321
				}#if end
3322
 
3323
			#執行到這邊代表沒有 "$value";${comment} 的格式
3324
 
3325
			#尋找有無 "..." 的內容存在
3326
			#函式說明:
3327
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3328
			#回傳結果:
3329
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3330
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3331
			#$result["function"],當前執行的函式名稱.
3332
			#$result["argu"],所使用的參數.
3333
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3334
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3335
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3336
			#必填參數:
3337
			#$conf["input"],字串,要檢查的字串.
3338
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3339
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3340
			$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
3341
			#可省略參數:
3342
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3343
			#$conf["varEqual"]=array(null,"found");
3344
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3345
			#$conf["varCon"]=array("no_tail"=>" not");
3346
			#參考資料:
3347
			#無.
3348
			#備註:
3349
			#無.
3350
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3351
			unset($conf["search::findSpecifyStrFormat"]);
3352
 
3353
			#如果執行異常
3354
			if($findSpecifyStrFormat["status"]==="false"){
3355
 
3356
				#設置錯誤識別
3357
				$result["status"]="false";
3358
 
3359
				#設置錯誤訊息
3360
				$result["error"]=$findSpecifyStrFormat;
3361
 
3362
				#回傳結果
3363
				return $result;
3364
 
3365
				}#if end
3366
 
3367
			#如果有 有符合 "$value" 的格式
3368
			if($findSpecifyStrFormat["found"]==="true"){
3369
 
3370
				#儲存value
3371
				$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
3372
 
3373
				#儲存 RR 的記錄
3374
				$result["content"]=$info;
3375
 
3376
				#設置執行正常
3377
				$result["status"]="true";
3378
 
3379
				#回傳結果
3380
				return $result;
3381
 
3382
				}#if end
3383
 
3384
			#執行到這邊代表沒有 "$value" 格式的內容
3385
 
3386
			#檢查是否有 $value;$comment 格式的內容
3387
			#函式說明:
3388
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3389
			#回傳結果:
3390
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3391
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3392
			#$result["function"],當前執行的函式名稱.
3393
			#$result["argu"],所使用的參數.
3394
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3395
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3396
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3397
			#必填參數:
3398
			#$conf["input"],字串,要檢查的字串.
3399
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3400
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3401
			$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3402
			#可省略參數:
3403
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3404
			#$conf["varEqual"]=array(null,"found");
3405
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3406
			#$conf["varCon"]=array("no_tail"=>" not");
3407
			#參考資料:
3408
			#無.
3409
			#備註:
3410
			#無.
3411
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3412
			unset($conf["search::findSpecifyStrFormat"]);
3413
 
3414
			#如果執行異常
3415
			if($findSpecifyStrFormat["status"]==="false"){
3416
 
3417
				#設置錯誤識別
3418
				$result["status"]="false";
3419
 
3420
				#設置錯誤訊息
3421
				$result["error"]=$findSpecifyStrFormat;
3422
 
3423
				#回傳結果
3424
				return $result;
3425
 
3426
				}#if end
3427
 
3428
			#如果有 有符合 "$value" 的格式
3429
			if($findSpecifyStrFormat["found"]==="true"){
3430
 
3431
				#儲存value
3432
				$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3433
 
3434
				#儲存comment
3435
				$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3436
 
3437
				#儲存 RR 的記錄
3438
				$result["content"]=$info;
3439
 
3440
				#設置執行正常
3441
				$result["status"]="true";
3442
 
3443
				#回傳結果
3444
				return $result;
3445
 
3446
				}#if end
3447
 
3448
			#執行到這邊代表沒有 ${value};${comment} 格式的內容
3449
 
3450
			#亦即剩下的內容都是 value
3451
 
3452
			#儲存value
3453
			$info["value"]=$unFormatStr;
3454
 
3455
			#儲存 RR 的記錄
3456
			$result["content"]=$info;
3457
 
3458
			#設置執行正常
3459
			$result["status"]="true";
3460
 
3461
			#回傳結果
3462
			return $result;
3463
 
3464
			}#while end
3465
 
3466
		}#function parseRRline end
3467
 
3468
	/*
3469
	#函式說明:
249 liveuser 3470
	#新增DNS記錄到檔案裡面.
3471
	#回傳結果:
3472
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3473
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
3474
	#$result["function"],當前執行的函式名稱.
3475
	#$result["argu"],所使用的參數.
3476
	#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
255 liveuser 3477
	#$result["domain"],字串,RR所屬domain.
3478
	#$result["defaultTTL"],字串,預設的RR更新時間.
249 liveuser 3479
	#$result["comment"],字串陣列,逐行的註解.
3480
	#必填參數:
255 liveuser 3481
	#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型(支援的有"A","TXT","CNAME","SOA","$TTL","$ORIGIN")、答案、註解.
249 liveuser 3482
	$conf["add"]=array();
3483
	#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
3484
	$conf["dnsRecordFile"]="";
3485
	#可省略參數:
3486
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
3487
	#$conf["writeNow"]="false";
253 liveuser 3488
	#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
3489
	#$conf["debug"]="false";
293 liveuser 3490
	#$conf["multiThreads"],字串,是否啟動多執行序加快執行速度,預設為"false"代表不要;反之為"true"代表要.
3491
	#$conf["multiThreads"]="false";
249 liveuser 3492
	#參考資料:
3493
	#無.
3494
	#備註:
3495
	#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
291 liveuser 3496
	#本套件是透過sshfs掛載來存取RR(dns記錄檔案),其檔案建議的擁有者權限為 root:qbpwcf,權限代碼為 774.
249 liveuser 3497
	#php-pear上的Net_DNS2也可以解析RR.
293 liveuser 3498
	#參數 multiThreads 目前有 bug.
249 liveuser 3499
	*/
3500
	public static function updateDnsRecordFile(&$conf){
3501
 
3502
		#初始化要回傳的結果
3503
		$result=array();
3504
 
3505
		#設置當其函數名稱
3506
		$result["function"]=__FUNCTION__;
3507
 
3508
		#如果 $conf 不為陣列
3509
		if(gettype($conf)!="array"){
3510
 
3511
			#設置執行失敗
3512
			$result["status"]="false";
3513
 
3514
			#設置執行錯誤訊息
3515
			$result["error"][]="\$conf變數須為陣列形態";
3516
 
3517
			#如果傳入的參數為 null
3518
			if($conf==null){
3519
 
3520
				#設置執行錯誤訊息
3521
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3522
 
3523
				}#if end
3524
 
3525
			#回傳結果
3526
			return $result;
3527
 
3528
			}#if end
3529
 
3530
		#取得參數
3531
		$result["argu"]=$conf;
3532
 
3533
		#檢查參數
3534
		#函式說明:
3535
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3536
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3537
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3538
		#$result["function"],當前執行的函式名稱.
3539
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3540
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3541
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3542
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
3543
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
3544
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3545
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3546
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3547
		#必填寫的參數:
3548
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3549
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3550
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3551
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("add","dnsRecordFile");
3552
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3553
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
3554
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3555
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3556
		#可以省略的參數:
3557
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3558
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3559
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
3560
		#$conf["skipableVariableCanNotBeEmpty"]=array();
3561
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 3562
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThreads");
249 liveuser 3563
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
291 liveuser 3564
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
249 liveuser 3565
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
291 liveuser 3566
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
249 liveuser 3567
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3568
		#$conf["arrayCountEqualCheck"][]=array();
3569
		#參考資料來源:
3570
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3571
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3572
		unset($conf["variableCheck::checkArguments"]);
3573
 
3574
		#如果檢查失敗
3575
		if($checkArguments["status"]==="false"){
3576
 
3577
			#設置錯誤識別
3578
			$result["status"]="false";
3579
 
3580
			#設置錯誤訊息
3581
			$result["error"]=$checkArguments;
3582
 
3583
			#回傳結果
3584
			return $result;
3585
 
3586
			}#if end
3587
 
3588
		#如果檢查不通過
3589
		if($checkArguments["passed"]==="false"){
3590
 
3591
			#設置錯誤識別
3592
			$result["status"]="false";
3593
 
3594
			#設置錯誤訊息
3595
			$result["error"]=$checkArguments;
3596
 
3597
			#回傳結果
3598
			return $result;
3599
 
3600
			}#if end
3601
 
3602
		#初始化要回傳的content
3603
		$result["content"]=array();
3604
 
3605
		#初始化儲存逐行的註解.
3606
		$result["comment"]=array();
3607
 
3608
		#預設的zone file domain為空
3609
		$result["domain"]="";
3610
 
3611
		#預設的 update 時間
3612
		$result["defaultTTL"]=3600;
3613
 
3614
		#取得 dns 記錄檔案的內容
3615
		#函式說明:
3616
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
3617
		#回傳的變數說明:
3618
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
3619
		#$result["error"],錯誤訊息提示.
3620
		#$result["warning"],警告訊息.
3621
		#$result["function"],當前執行的函數名稱.
3622
		#$result["fileContent"],爲檔案的內容陣列.
3623
		#$result["lineCount"],爲檔案內容總共的行數.
3624
		#$result["fullContent"],為檔案的完整內容.
3625
		#$result["base64dataOnly"],檔案的base64data.
3626
		#$result["base64data"],為在網頁上給予src參數的數值.
3627
		#$result["mimeType"],為檔案的mime type.
3628
		#必填參數:
3629
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
3630
		$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$conf["dnsRecordFile"];
3631
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3632
		$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
3633
		#可省略參數:
3634
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
3635
		$conf["fileAccesss::getFileContent"]["web"]="false";
3636
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
3637
		#$conf["createIfnotExist"]="false";
3638
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
3639
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
3640
		#參考資料:
3641
		#file(),取得檔案內容的行數.
3642
		#file=>http:#php.net/manual/en/function.file.php
3643
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
3644
		#filesize=>http://php.net/manual/en/function.filesize.php
3645
		#參考資料:
3646
		#無.
3647
		#備註:
3648
		#無.
3649
		$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
3650
		unset($conf["fileAccesss::getFileContent"]);
3651
 
3652
		#如果檢查失敗
3653
		if($getFileContent["status"]==="false"){
3654
 
3655
			#設置錯誤識別
3656
			$result["status"]="false";
3657
 
3658
			#設置錯誤訊息
3659
			$result["error"]=$getFileContent;
3660
 
3661
			#回傳結果
3662
			return $result;
3663
 
3664
			}#if end
3665
 
3666
		#取得每行內容
3667
		$lines=$getFileContent["fileContent"];
3668
 
3669
		/*
3670
		範例每行內容:
3671
		$ORIGIN server.domain.	;base domain-name,in this Resource Records (RR) file,"@" equal to base domain-name.
3672
		$TTL 86400	;default TTL for zone
3673
		@	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
3674
		@	3600	IN	TXT	"v=spf1 a mx ~all"
3675
		@	86400	IN	MX	1 mail.server.domain.
3676
		@	86400	IN	A	1.1.1.1
404 liveuser 3677
		@		IN	CAA	0 issue ";"
249 liveuser 3678
		mail.server.domain.	IN	1.1.1.1
3679
		10-42-0-1	IN	A	10.42.0.1
3680
		101-free        IN      A	101.101.101.101
3681
		127-0-0-1	IN	A	127.0.0.1
3682
		_dmarc	IN	TXT	"v=DMARC1;p=reject;sp=reject;pct=100;adkim=r;aspf=r;fo=1;ri=86400;rua=mailto:admin@server.domain"
3683
		default._domainkey	IN	TXT	( "v=DKIM1; k=rsa;" "p=MIGfMA0GCSqG/SIb3DQEBAQQAB" )  ; ----- DKIM key default for qbpwcf.org
3684
		...
3685
		*/
3686
 
3687
		#針對每行內容
3688
		foreach($lines as $lineNo => $line){
3689
 
291 liveuser 3690
			#如果要啟用多執行序
293 liveuser 3691
			if($conf["multiThreads"]==="true"){
291 liveuser 3692
 
293 liveuser 3693
				#如果要debug
3694
				if($conf["debug"]==="true"){
291 liveuser 3695
 
293 liveuser 3696
					#函式說明:
3697
					#撰寫log
3698
					#回傳結果:
3699
					#$result["status"],狀態,"true"或"false".
3700
					#$result["error"],錯誤訊息陣列.
3701
					#$result["function"],當前函式的名稱.
3702
					#$result["argu"],使用的參數.
3703
					#$result["content"],要寫入log的內容字串.
3704
					#必填參數:
3705
					#$conf["path"],字串,log檔案的路徑與名稱.
3706
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3707
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3708
					$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR through multi threads.".PHP_EOL;
3709
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3710
					$conf["logs::record"]["fileArgu"]=__FILE__;
3711
					#可省略參數:
3712
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3713
					#$conf["rewrite"]="false";
3714
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3715
					#$conf["returnOnly"]="true";
3716
					#參考資料:
3717
					#無.
3718
					#備註:
3719
					#無.
3720
					$record=logs::record($conf["logs::record"]);
3721
					unset($conf["logs::record"]);
291 liveuser 3722
 
293 liveuser 3723
					}#if end
3724
 
3725
				#初始化要執行的 php 程式
3726
				$phpCode2run="php -r ";
291 liveuser 3727
 
293 liveuser 3728
				#php code not escaped
3729
				$phpCode2escaped=<<<'PHP'
3730
/*
291 liveuser 3731
 
293 liveuser 3732
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
3733
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3734
 
3735
    This file is part of QBPWCF.
3736
 
3737
    QBPWCF is free software: you can redistribute it and/or modify
3738
    it under the terms of the GNU General Public License as published by
3739
    the Free Software Foundation, either version 3 of the License, or
3740
    (at your option) any later version.
3741
 
3742
    QBPWCF is distributed in the hope that it will be useful,
3743
    but WITHOUT ANY WARRANTY; without even the implied warranty of
3744
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3745
    GNU General Public License for more details.
3746
 
3747
    You should have received a copy of the GNU General Public License
3748
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
3749
 
3750
*/
3751
 
3752
#使用命名空間qbpwcf
3753
namespace qbpwcf;
3754
 
3755
#匯入套件
3756
PHP;
3757
 
3758
#設置 lib root path
3759
$libPath=pathinfo(__FILE__)["dirname"]."/..";
3760
 
3761
#串接匯入QBPWCF套件
3762
$phpCode2escaped=$phpCode2escaped.PHP_EOL."require_once(\"".$libPath."/qbpwcf/allInOne.php\");";
3763
 
3764
#串接php程式
3765
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
291 liveuser 3766
#函式說明:
3767
#解析RR檔案中其中的一行內容.
3768
#回傳結果:
3769
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3770
#$reuslt["error"],執行不正常結束的錯訊息陣列.
3771
#$result["function"],當前執行的函式名稱.
3772
#$result["argu"],所使用的參數.
293 liveuser 3773
#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
291 liveuser 3774
#$result["domain"],字串,RR所屬domain.
3775
#$result["defaultTTL"],字串,預設的RR更新時間.
293 liveuser 3776
#$result["comment"],字串,一行的註解.
291 liveuser 3777
#必填參數:
3778
#$conf["line"],字串,要解析的行內容.
293 liveuser 3779
PHP;
3780
 
3781
#串接變數
3782
$phpCode2escaped=$phpCode2escaped.PHP_EOL."\$conf[\"line\"]=base64_decode(\"".base64_encode($line)."\");";
3783
 
3784
#串接php程式
3785
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
291 liveuser 3786
#可省略參數:
3787
#無.
3788
#參考資料:
3789
#無.
3790
#備註:
3791
#無.
3792
$parseRRline=zerossl::parseRRline($conf);
3793
unset($conf);
3794
 
3795
#如果執行異常 
3796
if($parseRRline["status"]==="false"){
3797
 
3798
	#設置錯誤識別
3799
	$result["status"]="false";
3800
 
3801
	#設置錯誤訊息
3802
	$result["error"]=$parseRRline;
3803
 
3804
	#印出 json 結果
3805
	echo json_encode($result);
3806
 
3807
	#結束執行,回傳1.
3808
	exit(1);
3809
 
3810
	}#if end
3811
 
3812
#印出json
3813
echo json_encode($parseRRline);
3814
PHP;
3815
 
293 liveuser 3816
				#串接要執行的參數
3817
				$phpCode2run=$phpCode2run.escapeshellarg($phpCode2escaped);
3818
 
291 liveuser 3819
				#函式說明:
3820
				#透過proc來多執行序運作.
3821
				#回傳結果:
3822
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3823
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3824
				#$result["function"],當前執行的函式名稱.
3825
				#$result["argu"],使用的參數.
3826
				#$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"代表程序的資訊.
3827
				#必填參數:
3828
				#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
293 liveuser 3829
				$conf["threads::proc"]["cmds"]=array($phpCode2run);
291 liveuser 3830
				#可省略參數:
3831
				#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
3832
				$conf["threads::proc"]["wait"]="false";
3833
				#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
3834
				#$conf["timeout"]=array("10");
3835
				#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
293 liveuser 3836
				#$conf["threads::proc"]["workingDir"]=array(pathinfo(__FILE__)["dirname"]);
291 liveuser 3837
				#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
3838
				#$conf["envs"]=array(array("key"=>"value"));
3839
				#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
3840
				#$conf["executeBy"]=array("bash");
3841
				#參考資料:
3842
				#https://www.php.net/manual/en/function.proc-open.php
3843
				#https://www.php.net/manual/en/function.proc-get-status.php
3844
				#https://www.php.net/manual/en/function.proc-terminate.php
3845
				#備註:
3846
				#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
3847
				#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
3848
				$proc=threads::proc($conf["threads::proc"]);
3849
				unset($conf["threads::proc"]);
3850
 
293 liveuser 3851
				#debug
3852
				#var_dump($proc);exit;
3853
 
291 liveuser 3854
				#如果檢查失敗
3855
				if($proc["status"]==="false"){
3856
 
3857
					#設置錯誤識別
3858
					$result["status"]="false";
3859
 
3860
					#設置錯誤訊息
3861
					$result["error"]=$proc;
3862
 
3863
					#回傳結果
3864
					return $result;
3865
 
3866
					}#if end
3867
 
3868
				#儲存程序資訊
294 liveuser 3869
				$procs[$lineNo]=$proc;	
291 liveuser 3870
 
3871
				#換解析下一行
3872
				continue;
3873
 
3874
				}#if end
3875
 
249 liveuser 3876
			#另存一份要處理的RR
404 liveuser 3877
			#$unFormatStr=$line;
249 liveuser 3878
 
253 liveuser 3879
			#如果要debug
3880
			if($conf["debug"]==="true"){
3881
 
3882
				#函式說明:
3883
				#撰寫log
3884
				#回傳結果:
3885
				#$result["status"],狀態,"true"或"false".
3886
				#$result["error"],錯誤訊息陣列.
3887
				#$result["function"],當前函式的名稱.
3888
				#$result["argu"],使用的參數.
3889
				#$result["content"],要寫入log的內容字串.
3890
				#必填參數:
3891
				#$conf["path"],字串,log檔案的路徑與名稱.
3892
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3893
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3894
				$conf["logs::record"]["content"]="processing lineNo:".$lineNo." content:".$line.PHP_EOL;
3895
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3896
				$conf["logs::record"]["fileArgu"]=__FILE__;
3897
				#可省略參數:
3898
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3899
				#$conf["rewrite"]="false";
3900
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3901
				#$conf["returnOnly"]="true";
3902
				#參考資料:
3903
				#無.
3904
				#備註:
3905
				#無.
3906
				$record=logs::record($conf["logs::record"]);
3907
				unset($conf["logs::record"]);
3908
 
3909
				}#if end
3910
 
404 liveuser 3911
			#函式說明:
3912
			#解析RR檔案中其中的一行內容,回傳結果.
249 liveuser 3913
			#回傳結果:
3914
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3915
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
3916
			#$result["function"],當前執行的函式名稱.
3917
			#$result["argu"],所使用的參數.
404 liveuser 3918
			#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
3919
			#$result["domain"],字串,RR所屬domain.
3920
			#$result["defaultTTL"],字串,預設的RR更新時間.
3921
			#$result["comment"],字串,一行的註解.
249 liveuser 3922
			#必填參數:
404 liveuser 3923
			#$conf["line"],字串,要解析的行內容.
3924
			$conf["zerossl::parseRRline"]["line"]=$line;
249 liveuser 3925
			#可省略參數:
3926
			#無.
3927
			#參考資料:
3928
			#無.
3929
			#備註:
3930
			#無.
404 liveuser 3931
			$parseRRline=zerossl::parseRRline($conf["zerossl::parseRRline"]);
3932
			unset($conf["zerossl::parseRRline"]);
249 liveuser 3933
 
404 liveuser 3934
			#如果解析異常 
3935
			if($parseRRline["status"]==="false"){
249 liveuser 3936
 
3937
				#設置錯誤識別
3938
				$result["status"]="false";
3939
 
3940
				#設置錯誤訊息
406 liveuser 3941
				$result["error"]=$parseRRline;
249 liveuser 3942
 
3943
				#回傳結果
3944
				return $result;
3945
 
404 liveuser 3946
				}#iif end
249 liveuser 3947
 
404 liveuser 3948
			#取得該RR的解析結果
3949
			$info=$parseRRline["content"];
249 liveuser 3950
 
404 liveuser 3951
			#如果是TTL列
3952
			if($info["type"]==="\$TTL"){
249 liveuser 3953
 
404 liveuser 3954
				#設置預設的TTL
406 liveuser 3955
				$result["defaultTTL"]=$parseRRline["defaultTTL"];
249 liveuser 3956
 
3957
				}#if end
3958
 
404 liveuser 3959
			#如果是ORIGIN列
3960
			if($info["type"]==="\$ORIGIN"){	
249 liveuser 3961
 
406 liveuser 3962
				#debug
3963
				#var_dump($info);exit(1);
3964
 
404 liveuser 3965
				#設置RR所屬的domain
406 liveuser 3966
				$result["domain"]=$parseRRline["domain"];
249 liveuser 3967
 
3968
				}#if end
3969
 
404 liveuser 3970
			#儲存 RR 的記錄
3971
			$result["content"][]=$info;
249 liveuser 3972
 
3973
			}#foreach end
291 liveuser 3974
 
3975
		#如果要啟用多執行序
293 liveuser 3976
		if($conf["multiThreads"]==="true"){
249 liveuser 3977
 
293 liveuser 3978
			#如果要debug
3979
			if($conf["debug"]==="true"){
3980
 
3981
				#函式說明:
3982
				#撰寫log
3983
				#回傳結果:
3984
				#$result["status"],狀態,"true"或"false".
3985
				#$result["error"],錯誤訊息陣列.
3986
				#$result["function"],當前函式的名稱.
3987
				#$result["argu"],使用的參數.
3988
				#$result["content"],要寫入log的內容字串.
3989
				#必填參數:
3990
				#$conf["path"],字串,log檔案的路徑與名稱.
3991
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3992
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3993
				$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR result through multi threads.".PHP_EOL;
3994
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3995
				$conf["logs::record"]["fileArgu"]=__FILE__;
3996
				#可省略參數:
3997
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3998
				#$conf["rewrite"]="false";
3999
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4000
				#$conf["returnOnly"]="true";
4001
				#參考資料:
4002
				#無.
4003
				#備註:
4004
				#無.
4005
				$record=logs::record($conf["logs::record"]);
4006
				unset($conf["logs::record"]);
4007
 
4008
				}#if end
291 liveuser 4009
 
293 liveuser 4010
			#無窮迴圈
4011
			while(true){
4012
 
4013
				#等後1秒
4014
				sleep(1);
4015
 
4016
				#針對每行處理的狀況
4017
				foreach($procs as $procIndex => $proc){
4018
 
4019
					#如果要debug
4020
					if($conf["debug"]==="true"){
4021
 
4022
						#函式說明:
4023
						#撰寫log
4024
						#回傳結果:
4025
						#$result["status"],狀態,"true"或"false".
4026
						#$result["error"],錯誤訊息陣列.
4027
						#$result["function"],當前函式的名稱.
4028
						#$result["argu"],使用的參數.
4029
						#$result["content"],要寫入log的內容字串.
4030
						#必填參數:
4031
						#$conf["path"],字串,log檔案的路徑與名稱.
4032
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4033
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4034
						$conf["logs::record"]["content"]="lineNo:".__LINE__." Try get result of parsing RR line ".($procIndex+1)." through multi threads.".PHP_EOL;
4035
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4036
						$conf["logs::record"]["fileArgu"]=__FILE__;
4037
						#可省略參數:
4038
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4039
						#$conf["rewrite"]="false";
4040
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4041
						#$conf["returnOnly"]="true";
4042
						#參考資料:
4043
						#無.
4044
						#備註:
4045
						#無.
4046
						$record=logs::record($conf["logs::record"]);
4047
						unset($conf["logs::record"]);
4048
 
4049
						}#if end
4050
 
4051
					#函式說明:
4052
					#更新透過proc執行的多程序資訊.
4053
					#回傳結果:
4054
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4055
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
4056
					#$result["function"],當前執行的函式名稱.
4057
					#$result["argu"],使用的參數.
4058
					#$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"代表程序的資訊.
4059
					#必填參數:
4060
					#$conf["procs"],陣列,運行self::proc後回傳的content.
4061
					$conf["threads::proc_update"]["procs"]=$proc["content"];
4062
					#可省略參數:
4063
					#無.
4064
					#參考資料:
4065
					#無.
4066
					#備註:
4067
					#無.
4068
					$proc_update=threads::proc_update($conf["threads::proc_update"]);
4069
					unset($conf["threads::proc_update"]);
4070
 
4071
					#debug
4072
					#var_dump($proc_update);exit;
4073
 
4074
					#如果執行異常
4075
					if($proc_update["status"]==="false"){
4076
 
4077
						#設置執行異常
4078
						$result["status"]="false";
4079
 
4080
						#設置執行錯誤
4081
						$result["error"]=$proc_update;
4082
 
4083
						#回傳結果
4084
						return $result;
4085
 
4086
						}#if end
4087
 
4088
					#另存結果
4089
					$procRes=$proc_update["content"][0];
4090
 
4091
					#如果程序執行異常
4092
					if($procRes["status"]==="false"){
4093
 
4094
						#設置執行異常
4095
						$result["status"]="false";
4096
 
4097
						#設置執行錯誤
4098
						$result["error"]=$procRes;
4099
 
4100
						#回傳結果
4101
						return $result;
4102
 
4103
						}#if end
4104
 
4105
					#如果程序尚在執行
4106
					if($procRes["statusCode"]==="?"){
4107
 
4108
						#換看下一列的執行狀況
4109
						continue;
4110
 
4111
						}#if end
4112
 
4113
					#如果輸出內容不是 json
4114
					if(!(json_validate($procRes["content"]))){
4115
 
4116
						#設置執行異常
4117
						$result["status"]="false";
4118
 
4119
						#設置執行錯誤
4120
						$result["error"]=$procRes;
4121
 
4122
						#回傳結果
4123
						return $result;
4124
 
4125
						}#if end
4126
 
4127
					#解析json
4128
					$jsonRes=json_decode($procRes["content"]);
4129
 
4130
					#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","query","update",也可能為空陣列.
4131
					#$result["domain"],字串,RR所屬domain.
4132
					#$result["defaultTTL"],字串,預設的RR更新時間.
4133
					#$result["comment"],字串,一行的註解.
4134
 
4135
					#如果有 content->type 存在
4136
					if(isset($jsonRes->content->type)){
4137
 
4138
						#儲存value
4139
						$info["type"]=$jsonRes->content->type;
4140
 
4141
						}#if end
4142
 
4143
					#如果有 content->value 存在
4144
					if(isset($jsonRes->content->value)){
4145
 
4146
						#儲存value
4147
						$info["value"]=$jsonRes->content->value;
4148
 
4149
						}#if end
4150
 
4151
					#如果有 content->query 存在
4152
					if(isset($jsonRes->content->query)){
4153
 
4154
						#儲存query
4155
						$info["query"]=$jsonRes->content->query;
4156
 
4157
						}#if end
4158
 
4159
					#如果有 content->update 存在
4160
					if(isset($jsonRes->content->update)){
4161
 
4162
						#儲存query
4163
						$info["update"]=$jsonRes->content->update;
4164
 
4165
						}#if end
4166
 
4167
					#如果有 domain 存在
4168
					if(isset($jsonRes->domain)){
4169
 
4170
						#儲存domain
4171
						$result["domain"]=$jsonRes->domain;
4172
 
4173
						}#if end
4174
 
4175
					#如果有 defaultTTL 存在
4176
					if(isset($jsonRes->defaultTTL)){
4177
 
4178
						#儲存domain
404 liveuser 4179
						$result["defaultTTL"]=$jsonRes->defaultTTL;
293 liveuser 4180
 
4181
						}#if end
4182
 
4183
					#如果有 comment 存在
4184
					if(isset($jsonRes->comment)){
4185
 
4186
						#儲存comment,用$procIndex作為先後順率的識別
4187
						$result["comment"][$procIndex]=$jsonRes->comment;
4188
 
4189
						}#if end
4190
 
4191
					#儲存 RR 的記錄
4192
					$result["content"][$procIndex]=$info;
4193
 
4194
					#移除解析好的行號
4195
					unset($procs[$procIndex]);
4196
 
4197
					#如果要debug
4198
					if($conf["debug"]==="true"){
4199
 
4200
						#函式說明:
4201
						#撰寫log
4202
						#回傳結果:
4203
						#$result["status"],狀態,"true"或"false".
4204
						#$result["error"],錯誤訊息陣列.
4205
						#$result["function"],當前函式的名稱.
4206
						#$result["argu"],使用的參數.
4207
						#$result["content"],要寫入log的內容字串.
4208
						#必填參數:
4209
						#$conf["path"],字串,log檔案的路徑與名稱.
4210
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4211
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4212
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR line ".($procIndex+1)." through multi threads fin.".PHP_EOL;
4213
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4214
						$conf["logs::record"]["fileArgu"]=__FILE__;
4215
						#可省略參數:
4216
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4217
						#$conf["rewrite"]="false";
4218
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4219
						#$conf["returnOnly"]="true";
4220
						#參考資料:
4221
						#無.
4222
						#備註:
4223
						#無.
4224
						$record=logs::record($conf["logs::record"]);
4225
						unset($conf["logs::record"]);
4226
 
4227
						}#if end
4228
 
4229
					}#foreach end
4230
 
4231
				#如果每行都已經解析好了
4232
				if(count($procs)===0){
4233
 
4234
					#如果要debug
4235
					if($conf["debug"]==="true"){
4236
 
4237
						#函式說明:
4238
						#撰寫log
4239
						#回傳結果:
4240
						#$result["status"],狀態,"true"或"false".
4241
						#$result["error"],錯誤訊息陣列.
4242
						#$result["function"],當前函式的名稱.
4243
						#$result["argu"],使用的參數.
4244
						#$result["content"],要寫入log的內容字串.
4245
						#必填參數:
4246
						#$conf["path"],字串,log檔案的路徑與名稱.
4247
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4248
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4249
						$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR through multi threads fin.".PHP_EOL;
4250
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4251
						$conf["logs::record"]["fileArgu"]=__FILE__;
4252
						#可省略參數:
4253
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4254
						#$conf["rewrite"]="false";
4255
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4256
						#$conf["returnOnly"]="true";
4257
						#參考資料:
4258
						#無.
4259
						#備註:
4260
						#無.
4261
						$record=logs::record($conf["logs::record"]);
4262
						unset($conf["logs::record"]);
4263
 
4264
						}#if end
4265
 
4266
					#跳出 while
4267
					break;
4268
 
4269
					}#if end
4270
 
4271
				}#while end
4272
 
291 liveuser 4273
			}#if end
4274
 
253 liveuser 4275
		#如果要debug
4276
		if($conf["debug"]==="true"){
249 liveuser 4277
 
253 liveuser 4278
			#函式說明:
4279
			#撰寫log
4280
			#回傳結果:
4281
			#$result["status"],狀態,"true"或"false".
4282
			#$result["error"],錯誤訊息陣列.
4283
			#$result["function"],當前函式的名稱.
4284
			#$result["argu"],使用的參數.
4285
			#$result["content"],要寫入log的內容字串.
4286
			#必填參數:
4287
			#$conf["path"],字串,log檔案的路徑與名稱.
4288
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4289
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4290
			$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR fin.".PHP_EOL;
4291
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4292
			$conf["logs::record"]["fileArgu"]=__FILE__;
4293
			#可省略參數:
4294
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4295
			#$conf["rewrite"]="false";
4296
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4297
			#$conf["returnOnly"]="true";
4298
			#參考資料:
4299
			#無.
4300
			#備註:
4301
			#無.
4302
			$record=logs::record($conf["logs::record"]);
4303
			unset($conf["logs::record"]);
4304
 
4305
			}#if end
4306
 
249 liveuser 4307
		#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
4308
 
4309
		#針對每個要新增的RR記錄
255 liveuser 4310
		foreach($conf["add"] as $nri => $newRR){
249 liveuser 4311
 
255 liveuser 4312
			#如果要debug
4313
			if($conf["debug"]==="true"){
4314
 
4315
				#函式說明:
4316
				#撰寫log
4317
				#回傳結果:
4318
				#$result["status"],狀態,"true"或"false".
4319
				#$result["error"],錯誤訊息陣列.
4320
				#$result["function"],當前函式的名稱.
4321
				#$result["argu"],使用的參數.
4322
				#$result["content"],要寫入log的內容字串.
4323
				#必填參數:
4324
				#$conf["path"],字串,log檔案的路徑與名稱.
4325
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4326
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4327
				$conf["logs::record"]["content"]="lineNo:".__LINE__." ori newRR:".PHP_EOL;
4328
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4329
				$conf["logs::record"]["fileArgu"]=__FILE__;
4330
				#可省略參數:
4331
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4332
				#$conf["rewrite"]="false";
4333
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4334
				#$conf["returnOnly"]="true";
4335
				#參考資料:
4336
				#無.
4337
				#備註:
4338
				#無.
4339
				$record=logs::record($conf["logs::record"]);
4340
				unset($conf["logs::record"]);
4341
 
4342
				#函式說明:
4343
				#撰寫log
4344
				#回傳結果:
4345
				#$result["status"],狀態,"true"或"false".
4346
				#$result["error"],錯誤訊息陣列.
4347
				#$result["function"],當前函式的名稱.
4348
				#$result["argu"],使用的參數.
4349
				#$result["content"],要寫入log的內容字串.
4350
				#必填參數:
4351
				#$conf["path"],字串,log檔案的路徑與名稱.
4352
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4353
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4354
				$conf["logs::record"]["content"]=$newRR;
4355
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4356
				$conf["logs::record"]["fileArgu"]=__FILE__;
4357
				#可省略參數:
4358
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4359
				#$conf["rewrite"]="false";
4360
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4361
				#$conf["returnOnly"]="true";
4362
				#參考資料:
4363
				#無.
4364
				#備註:
4365
				#無.
4366
				$record=logs::record($conf["logs::record"]);
4367
				unset($conf["logs::record"]);
4368
 
4369
				}#if end
4370
 
4371
			#如果新的 RR 缺少必備的資訊
4372
			if(!isset($newRR["type"])){
4373
 
4374
				#設置執行異常
4375
				$result["status"]="false";
4376
 
4377
				#設置執行錯誤
4378
				$result["error"]="add參數的格式缺少type";
4379
 
4380
				#回傳結果
4381
				return $result;
4382
 
4383
				}#if end
4384
 
404 liveuser 4385
			#如果 query 不是"@"也不為"."結尾
255 liveuser 4386
			if( ($newRR["query"]!=="@") && ($newRR["query"][strlen($newRR["query"])-1]!==".") ){
4387
 
4388
				#加上 "."
4389
				$conf["add"][$nri]["query"]=$newRR["query"]=$newRR["query"].".";
4390
 
4391
				}#if end
4392
 
4393
			#如果新的 query 為 $ORGIN 結尾
4394
			#函式說明:
4395
			#將字串特定關鍵字與其後面的內容剔除
4396
			#回傳結果:
4397
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4398
			#$result["error"],錯誤訊息陣列.
4399
			#$result["warning"],警告訊息鎮列.
4400
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4401
			#$result["function"],當前執行的函數名稱.
4402
			#$result["oriStr"],要處理的原始字串內容.
4403
			#$result["content"],處理好的的字串內容.
4404
			#$result["deleted"],被移除的內容.
4405
			#$result["argu"],使用的參數.
4406
			#必填參數:
4407
			#$conf["stringIn"],字串,要處理的字串.
4408
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
4409
			#$conf["keyWord"],字串,特定字串.
4410
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["domain"];
4411
			#可省略參數:
4412
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
4413
			#$conf["deleteLastRepeatedOne"]="";
4414
			#參考資料:
4415
			#無.
4416
			#備註:
4417
			#無.
4418
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
4419
			unset($conf["stringProcess::delStrAfterKeyWord"]);
4420
 
4421
			#如果要debug
4422
			if($conf["debug"]==="true"){
4423
 
4424
				#函式說明:
4425
				#撰寫log
4426
				#回傳結果:
4427
				#$result["status"],狀態,"true"或"false".
4428
				#$result["error"],錯誤訊息陣列.
4429
				#$result["function"],當前函式的名稱.
4430
				#$result["argu"],使用的參數.
4431
				#$result["content"],要寫入log的內容字串.
4432
				#必填參數:
4433
				#$conf["path"],字串,log檔案的路徑與名稱.
4434
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4435
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4436
				$conf["logs::record"]["content"]="lineNo:".__LINE__." try process newRR with \$ORIGIN end".PHP_EOL;
4437
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4438
				$conf["logs::record"]["fileArgu"]=__FILE__;
4439
				#可省略參數:
4440
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4441
				#$conf["rewrite"]="false";
4442
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4443
				#$conf["returnOnly"]="true";
4444
				#參考資料:
4445
				#無.
4446
				#備註:
4447
				#無.
4448
				$record=logs::record($conf["logs::record"]);
4449
				unset($conf["logs::record"]);
4450
 
4451
				#函式說明:
4452
				#撰寫log
4453
				#回傳結果:
4454
				#$result["status"],狀態,"true"或"false".
4455
				#$result["error"],錯誤訊息陣列.
4456
				#$result["function"],當前函式的名稱.
4457
				#$result["argu"],使用的參數.
4458
				#$result["content"],要寫入log的內容字串.
4459
				#必填參數:
4460
				#$conf["path"],字串,log檔案的路徑與名稱.
4461
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4462
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4463
				$conf["logs::record"]["content"]=$delStrAfterKeyWord;
4464
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4465
				$conf["logs::record"]["fileArgu"]=__FILE__;
4466
				#可省略參數:
4467
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4468
				#$conf["rewrite"]="false";
4469
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4470
				#$conf["returnOnly"]="true";
4471
				#參考資料:
4472
				#無.
4473
				#備註:
4474
				#無.
4475
				$record=logs::record($conf["logs::record"]);
4476
				unset($conf["logs::record"]);
4477
 
4478
				}#if end
4479
 
4480
			#如果異常
4481
			if($delStrAfterKeyWord["status"]==="false"){
4482
 
4483
				#設置執行異常
4484
				$result["status"]="false";
4485
 
4486
				#設置執行錯誤
4487
				$result["error"]=$delStrAfterKeyWord;
4488
 
4489
				#回傳結果
4490
				return $result;
4491
 
4492
				}#if end
4493
 
4494
			#如果有找到 $ORIGIN 結尾
4495
			if($delStrAfterKeyWord["founded"]==="true"){
4496
 
4497
				#更新 query
4498
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
4499
 
4500
				#如果$newRR["query"] 變成 ""
4501
				if(empty($newRR["query"])){
4502
 
4503
					#變成 zone domain,亦即 $result["domain"]
4504
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
4505
 
4506
					}#if end
4507
 
4508
				#如果要debug
4509
				if($conf["debug"]==="true"){
4510
 
4511
					#函式說明:
4512
					#撰寫log
4513
					#回傳結果:
4514
					#$result["status"],狀態,"true"或"false".
4515
					#$result["error"],錯誤訊息陣列.
4516
					#$result["function"],當前函式的名稱.
4517
					#$result["argu"],使用的參數.
4518
					#$result["content"],要寫入log的內容字串.
4519
					#必填參數:
4520
					#$conf["path"],字串,log檔案的路徑與名稱.
4521
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4522
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4523
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4524
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4525
					$conf["logs::record"]["fileArgu"]=__FILE__;
4526
					#可省略參數:
4527
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4528
					#$conf["rewrite"]="false";
4529
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4530
					#$conf["returnOnly"]="true";
4531
					#參考資料:
4532
					#無.
4533
					#備註:
4534
					#無.
4535
					$record=logs::record($conf["logs::record"]);
4536
					unset($conf["logs::record"]);
4537
 
4538
					#函式說明:
4539
					#撰寫log
4540
					#回傳結果:
4541
					#$result["status"],狀態,"true"或"false".
4542
					#$result["error"],錯誤訊息陣列.
4543
					#$result["function"],當前函式的名稱.
4544
					#$result["argu"],使用的參數.
4545
					#$result["content"],要寫入log的內容字串.
4546
					#必填參數:
4547
					#$conf["path"],字串,log檔案的路徑與名稱.
4548
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4549
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4550
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4551
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4552
					$conf["logs::record"]["fileArgu"]=__FILE__;
4553
					#可省略參數:
4554
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4555
					#$conf["rewrite"]="false";
4556
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4557
					#$conf["returnOnly"]="true";
4558
					#參考資料:
4559
					#無.
4560
					#備註:
4561
					#無.
4562
					$record=logs::record($conf["logs::record"]);
4563
					unset($conf["logs::record"]);
4564
 
4565
					}#if end
4566
 
4567
				}#if end
4568
 
4569
			#如果新的 query 為 "." 結尾
4570
			#函式說明:
4571
			#將字串特定關鍵字與其後面的內容剔除
4572
			#回傳結果:
4573
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4574
			#$result["error"],錯誤訊息陣列.
4575
			#$result["warning"],警告訊息鎮列.
4576
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4577
			#$result["function"],當前執行的函數名稱.
4578
			#$result["oriStr"],要處理的原始字串內容.
4579
			#$result["content"],處理好的的字串內容.
4580
			#$result["deleted"],被移除的內容.
4581
			#$result["argu"],使用的參數.
4582
			#必填參數:
4583
			#$conf["stringIn"],字串,要處理的字串.
4584
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
4585
			#$conf["keyWord"],字串,特定字串.
4586
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".";
4587
			#可省略參數:
4588
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
4589
			#$conf["deleteLastRepeatedOne"]="";
4590
			#參考資料:
4591
			#無.
4592
			#備註:
4593
			#無.
4594
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
4595
			unset($conf["stringProcess::delStrAfterKeyWord"]);
4596
 
4597
			#如果異常
4598
			if($delStrAfterKeyWord["status"]==="false"){
4599
 
4600
				#設置執行異常
4601
				$result["status"]="false";
4602
 
4603
				#設置執行錯誤
4604
				$result["error"]=$delStrAfterKeyWord;
4605
 
4606
				#回傳結果
4607
				return $result;
4608
 
4609
				}#if end
4610
 
4611
			#如果有找到 "." 結尾
4612
			if($delStrAfterKeyWord["founded"]==="true"){
4613
 
4614
				#更新 query
4615
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
4616
 
4617
				#如果 $newRR["query"] 變成 ""
4618
				if(empty($newRR["query"])){
4619
 
4620
					#變成 zone domain,亦即 $result["domain"]
4621
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
4622
 
4623
					}#if end
4624
 
4625
				#如果要debug
4626
				if($conf["debug"]==="true"){
4627
 
4628
					#函式說明:
4629
					#撰寫log
4630
					#回傳結果:
4631
					#$result["status"],狀態,"true"或"false".
4632
					#$result["error"],錯誤訊息陣列.
4633
					#$result["function"],當前函式的名稱.
4634
					#$result["argu"],使用的參數.
4635
					#$result["content"],要寫入log的內容字串.
4636
					#必填參數:
4637
					#$conf["path"],字串,log檔案的路徑與名稱.
4638
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4639
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4640
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4641
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4642
					$conf["logs::record"]["fileArgu"]=__FILE__;
4643
					#可省略參數:
4644
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4645
					#$conf["rewrite"]="false";
4646
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4647
					#$conf["returnOnly"]="true";
4648
					#參考資料:
4649
					#無.
4650
					#備註:
4651
					#無.
4652
					$record=logs::record($conf["logs::record"]);
4653
					unset($conf["logs::record"]);
4654
 
4655
					#函式說明:
4656
					#撰寫log
4657
					#回傳結果:
4658
					#$result["status"],狀態,"true"或"false".
4659
					#$result["error"],錯誤訊息陣列.
4660
					#$result["function"],當前函式的名稱.
4661
					#$result["argu"],使用的參數.
4662
					#$result["content"],要寫入log的內容字串.
4663
					#必填參數:
4664
					#$conf["path"],字串,log檔案的路徑與名稱.
4665
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4666
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4667
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4668
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4669
					$conf["logs::record"]["fileArgu"]=__FILE__;
4670
					#可省略參數:
4671
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4672
					#$conf["rewrite"]="false";
4673
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4674
					#$conf["returnOnly"]="true";
4675
					#參考資料:
4676
					#無.
4677
					#備註:
4678
					#無.
4679
					$record=logs::record($conf["logs::record"]);
4680
					unset($conf["logs::record"]);
4681
 
4682
					}#if end
4683
 
4684
				}#if end
4685
 
404 liveuser 4686
			/* 看起來怪怪的
4687
 
255 liveuser 4688
			#如果新 RR 的 type 不是 A 且 value 不為 "." 結尾.
4689
			if( $newRR["type"]!=="A" && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
4690
 
4691
				#new RR add dot to value end.
4692
				$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
4693
 
4694
				#如果要debug
4695
				if($conf["debug"]==="true"){
4696
 
4697
					#函式說明:
4698
					#撰寫log
4699
					#回傳結果:
4700
					#$result["status"],狀態,"true"或"false".
4701
					#$result["error"],錯誤訊息陣列.
4702
					#$result["function"],當前函式的名稱.
4703
					#$result["argu"],使用的參數.
4704
					#$result["content"],要寫入log的內容字串.
4705
					#必填參數:
4706
					#$conf["path"],字串,log檔案的路徑與名稱.
4707
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4708
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4709
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4710
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4711
					$conf["logs::record"]["fileArgu"]=__FILE__;
4712
					#可省略參數:
4713
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4714
					#$conf["rewrite"]="false";
4715
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4716
					#$conf["returnOnly"]="true";
4717
					#參考資料:
4718
					#無.
4719
					#備註:
4720
					#無.
4721
					$record=logs::record($conf["logs::record"]);
4722
					unset($conf["logs::record"]);
4723
 
4724
					#函式說明:
4725
					#撰寫log
4726
					#回傳結果:
4727
					#$result["status"],狀態,"true"或"false".
4728
					#$result["error"],錯誤訊息陣列.
4729
					#$result["function"],當前函式的名稱.
4730
					#$result["argu"],使用的參數.
4731
					#$result["content"],要寫入log的內容字串.
4732
					#必填參數:
4733
					#$conf["path"],字串,log檔案的路徑與名稱.
4734
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4735
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4736
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4737
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4738
					$conf["logs::record"]["fileArgu"]=__FILE__;
4739
					#可省略參數:
4740
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4741
					#$conf["rewrite"]="false";
4742
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4743
					#$conf["returnOnly"]="true";
4744
					#參考資料:
4745
					#無.
4746
					#備註:
4747
					#無.
4748
					$record=logs::record($conf["logs::record"]);
4749
					unset($conf["logs::record"]);
4750
 
4751
					}#if end
4752
 
4753
				}#if end
4754
 
404 liveuser 4755
			*/
4756
 
249 liveuser 4757
			#針對 zone file 中既有的每個RR記錄
4758
			foreach($result["content"] as $index => $oldRR){
4759
 
4760
				#如果既有的跟新的RR都為 $ORIGIN
4761
				if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
4762
 
4763
					#取代既有的 RR
4764
					$result["content"][$index]=$newRR;
4765
 
4766
					#換看下一筆newRR
4767
					continue 2;
4768
 
4769
					}#if end
4770
 
4771
				#如果既有的跟新的RR都為 $TTL
4772
				if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
4773
 
4774
					#取代既有的 RR
4775
					$result["content"][$index]=$newRR;
4776
 
4777
					#換看下一筆newRR
4778
					continue 2;
4779
 
4780
					}#if end
4781
 
253 liveuser 4782
				#如果新舊資料都有query資訊
4783
				if( isset($newRR["query"]) && isset($oldRR["query"]) ){
249 liveuser 4784
 
253 liveuser 4785
					#如果跟既有的 query、type、value 有相同
4786
					if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
249 liveuser 4787
 
253 liveuser 4788
						#如果新 RR 有 update time
4789
						if(isset($newRR["update"])){
249 liveuser 4790
 
253 liveuser 4791
							#如果新舊 update time 不相同
4792
							if( $newRR["update"] !== $oldRR["update"] ){
249 liveuser 4793
 
253 liveuser 4794
								#取代既有的 RR
4795
								$result["content"][$index]=$newRR;
4796
 
4797
								#換看下一筆newRR
4798
								continue 2;
4799
 
4800
								}#if end
4801
 
4802
							}#if end
249 liveuser 4803
 
253 liveuser 4804
						#反之既有的 update time 若跟 global TTL 不一樣
4805
						else if( $oldRR["update"] !== $result["defaultTTL"] ){
4806
 
4807
							#更新為 global TTL
4808
							$result["content"][$index]["update"]=$result["defaultTTL"];
4809
 
249 liveuser 4810
							}#if end
253 liveuser 4811
 
4812
						#如果新 RR 有 comment
4813
						if( isset($newRR["comment"]) ){
249 liveuser 4814
 
253 liveuser 4815
							#更新既有 RR 的 comment
4816
							$result["content"][$index]["comment"]=$newRR["comment"];
249 liveuser 4817
 
253 liveuser 4818
							#換看下一筆newRR
4819
							continue 2;
249 liveuser 4820
 
253 liveuser 4821
							}#if end
4822
 
4823
						#反之,如果有既有 comment
4824
						else if(isset($result["content"][$index]["comment"])){
249 liveuser 4825
 
253 liveuser 4826
							#移除既有 comment
4827
							unset($result["content"][$index]["comment"]);
4828
 
4829
							#換看下一筆newRR
4830
							continue 2;
249 liveuser 4831
 
253 liveuser 4832
							}#else end
249 liveuser 4833
 
253 liveuser 4834
						}#if end
294 liveuser 4835
 
405 liveuser 4836
					#反之如果跟既有的 query、type有相同,且type 為 "CNAME"
4837
					else if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["type"]==="CNAME" ){
294 liveuser 4838
 
4839
						#更新既有 RR 的 value
4840
						$result["content"][$index]["value"]=$newRR["value"];
4841
 
4842
						#換看下一筆newRR
4843
						continue 2;
4844
 
4845
						}#if end
4846
 
405 liveuser 4847
					#反之如果跟既有的 query、type有相同,且type 為 "CAA"
4848
					else if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["type"]==="CAA" ){
4849
 
406 liveuser 4850
						#debug
4851
						var_dump(__LINE__,$oldRR,$newRR);
4852
 
4853
						#如果既有的 value 為 0 issue ";"
4854
						if($oldRR["value"]==="0 issue \";\""){
405 liveuser 4855
 
406 liveuser 4856
							#debug
4857
							#var_dump(__LINE__,$oldRR["value"]);
4858
 
4859
							#代表要從沒有限制變成有限制
405 liveuser 4860
 
4861
							#更新既有 RR 的 value
4862
							$result["content"][$index]["value"]=$newRR["value"];
4863
 
4864
							#換看下一筆newRR
4865
							continue 2;
4866
 
4867
							}#if end
4868
 
4869
						}#if end
4870
 
249 liveuser 4871
					}#if end
253 liveuser 4872
 
249 liveuser 4873
				}#foreach end
4874
 
4875
			#儲存確定要新增的RR
4876
			$result["content"][]=$newRR;
4877
 
4878
			}#foreach end
4879
 
255 liveuser 4880
		#如果要debug
4881
		if($conf["debug"]==="true"){
249 liveuser 4882
 
255 liveuser 4883
			#函式說明:
4884
			#撰寫log
4885
			#回傳結果:
4886
			#$result["status"],狀態,"true"或"false".
4887
			#$result["error"],錯誤訊息陣列.
4888
			#$result["function"],當前函式的名稱.
4889
			#$result["argu"],使用的參數.
4890
			#$result["content"],要寫入log的內容字串.
4891
			#必填參數:
4892
			#$conf["path"],字串,log檔案的路徑與名稱.
4893
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4894
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4895
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
4896
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4897
			$conf["logs::record"]["fileArgu"]=__FILE__;
4898
			#可省略參數:
4899
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4900
			#$conf["rewrite"]="false";
4901
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4902
			#$conf["returnOnly"]="true";
4903
			#參考資料:
4904
			#無.
4905
			#備註:
4906
			#無.
4907
			$record=logs::record($conf["logs::record"]);
4908
			unset($conf["logs::record"]);
249 liveuser 4909
 
255 liveuser 4910
			}#if end
4911
 
4912
		#如果要debug
4913
		if($conf["debug"]==="true"){
4914
 
4915
			#函式說明:
4916
			#撰寫log
4917
			#回傳結果:
4918
			#$result["status"],狀態,"true"或"false".
4919
			#$result["error"],錯誤訊息陣列.
4920
			#$result["function"],當前函式的名稱.
4921
			#$result["argu"],使用的參數.
4922
			#$result["content"],要寫入log的內容字串.
4923
			#必填參數:
4924
			#$conf["path"],字串,log檔案的路徑與名稱.
4925
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4926
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4927
			$conf["logs::record"]["content"]=$result["content"];
4928
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4929
			$conf["logs::record"]["fileArgu"]=__FILE__;
4930
			#可省略參數:
4931
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4932
			#$conf["rewrite"]="false";
4933
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4934
			#$conf["returnOnly"]="true";
4935
			#參考資料:
4936
			#無.
4937
			#備註:
4938
			#無.
4939
			$record=logs::record($conf["logs::record"]);
4940
			unset($conf["logs::record"]);
4941
 
4942
			}#if end
4943
 
249 liveuser 4944
		#初始化要寫入的內容
4945
		$strs2write=array();
4946
 
4947
		#針對每個RR記錄
4948
		foreach($result["content"] as $RR){
4949
 
4950
			#初始化暫存要寫入的行內容
4951
			$str2write="";
4952
 
4953
			#如果是
4954
			if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
4955
 
4956
				#組合變數名稱與數值
4957
				$str2write=$str2write.$RR["type"]."\t".$RR["value"];
4958
 
4959
				}#if end
4960
 
4961
			#反之
4962
			else{
4963
 
4964
				#加上查詢的字句
4965
				$str2write=$str2write.$RR["query"];
4966
 
4967
				#如果該筆RR有指定update time該ZONE具備 global TTL.
4968
				if(isset($RR["update"])){
4969
 
4970
					#如果 該ZONE具備 global TTL.
4971
					if(isset($result["defaultTTL"])){
4972
 
4973
						#如果該筆 RR 的 update time 不等於 global TTL
4974
						if($RR["update"]!==$result["defaultTTL"]){
4975
 
4976
							#加上TTL的字句
4977
							$str2write=$str2write."\t".$RR["update"];
4978
 
4979
							}#if end
4980
 
4981
						}#if end
4982
 
4983
					#反之
4984
					else{
4985
 
4986
						#加上TTL的字句
4987
						$str2write=$str2write."\t".$RR["update"];
4988
 
4989
						}#else end
4990
 
4991
					}#if end
4992
 
253 liveuser 4993
				#反之且該ZONE不具備 global TTL.
4994
				else if(!isset($result["defaultTTL"])){
249 liveuser 4995
 
4996
					#加上global TTL的字句
4997
					$str2write=$str2write."\t".$result["defaultTTL"];
4998
 
253 liveuser 4999
					}#if end
249 liveuser 5000
 
5001
				#加上IN跟TYPE跟value
5002
				$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
5003
 
5004
				}#else end
5005
 
5006
			#如果有註解
5007
			if(isset($RR["comment"])){
5008
 
5009
				#加上comment
5010
				$str2write=$str2write.";".$RR["comment"];
5011
 
5012
				}#if end
5013
 
253 liveuser 5014
			#如果要 debug
5015
			if($conf["debug"]==="true"){
249 liveuser 5016
 
253 liveuser 5017
				#函式說明:
5018
				#撰寫log
5019
				#回傳結果:
5020
				#$result["status"],狀態,"true"或"false".
5021
				#$result["error"],錯誤訊息陣列.
5022
				#$result["function"],當前函式的名稱.
5023
				#$result["argu"],使用的參數.
5024
				#$result["content"],要寫入log的內容字串.
5025
				#必填參數:
5026
				#$conf["path"],字串,log檔案的路徑與名稱.
5027
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5028
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5029
				$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
5030
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5031
				$conf["logs::record"]["fileArgu"]=__FILE__;
5032
				#可省略參數:
5033
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5034
				#$conf["rewrite"]="false";
5035
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5036
				#$conf["returnOnly"]="true";
5037
				#參考資料:
5038
				#無.
5039
				#備註:
5040
				#無.
5041
				$record=logs::record($conf["logs::record"]);
5042
				unset($conf["logs::record"]);
5043
 
5044
				}#if end
5045
 
249 liveuser 5046
			#加上要寫入的元素
5047
			$strs2write[]=$str2write;
5048
 
5049
			}#foreach end
5050
 
5051
		#如果有逐行註解
5052
		if(count($result["comment"])>0){
5053
 
5054
			#加到結尾
5055
			#函式說明:
5056
			#將多個一維陣列串聯起來,key從0開始排序.
5057
			#回傳的結果:
5058
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
5059
			#$result["error"],錯誤訊息陣列.
5060
			#$result["function"],當前執行的函數.
5061
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5062
			#$result["content"],合併好的一維陣列.
5063
			#必填參數
5064
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
5065
			$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
5066
			#可省略參數:
5067
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
5068
			#$conf["allowRepeat"]="true";
5069
			#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
5070
			#$conf["looseDiff"]="false";
5071
			#參考資料:
5072
			#無.
5073
			#備註:
5074
			#無.
5075
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
5076
			unset($conf["arrays::mergeArray"]);
5077
 
5078
			#如果執行異常
5079
			if($mergeArray["status"]==="false"){
5080
 
5081
				#設置錯誤識別
5082
				$result["status"]="false";
5083
 
5084
				#設置錯誤訊息
5085
				$result["error"]=$mergeArray;
5086
 
5087
				#回傳結果
5088
				return $result;
5089
 
5090
				}#if end
5091
 
5092
			#取得合併好的陣列
5093
			$strs2write=$mergeArray["content"];
5094
 
5095
			}#if end
5096
 
253 liveuser 5097
		#如果要 debug
5098
		if($conf["debug"]==="true"){
249 liveuser 5099
 
253 liveuser 5100
			#函式說明:
5101
			#撰寫log
5102
			#回傳結果:
5103
			#$result["status"],狀態,"true"或"false".
5104
			#$result["error"],錯誤訊息陣列.
5105
			#$result["function"],當前函式的名稱.
5106
			#$result["argu"],使用的參數.
5107
			#$result["content"],要寫入log的內容字串.
5108
			#必填參數:
5109
			#$conf["path"],字串,log檔案的路徑與名稱.
5110
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5111
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5112
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
5113
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5114
			$conf["logs::record"]["fileArgu"]=__FILE__;
5115
			#可省略參數:
5116
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5117
			#$conf["rewrite"]="false";
5118
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5119
			#$conf["returnOnly"]="true";
5120
			#參考資料:
5121
			#無.
5122
			#備註:
5123
			#無.
5124
			$record=logs::record($conf["logs::record"]);
5125
			unset($conf["logs::record"]);
5126
 
5127
			}#if end
5128
 
249 liveuser 5129
		#儲存新zone file每行的內容
5130
		$result["newZoneFileContent"]=$strs2write;
5131
 
5132
		#如果要寫入ZONE檔案
5133
		if($conf["writeNow"]==="true"){
5134
 
5135
			#覆寫 ZONE file
5136
			#函式說明:
5137
			#更新檔案的內容.
5138
			#回傳結果:
5139
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5140
			#$result["error"],錯誤訊息.
5141
			#$result["function"],當前執行的函數名稱.
5142
			#$result["content"],更新的資訊.
5143
			#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
5144
			#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
5145
			#必填參數:
5146
			#$conf["fileArgu"],字串,變數__FILE__的內容.
5147
			$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
5148
			#$conf["file"],字串,要更新的檔案位置與名稱.
5149
			$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
5150
			#可省略參數:
5151
			#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
5152
			$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
5153
			#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
5154
			#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
5155
			#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
5156
			#$conf["replaceLike"]="false";
5157
			#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
5158
			#$conf["addToTailWhenNoMatch"]="false";
5159
			#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
5160
			#$conf["addToTailBeforeThat"]="?\>";
5161
			#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
5162
			#$conf["replaceSpecifyLine"]=array();
5163
			#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
5164
			#$conf["outputPath"]="";
5165
			#參考資料:
5166
			#無.
5167
			#備註:
5168
			#無.
5169
			$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
5170
			unset($conf["fileAccess::updateFile"]);
5171
 
5172
			#如果執行異常
5173
			if($updateFile["status"]==="false"){
5174
 
5175
				#設置錯誤識別
5176
				$result["status"]="false";
5177
 
5178
				#設置錯誤訊息
5179
				$result["error"]=$updateFile;
5180
 
5181
				#回傳結果
5182
				return $result;
5183
 
5184
				}#if end
291 liveuser 5185
 
5186
			#修正 zone file 的權限
5187
			#函式說明:
5188
			#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
5189
			#回傳結果:
5190
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5191
			#$result["error"],錯誤訊息.
5192
			#$result["function"],當前執行的函式名稱.
5193
			#$result["cmd"],執行的指令.
5194
			#必填參數:
5195
			#$conf["owner"],字串,要變哪個使用者擁有.
5196
			$conf["cmd::chown"]["owner"]="root";
5197
			#$conf["target"],字串,需要變更擁有者、 群組的目標.
5198
			$conf["cmd::chown"]["target"]=$conf["dnsRecordFile"];
5199
			#可省略參數:
5200
			#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
5201
			$conf["cmd::chown"]["group"]=webUser;
5202
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
5203
			#$conf["recursive"]="true";
5204
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
5205
			#$conf["excludeSelf"]="true";
5206
			#參考資料:
5207
			#無.
5208
			#備註:
5209
			#無.
5210
			$chown=cmd::chown($conf["cmd::chown"]);
5211
			unset($conf["cmd::chown"]);
249 liveuser 5212
 
291 liveuser 5213
			#如果執行異常
5214
			if($chown["status"]==="false"){
5215
 
5216
				#設置錯誤識別
5217
				$result["status"]="false";
5218
 
5219
				#設置錯誤訊息
5220
				$result["error"]=$chown;
5221
 
5222
				#回傳結果
5223
				return $result;
5224
 
5225
				}#if end
5226
 
5227
			#函式說明:
5228
			#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
5229
			#回傳結果:
5230
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5231
			#$result["error"],錯誤訊息.
5232
			#$result["function"],當前執行的函式名稱.
5233
			#$result["cmd"],執行的指令.
5234
			#必填參數:
5235
			#$conf["mode"],字串,要變成什麼權限.
5236
			$conf["cmd::chmod"]["mode"]="774";
5237
			#$conf["target"],字串,需要變更權限的目標.
5238
			$conf["cmd::chmod"]["target"]=$conf["dnsRecordFile"];
5239
			#可省略參數:
5240
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
5241
			#$conf["recursive"]="true";
5242
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
5243
			#$conf["excludeSelf"]="true";
5244
			#參考資料:
5245
			#無.
5246
			#備註:
5247
			#無.
5248
			$chmod=cmd::chmod($conf["cmd::chmod"]);
5249
			unset($conf["cmd::chmod"]);
5250
 
5251
			#如果執行異常
5252
			if($chmod["status"]==="false"){
5253
 
5254
				#設置錯誤識別
5255
				$result["status"]="false";
5256
 
5257
				#設置錯誤訊息
5258
				$result["error"]=$chmod;
5259
 
5260
				#回傳結果
5261
				return $result;
5262
 
5263
				}#if end
5264
 
249 liveuser 5265
			}#if end
5266
 
5267
		#設置執行正常
5268
		$result["status"]="true";
5269
 
5270
		#回傳結果
5271
		return $result;
5272
 
5273
		}#function updateDnsRecordFile end
5274
 
5275
	/*
5276
	#函式說明:
255 liveuser 5277
	#請求驗證已經透過zerossl::createCertificate要求的domain.
249 liveuser 5278
	#回傳結果:
5279
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5280
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5281
	#$result["function"],當前執行的函式名稱.
5282
	#$result["argu"],所使用的參數.
5283
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 5284
	#$result["content"],結果json字串.
249 liveuser 5285
	#必填參數:
5286
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
5287
	$conf["id"]="";
5288
	#可省略參數:
5289
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5290
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5291
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5292
	#$conf["key"]=self::getApiInfo()["apiKey"];
5293
	#參考資料:
255 liveuser 5294
	#https://zerossl.com/documentation/api/verify-domains/
249 liveuser 5295
	#備註:
5296
	#無.
5297
	*/
5298
	public static function verifyDomain(&$conf){
5299
 
5300
		#初始化要回傳的結果
5301
		$result=array();
5302
 
5303
		#設置當其函數名稱
5304
		$result["function"]=__FUNCTION__;
5305
 
5306
		#如果 $conf 不為陣列
5307
		if(gettype($conf)!="array"){
5308
 
5309
			#設置執行失敗
5310
			$result["status"]="false";
5311
 
5312
			#設置執行錯誤訊息
5313
			$result["error"][]="\$conf變數須為陣列形態";
5314
 
5315
			#如果傳入的參數為 null
5316
			if($conf==null){
5317
 
5318
				#設置執行錯誤訊息
5319
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5320
 
5321
				}#if end
5322
 
5323
			#回傳結果
5324
			return $result;
5325
 
5326
			}#if end
5327
 
5328
		#取得參數
5329
		$result["argu"]=$conf;
5330
 
5331
		#檢查參數
5332
		#函式說明:
5333
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5334
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5335
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5336
		#$result["function"],當前執行的函式名稱.
5337
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5338
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5339
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5340
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5341
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5342
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5343
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5344
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5345
		#必填寫的參數:
5346
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5347
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5348
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5349
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5350
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5351
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5352
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5353
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5354
		#可以省略的參數:
5355
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5356
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5357
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5358
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5359
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5360
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
5361
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5362
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5363
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 5364
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
249 liveuser 5365
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5366
		#$conf["arrayCountEqualCheck"][]=array();
5367
		#參考資料來源:
5368
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5369
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5370
		unset($conf["variableCheck::checkArguments"]);
5371
 
5372
		#如果檢查失敗
5373
		if($checkArguments["status"]==="false"){
5374
 
5375
			#設置錯誤識別
5376
			$result["status"]="false";
5377
 
5378
			#設置錯誤訊息
5379
			$result["error"]=$checkArguments;
5380
 
5381
			#回傳結果
5382
			return $result;
5383
 
5384
			}#if end
5385
 
5386
		#如果檢查不通過
5387
		if($checkArguments["passed"]==="false"){
5388
 
5389
			#設置錯誤識別
5390
			$result["status"]="false";
5391
 
5392
			#設置錯誤訊息
5393
			$result["error"]=$checkArguments;
5394
 
5395
			#回傳結果
5396
			return $result;
5397
 
5398
			}#if end
5399
 
5400
		#要傳送的 key -> value
5401
		$postArray=array();
5402
 
5403
		#設置要簽署的domain
5404
		$postArray["validation_method"]="CNAME_CSR_HASH";
5405
 
5406
		#設置要傳送的 json
5407
		$postJson=json_encode($postArray);
5408
 
5409
		#函式說明:
5410
		#運行curl cmd
5411
		#回傳結果:
5412
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5413
		#$result["error"],錯誤訊息陣列.
5414
		#$result["function"],當前執行的函式名稱.
5415
		#$result["founded"],識別網址找不找得到.
5416
		#$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"代表程序的資訊.
5417
		#$result["fullContent"],取得回應的完整字串內容.
5418
		#$result["cookie"],cookie檔案的位置與名稱.
5419
		#$result["cmd"],執行的command.
5420
		#$result["argu],使用的參數.
5421
		#必填參數:
5422
		#$conf["url"],字串,目標url.
255 liveuser 5423
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
249 liveuser 5424
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5425
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5426
		#可省略參數:
5427
		#$conf["header"],字串陣列,要傳送的header.
5428
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5429
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5430
		#$conf["allowAnySSLcertificate"]="";
5431
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5432
		#$conf["postVar"]=array();
5433
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5434
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5435
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5436
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5437
		#$conf["agent"],字串,user agent的名稱.
5438
		#$conf["agent"]="";
5439
		#$conf["cookie"],字串,cookie位置與檔案位置.
5440
		#$conf["cookie"]="";
5441
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5442
		#$conf["forceNewCookie"]="";
5443
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5444
		#$conf["inBg"]="true";
5445
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5446
		#$conf["bgInProc"]="false";
5447
		#參考資料:
5448
		#無.
5449
		#備註:
5450
		#無.
5451
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5452
		unset($conf["catchWebContent::curlCmd"]);
5453
 
5454
		#如果異常
5455
		if($curlCmd["status"]==="false"){
5456
 
5457
			#設置錯誤識別
5458
			$result["status"]="false";
5459
 
5460
			#設置錯誤訊息
5461
			$result["error"]=$curlCmd;
5462
 
5463
			#回傳結果
5464
			return $result;
5465
 
5466
			}#if end
5467
 
5468
		#設置curl的詳細資訊
5469
		$result["curl_verbose_info"]=$curlCmd;
5470
 
255 liveuser 5471
		#驗證結果是否為 json
5472
		$json_validate=json_validate($curlCmd["fullContent"]);
5473
 
5474
		#如果回應不是 json
5475
		if(!$json_validate){
249 liveuser 5476
 
255 liveuser 5477
			#設置錯誤識別
5478
			$result["status"]="false";
5479
 
5480
			#設置錯誤訊息
5481
			$result["error"]=$curlCmd;
5482
 
5483
			#回傳結果
5484
			return $result;
5485
 
5486
			}#if end
5487
 
5488
		#設置json string結果
5489
		$result["content"]=$curlCmd["fullContent"];
5490
 
5491
		#解析json
5492
		$jsonRes=json_decode($result["content"]);
5493
 
293 liveuser 5494
		#如果有 success 資訊
5495
		if(isset($jsonRes->success)){
255 liveuser 5496
 
293 liveuser 5497
			#do nothing
5498
 
5499
			}#if end
5500
 
5501
		#反之如果沒有 status
5502
		else if(!isset($jsonRes->status)){
5503
 
255 liveuser 5504
			#設置錯誤識別
5505
			$result["status"]="false";
5506
 
5507
			#設置錯誤訊息
5508
			$result["error"]=$curlCmd;
5509
 
5510
			#回傳結果
5511
			return $result;
5512
 
5513
			}#if end
5514
 
293 liveuser 5515
		#反之有 status 資訊
5516
		else{
255 liveuser 5517
 
293 liveuser 5518
			#如果是 "pending_validation"
5519
			if($jsonRes->status==="pending_validation"){
255 liveuser 5520
 
293 liveuser 5521
				#do nothing
255 liveuser 5522
 
293 liveuser 5523
				}#if end
5524
 
5525
			#反之如果為 "issued"
5526
			else if($jsonRes->status==="issued"){
5527
 
5528
				#do nothing
5529
 
5530
				}#else 
5531
 
5532
			#反之
5533
			else{
5534
 
5535
				#設置錯誤識別
5536
				$result["status"]="false";
255 liveuser 5537
 
293 liveuser 5538
				#設置錯誤訊息
5539
				$result["error"]=$curlCmd;
255 liveuser 5540
 
293 liveuser 5541
				#回傳結果
5542
				return $result;
5543
 
5544
				}#else end
255 liveuser 5545
 
5546
			}#else end
5547
 
5548
		#設置執行正常
5549
		$result["status"]="true";
5550
 
5551
		#回傳結果
5552
		return $result;
5553
 
5554
		}#function verifyDomain end
5555
 
5556
	/*
5557
	#函式說明:
5558
	#取得CSR在zerossl上的狀態
5559
	#回傳結果:
5560
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5561
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5562
	#$result["function"],當前執行的函式名稱.
5563
	#$result["argu"],所使用的參數.
5564
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5565
	#$result["content"],結果json字串.
5566
	#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5567
	#必填參數:
5568
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
5569
	$conf["id"]="";
5570
	#可省略參數:
5571
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5572
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5573
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5574
	#$conf["key"]=self::getApiInfo()["apiKey"];
5575
	#參考資料:
5576
	#https://zerossl.com/documentation/api/get-certificate/
5577
	#備註:
5578
	#無.
5579
	*/
5580
	public static function getCertSta(&$conf){
5581
 
5582
		#初始化要回傳的結果
5583
		$result=array();
5584
 
5585
		#設置當其函數名稱
5586
		$result["function"]=__FUNCTION__;
5587
 
5588
		#如果 $conf 不為陣列
5589
		if(gettype($conf)!="array"){
5590
 
5591
			#設置執行失敗
5592
			$result["status"]="false";
5593
 
5594
			#設置執行錯誤訊息
5595
			$result["error"][]="\$conf變數須為陣列形態";
5596
 
5597
			#如果傳入的參數為 null
5598
			if($conf==null){
5599
 
5600
				#設置執行錯誤訊息
5601
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5602
 
5603
				}#if end
5604
 
5605
			#回傳結果
5606
			return $result;
5607
 
5608
			}#if end
5609
 
5610
		#取得參數
5611
		$result["argu"]=$conf;
291 liveuser 5612
 
5613
		#DEBUG
5614
		#var_dump(__LINE__,self::getApiInfo());exit;
255 liveuser 5615
 
5616
		#檢查參數
5617
		#函式說明:
5618
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5619
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5620
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5621
		#$result["function"],當前執行的函式名稱.
5622
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5623
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5624
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5625
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5626
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5627
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5628
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5629
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5630
		#必填寫的參數:
5631
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5632
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5633
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5634
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5635
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5636
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5637
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5638
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5639
		#可以省略的參數:
5640
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5641
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5642
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5643
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5644
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5645
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
5646
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5647
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5648
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5649
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
5650
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5651
		#$conf["arrayCountEqualCheck"][]=array();
5652
		#參考資料來源:
5653
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5654
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5655
		unset($conf["variableCheck::checkArguments"]);
5656
 
5657
		#如果檢查失敗
5658
		if($checkArguments["status"]==="false"){
5659
 
5660
			#設置錯誤識別
5661
			$result["status"]="false";
5662
 
5663
			#設置錯誤訊息
5664
			$result["error"]=$checkArguments;
5665
 
5666
			#回傳結果
5667
			return $result;
5668
 
5669
			}#if end
5670
 
5671
		#如果檢查不通過
5672
		if($checkArguments["passed"]==="false"){
5673
 
5674
			#設置錯誤識別
5675
			$result["status"]="false";
5676
 
5677
			#設置錯誤訊息
5678
			$result["error"]=$checkArguments;
5679
 
5680
			#回傳結果
5681
			return $result;
5682
 
5683
			}#if end
5684
 
5685
		#函式說明:
5686
		#運行curl cmd
5687
		#回傳結果:
5688
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5689
		#$result["error"],錯誤訊息陣列.
5690
		#$result["function"],當前執行的函式名稱.
5691
		#$result["founded"],識別網址找不找得到.
5692
		#$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"代表程序的資訊.
5693
		#$result["fullContent"],取得回應的完整字串內容.
5694
		#$result["cookie"],cookie檔案的位置與名稱.
5695
		#$result["cmd"],執行的command.
5696
		#$result["argu],使用的參數.
5697
		#必填參數:
5698
		#$conf["url"],字串,目標url.
5699
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
5700
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5701
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5702
		#可省略參數:
5703
		#$conf["header"],字串陣列,要傳送的header.
5704
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5705
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5706
		#$conf["allowAnySSLcertificate"]="";
5707
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5708
		#$conf["postVar"]=array();
5709
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5710
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5711
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5712
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5713
		#$conf["agent"],字串,user agent的名稱.
5714
		#$conf["agent"]="";
5715
		#$conf["cookie"],字串,cookie位置與檔案位置.
5716
		#$conf["cookie"]="";
5717
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5718
		#$conf["forceNewCookie"]="";
5719
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5720
		#$conf["inBg"]="true";
5721
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5722
		#$conf["bgInProc"]="false";
5723
		#參考資料:
5724
		#無.
5725
		#備註:
5726
		#無.
5727
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5728
		unset($conf["catchWebContent::curlCmd"]);
5729
 
5730
		#如果異常
5731
		if($curlCmd["status"]==="false"){
5732
 
5733
			#設置錯誤識別
5734
			$result["status"]="false";
5735
 
5736
			#設置錯誤訊息
5737
			$result["error"]=$curlCmd;
5738
 
5739
			#回傳結果
5740
			return $result;
5741
 
5742
			}#if end
5743
 
5744
		#設置curl的詳細資訊
5745
		$result["curl_verbose_info"]=$curlCmd;
5746
 
5747
		#驗證結果是否為 json
5748
		$json_validate=json_validate($curlCmd["fullContent"]);
5749
 
5750
		#如果回應不是 json
5751
		if(!$json_validate){
5752
 
5753
			#設置錯誤識別
5754
			$result["status"]="false";
5755
 
5756
			#設置錯誤訊息
5757
			$result["error"]=$curlCmd;
5758
 
5759
			#回傳結果
5760
			return $result;
5761
 
5762
			}#if end
5763
 
5764
		#設置json string結果
5765
		$result["content"]=$curlCmd["fullContent"];
5766
 
5767
		#解析json
5768
		$jsonRes=json_decode($result["content"]);
5769
 
5770
		#如果沒有 status
5771
		if(!isset($jsonRes->status)){
5772
 
5773
			#設置錯誤識別
5774
			$result["status"]="false";
5775
 
5776
			#設置錯誤訊息
5777
			$result["error"]=$curlCmd;
5778
 
5779
			#回傳結果
5780
			return $result;
5781
 
5782
			}#if end
5783
 
5784
		#取得csr在zerossl上的狀態
5785
		$result["cerStatus"]=$jsonRes->status;
5786
 
5787
		#設置執行正常
5788
		$result["status"]="true";
5789
 
5790
		#回傳結果
5791
		return $result;
5792
 
5793
		}#function getCertSta end
5794
 
5795
	/*
5796
	#函式說明:
5797
	#取得在zerossl上的CSR清單
5798
	#回傳結果:
5799
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5800
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5801
	#$result["function"],當前執行的函式名稱.
5802
	#$result["argu"],所使用的參數.
5803
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5804
	#$result["content"],結果json字串.
5805
	#$result["tCount"],總共的資料筆數.
5806
	#$result["count"],該頁的筆數.
5807
	#$result["page"],當前的頁碼.
5808
	#$result["certs"],陣列,certificates清單,key為certificate的id.
5809
	#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
5810
	#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
5811
	#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
5812
	#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
5813
	#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5814
	#必填參數:
5815
	#無
5816
	#可省略參數:
5817
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5818
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5819
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5820
	#$conf["key"]=self::getApiInfo()["apiKey"];
5821
	#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5822
	#$conf["cerStatus"]="";
309 liveuser 5823
	#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;"multiDomain90Days"多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
255 liveuser 5824
	#$conf["cerType"]="";
5825
	#$conf["search"],字串,透過certificate包含的domain來搜尋.
5826
	#$conf["search"]="";
5827
	#$conf["limit"],字串,一頁要多少筆,預設為100筆.
5828
	#$conf["limit"]="";
5829
	#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
5830
	#$conf["page"]="";
5831
	#參考資料:
5832
	#https://zerossl.com/documentation/api/list-certificates/
5833
	#備註:
5834
	#無.
5835
	*/
5836
	public static function getCertList(&$conf){
5837
 
5838
		#初始化要回傳的結果
5839
		$result=array();
5840
 
5841
		#設置當其函數名稱
5842
		$result["function"]=__FUNCTION__;
5843
 
5844
		#如果 $conf 不為陣列
5845
		if(gettype($conf)!="array"){
5846
 
5847
			#設置執行失敗
5848
			$result["status"]="false";
5849
 
5850
			#設置執行錯誤訊息
5851
			$result["error"][]="\$conf變數須為陣列形態";
5852
 
5853
			#如果傳入的參數為 null
5854
			if($conf==null){
5855
 
5856
				#設置執行錯誤訊息
5857
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5858
 
5859
				}#if end
5860
 
5861
			#回傳結果
5862
			return $result;
5863
 
5864
			}#if end
5865
 
5866
		#取得參數
5867
		$result["argu"]=$conf;
5868
 
5869
		#檢查參數
5870
		#函式說明:
5871
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5872
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5873
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5874
		#$result["function"],當前執行的函式名稱.
5875
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5876
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5877
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5878
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5879
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5880
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5881
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5882
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5883
		#必填寫的參數:
5884
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5885
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5886
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5887
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5888
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5889
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5890
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5891
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5892
		#可以省略的參數:
5893
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5894
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5895
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5896
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5897
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5898
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
5899
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5900
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
5901
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5902
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
5903
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5904
		#$conf["arrayCountEqualCheck"][]=array();
5905
		#參考資料來源:
5906
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5907
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5908
		unset($conf["variableCheck::checkArguments"]);
5909
 
5910
		#如果檢查失敗
5911
		if($checkArguments["status"]==="false"){
5912
 
5913
			#設置錯誤識別
5914
			$result["status"]="false";
5915
 
5916
			#設置錯誤訊息
5917
			$result["error"]=$checkArguments;
5918
 
5919
			#回傳結果
5920
			return $result;
5921
 
5922
			}#if end
5923
 
5924
		#如果檢查不通過
5925
		if($checkArguments["passed"]==="false"){
5926
 
5927
			#設置錯誤識別
5928
			$result["status"]="false";
5929
 
5930
			#設置錯誤訊息
5931
			$result["error"]=$checkArguments;
5932
 
5933
			#回傳結果
5934
			return $result;
5935
 
5936
			}#if end
5937
 
5938
		#預設網址
291 liveuser 5939
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."?access_key=".$conf["key"];
255 liveuser 5940
 
5941
		#如果有設置 cerStatus
5942
		if(isset($conf["cerStatus"])){
5943
 
5944
			#設置 certificate_status 
291 liveuser 5945
			$url=$url."&certificate_status=".urlencode($conf["cerStatus"]);
255 liveuser 5946
 
5947
			}#if end
5948
 
5949
		#如果有設置 cerType
5950
		if(isset($conf["cerType"])){
5951
 
5952
			#設置 certificate_type
291 liveuser 5953
			$url=$url."&certificate_type=".urlencode($conf["cerType"]);
255 liveuser 5954
 
5955
			}#if end
5956
 
5957
		#如果有設置 search
5958
		if(isset($conf["search"])){
5959
 
5960
			#設置 search
291 liveuser 5961
			$url=$url."&search=".urlencode($conf["search"]);
255 liveuser 5962
 
5963
			}#if end
5964
 
5965
		#如果有設置 limit
5966
		if(isset($conf["limit"])){
5967
 
5968
			#設置 search
291 liveuser 5969
			$url=$url."&limit=".urlencode($conf["limit"]);
255 liveuser 5970
 
5971
			}#if end
5972
 
5973
		#如果有設置 page
5974
		if(isset($conf["page"])){
5975
 
5976
			#設置 search
291 liveuser 5977
			$url=$url."&"."page=".urlencode($conf["page"]);
255 liveuser 5978
 
5979
			}#if end
5980
 
5981
		#函式說明:
5982
		#運行curl cmd
5983
		#回傳結果:
5984
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5985
		#$result["error"],錯誤訊息陣列.
5986
		#$result["function"],當前執行的函式名稱.
5987
		#$result["founded"],識別網址找不找得到.
5988
		#$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"代表程序的資訊.
5989
		#$result["fullContent"],取得回應的完整字串內容.
5990
		#$result["cookie"],cookie檔案的位置與名稱.
5991
		#$result["cmd"],執行的command.
5992
		#$result["argu],使用的參數.
5993
		#必填參數:
5994
		#$conf["url"],字串,目標url.
5995
		$conf["catchWebContent::curlCmd"]["url"]=$url;
5996
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5997
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5998
		#可省略參數:
5999
		#$conf["header"],字串陣列,要傳送的header.
6000
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
6001
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6002
		#$conf["allowAnySSLcertificate"]="";
6003
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6004
		#$conf["postVar"]=array();
6005
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6006
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6007
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
6008
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
6009
		#$conf["agent"],字串,user agent的名稱.
6010
		#$conf["agent"]="";
6011
		#$conf["cookie"],字串,cookie位置與檔案位置.
6012
		#$conf["cookie"]="";
6013
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6014
		#$conf["forceNewCookie"]="";
6015
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6016
		#$conf["inBg"]="true";
6017
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6018
		#$conf["bgInProc"]="false";
6019
		#參考資料:
6020
		#無.
6021
		#備註:
6022
		#無.
6023
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6024
		unset($conf["catchWebContent::curlCmd"]);
6025
 
6026
		#如果異常
6027
		if($curlCmd["status"]==="false"){
6028
 
6029
			#設置錯誤識別
6030
			$result["status"]="false";
6031
 
6032
			#設置錯誤訊息
6033
			$result["error"]=$curlCmd;
6034
 
6035
			#回傳結果
6036
			return $result;
6037
 
6038
			}#if end
6039
 
6040
		#設置curl的詳細資訊
6041
		$result["curl_verbose_info"]=$curlCmd;
6042
 
6043
		#驗證結果是否為 json
6044
		$json_validate=json_validate($curlCmd["fullContent"]);
6045
 
6046
		#如果回應不是 json
6047
		if(!$json_validate){
6048
 
6049
			#設置錯誤識別
6050
			$result["status"]="false";
6051
 
6052
			#設置錯誤訊息
6053
			$result["error"]=$curlCmd;
6054
 
6055
			#回傳結果
6056
			return $result;
6057
 
6058
			}#if end
6059
 
6060
		#設置json string結果
6061
		$result["content"]=$curlCmd["fullContent"];
6062
 
6063
		/* json response 範例
6064
		{
6065
			"total_count": 11,
6066
			"result_count": 10,
6067
			"page": 1,
6068
			"limit": 10,
6069
			"acmeUsageLevel": "LOW",
6070
			"isAcmeLocked": false,
6071
			"results": 
6072
			[
6073
				{
6074
					"id": "a856a39a1c3ad0s8asa606g37667d221",
6075
					"type": "1",
6076
					"common_name": "domain.com",
6077
					"additional_domains": "www.domain.com",
6078
					"created": "2020-04-29 09:04:19",
6079
					"expires": "2020-07-28 00:00:00",
6080
					"status": "draft",
6081
					"validation_type": null,
6082
					"validation_emails": null,
6083
					"replacement_for": "",
6084
					"fingerprint_sha1": null,
6085
					"brand_validation": null,
6086
					"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
6087
					"validation":
6088
					{
6089
						"email_validation":
6090
						{
6091
							"domain.com":
6092
							[
6093
								"admin@domain.com",
6094
								"administrator@domain.com",
6095
								"hostmaster@domain.com",
6096
								"postmaster@domain.com",
6097
								"webmaster@domain.com"
6098
							]
6099
						},
6100
						"other_methods": 
6101
						{
6102
							"domain.com":
6103
							{
6104
								"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
6105
								"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
6106
								"file_validation_content":
6107
								[
6108
									"2B449B722B449B729394793947",
6109
									"comodoca.com",
6110
									"4bad7360c7076ba"
6111
								],
6112
								"cname_validation_p1": "2B449B7293947.domain.com",
6113
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
6114
							},
6115
							"www.domain.com":
6116
							{
6117
								"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
6118
								"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",   
6119
								"file_validation_content":
6120
								[
6121
									"2B449B722B449B729394793947",
6122
									"comodoca.com",
6123
									"4bad7360c7076ba"
6124
								],
6125
								"cname_validation_p1": "2B449B7293947.www.domain.com",
6126
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
6127
							}
6128
						}
6129
					}
6130
				},
6131
				{
6132
					...
6133
				}
6134
			]
6135
		}
249 liveuser 6136
		*/
6137
 
255 liveuser 6138
		#解析json
6139
		$jsonRes=json_decode($result["content"]);
6140
 
6141
		#總共的資料筆數
6142
		$result["tCount"]=$jsonRes->total_count;
6143
 
6144
		#取得該頁的筆數
6145
		$result["count"]=$jsonRes->result_count;
6146
 
6147
		#取得certificate清單
291 liveuser 6148
		$certs=$jsonRes->results;
255 liveuser 6149
 
6150
		#針對每個certificate
6151
		foreach($certs as $index => $cert){
6152
 
6153
			#初始化暫存的陣列
6154
			$tmpA=array();
6155
 
6156
			#儲存 cert id
6157
			#$tmpA["id"]=$cert->id;
6158
 
6159
			#儲存 主要包含的 domain name
6160
			$tmpA["cname"]=$cert->common_name;
6161
 
6162
			#儲存額外包含的 domain name
6163
			$tmpA["anames"]=$cert->additional_domains;
6164
 
6165
			#最後有效年月日,格式為"2020-07-28 00:00:00".
6166
			$tmpA["expiresYMD"]=$cert->expires;
6167
 
6168
			#產生對於當前系統時間的差距(秒數)
6169
			#函式說明:
6170
			#計算時間點距離1970/01/01多少秒,亦即unixtime.
6171
			#回傳結果:
6172
			#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
6173
			#$result["error"],錯誤訊息陣列.
6174
			#$result["content"],時間點距離1970/01/01的多少秒.
6175
			#$result["argu"],使用的參數.
6176
			#$result["unixtime"],執行本函式時的unixtime.
6177
			#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
6178
			#必填參數:
6179
			#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
6180
			$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
6181
			#可省略參數:
6182
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
6183
			#$conf["UTC"]="false";
6184
			#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
6185
			$conf["time::caculateTimeAmount"]["replace0"]="false";
6186
			#參考資料:
6187
			#無.
6188
			#備註:
6189
			#無.
6190
			$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
6191
			unset($conf["time::caculateTimeAmount"]);
6192
 
6193
			#如果執行異常
291 liveuser 6194
			if($caculateTimeAmount["status"]==="false"){
255 liveuser 6195
 
6196
				#設置錯誤識別
6197
				$result["status"]="false";
6198
 
6199
				#設置錯誤訊息
6200
				$result["error"]=$caculateTimeAmount;
6201
 
6202
				#回傳結果
6203
				return $result;
6204
 
6205
				}#if end
6206
 
6207
			#儲存還要多少秒要過期
291 liveuser 6208
			$tmpA["expiresIn"]=$caculateTimeAmount["content"]-time();
255 liveuser 6209
 
6210
			#憑證的狀態
6211
			$tmpA["status"]=$cert->status;
6212
 
291 liveuser 6213
			#儲存要回傳的 certs 清單,key為cert的id.
6214
			$result["certs"][$cert->id]=$tmpA;
255 liveuser 6215
 
6216
			}#foreach end
6217
 
6218
		#設置執行正常
6219
		$result["status"]="true";
6220
 
6221
		#回傳結果
6222
		return $result;
6223
 
6224
		}#function getCertList end
6225
 
6226
	/*
6227
	#函式說明:
6228
	#下載certificate.
6229
	#回傳結果:
6230
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6231
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6232
	#$result["function"],當前執行的函式名稱.
6233
	#$result["argu"],所使用的參數.
6234
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6235
	#$result["content"],結果json字串.
6236
	#$result["certificate.crt"],字串,certificate.crt的內容.
6237
	#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
6238
	#必填參數:
6239
	#無.
6240
	#可省略參數:
6241
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6242
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6243
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6244
	#$conf["key"]=self::getApiInfo()["apiKey"];
6245
	#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
6246
	#$conf["id"]="";
6247
	#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
6248
	#$conf["cname"]="";
6249
	#參考資料:
6250
	#https://zerossl.com/documentation/api/download-certificate-inline/
6251
	#備註:
6252
	#無.
6253
	*/
6254
	public static function getCert(&$conf){
6255
 
6256
		#初始化要回傳的結果
6257
		$result=array();
6258
 
6259
		#設置當其函數名稱
6260
		$result["function"]=__FUNCTION__;
6261
 
6262
		#如果 $conf 不為陣列
6263
		if(gettype($conf)!="array"){
6264
 
6265
			#設置執行失敗
6266
			$result["status"]="false";
6267
 
6268
			#設置執行錯誤訊息
6269
			$result["error"][]="\$conf變數須為陣列形態";
6270
 
6271
			#如果傳入的參數為 null
6272
			if($conf==null){
6273
 
6274
				#設置執行錯誤訊息
6275
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6276
 
6277
				}#if end
6278
 
6279
			#回傳結果
6280
			return $result;
6281
 
6282
			}#if end
6283
 
6284
		#取得參數
6285
		$result["argu"]=$conf;
6286
 
6287
		#檢查參數
6288
		#函式說明:
6289
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6290
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6291
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6292
		#$result["function"],當前執行的函式名稱.
6293
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6294
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6295
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6296
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6297
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6298
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6299
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6300
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6301
		#必填寫的參數:
6302
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6303
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6304
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6305
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6306
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6307
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6308
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6309
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6310
		#可以省略的參數:
6311
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6312
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6313
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6314
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6315
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6316
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
6317
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6318
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
6319
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6320
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
6321
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6322
		#$conf["arrayCountEqualCheck"][]=array();
6323
		#參考資料來源:
6324
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6325
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6326
		unset($conf["variableCheck::checkArguments"]);
6327
 
6328
		#如果檢查失敗
6329
		if($checkArguments["status"]==="false"){
6330
 
6331
			#設置錯誤識別
6332
			$result["status"]="false";
6333
 
6334
			#設置錯誤訊息
6335
			$result["error"]=$checkArguments;
6336
 
6337
			#回傳結果
6338
			return $result;
6339
 
6340
			}#if end
6341
 
6342
		#如果檢查不通過
6343
		if($checkArguments["passed"]==="false"){
6344
 
6345
			#設置錯誤識別
6346
			$result["status"]="false";
6347
 
6348
			#設置錯誤訊息
6349
			$result["error"]=$checkArguments;
6350
 
6351
			#回傳結果
6352
			return $result;
6353
 
6354
			}#if end
6355
 
6356
		#如果有設置 id
6357
		if(isset($conf["id"])){
6358
 
6359
			#設置 id
6360
			$id=$conf["id"];
6361
 
6362
			}#if end
6363
 
6364
		#反之如果有設置 cname
6365
		else if(isset($conf["cname"])){
6366
 
6367
			#函式說明:
6368
			#取得在zerossl上的CSR清單
6369
			#回傳結果:
6370
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6371
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
6372
			#$result["function"],當前執行的函式名稱.
6373
			#$result["argu"],所使用的參數.
6374
			#$result["curl_verbose_info"],curl執行的詳細資訊.
6375
			#$result["content"],結果json字串.
6376
			#$result["tCound"],總共的資料筆數.
6377
			#$result["count"],該頁的筆數.
6378
			#$result["page"],當前的頁碼.
6379
			#$result["certs"],陣列,certificates清單,key為certificate的id.
6380
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
6381
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
6382
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
6383
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6384
			#必填參數:
6385
			#無
6386
			#可省略參數:
6387
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6388
			#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6389
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6390
			#$conf["key"]=self::getApiInfo()["apiKey"];
6391
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6392
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
6393
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
6394
			#$conf["cerType"]="";
6395
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
6396
			$conf["zerossl::getCertList"]["search"]=$conf["cname"];
6397
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
6398
			#$conf["limit"]="";
6399
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
6400
			#$conf["page"]="";
6401
			#參考資料:
6402
			#https://zerossl.com/documentation/api/get-certificate/
6403
			#備註:
6404
			#無.
6405
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
6406
			unset($conf["zerossl::getCertList"]);
6407
 
6408
			#如果檢查失敗
6409
			if($getCertList["status"]==="false"){
6410
 
6411
				#設置錯誤識別
6412
				$result["status"]="false";
6413
 
6414
				#設置錯誤訊息
6415
				$result["error"]=$getCertList;
6416
 
6417
				#回傳結果
6418
				return $result;
6419
 
6420
				}#if end
6421
 
6422
			#如果資料筆數大於0
6423
			if($getCertList["count"]>0){
6424
 
6425
				#取得第一筆
6426
				foreach($getCertList["certs"] as $cerId => $detail){
6427
 
6428
					#取得cettificate id
6429
					$id=$cerId;
6430
 
6431
					}#foreach end
6432
 
6433
				}#if end
6434
 
6435
			}#if end
6436
 
6437
		#預設網址
6438
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
6439
 
6440
		#函式說明:
6441
		#運行curl cmd
6442
		#回傳結果:
6443
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6444
		#$result["error"],錯誤訊息陣列.
6445
		#$result["function"],當前執行的函式名稱.
6446
		#$result["founded"],識別網址找不找得到.
6447
		#$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"代表程序的資訊.
6448
		#$result["fullContent"],取得回應的完整字串內容.
6449
		#$result["cookie"],cookie檔案的位置與名稱.
6450
		#$result["cmd"],執行的command.
6451
		#$result["argu],使用的參數.
6452
		#必填參數:
6453
		#$conf["url"],字串,目標url.
6454
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6455
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6456
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6457
		#可省略參數:
6458
		#$conf["header"],字串陣列,要傳送的header.
6459
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
6460
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6461
		#$conf["allowAnySSLcertificate"]="";
6462
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6463
		#$conf["postVar"]=array();
6464
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6465
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6466
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
6467
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
6468
		#$conf["agent"],字串,user agent的名稱.
6469
		#$conf["agent"]="";
6470
		#$conf["cookie"],字串,cookie位置與檔案位置.
6471
		#$conf["cookie"]="";
6472
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6473
		#$conf["forceNewCookie"]="";
6474
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6475
		#$conf["inBg"]="true";
6476
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6477
		#$conf["bgInProc"]="false";
6478
		#參考資料:
6479
		#無.
6480
		#備註:
6481
		#無.
6482
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6483
		unset($conf["catchWebContent::curlCmd"]);
6484
 
6485
		#如果異常
6486
		if($curlCmd["status"]==="false"){
6487
 
6488
			#設置錯誤識別
6489
			$result["status"]="false";
6490
 
6491
			#設置錯誤訊息
6492
			$result["error"]=$curlCmd;
6493
 
6494
			#回傳結果
6495
			return $result;
6496
 
6497
			}#if end
6498
 
6499
		#設置curl的詳細資訊
6500
		$result["curl_verbose_info"]=$curlCmd;
6501
 
249 liveuser 6502
		#驗證結果是否為 json
6503
		$json_validate=json_validate($curlCmd["fullContent"]);
6504
 
6505
		#如果回應不是 json
6506
		if(!$json_validate){
6507
 
6508
			#設置錯誤識別
6509
			$result["status"]="false";
6510
 
6511
			#設置錯誤訊息
6512
			$result["error"]=$curlCmd;
6513
 
6514
			#回傳結果
6515
			return $result;
6516
 
6517
			}#if end
6518
 
6519
		#設置json string結果
6520
		$result["content"]=$curlCmd["fullContent"];
255 liveuser 6521
 
6522
		#取得 json
6523
		$json=json_decode($curlCmd["fullContent"]);
6524
 
291 liveuser 6525
		#儲存成變數以便透過object呼叫
6526
		$c_crt="certificate.crt";
6527
 
6528
		#儲存成變數以便透過object呼叫
6529
		$ca_crt="ca_bundle.crt";
6530
 
294 liveuser 6531
		#如果沒有該有的 certificate.crt 跟 ca_bundle.crt 物件
6532
		if(!isset($json->$c_crt) || !isset($json->$ca_crt)){
6533
 
6534
			#設置錯誤識別
6535
			$result["status"]="false";
6536
 
6537
			#設置錯誤訊息
6538
			$result["error"]=$json;
6539
 
6540
			#回傳結果
6541
			return $result;
6542
 
6543
			}#if end
6544
 
255 liveuser 6545
		#取得certificate.crt的內容
291 liveuser 6546
		$result["certificate.crt"]=$json->$c_crt;
255 liveuser 6547
 
6548
		#取得ca_bundle.crt的內容
291 liveuser 6549
		$result["ca_bundle.crt"]=$json->$ca_crt;
255 liveuser 6550
 
6551
		#設置執行正常
6552
		$result["status"]="true";
6553
 
6554
		#回傳結果
6555
		return $result;
6556
 
6557
		}#function getCert end
6558
 
6559
	/*
6560
	#函式說明:
6561
	#請求廢除 issued zerossl certificate.
6562
	#回傳結果:
6563
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6564
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6565
	#$result["function"],當前執行的函式名稱.
6566
	#$result["argu"],所使用的參數.
6567
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6568
	#$result["content"],結果json字串.
341 liveuser 6569
	#$result["busy"],若content結果含有busy屬性,且為1,則為"true";反之為"false".
255 liveuser 6570
	#必填參數:
6571
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
6572
	$conf["id"]="";
6573
	#可省略參數:
6574
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6575
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6576
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6577
	#$conf["key"]=self::getApiInfo()["apiKey"];
6578
	#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
6579
	#$conf["reason"]="";
6580
	#參考資料:
6581
	#https://zerossl.com/documentation/api/revoke-certificate/
6582
	#備註:
338 liveuser 6583
	#跟api頁面的描述不同,access_key參數實際上要用get方式傳遞.
341 liveuser 6584
	#跟api頁面的描述不同,api point忙碌中,無法回應時,回應會為空.
255 liveuser 6585
	*/
6586
	public static function revokeCert(&$conf){
6587
 
6588
		#初始化要回傳的結果
6589
		$result=array();
249 liveuser 6590
 
255 liveuser 6591
		#設置當其函數名稱
6592
		$result["function"]=__FUNCTION__;
6593
 
6594
		#如果 $conf 不為陣列
6595
		if(gettype($conf)!="array"){
6596
 
6597
			#設置執行失敗
6598
			$result["status"]="false";
6599
 
6600
			#設置執行錯誤訊息
6601
			$result["error"][]="\$conf變數須為陣列形態";
6602
 
6603
			#如果傳入的參數為 null
6604
			if($conf==null){
6605
 
6606
				#設置執行錯誤訊息
6607
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6608
 
6609
				}#if end
6610
 
6611
			#回傳結果
6612
			return $result;
6613
 
6614
			}#if end
6615
 
6616
		#取得參數
6617
		$result["argu"]=$conf;
6618
 
6619
		#檢查參數
6620
		#函式說明:
6621
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6622
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6623
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6624
		#$result["function"],當前執行的函式名稱.
6625
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6626
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6627
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6628
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6629
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6630
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6631
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6632
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6633
		#必填寫的參數:
6634
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6635
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6636
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6637
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6638
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6639
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6640
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6641
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6642
		#可以省略的參數:
6643
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6644
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6645
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6646
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6647
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6648
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
6649
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
334 liveuser 6650
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
255 liveuser 6651
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6652
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
6653
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6654
		#$conf["arrayCountEqualCheck"][]=array();
6655
		#參考資料來源:
6656
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6657
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6658
		unset($conf["variableCheck::checkArguments"]);
6659
 
6660
		#如果檢查失敗
6661
		if($checkArguments["status"]==="false"){
6662
 
6663
			#設置錯誤識別
6664
			$result["status"]="false";
6665
 
6666
			#設置錯誤訊息
6667
			$result["error"]=$checkArguments;
6668
 
6669
			#回傳結果
6670
			return $result;
6671
 
6672
			}#if end
6673
 
6674
		#如果檢查不通過
6675
		if($checkArguments["passed"]==="false"){
6676
 
6677
			#設置錯誤識別
6678
			$result["status"]="false";
6679
 
6680
			#設置錯誤訊息
6681
			$result["error"]=$checkArguments;
6682
 
6683
			#回傳結果
6684
			return $result;
6685
 
6686
			}#if end
6687
 
338 liveuser 6688
		#url to call,含api key,跟 api 頁面不一致.
6689
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
255 liveuser 6690
 
337 liveuser 6691
		#初始化要post的變數陣列
6692
		$postVar=array();
6693
 
338 liveuser 6694
		#設置  api key,跟 api 頁面不一致.
6695
		#$postVar["access_key"]=$conf["key"];
337 liveuser 6696
 
255 liveuser 6697
		#如果有設置 reason
6698
		if(isset($conf["reason"])){
6699
 
6700
			#設置reason
337 liveuser 6701
			$postVar["reason"]=$conf["reason"];
255 liveuser 6702
 
6703
			}#if end
337 liveuser 6704
 
255 liveuser 6705
		#函式說明:
6706
		#運行curl cmd
6707
		#回傳結果:
6708
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6709
		#$result["error"],錯誤訊息陣列.
6710
		#$result["function"],當前執行的函式名稱.
6711
		#$result["founded"],識別網址找不找得到.
6712
		#$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"代表程序的資訊.
6713
		#$result["fullContent"],取得回應的完整字串內容.
6714
		#$result["cookie"],cookie檔案的位置與名稱.
6715
		#$result["cmd"],執行的command.
6716
		#$result["argu],使用的參數.
6717
		#必填參數:
6718
		#$conf["url"],字串,目標url.
6719
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6720
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6721
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6722
		#可省略參數:
6723
		#$conf["header"],字串陣列,要傳送的header.
338 liveuser 6724
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
255 liveuser 6725
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6726
		#$conf["allowAnySSLcertificate"]="";
338 liveuser 6727
 
6728
		#如果有資料
6729
		if(!empty($postVar)){
6730
 
6731
			#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6732
			$conf["catchWebContent::curlCmd"]["postVar"]=$postVar;
6733
 
6734
			}#if end
6735
 
255 liveuser 6736
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6737
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6738
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
338 liveuser 6739
		$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
255 liveuser 6740
		#$conf["agent"],字串,user agent的名稱.
6741
		#$conf["agent"]="";
6742
		#$conf["cookie"],字串,cookie位置與檔案位置.
6743
		#$conf["cookie"]="";
6744
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6745
		#$conf["forceNewCookie"]="";
6746
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6747
		#$conf["inBg"]="true";
6748
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6749
		#$conf["bgInProc"]="false";
6750
		#參考資料:
6751
		#無.
6752
		#備註:
6753
		#無.
6754
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6755
		unset($conf["catchWebContent::curlCmd"]);
6756
 
6757
		#如果異常
6758
		if($curlCmd["status"]==="false"){
6759
 
6760
			#設置錯誤識別
6761
			$result["status"]="false";
6762
 
6763
			#設置錯誤訊息
6764
			$result["error"]=$curlCmd;
6765
 
6766
			#回傳結果
6767
			return $result;
6768
 
6769
			}#if end
6770
 
6771
		#設置curl的詳細資訊
6772
		$result["curl_verbose_info"]=$curlCmd;
6773
 
341 liveuser 6774
		#如果 server 的回應為空
6775
		if(empty($curlCmd["fullContent"])){
6776
 
6777
			#初始化json回應
6778
			$jsonRes=array();
6779
 
6780
			#設置不成功
6781
			$jsonRes["success"]=0;
6782
 
6783
			#設置server忙碌中,贊述無法處理要求.
6784
			$jsonRes["busy"]=1;
6785
 
6786
			#設置json結果
6787
			$curlCmd["fullContent"]=json_encode($jsonRes);
6788
 
6789
			}#if end
6790
 
255 liveuser 6791
		#驗證結果是否為 json
6792
		$json_validate=json_validate($curlCmd["fullContent"]);
6793
 
6794
		#如果回應不是 json
6795
		if(!$json_validate){
6796
 
6797
			#設置錯誤識別
6798
			$result["status"]="false";
6799
 
6800
			#設置錯誤訊息
6801
			$result["error"]=$curlCmd;
6802
 
6803
			#回傳結果
6804
			return $result;
6805
 
6806
			}#if end
341 liveuser 6807
 
255 liveuser 6808
		#設置json string結果
6809
		$result["content"]=$curlCmd["fullContent"];
6810
 
249 liveuser 6811
		#解析json
6812
		$jsonRes=json_decode($result["content"]);
6813
 
255 liveuser 6814
		#如果沒有要有的attr
6815
		if(!isset($jsonRes->success)){
6816
 
6817
			#設置錯誤識別
6818
			$result["status"]="false";
6819
 
6820
			#設置錯誤訊息
6821
			$result["error"]=$curlCmd;
6822
 
6823
			#回傳結果
6824
			return $result;
6825
 
6826
			}#if end
341 liveuser 6827
 
255 liveuser 6828
		#如果 success 不等於 1
6829
		if($jsonRes->success!==1){
6830
 
341 liveuser 6831
			#如果有 busy 屬性
6832
			if(isset($jsonRes->busy)){
6833
 
6834
				#如果busy為1
6835
				if($jsonRes->busy===1){
6836
 
6837
					#設置sever忙碌中,無法回應.
6838
					$result["busy"]="true";
6839
 
6840
					}#if end
6841
 
6842
				}#if end
6843
 
255 liveuser 6844
			#設置錯誤識別
6845
			$result["status"]="false";
6846
 
6847
			#設置錯誤訊息
6848
			$result["error"]=$curlCmd;
6849
 
6850
			#回傳結果
6851
			return $result;
6852
 
6853
			}#if end
6854
 
341 liveuser 6855
		#如果回應結果不含busy元素
6856
		if(!isset($result["busy"])){
6857
 
6858
			#設置其為"false",代表server沒有忙碌中,無法回應.
6859
			$result["busy"]="false";
6860
 
6861
			}#else end
6862
 
249 liveuser 6863
		#設置執行正常
6864
		$result["status"]="true";
6865
 
6866
		#回傳結果
6867
		return $result;
6868
 
255 liveuser 6869
		}#function revokeCert end
6870
 
6871
	/*
6872
	#函式說明:
6873
	#請求取消 draft or unvalidated zerossl certificate.
6874
	#回傳結果:
6875
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6876
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6877
	#$result["function"],當前執行的函式名稱.
6878
	#$result["argu"],所使用的參數.
6879
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6880
	#$result["content"],結果json字串.
6881
	#必填參數:
6882
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
6883
	$conf["id"]="";
6884
	#可省略參數:
6885
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6886
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6887
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6888
	#$conf["key"]=self::getApiInfo()["apiKey"];
6889
	#參考資料:
6890
	#https://zerossl.com/documentation/api/revoke-certificate/
6891
	#備註:
6892
	#無.
6893
	*/
6894
	public static function cancelCert(&$conf){
6895
 
6896
		#初始化要回傳的結果
6897
		$result=array();
249 liveuser 6898
 
255 liveuser 6899
		#設置當其函數名稱
6900
		$result["function"]=__FUNCTION__;
6901
 
6902
		#如果 $conf 不為陣列
6903
		if(gettype($conf)!="array"){
6904
 
6905
			#設置執行失敗
6906
			$result["status"]="false";
6907
 
6908
			#設置執行錯誤訊息
6909
			$result["error"][]="\$conf變數須為陣列形態";
6910
 
6911
			#如果傳入的參數為 null
6912
			if($conf==null){
6913
 
6914
				#設置執行錯誤訊息
6915
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6916
 
6917
				}#if end
6918
 
6919
			#回傳結果
6920
			return $result;
6921
 
6922
			}#if end
6923
 
6924
		#取得參數
6925
		$result["argu"]=$conf;
6926
 
6927
		#檢查參數
6928
		#函式說明:
6929
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6930
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6931
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6932
		#$result["function"],當前執行的函式名稱.
6933
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6934
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6935
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6936
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6937
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6938
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6939
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6940
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6941
		#必填寫的參數:
6942
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6943
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6944
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6945
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6946
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6947
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6948
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6949
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6950
		#可以省略的參數:
6951
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6952
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6953
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6954
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6955
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6956
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
6957
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6958
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
6959
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6960
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
6961
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6962
		#$conf["arrayCountEqualCheck"][]=array();
6963
		#參考資料來源:
6964
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6965
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6966
		unset($conf["variableCheck::checkArguments"]);
6967
 
6968
		#如果檢查失敗
6969
		if($checkArguments["status"]==="false"){
6970
 
6971
			#設置錯誤識別
6972
			$result["status"]="false";
6973
 
6974
			#設置錯誤訊息
6975
			$result["error"]=$checkArguments;
6976
 
6977
			#回傳結果
6978
			return $result;
6979
 
6980
			}#if end
6981
 
6982
		#如果檢查不通過
6983
		if($checkArguments["passed"]==="false"){
6984
 
6985
			#設置錯誤識別
6986
			$result["status"]="false";
6987
 
6988
			#設置錯誤訊息
6989
			$result["error"]=$checkArguments;
6990
 
6991
			#回傳結果
6992
			return $result;
6993
 
6994
			}#if end
6995
 
6996
		#url to call
6997
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
6998
 
6999
		#函式說明:
7000
		#運行curl cmd
7001
		#回傳結果:
7002
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7003
		#$result["error"],錯誤訊息陣列.
7004
		#$result["function"],當前執行的函式名稱.
7005
		#$result["founded"],識別網址找不找得到.
7006
		#$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"代表程序的資訊.
7007
		#$result["fullContent"],取得回應的完整字串內容.
7008
		#$result["cookie"],cookie檔案的位置與名稱.
7009
		#$result["cmd"],執行的command.
7010
		#$result["argu],使用的參數.
7011
		#必填參數:
7012
		#$conf["url"],字串,目標url.
7013
		$conf["catchWebContent::curlCmd"]["url"]=$url;
7014
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7015
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7016
		#可省略參數:
7017
		#$conf["header"],字串陣列,要傳送的header.
7018
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7019
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7020
		#$conf["allowAnySSLcertificate"]="";
7021
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7022
		#$conf["postVar"]=array();
7023
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7024
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7025
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7026
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7027
		#$conf["agent"],字串,user agent的名稱.
7028
		#$conf["agent"]="";
7029
		#$conf["cookie"],字串,cookie位置與檔案位置.
7030
		#$conf["cookie"]="";
7031
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7032
		#$conf["forceNewCookie"]="";
7033
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7034
		#$conf["inBg"]="true";
7035
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7036
		#$conf["bgInProc"]="false";
7037
		#參考資料:
7038
		#無.
7039
		#備註:
7040
		#無.
7041
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7042
		unset($conf["catchWebContent::curlCmd"]);
7043
 
7044
		#如果異常
7045
		if($curlCmd["status"]==="false"){
7046
 
7047
			#設置錯誤識別
7048
			$result["status"]="false";
7049
 
7050
			#設置錯誤訊息
7051
			$result["error"]=$curlCmd;
7052
 
7053
			#回傳結果
7054
			return $result;
7055
 
7056
			}#if end
7057
 
7058
		#設置curl的詳細資訊
7059
		$result["curl_verbose_info"]=$curlCmd;
7060
 
7061
		#驗證結果是否為 json
7062
		$json_validate=json_validate($curlCmd["fullContent"]);
7063
 
7064
		#如果回應不是 json
7065
		if(!$json_validate){
7066
 
7067
			#設置錯誤識別
7068
			$result["status"]="false";
7069
 
7070
			#設置錯誤訊息
7071
			$result["error"]=$curlCmd;
7072
 
7073
			#回傳結果
7074
			return $result;
7075
 
7076
			}#if end
7077
 
7078
		#設置json string結果
7079
		$result["content"]=$curlCmd["fullContent"];
7080
 
7081
		#解析json
7082
		$jsonRes=json_decode($result["content"]);
7083
 
7084
		#如果沒有要有的attr
7085
		if(!isset($jsonRes->success)){
7086
 
7087
			#設置錯誤識別
7088
			$result["status"]="false";
7089
 
7090
			#設置錯誤訊息
7091
			$result["error"]=$curlCmd;
7092
 
7093
			#回傳結果
7094
			return $result;
7095
 
7096
			}#if end
7097
 
7098
		#如果 success 不等於 1
7099
		if($jsonRes->success!==1){
7100
 
7101
			#設置錯誤識別
7102
			$result["status"]="false";
7103
 
7104
			#設置錯誤訊息
7105
			$result["error"]=$curlCmd;
7106
 
7107
			#回傳結果
7108
			return $result;
7109
 
7110
			}#if end
7111
 
7112
		#設置執行正常
7113
		$result["status"]="true";
7114
 
7115
		#回傳結果
7116
		return $result;
7117
 
7118
		}#function cancelCert end
7119
 
7120
	/*
7121
	#函式說明:
7122
	#透過zerossl api確保ssl沒有過期.
7123
	#回傳結果:
7124
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7125
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7126
	#$result["function"],當前執行的函式名稱.
7127
	#$result["argu"],所使用的參數.
7128
	#必填參數:
7129
	#$conf["cName"],陣列,每個ssl的common domain name.
7130
	$conf["cName"]=array();
7131
	#$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內容合併後的檔案位置與名稱.
7132
	$conf["certInfo"]=array();
7133
	#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
7134
	$conf["rrFile"]=array();
7135
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
7136
	$conf["dnsSerAddr"]=array();
7137
	#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
7138
	$conf["actionAfterUpdateCert"]=array();
7139
	#可省略參數:
288 liveuser 7140
	#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/sslUpdater.sock
7141
	#$conf["sock"]="";
281 liveuser 7142
	#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
7143
	#$conf["debug"]="";
255 liveuser 7144
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7145
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7146
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7147
	#$conf["key"]=self::getApiInfo()["apiKey"];
293 liveuser 7148
	#$conf["multiThreads"],字串,預設為"false"代表不使用多執行序;"true"代表要用多執行序.
7149
	#$conf["multiThreads"]=""
255 liveuser 7150
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
7151
	#$conf["debug"]="";
7152
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
7153
	#$conf["addOnProcessFunc"]=array();
7154
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
7155
	#$conf["funcToRunWhenIdle"]=array();
7156
	#參考資料:
7157
	#無.
7158
	#備註:
7159
	#無.
7160
	*/
7161
	public static function sslUpdater(&$conf){
7162
 
7163
		#初始化要回傳的結果
7164
		$result=array();
7165
 
7166
		#設置當其函數名稱
7167
		$result["function"]=__FUNCTION__;
7168
 
7169
		#如果 $conf 不為陣列
7170
		if(gettype($conf)!="array"){
7171
 
7172
			#設置執行失敗
7173
			$result["status"]="false";
7174
 
7175
			#設置執行錯誤訊息
7176
			$result["error"][]="\$conf變數須為陣列形態";
7177
 
7178
			#如果傳入的參數為 null
7179
			if($conf==null){
7180
 
7181
				#設置執行錯誤訊息
7182
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7183
 
7184
				}#if end
7185
 
7186
			#回傳結果
7187
			return $result;
7188
 
7189
			}#if end
7190
 
7191
		#取得參數
7192
		$result["argu"]=$conf;
288 liveuser 7193
 
7194
		#初始化預設的 unix domain socket 路徑
7195
		$defaultSocket=pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/sslUpdater.sock";
255 liveuser 7196
 
7197
		#檢查參數
7198
		#函式說明:
7199
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7200
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7201
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7202
		#$result["function"],當前執行的函式名稱.
7203
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7204
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7205
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7206
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7207
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7208
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7209
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7210
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7211
		#必填寫的參數:
7212
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7213
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7214
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7215
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
7216
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7217
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
7218
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7219
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7220
		#可以省略的參數:
7221
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7222
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7223
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
293 liveuser 7224
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("multiThreads","sock","debug","apiDomain","key");
255 liveuser 7225
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 7226
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("multiThreads","sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
255 liveuser 7227
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
293 liveuser 7228
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array","array");
255 liveuser 7229
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
293 liveuser 7230
		$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 7231
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7232
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
7233
		#參考資料來源:
7234
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7235
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7236
		unset($conf["variableCheck::checkArguments"]);
7237
 
7238
		#如果檢查失敗
7239
		if($checkArguments["status"]==="false"){
7240
 
7241
			#設置錯誤識別
7242
			$result["status"]="false";
7243
 
7244
			#設置錯誤訊息
7245
			$result["error"]=$checkArguments;
7246
 
7247
			#回傳結果
7248
			return $result;
7249
 
7250
			}#if end
7251
 
7252
		#如果檢查不通過
7253
		if($checkArguments["passed"]==="false"){
7254
 
7255
			#設置錯誤識別
7256
			$result["status"]="false";
7257
 
7258
			#設置錯誤訊息
7259
			$result["error"]=$checkArguments;
7260
 
7261
			#回傳結果
7262
			return $result;
7263
 
7264
			}#if end
7265
 
7266
		#取得key
7267
		$share["key"]=$conf["key"];
7268
 
7269
		#取得apiDomain
7270
		$share["apiDomain"]=$conf["apiDomain"];
7271
 
281 liveuser 7272
		#設置debug flag
7273
		$share["debug"]=$conf["debug"];
7274
 
293 liveuser 7275
		#設置 multiThreads 
7276
		$share["multiThreads"]=$conf["multiThreads"];
7277
 
255 liveuser 7278
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
7279
		$share["certInfo"]=array();
7280
 
7281
		#針對每個 domain
7282
		foreach($conf["cName"] as $index=>$cName ){
7283
 
7284
			#如果沒有對應的certInfo
7285
			if(!isset($conf["certInfo"][$index])){
7286
 
7287
				#設置錯誤識別
7288
				$result["status"]="false";
7289
 
7290
				#設置錯誤訊息
7291
				$result["error"][]="missing certInfo";
7292
 
7293
				#設置錯誤訊息
7294
				$result["error"][]=$checkArguments;
7295
 
7296
				#回傳結果
7297
				return $result;
7298
 
7299
				}#if end
7300
 
291 liveuser 7301
			#檢查 $conf["certInfo"][$index] 是否資訊都有存在
7302
			#函式說明:
7303
			#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
7304
			#回傳結果:
7305
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7306
			#$result["error"],執行不正常結束的錯訊息陣列.
7307
			#$result["simpleError"],簡單表示的錯誤訊息.
7308
			#$result["function"],當前執行的函式名稱.
7309
			#$result["argu"],設置給予的參數.
7310
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7311
			#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7312
			#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7313
			#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7314
			#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7315
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7316
			#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7317
			#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7318
			#必填參數:
7319
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7320
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["certInfo"][$index];
7321
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7322
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7323
			#可省略參數:
7324
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7325
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
7326
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
7327
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
7328
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7329
			#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7330
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
7331
			#$conf["canNotBeEmpty"]=array();
7332
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
7333
			#$conf["canBeEmpty"]=array();
7334
			#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
7335
			$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("true","true","true","true");
7336
			#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7337
			$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
7338
			#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7339
			$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
7340
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7341
			$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");
7342
			#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
7343
			#$conf["disallowAllSkipableVarIsEmpty"]="";
7344
			#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
7345
			#$conf["disallowAllSkipableVarIsEmptyArray"]="";
7346
			#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
7347
			#$conf["disallowAllSkipableVarNotExist"]="";
7348
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7349
			#$conf["arrayCountEqualCheck"][]=array();
7350
			#參考資料:
7351
			#array_keys=>http://php.net/manual/en/function.array-keys.php
7352
			#備註:
7353
			#無.
7354
			$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7355
			unset($conf["variableCheck::checkArguments"]);
7356
 
7357
			#如果檢查失敗
7358
			if($checkArguments["status"]==="false"){
7359
 
7360
				#設置錯誤識別
7361
				$result["status"]="false";
7362
 
7363
				#設置錯誤訊息
7364
				$result["error"]=$checkArguments;
7365
 
7366
				#回傳結果
7367
				return $result;
7368
 
7369
				}#if end
7370
 
7371
			#如果檢查不通過
7372
			if($checkArguments["passed"]==="false"){
7373
 
7374
				#設置錯誤識別
7375
				$result["status"]="false";
7376
 
7377
				#設置錯誤訊息
7378
				$result["error"]=$checkArguments;
7379
 
7380
				#回傳結果
7381
				return $result;
7382
 
7383
				}#if end
7384
 
7385
			#儲存 cName
7386
			$cInfo["cName"]=$cName;
255 liveuser 7387
 
291 liveuser 7388
			#儲存 RR 檔案的路徑與名稱
7389
			$cInfo["rrFile"]=$conf["rrFile"][$index];
255 liveuser 7390
 
291 liveuser 7391
			#儲存 cName 對應的 dns server addr
7392
			$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
255 liveuser 7393
 
291 liveuser 7394
			#儲存 cName 的憑證更新後要做的事情.
7395
			$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
255 liveuser 7396
 
294 liveuser 7397
			#用 ";" 分割來取得有多少個動作要依序執行
7398
			#函式說明:
7399
			#將固定格式的字串分開,並回傳分開的結果.
7400
			#回傳結果:
7401
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7402
			#$result["error"],錯誤訊息陣列
7403
			#$result["function"],當前執行的函數名稱.
7404
			#$result["argu"],使用的參數.
7405
			#$result["oriStr"],要分割的原始字串內容
7406
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7407
			#$result["dataCounts"],爲總共分成幾段
7408
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
7409
			#必填參數:
7410
			#$conf["stringIn"],字串,要處理的字串.
7411
			$conf["stringProcess::spiltString"]["stringIn"]=$cInfo["actionAfterUpdateCert"];
7412
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
7413
			$conf["stringProcess::spiltString"]["spiltSymbol"]=";";
7414
			#可省略參數:
7415
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
7416
			#$conf["allowEmptyStr"]="false";
7417
			#參考資料:
7418
			#無.
7419
			#備註:
7420
			#無.
7421
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
7422
			unset($conf["stringProcess::spiltString"]);
7423
 
7424
			#如果執行異常
7425
			if($spiltString["status"]==="false"){
7426
 
7427
				#設置錯誤識別
7428
				$result["status"]="false";
7429
 
7430
				#設置錯誤訊息
7431
				$result["error"]=$spiltString;
7432
 
7433
				#回傳結果
7434
				return $result;
7435
 
7436
				}#if end
7437
 
7438
			#如果沒有";"存在,代表格式不對
7439
			if($spiltString["found"]==="false"){
7440
 
7441
				#設置錯誤識別
7442
				$result["status"]="false";
7443
 
7444
				#設置錯誤訊息
7445
				$result["error"]=$spiltString;
7446
 
7447
				#回傳結果
7448
				return $result;
7449
 
7450
				}#if end
7451
 
7452
			#取得每個動作
7453
			$cInfo["actionAfterUpdateCert"]=$spiltString["dataArray"];
7454
 
291 liveuser 7455
			#設置 certPath
7456
			$cInfo["ssl"]["certPath"]=$conf["certInfo"][$index]["certPath"];
255 liveuser 7457
 
291 liveuser 7458
			#設置 pKey
7459
			$cInfo["ssl"]["pKey"]=$conf["certInfo"][$index]["pKey"];
7460
 
7461
			#設置 caPath
7462
			$cInfo["ssl"]["caPath"]=$conf["certInfo"][$index]["caPath"];
7463
 
7464
			#設置 certWithCaPath
7465
			$cInfo["ssl"]["certWithCaPath"]=$conf["certInfo"][$index]["certWithCaPath"];
7466
 
7467
			#儲存 certInfo
7468
			$share["certInfo"][]=$cInfo;
7469
 
255 liveuser 7470
			}#foreach end
7471
 
7472
		#如果為空
7473
		if(empty($share["certInfo"])){
7474
 
7475
			#設置錯誤識別
7476
			$result["status"]="false";
7477
 
7478
			#設置錯誤訊息
7479
			$result["error"][]="certInfo 參數有缺";
7480
 
7481
			#設置錯誤訊息
7482
			$result["error"][]=$checkArguments;
7483
 
7484
			#回傳結果
7485
			return $result;
7486
 
7487
			}#if end
7488
 
7489
		#函式說明:
7490
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
7491
		#回傳結果:
7492
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
7493
		#$result["error"],錯誤訊息陣列.
7494
		#$result["function"],當前執行的函式名稱.
7495
		#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
7496
		#$result["serverCache"]["serverSide"],server side 的 cache.
7497
		#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
7498
		#$result["serverCache"]["clientSide"],client site 的 cache.
7499
		#必填參數:
7500
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
291 liveuser 7501
		$conf["sock::unixDomainSockServer"]["sock"]=$conf["sock"];
255 liveuser 7502
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7503
		$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
7504
		#可省略參數:
7505
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
7506
		$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
7507
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
7508
		$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
7509
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
7510
		#$conf["sessionTimeout"]="300";
7511
		#$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 7512
		$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("\qbpwcf\zerossl::sslUpdater_cmd");
255 liveuser 7513
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
291 liveuser 7514
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\qbpwcf\zerossl::sslUpdater_idle");
255 liveuser 7515
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
7516
		#$conf["paramsForFuncToRunWhenIdle"]=array();
7517
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7518
		$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
7519
		#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
7520
		#$conf["shutdownStrAddr"]="";
7521
		#參考資料:
7522
		#http://php.net/manual/en/function.stream-socket-server.php
7523
		#備註:
7524
		#無.
7525
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
7526
		unset($conf["sock::unixDomainSockServer"]);
7527
 
7528
		#執行異常
7529
		if($unixDomainSockServer["status"]==="false"){
7530
 
7531
			#設置錯誤識別
7532
			$result["status"]="false";
7533
 
7534
			#設置錯誤訊息
7535
			$result["error"]=$unixDomainSockServer;
7536
 
7537
			#回傳結果
7538
			return $result;
7539
 
7540
			}#if end
7541
 
7542
		#設置執行正常
7543
		$result["status"]="true";
7544
 
7545
		#回傳結果
7546
		return $result;
7547
 
7548
		}#function sslUpdater end
7549
 
7550
	/*
7551
	#函式說明:
7552
	#funcion sslUpdater 於收到訊息時要做的事情.
7553
	#回傳結果:
7554
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7555
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7556
	#$result["function"],當前執行的函式名稱.
7557
	#$result["argu"],所使用的參數.
7558
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
7559
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
7560
	#必填參數:
7561
	#$conf["request"],字串,收到的json訊息.
7562
	$conf["request"]="";
7563
	#$conf["sock"],resource,用戶的socket.
7564
	$conf["sock"]="";
7565
	#$conf["clientCache"],陣列,給予所有用戶的cache.
7566
	$conf["clientCache"]=array();
7567
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7568
	$conf["info"]=array();
7569
	#可省略參數:
7570
	#無.
7571
	#參考資料:
7572
	#無.
7573
	#備註:
7574
	#建構中...
7575
	*/
7576
	public static function sslUpdater_cmd(&$conf){
7577
 
7578
		#debug
7579
		var_dump($conf);
7580
 
7581
		}#function sslUpdater_cmd end
7582
 
7583
	/*
7584
	#函式說明:
7585
	#funcion sslUpdater 於閒置時要做的事情
7586
	#回傳結果:
7587
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7588
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7589
	#$result["function"],當前執行的函式名稱.
7590
	#$result["argu"],所使用的參數.
7591
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
7592
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
7593
	#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
7594
	#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
7595
	#必填參數:
7596
	#$conf["client"],陣列,所有用戶的資訊.
7597
	$conf["client"]=array();
7598
	#$conf["clientCache"],陣列,給予所有用戶的cache.
7599
	$conf["clientCache"]=array();
7600
	#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
7601
	$conf["serverCache"]=array();
7602
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7603
	$conf["info"]=array();
7604
	#可省略參數:
7605
	#無.
7606
	#參考資料:
7607
	#無.
7608
	#備註:
291 liveuser 7609
	#無.
255 liveuser 7610
	*/
7611
	public static function sslUpdater_idle(&$conf){
7612
 
7613
		#初始化要回傳的結果
7614
		$result=array();
7615
 
7616
		#設置當其函數名稱
7617
		$result["function"]=__FUNCTION__;
7618
 
7619
		#如果 $conf 不為陣列
7620
		if(gettype($conf)!="array"){
7621
 
7622
			#設置執行失敗
7623
			$result["status"]="false";
7624
 
7625
			#設置執行錯誤訊息
7626
			$result["error"][]="\$conf變數須為陣列形態";
7627
 
7628
			#如果傳入的參數為 null
7629
			if($conf==null){
7630
 
7631
				#設置執行錯誤訊息
7632
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7633
 
7634
				}#if end
7635
 
7636
			#回傳結果
7637
			return $result;
7638
 
7639
			}#if end
7640
 
7641
		#取得參數
7642
		$result["argu"]=$conf;
7643
 
7644
		#檢查參數
7645
		#函式說明:
7646
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7647
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7648
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7649
		#$result["function"],當前執行的函式名稱.
7650
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7651
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7652
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7653
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7654
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7655
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7656
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7657
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7658
		#必填寫的參數:
7659
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7660
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7661
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
291 liveuser 7662
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","serverCache","info");
255 liveuser 7663
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
291 liveuser 7664
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
255 liveuser 7665
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7666
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7667
		#可以省略的參數:
7668
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7669
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7670
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7671
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7672
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7673
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
7674
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7675
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
7676
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7677
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
7678
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7679
		#$conf["arrayCountEqualCheck"][]=array();
7680
		#參考資料來源:
7681
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7682
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7683
		unset($conf["variableCheck::checkArguments"]);
7684
 
7685
		#如果檢查失敗
7686
		if($checkArguments["status"]==="false"){
7687
 
7688
			#設置錯誤識別
7689
			$result["status"]="false";
7690
 
7691
			#設置錯誤訊息
7692
			$result["error"]=$checkArguments;
7693
 
7694
			#回傳結果
7695
			return $result;
7696
 
7697
			}#if end
7698
 
7699
		#如果檢查不通過
7700
		if($checkArguments["passed"]==="false"){
7701
 
7702
			#設置錯誤識別
7703
			$result["status"]="false";
7704
 
7705
			#設置錯誤訊息
7706
			$result["error"]=$checkArguments;
7707
 
7708
			#回傳結果
7709
			return $result;
7710
 
7711
			}#if end
281 liveuser 7712
 
7713
		#預設不開啟 debug flag
7714
		$debug=false;
7715
 
7716
		#如果有設置 debug 為 "true"
291 liveuser 7717
		if($conf["info"]["share"]["debug"]==="true"){
281 liveuser 7718
 
7719
			#設置 debug flag
7720
			$debug=true;
7721
 
7722
			}#if end
7723
 
293 liveuser 7724
		#如果有啟用 multiThreads
7725
		if($conf["info"]["share"]["multiThreads"]==="true"){
7726
 
7727
			#設置 multiThreads flag
7728
			$multiThreads=true;
7729
 
7730
			}#if end
7731
 
261 liveuser 7732
		#另存 server cache 的參考
7733
		$serverCache=&$conf["serverCache"];
7734
 
255 liveuser 7735
		#針對每個 domain name
291 liveuser 7736
		foreach($conf["info"]["share"]["certInfo"] as $certInfoIndex=>$cInfo){
255 liveuser 7737
 
7738
			#取得domain name
7739
			$cName=$cInfo["cName"];
7740
 
261 liveuser 7741
			#如果尚無對應domain name的記錄
7742
			if(!isset($serverCache[$cName])){
7743
 
7744
				#設置最新一次檢測的unixtime
7745
				$serverCache[$cName]["lastCheckUnixTime"]=time();
291 liveuser 7746
 
261 liveuser 7747
				}#if end
7748
 
7749
			#反之距離上次檢查不滿一天
291 liveuser 7750
			else{
261 liveuser 7751
 
291 liveuser 7752
				#計算距離上次檢查多少秒
7753
				$checkedAfter=time()-$serverCache[$cName]["lastCheckUnixTime"];
261 liveuser 7754
 
291 liveuser 7755
				#若距離上次檢查不滿一天
7756
				if($checkedAfter<86400){
7757
 
7758
					#if enable debug
7759
					if($debug){
7760
 
7761
						#debug msg
7762
						echo "Domain name(".$cName.") on zerossl require to check in ".(86400-$checkedAfter)." second(s).".PHP_EOL;
7763
 
7764
						}#if end
7765
 
7766
					#跳過該 domain name 的檢查
7767
					continue;
7768
 
7769
					}#if end
346 liveuser 7770
 
7771
				#反之
7772
				else{
291 liveuser 7773
 
346 liveuser 7774
					#重新設置上次檢查時間為當前時間
7775
					$serverCache[$cName]["lastCheckUnixTime"]=time();
7776
 
7777
					}#else end
7778
 
291 liveuser 7779
				}#else end
261 liveuser 7780
 
281 liveuser 7781
			#if enable debug
7782
			if($debug){
7783
 
7784
				#debug msg
291 liveuser 7785
				echo "Checking domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 7786
 
7787
				}#if end
7788
 
291 liveuser 7789
			#certPath
7790
			#$cInfo["ssl"]["certPath"];
7791
 
7792
			#pKey
7793
			#$cInfo["ssl"]["pKey"];
7794
 
7795
			#caPath
7796
			#$cInfo["ssl"]["caPath"]=;
7797
 
7798
			#certWithCaPath
7799
			#$cInfo["ssl"]["certWithCaPath"];
7800
 
255 liveuser 7801
			#嘗試取得 domain name 對應的可用憑證
7802
			#函式說明:
7803
			#取得在zerossl上的CSR清單
7804
			#回傳結果:
7805
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7806
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
7807
			#$result["function"],當前執行的函式名稱.
7808
			#$result["argu"],所使用的參數.
7809
			#$result["curl_verbose_info"],curl執行的詳細資訊.
7810
			#$result["content"],結果json字串.
7811
			#$result["tCount"],總共的資料筆數.
7812
			#$result["count"],該頁的筆數.
7813
			#$result["page"],當前的頁碼.
7814
			#$result["certs"],陣列,certificates清單,key為certificate的id.
7815
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
7816
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
7817
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
7818
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7819
			#必填參數:
7820
			#無
7821
			#可省略參數:
7822
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 7823
			$conf["zerossl::getCertList"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 7824
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 7825
			$conf["zerossl::getCertList"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 7826
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7827
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
7828
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
7829
			$conf["zerossl::getCertList"]["cerType"]="single90Days";
7830
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
7831
			$conf["zerossl::getCertList"]["search"]=$cName;
7832
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
7833
			#$conf["limit"]="";
7834
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
7835
			#$conf["page"]="";
7836
			#參考資料:
7837
			#https://zerossl.com/documentation/api/list-certificates/
7838
			#備註:
7839
			#無.
7840
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
7841
			unset($conf["zerossl::getCertList"]);
7842
 
7843
			#符合條件的數量
7844
			#$getCertList["tCount"];
7845
 
7846
			#符合條件的當頁數量
7847
			#$getCertList["count"];
7848
 
7849
			#如果執行異常
7850
			if($getCertList["status"]==="false"){
7851
 
7852
				#設置錯誤識別
7853
				$result["status"]="false";
7854
 
7855
				#設置錯誤訊息
7856
				$result["error"]=$getCertList;
7857
 
7858
				#回傳結果
7859
				return $result;
7860
 
7861
				}#if end
291 liveuser 7862
 
294 liveuser 7863
			#如果有資料
7864
			if($getCertList["count"]>0){
7865
 
7866
				#檢查 common name
7867
				foreach($getCertList["certs"] as $certId=>$certInfo){
7868
 
7869
					#如果 common name 不符合
7870
					if($certInfo["cname"]!==$cName){
7871
 
7872
						#移除之
7873
						unset($getCertList["certs"][$certId]);
7874
 
7875
						#當頁筆數-1
7876
						$getCertList["count"]--;
7877
 
7878
						#總共筆數減少1
7879
						$getCertList["tCount"]--;
7880
 
7881
						}#if end
7882
 
7883
					}#foreach end
7884
 
7885
				}#if end
7886
 
255 liveuser 7887
			#如果沒有憑證
291 liveuser 7888
			if($getCertList["count"]===0){
255 liveuser 7889
 
281 liveuser 7890
				#if enable debug
7891
				if($debug){
7892
 
7893
					#debug msg
291 liveuser 7894
					echo "There is not valid ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 7895
 
7896
					}#if end
7897
 
7898
				#if enable debug
7899
				if($debug){
7900
 
7901
					#debug msg
291 liveuser 7902
					echo "Checking ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7903
 
7904
					}#if end
7905
 
255 liveuser 7906
				#確認有無對應 cName 的 private key
7907
				#函式說明:
7908
				#檢查多個檔案與資料夾是否存在.
7909
				#回傳的結果:
7910
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7911
				#$result["error"],錯誤訊息陣列.
7912
				#$resutl["function"],當前執行的涵式名稱.
7913
				#$result["argu"],使用的參數.
7914
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
7915
				#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
7916
				#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
7917
				#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
7918
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
7919
				#必填參數:
7920
				#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
292 liveuser 7921
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 7922
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7923
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
7924
				#可省略參數:
7925
				#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
7926
				#$conf["disableWebSearch"]="false";
7927
				#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
7928
				$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
7929
				#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
7930
				$conf["fileAccess::checkMultiFileExist"]["web"]="false";
7931
				#參考資料:
7932
				#http://php.net/manual/en/function.file-exists.php
7933
				#http://php.net/manual/en/control-structures.foreach.php
7934
				#備註:
7935
				#函數file_exists檢查的路徑為檔案系統的路徑
7936
				#$result["varName"][$i]結果未實作
7937
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
7938
				unset($conf["fileAccess::checkMultiFileExist"]);
7939
 
7940
				#如果運行異常
7941
				if($checkMultiFileExist["status"]==="false"){
7942
 
7943
					#設置錯誤識別
7944
					$result["status"]="false";
7945
 
7946
					#設置錯誤訊息
7947
					$result["error"]=$getCertList;
7948
 
7949
					#回傳結果
7950
					return $result;
7951
 
7952
					}#if end
7953
 
7954
				#如果沒有 private key
7955
				if($checkMultiFileExist["allExist"]==="false"){
7956
 
281 liveuser 7957
					#if enable debug
7958
					if($debug){
7959
 
7960
						#debug msg
291 liveuser 7961
						echo "there is no ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7962
 
7963
						}#if end
7964
 
7965
					#if enable debug
7966
					if($debug){
7967
 
7968
						#debug msg
291 liveuser 7969
						echo "creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7970
 
7971
						}#if end
7972
 
255 liveuser 7973
					#建立 private key
7974
					#函式說明:
7975
					#產生ssl private key.
7976
					#回傳結果:
7977
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7978
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
7979
					#$result["function"],當前執行的函式名稱.
7980
					#$result["argu"],所使用的參數.
7981
					#$result["curl_verbose_info"],curl執行的詳細資訊.
7982
					#$result["content"],ssl用的private key.
7983
					#必填參數:
7984
					#$conf["fileArgu"],字串,變數__FILE__的內容.
7985
					$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
7986
					#可省略參數:
7987
					#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
7988
					#$conf["length"]=4096';
7989
					#參考資料:
7990
					#無.
7991
					#備註:
7992
					#key generated by openssl with RSA.
291 liveuser 7993
					$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 7994
					unset($conf["openssl::createPrivateKey"]);
7995
 
7996
					#如果運行異常
7997
					if($createPrivateKey["status"]==="false"){
7998
 
7999
						#設置錯誤識別
8000
						$result["status"]="false";
8001
 
8002
						#設置錯誤訊息
8003
						$result["error"]=$createPrivateKey;
8004
 
8005
						#回傳結果
8006
						return $result;
8007
 
8008
						}#if end
8009
 
8010
					#另存private key的字串
8011
					$pKeyStr=$createPrivateKey["content"];
8012
 
8013
					#建立private key檔案
8014
					#函式說明:
8015
					#將字串寫入到檔案
8016
					#回傳結果:
8017
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
8018
					#$result["error"],錯誤訊息陣列.
8019
					#$result["function"],當前執行的函數名稱.
8020
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
8021
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
8022
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
8023
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
8024
					#$result["argu"],使用的參數.
8025
					#必填參數:
8026
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8027
					$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
8028
					#可省略參數:
8029
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
292 liveuser 8030
					$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 8031
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
8032
					$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
8033
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
8034
					#$conf["writeMethod"]="a";
8035
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
8036
					#$conf["checkRepeat"]="";
8037
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
8038
					#$conf["filenameExtensionStartPoint"]="";
8039
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
8040
					#$conf["repeatNameRule"]="";
8041
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
8042
					$conf["zerossl::writeTextIntoFile"]["web"]="false";
8043
					#參考資料:
8044
					#無.
8045
					#備註:
8046
					#無.
291 liveuser 8047
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
255 liveuser 8048
					unset($conf["zerossl::writeTextIntoFile"]);
8049
 
8050
					#如果運行異常
8051
					if($writeTextIntoFile["status"]==="false"){
8052
 
8053
						#設置錯誤識別
8054
						$result["status"]="false";
8055
 
8056
						#設置錯誤訊息
8057
						$result["error"]=$writeTextIntoFile;
8058
 
8059
						#回傳結果
8060
						return $result;
8061
 
8062
						}#if end
8063
 
8064
					}#if end
8065
 
281 liveuser 8066
				#if enable debug
8067
				if($debug){
8068
 
8069
					#debug msg
291 liveuser 8070
					echo "Creating domain name(".$conf["info"]["share"]["apiDomain"].") csr for zerossl...".PHP_EOL;
281 liveuser 8071
 
8072
					}#if end
8073
 
255 liveuser 8074
				#建立準備給zerossl的csr
8075
				#函式說明:
8076
				#產生certificate sign request(CSR).
8077
				#回傳結果:
8078
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8079
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8080
				#$result["function"],當前執行的函式名稱.
8081
				#$result["argu"],所使用的參數.
8082
				#$result["content"],csr內容.
8083
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8084
				#$result["privateKey"], private key 的內容.
8085
				#必填參數:
8086
				#$conf["domain"],字串,csr內容的網域名稱.
8087
				$conf["zerossl::createCSR"]["domain"]=$cName;
8088
				#可省略參數:
8089
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 8090
				$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 8091
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
8092
				#$conf["country"]="";
8093
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
8094
				#$conf["state"]="";
8095
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
8096
				#$conf["org"]="";
8097
				#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
8098
				#$conf["unit"]="";
8099
				#參考資料:
8100
				#無.
8101
				#備註:
8102
				#無.
8103
				$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
8104
				unset($conf["zerossl::createCSR"]);
8105
 
8106
				#如果運行異常
8107
				if($createCSR["status"]==="false"){
8108
 
8109
					#設置錯誤識別
8110
					$result["status"]="false";
8111
 
8112
					#設置錯誤訊息
8113
					$result["error"]=$createCSR;
8114
 
8115
					#回傳結果
8116
					return $result;
8117
 
8118
					}#if end
8119
 
8120
				#取得本地端產生的csr內容
8121
				$csrLocal=$createCSR["content"];
8122
 
281 liveuser 8123
				#if enable debug
8124
				if($debug){
8125
 
8126
					#debug msg
291 liveuser 8127
					echo "Creating certificate for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 8128
 
8129
					}#if end
8130
 
255 liveuser 8131
				#函式說明:
281 liveuser 8132
				#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 8133
				#回傳結果:
8134
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8135
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8136
				#$result["function"],當前執行的函式名稱.
8137
				#$result["argu"],所使用的參數.
8138
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8139
				#$result["id"],用於zerossl api驗證domain的id.
8140
				#$result["content"],字串,得到的json字串回應.
8141
				#$result["cnameKey"],用於dns CNAME驗證鍵名.
8142
				#$result["cnameVal"],用於dms CNAME驗證鍵值.
8143
				#必填參數:
8144
				#$conf["certificate_domains"],字串,要簽署的doamin名稱.
8145
				$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
8146
				#$conf["certificate_csr"],字串,簽署的資訊.
8147
				$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
8148
				#$conf["fileArgu"],字串,變數__FILE__的內容.
8149
				$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
8150
				#可省略參數:
8151
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 8152
				$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 8153
				#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
8154
				#$conf["path"]=self::getApiInfo()["csrPath"];
8155
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 8156
				$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 8157
				#參考資料:
8158
				#無.
8159
				#備註:
8160
				#無.
8161
				$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
8162
				unset($conf["zerossl::createCertificate"]);
8163
 
8164
				#如果執行異常
8165
				if($createCertificate["status"]==="false"){
8166
 
8167
					#設置錯誤識別
8168
					$result["status"]="false";
8169
 
8170
					#設置錯誤訊息
8171
					$result["error"]=$createCertificate;
8172
 
8173
					#回傳結果
8174
					return $result;
8175
 
8176
					}#if end
8177
 
8178
				#取得csr在zerossl上的id
8179
				$csrId=$createCertificate["id"];
8180
 
8181
				#取得cname key
8182
				$cNameKey=$createCertificate["cnameKey"];
8183
 
8184
				#取得cname val
8185
				$cNameVal=$createCertificate["cnameVal"];
8186
 
8187
				#初始化要增加的RR記錄
8188
				$rr2add=array();
8189
 
8190
				#設置CNAME的查詢
8191
				$rr2add["query"]=$cNameKey;
8192
 
8193
				#設置CNAME的value
8194
				$rr2add["value"]=$cNameVal;
8195
 
8196
				#設置類型為 CNAME
8197
				$rr2add["type"]="CNAME";
8198
 
8199
				#設置註解
8200
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
8201
 
281 liveuser 8202
				#if enable debug
8203
				if($debug){
8204
 
8205
					#debug msg
291 liveuser 8206
					echo "Adding DNS record to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8207
 
8208
					}#if end
8209
 
255 liveuser 8210
				#函式說明:
8211
				#新增DNS記錄到檔案裡面.
8212
				#回傳結果:
8213
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8214
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8215
				#$result["function"],當前執行的函式名稱.
8216
				#$result["argu"],所使用的參數.
8217
				#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
8218
				#$result["domain"],字串,RR所屬domain.
8219
				#$result["defaultTTL"],字串,預設的RR更新時間.
8220
				#$result["comment"],字串陣列,逐行的註解.
8221
				#必填參數:
8222
				#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
291 liveuser 8223
				$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 8224
				#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
8225
				$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
8226
				#可省略參數:
8227
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
8228
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
8229
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
8230
				#$conf["debug"]="false";
293 liveuser 8231
 
8232
				#如果有啟用多執行序
8233
				if($conf["info"]["share"]["multiThreads"]==="true"){
8234
 
8235
					#設置要多執行序
8236
					$conf["zerossl::updateDnsRecordFile"]["multiThreads"]="true";
8237
 
8238
					}#if end
8239
 
255 liveuser 8240
				#參考資料:
8241
				#無.
8242
				#備註:
8243
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
8244
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
8245
				#php-pear上的Net_DNS2也可以解析RR.
8246
				$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
8247
				unset($conf["zerossl::updateDnsRecordFile"]);
8248
 
8249
				#如果執行異常
8250
				if($updateDnsRecordFile["status"]==="false"){
8251
 
8252
					#設置錯誤識別
8253
					$result["status"]="false";
8254
 
8255
					#設置錯誤訊息
8256
					$result["error"]=$updateDnsRecordFile;
8257
 
8258
					#回傳結果
8259
					return $result;
8260
 
8261
					}#if end
281 liveuser 8262
 
8263
				#if enable debug
8264
				if($debug){
8265
 
8266
					#debug msg
291 liveuser 8267
					echo "Restart DNS service to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8268
 
8269
					}#if end
8270
 
255 liveuser 8271
				#重新啟動dns伺服器
8272
				#函式說明:
8273
				#呼叫shell執行系統命令,並取得回傳的內容.
8274
				#回傳結果:
8275
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8276
				#$result["error"],錯誤訊息陣列.
8277
				#$result["function"],當前執行的函數名稱.
8278
				#$result["argu"],使用的參數.
8279
				#$result["cmd"],執行的指令內容.
8280
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8281
				#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8282
				#$result["content"],為執行完後的輸出字串.
8283
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8284
				#$result["running"],是否還在執行.
8285
				#$result["pid"],pid.
8286
				#$result["statusCode"],執行結束後的代碼.
8287
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8288
				#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8289
				#必填參數:
8290
				#$conf["command"],字串,要執行的指令.
291 liveuser 8291
				$conf["external::callShell"]["command"]="systemctl";
255 liveuser 8292
				#$conf["fileArgu"],字串,變數__FILE__的內容.
8293
				$conf["external::callShell"]["fileArgu"]=__FILE__;
8294
				#可省略參數:
8295
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8296
				$conf["external::callShell"]["argu"]=array("restart","named");
8297
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8298
				#$conf["arguIsAddr"]=array();
8299
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8300
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8301
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8302
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8303
				#$conf["enablePrintDescription"]="true";
8304
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8305
				#$conf["printDescription"]="";
8306
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8307
				#$conf["escapeshellarg"]="false";
8308
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8309
				#$conf["thereIsShellVar"]=array();
8310
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8311
				#$conf["username"]="";
8312
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8313
				#$conf["password"]="";
8314
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8315
				#$conf["useScript"]="";
8316
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8317
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8318
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8319
				#$conf["inBackGround"]="";
8320
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8321
				#$conf["getErr"]="false";
8322
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8323
				#$conf["doNotRun"]="false";
8324
				#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8325
				$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
8326
				#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8327
				#$conf["remoteUser"]="root";
8328
				#參考資料:
8329
				#exec=>http://php.net/manual/en/function.exec.php
8330
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8331
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8332
				#備註:
8333
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8334
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8335
				$callShell=external::callShell($conf["external::callShell"]);
8336
				unset($conf["external::callShell"]);
8337
 
8338
				#如果執行異常
8339
				if($callShell["status"]==="false"){
8340
 
8341
					#設置錯誤識別
8342
					$result["status"]="false";
8343
 
8344
					#設置錯誤訊息
8345
					$result["error"]=$callShell;
8346
 
8347
					#回傳結果
8348
					return $result;
8349
 
8350
					}#if end
281 liveuser 8351
 
8352
				#if enable debug
8353
				if($debug){
8354
 
8355
					#debug msg
291 liveuser 8356
					echo "Request zerossl to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8357
 
8358
					}#if end
8359
 
292 liveuser 8360
				#無窮迴圈
8361
				while(true){
255 liveuser 8362
 
292 liveuser 8363
					#函式說明:
8364
					#請求驗證已經透過zerossl::createCertificate要求的domain.
8365
					#回傳結果:
8366
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8367
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8368
					#$result["function"],當前執行的函式名稱.
8369
					#$result["argu"],所使用的參數.
8370
					#$result["curl_verbose_info"],curl執行的詳細資訊.
8371
					#$result["content"],結果json字串.
8372
					#必填參數:
8373
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
8374
					$conf["zerossl::verifyDomain"]["id"]=$csrId;
8375
					#可省略參數:
8376
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8377
					$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
8378
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8379
					$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
8380
					#參考資料:
8381
					#https://zerossl.com/documentation/api/verify-domains/
8382
					#備註:
8383
					#無.
8384
					$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
8385
					unset($conf["zerossl::verifyDomain"]);
291 liveuser 8386
 
292 liveuser 8387
					#如果執行異常
8388
					if($verifyDomain["status"]==="false"){
8389
 
8390
						#設置錯誤識別
8391
						$result["status"]="false";
291 liveuser 8392
 
292 liveuser 8393
						#設置錯誤訊息
8394
						$result["error"]=$verifyDomain;
291 liveuser 8395
 
292 liveuser 8396
						#回傳結果
8397
						return $result;
291 liveuser 8398
 
8399
						}#if end
8400
 
292 liveuser 8401
					#如果沒有回內容
293 liveuser 8402
					if(!isset($verifyDomain["content"])){
292 liveuser 8403
 
8404
						#設置錯誤識別
8405
						$result["status"]="false";
291 liveuser 8406
 
292 liveuser 8407
						#設置錯誤訊息
8408
						$result["error"]=$verifyDomain;
291 liveuser 8409
 
292 liveuser 8410
						#回傳結果
8411
						return $result;
8412
 
8413
						}#if end
8414
 
8415
					#如果回應不是 json
293 liveuser 8416
					if(!(json_validate($verifyDomain["content"]))){
292 liveuser 8417
 
8418
						#設置錯誤識別
8419
						$result["status"]="false";
291 liveuser 8420
 
292 liveuser 8421
						#設置錯誤訊息
8422
						$result["error"]=$verifyDomain;
291 liveuser 8423
 
292 liveuser 8424
						#回傳結果
8425
						return $result;
8426
 
8427
						}#if end
8428
 
294 liveuser 8429
					#if enable debug
8430
					if($debug){
8431
 
8432
						#debug msg
8433
						echo "Response of validating certificate for domain name(".$cName.") on zerossl".PHP_EOL;
8434
 
8435
						#debug msg
8436
						var_dump(__LINE__,$verifyDomain);
8437
 
8438
						}#if end
8439
 
292 liveuser 8440
					/*
8441
					範例json:
8442
					{"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}
8443
					*/
8444
 
8445
					#解析json回應
293 liveuser 8446
					$verifyDomainRes=json_decode($verifyDomain["content"]);
291 liveuser 8447
 
293 liveuser 8448
					#如果回應含有 success
8449
					if(isset($verifyDomainRes->success)){
292 liveuser 8450
 
293 liveuser 8451
						#如果是 zerossl 驗證失敗
294 liveuser 8452
						if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
291 liveuser 8453
 
293 liveuser 8454
							#如果是 CNAME 記錄找不到
8455
							if($verifyDomainRes->error->code===0){
291 liveuser 8456
 
293 liveuser 8457
								#取得錯誤訊息
8458
								#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
8459
 
8460
								#if enable debug
8461
								if($debug){
8462
 
8463
									#debug msg
8464
									echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
8465
 
8466
									}#if end
8467
 
8468
								#if enable debug
8469
								if($debug){
8470
 
8471
									#debug msg
8472
									echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
8473
 
8474
									}#if end
8475
 
8476
								#休息60秒
8477
								sleep(60);
294 liveuser 8478
 
8479
								#再跑一次要求認證
8480
								continue;
291 liveuser 8481
 
8482
								}#if end
293 liveuser 8483
 
8484
							#反之為不接受的錯誤訊息
8485
							else{
291 liveuser 8486
 
293 liveuser 8487
								#設置錯誤識別
8488
								$result["status"]="false";
8489
 
8490
								#設置錯誤訊息
8491
								$result["error"]=$verifyDomain;
8492
 
8493
								#回傳結果
8494
								return $result;
291 liveuser 8495
 
293 liveuser 8496
								}#else end
291 liveuser 8497
 
8498
							}#if end
292 liveuser 8499
 
8500
						}#if end
293 liveuser 8501
 
8502
					#反之如果回應含有 status
8503
					else if(isset($verifyDomainRes->status)){
292 liveuser 8504
 
293 liveuser 8505
						#如果是 zerossl 尚在驗證中
8506
						if($verifyDomainRes->status==="pending_validation"){
292 liveuser 8507
 
293 liveuser 8508
							#if enable debug
8509
							if($debug){
292 liveuser 8510
 
293 liveuser 8511
								#debug msg
8512
								echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
292 liveuser 8513
 
8514
								}#if end
8515
 
293 liveuser 8516
							#無窮迴圈
8517
							while(true){
8518
 
8519
								#查詢驗證狀況
8520
								#函式說明:
8521
								#取得CSR在zerossl上的狀態
8522
								#回傳結果:
8523
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8524
								#$reuslt["error"],執行不正常結束的錯訊息陣列.
8525
								#$result["function"],當前執行的函式名稱.
8526
								#$result["argu"],所使用的參數.
8527
								#$result["curl_verbose_info"],curl執行的詳細資訊.
8528
								#$result["content"],結果json字串.
8529
								#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
8530
								#必填參數:
8531
								#$conf["id"],字串,zerossl::createCertificate回傳的id.
8532
								$conf["zerossl::getCertSta"]["id"]=$csrId;
8533
								#可省略參數:
8534
								#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8535
								$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
8536
								#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8537
								$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
8538
								#參考資料:
8539
								#https://zerossl.com/documentation/api/get-certificate/
8540
								#備註:
8541
								#無.
8542
								$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
8543
								unset($conf["zerossl::getCertSta"]);
8544
 
8545
								#如果執行異常
8546
								if($getCertSta["status"]==="false"){
8547
 
8548
									#設置錯誤識別
8549
									$result["status"]="false";
292 liveuser 8550
 
293 liveuser 8551
									#設置錯誤訊息
8552
									$result["error"]=$getCertSta;
292 liveuser 8553
 
293 liveuser 8554
									#回傳結果
8555
									return $result;
292 liveuser 8556
 
293 liveuser 8557
									}#if end
8558
 
8559
								#如果沒有回應內容
8560
								if(!isset($getCertSta["content"])){
8561
 
8562
									#設置錯誤識別
8563
									$result["status"]="false";
292 liveuser 8564
 
293 liveuser 8565
									#設置錯誤訊息
8566
									$result["error"]=$getCertSta;
292 liveuser 8567
 
293 liveuser 8568
									#回傳結果
8569
									return $result;
292 liveuser 8570
 
293 liveuser 8571
									}#if end
8572
 
8573
								#如果回應不是 json
8574
								if(!(json_validate($getCertSta["content"]))){
292 liveuser 8575
 
293 liveuser 8576
									#設置錯誤識別
8577
									$result["status"]="false";
8578
 
8579
									#設置錯誤訊息
8580
									$result["error"]=$getCertSta;
8581
 
8582
									#回傳結果
8583
									return $result;
292 liveuser 8584
 
8585
									}#if end
293 liveuser 8586
 
8587
								#解析json回應
8588
								$getCertStaRes=json_decode($getCertSta["content"]);
292 liveuser 8589
 
293 liveuser 8590
								#如果憑證已經驗證通過了
8591
								if($getCertStaRes->status==="issued"){
292 liveuser 8592
 
293 liveuser 8593
									#if enable debug
8594
									if($debug){
8595
 
8596
										#debug msg
8597
										echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
8598
 
8599
										}#if end
292 liveuser 8600
 
294 liveuser 8601
									#結束等待,跳出 while
293 liveuser 8602
									break 2;
8603
 
292 liveuser 8604
									}#if end
8605
 
293 liveuser 8606
								#如果 zerossl 尚在處理中
8607
								else if($getCertStaRes->status==="pending_validation"){
292 liveuser 8608
 
293 liveuser 8609
									#if enable debug
8610
									if($debug){
8611
 
8612
										#debug msg
8613
										echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
8614
 
8615
										}#if end
8616
 
8617
									#休息1分鐘
8618
									sleep(60);
294 liveuser 8619
 
8620
									#再跑一次取得憑證狀態
8621
									continue;
293 liveuser 8622
 
8623
									}#if end
8624
 
8625
								#反之
8626
								else{
8627
 
8628
									#例外狀況
8629
 
8630
									#設置錯誤識別
8631
									$result["status"]="false";
292 liveuser 8632
 
293 liveuser 8633
									#設置錯誤訊息
8634
									$result["error"]=$getCertSta;
292 liveuser 8635
 
293 liveuser 8636
									#回傳結果
8637
									return $result;
8638
 
8639
									}#else end
292 liveuser 8640
 
293 liveuser 8641
								}#while end
8642
 
8643
							}#if end
8644
 
292 liveuser 8645
						}#if end
294 liveuser 8646
 
8647
					#反之.不應該執行到這邊
8648
					else{
8649
 
8650
						#設置錯誤識別
8651
						$result["status"]="false";
8652
 
8653
						#設置錯誤訊息
8654
						$result["error"]=$verifyDomain;
8655
 
8656
						#回傳結果
8657
						return $result;
8658
 
8659
						}#else 	
291 liveuser 8660
 
292 liveuser 8661
					}#while end
294 liveuser 8662
 
281 liveuser 8663
				#if enable debug
8664
				if($debug){
8665
 
8666
					#debug msg
291 liveuser 8667
					echo "Downloading certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8668
 
8669
					}#if end
8670
 
255 liveuser 8671
				#函式說明:
8672
				#下載certificate.
8673
				#回傳結果:
8674
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8675
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8676
				#$result["function"],當前執行的函式名稱.
8677
				#$result["argu"],所使用的參數.
8678
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8679
				#$result["content"],結果json字串.
8680
				#$result["certificate.crt"],字串,certificate.crt的內容.
8681
				#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
8682
				#必填參數:
8683
				#無.
8684
				#可省略參數:
8685
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 8686
				$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 8687
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 8688
				$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 8689
				#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
8690
				$conf["zerossl::getCert"]["id"]=$csrId;
8691
				#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
8692
				#$conf["zerossl::getCert"]["cname"]="";
8693
				#參考資料:
8694
				#https://zerossl.com/documentation/api/download-certificate-inline/
8695
				#備註:
8696
				#無.
8697
				$getCert=zerossl::getCert($conf["zerossl::getCert"]);
8698
				unset($conf["zerossl::getCert"]);
8699
 
8700
				#如果執行異常
8701
				if($getCert["status"]==="false"){
8702
 
8703
					#設置錯誤識別
8704
					$result["status"]="false";
8705
 
8706
					#設置錯誤訊息
8707
					$result["error"]=$getCert;
8708
 
8709
					#回傳結果
8710
					return $result;
8711
 
8712
					}#if end
281 liveuser 8713
 
8714
				#if enable debug
8715
				if($debug){
8716
 
8717
					#debug msg
291 liveuser 8718
					echo "Creating certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8719
 
8720
					}#if end
8721
 
293 liveuser 8722
				#certPath
8723
				#$cInfo["ssl"]["certPath"];
255 liveuser 8724
 
293 liveuser 8725
				#pKey
8726
				#$cInfo["ssl"]["pKey"];
255 liveuser 8727
 
293 liveuser 8728
				#caPath
8729
				#$cInfo["ssl"]["caPath"]=;
255 liveuser 8730
 
293 liveuser 8731
				#certWithCaPath
8732
				#$cInfo["ssl"]["certWithCaPath"];
8733
 
255 liveuser 8734
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
8735
				#函式說明:
8736
				#一次建立多個檔案,並寫入內容.
8737
				#回傳結果:
8738
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
8739
				#$result["error"],錯誤訊息陣列.
8740
				#$result["function"],當前執行的函數名稱.
8741
				#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
8742
				#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
8743
				#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
8744
				#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
8745
				#$result["argu"],使用的參數.
8746
				#必填參數:
8747
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8748
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
8749
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
293 liveuser 8750
				$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 8751
				#可省略參數:
8752
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
8753
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
8754
				#參考資料:
8755
				#無.
8756
				#備註:
8757
				#無.
293 liveuser 8758
				$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 8759
				unset($conf["zerossl::writeMultiFile"]);
8760
 
8761
				#如果執行異常
8762
				if($writeMultiFile["status"]==="false"){
8763
 
8764
					#設置錯誤識別
8765
					$result["status"]="false";
8766
 
8767
					#設置錯誤訊息
8768
					$result["error"]=$writeMultiFile;
8769
 
8770
					#回傳結果
8771
					return $result;
8772
 
8773
					}#if end
8774
 
8775
				#儲存 actionAfterUpdateCert
8776
				$action=$cInfo["actionAfterUpdateCert"];
8777
 
8778
				#如果有多個指令要執行
294 liveuser 8779
				if(count($action)>1){
255 liveuser 8780
 
281 liveuser 8781
					#if enable debug
8782
					if($debug){
8783
 
8784
						#debug msg
291 liveuser 8785
						echo "There are many cmds to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8786
 
8787
						}#if end
8788
 
8789
					#if enable debug
8790
					if($debug){
8791
 
8792
						#debug msg
291 liveuser 8793
						echo "Running cmd to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8794
 
8795
						}#if end
8796
 
255 liveuser 8797
					#針對每的指令
8798
					foreach($action as $ac){
8799
 
281 liveuser 8800
						#if enable debug
8801
						if($debug){
8802
 
8803
							#debug msg
8804
							echo ".".PHP_EOL;
8805
 
8806
							}#if end
8807
 
255 liveuser 8808
						#函式說明:
8809
						#呼叫shell執行系統命令,並取得回傳的內容.
8810
						#回傳結果:
8811
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8812
						#$result["error"],錯誤訊息陣列.
8813
						#$result["function"],當前執行的函數名稱.
8814
						#$result["argu"],使用的參數.
8815
						#$result["cmd"],執行的指令內容.
8816
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8817
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8818
						#$result["content"],為執行完後的輸出字串.
8819
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8820
						#$result["running"],是否還在執行.
8821
						#$result["pid"],pid.
8822
						#$result["statusCode"],執行結束後的代碼.
8823
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8824
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8825
						#必填參數:
8826
						#$conf["command"],字串,要執行的指令.
294 liveuser 8827
						$conf["external::callShell"]["command"]=$ac;
255 liveuser 8828
						#$conf["fileArgu"],字串,變數__FILE__的內容.
8829
						$conf["external::callShell"]["fileArgu"]=__FILE__;
8830
						#可省略參數:
8831
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
294 liveuser 8832
						#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 8833
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8834
						#$conf["arguIsAddr"]=array();
8835
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8836
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8837
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8838
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8839
						#$conf["enablePrintDescription"]="true";
8840
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8841
						#$conf["printDescription"]="";
8842
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8843
						$conf["external::callShell"]["escapeshellarg"]="true";
8844
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8845
						#$conf["thereIsShellVar"]=array();
8846
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8847
						#$conf["username"]="";
8848
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8849
						#$conf["password"]="";
8850
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8851
						#$conf["useScript"]="";
8852
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8853
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8854
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8855
						#$conf["inBackGround"]="";
8856
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8857
						#$conf["getErr"]="false";
294 liveuser 8858
						#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
8859
						$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 8860
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8861
						#$conf["doNotRun"]="false";
8862
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8863
						#$conf["remoteIp"]="";
8864
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8865
						#$conf["remoteUser"]="";
8866
						#參考資料:
8867
						#exec=>http://php.net/manual/en/function.exec.php
8868
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8869
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8870
						#備註:
8871
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8872
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8873
						$callShell=external::callShell($conf["external::callShell"]);
8874
						unset($conf["external::callShell"]);
8875
 
8876
						#如果執行異常
294 liveuser 8877
						if($callShell["status"]==="false"){
255 liveuser 8878
 
8879
							#設置錯誤識別
8880
							$result["status"]="false";
8881
 
8882
							#設置錯誤訊息
8883
							$result["error"]=$callShell;
8884
 
8885
							#回傳結果
8886
							return $result;
8887
 
8888
							}#if end
8889
 
8890
						}#foreach end
8891
 
8892
					}#if end
8893
 
8894
				#反之
8895
				else{
8896
 
281 liveuser 8897
					#if enable debug
8898
					if($debug){
8899
 
8900
						#debug msg
291 liveuser 8901
						echo "There is only one cmd to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8902
 
8903
						}#if end
8904
 
8905
					#if enable debug
8906
					if($debug){
8907
 
8908
						#debug msg
8909
						echo ".".PHP_EOL;
8910
 
8911
						}#if end
8912
 
255 liveuser 8913
					#函式說明:
8914
					#呼叫shell執行系統命令,並取得回傳的內容.
8915
					#回傳結果:
8916
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8917
					#$result["error"],錯誤訊息陣列.
8918
					#$result["function"],當前執行的函數名稱.
8919
					#$result["argu"],使用的參數.
8920
					#$result["cmd"],執行的指令內容.
8921
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8922
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8923
					#$result["content"],為執行完後的輸出字串.
8924
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8925
					#$result["running"],是否還在執行.
8926
					#$result["pid"],pid.
8927
					#$result["statusCode"],執行結束後的代碼.
8928
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8929
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8930
					#必填參數:
8931
					#$conf["command"],字串,要執行的指令.
302 liveuser 8932
					$conf["external::callShell"]["command"]=$action[0];
255 liveuser 8933
					#$conf["fileArgu"],字串,變數__FILE__的內容.
8934
					$conf["external::callShell"]["fileArgu"]=__FILE__;
8935
					#可省略參數:
8936
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 8937
					#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 8938
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8939
					#$conf["arguIsAddr"]=array();
8940
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8941
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8942
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8943
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8944
					#$conf["enablePrintDescription"]="true";
8945
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8946
					#$conf["printDescription"]="";
8947
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8948
					$conf["external::callShell"]["escapeshellarg"]="true";
8949
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8950
					#$conf["thereIsShellVar"]=array();
8951
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8952
					#$conf["username"]="";
8953
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8954
					#$conf["password"]="";
8955
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8956
					#$conf["useScript"]="";
8957
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8958
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8959
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8960
					#$conf["inBackGround"]="";
8961
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8962
					#$conf["getErr"]="false";
8963
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8964
					#$conf["doNotRun"]="false";
294 liveuser 8965
					#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
8966
					$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 8967
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8968
					#$conf["remoteIp"]="";
8969
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8970
					#$conf["remoteUser"]="";
8971
					#參考資料:
8972
					#exec=>http://php.net/manual/en/function.exec.php
8973
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8974
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8975
					#備註:
8976
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8977
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8978
					$callShell=external::callShell($conf["external::callShell"]);
8979
					unset($conf["external::callShell"]);
294 liveuser 8980
 
255 liveuser 8981
					#如果執行異常
294 liveuser 8982
					if($callShell["status"]==="false"){
255 liveuser 8983
 
8984
						#設置錯誤識別
8985
						$result["status"]="false";
8986
 
8987
						#設置錯誤訊息
8988
						$result["error"]=$callShell;
8989
 
8990
						#回傳結果
8991
						return $result;
8992
 
8993
						}#if end
8994
 
8995
					}#else end
8996
 
8997
				}#if end
8998
 
8999
			#反之
9000
			else{
9001
 
281 liveuser 9002
				#if enable debug
9003
				if($debug){
9004
 
9005
					#debug msg
291 liveuser 9006
					echo "There is already valid ssl for domain name(".$cName.") on zerossl".PHP_EOL;
281 liveuser 9007
 
9008
					}#if end
9009
 
291 liveuser 9010
				#debug
9011
				#var_dump(__LINE__,$getCertList);
9012
 
255 liveuser 9013
				#有 issued 的憑證
9014
 
291 liveuser 9015
				#if enable debug
9016
				if($debug){
9017
 
9018
					#debug msg
9019
					echo "Downloading ssl for domain name(".$cName.") on zerossl".PHP_EOL;
9020
 
9021
					}#if end
9022
 
255 liveuser 9023
				#取得 certificate id at zerossl
9024
				#函式說明:
9025
				#將陣列轉換成存有key與value的陣列
9026
				#回傳的結果:
9027
				#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
9028
				#$result["function"],當前執行的函數
9029
				#$result["error"],錯誤訊息.
9030
				#$result[$i]["key"],原先$i+1個元素的key.
9031
				#$result[$i]["value"],原先$i+1個元素的value.
9032
				#必填參數:
9033
				#$conf["rawInputArray"],陣列,要轉換的陣列變數.
9034
				$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
9035
				#可省略參數:
9036
				#無.
9037
				#參考資料:
9038
				#無.
9039
				#備註:
9040
				#無.
9041
				$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
9042
				unset($conf["arrays::getKeyAndValue"]);
9043
 
9044
				#如果執行異常
9045
				if($getKeyAndValue["status"]==="false"){
9046
 
9047
					#設置錯誤識別
9048
					$result["status"]="false";
9049
 
9050
					#設置錯誤訊息
9051
					$result["error"]=$getKeyAndValue;
9052
 
9053
					#回傳結果
9054
					return $result;
9055
 
9056
					}#if end
9057
 
291 liveuser 9058
				#debug
9059
				#var_dump($getKeyAndValue);exit;
9060
 
255 liveuser 9061
				#儲存 certificate id at zerossl
291 liveuser 9062
				$csrId=$getKeyAndValue[1]["key"];
255 liveuser 9063
 
9064
				#檢查憑證是否已經快過期
9065
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
9066
 
9067
				#如果距離當下不到2個星期就要過期
9068
				if($expiresIn<=86400*14){
291 liveuser 9069
 
281 liveuser 9070
					#if enable debug
9071
					if($debug){
9072
 
9073
						#debug msg
291 liveuser 9074
						echo "Valid ssl for domain name(".$cName.") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
281 liveuser 9075
 
9076
						}#if end
9077
 
291 liveuser 9078
					#debug
9079
					#var_dump($expiresIn);exit;
9080
 
255 liveuser 9081
					#另存舊的憑證id,最後要revoke之.
9082
					$oldCsrId=$csrId;
9083
 
281 liveuser 9084
					#if enable debug
9085
					if($debug){
9086
 
9087
						#debug msg
294 liveuser 9088
						echo "Start request new ssl process for domain name(".$cName.").".PHP_EOL;
281 liveuser 9089
 
9090
						}#if end
9091
 
9092
					#if enable debug
9093
					if($debug){
9094
 
9095
						#debug msg
291 liveuser 9096
						echo "Finding ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9097
 
9098
						}#if end
9099
 
255 liveuser 9100
					#確認有無對應 cName 的 private key
9101
					#函式說明:
9102
					#檢查多個檔案與資料夾是否存在.
9103
					#回傳的結果:
9104
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9105
					#$result["error"],錯誤訊息陣列.
9106
					#$resutl["function"],當前執行的涵式名稱.
9107
					#$result["argu"],使用的參數.
9108
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9109
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9110
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
9111
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
9112
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9113
					#必填參數:
9114
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
291 liveuser 9115
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 9116
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9117
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
9118
					#可省略參數:
9119
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9120
					#$conf["disableWebSearch"]="false";
9121
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9122
					$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
9123
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
9124
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
9125
					#參考資料:
9126
					#http://php.net/manual/en/function.file-exists.php
9127
					#http://php.net/manual/en/control-structures.foreach.php
9128
					#備註:
9129
					#函數file_exists檢查的路徑為檔案系統的路徑
9130
					#$result["varName"][$i]結果未實作
9131
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9132
					unset($conf["fileAccess::checkMultiFileExist"]);
9133
 
9134
					#如果運行異常
9135
					if($checkMultiFileExist["status"]==="false"){
9136
 
9137
						#設置錯誤識別
9138
						$result["status"]="false";
9139
 
9140
						#設置錯誤訊息
9141
						$result["error"]=$getCertList;
9142
 
9143
						#回傳結果
9144
						return $result;
9145
 
9146
						}#if end
9147
 
9148
					#如果沒有 private key
9149
					if($checkMultiFileExist["allExist"]==="false"){
9150
 
281 liveuser 9151
						#if enable debug
9152
						if($debug){
9153
 
9154
							#debug msg
291 liveuser 9155
							echo "Thers is no ssl private key for domain name(".$cName.").".PHP_EOL;
281 liveuser 9156
 
9157
							}#if end
9158
 
9159
						#if enable debug
9160
						if($debug){
9161
 
9162
							#debug msg
291 liveuser 9163
							echo "Creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9164
 
9165
							}#if end
9166
 
255 liveuser 9167
						#建立 private key
9168
						#函式說明:
9169
						#產生ssl private key.
9170
						#回傳結果:
9171
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9172
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
9173
						#$result["function"],當前執行的函式名稱.
9174
						#$result["argu"],所使用的參數.
9175
						#$result["curl_verbose_info"],curl執行的詳細資訊.
9176
						#$result["content"],ssl用的private key.
9177
						#必填參數:
9178
						#$conf["fileArgu"],字串,變數__FILE__的內容.
9179
						$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
9180
						#可省略參數:
9181
						#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
9182
						#$conf["length"]=4096';
9183
						#參考資料:
9184
						#無.
9185
						#備註:
9186
						#key generated by openssl with RSA.
291 liveuser 9187
						$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 9188
						unset($conf["openssl::createPrivateKey"]);
9189
 
9190
						#如果運行異常
9191
						if($createPrivateKey["status"]==="false"){
9192
 
9193
							#設置錯誤識別
9194
							$result["status"]="false";
9195
 
9196
							#設置錯誤訊息
9197
							$result["error"]=$createPrivateKey;
9198
 
9199
							#回傳結果
9200
							return $result;
9201
 
9202
							}#if end
9203
 
9204
						#另存private key的字串
9205
						$pKeyStr=$createPrivateKey["content"];
9206
 
281 liveuser 9207
						#if enable debug
9208
						if($debug){
9209
 
9210
							#debug msg
291 liveuser 9211
							echo "Writing ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9212
 
9213
							}#if end
9214
 
255 liveuser 9215
						#建立private key檔案
9216
						#函式說明:
9217
						#將字串寫入到檔案
9218
						#回傳結果:
9219
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9220
						#$result["error"],錯誤訊息陣列.
9221
						#$result["function"],當前執行的函數名稱.
9222
						#$result["fileInfo"],實際上寫入的檔案資訊陣列.
9223
						#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
9224
						#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
9225
						#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
9226
						#$result["argu"],使用的參數.
9227
						#必填參數:
9228
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9229
						$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
9230
						#可省略參數:
9231
						#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
291 liveuser 9232
						$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 9233
						#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
9234
						$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
9235
						#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
9236
						#$conf["writeMethod"]="a";
9237
						#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
9238
						#$conf["checkRepeat"]="";
9239
						#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
9240
						#$conf["filenameExtensionStartPoint"]="";
9241
						#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
9242
						#$conf["repeatNameRule"]="";
9243
						#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
9244
						$conf["zerossl::writeTextIntoFile"]["web"]="false";
9245
						#參考資料:
9246
						#無.
9247
						#備註:
9248
						#無.
9249
						$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
9250
						unset($conf["zerossl::writeTextIntoFile"]);
9251
 
9252
						#如果運行異常
9253
						if($writeTextIntoFile["status"]==="false"){
9254
 
9255
							#設置錯誤識別
9256
							$result["status"]="false";
9257
 
9258
							#設置錯誤訊息
9259
							$result["error"]=$writeTextIntoFile;
9260
 
9261
							#回傳結果
9262
							return $result;
9263
 
9264
							}#if end
9265
 
9266
						}#if end
9267
 
281 liveuser 9268
					#if enable debug
9269
					if($debug){
9270
 
9271
						#debug msg
291 liveuser 9272
						echo "Creating CSR for domain name(".$cName.") to zerossl.".PHP_EOL;
281 liveuser 9273
 
9274
						}#if end
9275
 
255 liveuser 9276
					#建立準備給zerossl的csr
9277
					#函式說明:
9278
					#產生certificate sign request(CSR).
9279
					#回傳結果:
9280
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9281
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9282
					#$result["function"],當前執行的函式名稱.
9283
					#$result["argu"],所使用的參數.
9284
					#$result["content"],csr內容.
9285
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9286
					#$result["privateKey"], private key 的內容.
9287
					#必填參數:
9288
					#$conf["domain"],字串,csr內容的網域名稱.
9289
					$conf["zerossl::createCSR"]["domain"]=$cName;
9290
					#可省略參數:
9291
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 9292
					$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 9293
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
9294
					#$conf["country"]="";
9295
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
9296
					#$conf["state"]="";
9297
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
9298
					#$conf["org"]="";
9299
					#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
9300
					#$conf["unit"]="";
9301
					#參考資料:
9302
					#無.
9303
					#備註:
9304
					#無.
9305
					$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
9306
					unset($conf["zerossl::createCSR"]);
9307
 
9308
					#如果運行異常
9309
					if($createCSR["status"]==="false"){
9310
 
9311
						#設置錯誤識別
9312
						$result["status"]="false";
9313
 
9314
						#設置錯誤訊息
9315
						$result["error"]=$createCSR;
9316
 
9317
						#回傳結果
9318
						return $result;
9319
 
9320
						}#if end
9321
 
9322
					#取得本地端產生的csr內容
9323
					$csrLocal=$createCSR["content"];
9324
 
281 liveuser 9325
					#if enable debug
9326
					if($debug){
9327
 
9328
						#debug msg
291 liveuser 9329
						echo "Providing CSR for domain name(".$cName.") to zerossl".PHP_EOL;
281 liveuser 9330
 
9331
						}#if end
9332
 
255 liveuser 9333
					#函式說明:
281 liveuser 9334
					#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 9335
					#回傳結果:
9336
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9337
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9338
					#$result["function"],當前執行的函式名稱.
9339
					#$result["argu"],所使用的參數.
9340
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9341
					#$result["id"],用於zerossl api驗證domain的id.
9342
					#$result["content"],字串,得到的json字串回應.
9343
					#$result["cnameKey"],用於dns CNAME驗證鍵名.
9344
					#$result["cnameVal"],用於dms CNAME驗證鍵值.
9345
					#必填參數:
9346
					#$conf["certificate_domains"],字串,要簽署的doamin名稱.
9347
					$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
9348
					#$conf["certificate_csr"],字串,簽署的資訊.
9349
					$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
9350
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9351
					$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
9352
					#可省略參數:
9353
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9354
					$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9355
					#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
9356
					#$conf["path"]=self::getApiInfo()["csrPath"];
9357
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9358
					$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9359
					#參考資料:
9360
					#無.
9361
					#備註:
9362
					#無.
9363
					$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
9364
					unset($conf["zerossl::createCertificate"]);
9365
 
9366
					#如果執行異常
9367
					if($createCertificate["status"]==="false"){
9368
 
9369
						#設置錯誤識別
9370
						$result["status"]="false";
9371
 
9372
						#設置錯誤訊息
9373
						$result["error"]=$createCertificate;
9374
 
9375
						#回傳結果
9376
						return $result;
9377
 
9378
						}#if end
9379
 
9380
					#取得csr在zerossl上的id
9381
					$csrId=$createCertificate["id"];
9382
 
9383
					#取得cname key
9384
					$cNameKey=$createCertificate["cnameKey"];
9385
 
9386
					#取得cname val
9387
					$cNameVal=$createCertificate["cnameVal"];
9388
 
9389
					#初始化要增加的RR記錄
9390
					$rr2add=array();
9391
 
9392
					#設置CNAME的查詢
9393
					$rr2add["query"]=$cNameKey;
9394
 
9395
					#設置CNAME的value
9396
					$rr2add["value"]=$cNameVal;
9397
 
9398
					#設置類型為 CNAME
9399
					$rr2add["type"]="CNAME";
9400
 
9401
					#設置註解
9402
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
9403
 
281 liveuser 9404
					#if enable debug
9405
					if($debug){
9406
 
9407
						#debug msg
335 liveuser 9408
						echo "Adding DNS record to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9409
 
9410
						}#if end
9411
 
255 liveuser 9412
					#函式說明:
9413
					#新增DNS記錄到檔案裡面.
9414
					#回傳結果:
9415
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9416
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9417
					#$result["function"],當前執行的函式名稱.
9418
					#$result["argu"],所使用的參數.
9419
					#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
9420
					#$result["domain"],字串,RR所屬domain.
9421
					#$result["defaultTTL"],字串,預設的RR更新時間.
9422
					#$result["comment"],字串陣列,逐行的註解.
9423
					#必填參數:
9424
					#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
333 liveuser 9425
					$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 9426
					#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
9427
					$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
9428
					#可省略參數:
9429
					#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
9430
					$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
9431
					#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
9432
					#$conf["debug"]="false";
9433
					#參考資料:
9434
					#無.
9435
					#備註:
9436
					#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
9437
					#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
9438
					#php-pear上的Net_DNS2也可以解析RR.
9439
					$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
9440
					unset($conf["zerossl::updateDnsRecordFile"]);
9441
 
9442
					#如果執行異常
9443
					if($updateDnsRecordFile["status"]==="false"){
9444
 
9445
						#設置錯誤識別
9446
						$result["status"]="false";
9447
 
9448
						#設置錯誤訊息
9449
						$result["error"]=$updateDnsRecordFile;
9450
 
9451
						#回傳結果
9452
						return $result;
9453
 
9454
						}#if end
281 liveuser 9455
 
9456
					#if enable debug
9457
					if($debug){
9458
 
9459
						#debug msg
336 liveuser 9460
						echo "Restarting DNS service to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9461
 
9462
						}#if end
9463
 
255 liveuser 9464
					#重新啟動dns伺服器
9465
					#函式說明:
9466
					#呼叫shell執行系統命令,並取得回傳的內容.
9467
					#回傳結果:
9468
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9469
					#$result["error"],錯誤訊息陣列.
9470
					#$result["function"],當前執行的函數名稱.
9471
					#$result["argu"],使用的參數.
9472
					#$result["cmd"],執行的指令內容.
9473
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9474
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9475
					#$result["content"],為執行完後的輸出字串.
9476
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9477
					#$result["running"],是否還在執行.
9478
					#$result["pid"],pid.
9479
					#$result["statusCode"],執行結束後的代碼.
9480
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9481
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9482
					#必填參數:
9483
					#$conf["command"],字串,要執行的指令.
291 liveuser 9484
					$conf["external::callShell"]["command"]="systemctl";
255 liveuser 9485
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9486
					$conf["external::callShell"]["fileArgu"]=__FILE__;
9487
					#可省略參數:
9488
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9489
					$conf["external::callShell"]["argu"]=array("restart","named");
9490
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9491
					#$conf["arguIsAddr"]=array();
9492
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9493
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9494
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9495
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9496
					#$conf["enablePrintDescription"]="true";
9497
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9498
					#$conf["printDescription"]="";
9499
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9500
					#$conf["escapeshellarg"]="false";
9501
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9502
					#$conf["thereIsShellVar"]=array();
9503
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9504
					#$conf["username"]="";
9505
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9506
					#$conf["password"]="";
9507
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9508
					#$conf["useScript"]="";
9509
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9510
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9511
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9512
					#$conf["inBackGround"]="";
9513
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9514
					#$conf["getErr"]="false";
9515
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9516
					#$conf["doNotRun"]="false";
302 liveuser 9517
					#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
9518
					#$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 9519
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
9520
					$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
9521
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
9522
					#$conf["remoteUser"]="root";
9523
					#參考資料:
9524
					#exec=>http://php.net/manual/en/function.exec.php
9525
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9526
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9527
					#備註:
9528
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9529
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9530
					$callShell=external::callShell($conf["external::callShell"]);
9531
					unset($conf["external::callShell"]);
9532
 
9533
					#如果執行異常
9534
					if($callShell["status"]==="false"){
9535
 
9536
						#設置錯誤識別
9537
						$result["status"]="false";
9538
 
9539
						#設置錯誤訊息
9540
						$result["error"]=$callShell;
9541
 
9542
						#回傳結果
9543
						return $result;
9544
 
9545
						}#if end
281 liveuser 9546
 
9547
					#if enable debug
9548
					if($debug){
9549
 
9550
						#debug msg
336 liveuser 9551
						echo "Request zerossl to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9552
 
9553
						}#if end
9554
 
294 liveuser 9555
					#無窮迴圈
9556
					while(true){
255 liveuser 9557
 
294 liveuser 9558
						#函式說明:
9559
						#請求驗證已經透過zerossl::createCertificate要求的domain.
9560
						#回傳結果:
9561
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9562
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
9563
						#$result["function"],當前執行的函式名稱.
9564
						#$result["argu"],所使用的參數.
9565
						#$result["curl_verbose_info"],curl執行的詳細資訊.
9566
						#$result["content"],結果json字串.
9567
						#必填參數:
9568
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
9569
						$conf["zerossl::verifyDomain"]["id"]=$csrId;
9570
						#可省略參數:
9571
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
9572
						$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
9573
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
9574
						$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
9575
						#參考資料:
9576
						#https://zerossl.com/documentation/api/verify-domains/
9577
						#備註:
9578
						#無.
9579
						$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
9580
						unset($conf["zerossl::verifyDomain"]);
9581
 
9582
						#如果執行異常
9583
						if($verifyDomain["status"]==="false"){
9584
 
9585
							#設置錯誤識別
9586
							$result["status"]="false";
255 liveuser 9587
 
294 liveuser 9588
							#設置錯誤訊息
9589
							$result["error"]=$verifyDomain;
255 liveuser 9590
 
294 liveuser 9591
							#回傳結果
9592
							return $result;
9593
 
9594
							}#if end
9595
 
9596
						#如果沒有回內容
9597
						if(!isset($verifyDomain["content"])){
9598
 
9599
							#設置錯誤識別
9600
							$result["status"]="false";
9601
 
9602
							#設置錯誤訊息
9603
							$result["error"]=$verifyDomain;
9604
 
9605
							#回傳結果
9606
							return $result;
9607
 
9608
							}#if end
9609
 
9610
						#如果回應不是 json
9611
						if(!(json_validate($verifyDomain["content"]))){
9612
 
9613
							#設置錯誤識別
9614
							$result["status"]="false";
9615
 
9616
							#設置錯誤訊息
9617
							$result["error"]=$verifyDomain;
9618
 
9619
							#回傳結果
9620
							return $result;
9621
 
9622
							}#if end
9623
 
9624
						/*
9625
						範例json:
9626
						{"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}
9627
						*/
9628
 
9629
						#解析json回應
9630
						$verifyDomainRes=json_decode($verifyDomain["content"]);
9631
 
9632
						#如果回應含有 success
9633
						if(isset($verifyDomainRes->success)){
9634
 
9635
							#如果是 zerossl 驗證失敗
9636
							if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
9637
 
9638
								#如果是 CNAME 記錄找不到
9639
								if($verifyDomainRes->error->code===0){
9640
 
9641
									#取得錯誤訊息
9642
									#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
9643
 
9644
									#if enable debug
9645
									if($debug){
9646
 
9647
										#debug msg
9648
										echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
9649
 
9650
										}#if end
9651
 
9652
									#if enable debug
9653
									if($debug){
9654
 
9655
										#debug msg
9656
										echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
9657
 
9658
										}#if end
9659
 
9660
									#休息60秒
9661
									sleep(60);
9662
 
9663
									#再跑一次要求認證憑證
9664
									continue;
9665
 
9666
									}#if end
9667
 
9668
								#反之為不接受的錯誤訊息
9669
								else{
9670
 
9671
									#設置錯誤識別
9672
									$result["status"]="false";
9673
 
9674
									#設置錯誤訊息
9675
									$result["error"]=$verifyDomain;
9676
 
9677
									#回傳結果
9678
									return $result;
9679
 
9680
									}#else end
9681
 
9682
								}#if end
9683
 
9684
							}#if end
9685
 
9686
						#反之如果回應含有 status
9687
						else if(isset($verifyDomainRes->status)){
9688
 
9689
							#如果是 zerossl 尚在驗證中
9690
							if($verifyDomainRes->status==="pending_validation"){
9691
 
9692
								#if enable debug
9693
								if($debug){
9694
 
9695
									#debug msg
9696
									echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9697
 
9698
									}#if end
9699
 
9700
								#無窮迴圈
9701
								while(true){
9702
 
9703
									#查詢驗證狀況
9704
									#函式說明:
9705
									#取得CSR在zerossl上的狀態
9706
									#回傳結果:
9707
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9708
									#$reuslt["error"],執行不正常結束的錯訊息陣列.
9709
									#$result["function"],當前執行的函式名稱.
9710
									#$result["argu"],所使用的參數.
9711
									#$result["curl_verbose_info"],curl執行的詳細資訊.
9712
									#$result["content"],結果json字串.
9713
									#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9714
									#必填參數:
9715
									#$conf["id"],字串,zerossl::createCertificate回傳的id.
9716
									$conf["zerossl::getCertSta"]["id"]=$csrId;
9717
									#可省略參數:
9718
									#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
9719
									$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
9720
									#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
9721
									$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
9722
									#參考資料:
9723
									#https://zerossl.com/documentation/api/get-certificate/
9724
									#備註:
9725
									#無.
9726
									$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
9727
									unset($conf["zerossl::getCertSta"]);
9728
 
9729
									#如果執行異常
9730
									if($getCertSta["status"]==="false"){
9731
 
9732
										#設置錯誤識別
9733
										$result["status"]="false";
9734
 
9735
										#設置錯誤訊息
9736
										$result["error"]=$getCertSta;
9737
 
9738
										#回傳結果
9739
										return $result;
9740
 
9741
										}#if end
9742
 
9743
									#如果沒有回應內容
9744
									if(!isset($getCertSta["content"])){
9745
 
9746
										#設置錯誤識別
9747
										$result["status"]="false";
9748
 
9749
										#設置錯誤訊息
9750
										$result["error"]=$getCertSta;
9751
 
9752
										#回傳結果
9753
										return $result;
9754
 
9755
										}#if end
9756
 
9757
									#如果回應不是 json
9758
									if(!(json_validate($getCertSta["content"]))){
9759
 
9760
										#設置錯誤識別
9761
										$result["status"]="false";
9762
 
9763
										#設置錯誤訊息
9764
										$result["error"]=$getCertSta;
9765
 
9766
										#回傳結果
9767
										return $result;
9768
 
9769
										}#if end
9770
 
9771
									#解析json回應
9772
									$getCertStaRes=json_decode($getCertSta["content"]);
9773
 
9774
									#如果憑證已經驗證通過了
9775
									if($getCertStaRes->status==="issued"){
9776
 
9777
										#if enable debug
9778
										if($debug){
9779
 
9780
											#debug msg
9781
											echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
9782
 
9783
											}#if end
9784
 
9785
										#結束等待,離開while
9786
										break 2;
9787
 
9788
										}#if end
9789
 
9790
									#如果 zerossl 尚在處理中
9791
									else if($getCertStaRes->status==="pending_validation"){
9792
 
9793
										#if enable debug
9794
										if($debug){
9795
 
9796
											#debug msg
9797
											echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9798
 
9799
											}#if end
9800
 
9801
										#休息1分鐘
9802
										sleep(60);
9803
 
9804
										#再次確認憑證的狀態
9805
										continue;
9806
 
9807
										}#if end
9808
 
9809
									#反之
9810
									else{
9811
 
9812
										#例外狀況
9813
 
9814
										#設置錯誤識別
9815
										$result["status"]="false";
9816
 
9817
										#設置錯誤訊息
9818
										$result["error"]=$getCertSta;
9819
 
9820
										#回傳結果
9821
										return $result;
9822
 
9823
										}#else end
9824
 
9825
									}#while end
9826
 
9827
								}#if end
9828
 
9829
							}#if end
255 liveuser 9830
 
294 liveuser 9831
						}#while end
281 liveuser 9832
 
294 liveuser 9833
 
281 liveuser 9834
					#if enable debug
9835
					if($debug){
9836
 
9837
						#debug msg
291 liveuser 9838
						echo "Downling ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 9839
 
9840
						}#if end
9841
 
255 liveuser 9842
					#函式說明:
9843
					#下載certificate.
9844
					#回傳結果:
9845
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9846
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9847
					#$result["function"],當前執行的函式名稱.
9848
					#$result["argu"],所使用的參數.
9849
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9850
					#$result["content"],結果json字串.
9851
					#$result["certificate.crt"],字串,certificate.crt的內容.
9852
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
9853
					#必填參數:
9854
					#無.
9855
					#可省略參數:
9856
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9857
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9858
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9859
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9860
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
9861
					$conf["zerossl::getCert"]["id"]=$csrId;
9862
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
9863
					#$conf["zerossl::getCert"]["cname"]="";
9864
					#參考資料:
9865
					#https://zerossl.com/documentation/api/download-certificate-inline/
9866
					#備註:
9867
					#無.
9868
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
9869
					unset($conf["zerossl::getCert"]);
9870
 
9871
					#如果執行異常
9872
					if($getCert["status"]==="false"){
9873
 
9874
						#設置錯誤識別
9875
						$result["status"]="false";
9876
 
9877
						#設置錯誤訊息
9878
						$result["error"]=$getCert;
9879
 
9880
						#回傳結果
9881
						return $result;
9882
 
9883
						}#if end
281 liveuser 9884
 
9885
					#if enable debug
9886
					if($debug){
9887
 
9888
						#debug msg
291 liveuser 9889
						echo "Creating ssl for domain name(".$cName.").".PHP_EOL;
281 liveuser 9890
 
9891
						}#if end
9892
 
255 liveuser 9893
					#建立 certificate.crt 檔案
9894
					#$cInfo["certPath"];
9895
 
9896
					#建立 ca_bundle.crt 檔案
9897
					#$cInfo["caPath"];
9898
 
9899
					#建立 certAndCa.crt 檔案
9900
					#$cInfo["certWithCaPath"];
9901
 
9902
					#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
9903
					#函式說明:
9904
					#一次建立多個檔案,並寫入內容.
9905
					#回傳結果:
9906
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9907
					#$result["error"],錯誤訊息陣列.
9908
					#$result["function"],當前執行的函數名稱.
9909
					#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
9910
					#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
9911
					#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
9912
					#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
9913
					#$result["argu"],使用的參數.
9914
					#必填參數:
9915
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9916
					$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
9917
					#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 9918
					$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 9919
					#可省略參數:
9920
					#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
9921
					$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
9922
					#參考資料:
9923
					#無.
9924
					#備註:
9925
					#無.
333 liveuser 9926
					$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 9927
					unset($conf["zerossl::writeMultiFile"]);
9928
 
9929
					#如果執行異常
9930
					if($writeMultiFile["status"]==="false"){
9931
 
9932
						#設置錯誤識別
9933
						$result["status"]="false";
9934
 
9935
						#設置錯誤訊息
9936
						$result["error"]=$writeMultiFile;
9937
 
9938
						#回傳結果
9939
						return $result;
9940
 
9941
						}#if end
9942
 
9943
					#儲存 actionAfterUpdateCert
9944
					$action=$cInfo["actionAfterUpdateCert"];
9945
 
9946
					#如果有多個指令要執行
294 liveuser 9947
					if(count($action)>0){
255 liveuser 9948
 
281 liveuser 9949
						#if enable debug
9950
						if($debug){
9951
 
9952
							#debug msg
338 liveuser 9953
							echo "There many cmd to run to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9954
 
9955
							}#if end
9956
 
294 liveuser 9957
						#針對每個指令
255 liveuser 9958
						foreach($action as $ac){
9959
 
281 liveuser 9960
							#if enable debug
9961
							if($debug){
9962
 
9963
								#debug msg
9964
								echo ".".PHP_EOL;
9965
 
9966
								}#if end
9967
 
255 liveuser 9968
							#函式說明:
9969
							#呼叫shell執行系統命令,並取得回傳的內容.
9970
							#回傳結果:
9971
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9972
							#$result["error"],錯誤訊息陣列.
9973
							#$result["function"],當前執行的函數名稱.
9974
							#$result["argu"],使用的參數.
9975
							#$result["cmd"],執行的指令內容.
9976
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9977
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9978
							#$result["content"],為執行完後的輸出字串.
9979
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9980
							#$result["running"],是否還在執行.
9981
							#$result["pid"],pid.
9982
							#$result["statusCode"],執行結束後的代碼.
9983
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9984
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9985
							#必填參數:
9986
							#$conf["command"],字串,要執行的指令.
302 liveuser 9987
							$conf["external::callShell"]["command"]=$ac;
255 liveuser 9988
							#$conf["fileArgu"],字串,變數__FILE__的內容.
9989
							$conf["external::callShell"]["fileArgu"]=__FILE__;
9990
							#可省略參數:
9991
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 9992
							#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 9993
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9994
							#$conf["arguIsAddr"]=array();
9995
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9996
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9997
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9998
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9999
							#$conf["enablePrintDescription"]="true";
10000
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10001
							#$conf["printDescription"]="";
10002
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10003
							$conf["external::callShell"]["escapeshellarg"]="true";
10004
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10005
							#$conf["thereIsShellVar"]=array();
10006
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10007
							#$conf["username"]="";
10008
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10009
							#$conf["password"]="";
10010
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10011
							#$conf["useScript"]="";
10012
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10013
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10014
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10015
							#$conf["inBackGround"]="";
10016
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10017
							#$conf["getErr"]="false";
10018
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10019
							#$conf["doNotRun"]="false";
302 liveuser 10020
							#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10021
							$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10022
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10023
							#$conf["remoteIp"]="";
10024
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10025
							#$conf["remoteUser"]="";
10026
							#參考資料:
10027
							#exec=>http://php.net/manual/en/function.exec.php
10028
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10029
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10030
							#備註:
10031
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10032
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10033
							$callShell=external::callShell($conf["external::callShell"]);
10034
							unset($conf["external::callShell"]);
294 liveuser 10035
 
255 liveuser 10036
							#如果執行異常
294 liveuser 10037
							if($callShell["status"]==="false"){
255 liveuser 10038
 
10039
								#設置錯誤識別
10040
								$result["status"]="false";
10041
 
10042
								#設置錯誤訊息
10043
								$result["error"]=$callShell;
10044
 
10045
								#回傳結果
10046
								return $result;
10047
 
10048
								}#if end
10049
 
10050
							}#foreach end
10051
 
10052
						}#if end
10053
 
10054
					#反之
10055
					else{
10056
 
281 liveuser 10057
						#if enable debug
10058
						if($debug){
10059
 
10060
							#debug msg
291 liveuser 10061
							echo "There is only one cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 10062
 
10063
							}#if end
10064
 
10065
						#if enable debug
10066
						if($debug){
10067
 
10068
							#debug msg
10069
							echo ".".PHP_EOL;
10070
 
10071
							}#if end
10072
 
255 liveuser 10073
						#函式說明:
10074
						#呼叫shell執行系統命令,並取得回傳的內容.
10075
						#回傳結果:
10076
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10077
						#$result["error"],錯誤訊息陣列.
10078
						#$result["function"],當前執行的函數名稱.
10079
						#$result["argu"],使用的參數.
10080
						#$result["cmd"],執行的指令內容.
10081
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10082
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10083
						#$result["content"],為執行完後的輸出字串.
10084
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10085
						#$result["running"],是否還在執行.
10086
						#$result["pid"],pid.
10087
						#$result["statusCode"],執行結束後的代碼.
10088
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10089
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10090
						#必填參數:
10091
						#$conf["command"],字串,要執行的指令.
302 liveuser 10092
						$conf["external::callShell"]["command"]=$action[0];
255 liveuser 10093
						#$conf["fileArgu"],字串,變數__FILE__的內容.
10094
						$conf["external::callShell"]["fileArgu"]=__FILE__;
10095
						#可省略參數:
10096
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10097
						#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 10098
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10099
						#$conf["arguIsAddr"]=array();
10100
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10101
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10102
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10103
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10104
						#$conf["enablePrintDescription"]="true";
10105
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10106
						#$conf["printDescription"]="";
10107
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10108
						$conf["external::callShell"]["escapeshellarg"]="true";
10109
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10110
						#$conf["thereIsShellVar"]=array();
10111
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10112
						#$conf["username"]="";
10113
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10114
						#$conf["password"]="";
10115
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10116
						#$conf["useScript"]="";
10117
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10118
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10119
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10120
						#$conf["inBackGround"]="";
10121
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10122
						#$conf["getErr"]="false";
10123
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10124
						#$conf["doNotRun"]="false";
302 liveuser 10125
						#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10126
						$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10127
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10128
						#$conf["remoteIp"]="";
10129
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10130
						#$conf["remoteUser"]="";
10131
						#參考資料:
10132
						#exec=>http://php.net/manual/en/function.exec.php
10133
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10134
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10135
						#備註:
10136
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10137
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10138
						$callShell=external::callShell($conf["external::callShell"]);
10139
						unset($conf["external::callShell"]);
294 liveuser 10140
 
255 liveuser 10141
						#如果執行異常
294 liveuser 10142
						if($callShell["status"]==="false"){
255 liveuser 10143
 
10144
							#設置錯誤識別
10145
							$result["status"]="false";
10146
 
10147
							#設置錯誤訊息
10148
							$result["error"]=$callShell;
10149
 
10150
							#回傳結果
10151
							return $result;
10152
 
10153
							}#if end
10154
 
10155
						}#else end
10156
 
10157
					#要移除舊的憑證 
10158
 
281 liveuser 10159
					#if enable debug
10160
					if($debug){
10161
 
10162
						#debug msg
341 liveuser 10163
						echo "Revoke old ssl(".$conf["info"]["share"]["apiDomain"].") on zerossl".PHP_EOL;
281 liveuser 10164
 
10165
						}#if end
10166
 
255 liveuser 10167
					#舊憑證於zerossl上的id
10168
					#$oldCsrId
10169
 
341 liveuser 10170
					#無窮迴圈
10171
					while(true){
255 liveuser 10172
 
341 liveuser 10173
						#移除舊的憑證
10174
						#函式說明:
10175
						#請求廢除 issued zerossl certificate.
10176
						#回傳結果:
10177
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10178
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
10179
						#$result["function"],當前執行的函式名稱.
10180
						#$result["argu"],所使用的參數.
10181
						#$result["curl_verbose_info"],curl執行的詳細資訊.
10182
						#$result["content"],結果json字串.
10183
						#$result["busy"],若content結果含有busy屬性,且為1,則為"true";反之為"false".
10184
						#必填參數:
10185
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
10186
						$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
10187
						#可省略參數:
10188
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
10189
						$conf["zerosssl::revokeCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
10190
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
10191
						$conf["zerosssl::revokeCert"]["key"]=$conf["info"]["share"]["key"];
10192
						#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
10193
						$conf["zerosssl::revokeCert"]["reason"]="Superseded";
10194
						#參考資料:
10195
						#https://zerossl.com/documentation/api/revoke-certificate/
10196
						#備註:
10197
						#無.
10198
						$revokeCert=zerossl::revokeCert($conf["zerosssl::revokeCert"]);
10199
						unset($conf["zerosssl::revokeCert"]);
10200
 
10201
						#如果執行異常
10202
						if($revokeCert["status"]==="false"){
10203
 
10204
							#如果是 api endpoint busy
10205
							if($revokeCert["busy"]==="true"){
10206
 
10207
								#if enable debug
10208
								if($debug){
10209
 
10210
									#debug msg
10211
									echo "Api endpoint busy, retry revoke old ssl(".$conf["info"]["share"]["apiDomain"].") on zerossl in 60 seconds".PHP_EOL;
10212
 
10213
									}#if end
10214
 
10215
								#休息1分鐘
10216
								sleep(60);
10217
 
10218
								#再執行一次
10219
								continue;
10220
 
10221
								}#if end
10222
 
10223
							#設置錯誤識別
10224
							$result["status"]="false";
255 liveuser 10225
 
341 liveuser 10226
							#設置錯誤訊息
10227
							$result["error"]=$revokeCert;
255 liveuser 10228
 
341 liveuser 10229
							#回傳結果
10230
							return $result;
10231
 
10232
							}#if end
10233
 
10234
						#revoke 成功,跳出 while loop.
10235
						break;
10236
 
10237
						}#while end
10238
 
10239
					#if enable debug
10240
					if($debug){
10241
 
10242
						#debug msg
10243
						echo "Old ssl on zerossl(".$conf["info"]["share"]["apiDomain"].") revoked".PHP_EOL;
10244
 
291 liveuser 10245
						}#if end
10246
 
255 liveuser 10247
					}#if end
10248
 
10249
				#反之,尚不需要提前申請新的憑證
10250
				else{
10251
 
291 liveuser 10252
					#debug
10253
					#var_dump(__LINE__,"尚不需要提前申請新的憑證");exit;
10254
 
281 liveuser 10255
					#if enable debug
10256
					if($debug){
10257
 
10258
						#debug msg
291 liveuser 10259
						echo "ssl for domain name(".$cName.") is valid ".PHP_EOL;
281 liveuser 10260
 
10261
						}#if end
10262
 
10263
					#if enable debug
10264
					if($debug){
10265
 
10266
						#debug msg
291 liveuser 10267
						echo "Downling ssl for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 10268
 
10269
						}#if end
10270
 
310 liveuser 10271
					#if enable debug
10272
					if($debug){
10273
 
10274
						#debug msg
10275
						echo "ID for domain name(".$cName.") on zerossl is ".$csrId.".".PHP_EOL;
10276
 
10277
						}#if end
10278
 
255 liveuser 10279
					#下載憑證
10280
					#函式說明:
10281
					#下載certificate.
10282
					#回傳結果:
10283
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10284
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10285
					#$result["function"],當前執行的函式名稱.
10286
					#$result["argu"],所使用的參數.
10287
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10288
					#$result["content"],結果json字串.
10289
					#$result["certificate.crt"],字串,certificate.crt的內容.
10290
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
10291
					#必填參數:
10292
					#無.
10293
					#可省略參數:
10294
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 10295
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 10296
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 10297
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 10298
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
10299
					$conf["zerossl::getCert"]["id"]=$csrId;
10300
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
10301
					#$conf["zerossl::getCert"]["cname"]="";
10302
					#參考資料:
10303
					#https://zerossl.com/documentation/api/download-certificate-inline/
10304
					#備註:
10305
					#無.
10306
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
10307
					unset($conf["zerossl::getCert"]);
10308
 
10309
					#如果執行異常
10310
					if($getCert["status"]==="false"){
10311
 
10312
						#設置錯誤識別
10313
						$result["status"]="false";
10314
 
10315
						#設置錯誤訊息
10316
						$result["error"]=$getCert;
10317
 
10318
						#回傳結果
10319
						return $result;
10320
 
10321
						}#if end
281 liveuser 10322
 
10323
					#if enable debug
10324
					if($debug){
10325
 
10326
						#debug msg
291 liveuser 10327
						echo "Getting host ssl for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10328
 
10329
						}#if end
10330
 
255 liveuser 10331
					#zerossl上的certificate.crt內容
10332
					#$getCert["certificate.crt"];
310 liveuser 10333
 
255 liveuser 10334
					#zerossl上的ca_bundle.crt內容
10335
					#$getCert["ca_bundle.crt"];
10336
 
10337
					#certificate.crt and ca_bundle.crt 合併後的檔案內容
10338
					#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
10339
 
10340
					#certificate.crt 檔案
10341
					#$cInfo["certPath"];
10342
 
10343
					#ca_bundle.crt 檔案
10344
					#$cInfo["caPath"];
10345
 
10346
					#certAndCa.crt 檔案
10347
					#$cInfo["certWithCaPath"];
281 liveuser 10348
 
10349
					#if enable debug
10350
					if($debug){
10351
 
10352
						#debug msg
310 liveuser 10353
						echo "Getting host ssl(certificate.crt) which path is ".$cInfo["ssl"]["certPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10354
 
10355
						}#if end
255 liveuser 10356
 
10357
					#取得既有的 certificate.crt 檔案內容
10358
					#函式說明:
10359
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10360
					#回傳的變數說明:
10361
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10362
					#$result["error"],錯誤訊息提示.
10363
					#$result["warning"],警告訊息.
10364
					#$result["function"],當前執行的函數名稱.
10365
					#$result["fileContent"],爲檔案的內容陣列.
10366
					#$result["lineCount"],爲檔案內容總共的行數.
10367
					#$result["fullContent"],為檔案的完整內容.
10368
					#$result["base64dataOnly"],檔案的base64data.
10369
					#$result["base64data"],為在網頁上給予src參數的數值.
10370
					#$result["mimeType"],為檔案的mime type.
10371
					#必填參數:
10372
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10373
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certPath"];
255 liveuser 10374
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10375
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10376
					#可省略參數:
10377
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10378
					#$conf["web"]="true";
10379
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10380
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10381
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10382
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10383
					#參考資料:
10384
					#file(),取得檔案內容的行數.
10385
					#file=>http:#php.net/manual/en/function.file.php
10386
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10387
					#filesize=>http://php.net/manual/en/function.filesize.php
10388
					#參考資料:
10389
					#無.
10390
					#備註:
10391
					#無.
291 liveuser 10392
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10393
					unset($conf["fileAccesss::getFileContent"]);
10394
 
10395
					#如果執行異常
10396
					if($getFileContent["status"]==="false"){
10397
 
10398
						#設置錯誤識別
10399
						$result["status"]="false";
10400
 
10401
						#設置錯誤訊息
10402
						$result["error"]=$getFileContent;
10403
 
10404
						#回傳結果
10405
						return $result;
10406
 
10407
						}#if end
10408
 
281 liveuser 10409
					#if enable debug
10410
					if($debug){
10411
 
10412
						#debug msg
291 liveuser 10413
						echo "Checking host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10414
 
10415
						}#if end
10416
 
291 liveuser 10417
					#預設 certificate.crt 不用更新
10418
					$certificate_need_update="false";
10419
 
255 liveuser 10420
					#如果既有憑證跟剛下載的憑證不一樣
10421
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
10422
 
10423
						#識別要改成下載好的憑證
10424
						$certificate_need_update="true";
281 liveuser 10425
 
10426
						#if enable debug
10427
						if($debug){
10428
 
10429
							#debug msg
291 liveuser 10430
							echo "SSL(certificate.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10431
 
10432
							}#if end
255 liveuser 10433
 
10434
						}#if end
281 liveuser 10435
 
10436
					#if enable debug
10437
					if($debug){
10438
 
10439
						#debug msg
310 liveuser 10440
						echo "Getting host ssl(ca_bundle.crt) which path is ".$cInfo["ssl"]["caPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10441
 
10442
						}#if end
10443
 
255 liveuser 10444
					#取得既有的 ca_bundle.crt 檔案內容
10445
					#函式說明:
10446
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10447
					#回傳的變數說明:
10448
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10449
					#$result["error"],錯誤訊息提示.
10450
					#$result["warning"],警告訊息.
10451
					#$result["function"],當前執行的函數名稱.
10452
					#$result["fileContent"],爲檔案的內容陣列.
10453
					#$result["lineCount"],爲檔案內容總共的行數.
10454
					#$result["fullContent"],為檔案的完整內容.
10455
					#$result["base64dataOnly"],檔案的base64data.
10456
					#$result["base64data"],為在網頁上給予src參數的數值.
10457
					#$result["mimeType"],為檔案的mime type.
10458
					#必填參數:
10459
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10460
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["caPath"];
255 liveuser 10461
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10462
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10463
					#可省略參數:
10464
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10465
					#$conf["web"]="true";
10466
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10467
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10468
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10469
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10470
					#參考資料:
10471
					#file(),取得檔案內容的行數.
10472
					#file=>http:#php.net/manual/en/function.file.php
10473
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10474
					#filesize=>http://php.net/manual/en/function.filesize.php
10475
					#參考資料:
10476
					#無.
10477
					#備註:
10478
					#無.
291 liveuser 10479
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10480
					unset($conf["fileAccesss::getFileContent"]);
10481
 
10482
					#如果執行異常
10483
					if($getFileContent["status"]==="false"){
10484
 
10485
						#設置錯誤識別
10486
						$result["status"]="false";
10487
 
10488
						#設置錯誤訊息
10489
						$result["error"]=$getFileContent;
10490
 
10491
						#回傳結果
10492
						return $result;
10493
 
10494
						}#if end
10495
 
281 liveuser 10496
					#if enable debug
10497
					if($debug){
10498
 
10499
						#debug msg
291 liveuser 10500
						echo "Checking host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10501
 
10502
						}#if end
10503
 
291 liveuser 10504
					#預設 ca_bundle.crt 不用更新
10505
					$ca_bundle_need_update="false";
10506
 
255 liveuser 10507
					#如果既有憑證跟剛下載的憑證不一樣
10508
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
10509
 
10510
						#識別要改成下載好的憑證
10511
						$ca_bundle_need_update="true";
281 liveuser 10512
 
10513
						#if enable debug
10514
						if($debug){
10515
 
10516
							#debug msg
291 liveuser 10517
							echo "SSL(ca_bundle.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10518
 
10519
							}#if end
255 liveuser 10520
 
10521
						}#if end
10522
 
281 liveuser 10523
					#if enable debug
10524
					if($debug){
10525
 
10526
						#debug msg
310 liveuser 10527
						echo "Getting host ssl(cert and ca_bundle) which path is ".$cInfo["ssl"]["certWithCaPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10528
 
10529
						}#if end
10530
 
255 liveuser 10531
					#取得既有的 certWithCa 檔案內容
10532
					#函式說明:
10533
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10534
					#回傳的變數說明:
10535
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10536
					#$result["error"],錯誤訊息提示.
10537
					#$result["warning"],警告訊息.
10538
					#$result["function"],當前執行的函數名稱.
10539
					#$result["fileContent"],爲檔案的內容陣列.
10540
					#$result["lineCount"],爲檔案內容總共的行數.
10541
					#$result["fullContent"],為檔案的完整內容.
10542
					#$result["base64dataOnly"],檔案的base64data.
10543
					#$result["base64data"],為在網頁上給予src參數的數值.
10544
					#$result["mimeType"],為檔案的mime type.
10545
					#必填參數:
10546
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10547
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certWithCaPath"];
255 liveuser 10548
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10549
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10550
					#可省略參數:
10551
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10552
					#$conf["web"]="true";
10553
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10554
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10555
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10556
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10557
					#參考資料:
10558
					#file(),取得檔案內容的行數.
10559
					#file=>http:#php.net/manual/en/function.file.php
10560
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10561
					#filesize=>http://php.net/manual/en/function.filesize.php
10562
					#參考資料:
10563
					#無.
10564
					#備註:
10565
					#無.
291 liveuser 10566
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10567
					unset($conf["fileAccesss::getFileContent"]);
10568
 
10569
					#如果執行異常
10570
					if($getFileContent["status"]==="false"){
10571
 
10572
						#設置錯誤識別
10573
						$result["status"]="false";
10574
 
10575
						#設置錯誤訊息
10576
						$result["error"]=$getFileContent;
10577
 
10578
						#回傳結果
10579
						return $result;
10580
 
10581
						}#if end
10582
 
281 liveuser 10583
					#if enable debug
10584
					if($debug){
10585
 
10586
						#debug msg
291 liveuser 10587
						echo "Checking host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10588
 
10589
						}#if end
10590
 
291 liveuser 10591
					#預設 cert_and_ca_bundle.crt 不用更新
10592
					$cert_and_ca_bundle_need_update="false";
10593
 
255 liveuser 10594
					#如果既有憑證跟剛下載的憑證不一樣
10595
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
10596
 
10597
						#識別要改成下載好的憑證
10598
						$cert_and_ca_bundle_need_update="true";
281 liveuser 10599
 
10600
						#if enable debug
10601
						if($debug){
10602
 
10603
							#debug msg
291 liveuser 10604
							echo "SSL(cert and ca_bundle) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10605
 
10606
							}#if end
255 liveuser 10607
 
10608
						}#if end
10609
 
10610
					#預設不需要執行更新憑證後的動作
10611
					$requireActionAfterUpdateCert="false";
10612
 
10613
					#如果 certificate 需要更新
10614
					if($certificate_need_update==="true"){
10615
 
281 liveuser 10616
						#if enable debug
10617
						if($debug){
10618
 
10619
							#debug msg
291 liveuser 10620
							echo "Updating host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10621
 
10622
							}#if end
10623
 
255 liveuser 10624
						#更新之
10625
						#函式說明:
10626
						#一次建立多個檔案,並寫入內容.
10627
						#回傳結果:
10628
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10629
						#$result["error"],錯誤訊息陣列.
10630
						#$result["function"],當前執行的函數名稱.
10631
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10632
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10633
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10634
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10635
						#$result["argu"],使用的參數.
10636
						#必填參數:
10637
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10638
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10639
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10640
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"]);
255 liveuser 10641
						#可省略參數:
10642
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10643
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
10644
						#參考資料:
10645
						#無.
10646
						#備註:
10647
						#無.
291 liveuser 10648
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10649
						unset($conf["zerossl::writeMultiFile"]);
10650
 
10651
						#如果執行異常
10652
						if($writeMultiFile["status"]==="false"){
10653
 
10654
							#設置錯誤識別
10655
							$result["status"]="false";
10656
 
10657
							#設置錯誤訊息
10658
							$result["error"]=$writeMultiFile;
10659
 
10660
							#回傳結果
10661
							return $result;
10662
 
10663
							}#if end
293 liveuser 10664
 
10665
						#設置需要執行指令來生效憑證
10666
						$requireActionAfterUpdateCert="true";
255 liveuser 10667
 
10668
						}#if end
10669
 
10670
					#如果 ca_bunle 需要更新
10671
					if($ca_bundle_need_update==="true"){
10672
 
281 liveuser 10673
						#if enable debug
10674
						if($debug){
10675
 
10676
							#debug msg
291 liveuser 10677
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10678
 
10679
							}#if end
293 liveuser 10680
 
10681
						#設置需要執行指令來生效憑證
10682
						$requireActionAfterUpdateCert="true";
281 liveuser 10683
 
255 liveuser 10684
						#更新之
10685
						#函式說明:
10686
						#一次建立多個檔案,並寫入內容.
10687
						#回傳結果:
10688
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10689
						#$result["error"],錯誤訊息陣列.
10690
						#$result["function"],當前執行的函數名稱.
10691
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10692
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10693
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10694
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10695
						#$result["argu"],使用的參數.
10696
						#必填參數:
10697
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10698
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10699
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10700
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["caPath"]);
255 liveuser 10701
						#可省略參數:
10702
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10703
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
10704
						#參考資料:
10705
						#無.
10706
						#備註:
10707
						#無.
291 liveuser 10708
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10709
						unset($conf["zerossl::writeMultiFile"]);
10710
 
10711
						#如果執行異常
10712
						if($writeMultiFile["status"]==="false"){
10713
 
10714
							#設置錯誤識別
10715
							$result["status"]="false";
10716
 
10717
							#設置錯誤訊息
10718
							$result["error"]=$writeMultiFile;
10719
 
10720
							#回傳結果
10721
							return $result;
10722
 
10723
							}#if end
293 liveuser 10724
 
10725
						#設置需要執行指令來生效憑證
10726
						$requireActionAfterUpdateCert="true";
255 liveuser 10727
 
10728
						}#if end
10729
 
10730
					#如果 certificate and ca_bundle 需要更新
10731
					if($cert_and_ca_bundle_need_update==="true"){
10732
 
281 liveuser 10733
						#if enable debug
10734
						if($debug){
10735
 
10736
							#debug msg
291 liveuser 10737
							echo "Updating host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10738
 
10739
							}#if end
10740
 
255 liveuser 10741
						#更新之
10742
						#函式說明:
10743
						#一次建立多個檔案,並寫入內容.
10744
						#回傳結果:
10745
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10746
						#$result["error"],錯誤訊息陣列.
10747
						#$result["function"],當前執行的函數名稱.
10748
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10749
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10750
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10751
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10752
						#$result["argu"],使用的參數.
10753
						#必填參數:
10754
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10755
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10756
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10757
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certWithCaPath"]);
255 liveuser 10758
						#可省略參數:
10759
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10760
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
10761
						#參考資料:
10762
						#無.
10763
						#備註:
10764
						#無.
291 liveuser 10765
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10766
						unset($conf["zerossl::writeMultiFile"]);
10767
 
10768
						#如果執行異常
10769
						if($writeMultiFile["status"]==="false"){
10770
 
10771
							#設置錯誤識別
10772
							$result["status"]="false";
10773
 
10774
							#設置錯誤訊息
10775
							$result["error"]=$writeMultiFile;
10776
 
10777
							#回傳結果
10778
							return $result;
10779
 
10780
							}#if end
10781
 
293 liveuser 10782
						#設置需要執行指令來生效憑證
10783
						$requireActionAfterUpdateCert="true";
10784
 
255 liveuser 10785
						}#if end
10786
 
10787
					#如果有需要執行指令來生效憑證
10788
					if($requireActionAfterUpdateCert==="true"){
10789
 
281 liveuser 10790
						#if enable debug
10791
						if($debug){
10792
 
10793
							#debug msg
291 liveuser 10794
							echo "Action required to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 10795
 
10796
							}#if end
10797
 
255 liveuser 10798
						#儲存 actionAfterUpdateCert
10799
						$action=$cInfo["actionAfterUpdateCert"];
10800
 
10801
						#如果有多個指令要執行
310 liveuser 10802
						if(count($action)>0){
255 liveuser 10803
 
281 liveuser 10804
							#if enable debug
10805
							if($debug){
10806
 
10807
								#debug msg
291 liveuser 10808
								echo "There are many cmds to run to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 10809
 
10810
								}#if end
10811
 
255 liveuser 10812
							#針對每的指令
10813
							foreach($action as $ac){
10814
 
281 liveuser 10815
								#if enable debug
10816
								if($debug){
10817
 
10818
									#debug msg
10819
									echo ".".PHP_EOL;
10820
 
10821
									}#if end
293 liveuser 10822
 
10823
								#函式說明:
255 liveuser 10824
								#呼叫shell執行系統命令,並取得回傳的內容.
10825
								#回傳結果:
10826
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10827
								#$result["error"],錯誤訊息陣列.
10828
								#$result["function"],當前執行的函數名稱.
10829
								#$result["argu"],使用的參數.
10830
								#$result["cmd"],執行的指令內容.
10831
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10832
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10833
								#$result["content"],為執行完後的輸出字串.
10834
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10835
								#$result["running"],是否還在執行.
10836
								#$result["pid"],pid.
10837
								#$result["statusCode"],執行結束後的代碼.
10838
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10839
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10840
								#必填參數:
10841
								#$conf["command"],字串,要執行的指令.
302 liveuser 10842
								$conf["external::callShell"]["command"]=$ac;
255 liveuser 10843
								#$conf["fileArgu"],字串,變數__FILE__的內容.
10844
								$conf["external::callShell"]["fileArgu"]=__FILE__;
10845
								#可省略參數:
10846
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10847
								#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
255 liveuser 10848
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10849
								#$conf["arguIsAddr"]=array();
10850
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10851
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10852
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10853
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10854
								#$conf["enablePrintDescription"]="true";
10855
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10856
								#$conf["printDescription"]="";
10857
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10858
								$conf["external::callShell"]["escapeshellarg"]="true";
10859
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10860
								#$conf["thereIsShellVar"]=array();
10861
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10862
								#$conf["username"]="";
10863
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10864
								#$conf["password"]="";
10865
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10866
								#$conf["useScript"]="";
10867
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10868
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10869
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10870
								#$conf["inBackGround"]="";
10871
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10872
								#$conf["getErr"]="false";
10873
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10874
								#$conf["doNotRun"]="false";
302 liveuser 10875
								#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10876
								$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10877
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10878
								#$conf["remoteIp"]="";
10879
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10880
								#$conf["remoteUser"]="";
10881
								#參考資料:
10882
								#exec=>http://php.net/manual/en/function.exec.php
10883
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10884
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10885
								#備註:
10886
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10887
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10888
								$callShell=external::callShell($conf["external::callShell"]);
10889
								unset($conf["external::callShell"]);
10890
 
10891
								#如果執行異常
310 liveuser 10892
								if($callShell["status"]==="false"){
255 liveuser 10893
 
10894
									#設置錯誤識別
10895
									$result["status"]="false";
10896
 
10897
									#設置錯誤訊息
10898
									$result["error"]=$callShell;
10899
 
10900
									#回傳結果
10901
									return $result;
10902
 
10903
									}#if end
10904
 
10905
								}#foreach end
10906
 
10907
							}#if end
10908
 
291 liveuser 10909
						#反之
10910
						else{
10911
 
10912
							#if enable debug
10913
							if($debug){
10914
 
10915
								#debug msg
10916
								echo "There is only one cmd to run to apply ssl for domain name(".$cName.")".PHP_EOL;
255 liveuser 10917
 
291 liveuser 10918
								}#if end
281 liveuser 10919
 
291 liveuser 10920
							#函式說明:
10921
							#呼叫shell執行系統命令,並取得回傳的內容.
10922
							#回傳結果:
10923
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10924
							#$result["error"],錯誤訊息陣列.
10925
							#$result["function"],當前執行的函數名稱.
10926
							#$result["argu"],使用的參數.
10927
							#$result["cmd"],執行的指令內容.
10928
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10929
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10930
							#$result["content"],為執行完後的輸出字串.
10931
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10932
							#$result["running"],是否還在執行.
10933
							#$result["pid"],pid.
10934
							#$result["statusCode"],執行結束後的代碼.
10935
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10936
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10937
							#必填參數:
10938
							#$conf["command"],字串,要執行的指令.
302 liveuser 10939
							$conf["external::callShell"]["command"]=$action;
291 liveuser 10940
							#$conf["fileArgu"],字串,變數__FILE__的內容.
10941
							$conf["external::callShell"]["fileArgu"]=__FILE__;
10942
							#可省略參數:
10943
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10944
							#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
291 liveuser 10945
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10946
							#$conf["arguIsAddr"]=array();
10947
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10948
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10949
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10950
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10951
							#$conf["enablePrintDescription"]="true";
10952
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10953
							#$conf["printDescription"]="";
10954
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10955
							$conf["external::callShell"]["escapeshellarg"]="true";
10956
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10957
							#$conf["thereIsShellVar"]=array();
10958
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10959
							#$conf["username"]="";
10960
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10961
							#$conf["password"]="";
10962
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10963
							#$conf["useScript"]="";
10964
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10965
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10966
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10967
							#$conf["inBackGround"]="";
10968
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10969
							#$conf["getErr"]="false";
10970
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10971
							#$conf["doNotRun"]="false";
302 liveuser 10972
							#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10973
							$conf["external::callShell"]["cmdContainArgu"]="true";
291 liveuser 10974
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10975
							#$conf["remoteIp"]="";
10976
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10977
							#$conf["remoteUser"]="";
10978
							#參考資料:
10979
							#exec=>http://php.net/manual/en/function.exec.php
10980
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10981
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10982
							#備註:
10983
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10984
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10985
							$callShell=external::callShell($conf["external::callShell"]);
10986
							unset($conf["external::callShell"]);
10987
 
10988
							#如果執行異常
310 liveuser 10989
							if($callShell["status"]==="false"){
255 liveuser 10990
 
291 liveuser 10991
								#設置錯誤識別
10992
								$result["status"]="false";
255 liveuser 10993
 
291 liveuser 10994
								#設置錯誤訊息
10995
								$result["error"]=$callShell;
255 liveuser 10996
 
291 liveuser 10997
								#回傳結果
10998
								return $result;
255 liveuser 10999
 
291 liveuser 11000
								}#if end
11001
 
11002
							}#else end
11003
 
11004
						}#if end
255 liveuser 11005
 
11006
					}#else end
11007
 
11008
				}#else end
291 liveuser 11009
 
255 liveuser 11010
			}#foreach end
11011
 
11012
		}#function sslUpdater_idle end
11013
 
226 liveuser 11014
	}#class zerossl end
255 liveuser 11015