Subversion Repositories php-qbpwcf

Rev

Rev 406 | 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
 
409 liveuser 4686
			#如果新 RR 的 type 是 MX 或 CNAME 且 value 不為 "." 結尾.
4687
			if( ( $newRR["type"]==="MX" || $newRR["type"]==="CNAME" ) && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
404 liveuser 4688
 
255 liveuser 4689
				#new RR add dot to value end.
4690
				$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
4691
 
4692
				#如果要debug
4693
				if($conf["debug"]==="true"){
4694
 
4695
					#函式說明:
4696
					#撰寫log
4697
					#回傳結果:
4698
					#$result["status"],狀態,"true"或"false".
4699
					#$result["error"],錯誤訊息陣列.
4700
					#$result["function"],當前函式的名稱.
4701
					#$result["argu"],使用的參數.
4702
					#$result["content"],要寫入log的內容字串.
4703
					#必填參數:
4704
					#$conf["path"],字串,log檔案的路徑與名稱.
4705
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4706
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4707
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4708
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4709
					$conf["logs::record"]["fileArgu"]=__FILE__;
4710
					#可省略參數:
4711
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4712
					#$conf["rewrite"]="false";
4713
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4714
					#$conf["returnOnly"]="true";
4715
					#參考資料:
4716
					#無.
4717
					#備註:
4718
					#無.
4719
					$record=logs::record($conf["logs::record"]);
4720
					unset($conf["logs::record"]);
4721
 
4722
					#函式說明:
4723
					#撰寫log
4724
					#回傳結果:
4725
					#$result["status"],狀態,"true"或"false".
4726
					#$result["error"],錯誤訊息陣列.
4727
					#$result["function"],當前函式的名稱.
4728
					#$result["argu"],使用的參數.
4729
					#$result["content"],要寫入log的內容字串.
4730
					#必填參數:
4731
					#$conf["path"],字串,log檔案的路徑與名稱.
4732
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4733
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4734
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4735
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4736
					$conf["logs::record"]["fileArgu"]=__FILE__;
4737
					#可省略參數:
4738
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4739
					#$conf["rewrite"]="false";
4740
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4741
					#$conf["returnOnly"]="true";
4742
					#參考資料:
4743
					#無.
4744
					#備註:
4745
					#無.
4746
					$record=logs::record($conf["logs::record"]);
4747
					unset($conf["logs::record"]);
4748
 
4749
					}#if end
4750
 
4751
				}#if end
4752
 
249 liveuser 4753
			#針對 zone file 中既有的每個RR記錄
4754
			foreach($result["content"] as $index => $oldRR){
4755
 
4756
				#如果既有的跟新的RR都為 $ORIGIN
4757
				if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
4758
 
4759
					#取代既有的 RR
4760
					$result["content"][$index]=$newRR;
4761
 
4762
					#換看下一筆newRR
4763
					continue 2;
4764
 
4765
					}#if end
4766
 
4767
				#如果既有的跟新的RR都為 $TTL
4768
				if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
4769
 
4770
					#取代既有的 RR
4771
					$result["content"][$index]=$newRR;
4772
 
4773
					#換看下一筆newRR
4774
					continue 2;
4775
 
4776
					}#if end
4777
 
253 liveuser 4778
				#如果新舊資料都有query資訊
4779
				if( isset($newRR["query"]) && isset($oldRR["query"]) ){
249 liveuser 4780
 
253 liveuser 4781
					#如果跟既有的 query、type、value 有相同
4782
					if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
249 liveuser 4783
 
253 liveuser 4784
						#如果新 RR 有 update time
4785
						if(isset($newRR["update"])){
249 liveuser 4786
 
253 liveuser 4787
							#如果新舊 update time 不相同
4788
							if( $newRR["update"] !== $oldRR["update"] ){
249 liveuser 4789
 
253 liveuser 4790
								#取代既有的 RR
4791
								$result["content"][$index]=$newRR;
4792
 
4793
								#換看下一筆newRR
4794
								continue 2;
4795
 
4796
								}#if end
4797
 
4798
							}#if end
249 liveuser 4799
 
253 liveuser 4800
						#反之既有的 update time 若跟 global TTL 不一樣
4801
						else if( $oldRR["update"] !== $result["defaultTTL"] ){
4802
 
4803
							#更新為 global TTL
4804
							$result["content"][$index]["update"]=$result["defaultTTL"];
4805
 
249 liveuser 4806
							}#if end
253 liveuser 4807
 
4808
						#如果新 RR 有 comment
4809
						if( isset($newRR["comment"]) ){
249 liveuser 4810
 
253 liveuser 4811
							#更新既有 RR 的 comment
4812
							$result["content"][$index]["comment"]=$newRR["comment"];
249 liveuser 4813
 
253 liveuser 4814
							#換看下一筆newRR
4815
							continue 2;
249 liveuser 4816
 
253 liveuser 4817
							}#if end
4818
 
4819
						#反之,如果有既有 comment
4820
						else if(isset($result["content"][$index]["comment"])){
249 liveuser 4821
 
253 liveuser 4822
							#移除既有 comment
4823
							unset($result["content"][$index]["comment"]);
4824
 
4825
							#換看下一筆newRR
4826
							continue 2;
249 liveuser 4827
 
253 liveuser 4828
							}#else end
249 liveuser 4829
 
253 liveuser 4830
						}#if end
294 liveuser 4831
 
405 liveuser 4832
					#反之如果跟既有的 query、type有相同,且type 為 "CNAME"
4833
					else if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["type"]==="CNAME" ){
294 liveuser 4834
 
4835
						#更新既有 RR 的 value
4836
						$result["content"][$index]["value"]=$newRR["value"];
4837
 
4838
						#換看下一筆newRR
4839
						continue 2;
4840
 
4841
						}#if end
4842
 
405 liveuser 4843
					#反之如果跟既有的 query、type有相同,且type 為 "CAA"
4844
					else if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["type"]==="CAA" ){
4845
 
406 liveuser 4846
						#debug
4847
						var_dump(__LINE__,$oldRR,$newRR);
4848
 
4849
						#如果既有的 value 為 0 issue ";"
4850
						if($oldRR["value"]==="0 issue \";\""){
405 liveuser 4851
 
406 liveuser 4852
							#debug
4853
							#var_dump(__LINE__,$oldRR["value"]);
4854
 
4855
							#代表要從沒有限制變成有限制
405 liveuser 4856
 
4857
							#更新既有 RR 的 value
4858
							$result["content"][$index]["value"]=$newRR["value"];
4859
 
4860
							#換看下一筆newRR
4861
							continue 2;
4862
 
4863
							}#if end
4864
 
4865
						}#if end
4866
 
249 liveuser 4867
					}#if end
253 liveuser 4868
 
249 liveuser 4869
				}#foreach end
4870
 
4871
			#儲存確定要新增的RR
4872
			$result["content"][]=$newRR;
4873
 
4874
			}#foreach end
4875
 
255 liveuser 4876
		#如果要debug
4877
		if($conf["debug"]==="true"){
249 liveuser 4878
 
255 liveuser 4879
			#函式說明:
4880
			#撰寫log
4881
			#回傳結果:
4882
			#$result["status"],狀態,"true"或"false".
4883
			#$result["error"],錯誤訊息陣列.
4884
			#$result["function"],當前函式的名稱.
4885
			#$result["argu"],使用的參數.
4886
			#$result["content"],要寫入log的內容字串.
4887
			#必填參數:
4888
			#$conf["path"],字串,log檔案的路徑與名稱.
4889
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4890
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4891
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
4892
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4893
			$conf["logs::record"]["fileArgu"]=__FILE__;
4894
			#可省略參數:
4895
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4896
			#$conf["rewrite"]="false";
4897
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4898
			#$conf["returnOnly"]="true";
4899
			#參考資料:
4900
			#無.
4901
			#備註:
4902
			#無.
4903
			$record=logs::record($conf["logs::record"]);
4904
			unset($conf["logs::record"]);
249 liveuser 4905
 
255 liveuser 4906
			}#if end
4907
 
4908
		#如果要debug
4909
		if($conf["debug"]==="true"){
4910
 
4911
			#函式說明:
4912
			#撰寫log
4913
			#回傳結果:
4914
			#$result["status"],狀態,"true"或"false".
4915
			#$result["error"],錯誤訊息陣列.
4916
			#$result["function"],當前函式的名稱.
4917
			#$result["argu"],使用的參數.
4918
			#$result["content"],要寫入log的內容字串.
4919
			#必填參數:
4920
			#$conf["path"],字串,log檔案的路徑與名稱.
4921
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4922
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4923
			$conf["logs::record"]["content"]=$result["content"];
4924
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4925
			$conf["logs::record"]["fileArgu"]=__FILE__;
4926
			#可省略參數:
4927
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4928
			#$conf["rewrite"]="false";
4929
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4930
			#$conf["returnOnly"]="true";
4931
			#參考資料:
4932
			#無.
4933
			#備註:
4934
			#無.
4935
			$record=logs::record($conf["logs::record"]);
4936
			unset($conf["logs::record"]);
4937
 
4938
			}#if end
4939
 
249 liveuser 4940
		#初始化要寫入的內容
4941
		$strs2write=array();
4942
 
4943
		#針對每個RR記錄
4944
		foreach($result["content"] as $RR){
4945
 
4946
			#初始化暫存要寫入的行內容
4947
			$str2write="";
4948
 
4949
			#如果是
4950
			if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
4951
 
4952
				#組合變數名稱與數值
4953
				$str2write=$str2write.$RR["type"]."\t".$RR["value"];
4954
 
4955
				}#if end
4956
 
4957
			#反之
4958
			else{
4959
 
4960
				#加上查詢的字句
4961
				$str2write=$str2write.$RR["query"];
4962
 
4963
				#如果該筆RR有指定update time該ZONE具備 global TTL.
4964
				if(isset($RR["update"])){
4965
 
4966
					#如果 該ZONE具備 global TTL.
4967
					if(isset($result["defaultTTL"])){
4968
 
4969
						#如果該筆 RR 的 update time 不等於 global TTL
4970
						if($RR["update"]!==$result["defaultTTL"]){
4971
 
4972
							#加上TTL的字句
4973
							$str2write=$str2write."\t".$RR["update"];
4974
 
4975
							}#if end
4976
 
4977
						}#if end
4978
 
4979
					#反之
4980
					else{
4981
 
4982
						#加上TTL的字句
4983
						$str2write=$str2write."\t".$RR["update"];
4984
 
4985
						}#else end
4986
 
4987
					}#if end
4988
 
253 liveuser 4989
				#反之且該ZONE不具備 global TTL.
4990
				else if(!isset($result["defaultTTL"])){
249 liveuser 4991
 
4992
					#加上global TTL的字句
4993
					$str2write=$str2write."\t".$result["defaultTTL"];
4994
 
253 liveuser 4995
					}#if end
249 liveuser 4996
 
4997
				#加上IN跟TYPE跟value
4998
				$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
4999
 
5000
				}#else end
5001
 
5002
			#如果有註解
5003
			if(isset($RR["comment"])){
5004
 
5005
				#加上comment
5006
				$str2write=$str2write.";".$RR["comment"];
5007
 
5008
				}#if end
5009
 
253 liveuser 5010
			#如果要 debug
5011
			if($conf["debug"]==="true"){
249 liveuser 5012
 
253 liveuser 5013
				#函式說明:
5014
				#撰寫log
5015
				#回傳結果:
5016
				#$result["status"],狀態,"true"或"false".
5017
				#$result["error"],錯誤訊息陣列.
5018
				#$result["function"],當前函式的名稱.
5019
				#$result["argu"],使用的參數.
5020
				#$result["content"],要寫入log的內容字串.
5021
				#必填參數:
5022
				#$conf["path"],字串,log檔案的路徑與名稱.
5023
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5024
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5025
				$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
5026
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5027
				$conf["logs::record"]["fileArgu"]=__FILE__;
5028
				#可省略參數:
5029
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5030
				#$conf["rewrite"]="false";
5031
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5032
				#$conf["returnOnly"]="true";
5033
				#參考資料:
5034
				#無.
5035
				#備註:
5036
				#無.
5037
				$record=logs::record($conf["logs::record"]);
5038
				unset($conf["logs::record"]);
5039
 
5040
				}#if end
5041
 
249 liveuser 5042
			#加上要寫入的元素
5043
			$strs2write[]=$str2write;
5044
 
5045
			}#foreach end
5046
 
5047
		#如果有逐行註解
5048
		if(count($result["comment"])>0){
5049
 
5050
			#加到結尾
5051
			#函式說明:
5052
			#將多個一維陣列串聯起來,key從0開始排序.
5053
			#回傳的結果:
5054
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
5055
			#$result["error"],錯誤訊息陣列.
5056
			#$result["function"],當前執行的函數.
5057
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5058
			#$result["content"],合併好的一維陣列.
5059
			#必填參數
5060
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
5061
			$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
5062
			#可省略參數:
5063
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
5064
			#$conf["allowRepeat"]="true";
5065
			#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
5066
			#$conf["looseDiff"]="false";
5067
			#參考資料:
5068
			#無.
5069
			#備註:
5070
			#無.
5071
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
5072
			unset($conf["arrays::mergeArray"]);
5073
 
5074
			#如果執行異常
5075
			if($mergeArray["status"]==="false"){
5076
 
5077
				#設置錯誤識別
5078
				$result["status"]="false";
5079
 
5080
				#設置錯誤訊息
5081
				$result["error"]=$mergeArray;
5082
 
5083
				#回傳結果
5084
				return $result;
5085
 
5086
				}#if end
5087
 
5088
			#取得合併好的陣列
5089
			$strs2write=$mergeArray["content"];
5090
 
5091
			}#if end
5092
 
253 liveuser 5093
		#如果要 debug
5094
		if($conf["debug"]==="true"){
249 liveuser 5095
 
253 liveuser 5096
			#函式說明:
5097
			#撰寫log
5098
			#回傳結果:
5099
			#$result["status"],狀態,"true"或"false".
5100
			#$result["error"],錯誤訊息陣列.
5101
			#$result["function"],當前函式的名稱.
5102
			#$result["argu"],使用的參數.
5103
			#$result["content"],要寫入log的內容字串.
5104
			#必填參數:
5105
			#$conf["path"],字串,log檔案的路徑與名稱.
5106
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
5107
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
5108
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
5109
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5110
			$conf["logs::record"]["fileArgu"]=__FILE__;
5111
			#可省略參數:
5112
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
5113
			#$conf["rewrite"]="false";
5114
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
5115
			#$conf["returnOnly"]="true";
5116
			#參考資料:
5117
			#無.
5118
			#備註:
5119
			#無.
5120
			$record=logs::record($conf["logs::record"]);
5121
			unset($conf["logs::record"]);
5122
 
5123
			}#if end
5124
 
249 liveuser 5125
		#儲存新zone file每行的內容
5126
		$result["newZoneFileContent"]=$strs2write;
5127
 
5128
		#如果要寫入ZONE檔案
5129
		if($conf["writeNow"]==="true"){
5130
 
5131
			#覆寫 ZONE file
5132
			#函式說明:
5133
			#更新檔案的內容.
5134
			#回傳結果:
5135
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5136
			#$result["error"],錯誤訊息.
5137
			#$result["function"],當前執行的函數名稱.
5138
			#$result["content"],更新的資訊.
5139
			#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
5140
			#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
5141
			#必填參數:
5142
			#$conf["fileArgu"],字串,變數__FILE__的內容.
5143
			$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
5144
			#$conf["file"],字串,要更新的檔案位置與名稱.
5145
			$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
5146
			#可省略參數:
5147
			#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
5148
			$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
5149
			#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
5150
			#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
5151
			#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
5152
			#$conf["replaceLike"]="false";
5153
			#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
5154
			#$conf["addToTailWhenNoMatch"]="false";
5155
			#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
5156
			#$conf["addToTailBeforeThat"]="?\>";
5157
			#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
5158
			#$conf["replaceSpecifyLine"]=array();
5159
			#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
5160
			#$conf["outputPath"]="";
5161
			#參考資料:
5162
			#無.
5163
			#備註:
5164
			#無.
5165
			$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
5166
			unset($conf["fileAccess::updateFile"]);
5167
 
5168
			#如果執行異常
5169
			if($updateFile["status"]==="false"){
5170
 
5171
				#設置錯誤識別
5172
				$result["status"]="false";
5173
 
5174
				#設置錯誤訊息
5175
				$result["error"]=$updateFile;
5176
 
5177
				#回傳結果
5178
				return $result;
5179
 
5180
				}#if end
291 liveuser 5181
 
5182
			#修正 zone file 的權限
5183
			#函式說明:
5184
			#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
5185
			#回傳結果:
5186
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5187
			#$result["error"],錯誤訊息.
5188
			#$result["function"],當前執行的函式名稱.
5189
			#$result["cmd"],執行的指令.
5190
			#必填參數:
5191
			#$conf["owner"],字串,要變哪個使用者擁有.
5192
			$conf["cmd::chown"]["owner"]="root";
5193
			#$conf["target"],字串,需要變更擁有者、 群組的目標.
5194
			$conf["cmd::chown"]["target"]=$conf["dnsRecordFile"];
5195
			#可省略參數:
5196
			#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
5197
			$conf["cmd::chown"]["group"]=webUser;
5198
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
5199
			#$conf["recursive"]="true";
5200
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
5201
			#$conf["excludeSelf"]="true";
5202
			#參考資料:
5203
			#無.
5204
			#備註:
5205
			#無.
5206
			$chown=cmd::chown($conf["cmd::chown"]);
5207
			unset($conf["cmd::chown"]);
249 liveuser 5208
 
291 liveuser 5209
			#如果執行異常
5210
			if($chown["status"]==="false"){
5211
 
5212
				#設置錯誤識別
5213
				$result["status"]="false";
5214
 
5215
				#設置錯誤訊息
5216
				$result["error"]=$chown;
5217
 
5218
				#回傳結果
5219
				return $result;
5220
 
5221
				}#if end
5222
 
5223
			#函式說明:
5224
			#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
5225
			#回傳結果:
5226
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5227
			#$result["error"],錯誤訊息.
5228
			#$result["function"],當前執行的函式名稱.
5229
			#$result["cmd"],執行的指令.
5230
			#必填參數:
5231
			#$conf["mode"],字串,要變成什麼權限.
5232
			$conf["cmd::chmod"]["mode"]="774";
5233
			#$conf["target"],字串,需要變更權限的目標.
5234
			$conf["cmd::chmod"]["target"]=$conf["dnsRecordFile"];
5235
			#可省略參數:
5236
			#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
5237
			#$conf["recursive"]="true";
5238
			#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
5239
			#$conf["excludeSelf"]="true";
5240
			#參考資料:
5241
			#無.
5242
			#備註:
5243
			#無.
5244
			$chmod=cmd::chmod($conf["cmd::chmod"]);
5245
			unset($conf["cmd::chmod"]);
5246
 
5247
			#如果執行異常
5248
			if($chmod["status"]==="false"){
5249
 
5250
				#設置錯誤識別
5251
				$result["status"]="false";
5252
 
5253
				#設置錯誤訊息
5254
				$result["error"]=$chmod;
5255
 
5256
				#回傳結果
5257
				return $result;
5258
 
5259
				}#if end
5260
 
249 liveuser 5261
			}#if end
5262
 
5263
		#設置執行正常
5264
		$result["status"]="true";
5265
 
5266
		#回傳結果
5267
		return $result;
5268
 
5269
		}#function updateDnsRecordFile end
5270
 
5271
	/*
5272
	#函式說明:
255 liveuser 5273
	#請求驗證已經透過zerossl::createCertificate要求的domain.
249 liveuser 5274
	#回傳結果:
5275
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5276
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5277
	#$result["function"],當前執行的函式名稱.
5278
	#$result["argu"],所使用的參數.
5279
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 5280
	#$result["content"],結果json字串.
249 liveuser 5281
	#必填參數:
5282
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
5283
	$conf["id"]="";
5284
	#可省略參數:
5285
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5286
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5287
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5288
	#$conf["key"]=self::getApiInfo()["apiKey"];
5289
	#參考資料:
255 liveuser 5290
	#https://zerossl.com/documentation/api/verify-domains/
249 liveuser 5291
	#備註:
5292
	#無.
5293
	*/
5294
	public static function verifyDomain(&$conf){
5295
 
5296
		#初始化要回傳的結果
5297
		$result=array();
5298
 
5299
		#設置當其函數名稱
5300
		$result["function"]=__FUNCTION__;
5301
 
5302
		#如果 $conf 不為陣列
5303
		if(gettype($conf)!="array"){
5304
 
5305
			#設置執行失敗
5306
			$result["status"]="false";
5307
 
5308
			#設置執行錯誤訊息
5309
			$result["error"][]="\$conf變數須為陣列形態";
5310
 
5311
			#如果傳入的參數為 null
5312
			if($conf==null){
5313
 
5314
				#設置執行錯誤訊息
5315
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5316
 
5317
				}#if end
5318
 
5319
			#回傳結果
5320
			return $result;
5321
 
5322
			}#if end
5323
 
5324
		#取得參數
5325
		$result["argu"]=$conf;
5326
 
5327
		#檢查參數
5328
		#函式說明:
5329
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5330
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5331
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5332
		#$result["function"],當前執行的函式名稱.
5333
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5334
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5335
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5336
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5337
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5338
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5339
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5340
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5341
		#必填寫的參數:
5342
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5343
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5344
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5345
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5346
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5347
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5348
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5349
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5350
		#可以省略的參數:
5351
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5352
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5353
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5354
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5355
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5356
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
5357
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5358
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5359
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 5360
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
249 liveuser 5361
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5362
		#$conf["arrayCountEqualCheck"][]=array();
5363
		#參考資料來源:
5364
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5365
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5366
		unset($conf["variableCheck::checkArguments"]);
5367
 
5368
		#如果檢查失敗
5369
		if($checkArguments["status"]==="false"){
5370
 
5371
			#設置錯誤識別
5372
			$result["status"]="false";
5373
 
5374
			#設置錯誤訊息
5375
			$result["error"]=$checkArguments;
5376
 
5377
			#回傳結果
5378
			return $result;
5379
 
5380
			}#if end
5381
 
5382
		#如果檢查不通過
5383
		if($checkArguments["passed"]==="false"){
5384
 
5385
			#設置錯誤識別
5386
			$result["status"]="false";
5387
 
5388
			#設置錯誤訊息
5389
			$result["error"]=$checkArguments;
5390
 
5391
			#回傳結果
5392
			return $result;
5393
 
5394
			}#if end
5395
 
5396
		#要傳送的 key -> value
5397
		$postArray=array();
5398
 
5399
		#設置要簽署的domain
5400
		$postArray["validation_method"]="CNAME_CSR_HASH";
5401
 
5402
		#設置要傳送的 json
5403
		$postJson=json_encode($postArray);
5404
 
5405
		#函式說明:
5406
		#運行curl cmd
5407
		#回傳結果:
5408
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5409
		#$result["error"],錯誤訊息陣列.
5410
		#$result["function"],當前執行的函式名稱.
5411
		#$result["founded"],識別網址找不找得到.
5412
		#$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"代表程序的資訊.
5413
		#$result["fullContent"],取得回應的完整字串內容.
5414
		#$result["cookie"],cookie檔案的位置與名稱.
5415
		#$result["cmd"],執行的command.
5416
		#$result["argu],使用的參數.
5417
		#必填參數:
5418
		#$conf["url"],字串,目標url.
255 liveuser 5419
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
249 liveuser 5420
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5421
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5422
		#可省略參數:
5423
		#$conf["header"],字串陣列,要傳送的header.
5424
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5425
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5426
		#$conf["allowAnySSLcertificate"]="";
5427
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5428
		#$conf["postVar"]=array();
5429
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5430
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5431
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5432
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5433
		#$conf["agent"],字串,user agent的名稱.
5434
		#$conf["agent"]="";
5435
		#$conf["cookie"],字串,cookie位置與檔案位置.
5436
		#$conf["cookie"]="";
5437
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5438
		#$conf["forceNewCookie"]="";
5439
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5440
		#$conf["inBg"]="true";
5441
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5442
		#$conf["bgInProc"]="false";
5443
		#參考資料:
5444
		#無.
5445
		#備註:
5446
		#無.
5447
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5448
		unset($conf["catchWebContent::curlCmd"]);
5449
 
5450
		#如果異常
5451
		if($curlCmd["status"]==="false"){
5452
 
5453
			#設置錯誤識別
5454
			$result["status"]="false";
5455
 
5456
			#設置錯誤訊息
5457
			$result["error"]=$curlCmd;
5458
 
5459
			#回傳結果
5460
			return $result;
5461
 
5462
			}#if end
5463
 
5464
		#設置curl的詳細資訊
5465
		$result["curl_verbose_info"]=$curlCmd;
5466
 
255 liveuser 5467
		#驗證結果是否為 json
5468
		$json_validate=json_validate($curlCmd["fullContent"]);
5469
 
5470
		#如果回應不是 json
5471
		if(!$json_validate){
249 liveuser 5472
 
255 liveuser 5473
			#設置錯誤識別
5474
			$result["status"]="false";
5475
 
5476
			#設置錯誤訊息
5477
			$result["error"]=$curlCmd;
5478
 
5479
			#回傳結果
5480
			return $result;
5481
 
5482
			}#if end
5483
 
5484
		#設置json string結果
5485
		$result["content"]=$curlCmd["fullContent"];
5486
 
5487
		#解析json
5488
		$jsonRes=json_decode($result["content"]);
5489
 
293 liveuser 5490
		#如果有 success 資訊
5491
		if(isset($jsonRes->success)){
255 liveuser 5492
 
293 liveuser 5493
			#do nothing
5494
 
5495
			}#if end
5496
 
5497
		#反之如果沒有 status
5498
		else if(!isset($jsonRes->status)){
5499
 
255 liveuser 5500
			#設置錯誤識別
5501
			$result["status"]="false";
5502
 
5503
			#設置錯誤訊息
5504
			$result["error"]=$curlCmd;
5505
 
5506
			#回傳結果
5507
			return $result;
5508
 
5509
			}#if end
5510
 
293 liveuser 5511
		#反之有 status 資訊
5512
		else{
255 liveuser 5513
 
293 liveuser 5514
			#如果是 "pending_validation"
5515
			if($jsonRes->status==="pending_validation"){
255 liveuser 5516
 
293 liveuser 5517
				#do nothing
255 liveuser 5518
 
293 liveuser 5519
				}#if end
5520
 
5521
			#反之如果為 "issued"
5522
			else if($jsonRes->status==="issued"){
5523
 
5524
				#do nothing
5525
 
5526
				}#else 
5527
 
5528
			#反之
5529
			else{
5530
 
5531
				#設置錯誤識別
5532
				$result["status"]="false";
255 liveuser 5533
 
293 liveuser 5534
				#設置錯誤訊息
5535
				$result["error"]=$curlCmd;
255 liveuser 5536
 
293 liveuser 5537
				#回傳結果
5538
				return $result;
5539
 
5540
				}#else end
255 liveuser 5541
 
5542
			}#else end
5543
 
5544
		#設置執行正常
5545
		$result["status"]="true";
5546
 
5547
		#回傳結果
5548
		return $result;
5549
 
5550
		}#function verifyDomain end
5551
 
5552
	/*
5553
	#函式說明:
5554
	#取得CSR在zerossl上的狀態
5555
	#回傳結果:
5556
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5557
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5558
	#$result["function"],當前執行的函式名稱.
5559
	#$result["argu"],所使用的參數.
5560
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5561
	#$result["content"],結果json字串.
5562
	#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5563
	#必填參數:
5564
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
5565
	$conf["id"]="";
5566
	#可省略參數:
5567
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5568
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5569
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5570
	#$conf["key"]=self::getApiInfo()["apiKey"];
5571
	#參考資料:
5572
	#https://zerossl.com/documentation/api/get-certificate/
5573
	#備註:
5574
	#無.
5575
	*/
5576
	public static function getCertSta(&$conf){
5577
 
5578
		#初始化要回傳的結果
5579
		$result=array();
5580
 
5581
		#設置當其函數名稱
5582
		$result["function"]=__FUNCTION__;
5583
 
5584
		#如果 $conf 不為陣列
5585
		if(gettype($conf)!="array"){
5586
 
5587
			#設置執行失敗
5588
			$result["status"]="false";
5589
 
5590
			#設置執行錯誤訊息
5591
			$result["error"][]="\$conf變數須為陣列形態";
5592
 
5593
			#如果傳入的參數為 null
5594
			if($conf==null){
5595
 
5596
				#設置執行錯誤訊息
5597
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5598
 
5599
				}#if end
5600
 
5601
			#回傳結果
5602
			return $result;
5603
 
5604
			}#if end
5605
 
5606
		#取得參數
5607
		$result["argu"]=$conf;
291 liveuser 5608
 
5609
		#DEBUG
5610
		#var_dump(__LINE__,self::getApiInfo());exit;
255 liveuser 5611
 
5612
		#檢查參數
5613
		#函式說明:
5614
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5615
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5616
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5617
		#$result["function"],當前執行的函式名稱.
5618
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5619
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5620
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5621
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5622
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5623
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5624
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5625
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5626
		#必填寫的參數:
5627
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5628
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5629
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5630
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5631
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5632
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5633
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5634
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5635
		#可以省略的參數:
5636
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5637
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5638
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5639
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5640
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5641
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
5642
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5643
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5644
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5645
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
5646
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5647
		#$conf["arrayCountEqualCheck"][]=array();
5648
		#參考資料來源:
5649
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5650
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5651
		unset($conf["variableCheck::checkArguments"]);
5652
 
5653
		#如果檢查失敗
5654
		if($checkArguments["status"]==="false"){
5655
 
5656
			#設置錯誤識別
5657
			$result["status"]="false";
5658
 
5659
			#設置錯誤訊息
5660
			$result["error"]=$checkArguments;
5661
 
5662
			#回傳結果
5663
			return $result;
5664
 
5665
			}#if end
5666
 
5667
		#如果檢查不通過
5668
		if($checkArguments["passed"]==="false"){
5669
 
5670
			#設置錯誤識別
5671
			$result["status"]="false";
5672
 
5673
			#設置錯誤訊息
5674
			$result["error"]=$checkArguments;
5675
 
5676
			#回傳結果
5677
			return $result;
5678
 
5679
			}#if end
5680
 
5681
		#函式說明:
5682
		#運行curl cmd
5683
		#回傳結果:
5684
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5685
		#$result["error"],錯誤訊息陣列.
5686
		#$result["function"],當前執行的函式名稱.
5687
		#$result["founded"],識別網址找不找得到.
5688
		#$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"代表程序的資訊.
5689
		#$result["fullContent"],取得回應的完整字串內容.
5690
		#$result["cookie"],cookie檔案的位置與名稱.
5691
		#$result["cmd"],執行的command.
5692
		#$result["argu],使用的參數.
5693
		#必填參數:
5694
		#$conf["url"],字串,目標url.
5695
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
5696
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5697
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5698
		#可省略參數:
5699
		#$conf["header"],字串陣列,要傳送的header.
5700
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5701
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5702
		#$conf["allowAnySSLcertificate"]="";
5703
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5704
		#$conf["postVar"]=array();
5705
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5706
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5707
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5708
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5709
		#$conf["agent"],字串,user agent的名稱.
5710
		#$conf["agent"]="";
5711
		#$conf["cookie"],字串,cookie位置與檔案位置.
5712
		#$conf["cookie"]="";
5713
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5714
		#$conf["forceNewCookie"]="";
5715
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5716
		#$conf["inBg"]="true";
5717
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5718
		#$conf["bgInProc"]="false";
5719
		#參考資料:
5720
		#無.
5721
		#備註:
5722
		#無.
5723
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5724
		unset($conf["catchWebContent::curlCmd"]);
5725
 
5726
		#如果異常
5727
		if($curlCmd["status"]==="false"){
5728
 
5729
			#設置錯誤識別
5730
			$result["status"]="false";
5731
 
5732
			#設置錯誤訊息
5733
			$result["error"]=$curlCmd;
5734
 
5735
			#回傳結果
5736
			return $result;
5737
 
5738
			}#if end
5739
 
5740
		#設置curl的詳細資訊
5741
		$result["curl_verbose_info"]=$curlCmd;
5742
 
5743
		#驗證結果是否為 json
5744
		$json_validate=json_validate($curlCmd["fullContent"]);
5745
 
5746
		#如果回應不是 json
5747
		if(!$json_validate){
5748
 
5749
			#設置錯誤識別
5750
			$result["status"]="false";
5751
 
5752
			#設置錯誤訊息
5753
			$result["error"]=$curlCmd;
5754
 
5755
			#回傳結果
5756
			return $result;
5757
 
5758
			}#if end
5759
 
5760
		#設置json string結果
5761
		$result["content"]=$curlCmd["fullContent"];
5762
 
5763
		#解析json
5764
		$jsonRes=json_decode($result["content"]);
5765
 
5766
		#如果沒有 status
5767
		if(!isset($jsonRes->status)){
5768
 
5769
			#設置錯誤識別
5770
			$result["status"]="false";
5771
 
5772
			#設置錯誤訊息
5773
			$result["error"]=$curlCmd;
5774
 
5775
			#回傳結果
5776
			return $result;
5777
 
5778
			}#if end
5779
 
5780
		#取得csr在zerossl上的狀態
5781
		$result["cerStatus"]=$jsonRes->status;
5782
 
5783
		#設置執行正常
5784
		$result["status"]="true";
5785
 
5786
		#回傳結果
5787
		return $result;
5788
 
5789
		}#function getCertSta end
5790
 
5791
	/*
5792
	#函式說明:
5793
	#取得在zerossl上的CSR清單
5794
	#回傳結果:
5795
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5796
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5797
	#$result["function"],當前執行的函式名稱.
5798
	#$result["argu"],所使用的參數.
5799
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5800
	#$result["content"],結果json字串.
5801
	#$result["tCount"],總共的資料筆數.
5802
	#$result["count"],該頁的筆數.
5803
	#$result["page"],當前的頁碼.
5804
	#$result["certs"],陣列,certificates清單,key為certificate的id.
5805
	#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
5806
	#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
5807
	#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
5808
	#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
5809
	#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5810
	#必填參數:
5811
	#無
5812
	#可省略參數:
5813
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5814
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5815
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5816
	#$conf["key"]=self::getApiInfo()["apiKey"];
5817
	#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5818
	#$conf["cerStatus"]="";
309 liveuser 5819
	#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;"multiDomain90Days"多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
255 liveuser 5820
	#$conf["cerType"]="";
5821
	#$conf["search"],字串,透過certificate包含的domain來搜尋.
5822
	#$conf["search"]="";
5823
	#$conf["limit"],字串,一頁要多少筆,預設為100筆.
5824
	#$conf["limit"]="";
5825
	#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
5826
	#$conf["page"]="";
5827
	#參考資料:
5828
	#https://zerossl.com/documentation/api/list-certificates/
5829
	#備註:
5830
	#無.
5831
	*/
5832
	public static function getCertList(&$conf){
5833
 
5834
		#初始化要回傳的結果
5835
		$result=array();
5836
 
5837
		#設置當其函數名稱
5838
		$result["function"]=__FUNCTION__;
5839
 
5840
		#如果 $conf 不為陣列
5841
		if(gettype($conf)!="array"){
5842
 
5843
			#設置執行失敗
5844
			$result["status"]="false";
5845
 
5846
			#設置執行錯誤訊息
5847
			$result["error"][]="\$conf變數須為陣列形態";
5848
 
5849
			#如果傳入的參數為 null
5850
			if($conf==null){
5851
 
5852
				#設置執行錯誤訊息
5853
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5854
 
5855
				}#if end
5856
 
5857
			#回傳結果
5858
			return $result;
5859
 
5860
			}#if end
5861
 
5862
		#取得參數
5863
		$result["argu"]=$conf;
5864
 
5865
		#檢查參數
5866
		#函式說明:
5867
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5868
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5869
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5870
		#$result["function"],當前執行的函式名稱.
5871
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5872
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5873
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5874
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5875
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5876
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5877
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5878
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5879
		#必填寫的參數:
5880
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5881
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5882
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5883
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5884
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5885
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5886
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5887
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5888
		#可以省略的參數:
5889
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5890
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5891
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5892
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5893
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5894
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
5895
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5896
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
5897
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5898
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
5899
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5900
		#$conf["arrayCountEqualCheck"][]=array();
5901
		#參考資料來源:
5902
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5903
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5904
		unset($conf["variableCheck::checkArguments"]);
5905
 
5906
		#如果檢查失敗
5907
		if($checkArguments["status"]==="false"){
5908
 
5909
			#設置錯誤識別
5910
			$result["status"]="false";
5911
 
5912
			#設置錯誤訊息
5913
			$result["error"]=$checkArguments;
5914
 
5915
			#回傳結果
5916
			return $result;
5917
 
5918
			}#if end
5919
 
5920
		#如果檢查不通過
5921
		if($checkArguments["passed"]==="false"){
5922
 
5923
			#設置錯誤識別
5924
			$result["status"]="false";
5925
 
5926
			#設置錯誤訊息
5927
			$result["error"]=$checkArguments;
5928
 
5929
			#回傳結果
5930
			return $result;
5931
 
5932
			}#if end
5933
 
5934
		#預設網址
291 liveuser 5935
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."?access_key=".$conf["key"];
255 liveuser 5936
 
5937
		#如果有設置 cerStatus
5938
		if(isset($conf["cerStatus"])){
5939
 
5940
			#設置 certificate_status 
291 liveuser 5941
			$url=$url."&certificate_status=".urlencode($conf["cerStatus"]);
255 liveuser 5942
 
5943
			}#if end
5944
 
5945
		#如果有設置 cerType
5946
		if(isset($conf["cerType"])){
5947
 
5948
			#設置 certificate_type
291 liveuser 5949
			$url=$url."&certificate_type=".urlencode($conf["cerType"]);
255 liveuser 5950
 
5951
			}#if end
5952
 
5953
		#如果有設置 search
5954
		if(isset($conf["search"])){
5955
 
5956
			#設置 search
291 liveuser 5957
			$url=$url."&search=".urlencode($conf["search"]);
255 liveuser 5958
 
5959
			}#if end
5960
 
5961
		#如果有設置 limit
5962
		if(isset($conf["limit"])){
5963
 
5964
			#設置 search
291 liveuser 5965
			$url=$url."&limit=".urlencode($conf["limit"]);
255 liveuser 5966
 
5967
			}#if end
5968
 
5969
		#如果有設置 page
5970
		if(isset($conf["page"])){
5971
 
5972
			#設置 search
291 liveuser 5973
			$url=$url."&"."page=".urlencode($conf["page"]);
255 liveuser 5974
 
5975
			}#if end
5976
 
5977
		#函式說明:
5978
		#運行curl cmd
5979
		#回傳結果:
5980
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5981
		#$result["error"],錯誤訊息陣列.
5982
		#$result["function"],當前執行的函式名稱.
5983
		#$result["founded"],識別網址找不找得到.
5984
		#$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"代表程序的資訊.
5985
		#$result["fullContent"],取得回應的完整字串內容.
5986
		#$result["cookie"],cookie檔案的位置與名稱.
5987
		#$result["cmd"],執行的command.
5988
		#$result["argu],使用的參數.
5989
		#必填參數:
5990
		#$conf["url"],字串,目標url.
5991
		$conf["catchWebContent::curlCmd"]["url"]=$url;
5992
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5993
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5994
		#可省略參數:
5995
		#$conf["header"],字串陣列,要傳送的header.
5996
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5997
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5998
		#$conf["allowAnySSLcertificate"]="";
5999
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6000
		#$conf["postVar"]=array();
6001
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6002
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6003
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
6004
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
6005
		#$conf["agent"],字串,user agent的名稱.
6006
		#$conf["agent"]="";
6007
		#$conf["cookie"],字串,cookie位置與檔案位置.
6008
		#$conf["cookie"]="";
6009
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6010
		#$conf["forceNewCookie"]="";
6011
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6012
		#$conf["inBg"]="true";
6013
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6014
		#$conf["bgInProc"]="false";
6015
		#參考資料:
6016
		#無.
6017
		#備註:
6018
		#無.
6019
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6020
		unset($conf["catchWebContent::curlCmd"]);
6021
 
6022
		#如果異常
6023
		if($curlCmd["status"]==="false"){
6024
 
6025
			#設置錯誤識別
6026
			$result["status"]="false";
6027
 
6028
			#設置錯誤訊息
6029
			$result["error"]=$curlCmd;
6030
 
6031
			#回傳結果
6032
			return $result;
6033
 
6034
			}#if end
6035
 
6036
		#設置curl的詳細資訊
6037
		$result["curl_verbose_info"]=$curlCmd;
6038
 
6039
		#驗證結果是否為 json
6040
		$json_validate=json_validate($curlCmd["fullContent"]);
6041
 
6042
		#如果回應不是 json
6043
		if(!$json_validate){
6044
 
6045
			#設置錯誤識別
6046
			$result["status"]="false";
6047
 
6048
			#設置錯誤訊息
6049
			$result["error"]=$curlCmd;
6050
 
6051
			#回傳結果
6052
			return $result;
6053
 
6054
			}#if end
6055
 
6056
		#設置json string結果
6057
		$result["content"]=$curlCmd["fullContent"];
6058
 
6059
		/* json response 範例
6060
		{
6061
			"total_count": 11,
6062
			"result_count": 10,
6063
			"page": 1,
6064
			"limit": 10,
6065
			"acmeUsageLevel": "LOW",
6066
			"isAcmeLocked": false,
6067
			"results": 
6068
			[
6069
				{
6070
					"id": "a856a39a1c3ad0s8asa606g37667d221",
6071
					"type": "1",
6072
					"common_name": "domain.com",
6073
					"additional_domains": "www.domain.com",
6074
					"created": "2020-04-29 09:04:19",
6075
					"expires": "2020-07-28 00:00:00",
6076
					"status": "draft",
6077
					"validation_type": null,
6078
					"validation_emails": null,
6079
					"replacement_for": "",
6080
					"fingerprint_sha1": null,
6081
					"brand_validation": null,
6082
					"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
6083
					"validation":
6084
					{
6085
						"email_validation":
6086
						{
6087
							"domain.com":
6088
							[
6089
								"admin@domain.com",
6090
								"administrator@domain.com",
6091
								"hostmaster@domain.com",
6092
								"postmaster@domain.com",
6093
								"webmaster@domain.com"
6094
							]
6095
						},
6096
						"other_methods": 
6097
						{
6098
							"domain.com":
6099
							{
6100
								"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
6101
								"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
6102
								"file_validation_content":
6103
								[
6104
									"2B449B722B449B729394793947",
6105
									"comodoca.com",
6106
									"4bad7360c7076ba"
6107
								],
6108
								"cname_validation_p1": "2B449B7293947.domain.com",
6109
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
6110
							},
6111
							"www.domain.com":
6112
							{
6113
								"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
6114
								"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",   
6115
								"file_validation_content":
6116
								[
6117
									"2B449B722B449B729394793947",
6118
									"comodoca.com",
6119
									"4bad7360c7076ba"
6120
								],
6121
								"cname_validation_p1": "2B449B7293947.www.domain.com",
6122
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
6123
							}
6124
						}
6125
					}
6126
				},
6127
				{
6128
					...
6129
				}
6130
			]
6131
		}
249 liveuser 6132
		*/
6133
 
255 liveuser 6134
		#解析json
6135
		$jsonRes=json_decode($result["content"]);
6136
 
6137
		#總共的資料筆數
6138
		$result["tCount"]=$jsonRes->total_count;
6139
 
6140
		#取得該頁的筆數
6141
		$result["count"]=$jsonRes->result_count;
6142
 
6143
		#取得certificate清單
291 liveuser 6144
		$certs=$jsonRes->results;
255 liveuser 6145
 
6146
		#針對每個certificate
6147
		foreach($certs as $index => $cert){
6148
 
6149
			#初始化暫存的陣列
6150
			$tmpA=array();
6151
 
6152
			#儲存 cert id
6153
			#$tmpA["id"]=$cert->id;
6154
 
6155
			#儲存 主要包含的 domain name
6156
			$tmpA["cname"]=$cert->common_name;
6157
 
6158
			#儲存額外包含的 domain name
6159
			$tmpA["anames"]=$cert->additional_domains;
6160
 
6161
			#最後有效年月日,格式為"2020-07-28 00:00:00".
6162
			$tmpA["expiresYMD"]=$cert->expires;
6163
 
6164
			#產生對於當前系統時間的差距(秒數)
6165
			#函式說明:
6166
			#計算時間點距離1970/01/01多少秒,亦即unixtime.
6167
			#回傳結果:
6168
			#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
6169
			#$result["error"],錯誤訊息陣列.
6170
			#$result["content"],時間點距離1970/01/01的多少秒.
6171
			#$result["argu"],使用的參數.
6172
			#$result["unixtime"],執行本函式時的unixtime.
6173
			#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
6174
			#必填參數:
6175
			#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
6176
			$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
6177
			#可省略參數:
6178
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
6179
			#$conf["UTC"]="false";
6180
			#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
6181
			$conf["time::caculateTimeAmount"]["replace0"]="false";
6182
			#參考資料:
6183
			#無.
6184
			#備註:
6185
			#無.
6186
			$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
6187
			unset($conf["time::caculateTimeAmount"]);
6188
 
6189
			#如果執行異常
291 liveuser 6190
			if($caculateTimeAmount["status"]==="false"){
255 liveuser 6191
 
6192
				#設置錯誤識別
6193
				$result["status"]="false";
6194
 
6195
				#設置錯誤訊息
6196
				$result["error"]=$caculateTimeAmount;
6197
 
6198
				#回傳結果
6199
				return $result;
6200
 
6201
				}#if end
6202
 
6203
			#儲存還要多少秒要過期
291 liveuser 6204
			$tmpA["expiresIn"]=$caculateTimeAmount["content"]-time();
255 liveuser 6205
 
6206
			#憑證的狀態
6207
			$tmpA["status"]=$cert->status;
6208
 
291 liveuser 6209
			#儲存要回傳的 certs 清單,key為cert的id.
6210
			$result["certs"][$cert->id]=$tmpA;
255 liveuser 6211
 
6212
			}#foreach end
6213
 
6214
		#設置執行正常
6215
		$result["status"]="true";
6216
 
6217
		#回傳結果
6218
		return $result;
6219
 
6220
		}#function getCertList end
6221
 
6222
	/*
6223
	#函式說明:
6224
	#下載certificate.
6225
	#回傳結果:
6226
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6227
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6228
	#$result["function"],當前執行的函式名稱.
6229
	#$result["argu"],所使用的參數.
6230
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6231
	#$result["content"],結果json字串.
6232
	#$result["certificate.crt"],字串,certificate.crt的內容.
6233
	#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
6234
	#必填參數:
6235
	#無.
6236
	#可省略參數:
6237
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6238
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6239
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6240
	#$conf["key"]=self::getApiInfo()["apiKey"];
6241
	#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
6242
	#$conf["id"]="";
6243
	#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
6244
	#$conf["cname"]="";
6245
	#參考資料:
6246
	#https://zerossl.com/documentation/api/download-certificate-inline/
6247
	#備註:
6248
	#無.
6249
	*/
6250
	public static function getCert(&$conf){
6251
 
6252
		#初始化要回傳的結果
6253
		$result=array();
6254
 
6255
		#設置當其函數名稱
6256
		$result["function"]=__FUNCTION__;
6257
 
6258
		#如果 $conf 不為陣列
6259
		if(gettype($conf)!="array"){
6260
 
6261
			#設置執行失敗
6262
			$result["status"]="false";
6263
 
6264
			#設置執行錯誤訊息
6265
			$result["error"][]="\$conf變數須為陣列形態";
6266
 
6267
			#如果傳入的參數為 null
6268
			if($conf==null){
6269
 
6270
				#設置執行錯誤訊息
6271
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6272
 
6273
				}#if end
6274
 
6275
			#回傳結果
6276
			return $result;
6277
 
6278
			}#if end
6279
 
6280
		#取得參數
6281
		$result["argu"]=$conf;
6282
 
6283
		#檢查參數
6284
		#函式說明:
6285
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6286
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6287
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6288
		#$result["function"],當前執行的函式名稱.
6289
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6290
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6291
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6292
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6293
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6294
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6295
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6296
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6297
		#必填寫的參數:
6298
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6299
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6300
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6301
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6302
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6303
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6304
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6305
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6306
		#可以省略的參數:
6307
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6308
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6309
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6310
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6311
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6312
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
6313
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6314
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
6315
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6316
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
6317
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6318
		#$conf["arrayCountEqualCheck"][]=array();
6319
		#參考資料來源:
6320
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6321
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6322
		unset($conf["variableCheck::checkArguments"]);
6323
 
6324
		#如果檢查失敗
6325
		if($checkArguments["status"]==="false"){
6326
 
6327
			#設置錯誤識別
6328
			$result["status"]="false";
6329
 
6330
			#設置錯誤訊息
6331
			$result["error"]=$checkArguments;
6332
 
6333
			#回傳結果
6334
			return $result;
6335
 
6336
			}#if end
6337
 
6338
		#如果檢查不通過
6339
		if($checkArguments["passed"]==="false"){
6340
 
6341
			#設置錯誤識別
6342
			$result["status"]="false";
6343
 
6344
			#設置錯誤訊息
6345
			$result["error"]=$checkArguments;
6346
 
6347
			#回傳結果
6348
			return $result;
6349
 
6350
			}#if end
6351
 
6352
		#如果有設置 id
6353
		if(isset($conf["id"])){
6354
 
6355
			#設置 id
6356
			$id=$conf["id"];
6357
 
6358
			}#if end
6359
 
6360
		#反之如果有設置 cname
6361
		else if(isset($conf["cname"])){
6362
 
6363
			#函式說明:
6364
			#取得在zerossl上的CSR清單
6365
			#回傳結果:
6366
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6367
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
6368
			#$result["function"],當前執行的函式名稱.
6369
			#$result["argu"],所使用的參數.
6370
			#$result["curl_verbose_info"],curl執行的詳細資訊.
6371
			#$result["content"],結果json字串.
6372
			#$result["tCound"],總共的資料筆數.
6373
			#$result["count"],該頁的筆數.
6374
			#$result["page"],當前的頁碼.
6375
			#$result["certs"],陣列,certificates清單,key為certificate的id.
6376
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
6377
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
6378
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
6379
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6380
			#必填參數:
6381
			#無
6382
			#可省略參數:
6383
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6384
			#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6385
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6386
			#$conf["key"]=self::getApiInfo()["apiKey"];
6387
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6388
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
6389
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
6390
			#$conf["cerType"]="";
6391
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
6392
			$conf["zerossl::getCertList"]["search"]=$conf["cname"];
6393
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
6394
			#$conf["limit"]="";
6395
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
6396
			#$conf["page"]="";
6397
			#參考資料:
6398
			#https://zerossl.com/documentation/api/get-certificate/
6399
			#備註:
6400
			#無.
6401
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
6402
			unset($conf["zerossl::getCertList"]);
6403
 
6404
			#如果檢查失敗
6405
			if($getCertList["status"]==="false"){
6406
 
6407
				#設置錯誤識別
6408
				$result["status"]="false";
6409
 
6410
				#設置錯誤訊息
6411
				$result["error"]=$getCertList;
6412
 
6413
				#回傳結果
6414
				return $result;
6415
 
6416
				}#if end
6417
 
6418
			#如果資料筆數大於0
6419
			if($getCertList["count"]>0){
6420
 
6421
				#取得第一筆
6422
				foreach($getCertList["certs"] as $cerId => $detail){
6423
 
6424
					#取得cettificate id
6425
					$id=$cerId;
6426
 
6427
					}#foreach end
6428
 
6429
				}#if end
6430
 
6431
			}#if end
6432
 
6433
		#預設網址
6434
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
6435
 
6436
		#函式說明:
6437
		#運行curl cmd
6438
		#回傳結果:
6439
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6440
		#$result["error"],錯誤訊息陣列.
6441
		#$result["function"],當前執行的函式名稱.
6442
		#$result["founded"],識別網址找不找得到.
6443
		#$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"代表程序的資訊.
6444
		#$result["fullContent"],取得回應的完整字串內容.
6445
		#$result["cookie"],cookie檔案的位置與名稱.
6446
		#$result["cmd"],執行的command.
6447
		#$result["argu],使用的參數.
6448
		#必填參數:
6449
		#$conf["url"],字串,目標url.
6450
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6451
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6452
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6453
		#可省略參數:
6454
		#$conf["header"],字串陣列,要傳送的header.
6455
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
6456
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6457
		#$conf["allowAnySSLcertificate"]="";
6458
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6459
		#$conf["postVar"]=array();
6460
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6461
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6462
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
6463
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
6464
		#$conf["agent"],字串,user agent的名稱.
6465
		#$conf["agent"]="";
6466
		#$conf["cookie"],字串,cookie位置與檔案位置.
6467
		#$conf["cookie"]="";
6468
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6469
		#$conf["forceNewCookie"]="";
6470
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6471
		#$conf["inBg"]="true";
6472
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6473
		#$conf["bgInProc"]="false";
6474
		#參考資料:
6475
		#無.
6476
		#備註:
6477
		#無.
6478
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6479
		unset($conf["catchWebContent::curlCmd"]);
6480
 
6481
		#如果異常
6482
		if($curlCmd["status"]==="false"){
6483
 
6484
			#設置錯誤識別
6485
			$result["status"]="false";
6486
 
6487
			#設置錯誤訊息
6488
			$result["error"]=$curlCmd;
6489
 
6490
			#回傳結果
6491
			return $result;
6492
 
6493
			}#if end
6494
 
6495
		#設置curl的詳細資訊
6496
		$result["curl_verbose_info"]=$curlCmd;
6497
 
249 liveuser 6498
		#驗證結果是否為 json
6499
		$json_validate=json_validate($curlCmd["fullContent"]);
6500
 
6501
		#如果回應不是 json
6502
		if(!$json_validate){
6503
 
6504
			#設置錯誤識別
6505
			$result["status"]="false";
6506
 
6507
			#設置錯誤訊息
6508
			$result["error"]=$curlCmd;
6509
 
6510
			#回傳結果
6511
			return $result;
6512
 
6513
			}#if end
6514
 
6515
		#設置json string結果
6516
		$result["content"]=$curlCmd["fullContent"];
255 liveuser 6517
 
6518
		#取得 json
6519
		$json=json_decode($curlCmd["fullContent"]);
6520
 
291 liveuser 6521
		#儲存成變數以便透過object呼叫
6522
		$c_crt="certificate.crt";
6523
 
6524
		#儲存成變數以便透過object呼叫
6525
		$ca_crt="ca_bundle.crt";
6526
 
294 liveuser 6527
		#如果沒有該有的 certificate.crt 跟 ca_bundle.crt 物件
6528
		if(!isset($json->$c_crt) || !isset($json->$ca_crt)){
6529
 
6530
			#設置錯誤識別
6531
			$result["status"]="false";
6532
 
6533
			#設置錯誤訊息
6534
			$result["error"]=$json;
6535
 
6536
			#回傳結果
6537
			return $result;
6538
 
6539
			}#if end
6540
 
255 liveuser 6541
		#取得certificate.crt的內容
291 liveuser 6542
		$result["certificate.crt"]=$json->$c_crt;
255 liveuser 6543
 
6544
		#取得ca_bundle.crt的內容
291 liveuser 6545
		$result["ca_bundle.crt"]=$json->$ca_crt;
255 liveuser 6546
 
6547
		#設置執行正常
6548
		$result["status"]="true";
6549
 
6550
		#回傳結果
6551
		return $result;
6552
 
6553
		}#function getCert end
6554
 
6555
	/*
6556
	#函式說明:
6557
	#請求廢除 issued zerossl certificate.
6558
	#回傳結果:
6559
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6560
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6561
	#$result["function"],當前執行的函式名稱.
6562
	#$result["argu"],所使用的參數.
6563
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6564
	#$result["content"],結果json字串.
341 liveuser 6565
	#$result["busy"],若content結果含有busy屬性,且為1,則為"true";反之為"false".
255 liveuser 6566
	#必填參數:
6567
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
6568
	$conf["id"]="";
6569
	#可省略參數:
6570
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6571
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6572
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6573
	#$conf["key"]=self::getApiInfo()["apiKey"];
6574
	#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
6575
	#$conf["reason"]="";
6576
	#參考資料:
6577
	#https://zerossl.com/documentation/api/revoke-certificate/
6578
	#備註:
338 liveuser 6579
	#跟api頁面的描述不同,access_key參數實際上要用get方式傳遞.
341 liveuser 6580
	#跟api頁面的描述不同,api point忙碌中,無法回應時,回應會為空.
255 liveuser 6581
	*/
6582
	public static function revokeCert(&$conf){
6583
 
6584
		#初始化要回傳的結果
6585
		$result=array();
249 liveuser 6586
 
255 liveuser 6587
		#設置當其函數名稱
6588
		$result["function"]=__FUNCTION__;
6589
 
6590
		#如果 $conf 不為陣列
6591
		if(gettype($conf)!="array"){
6592
 
6593
			#設置執行失敗
6594
			$result["status"]="false";
6595
 
6596
			#設置執行錯誤訊息
6597
			$result["error"][]="\$conf變數須為陣列形態";
6598
 
6599
			#如果傳入的參數為 null
6600
			if($conf==null){
6601
 
6602
				#設置執行錯誤訊息
6603
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6604
 
6605
				}#if end
6606
 
6607
			#回傳結果
6608
			return $result;
6609
 
6610
			}#if end
6611
 
6612
		#取得參數
6613
		$result["argu"]=$conf;
6614
 
6615
		#檢查參數
6616
		#函式說明:
6617
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6618
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6619
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6620
		#$result["function"],當前執行的函式名稱.
6621
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6622
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6623
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6624
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6625
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6626
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6627
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6628
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6629
		#必填寫的參數:
6630
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6631
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6632
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6633
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6634
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6635
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6636
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6637
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6638
		#可以省略的參數:
6639
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6640
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6641
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6642
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6643
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6644
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
6645
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
334 liveuser 6646
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
255 liveuser 6647
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6648
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
6649
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6650
		#$conf["arrayCountEqualCheck"][]=array();
6651
		#參考資料來源:
6652
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6653
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6654
		unset($conf["variableCheck::checkArguments"]);
6655
 
6656
		#如果檢查失敗
6657
		if($checkArguments["status"]==="false"){
6658
 
6659
			#設置錯誤識別
6660
			$result["status"]="false";
6661
 
6662
			#設置錯誤訊息
6663
			$result["error"]=$checkArguments;
6664
 
6665
			#回傳結果
6666
			return $result;
6667
 
6668
			}#if end
6669
 
6670
		#如果檢查不通過
6671
		if($checkArguments["passed"]==="false"){
6672
 
6673
			#設置錯誤識別
6674
			$result["status"]="false";
6675
 
6676
			#設置錯誤訊息
6677
			$result["error"]=$checkArguments;
6678
 
6679
			#回傳結果
6680
			return $result;
6681
 
6682
			}#if end
6683
 
338 liveuser 6684
		#url to call,含api key,跟 api 頁面不一致.
6685
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
255 liveuser 6686
 
337 liveuser 6687
		#初始化要post的變數陣列
6688
		$postVar=array();
6689
 
338 liveuser 6690
		#設置  api key,跟 api 頁面不一致.
6691
		#$postVar["access_key"]=$conf["key"];
337 liveuser 6692
 
255 liveuser 6693
		#如果有設置 reason
6694
		if(isset($conf["reason"])){
6695
 
6696
			#設置reason
337 liveuser 6697
			$postVar["reason"]=$conf["reason"];
255 liveuser 6698
 
6699
			}#if end
337 liveuser 6700
 
255 liveuser 6701
		#函式說明:
6702
		#運行curl cmd
6703
		#回傳結果:
6704
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6705
		#$result["error"],錯誤訊息陣列.
6706
		#$result["function"],當前執行的函式名稱.
6707
		#$result["founded"],識別網址找不找得到.
6708
		#$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"代表程序的資訊.
6709
		#$result["fullContent"],取得回應的完整字串內容.
6710
		#$result["cookie"],cookie檔案的位置與名稱.
6711
		#$result["cmd"],執行的command.
6712
		#$result["argu],使用的參數.
6713
		#必填參數:
6714
		#$conf["url"],字串,目標url.
6715
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6716
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6717
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6718
		#可省略參數:
6719
		#$conf["header"],字串陣列,要傳送的header.
338 liveuser 6720
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
255 liveuser 6721
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6722
		#$conf["allowAnySSLcertificate"]="";
338 liveuser 6723
 
6724
		#如果有資料
6725
		if(!empty($postVar)){
6726
 
6727
			#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6728
			$conf["catchWebContent::curlCmd"]["postVar"]=$postVar;
6729
 
6730
			}#if end
6731
 
255 liveuser 6732
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6733
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6734
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
338 liveuser 6735
		$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
255 liveuser 6736
		#$conf["agent"],字串,user agent的名稱.
6737
		#$conf["agent"]="";
6738
		#$conf["cookie"],字串,cookie位置與檔案位置.
6739
		#$conf["cookie"]="";
6740
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6741
		#$conf["forceNewCookie"]="";
6742
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6743
		#$conf["inBg"]="true";
6744
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6745
		#$conf["bgInProc"]="false";
6746
		#參考資料:
6747
		#無.
6748
		#備註:
6749
		#無.
6750
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6751
		unset($conf["catchWebContent::curlCmd"]);
6752
 
6753
		#如果異常
6754
		if($curlCmd["status"]==="false"){
6755
 
6756
			#設置錯誤識別
6757
			$result["status"]="false";
6758
 
6759
			#設置錯誤訊息
6760
			$result["error"]=$curlCmd;
6761
 
6762
			#回傳結果
6763
			return $result;
6764
 
6765
			}#if end
6766
 
6767
		#設置curl的詳細資訊
6768
		$result["curl_verbose_info"]=$curlCmd;
6769
 
341 liveuser 6770
		#如果 server 的回應為空
6771
		if(empty($curlCmd["fullContent"])){
6772
 
6773
			#初始化json回應
6774
			$jsonRes=array();
6775
 
6776
			#設置不成功
6777
			$jsonRes["success"]=0;
6778
 
6779
			#設置server忙碌中,贊述無法處理要求.
6780
			$jsonRes["busy"]=1;
6781
 
6782
			#設置json結果
6783
			$curlCmd["fullContent"]=json_encode($jsonRes);
6784
 
6785
			}#if end
6786
 
255 liveuser 6787
		#驗證結果是否為 json
6788
		$json_validate=json_validate($curlCmd["fullContent"]);
6789
 
6790
		#如果回應不是 json
6791
		if(!$json_validate){
6792
 
6793
			#設置錯誤識別
6794
			$result["status"]="false";
6795
 
6796
			#設置錯誤訊息
6797
			$result["error"]=$curlCmd;
6798
 
6799
			#回傳結果
6800
			return $result;
6801
 
6802
			}#if end
341 liveuser 6803
 
255 liveuser 6804
		#設置json string結果
6805
		$result["content"]=$curlCmd["fullContent"];
6806
 
249 liveuser 6807
		#解析json
6808
		$jsonRes=json_decode($result["content"]);
6809
 
255 liveuser 6810
		#如果沒有要有的attr
6811
		if(!isset($jsonRes->success)){
6812
 
6813
			#設置錯誤識別
6814
			$result["status"]="false";
6815
 
6816
			#設置錯誤訊息
6817
			$result["error"]=$curlCmd;
6818
 
6819
			#回傳結果
6820
			return $result;
6821
 
6822
			}#if end
341 liveuser 6823
 
255 liveuser 6824
		#如果 success 不等於 1
6825
		if($jsonRes->success!==1){
6826
 
341 liveuser 6827
			#如果有 busy 屬性
6828
			if(isset($jsonRes->busy)){
6829
 
6830
				#如果busy為1
6831
				if($jsonRes->busy===1){
6832
 
6833
					#設置sever忙碌中,無法回應.
6834
					$result["busy"]="true";
6835
 
6836
					}#if end
6837
 
6838
				}#if end
6839
 
255 liveuser 6840
			#設置錯誤識別
6841
			$result["status"]="false";
6842
 
6843
			#設置錯誤訊息
6844
			$result["error"]=$curlCmd;
6845
 
6846
			#回傳結果
6847
			return $result;
6848
 
6849
			}#if end
6850
 
341 liveuser 6851
		#如果回應結果不含busy元素
6852
		if(!isset($result["busy"])){
6853
 
6854
			#設置其為"false",代表server沒有忙碌中,無法回應.
6855
			$result["busy"]="false";
6856
 
6857
			}#else end
6858
 
249 liveuser 6859
		#設置執行正常
6860
		$result["status"]="true";
6861
 
6862
		#回傳結果
6863
		return $result;
6864
 
255 liveuser 6865
		}#function revokeCert end
6866
 
6867
	/*
6868
	#函式說明:
6869
	#請求取消 draft or unvalidated zerossl certificate.
6870
	#回傳結果:
6871
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6872
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6873
	#$result["function"],當前執行的函式名稱.
6874
	#$result["argu"],所使用的參數.
6875
	#$result["curl_verbose_info"],curl執行的詳細資訊.
6876
	#$result["content"],結果json字串.
6877
	#必填參數:
6878
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
6879
	$conf["id"]="";
6880
	#可省略參數:
6881
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6882
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6883
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6884
	#$conf["key"]=self::getApiInfo()["apiKey"];
6885
	#參考資料:
6886
	#https://zerossl.com/documentation/api/revoke-certificate/
6887
	#備註:
6888
	#無.
6889
	*/
6890
	public static function cancelCert(&$conf){
6891
 
6892
		#初始化要回傳的結果
6893
		$result=array();
249 liveuser 6894
 
255 liveuser 6895
		#設置當其函數名稱
6896
		$result["function"]=__FUNCTION__;
6897
 
6898
		#如果 $conf 不為陣列
6899
		if(gettype($conf)!="array"){
6900
 
6901
			#設置執行失敗
6902
			$result["status"]="false";
6903
 
6904
			#設置執行錯誤訊息
6905
			$result["error"][]="\$conf變數須為陣列形態";
6906
 
6907
			#如果傳入的參數為 null
6908
			if($conf==null){
6909
 
6910
				#設置執行錯誤訊息
6911
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6912
 
6913
				}#if end
6914
 
6915
			#回傳結果
6916
			return $result;
6917
 
6918
			}#if end
6919
 
6920
		#取得參數
6921
		$result["argu"]=$conf;
6922
 
6923
		#檢查參數
6924
		#函式說明:
6925
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6926
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6927
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6928
		#$result["function"],當前執行的函式名稱.
6929
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6930
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6931
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6932
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6933
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6934
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6935
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6936
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6937
		#必填寫的參數:
6938
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6939
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6940
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6941
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6942
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6943
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6944
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6945
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6946
		#可以省略的參數:
6947
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6948
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6949
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6950
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6951
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6952
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
6953
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6954
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
6955
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6956
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
6957
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6958
		#$conf["arrayCountEqualCheck"][]=array();
6959
		#參考資料來源:
6960
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6961
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6962
		unset($conf["variableCheck::checkArguments"]);
6963
 
6964
		#如果檢查失敗
6965
		if($checkArguments["status"]==="false"){
6966
 
6967
			#設置錯誤識別
6968
			$result["status"]="false";
6969
 
6970
			#設置錯誤訊息
6971
			$result["error"]=$checkArguments;
6972
 
6973
			#回傳結果
6974
			return $result;
6975
 
6976
			}#if end
6977
 
6978
		#如果檢查不通過
6979
		if($checkArguments["passed"]==="false"){
6980
 
6981
			#設置錯誤識別
6982
			$result["status"]="false";
6983
 
6984
			#設置錯誤訊息
6985
			$result["error"]=$checkArguments;
6986
 
6987
			#回傳結果
6988
			return $result;
6989
 
6990
			}#if end
6991
 
6992
		#url to call
6993
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
6994
 
6995
		#函式說明:
6996
		#運行curl cmd
6997
		#回傳結果:
6998
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6999
		#$result["error"],錯誤訊息陣列.
7000
		#$result["function"],當前執行的函式名稱.
7001
		#$result["founded"],識別網址找不找得到.
7002
		#$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"代表程序的資訊.
7003
		#$result["fullContent"],取得回應的完整字串內容.
7004
		#$result["cookie"],cookie檔案的位置與名稱.
7005
		#$result["cmd"],執行的command.
7006
		#$result["argu],使用的參數.
7007
		#必填參數:
7008
		#$conf["url"],字串,目標url.
7009
		$conf["catchWebContent::curlCmd"]["url"]=$url;
7010
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7011
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
7012
		#可省略參數:
7013
		#$conf["header"],字串陣列,要傳送的header.
7014
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
7015
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
7016
		#$conf["allowAnySSLcertificate"]="";
7017
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
7018
		#$conf["postVar"]=array();
7019
		#$conf["rawPost"]="字串",要傳送的raw post內容.
7020
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
7021
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
7022
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
7023
		#$conf["agent"],字串,user agent的名稱.
7024
		#$conf["agent"]="";
7025
		#$conf["cookie"],字串,cookie位置與檔案位置.
7026
		#$conf["cookie"]="";
7027
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
7028
		#$conf["forceNewCookie"]="";
7029
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
7030
		#$conf["inBg"]="true";
7031
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
7032
		#$conf["bgInProc"]="false";
7033
		#參考資料:
7034
		#無.
7035
		#備註:
7036
		#無.
7037
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
7038
		unset($conf["catchWebContent::curlCmd"]);
7039
 
7040
		#如果異常
7041
		if($curlCmd["status"]==="false"){
7042
 
7043
			#設置錯誤識別
7044
			$result["status"]="false";
7045
 
7046
			#設置錯誤訊息
7047
			$result["error"]=$curlCmd;
7048
 
7049
			#回傳結果
7050
			return $result;
7051
 
7052
			}#if end
7053
 
7054
		#設置curl的詳細資訊
7055
		$result["curl_verbose_info"]=$curlCmd;
7056
 
7057
		#驗證結果是否為 json
7058
		$json_validate=json_validate($curlCmd["fullContent"]);
7059
 
7060
		#如果回應不是 json
7061
		if(!$json_validate){
7062
 
7063
			#設置錯誤識別
7064
			$result["status"]="false";
7065
 
7066
			#設置錯誤訊息
7067
			$result["error"]=$curlCmd;
7068
 
7069
			#回傳結果
7070
			return $result;
7071
 
7072
			}#if end
7073
 
7074
		#設置json string結果
7075
		$result["content"]=$curlCmd["fullContent"];
7076
 
7077
		#解析json
7078
		$jsonRes=json_decode($result["content"]);
7079
 
7080
		#如果沒有要有的attr
7081
		if(!isset($jsonRes->success)){
7082
 
7083
			#設置錯誤識別
7084
			$result["status"]="false";
7085
 
7086
			#設置錯誤訊息
7087
			$result["error"]=$curlCmd;
7088
 
7089
			#回傳結果
7090
			return $result;
7091
 
7092
			}#if end
7093
 
7094
		#如果 success 不等於 1
7095
		if($jsonRes->success!==1){
7096
 
7097
			#設置錯誤識別
7098
			$result["status"]="false";
7099
 
7100
			#設置錯誤訊息
7101
			$result["error"]=$curlCmd;
7102
 
7103
			#回傳結果
7104
			return $result;
7105
 
7106
			}#if end
7107
 
7108
		#設置執行正常
7109
		$result["status"]="true";
7110
 
7111
		#回傳結果
7112
		return $result;
7113
 
7114
		}#function cancelCert end
7115
 
7116
	/*
7117
	#函式說明:
7118
	#透過zerossl api確保ssl沒有過期.
7119
	#回傳結果:
7120
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7121
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7122
	#$result["function"],當前執行的函式名稱.
7123
	#$result["argu"],所使用的參數.
7124
	#必填參數:
7125
	#$conf["cName"],陣列,每個ssl的common domain name.
7126
	$conf["cName"]=array();
7127
	#$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內容合併後的檔案位置與名稱.
7128
	$conf["certInfo"]=array();
7129
	#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
7130
	$conf["rrFile"]=array();
7131
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
7132
	$conf["dnsSerAddr"]=array();
7133
	#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
7134
	$conf["actionAfterUpdateCert"]=array();
7135
	#可省略參數:
288 liveuser 7136
	#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/sslUpdater.sock
7137
	#$conf["sock"]="";
281 liveuser 7138
	#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
7139
	#$conf["debug"]="";
255 liveuser 7140
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7141
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
7142
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7143
	#$conf["key"]=self::getApiInfo()["apiKey"];
293 liveuser 7144
	#$conf["multiThreads"],字串,預設為"false"代表不使用多執行序;"true"代表要用多執行序.
7145
	#$conf["multiThreads"]=""
255 liveuser 7146
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
7147
	#$conf["debug"]="";
7148
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
7149
	#$conf["addOnProcessFunc"]=array();
7150
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
7151
	#$conf["funcToRunWhenIdle"]=array();
7152
	#參考資料:
7153
	#無.
7154
	#備註:
7155
	#無.
7156
	*/
7157
	public static function sslUpdater(&$conf){
7158
 
7159
		#初始化要回傳的結果
7160
		$result=array();
7161
 
7162
		#設置當其函數名稱
7163
		$result["function"]=__FUNCTION__;
7164
 
7165
		#如果 $conf 不為陣列
7166
		if(gettype($conf)!="array"){
7167
 
7168
			#設置執行失敗
7169
			$result["status"]="false";
7170
 
7171
			#設置執行錯誤訊息
7172
			$result["error"][]="\$conf變數須為陣列形態";
7173
 
7174
			#如果傳入的參數為 null
7175
			if($conf==null){
7176
 
7177
				#設置執行錯誤訊息
7178
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7179
 
7180
				}#if end
7181
 
7182
			#回傳結果
7183
			return $result;
7184
 
7185
			}#if end
7186
 
7187
		#取得參數
7188
		$result["argu"]=$conf;
288 liveuser 7189
 
7190
		#初始化預設的 unix domain socket 路徑
7191
		$defaultSocket=pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/sslUpdater.sock";
255 liveuser 7192
 
7193
		#檢查參數
7194
		#函式說明:
7195
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7196
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7197
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7198
		#$result["function"],當前執行的函式名稱.
7199
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7200
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7201
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7202
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7203
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7204
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7205
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7206
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7207
		#必填寫的參數:
7208
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7209
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7210
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7211
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
7212
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
7213
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
7214
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7215
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7216
		#可以省略的參數:
7217
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7218
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7219
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
293 liveuser 7220
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("multiThreads","sock","debug","apiDomain","key");
255 liveuser 7221
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
293 liveuser 7222
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("multiThreads","sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
255 liveuser 7223
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
293 liveuser 7224
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array","array");
255 liveuser 7225
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
293 liveuser 7226
		$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 7227
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7228
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
7229
		#參考資料來源:
7230
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7231
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7232
		unset($conf["variableCheck::checkArguments"]);
7233
 
7234
		#如果檢查失敗
7235
		if($checkArguments["status"]==="false"){
7236
 
7237
			#設置錯誤識別
7238
			$result["status"]="false";
7239
 
7240
			#設置錯誤訊息
7241
			$result["error"]=$checkArguments;
7242
 
7243
			#回傳結果
7244
			return $result;
7245
 
7246
			}#if end
7247
 
7248
		#如果檢查不通過
7249
		if($checkArguments["passed"]==="false"){
7250
 
7251
			#設置錯誤識別
7252
			$result["status"]="false";
7253
 
7254
			#設置錯誤訊息
7255
			$result["error"]=$checkArguments;
7256
 
7257
			#回傳結果
7258
			return $result;
7259
 
7260
			}#if end
7261
 
7262
		#取得key
7263
		$share["key"]=$conf["key"];
7264
 
7265
		#取得apiDomain
7266
		$share["apiDomain"]=$conf["apiDomain"];
7267
 
281 liveuser 7268
		#設置debug flag
7269
		$share["debug"]=$conf["debug"];
7270
 
293 liveuser 7271
		#設置 multiThreads 
7272
		$share["multiThreads"]=$conf["multiThreads"];
7273
 
255 liveuser 7274
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
7275
		$share["certInfo"]=array();
7276
 
7277
		#針對每個 domain
7278
		foreach($conf["cName"] as $index=>$cName ){
7279
 
7280
			#如果沒有對應的certInfo
7281
			if(!isset($conf["certInfo"][$index])){
7282
 
7283
				#設置錯誤識別
7284
				$result["status"]="false";
7285
 
7286
				#設置錯誤訊息
7287
				$result["error"][]="missing certInfo";
7288
 
7289
				#設置錯誤訊息
7290
				$result["error"][]=$checkArguments;
7291
 
7292
				#回傳結果
7293
				return $result;
7294
 
7295
				}#if end
7296
 
291 liveuser 7297
			#檢查 $conf["certInfo"][$index] 是否資訊都有存在
7298
			#函式說明:
7299
			#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
7300
			#回傳結果:
7301
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7302
			#$result["error"],執行不正常結束的錯訊息陣列.
7303
			#$result["simpleError"],簡單表示的錯誤訊息.
7304
			#$result["function"],當前執行的函式名稱.
7305
			#$result["argu"],設置給予的參數.
7306
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7307
			#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7308
			#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7309
			#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7310
			#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7311
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7312
			#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7313
			#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7314
			#必填參數:
7315
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7316
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["certInfo"][$index];
7317
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7318
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7319
			#可省略參數:
7320
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7321
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
7322
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
7323
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
7324
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7325
			#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7326
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
7327
			#$conf["canNotBeEmpty"]=array();
7328
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
7329
			#$conf["canBeEmpty"]=array();
7330
			#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
7331
			$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("true","true","true","true");
7332
			#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7333
			$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
7334
			#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7335
			$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
7336
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7337
			$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");
7338
			#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
7339
			#$conf["disallowAllSkipableVarIsEmpty"]="";
7340
			#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
7341
			#$conf["disallowAllSkipableVarIsEmptyArray"]="";
7342
			#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
7343
			#$conf["disallowAllSkipableVarNotExist"]="";
7344
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7345
			#$conf["arrayCountEqualCheck"][]=array();
7346
			#參考資料:
7347
			#array_keys=>http://php.net/manual/en/function.array-keys.php
7348
			#備註:
7349
			#無.
7350
			$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7351
			unset($conf["variableCheck::checkArguments"]);
7352
 
7353
			#如果檢查失敗
7354
			if($checkArguments["status"]==="false"){
7355
 
7356
				#設置錯誤識別
7357
				$result["status"]="false";
7358
 
7359
				#設置錯誤訊息
7360
				$result["error"]=$checkArguments;
7361
 
7362
				#回傳結果
7363
				return $result;
7364
 
7365
				}#if end
7366
 
7367
			#如果檢查不通過
7368
			if($checkArguments["passed"]==="false"){
7369
 
7370
				#設置錯誤識別
7371
				$result["status"]="false";
7372
 
7373
				#設置錯誤訊息
7374
				$result["error"]=$checkArguments;
7375
 
7376
				#回傳結果
7377
				return $result;
7378
 
7379
				}#if end
7380
 
7381
			#儲存 cName
7382
			$cInfo["cName"]=$cName;
255 liveuser 7383
 
291 liveuser 7384
			#儲存 RR 檔案的路徑與名稱
7385
			$cInfo["rrFile"]=$conf["rrFile"][$index];
255 liveuser 7386
 
291 liveuser 7387
			#儲存 cName 對應的 dns server addr
7388
			$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
255 liveuser 7389
 
291 liveuser 7390
			#儲存 cName 的憑證更新後要做的事情.
7391
			$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
255 liveuser 7392
 
294 liveuser 7393
			#用 ";" 分割來取得有多少個動作要依序執行
7394
			#函式說明:
7395
			#將固定格式的字串分開,並回傳分開的結果.
7396
			#回傳結果:
7397
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7398
			#$result["error"],錯誤訊息陣列
7399
			#$result["function"],當前執行的函數名稱.
7400
			#$result["argu"],使用的參數.
7401
			#$result["oriStr"],要分割的原始字串內容
7402
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7403
			#$result["dataCounts"],爲總共分成幾段
7404
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
7405
			#必填參數:
7406
			#$conf["stringIn"],字串,要處理的字串.
7407
			$conf["stringProcess::spiltString"]["stringIn"]=$cInfo["actionAfterUpdateCert"];
7408
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
7409
			$conf["stringProcess::spiltString"]["spiltSymbol"]=";";
7410
			#可省略參數:
7411
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
7412
			#$conf["allowEmptyStr"]="false";
7413
			#參考資料:
7414
			#無.
7415
			#備註:
7416
			#無.
7417
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
7418
			unset($conf["stringProcess::spiltString"]);
7419
 
7420
			#如果執行異常
7421
			if($spiltString["status"]==="false"){
7422
 
7423
				#設置錯誤識別
7424
				$result["status"]="false";
7425
 
7426
				#設置錯誤訊息
7427
				$result["error"]=$spiltString;
7428
 
7429
				#回傳結果
7430
				return $result;
7431
 
7432
				}#if end
7433
 
7434
			#如果沒有";"存在,代表格式不對
7435
			if($spiltString["found"]==="false"){
7436
 
7437
				#設置錯誤識別
7438
				$result["status"]="false";
7439
 
7440
				#設置錯誤訊息
7441
				$result["error"]=$spiltString;
7442
 
7443
				#回傳結果
7444
				return $result;
7445
 
7446
				}#if end
7447
 
7448
			#取得每個動作
7449
			$cInfo["actionAfterUpdateCert"]=$spiltString["dataArray"];
7450
 
291 liveuser 7451
			#設置 certPath
7452
			$cInfo["ssl"]["certPath"]=$conf["certInfo"][$index]["certPath"];
255 liveuser 7453
 
291 liveuser 7454
			#設置 pKey
7455
			$cInfo["ssl"]["pKey"]=$conf["certInfo"][$index]["pKey"];
7456
 
7457
			#設置 caPath
7458
			$cInfo["ssl"]["caPath"]=$conf["certInfo"][$index]["caPath"];
7459
 
7460
			#設置 certWithCaPath
7461
			$cInfo["ssl"]["certWithCaPath"]=$conf["certInfo"][$index]["certWithCaPath"];
7462
 
7463
			#儲存 certInfo
7464
			$share["certInfo"][]=$cInfo;
7465
 
255 liveuser 7466
			}#foreach end
7467
 
7468
		#如果為空
7469
		if(empty($share["certInfo"])){
7470
 
7471
			#設置錯誤識別
7472
			$result["status"]="false";
7473
 
7474
			#設置錯誤訊息
7475
			$result["error"][]="certInfo 參數有缺";
7476
 
7477
			#設置錯誤訊息
7478
			$result["error"][]=$checkArguments;
7479
 
7480
			#回傳結果
7481
			return $result;
7482
 
7483
			}#if end
7484
 
7485
		#函式說明:
7486
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
7487
		#回傳結果:
7488
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
7489
		#$result["error"],錯誤訊息陣列.
7490
		#$result["function"],當前執行的函式名稱.
7491
		#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
7492
		#$result["serverCache"]["serverSide"],server side 的 cache.
7493
		#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
7494
		#$result["serverCache"]["clientSide"],client site 的 cache.
7495
		#必填參數:
7496
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
291 liveuser 7497
		$conf["sock::unixDomainSockServer"]["sock"]=$conf["sock"];
255 liveuser 7498
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7499
		$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
7500
		#可省略參數:
7501
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
7502
		$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
7503
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
7504
		$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
7505
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
7506
		#$conf["sessionTimeout"]="300";
7507
		#$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 7508
		$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("\qbpwcf\zerossl::sslUpdater_cmd");
255 liveuser 7509
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
291 liveuser 7510
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\qbpwcf\zerossl::sslUpdater_idle");
255 liveuser 7511
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
7512
		#$conf["paramsForFuncToRunWhenIdle"]=array();
7513
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7514
		$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
7515
		#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
7516
		#$conf["shutdownStrAddr"]="";
7517
		#參考資料:
7518
		#http://php.net/manual/en/function.stream-socket-server.php
7519
		#備註:
7520
		#無.
7521
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
7522
		unset($conf["sock::unixDomainSockServer"]);
7523
 
7524
		#執行異常
7525
		if($unixDomainSockServer["status"]==="false"){
7526
 
7527
			#設置錯誤識別
7528
			$result["status"]="false";
7529
 
7530
			#設置錯誤訊息
7531
			$result["error"]=$unixDomainSockServer;
7532
 
7533
			#回傳結果
7534
			return $result;
7535
 
7536
			}#if end
7537
 
7538
		#設置執行正常
7539
		$result["status"]="true";
7540
 
7541
		#回傳結果
7542
		return $result;
7543
 
7544
		}#function sslUpdater end
7545
 
7546
	/*
7547
	#函式說明:
7548
	#funcion sslUpdater 於收到訊息時要做的事情.
7549
	#回傳結果:
7550
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7551
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7552
	#$result["function"],當前執行的函式名稱.
7553
	#$result["argu"],所使用的參數.
7554
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
7555
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
7556
	#必填參數:
7557
	#$conf["request"],字串,收到的json訊息.
7558
	$conf["request"]="";
7559
	#$conf["sock"],resource,用戶的socket.
7560
	$conf["sock"]="";
7561
	#$conf["clientCache"],陣列,給予所有用戶的cache.
7562
	$conf["clientCache"]=array();
7563
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7564
	$conf["info"]=array();
7565
	#可省略參數:
7566
	#無.
7567
	#參考資料:
7568
	#無.
7569
	#備註:
7570
	#建構中...
7571
	*/
7572
	public static function sslUpdater_cmd(&$conf){
7573
 
7574
		#debug
7575
		var_dump($conf);
7576
 
7577
		}#function sslUpdater_cmd end
7578
 
7579
	/*
7580
	#函式說明:
7581
	#funcion sslUpdater 於閒置時要做的事情
7582
	#回傳結果:
7583
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7584
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
7585
	#$result["function"],當前執行的函式名稱.
7586
	#$result["argu"],所使用的參數.
7587
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
7588
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
7589
	#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
7590
	#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
7591
	#必填參數:
7592
	#$conf["client"],陣列,所有用戶的資訊.
7593
	$conf["client"]=array();
7594
	#$conf["clientCache"],陣列,給予所有用戶的cache.
7595
	$conf["clientCache"]=array();
7596
	#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
7597
	$conf["serverCache"]=array();
7598
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
7599
	$conf["info"]=array();
7600
	#可省略參數:
7601
	#無.
7602
	#參考資料:
7603
	#無.
7604
	#備註:
291 liveuser 7605
	#無.
255 liveuser 7606
	*/
7607
	public static function sslUpdater_idle(&$conf){
7608
 
7609
		#初始化要回傳的結果
7610
		$result=array();
7611
 
7612
		#設置當其函數名稱
7613
		$result["function"]=__FUNCTION__;
7614
 
7615
		#如果 $conf 不為陣列
7616
		if(gettype($conf)!="array"){
7617
 
7618
			#設置執行失敗
7619
			$result["status"]="false";
7620
 
7621
			#設置執行錯誤訊息
7622
			$result["error"][]="\$conf變數須為陣列形態";
7623
 
7624
			#如果傳入的參數為 null
7625
			if($conf==null){
7626
 
7627
				#設置執行錯誤訊息
7628
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7629
 
7630
				}#if end
7631
 
7632
			#回傳結果
7633
			return $result;
7634
 
7635
			}#if end
7636
 
7637
		#取得參數
7638
		$result["argu"]=$conf;
7639
 
7640
		#檢查參數
7641
		#函式說明:
7642
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7643
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7644
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7645
		#$result["function"],當前執行的函式名稱.
7646
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7647
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7648
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7649
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7650
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7651
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7652
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7653
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7654
		#必填寫的參數:
7655
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7656
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7657
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
291 liveuser 7658
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","serverCache","info");
255 liveuser 7659
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
291 liveuser 7660
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
255 liveuser 7661
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7662
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7663
		#可以省略的參數:
7664
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7665
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7666
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
7667
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7668
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7669
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
7670
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7671
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
7672
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7673
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
7674
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7675
		#$conf["arrayCountEqualCheck"][]=array();
7676
		#參考資料來源:
7677
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7678
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7679
		unset($conf["variableCheck::checkArguments"]);
7680
 
7681
		#如果檢查失敗
7682
		if($checkArguments["status"]==="false"){
7683
 
7684
			#設置錯誤識別
7685
			$result["status"]="false";
7686
 
7687
			#設置錯誤訊息
7688
			$result["error"]=$checkArguments;
7689
 
7690
			#回傳結果
7691
			return $result;
7692
 
7693
			}#if end
7694
 
7695
		#如果檢查不通過
7696
		if($checkArguments["passed"]==="false"){
7697
 
7698
			#設置錯誤識別
7699
			$result["status"]="false";
7700
 
7701
			#設置錯誤訊息
7702
			$result["error"]=$checkArguments;
7703
 
7704
			#回傳結果
7705
			return $result;
7706
 
7707
			}#if end
281 liveuser 7708
 
7709
		#預設不開啟 debug flag
7710
		$debug=false;
7711
 
7712
		#如果有設置 debug 為 "true"
291 liveuser 7713
		if($conf["info"]["share"]["debug"]==="true"){
281 liveuser 7714
 
7715
			#設置 debug flag
7716
			$debug=true;
7717
 
7718
			}#if end
7719
 
293 liveuser 7720
		#如果有啟用 multiThreads
7721
		if($conf["info"]["share"]["multiThreads"]==="true"){
7722
 
7723
			#設置 multiThreads flag
7724
			$multiThreads=true;
7725
 
7726
			}#if end
7727
 
261 liveuser 7728
		#另存 server cache 的參考
7729
		$serverCache=&$conf["serverCache"];
7730
 
255 liveuser 7731
		#針對每個 domain name
291 liveuser 7732
		foreach($conf["info"]["share"]["certInfo"] as $certInfoIndex=>$cInfo){
255 liveuser 7733
 
7734
			#取得domain name
7735
			$cName=$cInfo["cName"];
7736
 
261 liveuser 7737
			#如果尚無對應domain name的記錄
7738
			if(!isset($serverCache[$cName])){
7739
 
7740
				#設置最新一次檢測的unixtime
7741
				$serverCache[$cName]["lastCheckUnixTime"]=time();
291 liveuser 7742
 
261 liveuser 7743
				}#if end
7744
 
7745
			#反之距離上次檢查不滿一天
291 liveuser 7746
			else{
261 liveuser 7747
 
291 liveuser 7748
				#計算距離上次檢查多少秒
7749
				$checkedAfter=time()-$serverCache[$cName]["lastCheckUnixTime"];
261 liveuser 7750
 
291 liveuser 7751
				#若距離上次檢查不滿一天
7752
				if($checkedAfter<86400){
7753
 
7754
					#if enable debug
7755
					if($debug){
7756
 
7757
						#debug msg
7758
						echo "Domain name(".$cName.") on zerossl require to check in ".(86400-$checkedAfter)." second(s).".PHP_EOL;
7759
 
7760
						}#if end
7761
 
7762
					#跳過該 domain name 的檢查
7763
					continue;
7764
 
7765
					}#if end
346 liveuser 7766
 
7767
				#反之
7768
				else{
291 liveuser 7769
 
346 liveuser 7770
					#重新設置上次檢查時間為當前時間
7771
					$serverCache[$cName]["lastCheckUnixTime"]=time();
7772
 
7773
					}#else end
7774
 
291 liveuser 7775
				}#else end
261 liveuser 7776
 
281 liveuser 7777
			#if enable debug
7778
			if($debug){
7779
 
7780
				#debug msg
291 liveuser 7781
				echo "Checking domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 7782
 
7783
				}#if end
7784
 
291 liveuser 7785
			#certPath
7786
			#$cInfo["ssl"]["certPath"];
7787
 
7788
			#pKey
7789
			#$cInfo["ssl"]["pKey"];
7790
 
7791
			#caPath
7792
			#$cInfo["ssl"]["caPath"]=;
7793
 
7794
			#certWithCaPath
7795
			#$cInfo["ssl"]["certWithCaPath"];
7796
 
255 liveuser 7797
			#嘗試取得 domain name 對應的可用憑證
7798
			#函式說明:
7799
			#取得在zerossl上的CSR清單
7800
			#回傳結果:
7801
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7802
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
7803
			#$result["function"],當前執行的函式名稱.
7804
			#$result["argu"],所使用的參數.
7805
			#$result["curl_verbose_info"],curl執行的詳細資訊.
7806
			#$result["content"],結果json字串.
7807
			#$result["tCount"],總共的資料筆數.
7808
			#$result["count"],該頁的筆數.
7809
			#$result["page"],當前的頁碼.
7810
			#$result["certs"],陣列,certificates清單,key為certificate的id.
7811
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
7812
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
7813
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
7814
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7815
			#必填參數:
7816
			#無
7817
			#可省略參數:
7818
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 7819
			$conf["zerossl::getCertList"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 7820
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 7821
			$conf["zerossl::getCertList"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 7822
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
7823
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
7824
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
7825
			$conf["zerossl::getCertList"]["cerType"]="single90Days";
7826
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
7827
			$conf["zerossl::getCertList"]["search"]=$cName;
7828
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
7829
			#$conf["limit"]="";
7830
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
7831
			#$conf["page"]="";
7832
			#參考資料:
7833
			#https://zerossl.com/documentation/api/list-certificates/
7834
			#備註:
7835
			#無.
7836
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
7837
			unset($conf["zerossl::getCertList"]);
7838
 
7839
			#符合條件的數量
7840
			#$getCertList["tCount"];
7841
 
7842
			#符合條件的當頁數量
7843
			#$getCertList["count"];
7844
 
7845
			#如果執行異常
7846
			if($getCertList["status"]==="false"){
7847
 
7848
				#設置錯誤識別
7849
				$result["status"]="false";
7850
 
7851
				#設置錯誤訊息
7852
				$result["error"]=$getCertList;
7853
 
7854
				#回傳結果
7855
				return $result;
7856
 
7857
				}#if end
291 liveuser 7858
 
294 liveuser 7859
			#如果有資料
7860
			if($getCertList["count"]>0){
7861
 
7862
				#檢查 common name
7863
				foreach($getCertList["certs"] as $certId=>$certInfo){
7864
 
7865
					#如果 common name 不符合
7866
					if($certInfo["cname"]!==$cName){
7867
 
7868
						#移除之
7869
						unset($getCertList["certs"][$certId]);
7870
 
7871
						#當頁筆數-1
7872
						$getCertList["count"]--;
7873
 
7874
						#總共筆數減少1
7875
						$getCertList["tCount"]--;
7876
 
7877
						}#if end
7878
 
7879
					}#foreach end
7880
 
7881
				}#if end
7882
 
255 liveuser 7883
			#如果沒有憑證
291 liveuser 7884
			if($getCertList["count"]===0){
255 liveuser 7885
 
281 liveuser 7886
				#if enable debug
7887
				if($debug){
7888
 
7889
					#debug msg
291 liveuser 7890
					echo "There is not valid ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 7891
 
7892
					}#if end
7893
 
7894
				#if enable debug
7895
				if($debug){
7896
 
7897
					#debug msg
291 liveuser 7898
					echo "Checking ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7899
 
7900
					}#if end
7901
 
255 liveuser 7902
				#確認有無對應 cName 的 private key
7903
				#函式說明:
7904
				#檢查多個檔案與資料夾是否存在.
7905
				#回傳的結果:
7906
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7907
				#$result["error"],錯誤訊息陣列.
7908
				#$resutl["function"],當前執行的涵式名稱.
7909
				#$result["argu"],使用的參數.
7910
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
7911
				#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
7912
				#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
7913
				#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
7914
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
7915
				#必填參數:
7916
				#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
292 liveuser 7917
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 7918
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7919
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
7920
				#可省略參數:
7921
				#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
7922
				#$conf["disableWebSearch"]="false";
7923
				#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
7924
				$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
7925
				#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
7926
				$conf["fileAccess::checkMultiFileExist"]["web"]="false";
7927
				#參考資料:
7928
				#http://php.net/manual/en/function.file-exists.php
7929
				#http://php.net/manual/en/control-structures.foreach.php
7930
				#備註:
7931
				#函數file_exists檢查的路徑為檔案系統的路徑
7932
				#$result["varName"][$i]結果未實作
7933
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
7934
				unset($conf["fileAccess::checkMultiFileExist"]);
7935
 
7936
				#如果運行異常
7937
				if($checkMultiFileExist["status"]==="false"){
7938
 
7939
					#設置錯誤識別
7940
					$result["status"]="false";
7941
 
7942
					#設置錯誤訊息
7943
					$result["error"]=$getCertList;
7944
 
7945
					#回傳結果
7946
					return $result;
7947
 
7948
					}#if end
7949
 
7950
				#如果沒有 private key
7951
				if($checkMultiFileExist["allExist"]==="false"){
7952
 
281 liveuser 7953
					#if enable debug
7954
					if($debug){
7955
 
7956
						#debug msg
291 liveuser 7957
						echo "there is no ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7958
 
7959
						}#if end
7960
 
7961
					#if enable debug
7962
					if($debug){
7963
 
7964
						#debug msg
291 liveuser 7965
						echo "creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 7966
 
7967
						}#if end
7968
 
255 liveuser 7969
					#建立 private key
7970
					#函式說明:
7971
					#產生ssl private key.
7972
					#回傳結果:
7973
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7974
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
7975
					#$result["function"],當前執行的函式名稱.
7976
					#$result["argu"],所使用的參數.
7977
					#$result["curl_verbose_info"],curl執行的詳細資訊.
7978
					#$result["content"],ssl用的private key.
7979
					#必填參數:
7980
					#$conf["fileArgu"],字串,變數__FILE__的內容.
7981
					$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
7982
					#可省略參數:
7983
					#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
7984
					#$conf["length"]=4096';
7985
					#參考資料:
7986
					#無.
7987
					#備註:
7988
					#key generated by openssl with RSA.
291 liveuser 7989
					$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 7990
					unset($conf["openssl::createPrivateKey"]);
7991
 
7992
					#如果運行異常
7993
					if($createPrivateKey["status"]==="false"){
7994
 
7995
						#設置錯誤識別
7996
						$result["status"]="false";
7997
 
7998
						#設置錯誤訊息
7999
						$result["error"]=$createPrivateKey;
8000
 
8001
						#回傳結果
8002
						return $result;
8003
 
8004
						}#if end
8005
 
8006
					#另存private key的字串
8007
					$pKeyStr=$createPrivateKey["content"];
8008
 
8009
					#建立private key檔案
8010
					#函式說明:
8011
					#將字串寫入到檔案
8012
					#回傳結果:
8013
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
8014
					#$result["error"],錯誤訊息陣列.
8015
					#$result["function"],當前執行的函數名稱.
8016
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
8017
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
8018
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
8019
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
8020
					#$result["argu"],使用的參數.
8021
					#必填參數:
8022
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8023
					$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
8024
					#可省略參數:
8025
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
292 liveuser 8026
					$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 8027
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
8028
					$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
8029
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
8030
					#$conf["writeMethod"]="a";
8031
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
8032
					#$conf["checkRepeat"]="";
8033
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
8034
					#$conf["filenameExtensionStartPoint"]="";
8035
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
8036
					#$conf["repeatNameRule"]="";
8037
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
8038
					$conf["zerossl::writeTextIntoFile"]["web"]="false";
8039
					#參考資料:
8040
					#無.
8041
					#備註:
8042
					#無.
291 liveuser 8043
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
255 liveuser 8044
					unset($conf["zerossl::writeTextIntoFile"]);
8045
 
8046
					#如果運行異常
8047
					if($writeTextIntoFile["status"]==="false"){
8048
 
8049
						#設置錯誤識別
8050
						$result["status"]="false";
8051
 
8052
						#設置錯誤訊息
8053
						$result["error"]=$writeTextIntoFile;
8054
 
8055
						#回傳結果
8056
						return $result;
8057
 
8058
						}#if end
8059
 
8060
					}#if end
8061
 
281 liveuser 8062
				#if enable debug
8063
				if($debug){
8064
 
8065
					#debug msg
291 liveuser 8066
					echo "Creating domain name(".$conf["info"]["share"]["apiDomain"].") csr for zerossl...".PHP_EOL;
281 liveuser 8067
 
8068
					}#if end
8069
 
255 liveuser 8070
				#建立準備給zerossl的csr
8071
				#函式說明:
8072
				#產生certificate sign request(CSR).
8073
				#回傳結果:
8074
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8075
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8076
				#$result["function"],當前執行的函式名稱.
8077
				#$result["argu"],所使用的參數.
8078
				#$result["content"],csr內容.
8079
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8080
				#$result["privateKey"], private key 的內容.
8081
				#必填參數:
8082
				#$conf["domain"],字串,csr內容的網域名稱.
8083
				$conf["zerossl::createCSR"]["domain"]=$cName;
8084
				#可省略參數:
8085
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 8086
				$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 8087
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
8088
				#$conf["country"]="";
8089
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
8090
				#$conf["state"]="";
8091
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
8092
				#$conf["org"]="";
8093
				#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
8094
				#$conf["unit"]="";
8095
				#參考資料:
8096
				#無.
8097
				#備註:
8098
				#無.
8099
				$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
8100
				unset($conf["zerossl::createCSR"]);
8101
 
8102
				#如果運行異常
8103
				if($createCSR["status"]==="false"){
8104
 
8105
					#設置錯誤識別
8106
					$result["status"]="false";
8107
 
8108
					#設置錯誤訊息
8109
					$result["error"]=$createCSR;
8110
 
8111
					#回傳結果
8112
					return $result;
8113
 
8114
					}#if end
8115
 
8116
				#取得本地端產生的csr內容
8117
				$csrLocal=$createCSR["content"];
8118
 
281 liveuser 8119
				#if enable debug
8120
				if($debug){
8121
 
8122
					#debug msg
291 liveuser 8123
					echo "Creating certificate for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 8124
 
8125
					}#if end
8126
 
255 liveuser 8127
				#函式說明:
281 liveuser 8128
				#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 8129
				#回傳結果:
8130
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8131
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8132
				#$result["function"],當前執行的函式名稱.
8133
				#$result["argu"],所使用的參數.
8134
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8135
				#$result["id"],用於zerossl api驗證domain的id.
8136
				#$result["content"],字串,得到的json字串回應.
8137
				#$result["cnameKey"],用於dns CNAME驗證鍵名.
8138
				#$result["cnameVal"],用於dms CNAME驗證鍵值.
8139
				#必填參數:
8140
				#$conf["certificate_domains"],字串,要簽署的doamin名稱.
8141
				$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
8142
				#$conf["certificate_csr"],字串,簽署的資訊.
8143
				$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
8144
				#$conf["fileArgu"],字串,變數__FILE__的內容.
8145
				$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
8146
				#可省略參數:
8147
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 8148
				$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 8149
				#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
8150
				#$conf["path"]=self::getApiInfo()["csrPath"];
8151
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 8152
				$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 8153
				#參考資料:
8154
				#無.
8155
				#備註:
8156
				#無.
8157
				$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
8158
				unset($conf["zerossl::createCertificate"]);
8159
 
8160
				#如果執行異常
8161
				if($createCertificate["status"]==="false"){
8162
 
8163
					#設置錯誤識別
8164
					$result["status"]="false";
8165
 
8166
					#設置錯誤訊息
8167
					$result["error"]=$createCertificate;
8168
 
8169
					#回傳結果
8170
					return $result;
8171
 
8172
					}#if end
8173
 
8174
				#取得csr在zerossl上的id
8175
				$csrId=$createCertificate["id"];
8176
 
8177
				#取得cname key
8178
				$cNameKey=$createCertificate["cnameKey"];
8179
 
8180
				#取得cname val
8181
				$cNameVal=$createCertificate["cnameVal"];
8182
 
8183
				#初始化要增加的RR記錄
8184
				$rr2add=array();
8185
 
8186
				#設置CNAME的查詢
8187
				$rr2add["query"]=$cNameKey;
8188
 
8189
				#設置CNAME的value
8190
				$rr2add["value"]=$cNameVal;
8191
 
8192
				#設置類型為 CNAME
8193
				$rr2add["type"]="CNAME";
8194
 
8195
				#設置註解
8196
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
8197
 
281 liveuser 8198
				#if enable debug
8199
				if($debug){
8200
 
8201
					#debug msg
291 liveuser 8202
					echo "Adding DNS record to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8203
 
8204
					}#if end
8205
 
255 liveuser 8206
				#函式說明:
8207
				#新增DNS記錄到檔案裡面.
8208
				#回傳結果:
8209
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8210
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8211
				#$result["function"],當前執行的函式名稱.
8212
				#$result["argu"],所使用的參數.
8213
				#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
8214
				#$result["domain"],字串,RR所屬domain.
8215
				#$result["defaultTTL"],字串,預設的RR更新時間.
8216
				#$result["comment"],字串陣列,逐行的註解.
8217
				#必填參數:
8218
				#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
291 liveuser 8219
				$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 8220
				#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
8221
				$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
8222
				#可省略參數:
8223
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
8224
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
8225
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
8226
				#$conf["debug"]="false";
293 liveuser 8227
 
8228
				#如果有啟用多執行序
8229
				if($conf["info"]["share"]["multiThreads"]==="true"){
8230
 
8231
					#設置要多執行序
8232
					$conf["zerossl::updateDnsRecordFile"]["multiThreads"]="true";
8233
 
8234
					}#if end
8235
 
255 liveuser 8236
				#參考資料:
8237
				#無.
8238
				#備註:
8239
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
8240
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
8241
				#php-pear上的Net_DNS2也可以解析RR.
8242
				$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
8243
				unset($conf["zerossl::updateDnsRecordFile"]);
8244
 
8245
				#如果執行異常
8246
				if($updateDnsRecordFile["status"]==="false"){
8247
 
8248
					#設置錯誤識別
8249
					$result["status"]="false";
8250
 
8251
					#設置錯誤訊息
8252
					$result["error"]=$updateDnsRecordFile;
8253
 
8254
					#回傳結果
8255
					return $result;
8256
 
8257
					}#if end
281 liveuser 8258
 
8259
				#if enable debug
8260
				if($debug){
8261
 
8262
					#debug msg
291 liveuser 8263
					echo "Restart DNS service to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8264
 
8265
					}#if end
8266
 
255 liveuser 8267
				#重新啟動dns伺服器
8268
				#函式說明:
8269
				#呼叫shell執行系統命令,並取得回傳的內容.
8270
				#回傳結果:
8271
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8272
				#$result["error"],錯誤訊息陣列.
8273
				#$result["function"],當前執行的函數名稱.
8274
				#$result["argu"],使用的參數.
8275
				#$result["cmd"],執行的指令內容.
8276
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8277
				#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8278
				#$result["content"],為執行完後的輸出字串.
8279
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8280
				#$result["running"],是否還在執行.
8281
				#$result["pid"],pid.
8282
				#$result["statusCode"],執行結束後的代碼.
8283
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8284
				#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8285
				#必填參數:
8286
				#$conf["command"],字串,要執行的指令.
291 liveuser 8287
				$conf["external::callShell"]["command"]="systemctl";
255 liveuser 8288
				#$conf["fileArgu"],字串,變數__FILE__的內容.
8289
				$conf["external::callShell"]["fileArgu"]=__FILE__;
8290
				#可省略參數:
8291
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8292
				$conf["external::callShell"]["argu"]=array("restart","named");
8293
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8294
				#$conf["arguIsAddr"]=array();
8295
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8296
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8297
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8298
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8299
				#$conf["enablePrintDescription"]="true";
8300
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8301
				#$conf["printDescription"]="";
8302
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8303
				#$conf["escapeshellarg"]="false";
8304
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8305
				#$conf["thereIsShellVar"]=array();
8306
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8307
				#$conf["username"]="";
8308
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8309
				#$conf["password"]="";
8310
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8311
				#$conf["useScript"]="";
8312
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8313
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8314
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8315
				#$conf["inBackGround"]="";
8316
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8317
				#$conf["getErr"]="false";
8318
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8319
				#$conf["doNotRun"]="false";
8320
				#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8321
				$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
8322
				#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8323
				#$conf["remoteUser"]="root";
8324
				#參考資料:
8325
				#exec=>http://php.net/manual/en/function.exec.php
8326
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8327
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8328
				#備註:
8329
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8330
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8331
				$callShell=external::callShell($conf["external::callShell"]);
8332
				unset($conf["external::callShell"]);
8333
 
8334
				#如果執行異常
8335
				if($callShell["status"]==="false"){
8336
 
8337
					#設置錯誤識別
8338
					$result["status"]="false";
8339
 
8340
					#設置錯誤訊息
8341
					$result["error"]=$callShell;
8342
 
8343
					#回傳結果
8344
					return $result;
8345
 
8346
					}#if end
281 liveuser 8347
 
8348
				#if enable debug
8349
				if($debug){
8350
 
8351
					#debug msg
291 liveuser 8352
					echo "Request zerossl to validate certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8353
 
8354
					}#if end
8355
 
292 liveuser 8356
				#無窮迴圈
8357
				while(true){
255 liveuser 8358
 
292 liveuser 8359
					#函式說明:
8360
					#請求驗證已經透過zerossl::createCertificate要求的domain.
8361
					#回傳結果:
8362
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8363
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8364
					#$result["function"],當前執行的函式名稱.
8365
					#$result["argu"],所使用的參數.
8366
					#$result["curl_verbose_info"],curl執行的詳細資訊.
8367
					#$result["content"],結果json字串.
8368
					#必填參數:
8369
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
8370
					$conf["zerossl::verifyDomain"]["id"]=$csrId;
8371
					#可省略參數:
8372
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8373
					$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
8374
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8375
					$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
8376
					#參考資料:
8377
					#https://zerossl.com/documentation/api/verify-domains/
8378
					#備註:
8379
					#無.
8380
					$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
8381
					unset($conf["zerossl::verifyDomain"]);
291 liveuser 8382
 
292 liveuser 8383
					#如果執行異常
8384
					if($verifyDomain["status"]==="false"){
8385
 
8386
						#設置錯誤識別
8387
						$result["status"]="false";
291 liveuser 8388
 
292 liveuser 8389
						#設置錯誤訊息
8390
						$result["error"]=$verifyDomain;
291 liveuser 8391
 
292 liveuser 8392
						#回傳結果
8393
						return $result;
291 liveuser 8394
 
8395
						}#if end
8396
 
292 liveuser 8397
					#如果沒有回內容
293 liveuser 8398
					if(!isset($verifyDomain["content"])){
292 liveuser 8399
 
8400
						#設置錯誤識別
8401
						$result["status"]="false";
291 liveuser 8402
 
292 liveuser 8403
						#設置錯誤訊息
8404
						$result["error"]=$verifyDomain;
291 liveuser 8405
 
292 liveuser 8406
						#回傳結果
8407
						return $result;
8408
 
8409
						}#if end
8410
 
8411
					#如果回應不是 json
293 liveuser 8412
					if(!(json_validate($verifyDomain["content"]))){
292 liveuser 8413
 
8414
						#設置錯誤識別
8415
						$result["status"]="false";
291 liveuser 8416
 
292 liveuser 8417
						#設置錯誤訊息
8418
						$result["error"]=$verifyDomain;
291 liveuser 8419
 
292 liveuser 8420
						#回傳結果
8421
						return $result;
8422
 
8423
						}#if end
8424
 
294 liveuser 8425
					#if enable debug
8426
					if($debug){
8427
 
8428
						#debug msg
8429
						echo "Response of validating certificate for domain name(".$cName.") on zerossl".PHP_EOL;
8430
 
8431
						#debug msg
8432
						var_dump(__LINE__,$verifyDomain);
8433
 
8434
						}#if end
8435
 
292 liveuser 8436
					/*
8437
					範例json:
8438
					{"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}
8439
					*/
8440
 
8441
					#解析json回應
293 liveuser 8442
					$verifyDomainRes=json_decode($verifyDomain["content"]);
291 liveuser 8443
 
293 liveuser 8444
					#如果回應含有 success
8445
					if(isset($verifyDomainRes->success)){
292 liveuser 8446
 
293 liveuser 8447
						#如果是 zerossl 驗證失敗
294 liveuser 8448
						if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
291 liveuser 8449
 
293 liveuser 8450
							#如果是 CNAME 記錄找不到
8451
							if($verifyDomainRes->error->code===0){
291 liveuser 8452
 
293 liveuser 8453
								#取得錯誤訊息
8454
								#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
8455
 
8456
								#if enable debug
8457
								if($debug){
8458
 
8459
									#debug msg
8460
									echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
8461
 
8462
									}#if end
8463
 
8464
								#if enable debug
8465
								if($debug){
8466
 
8467
									#debug msg
8468
									echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
8469
 
8470
									}#if end
8471
 
8472
								#休息60秒
8473
								sleep(60);
294 liveuser 8474
 
8475
								#再跑一次要求認證
8476
								continue;
291 liveuser 8477
 
8478
								}#if end
293 liveuser 8479
 
8480
							#反之為不接受的錯誤訊息
8481
							else{
291 liveuser 8482
 
293 liveuser 8483
								#設置錯誤識別
8484
								$result["status"]="false";
8485
 
8486
								#設置錯誤訊息
8487
								$result["error"]=$verifyDomain;
8488
 
8489
								#回傳結果
8490
								return $result;
291 liveuser 8491
 
293 liveuser 8492
								}#else end
291 liveuser 8493
 
8494
							}#if end
292 liveuser 8495
 
8496
						}#if end
293 liveuser 8497
 
8498
					#反之如果回應含有 status
8499
					else if(isset($verifyDomainRes->status)){
292 liveuser 8500
 
293 liveuser 8501
						#如果是 zerossl 尚在驗證中
8502
						if($verifyDomainRes->status==="pending_validation"){
292 liveuser 8503
 
293 liveuser 8504
							#if enable debug
8505
							if($debug){
292 liveuser 8506
 
293 liveuser 8507
								#debug msg
8508
								echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
292 liveuser 8509
 
8510
								}#if end
8511
 
293 liveuser 8512
							#無窮迴圈
8513
							while(true){
8514
 
8515
								#查詢驗證狀況
8516
								#函式說明:
8517
								#取得CSR在zerossl上的狀態
8518
								#回傳結果:
8519
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8520
								#$reuslt["error"],執行不正常結束的錯訊息陣列.
8521
								#$result["function"],當前執行的函式名稱.
8522
								#$result["argu"],所使用的參數.
8523
								#$result["curl_verbose_info"],curl執行的詳細資訊.
8524
								#$result["content"],結果json字串.
8525
								#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
8526
								#必填參數:
8527
								#$conf["id"],字串,zerossl::createCertificate回傳的id.
8528
								$conf["zerossl::getCertSta"]["id"]=$csrId;
8529
								#可省略參數:
8530
								#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8531
								$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
8532
								#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8533
								$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
8534
								#參考資料:
8535
								#https://zerossl.com/documentation/api/get-certificate/
8536
								#備註:
8537
								#無.
8538
								$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
8539
								unset($conf["zerossl::getCertSta"]);
8540
 
8541
								#如果執行異常
8542
								if($getCertSta["status"]==="false"){
8543
 
8544
									#設置錯誤識別
8545
									$result["status"]="false";
292 liveuser 8546
 
293 liveuser 8547
									#設置錯誤訊息
8548
									$result["error"]=$getCertSta;
292 liveuser 8549
 
293 liveuser 8550
									#回傳結果
8551
									return $result;
292 liveuser 8552
 
293 liveuser 8553
									}#if end
8554
 
8555
								#如果沒有回應內容
8556
								if(!isset($getCertSta["content"])){
8557
 
8558
									#設置錯誤識別
8559
									$result["status"]="false";
292 liveuser 8560
 
293 liveuser 8561
									#設置錯誤訊息
8562
									$result["error"]=$getCertSta;
292 liveuser 8563
 
293 liveuser 8564
									#回傳結果
8565
									return $result;
292 liveuser 8566
 
293 liveuser 8567
									}#if end
8568
 
8569
								#如果回應不是 json
8570
								if(!(json_validate($getCertSta["content"]))){
292 liveuser 8571
 
293 liveuser 8572
									#設置錯誤識別
8573
									$result["status"]="false";
8574
 
8575
									#設置錯誤訊息
8576
									$result["error"]=$getCertSta;
8577
 
8578
									#回傳結果
8579
									return $result;
292 liveuser 8580
 
8581
									}#if end
293 liveuser 8582
 
8583
								#解析json回應
8584
								$getCertStaRes=json_decode($getCertSta["content"]);
292 liveuser 8585
 
293 liveuser 8586
								#如果憑證已經驗證通過了
8587
								if($getCertStaRes->status==="issued"){
292 liveuser 8588
 
293 liveuser 8589
									#if enable debug
8590
									if($debug){
8591
 
8592
										#debug msg
8593
										echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
8594
 
8595
										}#if end
292 liveuser 8596
 
294 liveuser 8597
									#結束等待,跳出 while
293 liveuser 8598
									break 2;
8599
 
292 liveuser 8600
									}#if end
8601
 
293 liveuser 8602
								#如果 zerossl 尚在處理中
8603
								else if($getCertStaRes->status==="pending_validation"){
292 liveuser 8604
 
293 liveuser 8605
									#if enable debug
8606
									if($debug){
8607
 
8608
										#debug msg
8609
										echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
8610
 
8611
										}#if end
8612
 
8613
									#休息1分鐘
8614
									sleep(60);
294 liveuser 8615
 
8616
									#再跑一次取得憑證狀態
8617
									continue;
293 liveuser 8618
 
8619
									}#if end
8620
 
8621
								#反之
8622
								else{
8623
 
8624
									#例外狀況
8625
 
8626
									#設置錯誤識別
8627
									$result["status"]="false";
292 liveuser 8628
 
293 liveuser 8629
									#設置錯誤訊息
8630
									$result["error"]=$getCertSta;
292 liveuser 8631
 
293 liveuser 8632
									#回傳結果
8633
									return $result;
8634
 
8635
									}#else end
292 liveuser 8636
 
293 liveuser 8637
								}#while end
8638
 
8639
							}#if end
8640
 
292 liveuser 8641
						}#if end
294 liveuser 8642
 
8643
					#反之.不應該執行到這邊
8644
					else{
8645
 
8646
						#設置錯誤識別
8647
						$result["status"]="false";
8648
 
8649
						#設置錯誤訊息
8650
						$result["error"]=$verifyDomain;
8651
 
8652
						#回傳結果
8653
						return $result;
8654
 
8655
						}#else 	
291 liveuser 8656
 
292 liveuser 8657
					}#while end
294 liveuser 8658
 
281 liveuser 8659
				#if enable debug
8660
				if($debug){
8661
 
8662
					#debug msg
291 liveuser 8663
					echo "Downloading certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8664
 
8665
					}#if end
8666
 
255 liveuser 8667
				#函式說明:
8668
				#下載certificate.
8669
				#回傳結果:
8670
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8671
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
8672
				#$result["function"],當前執行的函式名稱.
8673
				#$result["argu"],所使用的參數.
8674
				#$result["curl_verbose_info"],curl執行的詳細資訊.
8675
				#$result["content"],結果json字串.
8676
				#$result["certificate.crt"],字串,certificate.crt的內容.
8677
				#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
8678
				#必填參數:
8679
				#無.
8680
				#可省略參數:
8681
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 8682
				$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 8683
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 8684
				$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 8685
				#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
8686
				$conf["zerossl::getCert"]["id"]=$csrId;
8687
				#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
8688
				#$conf["zerossl::getCert"]["cname"]="";
8689
				#參考資料:
8690
				#https://zerossl.com/documentation/api/download-certificate-inline/
8691
				#備註:
8692
				#無.
8693
				$getCert=zerossl::getCert($conf["zerossl::getCert"]);
8694
				unset($conf["zerossl::getCert"]);
8695
 
8696
				#如果執行異常
8697
				if($getCert["status"]==="false"){
8698
 
8699
					#設置錯誤識別
8700
					$result["status"]="false";
8701
 
8702
					#設置錯誤訊息
8703
					$result["error"]=$getCert;
8704
 
8705
					#回傳結果
8706
					return $result;
8707
 
8708
					}#if end
281 liveuser 8709
 
8710
				#if enable debug
8711
				if($debug){
8712
 
8713
					#debug msg
291 liveuser 8714
					echo "Creating certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8715
 
8716
					}#if end
8717
 
293 liveuser 8718
				#certPath
8719
				#$cInfo["ssl"]["certPath"];
255 liveuser 8720
 
293 liveuser 8721
				#pKey
8722
				#$cInfo["ssl"]["pKey"];
255 liveuser 8723
 
293 liveuser 8724
				#caPath
8725
				#$cInfo["ssl"]["caPath"]=;
255 liveuser 8726
 
293 liveuser 8727
				#certWithCaPath
8728
				#$cInfo["ssl"]["certWithCaPath"];
8729
 
255 liveuser 8730
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
8731
				#函式說明:
8732
				#一次建立多個檔案,並寫入內容.
8733
				#回傳結果:
8734
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
8735
				#$result["error"],錯誤訊息陣列.
8736
				#$result["function"],當前執行的函數名稱.
8737
				#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
8738
				#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
8739
				#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
8740
				#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
8741
				#$result["argu"],使用的參數.
8742
				#必填參數:
8743
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8744
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
8745
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
293 liveuser 8746
				$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 8747
				#可省略參數:
8748
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
8749
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
8750
				#參考資料:
8751
				#無.
8752
				#備註:
8753
				#無.
293 liveuser 8754
				$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 8755
				unset($conf["zerossl::writeMultiFile"]);
8756
 
8757
				#如果執行異常
8758
				if($writeMultiFile["status"]==="false"){
8759
 
8760
					#設置錯誤識別
8761
					$result["status"]="false";
8762
 
8763
					#設置錯誤訊息
8764
					$result["error"]=$writeMultiFile;
8765
 
8766
					#回傳結果
8767
					return $result;
8768
 
8769
					}#if end
8770
 
8771
				#儲存 actionAfterUpdateCert
8772
				$action=$cInfo["actionAfterUpdateCert"];
8773
 
8774
				#如果有多個指令要執行
294 liveuser 8775
				if(count($action)>1){
255 liveuser 8776
 
281 liveuser 8777
					#if enable debug
8778
					if($debug){
8779
 
8780
						#debug msg
291 liveuser 8781
						echo "There are many cmds to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8782
 
8783
						}#if end
8784
 
8785
					#if enable debug
8786
					if($debug){
8787
 
8788
						#debug msg
291 liveuser 8789
						echo "Running cmd to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8790
 
8791
						}#if end
8792
 
255 liveuser 8793
					#針對每的指令
8794
					foreach($action as $ac){
8795
 
281 liveuser 8796
						#if enable debug
8797
						if($debug){
8798
 
8799
							#debug msg
8800
							echo ".".PHP_EOL;
8801
 
8802
							}#if end
8803
 
255 liveuser 8804
						#函式說明:
8805
						#呼叫shell執行系統命令,並取得回傳的內容.
8806
						#回傳結果:
8807
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8808
						#$result["error"],錯誤訊息陣列.
8809
						#$result["function"],當前執行的函數名稱.
8810
						#$result["argu"],使用的參數.
8811
						#$result["cmd"],執行的指令內容.
8812
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8813
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8814
						#$result["content"],為執行完後的輸出字串.
8815
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8816
						#$result["running"],是否還在執行.
8817
						#$result["pid"],pid.
8818
						#$result["statusCode"],執行結束後的代碼.
8819
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8820
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8821
						#必填參數:
8822
						#$conf["command"],字串,要執行的指令.
294 liveuser 8823
						$conf["external::callShell"]["command"]=$ac;
255 liveuser 8824
						#$conf["fileArgu"],字串,變數__FILE__的內容.
8825
						$conf["external::callShell"]["fileArgu"]=__FILE__;
8826
						#可省略參數:
8827
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
294 liveuser 8828
						#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 8829
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8830
						#$conf["arguIsAddr"]=array();
8831
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8832
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8833
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8834
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8835
						#$conf["enablePrintDescription"]="true";
8836
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8837
						#$conf["printDescription"]="";
8838
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8839
						$conf["external::callShell"]["escapeshellarg"]="true";
8840
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8841
						#$conf["thereIsShellVar"]=array();
8842
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8843
						#$conf["username"]="";
8844
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8845
						#$conf["password"]="";
8846
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8847
						#$conf["useScript"]="";
8848
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8849
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8850
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8851
						#$conf["inBackGround"]="";
8852
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8853
						#$conf["getErr"]="false";
294 liveuser 8854
						#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
8855
						$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 8856
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8857
						#$conf["doNotRun"]="false";
8858
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8859
						#$conf["remoteIp"]="";
8860
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8861
						#$conf["remoteUser"]="";
8862
						#參考資料:
8863
						#exec=>http://php.net/manual/en/function.exec.php
8864
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8865
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8866
						#備註:
8867
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8868
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8869
						$callShell=external::callShell($conf["external::callShell"]);
8870
						unset($conf["external::callShell"]);
8871
 
8872
						#如果執行異常
294 liveuser 8873
						if($callShell["status"]==="false"){
255 liveuser 8874
 
8875
							#設置錯誤識別
8876
							$result["status"]="false";
8877
 
8878
							#設置錯誤訊息
8879
							$result["error"]=$callShell;
8880
 
8881
							#回傳結果
8882
							return $result;
8883
 
8884
							}#if end
8885
 
8886
						}#foreach end
8887
 
8888
					}#if end
8889
 
8890
				#反之
8891
				else{
8892
 
281 liveuser 8893
					#if enable debug
8894
					if($debug){
8895
 
8896
						#debug msg
291 liveuser 8897
						echo "There is only one cmd to run to apply certificate for domain name(".$cName.")".PHP_EOL;
281 liveuser 8898
 
8899
						}#if end
8900
 
8901
					#if enable debug
8902
					if($debug){
8903
 
8904
						#debug msg
8905
						echo ".".PHP_EOL;
8906
 
8907
						}#if end
8908
 
255 liveuser 8909
					#函式說明:
8910
					#呼叫shell執行系統命令,並取得回傳的內容.
8911
					#回傳結果:
8912
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8913
					#$result["error"],錯誤訊息陣列.
8914
					#$result["function"],當前執行的函數名稱.
8915
					#$result["argu"],使用的參數.
8916
					#$result["cmd"],執行的指令內容.
8917
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8918
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8919
					#$result["content"],為執行完後的輸出字串.
8920
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8921
					#$result["running"],是否還在執行.
8922
					#$result["pid"],pid.
8923
					#$result["statusCode"],執行結束後的代碼.
8924
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8925
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8926
					#必填參數:
8927
					#$conf["command"],字串,要執行的指令.
302 liveuser 8928
					$conf["external::callShell"]["command"]=$action[0];
255 liveuser 8929
					#$conf["fileArgu"],字串,變數__FILE__的內容.
8930
					$conf["external::callShell"]["fileArgu"]=__FILE__;
8931
					#可省略參數:
8932
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 8933
					#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 8934
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8935
					#$conf["arguIsAddr"]=array();
8936
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8937
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8938
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8939
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8940
					#$conf["enablePrintDescription"]="true";
8941
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8942
					#$conf["printDescription"]="";
8943
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8944
					$conf["external::callShell"]["escapeshellarg"]="true";
8945
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8946
					#$conf["thereIsShellVar"]=array();
8947
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8948
					#$conf["username"]="";
8949
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8950
					#$conf["password"]="";
8951
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8952
					#$conf["useScript"]="";
8953
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8954
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8955
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8956
					#$conf["inBackGround"]="";
8957
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8958
					#$conf["getErr"]="false";
8959
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8960
					#$conf["doNotRun"]="false";
294 liveuser 8961
					#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
8962
					$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 8963
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8964
					#$conf["remoteIp"]="";
8965
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8966
					#$conf["remoteUser"]="";
8967
					#參考資料:
8968
					#exec=>http://php.net/manual/en/function.exec.php
8969
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8970
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8971
					#備註:
8972
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8973
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8974
					$callShell=external::callShell($conf["external::callShell"]);
8975
					unset($conf["external::callShell"]);
294 liveuser 8976
 
255 liveuser 8977
					#如果執行異常
294 liveuser 8978
					if($callShell["status"]==="false"){
255 liveuser 8979
 
8980
						#設置錯誤識別
8981
						$result["status"]="false";
8982
 
8983
						#設置錯誤訊息
8984
						$result["error"]=$callShell;
8985
 
8986
						#回傳結果
8987
						return $result;
8988
 
8989
						}#if end
8990
 
8991
					}#else end
8992
 
8993
				}#if end
8994
 
8995
			#反之
8996
			else{
8997
 
281 liveuser 8998
				#if enable debug
8999
				if($debug){
9000
 
9001
					#debug msg
291 liveuser 9002
					echo "There is already valid ssl for domain name(".$cName.") on zerossl".PHP_EOL;
281 liveuser 9003
 
9004
					}#if end
9005
 
291 liveuser 9006
				#debug
9007
				#var_dump(__LINE__,$getCertList);
9008
 
255 liveuser 9009
				#有 issued 的憑證
9010
 
291 liveuser 9011
				#if enable debug
9012
				if($debug){
9013
 
9014
					#debug msg
9015
					echo "Downloading ssl for domain name(".$cName.") on zerossl".PHP_EOL;
9016
 
9017
					}#if end
9018
 
255 liveuser 9019
				#取得 certificate id at zerossl
9020
				#函式說明:
9021
				#將陣列轉換成存有key與value的陣列
9022
				#回傳的結果:
9023
				#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
9024
				#$result["function"],當前執行的函數
9025
				#$result["error"],錯誤訊息.
9026
				#$result[$i]["key"],原先$i+1個元素的key.
9027
				#$result[$i]["value"],原先$i+1個元素的value.
9028
				#必填參數:
9029
				#$conf["rawInputArray"],陣列,要轉換的陣列變數.
9030
				$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
9031
				#可省略參數:
9032
				#無.
9033
				#參考資料:
9034
				#無.
9035
				#備註:
9036
				#無.
9037
				$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
9038
				unset($conf["arrays::getKeyAndValue"]);
9039
 
9040
				#如果執行異常
9041
				if($getKeyAndValue["status"]==="false"){
9042
 
9043
					#設置錯誤識別
9044
					$result["status"]="false";
9045
 
9046
					#設置錯誤訊息
9047
					$result["error"]=$getKeyAndValue;
9048
 
9049
					#回傳結果
9050
					return $result;
9051
 
9052
					}#if end
9053
 
291 liveuser 9054
				#debug
9055
				#var_dump($getKeyAndValue);exit;
9056
 
255 liveuser 9057
				#儲存 certificate id at zerossl
291 liveuser 9058
				$csrId=$getKeyAndValue[1]["key"];
255 liveuser 9059
 
9060
				#檢查憑證是否已經快過期
9061
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
9062
 
9063
				#如果距離當下不到2個星期就要過期
9064
				if($expiresIn<=86400*14){
291 liveuser 9065
 
281 liveuser 9066
					#if enable debug
9067
					if($debug){
9068
 
9069
						#debug msg
291 liveuser 9070
						echo "Valid ssl for domain name(".$cName.") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
281 liveuser 9071
 
9072
						}#if end
9073
 
291 liveuser 9074
					#debug
9075
					#var_dump($expiresIn);exit;
9076
 
255 liveuser 9077
					#另存舊的憑證id,最後要revoke之.
9078
					$oldCsrId=$csrId;
9079
 
281 liveuser 9080
					#if enable debug
9081
					if($debug){
9082
 
9083
						#debug msg
294 liveuser 9084
						echo "Start request new ssl process for domain name(".$cName.").".PHP_EOL;
281 liveuser 9085
 
9086
						}#if end
9087
 
9088
					#if enable debug
9089
					if($debug){
9090
 
9091
						#debug msg
291 liveuser 9092
						echo "Finding ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9093
 
9094
						}#if end
9095
 
255 liveuser 9096
					#確認有無對應 cName 的 private key
9097
					#函式說明:
9098
					#檢查多個檔案與資料夾是否存在.
9099
					#回傳的結果:
9100
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9101
					#$result["error"],錯誤訊息陣列.
9102
					#$resutl["function"],當前執行的涵式名稱.
9103
					#$result["argu"],使用的參數.
9104
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9105
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9106
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
9107
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
9108
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9109
					#必填參數:
9110
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
291 liveuser 9111
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
255 liveuser 9112
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9113
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
9114
					#可省略參數:
9115
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9116
					#$conf["disableWebSearch"]="false";
9117
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9118
					$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
9119
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
9120
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
9121
					#參考資料:
9122
					#http://php.net/manual/en/function.file-exists.php
9123
					#http://php.net/manual/en/control-structures.foreach.php
9124
					#備註:
9125
					#函數file_exists檢查的路徑為檔案系統的路徑
9126
					#$result["varName"][$i]結果未實作
9127
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9128
					unset($conf["fileAccess::checkMultiFileExist"]);
9129
 
9130
					#如果運行異常
9131
					if($checkMultiFileExist["status"]==="false"){
9132
 
9133
						#設置錯誤識別
9134
						$result["status"]="false";
9135
 
9136
						#設置錯誤訊息
9137
						$result["error"]=$getCertList;
9138
 
9139
						#回傳結果
9140
						return $result;
9141
 
9142
						}#if end
9143
 
9144
					#如果沒有 private key
9145
					if($checkMultiFileExist["allExist"]==="false"){
9146
 
281 liveuser 9147
						#if enable debug
9148
						if($debug){
9149
 
9150
							#debug msg
291 liveuser 9151
							echo "Thers is no ssl private key for domain name(".$cName.").".PHP_EOL;
281 liveuser 9152
 
9153
							}#if end
9154
 
9155
						#if enable debug
9156
						if($debug){
9157
 
9158
							#debug msg
291 liveuser 9159
							echo "Creating ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9160
 
9161
							}#if end
9162
 
255 liveuser 9163
						#建立 private key
9164
						#函式說明:
9165
						#產生ssl private key.
9166
						#回傳結果:
9167
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9168
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
9169
						#$result["function"],當前執行的函式名稱.
9170
						#$result["argu"],所使用的參數.
9171
						#$result["curl_verbose_info"],curl執行的詳細資訊.
9172
						#$result["content"],ssl用的private key.
9173
						#必填參數:
9174
						#$conf["fileArgu"],字串,變數__FILE__的內容.
9175
						$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
9176
						#可省略參數:
9177
						#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
9178
						#$conf["length"]=4096';
9179
						#參考資料:
9180
						#無.
9181
						#備註:
9182
						#key generated by openssl with RSA.
291 liveuser 9183
						$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
255 liveuser 9184
						unset($conf["openssl::createPrivateKey"]);
9185
 
9186
						#如果運行異常
9187
						if($createPrivateKey["status"]==="false"){
9188
 
9189
							#設置錯誤識別
9190
							$result["status"]="false";
9191
 
9192
							#設置錯誤訊息
9193
							$result["error"]=$createPrivateKey;
9194
 
9195
							#回傳結果
9196
							return $result;
9197
 
9198
							}#if end
9199
 
9200
						#另存private key的字串
9201
						$pKeyStr=$createPrivateKey["content"];
9202
 
281 liveuser 9203
						#if enable debug
9204
						if($debug){
9205
 
9206
							#debug msg
291 liveuser 9207
							echo "Writing ssl private key for domain name(".$cName.")...".PHP_EOL;
281 liveuser 9208
 
9209
							}#if end
9210
 
255 liveuser 9211
						#建立private key檔案
9212
						#函式說明:
9213
						#將字串寫入到檔案
9214
						#回傳結果:
9215
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9216
						#$result["error"],錯誤訊息陣列.
9217
						#$result["function"],當前執行的函數名稱.
9218
						#$result["fileInfo"],實際上寫入的檔案資訊陣列.
9219
						#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
9220
						#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
9221
						#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
9222
						#$result["argu"],使用的參數.
9223
						#必填參數:
9224
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9225
						$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
9226
						#可省略參數:
9227
						#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
291 liveuser 9228
						$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
255 liveuser 9229
						#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
9230
						$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
9231
						#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
9232
						#$conf["writeMethod"]="a";
9233
						#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
9234
						#$conf["checkRepeat"]="";
9235
						#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
9236
						#$conf["filenameExtensionStartPoint"]="";
9237
						#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
9238
						#$conf["repeatNameRule"]="";
9239
						#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
9240
						$conf["zerossl::writeTextIntoFile"]["web"]="false";
9241
						#參考資料:
9242
						#無.
9243
						#備註:
9244
						#無.
9245
						$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
9246
						unset($conf["zerossl::writeTextIntoFile"]);
9247
 
9248
						#如果運行異常
9249
						if($writeTextIntoFile["status"]==="false"){
9250
 
9251
							#設置錯誤識別
9252
							$result["status"]="false";
9253
 
9254
							#設置錯誤訊息
9255
							$result["error"]=$writeTextIntoFile;
9256
 
9257
							#回傳結果
9258
							return $result;
9259
 
9260
							}#if end
9261
 
9262
						}#if end
9263
 
281 liveuser 9264
					#if enable debug
9265
					if($debug){
9266
 
9267
						#debug msg
291 liveuser 9268
						echo "Creating CSR for domain name(".$cName.") to zerossl.".PHP_EOL;
281 liveuser 9269
 
9270
						}#if end
9271
 
255 liveuser 9272
					#建立準備給zerossl的csr
9273
					#函式說明:
9274
					#產生certificate sign request(CSR).
9275
					#回傳結果:
9276
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9277
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9278
					#$result["function"],當前執行的函式名稱.
9279
					#$result["argu"],所使用的參數.
9280
					#$result["content"],csr內容.
9281
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9282
					#$result["privateKey"], private key 的內容.
9283
					#必填參數:
9284
					#$conf["domain"],字串,csr內容的網域名稱.
9285
					$conf["zerossl::createCSR"]["domain"]=$cName;
9286
					#可省略參數:
9287
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
293 liveuser 9288
					$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
255 liveuser 9289
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
9290
					#$conf["country"]="";
9291
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
9292
					#$conf["state"]="";
9293
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
9294
					#$conf["org"]="";
9295
					#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
9296
					#$conf["unit"]="";
9297
					#參考資料:
9298
					#無.
9299
					#備註:
9300
					#無.
9301
					$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
9302
					unset($conf["zerossl::createCSR"]);
9303
 
9304
					#如果運行異常
9305
					if($createCSR["status"]==="false"){
9306
 
9307
						#設置錯誤識別
9308
						$result["status"]="false";
9309
 
9310
						#設置錯誤訊息
9311
						$result["error"]=$createCSR;
9312
 
9313
						#回傳結果
9314
						return $result;
9315
 
9316
						}#if end
9317
 
9318
					#取得本地端產生的csr內容
9319
					$csrLocal=$createCSR["content"];
9320
 
281 liveuser 9321
					#if enable debug
9322
					if($debug){
9323
 
9324
						#debug msg
291 liveuser 9325
						echo "Providing CSR for domain name(".$cName.") to zerossl".PHP_EOL;
281 liveuser 9326
 
9327
						}#if end
9328
 
255 liveuser 9329
					#函式說明:
281 liveuser 9330
					#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 9331
					#回傳結果:
9332
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9333
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9334
					#$result["function"],當前執行的函式名稱.
9335
					#$result["argu"],所使用的參數.
9336
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9337
					#$result["id"],用於zerossl api驗證domain的id.
9338
					#$result["content"],字串,得到的json字串回應.
9339
					#$result["cnameKey"],用於dns CNAME驗證鍵名.
9340
					#$result["cnameVal"],用於dms CNAME驗證鍵值.
9341
					#必填參數:
9342
					#$conf["certificate_domains"],字串,要簽署的doamin名稱.
9343
					$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
9344
					#$conf["certificate_csr"],字串,簽署的資訊.
9345
					$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
9346
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9347
					$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
9348
					#可省略參數:
9349
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9350
					$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9351
					#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
9352
					#$conf["path"]=self::getApiInfo()["csrPath"];
9353
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9354
					$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9355
					#參考資料:
9356
					#無.
9357
					#備註:
9358
					#無.
9359
					$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
9360
					unset($conf["zerossl::createCertificate"]);
9361
 
9362
					#如果執行異常
9363
					if($createCertificate["status"]==="false"){
9364
 
9365
						#設置錯誤識別
9366
						$result["status"]="false";
9367
 
9368
						#設置錯誤訊息
9369
						$result["error"]=$createCertificate;
9370
 
9371
						#回傳結果
9372
						return $result;
9373
 
9374
						}#if end
9375
 
9376
					#取得csr在zerossl上的id
9377
					$csrId=$createCertificate["id"];
9378
 
9379
					#取得cname key
9380
					$cNameKey=$createCertificate["cnameKey"];
9381
 
9382
					#取得cname val
9383
					$cNameVal=$createCertificate["cnameVal"];
9384
 
9385
					#初始化要增加的RR記錄
9386
					$rr2add=array();
9387
 
9388
					#設置CNAME的查詢
9389
					$rr2add["query"]=$cNameKey;
9390
 
9391
					#設置CNAME的value
9392
					$rr2add["value"]=$cNameVal;
9393
 
9394
					#設置類型為 CNAME
9395
					$rr2add["type"]="CNAME";
9396
 
9397
					#設置註解
9398
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
9399
 
281 liveuser 9400
					#if enable debug
9401
					if($debug){
9402
 
9403
						#debug msg
335 liveuser 9404
						echo "Adding DNS record to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9405
 
9406
						}#if end
9407
 
255 liveuser 9408
					#函式說明:
9409
					#新增DNS記錄到檔案裡面.
9410
					#回傳結果:
9411
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9412
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9413
					#$result["function"],當前執行的函式名稱.
9414
					#$result["argu"],所使用的參數.
9415
					#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
9416
					#$result["domain"],字串,RR所屬domain.
9417
					#$result["defaultTTL"],字串,預設的RR更新時間.
9418
					#$result["comment"],字串陣列,逐行的註解.
9419
					#必填參數:
9420
					#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
333 liveuser 9421
					$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
255 liveuser 9422
					#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
9423
					$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
9424
					#可省略參數:
9425
					#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
9426
					$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
9427
					#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
9428
					#$conf["debug"]="false";
9429
					#參考資料:
9430
					#無.
9431
					#備註:
9432
					#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
9433
					#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
9434
					#php-pear上的Net_DNS2也可以解析RR.
9435
					$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
9436
					unset($conf["zerossl::updateDnsRecordFile"]);
9437
 
9438
					#如果執行異常
9439
					if($updateDnsRecordFile["status"]==="false"){
9440
 
9441
						#設置錯誤識別
9442
						$result["status"]="false";
9443
 
9444
						#設置錯誤訊息
9445
						$result["error"]=$updateDnsRecordFile;
9446
 
9447
						#回傳結果
9448
						return $result;
9449
 
9450
						}#if end
281 liveuser 9451
 
9452
					#if enable debug
9453
					if($debug){
9454
 
9455
						#debug msg
336 liveuser 9456
						echo "Restarting DNS service to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9457
 
9458
						}#if end
9459
 
255 liveuser 9460
					#重新啟動dns伺服器
9461
					#函式說明:
9462
					#呼叫shell執行系統命令,並取得回傳的內容.
9463
					#回傳結果:
9464
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9465
					#$result["error"],錯誤訊息陣列.
9466
					#$result["function"],當前執行的函數名稱.
9467
					#$result["argu"],使用的參數.
9468
					#$result["cmd"],執行的指令內容.
9469
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9470
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9471
					#$result["content"],為執行完後的輸出字串.
9472
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9473
					#$result["running"],是否還在執行.
9474
					#$result["pid"],pid.
9475
					#$result["statusCode"],執行結束後的代碼.
9476
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9477
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9478
					#必填參數:
9479
					#$conf["command"],字串,要執行的指令.
291 liveuser 9480
					$conf["external::callShell"]["command"]="systemctl";
255 liveuser 9481
					#$conf["fileArgu"],字串,變數__FILE__的內容.
9482
					$conf["external::callShell"]["fileArgu"]=__FILE__;
9483
					#可省略參數:
9484
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9485
					$conf["external::callShell"]["argu"]=array("restart","named");
9486
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9487
					#$conf["arguIsAddr"]=array();
9488
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9489
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9490
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9491
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9492
					#$conf["enablePrintDescription"]="true";
9493
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9494
					#$conf["printDescription"]="";
9495
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9496
					#$conf["escapeshellarg"]="false";
9497
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9498
					#$conf["thereIsShellVar"]=array();
9499
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9500
					#$conf["username"]="";
9501
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9502
					#$conf["password"]="";
9503
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9504
					#$conf["useScript"]="";
9505
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9506
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9507
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9508
					#$conf["inBackGround"]="";
9509
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9510
					#$conf["getErr"]="false";
9511
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9512
					#$conf["doNotRun"]="false";
302 liveuser 9513
					#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
9514
					#$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 9515
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
9516
					$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
9517
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
9518
					#$conf["remoteUser"]="root";
9519
					#參考資料:
9520
					#exec=>http://php.net/manual/en/function.exec.php
9521
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9522
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9523
					#備註:
9524
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9525
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9526
					$callShell=external::callShell($conf["external::callShell"]);
9527
					unset($conf["external::callShell"]);
9528
 
9529
					#如果執行異常
9530
					if($callShell["status"]==="false"){
9531
 
9532
						#設置錯誤識別
9533
						$result["status"]="false";
9534
 
9535
						#設置錯誤訊息
9536
						$result["error"]=$callShell;
9537
 
9538
						#回傳結果
9539
						return $result;
9540
 
9541
						}#if end
281 liveuser 9542
 
9543
					#if enable debug
9544
					if($debug){
9545
 
9546
						#debug msg
336 liveuser 9547
						echo "Request zerossl to valid domain name(".$cName.").".PHP_EOL;
281 liveuser 9548
 
9549
						}#if end
9550
 
294 liveuser 9551
					#無窮迴圈
9552
					while(true){
255 liveuser 9553
 
294 liveuser 9554
						#函式說明:
9555
						#請求驗證已經透過zerossl::createCertificate要求的domain.
9556
						#回傳結果:
9557
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9558
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
9559
						#$result["function"],當前執行的函式名稱.
9560
						#$result["argu"],所使用的參數.
9561
						#$result["curl_verbose_info"],curl執行的詳細資訊.
9562
						#$result["content"],結果json字串.
9563
						#必填參數:
9564
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
9565
						$conf["zerossl::verifyDomain"]["id"]=$csrId;
9566
						#可省略參數:
9567
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
9568
						$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
9569
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
9570
						$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
9571
						#參考資料:
9572
						#https://zerossl.com/documentation/api/verify-domains/
9573
						#備註:
9574
						#無.
9575
						$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
9576
						unset($conf["zerossl::verifyDomain"]);
9577
 
9578
						#如果執行異常
9579
						if($verifyDomain["status"]==="false"){
9580
 
9581
							#設置錯誤識別
9582
							$result["status"]="false";
255 liveuser 9583
 
294 liveuser 9584
							#設置錯誤訊息
9585
							$result["error"]=$verifyDomain;
255 liveuser 9586
 
294 liveuser 9587
							#回傳結果
9588
							return $result;
9589
 
9590
							}#if end
9591
 
9592
						#如果沒有回內容
9593
						if(!isset($verifyDomain["content"])){
9594
 
9595
							#設置錯誤識別
9596
							$result["status"]="false";
9597
 
9598
							#設置錯誤訊息
9599
							$result["error"]=$verifyDomain;
9600
 
9601
							#回傳結果
9602
							return $result;
9603
 
9604
							}#if end
9605
 
9606
						#如果回應不是 json
9607
						if(!(json_validate($verifyDomain["content"]))){
9608
 
9609
							#設置錯誤識別
9610
							$result["status"]="false";
9611
 
9612
							#設置錯誤訊息
9613
							$result["error"]=$verifyDomain;
9614
 
9615
							#回傳結果
9616
							return $result;
9617
 
9618
							}#if end
9619
 
9620
						/*
9621
						範例json:
9622
						{"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}
9623
						*/
9624
 
9625
						#解析json回應
9626
						$verifyDomainRes=json_decode($verifyDomain["content"]);
9627
 
9628
						#如果回應含有 success
9629
						if(isset($verifyDomainRes->success)){
9630
 
9631
							#如果是 zerossl 驗證失敗
9632
							if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
9633
 
9634
								#如果是 CNAME 記錄找不到
9635
								if($verifyDomainRes->error->code===0){
9636
 
9637
									#取得錯誤訊息
9638
									#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
9639
 
9640
									#if enable debug
9641
									if($debug){
9642
 
9643
										#debug msg
9644
										echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
9645
 
9646
										}#if end
9647
 
9648
									#if enable debug
9649
									if($debug){
9650
 
9651
										#debug msg
9652
										echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
9653
 
9654
										}#if end
9655
 
9656
									#休息60秒
9657
									sleep(60);
9658
 
9659
									#再跑一次要求認證憑證
9660
									continue;
9661
 
9662
									}#if end
9663
 
9664
								#反之為不接受的錯誤訊息
9665
								else{
9666
 
9667
									#設置錯誤識別
9668
									$result["status"]="false";
9669
 
9670
									#設置錯誤訊息
9671
									$result["error"]=$verifyDomain;
9672
 
9673
									#回傳結果
9674
									return $result;
9675
 
9676
									}#else end
9677
 
9678
								}#if end
9679
 
9680
							}#if end
9681
 
9682
						#反之如果回應含有 status
9683
						else if(isset($verifyDomainRes->status)){
9684
 
9685
							#如果是 zerossl 尚在驗證中
9686
							if($verifyDomainRes->status==="pending_validation"){
9687
 
9688
								#if enable debug
9689
								if($debug){
9690
 
9691
									#debug msg
9692
									echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9693
 
9694
									}#if end
9695
 
9696
								#無窮迴圈
9697
								while(true){
9698
 
9699
									#查詢驗證狀況
9700
									#函式說明:
9701
									#取得CSR在zerossl上的狀態
9702
									#回傳結果:
9703
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9704
									#$reuslt["error"],執行不正常結束的錯訊息陣列.
9705
									#$result["function"],當前執行的函式名稱.
9706
									#$result["argu"],所使用的參數.
9707
									#$result["curl_verbose_info"],curl執行的詳細資訊.
9708
									#$result["content"],結果json字串.
9709
									#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
9710
									#必填參數:
9711
									#$conf["id"],字串,zerossl::createCertificate回傳的id.
9712
									$conf["zerossl::getCertSta"]["id"]=$csrId;
9713
									#可省略參數:
9714
									#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
9715
									$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
9716
									#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
9717
									$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
9718
									#參考資料:
9719
									#https://zerossl.com/documentation/api/get-certificate/
9720
									#備註:
9721
									#無.
9722
									$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
9723
									unset($conf["zerossl::getCertSta"]);
9724
 
9725
									#如果執行異常
9726
									if($getCertSta["status"]==="false"){
9727
 
9728
										#設置錯誤識別
9729
										$result["status"]="false";
9730
 
9731
										#設置錯誤訊息
9732
										$result["error"]=$getCertSta;
9733
 
9734
										#回傳結果
9735
										return $result;
9736
 
9737
										}#if end
9738
 
9739
									#如果沒有回應內容
9740
									if(!isset($getCertSta["content"])){
9741
 
9742
										#設置錯誤識別
9743
										$result["status"]="false";
9744
 
9745
										#設置錯誤訊息
9746
										$result["error"]=$getCertSta;
9747
 
9748
										#回傳結果
9749
										return $result;
9750
 
9751
										}#if end
9752
 
9753
									#如果回應不是 json
9754
									if(!(json_validate($getCertSta["content"]))){
9755
 
9756
										#設置錯誤識別
9757
										$result["status"]="false";
9758
 
9759
										#設置錯誤訊息
9760
										$result["error"]=$getCertSta;
9761
 
9762
										#回傳結果
9763
										return $result;
9764
 
9765
										}#if end
9766
 
9767
									#解析json回應
9768
									$getCertStaRes=json_decode($getCertSta["content"]);
9769
 
9770
									#如果憑證已經驗證通過了
9771
									if($getCertStaRes->status==="issued"){
9772
 
9773
										#if enable debug
9774
										if($debug){
9775
 
9776
											#debug msg
9777
											echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
9778
 
9779
											}#if end
9780
 
9781
										#結束等待,離開while
9782
										break 2;
9783
 
9784
										}#if end
9785
 
9786
									#如果 zerossl 尚在處理中
9787
									else if($getCertStaRes->status==="pending_validation"){
9788
 
9789
										#if enable debug
9790
										if($debug){
9791
 
9792
											#debug msg
9793
											echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
9794
 
9795
											}#if end
9796
 
9797
										#休息1分鐘
9798
										sleep(60);
9799
 
9800
										#再次確認憑證的狀態
9801
										continue;
9802
 
9803
										}#if end
9804
 
9805
									#反之
9806
									else{
9807
 
9808
										#例外狀況
9809
 
9810
										#設置錯誤識別
9811
										$result["status"]="false";
9812
 
9813
										#設置錯誤訊息
9814
										$result["error"]=$getCertSta;
9815
 
9816
										#回傳結果
9817
										return $result;
9818
 
9819
										}#else end
9820
 
9821
									}#while end
9822
 
9823
								}#if end
9824
 
9825
							}#if end
255 liveuser 9826
 
294 liveuser 9827
						}#while end
281 liveuser 9828
 
294 liveuser 9829
 
281 liveuser 9830
					#if enable debug
9831
					if($debug){
9832
 
9833
						#debug msg
291 liveuser 9834
						echo "Downling ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
281 liveuser 9835
 
9836
						}#if end
9837
 
255 liveuser 9838
					#函式說明:
9839
					#下載certificate.
9840
					#回傳結果:
9841
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9842
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
9843
					#$result["function"],當前執行的函式名稱.
9844
					#$result["argu"],所使用的參數.
9845
					#$result["curl_verbose_info"],curl執行的詳細資訊.
9846
					#$result["content"],結果json字串.
9847
					#$result["certificate.crt"],字串,certificate.crt的內容.
9848
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
9849
					#必填參數:
9850
					#無.
9851
					#可省略參數:
9852
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 9853
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 9854
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 9855
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 9856
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
9857
					$conf["zerossl::getCert"]["id"]=$csrId;
9858
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
9859
					#$conf["zerossl::getCert"]["cname"]="";
9860
					#參考資料:
9861
					#https://zerossl.com/documentation/api/download-certificate-inline/
9862
					#備註:
9863
					#無.
9864
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
9865
					unset($conf["zerossl::getCert"]);
9866
 
9867
					#如果執行異常
9868
					if($getCert["status"]==="false"){
9869
 
9870
						#設置錯誤識別
9871
						$result["status"]="false";
9872
 
9873
						#設置錯誤訊息
9874
						$result["error"]=$getCert;
9875
 
9876
						#回傳結果
9877
						return $result;
9878
 
9879
						}#if end
281 liveuser 9880
 
9881
					#if enable debug
9882
					if($debug){
9883
 
9884
						#debug msg
409 liveuser 9885
						echo "Updating ssl for domain name(".$cName.").".PHP_EOL;
281 liveuser 9886
 
9887
						}#if end
9888
 
255 liveuser 9889
					#建立 certificate.crt 檔案
9890
					#$cInfo["certPath"];
9891
 
9892
					#建立 ca_bundle.crt 檔案
9893
					#$cInfo["caPath"];
9894
 
9895
					#建立 certAndCa.crt 檔案
9896
					#$cInfo["certWithCaPath"];
9897
 
9898
					#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
9899
					#函式說明:
9900
					#一次建立多個檔案,並寫入內容.
9901
					#回傳結果:
9902
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9903
					#$result["error"],錯誤訊息陣列.
9904
					#$result["function"],當前執行的函數名稱.
9905
					#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
9906
					#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
9907
					#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
9908
					#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
9909
					#$result["argu"],使用的參數.
9910
					#必填參數:
9911
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9912
					$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
9913
					#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 9914
					$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
255 liveuser 9915
					#可省略參數:
9916
					#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
9917
					$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
9918
					#參考資料:
9919
					#無.
9920
					#備註:
9921
					#無.
333 liveuser 9922
					$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 9923
					unset($conf["zerossl::writeMultiFile"]);
9924
 
9925
					#如果執行異常
9926
					if($writeMultiFile["status"]==="false"){
9927
 
9928
						#設置錯誤識別
9929
						$result["status"]="false";
9930
 
9931
						#設置錯誤訊息
9932
						$result["error"]=$writeMultiFile;
9933
 
9934
						#回傳結果
9935
						return $result;
9936
 
9937
						}#if end
9938
 
9939
					#儲存 actionAfterUpdateCert
9940
					$action=$cInfo["actionAfterUpdateCert"];
9941
 
9942
					#如果有多個指令要執行
294 liveuser 9943
					if(count($action)>0){
255 liveuser 9944
 
281 liveuser 9945
						#if enable debug
9946
						if($debug){
9947
 
9948
							#debug msg
409 liveuser 9949
							echo "There are many cmd to run to enable ssl(".$cName.").".PHP_EOL;
281 liveuser 9950
 
9951
							}#if end
9952
 
294 liveuser 9953
						#針對每個指令
255 liveuser 9954
						foreach($action as $ac){
9955
 
281 liveuser 9956
							#if enable debug
9957
							if($debug){
9958
 
9959
								#debug msg
9960
								echo ".".PHP_EOL;
9961
 
9962
								}#if end
9963
 
255 liveuser 9964
							#函式說明:
9965
							#呼叫shell執行系統命令,並取得回傳的內容.
9966
							#回傳結果:
9967
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9968
							#$result["error"],錯誤訊息陣列.
9969
							#$result["function"],當前執行的函數名稱.
9970
							#$result["argu"],使用的參數.
9971
							#$result["cmd"],執行的指令內容.
9972
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9973
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9974
							#$result["content"],為執行完後的輸出字串.
9975
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9976
							#$result["running"],是否還在執行.
9977
							#$result["pid"],pid.
9978
							#$result["statusCode"],執行結束後的代碼.
9979
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9980
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9981
							#必填參數:
9982
							#$conf["command"],字串,要執行的指令.
302 liveuser 9983
							$conf["external::callShell"]["command"]=$ac;
255 liveuser 9984
							#$conf["fileArgu"],字串,變數__FILE__的內容.
9985
							$conf["external::callShell"]["fileArgu"]=__FILE__;
9986
							#可省略參數:
9987
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 9988
							#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 9989
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9990
							#$conf["arguIsAddr"]=array();
9991
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9992
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9993
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9994
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9995
							#$conf["enablePrintDescription"]="true";
9996
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9997
							#$conf["printDescription"]="";
9998
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9999
							$conf["external::callShell"]["escapeshellarg"]="true";
10000
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10001
							#$conf["thereIsShellVar"]=array();
10002
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10003
							#$conf["username"]="";
10004
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10005
							#$conf["password"]="";
10006
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10007
							#$conf["useScript"]="";
10008
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10009
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10010
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10011
							#$conf["inBackGround"]="";
10012
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10013
							#$conf["getErr"]="false";
10014
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10015
							#$conf["doNotRun"]="false";
302 liveuser 10016
							#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10017
							$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10018
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10019
							#$conf["remoteIp"]="";
10020
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10021
							#$conf["remoteUser"]="";
10022
							#參考資料:
10023
							#exec=>http://php.net/manual/en/function.exec.php
10024
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10025
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10026
							#備註:
10027
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10028
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10029
							$callShell=external::callShell($conf["external::callShell"]);
10030
							unset($conf["external::callShell"]);
294 liveuser 10031
 
255 liveuser 10032
							#如果執行異常
294 liveuser 10033
							if($callShell["status"]==="false"){
255 liveuser 10034
 
10035
								#設置錯誤識別
10036
								$result["status"]="false";
10037
 
10038
								#設置錯誤訊息
10039
								$result["error"]=$callShell;
10040
 
10041
								#回傳結果
10042
								return $result;
10043
 
10044
								}#if end
10045
 
10046
							}#foreach end
10047
 
10048
						}#if end
10049
 
10050
					#反之
10051
					else{
10052
 
281 liveuser 10053
						#if enable debug
10054
						if($debug){
10055
 
10056
							#debug msg
291 liveuser 10057
							echo "There is only one cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
281 liveuser 10058
 
10059
							}#if end
10060
 
10061
						#if enable debug
10062
						if($debug){
10063
 
10064
							#debug msg
10065
							echo ".".PHP_EOL;
10066
 
10067
							}#if end
10068
 
255 liveuser 10069
						#函式說明:
10070
						#呼叫shell執行系統命令,並取得回傳的內容.
10071
						#回傳結果:
10072
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10073
						#$result["error"],錯誤訊息陣列.
10074
						#$result["function"],當前執行的函數名稱.
10075
						#$result["argu"],使用的參數.
10076
						#$result["cmd"],執行的指令內容.
10077
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10078
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10079
						#$result["content"],為執行完後的輸出字串.
10080
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10081
						#$result["running"],是否還在執行.
10082
						#$result["pid"],pid.
10083
						#$result["statusCode"],執行結束後的代碼.
10084
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10085
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10086
						#必填參數:
10087
						#$conf["command"],字串,要執行的指令.
302 liveuser 10088
						$conf["external::callShell"]["command"]=$action[0];
255 liveuser 10089
						#$conf["fileArgu"],字串,變數__FILE__的內容.
10090
						$conf["external::callShell"]["fileArgu"]=__FILE__;
10091
						#可省略參數:
10092
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10093
						#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
255 liveuser 10094
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10095
						#$conf["arguIsAddr"]=array();
10096
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10097
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10098
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10099
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10100
						#$conf["enablePrintDescription"]="true";
10101
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10102
						#$conf["printDescription"]="";
10103
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10104
						$conf["external::callShell"]["escapeshellarg"]="true";
10105
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10106
						#$conf["thereIsShellVar"]=array();
10107
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10108
						#$conf["username"]="";
10109
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10110
						#$conf["password"]="";
10111
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10112
						#$conf["useScript"]="";
10113
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10114
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10115
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10116
						#$conf["inBackGround"]="";
10117
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10118
						#$conf["getErr"]="false";
10119
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10120
						#$conf["doNotRun"]="false";
302 liveuser 10121
						#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10122
						$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10123
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10124
						#$conf["remoteIp"]="";
10125
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10126
						#$conf["remoteUser"]="";
10127
						#參考資料:
10128
						#exec=>http://php.net/manual/en/function.exec.php
10129
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10130
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10131
						#備註:
10132
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10133
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10134
						$callShell=external::callShell($conf["external::callShell"]);
10135
						unset($conf["external::callShell"]);
294 liveuser 10136
 
255 liveuser 10137
						#如果執行異常
294 liveuser 10138
						if($callShell["status"]==="false"){
255 liveuser 10139
 
10140
							#設置錯誤識別
10141
							$result["status"]="false";
10142
 
10143
							#設置錯誤訊息
10144
							$result["error"]=$callShell;
10145
 
10146
							#回傳結果
10147
							return $result;
10148
 
10149
							}#if end
10150
 
10151
						}#else end
10152
 
10153
					#要移除舊的憑證 
10154
 
281 liveuser 10155
					#if enable debug
10156
					if($debug){
10157
 
10158
						#debug msg
409 liveuser 10159
						echo "Revoke old ssl(".$cName.") on zerossl(".$conf["info"]["share"]["apiDomain"].")".PHP_EOL;
281 liveuser 10160
 
10161
						}#if end
10162
 
255 liveuser 10163
					#舊憑證於zerossl上的id
10164
					#$oldCsrId
10165
 
341 liveuser 10166
					#無窮迴圈
10167
					while(true){
255 liveuser 10168
 
341 liveuser 10169
						#移除舊的憑證
10170
						#函式說明:
10171
						#請求廢除 issued zerossl certificate.
10172
						#回傳結果:
10173
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10174
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
10175
						#$result["function"],當前執行的函式名稱.
10176
						#$result["argu"],所使用的參數.
10177
						#$result["curl_verbose_info"],curl執行的詳細資訊.
10178
						#$result["content"],結果json字串.
10179
						#$result["busy"],若content結果含有busy屬性,且為1,則為"true";反之為"false".
10180
						#必填參數:
10181
						#$conf["id"],字串,zerossl::createCertificate回傳的id.
10182
						$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
10183
						#可省略參數:
10184
						#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
10185
						$conf["zerosssl::revokeCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
10186
						#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
10187
						$conf["zerosssl::revokeCert"]["key"]=$conf["info"]["share"]["key"];
10188
						#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
10189
						$conf["zerosssl::revokeCert"]["reason"]="Superseded";
10190
						#參考資料:
10191
						#https://zerossl.com/documentation/api/revoke-certificate/
10192
						#備註:
10193
						#無.
10194
						$revokeCert=zerossl::revokeCert($conf["zerosssl::revokeCert"]);
10195
						unset($conf["zerosssl::revokeCert"]);
10196
 
10197
						#如果執行異常
10198
						if($revokeCert["status"]==="false"){
10199
 
10200
							#如果是 api endpoint busy
10201
							if($revokeCert["busy"]==="true"){
10202
 
10203
								#if enable debug
10204
								if($debug){
10205
 
10206
									#debug msg
409 liveuser 10207
									echo "Api endpoint busy, retry revoke old ssl(".$cName.") on zerossl(".$conf["info"]["share"]["apiDomain"].") in 60 seconds".PHP_EOL;
341 liveuser 10208
 
10209
									}#if end
10210
 
10211
								#休息1分鐘
10212
								sleep(60);
10213
 
10214
								#再執行一次
10215
								continue;
10216
 
10217
								}#if end
10218
 
10219
							#設置錯誤識別
10220
							$result["status"]="false";
255 liveuser 10221
 
341 liveuser 10222
							#設置錯誤訊息
10223
							$result["error"]=$revokeCert;
255 liveuser 10224
 
341 liveuser 10225
							#回傳結果
10226
							return $result;
10227
 
10228
							}#if end
10229
 
10230
						#revoke 成功,跳出 while loop.
10231
						break;
10232
 
10233
						}#while end
10234
 
10235
					#if enable debug
10236
					if($debug){
10237
 
10238
						#debug msg
409 liveuser 10239
						echo "Old ssl(".$cName.") on zerossl(".$conf["info"]["share"]["apiDomain"].") revoked".PHP_EOL;
341 liveuser 10240
 
291 liveuser 10241
						}#if end
10242
 
255 liveuser 10243
					}#if end
10244
 
10245
				#反之,尚不需要提前申請新的憑證
10246
				else{
10247
 
291 liveuser 10248
					#debug
10249
					#var_dump(__LINE__,"尚不需要提前申請新的憑證");exit;
10250
 
281 liveuser 10251
					#if enable debug
10252
					if($debug){
10253
 
10254
						#debug msg
291 liveuser 10255
						echo "ssl for domain name(".$cName.") is valid ".PHP_EOL;
281 liveuser 10256
 
10257
						}#if end
10258
 
10259
					#if enable debug
10260
					if($debug){
10261
 
10262
						#debug msg
291 liveuser 10263
						echo "Downling ssl for domain name(".$cName.") on zerossl...".PHP_EOL;
281 liveuser 10264
 
10265
						}#if end
10266
 
310 liveuser 10267
					#if enable debug
10268
					if($debug){
10269
 
10270
						#debug msg
10271
						echo "ID for domain name(".$cName.") on zerossl is ".$csrId.".".PHP_EOL;
10272
 
10273
						}#if end
10274
 
255 liveuser 10275
					#下載憑證
10276
					#函式說明:
10277
					#下載certificate.
10278
					#回傳結果:
10279
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10280
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
10281
					#$result["function"],當前執行的函式名稱.
10282
					#$result["argu"],所使用的參數.
10283
					#$result["curl_verbose_info"],curl執行的詳細資訊.
10284
					#$result["content"],結果json字串.
10285
					#$result["certificate.crt"],字串,certificate.crt的內容.
10286
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
10287
					#必填參數:
10288
					#無.
10289
					#可省略參數:
10290
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
291 liveuser 10291
					$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
255 liveuser 10292
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
291 liveuser 10293
					$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
255 liveuser 10294
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
10295
					$conf["zerossl::getCert"]["id"]=$csrId;
10296
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
10297
					#$conf["zerossl::getCert"]["cname"]="";
10298
					#參考資料:
10299
					#https://zerossl.com/documentation/api/download-certificate-inline/
10300
					#備註:
10301
					#無.
10302
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
10303
					unset($conf["zerossl::getCert"]);
10304
 
10305
					#如果執行異常
10306
					if($getCert["status"]==="false"){
10307
 
10308
						#設置錯誤識別
10309
						$result["status"]="false";
10310
 
10311
						#設置錯誤訊息
10312
						$result["error"]=$getCert;
10313
 
10314
						#回傳結果
10315
						return $result;
10316
 
10317
						}#if end
281 liveuser 10318
 
10319
					#if enable debug
10320
					if($debug){
10321
 
10322
						#debug msg
291 liveuser 10323
						echo "Getting host ssl for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10324
 
10325
						}#if end
10326
 
255 liveuser 10327
					#zerossl上的certificate.crt內容
10328
					#$getCert["certificate.crt"];
310 liveuser 10329
 
255 liveuser 10330
					#zerossl上的ca_bundle.crt內容
10331
					#$getCert["ca_bundle.crt"];
10332
 
10333
					#certificate.crt and ca_bundle.crt 合併後的檔案內容
10334
					#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
10335
 
10336
					#certificate.crt 檔案
10337
					#$cInfo["certPath"];
10338
 
10339
					#ca_bundle.crt 檔案
10340
					#$cInfo["caPath"];
10341
 
10342
					#certAndCa.crt 檔案
10343
					#$cInfo["certWithCaPath"];
281 liveuser 10344
 
10345
					#if enable debug
10346
					if($debug){
10347
 
10348
						#debug msg
310 liveuser 10349
						echo "Getting host ssl(certificate.crt) which path is ".$cInfo["ssl"]["certPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10350
 
10351
						}#if end
255 liveuser 10352
 
10353
					#取得既有的 certificate.crt 檔案內容
10354
					#函式說明:
10355
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10356
					#回傳的變數說明:
10357
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10358
					#$result["error"],錯誤訊息提示.
10359
					#$result["warning"],警告訊息.
10360
					#$result["function"],當前執行的函數名稱.
10361
					#$result["fileContent"],爲檔案的內容陣列.
10362
					#$result["lineCount"],爲檔案內容總共的行數.
10363
					#$result["fullContent"],為檔案的完整內容.
10364
					#$result["base64dataOnly"],檔案的base64data.
10365
					#$result["base64data"],為在網頁上給予src參數的數值.
10366
					#$result["mimeType"],為檔案的mime type.
10367
					#必填參數:
10368
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10369
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certPath"];
255 liveuser 10370
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10371
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10372
					#可省略參數:
10373
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10374
					#$conf["web"]="true";
10375
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10376
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10377
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10378
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10379
					#參考資料:
10380
					#file(),取得檔案內容的行數.
10381
					#file=>http:#php.net/manual/en/function.file.php
10382
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10383
					#filesize=>http://php.net/manual/en/function.filesize.php
10384
					#參考資料:
10385
					#無.
10386
					#備註:
10387
					#無.
291 liveuser 10388
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10389
					unset($conf["fileAccesss::getFileContent"]);
10390
 
10391
					#如果執行異常
10392
					if($getFileContent["status"]==="false"){
10393
 
10394
						#設置錯誤識別
10395
						$result["status"]="false";
10396
 
10397
						#設置錯誤訊息
10398
						$result["error"]=$getFileContent;
10399
 
10400
						#回傳結果
10401
						return $result;
10402
 
10403
						}#if end
10404
 
281 liveuser 10405
					#if enable debug
10406
					if($debug){
10407
 
10408
						#debug msg
291 liveuser 10409
						echo "Checking host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10410
 
10411
						}#if end
10412
 
291 liveuser 10413
					#預設 certificate.crt 不用更新
10414
					$certificate_need_update="false";
10415
 
255 liveuser 10416
					#如果既有憑證跟剛下載的憑證不一樣
10417
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
10418
 
10419
						#識別要改成下載好的憑證
10420
						$certificate_need_update="true";
281 liveuser 10421
 
10422
						#if enable debug
10423
						if($debug){
10424
 
10425
							#debug msg
291 liveuser 10426
							echo "SSL(certificate.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10427
 
10428
							}#if end
255 liveuser 10429
 
10430
						}#if end
281 liveuser 10431
 
10432
					#if enable debug
10433
					if($debug){
10434
 
10435
						#debug msg
310 liveuser 10436
						echo "Getting host ssl(ca_bundle.crt) which path is ".$cInfo["ssl"]["caPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10437
 
10438
						}#if end
10439
 
255 liveuser 10440
					#取得既有的 ca_bundle.crt 檔案內容
10441
					#函式說明:
10442
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10443
					#回傳的變數說明:
10444
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10445
					#$result["error"],錯誤訊息提示.
10446
					#$result["warning"],警告訊息.
10447
					#$result["function"],當前執行的函數名稱.
10448
					#$result["fileContent"],爲檔案的內容陣列.
10449
					#$result["lineCount"],爲檔案內容總共的行數.
10450
					#$result["fullContent"],為檔案的完整內容.
10451
					#$result["base64dataOnly"],檔案的base64data.
10452
					#$result["base64data"],為在網頁上給予src參數的數值.
10453
					#$result["mimeType"],為檔案的mime type.
10454
					#必填參數:
10455
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10456
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["caPath"];
255 liveuser 10457
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10458
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10459
					#可省略參數:
10460
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10461
					#$conf["web"]="true";
10462
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10463
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10464
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10465
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10466
					#參考資料:
10467
					#file(),取得檔案內容的行數.
10468
					#file=>http:#php.net/manual/en/function.file.php
10469
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10470
					#filesize=>http://php.net/manual/en/function.filesize.php
10471
					#參考資料:
10472
					#無.
10473
					#備註:
10474
					#無.
291 liveuser 10475
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10476
					unset($conf["fileAccesss::getFileContent"]);
10477
 
10478
					#如果執行異常
10479
					if($getFileContent["status"]==="false"){
10480
 
10481
						#設置錯誤識別
10482
						$result["status"]="false";
10483
 
10484
						#設置錯誤訊息
10485
						$result["error"]=$getFileContent;
10486
 
10487
						#回傳結果
10488
						return $result;
10489
 
10490
						}#if end
10491
 
281 liveuser 10492
					#if enable debug
10493
					if($debug){
10494
 
10495
						#debug msg
291 liveuser 10496
						echo "Checking host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10497
 
10498
						}#if end
10499
 
291 liveuser 10500
					#預設 ca_bundle.crt 不用更新
10501
					$ca_bundle_need_update="false";
10502
 
255 liveuser 10503
					#如果既有憑證跟剛下載的憑證不一樣
10504
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
10505
 
10506
						#識別要改成下載好的憑證
10507
						$ca_bundle_need_update="true";
281 liveuser 10508
 
10509
						#if enable debug
10510
						if($debug){
10511
 
10512
							#debug msg
291 liveuser 10513
							echo "SSL(ca_bundle.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10514
 
10515
							}#if end
255 liveuser 10516
 
10517
						}#if end
10518
 
281 liveuser 10519
					#if enable debug
10520
					if($debug){
10521
 
10522
						#debug msg
310 liveuser 10523
						echo "Getting host ssl(cert and ca_bundle) which path is ".$cInfo["ssl"]["certWithCaPath"]." for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10524
 
10525
						}#if end
10526
 
255 liveuser 10527
					#取得既有的 certWithCa 檔案內容
10528
					#函式說明:
10529
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
10530
					#回傳的變數說明:
10531
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
10532
					#$result["error"],錯誤訊息提示.
10533
					#$result["warning"],警告訊息.
10534
					#$result["function"],當前執行的函數名稱.
10535
					#$result["fileContent"],爲檔案的內容陣列.
10536
					#$result["lineCount"],爲檔案內容總共的行數.
10537
					#$result["fullContent"],為檔案的完整內容.
10538
					#$result["base64dataOnly"],檔案的base64data.
10539
					#$result["base64data"],為在網頁上給予src參數的數值.
10540
					#$result["mimeType"],為檔案的mime type.
10541
					#必填參數:
10542
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
291 liveuser 10543
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certWithCaPath"];
255 liveuser 10544
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10545
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
10546
					#可省略參數:
10547
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
10548
					#$conf["web"]="true";
10549
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
291 liveuser 10550
					$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
255 liveuser 10551
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
10552
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
10553
					#參考資料:
10554
					#file(),取得檔案內容的行數.
10555
					#file=>http:#php.net/manual/en/function.file.php
10556
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
10557
					#filesize=>http://php.net/manual/en/function.filesize.php
10558
					#參考資料:
10559
					#無.
10560
					#備註:
10561
					#無.
291 liveuser 10562
					$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
255 liveuser 10563
					unset($conf["fileAccesss::getFileContent"]);
10564
 
10565
					#如果執行異常
10566
					if($getFileContent["status"]==="false"){
10567
 
10568
						#設置錯誤識別
10569
						$result["status"]="false";
10570
 
10571
						#設置錯誤訊息
10572
						$result["error"]=$getFileContent;
10573
 
10574
						#回傳結果
10575
						return $result;
10576
 
10577
						}#if end
10578
 
281 liveuser 10579
					#if enable debug
10580
					if($debug){
10581
 
10582
						#debug msg
291 liveuser 10583
						echo "Checking host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10584
 
10585
						}#if end
10586
 
291 liveuser 10587
					#預設 cert_and_ca_bundle.crt 不用更新
10588
					$cert_and_ca_bundle_need_update="false";
10589
 
255 liveuser 10590
					#如果既有憑證跟剛下載的憑證不一樣
10591
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
10592
 
10593
						#識別要改成下載好的憑證
10594
						$cert_and_ca_bundle_need_update="true";
281 liveuser 10595
 
10596
						#if enable debug
10597
						if($debug){
10598
 
10599
							#debug msg
291 liveuser 10600
							echo "SSL(cert and ca_bundle) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
281 liveuser 10601
 
10602
							}#if end
255 liveuser 10603
 
10604
						}#if end
10605
 
10606
					#預設不需要執行更新憑證後的動作
10607
					$requireActionAfterUpdateCert="false";
10608
 
10609
					#如果 certificate 需要更新
10610
					if($certificate_need_update==="true"){
10611
 
281 liveuser 10612
						#if enable debug
10613
						if($debug){
10614
 
10615
							#debug msg
291 liveuser 10616
							echo "Updating host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10617
 
10618
							}#if end
10619
 
255 liveuser 10620
						#更新之
10621
						#函式說明:
10622
						#一次建立多個檔案,並寫入內容.
10623
						#回傳結果:
10624
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10625
						#$result["error"],錯誤訊息陣列.
10626
						#$result["function"],當前執行的函數名稱.
10627
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10628
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10629
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10630
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10631
						#$result["argu"],使用的參數.
10632
						#必填參數:
10633
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10634
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10635
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10636
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"]);
255 liveuser 10637
						#可省略參數:
10638
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10639
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
10640
						#參考資料:
10641
						#無.
10642
						#備註:
10643
						#無.
291 liveuser 10644
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10645
						unset($conf["zerossl::writeMultiFile"]);
10646
 
10647
						#如果執行異常
10648
						if($writeMultiFile["status"]==="false"){
10649
 
10650
							#設置錯誤識別
10651
							$result["status"]="false";
10652
 
10653
							#設置錯誤訊息
10654
							$result["error"]=$writeMultiFile;
10655
 
10656
							#回傳結果
10657
							return $result;
10658
 
10659
							}#if end
293 liveuser 10660
 
10661
						#設置需要執行指令來生效憑證
10662
						$requireActionAfterUpdateCert="true";
255 liveuser 10663
 
10664
						}#if end
10665
 
10666
					#如果 ca_bunle 需要更新
10667
					if($ca_bundle_need_update==="true"){
10668
 
281 liveuser 10669
						#if enable debug
10670
						if($debug){
10671
 
10672
							#debug msg
291 liveuser 10673
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10674
 
10675
							}#if end
293 liveuser 10676
 
10677
						#設置需要執行指令來生效憑證
10678
						$requireActionAfterUpdateCert="true";
281 liveuser 10679
 
255 liveuser 10680
						#更新之
10681
						#函式說明:
10682
						#一次建立多個檔案,並寫入內容.
10683
						#回傳結果:
10684
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10685
						#$result["error"],錯誤訊息陣列.
10686
						#$result["function"],當前執行的函數名稱.
10687
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10688
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10689
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10690
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10691
						#$result["argu"],使用的參數.
10692
						#必填參數:
10693
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10694
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10695
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10696
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["caPath"]);
255 liveuser 10697
						#可省略參數:
10698
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10699
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
10700
						#參考資料:
10701
						#無.
10702
						#備註:
10703
						#無.
291 liveuser 10704
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10705
						unset($conf["zerossl::writeMultiFile"]);
10706
 
10707
						#如果執行異常
10708
						if($writeMultiFile["status"]==="false"){
10709
 
10710
							#設置錯誤識別
10711
							$result["status"]="false";
10712
 
10713
							#設置錯誤訊息
10714
							$result["error"]=$writeMultiFile;
10715
 
10716
							#回傳結果
10717
							return $result;
10718
 
10719
							}#if end
293 liveuser 10720
 
10721
						#設置需要執行指令來生效憑證
10722
						$requireActionAfterUpdateCert="true";
255 liveuser 10723
 
10724
						}#if end
10725
 
10726
					#如果 certificate and ca_bundle 需要更新
10727
					if($cert_and_ca_bundle_need_update==="true"){
10728
 
281 liveuser 10729
						#if enable debug
10730
						if($debug){
10731
 
10732
							#debug msg
291 liveuser 10733
							echo "Updating host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
281 liveuser 10734
 
10735
							}#if end
10736
 
255 liveuser 10737
						#更新之
10738
						#函式說明:
10739
						#一次建立多個檔案,並寫入內容.
10740
						#回傳結果:
10741
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
10742
						#$result["error"],錯誤訊息陣列.
10743
						#$result["function"],當前執行的函數名稱.
10744
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
10745
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
10746
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
10747
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
10748
						#$result["argu"],使用的參數.
10749
						#必填參數:
10750
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
10751
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
10752
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
291 liveuser 10753
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certWithCaPath"]);
255 liveuser 10754
						#可省略參數:
10755
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
10756
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
10757
						#參考資料:
10758
						#無.
10759
						#備註:
10760
						#無.
291 liveuser 10761
						$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
255 liveuser 10762
						unset($conf["zerossl::writeMultiFile"]);
10763
 
10764
						#如果執行異常
10765
						if($writeMultiFile["status"]==="false"){
10766
 
10767
							#設置錯誤識別
10768
							$result["status"]="false";
10769
 
10770
							#設置錯誤訊息
10771
							$result["error"]=$writeMultiFile;
10772
 
10773
							#回傳結果
10774
							return $result;
10775
 
10776
							}#if end
10777
 
293 liveuser 10778
						#設置需要執行指令來生效憑證
10779
						$requireActionAfterUpdateCert="true";
10780
 
255 liveuser 10781
						}#if end
10782
 
10783
					#如果有需要執行指令來生效憑證
10784
					if($requireActionAfterUpdateCert==="true"){
10785
 
281 liveuser 10786
						#if enable debug
10787
						if($debug){
10788
 
10789
							#debug msg
291 liveuser 10790
							echo "Action required to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 10791
 
10792
							}#if end
10793
 
255 liveuser 10794
						#儲存 actionAfterUpdateCert
10795
						$action=$cInfo["actionAfterUpdateCert"];
10796
 
10797
						#如果有多個指令要執行
310 liveuser 10798
						if(count($action)>0){
255 liveuser 10799
 
281 liveuser 10800
							#if enable debug
10801
							if($debug){
10802
 
10803
								#debug msg
291 liveuser 10804
								echo "There are many cmds to run to apply ssl for domain name(".$cName.")".PHP_EOL;
281 liveuser 10805
 
10806
								}#if end
10807
 
255 liveuser 10808
							#針對每的指令
10809
							foreach($action as $ac){
10810
 
281 liveuser 10811
								#if enable debug
10812
								if($debug){
10813
 
10814
									#debug msg
10815
									echo ".".PHP_EOL;
10816
 
10817
									}#if end
293 liveuser 10818
 
10819
								#函式說明:
255 liveuser 10820
								#呼叫shell執行系統命令,並取得回傳的內容.
10821
								#回傳結果:
10822
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10823
								#$result["error"],錯誤訊息陣列.
10824
								#$result["function"],當前執行的函數名稱.
10825
								#$result["argu"],使用的參數.
10826
								#$result["cmd"],執行的指令內容.
10827
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10828
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10829
								#$result["content"],為執行完後的輸出字串.
10830
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10831
								#$result["running"],是否還在執行.
10832
								#$result["pid"],pid.
10833
								#$result["statusCode"],執行結束後的代碼.
10834
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10835
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10836
								#必填參數:
10837
								#$conf["command"],字串,要執行的指令.
302 liveuser 10838
								$conf["external::callShell"]["command"]=$ac;
255 liveuser 10839
								#$conf["fileArgu"],字串,變數__FILE__的內容.
10840
								$conf["external::callShell"]["fileArgu"]=__FILE__;
10841
								#可省略參數:
10842
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10843
								#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
255 liveuser 10844
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10845
								#$conf["arguIsAddr"]=array();
10846
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10847
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10848
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10849
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10850
								#$conf["enablePrintDescription"]="true";
10851
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10852
								#$conf["printDescription"]="";
10853
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10854
								$conf["external::callShell"]["escapeshellarg"]="true";
10855
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10856
								#$conf["thereIsShellVar"]=array();
10857
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10858
								#$conf["username"]="";
10859
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10860
								#$conf["password"]="";
10861
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10862
								#$conf["useScript"]="";
10863
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10864
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10865
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10866
								#$conf["inBackGround"]="";
10867
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10868
								#$conf["getErr"]="false";
10869
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10870
								#$conf["doNotRun"]="false";
302 liveuser 10871
								#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10872
								$conf["external::callShell"]["cmdContainArgu"]="true";
255 liveuser 10873
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10874
								#$conf["remoteIp"]="";
10875
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10876
								#$conf["remoteUser"]="";
10877
								#參考資料:
10878
								#exec=>http://php.net/manual/en/function.exec.php
10879
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10880
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10881
								#備註:
10882
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10883
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10884
								$callShell=external::callShell($conf["external::callShell"]);
10885
								unset($conf["external::callShell"]);
10886
 
10887
								#如果執行異常
310 liveuser 10888
								if($callShell["status"]==="false"){
255 liveuser 10889
 
10890
									#設置錯誤識別
10891
									$result["status"]="false";
10892
 
10893
									#設置錯誤訊息
10894
									$result["error"]=$callShell;
10895
 
10896
									#回傳結果
10897
									return $result;
10898
 
10899
									}#if end
10900
 
10901
								}#foreach end
10902
 
10903
							}#if end
10904
 
291 liveuser 10905
						#反之
10906
						else{
10907
 
10908
							#if enable debug
10909
							if($debug){
10910
 
10911
								#debug msg
10912
								echo "There is only one cmd to run to apply ssl for domain name(".$cName.")".PHP_EOL;
255 liveuser 10913
 
291 liveuser 10914
								}#if end
281 liveuser 10915
 
291 liveuser 10916
							#函式說明:
10917
							#呼叫shell執行系統命令,並取得回傳的內容.
10918
							#回傳結果:
10919
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10920
							#$result["error"],錯誤訊息陣列.
10921
							#$result["function"],當前執行的函數名稱.
10922
							#$result["argu"],使用的參數.
10923
							#$result["cmd"],執行的指令內容.
10924
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10925
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10926
							#$result["content"],為執行完後的輸出字串.
10927
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10928
							#$result["running"],是否還在執行.
10929
							#$result["pid"],pid.
10930
							#$result["statusCode"],執行結束後的代碼.
10931
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10932
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
10933
							#必填參數:
10934
							#$conf["command"],字串,要執行的指令.
302 liveuser 10935
							$conf["external::callShell"]["command"]=$action;
291 liveuser 10936
							#$conf["fileArgu"],字串,變數__FILE__的內容.
10937
							$conf["external::callShell"]["fileArgu"]=__FILE__;
10938
							#可省略參數:
10939
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302 liveuser 10940
							#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
291 liveuser 10941
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10942
							#$conf["arguIsAddr"]=array();
10943
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10944
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10945
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10946
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10947
							#$conf["enablePrintDescription"]="true";
10948
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10949
							#$conf["printDescription"]="";
10950
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
10951
							$conf["external::callShell"]["escapeshellarg"]="true";
10952
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
10953
							#$conf["thereIsShellVar"]=array();
10954
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10955
							#$conf["username"]="";
10956
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10957
							#$conf["password"]="";
10958
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10959
							#$conf["useScript"]="";
10960
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10961
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10962
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10963
							#$conf["inBackGround"]="";
10964
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
10965
							#$conf["getErr"]="false";
10966
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
10967
							#$conf["doNotRun"]="false";
302 liveuser 10968
							#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
10969
							$conf["external::callShell"]["cmdContainArgu"]="true";
291 liveuser 10970
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
10971
							#$conf["remoteIp"]="";
10972
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
10973
							#$conf["remoteUser"]="";
10974
							#參考資料:
10975
							#exec=>http://php.net/manual/en/function.exec.php
10976
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10977
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10978
							#備註:
10979
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10980
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
10981
							$callShell=external::callShell($conf["external::callShell"]);
10982
							unset($conf["external::callShell"]);
10983
 
10984
							#如果執行異常
310 liveuser 10985
							if($callShell["status"]==="false"){
255 liveuser 10986
 
291 liveuser 10987
								#設置錯誤識別
10988
								$result["status"]="false";
255 liveuser 10989
 
291 liveuser 10990
								#設置錯誤訊息
10991
								$result["error"]=$callShell;
255 liveuser 10992
 
291 liveuser 10993
								#回傳結果
10994
								return $result;
255 liveuser 10995
 
291 liveuser 10996
								}#if end
10997
 
10998
							}#else end
10999
 
11000
						}#if end
255 liveuser 11001
 
11002
					}#else end
11003
 
11004
				}#else end
291 liveuser 11005
 
255 liveuser 11006
			}#foreach end
11007
 
11008
		}#function sslUpdater_idle end
11009
 
226 liveuser 11010
	}#class zerossl end
255 liveuser 11011