Subversion Repositories php-qbpwcf

Rev

Rev 3 | Rev 239 | 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.
226 liveuser 6
    Copyright (C) 2014~2025 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
 
3 liveuser 127
		#create certificate path
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執行的詳細資訊.
153
	#必填參數:
154
	#$conf["fileArgu"],字串,變數__FILE__的內容.
155
	$conf["fileArgu"]=__FILE__;
156
	#可省略參數:
157
	#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
158
	#$conf["length"]=4096';
159
	#參考資料:
160
	#無.
161
	#備註:
162
	#key generated by openssl with RSA.
163
	*/
164
	public static function createPrivateKey(&$conf){
226 liveuser 165
 
3 liveuser 166
		#初始化要回傳的結果
167
		$result=array();
226 liveuser 168
 
3 liveuser 169
		#取得當前執行的函數名稱
170
		$result["function"]=__FUNCTION__;
226 liveuser 171
 
3 liveuser 172
		#如果 $conf 不為陣列
173
		if(gettype($conf)!="array"){
226 liveuser 174
 
3 liveuser 175
			#設置執行失敗
176
			$result["status"]="false";
226 liveuser 177
 
3 liveuser 178
			#設置執行錯誤訊息
179
			$result["error"][]="\$conf變數須為陣列形態";
180
 
181
			#如果傳入的參數為 null
182
			if($conf==null){
226 liveuser 183
 
3 liveuser 184
				#設置執行錯誤訊息
185
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 186
 
3 liveuser 187
				}#if end
188
 
189
			#回傳結果
190
			return $result;
226 liveuser 191
 
3 liveuser 192
			}#if end
226 liveuser 193
 
3 liveuser 194
		#取得參數
195
		$result["argu"]=$conf;
226 liveuser 196
 
3 liveuser 197
		#函式說明:
198
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
199
		#回傳結果:
200
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
201
		#$result["error"],執行不正常結束的錯訊息陣列.
202
		#$result["simpleError"],簡單表示的錯誤訊息.
203
		#$result["function"],當前執行的函式名稱.
204
		#$result["argu"],設置給予的參數.
205
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
206
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
207
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
208
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
209
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
210
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
211
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
212
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
213
		#必填參數:
214
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
215
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
216
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
217
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
218
		#可省略參數:
219
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
220
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
221
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
222
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
223
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
224
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
225
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
226
		#$conf["canNotBeEmpty"]=array();
227
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
228
		#$conf["canBeEmpty"]=array();
229
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
230
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("length");
231
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
232
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
233
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
234
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer");
235
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
236
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(4096);
237
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
238
		#$conf["disallowAllSkipableVarIsEmpty"]="";
239
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
240
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
241
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
242
		#$conf["disallowAllSkipableVarNotExist"]="";
243
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
244
		#$conf["arrayCountEqualCheck"][]=array();
245
		#參考資料:
246
		#array_keys=>http://php.net/manual/en/function.array-keys.php
247
		#備註:
248
		#無.
249
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
250
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 251
 
3 liveuser 252
		#如果 $checkArguments["status"]等於 "false"
253
		if($checkArguments["status"]==="false"){
254
 
255
			#設置執行錯誤的識別
256
			$result["status"]="false";
257
 
258
			#設置錯誤訊息
259
			$result["error"]=$checkArguments;
260
 
261
			#回傳結果
262
			return $result;
263
 
264
			}#if end
265
 
266
		#如果 $checkArguments["passed"]等於 "false"
267
		if($checkArguments["passed"]==="false"){
268
 
269
			#設置執行錯誤的識別
270
			$result["status"]="false";
271
 
272
			#設置錯誤訊息
273
			$result["error"]=$checkArguments;
274
 
275
			#回傳結果
276
			return $result;
277
 
278
			}#if end
226 liveuser 279
 
3 liveuser 280
		#函式說明:
281
		#呼叫shell執行系統命令,並取得回傳的內容.
282
		#回傳結果:
283
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
284
		#$result["error"],錯誤訊息陣列.
285
		#$result["function"],當前執行的函數名稱.
286
		#$result["argu"],使用的參數.
287
		#$result["cmd"],執行的指令內容.
288
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
289
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
290
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
291
		#$result["running"],是否還在執行.
292
		#$result["pid"],pid.
293
		#$result["statusCode"],執行結束後的代碼.
294
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
295
		#必填參數:
296
		#$conf["command"],字串,要執行的指令.
297
		$conf["external::callShell"]["command"]="openssl";
298
		#$conf["fileArgu"],字串,變數__FILE__的內容.
299
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
300
		#可省略參數:
301
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
302
		$conf["external::callShell"]["argu"]=array("genrsa",$conf["length"]);
303
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
304
		#$conf["arguIsAddr"]=array();
305
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
306
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
307
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
308
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
309
		#$conf["enablePrintDescription"]="true";
310
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
311
		#$conf["printDescription"]="";
312
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
313
		$conf["external::callShell"]["escapeshellarg"]="true";
314
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
315
		#$conf["thereIsShellVar"]=array();
316
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
317
		#$conf["username"]="";
318
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
319
		#$conf["password"]="";
320
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
321
		#$conf["useScript"]="";
322
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
323
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
324
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
325
		#$conf["inBackGround"]="";
326
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
327
		#$conf["getErr"]="false";
328
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
329
		#$conf["doNotRun"]="false";
330
		#參考資料:
331
		#exec=>http://php.net/manual/en/function.exec.php
332
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
333
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
334
		#備註:
335
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
336
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
337
		$callShell=external::callShell($conf["external::callShell"]);
338
		unset($conf["external::callShell"]);
226 liveuser 339
 
3 liveuser 340
		#如果異常
341
		if($callShell["status"]==="false"){
226 liveuser 342
 
3 liveuser 343
			#設置錯誤識別
344
			$result["status"]="false";
226 liveuser 345
 
3 liveuser 346
			#設置錯誤訊息
347
			$result["error"]=$callShell;
226 liveuser 348
 
3 liveuser 349
			#回傳結果
350
			return $result;
226 liveuser 351
 
3 liveuser 352
			}#if end
226 liveuser 353
 
3 liveuser 354
		#函式說明:
355
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
356
		#回傳的結果:
357
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
358
		#$result["function"],當前執行的function名稱
359
		#$result["error"],錯誤訊息陣列.
360
		#$result["content"],處理好的字串.
361
		#$result["argu"],使用的參數.
362
		#必填參數:
363
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
364
		$conf["arrays::arrayToString"]["inputArray"]=$callShell["output"];
365
		#可省略參數:
366
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
367
		$conf["arrays::arrayToString"]["spiltSymbol"]="";
368
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
369
		$conf["arrays::arrayToString"]["skipEnd"]="true";
370
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
371
		#$conf["spiltSymbolAtStart"]="";
372
		#參考資料:
373
		#無.
374
		#備註:
375
		#無.
376
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
377
		unset($conf["arrays::arrayToString"]);
226 liveuser 378
 
3 liveuser 379
		#如果異常
380
		if($arrayToString["status"]==="false"){
226 liveuser 381
 
3 liveuser 382
			#設置錯誤識別
383
			$result["status"]="false";
226 liveuser 384
 
3 liveuser 385
			#設置錯誤訊息
386
			$result["error"]=$arrayToString;
226 liveuser 387
 
3 liveuser 388
			#回傳結果
389
			return $result;
226 liveuser 390
 
3 liveuser 391
			}#if end
226 liveuser 392
 
3 liveuser 393
		#取得 private key 字串
394
		$result["content"]=$arrayToString["content"];
226 liveuser 395
 
3 liveuser 396
		#設置執行正常
397
		$result["status"]="true";
226 liveuser 398
 
3 liveuser 399
		#回傳結果
400
		return $result;
226 liveuser 401
 
3 liveuser 402
		}#function createPrivateKey end
226 liveuser 403
 
3 liveuser 404
	/*
405
	#函式說明:
406
	#產生certificate sign request.
407
	#回傳結果:
408
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
409
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
410
	#$result["function"],當前執行的函式名稱.
411
	#$result["argu"],所使用的參數.
412
	#$result["curl_verbose_info"],curl執行的詳細資訊.
413
	#必填參數:
414
	#$conf["certificate_domains"],字串,要簽署的doamin名稱.
415
	$conf["certificate_domains"]="";
416
	#$conf["certificate_csr"],字串,簽署的資訊.
417
	$conf["certificate_csr"]="";
418
	#$conf["fileArgu"],字串,變數__FILE__的內容.
419
	$conf["fileArgu"]=__FILE__;
420
	#可省略參數:
421
	#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
422
	#$conf["apiDomain"]=self::getApiInfo()["doamin"];
423
	#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
424
	#$conf["path"]=self::getApiInfo()["csrPath"];
425
	#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
426
	#$conf["key"]=self::getApiInfo()["apiKey"];
427
	#參考資料:
428
	#無.
429
	#備註:
430
	#無.
431
	*/
432
	public static function csr(&$conf){
226 liveuser 433
 
3 liveuser 434
		#break point
435
		#var_dump(self::getApiInfo());exit;
226 liveuser 436
 
3 liveuser 437
		#初始化要回傳的結果
438
		$result=array();
226 liveuser 439
 
3 liveuser 440
		#設置當其函數名稱
441
		$result["function"]=__FUNCTION__;
226 liveuser 442
 
3 liveuser 443
		#如果 $conf 不為陣列
444
		if(gettype($conf)!="array"){
226 liveuser 445
 
3 liveuser 446
			#設置執行失敗
447
			$result["status"]="false";
226 liveuser 448
 
3 liveuser 449
			#設置執行錯誤訊息
450
			$result["error"][]="\$conf變數須為陣列形態";
451
 
452
			#如果傳入的參數為 null
453
			if($conf==null){
226 liveuser 454
 
3 liveuser 455
				#設置執行錯誤訊息
456
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 457
 
3 liveuser 458
				}#if end
459
 
460
			#回傳結果
461
			return $result;
226 liveuser 462
 
3 liveuser 463
			}#if end
226 liveuser 464
 
3 liveuser 465
		#取得參數
466
		$result["argu"]=$conf;
226 liveuser 467
 
3 liveuser 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("fileArgu","certificate_domains","certificate_csr");
226 liveuser 487
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 488
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","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");
497
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","path","key");
226 liveuser 498
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 499
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
500
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
501
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["csrPath"],self::getApiInfo()["apiKey"]);
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"]);
226 liveuser 508
 
3 liveuser 509
		#如果檢查失敗
510
		if($checkArguments["status"]=="false"){
226 liveuser 511
 
3 liveuser 512
			#設置錯誤識別
513
			$result["status"]="false";
226 liveuser 514
 
3 liveuser 515
			#設置錯誤訊息
516
			$result["error"]=$checkArguments;
226 liveuser 517
 
3 liveuser 518
			#回傳結果
519
			return $result;
226 liveuser 520
 
3 liveuser 521
			}#if end
226 liveuser 522
 
3 liveuser 523
		#如果檢查不通過
524
		if($checkArguments["passed"]=="false"){
226 liveuser 525
 
3 liveuser 526
			#設置錯誤識別
527
			$result["status"]="false";
226 liveuser 528
 
3 liveuser 529
			#設置錯誤訊息
530
			$result["error"]=$checkArguments;
226 liveuser 531
 
3 liveuser 532
			#回傳結果
533
			return $result;
226 liveuser 534
 
3 liveuser 535
			}#if end
226 liveuser 536
 
3 liveuser 537
		#要傳送的 key -> value
538
		$postArray=array();
226 liveuser 539
 
3 liveuser 540
		#設置要簽署的domain
541
		$postArray["certificate_domains"]=$conf["certificate_domains"];
226 liveuser 542
 
3 liveuser 543
		#設置csr
544
		$postArray["certificate_csr"]=$conf["certificate_csr"];
226 liveuser 545
 
3 liveuser 546
		#預設為 90 天的憑證
547
		$postArray["certificate_validity_days"]=90;
226 liveuser 548
 
3 liveuser 549
		#強制讓 要簽署的domain 為 $postArray["certificate_domains"]
550
		$postArray["strict_domains"]=1;
226 liveuser 551
 
3 liveuser 552
		#設置要傳送的 json
553
		$postJson=json_encode($postArray);
226 liveuser 554
 
3 liveuser 555
		#函式說明:
556
		#運行curl cmd
557
		#回傳結果:
558
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
559
		#$result["error"],錯誤訊息陣列.
560
		#$result["function"],當前執行的函式名稱.
561
		#$result["founded"],識別網址找不找得到.
562
		#$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"代表程序的資訊.
563
		#$result["fullContent"],取得回應的完整字串內容.
564
		#$result["cookie"],cookie檔案的位置與名稱.
565
		#$result["cmd"],執行的command.
566
		#$result["argu],使用的參數.
567
		#必填參數:
568
		#$conf["url"],字串,目標url.
569
		$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].$conf["path"]."?access_key=".$conf["key"];
570
		#$conf["fileArgu"],字串,變數__FILE__的內容.
571
		$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
572
		#可省略參數:
573
		#$conf["header"],字串陣列,要傳送的header.
574
		$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
575
		#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
576
		#$conf["allowAnySSLcertificate"]="";
577
		#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
578
		#$conf["postVar"]=array();
579
		#$conf["rawPost"]="字串",要傳送的raw post內容.
580
		$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
581
		#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
582
		#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
583
		#$conf["agent"],字串,user agent的名稱.
584
		#$conf["agent"]="";
585
		#$conf["cookie"],字串,cookie位置與檔案位置.
586
		#$conf["cookie"]="";
587
		#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
588
		#$conf["forceNewCookie"]="";
589
		#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
590
		#$conf["inBg"]="true";
591
		#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
592
		#$conf["bgInProc"]="false";
593
		#參考資料:
594
		#無.
595
		#備註:
596
		#無.
597
		$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
598
		unset($conf["catchWebContent::curlCmd"]);
226 liveuser 599
 
3 liveuser 600
		#如果異常
601
		if($curlCmd["status"]==="false"){
226 liveuser 602
 
3 liveuser 603
			#設置錯誤識別
604
			$result["status"]="false";
226 liveuser 605
 
3 liveuser 606
			#設置錯誤訊息
607
			$result["error"]=$curlCmd;
226 liveuser 608
 
3 liveuser 609
			#回傳結果
610
			return $result;
226 liveuser 611
 
3 liveuser 612
			}#if end
226 liveuser 613
 
3 liveuser 614
		#設置curl的詳細資訊
615
		$result["curl_verbose_info"]=$curlCmd;
226 liveuser 616
 
3 liveuser 617
		/* 範例 json content
618
		"{"id":"f1448a54da0925356faec06154989452","type":"1","common_name":"test.qbpwcf.org","additional_domains":"","created":"2024-11-27 12:05:52","expires":"2025-02-25 00:00:00","status":"draft","validation_type":null,"validation_emails":null,"replacement_for":"","validation":{"email_validation":{"test.qbpwcf.org":["admin@test.qbpwcf.org","administrator@test.qbpwcf.org","hostmaster@test.qbpwcf.org","postmaster@test.qbpwcf.org","webmaster@test.qbpwcf.org","admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"test.qbpwcf.org":{"file_validation_url_http":"http:\/\/test.qbpwcf.org\/.well-known\/pki-validation\/5CED79AF9CCCB7C8633875D1A7C919FA.txt","file_validation_url_https":"https:\/\/test.qbpwcf.org\/.well-known\/pki-validation\/5CED79AF9CCCB7C8633875D1A7C919FA.txt","file_validation_content":["2C2CAB7C8B941192CB6BD9345DA3806BBC9F13A3DF3109C1E1A8B9B1ECC5B5FC","comodoca.com","42f21840bf8a7a6"],"cname_validation_p1":"_5CED79AF9CCCB7C8633875D1A7C919FA.test.qbpwcf.org","cname_validation_p2":"2C2CAB7C8B941192CB6BD9345DA3806B.BC9F13A3DF3109C1E1A8B9B1ECC5B5FC.42f21840bf8a7a6.comodoca.com"}}}}"
619
		*/
226 liveuser 620
 
3 liveuser 621
		#設置結果
622
		$result["content"]=$curlCmd["content"];
226 liveuser 623
 
3 liveuser 624
		#設置執行正常
625
		$result["status"]="true";
226 liveuser 626
 
3 liveuser 627
		#回傳結果
628
		return $result;
226 liveuser 629
 
3 liveuser 630
		}#function csr end
631
 
226 liveuser 632
	}#class zerossl end