Subversion Repositories php-qbpwcf

Rev

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

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
27
類別說明:
28
應用 zerossl 的類別.
29
備註:
30
無.
31
*/
32
class zerossl{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	#備註:
47
	#無.
48
	*/
49
	public function __call($method,$arguments){
226 liveuser 50
 
3 liveuser 51
		#取得當前執行的函式
52
		$result["function"]=__FUNCTION__;
226 liveuser 53
 
3 liveuser 54
		#設置執行不正常
55
		$result["status"]="false";
226 liveuser 56
 
3 liveuser 57
		#設置執行錯誤
58
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 59
 
3 liveuser 60
		#設置所丟入的參數
61
		$result["error"][]=$arguments;
226 liveuser 62
 
3 liveuser 63
		#回傳結果
64
		return $result;
226 liveuser 65
 
3 liveuser 66
		}#function __call end
226 liveuser 67
 
3 liveuser 68
	/*
69
	#函式說明:
70
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
71
	#回傳結果:
72
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
73
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
74
	#$result["function"],當前執行的函式名稱.
75
	#必填參數:
76
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
77
	#$arguments,陣列,為呼叫方法時所用的參數.
78
	#參考資料:
79
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
80
	#備註:
81
	#無.
82
	*/
83
	public static function __callStatic($method,$arguments){
226 liveuser 84
 
3 liveuser 85
		#取得當前執行的函式
86
		$result["function"]=__FUNCTION__;
226 liveuser 87
 
3 liveuser 88
		#設置執行不正常
89
		$result["status"]="false";
226 liveuser 90
 
3 liveuser 91
		#設置執行錯誤
92
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 93
 
3 liveuser 94
		#設置所丟入的參數
95
		$result["error"][]=$arguments;
226 liveuser 96
 
3 liveuser 97
		#回傳結果
98
		return $result;
226 liveuser 99
 
3 liveuser 100
		}#function __callStatic end
226 liveuser 101
 
3 liveuser 102
	/*
103
	#函式說明:
104
	#取得api的資訊
105
	#回傳結果:
106
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
107
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
108
	#$result["function"],當前執行的函式名稱.
109
	#$result["content"],api資訊陣列.
110
	#必填參數:
111
	#無
112
	#可省略參數:
113
	#無
114
	#參考資料:
115
	#無.
116
	#備註:
117
	#無.
118
	*/
119
	public static function getApiInfo(){
226 liveuser 120
 
3 liveuser 121
		#初始化要回傳的陣列
122
		$result=array();
226 liveuser 123
 
3 liveuser 124
		#api domain
125
		$result["apiDomain"]="api.zerossl.com";
226 liveuser 126
 
249 liveuser 127
		#create certificate api path
3 liveuser 128
		$result["csrPath"]="/certificates";
226 liveuser 129
 
3 liveuser 130
		#create certificate url
131
		$result["csrUrl"]=$result["apiDomain"].$result["csrPath"];
226 liveuser 132
 
3 liveuser 133
		#api access key
134
		$result["apiKey"]=zeroSSLapiKey;
226 liveuser 135
 
3 liveuser 136
		#設置執行正常
137
		$result["status"]="true";
226 liveuser 138
 
3 liveuser 139
		#回傳結果
140
		return $result;
226 liveuser 141
 
3 liveuser 142
		}#function getApiInfo end
226 liveuser 143
 
3 liveuser 144
	/*
145
	#函式說明:
146
	#產生ssl private key.
147
	#回傳結果:
148
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
149
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
150
	#$result["function"],當前執行的函式名稱.
151
	#$result["argu"],所使用的參數.
152
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 153
	#$result["content"],ssl用的private key.
3 liveuser 154
	#必填參數:
155
	#$conf["fileArgu"],字串,變數__FILE__的內容.
156
	$conf["fileArgu"]=__FILE__;
157
	#可省略參數:
158
	#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
159
	#$conf["length"]=4096';
160
	#參考資料:
161
	#無.
162
	#備註:
163
	#key generated by openssl with RSA.
164
	*/
165
	public static function createPrivateKey(&$conf){
226 liveuser 166
 
3 liveuser 167
		#初始化要回傳的結果
168
		$result=array();
226 liveuser 169
 
3 liveuser 170
		#取得當前執行的函數名稱
171
		$result["function"]=__FUNCTION__;
226 liveuser 172
 
3 liveuser 173
		#如果 $conf 不為陣列
174
		if(gettype($conf)!="array"){
226 liveuser 175
 
3 liveuser 176
			#設置執行失敗
177
			$result["status"]="false";
226 liveuser 178
 
3 liveuser 179
			#設置執行錯誤訊息
180
			$result["error"][]="\$conf變數須為陣列形態";
181
 
182
			#如果傳入的參數為 null
183
			if($conf==null){
226 liveuser 184
 
3 liveuser 185
				#設置執行錯誤訊息
186
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 187
 
3 liveuser 188
				}#if end
189
 
190
			#回傳結果
191
			return $result;
226 liveuser 192
 
3 liveuser 193
			}#if end
226 liveuser 194
 
3 liveuser 195
		#取得參數
196
		$result["argu"]=$conf;
226 liveuser 197
 
3 liveuser 198
		#函式說明:
199
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
200
		#回傳結果:
201
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
202
		#$result["error"],執行不正常結束的錯訊息陣列.
203
		#$result["simpleError"],簡單表示的錯誤訊息.
204
		#$result["function"],當前執行的函式名稱.
205
		#$result["argu"],設置給予的參數.
206
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
207
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
208
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
209
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
210
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
211
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
212
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
213
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
214
		#必填參數:
215
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
216
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
217
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
218
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
219
		#可省略參數:
220
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
221
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
222
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
223
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
224
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
225
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
226
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
227
		#$conf["canNotBeEmpty"]=array();
228
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
229
		#$conf["canBeEmpty"]=array();
230
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
231
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("length");
232
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
233
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
234
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
235
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer");
236
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
237
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(4096);
238
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
239
		#$conf["disallowAllSkipableVarIsEmpty"]="";
240
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
241
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
242
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
243
		#$conf["disallowAllSkipableVarNotExist"]="";
244
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
245
		#$conf["arrayCountEqualCheck"][]=array();
246
		#參考資料:
247
		#array_keys=>http://php.net/manual/en/function.array-keys.php
248
		#備註:
249
		#無.
250
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
251
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 252
 
3 liveuser 253
		#如果 $checkArguments["status"]等於 "false"
254
		if($checkArguments["status"]==="false"){
255
 
256
			#設置執行錯誤的識別
257
			$result["status"]="false";
258
 
259
			#設置錯誤訊息
260
			$result["error"]=$checkArguments;
261
 
262
			#回傳結果
263
			return $result;
264
 
265
			}#if end
266
 
267
		#如果 $checkArguments["passed"]等於 "false"
268
		if($checkArguments["passed"]==="false"){
269
 
270
			#設置執行錯誤的識別
271
			$result["status"]="false";
272
 
273
			#設置錯誤訊息
274
			$result["error"]=$checkArguments;
275
 
276
			#回傳結果
277
			return $result;
278
 
279
			}#if end
226 liveuser 280
 
3 liveuser 281
		#函式說明:
282
		#呼叫shell執行系統命令,並取得回傳的內容.
283
		#回傳結果:
284
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
285
		#$result["error"],錯誤訊息陣列.
286
		#$result["function"],當前執行的函數名稱.
287
		#$result["argu"],使用的參數.
288
		#$result["cmd"],執行的指令內容.
289
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
290
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
291
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
292
		#$result["running"],是否還在執行.
293
		#$result["pid"],pid.
294
		#$result["statusCode"],執行結束後的代碼.
295
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
296
		#必填參數:
297
		#$conf["command"],字串,要執行的指令.
298
		$conf["external::callShell"]["command"]="openssl";
299
		#$conf["fileArgu"],字串,變數__FILE__的內容.
300
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
301
		#可省略參數:
302
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
303
		$conf["external::callShell"]["argu"]=array("genrsa",$conf["length"]);
304
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
305
		#$conf["arguIsAddr"]=array();
306
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
307
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
308
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
309
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
310
		#$conf["enablePrintDescription"]="true";
311
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
312
		#$conf["printDescription"]="";
313
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
314
		$conf["external::callShell"]["escapeshellarg"]="true";
315
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
316
		#$conf["thereIsShellVar"]=array();
317
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
318
		#$conf["username"]="";
319
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
320
		#$conf["password"]="";
321
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
322
		#$conf["useScript"]="";
323
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
324
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
325
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
326
		#$conf["inBackGround"]="";
327
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
328
		#$conf["getErr"]="false";
329
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
330
		#$conf["doNotRun"]="false";
331
		#參考資料:
332
		#exec=>http://php.net/manual/en/function.exec.php
333
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
334
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
335
		#備註:
336
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
337
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
338
		$callShell=external::callShell($conf["external::callShell"]);
339
		unset($conf["external::callShell"]);
226 liveuser 340
 
3 liveuser 341
		#如果異常
342
		if($callShell["status"]==="false"){
226 liveuser 343
 
3 liveuser 344
			#設置錯誤識別
345
			$result["status"]="false";
226 liveuser 346
 
3 liveuser 347
			#設置錯誤訊息
348
			$result["error"]=$callShell;
226 liveuser 349
 
3 liveuser 350
			#回傳結果
351
			return $result;
226 liveuser 352
 
3 liveuser 353
			}#if end
226 liveuser 354
 
3 liveuser 355
		#函式說明:
356
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
357
		#回傳的結果:
358
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
359
		#$result["function"],當前執行的function名稱
360
		#$result["error"],錯誤訊息陣列.
361
		#$result["content"],處理好的字串.
362
		#$result["argu"],使用的參數.
363
		#必填參數:
364
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
365
		$conf["arrays::arrayToString"]["inputArray"]=$callShell["output"];
366
		#可省略參數:
367
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
255 liveuser 368
		$conf["arrays::arrayToString"]["spiltSymbol"]=PHP_EOL;
3 liveuser 369
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
370
		$conf["arrays::arrayToString"]["skipEnd"]="true";
371
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
372
		#$conf["spiltSymbolAtStart"]="";
373
		#參考資料:
374
		#無.
375
		#備註:
376
		#無.
377
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
378
		unset($conf["arrays::arrayToString"]);
226 liveuser 379
 
3 liveuser 380
		#如果異常
381
		if($arrayToString["status"]==="false"){
226 liveuser 382
 
3 liveuser 383
			#設置錯誤識別
384
			$result["status"]="false";
226 liveuser 385
 
3 liveuser 386
			#設置錯誤訊息
387
			$result["error"]=$arrayToString;
226 liveuser 388
 
3 liveuser 389
			#回傳結果
390
			return $result;
226 liveuser 391
 
3 liveuser 392
			}#if end
226 liveuser 393
 
3 liveuser 394
		#取得 private key 字串
395
		$result["content"]=$arrayToString["content"];
226 liveuser 396
 
3 liveuser 397
		#設置執行正常
398
		$result["status"]="true";
226 liveuser 399
 
3 liveuser 400
		#回傳結果
401
		return $result;
226 liveuser 402
 
3 liveuser 403
		}#function createPrivateKey end
226 liveuser 404
 
3 liveuser 405
	/*
406
	#函式說明:
249 liveuser 407
	#產生certificate sign request(CSR).
3 liveuser 408
	#回傳結果:
409
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
410
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
411
	#$result["function"],當前執行的函式名稱.
412
	#$result["argu"],所使用的參數.
255 liveuser 413
	#$result["content"],csr內容.
3 liveuser 414
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 415
	#$result["privateKey"], private key 的內容.
3 liveuser 416
	#必填參數:
249 liveuser 417
	#$conf["domain"],字串,csr內容的網域名稱.
418
	#$conf["domain"]="";
419
	#可省略參數:
255 liveuser 420
	#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
421
	#$conf["pKey"]="";
249 liveuser 422
	#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
423
	#$conf["country"]="";
424
	#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
425
	#$conf["state"]="";
426
	#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
427
	#$conf["org"]="";
428
	#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
429
	#$conf["unit"]="";
430
	#參考資料:
431
	#無.
432
	#備註:
433
	#無.
434
	*/
435
	public static function createCSR(&$conf){
436
 
437
		#初始化要回傳的結果
438
		$result=array();
439
 
440
		#設置當其函數名稱
441
		$result["function"]=__FUNCTION__;
442
 
443
		#如果 $conf 不為陣列
444
		if(gettype($conf)!="array"){
445
 
446
			#設置執行失敗
447
			$result["status"]="false";
448
 
449
			#設置執行錯誤訊息
450
			$result["error"][]="\$conf變數須為陣列形態";
451
 
452
			#如果傳入的參數為 null
453
			if($conf==null){
454
 
455
				#設置執行錯誤訊息
456
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
457
 
458
				}#if end
459
 
460
			#回傳結果
461
			return $result;
462
 
463
			}#if end
464
 
465
		#取得參數
466
		$result["argu"]=$conf;
467
 
468
		#檢查參數
469
		#函式說明:
470
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
471
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
472
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
473
		#$result["function"],當前執行的函式名稱.
474
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
475
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
476
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
477
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
478
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
479
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
480
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
481
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
482
		#必填寫的參數:
483
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
484
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
485
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
486
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("domain");
487
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
488
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
489
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
490
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
491
		#可以省略的參數:
492
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
493
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
494
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
495
		#$conf["skipableVariableCanNotBeEmpty"]=array();
496
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
255 liveuser 497
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pKey","country","state","city","org","unit");
249 liveuser 498
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
255 liveuser 499
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
249 liveuser 500
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 501
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"TW","Taiwan","Taoyuan City","QBPWCF","RD");
249 liveuser 502
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
503
		#$conf["arrayCountEqualCheck"][]=array();
504
		#參考資料來源:
505
		#array_keys=>http://php.net/manual/en/function.array-keys.php
506
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
507
		unset($conf["variableCheck::checkArguments"]);
508
 
509
		#如果檢查失敗
510
		if($checkArguments["status"]==="false"){
511
 
512
			#設置錯誤識別
513
			$result["status"]="false";
514
 
515
			#設置錯誤訊息
516
			$result["error"]=$checkArguments;
517
 
518
			#回傳結果
519
			return $result;
520
 
521
			}#if end
522
 
523
		#如果檢查不通過
524
		if($checkArguments["passed"]==="false"){
525
 
526
			#設置錯誤識別
527
			$result["status"]="false";
528
 
529
			#設置錯誤訊息
530
			$result["error"]=$checkArguments;
531
 
532
			#回傳結果
533
			return $result;
534
 
535
			}#if end
536
 
255 liveuser 537
		#如果沒有指定 pKey
538
		if(!isset($conf["pKey"])){
249 liveuser 539
 
255 liveuser 540
			#產生uuid名稱
541
			#函式說明:
542
			#使用 linux 的 uuid 指令來產生 uuid 字串
543
			#回傳結果:
544
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
545
			#$result["error"],錯誤訊息.
546
			#$result["function"],當前執行的函式名稱.
547
			#$result["content"],uuid.
548
			#必填參數:
549
			#無.
550
			#可省略參數:
551
			#無.
552
			#參考資料:
553
			#無.
554
			#備註:
555
			#無.
556
			$uuid=cmd::uuid();
557
 
558
			#如果執行異常
559
			if($uuid["status"]==="false"){
249 liveuser 560
 
255 liveuser 561
				#設置錯誤識別
562
				$result["status"]="false";
249 liveuser 563
 
255 liveuser 564
				#設置錯誤訊息
565
				$result["error"]=$uuid;
249 liveuser 566
 
255 liveuser 567
				#回傳結果
568
				return $result;
249 liveuser 569
 
255 liveuser 570
				}#if end
571
 
572
			#取得暫存的檔案名稱
573
			$TFN=$uuid["content"];
574
 
575
			#函式說明:
576
			#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
577
			#回傳結果:
578
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
579
			#$result["error"],錯誤訊息.
580
			#$result["function"],當前執行的函數名稱.
581
			#$result["content"],暫存檔案的路徑與名稱.
582
			#$result["fileName"],暫存檔案的名稱.
583
			#$result["path"],暫存檔案的路徑.
584
			#必填參數:
585
			#無.
586
			#可省略參數:
587
			#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
588
			#$conf["contant"]=array();
589
			#參考資料:
590
			#無.
591
			#備註:
592
			#無.
593
			$conf["fileAccess::createTempFile"]=array();
594
			$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
595
			unset($conf["fileAccess::createTempFile"]);
596
 
597
			#如果執行異常
598
			if($createTempFile["status"]==="false"){
249 liveuser 599
 
255 liveuser 600
				#設置錯誤識別
601
				$result["status"]="false";
249 liveuser 602
 
255 liveuser 603
				#設置錯誤訊息
604
				$result["error"]=$createTempFile;
249 liveuser 605
 
255 liveuser 606
				#回傳結果
607
				return $result;
249 liveuser 608
 
255 liveuser 609
				}#if end
610
 
611
			#暫存的檔案路徑與名稱
612
			$TFN=$createTempFile["content"];
613
 
614
			#產生 privae key
615
			#openssl genrsa -out output.key 4096 
616
 
617
			#函式說明:
618
			#呼叫shell執行系統命令,並取得回傳的內容.
619
			#回傳結果:
620
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
621
			#$result["error"],錯誤訊息陣列.
622
			#$result["function"],當前執行的函數名稱.
623
			#$result["argu"],使用的參數.
624
			#$result["cmd"],執行的指令內容.
625
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
626
			#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
627
			#$result["content"],為執行完後的輸出字串.
628
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
629
			#$result["running"],是否還在執行.
630
			#$result["pid"],pid.
631
			#$result["statusCode"],執行結束後的代碼.
632
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
633
			#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
634
			#必填參數:
635
			#$conf["command"],字串,要執行的指令.
636
			$conf["external::callShell"]["command"]="openssl";
637
			#$conf["fileArgu"],字串,變數__FILE__的內容.
638
			$conf["external::callShell"]["fileArgu"]=__FILE__;
639
			#可省略參數:
640
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
641
			$conf["external::callShell"]["argu"]=array("genrsa","-out",$TFN,"4096");
642
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
643
			#$conf["arguIsAddr"]=array();
644
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
645
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
646
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
647
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
648
			#$conf["enablePrintDescription"]="true";
649
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
650
			#$conf["printDescription"]="";
651
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
652
			#$conf["escapeshellarg"]="false";
653
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
654
			#$conf["thereIsShellVar"]=array();
655
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
656
			#$conf["username"]="";
657
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
658
			#$conf["password"]="";
659
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
660
			#$conf["useScript"]="";
661
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
662
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
663
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
664
			#$conf["inBackGround"]="";
665
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
666
			#$conf["getErr"]="false";
667
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
668
			$conf["external::callShell"]["doNotRun"]="true";
669
			#參考資料:
670
			#exec=>http://php.net/manual/en/function.exec.php
671
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
672
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
673
			#備註:
674
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
675
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
676
			$callShell=external::callShell($conf["external::callShell"]);
677
			unset($conf["external::callShell"]);
678
 
679
			#如果執行異常
680
			if($callShell["status"]==="false"){
249 liveuser 681
 
255 liveuser 682
				#設置錯誤識別
683
				$result["status"]="false";
249 liveuser 684
 
255 liveuser 685
				#設置錯誤訊息
686
				$result["error"]=$callShell;
249 liveuser 687
 
255 liveuser 688
				#回傳結果
689
				return $result;
249 liveuser 690
 
255 liveuser 691
				}#if end
692
 
693
			#debug
694
			#var_dump(__LINE__,$callShell);exit;
695
 
696
			#函式說明:
697
			#透過proc來多執行序運作.
698
			#回傳結果:
699
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
700
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
701
			#$result["function"],當前執行的函式名稱.
702
			#$result["argu"],使用的參數.
703
			#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
704
			#必填參數:
705
			#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
706
			$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
707
			#可省略參數:
708
			#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
709
			$conf["threads::proc"]["wait"]="true";
710
			#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
711
			#$conf["timeout"]=array("10");
712
			#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
713
			#$conf["workingDir"]=array("path");
714
			#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
715
			#$conf["envs"]=array(array("key"=>"value"));
716
			#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
717
			#$conf["executeBy"]=array("bash");
718
			#參考資料:
719
			#https://www.php.net/manual/en/function.proc-open.php
720
			#https://www.php.net/manual/en/function.proc-get-status.php
721
			#https://www.php.net/manual/en/function.proc-terminate.php
722
			#備註:
723
			#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
724
			$proc=threads::proc($conf["threads::proc"]);
725
			unset($conf["threads::proc"]);
726
 
727
			#如果執行異常
728
			if($proc["status"]==="false"){
249 liveuser 729
 
255 liveuser 730
				#設置錯誤識別
731
				$result["status"]="false";
249 liveuser 732
 
255 liveuser 733
				#設置錯誤訊息
734
				$result["error"]=$proc;
249 liveuser 735
 
255 liveuser 736
				#回傳結果
737
				return $result;
249 liveuser 738
 
255 liveuser 739
				}#if end
740
 
741
			#debug
742
			#var_dump(__LINE__,$proc);exit;
743
 
744
			#如果執行異常
745
			if($proc["content"][0]["status"]==="false"){
746
 
747
				#設置錯誤識別
748
				$result["status"]="false";
249 liveuser 749
 
255 liveuser 750
				#設置錯誤訊息
751
				$result["error"]=$proc["content"][0]["error"];
249 liveuser 752
 
255 liveuser 753
				#回傳結果
754
				return $result;
755
 
756
				}#if end
757
 
758
			#儲存錯誤訊息
759
			$errorMsg=$proc["content"][0]["error"];
760
 
761
			#如果有錯誤訊息
762
			if(!empty($errorMsg)){
763
 
764
				#設置錯誤識別
765
				$result["status"]="false";
766
 
767
				#設置錯誤訊息
768
				$result["error"]=$errorMsg;
769
 
770
				#回傳結果
771
				return $result;
772
 
773
				}#if end
249 liveuser 774
 
775
			}#if end
776
 
255 liveuser 777
		#反之
778
		else{
249 liveuser 779
 
255 liveuser 780
			#檢查 pKey 是否存在
781
			#函式說明:
782
			#檢查多個檔案與資料夾是否存在.
783
			#回傳的結果:
784
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
785
			#$result["error"],錯誤訊息陣列.
786
			#$resutl["function"],當前執行的涵式名稱.
787
			#$result["argu"],使用的參數.
788
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
789
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
790
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
791
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
792
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
793
			#必填參數:
794
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
795
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["pKey"];
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
	#函式說明:
1400
	#新增DNS記錄到檔案裡面.
1401
	#回傳結果:
1402
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1403
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1404
	#$result["function"],當前執行的函式名稱.
1405
	#$result["argu"],所使用的參數.
1406
	#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
255 liveuser 1407
	#$result["domain"],字串,RR所屬domain.
1408
	#$result["defaultTTL"],字串,預設的RR更新時間.
249 liveuser 1409
	#$result["comment"],字串陣列,逐行的註解.
1410
	#必填參數:
255 liveuser 1411
	#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型(支援的有"A","TXT","CNAME","SOA","$TTL","$ORIGIN")、答案、註解.
249 liveuser 1412
	$conf["add"]=array();
1413
	#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
1414
	$conf["dnsRecordFile"]="";
1415
	#可省略參數:
1416
	#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
1417
	#$conf["writeNow"]="false";
253 liveuser 1418
	#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
1419
	#$conf["debug"]="false";
249 liveuser 1420
	#參考資料:
1421
	#無.
1422
	#備註:
1423
	#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
1424
	#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
1425
	#php-pear上的Net_DNS2也可以解析RR.
1426
	*/
1427
	public static function updateDnsRecordFile(&$conf){
1428
 
1429
		#初始化要回傳的結果
1430
		$result=array();
1431
 
1432
		#設置當其函數名稱
1433
		$result["function"]=__FUNCTION__;
1434
 
1435
		#如果 $conf 不為陣列
1436
		if(gettype($conf)!="array"){
1437
 
1438
			#設置執行失敗
1439
			$result["status"]="false";
1440
 
1441
			#設置執行錯誤訊息
1442
			$result["error"][]="\$conf變數須為陣列形態";
1443
 
1444
			#如果傳入的參數為 null
1445
			if($conf==null){
1446
 
1447
				#設置執行錯誤訊息
1448
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1449
 
1450
				}#if end
1451
 
1452
			#回傳結果
1453
			return $result;
1454
 
1455
			}#if end
1456
 
1457
		#取得參數
1458
		$result["argu"]=$conf;
1459
 
1460
		#檢查參數
1461
		#函式說明:
1462
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1463
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1464
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1465
		#$result["function"],當前執行的函式名稱.
1466
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1467
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1468
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1469
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1470
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1471
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1472
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1473
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1474
		#必填寫的參數:
1475
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1476
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1477
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1478
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("add","dnsRecordFile");
1479
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
1480
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
1481
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1482
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1483
		#可以省略的參數:
1484
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1485
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1486
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
1487
		#$conf["skipableVariableCanNotBeEmpty"]=array();
1488
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
253 liveuser 1489
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug");
249 liveuser 1490
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
253 liveuser 1491
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
249 liveuser 1492
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
253 liveuser 1493
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
249 liveuser 1494
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1495
		#$conf["arrayCountEqualCheck"][]=array();
1496
		#參考資料來源:
1497
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1498
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1499
		unset($conf["variableCheck::checkArguments"]);
1500
 
1501
		#如果檢查失敗
1502
		if($checkArguments["status"]==="false"){
1503
 
1504
			#設置錯誤識別
1505
			$result["status"]="false";
1506
 
1507
			#設置錯誤訊息
1508
			$result["error"]=$checkArguments;
1509
 
1510
			#回傳結果
1511
			return $result;
1512
 
1513
			}#if end
1514
 
1515
		#如果檢查不通過
1516
		if($checkArguments["passed"]==="false"){
1517
 
1518
			#設置錯誤識別
1519
			$result["status"]="false";
1520
 
1521
			#設置錯誤訊息
1522
			$result["error"]=$checkArguments;
1523
 
1524
			#回傳結果
1525
			return $result;
1526
 
1527
			}#if end
1528
 
1529
		#初始化要回傳的content
1530
		$result["content"]=array();
1531
 
1532
		#初始化儲存逐行的註解.
1533
		$result["comment"]=array();
1534
 
1535
		#預設的zone file domain為空
1536
		$result["domain"]="";
1537
 
1538
		#預設的 update 時間
1539
		$result["defaultTTL"]=3600;
1540
 
1541
		#取得 dns 記錄檔案的內容
1542
		#函式說明:
1543
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1544
		#回傳的變數說明:
1545
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1546
		#$result["error"],錯誤訊息提示.
1547
		#$result["warning"],警告訊息.
1548
		#$result["function"],當前執行的函數名稱.
1549
		#$result["fileContent"],爲檔案的內容陣列.
1550
		#$result["lineCount"],爲檔案內容總共的行數.
1551
		#$result["fullContent"],為檔案的完整內容.
1552
		#$result["base64dataOnly"],檔案的base64data.
1553
		#$result["base64data"],為在網頁上給予src參數的數值.
1554
		#$result["mimeType"],為檔案的mime type.
1555
		#必填參數:
1556
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1557
		$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$conf["dnsRecordFile"];
1558
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1559
		$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
1560
		#可省略參數:
1561
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
1562
		$conf["fileAccesss::getFileContent"]["web"]="false";
1563
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1564
		#$conf["createIfnotExist"]="false";
1565
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
1566
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
1567
		#參考資料:
1568
		#file(),取得檔案內容的行數.
1569
		#file=>http:#php.net/manual/en/function.file.php
1570
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1571
		#filesize=>http://php.net/manual/en/function.filesize.php
1572
		#參考資料:
1573
		#無.
1574
		#備註:
1575
		#無.
1576
		$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
1577
		unset($conf["fileAccesss::getFileContent"]);
1578
 
1579
		#如果檢查失敗
1580
		if($getFileContent["status"]==="false"){
1581
 
1582
			#設置錯誤識別
1583
			$result["status"]="false";
1584
 
1585
			#設置錯誤訊息
1586
			$result["error"]=$getFileContent;
1587
 
1588
			#回傳結果
1589
			return $result;
1590
 
1591
			}#if end
1592
 
1593
		#取得每行內容
1594
		$lines=$getFileContent["fileContent"];
1595
 
1596
		/*
1597
		範例每行內容:
1598
		$ORIGIN server.domain.	;base domain-name,in this Resource Records (RR) file,"@" equal to base domain-name.
1599
		$TTL 86400	;default TTL for zone
1600
		@	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
1601
		@	3600	IN	TXT	"v=spf1 a mx ~all"
1602
		@	86400	IN	MX	1 mail.server.domain.
1603
		@	86400	IN	A	1.1.1.1
1604
		mail.server.domain.	IN	1.1.1.1
1605
		10-42-0-1	IN	A	10.42.0.1
1606
		101-free        IN      A	101.101.101.101
1607
		127-0-0-1	IN	A	127.0.0.1
1608
		_dmarc	IN	TXT	"v=DMARC1;p=reject;sp=reject;pct=100;adkim=r;aspf=r;fo=1;ri=86400;rua=mailto:admin@server.domain"
1609
		default._domainkey	IN	TXT	( "v=DKIM1; k=rsa;" "p=MIGfMA0GCSqG/SIb3DQEBAQQAB" )  ; ----- DKIM key default for qbpwcf.org
1610
		...
1611
		*/
1612
 
1613
		#針對每行內容
1614
		foreach($lines as $lineNo => $line){
1615
 
1616
			#另存一份要處理的RR
1617
			$unFormatStr=$line;
1618
 
253 liveuser 1619
			#如果要debug
1620
			if($conf["debug"]==="true"){
1621
 
1622
				#函式說明:
1623
				#撰寫log
1624
				#回傳結果:
1625
				#$result["status"],狀態,"true"或"false".
1626
				#$result["error"],錯誤訊息陣列.
1627
				#$result["function"],當前函式的名稱.
1628
				#$result["argu"],使用的參數.
1629
				#$result["content"],要寫入log的內容字串.
1630
				#必填參數:
1631
				#$conf["path"],字串,log檔案的路徑與名稱.
1632
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
1633
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1634
				$conf["logs::record"]["content"]="processing lineNo:".$lineNo." content:".$line.PHP_EOL;
1635
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1636
				$conf["logs::record"]["fileArgu"]=__FILE__;
1637
				#可省略參數:
1638
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1639
				#$conf["rewrite"]="false";
1640
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
1641
				#$conf["returnOnly"]="true";
1642
				#參考資料:
1643
				#無.
1644
				#備註:
1645
				#無.
1646
				$record=logs::record($conf["logs::record"]);
1647
				unset($conf["logs::record"]);
1648
 
1649
				}#if end
1650
 
249 liveuser 1651
			#初始化該行的資訊陣列
1652
			$info=array();
1653
 
1654
			#尋找";"開頭的內容,亦即整行都是註解.
1655
			#函式說明:
1656
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1657
			#回傳結果:
1658
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1659
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1660
			#$result["function"],當前執行的函式名稱.
1661
			#$result["argu"],所使用的參數.
1662
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1663
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1664
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1665
			#必填參數:
1666
			#$conf["input"],字串,要檢查的字串.
1667
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1668
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1669
			$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
1670
			#可省略參數:
1671
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1672
			#$conf["varEqual"]=array(null,"found");
1673
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1674
			#$conf["varCon"]=array("no_tail"=>" not");
1675
			#參考資料:
1676
			#無.
1677
			#備註:
1678
			#無.
1679
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1680
			unset($conf["search::findSpecifyStrFormat"]);
1681
 
1682
			#如果執行異常
1683
			if($findSpecifyStrFormat["status"]==="false"){
1684
 
1685
				#設置錯誤識別
1686
				$result["status"]="false";
1687
 
1688
				#設置錯誤訊息
1689
				$result["error"]=$findSpecifyStrFormat;
1690
 
1691
				#回傳結果
1692
				return $result;
1693
 
1694
				}#if end
1695
 
1696
			#如果有找到符合格式的內容
1697
			if($findSpecifyStrFormat["found"]==="true"){
1698
 
1699
				#儲存為註解
1700
				$result["comment"][]=$unFormatStr;
1701
 
1702
				#換下一行
1703
				continue;
1704
 
1705
				}#if end
1706
 
1707
			#函式說明:
1708
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1709
			#回傳結果:
1710
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1711
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1712
			#$result["function"],當前執行的函式名稱.
1713
			#$result["argu"],所使用的參數.
1714
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1715
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1716
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1717
			#必填參數:
1718
			#$conf["input"],字串,要檢查的字串.
1719
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1720
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1721
			$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
1722
			#可省略參數:
1723
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1724
			#$conf["varEqual"]=array(null,"found");
1725
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1726
			#$conf["varCon"]=array("no_tail"=>" not");
1727
			#參考資料:
1728
			#無.
1729
			#備註:
1730
			#無.
1731
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1732
			unset($conf["search::findSpecifyStrFormat"]);
1733
 
1734
			#如果執行異常
1735
			if($findSpecifyStrFormat["status"]==="false"){
1736
 
1737
				#設置錯誤識別
1738
				$result["status"]="false";
1739
 
1740
				#設置錯誤訊息
1741
				$result["error"]=$findSpecifyStrFormat;
1742
 
1743
				#回傳結果
1744
				return $result;
1745
 
1746
				}#if end
1747
 
1748
			#如果有找到符合格式的內容
1749
			if($findSpecifyStrFormat["found"]==="true"){
1750
 
1751
				#設置 type 的數值
1752
				$info["type"]="\$ORIGIN";
1753
 
1754
				#取得後面待處理的內容
1755
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
1756
 
1757
				#函式說明:
1758
				#將字串開頭的特定關鍵字移除.
1759
				#回傳結果:
1760
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1761
				#$result["error"],錯誤訊息陣列.
1762
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
1763
				#$result["function"],當前執行的函數名稱.
1764
				#$result["argu"],使用的參數.
1765
				#$result["content"],處理好的的字串內容.
1766
				#$result["deleted"],被移除的內容.
1767
				#必填參數:
1768
				#$conf["stringIn"],字串,要處理的字串.
1769
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
1770
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
1771
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
1772
				#可省略參數:
1773
				#無.
1774
				#參考資料:
1775
				#無.
1776
				#備註:
1777
				#無.
1778
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
1779
				unset($conf["stringProcess::delHeadStr"]);
1780
 
1781
				#如果執行異常
1782
				if($delHeadStr["status"]==="false"){
1783
 
1784
					#設置錯誤識別
1785
					$result["status"]="false";
1786
 
1787
					#設置錯誤訊息
1788
					$result["error"]=$delHeadStr;
1789
 
1790
					#回傳結果
1791
					return $result;
1792
 
1793
					}#if end
1794
 
1795
				#如果有移除開頭的字串
1796
				if($delHeadStr["founded"]==="true"){
1797
 
1798
					#取得處理後的結果
1799
					$unFormatStr=$delHeadStr["content"];
1800
 
1801
					}#if end
1802
 
253 liveuser 1803
 
1804
 
249 liveuser 1805
				#解析 $ORIGN 的數值, 以及後面是否有註解...
1806
				#函式說明:
1807
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1808
				#回傳結果:
1809
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1810
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
1811
				#$result["function"],當前執行的函式名稱.
1812
				#$result["argu"],所使用的參數.
1813
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1814
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1815
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1816
				#必填參數:
1817
				#$conf["input"],字串,要檢查的字串.
1818
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1819
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1820
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
1821
				#可省略參數:
1822
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1823
				#$conf["varEqual"]=array(null,"found");
1824
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1825
				#$conf["varCon"]=array("no_tail"=>" not");
1826
				#參考資料:
1827
				#無.
1828
				#備註:
1829
				#無.
1830
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1831
				unset($conf["search::findSpecifyStrFormat"]);
1832
 
1833
				#如果執行異常
1834
				if($findSpecifyStrFormat["status"]==="false"){
1835
 
1836
					#設置錯誤識別
1837
					$result["status"]="false";
1838
 
1839
					#設置錯誤訊息
1840
					$result["error"]=$findSpecifyStrFormat;
1841
 
1842
					#回傳結果
1843
					return $result;
1844
 
1845
					}#if end
1846
 
1847
				#如果有數值跟註解
1848
				if($findSpecifyStrFormat["found"]==="true"){
1849
 
1850
					#儲存數值
1851
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
1852
 
1853
					#儲存zone domain
1854
					$result["domain"]=trim($info["value"]);
1855
 
1856
					#儲存註解
253 liveuser 1857
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
249 liveuser 1858
 
1859
					#儲存解析好的RR
1860
					$result["content"][]=$info;
1861
 
1862
					#換下一行
1863
					continue;
1864
 
1865
					}#if end
1866
 
1867
				#執行到這邊代表剩下的內容都是 value
1868
				$info["value"]=$unFormatStr;
1869
 
1870
				#儲存zone domain
1871
				$result["domain"]=trim($info["value"]);
1872
 
1873
				#儲存解析好的RR
1874
				$result["content"][]=$info;
1875
 
1876
				#換下一行
1877
				continue;
1878
 
1879
				}#if end
1880
 
1881
			#檢查是否為 $TTL 開頭
1882
			#函式說明:
1883
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1884
			#回傳結果:
1885
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1886
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1887
			#$result["function"],當前執行的函式名稱.
1888
			#$result["argu"],所使用的參數.
1889
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1890
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1891
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1892
			#必填參數:
1893
			#$conf["input"],字串,要檢查的字串.
1894
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1895
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1896
			$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
1897
			#可省略參數:
1898
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1899
			#$conf["varEqual"]=array(null,"found");
1900
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1901
			#$conf["varCon"]=array("no_tail"=>" not");
1902
			#參考資料:
1903
			#無.
1904
			#備註:
1905
			#無.
1906
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1907
			unset($conf["search::findSpecifyStrFormat"]);
1908
 
1909
			#如果執行異常
1910
			if($findSpecifyStrFormat["status"]==="false"){
1911
 
1912
				#設置錯誤識別
1913
				$result["status"]="false";
1914
 
1915
				#設置錯誤訊息
1916
				$result["error"]=$findSpecifyStrFormat;
1917
 
1918
				#回傳結果
1919
				return $result;
1920
 
1921
				}#if end
1922
 
1923
			#如果有找到符合格式的內容
1924
			if($findSpecifyStrFormat["found"]==="true"){
1925
 
1926
				#設置 type 的數值
1927
				$info["type"]="\$TTL";
1928
 
1929
				#取得後面待處理的內容
1930
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
1931
 
1932
				#函式說明:
1933
				#將字串開頭的特定關鍵字移除.
1934
				#回傳結果:
1935
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1936
				#$result["error"],錯誤訊息陣列.
1937
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
1938
				#$result["function"],當前執行的函數名稱.
1939
				#$result["argu"],使用的參數.
1940
				#$result["content"],處理好的的字串內容.
1941
				#$result["deleted"],被移除的內容.
1942
				#必填參數:
1943
				#$conf["stringIn"],字串,要處理的字串.
1944
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
1945
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
1946
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
1947
				#可省略參數:
1948
				#無.
1949
				#參考資料:
1950
				#無.
1951
				#備註:
1952
				#無.
1953
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
1954
				unset($conf["stringProcess::delHeadStr"]);
1955
 
1956
				#如果執行異常
1957
				if($delHeadStr["status"]==="false"){
1958
 
1959
					#設置錯誤識別
1960
					$result["status"]="false";
1961
 
1962
					#設置錯誤訊息
1963
					$result["error"]=$delHeadStr;
1964
 
1965
					#回傳結果
1966
					return $result;
1967
 
1968
					}#if end
1969
 
1970
				#如果有移除開頭的字串
1971
				if($delHeadStr["founded"]==="true"){
1972
 
1973
					#取得處理後的結果
1974
					$unFormatStr=$delHeadStr["content"];
1975
 
1976
					}#if end
1977
 
1978
				#解析 $TTL 的數值, 以及後面是否有註解...
1979
				#函式說明:
1980
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1981
				#回傳結果:
1982
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1983
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
1984
				#$result["function"],當前執行的函式名稱.
1985
				#$result["argu"],所使用的參數.
1986
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1987
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1988
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1989
				#必填參數:
1990
				#$conf["input"],字串,要檢查的字串.
1991
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
1992
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1993
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
1994
				#可省略參數:
1995
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1996
				#$conf["varEqual"]=array(null,"found");
1997
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1998
				#$conf["varCon"]=array("no_tail"=>" not");
1999
				#參考資料:
2000
				#無.
2001
				#備註:
2002
				#無.
2003
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2004
				unset($conf["search::findSpecifyStrFormat"]);
2005
 
2006
				#如果執行異常
2007
				if($findSpecifyStrFormat["status"]==="false"){
2008
 
2009
					#設置錯誤識別
2010
					$result["status"]="false";
2011
 
2012
					#設置錯誤訊息
2013
					$result["error"]=$findSpecifyStrFormat;
2014
 
2015
					#回傳結果
2016
					return $result;
2017
 
2018
					}#if end
2019
 
2020
				#如果有數值跟註解
2021
				if($findSpecifyStrFormat["found"]==="true"){
2022
 
2023
					#儲存數值
2024
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
2025
 
2026
					#儲存註解
253 liveuser 2027
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
249 liveuser 2028
 
2029
					#儲存預設的 TTL
2030
					$result["defaultTTL"]=trim($info["value"]);
2031
 
2032
					#儲存解析好的RR
2033
					$result["content"][]=$info;
2034
 
2035
					#換下一行
2036
					continue;
2037
 
2038
					}#if end
2039
 
2040
				#執行到這邊代表剩下的內容都是 value
2041
				$info["value"]=$unFormatStr;
2042
 
2043
				#儲存預設的 TTL
2044
				$result["defaultTTL"]=trim($info["value"]);
2045
 
2046
				#儲存解析好的RR
2047
				$result["content"][]=$info;
2048
 
2049
				#換下一行
2050
				continue;
2051
 
2052
				}#if end
2053
 
2054
			#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
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
			#反之
2109
			else{
2110
 
2111
				#函式說明:
2112
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2113
				#回傳結果:
2114
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2115
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2116
				#$result["function"],當前執行的函式名稱.
2117
				#$result["argu"],所使用的參數.
2118
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2119
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2120
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2121
				#必填參數:
2122
				#$conf["input"],字串,要檢查的字串.
2123
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2124
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2125
				$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
2126
				#可省略參數:
2127
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2128
				#$conf["varEqual"]=array(null,"found");
2129
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2130
				#$conf["varCon"]=array("no_tail"=>" not");
2131
				#參考資料:
2132
				#無.
2133
				#備註:
2134
				#無.
2135
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2136
				unset($conf["search::findSpecifyStrFormat"]);
2137
 
2138
				#如果執行異常
2139
				if($findSpecifyStrFormat["status"]==="false"){
2140
 
2141
					#設置錯誤識別
2142
					$result["status"]="false";
2143
 
2144
					#設置錯誤訊息
2145
					$result["error"]=$findSpecifyStrFormat;
2146
 
2147
					#回傳結果
2148
					return $result;
2149
 
2150
					}#if end
2151
 
2152
				#如果存在"
2153
				if($findSpecifyStrFormat["found"]==="true"){
2154
 
2155
					#取得無"的內容
2156
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2157
 
2158
					#取得拆下來的含開頭"內容
2159
					$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
2160
 
2161
					}#if end
2162
 
2163
				#反之
2164
				else{
2165
 
2166
					#函式說明:
2167
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2168
					#回傳結果:
2169
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2170
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2171
					#$result["function"],當前執行的函式名稱.
2172
					#$result["argu"],所使用的參數.
2173
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2174
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2175
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2176
					#必填參數:
2177
					#$conf["input"],字串,要檢查的字串.
2178
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2179
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2180
					$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
2181
					#可省略參數:
2182
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2183
					#$conf["varEqual"]=array(null,"found");
2184
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2185
					#$conf["varCon"]=array("no_tail"=>" not");
2186
					#參考資料:
2187
					#無.
2188
					#備註:
2189
					#無.
2190
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2191
					unset($conf["search::findSpecifyStrFormat"]);
2192
 
2193
					#如果執行異常
2194
					if($findSpecifyStrFormat["status"]==="false"){
2195
 
2196
						#設置錯誤識別
2197
						$result["status"]="false";
2198
 
2199
						#設置錯誤訊息
2200
						$result["error"]=$findSpecifyStrFormat;
2201
 
2202
						#回傳結果
2203
						return $result;
2204
 
2205
						}#if end
2206
 
2207
					#如果存在";"
2208
					if($findSpecifyStrFormat["found"]==="true"){
2209
 
2210
						#取得無";"的內容
2211
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2212
 
2213
						#取得拆下來的含開頭";"內容
2214
						$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
2215
 
2216
						}#if end
2217
 
2218
					}#else end
2219
 
2220
				}#else end
2221
 
2222
			#檢查是否為 @ 開頭
2223
			#函式說明:
2224
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2225
			#回傳結果:
2226
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2227
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2228
			#$result["function"],當前執行的函式名稱.
2229
			#$result["argu"],所使用的參數.
2230
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2231
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2232
			#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2233
			#必填參數:
2234
			#$conf["input"],字串,要檢查的字串.
2235
			$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2236
			#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2237
			$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
2238
			#可省略參數:
2239
			#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2240
			#$conf["varEqual"]=array(null,"found");
2241
			#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2242
			#$conf["varCon"]=array("no_tail"=>" not");
2243
			#參考資料:
2244
			#無.
2245
			#備註:
2246
			#無.
2247
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2248
			unset($conf["search::findSpecifyStrFormat"]);
2249
 
2250
			#如果執行異常
2251
			if($findSpecifyStrFormat["status"]==="false"){
2252
 
2253
				#設置錯誤識別
2254
				$result["status"]="false";
2255
 
2256
				#設置錯誤訊息
2257
				$result["error"]=$findSpecifyStrFormat;
2258
 
2259
				#回傳結果
2260
				return $result;
2261
 
2262
				}#if end
2263
 
2264
			#如果有找到符合格式的內容
2265
			if($findSpecifyStrFormat["found"]==="true"){
2266
 
2267
				#設置 query 的數值
2268
				$info["query"]="@";
2269
 
2270
				#取得後面待處理的內容
2271
				$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
2272
 
2273
				#函式說明:
2274
				#將字串開頭的特定關鍵字移除.
2275
				#回傳結果:
2276
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2277
				#$result["error"],錯誤訊息陣列.
2278
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2279
				#$result["function"],當前執行的函數名稱.
2280
				#$result["argu"],使用的參數.
2281
				#$result["content"],處理好的的字串內容.
2282
				#$result["deleted"],被移除的內容.
2283
				#必填參數:
2284
				#$conf["stringIn"],字串,要處理的字串.
2285
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2286
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2287
				$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
2288
				#可省略參數:
2289
				#無.
2290
				#參考資料:
2291
				#無.
2292
				#備註:
2293
				#無.
2294
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2295
				unset($conf["stringProcess::delHeadStr"]);
2296
 
2297
				#如果執行異常
2298
				if($delHeadStr["status"]==="false"){
2299
 
2300
					#設置錯誤識別
2301
					$result["status"]="false";
2302
 
2303
					#設置錯誤訊息
2304
					$result["error"]=$delHeadStr;
2305
 
2306
					#回傳結果
2307
					return $result;
2308
 
2309
					}#if end
2310
 
2311
				#如果有移除開頭的字串
2312
				if($delHeadStr["founded"]==="true"){
2313
 
2314
					#取得處理後的結果 update time..IN..type...value;comment
2315
					$unFormatStr=$delHeadStr["content"];
2316
 
2317
					}#if end
2318
 
2319
				#debug
2320
				#var_dump(__LINE__,$delHeadStr);
2321
 
2322
				}#if end
2323
 
2324
			#反之
2325
			else{
2326
 
2327
				#執行到這邊,代表 query 為一非 @ 的字串
2328
				#函式說明:
2329
				#將指令字串解析成陣列,方便給予 external::callShell 使用
2330
				#回傳結果:
2331
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2332
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2333
				#$result["function"],當前執行的函式名稱.
2334
				#$result["content"],解析好的指令陣列.
2335
				#$result["cmd"],解析好的指令名稱.
2336
				#$result["argus"],解析好的參數陣列.
2337
				#$result["argu"],所使用的參數.
2338
				#必填參數
2339
				#$conf["cmdStr"],字串,要解析的指令字串
2340
				$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
2341
				#可省略參數:
2342
				#無.
2343
				#參考資料:
2344
				#無.
2345
				#備註:
2346
				#無.
2347
				$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
2348
				unset($conf["stringProcess::parseCmdString"]);
2349
 
2350
				#如果執行失敗
2351
				if($parseCmdString["status"]==="false"){
2352
 
2353
					#設置錯誤識別
2354
					$result["status"]="false";
2355
 
2356
					#設置錯誤訊息
2357
					$result["error"]=$parseCmdString;
2358
 
2359
					#debug
2360
					#$result["errorProcessLine"]=$line;
2361
 
2362
					#回傳結果
2363
					return $result;
2364
 
2365
					}#if end
2366
 
2367
				#取得 query 的內容
2368
				$info["query"]=$parseCmdString["content"][0];
2369
 
2370
				#剔除 query以及後面的" "跟\t
2371
				#函式說明:
2372
				#將字串開頭的特定關鍵字移除.
2373
				#回傳結果:
2374
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2375
				#$result["error"],錯誤訊息陣列.
2376
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2377
				#$result["function"],當前執行的函數名稱.
2378
				#$result["argu"],使用的參數.
2379
				#$result["content"],處理好的的字串內容.
2380
				#$result["deleted"],被移除的內容.
2381
				#必填參數:
2382
				#$conf["stringIn"],字串,要處理的字串.
2383
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2384
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2385
				$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
2386
				#可省略參數:
2387
				#無.
2388
				#參考資料:
2389
				#無.
2390
				#備註:
2391
				#無.
2392
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2393
				unset($conf["stringProcess::delHeadStr"]);
2394
 
2395
				#如果執行異常
2396
				if($delHeadStr["status"]==="false"){
2397
 
2398
					#設置錯誤識別
2399
					$result["status"]="false";
2400
 
2401
					#設置錯誤訊息
2402
					$result["error"]=$delHeadStr;
2403
 
2404
					#回傳結果
2405
					return $result;
2406
 
2407
					}#if end
2408
 
2409
				#取得update time..IN..type...value;comment
2410
				$unFormatStr=$delHeadStr["content"];
2411
 
2412
				}#else end
2413
 
2414
			#無窮迴圈
2415
			while(true){
2416
 
253 liveuser 2417
				#如果要debug
2418
				if($conf["debug"]==="true"){
249 liveuser 2419
 
253 liveuser 2420
					#函式說明:
2421
					#撰寫log
2422
					#回傳結果:
2423
					#$result["status"],狀態,"true"或"false".
2424
					#$result["error"],錯誤訊息陣列.
2425
					#$result["function"],當前函式的名稱.
2426
					#$result["argu"],使用的參數.
2427
					#$result["content"],要寫入log的內容字串.
2428
					#必填參數:
2429
					#$conf["path"],字串,log檔案的路徑與名稱.
2430
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2431
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2432
					$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
2433
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2434
					$conf["logs::record"]["fileArgu"]=__FILE__;
2435
					#可省略參數:
2436
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2437
					#$conf["rewrite"]="false";
2438
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2439
					#$conf["returnOnly"]="true";
2440
					#參考資料:
2441
					#無.
2442
					#備註:
2443
					#無.
2444
					$record=logs::record($conf["logs::record"]);
2445
					unset($conf["logs::record"]);
2446
 
2447
					}#if end
2448
 
249 liveuser 2449
				#解析 updateTime..IN..type...value...comment
2450
 
2451
				#判斷是否無 update time
2452
 
2453
				#函式說明:
2454
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2455
				#回傳結果:
2456
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2457
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2458
				#$result["function"],當前執行的函式名稱.
2459
				#$result["argu"],所使用的參數.
2460
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2461
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2462
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2463
				#必填參數:
2464
				#$conf["input"],字串,要檢查的字串.
2465
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2466
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2467
				$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
2468
				#可省略參數:
2469
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2470
				#$conf["varEqual"]=array(null,"found");
2471
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2472
				#$conf["varCon"]=array("no_tail"=>" not");
2473
				#參考資料:
2474
				#無.
2475
				#備註:
2476
				#無.
2477
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2478
				unset($conf["search::findSpecifyStrFormat"]);
2479
 
2480
				#如果執行異常
2481
				if($findSpecifyStrFormat["status"]==="false"){
2482
 
2483
					#設置錯誤識別
2484
					$result["status"]="false";
2485
 
2486
					#設置錯誤訊息
2487
					$result["error"]=$findSpecifyStrFormat;
2488
 
2489
					#回傳結果
2490
					return $result;
2491
 
2492
					}#if end
2493
 
2494
				#如果有找到符合格式的內容
2495
				if($findSpecifyStrFormat["found"]==="true"){
2496
 
2497
					#代表沒有 update time 欄位,因此儲存預設的TTL
2498
					$info["update"]=&$result["defaultTTL"];
2499
 
2500
					#取得剩下的 ...type...value;comment
2501
					$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
2502
 
2503
					#設置該行沒有指定 update time
2504
					$noUpdateTime="true";
2505
 
253 liveuser 2506
					#如果要debug
2507
					if($conf["debug"]==="true"){
2508
 
2509
						#函式說明:
2510
						#撰寫log
2511
						#回傳結果:
2512
						#$result["status"],狀態,"true"或"false".
2513
						#$result["error"],錯誤訊息陣列.
2514
						#$result["function"],當前函式的名稱.
2515
						#$result["argu"],使用的參數.
2516
						#$result["content"],要寫入log的內容字串.
2517
						#必填參數:
2518
						#$conf["path"],字串,log檔案的路徑與名稱.
2519
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2520
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2521
						$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
2522
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2523
						$conf["logs::record"]["fileArgu"]=__FILE__;
2524
						#可省略參數:
2525
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2526
						#$conf["rewrite"]="false";
2527
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2528
						#$conf["returnOnly"]="true";
2529
						#參考資料:
2530
						#無.
2531
						#備註:
2532
						#無.
2533
						$record=logs::record($conf["logs::record"]);
2534
						unset($conf["logs::record"]);
2535
 
2536
						}#if end
249 liveuser 2537
 
2538
					}#if end
2539
 
2540
				#反之
2541
				else{
2542
 
2543
					#設置該行有指定 update time
2544
					$noUpdateTime="false";
2545
 
2546
					#如果有指定 update time
2547
					if($noUpdateTime==="false"){
2548
 
2549
						#要來解析 update time
2550
						#函式說明:
2551
						#將字串進行解析,變成多個參數.
2552
						#回傳結果:
2553
						#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2554
						#$result["function"],當前執行的函式內容.
2555
						#$result["error"],錯誤訊息陣列.
2556
						#$result["content"],參數陣列.
2557
						#$result["count"],總共有幾個參數.
2558
						#必填參數:
2559
						#$conf["input"],字串,要解析成參數的字串.
2560
						$conf["stringProcess::parse"]["input"]=$unFormatStr;
2561
						#可省略參數:
2562
						#無.
2563
						#參考資料:
2564
						#無.
2565
						#備註:
2566
						#無.
2567
						$parse=stringProcess::parse($conf["stringProcess::parse"]);
2568
						unset($conf["stringProcess::parse"]);
2569
 
2570
						#如果執行異常
2571
						if($parse["status"]==="false"){
2572
 
2573
							#設置錯誤識別
2574
							$result["status"]="false";
2575
 
2576
							#設置錯誤訊息
2577
							$result["error"]=$parse;
2578
 
2579
							#回傳結果
2580
							return $result;
2581
 
2582
							}#if end
2583
 
2584
						#取得更新時間
2585
						$info["update"]=$parse["content"][0];
2586
 
2587
						#取得 update time 後面的內容
2588
						#函式說明:
2589
						#將字串開頭的特定關鍵字移除.
2590
						#回傳結果:
2591
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2592
						#$result["error"],錯誤訊息陣列.
2593
						#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2594
						#$result["function"],當前執行的函數名稱.
2595
						#$result["argu"],使用的參數.
2596
						#$result["content"],處理好的的字串內容.
2597
						#$result["deleted"],被移除的內容.
2598
						#必填參數:
2599
						#$conf["stringIn"],字串,要處理的字串.
2600
						$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2601
						#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2602
						$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
2603
						#可省略參數:
2604
						#無.
2605
						#參考資料:
2606
						#無.
2607
						#備註:
2608
						#無.
2609
						$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2610
						unset($conf["stringProcess::delHeadStr"]);
2611
 
2612
						#如果執行異常
2613
						if($delHeadStr["status"]==="false"){
2614
 
2615
							#設置錯誤識別
2616
							$result["status"]="false";
2617
 
2618
							#設置錯誤訊息
2619
							$result["error"]=$delHeadStr;
2620
 
2621
							#回傳結果
2622
							return $result;
2623
 
2624
							}#if end
2625
 
2626
						#取得...IN...value;comment
2627
						$unFormatStr=$delHeadStr["content"];
2628
 
2629
						}#if end
2630
 
2631
					#取得 ...IN... 後面的內容
2632
					#函式說明:
2633
					#將字串開頭的特定關鍵字移除.
2634
					#回傳結果:
2635
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2636
					#$result["error"],錯誤訊息陣列.
2637
					#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2638
					#$result["function"],當前執行的函數名稱.
2639
					#$result["argu"],使用的參數.
2640
					#$result["content"],處理好的的字串內容.
2641
					#$result["deleted"],被移除的內容.
2642
					#必填參數:
2643
					#$conf["stringIn"],字串,要處理的字串.
2644
					$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2645
					#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2646
					$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
2647
					#可省略參數:
2648
					#無.
2649
					#參考資料:
2650
					#無.
2651
					#備註:
2652
					#無.
2653
					$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2654
					unset($conf["stringProcess::delHeadStr"]);
2655
 
2656
					#如果執行異常
2657
					if($delHeadStr["status"]==="false"){
2658
 
2659
						#設置錯誤識別
2660
						$result["status"]="false";
2661
 
2662
						#設置錯誤訊息
2663
						$result["error"]=$delHeadStr;
2664
 
2665
						#回傳結果
2666
						return $result;
2667
 
2668
						}#if end
2669
 
2670
					#取得IN...value;comment
2671
					$unFormatStr=$delHeadStr["content"];
2672
 
253 liveuser 2673
					#如果要debug
2674
					if($conf["debug"]==="true"){
249 liveuser 2675
 
253 liveuser 2676
						#函式說明:
2677
						#撰寫log
2678
						#回傳結果:
2679
						#$result["status"],狀態,"true"或"false".
2680
						#$result["error"],錯誤訊息陣列.
2681
						#$result["function"],當前函式的名稱.
2682
						#$result["argu"],使用的參數.
2683
						#$result["content"],要寫入log的內容字串.
2684
						#必填參數:
2685
						#$conf["path"],字串,log檔案的路徑與名稱.
2686
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2687
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2688
						$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
2689
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2690
						$conf["logs::record"]["fileArgu"]=__FILE__;
2691
						#可省略參數:
2692
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2693
						#$conf["rewrite"]="false";
2694
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2695
						#$conf["returnOnly"]="true";
2696
						#參考資料:
2697
						#無.
2698
						#備註:
2699
						#無.
2700
						$record=logs::record($conf["logs::record"]);
2701
						unset($conf["logs::record"]);
2702
 
2703
						}#if end
2704
 
249 liveuser 2705
					}#else end
2706
 
2707
				#解析 type...value;comment
2708
				#函式說明:
2709
				#將字串進行解析,變成多個參數.
2710
				#回傳結果:
2711
				#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
2712
				#$result["function"],當前執行的函式內容.
2713
				#$result["error"],錯誤訊息陣列.
2714
				#$result["content"],參數陣列.
2715
				#$result["count"],總共有幾個參數.
2716
				#必填參數:
2717
				#$conf["input"],字串,要解析成參數的字串.
2718
				$conf["stringProcess::parse"]["input"]=$unFormatStr;
2719
				#可省略參數:
2720
				#無.
2721
				#參考資料:
2722
				#無.
2723
				#備註:
2724
				#無.
2725
				$parse=stringProcess::parse($conf["stringProcess::parse"]);
2726
				unset($conf["stringProcess::parse"]);
2727
 
2728
				#如果執行異常
2729
				if($parse["status"]==="false"){
2730
 
2731
					#設置錯誤識別
2732
					$result["status"]="false";
2733
 
2734
					#設置錯誤訊息
2735
					$result["error"]=$parse;
2736
 
2737
					#回傳結果
2738
					return $result;
2739
 
2740
					}#if end
2741
 
2742
				#取得 type
2743
				$info["type"]=$parse["content"][0];
2744
 
2745
				#取得 type...後面的value;comment內容
2746
				#函式說明:
2747
				#將字串開頭的特定關鍵字移除.
2748
				#回傳結果:
2749
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2750
				#$result["error"],錯誤訊息陣列.
2751
				#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
2752
				#$result["function"],當前執行的函數名稱.
2753
				#$result["argu"],使用的參數.
2754
				#$result["content"],處理好的的字串內容.
2755
				#$result["deleted"],被移除的內容.
2756
				#必填參數:
2757
				#$conf["stringIn"],字串,要處理的字串.
2758
				$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
2759
				#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
2760
				$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
2761
				#可省略參數:
2762
				#無.
2763
				#參考資料:
2764
				#無.
2765
				#備註:
2766
				#無.
2767
				$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
2768
				unset($conf["stringProcess::delHeadStr"]);
2769
 
2770
				#如果執行異常
2771
				if($delHeadStr["status"]==="false"){
2772
 
2773
					#設置錯誤識別
2774
					$result["status"]="false";
2775
 
2776
					#設置錯誤訊息
2777
					$result["error"]=$delHeadStr;
2778
 
2779
					#回傳結果
2780
					return $result;
2781
 
2782
					}#if end
2783
 
2784
				#取得 value;comment
2785
				$unFormatStr=$delHeadStr["content"];
2786
 
2787
				#如果有要合併回去的內容
2788
				if(isset($unFormatStr2add)){
2789
 
2790
					#合併回去內容
2791
					$unFormatStr=$unFormatStr.$unFormatStr2add;
2792
 
2793
					#移除用不到的變數
2794
					unset($unFormatStr2add);
2795
 
2796
					}#if end
2797
 
253 liveuser 2798
				#如果要debug
2799
				if($conf["debug"]==="true"){
249 liveuser 2800
 
253 liveuser 2801
					#函式說明:
2802
					#撰寫log
2803
					#回傳結果:
2804
					#$result["status"],狀態,"true"或"false".
2805
					#$result["error"],錯誤訊息陣列.
2806
					#$result["function"],當前函式的名稱.
2807
					#$result["argu"],使用的參數.
2808
					#$result["content"],要寫入log的內容字串.
2809
					#必填參數:
2810
					#$conf["path"],字串,log檔案的路徑與名稱.
2811
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2812
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2813
					$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
2814
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2815
					$conf["logs::record"]["fileArgu"]=__FILE__;
2816
					#可省略參數:
2817
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2818
					#$conf["rewrite"]="false";
2819
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2820
					#$conf["returnOnly"]="true";
2821
					#參考資料:
2822
					#無.
2823
					#備註:
2824
					#無.
2825
					$record=logs::record($conf["logs::record"]);
2826
					unset($conf["logs::record"]);
2827
 
2828
					}#if end
2829
 
249 liveuser 2830
				#如果type不為 CNAME 跟 TXT 跟 SOA
2831
				if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" ){
2832
 
2833
					#儲存value
2834
					$info["value"]=$unFormatStr;
2835
 
2836
					#判斷是否有 ";" 存在
2837
					#函式說明:
2838
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2839
					#回傳結果:
2840
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2841
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2842
					#$result["function"],當前執行的函式名稱.
2843
					#$result["argu"],所使用的參數.
2844
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2845
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2846
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2847
					#必填參數:
2848
					#$conf["input"],字串,要檢查的字串.
2849
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2850
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2851
					$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
2852
					#可省略參數:
2853
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2854
					#$conf["varEqual"]=array(null,"found");
2855
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2856
					#$conf["varCon"]=array("no_tail"=>" not");
2857
					#參考資料:
2858
					#無.
2859
					#備註:
2860
					#無.
2861
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2862
					unset($conf["search::findSpecifyStrFormat"]);
2863
 
2864
					#如果執行異常
2865
					if($findSpecifyStrFormat["status"]==="false"){
2866
 
2867
						#設置錯誤識別
2868
						$result["status"]="false";
2869
 
2870
						#設置錯誤訊息
2871
						$result["error"]=$findSpecifyStrFormat;
2872
 
2873
						#回傳結果
2874
						return $result;
2875
 
2876
						}#if end
2877
 
2878
					#如果有 ";"
2879
					if($findSpecifyStrFormat["found"]==="true"){
2880
 
2881
						#儲存value
2882
						$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
2883
 
2884
						#儲存comment
2885
						$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
2886
 
2887
						}#if end
2888
 
2889
					#儲存該筆RR
2890
					$result["content"][]=$info;
2891
 
2892
					#解析完畢換下一行
2893
					continue 2;
2894
 
2895
					}#if end
2896
 
2897
				#執行到這邊,代表type為CNAME或TXT或SOA
2898
 
2899
				#如果 type 是 SOA
2900
				if($info["type"]==="SOA"){
2901
 
253 liveuser 2902
					#如果要debug
2903
					if($conf["debug"]==="true"){
2904
 
2905
						#函式說明:
2906
						#撰寫log
2907
						#回傳結果:
2908
						#$result["status"],狀態,"true"或"false".
2909
						#$result["error"],錯誤訊息陣列.
2910
						#$result["function"],當前函式的名稱.
2911
						#$result["argu"],使用的參數.
2912
						#$result["content"],要寫入log的內容字串.
2913
						#必填參數:
2914
						#$conf["path"],字串,log檔案的路徑與名稱.
2915
						$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
2916
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2917
						$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
2918
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2919
						$conf["logs::record"]["fileArgu"]=__FILE__;
2920
						#可省略參數:
2921
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2922
						#$conf["rewrite"]="false";
2923
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2924
						#$conf["returnOnly"]="true";
2925
						#參考資料:
2926
						#無.
2927
						#備註:
2928
						#無.
2929
						$record=logs::record($conf["logs::record"]);
2930
						unset($conf["logs::record"]);
2931
 
2932
						}#if end
2933
 
249 liveuser 2934
					#SOA 範例
2935
					#@	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
2936
 
2937
					#再度嘗試分割
2938
					#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
2939
 
2940
					#函式說明:
2941
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2942
					#回傳結果:
2943
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2944
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2945
					#$result["function"],當前執行的函式名稱.
2946
					#$result["argu"],所使用的參數.
2947
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2948
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2949
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
2950
					#必填參數:
2951
					#$conf["input"],字串,要檢查的字串.
2952
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
2953
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2954
					$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
2955
					#可省略參數:
2956
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2957
					#$conf["varEqual"]=array(null,"found");
2958
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2959
					#$conf["varCon"]=array("no_tail"=>" not");
2960
					#參考資料:
2961
					#無.
2962
					#備註:
2963
					#無.
2964
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2965
					unset($conf["search::findSpecifyStrFormat"]);
2966
 
2967
					#如果執行異常
2968
					if($findSpecifyStrFormat["status"]==="false"){
2969
 
2970
						#設置錯誤識別
2971
						$result["status"]="false";
2972
 
2973
						#設置錯誤訊息
2974
						$result["error"]=$findSpecifyStrFormat;
2975
 
2976
						#回傳結果
2977
						return $result;
2978
 
2979
						}#if end
2980
 
2981
					#如果存在"("
2982
					if($findSpecifyStrFormat["found"]==="true"){
2983
 
2984
						#取得無"("的內容
2985
						$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
2986
 
2987
						#取得拆下來的含開頭"("內容
2988
						$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
2989
 
2990
						}#if end
2991
 
2992
					#反之
2993
					else{
2994
 
2995
						#函式說明:
2996
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2997
						#回傳結果:
2998
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2999
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
3000
						#$result["function"],當前執行的函式名稱.
3001
						#$result["argu"],所使用的參數.
3002
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3003
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3004
						#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
3005
						#必填參數:
3006
						#$conf["input"],字串,要檢查的字串.
3007
						$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3008
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3009
						$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
3010
						#可省略參數:
3011
						#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3012
						#$conf["varEqual"]=array(null,"found");
3013
						#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3014
						#$conf["varCon"]=array("no_tail"=>" not");
3015
						#參考資料:
3016
						#無.
3017
						#備註:
3018
						#無.
3019
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3020
						unset($conf["search::findSpecifyStrFormat"]);
3021
 
3022
						#如果執行異常
3023
						if($findSpecifyStrFormat["status"]==="false"){
3024
 
3025
							#設置錯誤識別
3026
							$result["status"]="false";
3027
 
3028
							#設置錯誤訊息
3029
							$result["error"]=$findSpecifyStrFormat;
3030
 
3031
							#回傳結果
3032
							return $result;
3033
 
3034
							}#if end
3035
 
3036
						#如果存在"
3037
						if($findSpecifyStrFormat["found"]==="true"){
3038
 
3039
							#取得無"的內容
3040
							$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
3041
 
3042
							#取得拆下來的含開頭"內容
3043
							$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
3044
 
3045
							}#if end
3046
 
3047
						#反之
3048
						else{
3049
 
3050
							#函式說明:
3051
							#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3052
							#回傳結果:
3053
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3054
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
3055
							#$result["function"],當前執行的函式名稱.
3056
							#$result["argu"],所使用的參數.
3057
							#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3058
							#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3059
							#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
3060
							#必填參數:
3061
							#$conf["input"],字串,要檢查的字串.
3062
							$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3063
							#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3064
							$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
3065
							#可省略參數:
3066
							#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3067
							#$conf["varEqual"]=array(null,"found");
3068
							#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3069
							#$conf["varCon"]=array("no_tail"=>" not");
3070
							#參考資料:
3071
							#無.
3072
							#備註:
3073
							#無.
3074
							$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3075
							unset($conf["search::findSpecifyStrFormat"]);
3076
 
3077
							#如果執行異常
3078
							if($findSpecifyStrFormat["status"]==="false"){
3079
 
3080
								#設置錯誤識別
3081
								$result["status"]="false";
3082
 
3083
								#設置錯誤訊息
3084
								$result["error"]=$findSpecifyStrFormat;
3085
 
3086
								#回傳結果
3087
								return $result;
3088
 
3089
								}#if end
3090
 
3091
							#如果存在";"
3092
							if($findSpecifyStrFormat["found"]==="true"){
3093
 
3094
								#取得無";"的內容
3095
								$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
3096
 
3097
								#取得拆下來的含開頭";"內容
3098
								$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
3099
 
3100
								}#if end
3101
 
3102
							}#else end
3103
 
3104
						}#else end
3105
 
3106
					#取得 serial number
3107
					#函式說明:
3108
					#將字串進行解析,變成多個參數.
3109
					#回傳結果:
3110
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
3111
					#$result["function"],當前執行的函式內容.
3112
					#$result["error"],錯誤訊息陣列.
3113
					#$result["content"],參數陣列.
3114
					#$result["count"],總共有幾個參數.
3115
					#必填參數:
3116
					#$conf["input"],字串,要解析成參數的字串.
3117
					$conf["stringProcess::parse"]["input"]=$unFormatStr;
3118
					#可省略參數:
3119
					#無.
3120
					#參考資料:
3121
					#無.
3122
					#備註:
3123
					#無.
3124
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
3125
					unset($conf["stringProcess::parse"]);
3126
 
3127
					#如果執行異常
3128
					if($parse["status"]==="false"){
3129
 
3130
						#設置錯誤識別
3131
						$result["status"]="false";
3132
 
3133
						#設置錯誤訊息
3134
						$result["error"]=$parse;
3135
 
3136
						#回傳結果
3137
						return $result;
3138
 
3139
						}#if end
3140
 
3141
					#取得serial number
3142
					$serialNo=$parse["content"][2];
3143
 
3144
					#serialNo+1
3145
					$serialNo++;
3146
 
3147
					#回存
3148
					$parse["content"][2]=(string)$serialNo;
3149
 
3150
					#函式說明:
3151
					#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
3152
					#回傳的結果:
3153
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3154
					#$result["function"],當前執行的function名稱
3155
					#$result["error"],錯誤訊息陣列.
3156
					#$result["content"],處理好的字串.
3157
					#$result["argu"],使用的參數.
3158
					#必填參數:
3159
					#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
3160
					$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
3161
					#可省略參數:
3162
					#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
3163
					$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
3164
					#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
3165
					$conf["arrays::arrayToString"]["skipEnd"]="true";
3166
					#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
3167
					#$conf["spiltSymbolAtStart"]="";
3168
					#參考資料:
3169
					#無.
3170
					#備註:
3171
					#無.
3172
					$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
3173
					unset($conf["arrays::arrayToString"]);
3174
 
3175
					#如果執行異常
3176
					if($arrayToString["status"]==="false"){
3177
 
3178
						#設置錯誤識別
3179
						$result["status"]="false";
3180
 
3181
						#設置錯誤訊息
3182
						$result["error"]=$arrayToString;
3183
 
3184
						#回傳結果
3185
						return $result;
3186
 
3187
						}#if end
3188
 
3189
					#取得更新 serial number 後的 SOA value string
3190
					$unFormatStr=$arrayToString["content"];
3191
 
3192
					#如果有要合併回去的內容
3193
					if(isset($unFormatStr2add)){
3194
 
3195
						#合併回去內容
3196
						$unFormatStr=$unFormatStr.$unFormatStr2add;
3197
 
3198
						#移除用不到的變數
3199
						unset($unFormatStr2add);
3200
 
3201
						}#if end
3202
 
3203
					#假設剩下的沒有註解都是 value
3204
					$info["value"]=$unFormatStr;
3205
 
3206
					#函式說明:
3207
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3208
					#回傳結果:
3209
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3210
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
3211
					#$result["function"],當前執行的函式名稱.
3212
					#$result["argu"],所使用的參數.
3213
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3214
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3215
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3216
					#必填參數:
3217
					#$conf["input"],字串,要檢查的字串.
3218
					$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3219
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3220
					$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3221
					#可省略參數:
3222
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3223
					#$conf["varEqual"]=array(null,"found");
3224
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3225
					#$conf["varCon"]=array("no_tail"=>" not");
3226
					#參考資料:
3227
					#無.
3228
					#備註:
3229
					#無.
3230
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3231
					unset($conf["search::findSpecifyStrFormat"]);
3232
 
3233
					#如果執行異常
3234
					if($findSpecifyStrFormat["status"]==="false"){
3235
 
3236
						#設置錯誤識別
3237
						$result["status"]="false";
3238
 
3239
						#設置錯誤訊息
3240
						$result["error"]=$findSpecifyStrFormat;
3241
 
3242
						#回傳結果
3243
						return $result;
3244
 
3245
						}#if end
3246
 
3247
					#如果有符合格式
3248
					if($findSpecifyStrFormat["found"]==="true"){
3249
 
3250
						#儲存 value
3251
						$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3252
 
3253
						#儲存 comment
3254
						$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3255
 
3256
						}#if end
3257
 
3258
					#儲存該筆RR
3259
					$result["content"][]=$info;
3260
 
3261
					#換下解析下筆RR
3262
					continue 2;
3263
 
3264
					}#if end
3265
 
3266
				#執行到這邊代表不是 SOA
3267
 
3268
				#尋找是否有(...)...的內容存在
3269
				#函式說明:
3270
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3271
				#回傳結果:
3272
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3273
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3274
				#$result["function"],當前執行的函式名稱.
3275
				#$result["argu"],所使用的參數.
3276
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3277
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3278
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3279
				#必填參數:
3280
				#$conf["input"],字串,要檢查的字串.
3281
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3282
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3283
				$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
3284
				#可省略參數:
3285
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3286
				#$conf["varEqual"]=array(null,"found");
3287
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3288
				#$conf["varCon"]=array("no_tail"=>" not");
3289
				#參考資料:
3290
				#無.
3291
				#備註:
3292
				#無.
3293
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3294
				unset($conf["search::findSpecifyStrFormat"]);
3295
 
3296
				#如果執行異常
3297
				if($findSpecifyStrFormat["status"]==="false"){
3298
 
3299
					#設置錯誤識別
3300
					$result["status"]="false";
3301
 
3302
					#設置錯誤訊息
3303
					$result["error"]=$findSpecifyStrFormat;
3304
 
3305
					#回傳結果
3306
					return $result;
3307
 
3308
					}#if end
3309
 
3310
				#如果有 有符合 ($value);${comment} 的格式
3311
				if($findSpecifyStrFormat["found"]==="true"){
3312
 
3313
					#儲存value
3314
					$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
3315
 
3316
					#儲存comment
3317
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3318
 
3319
					#儲存 RR 的記錄
3320
					$result["content"][]=$info;
3321
 
3322
					#跳到下一筆要解析的RR
3323
					continue 2;
3324
 
3325
					}#if end
3326
 
3327
				#執行到這邊代表沒有 (...)... 的內容存在
3328
 
3329
				#尋找是否有 (...) 的內容存在
3330
				#函式說明:
3331
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3332
				#回傳結果:
3333
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3334
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3335
				#$result["function"],當前執行的函式名稱.
3336
				#$result["argu"],所使用的參數.
3337
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3338
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3339
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3340
				#必填參數:
3341
				#$conf["input"],字串,要檢查的字串.
3342
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3343
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3344
				$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
3345
				#可省略參數:
3346
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3347
				#$conf["varEqual"]=array(null,"found");
3348
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3349
				#$conf["varCon"]=array("no_tail"=>" not");
3350
				#參考資料:
3351
				#無.
3352
				#備註:
3353
				#無.
3354
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3355
				unset($conf["search::findSpecifyStrFormat"]);
3356
 
3357
				#如果執行異常
3358
				if($findSpecifyStrFormat["status"]==="false"){
3359
 
3360
					#設置錯誤識別
3361
					$result["status"]="false";
3362
 
3363
					#設置錯誤訊息
3364
					$result["error"]=$findSpecifyStrFormat;
3365
 
3366
					#回傳結果
3367
					return $result;
3368
 
3369
					}#if end
3370
 
3371
				#如果有 有符合 ($value);${comment} 的格式
3372
				if($findSpecifyStrFormat["found"]==="true"){
3373
 
3374
					#儲存value
3375
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3376
 
3377
					#儲存 RR 的記錄
3378
					$result["content"][]=$info;
3379
 
3380
					#跳到下一筆要解析的RR
3381
					continue 2;
3382
 
3383
					}#if end
3384
 
3385
				#執行到這邊代表沒有 (...) 的內容存在
3386
 
3387
				#尋找有無 "...";... 的內容存在
3388
				#函式說明:
3389
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3390
				#回傳結果:
3391
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3392
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3393
				#$result["function"],當前執行的函式名稱.
3394
				#$result["argu"],所使用的參數.
3395
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3396
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3397
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3398
				#必填參數:
3399
				#$conf["input"],字串,要檢查的字串.
3400
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3401
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3402
				$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
3403
				#可省略參數:
3404
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3405
				#$conf["varEqual"]=array(null,"found");
3406
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3407
				#$conf["varCon"]=array("no_tail"=>" not");
3408
				#參考資料:
3409
				#無.
3410
				#備註:
3411
				#無.
3412
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3413
				unset($conf["search::findSpecifyStrFormat"]);
3414
 
3415
				#如果執行異常
3416
				if($findSpecifyStrFormat["status"]==="false"){
3417
 
3418
					#設置錯誤識別
3419
					$result["status"]="false";
3420
 
3421
					#設置錯誤訊息
3422
					$result["error"]=$findSpecifyStrFormat;
3423
 
3424
					#回傳結果
3425
					return $result;
3426
 
3427
					}#if end
3428
 
3429
				#如果有 有符合 "$value";${comment} 的格式
3430
				if($findSpecifyStrFormat["found"]==="true"){
3431
 
3432
					#儲存value
3433
					$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
3434
 
3435
					#儲存comment
3436
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3437
 
3438
					#儲存 RR 的記錄
3439
					$result["content"][]=$info;
3440
 
3441
					#跳到下一筆要解析的RR
3442
					continue 2;
3443
 
3444
					}#if end
3445
 
3446
				#執行到這邊代表沒有 "$value";${comment} 的格式
3447
 
3448
				#尋找有無 "..." 的內容存在
3449
				#函式說明:
3450
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3451
				#回傳結果:
3452
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3453
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3454
				#$result["function"],當前執行的函式名稱.
3455
				#$result["argu"],所使用的參數.
3456
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3457
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3458
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3459
				#必填參數:
3460
				#$conf["input"],字串,要檢查的字串.
3461
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3462
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3463
				$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
3464
				#可省略參數:
3465
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3466
				#$conf["varEqual"]=array(null,"found");
3467
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3468
				#$conf["varCon"]=array("no_tail"=>" not");
3469
				#參考資料:
3470
				#無.
3471
				#備註:
3472
				#無.
3473
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3474
				unset($conf["search::findSpecifyStrFormat"]);
3475
 
3476
				#如果執行異常
3477
				if($findSpecifyStrFormat["status"]==="false"){
3478
 
3479
					#設置錯誤識別
3480
					$result["status"]="false";
3481
 
3482
					#設置錯誤訊息
3483
					$result["error"]=$findSpecifyStrFormat;
3484
 
3485
					#回傳結果
3486
					return $result;
3487
 
3488
					}#if end
3489
 
3490
				#如果有 有符合 "$value" 的格式
3491
				if($findSpecifyStrFormat["found"]==="true"){
3492
 
3493
					#儲存value
3494
					$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
3495
 
3496
					#儲存 RR 的記錄
3497
					$result["content"][]=$info;
3498
 
3499
					#跳到下一筆要解析的RR
3500
					continue 2;
3501
 
3502
					}#if end
3503
 
3504
				#執行到這邊代表沒有 "$value" 格式的內容
3505
 
3506
				#檢查是否有 $value;$comment 格式的內容
3507
				#函式說明:
3508
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3509
				#回傳結果:
3510
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3511
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
3512
				#$result["function"],當前執行的函式名稱.
3513
				#$result["argu"],所使用的參數.
3514
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3515
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3516
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3517
				#必填參數:
3518
				#$conf["input"],字串,要檢查的字串.
3519
				$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
3520
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3521
				$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
3522
				#可省略參數:
3523
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3524
				#$conf["varEqual"]=array(null,"found");
3525
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3526
				#$conf["varCon"]=array("no_tail"=>" not");
3527
				#參考資料:
3528
				#無.
3529
				#備註:
3530
				#無.
3531
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3532
				unset($conf["search::findSpecifyStrFormat"]);
3533
 
3534
				#如果執行異常
3535
				if($findSpecifyStrFormat["status"]==="false"){
3536
 
3537
					#設置錯誤識別
3538
					$result["status"]="false";
3539
 
3540
					#設置錯誤訊息
3541
					$result["error"]=$findSpecifyStrFormat;
3542
 
3543
					#回傳結果
3544
					return $result;
3545
 
3546
					}#if end
3547
 
3548
				#如果有 有符合 "$value" 的格式
3549
				if($findSpecifyStrFormat["found"]==="true"){
3550
 
3551
					#儲存value
3552
					$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
3553
 
3554
					#儲存comment
3555
					$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
3556
 
3557
					#儲存 RR 的記錄
3558
					$result["content"][]=$info;
3559
 
3560
					#跳到下一筆要解析的RR
3561
					continue 2;
3562
 
3563
					}#if end
3564
 
3565
				#執行到這邊代表沒有 ${value};${comment} 格式的內容
3566
 
3567
				#亦即剩下的內容都是 value
3568
 
3569
				#儲存value
3570
				$info["value"]=$unFormatStr;
3571
 
3572
				#儲存 RR 的記錄
3573
				$result["content"][]=$info;
3574
 
3575
				#跳到下一筆要解析的RR
3576
				continue 2;
3577
 
3578
				}#while end
3579
 
3580
			}#foreach end
3581
 
253 liveuser 3582
		#如果要debug
3583
		if($conf["debug"]==="true"){
249 liveuser 3584
 
253 liveuser 3585
			#函式說明:
3586
			#撰寫log
3587
			#回傳結果:
3588
			#$result["status"],狀態,"true"或"false".
3589
			#$result["error"],錯誤訊息陣列.
3590
			#$result["function"],當前函式的名稱.
3591
			#$result["argu"],使用的參數.
3592
			#$result["content"],要寫入log的內容字串.
3593
			#必填參數:
3594
			#$conf["path"],字串,log檔案的路徑與名稱.
3595
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3596
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3597
			$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR fin.".PHP_EOL;
3598
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3599
			$conf["logs::record"]["fileArgu"]=__FILE__;
3600
			#可省略參數:
3601
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3602
			#$conf["rewrite"]="false";
3603
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3604
			#$conf["returnOnly"]="true";
3605
			#參考資料:
3606
			#無.
3607
			#備註:
3608
			#無.
3609
			$record=logs::record($conf["logs::record"]);
3610
			unset($conf["logs::record"]);
3611
 
3612
			}#if end
3613
 
249 liveuser 3614
		#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
3615
 
3616
		#針對每個要新增的RR記錄
255 liveuser 3617
		foreach($conf["add"] as $nri => $newRR){
249 liveuser 3618
 
255 liveuser 3619
			#如果要debug
3620
			if($conf["debug"]==="true"){
3621
 
3622
				#函式說明:
3623
				#撰寫log
3624
				#回傳結果:
3625
				#$result["status"],狀態,"true"或"false".
3626
				#$result["error"],錯誤訊息陣列.
3627
				#$result["function"],當前函式的名稱.
3628
				#$result["argu"],使用的參數.
3629
				#$result["content"],要寫入log的內容字串.
3630
				#必填參數:
3631
				#$conf["path"],字串,log檔案的路徑與名稱.
3632
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3633
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3634
				$conf["logs::record"]["content"]="lineNo:".__LINE__." ori newRR:".PHP_EOL;
3635
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3636
				$conf["logs::record"]["fileArgu"]=__FILE__;
3637
				#可省略參數:
3638
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3639
				#$conf["rewrite"]="false";
3640
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3641
				#$conf["returnOnly"]="true";
3642
				#參考資料:
3643
				#無.
3644
				#備註:
3645
				#無.
3646
				$record=logs::record($conf["logs::record"]);
3647
				unset($conf["logs::record"]);
3648
 
3649
				#函式說明:
3650
				#撰寫log
3651
				#回傳結果:
3652
				#$result["status"],狀態,"true"或"false".
3653
				#$result["error"],錯誤訊息陣列.
3654
				#$result["function"],當前函式的名稱.
3655
				#$result["argu"],使用的參數.
3656
				#$result["content"],要寫入log的內容字串.
3657
				#必填參數:
3658
				#$conf["path"],字串,log檔案的路徑與名稱.
3659
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3660
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3661
				$conf["logs::record"]["content"]=$newRR;
3662
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3663
				$conf["logs::record"]["fileArgu"]=__FILE__;
3664
				#可省略參數:
3665
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3666
				#$conf["rewrite"]="false";
3667
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3668
				#$conf["returnOnly"]="true";
3669
				#參考資料:
3670
				#無.
3671
				#備註:
3672
				#無.
3673
				$record=logs::record($conf["logs::record"]);
3674
				unset($conf["logs::record"]);
3675
 
3676
				}#if end
3677
 
3678
			#如果新的 RR 缺少必備的資訊
3679
			if(!isset($newRR["type"])){
3680
 
3681
				#設置執行異常
3682
				$result["status"]="false";
3683
 
3684
				#設置執行錯誤
3685
				$result["error"]="add參數的格式缺少type";
3686
 
3687
				#回傳結果
3688
				return $result;
3689
 
3690
				}#if end
3691
 
3692
			#如果 query 結尾不是"@"也不為"."結尾
3693
			if( ($newRR["query"]!=="@") && ($newRR["query"][strlen($newRR["query"])-1]!==".") ){
3694
 
3695
				#加上 "."
3696
				$conf["add"][$nri]["query"]=$newRR["query"]=$newRR["query"].".";
3697
 
3698
				}#if end
3699
 
3700
			#如果新的 query 為 $ORGIN 結尾
3701
			#函式說明:
3702
			#將字串特定關鍵字與其後面的內容剔除
3703
			#回傳結果:
3704
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3705
			#$result["error"],錯誤訊息陣列.
3706
			#$result["warning"],警告訊息鎮列.
3707
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
3708
			#$result["function"],當前執行的函數名稱.
3709
			#$result["oriStr"],要處理的原始字串內容.
3710
			#$result["content"],處理好的的字串內容.
3711
			#$result["deleted"],被移除的內容.
3712
			#$result["argu"],使用的參數.
3713
			#必填參數:
3714
			#$conf["stringIn"],字串,要處理的字串.
3715
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
3716
			#$conf["keyWord"],字串,特定字串.
3717
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["domain"];
3718
			#可省略參數:
3719
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
3720
			#$conf["deleteLastRepeatedOne"]="";
3721
			#參考資料:
3722
			#無.
3723
			#備註:
3724
			#無.
3725
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
3726
			unset($conf["stringProcess::delStrAfterKeyWord"]);
3727
 
3728
			#如果要debug
3729
			if($conf["debug"]==="true"){
3730
 
3731
				#函式說明:
3732
				#撰寫log
3733
				#回傳結果:
3734
				#$result["status"],狀態,"true"或"false".
3735
				#$result["error"],錯誤訊息陣列.
3736
				#$result["function"],當前函式的名稱.
3737
				#$result["argu"],使用的參數.
3738
				#$result["content"],要寫入log的內容字串.
3739
				#必填參數:
3740
				#$conf["path"],字串,log檔案的路徑與名稱.
3741
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3742
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3743
				$conf["logs::record"]["content"]="lineNo:".__LINE__." try process newRR with \$ORIGIN end".PHP_EOL;
3744
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3745
				$conf["logs::record"]["fileArgu"]=__FILE__;
3746
				#可省略參數:
3747
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3748
				#$conf["rewrite"]="false";
3749
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3750
				#$conf["returnOnly"]="true";
3751
				#參考資料:
3752
				#無.
3753
				#備註:
3754
				#無.
3755
				$record=logs::record($conf["logs::record"]);
3756
				unset($conf["logs::record"]);
3757
 
3758
				#函式說明:
3759
				#撰寫log
3760
				#回傳結果:
3761
				#$result["status"],狀態,"true"或"false".
3762
				#$result["error"],錯誤訊息陣列.
3763
				#$result["function"],當前函式的名稱.
3764
				#$result["argu"],使用的參數.
3765
				#$result["content"],要寫入log的內容字串.
3766
				#必填參數:
3767
				#$conf["path"],字串,log檔案的路徑與名稱.
3768
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3769
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3770
				$conf["logs::record"]["content"]=$delStrAfterKeyWord;
3771
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3772
				$conf["logs::record"]["fileArgu"]=__FILE__;
3773
				#可省略參數:
3774
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3775
				#$conf["rewrite"]="false";
3776
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3777
				#$conf["returnOnly"]="true";
3778
				#參考資料:
3779
				#無.
3780
				#備註:
3781
				#無.
3782
				$record=logs::record($conf["logs::record"]);
3783
				unset($conf["logs::record"]);
3784
 
3785
				}#if end
3786
 
3787
			#如果異常
3788
			if($delStrAfterKeyWord["status"]==="false"){
3789
 
3790
				#設置執行異常
3791
				$result["status"]="false";
3792
 
3793
				#設置執行錯誤
3794
				$result["error"]=$delStrAfterKeyWord;
3795
 
3796
				#回傳結果
3797
				return $result;
3798
 
3799
				}#if end
3800
 
3801
			#如果有找到 $ORIGIN 結尾
3802
			if($delStrAfterKeyWord["founded"]==="true"){
3803
 
3804
				#更新 query
3805
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
3806
 
3807
				#如果$newRR["query"] 變成 ""
3808
				if(empty($newRR["query"])){
3809
 
3810
					#變成 zone domain,亦即 $result["domain"]
3811
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
3812
 
3813
					}#if end
3814
 
3815
				#如果要debug
3816
				if($conf["debug"]==="true"){
3817
 
3818
					#函式說明:
3819
					#撰寫log
3820
					#回傳結果:
3821
					#$result["status"],狀態,"true"或"false".
3822
					#$result["error"],錯誤訊息陣列.
3823
					#$result["function"],當前函式的名稱.
3824
					#$result["argu"],使用的參數.
3825
					#$result["content"],要寫入log的內容字串.
3826
					#必填參數:
3827
					#$conf["path"],字串,log檔案的路徑與名稱.
3828
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3829
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3830
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
3831
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3832
					$conf["logs::record"]["fileArgu"]=__FILE__;
3833
					#可省略參數:
3834
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3835
					#$conf["rewrite"]="false";
3836
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3837
					#$conf["returnOnly"]="true";
3838
					#參考資料:
3839
					#無.
3840
					#備註:
3841
					#無.
3842
					$record=logs::record($conf["logs::record"]);
3843
					unset($conf["logs::record"]);
3844
 
3845
					#函式說明:
3846
					#撰寫log
3847
					#回傳結果:
3848
					#$result["status"],狀態,"true"或"false".
3849
					#$result["error"],錯誤訊息陣列.
3850
					#$result["function"],當前函式的名稱.
3851
					#$result["argu"],使用的參數.
3852
					#$result["content"],要寫入log的內容字串.
3853
					#必填參數:
3854
					#$conf["path"],字串,log檔案的路徑與名稱.
3855
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3856
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3857
					$conf["logs::record"]["content"]=$conf["add"][$nri];
3858
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3859
					$conf["logs::record"]["fileArgu"]=__FILE__;
3860
					#可省略參數:
3861
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3862
					#$conf["rewrite"]="false";
3863
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3864
					#$conf["returnOnly"]="true";
3865
					#參考資料:
3866
					#無.
3867
					#備註:
3868
					#無.
3869
					$record=logs::record($conf["logs::record"]);
3870
					unset($conf["logs::record"]);
3871
 
3872
					}#if end
3873
 
3874
				}#if end
3875
 
3876
			#如果新的 query 為 "." 結尾
3877
			#函式說明:
3878
			#將字串特定關鍵字與其後面的內容剔除
3879
			#回傳結果:
3880
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3881
			#$result["error"],錯誤訊息陣列.
3882
			#$result["warning"],警告訊息鎮列.
3883
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
3884
			#$result["function"],當前執行的函數名稱.
3885
			#$result["oriStr"],要處理的原始字串內容.
3886
			#$result["content"],處理好的的字串內容.
3887
			#$result["deleted"],被移除的內容.
3888
			#$result["argu"],使用的參數.
3889
			#必填參數:
3890
			#$conf["stringIn"],字串,要處理的字串.
3891
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
3892
			#$conf["keyWord"],字串,特定字串.
3893
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".";
3894
			#可省略參數:
3895
			#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
3896
			#$conf["deleteLastRepeatedOne"]="";
3897
			#參考資料:
3898
			#無.
3899
			#備註:
3900
			#無.
3901
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
3902
			unset($conf["stringProcess::delStrAfterKeyWord"]);
3903
 
3904
			#如果異常
3905
			if($delStrAfterKeyWord["status"]==="false"){
3906
 
3907
				#設置執行異常
3908
				$result["status"]="false";
3909
 
3910
				#設置執行錯誤
3911
				$result["error"]=$delStrAfterKeyWord;
3912
 
3913
				#回傳結果
3914
				return $result;
3915
 
3916
				}#if end
3917
 
3918
			#如果有找到 "." 結尾
3919
			if($delStrAfterKeyWord["founded"]==="true"){
3920
 
3921
				#更新 query
3922
				$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
3923
 
3924
				#如果 $newRR["query"] 變成 ""
3925
				if(empty($newRR["query"])){
3926
 
3927
					#變成 zone domain,亦即 $result["domain"]
3928
					$conf["add"][$nri]["query"]=$newRR["query"]="@";
3929
 
3930
					}#if end
3931
 
3932
				#如果要debug
3933
				if($conf["debug"]==="true"){
3934
 
3935
					#函式說明:
3936
					#撰寫log
3937
					#回傳結果:
3938
					#$result["status"],狀態,"true"或"false".
3939
					#$result["error"],錯誤訊息陣列.
3940
					#$result["function"],當前函式的名稱.
3941
					#$result["argu"],使用的參數.
3942
					#$result["content"],要寫入log的內容字串.
3943
					#必填參數:
3944
					#$conf["path"],字串,log檔案的路徑與名稱.
3945
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3946
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3947
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
3948
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3949
					$conf["logs::record"]["fileArgu"]=__FILE__;
3950
					#可省略參數:
3951
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3952
					#$conf["rewrite"]="false";
3953
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3954
					#$conf["returnOnly"]="true";
3955
					#參考資料:
3956
					#無.
3957
					#備註:
3958
					#無.
3959
					$record=logs::record($conf["logs::record"]);
3960
					unset($conf["logs::record"]);
3961
 
3962
					#函式說明:
3963
					#撰寫log
3964
					#回傳結果:
3965
					#$result["status"],狀態,"true"或"false".
3966
					#$result["error"],錯誤訊息陣列.
3967
					#$result["function"],當前函式的名稱.
3968
					#$result["argu"],使用的參數.
3969
					#$result["content"],要寫入log的內容字串.
3970
					#必填參數:
3971
					#$conf["path"],字串,log檔案的路徑與名稱.
3972
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
3973
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
3974
					$conf["logs::record"]["content"]=$conf["add"][$nri];
3975
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3976
					$conf["logs::record"]["fileArgu"]=__FILE__;
3977
					#可省略參數:
3978
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
3979
					#$conf["rewrite"]="false";
3980
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
3981
					#$conf["returnOnly"]="true";
3982
					#參考資料:
3983
					#無.
3984
					#備註:
3985
					#無.
3986
					$record=logs::record($conf["logs::record"]);
3987
					unset($conf["logs::record"]);
3988
 
3989
					}#if end
3990
 
3991
				}#if end
3992
 
3993
			#如果新 RR 的 type 不是 A 且 value 不為 "." 結尾.
3994
			if( $newRR["type"]!=="A" && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
3995
 
3996
				#new RR add dot to value end.
3997
				$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
3998
 
3999
				#如果要debug
4000
				if($conf["debug"]==="true"){
4001
 
4002
					#函式說明:
4003
					#撰寫log
4004
					#回傳結果:
4005
					#$result["status"],狀態,"true"或"false".
4006
					#$result["error"],錯誤訊息陣列.
4007
					#$result["function"],當前函式的名稱.
4008
					#$result["argu"],使用的參數.
4009
					#$result["content"],要寫入log的內容字串.
4010
					#必填參數:
4011
					#$conf["path"],字串,log檔案的路徑與名稱.
4012
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4013
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4014
					$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
4015
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4016
					$conf["logs::record"]["fileArgu"]=__FILE__;
4017
					#可省略參數:
4018
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4019
					#$conf["rewrite"]="false";
4020
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4021
					#$conf["returnOnly"]="true";
4022
					#參考資料:
4023
					#無.
4024
					#備註:
4025
					#無.
4026
					$record=logs::record($conf["logs::record"]);
4027
					unset($conf["logs::record"]);
4028
 
4029
					#函式說明:
4030
					#撰寫log
4031
					#回傳結果:
4032
					#$result["status"],狀態,"true"或"false".
4033
					#$result["error"],錯誤訊息陣列.
4034
					#$result["function"],當前函式的名稱.
4035
					#$result["argu"],使用的參數.
4036
					#$result["content"],要寫入log的內容字串.
4037
					#必填參數:
4038
					#$conf["path"],字串,log檔案的路徑與名稱.
4039
					$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4040
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4041
					$conf["logs::record"]["content"]=$conf["add"][$nri];
4042
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4043
					$conf["logs::record"]["fileArgu"]=__FILE__;
4044
					#可省略參數:
4045
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4046
					#$conf["rewrite"]="false";
4047
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4048
					#$conf["returnOnly"]="true";
4049
					#參考資料:
4050
					#無.
4051
					#備註:
4052
					#無.
4053
					$record=logs::record($conf["logs::record"]);
4054
					unset($conf["logs::record"]);
4055
 
4056
					}#if end
4057
 
4058
				}#if end
4059
 
249 liveuser 4060
			#針對 zone file 中既有的每個RR記錄
4061
			foreach($result["content"] as $index => $oldRR){
4062
 
4063
				#如果既有的跟新的RR都為 $ORIGIN
4064
				if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
4065
 
4066
					#取代既有的 RR
4067
					$result["content"][$index]=$newRR;
4068
 
4069
					#換看下一筆newRR
4070
					continue 2;
4071
 
4072
					}#if end
4073
 
4074
				#如果既有的跟新的RR都為 $TTL
4075
				if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
4076
 
4077
					#取代既有的 RR
4078
					$result["content"][$index]=$newRR;
4079
 
4080
					#換看下一筆newRR
4081
					continue 2;
4082
 
4083
					}#if end
4084
 
253 liveuser 4085
				#如果新舊資料都有query資訊
4086
				if( isset($newRR["query"]) && isset($oldRR["query"]) ){
249 liveuser 4087
 
253 liveuser 4088
					#如果跟既有的 query、type、value 有相同
4089
					if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
249 liveuser 4090
 
253 liveuser 4091
						#如果新 RR 有 update time
4092
						if(isset($newRR["update"])){
249 liveuser 4093
 
253 liveuser 4094
							#如果新舊 update time 不相同
4095
							if( $newRR["update"] !== $oldRR["update"] ){
249 liveuser 4096
 
253 liveuser 4097
								#取代既有的 RR
4098
								$result["content"][$index]=$newRR;
4099
 
4100
								#換看下一筆newRR
4101
								continue 2;
4102
 
4103
								}#if end
4104
 
4105
							}#if end
249 liveuser 4106
 
253 liveuser 4107
						#反之既有的 update time 若跟 global TTL 不一樣
4108
						else if( $oldRR["update"] !== $result["defaultTTL"] ){
4109
 
4110
							#更新為 global TTL
4111
							$result["content"][$index]["update"]=$result["defaultTTL"];
4112
 
249 liveuser 4113
							}#if end
253 liveuser 4114
 
4115
						#如果新 RR 有 comment
4116
						if( isset($newRR["comment"]) ){
249 liveuser 4117
 
253 liveuser 4118
							#更新既有 RR 的 comment
4119
							$result["content"][$index]["comment"]=$newRR["comment"];
249 liveuser 4120
 
253 liveuser 4121
							#換看下一筆newRR
4122
							continue 2;
249 liveuser 4123
 
253 liveuser 4124
							}#if end
4125
 
4126
						#反之,如果有既有 comment
4127
						else if(isset($result["content"][$index]["comment"])){
249 liveuser 4128
 
253 liveuser 4129
							#移除既有 comment
4130
							unset($result["content"][$index]["comment"]);
4131
 
4132
							#換看下一筆newRR
4133
							continue 2;
249 liveuser 4134
 
253 liveuser 4135
							}#else end
249 liveuser 4136
 
253 liveuser 4137
						}#if end
249 liveuser 4138
 
4139
					}#if end
253 liveuser 4140
 
249 liveuser 4141
				}#foreach end
4142
 
4143
			#儲存確定要新增的RR
4144
			$result["content"][]=$newRR;
4145
 
4146
			}#foreach end
4147
 
255 liveuser 4148
		#如果要debug
4149
		if($conf["debug"]==="true"){
249 liveuser 4150
 
255 liveuser 4151
			#函式說明:
4152
			#撰寫log
4153
			#回傳結果:
4154
			#$result["status"],狀態,"true"或"false".
4155
			#$result["error"],錯誤訊息陣列.
4156
			#$result["function"],當前函式的名稱.
4157
			#$result["argu"],使用的參數.
4158
			#$result["content"],要寫入log的內容字串.
4159
			#必填參數:
4160
			#$conf["path"],字串,log檔案的路徑與名稱.
4161
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4162
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4163
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
4164
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4165
			$conf["logs::record"]["fileArgu"]=__FILE__;
4166
			#可省略參數:
4167
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4168
			#$conf["rewrite"]="false";
4169
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4170
			#$conf["returnOnly"]="true";
4171
			#參考資料:
4172
			#無.
4173
			#備註:
4174
			#無.
4175
			$record=logs::record($conf["logs::record"]);
4176
			unset($conf["logs::record"]);
249 liveuser 4177
 
255 liveuser 4178
			}#if end
4179
 
4180
		#如果要debug
4181
		if($conf["debug"]==="true"){
4182
 
4183
			#函式說明:
4184
			#撰寫log
4185
			#回傳結果:
4186
			#$result["status"],狀態,"true"或"false".
4187
			#$result["error"],錯誤訊息陣列.
4188
			#$result["function"],當前函式的名稱.
4189
			#$result["argu"],使用的參數.
4190
			#$result["content"],要寫入log的內容字串.
4191
			#必填參數:
4192
			#$conf["path"],字串,log檔案的路徑與名稱.
4193
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4194
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4195
			$conf["logs::record"]["content"]=$result["content"];
4196
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4197
			$conf["logs::record"]["fileArgu"]=__FILE__;
4198
			#可省略參數:
4199
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4200
			#$conf["rewrite"]="false";
4201
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4202
			#$conf["returnOnly"]="true";
4203
			#參考資料:
4204
			#無.
4205
			#備註:
4206
			#無.
4207
			$record=logs::record($conf["logs::record"]);
4208
			unset($conf["logs::record"]);
4209
 
4210
			}#if end
4211
 
249 liveuser 4212
		#初始化要寫入的內容
4213
		$strs2write=array();
4214
 
4215
		#針對每個RR記錄
4216
		foreach($result["content"] as $RR){
4217
 
4218
			#初始化暫存要寫入的行內容
4219
			$str2write="";
4220
 
4221
			#如果是
4222
			if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
4223
 
4224
				#組合變數名稱與數值
4225
				$str2write=$str2write.$RR["type"]."\t".$RR["value"];
4226
 
4227
				}#if end
4228
 
4229
			#反之
4230
			else{
4231
 
4232
				#加上查詢的字句
4233
				$str2write=$str2write.$RR["query"];
4234
 
4235
				#如果該筆RR有指定update time該ZONE具備 global TTL.
4236
				if(isset($RR["update"])){
4237
 
4238
					#如果 該ZONE具備 global TTL.
4239
					if(isset($result["defaultTTL"])){
4240
 
4241
						#如果該筆 RR 的 update time 不等於 global TTL
4242
						if($RR["update"]!==$result["defaultTTL"]){
4243
 
4244
							#加上TTL的字句
4245
							$str2write=$str2write."\t".$RR["update"];
4246
 
4247
							}#if end
4248
 
4249
						}#if end
4250
 
4251
					#反之
4252
					else{
4253
 
4254
						#加上TTL的字句
4255
						$str2write=$str2write."\t".$RR["update"];
4256
 
4257
						}#else end
4258
 
4259
					}#if end
4260
 
253 liveuser 4261
				#反之且該ZONE不具備 global TTL.
4262
				else if(!isset($result["defaultTTL"])){
249 liveuser 4263
 
4264
					#加上global TTL的字句
4265
					$str2write=$str2write."\t".$result["defaultTTL"];
4266
 
253 liveuser 4267
					}#if end
249 liveuser 4268
 
4269
				#加上IN跟TYPE跟value
4270
				$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
4271
 
4272
				}#else end
4273
 
4274
			#如果有註解
4275
			if(isset($RR["comment"])){
4276
 
4277
				#加上comment
4278
				$str2write=$str2write.";".$RR["comment"];
4279
 
4280
				}#if end
4281
 
253 liveuser 4282
			#如果要 debug
4283
			if($conf["debug"]==="true"){
249 liveuser 4284
 
253 liveuser 4285
				#函式說明:
4286
				#撰寫log
4287
				#回傳結果:
4288
				#$result["status"],狀態,"true"或"false".
4289
				#$result["error"],錯誤訊息陣列.
4290
				#$result["function"],當前函式的名稱.
4291
				#$result["argu"],使用的參數.
4292
				#$result["content"],要寫入log的內容字串.
4293
				#必填參數:
4294
				#$conf["path"],字串,log檔案的路徑與名稱.
4295
				$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4296
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4297
				$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
4298
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4299
				$conf["logs::record"]["fileArgu"]=__FILE__;
4300
				#可省略參數:
4301
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4302
				#$conf["rewrite"]="false";
4303
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4304
				#$conf["returnOnly"]="true";
4305
				#參考資料:
4306
				#無.
4307
				#備註:
4308
				#無.
4309
				$record=logs::record($conf["logs::record"]);
4310
				unset($conf["logs::record"]);
4311
 
4312
				}#if end
4313
 
249 liveuser 4314
			#加上要寫入的元素
4315
			$strs2write[]=$str2write;
4316
 
4317
			}#foreach end
4318
 
4319
		#如果有逐行註解
4320
		if(count($result["comment"])>0){
4321
 
4322
			#加到結尾
4323
			#函式說明:
4324
			#將多個一維陣列串聯起來,key從0開始排序.
4325
			#回傳的結果:
4326
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
4327
			#$result["error"],錯誤訊息陣列.
4328
			#$result["function"],當前執行的函數.
4329
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4330
			#$result["content"],合併好的一維陣列.
4331
			#必填參數
4332
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
4333
			$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
4334
			#可省略參數:
4335
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
4336
			#$conf["allowRepeat"]="true";
4337
			#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
4338
			#$conf["looseDiff"]="false";
4339
			#參考資料:
4340
			#無.
4341
			#備註:
4342
			#無.
4343
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
4344
			unset($conf["arrays::mergeArray"]);
4345
 
4346
			#如果執行異常
4347
			if($mergeArray["status"]==="false"){
4348
 
4349
				#設置錯誤識別
4350
				$result["status"]="false";
4351
 
4352
				#設置錯誤訊息
4353
				$result["error"]=$mergeArray;
4354
 
4355
				#回傳結果
4356
				return $result;
4357
 
4358
				}#if end
4359
 
4360
			#取得合併好的陣列
4361
			$strs2write=$mergeArray["content"];
4362
 
4363
			}#if end
4364
 
253 liveuser 4365
		#如果要 debug
4366
		if($conf["debug"]==="true"){
249 liveuser 4367
 
253 liveuser 4368
			#函式說明:
4369
			#撰寫log
4370
			#回傳結果:
4371
			#$result["status"],狀態,"true"或"false".
4372
			#$result["error"],錯誤訊息陣列.
4373
			#$result["function"],當前函式的名稱.
4374
			#$result["argu"],使用的參數.
4375
			#$result["content"],要寫入log的內容字串.
4376
			#必填參數:
4377
			#$conf["path"],字串,log檔案的路徑與名稱.
4378
			$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
4379
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
4380
			$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
4381
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4382
			$conf["logs::record"]["fileArgu"]=__FILE__;
4383
			#可省略參數:
4384
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
4385
			#$conf["rewrite"]="false";
4386
			#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
4387
			#$conf["returnOnly"]="true";
4388
			#參考資料:
4389
			#無.
4390
			#備註:
4391
			#無.
4392
			$record=logs::record($conf["logs::record"]);
4393
			unset($conf["logs::record"]);
4394
 
4395
			}#if end
4396
 
249 liveuser 4397
		#儲存新zone file每行的內容
4398
		$result["newZoneFileContent"]=$strs2write;
4399
 
4400
		#如果要寫入ZONE檔案
4401
		if($conf["writeNow"]==="true"){
4402
 
4403
			#覆寫 ZONE file
4404
			#函式說明:
4405
			#更新檔案的內容.
4406
			#回傳結果:
4407
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4408
			#$result["error"],錯誤訊息.
4409
			#$result["function"],當前執行的函數名稱.
4410
			#$result["content"],更新的資訊.
4411
			#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
4412
			#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
4413
			#必填參數:
4414
			#$conf["fileArgu"],字串,變數__FILE__的內容.
4415
			$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
4416
			#$conf["file"],字串,要更新的檔案位置與名稱.
4417
			$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
4418
			#可省略參數:
4419
			#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
4420
			$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
4421
			#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
4422
			#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
4423
			#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
4424
			#$conf["replaceLike"]="false";
4425
			#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
4426
			#$conf["addToTailWhenNoMatch"]="false";
4427
			#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
4428
			#$conf["addToTailBeforeThat"]="?\>";
4429
			#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
4430
			#$conf["replaceSpecifyLine"]=array();
4431
			#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
4432
			#$conf["outputPath"]="";
4433
			#參考資料:
4434
			#無.
4435
			#備註:
4436
			#無.
4437
			$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
4438
			unset($conf["fileAccess::updateFile"]);
4439
 
4440
			#如果執行異常
4441
			if($updateFile["status"]==="false"){
4442
 
4443
				#設置錯誤識別
4444
				$result["status"]="false";
4445
 
4446
				#設置錯誤訊息
4447
				$result["error"]=$updateFile;
4448
 
4449
				#回傳結果
4450
				return $result;
4451
 
4452
				}#if end
4453
 
4454
			}#if end
4455
 
4456
		#設置執行正常
4457
		$result["status"]="true";
4458
 
4459
		#回傳結果
4460
		return $result;
4461
 
4462
		}#function updateDnsRecordFile end
4463
 
4464
	/*
4465
	#函式說明:
255 liveuser 4466
	#請求驗證已經透過zerossl::createCertificate要求的domain.
249 liveuser 4467
	#回傳結果:
4468
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4469
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
4470
	#$result["function"],當前執行的函式名稱.
4471
	#$result["argu"],所使用的參數.
4472
	#$result["curl_verbose_info"],curl執行的詳細資訊.
255 liveuser 4473
	#$result["content"],結果json字串.
249 liveuser 4474
	#必填參數:
4475
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
4476
	$conf["id"]="";
4477
	#可省略參數:
4478
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
4479
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
4480
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
4481
	#$conf["key"]=self::getApiInfo()["apiKey"];
4482
	#參考資料:
255 liveuser 4483
	#https://zerossl.com/documentation/api/verify-domains/
249 liveuser 4484
	#備註:
4485
	#無.
4486
	*/
4487
	public static function verifyDomain(&$conf){
4488
 
4489
		#初始化要回傳的結果
4490
		$result=array();
4491
 
4492
		#設置當其函數名稱
4493
		$result["function"]=__FUNCTION__;
4494
 
4495
		#如果 $conf 不為陣列
4496
		if(gettype($conf)!="array"){
4497
 
4498
			#設置執行失敗
4499
			$result["status"]="false";
4500
 
4501
			#設置執行錯誤訊息
4502
			$result["error"][]="\$conf變數須為陣列形態";
4503
 
4504
			#如果傳入的參數為 null
4505
			if($conf==null){
4506
 
4507
				#設置執行錯誤訊息
4508
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
4509
 
4510
				}#if end
4511
 
4512
			#回傳結果
4513
			return $result;
4514
 
4515
			}#if end
4516
 
4517
		#取得參數
4518
		$result["argu"]=$conf;
4519
 
4520
		#檢查參數
4521
		#函式說明:
4522
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4523
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4524
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4525
		#$result["function"],當前執行的函式名稱.
4526
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4527
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4528
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4529
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4530
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4531
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4532
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4533
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4534
		#必填寫的參數:
4535
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4536
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4537
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4538
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
4539
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
4540
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4541
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4542
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4543
		#可以省略的參數:
4544
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4545
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
4546
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
4547
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4548
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4549
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
4550
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
4551
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
4552
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 4553
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
249 liveuser 4554
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4555
		#$conf["arrayCountEqualCheck"][]=array();
4556
		#參考資料來源:
4557
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4558
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4559
		unset($conf["variableCheck::checkArguments"]);
4560
 
4561
		#如果檢查失敗
4562
		if($checkArguments["status"]==="false"){
4563
 
4564
			#設置錯誤識別
4565
			$result["status"]="false";
4566
 
4567
			#設置錯誤訊息
4568
			$result["error"]=$checkArguments;
4569
 
4570
			#回傳結果
4571
			return $result;
4572
 
4573
			}#if end
4574
 
4575
		#如果檢查不通過
4576
		if($checkArguments["passed"]==="false"){
4577
 
4578
			#設置錯誤識別
4579
			$result["status"]="false";
4580
 
4581
			#設置錯誤訊息
4582
			$result["error"]=$checkArguments;
4583
 
4584
			#回傳結果
4585
			return $result;
4586
 
4587
			}#if end
4588
 
4589
		#要傳送的 key -> value
4590
		$postArray=array();
4591
 
4592
		#設置要簽署的domain
4593
		$postArray["validation_method"]="CNAME_CSR_HASH";
4594
 
4595
		#設置要傳送的 json
4596
		$postJson=json_encode($postArray);
4597
 
4598
		#函式說明:
4599
		#運行curl cmd
4600
		#回傳結果:
4601
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4602
		#$result["error"],錯誤訊息陣列.
4603
		#$result["function"],當前執行的函式名稱.
4604
		#$result["founded"],識別網址找不找得到.
4605
		#$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"代表程序的資訊.
4606
		#$result["fullContent"],取得回應的完整字串內容.
4607
		#$result["cookie"],cookie檔案的位置與名稱.
4608
		#$result["cmd"],執行的command.
4609
		#$result["argu],使用的參數.
4610
		#必填參數:
4611
		#$conf["url"],字串,目標url.
255 liveuser 4612
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
249 liveuser 4613
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4614
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
4615
		#可省略參數:
4616
		#$conf["header"],字串陣列,要傳送的header.
4617
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
4618
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
4619
		#$conf["allowAnySSLcertificate"]="";
4620
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
4621
		#$conf["postVar"]=array();
4622
		#$conf["rawPost"]="字串",要傳送的raw post內容.
4623
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
4624
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
4625
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
4626
		#$conf["agent"],字串,user agent的名稱.
4627
		#$conf["agent"]="";
4628
		#$conf["cookie"],字串,cookie位置與檔案位置.
4629
		#$conf["cookie"]="";
4630
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
4631
		#$conf["forceNewCookie"]="";
4632
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
4633
		#$conf["inBg"]="true";
4634
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
4635
		#$conf["bgInProc"]="false";
4636
		#參考資料:
4637
		#無.
4638
		#備註:
4639
		#無.
4640
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
4641
		unset($conf["catchWebContent::curlCmd"]);
4642
 
4643
		#如果異常
4644
		if($curlCmd["status"]==="false"){
4645
 
4646
			#設置錯誤識別
4647
			$result["status"]="false";
4648
 
4649
			#設置錯誤訊息
4650
			$result["error"]=$curlCmd;
4651
 
4652
			#回傳結果
4653
			return $result;
4654
 
4655
			}#if end
4656
 
4657
		#設置curl的詳細資訊
4658
		$result["curl_verbose_info"]=$curlCmd;
4659
 
255 liveuser 4660
		#驗證結果是否為 json
4661
		$json_validate=json_validate($curlCmd["fullContent"]);
4662
 
4663
		#如果回應不是 json
4664
		if(!$json_validate){
249 liveuser 4665
 
255 liveuser 4666
			#設置錯誤識別
4667
			$result["status"]="false";
4668
 
4669
			#設置錯誤訊息
4670
			$result["error"]=$curlCmd;
4671
 
4672
			#回傳結果
4673
			return $result;
4674
 
4675
			}#if end
4676
 
4677
		#設置json string結果
4678
		$result["content"]=$curlCmd["fullContent"];
4679
 
4680
		#解析json
4681
		$jsonRes=json_decode($result["content"]);
4682
 
4683
		#如果沒有 status
4684
		if(!isset($jsonRes->status)){
4685
 
4686
			#設置錯誤識別
4687
			$result["status"]="false";
4688
 
4689
			#設置錯誤訊息
4690
			$result["error"]=$curlCmd;
4691
 
4692
			#回傳結果
4693
			return $result;
4694
 
4695
			}#if end
4696
 
4697
		#如果是 "pending_validation"
4698
		if($json->status==="pending_validation"){
4699
 
4700
			#do nothing
4701
 
4702
			}#if end
4703
 
4704
		#反之如果為 "issued"
4705
		else if($json->status==="issued"){
4706
 
4707
			#do nothing
4708
 
4709
			}#else 
4710
 
4711
		#反之
4712
		else{
4713
 
4714
			#設置錯誤識別
4715
			$result["status"]="false";
4716
 
4717
			#設置錯誤訊息
4718
			$result["error"]=$curlCmd;
4719
 
4720
			#回傳結果
4721
			return $result;
4722
 
4723
			}#else end
4724
 
4725
 
4726
		#設置執行正常
4727
		$result["status"]="true";
4728
 
4729
		#回傳結果
4730
		return $result;
4731
 
4732
		}#function verifyDomain end
4733
 
4734
	/*
4735
	#函式說明:
4736
	#取得CSR在zerossl上的狀態
4737
	#回傳結果:
4738
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4739
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
4740
	#$result["function"],當前執行的函式名稱.
4741
	#$result["argu"],所使用的參數.
4742
	#$result["curl_verbose_info"],curl執行的詳細資訊.
4743
	#$result["content"],結果json字串.
4744
	#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
4745
	#必填參數:
4746
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
4747
	$conf["id"]="";
4748
	#可省略參數:
4749
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
4750
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
4751
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
4752
	#$conf["key"]=self::getApiInfo()["apiKey"];
4753
	#參考資料:
4754
	#https://zerossl.com/documentation/api/get-certificate/
4755
	#備註:
4756
	#無.
4757
	*/
4758
	public static function getCertSta(&$conf){
4759
 
4760
		#初始化要回傳的結果
4761
		$result=array();
4762
 
4763
		#設置當其函數名稱
4764
		$result["function"]=__FUNCTION__;
4765
 
4766
		#如果 $conf 不為陣列
4767
		if(gettype($conf)!="array"){
4768
 
4769
			#設置執行失敗
4770
			$result["status"]="false";
4771
 
4772
			#設置執行錯誤訊息
4773
			$result["error"][]="\$conf變數須為陣列形態";
4774
 
4775
			#如果傳入的參數為 null
4776
			if($conf==null){
4777
 
4778
				#設置執行錯誤訊息
4779
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
4780
 
4781
				}#if end
4782
 
4783
			#回傳結果
4784
			return $result;
4785
 
4786
			}#if end
4787
 
4788
		#取得參數
4789
		$result["argu"]=$conf;
4790
 
4791
		#檢查參數
4792
		#函式說明:
4793
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4794
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4795
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4796
		#$result["function"],當前執行的函式名稱.
4797
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4798
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4799
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4800
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4801
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4802
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4803
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4804
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4805
		#必填寫的參數:
4806
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4807
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4808
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4809
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
4810
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
4811
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4812
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4813
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4814
		#可以省略的參數:
4815
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4816
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
4817
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
4818
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4819
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4820
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
4821
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
4822
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
4823
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4824
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
4825
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4826
		#$conf["arrayCountEqualCheck"][]=array();
4827
		#參考資料來源:
4828
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4829
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4830
		unset($conf["variableCheck::checkArguments"]);
4831
 
4832
		#如果檢查失敗
4833
		if($checkArguments["status"]==="false"){
4834
 
4835
			#設置錯誤識別
4836
			$result["status"]="false";
4837
 
4838
			#設置錯誤訊息
4839
			$result["error"]=$checkArguments;
4840
 
4841
			#回傳結果
4842
			return $result;
4843
 
4844
			}#if end
4845
 
4846
		#如果檢查不通過
4847
		if($checkArguments["passed"]==="false"){
4848
 
4849
			#設置錯誤識別
4850
			$result["status"]="false";
4851
 
4852
			#設置錯誤訊息
4853
			$result["error"]=$checkArguments;
4854
 
4855
			#回傳結果
4856
			return $result;
4857
 
4858
			}#if end
4859
 
4860
		#函式說明:
4861
		#運行curl cmd
4862
		#回傳結果:
4863
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4864
		#$result["error"],錯誤訊息陣列.
4865
		#$result["function"],當前執行的函式名稱.
4866
		#$result["founded"],識別網址找不找得到.
4867
		#$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"代表程序的資訊.
4868
		#$result["fullContent"],取得回應的完整字串內容.
4869
		#$result["cookie"],cookie檔案的位置與名稱.
4870
		#$result["cmd"],執行的command.
4871
		#$result["argu],使用的參數.
4872
		#必填參數:
4873
		#$conf["url"],字串,目標url.
4874
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
4875
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4876
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
4877
		#可省略參數:
4878
		#$conf["header"],字串陣列,要傳送的header.
4879
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
4880
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
4881
		#$conf["allowAnySSLcertificate"]="";
4882
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
4883
		#$conf["postVar"]=array();
4884
		#$conf["rawPost"]="字串",要傳送的raw post內容.
4885
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
4886
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
4887
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
4888
		#$conf["agent"],字串,user agent的名稱.
4889
		#$conf["agent"]="";
4890
		#$conf["cookie"],字串,cookie位置與檔案位置.
4891
		#$conf["cookie"]="";
4892
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
4893
		#$conf["forceNewCookie"]="";
4894
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
4895
		#$conf["inBg"]="true";
4896
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
4897
		#$conf["bgInProc"]="false";
4898
		#參考資料:
4899
		#無.
4900
		#備註:
4901
		#無.
4902
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
4903
		unset($conf["catchWebContent::curlCmd"]);
4904
 
4905
		#如果異常
4906
		if($curlCmd["status"]==="false"){
4907
 
4908
			#設置錯誤識別
4909
			$result["status"]="false";
4910
 
4911
			#設置錯誤訊息
4912
			$result["error"]=$curlCmd;
4913
 
4914
			#回傳結果
4915
			return $result;
4916
 
4917
			}#if end
4918
 
4919
		#設置curl的詳細資訊
4920
		$result["curl_verbose_info"]=$curlCmd;
4921
 
4922
		#驗證結果是否為 json
4923
		$json_validate=json_validate($curlCmd["fullContent"]);
4924
 
4925
		#如果回應不是 json
4926
		if(!$json_validate){
4927
 
4928
			#設置錯誤識別
4929
			$result["status"]="false";
4930
 
4931
			#設置錯誤訊息
4932
			$result["error"]=$curlCmd;
4933
 
4934
			#回傳結果
4935
			return $result;
4936
 
4937
			}#if end
4938
 
4939
		#設置json string結果
4940
		$result["content"]=$curlCmd["fullContent"];
4941
 
4942
		#解析json
4943
		$jsonRes=json_decode($result["content"]);
4944
 
4945
		#如果沒有 status
4946
		if(!isset($jsonRes->status)){
4947
 
4948
			#設置錯誤識別
4949
			$result["status"]="false";
4950
 
4951
			#設置錯誤訊息
4952
			$result["error"]=$curlCmd;
4953
 
4954
			#回傳結果
4955
			return $result;
4956
 
4957
			}#if end
4958
 
4959
		#取得csr在zerossl上的狀態
4960
		$result["cerStatus"]=$jsonRes->status;
4961
 
4962
		#設置執行正常
4963
		$result["status"]="true";
4964
 
4965
		#回傳結果
4966
		return $result;
4967
 
4968
		}#function getCertSta end
4969
 
4970
	/*
4971
	#函式說明:
4972
	#取得在zerossl上的CSR清單
4973
	#回傳結果:
4974
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4975
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
4976
	#$result["function"],當前執行的函式名稱.
4977
	#$result["argu"],所使用的參數.
4978
	#$result["curl_verbose_info"],curl執行的詳細資訊.
4979
	#$result["content"],結果json字串.
4980
	#$result["tCount"],總共的資料筆數.
4981
	#$result["count"],該頁的筆數.
4982
	#$result["page"],當前的頁碼.
4983
	#$result["certs"],陣列,certificates清單,key為certificate的id.
4984
	#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
4985
	#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
4986
	#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
4987
	#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
4988
	#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
4989
	#必填參數:
4990
	#無
4991
	#可省略參數:
4992
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
4993
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
4994
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
4995
	#$conf["key"]=self::getApiInfo()["apiKey"];
4996
	#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
4997
	#$conf["cerStatus"]="";
4998
	#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
4999
	#$conf["cerType"]="";
5000
	#$conf["search"],字串,透過certificate包含的domain來搜尋.
5001
	#$conf["search"]="";
5002
	#$conf["limit"],字串,一頁要多少筆,預設為100筆.
5003
	#$conf["limit"]="";
5004
	#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
5005
	#$conf["page"]="";
5006
	#參考資料:
5007
	#https://zerossl.com/documentation/api/list-certificates/
5008
	#備註:
5009
	#無.
5010
	*/
5011
	public static function getCertList(&$conf){
5012
 
5013
		#初始化要回傳的結果
5014
		$result=array();
5015
 
5016
		#設置當其函數名稱
5017
		$result["function"]=__FUNCTION__;
5018
 
5019
		#如果 $conf 不為陣列
5020
		if(gettype($conf)!="array"){
5021
 
5022
			#設置執行失敗
5023
			$result["status"]="false";
5024
 
5025
			#設置執行錯誤訊息
5026
			$result["error"][]="\$conf變數須為陣列形態";
5027
 
5028
			#如果傳入的參數為 null
5029
			if($conf==null){
5030
 
5031
				#設置執行錯誤訊息
5032
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5033
 
5034
				}#if end
5035
 
5036
			#回傳結果
5037
			return $result;
5038
 
5039
			}#if end
5040
 
5041
		#取得參數
5042
		$result["argu"]=$conf;
5043
 
5044
		#檢查參數
5045
		#函式說明:
5046
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5047
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5048
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5049
		#$result["function"],當前執行的函式名稱.
5050
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5051
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5052
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5053
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5054
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5055
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5056
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5057
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5058
		#必填寫的參數:
5059
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5060
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5061
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5062
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5063
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5064
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5065
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5066
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5067
		#可以省略的參數:
5068
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5069
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5070
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5071
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5072
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5073
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
5074
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5075
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
5076
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5077
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
5078
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5079
		#$conf["arrayCountEqualCheck"][]=array();
5080
		#參考資料來源:
5081
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5082
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5083
		unset($conf["variableCheck::checkArguments"]);
5084
 
5085
		#如果檢查失敗
5086
		if($checkArguments["status"]==="false"){
5087
 
5088
			#設置錯誤識別
5089
			$result["status"]="false";
5090
 
5091
			#設置錯誤訊息
5092
			$result["error"]=$checkArguments;
5093
 
5094
			#回傳結果
5095
			return $result;
5096
 
5097
			}#if end
5098
 
5099
		#如果檢查不通過
5100
		if($checkArguments["passed"]==="false"){
5101
 
5102
			#設置錯誤識別
5103
			$result["status"]="false";
5104
 
5105
			#設置錯誤訊息
5106
			$result["error"]=$checkArguments;
5107
 
5108
			#回傳結果
5109
			return $result;
5110
 
5111
			}#if end
5112
 
5113
		#預設網址
5114
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/?access_key=".$conf["key"];
5115
 
5116
		#如果有設置 cerStatus
5117
		if(isset($conf["cerStatus"])){
5118
 
5119
			#設置 certificate_status 
5120
			$url=$url."?certificate_status=".urlencode($conf["cerStatus"]);
5121
 
5122
			}#if end
5123
 
5124
		#如果有設置 cerType
5125
		if(isset($conf["cerType"])){
5126
 
5127
			#設置 certificate_type
5128
			$url=$url."?certificate_type=".$conf["cerType"];
5129
 
5130
			}#if end
5131
 
5132
		#如果有設置 search
5133
		if(isset($conf["search"])){
5134
 
5135
			#設置 search
5136
			$url=$url."?search=".urlencode($conf["search"]);
5137
 
5138
			}#if end
5139
 
5140
		#如果有設置 limit
5141
		if(isset($conf["limit"])){
5142
 
5143
			#設置 search
5144
			$url=$url."?limit=".$conf["limit"];
5145
 
5146
			}#if end
5147
 
5148
		#如果有設置 page
5149
		if(isset($conf["page"])){
5150
 
5151
			#設置 search
5152
			$url=$url."?page=".$conf["page"];
5153
 
5154
			}#if end
5155
 
5156
		#函式說明:
5157
		#運行curl cmd
5158
		#回傳結果:
5159
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5160
		#$result["error"],錯誤訊息陣列.
5161
		#$result["function"],當前執行的函式名稱.
5162
		#$result["founded"],識別網址找不找得到.
5163
		#$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"代表程序的資訊.
5164
		#$result["fullContent"],取得回應的完整字串內容.
5165
		#$result["cookie"],cookie檔案的位置與名稱.
5166
		#$result["cmd"],執行的command.
5167
		#$result["argu],使用的參數.
5168
		#必填參數:
5169
		#$conf["url"],字串,目標url.
5170
		$conf["catchWebContent::curlCmd"]["url"]=$url;
5171
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5172
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5173
		#可省略參數:
5174
		#$conf["header"],字串陣列,要傳送的header.
5175
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5176
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5177
		#$conf["allowAnySSLcertificate"]="";
5178
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5179
		#$conf["postVar"]=array();
5180
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5181
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5182
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5183
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5184
		#$conf["agent"],字串,user agent的名稱.
5185
		#$conf["agent"]="";
5186
		#$conf["cookie"],字串,cookie位置與檔案位置.
5187
		#$conf["cookie"]="";
5188
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5189
		#$conf["forceNewCookie"]="";
5190
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5191
		#$conf["inBg"]="true";
5192
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5193
		#$conf["bgInProc"]="false";
5194
		#參考資料:
5195
		#無.
5196
		#備註:
5197
		#無.
5198
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5199
		unset($conf["catchWebContent::curlCmd"]);
5200
 
5201
		#如果異常
5202
		if($curlCmd["status"]==="false"){
5203
 
5204
			#設置錯誤識別
5205
			$result["status"]="false";
5206
 
5207
			#設置錯誤訊息
5208
			$result["error"]=$curlCmd;
5209
 
5210
			#回傳結果
5211
			return $result;
5212
 
5213
			}#if end
5214
 
5215
		#設置curl的詳細資訊
5216
		$result["curl_verbose_info"]=$curlCmd;
5217
 
5218
		#驗證結果是否為 json
5219
		$json_validate=json_validate($curlCmd["fullContent"]);
5220
 
5221
		#如果回應不是 json
5222
		if(!$json_validate){
5223
 
5224
			#設置錯誤識別
5225
			$result["status"]="false";
5226
 
5227
			#設置錯誤訊息
5228
			$result["error"]=$curlCmd;
5229
 
5230
			#回傳結果
5231
			return $result;
5232
 
5233
			}#if end
5234
 
5235
		#設置json string結果
5236
		$result["content"]=$curlCmd["fullContent"];
5237
 
5238
		/* json response 範例
5239
		{
5240
			"total_count": 11,
5241
			"result_count": 10,
5242
			"page": 1,
5243
			"limit": 10,
5244
			"acmeUsageLevel": "LOW",
5245
			"isAcmeLocked": false,
5246
			"results": 
5247
			[
5248
				{
5249
					"id": "a856a39a1c3ad0s8asa606g37667d221",
5250
					"type": "1",
5251
					"common_name": "domain.com",
5252
					"additional_domains": "www.domain.com",
5253
					"created": "2020-04-29 09:04:19",
5254
					"expires": "2020-07-28 00:00:00",
5255
					"status": "draft",
5256
					"validation_type": null,
5257
					"validation_emails": null,
5258
					"replacement_for": "",
5259
					"fingerprint_sha1": null,
5260
					"brand_validation": null,
5261
					"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
5262
					"validation":
5263
					{
5264
						"email_validation":
5265
						{
5266
							"domain.com":
5267
							[
5268
								"admin@domain.com",
5269
								"administrator@domain.com",
5270
								"hostmaster@domain.com",
5271
								"postmaster@domain.com",
5272
								"webmaster@domain.com"
5273
							]
5274
						},
5275
						"other_methods": 
5276
						{
5277
							"domain.com":
5278
							{
5279
								"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
5280
								"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
5281
								"file_validation_content":
5282
								[
5283
									"2B449B722B449B729394793947",
5284
									"comodoca.com",
5285
									"4bad7360c7076ba"
5286
								],
5287
								"cname_validation_p1": "2B449B7293947.domain.com",
5288
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
5289
							},
5290
							"www.domain.com":
5291
							{
5292
								"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
5293
								"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",   
5294
								"file_validation_content":
5295
								[
5296
									"2B449B722B449B729394793947",
5297
									"comodoca.com",
5298
									"4bad7360c7076ba"
5299
								],
5300
								"cname_validation_p1": "2B449B7293947.www.domain.com",
5301
								"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
5302
							}
5303
						}
5304
					}
5305
				},
5306
				{
5307
					...
5308
				}
5309
			]
5310
		}
249 liveuser 5311
		*/
5312
 
255 liveuser 5313
		#解析json
5314
		$jsonRes=json_decode($result["content"]);
5315
 
5316
		#總共的資料筆數
5317
		$result["tCount"]=$jsonRes->total_count;
5318
 
5319
		#取得該頁的筆數
5320
		$result["count"]=$jsonRes->result_count;
5321
 
5322
		#取得certificate清單
5323
		$cers=$jsonRes->results;
5324
 
5325
		#針對每個certificate
5326
		foreach($certs as $index => $cert){
5327
 
5328
			#初始化暫存的陣列
5329
			$tmpA=array();
5330
 
5331
			#儲存 cert id
5332
			#$tmpA["id"]=$cert->id;
5333
 
5334
			#儲存 主要包含的 domain name
5335
			$tmpA["cname"]=$cert->common_name;
5336
 
5337
			#儲存額外包含的 domain name
5338
			$tmpA["anames"]=$cert->additional_domains;
5339
 
5340
			#最後有效年月日,格式為"2020-07-28 00:00:00".
5341
			$tmpA["expiresYMD"]=$cert->expires;
5342
 
5343
			#產生對於當前系統時間的差距(秒數)
5344
			#函式說明:
5345
			#計算時間點距離1970/01/01多少秒,亦即unixtime.
5346
			#回傳結果:
5347
			#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
5348
			#$result["error"],錯誤訊息陣列.
5349
			#$result["content"],時間點距離1970/01/01的多少秒.
5350
			#$result["argu"],使用的參數.
5351
			#$result["unixtime"],執行本函式時的unixtime.
5352
			#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
5353
			#必填參數:
5354
			#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
5355
			$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
5356
			#可省略參數:
5357
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
5358
			#$conf["UTC"]="false";
5359
			#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
5360
			$conf["time::caculateTimeAmount"]["replace0"]="false";
5361
			#參考資料:
5362
			#無.
5363
			#備註:
5364
			#無.
5365
			$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
5366
			unset($conf["time::caculateTimeAmount"]);
5367
 
5368
			#如果執行異常
5369
			if($caculateTimeAmount["passed"]==="false"){
5370
 
5371
				#設置錯誤識別
5372
				$result["status"]="false";
5373
 
5374
				#設置錯誤訊息
5375
				$result["error"]=$caculateTimeAmount;
5376
 
5377
				#回傳結果
5378
				return $result;
5379
 
5380
				}#if end
5381
 
5382
			#儲存還要多少秒要過期
5383
			$tmpA["expiresIn"]=$caculateTimeAmount["unixtime"]-time();
5384
 
5385
			#憑證的狀態
5386
			$tmpA["status"]=$cert->status;
5387
 
5388
			#儲存要回傳的 cers 清單,key為cert的id.
5389
			$result["cers"][$cert->id]=$tmpA;
5390
 
5391
			}#foreach end
5392
 
5393
		#設置執行正常
5394
		$result["status"]="true";
5395
 
5396
		#回傳結果
5397
		return $result;
5398
 
5399
		}#function getCertList end
5400
 
5401
	/*
5402
	#函式說明:
5403
	#下載certificate.
5404
	#回傳結果:
5405
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5406
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5407
	#$result["function"],當前執行的函式名稱.
5408
	#$result["argu"],所使用的參數.
5409
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5410
	#$result["content"],結果json字串.
5411
	#$result["certificate.crt"],字串,certificate.crt的內容.
5412
	#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
5413
	#必填參數:
5414
	#無.
5415
	#可省略參數:
5416
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5417
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5418
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5419
	#$conf["key"]=self::getApiInfo()["apiKey"];
5420
	#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
5421
	#$conf["id"]="";
5422
	#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
5423
	#$conf["cname"]="";
5424
	#參考資料:
5425
	#https://zerossl.com/documentation/api/download-certificate-inline/
5426
	#備註:
5427
	#無.
5428
	*/
5429
	public static function getCert(&$conf){
5430
 
5431
		#初始化要回傳的結果
5432
		$result=array();
5433
 
5434
		#設置當其函數名稱
5435
		$result["function"]=__FUNCTION__;
5436
 
5437
		#如果 $conf 不為陣列
5438
		if(gettype($conf)!="array"){
5439
 
5440
			#設置執行失敗
5441
			$result["status"]="false";
5442
 
5443
			#設置執行錯誤訊息
5444
			$result["error"][]="\$conf變數須為陣列形態";
5445
 
5446
			#如果傳入的參數為 null
5447
			if($conf==null){
5448
 
5449
				#設置執行錯誤訊息
5450
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5451
 
5452
				}#if end
5453
 
5454
			#回傳結果
5455
			return $result;
5456
 
5457
			}#if end
5458
 
5459
		#取得參數
5460
		$result["argu"]=$conf;
5461
 
5462
		#檢查參數
5463
		#函式說明:
5464
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5465
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5466
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5467
		#$result["function"],當前執行的函式名稱.
5468
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5469
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5470
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5471
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5472
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5473
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5474
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5475
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5476
		#必填寫的參數:
5477
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5478
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5479
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5480
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5481
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5482
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5483
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5484
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5485
		#可以省略的參數:
5486
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5487
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5488
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5489
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5490
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5491
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
5492
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5493
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
5494
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5495
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
5496
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5497
		#$conf["arrayCountEqualCheck"][]=array();
5498
		#參考資料來源:
5499
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5500
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5501
		unset($conf["variableCheck::checkArguments"]);
5502
 
5503
		#如果檢查失敗
5504
		if($checkArguments["status"]==="false"){
5505
 
5506
			#設置錯誤識別
5507
			$result["status"]="false";
5508
 
5509
			#設置錯誤訊息
5510
			$result["error"]=$checkArguments;
5511
 
5512
			#回傳結果
5513
			return $result;
5514
 
5515
			}#if end
5516
 
5517
		#如果檢查不通過
5518
		if($checkArguments["passed"]==="false"){
5519
 
5520
			#設置錯誤識別
5521
			$result["status"]="false";
5522
 
5523
			#設置錯誤訊息
5524
			$result["error"]=$checkArguments;
5525
 
5526
			#回傳結果
5527
			return $result;
5528
 
5529
			}#if end
5530
 
5531
		#如果有設置 id
5532
		if(isset($conf["id"])){
5533
 
5534
			#設置 id
5535
			$id=$conf["id"];
5536
 
5537
			}#if end
5538
 
5539
		#反之如果有設置 cname
5540
		else if(isset($conf["cname"])){
5541
 
5542
			#函式說明:
5543
			#取得在zerossl上的CSR清單
5544
			#回傳結果:
5545
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5546
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
5547
			#$result["function"],當前執行的函式名稱.
5548
			#$result["argu"],所使用的參數.
5549
			#$result["curl_verbose_info"],curl執行的詳細資訊.
5550
			#$result["content"],結果json字串.
5551
			#$result["tCound"],總共的資料筆數.
5552
			#$result["count"],該頁的筆數.
5553
			#$result["page"],當前的頁碼.
5554
			#$result["certs"],陣列,certificates清單,key為certificate的id.
5555
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
5556
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
5557
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
5558
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5559
			#必填參數:
5560
			#無
5561
			#可省略參數:
5562
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5563
			#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5564
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5565
			#$conf["key"]=self::getApiInfo()["apiKey"];
5566
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
5567
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
5568
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
5569
			#$conf["cerType"]="";
5570
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
5571
			$conf["zerossl::getCertList"]["search"]=$conf["cname"];
5572
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
5573
			#$conf["limit"]="";
5574
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
5575
			#$conf["page"]="";
5576
			#參考資料:
5577
			#https://zerossl.com/documentation/api/get-certificate/
5578
			#備註:
5579
			#無.
5580
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
5581
			unset($conf["zerossl::getCertList"]);
5582
 
5583
			#如果檢查失敗
5584
			if($getCertList["status"]==="false"){
5585
 
5586
				#設置錯誤識別
5587
				$result["status"]="false";
5588
 
5589
				#設置錯誤訊息
5590
				$result["error"]=$getCertList;
5591
 
5592
				#回傳結果
5593
				return $result;
5594
 
5595
				}#if end
5596
 
5597
			#如果資料筆數大於0
5598
			if($getCertList["count"]>0){
5599
 
5600
				#取得第一筆
5601
				foreach($getCertList["certs"] as $cerId => $detail){
5602
 
5603
					#取得cettificate id
5604
					$id=$cerId;
5605
 
5606
					}#foreach end
5607
 
5608
				}#if end
5609
 
5610
			}#if end
5611
 
5612
		#預設網址
5613
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
5614
 
5615
		#函式說明:
5616
		#運行curl cmd
5617
		#回傳結果:
5618
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5619
		#$result["error"],錯誤訊息陣列.
5620
		#$result["function"],當前執行的函式名稱.
5621
		#$result["founded"],識別網址找不找得到.
5622
		#$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"代表程序的資訊.
5623
		#$result["fullContent"],取得回應的完整字串內容.
5624
		#$result["cookie"],cookie檔案的位置與名稱.
5625
		#$result["cmd"],執行的command.
5626
		#$result["argu],使用的參數.
5627
		#必填參數:
5628
		#$conf["url"],字串,目標url.
5629
		$conf["catchWebContent::curlCmd"]["url"]=$url;
5630
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5631
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5632
		#可省略參數:
5633
		#$conf["header"],字串陣列,要傳送的header.
5634
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5635
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5636
		#$conf["allowAnySSLcertificate"]="";
5637
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5638
		#$conf["postVar"]=array();
5639
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5640
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5641
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5642
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5643
		#$conf["agent"],字串,user agent的名稱.
5644
		#$conf["agent"]="";
5645
		#$conf["cookie"],字串,cookie位置與檔案位置.
5646
		#$conf["cookie"]="";
5647
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5648
		#$conf["forceNewCookie"]="";
5649
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5650
		#$conf["inBg"]="true";
5651
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5652
		#$conf["bgInProc"]="false";
5653
		#參考資料:
5654
		#無.
5655
		#備註:
5656
		#無.
5657
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5658
		unset($conf["catchWebContent::curlCmd"]);
5659
 
5660
		#如果異常
5661
		if($curlCmd["status"]==="false"){
5662
 
5663
			#設置錯誤識別
5664
			$result["status"]="false";
5665
 
5666
			#設置錯誤訊息
5667
			$result["error"]=$curlCmd;
5668
 
5669
			#回傳結果
5670
			return $result;
5671
 
5672
			}#if end
5673
 
5674
		#設置curl的詳細資訊
5675
		$result["curl_verbose_info"]=$curlCmd;
5676
 
249 liveuser 5677
		#驗證結果是否為 json
5678
		$json_validate=json_validate($curlCmd["fullContent"]);
5679
 
5680
		#如果回應不是 json
5681
		if(!$json_validate){
5682
 
5683
			#設置錯誤識別
5684
			$result["status"]="false";
5685
 
5686
			#設置錯誤訊息
5687
			$result["error"]=$curlCmd;
5688
 
5689
			#回傳結果
5690
			return $result;
5691
 
5692
			}#if end
5693
 
5694
		#設置json string結果
5695
		$result["content"]=$curlCmd["fullContent"];
255 liveuser 5696
 
5697
		#取得 json
5698
		$json=json_decode($curlCmd["fullContent"]);
5699
 
5700
		#取得certificate.crt的內容
5701
		$result["certificate.crt"]=$json->certificate.crt;
5702
 
5703
		#取得ca_bundle.crt的內容
5704
		$result["ca_bundle.crt"]=$json->ca_bundle.crt;
5705
 
5706
		#設置執行正常
5707
		$result["status"]="true";
5708
 
5709
		#回傳結果
5710
		return $result;
5711
 
5712
		}#function getCert end
5713
 
5714
	/*
5715
	#函式說明:
5716
	#請求廢除 issued zerossl certificate.
5717
	#回傳結果:
5718
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5719
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5720
	#$result["function"],當前執行的函式名稱.
5721
	#$result["argu"],所使用的參數.
5722
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5723
	#$result["content"],結果json字串.
5724
	#必填參數:
5725
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
5726
	$conf["id"]="";
5727
	#可省略參數:
5728
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5729
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5730
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5731
	#$conf["key"]=self::getApiInfo()["apiKey"];
5732
	#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
5733
	#$conf["reason"]="";
5734
	#參考資料:
5735
	#https://zerossl.com/documentation/api/revoke-certificate/
5736
	#備註:
5737
	#無.
5738
	*/
5739
	public static function revokeCert(&$conf){
5740
 
5741
		#初始化要回傳的結果
5742
		$result=array();
249 liveuser 5743
 
255 liveuser 5744
		#設置當其函數名稱
5745
		$result["function"]=__FUNCTION__;
5746
 
5747
		#如果 $conf 不為陣列
5748
		if(gettype($conf)!="array"){
5749
 
5750
			#設置執行失敗
5751
			$result["status"]="false";
5752
 
5753
			#設置執行錯誤訊息
5754
			$result["error"][]="\$conf變數須為陣列形態";
5755
 
5756
			#如果傳入的參數為 null
5757
			if($conf==null){
5758
 
5759
				#設置執行錯誤訊息
5760
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
5761
 
5762
				}#if end
5763
 
5764
			#回傳結果
5765
			return $result;
5766
 
5767
			}#if end
5768
 
5769
		#取得參數
5770
		$result["argu"]=$conf;
5771
 
5772
		#檢查參數
5773
		#函式說明:
5774
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5775
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5776
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5777
		#$result["function"],當前執行的函式名稱.
5778
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5779
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5780
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5781
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5782
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5783
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5784
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5785
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5786
		#必填寫的參數:
5787
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5788
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5789
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5790
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
5791
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
5792
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5793
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5794
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5795
		#可以省略的參數:
5796
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5797
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5798
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5799
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5800
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5801
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
5802
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5803
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","status");
5804
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5805
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
5806
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5807
		#$conf["arrayCountEqualCheck"][]=array();
5808
		#參考資料來源:
5809
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5810
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5811
		unset($conf["variableCheck::checkArguments"]);
5812
 
5813
		#如果檢查失敗
5814
		if($checkArguments["status"]==="false"){
5815
 
5816
			#設置錯誤識別
5817
			$result["status"]="false";
5818
 
5819
			#設置錯誤訊息
5820
			$result["error"]=$checkArguments;
5821
 
5822
			#回傳結果
5823
			return $result;
5824
 
5825
			}#if end
5826
 
5827
		#如果檢查不通過
5828
		if($checkArguments["passed"]==="false"){
5829
 
5830
			#設置錯誤識別
5831
			$result["status"]="false";
5832
 
5833
			#設置錯誤訊息
5834
			$result["error"]=$checkArguments;
5835
 
5836
			#回傳結果
5837
			return $result;
5838
 
5839
			}#if end
5840
 
5841
		#url to call
5842
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
5843
 
5844
		#如果有設置 reason
5845
		if(isset($conf["reason"])){
5846
 
5847
			#設置reason
5848
			$reason="&reason=".$conf["reason"];
5849
 
5850
			#串接reason
5851
			$url=$url.$reason;
5852
 
5853
			}#if end
5854
 
5855
		#函式說明:
5856
		#運行curl cmd
5857
		#回傳結果:
5858
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5859
		#$result["error"],錯誤訊息陣列.
5860
		#$result["function"],當前執行的函式名稱.
5861
		#$result["founded"],識別網址找不找得到.
5862
		#$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"代表程序的資訊.
5863
		#$result["fullContent"],取得回應的完整字串內容.
5864
		#$result["cookie"],cookie檔案的位置與名稱.
5865
		#$result["cmd"],執行的command.
5866
		#$result["argu],使用的參數.
5867
		#必填參數:
5868
		#$conf["url"],字串,目標url.
5869
		$conf["catchWebContent::curlCmd"]["url"]=$url;
5870
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5871
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
5872
		#可省略參數:
5873
		#$conf["header"],字串陣列,要傳送的header.
5874
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
5875
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
5876
		#$conf["allowAnySSLcertificate"]="";
5877
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
5878
		#$conf["postVar"]=array();
5879
		#$conf["rawPost"]="字串",要傳送的raw post內容.
5880
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
5881
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
5882
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
5883
		#$conf["agent"],字串,user agent的名稱.
5884
		#$conf["agent"]="";
5885
		#$conf["cookie"],字串,cookie位置與檔案位置.
5886
		#$conf["cookie"]="";
5887
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
5888
		#$conf["forceNewCookie"]="";
5889
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
5890
		#$conf["inBg"]="true";
5891
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
5892
		#$conf["bgInProc"]="false";
5893
		#參考資料:
5894
		#無.
5895
		#備註:
5896
		#無.
5897
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
5898
		unset($conf["catchWebContent::curlCmd"]);
5899
 
5900
		#如果異常
5901
		if($curlCmd["status"]==="false"){
5902
 
5903
			#設置錯誤識別
5904
			$result["status"]="false";
5905
 
5906
			#設置錯誤訊息
5907
			$result["error"]=$curlCmd;
5908
 
5909
			#回傳結果
5910
			return $result;
5911
 
5912
			}#if end
5913
 
5914
		#設置curl的詳細資訊
5915
		$result["curl_verbose_info"]=$curlCmd;
5916
 
5917
		#驗證結果是否為 json
5918
		$json_validate=json_validate($curlCmd["fullContent"]);
5919
 
5920
		#如果回應不是 json
5921
		if(!$json_validate){
5922
 
5923
			#設置錯誤識別
5924
			$result["status"]="false";
5925
 
5926
			#設置錯誤訊息
5927
			$result["error"]=$curlCmd;
5928
 
5929
			#回傳結果
5930
			return $result;
5931
 
5932
			}#if end
5933
 
5934
		#設置json string結果
5935
		$result["content"]=$curlCmd["fullContent"];
5936
 
249 liveuser 5937
		#解析json
5938
		$jsonRes=json_decode($result["content"]);
5939
 
255 liveuser 5940
		#如果沒有要有的attr
5941
		if(!isset($jsonRes->success)){
5942
 
5943
			#設置錯誤識別
5944
			$result["status"]="false";
5945
 
5946
			#設置錯誤訊息
5947
			$result["error"]=$curlCmd;
5948
 
5949
			#回傳結果
5950
			return $result;
5951
 
5952
			}#if end
5953
 
5954
		#如果 success 不等於 1
5955
		if($jsonRes->success!==1){
5956
 
5957
			#設置錯誤識別
5958
			$result["status"]="false";
5959
 
5960
			#設置錯誤訊息
5961
			$result["error"]=$curlCmd;
5962
 
5963
			#回傳結果
5964
			return $result;
5965
 
5966
			}#if end
5967
 
249 liveuser 5968
		#設置執行正常
5969
		$result["status"]="true";
5970
 
5971
		#回傳結果
5972
		return $result;
5973
 
255 liveuser 5974
		}#function revokeCert end
5975
 
5976
	/*
5977
	#函式說明:
5978
	#請求取消 draft or unvalidated zerossl certificate.
5979
	#回傳結果:
5980
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5981
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5982
	#$result["function"],當前執行的函式名稱.
5983
	#$result["argu"],所使用的參數.
5984
	#$result["curl_verbose_info"],curl執行的詳細資訊.
5985
	#$result["content"],結果json字串.
5986
	#必填參數:
5987
	#$conf["id"],字串,zerossl::createCertificate回傳的id.
5988
	$conf["id"]="";
5989
	#可省略參數:
5990
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
5991
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
5992
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
5993
	#$conf["key"]=self::getApiInfo()["apiKey"];
5994
	#參考資料:
5995
	#https://zerossl.com/documentation/api/revoke-certificate/
5996
	#備註:
5997
	#無.
5998
	*/
5999
	public static function cancelCert(&$conf){
6000
 
6001
		#初始化要回傳的結果
6002
		$result=array();
249 liveuser 6003
 
255 liveuser 6004
		#設置當其函數名稱
6005
		$result["function"]=__FUNCTION__;
6006
 
6007
		#如果 $conf 不為陣列
6008
		if(gettype($conf)!="array"){
6009
 
6010
			#設置執行失敗
6011
			$result["status"]="false";
6012
 
6013
			#設置執行錯誤訊息
6014
			$result["error"][]="\$conf變數須為陣列形態";
6015
 
6016
			#如果傳入的參數為 null
6017
			if($conf==null){
6018
 
6019
				#設置執行錯誤訊息
6020
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6021
 
6022
				}#if end
6023
 
6024
			#回傳結果
6025
			return $result;
6026
 
6027
			}#if end
6028
 
6029
		#取得參數
6030
		$result["argu"]=$conf;
6031
 
6032
		#檢查參數
6033
		#函式說明:
6034
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6035
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6036
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6037
		#$result["function"],當前執行的函式名稱.
6038
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6039
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6040
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6041
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6042
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6043
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6044
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6045
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6046
		#必填寫的參數:
6047
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6048
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6049
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6050
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
6051
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6052
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6053
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6054
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6055
		#可以省略的參數:
6056
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6057
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6058
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6059
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6060
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6061
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
6062
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6063
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
6064
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6065
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
6066
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6067
		#$conf["arrayCountEqualCheck"][]=array();
6068
		#參考資料來源:
6069
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6070
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6071
		unset($conf["variableCheck::checkArguments"]);
6072
 
6073
		#如果檢查失敗
6074
		if($checkArguments["status"]==="false"){
6075
 
6076
			#設置錯誤識別
6077
			$result["status"]="false";
6078
 
6079
			#設置錯誤訊息
6080
			$result["error"]=$checkArguments;
6081
 
6082
			#回傳結果
6083
			return $result;
6084
 
6085
			}#if end
6086
 
6087
		#如果檢查不通過
6088
		if($checkArguments["passed"]==="false"){
6089
 
6090
			#設置錯誤識別
6091
			$result["status"]="false";
6092
 
6093
			#設置錯誤訊息
6094
			$result["error"]=$checkArguments;
6095
 
6096
			#回傳結果
6097
			return $result;
6098
 
6099
			}#if end
6100
 
6101
		#url to call
6102
		$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
6103
 
6104
		#函式說明:
6105
		#運行curl cmd
6106
		#回傳結果:
6107
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6108
		#$result["error"],錯誤訊息陣列.
6109
		#$result["function"],當前執行的函式名稱.
6110
		#$result["founded"],識別網址找不找得到.
6111
		#$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"代表程序的資訊.
6112
		#$result["fullContent"],取得回應的完整字串內容.
6113
		#$result["cookie"],cookie檔案的位置與名稱.
6114
		#$result["cmd"],執行的command.
6115
		#$result["argu],使用的參數.
6116
		#必填參數:
6117
		#$conf["url"],字串,目標url.
6118
		$conf["catchWebContent::curlCmd"]["url"]=$url;
6119
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6120
		$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
6121
		#可省略參數:
6122
		#$conf["header"],字串陣列,要傳送的header.
6123
		#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
6124
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
6125
		#$conf["allowAnySSLcertificate"]="";
6126
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
6127
		#$conf["postVar"]=array();
6128
		#$conf["rawPost"]="字串",要傳送的raw post內容.
6129
		#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
6130
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
6131
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
6132
		#$conf["agent"],字串,user agent的名稱.
6133
		#$conf["agent"]="";
6134
		#$conf["cookie"],字串,cookie位置與檔案位置.
6135
		#$conf["cookie"]="";
6136
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
6137
		#$conf["forceNewCookie"]="";
6138
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
6139
		#$conf["inBg"]="true";
6140
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
6141
		#$conf["bgInProc"]="false";
6142
		#參考資料:
6143
		#無.
6144
		#備註:
6145
		#無.
6146
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
6147
		unset($conf["catchWebContent::curlCmd"]);
6148
 
6149
		#如果異常
6150
		if($curlCmd["status"]==="false"){
6151
 
6152
			#設置錯誤識別
6153
			$result["status"]="false";
6154
 
6155
			#設置錯誤訊息
6156
			$result["error"]=$curlCmd;
6157
 
6158
			#回傳結果
6159
			return $result;
6160
 
6161
			}#if end
6162
 
6163
		#設置curl的詳細資訊
6164
		$result["curl_verbose_info"]=$curlCmd;
6165
 
6166
		#驗證結果是否為 json
6167
		$json_validate=json_validate($curlCmd["fullContent"]);
6168
 
6169
		#如果回應不是 json
6170
		if(!$json_validate){
6171
 
6172
			#設置錯誤識別
6173
			$result["status"]="false";
6174
 
6175
			#設置錯誤訊息
6176
			$result["error"]=$curlCmd;
6177
 
6178
			#回傳結果
6179
			return $result;
6180
 
6181
			}#if end
6182
 
6183
		#設置json string結果
6184
		$result["content"]=$curlCmd["fullContent"];
6185
 
6186
		#解析json
6187
		$jsonRes=json_decode($result["content"]);
6188
 
6189
		#如果沒有要有的attr
6190
		if(!isset($jsonRes->success)){
6191
 
6192
			#設置錯誤識別
6193
			$result["status"]="false";
6194
 
6195
			#設置錯誤訊息
6196
			$result["error"]=$curlCmd;
6197
 
6198
			#回傳結果
6199
			return $result;
6200
 
6201
			}#if end
6202
 
6203
		#如果 success 不等於 1
6204
		if($jsonRes->success!==1){
6205
 
6206
			#設置錯誤識別
6207
			$result["status"]="false";
6208
 
6209
			#設置錯誤訊息
6210
			$result["error"]=$curlCmd;
6211
 
6212
			#回傳結果
6213
			return $result;
6214
 
6215
			}#if end
6216
 
6217
		#設置執行正常
6218
		$result["status"]="true";
6219
 
6220
		#回傳結果
6221
		return $result;
6222
 
6223
		}#function cancelCert end
6224
 
6225
	/*
6226
	#函式說明:
6227
	#透過zerossl api確保ssl沒有過期.
6228
	#回傳結果:
6229
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6230
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6231
	#$result["function"],當前執行的函式名稱.
6232
	#$result["argu"],所使用的參數.
6233
	#必填參數:
6234
	#$conf["cName"],陣列,每個ssl的common domain name.
6235
	$conf["cName"]=array();
6236
	#$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內容合併後的檔案位置與名稱.
6237
	$conf["certInfo"]=array();
6238
	#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
6239
	$conf["rrFile"]=array();
6240
	#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
6241
	$conf["dnsSerAddr"]=array();
6242
	#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
6243
	$conf["actionAfterUpdateCert"]=array();
6244
	#可省略參數:
281 liveuser 6245
	#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
6246
	#$conf["debug"]="";
255 liveuser 6247
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6248
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
6249
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6250
	#$conf["key"]=self::getApiInfo()["apiKey"];
6251
	#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
6252
	#$conf["debug"]="";
6253
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
6254
	#$conf["addOnProcessFunc"]=array();
6255
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
6256
	#$conf["funcToRunWhenIdle"]=array();
6257
	#參考資料:
6258
	#無.
6259
	#備註:
6260
	#無.
6261
	*/
6262
	public static function sslUpdater(&$conf){
6263
 
6264
		#初始化要回傳的結果
6265
		$result=array();
6266
 
6267
		#設置當其函數名稱
6268
		$result["function"]=__FUNCTION__;
6269
 
6270
		#如果 $conf 不為陣列
6271
		if(gettype($conf)!="array"){
6272
 
6273
			#設置執行失敗
6274
			$result["status"]="false";
6275
 
6276
			#設置執行錯誤訊息
6277
			$result["error"][]="\$conf變數須為陣列形態";
6278
 
6279
			#如果傳入的參數為 null
6280
			if($conf==null){
6281
 
6282
				#設置執行錯誤訊息
6283
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6284
 
6285
				}#if end
6286
 
6287
			#回傳結果
6288
			return $result;
6289
 
6290
			}#if end
6291
 
6292
		#取得參數
6293
		$result["argu"]=$conf;
6294
 
6295
		#檢查參數
6296
		#函式說明:
6297
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6298
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6299
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6300
		#$result["function"],當前執行的函式名稱.
6301
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6302
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6303
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6304
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6305
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6306
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6307
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6308
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6309
		#必填寫的參數:
6310
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6311
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6312
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6313
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
6314
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6315
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
6316
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6317
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6318
		#可以省略的參數:
6319
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6320
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6321
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
281 liveuser 6322
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("debug","apiDomain","key","debug");
255 liveuser 6323
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
281 liveuser 6324
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("debug","apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
255 liveuser 6325
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
281 liveuser 6326
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","array","array");
255 liveuser 6327
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
281 liveuser 6328
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
255 liveuser 6329
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6330
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
6331
		#參考資料來源:
6332
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6333
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6334
		unset($conf["variableCheck::checkArguments"]);
6335
 
6336
		#如果檢查失敗
6337
		if($checkArguments["status"]==="false"){
6338
 
6339
			#設置錯誤識別
6340
			$result["status"]="false";
6341
 
6342
			#設置錯誤訊息
6343
			$result["error"]=$checkArguments;
6344
 
6345
			#回傳結果
6346
			return $result;
6347
 
6348
			}#if end
6349
 
6350
		#如果檢查不通過
6351
		if($checkArguments["passed"]==="false"){
6352
 
6353
			#設置錯誤識別
6354
			$result["status"]="false";
6355
 
6356
			#設置錯誤訊息
6357
			$result["error"]=$checkArguments;
6358
 
6359
			#回傳結果
6360
			return $result;
6361
 
6362
			}#if end
6363
 
6364
		#取得key
6365
		$share["key"]=$conf["key"];
6366
 
6367
		#取得apiDomain
6368
		$share["apiDomain"]=$conf["apiDomain"];
6369
 
281 liveuser 6370
		#設置debug flag
6371
		$share["debug"]=$conf["debug"];
6372
 
255 liveuser 6373
		#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
6374
		$share["certInfo"]=array();
6375
 
6376
		#針對每個 domain
6377
		foreach($conf["cName"] as $index=>$cName ){
6378
 
6379
			#如果沒有對應的certInfo
6380
			if(!isset($conf["certInfo"][$index])){
6381
 
6382
				#設置錯誤識別
6383
				$result["status"]="false";
6384
 
6385
				#設置錯誤訊息
6386
				$result["error"][]="missing certInfo";
6387
 
6388
				#設置錯誤訊息
6389
				$result["error"][]=$checkArguments;
6390
 
6391
				#回傳結果
6392
				return $result;
6393
 
6394
				}#if end
6395
 
6396
			#檢查 certInfo
6397
			foreach($certInfo[$index] as $cInfo){
6398
 
6399
				#如果沒有設定 certPath
6400
				if(!isset($cInfo["certPath"])){
6401
 
6402
					#初始化為 ${cName}-cerfificate.crt
6403
					$cInfo["certPath"]=$conf["cName"][$index]."-certificate.crt";
6404
 
6405
					}#if end
6406
 
6407
				#如果沒有設定 pKey
6408
				if(!isset($cInfo["pKey"])){
6409
 
6410
					#初始化為 ${cName}-private.key
6411
					$cInfo["pKey"]=$conf["cName"][$index]."-private.key";
6412
 
6413
					}#if end
6414
 
6415
				#如果沒有設定 caPath
6416
				if(!isset($cInfo["caPath"])){
6417
 
6418
					#初始化為 ${cName}-ca_bundle.crt"
6419
					$cInfo["caPath"]=$conf["cName"][$index]."-ca_bundle.crt";
6420
 
6421
					}#if end
6422
 
6423
				#如果沒有設定 certWithCaPath
6424
				if(!isset($cInfo["certWithCaPath"])){
6425
 
6426
					#初始化為 ${cName}-certWithCaPath.crt"
6427
					$cInfo["certWithCaPath"]=$conf["cName"][$index]."-certWithCaPath.crt";
6428
 
6429
					}#if end
6430
 
6431
				#儲存 cName
6432
				$cInfo["cName"]=$cName;
6433
 
6434
				#儲存 RR 檔案的路徑與名稱
6435
				$cInfo["rrFile"]=$conf["rrFile"][$index];
6436
 
6437
				#儲存 cName 對應的 dns server addr
6438
				$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
6439
 
6440
				#儲存 cName 的憑證更新後要做的事情.
6441
				$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
6442
 
6443
				#儲存 certInfo
6444
				$share["certInfo"][]=$cInfo;
6445
 
6446
				}#foreach end
6447
 
6448
			}#foreach end
6449
 
6450
		#如果為空
6451
		if(empty($share["certInfo"])){
6452
 
6453
			#設置錯誤識別
6454
			$result["status"]="false";
6455
 
6456
			#設置錯誤訊息
6457
			$result["error"][]="certInfo 參數有缺";
6458
 
6459
			#設置錯誤訊息
6460
			$result["error"][]=$checkArguments;
6461
 
6462
			#回傳結果
6463
			return $result;
6464
 
6465
			}#if end
6466
 
6467
		#函式說明:
6468
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
6469
		#回傳結果:
6470
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
6471
		#$result["error"],錯誤訊息陣列.
6472
		#$result["function"],當前執行的函式名稱.
6473
		#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
6474
		#$result["serverCache"]["serverSide"],server side 的 cache.
6475
		#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
6476
		#$result["serverCache"]["clientSide"],client site 的 cache.
6477
		#必填參數:
6478
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
6479
		$conf["sock::unixDomainSockServer"]["sock"]=$unixSocket;
6480
		#$conf["fileArgu"],字串,變數__FILE__的內容.
6481
		$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
6482
		#可省略參數:
6483
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
6484
		$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
6485
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
6486
		$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
6487
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
6488
		#$conf["sessionTimeout"]="300";
6489
		#$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"代表執行不正常.
6490
		$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("/qbpwcf/zerossl::sslUpdater_cmd");
6491
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
6492
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("/qbpwcf/zerossl::sslUpdater_idle");
6493
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
6494
		#$conf["paramsForFuncToRunWhenIdle"]=array();
6495
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
6496
		$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
6497
		#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
6498
		#$conf["shutdownStrAddr"]="";
6499
		#參考資料:
6500
		#http://php.net/manual/en/function.stream-socket-server.php
6501
		#備註:
6502
		#無.
6503
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
6504
		unset($conf["sock::unixDomainSockServer"]);
6505
 
6506
		#執行異常
6507
		if($unixDomainSockServer["status"]==="false"){
6508
 
6509
			#設置錯誤識別
6510
			$result["status"]="false";
6511
 
6512
			#設置錯誤訊息
6513
			$result["error"]=$unixDomainSockServer;
6514
 
6515
			#回傳結果
6516
			return $result;
6517
 
6518
			}#if end
6519
 
6520
		#設置執行正常
6521
		$result["status"]="true";
6522
 
6523
		#回傳結果
6524
		return $result;
6525
 
6526
		}#function sslUpdater end
6527
 
6528
	/*
6529
	#函式說明:
6530
	#funcion sslUpdater 於收到訊息時要做的事情.
6531
	#回傳結果:
6532
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6533
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6534
	#$result["function"],當前執行的函式名稱.
6535
	#$result["argu"],所使用的參數.
6536
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
6537
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
6538
	#必填參數:
6539
	#$conf["request"],字串,收到的json訊息.
6540
	$conf["request"]="";
6541
	#$conf["sock"],resource,用戶的socket.
6542
	$conf["sock"]="";
6543
	#$conf["clientCache"],陣列,給予所有用戶的cache.
6544
	$conf["clientCache"]=array();
6545
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
6546
	$conf["info"]=array();
6547
	#可省略參數:
6548
	#無.
6549
	#參考資料:
6550
	#無.
6551
	#備註:
6552
	#建構中...
6553
	*/
6554
	public static function sslUpdater_cmd(&$conf){
6555
 
6556
		#debug
6557
		var_dump($conf);
6558
 
6559
		}#function sslUpdater_cmd end
6560
 
6561
	/*
6562
	#函式說明:
6563
	#funcion sslUpdater 於閒置時要做的事情
6564
	#回傳結果:
6565
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6566
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
6567
	#$result["function"],當前執行的函式名稱.
6568
	#$result["argu"],所使用的參數.
6569
	#$result["content"],字串,代表收到的訊息要變更成該變數內容.
6570
	#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
6571
	#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
6572
	#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
6573
	#必填參數:
6574
	#$conf["client"],陣列,所有用戶的資訊.
6575
	$conf["client"]=array();
6576
	#$conf["clientCache"],陣列,給予所有用戶的cache.
6577
	$conf["clientCache"]=array();
6578
	#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
6579
	$conf["serverCache"]=array();
6580
	#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
6581
	$conf["info"]=array();
6582
	#可省略參數:
6583
	#無.
6584
	#參考資料:
6585
	#無.
6586
	#備註:
6587
	#建構中...
6588
	*/
6589
	public static function sslUpdater_idle(&$conf){
6590
 
6591
		#初始化要回傳的結果
6592
		$result=array();
6593
 
6594
		#設置當其函數名稱
6595
		$result["function"]=__FUNCTION__;
6596
 
6597
		#如果 $conf 不為陣列
6598
		if(gettype($conf)!="array"){
6599
 
6600
			#設置執行失敗
6601
			$result["status"]="false";
6602
 
6603
			#設置執行錯誤訊息
6604
			$result["error"][]="\$conf變數須為陣列形態";
6605
 
6606
			#如果傳入的參數為 null
6607
			if($conf==null){
6608
 
6609
				#設置執行錯誤訊息
6610
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6611
 
6612
				}#if end
6613
 
6614
			#回傳結果
6615
			return $result;
6616
 
6617
			}#if end
6618
 
6619
		#取得參數
6620
		$result["argu"]=$conf;
6621
 
6622
		#檢查參數
6623
		#函式說明:
6624
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6625
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6626
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6627
		#$result["function"],當前執行的函式名稱.
6628
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6629
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6630
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6631
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6632
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6633
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6634
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6635
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6636
		#必填寫的參數:
6637
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6638
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6639
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6640
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","clientCache","serverCache","info");
6641
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
6642
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
6643
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6644
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6645
		#可以省略的參數:
6646
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6647
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6648
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6649
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6650
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6651
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
6652
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6653
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
6654
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6655
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
6656
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6657
		#$conf["arrayCountEqualCheck"][]=array();
6658
		#參考資料來源:
6659
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6660
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6661
		unset($conf["variableCheck::checkArguments"]);
6662
 
6663
		#如果檢查失敗
6664
		if($checkArguments["status"]==="false"){
6665
 
6666
			#設置錯誤識別
6667
			$result["status"]="false";
6668
 
6669
			#設置錯誤訊息
6670
			$result["error"]=$checkArguments;
6671
 
6672
			#回傳結果
6673
			return $result;
6674
 
6675
			}#if end
6676
 
6677
		#如果檢查不通過
6678
		if($checkArguments["passed"]==="false"){
6679
 
6680
			#設置錯誤識別
6681
			$result["status"]="false";
6682
 
6683
			#設置錯誤訊息
6684
			$result["error"]=$checkArguments;
6685
 
6686
			#回傳結果
6687
			return $result;
6688
 
6689
			}#if end
281 liveuser 6690
 
6691
		#預設不開啟 debug flag
6692
		$debug=false;
6693
 
6694
		#如果有設置 debug 為 "true"
6695
		if($info["share"]["debug"]==="true"){
6696
 
6697
			#設置 debug flag
6698
			$debug=true;
6699
 
6700
			}#if end
6701
 
261 liveuser 6702
		#另存 server cache 的參考
6703
		$serverCache=&$conf["serverCache"];
6704
 
255 liveuser 6705
		#針對每個 domain name
6706
		foreach($info["share"]["certInfo"] as $cInfo){
6707
 
6708
			#取得domain name
6709
			$cName=$cInfo["cName"];
6710
 
261 liveuser 6711
			#如果尚無對應domain name的記錄
6712
			if(!isset($serverCache[$cName])){
6713
 
6714
				#設置最新一次檢測的unixtime
6715
				$serverCache[$cName]["lastCheckUnixTime"]=time();
6716
 
6717
				}#if end
6718
 
6719
			#反之距離上次檢查不滿一天
6720
			else if(time()-$serverCache[$cName]["lastCheckUnixTime"]<86400){
6721
 
6722
				#跳過該 domain name 的檢查
6723
				continue;
6724
 
6725
				}#if end
6726
 
281 liveuser 6727
			#if enable debug
6728
			if($debug){
6729
 
6730
				#debug msg
6731
				echo "Checking domain name(".$cInfo["apiDomain"].") on zerossl...".PHP_EOL;
6732
 
6733
				}#if end
6734
 
255 liveuser 6735
			#嘗試取得 domain name 對應的可用憑證
6736
			#函式說明:
6737
			#取得在zerossl上的CSR清單
6738
			#回傳結果:
6739
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6740
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
6741
			#$result["function"],當前執行的函式名稱.
6742
			#$result["argu"],所使用的參數.
6743
			#$result["curl_verbose_info"],curl執行的詳細資訊.
6744
			#$result["content"],結果json字串.
6745
			#$result["tCount"],總共的資料筆數.
6746
			#$result["count"],該頁的筆數.
6747
			#$result["page"],當前的頁碼.
6748
			#$result["certs"],陣列,certificates清單,key為certificate的id.
6749
			#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
6750
			#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
6751
			#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
6752
			#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6753
			#必填參數:
6754
			#無
6755
			#可省略參數:
6756
			#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
6757
			$conf["zerossl::getCertList"]["apiDomain"]=$cInfo["apiDomain"];
6758
			#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
6759
			$conf["zerossl::getCertList"]["key"]=$cInfo["key"];
6760
			#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
6761
			$conf["zerossl::getCertList"]["cerStatus"]="issued";
6762
			#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
6763
			$conf["zerossl::getCertList"]["cerType"]="single90Days";
6764
			#$conf["search"],字串,透過certificate包含的domain來搜尋.
6765
			$conf["zerossl::getCertList"]["search"]=$cName;
6766
			#$conf["limit"],字串,一頁要多少筆,預設為100筆.
6767
			#$conf["limit"]="";
6768
			#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
6769
			#$conf["page"]="";
6770
			#參考資料:
6771
			#https://zerossl.com/documentation/api/list-certificates/
6772
			#備註:
6773
			#無.
6774
			$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
6775
			unset($conf["zerossl::getCertList"]);
6776
 
6777
			#符合條件的數量
6778
			#$getCertList["tCount"];
6779
 
6780
			#符合條件的當頁數量
6781
			#$getCertList["count"];
6782
 
6783
			#如果執行異常
6784
			if($getCertList["status"]==="false"){
6785
 
6786
				#設置錯誤識別
6787
				$result["status"]="false";
6788
 
6789
				#設置錯誤訊息
6790
				$result["error"]=$getCertList;
6791
 
6792
				#回傳結果
6793
				return $result;
6794
 
6795
				}#if end
6796
 
6797
			#如果沒有憑證
6798
			if($getCertList["count"]==="0"){
6799
 
281 liveuser 6800
				#if enable debug
6801
				if($debug){
6802
 
6803
					#debug msg
6804
					echo "There is not valid ssl for domain name(".$cInfo["apiDomain"].") on zerossl.".PHP_EOL;
6805
 
6806
					}#if end
6807
 
6808
				#if enable debug
6809
				if($debug){
6810
 
6811
					#debug msg
6812
					echo "Checking ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
6813
 
6814
					}#if end
6815
 
255 liveuser 6816
				#確認有無對應 cName 的 private key
6817
				#函式說明:
6818
				#檢查多個檔案與資料夾是否存在.
6819
				#回傳的結果:
6820
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6821
				#$result["error"],錯誤訊息陣列.
6822
				#$resutl["function"],當前執行的涵式名稱.
6823
				#$result["argu"],使用的參數.
6824
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6825
				#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
6826
				#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
6827
				#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
6828
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6829
				#必填參數:
6830
				#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
6831
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["pKey"]);
6832
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6833
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
6834
				#可省略參數:
6835
				#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
6836
				#$conf["disableWebSearch"]="false";
6837
				#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
6838
				$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
6839
				#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
6840
				$conf["fileAccess::checkMultiFileExist"]["web"]="false";
6841
				#參考資料:
6842
				#http://php.net/manual/en/function.file-exists.php
6843
				#http://php.net/manual/en/control-structures.foreach.php
6844
				#備註:
6845
				#函數file_exists檢查的路徑為檔案系統的路徑
6846
				#$result["varName"][$i]結果未實作
6847
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6848
				unset($conf["fileAccess::checkMultiFileExist"]);
6849
 
6850
				#如果運行異常
6851
				if($checkMultiFileExist["status"]==="false"){
6852
 
6853
					#設置錯誤識別
6854
					$result["status"]="false";
6855
 
6856
					#設置錯誤訊息
6857
					$result["error"]=$getCertList;
6858
 
6859
					#回傳結果
6860
					return $result;
6861
 
6862
					}#if end
6863
 
6864
				#如果沒有 private key
6865
				if($checkMultiFileExist["allExist"]==="false"){
6866
 
281 liveuser 6867
					#if enable debug
6868
					if($debug){
6869
 
6870
						#debug msg
6871
						echo "there is no ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
6872
 
6873
						}#if end
6874
 
6875
					#if enable debug
6876
					if($debug){
6877
 
6878
						#debug msg
6879
						echo "creating ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
6880
 
6881
						}#if end
6882
 
255 liveuser 6883
					#建立 private key
6884
					#函式說明:
6885
					#產生ssl private key.
6886
					#回傳結果:
6887
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6888
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
6889
					#$result["function"],當前執行的函式名稱.
6890
					#$result["argu"],所使用的參數.
6891
					#$result["curl_verbose_info"],curl執行的詳細資訊.
6892
					#$result["content"],ssl用的private key.
6893
					#必填參數:
6894
					#$conf["fileArgu"],字串,變數__FILE__的內容.
6895
					$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
6896
					#可省略參數:
6897
					#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
6898
					#$conf["length"]=4096';
6899
					#參考資料:
6900
					#無.
6901
					#備註:
6902
					#key generated by openssl with RSA.
6903
					$createPrivateKey=openssl::createPrivateKey($conf["openssl::createPrivateKey"]);
6904
					unset($conf["openssl::createPrivateKey"]);
6905
 
6906
					#如果運行異常
6907
					if($createPrivateKey["status"]==="false"){
6908
 
6909
						#設置錯誤識別
6910
						$result["status"]="false";
6911
 
6912
						#設置錯誤訊息
6913
						$result["error"]=$createPrivateKey;
6914
 
6915
						#回傳結果
6916
						return $result;
6917
 
6918
						}#if end
6919
 
6920
					#另存private key的字串
6921
					$pKeyStr=$createPrivateKey["content"];
6922
 
6923
					#建立private key檔案
6924
					#函式說明:
6925
					#將字串寫入到檔案
6926
					#回傳結果:
6927
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
6928
					#$result["error"],錯誤訊息陣列.
6929
					#$result["function"],當前執行的函數名稱.
6930
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
6931
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
6932
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
6933
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
6934
					#$result["argu"],使用的參數.
6935
					#必填參數:
6936
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6937
					$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
6938
					#可省略參數:
6939
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
6940
					$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["pKey"];
6941
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
6942
					$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
6943
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
6944
					#$conf["writeMethod"]="a";
6945
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
6946
					#$conf["checkRepeat"]="";
6947
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
6948
					#$conf["filenameExtensionStartPoint"]="";
6949
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
6950
					#$conf["repeatNameRule"]="";
6951
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
6952
					$conf["zerossl::writeTextIntoFile"]["web"]="false";
6953
					#參考資料:
6954
					#無.
6955
					#備註:
6956
					#無.
6957
					$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
6958
					unset($conf["zerossl::writeTextIntoFile"]);
6959
 
6960
					#如果運行異常
6961
					if($writeTextIntoFile["status"]==="false"){
6962
 
6963
						#設置錯誤識別
6964
						$result["status"]="false";
6965
 
6966
						#設置錯誤訊息
6967
						$result["error"]=$writeTextIntoFile;
6968
 
6969
						#回傳結果
6970
						return $result;
6971
 
6972
						}#if end
6973
 
6974
					}#if end
6975
 
281 liveuser 6976
				#if enable debug
6977
				if($debug){
6978
 
6979
					#debug msg
6980
					echo "Creating domain name(".$cInfo["apiDomain"].") csr for zerossl...".PHP_EOL;
6981
 
6982
					}#if end
6983
 
255 liveuser 6984
				#建立準備給zerossl的csr
6985
				#函式說明:
6986
				#產生certificate sign request(CSR).
6987
				#回傳結果:
6988
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6989
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
6990
				#$result["function"],當前執行的函式名稱.
6991
				#$result["argu"],所使用的參數.
6992
				#$result["content"],csr內容.
6993
				#$result["curl_verbose_info"],curl執行的詳細資訊.
6994
				#$result["privateKey"], private key 的內容.
6995
				#必填參數:
6996
				#$conf["domain"],字串,csr內容的網域名稱.
6997
				$conf["zerossl::createCSR"]["domain"]=$cName;
6998
				#可省略參數:
6999
				#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
7000
				#$conf["pKey"]="";
7001
				#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
7002
				#$conf["country"]="";
7003
				#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
7004
				#$conf["state"]="";
7005
				#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
7006
				#$conf["org"]="";
7007
				#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
7008
				#$conf["unit"]="";
7009
				#參考資料:
7010
				#無.
7011
				#備註:
7012
				#無.
7013
				$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
7014
				unset($conf["zerossl::createCSR"]);
7015
 
7016
				#如果運行異常
7017
				if($createCSR["status"]==="false"){
7018
 
7019
					#設置錯誤識別
7020
					$result["status"]="false";
7021
 
7022
					#設置錯誤訊息
7023
					$result["error"]=$createCSR;
7024
 
7025
					#回傳結果
7026
					return $result;
7027
 
7028
					}#if end
7029
 
7030
				#取得本地端產生的csr內容
7031
				$csrLocal=$createCSR["content"];
7032
 
281 liveuser 7033
				#if enable debug
7034
				if($debug){
7035
 
7036
					#debug msg
7037
					echo "Creating certificate for domain name(".$cInfo["apiDomain"].") on zerossl...".PHP_EOL;
7038
 
7039
					}#if end
7040
 
255 liveuser 7041
				#函式說明:
281 liveuser 7042
				#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 7043
				#回傳結果:
7044
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7045
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
7046
				#$result["function"],當前執行的函式名稱.
7047
				#$result["argu"],所使用的參數.
7048
				#$result["curl_verbose_info"],curl執行的詳細資訊.
7049
				#$result["id"],用於zerossl api驗證domain的id.
7050
				#$result["content"],字串,得到的json字串回應.
7051
				#$result["cnameKey"],用於dns CNAME驗證鍵名.
7052
				#$result["cnameVal"],用於dms CNAME驗證鍵值.
7053
				#必填參數:
7054
				#$conf["certificate_domains"],字串,要簽署的doamin名稱.
7055
				$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
7056
				#$conf["certificate_csr"],字串,簽署的資訊.
7057
				$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
7058
				#$conf["fileArgu"],字串,變數__FILE__的內容.
7059
				$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
7060
				#可省略參數:
7061
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7062
				$conf["zerossl::createCertificate"]["apiDomain"]=$cInfo["domain"];
7063
				#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
7064
				#$conf["path"]=self::getApiInfo()["csrPath"];
7065
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7066
				$conf["zerossl::createCertificate"]["key"]=$cInfo["key"];
7067
				#參考資料:
7068
				#無.
7069
				#備註:
7070
				#無.
7071
				$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
7072
				unset($conf["zerossl::createCertificate"]);
7073
 
7074
				#如果執行異常
7075
				if($createCertificate["status"]==="false"){
7076
 
7077
					#設置錯誤識別
7078
					$result["status"]="false";
7079
 
7080
					#設置錯誤訊息
7081
					$result["error"]=$createCertificate;
7082
 
7083
					#回傳結果
7084
					return $result;
7085
 
7086
					}#if end
7087
 
7088
				#取得csr在zerossl上的id
7089
				$csrId=$createCertificate["id"];
7090
 
7091
				#取得cname key
7092
				$cNameKey=$createCertificate["cnameKey"];
7093
 
7094
				#取得cname val
7095
				$cNameVal=$createCertificate["cnameVal"];
7096
 
7097
				#初始化要增加的RR記錄
7098
				$rr2add=array();
7099
 
7100
				#設置CNAME的查詢
7101
				$rr2add["query"]=$cNameKey;
7102
 
7103
				#設置CNAME的value
7104
				$rr2add["value"]=$cNameVal;
7105
 
7106
				#設置類型為 CNAME
7107
				$rr2add["type"]="CNAME";
7108
 
7109
				#設置註解
7110
				$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
7111
 
281 liveuser 7112
				#if enable debug
7113
				if($debug){
7114
 
7115
					#debug msg
7116
					echo "Adding DNS record to validate certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
7117
 
7118
					}#if end
7119
 
255 liveuser 7120
				#函式說明:
7121
				#新增DNS記錄到檔案裡面.
7122
				#回傳結果:
7123
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7124
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
7125
				#$result["function"],當前執行的函式名稱.
7126
				#$result["argu"],所使用的參數.
7127
				#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
7128
				#$result["domain"],字串,RR所屬domain.
7129
				#$result["defaultTTL"],字串,預設的RR更新時間.
7130
				#$result["comment"],字串陣列,逐行的註解.
7131
				#必填參數:
7132
				#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
7133
				$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2ad);
7134
				#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
7135
				$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
7136
				#可省略參數:
7137
				#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
7138
				$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
7139
				#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
7140
				#$conf["debug"]="false";
7141
				#參考資料:
7142
				#無.
7143
				#備註:
7144
				#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
7145
				#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
7146
				#php-pear上的Net_DNS2也可以解析RR.
7147
				$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
7148
				unset($conf["zerossl::updateDnsRecordFile"]);
7149
 
7150
				#如果執行異常
7151
				if($updateDnsRecordFile["status"]==="false"){
7152
 
7153
					#設置錯誤識別
7154
					$result["status"]="false";
7155
 
7156
					#設置錯誤訊息
7157
					$result["error"]=$updateDnsRecordFile;
7158
 
7159
					#回傳結果
7160
					return $result;
7161
 
7162
					}#if end
281 liveuser 7163
 
7164
				#if enable debug
7165
				if($debug){
7166
 
7167
					#debug msg
7168
					echo "Restart DNS service to validate certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
7169
 
7170
					}#if end
7171
 
255 liveuser 7172
				#重新啟動dns伺服器
7173
				#函式說明:
7174
				#呼叫shell執行系統命令,並取得回傳的內容.
7175
				#回傳結果:
7176
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7177
				#$result["error"],錯誤訊息陣列.
7178
				#$result["function"],當前執行的函數名稱.
7179
				#$result["argu"],使用的參數.
7180
				#$result["cmd"],執行的指令內容.
7181
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
7182
				#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
7183
				#$result["content"],為執行完後的輸出字串.
7184
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
7185
				#$result["running"],是否還在執行.
7186
				#$result["pid"],pid.
7187
				#$result["statusCode"],執行結束後的代碼.
7188
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
7189
				#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
7190
				#必填參數:
7191
				#$conf["command"],字串,要執行的指令.
7192
				$conf["external::callShell"]["command"]="systemd";
7193
				#$conf["fileArgu"],字串,變數__FILE__的內容.
7194
				$conf["external::callShell"]["fileArgu"]=__FILE__;
7195
				#可省略參數:
7196
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7197
				$conf["external::callShell"]["argu"]=array("restart","named");
7198
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
7199
				#$conf["arguIsAddr"]=array();
7200
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
7201
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
7202
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
7203
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7204
				#$conf["enablePrintDescription"]="true";
7205
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
7206
				#$conf["printDescription"]="";
7207
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
7208
				#$conf["escapeshellarg"]="false";
7209
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
7210
				#$conf["thereIsShellVar"]=array();
7211
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
7212
				#$conf["username"]="";
7213
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
7214
				#$conf["password"]="";
7215
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
7216
				#$conf["useScript"]="";
7217
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
7218
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
7219
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
7220
				#$conf["inBackGround"]="";
7221
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
7222
				#$conf["getErr"]="false";
7223
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
7224
				#$conf["doNotRun"]="false";
7225
				#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
7226
				$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
7227
				#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
7228
				#$conf["remoteUser"]="root";
7229
				#參考資料:
7230
				#exec=>http://php.net/manual/en/function.exec.php
7231
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7232
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7233
				#備註:
7234
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
7235
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
7236
				$callShell=external::callShell($conf["external::callShell"]);
7237
				unset($conf["external::callShell"]);
7238
 
7239
				#如果執行異常
7240
				if($callShell["status"]==="false"){
7241
 
7242
					#設置錯誤識別
7243
					$result["status"]="false";
7244
 
7245
					#設置錯誤訊息
7246
					$result["error"]=$callShell;
7247
 
7248
					#回傳結果
7249
					return $result;
7250
 
7251
					}#if end
281 liveuser 7252
 
7253
				#if enable debug
7254
				if($debug){
7255
 
7256
					#debug msg
7257
					echo "Request zerossl to validate certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
7258
 
7259
					}#if end
7260
 
255 liveuser 7261
				#函式說明:
7262
				#請求驗證已經透過zerossl::createCertificate要求的domain.
7263
				#回傳結果:
7264
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7265
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
7266
				#$result["function"],當前執行的函式名稱.
7267
				#$result["argu"],所使用的參數.
7268
				#$result["curl_verbose_info"],curl執行的詳細資訊.
7269
				#$result["content"],結果json字串.
7270
				#必填參數:
7271
				#$conf["id"],字串,zerossl::createCertificate回傳的id.
7272
				$conf["zerossl::verifyDomain"]["id"]=$csrId;
7273
				#可省略參數:
7274
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7275
				$conf["zerossl::verifyDomain"]["apiDomain"]=$cInfo["domain"];
7276
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7277
				$conf["zerossl::verifyDomain"]["key"]=$cInfo["key"];
7278
				#參考資料:
7279
				#https://zerossl.com/documentation/api/verify-domains/
7280
				#備註:
7281
				#無.
7282
				$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
7283
				unset($conf["zerossl::verifyDomain"]);
7284
 
7285
				#如果執行異常
7286
				if($verifyDomain["status"]==="false"){
7287
 
7288
					#設置錯誤識別
7289
					$result["status"]="false";
7290
 
7291
					#設置錯誤訊息
7292
					$result["error"]=$verifyDomain;
7293
 
7294
					#回傳結果
7295
					return $result;
7296
 
7297
					}#if end
281 liveuser 7298
 
7299
				#if enable debug
7300
				if($debug){
7301
 
7302
					#debug msg
7303
					echo "Downloading certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
7304
 
7305
					}#if end
7306
 
255 liveuser 7307
				#函式說明:
7308
				#下載certificate.
7309
				#回傳結果:
7310
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7311
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
7312
				#$result["function"],當前執行的函式名稱.
7313
				#$result["argu"],所使用的參數.
7314
				#$result["curl_verbose_info"],curl執行的詳細資訊.
7315
				#$result["content"],結果json字串.
7316
				#$result["certificate.crt"],字串,certificate.crt的內容.
7317
				#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
7318
				#必填參數:
7319
				#無.
7320
				#可省略參數:
7321
				#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
7322
				$conf["zerossl::getCert"]["apiDomain"]=$cInfo["domain"];
7323
				#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
7324
				$conf["zerossl::getCert"]["key"]=$cInfo["key"];
7325
				#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
7326
				$conf["zerossl::getCert"]["id"]=$csrId;
7327
				#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
7328
				#$conf["zerossl::getCert"]["cname"]="";
7329
				#參考資料:
7330
				#https://zerossl.com/documentation/api/download-certificate-inline/
7331
				#備註:
7332
				#無.
7333
				$getCert=zerossl::getCert($conf["zerossl::getCert"]);
7334
				unset($conf["zerossl::getCert"]);
7335
 
7336
				#如果執行異常
7337
				if($getCert["status"]==="false"){
7338
 
7339
					#設置錯誤識別
7340
					$result["status"]="false";
7341
 
7342
					#設置錯誤訊息
7343
					$result["error"]=$getCert;
7344
 
7345
					#回傳結果
7346
					return $result;
7347
 
7348
					}#if end
281 liveuser 7349
 
7350
				#if enable debug
7351
				if($debug){
7352
 
7353
					#debug msg
7354
					echo "Creating certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
7355
 
7356
					}#if end
7357
 
255 liveuser 7358
				#建立 certificate.crt 檔案
7359
				#$cInfo["certPath"];
7360
 
7361
				#建立 ca_bundle.crt 檔案
7362
				#$cInfo["caPath"];
7363
 
7364
				#建立 certAndCa.crt 檔案
7365
				#$cInfo["certWithCaPath"];
7366
 
7367
				#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
7368
				#函式說明:
7369
				#一次建立多個檔案,並寫入內容.
7370
				#回傳結果:
7371
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
7372
				#$result["error"],錯誤訊息陣列.
7373
				#$result["function"],當前執行的函數名稱.
7374
				#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
7375
				#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
7376
				#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
7377
				#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
7378
				#$result["argu"],使用的參數.
7379
				#必填參數:
7380
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7381
				$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
7382
				#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
7383
				$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certPath"],$cInfo["caPath"],$cInfo["certWithCaPath"]);
7384
				#可省略參數:
7385
				#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
7386
				$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
7387
				#參考資料:
7388
				#無.
7389
				#備註:
7390
				#無.
7391
				$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
7392
				unset($conf["zerossl::writeMultiFile"]);
7393
 
7394
				#如果執行異常
7395
				if($writeMultiFile["status"]==="false"){
7396
 
7397
					#設置錯誤識別
7398
					$result["status"]="false";
7399
 
7400
					#設置錯誤訊息
7401
					$result["error"]=$writeMultiFile;
7402
 
7403
					#回傳結果
7404
					return $result;
7405
 
7406
					}#if end
7407
 
7408
				#儲存 actionAfterUpdateCert
7409
				$action=$cInfo["actionAfterUpdateCert"];
7410
 
7411
				#如果有多個指令要執行
7412
				if(gettype($action[0])==="array"){
7413
 
281 liveuser 7414
					#if enable debug
7415
					if($debug){
7416
 
7417
						#debug msg
7418
						echo "There are many cmds to run to apply certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
7419
 
7420
						}#if end
7421
 
7422
					#if enable debug
7423
					if($debug){
7424
 
7425
						#debug msg
7426
						echo "Running cmd to apply certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
7427
 
7428
						}#if end
7429
 
255 liveuser 7430
					#針對每的指令
7431
					foreach($action as $ac){
7432
 
281 liveuser 7433
						#if enable debug
7434
						if($debug){
7435
 
7436
							#debug msg
7437
							echo ".".PHP_EOL;
7438
 
7439
							}#if end
7440
 
255 liveuser 7441
						#函式說明:
7442
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
7443
						#回傳結果:
7444
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7445
						#$result["error"],錯誤訊息陣列.
7446
						#$result["function"],當前執行的函數名稱.
7447
						#$result["argu"],使用的參數.
7448
						#$result["cmd"],執行的指令名稱.
7449
						#$result["params"],執行指令伴隨的參數.
7450
						#必填參數:
7451
						#$conf["cmdArray"],字串陣列,要執行的指令字串.
7452
						$conf["external::callShellHelper"]["cmdArray"]=$ac;
7453
						#可省略參數:
7454
						#無.
7455
						#參考資料:
7456
						#array_shift=>https://www.php.net/manual/en/function.array-shift.php
7457
						#備註:
7458
						#無.
7459
						$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
7460
						unset($conf["external::callShellHelper"]);
7461
 
7462
						#如果執行異常
7463
						if($callShellHelper["status"]==="false"){
7464
 
7465
							#設置錯誤識別
7466
							$result["status"]="false";
7467
 
7468
							#設置錯誤訊息
7469
							$result["error"]=$callShellHelper;
7470
 
7471
							#回傳結果
7472
							return $result;
7473
 
7474
							}#if end
7475
 
7476
						#函式說明:
7477
						#呼叫shell執行系統命令,並取得回傳的內容.
7478
						#回傳結果:
7479
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7480
						#$result["error"],錯誤訊息陣列.
7481
						#$result["function"],當前執行的函數名稱.
7482
						#$result["argu"],使用的參數.
7483
						#$result["cmd"],執行的指令內容.
7484
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
7485
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
7486
						#$result["content"],為執行完後的輸出字串.
7487
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
7488
						#$result["running"],是否還在執行.
7489
						#$result["pid"],pid.
7490
						#$result["statusCode"],執行結束後的代碼.
7491
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
7492
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
7493
						#必填參數:
7494
						#$conf["command"],字串,要執行的指令.
7495
						$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
7496
						#$conf["fileArgu"],字串,變數__FILE__的內容.
7497
						$conf["external::callShell"]["fileArgu"]=__FILE__;
7498
						#可省略參數:
7499
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7500
						$conf["external::callShell"]["argu"]=$callShellHelper["params"];
7501
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
7502
						#$conf["arguIsAddr"]=array();
7503
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
7504
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
7505
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
7506
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7507
						#$conf["enablePrintDescription"]="true";
7508
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
7509
						#$conf["printDescription"]="";
7510
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
7511
						$conf["external::callShell"]["escapeshellarg"]="true";
7512
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
7513
						#$conf["thereIsShellVar"]=array();
7514
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
7515
						#$conf["username"]="";
7516
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
7517
						#$conf["password"]="";
7518
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
7519
						#$conf["useScript"]="";
7520
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
7521
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
7522
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
7523
						#$conf["inBackGround"]="";
7524
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
7525
						#$conf["getErr"]="false";
7526
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
7527
						#$conf["doNotRun"]="false";
7528
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
7529
						#$conf["remoteIp"]="";
7530
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
7531
						#$conf["remoteUser"]="";
7532
						#參考資料:
7533
						#exec=>http://php.net/manual/en/function.exec.php
7534
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7535
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7536
						#備註:
7537
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
7538
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
7539
						$callShell=external::callShell($conf["external::callShell"]);
7540
						unset($conf["external::callShell"]);
7541
 
7542
						#如果執行異常
7543
						if($callShellHelper["status"]==="false"){
7544
 
7545
							#設置錯誤識別
7546
							$result["status"]="false";
7547
 
7548
							#設置錯誤訊息
7549
							$result["error"]=$callShell;
7550
 
7551
							#回傳結果
7552
							return $result;
7553
 
7554
							}#if end
7555
 
7556
						}#foreach end
7557
 
7558
					}#if end
7559
 
7560
				#反之
7561
				else{
7562
 
281 liveuser 7563
					#if enable debug
7564
					if($debug){
7565
 
7566
						#debug msg
7567
						echo "There is only one cmd to run to apply certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
7568
 
7569
						}#if end
7570
 
7571
					#if enable debug
7572
					if($debug){
7573
 
7574
						#debug msg
7575
						echo ".".PHP_EOL;
7576
 
7577
						}#if end
7578
 
255 liveuser 7579
					#函式說明:
7580
					#解析指令與參數,回傳指令與參數給 callShell 函式使用.
7581
					#回傳結果:
7582
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7583
					#$result["error"],錯誤訊息陣列.
7584
					#$result["function"],當前執行的函數名稱.
7585
					#$result["argu"],使用的參數.
7586
					#$result["cmd"],執行的指令名稱.
7587
					#$result["params"],執行指令伴隨的參數.
7588
					#必填參數:
7589
					#$conf["cmdArray"],字串陣列,要執行的指令字串.
7590
					$conf["external::callShellHelper"]["cmdArray"]=$action;
7591
					#可省略參數:
7592
					#無.
7593
					#參考資料:
7594
					#array_shift=>https://www.php.net/manual/en/function.array-shift.php
7595
					#備註:
7596
					#無.
7597
					$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
7598
					unset($conf["external::callShellHelper"]);
7599
 
7600
					#如果執行異常
7601
					if($callShellHelper["status"]==="false"){
7602
 
7603
						#設置錯誤識別
7604
						$result["status"]="false";
7605
 
7606
						#設置錯誤訊息
7607
						$result["error"]=$callShellHelper;
7608
 
7609
						#回傳結果
7610
						return $result;
7611
 
7612
						}#if end
7613
 
7614
					#函式說明:
7615
					#呼叫shell執行系統命令,並取得回傳的內容.
7616
					#回傳結果:
7617
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7618
					#$result["error"],錯誤訊息陣列.
7619
					#$result["function"],當前執行的函數名稱.
7620
					#$result["argu"],使用的參數.
7621
					#$result["cmd"],執行的指令內容.
7622
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
7623
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
7624
					#$result["content"],為執行完後的輸出字串.
7625
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
7626
					#$result["running"],是否還在執行.
7627
					#$result["pid"],pid.
7628
					#$result["statusCode"],執行結束後的代碼.
7629
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
7630
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
7631
					#必填參數:
7632
					#$conf["command"],字串,要執行的指令.
7633
					$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
7634
					#$conf["fileArgu"],字串,變數__FILE__的內容.
7635
					$conf["external::callShell"]["fileArgu"]=__FILE__;
7636
					#可省略參數:
7637
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7638
					$conf["external::callShell"]["argu"]=$callShellHelper["params"];
7639
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
7640
					#$conf["arguIsAddr"]=array();
7641
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
7642
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
7643
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
7644
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7645
					#$conf["enablePrintDescription"]="true";
7646
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
7647
					#$conf["printDescription"]="";
7648
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
7649
					$conf["external::callShell"]["escapeshellarg"]="true";
7650
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
7651
					#$conf["thereIsShellVar"]=array();
7652
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
7653
					#$conf["username"]="";
7654
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
7655
					#$conf["password"]="";
7656
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
7657
					#$conf["useScript"]="";
7658
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
7659
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
7660
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
7661
					#$conf["inBackGround"]="";
7662
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
7663
					#$conf["getErr"]="false";
7664
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
7665
					#$conf["doNotRun"]="false";
7666
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
7667
					#$conf["remoteIp"]="";
7668
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
7669
					#$conf["remoteUser"]="";
7670
					#參考資料:
7671
					#exec=>http://php.net/manual/en/function.exec.php
7672
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7673
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7674
					#備註:
7675
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
7676
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
7677
					$callShell=external::callShell($conf["external::callShell"]);
7678
					unset($conf["external::callShell"]);
7679
 
7680
					#如果執行異常
7681
					if($callShellHelper["status"]==="false"){
7682
 
7683
						#設置錯誤識別
7684
						$result["status"]="false";
7685
 
7686
						#設置錯誤訊息
7687
						$result["error"]=$callShell;
7688
 
7689
						#回傳結果
7690
						return $result;
7691
 
7692
						}#if end
7693
 
7694
					}#else end
7695
 
7696
				}#if end
7697
 
7698
			#反之
7699
			else{
7700
 
281 liveuser 7701
				#if enable debug
7702
				if($debug){
7703
 
7704
					#debug msg
7705
					echo "There is already valid ssl for domain name(".$cInfo["apiDomain"].") on zerossl".PHP_EOL;
7706
 
7707
					}#if end
7708
 
255 liveuser 7709
				#有 issued 的憑證
7710
 
7711
				#取得 certificate id at zerossl
7712
				#函式說明:
7713
				#將陣列轉換成存有key與value的陣列
7714
				#回傳的結果:
7715
				#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
7716
				#$result["function"],當前執行的函數
7717
				#$result["error"],錯誤訊息.
7718
				#$result[$i]["key"],原先$i+1個元素的key.
7719
				#$result[$i]["value"],原先$i+1個元素的value.
7720
				#必填參數:
7721
				#$conf["rawInputArray"],陣列,要轉換的陣列變數.
7722
				$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
7723
				#可省略參數:
7724
				#無.
7725
				#參考資料:
7726
				#無.
7727
				#備註:
7728
				#無.
7729
				$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
7730
				unset($conf["arrays::getKeyAndValue"]);
7731
 
7732
				#如果執行異常
7733
				if($getKeyAndValue["status"]==="false"){
7734
 
7735
					#設置錯誤識別
7736
					$result["status"]="false";
7737
 
7738
					#設置錯誤訊息
7739
					$result["error"]=$getKeyAndValue;
7740
 
7741
					#回傳結果
7742
					return $result;
7743
 
7744
					}#if end
7745
 
7746
				#儲存 certificate id at zerossl
7747
				$csrId=$getKeyAndValue["key"][0];
7748
 
7749
				#檢查憑證是否已經快過期
7750
				$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
7751
 
7752
				#如果距離當下不到2個星期就要過期
7753
				if($expiresIn<=86400*14){
7754
 
281 liveuser 7755
					#if enable debug
7756
					if($debug){
7757
 
7758
						#debug msg
7759
						echo "Valid ssl for domain name(".$cInfo["apiDomain"].") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
7760
 
7761
						}#if end
7762
 
255 liveuser 7763
					#另存舊的憑證id,最後要revoke之.
7764
					$oldCsrId=$csrId;
7765
 
281 liveuser 7766
					#if enable debug
7767
					if($debug){
7768
 
7769
						#debug msg
7770
						echo "Start requst new ssl process for domain name(".$cInfo["apiDomain"].").".PHP_EOL;
7771
 
7772
						}#if end
7773
 
7774
					#if enable debug
7775
					if($debug){
7776
 
7777
						#debug msg
7778
						echo "Finding ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
7779
 
7780
						}#if end
7781
 
255 liveuser 7782
					#確認有無對應 cName 的 private key
7783
					#函式說明:
7784
					#檢查多個檔案與資料夾是否存在.
7785
					#回傳的結果:
7786
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7787
					#$result["error"],錯誤訊息陣列.
7788
					#$resutl["function"],當前執行的涵式名稱.
7789
					#$result["argu"],使用的參數.
7790
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
7791
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
7792
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
7793
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
7794
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
7795
					#必填參數:
7796
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
7797
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["pKey"]);
7798
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7799
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
7800
					#可省略參數:
7801
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
7802
					#$conf["disableWebSearch"]="false";
7803
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
7804
					$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
7805
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
7806
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
7807
					#參考資料:
7808
					#http://php.net/manual/en/function.file-exists.php
7809
					#http://php.net/manual/en/control-structures.foreach.php
7810
					#備註:
7811
					#函數file_exists檢查的路徑為檔案系統的路徑
7812
					#$result["varName"][$i]結果未實作
7813
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
7814
					unset($conf["fileAccess::checkMultiFileExist"]);
7815
 
7816
					#如果運行異常
7817
					if($checkMultiFileExist["status"]==="false"){
7818
 
7819
						#設置錯誤識別
7820
						$result["status"]="false";
7821
 
7822
						#設置錯誤訊息
7823
						$result["error"]=$getCertList;
7824
 
7825
						#回傳結果
7826
						return $result;
7827
 
7828
						}#if end
7829
 
7830
					#如果沒有 private key
7831
					if($checkMultiFileExist["allExist"]==="false"){
7832
 
281 liveuser 7833
						#if enable debug
7834
						if($debug){
7835
 
7836
							#debug msg
7837
							echo "Thers is no ssl private key for domain name(".$cInfo["apiDomain"].").".PHP_EOL;
7838
 
7839
							}#if end
7840
 
7841
						#if enable debug
7842
						if($debug){
7843
 
7844
							#debug msg
7845
							echo "Creating ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
7846
 
7847
							}#if end
7848
 
255 liveuser 7849
						#建立 private key
7850
						#函式說明:
7851
						#產生ssl private key.
7852
						#回傳結果:
7853
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7854
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
7855
						#$result["function"],當前執行的函式名稱.
7856
						#$result["argu"],所使用的參數.
7857
						#$result["curl_verbose_info"],curl執行的詳細資訊.
7858
						#$result["content"],ssl用的private key.
7859
						#必填參數:
7860
						#$conf["fileArgu"],字串,變數__FILE__的內容.
7861
						$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
7862
						#可省略參數:
7863
						#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
7864
						#$conf["length"]=4096';
7865
						#參考資料:
7866
						#無.
7867
						#備註:
7868
						#key generated by openssl with RSA.
7869
						$createPrivateKey=openssl::createPrivateKey($conf["openssl::createPrivateKey"]);
7870
						unset($conf["openssl::createPrivateKey"]);
7871
 
7872
						#如果運行異常
7873
						if($createPrivateKey["status"]==="false"){
7874
 
7875
							#設置錯誤識別
7876
							$result["status"]="false";
7877
 
7878
							#設置錯誤訊息
7879
							$result["error"]=$createPrivateKey;
7880
 
7881
							#回傳結果
7882
							return $result;
7883
 
7884
							}#if end
7885
 
7886
						#另存private key的字串
7887
						$pKeyStr=$createPrivateKey["content"];
7888
 
281 liveuser 7889
						#if enable debug
7890
						if($debug){
7891
 
7892
							#debug msg
7893
							echo "Writing ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
7894
 
7895
							}#if end
7896
 
255 liveuser 7897
						#建立private key檔案
7898
						#函式說明:
7899
						#將字串寫入到檔案
7900
						#回傳結果:
7901
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
7902
						#$result["error"],錯誤訊息陣列.
7903
						#$result["function"],當前執行的函數名稱.
7904
						#$result["fileInfo"],實際上寫入的檔案資訊陣列.
7905
						#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
7906
						#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
7907
						#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
7908
						#$result["argu"],使用的參數.
7909
						#必填參數:
7910
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7911
						$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
7912
						#可省略參數:
7913
						#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
7914
						$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["pKey"];
7915
						#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
7916
						$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
7917
						#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
7918
						#$conf["writeMethod"]="a";
7919
						#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
7920
						#$conf["checkRepeat"]="";
7921
						#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
7922
						#$conf["filenameExtensionStartPoint"]="";
7923
						#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
7924
						#$conf["repeatNameRule"]="";
7925
						#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
7926
						$conf["zerossl::writeTextIntoFile"]["web"]="false";
7927
						#參考資料:
7928
						#無.
7929
						#備註:
7930
						#無.
7931
						$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
7932
						unset($conf["zerossl::writeTextIntoFile"]);
7933
 
7934
						#如果運行異常
7935
						if($writeTextIntoFile["status"]==="false"){
7936
 
7937
							#設置錯誤識別
7938
							$result["status"]="false";
7939
 
7940
							#設置錯誤訊息
7941
							$result["error"]=$writeTextIntoFile;
7942
 
7943
							#回傳結果
7944
							return $result;
7945
 
7946
							}#if end
7947
 
7948
						}#if end
7949
 
281 liveuser 7950
					#if enable debug
7951
					if($debug){
7952
 
7953
						#debug msg
7954
						echo "Creating CSR for domain name(".$cInfo["apiDomain"].") to zerossl.".PHP_EOL;
7955
 
7956
						}#if end
7957
 
255 liveuser 7958
					#建立準備給zerossl的csr
7959
					#函式說明:
7960
					#產生certificate sign request(CSR).
7961
					#回傳結果:
7962
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7963
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
7964
					#$result["function"],當前執行的函式名稱.
7965
					#$result["argu"],所使用的參數.
7966
					#$result["content"],csr內容.
7967
					#$result["curl_verbose_info"],curl執行的詳細資訊.
7968
					#$result["privateKey"], private key 的內容.
7969
					#必填參數:
7970
					#$conf["domain"],字串,csr內容的網域名稱.
7971
					$conf["zerossl::createCSR"]["domain"]=$cName;
7972
					#可省略參數:
7973
					#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
7974
					#$conf["pKey"]="";
7975
					#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
7976
					#$conf["country"]="";
7977
					#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
7978
					#$conf["state"]="";
7979
					#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
7980
					#$conf["org"]="";
7981
					#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
7982
					#$conf["unit"]="";
7983
					#參考資料:
7984
					#無.
7985
					#備註:
7986
					#無.
7987
					$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
7988
					unset($conf["zerossl::createCSR"]);
7989
 
7990
					#如果運行異常
7991
					if($createCSR["status"]==="false"){
7992
 
7993
						#設置錯誤識別
7994
						$result["status"]="false";
7995
 
7996
						#設置錯誤訊息
7997
						$result["error"]=$createCSR;
7998
 
7999
						#回傳結果
8000
						return $result;
8001
 
8002
						}#if end
8003
 
8004
					#取得本地端產生的csr內容
8005
					$csrLocal=$createCSR["content"];
8006
 
281 liveuser 8007
					#if enable debug
8008
					if($debug){
8009
 
8010
						#debug msg
8011
						echo "Providing CSR for domain name(".$cInfo["apiDomain"].") to zerossl".PHP_EOL;
8012
 
8013
						}#if end
8014
 
255 liveuser 8015
					#函式說明:
281 liveuser 8016
					#提供certificate sign request(CSR)透過zerossl產生certificate.
255 liveuser 8017
					#回傳結果:
8018
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8019
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8020
					#$result["function"],當前執行的函式名稱.
8021
					#$result["argu"],所使用的參數.
8022
					#$result["curl_verbose_info"],curl執行的詳細資訊.
8023
					#$result["id"],用於zerossl api驗證domain的id.
8024
					#$result["content"],字串,得到的json字串回應.
8025
					#$result["cnameKey"],用於dns CNAME驗證鍵名.
8026
					#$result["cnameVal"],用於dms CNAME驗證鍵值.
8027
					#必填參數:
8028
					#$conf["certificate_domains"],字串,要簽署的doamin名稱.
8029
					$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
8030
					#$conf["certificate_csr"],字串,簽署的資訊.
8031
					$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
8032
					#$conf["fileArgu"],字串,變數__FILE__的內容.
8033
					$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
8034
					#可省略參數:
8035
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8036
					$conf["zerossl::createCertificate"]["apiDomain"]=$cInfo["domain"];
8037
					#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
8038
					#$conf["path"]=self::getApiInfo()["csrPath"];
8039
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8040
					$conf["zerossl::createCertificate"]["key"]=$cInfo["key"];
8041
					#參考資料:
8042
					#無.
8043
					#備註:
8044
					#無.
8045
					$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
8046
					unset($conf["zerossl::createCertificate"]);
8047
 
8048
					#如果執行異常
8049
					if($createCertificate["status"]==="false"){
8050
 
8051
						#設置錯誤識別
8052
						$result["status"]="false";
8053
 
8054
						#設置錯誤訊息
8055
						$result["error"]=$createCertificate;
8056
 
8057
						#回傳結果
8058
						return $result;
8059
 
8060
						}#if end
8061
 
8062
					#取得csr在zerossl上的id
8063
					$csrId=$createCertificate["id"];
8064
 
8065
					#取得cname key
8066
					$cNameKey=$createCertificate["cnameKey"];
8067
 
8068
					#取得cname val
8069
					$cNameVal=$createCertificate["cnameVal"];
8070
 
8071
					#初始化要增加的RR記錄
8072
					$rr2add=array();
8073
 
8074
					#設置CNAME的查詢
8075
					$rr2add["query"]=$cNameKey;
8076
 
8077
					#設置CNAME的value
8078
					$rr2add["value"]=$cNameVal;
8079
 
8080
					#設置類型為 CNAME
8081
					$rr2add["type"]="CNAME";
8082
 
8083
					#設置註解
8084
					$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
8085
 
281 liveuser 8086
					#if enable debug
8087
					if($debug){
8088
 
8089
						#debug msg
8090
						echo "Adding DNS record to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
8091
 
8092
						}#if end
8093
 
255 liveuser 8094
					#函式說明:
8095
					#新增DNS記錄到檔案裡面.
8096
					#回傳結果:
8097
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8098
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8099
					#$result["function"],當前執行的函式名稱.
8100
					#$result["argu"],所使用的參數.
8101
					#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
8102
					#$result["domain"],字串,RR所屬domain.
8103
					#$result["defaultTTL"],字串,預設的RR更新時間.
8104
					#$result["comment"],字串陣列,逐行的註解.
8105
					#必填參數:
8106
					#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
8107
					$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2ad);
8108
					#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
8109
					$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
8110
					#可省略參數:
8111
					#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
8112
					$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
8113
					#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
8114
					#$conf["debug"]="false";
8115
					#參考資料:
8116
					#無.
8117
					#備註:
8118
					#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
8119
					#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
8120
					#php-pear上的Net_DNS2也可以解析RR.
8121
					$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
8122
					unset($conf["zerossl::updateDnsRecordFile"]);
8123
 
8124
					#如果執行異常
8125
					if($updateDnsRecordFile["status"]==="false"){
8126
 
8127
						#設置錯誤識別
8128
						$result["status"]="false";
8129
 
8130
						#設置錯誤訊息
8131
						$result["error"]=$updateDnsRecordFile;
8132
 
8133
						#回傳結果
8134
						return $result;
8135
 
8136
						}#if end
281 liveuser 8137
 
8138
					#if enable debug
8139
					if($debug){
8140
 
8141
						#debug msg
8142
						echo "Restarting DNS service to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
8143
 
8144
						}#if end
8145
 
255 liveuser 8146
					#重新啟動dns伺服器
8147
					#函式說明:
8148
					#呼叫shell執行系統命令,並取得回傳的內容.
8149
					#回傳結果:
8150
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8151
					#$result["error"],錯誤訊息陣列.
8152
					#$result["function"],當前執行的函數名稱.
8153
					#$result["argu"],使用的參數.
8154
					#$result["cmd"],執行的指令內容.
8155
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8156
					#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8157
					#$result["content"],為執行完後的輸出字串.
8158
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8159
					#$result["running"],是否還在執行.
8160
					#$result["pid"],pid.
8161
					#$result["statusCode"],執行結束後的代碼.
8162
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8163
					#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8164
					#必填參數:
8165
					#$conf["command"],字串,要執行的指令.
8166
					$conf["external::callShell"]["command"]="systemd";
8167
					#$conf["fileArgu"],字串,變數__FILE__的內容.
8168
					$conf["external::callShell"]["fileArgu"]=__FILE__;
8169
					#可省略參數:
8170
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8171
					$conf["external::callShell"]["argu"]=array("restart","named");
8172
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8173
					#$conf["arguIsAddr"]=array();
8174
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8175
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8176
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8177
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8178
					#$conf["enablePrintDescription"]="true";
8179
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8180
					#$conf["printDescription"]="";
8181
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8182
					#$conf["escapeshellarg"]="false";
8183
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8184
					#$conf["thereIsShellVar"]=array();
8185
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8186
					#$conf["username"]="";
8187
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8188
					#$conf["password"]="";
8189
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8190
					#$conf["useScript"]="";
8191
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8192
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8193
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8194
					#$conf["inBackGround"]="";
8195
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8196
					#$conf["getErr"]="false";
8197
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8198
					#$conf["doNotRun"]="false";
8199
					#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8200
					$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
8201
					#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8202
					#$conf["remoteUser"]="root";
8203
					#參考資料:
8204
					#exec=>http://php.net/manual/en/function.exec.php
8205
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8206
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8207
					#備註:
8208
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8209
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8210
					$callShell=external::callShell($conf["external::callShell"]);
8211
					unset($conf["external::callShell"]);
8212
 
8213
					#如果執行異常
8214
					if($callShell["status"]==="false"){
8215
 
8216
						#設置錯誤識別
8217
						$result["status"]="false";
8218
 
8219
						#設置錯誤訊息
8220
						$result["error"]=$callShell;
8221
 
8222
						#回傳結果
8223
						return $result;
8224
 
8225
						}#if end
281 liveuser 8226
 
8227
					#if enable debug
8228
					if($debug){
8229
 
8230
						#debug msg
8231
						echo "Request zerossl to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
8232
 
8233
						}#if end
8234
 
255 liveuser 8235
					#函式說明:
8236
					#請求驗證已經透過zerossl::createCertificate要求的domain.
8237
					#回傳結果:
8238
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8239
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8240
					#$result["function"],當前執行的函式名稱.
8241
					#$result["argu"],所使用的參數.
8242
					#$result["curl_verbose_info"],curl執行的詳細資訊.
8243
					#$result["content"],結果json字串.
8244
					#必填參數:
8245
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
8246
					$conf["zerossl::verifyDomain"]["id"]=$csrId;
8247
					#可省略參數:
8248
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8249
					$conf["zerossl::verifyDomain"]["apiDomain"]=$cInfo["domain"];
8250
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8251
					$conf["zerossl::verifyDomain"]["key"]=$cInfo["key"];
8252
					#參考資料:
8253
					#https://zerossl.com/documentation/api/verify-domains/
8254
					#備註:
8255
					#無.
8256
					$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
8257
					unset($conf["zerossl::verifyDomain"]);
8258
 
8259
					#如果執行異常
8260
					if($verifyDomain["status"]==="false"){
8261
 
8262
						#設置錯誤識別
8263
						$result["status"]="false";
8264
 
8265
						#設置錯誤訊息
8266
						$result["error"]=$verifyDomain;
8267
 
8268
						#回傳結果
8269
						return $result;
8270
 
8271
						}#if end
281 liveuser 8272
 
8273
					#if enable debug
8274
					if($debug){
8275
 
8276
						#debug msg
8277
						echo "Downling ssl for domain name(".$cInfo["apiDomain"].") on zerossl.".PHP_EOL;
8278
 
8279
						}#if end
8280
 
255 liveuser 8281
					#函式說明:
8282
					#下載certificate.
8283
					#回傳結果:
8284
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8285
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8286
					#$result["function"],當前執行的函式名稱.
8287
					#$result["argu"],所使用的參數.
8288
					#$result["curl_verbose_info"],curl執行的詳細資訊.
8289
					#$result["content"],結果json字串.
8290
					#$result["certificate.crt"],字串,certificate.crt的內容.
8291
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
8292
					#必填參數:
8293
					#無.
8294
					#可省略參數:
8295
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8296
					$conf["zerossl::getCert"]["apiDomain"]=$cInfo["domain"];
8297
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8298
					$conf["zerossl::getCert"]["key"]=$cInfo["key"];
8299
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
8300
					$conf["zerossl::getCert"]["id"]=$csrId;
8301
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
8302
					#$conf["zerossl::getCert"]["cname"]="";
8303
					#參考資料:
8304
					#https://zerossl.com/documentation/api/download-certificate-inline/
8305
					#備註:
8306
					#無.
8307
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
8308
					unset($conf["zerossl::getCert"]);
8309
 
8310
					#如果執行異常
8311
					if($getCert["status"]==="false"){
8312
 
8313
						#設置錯誤識別
8314
						$result["status"]="false";
8315
 
8316
						#設置錯誤訊息
8317
						$result["error"]=$getCert;
8318
 
8319
						#回傳結果
8320
						return $result;
8321
 
8322
						}#if end
281 liveuser 8323
 
8324
					#if enable debug
8325
					if($debug){
8326
 
8327
						#debug msg
8328
						echo "Creating ssl for domain name(".$cInfo["apiDomain"].").".PHP_EOL;
8329
 
8330
						}#if end
8331
 
255 liveuser 8332
					#建立 certificate.crt 檔案
8333
					#$cInfo["certPath"];
8334
 
8335
					#建立 ca_bundle.crt 檔案
8336
					#$cInfo["caPath"];
8337
 
8338
					#建立 certAndCa.crt 檔案
8339
					#$cInfo["certWithCaPath"];
8340
 
8341
					#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
8342
					#函式說明:
8343
					#一次建立多個檔案,並寫入內容.
8344
					#回傳結果:
8345
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
8346
					#$result["error"],錯誤訊息陣列.
8347
					#$result["function"],當前執行的函數名稱.
8348
					#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
8349
					#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
8350
					#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
8351
					#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
8352
					#$result["argu"],使用的參數.
8353
					#必填參數:
8354
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8355
					$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
8356
					#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
8357
					$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certPath"],$cInfo["caPath"],$cInfo["certWithCaPath"]);
8358
					#可省略參數:
8359
					#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
8360
					$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
8361
					#參考資料:
8362
					#無.
8363
					#備註:
8364
					#無.
8365
					$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
8366
					unset($conf["zerossl::writeMultiFile"]);
8367
 
8368
					#如果執行異常
8369
					if($writeMultiFile["status"]==="false"){
8370
 
8371
						#設置錯誤識別
8372
						$result["status"]="false";
8373
 
8374
						#設置錯誤訊息
8375
						$result["error"]=$writeMultiFile;
8376
 
8377
						#回傳結果
8378
						return $result;
8379
 
8380
						}#if end
8381
 
8382
					#儲存 actionAfterUpdateCert
8383
					$action=$cInfo["actionAfterUpdateCert"];
8384
 
8385
					#如果有多個指令要執行
8386
					if(gettype($action[0])==="array"){
8387
 
281 liveuser 8388
						#if enable debug
8389
						if($debug){
8390
 
8391
							#debug msg
8392
							echo "There many cmd to run to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
8393
 
8394
							}#if end
8395
 
255 liveuser 8396
						#針對每的指令
8397
						foreach($action as $ac){
8398
 
281 liveuser 8399
							#if enable debug
8400
							if($debug){
8401
 
8402
								#debug msg
8403
								echo ".".PHP_EOL;
8404
 
8405
								}#if end
8406
 
255 liveuser 8407
							#函式說明:
8408
							#解析指令與參數,回傳指令與參數給 callShell 函式使用.
8409
							#回傳結果:
8410
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8411
							#$result["error"],錯誤訊息陣列.
8412
							#$result["function"],當前執行的函數名稱.
8413
							#$result["argu"],使用的參數.
8414
							#$result["cmd"],執行的指令名稱.
8415
							#$result["params"],執行指令伴隨的參數.
8416
							#必填參數:
8417
							#$conf["cmdArray"],字串陣列,要執行的指令字串.
8418
							$conf["external::callShellHelper"]["cmdArray"]=$ac;
8419
							#可省略參數:
8420
							#無.
8421
							#參考資料:
8422
							#array_shift=>https://www.php.net/manual/en/function.array-shift.php
8423
							#備註:
8424
							#無.
8425
							$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
8426
							unset($conf["external::callShellHelper"]);
8427
 
8428
							#如果執行異常
8429
							if($callShellHelper["status"]==="false"){
8430
 
8431
								#設置錯誤識別
8432
								$result["status"]="false";
8433
 
8434
								#設置錯誤訊息
8435
								$result["error"]=$callShellHelper;
8436
 
8437
								#回傳結果
8438
								return $result;
8439
 
8440
								}#if end
8441
 
8442
							#函式說明:
8443
							#呼叫shell執行系統命令,並取得回傳的內容.
8444
							#回傳結果:
8445
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8446
							#$result["error"],錯誤訊息陣列.
8447
							#$result["function"],當前執行的函數名稱.
8448
							#$result["argu"],使用的參數.
8449
							#$result["cmd"],執行的指令內容.
8450
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8451
							#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8452
							#$result["content"],為執行完後的輸出字串.
8453
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8454
							#$result["running"],是否還在執行.
8455
							#$result["pid"],pid.
8456
							#$result["statusCode"],執行結束後的代碼.
8457
							#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8458
							#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8459
							#必填參數:
8460
							#$conf["command"],字串,要執行的指令.
8461
							$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
8462
							#$conf["fileArgu"],字串,變數__FILE__的內容.
8463
							$conf["external::callShell"]["fileArgu"]=__FILE__;
8464
							#可省略參數:
8465
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8466
							$conf["external::callShell"]["argu"]=$callShellHelper["params"];
8467
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8468
							#$conf["arguIsAddr"]=array();
8469
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8470
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8471
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8472
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8473
							#$conf["enablePrintDescription"]="true";
8474
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8475
							#$conf["printDescription"]="";
8476
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8477
							$conf["external::callShell"]["escapeshellarg"]="true";
8478
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8479
							#$conf["thereIsShellVar"]=array();
8480
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8481
							#$conf["username"]="";
8482
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8483
							#$conf["password"]="";
8484
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8485
							#$conf["useScript"]="";
8486
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8487
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8488
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8489
							#$conf["inBackGround"]="";
8490
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8491
							#$conf["getErr"]="false";
8492
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8493
							#$conf["doNotRun"]="false";
8494
							#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8495
							#$conf["remoteIp"]="";
8496
							#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8497
							#$conf["remoteUser"]="";
8498
							#參考資料:
8499
							#exec=>http://php.net/manual/en/function.exec.php
8500
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8501
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8502
							#備註:
8503
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8504
							#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8505
							$callShell=external::callShell($conf["external::callShell"]);
8506
							unset($conf["external::callShell"]);
8507
 
8508
							#如果執行異常
8509
							if($callShellHelper["status"]==="false"){
8510
 
8511
								#設置錯誤識別
8512
								$result["status"]="false";
8513
 
8514
								#設置錯誤訊息
8515
								$result["error"]=$callShell;
8516
 
8517
								#回傳結果
8518
								return $result;
8519
 
8520
								}#if end
8521
 
8522
							}#foreach end
8523
 
8524
						}#if end
8525
 
8526
					#反之
8527
					else{
8528
 
281 liveuser 8529
						#if enable debug
8530
						if($debug){
8531
 
8532
							#debug msg
8533
							echo "There is only one cmd to run to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
8534
 
8535
							}#if end
8536
 
8537
						#if enable debug
8538
						if($debug){
8539
 
8540
							#debug msg
8541
							echo ".".PHP_EOL;
8542
 
8543
							}#if end
8544
 
255 liveuser 8545
						#函式說明:
8546
						#解析指令與參數,回傳指令與參數給 callShell 函式使用.
8547
						#回傳結果:
8548
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8549
						#$result["error"],錯誤訊息陣列.
8550
						#$result["function"],當前執行的函數名稱.
8551
						#$result["argu"],使用的參數.
8552
						#$result["cmd"],執行的指令名稱.
8553
						#$result["params"],執行指令伴隨的參數.
8554
						#必填參數:
8555
						#$conf["cmdArray"],字串陣列,要執行的指令字串.
8556
						$conf["external::callShellHelper"]["cmdArray"]=$action;
8557
						#可省略參數:
8558
						#無.
8559
						#參考資料:
8560
						#array_shift=>https://www.php.net/manual/en/function.array-shift.php
8561
						#備註:
8562
						#無.
8563
						$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
8564
						unset($conf["external::callShellHelper"]);
8565
 
8566
						#如果執行異常
8567
						if($callShellHelper["status"]==="false"){
8568
 
8569
							#設置錯誤識別
8570
							$result["status"]="false";
8571
 
8572
							#設置錯誤訊息
8573
							$result["error"]=$callShellHelper;
8574
 
8575
							#回傳結果
8576
							return $result;
8577
 
8578
							}#if end
8579
 
8580
						#函式說明:
8581
						#呼叫shell執行系統命令,並取得回傳的內容.
8582
						#回傳結果:
8583
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8584
						#$result["error"],錯誤訊息陣列.
8585
						#$result["function"],當前執行的函數名稱.
8586
						#$result["argu"],使用的參數.
8587
						#$result["cmd"],執行的指令內容.
8588
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8589
						#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8590
						#$result["content"],為執行完後的輸出字串.
8591
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8592
						#$result["running"],是否還在執行.
8593
						#$result["pid"],pid.
8594
						#$result["statusCode"],執行結束後的代碼.
8595
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8596
						#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
8597
						#必填參數:
8598
						#$conf["command"],字串,要執行的指令.
8599
						$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
8600
						#$conf["fileArgu"],字串,變數__FILE__的內容.
8601
						$conf["external::callShell"]["fileArgu"]=__FILE__;
8602
						#可省略參數:
8603
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8604
						$conf["external::callShell"]["argu"]=$callShellHelper["params"];
8605
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8606
						#$conf["arguIsAddr"]=array();
8607
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8608
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8609
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8610
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8611
						#$conf["enablePrintDescription"]="true";
8612
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8613
						#$conf["printDescription"]="";
8614
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
8615
						$conf["external::callShell"]["escapeshellarg"]="true";
8616
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
8617
						#$conf["thereIsShellVar"]=array();
8618
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8619
						#$conf["username"]="";
8620
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8621
						#$conf["password"]="";
8622
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8623
						#$conf["useScript"]="";
8624
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8625
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8626
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8627
						#$conf["inBackGround"]="";
8628
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8629
						#$conf["getErr"]="false";
8630
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
8631
						#$conf["doNotRun"]="false";
8632
						#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
8633
						#$conf["remoteIp"]="";
8634
						#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
8635
						#$conf["remoteUser"]="";
8636
						#參考資料:
8637
						#exec=>http://php.net/manual/en/function.exec.php
8638
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8639
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8640
						#備註:
8641
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8642
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
8643
						$callShell=external::callShell($conf["external::callShell"]);
8644
						unset($conf["external::callShell"]);
8645
 
8646
						#如果執行異常
8647
						if($callShellHelper["status"]==="false"){
8648
 
8649
							#設置錯誤識別
8650
							$result["status"]="false";
8651
 
8652
							#設置錯誤訊息
8653
							$result["error"]=$callShell;
8654
 
8655
							#回傳結果
8656
							return $result;
8657
 
8658
							}#if end
8659
 
8660
						}#else end
8661
 
8662
					#要移除舊的憑證 
8663
 
281 liveuser 8664
					#if enable debug
8665
					if($debug){
8666
 
8667
						#debug msg
8668
						echo "Removing old ssl file".PHP_EOL;
8669
 
8670
						}#if end
8671
 
255 liveuser 8672
					#舊憑證於zerossl上的id
8673
					#$oldCsrId
8674
 
8675
					#移除舊的憑證
8676
					#函式說明:
8677
					#請求廢除 issued zerossl certificate.
8678
					#回傳結果:
8679
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8680
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8681
					#$result["function"],當前執行的函式名稱.
8682
					#$result["argu"],所使用的參數.
8683
					#$result["curl_verbose_info"],curl執行的詳細資訊.
8684
					#$result["content"],結果json字串.
8685
					#必填參數:
8686
					#$conf["id"],字串,zerossl::createCertificate回傳的id.
8687
					$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
8688
					#可省略參數:
8689
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8690
					$conf["zerosssl::revokeCert"]["apiDomain"]=$cInfo["domain"];
8691
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8692
					$conf["zerosssl::revokeCert"]["key"]=$cInfo["key"];
8693
					#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
8694
					$conf["zerosssl::revokeCert"]["reason"]="Superseded";
8695
					#參考資料:
8696
					#https://zerossl.com/documentation/api/revoke-certificate/
8697
					#備註:
8698
					#無.
8699
					$revokeCert=zerosssl::revokeCert($conf["zerosssl::revokeCert"]);
8700
					unset($conf["zerosssl::revokeCert"]);
8701
 
8702
					#如果執行異常
8703
					if($revokeCert["status"]==="false"){
8704
 
8705
						#設置錯誤識別
8706
						$result["status"]="false";
8707
 
8708
						#設置錯誤訊息
8709
						$result["error"]=$revokeCert;
8710
 
8711
						#回傳結果
8712
						return $result;
8713
 
8714
					}#if end
8715
 
8716
				#反之,尚不需要提前申請新的憑證
8717
				else{
8718
 
281 liveuser 8719
					#if enable debug
8720
					if($debug){
8721
 
8722
						#debug msg
8723
						echo "ssl for domain name(".$cInfo["apiDomain"].") is valid ".PHP_EOL;
8724
 
8725
						}#if end
8726
 
8727
					#if enable debug
8728
					if($debug){
8729
 
8730
						#debug msg
8731
						echo "Downling ssl for domain name(".$cInfo["apiDomain"].") on zerossl...".PHP_EOL;
8732
 
8733
						}#if end
8734
 
255 liveuser 8735
					#下載憑證
8736
					#函式說明:
8737
					#下載certificate.
8738
					#回傳結果:
8739
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8740
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
8741
					#$result["function"],當前執行的函式名稱.
8742
					#$result["argu"],所使用的參數.
8743
					#$result["curl_verbose_info"],curl執行的詳細資訊.
8744
					#$result["content"],結果json字串.
8745
					#$result["certificate.crt"],字串,certificate.crt的內容.
8746
					#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
8747
					#必填參數:
8748
					#無.
8749
					#可省略參數:
8750
					#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
8751
					$conf["zerossl::getCert"]["apiDomain"]=$cInfo["domain"];
8752
					#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
8753
					$conf["zerossl::getCert"]["key"]=$cInfo["key"];
8754
					#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
8755
					$conf["zerossl::getCert"]["id"]=$csrId;
8756
					#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
8757
					#$conf["zerossl::getCert"]["cname"]="";
8758
					#參考資料:
8759
					#https://zerossl.com/documentation/api/download-certificate-inline/
8760
					#備註:
8761
					#無.
8762
					$getCert=zerossl::getCert($conf["zerossl::getCert"]);
8763
					unset($conf["zerossl::getCert"]);
8764
 
8765
					#如果執行異常
8766
					if($getCert["status"]==="false"){
8767
 
8768
						#設置錯誤識別
8769
						$result["status"]="false";
8770
 
8771
						#設置錯誤訊息
8772
						$result["error"]=$getCert;
8773
 
8774
						#回傳結果
8775
						return $result;
8776
 
8777
						}#if end
281 liveuser 8778
 
8779
					#if enable debug
8780
					if($debug){
8781
 
8782
						#debug msg
8783
						echo "Getting host ssl for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
8784
 
8785
						}#if end
8786
 
255 liveuser 8787
					#zerossl上的certificate.crt內容
8788
					#$getCert["certificate.crt"];
8789
 
8790
					#zerossl上的ca_bundle.crt內容
8791
					#$getCert["ca_bundle.crt"];
8792
 
8793
					#certificate.crt and ca_bundle.crt 合併後的檔案內容
8794
					#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
8795
 
8796
					#certificate.crt 檔案
8797
					#$cInfo["certPath"];
8798
 
8799
					#ca_bundle.crt 檔案
8800
					#$cInfo["caPath"];
8801
 
8802
					#certAndCa.crt 檔案
8803
					#$cInfo["certWithCaPath"];
281 liveuser 8804
 
8805
					#if enable debug
8806
					if($debug){
8807
 
8808
						#debug msg
8809
						echo "Getting host ssl(certificate.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
8810
 
8811
						}#if end
255 liveuser 8812
 
8813
					#取得既有的 certificate.crt 檔案內容
8814
					#函式說明:
8815
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
8816
					#回傳的變數說明:
8817
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
8818
					#$result["error"],錯誤訊息提示.
8819
					#$result["warning"],警告訊息.
8820
					#$result["function"],當前執行的函數名稱.
8821
					#$result["fileContent"],爲檔案的內容陣列.
8822
					#$result["lineCount"],爲檔案內容總共的行數.
8823
					#$result["fullContent"],為檔案的完整內容.
8824
					#$result["base64dataOnly"],檔案的base64data.
8825
					#$result["base64data"],為在網頁上給予src參數的數值.
8826
					#$result["mimeType"],為檔案的mime type.
8827
					#必填參數:
8828
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
8829
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["certPath"];
8830
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8831
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
8832
					#可省略參數:
8833
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
8834
					#$conf["web"]="true";
8835
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
8836
					#$conf["createIfnotExist"]="false";
8837
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
8838
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
8839
					#參考資料:
8840
					#file(),取得檔案內容的行數.
8841
					#file=>http:#php.net/manual/en/function.file.php
8842
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
8843
					#filesize=>http://php.net/manual/en/function.filesize.php
8844
					#參考資料:
8845
					#無.
8846
					#備註:
8847
					#無.
8848
					$getFileContent=fileAccesss::getFileContent($conf["fileAccesss::getFileContent"]);
8849
					unset($conf["fileAccesss::getFileContent"]);
8850
 
8851
					#如果執行異常
8852
					if($getFileContent["status"]==="false"){
8853
 
8854
						#設置錯誤識別
8855
						$result["status"]="false";
8856
 
8857
						#設置錯誤訊息
8858
						$result["error"]=$getFileContent;
8859
 
8860
						#回傳結果
8861
						return $result;
8862
 
8863
						}#if end
8864
 
281 liveuser 8865
					#if enable debug
8866
					if($debug){
8867
 
8868
						#debug msg
8869
						echo "Checking host ssl(certificate.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
8870
 
8871
						}#if end
8872
 
255 liveuser 8873
					#如果既有憑證跟剛下載的憑證不一樣
8874
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
8875
 
8876
						#識別要改成下載好的憑證
8877
						$certificate_need_update="true";
281 liveuser 8878
 
8879
						#if enable debug
8880
						if($debug){
8881
 
8882
							#debug msg
8883
							echo "SSL(certificate.crt) for domain name(".$cInfo["apiDomain"].") differs between host and zerossl".PHP_EOL;
8884
 
8885
							}#if end
255 liveuser 8886
 
8887
						}#if end
281 liveuser 8888
 
8889
					#if enable debug
8890
					if($debug){
8891
 
8892
						#debug msg
8893
						echo "Getting host ssl(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
8894
 
8895
						}#if end
8896
 
255 liveuser 8897
					#取得既有的 ca_bundle.crt 檔案內容
8898
					#函式說明:
8899
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
8900
					#回傳的變數說明:
8901
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
8902
					#$result["error"],錯誤訊息提示.
8903
					#$result["warning"],警告訊息.
8904
					#$result["function"],當前執行的函數名稱.
8905
					#$result["fileContent"],爲檔案的內容陣列.
8906
					#$result["lineCount"],爲檔案內容總共的行數.
8907
					#$result["fullContent"],為檔案的完整內容.
8908
					#$result["base64dataOnly"],檔案的base64data.
8909
					#$result["base64data"],為在網頁上給予src參數的數值.
8910
					#$result["mimeType"],為檔案的mime type.
8911
					#必填參數:
8912
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
8913
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["caPath"];
8914
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8915
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
8916
					#可省略參數:
8917
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
8918
					#$conf["web"]="true";
8919
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
8920
					#$conf["createIfnotExist"]="false";
8921
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
8922
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
8923
					#參考資料:
8924
					#file(),取得檔案內容的行數.
8925
					#file=>http:#php.net/manual/en/function.file.php
8926
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
8927
					#filesize=>http://php.net/manual/en/function.filesize.php
8928
					#參考資料:
8929
					#無.
8930
					#備註:
8931
					#無.
8932
					$getFileContent=fileAccesss::getFileContent($conf["fileAccesss::getFileContent"]);
8933
					unset($conf["fileAccesss::getFileContent"]);
8934
 
8935
					#如果執行異常
8936
					if($getFileContent["status"]==="false"){
8937
 
8938
						#設置錯誤識別
8939
						$result["status"]="false";
8940
 
8941
						#設置錯誤訊息
8942
						$result["error"]=$getFileContent;
8943
 
8944
						#回傳結果
8945
						return $result;
8946
 
8947
						}#if end
8948
 
281 liveuser 8949
					#if enable debug
8950
					if($debug){
8951
 
8952
						#debug msg
8953
						echo "Checking host ssl(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
8954
 
8955
						}#if end
8956
 
255 liveuser 8957
					#如果既有憑證跟剛下載的憑證不一樣
8958
					if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
8959
 
8960
						#識別要改成下載好的憑證
8961
						$ca_bundle_need_update="true";
281 liveuser 8962
 
8963
						#if enable debug
8964
						if($debug){
8965
 
8966
							#debug msg
8967
							echo "SSL(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].") differs between host and zerossl".PHP_EOL;
8968
 
8969
							}#if end
255 liveuser 8970
 
8971
						}#if end
8972
 
281 liveuser 8973
					#if enable debug
8974
					if($debug){
8975
 
8976
						#debug msg
8977
						echo "Getting host ssl(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
8978
 
8979
						}#if end
8980
 
255 liveuser 8981
					#取得既有的 certWithCa 檔案內容
8982
					#函式說明:
8983
					#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
8984
					#回傳的變數說明:
8985
					#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
8986
					#$result["error"],錯誤訊息提示.
8987
					#$result["warning"],警告訊息.
8988
					#$result["function"],當前執行的函數名稱.
8989
					#$result["fileContent"],爲檔案的內容陣列.
8990
					#$result["lineCount"],爲檔案內容總共的行數.
8991
					#$result["fullContent"],為檔案的完整內容.
8992
					#$result["base64dataOnly"],檔案的base64data.
8993
					#$result["base64data"],為在網頁上給予src參數的數值.
8994
					#$result["mimeType"],為檔案的mime type.
8995
					#必填參數:
8996
					#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
8997
					$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["certWithCaPath"];
8998
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8999
					$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
9000
					#可省略參數:
9001
					#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
9002
					#$conf["web"]="true";
9003
					#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
9004
					#$conf["createIfnotExist"]="false";
9005
					#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
9006
					#$conf["autoDeleteSpaceOnEachLineStart"]="false";
9007
					#參考資料:
9008
					#file(),取得檔案內容的行數.
9009
					#file=>http:#php.net/manual/en/function.file.php
9010
					#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
9011
					#filesize=>http://php.net/manual/en/function.filesize.php
9012
					#參考資料:
9013
					#無.
9014
					#備註:
9015
					#無.
9016
					$getFileContent=fileAccesss::getFileContent($conf["fileAccesss::getFileContent"]);
9017
					unset($conf["fileAccesss::getFileContent"]);
9018
 
9019
					#如果執行異常
9020
					if($getFileContent["status"]==="false"){
9021
 
9022
						#設置錯誤識別
9023
						$result["status"]="false";
9024
 
9025
						#設置錯誤訊息
9026
						$result["error"]=$getFileContent;
9027
 
9028
						#回傳結果
9029
						return $result;
9030
 
9031
						}#if end
9032
 
281 liveuser 9033
					#if enable debug
9034
					if($debug){
9035
 
9036
						#debug msg
9037
						echo "Checking host ssl(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
9038
 
9039
						}#if end
9040
 
255 liveuser 9041
					#如果既有憑證跟剛下載的憑證不一樣
9042
					if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
9043
 
9044
						#識別要改成下載好的憑證
9045
						$cert_and_ca_bundle_need_update="true";
281 liveuser 9046
 
9047
						#if enable debug
9048
						if($debug){
9049
 
9050
							#debug msg
9051
							echo "SSL(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].") differs between host and zerossl".PHP_EOL;
9052
 
9053
							}#if end
255 liveuser 9054
 
9055
						}#if end
9056
 
9057
					#預設不需要執行更新憑證後的動作
9058
					$requireActionAfterUpdateCert="false";
9059
 
9060
					#如果 certificate 需要更新
9061
					if($certificate_need_update==="true"){
9062
 
281 liveuser 9063
						#if enable debug
9064
						if($debug){
9065
 
9066
							#debug msg
9067
							echo "Updating host ssl(certificate.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
9068
 
9069
							}#if end
9070
 
255 liveuser 9071
						#更新之
9072
						#函式說明:
9073
						#一次建立多個檔案,並寫入內容.
9074
						#回傳結果:
9075
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9076
						#$result["error"],錯誤訊息陣列.
9077
						#$result["function"],當前執行的函數名稱.
9078
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
9079
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
9080
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
9081
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
9082
						#$result["argu"],使用的參數.
9083
						#必填參數:
9084
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9085
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
9086
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
9087
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certPath"]);
9088
						#可省略參數:
9089
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
9090
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
9091
						#參考資料:
9092
						#無.
9093
						#備註:
9094
						#無.
9095
						$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
9096
						unset($conf["zerossl::writeMultiFile"]);
9097
 
9098
						#如果執行異常
9099
						if($writeMultiFile["status"]==="false"){
9100
 
9101
							#設置錯誤識別
9102
							$result["status"]="false";
9103
 
9104
							#設置錯誤訊息
9105
							$result["error"]=$writeMultiFile;
9106
 
9107
							#回傳結果
9108
							return $result;
9109
 
9110
							}#if end
9111
 
9112
						}#if end
9113
 
9114
					#如果 ca_bunle 需要更新
9115
					if($ca_bundle_need_update==="true"){
9116
 
281 liveuser 9117
						#if enable debug
9118
						if($debug){
9119
 
9120
							#debug msg
9121
							echo "Updating host ssl(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
9122
 
9123
							}#if end
9124
 
255 liveuser 9125
						#更新之
9126
						#函式說明:
9127
						#一次建立多個檔案,並寫入內容.
9128
						#回傳結果:
9129
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9130
						#$result["error"],錯誤訊息陣列.
9131
						#$result["function"],當前執行的函數名稱.
9132
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
9133
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
9134
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
9135
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
9136
						#$result["argu"],使用的參數.
9137
						#必填參數:
9138
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9139
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
9140
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
9141
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["caPath"]);
9142
						#可省略參數:
9143
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
9144
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
9145
						#參考資料:
9146
						#無.
9147
						#備註:
9148
						#無.
9149
						$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
9150
						unset($conf["zerossl::writeMultiFile"]);
9151
 
9152
						#如果執行異常
9153
						if($writeMultiFile["status"]==="false"){
9154
 
9155
							#設置錯誤識別
9156
							$result["status"]="false";
9157
 
9158
							#設置錯誤訊息
9159
							$result["error"]=$writeMultiFile;
9160
 
9161
							#回傳結果
9162
							return $result;
9163
 
9164
							}#if end
9165
 
9166
						}#if end
9167
 
9168
					#如果 certificate and ca_bundle 需要更新
9169
					if($cert_and_ca_bundle_need_update==="true"){
9170
 
281 liveuser 9171
						#if enable debug
9172
						if($debug){
9173
 
9174
							#debug msg
9175
							echo "Updating host ssl(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
9176
 
9177
							}#if end
9178
 
255 liveuser 9179
						#更新之
9180
						#函式說明:
9181
						#一次建立多個檔案,並寫入內容.
9182
						#回傳結果:
9183
						#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
9184
						#$result["error"],錯誤訊息陣列.
9185
						#$result["function"],當前執行的函數名稱.
9186
						#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
9187
						#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
9188
						#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
9189
						#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
9190
						#$result["argu"],使用的參數.
9191
						#必填參數:
9192
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9193
						$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
9194
						#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
9195
						$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certWithCaPath"]);
9196
						#可省略參數:
9197
						#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
9198
						$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
9199
						#參考資料:
9200
						#無.
9201
						#備註:
9202
						#無.
9203
						$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
9204
						unset($conf["zerossl::writeMultiFile"]);
9205
 
9206
						#如果執行異常
9207
						if($writeMultiFile["status"]==="false"){
9208
 
9209
							#設置錯誤識別
9210
							$result["status"]="false";
9211
 
9212
							#設置錯誤訊息
9213
							$result["error"]=$writeMultiFile;
9214
 
9215
							#回傳結果
9216
							return $result;
9217
 
9218
							}#if end
9219
 
9220
						}#if end
9221
 
9222
					#如果有需要執行指令來生效憑證
9223
					if($requireActionAfterUpdateCert==="true"){
9224
 
281 liveuser 9225
						#if enable debug
9226
						if($debug){
9227
 
9228
							#debug msg
9229
							echo "Action required to apply ssl for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
9230
 
9231
							}#if end
9232
 
255 liveuser 9233
						#儲存 actionAfterUpdateCert
9234
						$action=$cInfo["actionAfterUpdateCert"];
9235
 
9236
						#如果有多個指令要執行
9237
						if(gettype($action[0])==="array"){
9238
 
281 liveuser 9239
							#if enable debug
9240
							if($debug){
9241
 
9242
								#debug msg
9243
								echo "There are many cmds to run to apply ssl for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
9244
 
9245
								}#if end
9246
 
255 liveuser 9247
							#針對每的指令
9248
							foreach($action as $ac){
9249
 
281 liveuser 9250
								#if enable debug
9251
								if($debug){
9252
 
9253
									#debug msg
9254
									echo ".".PHP_EOL;
9255
 
9256
									}#if end
9257
 
255 liveuser 9258
								#函式說明:
9259
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
9260
								#回傳結果:
9261
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9262
								#$result["error"],錯誤訊息陣列.
9263
								#$result["function"],當前執行的函數名稱.
9264
								#$result["argu"],使用的參數.
9265
								#$result["cmd"],執行的指令名稱.
9266
								#$result["params"],執行指令伴隨的參數.
9267
								#必填參數:
9268
								#$conf["cmdArray"],字串陣列,要執行的指令字串.
9269
								$conf["external::callShellHelper"]["cmdArray"]=$ac;
9270
								#可省略參數:
9271
								#無.
9272
								#參考資料:
9273
								#array_shift=>https://www.php.net/manual/en/function.array-shift.php
9274
								#備註:
9275
								#無.
9276
								$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
9277
								unset($conf["external::callShellHelper"]);
9278
 
9279
								#如果執行異常
9280
								if($callShellHelper["status"]==="false"){
9281
 
9282
									#設置錯誤識別
9283
									$result["status"]="false";
9284
 
9285
									#設置錯誤訊息
9286
									$result["error"]=$callShellHelper;
9287
 
9288
									#回傳結果
9289
									return $result;
9290
 
9291
									}#if end
9292
 
9293
								#函式說明:
9294
								#呼叫shell執行系統命令,並取得回傳的內容.
9295
								#回傳結果:
9296
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9297
								#$result["error"],錯誤訊息陣列.
9298
								#$result["function"],當前執行的函數名稱.
9299
								#$result["argu"],使用的參數.
9300
								#$result["cmd"],執行的指令內容.
9301
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9302
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9303
								#$result["content"],為執行完後的輸出字串.
9304
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9305
								#$result["running"],是否還在執行.
9306
								#$result["pid"],pid.
9307
								#$result["statusCode"],執行結束後的代碼.
9308
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9309
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9310
								#必填參數:
9311
								#$conf["command"],字串,要執行的指令.
9312
								$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
9313
								#$conf["fileArgu"],字串,變數__FILE__的內容.
9314
								$conf["external::callShell"]["fileArgu"]=__FILE__;
9315
								#可省略參數:
9316
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9317
								$conf["external::callShell"]["argu"]=$callShellHelper["params"];
9318
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9319
								#$conf["arguIsAddr"]=array();
9320
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9321
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9322
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9323
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9324
								#$conf["enablePrintDescription"]="true";
9325
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9326
								#$conf["printDescription"]="";
9327
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9328
								$conf["external::callShell"]["escapeshellarg"]="true";
9329
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9330
								#$conf["thereIsShellVar"]=array();
9331
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9332
								#$conf["username"]="";
9333
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9334
								#$conf["password"]="";
9335
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9336
								#$conf["useScript"]="";
9337
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9338
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9339
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9340
								#$conf["inBackGround"]="";
9341
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9342
								#$conf["getErr"]="false";
9343
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9344
								#$conf["doNotRun"]="false";
9345
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
9346
								#$conf["remoteIp"]="";
9347
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
9348
								#$conf["remoteUser"]="";
9349
								#參考資料:
9350
								#exec=>http://php.net/manual/en/function.exec.php
9351
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9352
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9353
								#備註:
9354
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9355
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9356
								$callShell=external::callShell($conf["external::callShell"]);
9357
								unset($conf["external::callShell"]);
9358
 
9359
								#如果執行異常
9360
								if($callShellHelper["status"]==="false"){
9361
 
9362
									#設置錯誤識別
9363
									$result["status"]="false";
9364
 
9365
									#設置錯誤訊息
9366
									$result["error"]=$callShell;
9367
 
9368
									#回傳結果
9369
									return $result;
9370
 
9371
									}#if end
9372
 
9373
								}#foreach end
9374
 
9375
							}#if end
9376
 
9377
							#反之
9378
							else{
9379
 
281 liveuser 9380
								#if enable debug
9381
								if($debug){
9382
 
9383
									#debug msg
9384
									echo "There is only one cmd to run to apply ssl for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
9385
 
9386
									}#if end
9387
 
255 liveuser 9388
								#函式說明:
9389
								#解析指令與參數,回傳指令與參數給 callShell 函式使用.
9390
								#回傳結果:
9391
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9392
								#$result["error"],錯誤訊息陣列.
9393
								#$result["function"],當前執行的函數名稱.
9394
								#$result["argu"],使用的參數.
9395
								#$result["cmd"],執行的指令名稱.
9396
								#$result["params"],執行指令伴隨的參數.
9397
								#必填參數:
9398
								#$conf["cmdArray"],字串陣列,要執行的指令字串.
9399
								$conf["external::callShellHelper"]["cmdArray"]=$action;
9400
								#可省略參數:
9401
								#無.
9402
								#參考資料:
9403
								#array_shift=>https://www.php.net/manual/en/function.array-shift.php
9404
								#備註:
9405
								#無.
9406
								$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
9407
								unset($conf["external::callShellHelper"]);
9408
 
9409
								#如果執行異常
9410
								if($callShellHelper["status"]==="false"){
9411
 
9412
									#設置錯誤識別
9413
									$result["status"]="false";
9414
 
9415
									#設置錯誤訊息
9416
									$result["error"]=$callShellHelper;
9417
 
9418
									#回傳結果
9419
									return $result;
9420
 
9421
									}#if end
9422
 
9423
								#函式說明:
9424
								#呼叫shell執行系統命令,並取得回傳的內容.
9425
								#回傳結果:
9426
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9427
								#$result["error"],錯誤訊息陣列.
9428
								#$result["function"],當前執行的函數名稱.
9429
								#$result["argu"],使用的參數.
9430
								#$result["cmd"],執行的指令內容.
9431
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9432
								#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9433
								#$result["content"],為執行完後的輸出字串.
9434
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9435
								#$result["running"],是否還在執行.
9436
								#$result["pid"],pid.
9437
								#$result["statusCode"],執行結束後的代碼.
9438
								#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9439
								#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
9440
								#必填參數:
9441
								#$conf["command"],字串,要執行的指令.
9442
								$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
9443
								#$conf["fileArgu"],字串,變數__FILE__的內容.
9444
								$conf["external::callShell"]["fileArgu"]=__FILE__;
9445
								#可省略參數:
9446
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9447
								$conf["external::callShell"]["argu"]=$callShellHelper["params"];
9448
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9449
								#$conf["arguIsAddr"]=array();
9450
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9451
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9452
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9453
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9454
								#$conf["enablePrintDescription"]="true";
9455
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9456
								#$conf["printDescription"]="";
9457
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9458
								$conf["external::callShell"]["escapeshellarg"]="true";
9459
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9460
								#$conf["thereIsShellVar"]=array();
9461
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9462
								#$conf["username"]="";
9463
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9464
								#$conf["password"]="";
9465
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9466
								#$conf["useScript"]="";
9467
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9468
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9469
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9470
								#$conf["inBackGround"]="";
9471
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9472
								#$conf["getErr"]="false";
9473
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9474
								#$conf["doNotRun"]="false";
9475
								#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
9476
								#$conf["remoteIp"]="";
9477
								#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
9478
								#$conf["remoteUser"]="";
9479
								#參考資料:
9480
								#exec=>http://php.net/manual/en/function.exec.php
9481
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9482
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9483
								#備註:
9484
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9485
								#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9486
								$callShell=external::callShell($conf["external::callShell"]);
9487
								unset($conf["external::callShell"]);
9488
 
9489
								#如果執行異常
9490
								if($callShellHelper["status"]==="false"){
9491
 
9492
									#設置錯誤識別
9493
									$result["status"]="false";
9494
 
9495
									#設置錯誤訊息
9496
									$result["error"]=$callShell;
9497
 
9498
									#回傳結果
9499
									return $result;
9500
 
9501
									}#if end
9502
 
9503
								}#else end
9504
 
9505
							}#if end
9506
 
9507
						}#if end
9508
 
9509
					}#else end
9510
 
9511
				}#else end
9512
 
9513
			}#foreach end
9514
 
9515
		}#function sslUpdater_idle end
9516
 
226 liveuser 9517
	}#class zerossl end
255 liveuser 9518