Subversion Repositories php-qbpwcf

Rev

Rev 232 | 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
用於驗證處理的類別.
29
備註:
30
無.
31
*/
32
class authenticate{
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
	public function __call($method,$arguments){
226 liveuser 48
 
3 liveuser 49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
226 liveuser 51
 
3 liveuser 52
		#設置執行不正常
53
		$result["status"]="false";
226 liveuser 54
 
3 liveuser 55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 57
 
3 liveuser 58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
226 liveuser 60
 
3 liveuser 61
		#回傳結果
62
		return $result;
226 liveuser 63
 
3 liveuser 64
		}#function __call end
226 liveuser 65
 
3 liveuser 66
	/*
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
71
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
72
	#$result["function"],當前執行的函式名稱.
73
	#必填參數:
74
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
79
	public static function __callStatic($method,$arguments){
226 liveuser 80
 
3 liveuser 81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
226 liveuser 83
 
3 liveuser 84
		#設置執行不正常
85
		$result["status"]="false";
226 liveuser 86
 
3 liveuser 87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 89
 
3 liveuser 90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
226 liveuser 92
 
3 liveuser 93
		#回傳結果
94
		return $result;
226 liveuser 95
 
3 liveuser 96
		}#function __callStatic end
97
 
98
	/*
99
	#函式說明:
100
	#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確
101
	#回傳結果:
102
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
103
	#$result["passed"],是否驗證通過,"true"為驗證通過,"false"為驗證不通過.
104
	#$result["function"],當前執行的函數名稱.
105
	#$result["error"],錯誤訊息陣列.
106
	#必填參數:
107
	$conf["password"]="";#是驗證碼的內容應該要等於什麼才是對的。
108
	#可省略參數:
109
	#無.
110
	#參考資料:
111
	#無.
112
	#備註:
113
	#無.
226 liveuser 114
	*/
3 liveuser 115
	public static function simpleAuthenticate(&$conf){
226 liveuser 116
 
3 liveuser 117
		#初始化要回傳的變數
118
		$result=array();
226 liveuser 119
 
3 liveuser 120
		#記錄當前執行的函數名稱
121
		$result["function"]=__FUNCTION__;
226 liveuser 122
 
3 liveuser 123
		#如果 $conf 不為陣列
124
		if(gettype($conf)!="array"){
226 liveuser 125
 
3 liveuser 126
			#設置執行失敗
127
			$result["status"]="false";
226 liveuser 128
 
3 liveuser 129
			#設置執行錯誤訊息
130
			$result["error"][]="\$conf變數須為陣列形態";
131
 
132
			#如果傳入的參數為 null
133
			if($conf==null){
226 liveuser 134
 
3 liveuser 135
				#設置執行錯誤訊息
136
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 137
 
3 liveuser 138
				}#if end
139
 
140
			#回傳結果
141
			return $result;
226 liveuser 142
 
3 liveuser 143
			}#if end
226 liveuser 144
 
3 liveuser 145
		#檢查參數
146
		#函式說明:
147
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
148
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
149
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
150
		#$result["function"],當前執行的函式名稱.
151
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
152
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
153
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
154
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
155
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
156
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
157
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
158
		#必填參數:
159
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
160
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
161
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
162
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("password");
226 liveuser 163
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 164
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
165
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
166
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
167
		#可以省略的參數:
168
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
169
		#$conf["canBeEmptyString"]="false";
170
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
171
		#$conf["skipableVariableName"]=array();
226 liveuser 172
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 173
		#$conf["skipableVariableType"]=array();
174
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
175
		#$conf["skipableVarDefaultValue"]=array("");
176
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
177
		#$conf["arrayCountEqualCheck"][]=array();
178
		#參考資料來源:
179
		#array_keys=>http://php.net/manual/en/function.array-keys.php
180
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
181
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 182
 
3 liveuser 183
		#debug
184
		#var_dump($checkResult);
185
		#exit;
226 liveuser 186
 
3 liveuser 187
		#debug
188
		#var_dump($result);
189
		#exit;
226 liveuser 190
 
3 liveuser 191
		#如果檢查失敗
192
		if($checkResult["status"]=="false"){
226 liveuser 193
 
3 liveuser 194
			#debug
195
			#var_dump($result);
196
			#exit;
226 liveuser 197
 
3 liveuser 198
			#debug
199
			#var_dump($checkResult);
200
			#exit;
226 liveuser 201
 
3 liveuser 202
			#設置執行失敗
203
			$result["status"]="false";
226 liveuser 204
 
3 liveuser 205
			#設置執行錯誤訊息
206
			$result["error"]=$checkResult;
207
 
208
			#回傳結果
209
			return $result;
226 liveuser 210
 
3 liveuser 211
			}#if end
226 liveuser 212
 
3 liveuser 213
		#如果檢查不通過
214
		if($checkResult["passed"]=="false"){
226 liveuser 215
 
3 liveuser 216
			#設置執行失敗
217
			$result["status"]="false";
226 liveuser 218
 
3 liveuser 219
			#設置執行錯誤訊息
220
			$result["error"]=$checkResult;
221
 
222
			#回傳結果
223
			return $result;
226 liveuser 224
 
3 liveuser 225
			}#if end
226 liveuser 226
 
3 liveuser 227
		#debug
228
		#var_dump($result);
229
		#exit;
226 liveuser 230
 
3 liveuser 231
		#echo "entered";
226 liveuser 232
 
3 liveuser 233
		#若沒有供驗證的變數,或其驗證內容爲""
234
		if(!isset($_SESSION['password']) || $_SESSION['password']===""){
235
 
236
			#設置執行成功
237
			$result["status"]="true";
226 liveuser 238
 
3 liveuser 239
			#設置驗證不通過
240
			$result["passed"]="false";
226 liveuser 241
 
3 liveuser 242
			#回傳結果
243
			return $result;
226 liveuser 244
 
3 liveuser 245
			}#if end
246
 
247
		#如果驗證碼不正確
248
		if($_SESSION['password']!==$conf["password"]){
249
 
250
			#設置執行成功
251
			$result["status"]="true";
226 liveuser 252
 
3 liveuser 253
			#設置驗證不通過
254
			$result["passed"]="false";
226 liveuser 255
 
3 liveuser 256
			#回傳結果
257
			return $result;
258
 
259
			}#if end
260
 
261
		#反之驗證成功
262
		else{
263
 
264
			#設置執行成功
265
			$result["status"]="true";
226 liveuser 266
 
3 liveuser 267
			#設置驗證通過
268
			$result["passed"]="true";
226 liveuser 269
 
3 liveuser 270
			#回傳結果
271
			return $result;
272
 
273
			}#else end
226 liveuser 274
 
3 liveuser 275
		#不應該執行到這邊
276
		#設置執行失敗
277
		$result["status"]="false";
226 liveuser 278
 
3 liveuser 279
		#設置驗證不通過
280
		$result["passed"]="false";
226 liveuser 281
 
3 liveuser 282
		#回傳結果
283
		return $result;
226 liveuser 284
 
3 liveuser 285
		}#函式結束
286
 
287
	/*
288
	#函式說明:
289
	#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確,如果檢查不通過,則會轉址.
290
	#回傳結果:
291
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
292
	#$result["passed"],是否驗證通過,"true"為驗證通過,"false"為驗證不通過.
293
	#$result["function"],當前執行的函數名稱.
294
	#必填參數:
295
	$conf["failLocation"]="";#是當驗證失敗時要轉址到的位置
296
	$conf["password"]="";#是驗證碼的內容應該要等於什麼才是對的。
297
	#可省略參數:
298
	#無.
299
	#參考資料:
300
	#無.
301
	#備註:
302
	#無.
226 liveuser 303
	*/
3 liveuser 304
	public static function sessionAuthenticate(&$conf){
226 liveuser 305
 
3 liveuser 306
		#初始化要回傳的變數
307
		$result=array();
226 liveuser 308
 
3 liveuser 309
		#記錄當前執行的函數名稱
310
		$result["function"]=__FUNCTION__;
226 liveuser 311
 
3 liveuser 312
		#如果 $conf 不為陣列
313
		if(gettype($conf)!="array"){
226 liveuser 314
 
3 liveuser 315
			#設置執行失敗
316
			$result["status"]="false";
226 liveuser 317
 
3 liveuser 318
			#設置執行錯誤訊息
319
			$result["error"][]="\$conf變數須為陣列形態";
320
 
321
			#如果傳入的參數為 null
322
			if($conf==null){
226 liveuser 323
 
3 liveuser 324
				#設置執行錯誤訊息
325
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 326
 
3 liveuser 327
				}#if end
328
 
329
			#回傳結果
330
			return $result;
226 liveuser 331
 
3 liveuser 332
			}#if end
226 liveuser 333
 
3 liveuser 334
		#檢查參數
335
		#函式說明:
336
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
337
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
338
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
339
		#$result["function"],當前執行的函式名稱.
340
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
341
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
342
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
343
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
344
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
345
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
346
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
347
		#必填參數:
348
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
349
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
350
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
351
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("failLocation","password");
226 liveuser 352
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 353
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
354
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
355
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
356
		#可以省略的參數:
357
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
358
		#$conf["canBeEmptyString"]="false";
359
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
360
		#$conf["skipableVariableName"]=array();
226 liveuser 361
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 362
		#$conf["skipableVariableType"]=array();
363
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
364
		#$conf["skipableVarDefaultValue"]=array("");
365
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
366
		#$conf["arrayCountEqualCheck"][]=array();
367
		#參考資料來源:
368
		#array_keys=>http://php.net/manual/en/function.array-keys.php
369
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
370
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 371
 
3 liveuser 372
		#如果檢查失敗
373
		if($checkResult["status"]=="false"){
226 liveuser 374
 
3 liveuser 375
			#設置執行失敗
376
			$result["status"]="false";
226 liveuser 377
 
3 liveuser 378
			#設置執行錯誤訊息
379
			$result["error"]=$checkResult;
380
 
381
			#回傳結果
382
			return $result;
226 liveuser 383
 
3 liveuser 384
			}#if end
226 liveuser 385
 
3 liveuser 386
		#如果檢查不通過
387
		if($checkResult["status"]=="false"){
226 liveuser 388
 
3 liveuser 389
			#設置執行失敗
390
			$result["status"]="false";
226 liveuser 391
 
3 liveuser 392
			#設置執行錯誤訊息
393
			$result["error"]=$checkResult;
394
 
395
			#回傳結果
396
			return $result;
226 liveuser 397
 
3 liveuser 398
			}#if end
226 liveuser 399
 
3 liveuser 400
		#取得驗證碼驗證的回傳值
401
		#函式說明:
402
		#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確
403
		#回傳結果:
404
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
405
		#$result["passed"],是否驗證通過,"true"為驗證通過,"false"為驗證不通過.
406
		#$result["function"],當前執行的函數名稱.
407
		#$result["error"],錯誤訊息陣列.
408
		#必填參數:
409
		$conf["authenticate::simpleAuthenticate"]["password"]=$conf["password"];#是驗證碼的內容應該要等於什麼才是對的。
410
		$simpleAuthenticate=authenticate::simpleAuthenticate($conf["authenticate::simpleAuthenticate"]);
411
		unset($conf["authenticate::simpleAuthenticate"]);
412
 
413
		#如果執行驗證失敗
414
		if($simpleAuthenticate["status"]=="false"){
226 liveuser 415
 
3 liveuser 416
			#設置執行失敗
417
			$result["status"]="false";
226 liveuser 418
 
3 liveuser 419
			#設置錯誤訊息
420
			$result["error"]=$simpleAuthenticate;
226 liveuser 421
 
3 liveuser 422
			#回傳結果
423
			return $result;
226 liveuser 424
 
3 liveuser 425
			}#if end
426
 
427
		#如果驗證失敗
428
		if($simpleAuthenticate["passed"]=="false"){
226 liveuser 429
 
3 liveuser 430
			#進行轉址
431
			#函式說明:
432
			#設定session變數後,立即轉址.
433
			#回傳的結果:
434
			#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
435
			#$result["error"],錯誤訊息陣列.
436
			#必填的參數:
437
			#$conf["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
438
			$conf["header::redirectionNow"]["headerLocation"]=$conf["failLocation"];
439
			#可省略的參數:
440
			#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
441
			#$conf["sessionName"]=array("");
442
			#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
443
			#$conf["sessionValue"]=array("");
444
			#參靠資料來源:
445
			#http://php.net/manual/en/reserved.variables.server.php
446
			$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
447
			unset($conf["header::redirectionNow"]);
226 liveuser 448
 
3 liveuser 449
			#如果轉址失敗
450
			if($redirectionNow["status"]=="false"){
226 liveuser 451
 
3 liveuser 452
				#設置執行失敗
453
				$result["status"]="false";
226 liveuser 454
 
3 liveuser 455
				#設置錯誤訊息
456
				$result["error"]=$redirectionNow;
226 liveuser 457
 
3 liveuser 458
				#回傳結果
459
				return $result;
226 liveuser 460
 
3 liveuser 461
				}#if end
462
 
179 liveuser 463
			}#if end
226 liveuser 464
 
3 liveuser 465
		#執行到這邊代表正常
466
		#設置執行正常
467
		$result["status"]="true";
226 liveuser 468
 
3 liveuser 469
		#回傳結果
470
		return $result;
471
 
472
		}#函式結束
473
 
474
	/*
475
	#函式說明:
179 liveuser 476
	#用來檢查指定 session 變數是否存在以及其值是否正確,如果檢查不通過,可進行轉址.
477
	#回傳結果:
478
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
479
	#$result["function"],當前執行的函數名稱.
480
	#必填參數:
481
	#$conf["key"],字串陣列,session的key名稱與層級.
482
	$conf["key"]=array();
483
	#$conf["content"],session的內容應該要等於什麼才是對的.
484
	$conf["content"]=;
485
	#$conf["failLocation"],當驗證失敗時要轉址到的位置.
486
	$conf["failLocation"]="";
487
	#可省略參數:
488
	#$conf["unsetSess"],字串,預設為"false",代表不需要清除檢查過的seession變數;反之為"true".
489
	#$conf["unsetSess"]="false";
490
	#參考資料:
491
	#無.
492
	#備註:
493
	#無.
207 liveuser 494
	*/
179 liveuser 495
	public static function validateSession(&$conf){
226 liveuser 496
 
179 liveuser 497
		#初始化要回傳的變數
498
		$result=array();
226 liveuser 499
 
179 liveuser 500
		#記錄當前執行的函數名稱
501
		$result["function"]=__FUNCTION__;
226 liveuser 502
 
179 liveuser 503
		#如果 $conf 不為陣列
504
		if(gettype($conf)!="array"){
226 liveuser 505
 
179 liveuser 506
			#設置執行失敗
507
			$result["status"]="false";
226 liveuser 508
 
179 liveuser 509
			#設置執行錯誤訊息
510
			$result["error"][]="\$conf變數須為陣列形態";
511
 
512
			#如果傳入的參數為 null
513
			if($conf==null){
226 liveuser 514
 
179 liveuser 515
				#設置執行錯誤訊息
516
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 517
 
179 liveuser 518
				}#if end
519
 
520
			#回傳結果
521
			return $result;
226 liveuser 522
 
179 liveuser 523
			}#if end
226 liveuser 524
 
179 liveuser 525
		#檢查參數
526
		#函式說明:
527
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
528
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
529
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
530
		#$result["function"],當前執行的函式名稱.
531
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
532
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
533
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
534
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
535
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
536
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
537
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
538
		#必填參數:
539
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
540
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
541
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
542
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key","content","failLocation");
226 liveuser 543
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
179 liveuser 544
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
545
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
546
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
547
		#可以省略的參數:
548
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
549
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
550
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
551
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("unsetSess");
226 liveuser 552
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
179 liveuser 553
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
554
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
555
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
556
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
557
		#$conf["arrayCountEqualCheck"][]=array();
558
		#參考資料來源:
559
		#array_keys=>http://php.net/manual/en/function.array-keys.php
560
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
561
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 562
 
179 liveuser 563
		#如果檢查失敗
564
		if($checkResult["status"]==="false"){
226 liveuser 565
 
179 liveuser 566
			#設置執行失敗
567
			$result["status"]="false";
226 liveuser 568
 
179 liveuser 569
			#設置執行錯誤訊息
570
			$result["error"]=$checkResult;
571
 
572
			#回傳結果
573
			return $result;
226 liveuser 574
 
179 liveuser 575
			}#if end
226 liveuser 576
 
179 liveuser 577
		#如果檢查不通過
578
		if($checkResult["passed"]==="false"){
226 liveuser 579
 
179 liveuser 580
			#設置執行失敗
581
			$result["status"]="false";
226 liveuser 582
 
179 liveuser 583
			#設置執行錯誤訊息
584
			$result["error"]=$checkResult;
585
 
586
			#回傳結果
587
			return $result;
226 liveuser 588
 
179 liveuser 589
			}#if end
226 liveuser 590
 
179 liveuser 591
		#函式說明:
226 liveuser 592
		#取得指定的session數值
179 liveuser 593
		#回傳結果:
594
		#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
595
		#$result["error"],錯誤訊息.
596
		#$result["founded"],是否有該session變數,"true"代表有,"false"代表沒有.
597
		#$result["content"],session變數的內容
598
		#$result["address"],session變數的位址,請用 $yourVar=&$result["address"] 來取得位址.
599
		#$result["function"],當前執行的函數名稱.
600
		#$result["argu"],使用的參數.
601
		#必填參數:
602
		#$conf["key"],字串陣列,session的key名稱與層級.
603
		$conf["session::getVal"]["key"]=$conf["key"];
604
		#可省略參數:
605
		#$conf["unsetSess"],字串,是否要於成功取得session變數後,將之移除,預設為"false"代表不移除;反之為"true".
606
		$conf["session::getVal"]["unsetSess"]=$conf["unsetSess"];
607
		#參考資料:
608
		#無.
609
		#備註:
610
		#無.
611
		$getVal=session::getVal($conf["session::getVal"]);
612
		unset($conf["session::getVal"]);
226 liveuser 613
 
179 liveuser 614
		#如果執行異常
615
		if($getVal["status"]=="false"){
226 liveuser 616
 
179 liveuser 617
			#設置執行失敗
618
			$result["status"]="false";
226 liveuser 619
 
179 liveuser 620
			#設置執行錯誤訊息
621
			$result["error"]=$getVal;
622
 
623
			#回傳結果
624
			return $result;
226 liveuser 625
 
179 liveuser 626
			}#if end
226 liveuser 627
 
179 liveuser 628
		#如果指定的session變數不存在 或 session 內容不一樣
629
		if($getVal["founded"]==="false" || $getVal["content"]!==$conf["content"]){
226 liveuser 630
 
179 liveuser 631
			#函式說明:
632
			#設定session變數後,立即轉址.
633
			#回傳的結果:
634
			#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
635
			#$result["function"],當前執行的函數名稱.
636
			#$result["error"],錯誤訊息陣列.
637
			#必填參數:
638
			#$conf["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
639
			$conf["header::redirectionNow"]["headerLocation"]=$conf["failLocation"];
640
			#可省略參數:
641
			#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
642
			#$conf["sessionName"]=array("");
643
			#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
644
			#$conf["sessionValue"]=array("");
645
			#參考資料:
646
			#http://php.net/manual/en/reserved.variables.server.php
647
			#備註:
648
			#無.
649
			$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
650
			unset($conf["header::redirectionNow"]);
226 liveuser 651
 
179 liveuser 652
			#如果執行異常
653
			if($redirectionNow["status"]=="false"){
226 liveuser 654
 
179 liveuser 655
				#設置執行失敗
656
				$result["status"]="false";
226 liveuser 657
 
179 liveuser 658
				#設置執行錯誤訊息
659
				$result["error"]=$redirectionNow;
660
 
661
				#回傳結果
662
				return $result;
226 liveuser 663
 
179 liveuser 664
				}#if end
226 liveuser 665
 
179 liveuser 666
			}#if end
226 liveuser 667
 
179 liveuser 668
		}#function validateSession end
669
 
670
	/*
671
	#函式說明:
3 liveuser 672
	#檢查session裏面的使用者$_SESSION["account"]是否在會員清單裏面,與該會員所屬的羣組是否具有權限瀏覽該子功能頁面.
673
	#回傳的參數:
674
	#$result["status"],執行是否正常的識別,"true"代表一切正常,"false"代表不正常
675
	#$result["error"],錯誤訊息
676
	#$result["function"],當前執行的函數名稱
677
	#$result["passed"],是否通過檢查,"true"代表通過檢查,"false"代表沒有通過檢查.
678
	#$result["warning"],記錄不會影響程式執行,但是需要注意的事情。
679
	#$result["sql"],查詢用的sql.
680
	#必填參數:
681
	$conf["thisSubSystemName"]="";#爲該子系統的名稱,若該羣組所能瀏覽的子系統裏面有該名稱,則通過驗證。
682
	$conf["dbName"]="";#爲指定的資料庫名稱,欲選擇的資料庫名稱
683
	$conf["dbPassword"]="";#爲連線到資料庫時要使用的密碼,可省略,若省略則代表不使用密碼
684
	#可省略參數:
685
	#$conf["dbAddress"]="localhost";#爲資料庫的位置,預設爲 "localhost"
686
	#$conf["dbAccount"]="root";#爲用於連入資料庫時要使用的帳號,預設爲 "root"
687
	#$conf["dtName.member"]="member";#儲存會員資料的資料表,預設爲 "member"
688
	#$conf["dtName.userGroup"]="userGroupAuthorties";#儲存羣組資料的資,預設爲 "userGroupAuthorities"
689
	#參考資料:
690
	#無.
691
	#備註:
692
	#無.
693
	*/
694
	public static function checkUserGroupAuthorities($conf){
695
 
696
		#初始化要回傳的結果
697
		$result=array();
226 liveuser 698
 
3 liveuser 699
		#初始化儲存要回傳的警告訊息
700
		$result["warning"]=array();
226 liveuser 701
 
3 liveuser 702
		#記錄當前執行的涵式名稱
703
		$result["function"]=__FUNCTION__;
226 liveuser 704
 
3 liveuser 705
		#如果 $conf 不為陣列
706
		if(gettype($conf)!="array"){
226 liveuser 707
 
3 liveuser 708
			#設置執行失敗
709
			$result["status"]="false";
226 liveuser 710
 
3 liveuser 711
			#設置執行錯誤訊息
712
			$result["error"][]="\$conf變數須為陣列形態";
713
 
714
			#如果傳入的參數為 null
715
			if($conf==null){
226 liveuser 716
 
3 liveuser 717
				#設置執行錯誤訊息
718
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 719
 
3 liveuser 720
				}#if end
721
 
722
			#回傳結果
723
			return $result;
226 liveuser 724
 
3 liveuser 725
			}#if end
226 liveuser 726
 
3 liveuser 727
		#檢查參數
728
		#函式說明:
729
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
730
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
731
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
732
		#$result["function"],當前執行的函式名稱.
733
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
734
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
735
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
736
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
737
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
738
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
739
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
740
		#必填參數:
741
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
742
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
743
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
744
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("thisSubSystemName","dbName","dbPassword");
226 liveuser 745
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 746
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
747
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
748
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
749
		#可以省略的參數:
750
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
751
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
752
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
753
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbAddress","dbAccount","dtName.member","dtName.userGroup");
226 liveuser 754
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 755
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
756
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
757
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("localhost","root","member","userGroupAuthorities");
758
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
759
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
760
		#參考資料來源:
761
		#array_keys=>http://php.net/manual/en/function.array-keys.php
762
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
763
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 764
 
3 liveuser 765
		#如果 $checkResult["status"]=="false"
766
		if($checkResult["status"]=="false"){
226 liveuser 767
 
3 liveuser 768
			#設置執行不正常的適別
769
			$result["status"]="false";
226 liveuser 770
 
3 liveuser 771
			#設置執行錯誤的訊息
772
			$result["error"]=$checkResult;
226 liveuser 773
 
3 liveuser 774
			#回傳結果
775
			return $result;
226 liveuser 776
 
3 liveuser 777
			}#if end
778
 
779
		#如果 $checkResult["passed"] 等於 "false"
780
		if($checkResult["passed"]=="false"){
226 liveuser 781
 
3 liveuser 782
			#設置執行不正常的適別
783
			$result["status"]="false";
226 liveuser 784
 
3 liveuser 785
			#設置執行錯誤的訊息
786
			$result["error"]=$checkResult;
226 liveuser 787
 
3 liveuser 788
			#回傳結果
789
			return $result;
226 liveuser 790
 
3 liveuser 791
			}#if end
226 liveuser 792
 
3 liveuser 793
		#檢查是否有session["username"],如果不存在
794
		if(!isset($_SESSION["username"])){
795
 
796
			#設置執行正常的適別
797
			$result["status"]="true";
226 liveuser 798
 
3 liveuser 799
			#設置檢查不通過
800
			$result["passed"]="false";
226 liveuser 801
 
3 liveuser 802
			#設置警告訊息
803
			$result["warning"][]="使用者名稱變數不存在";
226 liveuser 804
 
3 liveuser 805
			#回傳結果
806
			return $result;
807
 
808
			}#if end
809
 
810
		#檢查$_SESSION["username"]所屬的羣組爲何
226 liveuser 811
 
3 liveuser 812
		#函式說明:
813
		#一次取得資料庫、表的資料
814
		#回傳的結果
815
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
816
		#$result["error"],錯誤訊息陣列。
817
		#$result["dataContent"],爲資料的內容。
818
		#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
819
			#$dataSetNum 爲第$dataSetNum+1筆資料
820
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
821
		#$result["dataCount"],爲取得的資料筆數。
822
		#$result["sql"],執行的sql字串.
823
		#必填參數:
824
		$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
825
		$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
826
		$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"];#爲要存取的資料庫名稱
827
		$conf["db"]["fastGetDbData"]["tableName"]=$conf["dtName.member"];#爲要存取的資料表名稱
828
		$conf["db"]["fastGetDbData"]["columnYouWant"]=array("account","groupName");#你想要的欄位!
829
		#可省略參數:
830
		$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
831
		$conf["db"]["fastGetDbData"]["WhereColumnName"]=array("account");#用於判斷語句的欄位項目陣列。
832
		$conf["db"]["fastGetDbData"]["WhereColumnValue"]=array($_SESSION["account"]);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
833
		#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
834
		#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
835
		#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
836
		#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
837
		#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
838
		#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
839
		#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
840
		#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
841
		$memberData=db::fastGetDbData($conf["db"]["fastGetDbData"]);
842
		unset($conf["db"]["fastGetDbData"]);
843
 
844
		#如果 $memberData["status"] 等於 "false"
845
		if($memberData["status"]=="false"){
226 liveuser 846
 
3 liveuser 847
			#設置執行不正常的適別
848
			$result["status"]="false";
226 liveuser 849
 
3 liveuser 850
			#設置執行錯誤的訊息
851
			$result["error"]=$memberData;
226 liveuser 852
 
3 liveuser 853
			#回傳結果
854
			return $result;
226 liveuser 855
 
3 liveuser 856
			}#if end
857
 
858
		#如果 $memberData["dataCount"] 等於 0
859
		if($memberData["dataCount"]==0){
226 liveuser 860
 
3 liveuser 861
			#代表沒有符合的帳戶
862
			$result["status"]="true";
226 liveuser 863
 
3 liveuser 864
			#設置警告訊息
865
			$result["warning"][]="使用者沒有歸屬於任何群組";
226 liveuser 866
 
3 liveuser 867
			#紀錄查詢用的sql
868
			$result["sql"]=$memberData["sql"];
226 liveuser 869
 
3 liveuser 870
			#設置檢查不通過
871
			$result["passed"]="false";
226 liveuser 872
 
3 liveuser 873
			#回傳結果
874
			return $result;
226 liveuser 875
 
3 liveuser 876
			}#if end
877
 
878
		#取得目前該使用者所屬的羣組
879
		$userGroup=$memberData["dataContent"]["groupName"][0];#符合資料的會員群組名稱。
880
 
881
		#檢查該群組能否瀏覽目標子系統
882
		#函式說明:
883
		#檢查資料庫裏的資料表有無指定條件的資料
884
		#回傳的結果:
885
		#$result["status"],執行是否成功,成功為"true",失敗為"false"。
226 liveuser 886
		#$result["error"],錯誤訊息
887
		#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
3 liveuser 888
		#必填參數:
889
		$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
890
		$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
891
		$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
892
		$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["dtName.userGroup"];#欲選擇的資料表名稱
893
		#可省略的參數:
894
		$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
895
		$conf["db"]["checkDataExists"]["conditionTargetName"]=array("groupName","visitableSubSystem");#用來判斷的資料表數值名稱,需爲陣列,可省略
896
		$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($userGroup,$conf["thisSubSystemName"]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
897
		$checkDataExistResult=db::checkDataExists($conf["db"]["checkDataExists"]);
898
		unset($conf["db"]["checkDataExists"]);
226 liveuser 899
 
3 liveuser 900
		#var_dump($checkDataExistResult);
226 liveuser 901
 
3 liveuser 902
		#如果 $checkDataExistResult["status"] 等於 "false"
903
		if($checkDataExistResult["status"]=="false"){
226 liveuser 904
 
3 liveuser 905
			#代表操作失敗
906
			$result["status"]="false";
226 liveuser 907
 
3 liveuser 908
			#設置警告訊息
909
			$result["error"]=$checkDataExistResult;
226 liveuser 910
 
3 liveuser 911
			#回傳結果
912
			return $result;
226 liveuser 913
 
3 liveuser 914
			}#if end
226 liveuser 915
 
3 liveuser 916
		#反之代表執行成功
917
		else{
226 liveuser 918
 
3 liveuser 919
			#如果 $checkDataExistResult["founded"] 等於 "true"
920
			if($checkDataExistResult["founded"]=="true"){
226 liveuser 921
 
3 liveuser 922
				#代表有相符合的資料
226 liveuser 923
 
3 liveuser 924
				#設置符合權限
925
				$result["passed"]="true";
226 liveuser 926
 
3 liveuser 927
				#設置執行正常
928
				$result["status"]="true";
226 liveuser 929
 
3 liveuser 930
				#回傳結果
931
				return $result;
226 liveuser 932
 
3 liveuser 933
				}#if end
226 liveuser 934
 
935
			#反之代表沒有找到相符的資料,不符合權限.
3 liveuser 936
			else{
226 liveuser 937
 
3 liveuser 938
				#設置符合權限
939
				$result["passed"]="false";
226 liveuser 940
 
3 liveuser 941
				#設置執行正常
226 liveuser 942
				$result["status"]="true";
943
 
3 liveuser 944
				#設置警告訊息
226 liveuser 945
				$result["warning"][]="使用者所屬的群組沒有權限使用該子系統";
946
 
3 liveuser 947
				#回傳結果
226 liveuser 948
				return $result;
949
 
3 liveuser 950
				}#else end
226 liveuser 951
 
3 liveuser 952
			}#else end
226 liveuser 953
 
3 liveuser 954
		#執行到這邊代表執行不正常
955
		$result["status"]="false";
226 liveuser 956
 
3 liveuser 957
		#設置錯誤訊息
226 liveuser 958
		$result["error"][]="不應該執行到的位置";
959
 
3 liveuser 960
		#回傳結果
961
		return $result;
226 liveuser 962
 
3 liveuser 963
		}#函式結束
226 liveuser 964
 
3 liveuser 965
	/*
966
	#函式說明:
967
	#建立以圖片(PNG格式)呈現的驗證碼.
968
	#回傳的解果:
969
	#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
970
	#$result["error"],錯誤訊息.
971
	#$result["function"],檔前執行的函數名稱.
972
	#$result["randNumberWord"],傳驗證碼的內容.
973
	#$result["imgAddress"],包含src圖片的位置與名稱.
974
	#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
975
	#必填參數:
976
	#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
977
	$conf["imgAddressAndName"]="";
978
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
979
	$conf["fileArgu"]=__FILE__;
980
	#可省略參數:
981
	#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
982
	#$conf["num"]="8";
983
	#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
984
	#$conf["disableImg"]="false";
985
	#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
986
	#$conf["imgToData"]="true";
987
	#$conf["class"],字串,圖片要套用的css樣式類別.
988
	#$conf["class"]="";
989
	#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
990
	#$conf["content"]=array();
991
	#參考資料:
992
	#無.
993
	#備註:
994
	#無.
207 liveuser 995
	*/
3 liveuser 996
	public static function validationCode(&$conf){
997
 
998
		#初始化要回傳的結果
999
		$result=array();
226 liveuser 1000
 
3 liveuser 1001
		#取得當前執行的函數
1002
		$result["function"]=__FUNCTION__;
1003
 
1004
		#如果 $conf 不為陣列
1005
		if(gettype($conf)!="array"){
226 liveuser 1006
 
3 liveuser 1007
			#設置執行失敗
1008
			$result["status"]="false";
226 liveuser 1009
 
3 liveuser 1010
			#設置執行錯誤訊息
1011
			$result["error"][]="\$conf變數須為陣列形態";
1012
 
1013
			#如果傳入的參數為 null
1014
			if($conf==null){
226 liveuser 1015
 
3 liveuser 1016
				#設置執行錯誤訊息
1017
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1018
 
3 liveuser 1019
				}#if end
1020
 
1021
			#回傳結果
1022
			return $result;
226 liveuser 1023
 
3 liveuser 1024
			}#if end
1025
 
1026
		#檢查參數
1027
		#函式說明:
1028
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1029
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1030
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1031
		#$result["function"],當前執行的函式名稱.
1032
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1033
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1034
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1035
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1036
		#必填參數:
1037
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1038
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1039
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1040
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("imgAddressAndName","fileArgu");
226 liveuser 1041
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 1042
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
1043
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1044
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1045
		#可以省略的參數:
1046
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1047
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1048
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1049
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","num","disableImg","imgToData","class","content");
226 liveuser 1050
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1051
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array");
1052
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1053
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"8","false","true",null,array("1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","V","U","W","X","Y","Z"));
1054
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1055
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
1056
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1057
		unset($conf["variableCheck::checkArguments"]);
1058
 
1059
		#如果檢查失敗
1060
		if($checkResult["status"]=="false"){
226 liveuser 1061
 
3 liveuser 1062
			#設置錯誤狀態
1063
			$result["status"]="false";
226 liveuser 1064
 
3 liveuser 1065
			#設置錯誤提示
1066
			$result["error"]=$checkResult;
226 liveuser 1067
 
3 liveuser 1068
			return $result;
226 liveuser 1069
 
3 liveuser 1070
			}#if end
1071
 
1072
		#如果檢查不通過
1073
		if($checkResult["passed"]=="false"){
226 liveuser 1074
 
3 liveuser 1075
			#設置錯誤狀態
1076
			$result["status"]="false";
226 liveuser 1077
 
3 liveuser 1078
			#設置錯誤提示
1079
			$result["error"]=$checkResult;
226 liveuser 1080
 
3 liveuser 1081
			return $result;
226 liveuser 1082
 
3 liveuser 1083
			}#if end
1084
 
1085
		#可以出現的亂數字碼
1086
		$target=$conf["content"];
1087
 
1088
		#建立$randNumberWordUn的初始值
1089
		$randNumberWordUn="";
1090
 
1091
		#跑$num次
1092
		for($i=0;$i<=($conf["num"]-1);$i++){
1093
 
1094
			#則將該代數值轉換成對應的target陣列值。
1095
			$number[$i]=$target[rand(0,count($target)-1)];
226 liveuser 1096
 
3 liveuser 1097
			#將轉換完的驗證碼合併
1098
			$randNumberWordUn=$randNumberWordUn.$number[$i];
226 liveuser 1099
 
3 liveuser 1100
			}#for end
226 liveuser 1101
 
1102
		#將合併好的驗證碼到randNumberWord
3 liveuser 1103
		$randNumberWord = $randNumberWordUn;
1104
 
1105
		#如果有設定產出圖片
1106
		if($conf["disableImg"]=="false"){
226 liveuser 1107
 
3 liveuser 1108
			#如果驗證碼數量爲$num則放置驗證碼的圖片寬度就等於
1109
			$backgroundImgWidth=$conf["num"]*10;
1110
 
1111
			#函式說明:
1112
			#建立含有文字的png圖檔
1113
			#回傳的結果:
1114
			#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
1115
			#$result["error"],錯誤訊息陣列
1116
			#$result["function"],當前執行的函數名稱
1117
			#$result["content"],圖片的位置與檔案名稱
1118
			#必填參數:
1119
			$conf["img::create"]["imgWidth"]=$backgroundImgWidth;#圖片的寬度(int)
1120
			$conf["img::create"]["imgHeight"]=20;#圖片的高度(int)
1121
			$conf["img::create"]["imgStoreAddAndName"]=$conf["imgAddressAndName"];#圖片要儲存到的地方以及其名稱
1122
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1123
			$conf["img::create"]["fileArgu"]=$conf["fileArgu"];
1124
			#可省略參數:
1125
			#$conf["bgRedNum"]=0;#圖片的紅色底色數值0~255,預設爲0
1126
			#$conf["bgGreenNum"]=0;#圖片的綠色底色數值0~255,預設爲0
1127
			#$conf["bgBlueNum"]=0;#圖片的藍色底色數值0~255,預設爲0
1128
			$conf["img::create"]["strOnImg"]=$randNumberWord;#要出現在圖片上的文字,預設為""
1129
			#$conf["textRedNum"]=255;#文字顏色的紅色數值0~255,預設爲255
1130
			#$conf["textGreenNum"]=255;#文字顏色的綠色數值0~255,預設爲255
1131
			#$conf["textBlueNum"]=255;#文字顏色的藍色數值0~255,預設爲255
1132
			#$conf["drawLine"]=array("");#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
1133
			#在圖片上畫左下到右上的線
1134
			$conf["img::create"]["drawLine"][]="0,0,".$backgroundImgWidth.",".$conf["img::create"]["imgHeight"].",255,0,0";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
1135
			#在圖片上畫左上到右下的線
1136
			$conf["img::create"]["drawLine"][]="0,".$conf["img::create"]["imgHeight"].",".$backgroundImgWidth.",0,0,255,0";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
1137
			#在圖片上畫左中到右中的線
1138
			$conf["img::create"]["drawLine"][]="0,".($conf["img::create"]["imgHeight"]/2).",".$backgroundImgWidth.",".($conf["img::create"]["imgHeight"]/2).",0,0,255";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
1139
			#在圖片上畫中上到中下的線
1140
			$conf["img::create"]["drawLine"][]=($backgroundImgWidth/2).",".$conf["img::create"]["imgHeight"].",".($backgroundImgWidth/2).",0,50,50,50";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
1141
			$conf["img::create"]["replaceOriImg"]="true";#如果遇到相同名字會將之刪除,flase爲不要刪除,預設為"false".
1142
			#參考資料來源:
1143
			#imagecreate=>http://php.net/manual/en/function.imagecreate.php
1144
			#imagecolorallocate=>http://php.net/manual/en/function.imagecolorallocate.php
1145
			#imagestring=>http://php.net/manual/en/function.imagestring.php
1146
			#imageline=>http://php.net/manual/en/function.imageline.php
1147
			#imagepng=>http://php.net/manual/en/function.imagepng.php
1148
			#imagedestroy=>http://php.net/manual/en/function.imagedestroy.php
1149
			$imgAddress=img::create($conf["img::create"]);
1150
			unset($conf["img::create"]);
226 liveuser 1151
 
3 liveuser 1152
			#如果建立圖片失敗
1153
			if($imgAddress["status"]=="false"){
226 liveuser 1154
 
3 liveuser 1155
				#設置錯誤狀態
1156
				$result["status"]="false";
226 liveuser 1157
 
3 liveuser 1158
				#設置錯誤提示
1159
				$result["error"]=$imgAddress;
226 liveuser 1160
 
3 liveuser 1161
				return $result;
226 liveuser 1162
 
3 liveuser 1163
				}#if end
226 liveuser 1164
 
3 liveuser 1165
			#設置圖片的位置與名稱
1166
			$result["imgAddress"]=$imgAddress["content"];
226 liveuser 1167
 
3 liveuser 1168
			#如果要把圖片轉存成base64
1169
			if($conf["imgToData"]=="true"){
226 liveuser 1170
 
3 liveuser 1171
				#函數說明:
1172
				#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
1173
				#回傳結果:
1174
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1175
				#$result["error"],錯誤訊息
1176
				#$result["content"]["imgWithoutImgTag"],img的src數值內容.
1177
				#$result["content"]["img"],圖片的連結資訊
226 liveuser 1178
				#$result["function"],當前執行的函數名稱
3 liveuser 1179
				#必填參數:
1180
				#$conf["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
1181
				$conf["img::data"]["imgPosition"]=$result["imgAddress"];
1182
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1183
				$conf["img::data"]["fileArgu"]=$conf["fileArgu"];
1184
				#可省略參數:
1185
				#$conf["alt"],若沒有圖片要用什麼文字顯示。
1186
				#$conf["alt"]="";
1187
				#$conf["class"],圖片要套用的css樣式名稱.
226 liveuser 1188
 
3 liveuser 1189
				#如果有設定 class
1190
				if(isset($conf["class"])){
226 liveuser 1191
 
3 liveuser 1192
					#設置圖片的 class
1193
					$conf["img::data"]["class"]=$conf["class"];
226 liveuser 1194
 
3 liveuser 1195
					}#if end
226 liveuser 1196
 
3 liveuser 1197
				#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
1198
				#$conf["mimeType"]="image/*";
1199
				#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
1200
				#$conf["compressType"]="base64";
1201
				#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
1202
				$conf["img::data"]["delImg"]="true";
1203
				#參考資料:
1204
				#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
1205
				#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
1206
				$data=img::data($conf["img::data"]);
1207
				unset($conf["img::data"]);
226 liveuser 1208
 
3 liveuser 1209
				#如果轉存成base64失敗
1210
				if($data["status"]=="false"){
226 liveuser 1211
 
3 liveuser 1212
					#設置錯誤狀態
1213
					$result["status"]="false";
226 liveuser 1214
 
3 liveuser 1215
					#設置錯誤提示
1216
					$result["error"]=$data;
226 liveuser 1217
 
3 liveuser 1218
					return $result;
226 liveuser 1219
 
3 liveuser 1220
					}#if end
226 liveuser 1221
 
1222
				#設置圖片src的數值
3 liveuser 1223
				$result["imgSrcVal"]=$data["content"]["imgWithoutImgTag"];
1224
 
1225
				#更新圖片位置為base64
1226
				$result["imgAddress"]=$data["content"]["img"];
226 liveuser 1227
 
3 liveuser 1228
				}#if end
226 liveuser 1229
 
3 liveuser 1230
			}#if end
226 liveuser 1231
 
3 liveuser 1232
		#設置執行成功狀態
1233
		$result["status"]="true";
226 liveuser 1234
 
3 liveuser 1235
		#設置亂數文字結果
1236
		$result["randNumberWord"]=$randNumberWord;
226 liveuser 1237
 
3 liveuser 1238
		#回傳內容
1239
		return $result;
1240
 
1241
		}#函式結束
226 liveuser 1242
 
3 liveuser 1243
	/*
1244
	#函式說明:
1245
	#產生亂數驗證碼或驗證亂數驗證碼與表單資料
1246
	#回傳結果:
1247
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1248
	#$result["error"],錯誤訊息.
1249
	#$result["argu"],使用的參數.
1250
	#$result["function"],當前執行的函數名稱.
1251
	#$result["content"],語法.
1252
	#必填參數:
1253
	#$conf["fileArgu"]
1254
	$conf["fileArgu"]=__FILE__;
1255
	#可省略參數:
1256
	#$conf["sendedName"],字串,傳送的post變數名稱,預設爲"formData".
226 liveuser 1257
	#$conf["sendedName"]="";
3 liveuser 1258
	#$conf["codeFormName"],字串,驗證碼表單的名稱,預設為"randomCode",對應的 session 變數名稱為 authenticate.verifyCodeAndFormData.$conf["codeFormName"]
1259
	#$conf["codeFormName"]="randomCode";
1260
	#$conf["names"],字串陣列,需要處理的表單必填變數.
1261
	#$conf["names"]=array();
1262
	#$conf["skipNames"],字串陣列,需要處理的表單可爲空變數.
226 liveuser 1263
	#$conf["skipNames"]=array();
3 liveuser 1264
	#參考資料:
1265
	#無.
1266
	#備註:
1267
	#請跟javaScript類別的randomCode函式搭配.應用情境在會員登入、驗證與寄送Email表單.
1268
	*/
1269
	function verifyCodeAndFormData($conf){
1270
 
1271
		#初始化要回傳的結果
1272
		$result=array();
1273
 
1274
		#取得當前執行的函數名稱
1275
		$result["function"]=__FUNCTION__;
1276
 
1277
		#如果沒有參數
1278
		if(func_num_args()==0){
1279
 
1280
			#設置執行失敗
1281
			$result["status"]="false";
1282
 
1283
			#設置執行錯誤訊息
1284
			$result["error"]="函數".$result["function"]."需要參數";
1285
 
1286
			#回傳結果
1287
			return $result;
1288
 
1289
			}#if en
1290
 
1291
		#取得參數
1292
		$result["argu"]=$conf;
1293
 
1294
		#如果 $conf 不為陣列
1295
		if(gettype($conf)!=="array"){
1296
 
1297
			#設置執行失敗
1298
			$result["status"]="false";
1299
 
1300
			#設置執行錯誤訊息
1301
			$result["error"][]="\$conf變數須為陣列形態";
1302
 
1303
			#如果傳入的參數為 null
1304
			if(is_null($conf)){
1305
 
1306
				#設置執行錯誤訊息
1307
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1308
 
1309
				}#if end
1310
 
1311
			#回傳結果
1312
			return $result;
1313
 
1314
			}#if end
226 liveuser 1315
 
3 liveuser 1316
		#函式說明:
1317
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1318
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1319
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1320
		#$result["function"],當前執行的函式名稱.
1321
		#$result["argu"],設置給予的參數.
1322
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1323
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1324
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1325
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1326
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1327
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1328
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1329
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1330
		#必填寫的參數:
1331
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1332
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1333
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1334
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1335
		#可以省略的參數:
1336
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1337
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
1338
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
1339
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
1340
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1341
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1342
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
1343
		#$conf["canNotBeEmpty"]=array();
1344
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
1345
		#$conf["canBeEmpty"]=array();
1346
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
1347
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sendedName","codeFormName","names","skipNames");
1348
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1349
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sendedName","codeFormName","names","skipNames");
1350
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1351
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array");
1352
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1353
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("formData","randomCode",null,null);
1354
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
1355
		#$conf["disallowAllSkipableVarIsEmpty"]="";
1356
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
1357
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
1358
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1359
		#$conf["arrayCountEqualCheck"][]=array();
1360
		#參考資料來源:
1361
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1362
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1363
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1364
 
3 liveuser 1365
		#如果出錯
1366
		if($checkArguments["status"]==="false"){
1367
 
1368
			#設置執行失敗
1369
			$result["status"]="false";
1370
 
1371
			#設置執行失敗
1372
			$result["error"]=$checkArguments;
1373
 
1374
			#回傳結果
1375
			return $result;
1376
 
1377
			}#if end
1378
 
1379
		#如果出錯
1380
		if($checkArguments["passed"]==="false"){
1381
 
1382
			#設置執行失敗
1383
			$result["status"]="false";
1384
 
1385
			#設置執行失敗
1386
			$result["error"]=$checkArguments;
1387
 
1388
			#回傳結果
1389
			return $result;
1390
 
226 liveuser 1391
			}#if end
3 liveuser 1392
 
226 liveuser 1393
		#如果沒有設置 $conf["names"]
3 liveuser 1394
		if(!isset($conf["names"])){
226 liveuser 1395
 
3 liveuser 1396
			#初始化
1397
			$conf["names"]=array($conf["codeFormName"]);
226 liveuser 1398
 
3 liveuser 1399
			}#if end
226 liveuser 1400
 
3 liveuser 1401
		#反之
1402
		else{
226 liveuser 1403
 
3 liveuser 1404
			#加上驗證碼表單
1405
			$conf["names"][]=$conf["codeFormName"];
226 liveuser 1406
 
3 liveuser 1407
			}#else end
1408
 
226 liveuser 1409
		#如果沒有設置 $conf["skipNames"]
3 liveuser 1410
		if(!isset($conf["skipNames"])){
226 liveuser 1411
 
3 liveuser 1412
			#初始化
1413
			$conf["skipNames"]=array();
226 liveuser 1414
 
3 liveuser 1415
			}#if end
226 liveuser 1416
 
3 liveuser 1417
		#函式說明:
1418
		#建立一個陣列,可以指派陣列的內容,然後回傳
1419
		#回傳的結果:
1420
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1421
		#$result["function"],當前執行的函數名稱.
1422
		#$result["error"],錯誤訊息陣列.
1423
		#$result["argu"],使用的參數.
1424
		#$result["content"],爲陣列變數內容
1425
		#必填參數:
1426
		$conf["arrays::create"]["arrayContent"]=array("string");#陣列元素的內容,須爲陣列值。
1427
		#可省略參數:
1428
		$conf["arrays::create"]["arrayCounts"]=count($conf["names"])+count($conf["skipNames"]);#爲陣列的元素有幾個,若沒設定,則數量爲$conf["arrayContent"]裏的元素數量
1429
		$conf["arrays::create"]["theSameAs"]="true";#若設爲"true",則所有元素內容都跟第一個元素內容相同
1430
		$create=arrays::create($conf["arrays::create"]);
1431
		unset($conf["arrays::create"]);
226 liveuser 1432
 
3 liveuser 1433
		#如果失敗
1434
		if($create["status"]==="false"){
226 liveuser 1435
 
3 liveuser 1436
			#設置執行失敗
1437
			$result["status"]="false";
1438
 
1439
			#設置執行失敗
1440
			$result["error"]=$create;
1441
 
1442
			#回傳結果
1443
			return $result;
226 liveuser 1444
 
3 liveuser 1445
			}#if end
226 liveuser 1446
 
3 liveuser 1447
		#函式說明:
1448
		#將多個一維陣列串聯起來,key從0開始排序.
1449
		#回傳的結果:
1450
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
1451
		#$result["error"],錯誤訊息陣列.
1452
		#$result["function"],當前執行的函數.
1453
		#$result["content"],合併好的一維陣列.
1454
		#必填的參數
1455
		#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
1456
		$conf["arrays::mergeArray"]["inputArray"]=array($conf["names"],$conf["skipNames"]);
1457
		#可省略的參數:
1458
		#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
1459
		#$conf["allowRepeat"]="true";
1460
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
1461
		unset($conf["arrays::mergeArray"]);
226 liveuser 1462
 
3 liveuser 1463
		#如果失敗
1464
		if($mergeArray["status"]==="false"){
226 liveuser 1465
 
3 liveuser 1466
			#設置執行失敗
1467
			$result["status"]="false";
1468
 
1469
			#設置執行失敗
1470
			$result["error"]=$mergeArray;
1471
 
1472
			#回傳結果
1473
			return $result;
226 liveuser 1474
 
3 liveuser 1475
			}#if end
226 liveuser 1476
 
3 liveuser 1477
		#如表單變數存在
1478
		if(isset($_POST[$conf["sendedName"]])){
1479
 
1480
			#解碼
1481
			$urlEncodeStr=base64_decode($_POST[$conf["sendedName"]]);
226 liveuser 1482
 
3 liveuser 1483
			#解碼
226 liveuser 1484
			$jsonEncodeStr=urldecode($urlEncodeStr);
3 liveuser 1485
 
1486
			#解碼
1487
			$obj=json_decode($jsonEncodeStr);
1488
 
1489
			#debug
1490
			#echo $urlEncodeStr."<p>";
1491
			#echo $jsonEncodeStr."<p>";
1492
			#var_dump($obj);
1493
 
1494
			#如果爲空物件
1495
			if($jsonEncodeStr==="{}"){
1496
 
1497
				#建立亂數驗證碼
1498
				#函式說明:
1499
				#建立以圖片(PNG格式)呈現的驗證碼.
1500
				#回傳的解果:
1501
				#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
1502
				#$result["error"],錯誤訊息.
1503
				#$result["function"],檔前執行的函數名稱.
1504
				#$result["randNumberWord"],傳驗證碼的內容.
1505
				#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
1506
				#$result["imgAddress"],圖片的位置與名稱.
1507
				#必填的參數:
1508
				#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
1509
				$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/authenticate.verifyCodeAndFormData.".$conf["codeFormName"];
1510
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1511
				$conf["authenticate::validationCode"]["fileArgu"]=$conf["fileArgu"];
1512
				#可省略參數:
1513
				#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
1514
				#$conf["num"]="8";
1515
				#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
1516
				#$conf["disableImg"]="false";
1517
				#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
1518
				#$conf["imgToData"]="true";
1519
				#$conf["class"],字串,圖片要套用的css樣式類別.
1520
				#$conf["class"]="";
1521
				$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
1522
				unset($conf["authenticate::validationCode"]);
1523
 
1524
				#如果建立亂碼圖片失敗
226 liveuser 1525
				if($validationCode["status"]==="false"){
3 liveuser 1526
 
1527
					#設置執行失敗
1528
					$result["status"]="false";
1529
 
1530
					#設置執行失敗
1531
					$result["error"]=$validationCode;
1532
 
1533
					#回傳結果
1534
					return $result;
1535
 
1536
					}#if end
1537
 
1538
				#設置驗證碼到session變數
1539
				$_SESSION["authenticate.verifyCodeAndFormData.".$conf["codeFormName"]]=$validationCode["randNumberWord"];
226 liveuser 1540
 
3 liveuser 1541
				#取得驗證碼長度
1542
				$json["content"]["randomCodeLength"]=strlen($_SESSION["authenticate.verifyCodeAndFormData.".$conf["codeFormName"]]);
1543
 
1544
				#設置圖片data
1545
				$json["content"]["randomCodeSrc"]=$validationCode["imgSrcVal"];
1546
 
1547
				#設置執行失敗
1548
				$json["status"]="false";
1549
 
1550
				#設置執行錯誤
1551
				$json["error"]="no data";
1552
 
1553
				#設置 json
1554
				$result["content"]=json_encode($json);
1555
 
1556
				#運行正常
1557
				$result["status"]="true";
1558
 
1559
				#回傳結果
1560
				return $result;
1561
 
226 liveuser 1562
				}#if end
1563
 
3 liveuser 1564
			#反之有內容
1565
			else{
226 liveuser 1566
 
3 liveuser 1567
				#清空post變數
226 liveuser 1568
				$_POST=array();
1569
 
3 liveuser 1570
				#debug
1571
				#echo $urlEncodeStr."<p>";
1572
				#echo $jsonEncodeStr."<p>";
1573
				#var_dump($obj);
1574
 
1575
				#依據每個物件
1576
				foreach($obj as $key=>$val){
1577
 
1578
					#設置對應的 post 數值
226 liveuser 1579
					$_POST[$key]=$val;
1580
 
3 liveuser 1581
					}#foreach end
1582
 
1583
				#debug
1584
				#echo json_encode($_POST);
1585
 
1586
				#如果驗證碼正確
1587
				if($_POST["randomCode"]===$_SESSION["authenticate.verifyCodeAndFormData.".$conf["codeFormName"]]){
1588
 
1589
					#設置執行正常
1590
					$json["status"]="true";
1591
 
1592
					#設置通過驗證
1593
					$json["passed"]="true";
1594
 
226 liveuser 1595
					#設置訊息
3 liveuser 1596
					$json["msg"]="通過驗證";
226 liveuser 1597
 
3 liveuser 1598
					#取得要檢查的變數名稱
1599
					$mustBeFilledVariableName=$mergeArray["content"];
226 liveuser 1600
 
3 liveuser 1601
					#取得要檢查的變數形態
226 liveuser 1602
					$mustBeFilledVariableType=$create["content"];
1603
 
3 liveuser 1604
					#檢查POST參數
1605
					#函式說明:
1606
					#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1607
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1608
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
1609
					#$result["function"],當前執行的函式名稱.
1610
					#$result["argu"],設置給予的參數.
1611
					#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1612
					#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1613
					#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1614
					#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1615
					#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1616
					#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1617
					#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1618
					#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1619
					#必填寫的參數:
1620
					#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1621
					$conf["variableCheck::checkArguments"]["varInput"]=&$_POST;
1622
					#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1623
					$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1624
					#可以省略的參數:
1625
					#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1626
					$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=$mustBeFilledVariableName;
1627
					#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
1628
					$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=$mustBeFilledVariableType;
1629
					#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1630
					$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
1631
					#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
1632
					$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=$conf["names"];
1633
					#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
1634
					#$conf["canBeEmpty"]=array();
1635
					#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
1636
					#$conf["skipableVariableCanNotBeEmpty"]=array();
1637
					#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1638
					#$conf["skipableVariableName"]=array();
1639
					#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1640
					#$conf["skipableVariableType"]=array();
1641
					#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1642
					#$conf["skipableVarDefaultValue"]=array("");
1643
					#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
1644
					#$conf["disallowAllSkipableVarIsEmpty"]="";
1645
					#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
1646
					#$conf["disallowAllSkipableVarIsEmptyArray"]="";
1647
					#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1648
					#$conf["arrayCountEqualCheck"][]=array();
1649
					#參考資料來源:
1650
					#array_keys=>http://php.net/manual/en/function.array-keys.php
1651
					$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1652
					unset($conf["variableCheck::checkArguments"]);
1653
 
1654
					#如果檢查失敗
1655
					if($checkArguments["status"]==="false"){
226 liveuser 1656
 
3 liveuser 1657
						#設置執行不正常
1658
						$jsons["status"]="false";
226 liveuser 1659
 
3 liveuser 1660
						#設置檢查不通過
1661
						$json["passed"]="false";
1662
 
1663
						#設置執行失敗
1664
						$json["error"]=$checkArguments;
1665
 
1666
						#設置 json
1667
						$result["content"]=json_encode($json);
226 liveuser 1668
 
3 liveuser 1669
						#運行正常
1670
						$result["status"]="true";
1671
 
1672
						#回傳結果
1673
						return $result;
226 liveuser 1674
 
3 liveuser 1675
						}#if end
226 liveuser 1676
 
3 liveuser 1677
					#如果檢查不通過
1678
					if($checkArguments["passed"]==="false"){
226 liveuser 1679
 
3 liveuser 1680
						#設置執行正常
1681
						$json["status"]="true";
226 liveuser 1682
 
3 liveuser 1683
						#設置檢查不通過
1684
						$json["passed"]="false";
1685
 
1686
						#設置執行失敗
1687
						$json["error"]=$checkArguments;
1688
 
1689
						#設置 json
1690
						$result["content"]=json_encode($json);
226 liveuser 1691
 
1692
						#運行正常
3 liveuser 1693
						$result["status"]="true";
1694
 
1695
						#回傳結果
1696
						return $result;
226 liveuser 1697
 
3 liveuser 1698
						}#if end
1699
 
1700
					#設置執行正常
1701
					$json["status"]="true";
1702
 
1703
					#設置通過驗證
226 liveuser 1704
					$json["passed"]="true";
1705
 
3 liveuser 1706
					#設置抓到的 post 內容
1707
					$json["post"]=$_POST;
1708
 
1709
					#設置 json
1710
					$result["content"]=json_encode($json);
226 liveuser 1711
 
1712
					#運行正常
3 liveuser 1713
					$result["status"]="true";
1714
 
1715
					#回傳結果
1716
					return $result;
226 liveuser 1717
 
3 liveuser 1718
					}#if end
1719
 
1720
				#反之
1721
				else{
1722
 
1723
					#設置執行正常
1724
					$json["status"]="true";
1725
 
1726
					#設置未通過驗證
1727
					$json["passed"]="false";
1728
 
226 liveuser 1729
					#設置錯誤訊息
3 liveuser 1730
					$json["error"]="驗證碼錯誤";
226 liveuser 1731
 
3 liveuser 1732
					#設置 json
1733
					$result["content"]=json_encode($json);
226 liveuser 1734
 
1735
					#運行正常
3 liveuser 1736
					$result["status"]="true";
1737
 
226 liveuser 1738
					#回傳結果
1739
					return $result;
3 liveuser 1740
 
1741
					}#else end
1742
 
1743
				}#else end
226 liveuser 1744
 
3 liveuser 1745
			#設置執行正常
1746
			$json["status"]="false";
1747
 
1748
			#設置通過驗證
1749
			$json["passed"]="false";
1750
 
226 liveuser 1751
			#設置錯誤訊息
1752
			$json["error"]="缺少POST變數";
1753
 
3 liveuser 1754
			#設置抓到的 post 內容
1755
			$json["post"]=$_POST;
1756
 
1757
			#設置 json
1758
			$result["content"]=json_encode($json);
226 liveuser 1759
 
1760
			#運行不正常
3 liveuser 1761
			$result["status"]="false";
1762
 
226 liveuser 1763
			#設置錯誤訊息
61 liveuser 1764
			$result["error"][]="缺少POST變數";
3 liveuser 1765
 
1766
			#回傳結果
1767
			return $result;
226 liveuser 1768
 
3 liveuser 1769
			}#if end
1770
 
1771
		}#function verifyCodeAndFormData end
226 liveuser 1772
 
3 liveuser 1773
	/*
1774
	#函式說明:
61 liveuser 1775
	#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
3 liveuser 1776
	#回傳結果:
226 liveuser 1777
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3 liveuser 1778
	#$result["function"],當前執行的函數名稱.
1779
	#$result["content"],加密後的結果.
1780
	#$result["error"],錯誤訊息陣列.
1781
	#$result["argu"],使用的參數.
1782
	#必填參數:
1783
	#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
1784
	$conf["enCodeStr"]="";
170 liveuser 1785
	#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過json_encode、urlencode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
3 liveuser 1786
	$conf["enCodeType"]="sha1";
1787
	#可省略參數:
1788
	#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
1789
	#$conf["sha1Raw"]="false";
1790
	#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
1791
	#$conf["p_hash"]="";
1792
	#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
1793
	#$conf["keyForAes256"]="";
1794
	#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
1795
	#$conf["aes256Encode"]="";
1796
	#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
1797
	#$conf["qbpwcfDecode"]="false";
61 liveuser 1798
	#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
1799
	#$conf["gpgDecrypt"]="false";
170 liveuser 1800
	#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
61 liveuser 1801
	#$conf["gpgId"]="";
3 liveuser 1802
	#參考資料:
1803
	#sha1=>http://php.net/manual/en/function.sha1.php
1804
	#md5=>http://php.net/manual/en/function.md5.php
1805
	#password_hash=>http://php.net/manual/en/function.password-hash.php
1806
	#password_verify=>http://php.net/manual/en/function.password-verify.php
1807
	#json_decode=>https://www.php.net/manual/en/function.json-decode.php
1808
	#備註:
1809
	#無.
1810
	*/
1811
	public static function enCodeStr(&$conf){
226 liveuser 1812
 
3 liveuser 1813
		#初始化要回傳的結果
1814
		$result=array();
226 liveuser 1815
 
3 liveuser 1816
		#記錄當前執行的函數
1817
		$result["function"]=__FUNCTION__;
226 liveuser 1818
 
3 liveuser 1819
		#如果 $conf 不為陣列
1820
		if(gettype($conf)!="array"){
226 liveuser 1821
 
3 liveuser 1822
			#設置執行失敗
1823
			$result["status"]="false";
226 liveuser 1824
 
3 liveuser 1825
			#設置執行錯誤訊息
1826
			$result["error"][]="\$conf變數須為陣列形態";
1827
 
1828
			#如果傳入的參數為 null
1829
			if($conf==null){
226 liveuser 1830
 
3 liveuser 1831
				#設置執行錯誤訊息
1832
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1833
 
3 liveuser 1834
				}#if end
1835
 
1836
			#回傳結果
1837
			return $result;
226 liveuser 1838
 
3 liveuser 1839
			}#if end
226 liveuser 1840
 
3 liveuser 1841
		#計數使用的參數
1842
		$result["argu"]=$conf;
226 liveuser 1843
 
3 liveuser 1844
		#檢查參數
1845
		#函式說明:
1846
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1847
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1848
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1849
		#$result["function"],當前執行的函式名稱.
1850
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1851
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1852
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1853
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1854
		#必填參數:
1855
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1856
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1857
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1858
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("enCodeStr","enCodeType");
226 liveuser 1859
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 1860
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array(null,"string");
1861
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1862
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1863
		#可以省略的參數:
1864
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1865
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1866
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
61 liveuser 1867
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sha1Raw","p_hash","keyForAes256","aes256Encode","qbpwcfDecode","gpgDecrypt","gpgId");
226 liveuser 1868
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
61 liveuser 1869
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
3 liveuser 1870
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
170 liveuser 1871
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,null,null,"false","false",gnupgId);
3 liveuser 1872
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1873
		#$conf["arrayCountEqualCheck"][]=array();
1874
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1875
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1876
 
3 liveuser 1877
		#如果檢查參數失敗
61 liveuser 1878
		if($checkResult["status"]==="false"){
226 liveuser 1879
 
3 liveuser 1880
			#設置執行失敗
1881
			$result["status"]="false";
226 liveuser 1882
 
3 liveuser 1883
			#設置執行錯誤
1884
			$result["error"]=$checkResult;
226 liveuser 1885
 
3 liveuser 1886
			#回傳結果
1887
			return $result;
226 liveuser 1888
 
3 liveuser 1889
			}#if end
226 liveuser 1890
 
3 liveuser 1891
		#如果檢查參數不通過
61 liveuser 1892
		if($checkResult["passed"]==="false"){
226 liveuser 1893
 
3 liveuser 1894
			#設置執行失敗
1895
			$result["status"]="false";
226 liveuser 1896
 
3 liveuser 1897
			#設置執行錯誤
1898
			$result["error"]=$checkResult;
226 liveuser 1899
 
3 liveuser 1900
			#回傳結果
1901
			return $result;
226 liveuser 1902
 
182 liveuser 1903
			}#if end
226 liveuser 1904
 
3 liveuser 1905
		#判斷是哪一種加密方法
1906
		switch($conf["enCodeType"]){
226 liveuser 1907
 
3 liveuser 1908
			#如果是 "sha1"
1909
			case "sha1":
226 liveuser 1910
 
3 liveuser 1911
				#如果輸入不是字串
1912
				if(gettype($conf["enCodeStr"])!=="string"){
226 liveuser 1913
 
3 liveuser 1914
					#設置執行失敗
1915
					$result["status"]="false";
226 liveuser 1916
 
3 liveuser 1917
					#設置執行錯誤
1918
					$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
226 liveuser 1919
 
3 liveuser 1920
					#回傳結果
1921
					return $result;
226 liveuser 1922
 
3 liveuser 1923
					}#if end
226 liveuser 1924
 
3 liveuser 1925
				#如果要用2元碼輸出
1926
				if($conf["sha1Raw"]=="true"){
226 liveuser 1927
 
3 liveuser 1928
					#sha1加密
1929
					$encodeStr=sha1($conf["enCodeStr"],TRUE);
226 liveuser 1930
 
3 liveuser 1931
					#如果加密失敗
1932
					if($encodeStr==false){
226 liveuser 1933
 
3 liveuser 1934
						#設置執行失敗
1935
						$result["status"]="false";
226 liveuser 1936
 
3 liveuser 1937
						#設置執行錯誤
1938
						$result["error"][]="加密失敗";
226 liveuser 1939
 
3 liveuser 1940
						#回傳結果
1941
						return $result;
226 liveuser 1942
 
3 liveuser 1943
						}#if end
226 liveuser 1944
 
3 liveuser 1945
					#反之加密成功
1946
					else{
226 liveuser 1947
 
3 liveuser 1948
						#取得加密後的字串
1949
						$result["content"]=$encodeStr;
226 liveuser 1950
 
3 liveuser 1951
						}#else end
226 liveuser 1952
 
3 liveuser 1953
					}#if end
226 liveuser 1954
 
3 liveuser 1955
				#反之用16進位數值輸出
1956
				else{
226 liveuser 1957
 
3 liveuser 1958
					#sha1加密
1959
					$encodeStr=sha1($conf["enCodeStr"],FALSE);
226 liveuser 1960
 
3 liveuser 1961
					#如果加密失敗
1962
					if($encodeStr==false){
226 liveuser 1963
 
3 liveuser 1964
						#設置執行失敗
1965
						$result["status"]="false";
226 liveuser 1966
 
3 liveuser 1967
						#設置執行錯誤
1968
						$result["error"][]="加密失敗";
226 liveuser 1969
 
3 liveuser 1970
						#回傳結果
1971
						return $result;
226 liveuser 1972
 
3 liveuser 1973
						}#if end
226 liveuser 1974
 
3 liveuser 1975
					#反之加密成功
1976
					else{
226 liveuser 1977
 
3 liveuser 1978
						#取得加密後的字串
1979
						$result["content"]=$encodeStr;
226 liveuser 1980
 
3 liveuser 1981
						}#else end
1982
 
1983
					}#else end
226 liveuser 1984
 
3 liveuser 1985
				#跳出
1986
				break;
226 liveuser 1987
 
3 liveuser 1988
			#如果是 "md5"
1989
			case "md5";
226 liveuser 1990
 
3 liveuser 1991
				#如果輸入不是字串
1992
				if(gettype($conf["enCodeStr"])!=="string"){
226 liveuser 1993
 
3 liveuser 1994
					#設置執行失敗
1995
					$result["status"]="false";
226 liveuser 1996
 
3 liveuser 1997
					#設置執行錯誤
1998
					$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
226 liveuser 1999
 
3 liveuser 2000
					#回傳結果
2001
					return $result;
226 liveuser 2002
 
3 liveuser 2003
					}#if end
226 liveuser 2004
 
3 liveuser 2005
				#md5加密
2006
				$encodeStr=md5($conf["enCodeStr"]);
226 liveuser 2007
 
3 liveuser 2008
				#如果加密失敗
2009
				if($encodeStr==false){
226 liveuser 2010
 
3 liveuser 2011
					#設置執行失敗
2012
					$result["status"]="false";
226 liveuser 2013
 
3 liveuser 2014
					#設置執行錯誤
2015
					$result["error"][]="加密失敗";
226 liveuser 2016
 
3 liveuser 2017
					#回傳結果
2018
					return $result;
226 liveuser 2019
 
3 liveuser 2020
					}#if end
226 liveuser 2021
 
3 liveuser 2022
				#反之加密成功
2023
				else{
226 liveuser 2024
 
3 liveuser 2025
					#取得加密後的字串
2026
					$result["content"]=$encodeStr;
226 liveuser 2027
 
3 liveuser 2028
					}#else end
226 liveuser 2029
 
3 liveuser 2030
				#跳出
2031
				break;
226 liveuser 2032
 
3 liveuser 2033
			#如果是"p_hash"
2034
			case "p_hash":
226 liveuser 2035
 
3 liveuser 2036
				#如果輸入不是字串
2037
				if(gettype($conf["enCodeStr"])!=="string"){
226 liveuser 2038
 
3 liveuser 2039
					#設置執行失敗
2040
					$result["status"]="false";
226 liveuser 2041
 
3 liveuser 2042
					#設置執行錯誤
2043
					$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
226 liveuser 2044
 
3 liveuser 2045
					#回傳結果
2046
					return $result;
226 liveuser 2047
 
3 liveuser 2048
					}#if end
226 liveuser 2049
 
3 liveuser 2050
				#如果 $conf["p_hash"] 存在
2051
				if(isset($conf["p_hash"])){
226 liveuser 2052
 
3 liveuser 2053
					#檢驗 $conf["enCodeStr"] 是否與 $conf["p_hash"] 相符
2054
					if(password_verify($conf["enCodeStr"],$conf["p_hash"])){
226 liveuser 2055
 
3 liveuser 2056
						#設置執行正常
2057
						$result["status"]="true";
226 liveuser 2058
 
3 liveuser 2059
						#回傳結果
2060
						return $result;
226 liveuser 2061
 
3 liveuser 2062
						}#if end
226 liveuser 2063
 
3 liveuser 2064
					#反之
2065
					else{
226 liveuser 2066
 
3 liveuser 2067
						#設置執行失敗
2068
						$result["status"]="false";
226 liveuser 2069
 
3 liveuser 2070
						#設置執行錯誤
2071
						$result["error"][]="密碼不正確";
226 liveuser 2072
 
3 liveuser 2073
						#回傳結果
2074
						return $result;
226 liveuser 2075
 
3 liveuser 2076
						}#else end
226 liveuser 2077
 
3 liveuser 2078
					}#if end
226 liveuser 2079
 
3 liveuser 2080
				#加密密碼
2081
				$encodeStr=password_hash($conf["enCodeStr"],PASSWORD_DEFAULT);
226 liveuser 2082
 
3 liveuser 2083
				#如果加密失敗
2084
				if($encodeStr==false){
226 liveuser 2085
 
3 liveuser 2086
					#設置執行失敗
2087
					$result["status"]="false";
226 liveuser 2088
 
3 liveuser 2089
					#設置執行錯誤
2090
					$result["error"][]="加密失敗";
226 liveuser 2091
 
3 liveuser 2092
					#回傳結果
2093
					return $result;
226 liveuser 2094
 
3 liveuser 2095
					}#if end
226 liveuser 2096
 
3 liveuser 2097
				#反之加密成功
2098
				else{
226 liveuser 2099
 
3 liveuser 2100
					#取得加密後的字串
2101
					$result["content"]=$encodeStr;
226 liveuser 2102
 
3 liveuser 2103
					}#else end
226 liveuser 2104
 
3 liveuser 2105
				break;
226 liveuser 2106
 
3 liveuser 2107
			#如果是 AES 256 bit 加密
2108
			#參考資料:
2109
			#https://www.ucamc.com/e-learning/php/388-php%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8aes-openssl%E5%8A%A0%E5%AF%86%E4%BB%A3%E7%A2%BC%E3%80%81encrypt%E3%80%81decrypt
2110
			case "aes256":
226 liveuser 2111
 
3 liveuser 2112
				#如果輸入不是字串
2113
				if(gettype($conf["enCodeStr"])!=="string"){
226 liveuser 2114
 
3 liveuser 2115
					#設置執行失敗
2116
					$result["status"]="false";
226 liveuser 2117
 
3 liveuser 2118
					#設置執行錯誤
2119
					$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
226 liveuser 2120
 
3 liveuser 2121
					#回傳結果
2122
					return $result;
226 liveuser 2123
 
3 liveuser 2124
					}#if end
226 liveuser 2125
 
3 liveuser 2126
				#如果參數有缺
2127
				if( !isset($conf["keyForAes256"]) || !isset($conf["aes256Encode"]) ){
226 liveuser 2128
 
3 liveuser 2129
					#設置執行失敗
2130
					$result["status"]="false";
226 liveuser 2131
 
3 liveuser 2132
					#設置執行錯誤
2133
					$result["error"][]="aes256 演算法需要 keyForAes256 與 aes256Encode 參數";
226 liveuser 2134
 
3 liveuser 2135
					#回傳結果
2136
					return $result;
226 liveuser 2137
 
3 liveuser 2138
					}#if end
226 liveuser 2139
 
3 liveuser 2140
				#如果是要加密
2141
				if($conf["aes256Encode"]==="true"){
226 liveuser 2142
 
3 liveuser 2143
					#取得iv
2144
					$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
226 liveuser 2145
 
3 liveuser 2146
					#加密內容
2147
					$encrypted = openssl_encrypt($conf["enCodeStr"], 'aes-256-cbc', $conf["keyForAes256"], 0, $iv);
226 liveuser 2148
 
3 liveuser 2149
					#使用base64加密的內容
2150
					$result["content"]=base64_encode($encrypted . '::' . $iv);
226 liveuser 2151
 
3 liveuser 2152
					#數值執行正常
2153
					$result["status"]="true";
226 liveuser 2154
 
3 liveuser 2155
					#回傳結果
2156
					return $result;
226 liveuser 2157
 
3 liveuser 2158
					}#if end
226 liveuser 2159
 
3 liveuser 2160
				#反之是要解密
2161
				else{
226 liveuser 2162
 
3 liveuser 2163
					#取得 base64_decoed 的本文與 iv
2164
					list($conf["enCodeStr"], $iv) = explode('::', base64_decode($conf["enCodeStr"]), 2);
226 liveuser 2165
 
3 liveuser 2166
					#取得 解密好的內容
61 liveuser 2167
					$result["content"]=openssl_decrypt($conf["enCodeStr"], 'aes-256-cbc', $conf["keyForAes256"], 0, $iv);
226 liveuser 2168
 
61 liveuser 2169
					#數值執行正常
3 liveuser 2170
					$result["status"]="true";
226 liveuser 2171
 
3 liveuser 2172
					#回傳結果
2173
					return $result;
226 liveuser 2174
 
3 liveuser 2175
					}#else end
226 liveuser 2176
 
3 liveuser 2177
				#跳出迴圈
226 liveuser 2178
				break;
2179
 
3 liveuser 2180
			#如果是 "qbpwcf"
2181
			case "qbpwcf":
226 liveuser 2182
 
3 liveuser 2183
				#如果是要加密
2184
				if($conf["qbpwcfDecode"]==="false"){
226 liveuser 2185
 
232 liveuser 2186
					#設置編碼好的內容
2187
					$result["content"]=base64_encode(serialize($conf["enCodeStr"]));
239 liveuser 2188
 
3 liveuser 2189
					}#if end
226 liveuser 2190
 
3 liveuser 2191
				#反之是要解密
2192
				else{
226 liveuser 2193
 
3 liveuser 2194
					#設置解密好的內容
232 liveuser 2195
					$result["content"]=unserialize(base64_decode($conf["enCodeStr"]));
226 liveuser 2196
 
3 liveuser 2197
					}#else end
226 liveuser 2198
 
61 liveuser 2199
				#跳出 switch
226 liveuser 2200
				break;
2201
 
61 liveuser 2202
			#若是bin2hex
2203
			case "bin2hex":
226 liveuser 2204
 
61 liveuser 2205
				#用16進位的兩個字母來表示每個byte
66 liveuser 2206
				$unpack=unpack("H*",$conf["enCodeStr"]);
226 liveuser 2207
 
66 liveuser 2208
				#如果沒有結果
2209
				if(!isset($unpack[1])){
226 liveuser 2210
 
66 liveuser 2211
					#設置執行失敗
2212
					$result["status"]="false";
226 liveuser 2213
 
66 liveuser 2214
					#設置執行錯誤
2215
					$result["error"][]="bin2hex failed";
226 liveuser 2216
 
66 liveuser 2217
					#設置執行錯誤
2218
					$result["error"][]=$unpack;
226 liveuser 2219
 
66 liveuser 2220
					#回傳結果
2221
					return $result;
226 liveuser 2222
 
66 liveuser 2223
					}#if end
226 liveuser 2224
 
66 liveuser 2225
				#取得結果
2226
				$result["content"]=$unpack[1];
226 liveuser 2227
 
61 liveuser 2228
				#相當於
2229
				#$result["content"]=bin2hex($conf["enCodeStr"]);
226 liveuser 2230
 
61 liveuser 2231
				#跳出 switch
2232
				break;
226 liveuser 2233
 
61 liveuser 2234
			#若是hex2bin
2235
			case "hex2bin":
226 liveuser 2236
 
61 liveuser 2237
				#將每個byte用兩個16進位字母來表示的字串變成 binary string
66 liveuser 2238
 				$pack=pack("H*",$conf["enCodeStr"]);
226 liveuser 2239
 
66 liveuser 2240
				$result["content"]=$pack;
226 liveuser 2241
 
61 liveuser 2242
				#跳出 switch
2243
				break;
226 liveuser 2244
 
61 liveuser 2245
			#如果是"gpg加解密"
2246
			case "gpg":
226 liveuser 2247
 
61 liveuser 2248
				#如果沒有 gpgId
2249
				if(!isset($conf["gpgId"])){
226 liveuser 2250
 
61 liveuser 2251
					#設置執行失敗
2252
					$result["status"]="false";
226 liveuser 2253
 
61 liveuser 2254
					#設置執行錯誤
2255
					$result["error"]="param gpgId if required when enCodeType is ".$conf["enCodeType"];
226 liveuser 2256
 
61 liveuser 2257
					#回傳結果
2258
					return $result;
226 liveuser 2259
 
61 liveuser 2260
					}#if end
226 liveuser 2261
 
232 liveuser 2262
				#如果是用gpg加密
61 liveuser 2263
				if($conf["gpgDecrypt"]==="false"){
226 liveuser 2264
 
232 liveuser 2265
					#如果是 array 或 object
2266
					if( gettype($conf["enCodeStr"])==="array" || gettype($conf["enCodeStr"])==="object"){
239 liveuser 2267
 
232 liveuser 2268
						#用 qbpwcf encode
2269
						#函式說明:
2270
						#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
2271
						#回傳結果:
2272
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2273
						#$result["function"],當前執行的函數名稱.
2274
						#$result["content"],加密後的結果.
2275
						#$result["error"],錯誤訊息陣列.
2276
						#$result["argu"],使用的參數.
2277
						#必填參數:
2278
						#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
2279
						$conf["self::enCodeStr"]["enCodeStr"]=$conf["enCodeStr"];
2280
						#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過json_encode、urlencode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
2281
						$conf["self::enCodeStr"]["enCodeType"]="qbpwcf";
2282
						#可省略參數:
2283
						#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
2284
						#$conf["sha1Raw"]="false";
2285
						#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
2286
						#$conf["p_hash"]="";
2287
						#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
2288
						#$conf["keyForAes256"]="";
2289
						#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
2290
						#$conf["aes256Encode"]="";
2291
						#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
2292
						#$conf["qbpwcfDecode"]="false";
2293
						#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
2294
						#$conf["gpgDecrypt"]="false";
2295
						#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
2296
						#$conf["gpgId"]="";
2297
						#參考資料:
2298
						#sha1=>http://php.net/manual/en/function.sha1.php
2299
						#md5=>http://php.net/manual/en/function.md5.php
2300
						#password_hash=>http://php.net/manual/en/function.password-hash.php
2301
						#password_verify=>http://php.net/manual/en/function.password-verify.php
2302
						#json_decode=>https://www.php.net/manual/en/function.json-decode.php
2303
						#備註:
2304
						#無.
2305
						$enCodeStr=self::enCodeStr($conf["self::enCodeStr"]);
2306
						unset($conf["self::enCodeStr"]);
239 liveuser 2307
 
232 liveuser 2308
						#如果執行失敗
2309
						if($enCodeStr["status"]==="false"){
61 liveuser 2310
 
232 liveuser 2311
							#設置執行失敗
2312
							$result["status"]="false";
61 liveuser 2313
 
232 liveuser 2314
							#設置執行錯誤
2315
							$result["error"]=$enCodeStr;
2316
 
2317
							#回傳結果
2318
							return $result;
2319
 
2320
							}#if end
239 liveuser 2321
 
232 liveuser 2322
						#取得 qbpwcf 編碼後的結果
2323
						$conf["enCodeStr"]=$enCodeStr["content"];
239 liveuser 2324
 
232 liveuser 2325
						}#if end
2326
 
2327
					#如果已經為字串
2328
					if(gettype($conf["enCodeStr"])==="string"){
239 liveuser 2329
 
232 liveuser 2330
						#先用 base64 decode 為原始加密後的結果 再用 gpg 解密.
2331
						#函式說明:
2332
						#呼叫shell執行系統命令,並取得回傳的內容.
2333
						#回傳結果:
2334
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2335
						#$result["error"],錯誤訊息陣列.
2336
						#$result["function"],當前執行的函數名稱.
2337
						#$result["argu"],使用的參數.
2338
						#$result["cmd"],執行的指令內容.
2339
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
2340
						#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
2341
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
2342
						#$result["content"],為執行完後的輸出字串.
2343
						#$result["running"],是否還在執行.
2344
						#$result["pid"],pid.
2345
						#$result["statusCode"],執行結束後的代碼.
2346
						#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
2347
						#必填參數:
2348
						#$conf["command"],字串,要執行的指令.
2349
						$conf["external::callShell"]["command"]="base64decode.php";
2350
						#$conf["fileArgu"],字串,變數__FILE__的內容.
2351
						$conf["external::callShell"]["fileArgu"]=__FILE__;
2352
						#可省略參數:
2353
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
2354
						$conf["external::callShell"]["argu"]=array(base64_encode($conf["enCodeStr"]),"|","gpg","-r",$conf["gpgId"],"--trust-model","always","-v","-e");
2355
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
2356
						#$conf["arguIsAddr"]=array();
2357
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
2358
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
2359
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
2360
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2361
						#$conf["enablePrintDescription"]="true";
2362
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
2363
						#$conf["printDescription"]="";
2364
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
2365
						$conf["external::callShell"]["escapeshellarg"]="true";
2366
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
2367
						#$conf["thereIsShellVar"]=array();
2368
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
2369
						#$conf["username"]="";
2370
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2371
						#$conf["password"]="";
2372
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
2373
						#$conf["useScript"]="";
2374
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
2375
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
2376
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
2377
						#$conf["inBackGround"]="";
2378
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
2379
						#$conf["getErr"]="false";
2380
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
2381
						#$conf["doNotRun"]="false";
2382
						#參考資料:
2383
						#exec=>http://php.net/manual/en/function.exec.php
2384
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2385
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2386
						#備註:
2387
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
2388
						#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
2389
						$callShell=external::callShell($conf["external::callShell"]);
2390
						unset($conf["external::callShell"]);
2391
 
2392
						#如果執行失敗
2393
						if($callShell["status"]==="false"){
2394
 
2395
							#設置執行失敗
2396
							$result["status"]="false";
2397
 
2398
							#設置執行錯誤
2399
							$result["error"]=$callShell;
2400
 
2401
							#回傳結果
2402
							return $result;
2403
 
2404
							}#if end
239 liveuser 2405
 
232 liveuser 2406
						#取得加密後的內容
2407
						$result["content"]=$callShell["content"];
239 liveuser 2408
 
232 liveuser 2409
						}#if end
2410
 
2411
					#反之為不支援的參數形態
2412
					else{
239 liveuser 2413
 
61 liveuser 2414
						#設置執行失敗
2415
						$result["status"]="false";
226 liveuser 2416
 
61 liveuser 2417
						#設置執行錯誤
232 liveuser 2418
						$result["error"]="unsupported input type(".$gettype($conf["enCodeStr"]).")";
226 liveuser 2419
 
61 liveuser 2420
						#回傳結果
2421
						return $result;
239 liveuser 2422
 
232 liveuser 2423
						}#else end
226 liveuser 2424
 
61 liveuser 2425
					}#if end
226 liveuser 2426
 
232 liveuser 2427
				#反之如果是 gpg 解密
61 liveuser 2428
				else if($conf["gpgDecrypt"]==="true"){
226 liveuser 2429
 
232 liveuser 2430
					#用 base64 decode 解編碼
61 liveuser 2431
					#函式說明:
2432
					#呼叫shell執行系統命令,並取得回傳的內容.
2433
					#回傳結果:
2434
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2435
					#$result["error"],錯誤訊息陣列.
2436
					#$result["function"],當前執行的函數名稱.
2437
					#$result["argu"],使用的參數.
2438
					#$result["cmd"],執行的指令內容.
2439
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
2440
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
2441
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
2442
					#$result["content"],為執行完後的輸出字串.
2443
					#$result["running"],是否還在執行.
2444
					#$result["pid"],pid.
2445
					#$result["statusCode"],執行結束後的代碼.
2446
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
2447
					#必填參數:
2448
					#$conf["command"],字串,要執行的指令.
2449
					$conf["external::callShell"]["command"]="base64decode.php";
2450
					#$conf["fileArgu"],字串,變數__FILE__的內容.
2451
					$conf["external::callShell"]["fileArgu"]=__FILE__;
2452
					#可省略參數:
2453
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
2454
					$conf["external::callShell"]["argu"]=array(base64_encode($conf["enCodeStr"]),"|","gpg","-r",$conf["gpgId"],"--trust-model","always","-v","-d");
2455
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
2456
					#$conf["arguIsAddr"]=array();
2457
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
2458
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
2459
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
2460
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2461
					#$conf["enablePrintDescription"]="true";
2462
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
2463
					#$conf["printDescription"]="";
2464
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
2465
					$conf["external::callShell"]["escapeshellarg"]="true";
2466
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
2467
					#$conf["thereIsShellVar"]=array();
2468
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
2469
					#$conf["username"]="";
2470
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2471
					#$conf["password"]="";
2472
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
2473
					#$conf["useScript"]="";
2474
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
2475
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
2476
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
2477
					#$conf["inBackGround"]="";
2478
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
2479
					#$conf["getErr"]="false";
2480
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
2481
					#$conf["doNotRun"]="false";
2482
					#參考資料:
2483
					#exec=>http://php.net/manual/en/function.exec.php
2484
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2485
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2486
					#備註:
2487
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
2488
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
2489
					$callShell=external::callShell($conf["external::callShell"]);
2490
					unset($conf["external::callShell"]);
2491
 
2492
					#如果執行失敗
2493
					if($callShell["status"]==="false"){
2494
 
2495
						#設置執行失敗
2496
						$result["status"]="false";
226 liveuser 2497
 
61 liveuser 2498
						#設置執行錯誤
2499
						$result["error"]=$callShell;
226 liveuser 2500
 
61 liveuser 2501
						#回傳結果
2502
						return $result;
2503
 
2504
						}#if end
226 liveuser 2505
 
232 liveuser 2506
					#取得解密後的內容
61 liveuser 2507
					$result["content"]=$callShell["content"];
226 liveuser 2508
 
61 liveuser 2509
					}#else end
226 liveuser 2510
 
61 liveuser 2511
				#跳出 switch
2512
				break;
226 liveuser 2513
 
3 liveuser 2514
			#如果是其他內容
2515
			default:
226 liveuser 2516
 
3 liveuser 2517
				#設置執行失敗
2518
				$result["status"]="false";
226 liveuser 2519
 
3 liveuser 2520
				#設置執行錯誤
2521
				$result["error"][]="不支援的加密方法「".$conf["enCodeType"]."」";
226 liveuser 2522
 
3 liveuser 2523
				#回傳結果
2524
				return $result;
226 liveuser 2525
 
3 liveuser 2526
			}#switch end
226 liveuser 2527
 
3 liveuser 2528
		#執行到這邊代表執行正常
2529
		$result["status"]="true";
226 liveuser 2530
 
3 liveuser 2531
		#回傳結果
2532
		return $result;
226 liveuser 2533
 
61 liveuser 2534
		}#function enCodeStr end
226 liveuser 2535
 
3 liveuser 2536
	/*
2537
	#函式說明:
2538
	#將字串變成2元碼或2元碼變成字串.
2539
	#回傳結果:
226 liveuser 2540
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3 liveuser 2541
	#$result["function"],當前執行的函數名稱.
2542
	#$result["content"],加密後的結果.
2543
	#$result["error"],錯誤訊息陣列.
2544
	#必填參數:
2545
	#$conf["input"],"字串",要hex或unhex的字串
2546
	$conf["input"]="";
2547
	#$conf["action"],"字串",要toBin或toStr.
226 liveuser 2548
	$conf["action"]="";
3 liveuser 2549
	#可省略參數:
2550
	#無.
2551
	#參考資料:
2552
	#hex2bin=>http://php.net/manual/en/function.hex2bin.php #bin2hex=>http://php.net/manual/en/function.binhex.php #pack=>http://php.net/manual/en/function.pack.php 轉換的方法似乎有問題. bin2hex可以將10進位數字字串轉換成2進位字串.
2553
	#備註:
2554
	#無.
2555
	*/
2556
	public static function str2bin(&$conf){
226 liveuser 2557
 
3 liveuser 2558
		#初始化要回傳的結果
2559
		$result=array();
226 liveuser 2560
 
3 liveuser 2561
		#記錄當前執行的函數
2562
		$result["function"]=__FUNCTION__;
226 liveuser 2563
 
3 liveuser 2564
		#如果沒有參數
2565
		if(func_num_args()==0){
226 liveuser 2566
 
3 liveuser 2567
			#設置執行失敗
2568
			$result["status"]="false";
226 liveuser 2569
 
3 liveuser 2570
			#設置執行錯誤訊息
2571
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 2572
 
3 liveuser 2573
			#回傳結果
2574
			return $result;
226 liveuser 2575
 
3 liveuser 2576
			}#if end
226 liveuser 2577
 
3 liveuser 2578
		#如果 $conf 不為陣列
2579
		if(gettype($conf)!="array"){
226 liveuser 2580
 
3 liveuser 2581
			#設置執行失敗
2582
			$result["status"]="false";
226 liveuser 2583
 
3 liveuser 2584
			#設置執行錯誤訊息
2585
			$result["error"][]="\$conf變數須為陣列形態";
2586
 
2587
			#如果傳入的參數為 null
2588
			if($conf==null){
226 liveuser 2589
 
3 liveuser 2590
				#設置執行錯誤訊息
2591
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2592
 
3 liveuser 2593
				}#if end
2594
 
2595
			#回傳結果
2596
			return $result;
226 liveuser 2597
 
3 liveuser 2598
			}#if end
226 liveuser 2599
 
3 liveuser 2600
		#檢查參數
2601
		#函式說明:
2602
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2603
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2604
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2605
		#$result["function"],當前執行的函式名稱.
2606
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2607
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2608
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2609
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2610
		#必填參數:
2611
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2612
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2613
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2614
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input","action");
226 liveuser 2615
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2616
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2617
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2618
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2619
		#可以省略的參數:
2620
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2621
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2622
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2623
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sha1Raw","p_hash");
226 liveuser 2624
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2625
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
2626
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2627
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null);
2628
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2629
		#$conf["arrayCountEqualCheck"][]=array();
2630
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2631
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 2632
 
3 liveuser 2633
		#如果檢查參數失敗
2634
		if($checkResult["status"]=="false"){
226 liveuser 2635
 
3 liveuser 2636
			#設置執行失敗
2637
			$result["status"]="false";
226 liveuser 2638
 
3 liveuser 2639
			#設置執行錯誤
2640
			$result["error"]=$checkResult;
226 liveuser 2641
 
3 liveuser 2642
			#回傳結果
2643
			return $result;
226 liveuser 2644
 
3 liveuser 2645
			}#if end
226 liveuser 2646
 
3 liveuser 2647
		#如果要hex
2648
		if($conf["action"]=="toBin"){
226 liveuser 2649
 
3 liveuser 2650
			#將字串轉換成2進位
2651
			$result["content"]=pack('H*', base_convert($conf["input"], 2, 16));
226 liveuser 2652
 
2653
			}#if end
2654
 
3 liveuser 2655
		#反之如果要unhex
2656
		else if($conf["action"]=="toStr"){
226 liveuser 2657
 
3 liveuser 2658
			#將2進位轉為字串
2659
			$result["content"]=unpack('H*',$conf["input"]);
2660
 
2661
			#針對每個字
2662
			foreach($result["content"] as $key=>$bin){
2663
 
2664
				#轉換成字串
2665
				$result["content"][$key]=base_convert($result["content"][1], 16, 2);
2666
 
61 liveuser 2667
				}#foreach end
226 liveuser 2668
 
3 liveuser 2669
			}#if end
226 liveuser 2670
 
3 liveuser 2671
		#設置執行正常
2672
		$result["status"]="true";
226 liveuser 2673
 
3 liveuser 2674
		#回傳結果
2675
		return $result;
2676
 
226 liveuser 2677
		}#function str2bin end
2678
 
3 liveuser 2679
	/*
2680
	#函式說明:
66 liveuser 2681
	#驗證Linux使用者的密碼或ssh private key是否正確.
3 liveuser 2682
	#回傳結果:
226 liveuser 2683
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3 liveuser 2684
	#$result["function"],當前執行的函數名稱.
2685
	#$result["error"],錯誤訊息陣列.
2686
	#$result["warninig"],警告訊息陣列.
2687
	#$result["valid"],是否為存在的使用者且密碼正確.
2688
	#必填參數:
2689
	#$conf["username"],字串,要驗證的使用者名稱.
2690
	$conf["username"]="";
2691
	#$conf["password"],字串,用於驗證使用者的密碼.
2692
	$conf["password"]="";
2693
	#$conf["fileArgu"],字串,變數__FILE__的內容.
2694
	$conf["fileArgu"]=__FILE__;
2695
	#可省略參數:
66 liveuser 2696
	#$conf["sshPrivateKey"],字串,"true"代表password為ssh private key的內容;反之預設為密碼,設置為"false".
2697
	#$conf["sshPrivateKey"]="false";
3 liveuser 2698
	#參考資料:
2699
	#無.
2700
	#備註:
66 liveuser 2701
	#僅能在命令列環境下運.
2702
	#目前僅支援驗證執行php端的使用者.
3 liveuser 2703
	*/
2704
	public static function validUser(&$conf){
226 liveuser 2705
 
3 liveuser 2706
		#初始化要回傳的結果
2707
		$result=array();
2708
 
2709
		#取得當前執行的函數名稱
2710
		$result["function"]=__FUNCTION__;
2711
 
2712
		#初始化警告訊息
2713
		$result["warning"]=array();
2714
 
2715
		#函式說明:
2716
		#判斷當前環境為web還是cmd
2717
		#回傳結果:
2718
		#$result,"web"或"cmd"
2719
		if(csInformation::getEnv()=="web"){
226 liveuser 2720
 
3 liveuser 2721
			#設置執行失敗
2722
			$result["status"]="false";
226 liveuser 2723
 
3 liveuser 2724
			#設置執行錯誤訊息
2725
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 2726
 
3 liveuser 2727
			#回傳結果
2728
			return $result;
226 liveuser 2729
 
3 liveuser 2730
			}#if end
2731
 
2732
		#如果沒有參數
2733
		if(func_num_args()==0){
226 liveuser 2734
 
3 liveuser 2735
			#設置執行失敗
2736
			$result["status"]="false";
226 liveuser 2737
 
3 liveuser 2738
			#設置執行錯誤訊息
2739
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 2740
 
3 liveuser 2741
			#回傳結果
2742
			return $result;
226 liveuser 2743
 
3 liveuser 2744
			}#if end
2745
 
2746
		#取得參數
2747
		$result["argu"]=$conf;
2748
 
2749
		#如果 $conf 不為陣列
2750
		if(gettype($conf)!="array"){
226 liveuser 2751
 
3 liveuser 2752
			#設置執行失敗
2753
			$result["status"]="false";
226 liveuser 2754
 
3 liveuser 2755
			#設置執行錯誤訊息
2756
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 2757
 
3 liveuser 2758
			#如果傳入的參數為 null
2759
			if($conf==null){
226 liveuser 2760
 
3 liveuser 2761
				#設置執行錯誤訊息
2762
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2763
 
3 liveuser 2764
				}#if end
2765
 
2766
			#回傳結果
2767
			return $result;
226 liveuser 2768
 
3 liveuser 2769
			}#if end
226 liveuser 2770
 
3 liveuser 2771
		#檢查參數
2772
		#函式說明:
2773
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2774
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2775
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2776
		#$result["function"],當前執行的函式名稱.
2777
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2778
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2779
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2780
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
2781
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
2782
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2783
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2784
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2785
		#必填參數:
2786
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2787
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2788
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2789
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","fileArgu");
2790
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
2791
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
2792
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2793
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2794
		#可以省略的參數:
2795
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
2796
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2797
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列
2798
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("password");
2799
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列
2800
		$conf["variableCheck::checkArguments"]["canBeEmpty"]=array("password");
2801
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
2802
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2803
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
66 liveuser 2804
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sshPrivateKey");
226 liveuser 2805
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
66 liveuser 2806
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
3 liveuser 2807
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
66 liveuser 2808
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
3 liveuser 2809
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2810
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
2811
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
2812
		#參考資料來源:
2813
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2814
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
226 liveuser 2815
		unset($conf["variableCheck::checkArguments"]);
2816
 
3 liveuser 2817
		#如果檢查參數失敗
2818
		if($checkArguments["status"]=="false"){
226 liveuser 2819
 
3 liveuser 2820
			#設置執行不正常
2821
			$result["status"]="false";
226 liveuser 2822
 
3 liveuser 2823
			#設置執行錯誤
2824
			$result["error"]=$checkArguments;
226 liveuser 2825
 
3 liveuser 2826
			#回傳結果
2827
			return $result;
226 liveuser 2828
 
3 liveuser 2829
			}#if end
226 liveuser 2830
 
3 liveuser 2831
		#如果檢查參數不通過
2832
		if($checkArguments["passed"]=="false"){
226 liveuser 2833
 
3 liveuser 2834
			#設置執行不正常
2835
			$result["status"]="false";
226 liveuser 2836
 
3 liveuser 2837
			#設置執行錯誤
2838
			$result["error"]=$checkArguments;
226 liveuser 2839
 
3 liveuser 2840
			#回傳結果
2841
			return $result;
226 liveuser 2842
 
3 liveuser 2843
			}#if end
226 liveuser 2844
 
3 liveuser 2845
		#檢查使用者是否存在
2846
		#函式說明:
2847
		#呼叫shell執行系統命令,並取得回傳的內容.
2848
		#回傳的結果:
2849
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2850
		#$result["error"],錯誤訊息陣列.
2851
		#$result["function"],當前執行的函數名稱.
2852
		#$result["cmd"],執行的指令內容.
2853
		#$result["output"],爲執行完二元碼後的輸出陣列.
2854
		#必填的參數
2855
		#$conf["command"],字串,要執行的指令與.
2856
		$conf["external::callShell"]["command"]="id";
2857
		#可省略參數:
2858
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
2859
		$conf["external::callShell"]["argu"]=array($conf["username"]);
2860
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2861
		#$conf["enablePrintDescription"]="true";
2862
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
2863
		#$conf["printDescription"]="";
2864
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
2865
		#$conf["escapeshellarg"]="false";
2866
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
2867
		#$conf["external::callShell"]["username"]="";
2868
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
2869
		#$conf["external::callShell"]["password"]="";
2870
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
2871
		$conf["external::callShell"]["useScript"]="true";
2872
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
2873
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
2874
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
2875
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2876
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
2877
		#備註:
2878
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
2879
		#參考資料:
2880
		#exec=>http://php.net/manual/en/function.exec.php
2881
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2882
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2883
		$callShell=external::callShell($conf["external::callShell"]);
2884
		unset($conf["external::callShell"]);
226 liveuser 2885
 
3 liveuser 2886
		#如果執行shell失敗
66 liveuser 2887
		if($callShell["status"]==="false"){
226 liveuser 2888
 
3 liveuser 2889
			#設置執行不正常
2890
			$result["status"]="false";
226 liveuser 2891
 
3 liveuser 2892
			#設置執行錯誤
2893
			$result["error"]=$callShell;
226 liveuser 2894
 
3 liveuser 2895
			#回傳結果
2896
			return $result;
226 liveuser 2897
 
3 liveuser 2898
			}#if end
226 liveuser 2899
 
3 liveuser 2900
		#如果使用者 $conf["username"] 不存在
66 liveuser 2901
		if($callShell["output"][0]==="id: ".$conf["username"].": no such user"){
226 liveuser 2902
 
3 liveuser 2903
			#設置執行不正常
2904
			$result["status"]="true";
226 liveuser 2905
 
3 liveuser 2906
			#設置使用者驗證失敗
2907
			$result["valid"]="false";
226 liveuser 2908
 
3 liveuser 2909
			#設置使用者不存在的警告
2910
			$result["warninig"][]="使用者 \"".$conf["username"]."\" 不存在!";
226 liveuser 2911
 
3 liveuser 2912
			#回傳結果
2913
			return $result;
226 liveuser 2914
 
3 liveuser 2915
			}#if end
226 liveuser 2916
 
66 liveuser 2917
		#如果要用ssh private key進行認證
2918
		if($conf["sshPrivateKey"]==="true"){
226 liveuser 2919
 
66 liveuser 2920
			#可以用 echo "env | grep SSH_CONNECTION=" | ssh username@127.0.0.1 來驗證使用者的ssh連線是否成功
226 liveuser 2921
 
66 liveuser 2922
			#預設用來測試ssh private key 與 username 是否可成功登入的賬戶
2923
			$sshAgentAcct="qbpwcf";
226 liveuser 2924
 
66 liveuser 2925
			#確認用來測試登入ssh的使用者qbpwcf存在
2926
			#檢查使用者是否存在
2927
			#函式說明:
2928
			#呼叫shell執行系統命令,並取得回傳的內容.
2929
			#回傳的結果:
2930
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2931
			#$result["error"],錯誤訊息陣列.
2932
			#$result["function"],當前執行的函數名稱.
2933
			#$result["cmd"],執行的指令內容.
2934
			#$result["output"],爲執行完二元碼後的輸出陣列.
2935
			#必填的參數
2936
			#$conf["command"],字串,要執行的指令與.
2937
			$conf["external::callShell"]["command"]="id";
2938
			#可省略參數:
2939
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
2940
			$conf["external::callShell"]["argu"]=array($sshAgentAcct);
2941
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2942
			#$conf["enablePrintDescription"]="true";
2943
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
2944
			#$conf["printDescription"]="";
2945
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
2946
			#$conf["escapeshellarg"]="false";
2947
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
2948
			#$conf["external::callShell"]["username"]="";
2949
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
2950
			#$conf["external::callShell"]["password"]="";
2951
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
2952
			$conf["external::callShell"]["useScript"]="true";
2953
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
2954
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
2955
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
2956
			#$conf["fileArgu"],字串,變數__FILE__的內容.
2957
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
2958
			#備註:
2959
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
2960
			#參考資料:
2961
			#exec=>http://php.net/manual/en/function.exec.php
2962
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2963
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2964
			$callShell=external::callShell($conf["external::callShell"]);
2965
			unset($conf["external::callShell"]);
226 liveuser 2966
 
66 liveuser 2967
			#如果執行shell失敗
2968
			if($callShell["status"]==="false"){
226 liveuser 2969
 
66 liveuser 2970
				#設置執行不正常
2971
				$result["status"]="false";
226 liveuser 2972
 
66 liveuser 2973
				#設置執行錯誤
2974
				$result["error"]=$callShell;
226 liveuser 2975
 
66 liveuser 2976
				#回傳結果
2977
				return $result;
226 liveuser 2978
 
66 liveuser 2979
				}#if end
226 liveuser 2980
 
66 liveuser 2981
			#另外儲存存放ssh使用者設定的目錄
2982
			$dotsshFolderOfsshAgent="/home/".$sshAgentAcct."/.ssh";
226 liveuser 2983
 
66 liveuser 2984
			#如果使用者 $sshAgentAcct 不存在
2985
			if($callShell["output"][0]==="id: ".$sshAgentAcct.": no such user"){
226 liveuser 2986
 
66 liveuser 2987
				#透過 qbpwcf-usock.service 服務建立對應的使用者
2988
				#函式說明:
2989
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
2990
				#回傳結果:
2991
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
2992
				#$result["error"],錯誤訊息陣列.
2993
				#$result["function"],當前執行的函式名稱.
2994
				#$result["argu"],使用的參數.
2995
				#$result["content"],執行完指令的結果.
2996
				#必填參數:
2997
				#$conf["fileArgu"],字串,變數__FILE__的內容.
2998
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
2999
				#$conf["command"],字串,要執行的指令名稱.
3000
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="useradd";
3001
				#可省略參數:
3002
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3003
				#$conf["sock"]=qbpwcf_usock_path;
3004
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3005
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshAgentAcct);
3006
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3007
				#$conf["commandIncludeArgu"]="false";
3008
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3009
				#$conf["commandInBg"]="false";
3010
				#參考資料:
3011
				#無.
3012
				#備註:
3013
				#無.
3014
				$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3015
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3016
 
66 liveuser 3017
				#如果執行shell失敗
3018
				if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
226 liveuser 3019
 
66 liveuser 3020
					#設置執行不正常
3021
					$result["status"]="false";
226 liveuser 3022
 
66 liveuser 3023
					#設置執行錯誤
3024
					$result["error"]=$execAnyCmdByQBPWCFunixSocket;
226 liveuser 3025
 
66 liveuser 3026
					#回傳結果
3027
					return $result;
226 liveuser 3028
 
66 liveuser 3029
					}#if end
226 liveuser 3030
 
3031
				#透過 qbpwcf-usock.service 服務建立設置對應使用者的 .ssh 目錄
66 liveuser 3032
				#函式說明:
3033
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3034
				#回傳結果:
3035
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3036
				#$result["error"],錯誤訊息陣列.
3037
				#$result["function"],當前執行的函式名稱.
3038
				#$result["argu"],使用的參數.
3039
				#$result["content"],執行完指令的結果.
3040
				#必填參數:
3041
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3042
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3043
				#$conf["command"],字串,要執行的指令名稱.
3044
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="mkdir";
3045
				#可省略參數:
3046
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3047
				#$conf["sock"]=qbpwcf_usock_path;
3048
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3049
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($dotsshFolderOfsshAgent);
3050
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3051
				#$conf["commandIncludeArgu"]="false";
3052
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3053
				#$conf["commandInBg"]="false";
3054
				#參考資料:
3055
				#無.
3056
				#備註:
3057
				#無.
3058
				$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3059
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3060
 
66 liveuser 3061
				#如果執行shell失敗
3062
				if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
226 liveuser 3063
 
66 liveuser 3064
					#設置執行不正常
3065
					$result["status"]="false";
226 liveuser 3066
 
66 liveuser 3067
					#設置執行錯誤
3068
					$result["error"]=$execAnyCmdByQBPWCFunixSocket;
226 liveuser 3069
 
66 liveuser 3070
					#回傳結果
3071
					return $result;
226 liveuser 3072
 
66 liveuser 3073
					}#if end
226 liveuser 3074
 
66 liveuser 3075
				}#if end
226 liveuser 3076
 
66 liveuser 3077
			#確認 ssh 使用者設定的目錄 $dotsshFolderOfsshAgent 是否存在
3078
			#函式說明:
3079
			#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3080
			#回傳結果:
3081
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3082
			#$result["error"],錯誤訊息陣列.
3083
			#$result["function"],當前執行的函式名稱.
3084
			#$result["argu"],使用的參數.
3085
			#$result["content"],執行完指令的結果.
3086
			#必填參數:
3087
			#$conf["fileArgu"],字串,變數__FILE__的內容.
3088
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3089
			#$conf["command"],字串,要執行的指令名稱.
3090
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="checkNodeExist.php";
3091
			#可省略參數:
3092
			#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3093
			#$conf["sock"]=qbpwcf_usock_path;
3094
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3095
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($dotsshFolderOfsshAgent);
3096
			#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3097
			#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3098
			#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3099
			#$conf["commandInBg"]="false";
3100
			#參考資料:
3101
			#無.
3102
			#備註:
3103
			#無.
3104
			$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3105
			unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3106
 
66 liveuser 3107
			#如果執行shell失敗
3108
			if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
226 liveuser 3109
 
66 liveuser 3110
				#設置執行不正常
3111
				$result["status"]="false";
226 liveuser 3112
 
66 liveuser 3113
				#設置執行錯誤
3114
				$result["error"]=$execAnyCmdByQBPWCFunixSocket;
226 liveuser 3115
 
66 liveuser 3116
				#回傳結果
3117
				return $result;
226 liveuser 3118
 
66 liveuser 3119
				}#if end
226 liveuser 3120
 
66 liveuser 3121
			#如果得到的結果不為 json
3122
			if(!json_validate($execAnyCmdByQBPWCFunixSocket["content"])){
226 liveuser 3123
 
66 liveuser 3124
				#設置執行不正常
3125
				$result["status"]="false";
226 liveuser 3126
 
66 liveuser 3127
				#設置執行錯誤
3128
				$result["error"]=$execAnyCmdByQBPWCFunixSocket;
226 liveuser 3129
 
66 liveuser 3130
				#回傳結果
3131
				return $result;
226 liveuser 3132
 
66 liveuser 3133
				}#if end
226 liveuser 3134
 
66 liveuser 3135
			#解析 json 並轉換成 array
3136
			$execAnyCmdByQBPWCFunixSocket["content"]=(array)(json_decode($execAnyCmdByQBPWCFunixSocket["content"]));
226 liveuser 3137
 
66 liveuser 3138
			#如果沒有找到要存在的 $dotsshFolderOfsshAgent 目錄
3139
			if(count($execAnyCmdByQBPWCFunixSocket["content"])===0){
226 liveuser 3140
 
66 liveuser 3141
				#建立之
3142
				#函式說明:
3143
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3144
				#回傳結果:
3145
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3146
				#$result["error"],錯誤訊息陣列.
3147
				#$result["function"],當前執行的函式名稱.
3148
				#$result["argu"],使用的參數.
3149
				#$result["content"],執行完指令的結果.
3150
				#必填參數:
3151
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3152
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3153
				#$conf["command"],字串,要執行的指令名稱.
3154
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="mkdir";
3155
				#可省略參數:
3156
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3157
				#$conf["sock"]=qbpwcf_usock_path;
3158
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3159
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("-p",$dotsshFolderOfsshAgent);
3160
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3161
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3162
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3163
				#$conf["commandInBg"]="false";
3164
				#參考資料:
3165
				#無.
3166
				#備註:
3167
				#無.
3168
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3169
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3170
 
66 liveuser 3171
				#如果執行shell失敗
3172
				if($createDotsshFolderOfsshAgent["status"]==="false"){
226 liveuser 3173
 
66 liveuser 3174
					#設置執行不正常
3175
					$result["status"]="false";
226 liveuser 3176
 
66 liveuser 3177
					#設置執行錯誤
3178
					$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3179
 
66 liveuser 3180
					#回傳結果
3181
					return $result;
226 liveuser 3182
 
66 liveuser 3183
					}#if end
226 liveuser 3184
 
66 liveuser 3185
				}#if end
226 liveuser 3186
 
66 liveuser 3187
			#如果沒有找到要存在的 $dotsshFolderOfsshAgent 目錄
3188
			else if($execAnyCmdByQBPWCFunixSocket[0]!==$dotsshFolderOfsshAgent){
226 liveuser 3189
 
66 liveuser 3190
				#建立之
3191
				#函式說明:
3192
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3193
				#回傳結果:
3194
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3195
				#$result["error"],錯誤訊息陣列.
3196
				#$result["function"],當前執行的函式名稱.
3197
				#$result["argu"],使用的參數.
3198
				#$result["content"],執行完指令的結果.
3199
				#必填參數:
3200
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3201
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3202
				#$conf["command"],字串,要執行的指令名稱.
3203
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="mkdir";
3204
				#可省略參數:
3205
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3206
				#$conf["sock"]=qbpwcf_usock_path;
3207
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3208
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("-p",$dotsshFolderOfsshAgent);
3209
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3210
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3211
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3212
				#$conf["commandInBg"]="false";
3213
				#參考資料:
3214
				#無.
3215
				#備註:
3216
				#無.
3217
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3218
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3219
 
66 liveuser 3220
				#如果執行shell失敗
3221
				if($createDotsshFolderOfsshAgent["status"]==="false"){
226 liveuser 3222
 
66 liveuser 3223
					#設置執行不正常
3224
					$result["status"]="false";
226 liveuser 3225
 
66 liveuser 3226
					#設置執行錯誤
3227
					$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3228
 
66 liveuser 3229
					#回傳結果
3230
					return $result;
226 liveuser 3231
 
66 liveuser 3232
					}#if end
226 liveuser 3233
 
66 liveuser 3234
				}#if end
226 liveuser 3235
 
66 liveuser 3236
			#取得 $dotsshFolderOfsshAgent 的權限與擁有着
3237
			#函式說明:
3238
			#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3239
			#回傳結果:
3240
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3241
			#$result["error"],錯誤訊息陣列.
3242
			#$result["function"],當前執行的函式名稱.
3243
			#$result["argu"],使用的參數.
3244
			#$result["content"],執行完指令的結果.
3245
			#必填參數:
3246
			#$conf["fileArgu"],字串,變數__FILE__的內容.
3247
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3248
			#$conf["command"],字串,要執行的指令名稱.
3249
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="getNodeInfo.php";
3250
			#可省略參數:
3251
			#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3252
			#$conf["sock"]=qbpwcf_usock_path;
3253
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3254
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("--node",$dotsshFolderOfsshAgent);
3255
			#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3256
			#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3257
			#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3258
			#$conf["commandInBg"]="false";
3259
			#參考資料:
3260
			#無.
3261
			#備註:
3262
			#無.
3263
			$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3264
			unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3265
 
66 liveuser 3266
			#如果執行shell失敗
3267
			if($createDotsshFolderOfsshAgent["status"]==="false"){
226 liveuser 3268
 
66 liveuser 3269
				#設置執行不正常
3270
				$result["status"]="false";
226 liveuser 3271
 
66 liveuser 3272
				#設置執行錯誤
3273
				$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3274
 
66 liveuser 3275
				#回傳結果
3276
				return $result;
226 liveuser 3277
 
66 liveuser 3278
				}#if end
226 liveuser 3279
 
66 liveuser 3280
			#如果執行異常
3281
			if($createDotsshFolderOfsshAgent["status"]==="false"){
226 liveuser 3282
 
66 liveuser 3283
				#設置執行不正常
3284
				$result["status"]="false";
226 liveuser 3285
 
66 liveuser 3286
				#設置執行錯誤
3287
				$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3288
 
66 liveuser 3289
				#回傳結果
3290
				return $result;
226 liveuser 3291
 
66 liveuser 3292
				}#if end
226 liveuser 3293
 
66 liveuser 3294
			#如果沒有得到輸出
3295
			if(!isset($createDotsshFolderOfsshAgent["content"][0])){
226 liveuser 3296
 
66 liveuser 3297
				#設置執行不正常
3298
				$result["status"]="false";
226 liveuser 3299
 
66 liveuser 3300
				#設置執行錯誤
3301
				$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3302
 
66 liveuser 3303
				#回傳結果
3304
				return $result;
226 liveuser 3305
 
66 liveuser 3306
				}#if end
226 liveuser 3307
 
66 liveuser 3308
			#如果輸出結果不是json
3309
			if(!json_validate($createDotsshFolderOfsshAgent["content"][0])){
226 liveuser 3310
 
66 liveuser 3311
				#設置執行不正常
3312
				$result["status"]="false";
226 liveuser 3313
 
66 liveuser 3314
				#設置執行錯誤
3315
				$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3316
 
66 liveuser 3317
				#回傳結果
3318
				return $result;
226 liveuser 3319
 
66 liveuser 3320
				}#if end
226 liveuser 3321
 
66 liveuser 3322
			#解析json
3323
			$node_info=json_decode($createDotsshFolderOfsshAgent["content"][0]);
226 liveuser 3324
 
66 liveuser 3325
			#若 $dotsshFolderOfsshAgent 的權限,不為 "rwx------"
3326
			if($node_info->ownerPerm!=="rwx" || $node_info->groupPerm!=="---" || $node_info->otherPerm!=="---"){
226 liveuser 3327
 
66 liveuser 3328
				#更新其權限設置
3329
				#函式說明:
3330
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3331
				#回傳結果:
3332
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3333
				#$result["error"],錯誤訊息陣列.
3334
				#$result["function"],當前執行的函式名稱.
3335
				#$result["argu"],使用的參數.
3336
				#$result["content"],執行完指令的結果.
3337
				#必填參數:
3338
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3339
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3340
				#$conf["command"],字串,要執行的指令名稱.
3341
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chmod";
3342
				#可省略參數:
3343
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3344
				#$conf["sock"]=qbpwcf_usock_path;
3345
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3346
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("700",$dotsshFolderOfsshAgent);
3347
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3348
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3349
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3350
				#$conf["commandInBg"]="false";
3351
				#參考資料:
3352
				#無.
3353
				#備註:
3354
				#無.
3355
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3356
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3357
 
66 liveuser 3358
				#如果執行shell失敗
3359
				if($createDotsshFolderOfsshAgent["status"]==="false"){
226 liveuser 3360
 
66 liveuser 3361
					#設置執行不正常
3362
					$result["status"]="false";
226 liveuser 3363
 
66 liveuser 3364
					#設置執行錯誤
3365
					$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3366
 
66 liveuser 3367
					#回傳結果
3368
					return $result;
226 liveuser 3369
 
66 liveuser 3370
					}#if end
226 liveuser 3371
 
66 liveuser 3372
				}#if end
226 liveuser 3373
 
66 liveuser 3374
			#若 $dotsshFolderOfsshAgent 的擁有着不為 $sshAgentAcct:$sshAgentAcct
3375
			if($node_info->ownerName!==$sshAgentAcct || $node_info->groupName!==$sshAgentAcct){
226 liveuser 3376
 
66 liveuser 3377
				#更新其擁有着設置
3378
				#函式說明:
3379
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3380
				#回傳結果:
3381
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3382
				#$result["error"],錯誤訊息陣列.
3383
				#$result["function"],當前執行的函式名稱.
3384
				#$result["argu"],使用的參數.
3385
				#$result["content"],執行完指令的結果.
3386
				#必填參數:
3387
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3388
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3389
				#$conf["command"],字串,要執行的指令名稱.
3390
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chown";
3391
				#可省略參數:
3392
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3393
				#$conf["sock"]=qbpwcf_usock_path;
3394
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3395
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshAgentAcct.":".$sshAgentAcct,$dotsshFolderOfsshAgent);
3396
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3397
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3398
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3399
				#$conf["commandInBg"]="false";
3400
				#參考資料:
3401
				#無.
3402
				#備註:
3403
				#無.
3404
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3405
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3406
 
66 liveuser 3407
				#如果執行shell失敗
3408
				if($createDotsshFolderOfsshAgent["status"]==="false"){
226 liveuser 3409
 
66 liveuser 3410
					#設置執行不正常
3411
					$result["status"]="false";
226 liveuser 3412
 
66 liveuser 3413
					#設置執行錯誤
3414
					$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3415
 
66 liveuser 3416
					#回傳結果
3417
					return $result;
226 liveuser 3418
 
66 liveuser 3419
					}#if end
226 liveuser 3420
 
66 liveuser 3421
				}#if end
226 liveuser 3422
 
66 liveuser 3423
			#設置要使用的ssh private key
3424
			#函式說明:
3425
			#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3426
			#回傳結果:
3427
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3428
			#$result["error"],錯誤訊息陣列.
3429
			#$result["function"],當前執行的函式名稱.
3430
			#$result["argu"],使用的參數.
3431
			#$result["content"],執行完指令的結果.
3432
			#必填參數:
3433
			#$conf["fileArgu"],字串,變數__FILE__的內容.
3434
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3435
			#$conf["command"],字串,要執行的指令名稱.
3436
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="echo";
3437
			#可省略參數:
3438
			#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3439
			#$conf["sock"]=qbpwcf_usock_path;
3440
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3441
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshPrivateKeyContent,">",$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName);
3442
			#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3443
			#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3444
			#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3445
			#$conf["commandInBg"]="false";
3446
			#參考資料:
3447
			#無.
3448
			#備註:
3449
			#無.
3450
			$createSshPrivateKey=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3451
			unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3452
 
66 liveuser 3453
			#如果執行shell失敗
3454
			if($createSshPrivateKey["status"]==="false"){
226 liveuser 3455
 
66 liveuser 3456
				#設置執行不正常
3457
				$result["status"]="false";
226 liveuser 3458
 
66 liveuser 3459
				#設置執行錯誤
3460
				$result["error"]=$createSshPrivateKey;
226 liveuser 3461
 
66 liveuser 3462
				#回傳結果
3463
				return $result;
226 liveuser 3464
 
66 liveuser 3465
				}#if end
226 liveuser 3466
 
66 liveuser 3467
			#取得 ssh privacy key 檔案的權限與擁有着
3468
			#函式說明:
3469
			#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3470
			#回傳結果:
3471
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3472
			#$result["error"],錯誤訊息陣列.
3473
			#$result["function"],當前執行的函式名稱.
3474
			#$result["argu"],使用的參數.
3475
			#$result["content"],執行完指令的結果.
3476
			#必填參數:
3477
			#$conf["fileArgu"],字串,變數__FILE__的內容.
3478
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3479
			#$conf["command"],字串,要執行的指令名稱.
3480
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="getNodeInfo.php";
3481
			#可省略參數:
3482
			#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3483
			#$conf["sock"]=qbpwcf_usock_path;
3484
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3485
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("--node",$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName);
3486
			#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3487
			#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3488
			#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3489
			#$conf["commandInBg"]="false";
3490
			#參考資料:
3491
			#無.
3492
			#備註:
3493
			#無.
3494
			$getSshPrivateKeyFileInfo=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3495
			unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3496
 
66 liveuser 3497
			#如果執行shell失敗
3498
			if($getSshPrivateKeyFileInfo["status"]==="false"){
226 liveuser 3499
 
66 liveuser 3500
				#設置執行不正常
3501
				$result["status"]="false";
226 liveuser 3502
 
66 liveuser 3503
				#設置執行錯誤
3504
				$result["error"]=$getSshPrivateKeyFileInfo;
226 liveuser 3505
 
66 liveuser 3506
				#回傳結果
3507
				return $result;
226 liveuser 3508
 
66 liveuser 3509
				}#if end
226 liveuser 3510
 
66 liveuser 3511
			#如果執行異常
3512
			if($createDotsshFolderOfsshAgent["status"]==="false"){
226 liveuser 3513
 
66 liveuser 3514
				#設置執行不正常
3515
				$result["status"]="false";
226 liveuser 3516
 
66 liveuser 3517
				#設置執行錯誤
3518
				$result["error"]=$getSshPrivateKeyFileInfo;
226 liveuser 3519
 
66 liveuser 3520
				#回傳結果
3521
				return $result;
226 liveuser 3522
 
66 liveuser 3523
				}#if end
226 liveuser 3524
 
66 liveuser 3525
			#如果沒有得到輸出
3526
			if(!isset($createDotsshFolderOfsshAgent["content"][0])){
226 liveuser 3527
 
66 liveuser 3528
				#設置執行不正常
3529
				$result["status"]="false";
226 liveuser 3530
 
66 liveuser 3531
				#設置執行錯誤
3532
				$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3533
 
66 liveuser 3534
				#回傳結果
3535
				return $result;
226 liveuser 3536
 
66 liveuser 3537
				}#if end
226 liveuser 3538
 
66 liveuser 3539
			#如果輸出結果不是json
3540
			if(!json_validate($createDotsshFolderOfsshAgent["content"][0])){
226 liveuser 3541
 
66 liveuser 3542
				#設置執行不正常
3543
				$result["status"]="false";
226 liveuser 3544
 
66 liveuser 3545
				#設置執行錯誤
3546
				$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3547
 
66 liveuser 3548
				#回傳結果
3549
				return $result;
226 liveuser 3550
 
66 liveuser 3551
				}#if end
226 liveuser 3552
 
66 liveuser 3553
			#解析json
3554
			$node_info=json_decode($createDotsshFolderOfsshAgent["content"][0]);
226 liveuser 3555
 
66 liveuser 3556
			#若 ssh privacy key 檔案的擁有着不為 $sshAgentAcct:$sshAgentAcct
3557
			if($node_info->ownerName!==$sshAgentAcct || $node_info->groupName!==$sshAgentAcct){
226 liveuser 3558
 
66 liveuser 3559
				#更新 ssh privacy key 的檔案擁有者
3560
				#函式說明:
3561
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3562
				#回傳結果:
3563
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3564
				#$result["error"],錯誤訊息陣列.
3565
				#$result["function"],當前執行的函式名稱.
3566
				#$result["argu"],使用的參數.
3567
				#$result["content"],執行完指令的結果.
3568
				#必填參數:
3569
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3570
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3571
				#$conf["command"],字串,要執行的指令名稱.
3572
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chmod";
3573
				#可省略參數:
3574
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3575
				#$conf["sock"]=qbpwcf_usock_path;
3576
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3577
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("700",$dotsshFolderOfsshAgent);
3578
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3579
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3580
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3581
				#$conf["commandInBg"]="false";
3582
				#參考資料:
3583
				#無.
3584
				#備註:
3585
				#無.
3586
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3587
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3588
 
66 liveuser 3589
				#如果執行shell失敗
3590
				if($createDotsshFolderOfsshAgent["status"]==="false"){
226 liveuser 3591
 
66 liveuser 3592
					#設置執行不正常
3593
					$result["status"]="false";
226 liveuser 3594
 
66 liveuser 3595
					#設置執行錯誤
3596
					$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3597
 
66 liveuser 3598
					#回傳結果
3599
					return $result;
226 liveuser 3600
 
66 liveuser 3601
					}#if end
226 liveuser 3602
 
66 liveuser 3603
				}#if end
226 liveuser 3604
 
66 liveuser 3605
			#若 ssh privacy key 檔案的權限不為 "rw-------"
3606
			if($node_info->ownerPerm!=="rw-" || $node_info->groupPerm!=="---" || $node_info->otherPerm!=="---"){
226 liveuser 3607
 
66 liveuser 3608
				#更新 ssh privacy key 的檔案擁有者
3609
				#函式說明:
3610
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3611
				#回傳結果:
3612
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3613
				#$result["error"],錯誤訊息陣列.
3614
				#$result["function"],當前執行的函式名稱.
3615
				#$result["argu"],使用的參數.
3616
				#$result["content"],執行完指令的結果.
3617
				#必填參數:
3618
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3619
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3620
				#$conf["command"],字串,要執行的指令名稱.
3621
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chown";
3622
				#可省略參數:
3623
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3624
				#$conf["sock"]=qbpwcf_usock_path;
3625
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3626
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshAgentAcct.":".$sshAgentAcct,$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName);
3627
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3628
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3629
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3630
				#$conf["commandInBg"]="false";
3631
				#參考資料:
3632
				#無.
3633
				#備註:
3634
				#無.
3635
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3636
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3637
 
66 liveuser 3638
				#如果執行shell失敗
3639
				if($createDotsshFolderOfsshAgent["status"]==="false"){
226 liveuser 3640
 
66 liveuser 3641
					#設置執行不正常
3642
					$result["status"]="false";
226 liveuser 3643
 
66 liveuser 3644
					#設置執行錯誤
3645
					$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3646
 
66 liveuser 3647
					#回傳結果
3648
					return $result;
226 liveuser 3649
 
66 liveuser 3650
					}#if end
226 liveuser 3651
 
66 liveuser 3652
				}#if end
226 liveuser 3653
 
66 liveuser 3654
			#嘗試進行連線,並確認是否成功
3655
			#函式說明:
3656
			#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3657
			#回傳結果:
3658
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3659
			#$result["error"],錯誤訊息陣列.
3660
			#$result["function"],當前執行的函式名稱.
3661
			#$result["argu"],使用的參數.
3662
			#$result["content"],執行完指令的結果.
3663
			#必填參數:
3664
			#$conf["fileArgu"],字串,變數__FILE__的內容.
3665
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3666
			#$conf["command"],字串,要執行的指令名稱.
3667
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="echo";
3668
			#可省略參數:
3669
			#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3670
			#$conf["sock"]=qbpwcf_usock_path;
3671
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3672
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("env","|","ssh",$sshAgentAcct."@"."127.0.0.1","-i",$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName,"|","grep","SSH_CLIENT=127.0.0.1","|","wc","-l");
3673
			#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3674
			#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
3675
			#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3676
			#$conf["commandInBg"]="false";
3677
			#參考資料:
3678
			#無.
3679
			#備註:
3680
			#無.
3681
			$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3682
			unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
226 liveuser 3683
 
66 liveuser 3684
			#如果執行shell失敗
3685
			if($createDotsshFolderOfsshAgent["status"]==="false"){
226 liveuser 3686
 
66 liveuser 3687
				#設置執行不正常
3688
				$result["status"]="false";
226 liveuser 3689
 
66 liveuser 3690
				#設置執行錯誤
3691
				$result["error"]=$createDotsshFolderOfsshAgent;
226 liveuser 3692
 
66 liveuser 3693
				#回傳結果
3694
				return $result;
226 liveuser 3695
 
66 liveuser 3696
				}#if end
226 liveuser 3697
 
66 liveuser 3698
			#若得到的輸出未含有ssh登入的資訊(SSH_CLIENT=127.0.0.1 ...)
3699
			if($createDotsshFolderOfsshAgent["content"]!=="1"){
226 liveuser 3700
 
66 liveuser 3701
				#設置執行正常
3702
				$result["status"]="true";
226 liveuser 3703
 
66 liveuser 3704
				#設置使用者驗證失敗
3705
				$result["valid"]="false";
226 liveuser 3706
 
66 liveuser 3707
				#設置使用者不存在的警告
3708
				$result["warning"][]="使用者 \"".$conf["username"]."\"可能不存在或無法被ssh登入!";
226 liveuser 3709
 
66 liveuser 3710
				#回傳結果
3711
				return $result;
226 liveuser 3712
 
66 liveuser 3713
				}#if end
226 liveuser 3714
 
66 liveuser 3715
			#設置執行正常
3 liveuser 3716
			$result["status"]="true";
226 liveuser 3717
 
66 liveuser 3718
			#設置使用者驗證正常
3719
			$result["valid"]="true";
226 liveuser 3720
 
3 liveuser 3721
			#回傳結果
3722
			return $result;
226 liveuser 3723
 
3 liveuser 3724
			}#if end
226 liveuser 3725
 
3 liveuser 3726
		#反之
66 liveuser 3727
		else{
226 liveuser 3728
 
66 liveuser 3729
			#可以用 echo 'password' | su username -c 'echo valid' 來檢查使用者密碼是否正確
3730
			#檢查使用者是否存在
3731
			#函式說明:
3732
			#呼叫shell執行系統命令,並取得回傳的內容.
3733
			#回傳的結果:
3734
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3735
			#$result["error"],錯誤訊息陣列.
3736
			#$result["function"],當前執行的函數名稱.
3737
			#$result["cmd"],執行的指令內容.
3738
			#$result["output"],爲執行完二元碼後的輸出陣列.
3739
			#必填的參數
3740
			#$conf["command"],字串,要執行的指令與.
3741
			$conf["external::callShell"]["command"]="echo";
3742
			#可省略參數:
3743
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3744
			$conf["external::callShell"]["argu"]=array($conf["password"],"|","su",$conf["username"],"-c","echo valid");
3745
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3746
			#$conf["enablePrintDescription"]="true";
3747
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
3748
			#$conf["printDescription"]="";
3749
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
3750
			#$conf["escapeshellarg"]="false";
3751
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
3752
			#$conf["external::callShell"]["username"]="";
3753
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
3754
			#$conf["external::callShell"]["password"]="";
3755
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
3756
			$conf["external::callShell"]["useScript"]="true";
3757
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
3758
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3759
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
3760
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3761
			#備註:
3762
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
3763
			#參考資料:
3764
			#exec=>http://php.net/manual/en/function.exec.php
3765
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3766
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3767
			$callShell=external::callShell($conf["external::callShell"]);
3768
			unset($conf["external::callShell"]);
226 liveuser 3769
 
66 liveuser 3770
			#如果執行shell失敗
3771
			if($callShell["status"]==="false"){
226 liveuser 3772
 
66 liveuser 3773
				#設置執行不正常
3774
				$result["status"]="false";
226 liveuser 3775
 
66 liveuser 3776
				#設置執行錯誤
3777
				$result["error"]=$callShell;
226 liveuser 3778
 
66 liveuser 3779
				#回傳結果
3780
				return $result;
226 liveuser 3781
 
66 liveuser 3782
				}#if end
226 liveuser 3783
 
66 liveuser 3784
			#範例輸出:
3785
			#Script started on Sat 05 Nov 2016 06:08:31 PM CST
3786
			#Password: valid
226 liveuser 3787
 
66 liveuser 3788
			#如果輸出 "valid"
3789
			if($callShell["output"][1]=="Password: valid"){
226 liveuser 3790
 
66 liveuser 3791
				#代表使用者密碼正確
226 liveuser 3792
 
66 liveuser 3793
				#設置執行正常
3794
				$result["status"]="true";
226 liveuser 3795
 
66 liveuser 3796
				#設置使用者驗證失敗
3797
				$result["valid"]="true";
226 liveuser 3798
 
66 liveuser 3799
				#回傳結果
3800
				return $result;
226 liveuser 3801
 
66 liveuser 3802
				}#if end
226 liveuser 3803
 
66 liveuser 3804
			#反之如果是
3805
			else if($callShell["output"][1]==="Password: su: Authentication failure"){
226 liveuser 3806
 
66 liveuser 3807
				#代表使用者密碼不正確
3808
				$result["status"]="true";
226 liveuser 3809
 
66 liveuser 3810
				#設置使用者驗證失敗
3811
				$result["valid"]="false";
226 liveuser 3812
 
66 liveuser 3813
				#設置使用者不存在的警告
3814
				$result["warning"][]="使用者 \"".$conf["username"]."\" 的密碼不為 \"".$conf["password"]."\" !";
226 liveuser 3815
 
66 liveuser 3816
				#回傳結果
3817
				return $result;
226 liveuser 3818
 
66 liveuser 3819
				}#if end
226 liveuser 3820
 
66 liveuser 3821
			#反之
3822
			else{
226 liveuser 3823
 
66 liveuser 3824
				#設置執行不正常
3825
				$result["status"]="false";
226 liveuser 3826
 
66 liveuser 3827
				#設置錯誤訊息
3828
				$result["error"][]="非預期的輸出結果!";
226 liveuser 3829
 
66 liveuser 3830
				#設置錯誤訊息
3831
				$result["error"][]=$callShell;
226 liveuser 3832
 
66 liveuser 3833
				#回傳結果
3834
				return $result;
226 liveuser 3835
 
66 liveuser 3836
				}#else end
226 liveuser 3837
 
3 liveuser 3838
			}#else end
226 liveuser 3839
 
3 liveuser 3840
		#設置執行不正常
3841
		$result["status"]="false";
226 liveuser 3842
 
3 liveuser 3843
		#設置錯誤訊息
66 liveuser 3844
		$result["error"][]="非預期的結果!";
226 liveuser 3845
 
3 liveuser 3846
		#回傳結果
3847
		return $result;
226 liveuser 3848
 
3 liveuser 3849
		}#function validUser end
226 liveuser 3850
 
3 liveuser 3851
	/*
3852
	#函式說明:
226 liveuser 3853
	#用php的password_hash方法來單向加密密碼.
3 liveuser 3854
	#回傳結果:
3855
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3856
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
3857
	#$result["function"],當前執行的函式名稱.
3858
	#$result["content"],呼叫完WebService所得回傳結果.
3859
	#必填參數:
3860
	#無
3861
	#可省略參數:
3862
	#$conf["password"],字串,要加密的密碼,預設為"qbpwcf".
3863
	#$conf["password"]="qbpwcf";
3864
	#參考資料:
3865
	#無.
3866
	#備註:
3867
	#無.
3868
	*/
3869
	public static function encodePassword(&$conf=array()){
226 liveuser 3870
 
3 liveuser 3871
		#初始化要回傳的結果
3872
		$result=array();
3873
 
3874
		#取得當前執行的函數名稱
3875
		$result["function"]=__FUNCTION__;
3876
 
3877
		#如果沒有參數
3878
		if(func_num_args()==0){
226 liveuser 3879
 
3 liveuser 3880
			#設置執行失敗
3881
			$result["status"]="false";
226 liveuser 3882
 
3 liveuser 3883
			#設置執行錯誤訊息
3884
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 3885
 
3 liveuser 3886
			#回傳結果
3887
			return $result;
226 liveuser 3888
 
3 liveuser 3889
			}#if end
226 liveuser 3890
 
3 liveuser 3891
		#取得參數
3892
		$result["argu"]=$conf;
3893
 
3894
		#如果 $conf 不為陣列
3895
		if(gettype($conf)!=="array"){
226 liveuser 3896
 
3 liveuser 3897
			#設置執行失敗
3898
			$result["status"]="false";
226 liveuser 3899
 
3 liveuser 3900
			#設置執行錯誤訊息
3901
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 3902
 
3 liveuser 3903
			#如果傳入的參數為 null
3904
			if($conf===null){
226 liveuser 3905
 
3 liveuser 3906
				#設置執行錯誤訊息
3907
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3908
 
3 liveuser 3909
				}#if end
3910
 
3911
			#回傳結果
3912
			return $result;
226 liveuser 3913
 
3 liveuser 3914
			}#if end
226 liveuser 3915
 
3 liveuser 3916
		#檢查參數
3917
		#函式說明:
3918
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3919
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3920
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3921
		#$result["function"],當前執行的函式名稱.
3922
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3923
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3924
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3925
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
3926
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
3927
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3928
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3929
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3930
		#必填寫的參數:
3931
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 3932
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 3933
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3934
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3935
		#可以省略的參數:
3936
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3937
		#$conf["mustBeFilledVariableName"]=array();
3938
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
3939
		#$conf["mustBeFilledVariableType"]=array();
3940
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3941
		#$conf["canBeEmptyString"]="false";
3942
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
3943
		#$conf["canNotBeEmpty"]=array();
3944
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
3945
		#$conf["canBeEmpty"]=array();
3946
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
3947
		#$conf["skipableVariableCanNotBeEmpty"]=array();
3948
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3949
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("password");
226 liveuser 3950
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3951
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
3952
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3953
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("qbpwcf");
3954
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
3955
		#$conf["disallowAllSkipableVarIsEmpty"]="";
3956
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
3957
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
3958
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3959
		#$conf["arrayCountEqualCheck"][]=array();
3960
		#參考資料來源:
3961
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3962
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3963
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3964
 
3 liveuser 3965
		#如果驗證失敗
3966
		if($checkArguments["status"]==="false"){
226 liveuser 3967
 
3 liveuser 3968
			#設置執行失敗
3969
			$result["status"]="false";
226 liveuser 3970
 
3 liveuser 3971
			#設置錯誤訊息
3972
			$result["error"]=$checkArguments;
226 liveuser 3973
 
3 liveuser 3974
			#回傳結果
3975
			return $result;
226 liveuser 3976
 
3 liveuser 3977
			}#if end
226 liveuser 3978
 
3 liveuser 3979
		#如果驗證不成功
3980
		if($checkArguments["passed"]==="false"){
226 liveuser 3981
 
3 liveuser 3982
			#設置執行失敗
3983
			$result["status"]="false";
226 liveuser 3984
 
3 liveuser 3985
			#設置錯誤訊息
3986
			$result["error"]=$checkArguments;
226 liveuser 3987
 
3 liveuser 3988
			#回傳結果
3989
			return $result;
226 liveuser 3990
 
3 liveuser 3991
			}#if end
226 liveuser 3992
 
3 liveuser 3993
		#取得加密好的密碼
3994
		$result["content"]=password_hash($conf["password"],PASSWORD_DEFAULT);
226 liveuser 3995
 
3 liveuser 3996
		#設置執行正常
3997
		$result["status"]="true";
226 liveuser 3998
 
3 liveuser 3999
		#回傳結果
4000
		return $result;
226 liveuser 4001
 
3 liveuser 4002
		}#function encodePassword end
226 liveuser 4003
 
3 liveuser 4004
	/*
4005
	#函式說明:
226 liveuser 4006
	#用php的password_verify方法來驗證密碼是否正確.
3 liveuser 4007
	#回傳結果:
4008
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4009
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
4010
	#$result["function"],當前執行的函式名稱.
4011
	#$result["content"],呼叫完WebService所得回傳結果.
4012
	#必填參數:
4013
	#$conf["input"],字串,要檢查是否正確的待驗證密碼.
4014
	$conf["input"]="";
4015
	#$conf["password"],字串,透過encodePassword加密後的密碼.
4016
	$conf["password"]="";
4017
	#可省略參數:
4018
	#無.
4019
	#參考資料:
4020
	#無.
4021
	#備註:
4022
	#無.
4023
	*/
4024
	public static function validPassword(&$conf=array()){
226 liveuser 4025
 
3 liveuser 4026
		#初始化要回傳的結果
4027
		$result=array();
4028
 
4029
		#取得當前執行的函數名稱
4030
		$result["function"]=__FUNCTION__;
4031
 
4032
		#如果沒有參數
4033
		if(func_num_args()==0){
226 liveuser 4034
 
3 liveuser 4035
			#設置執行失敗
4036
			$result["status"]="false";
226 liveuser 4037
 
3 liveuser 4038
			#設置執行錯誤訊息
4039
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 4040
 
3 liveuser 4041
			#回傳結果
4042
			return $result;
226 liveuser 4043
 
3 liveuser 4044
			}#if end
226 liveuser 4045
 
3 liveuser 4046
		#取得參數
4047
		$result["argu"]=$conf;
4048
 
4049
		#如果 $conf 不為陣列
4050
		if(gettype($conf)!=="array"){
226 liveuser 4051
 
3 liveuser 4052
			#設置執行失敗
4053
			$result["status"]="false";
226 liveuser 4054
 
3 liveuser 4055
			#設置執行錯誤訊息
4056
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 4057
 
3 liveuser 4058
			#如果傳入的參數為 null
4059
			if($conf===null){
226 liveuser 4060
 
3 liveuser 4061
				#設置執行錯誤訊息
4062
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4063
 
3 liveuser 4064
				}#if end
4065
 
4066
			#回傳結果
4067
			return $result;
226 liveuser 4068
 
3 liveuser 4069
			}#if end
226 liveuser 4070
 
3 liveuser 4071
		#檢查參數
4072
		#函式說明:
4073
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4074
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4075
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4076
		#$result["function"],當前執行的函式名稱.
4077
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4078
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4079
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4080
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4081
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4082
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4083
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4084
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4085
		#必填寫的參數:
4086
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 4087
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 4088
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4089
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4090
		#可以省略的參數:
4091
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4092
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input","password");
4093
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
4094
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
4095
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4096
		#$conf["canBeEmptyString"]="false";
4097
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
4098
		#$conf["canNotBeEmpty"]=array();
4099
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
4100
		#$conf["canBeEmpty"]=array();
4101
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
4102
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4103
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4104
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("password");
226 liveuser 4105
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4106
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4107
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4108
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("qbpwcf");
4109
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
4110
		#$conf["disallowAllSkipableVarIsEmpty"]="";
4111
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
4112
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
4113
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4114
		#$conf["arrayCountEqualCheck"][]=array();
4115
		#參考資料來源:
4116
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4117
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4118
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 4119
 
3 liveuser 4120
		#如果驗證失敗
4121
		if($checkArguments["status"]==="false"){
226 liveuser 4122
 
3 liveuser 4123
			#設置執行失敗
4124
			$result["status"]="false";
226 liveuser 4125
 
3 liveuser 4126
			#設置錯誤訊息
4127
			$result["error"]=$checkArguments;
226 liveuser 4128
 
3 liveuser 4129
			#回傳結果
4130
			return $result;
226 liveuser 4131
 
3 liveuser 4132
			}#if end
226 liveuser 4133
 
3 liveuser 4134
		#如果驗證不成功
4135
		if($checkArguments["passed"]==="false"){
226 liveuser 4136
 
3 liveuser 4137
			#設置執行失敗
4138
			$result["status"]="false";
226 liveuser 4139
 
3 liveuser 4140
			#設置錯誤訊息
4141
			$result["error"]=$checkArguments;
226 liveuser 4142
 
3 liveuser 4143
			#回傳結果
4144
			return $result;
226 liveuser 4145
 
3 liveuser 4146
			}#if end
226 liveuser 4147
 
3 liveuser 4148
		#儲存驗證後的結果
4149
		$pass=password_verify($conf["input"],$conf["password"]);
226 liveuser 4150
 
3 liveuser 4151
		#如果驗證成功
4152
		if($pass){
226 liveuser 4153
 
3 liveuser 4154
			#設置驗證成功
4155
			$result["passed"]="true";
226 liveuser 4156
 
3 liveuser 4157
			}#if end
226 liveuser 4158
 
3 liveuser 4159
		#反之驗證失敗
4160
		else{
226 liveuser 4161
 
3 liveuser 4162
			#設置驗證成功
4163
			$result["passed"]="false";
226 liveuser 4164
 
3 liveuser 4165
			}#else end
226 liveuser 4166
 
3 liveuser 4167
		#設置執行正常
4168
		$result["status"]="true";
226 liveuser 4169
 
3 liveuser 4170
		#回傳結果
4171
		return $result;
226 liveuser 4172
 
3 liveuser 4173
		}#function validPassword end
4174
 
66 liveuser 4175
	/*
4176
	#函式說明:
4177
	#id指令來取得目標賬號的群組資訊
4178
	#回傳結果:
4179
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4180
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
4181
	#$result["function"],當前執行的函式名稱.
4182
	#$result["content"],呼叫完WebService所得回傳結果.
4183
	#$result["content"]["groupId"],群組的id.
4184
	#$result["content"]["belongGroupName"],陣列,隸屬的群組名稱陣列.
4185
	#$result["content"]["belongGroupId"],陣列,隸屬的群組id.
4186
	#必填參數:
4187
	#$conf["user"],字串,要取得群組資訊的目標使用者名稱.
4188
	$conf["user"]="";
4189
	#可省略參數:
4190
	#無.
4191
	#參考資料:
4192
	#無.
4193
	#備註:
4194
	#無.
4195
	*/
4196
	public static function getUserGroup(&$conf){
226 liveuser 4197
 
66 liveuser 4198
		#初始化要回傳的結果
4199
		$result=array();
4200
 
4201
		#取得當前執行的函數名稱
4202
		$result["function"]=__FUNCTION__;
4203
 
4204
		#如果沒有參數
4205
		if(func_num_args()==0){
226 liveuser 4206
 
66 liveuser 4207
			#設置執行失敗
4208
			$result["status"]="false";
226 liveuser 4209
 
66 liveuser 4210
			#設置執行錯誤訊息
4211
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 4212
 
66 liveuser 4213
			#回傳結果
4214
			return $result;
226 liveuser 4215
 
66 liveuser 4216
			}#if end
226 liveuser 4217
 
66 liveuser 4218
		#取得參數
4219
		$result["argu"]=$conf;
4220
 
4221
		#如果 $conf 不為陣列
4222
		if(gettype($conf)!=="array"){
226 liveuser 4223
 
66 liveuser 4224
			#設置執行失敗
4225
			$result["status"]="false";
226 liveuser 4226
 
66 liveuser 4227
			#設置執行錯誤訊息
4228
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 4229
 
66 liveuser 4230
			#如果傳入的參數為 null
4231
			if($conf===null){
226 liveuser 4232
 
66 liveuser 4233
				#設置執行錯誤訊息
4234
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4235
 
66 liveuser 4236
				}#if end
4237
 
4238
			#回傳結果
4239
			return $result;
226 liveuser 4240
 
66 liveuser 4241
			}#if end
226 liveuser 4242
 
66 liveuser 4243
		#函式說明:
4244
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
4245
		#回傳結果:
4246
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4247
		#$result["error"],執行不正常結束的錯訊息陣列.
4248
		#$result["simpleError"],簡單表示的錯誤訊息.
4249
		#$result["function"],當前執行的函式名稱.
4250
		#$result["argu"],設置給予的參數.
4251
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4252
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4253
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4254
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4255
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4256
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4257
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4258
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4259
		#必填參數:
4260
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4261
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4262
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4263
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4264
		#可省略參數:
4265
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4266
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("user");
4267
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
4268
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4269
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4270
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
4271
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
4272
		#$conf["canNotBeEmpty"]=array();
4273
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
4274
		#$conf["canBeEmpty"]=array();
4275
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
4276
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4277
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4278
		#$conf["skipableVariableName"]=array();
4279
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
4280
		#$conf["skipableVariableType"]=array();
4281
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4282
		#$conf["skipableVarDefaultValue"]=array("");
4283
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
4284
		#$conf["disallowAllSkipableVarIsEmpty"]="";
4285
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
4286
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
4287
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
4288
		#$conf["disallowAllSkipableVarNotExist"]="";
4289
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4290
		#$conf["arrayCountEqualCheck"][]=array();
4291
		#參考資料:
4292
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4293
		#備註:
4294
		#無.
4295
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4296
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 4297
 
66 liveuser 4298
		#如果驗證失敗
4299
		if($checkArguments["status"]==="false"){
226 liveuser 4300
 
66 liveuser 4301
			#設置執行失敗
4302
			$result["status"]="false";
226 liveuser 4303
 
66 liveuser 4304
			#設置錯誤訊息
4305
			$result["error"]=$checkArguments;
226 liveuser 4306
 
66 liveuser 4307
			#回傳結果
4308
			return $result;
226 liveuser 4309
 
66 liveuser 4310
			}#if end
226 liveuser 4311
 
66 liveuser 4312
		#如果驗證不成功
4313
		if($checkArguments["passed"]==="false"){
226 liveuser 4314
 
66 liveuser 4315
			#設置執行失敗
4316
			$result["status"]="false";
226 liveuser 4317
 
66 liveuser 4318
			#設置錯誤訊息
4319
			$result["error"]=$checkArguments;
226 liveuser 4320
 
66 liveuser 4321
			#回傳結果
4322
			return $result;
226 liveuser 4323
 
66 liveuser 4324
			}#if end
226 liveuser 4325
 
66 liveuser 4326
		#函式說明:
4327
		#呼叫shell執行系統命令,並取得回傳的內容.
4328
		#回傳結果:
4329
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4330
		#$result["error"],錯誤訊息陣列.
4331
		#$result["function"],當前執行的函數名稱.
4332
		#$result["argu"],使用的參數.
4333
		#$result["cmd"],執行的指令內容.
4334
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
4335
		#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
4336
		#$result["content"],為執行完後的輸出字串.
4337
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
4338
		#$result["running"],是否還在執行.
4339
		#$result["pid"],pid.
4340
		#$result["statusCode"],執行結束後的代碼.
4341
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
4342
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
4343
		#必填參數:
4344
		#$conf["command"],字串,要執行的指令.
4345
		$conf["external::callShell"]["command"]="id";
4346
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4347
		$conf["external::callShell"]["fileArgu"]=__FILE__;
4348
		#可省略參數:
4349
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
4350
		$conf["external::callShell"]["argu"]=array($user);
4351
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
4352
		#$conf["arguIsAddr"]=array();
4353
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
4354
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
4355
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
4356
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
4357
		#$conf["enablePrintDescription"]="true";
4358
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
4359
		#$conf["printDescription"]="";
4360
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
4361
		$conf["external::callShell"]["escapeshellarg"]="true";
4362
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
4363
		#$conf["thereIsShellVar"]=array();
4364
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
4365
		#$conf["username"]="";
4366
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
4367
		#$conf["password"]="";
4368
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
4369
		#$conf["useScript"]="";
4370
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
4371
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
4372
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
4373
		#$conf["inBackGround"]="";
4374
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
4375
		#$conf["getErr"]="false";
4376
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
4377
		#$conf["doNotRun"]="false";
4378
		#參考資料:
4379
		#exec=>http://php.net/manual/en/function.exec.php
4380
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
4381
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4382
		#備註:
4383
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
4384
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
4385
		$callShell=external::callShell($conf["external::callShell"]);
4386
		unset($conf["external::callShell"]);
226 liveuser 4387
 
66 liveuser 4388
		#如果執行異常
4389
		if($callShell["status"]==="false"){
226 liveuser 4390
 
66 liveuser 4391
			#設置執行失敗
4392
			$result["status"]="false";
226 liveuser 4393
 
66 liveuser 4394
			#設置錯誤訊息
4395
			$result["error"]=$callShell;
226 liveuser 4396
 
66 liveuser 4397
			#回傳結果
4398
			return $result;
226 liveuser 4399
 
66 liveuser 4400
			}#if end
226 liveuser 4401
 
66 liveuser 4402
		#若輸出不對
4403
		if(count($callShell["content"])===0){
226 liveuser 4404
 
66 liveuser 4405
			#設置執行失敗
4406
			$result["status"]="false";
226 liveuser 4407
 
66 liveuser 4408
			#設置錯誤訊息
4409
			$result["error"]=$callShell;
226 liveuser 4410
 
66 liveuser 4411
			#回傳結果
4412
			return $result;
226 liveuser 4413
 
66 liveuser 4414
			}#if end
226 liveuser 4415
 
66 liveuser 4416
		#解析輸出資訊
4417
		#範例輸出:
4418
		#uid=1000(liveuser) gid=1000(liveuser) groups=1000(liveuser),10(wheel),1002(web)
226 liveuser 4419
 
66 liveuser 4420
		#函式說明:
4421
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4422
		#回傳結果:
4423
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4424
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4425
		#$result["function"],當前執行的函式名稱.
4426
		#$result["argu"],所使用的參數.
4427
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4428
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4429
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4430
		#必填參數:
4431
		#$conf["input"],字串,要檢查的字串.
4432
		$conf["search::findSpecifyStrFormat"]["input"]=$callShell["content"][0];
4433
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4434
		$conf["search::findSpecifyStrFormat"]["format"]="uid=\${userId}(\${userName}) gid=\${groupId}(\${groupName}) groups=\${repeatedGroupId}(\${repeatedGroupName})\${otherGroupStr}";
4435
		#可省略參數:
4436
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4437
		#$conf["varEqual"]=array(null,"found");
4438
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4439
		#$conf["varCon"]=array("no_tail"=>" not");
4440
		#參考資料:
4441
		#無.
4442
		#備註:
4443
		#無.
4444
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4445
		unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 4446
 
66 liveuser 4447
		#如果執行異常
4448
		if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 4449
 
66 liveuser 4450
			#設置執行失敗
4451
			$result["status"]="false";
226 liveuser 4452
 
66 liveuser 4453
			#設置錯誤訊息
4454
			$result["error"]=$findSpecifyStrFormat;
226 liveuser 4455
 
66 liveuser 4456
			#回傳結果
4457
			return $result;
226 liveuser 4458
 
66 liveuser 4459
			}#if end
226 liveuser 4460
 
66 liveuser 4461
		#如果沒有符合格式的內容
4462
		if($findSpecifyStrFormat["found"]==="false"){
226 liveuser 4463
 
66 liveuser 4464
			#設置執行失敗
4465
			$result["status"]="false";
226 liveuser 4466
 
66 liveuser 4467
			#設置錯誤訊息
4468
			$result["error"]=$findSpecifyStrFormat;
226 liveuser 4469
 
66 liveuser 4470
			#回傳結果
4471
			return $result;
226 liveuser 4472
 
66 liveuser 4473
			}#if end
226 liveuser 4474
 
66 liveuser 4475
		#另存使用者id
4476
		$userId=$findSpecifyStrFormat["parsedVar"]["userId"][0];
226 liveuser 4477
 
66 liveuser 4478
		#另存群組的id
4479
		$groupId=$findSpecifyStrFormat["parsedVar"]["groupId"][0];
226 liveuser 4480
 
66 liveuser 4481
		#另存隸屬其他群組的資訊
4482
		$othergGroupStr=$findSpecifyStrFormat["parsedVar"]["othergGroupStr"][0];
226 liveuser 4483
 
66 liveuser 4484
		#如果有其他群組資訊
4485
		if(!empty($othergGroupStr)){
226 liveuser 4486
 
66 liveuser 4487
			#用逗號切割結果出來
4488
			#函式說明:
4489
			#將固定格式的字串分開,並回傳分開的結果.
4490
			#回傳結果:
4491
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4492
			#$result["error"],錯誤訊息陣列
4493
			#$result["function"],當前執行的函數名稱.
4494
			#$result["argu"],使用的參數.
4495
			#$result["oriStr"],要分割的原始字串內容
4496
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4497
			#$result["dataCounts"],爲總共分成幾段
4498
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4499
			#必填參數:
4500
			#$conf["stringIn"],字串,要處理的字串.
4501
			$conf["stringProcess::spiltString"]["stringIn"]=$othergGroupStr;
4502
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4503
			$conf["stringProcess::spiltString"]["spiltSymbol"]=",";
4504
			#可省略參數:
4505
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4506
			#$conf["allowEmptyStr"]="false";
4507
			#參考資料:
4508
			#無.
4509
			#備註:
4510
			#無.
4511
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4512
			unset($conf["stringProcess::spiltString"]);
226 liveuser 4513
 
66 liveuser 4514
			#如果執行異常
4515
			if($spiltString["status"]==="false"){
226 liveuser 4516
 
66 liveuser 4517
				#設置執行失敗
4518
				$result["status"]="false";
226 liveuser 4519
 
66 liveuser 4520
				#設置錯誤訊息
4521
				$result["error"]=$spiltString;
226 liveuser 4522
 
66 liveuser 4523
				#回傳結果
4524
				return $result;
226 liveuser 4525
 
66 liveuser 4526
				}#if end
226 liveuser 4527
 
66 liveuser 4528
			#如果沒有符合格式的內容
4529
			if($spiltString["found"]==="false"){
226 liveuser 4530
 
66 liveuser 4531
				#設置執行失敗
4532
				$result["status"]="false";
226 liveuser 4533
 
66 liveuser 4534
				#設置錯誤訊息
4535
				$result["error"]=$spiltString;
226 liveuser 4536
 
66 liveuser 4537
				#回傳結果
4538
				return $result;
226 liveuser 4539
 
66 liveuser 4540
				}#if end
226 liveuser 4541
 
66 liveuser 4542
			#依照分隔成的段數
4543
			foreach($spiltString["dataArray"] as $oginfo){
226 liveuser 4544
 
66 liveuser 4545
				#解析groudId跟groupName
226 liveuser 4546
 
66 liveuser 4547
				#範例輸出:
4548
				#10(wheel)
226 liveuser 4549
 
66 liveuser 4550
				#函式說明:
4551
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
4552
				#回傳結果:
4553
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4554
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
4555
				#$result["function"],當前執行的函式名稱.
4556
				#$result["argu"],所使用的參數.
4557
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
4558
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
4559
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
4560
				#必填參數:
4561
				#$conf["input"],字串,要檢查的字串.
4562
				$conf["search::findSpecifyStrFormat"]["input"]=$oginfo;
4563
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
4564
				$conf["search::findSpecifyStrFormat"]["format"]="gid=\${groupId}(\${groupName})";
4565
				#可省略參數:
4566
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
4567
				#$conf["varEqual"]=array(null,"found");
4568
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
4569
				#$conf["varCon"]=array("no_tail"=>" not");
4570
				#參考資料:
4571
				#無.
4572
				#備註:
4573
				#無.
4574
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
4575
				unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 4576
 
66 liveuser 4577
				#如果執行異常
4578
				if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 4579
 
66 liveuser 4580
					#設置執行失敗
4581
					$result["status"]="false";
226 liveuser 4582
 
66 liveuser 4583
					#設置錯誤訊息
4584
					$result["error"]=$findSpecifyStrFormat;
226 liveuser 4585
 
66 liveuser 4586
					#回傳結果
4587
					return $result;
226 liveuser 4588
 
66 liveuser 4589
					}#if end
226 liveuser 4590
 
66 liveuser 4591
				#如果格式異常
4592
				if($findSpecifyStrFormat["found"]==="false"){
226 liveuser 4593
 
66 liveuser 4594
					#設置執行失敗
4595
					$result["status"]="false";
226 liveuser 4596
 
66 liveuser 4597
					#設置錯誤訊息
4598
					$result["error"]=$findSpecifyStrFormat;
226 liveuser 4599
 
66 liveuser 4600
					#回傳結果
4601
					return $result;
226 liveuser 4602
 
66 liveuser 4603
					}#if end
226 liveuser 4604
 
66 liveuser 4605
				#如果是 user 自己的群組
4606
				if($findSpecifyStrFormat["parsedVar"]["groupName"][0]===$user){
226 liveuser 4607
 
66 liveuser 4608
					#跳過該群組資訊
4609
					continue;
226 liveuser 4610
 
4611
					}#if end
4612
 
66 liveuser 4613
				#儲存其他 group id
4614
				$otherGroupId[]=$findSpecifyStrFormat["parsedVar"]["groupId"][0];
226 liveuser 4615
 
66 liveuser 4616
				#儲存其他 group name
4617
				$otherGroupName[]=$findSpecifyStrFormat["parsedVar"]["groupName"][0];
226 liveuser 4618
 
66 liveuser 4619
				}#foreach end
226 liveuser 4620
 
66 liveuser 4621
			}#if end
226 liveuser 4622
 
66 liveuser 4623
		#設置 group id 結果
4624
		$result["content"]["groupId"]=$groupId;
226 liveuser 4625
 
66 liveuser 4626
		#設置隸屬的 group 名稱
4627
		$result["content"]["belongGroupName"]=$otherGroupName;
226 liveuser 4628
 
66 liveuser 4629
		#設置隸屬的 group id
4630
		$result["content"]["belongGroupId"]=$otherGroupId;
226 liveuser 4631
 
66 liveuser 4632
		#設置執行正常
4633
		$result["status"]="true";
226 liveuser 4634
 
4635
		#回傳結果
66 liveuser 4636
		return $result;
4637
 
226 liveuser 4638
		}#function getUserGroup end
4639
 
3 liveuser 4640
	}#class authenticate end
226 liveuser 4641
 
3 liveuser 4642
?>