Subversion Repositories php-qbpwcf

Rev

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

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2025 Min-Jhin,Chen
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 cmd{
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){
48
 
49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
51
 
52
		#設置執行不正常
53
		$result["status"]="false";
54
 
55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
57
 
58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
60
 
61
		#回傳結果
62
		return $result;
63
 
64
		}#function __call end
65
 
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){
80
 
81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
83
 
84
		#設置執行不正常
85
		$result["status"]="false";
86
 
87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
89
 
90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
92
 
93
		#回傳結果
94
		return $result;
95
 
96
		}#function __callStatic end
97
 
98
	/*
99
	#函式說明:
100
	#讀取標準I/O的一行輸入.並提供提示說明.
101
	#回傳結果:
102
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
103
	#$result["error"],錯誤訊息.
104
	#$result["function"],當前執行的函式名稱.
105
	#$result["content"],取得的輸入內容.
106
	#必填參數:
107
	#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
108
	$conf["commentsArray"]=array("請輸入");
109
	#可省略參數:
110
	#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
111
	#$conf["newLineBreak"]="false";
112
	#參考資料:
113
	#無.
114
	#備註:
115
	#無.
116
	*/
117
	public static function readLine($conf){
118
 
119
		#初始化要回傳的內容
120
		$result=array();
121
 
122
		#取得當前函式的名稱
123
		$result["function"]=__FUNCTION__;
124
 
125
		#函式說明:
126
		#判斷當前環境為web還是cmd
127
		#回傳結果:
128
		#$result,"web"或"cmd"
129
		if(csInformation::getEnv()=="web"){
130
 
131
			#設置執行失敗
132
			$result["status"]="false";
133
 
134
			#設置執行錯誤訊息
135
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
136
 
137
			#回傳結果
138
			return $result;
139
 
140
			}#if end
141
 
142
		#如果 $conf 不為陣列
143
		if(gettype($conf)!="array"){
144
 
145
			#設置執行失敗
146
			$result["status"]="false";
147
 
148
			#設置執行錯誤訊息
149
			$result["error"][]="\$conf變數須為陣列形態";
150
 
151
			#如果傳入的參數為 null
152
			if($conf==null){
153
 
154
				#設置執行錯誤訊息
155
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
156
 
157
				}#if end
158
 
159
			#回傳結果
160
			return $result;
161
 
162
			}#if end
163
 
164
		#函式說明:
165
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
166
		#回傳的結果:
167
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
168
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
169
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
170
		#必填寫的參數:
171
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
172
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("commentsArray");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
173
		#可以省略的參數:
174
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
175
		#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
176
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
177
		unset($conf["variableCheck"]["isexistMuti"]);
178
 
179
		#如果 $checkResult["status"] 等於 "false"
180
		if($checkResult["status"]=="false"){
181
 
182
			#設置執行錯誤識別
183
			$result["status"]="false";
184
 
185
			#取得錯誤訊息
186
			$result["error"]=$checkResult;
187
 
188
			#回傳結果
189
			return $result;
190
 
191
			}#if end
192
 
193
		#如果 $checkResult["passed"] 等於 "false"
194
		if($checkResult["passed"]=="false"){
195
 
196
			#設置執行錯誤識別
197
			$result["status"]="false";
198
 
199
			#取得錯誤訊息
200
			$result["error"]=$checkResult;
201
 
202
			#回傳結果
203
			return $result;
204
 
205
			}#if end
206
 
207
		#如果 $conf["newLineBreak"] 不存在
208
		if(!isset($conf["newLineBreak"])){
209
 
210
			$conf["newLineBreak"]="true";
211
 
212
			}#if end
213
 
214
		#根據 $conf["commentsArray"] 的元素數量
215
		foreach($conf["commentsArray"] as $comemntLine){
216
 
217
			#印出內容
218
			echo $comemntLine;
219
 
220
			#如果 $conf["newLineBreak"] 等於 "true"
221
			if($conf["newLineBreak"]=="true"){
222
 
223
				#換行
224
				echo "\n";
225
 
226
				}#if end
227
 
228
			}#foreach end
229
 
230
		#設置執行成功
231
		$result["status"]="true";
232
 
233
		#設置取的內容
234
		$result["content"]=trim(fgets(STDIN));
235
 
236
		#回傳結果
237
		return $result;
238
 
239
		}#function readLine end
240
 
241
	/*
242
	#函式說明:
243
	#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
244
	#回傳結果:
245
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
246
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
247
	#$result["function"],當前執行的函式名稱.
248
	#$result["argu"],使用的參數.
249
	#$result["content"],設定值內容.
250
	#必填參數:
251
	#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
252
	$conf["readVarName"]="";
253
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
254
	$conf["fileArgu"]=__FILE__;
255
	#可省略參數:
256
	#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
257
	#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
258
	#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
259
	#$conf["commentsArray"]=array();
260
	#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要,預設為"false".
261
	#$conf["forceRewrite"]="";
262
	#參考資料:
263
	#無.
264
	#備註:
265
	#無.
266
	*/
267
	public static function getFromConf(&$conf){
268
 
269
		#初始化要回傳的結果
270
		$result=array();
271
 
272
		#取得當前執行的函式名稱
273
		$result["function"]=__FUNCTION__;
274
 
275
		#函式說明:
276
		#判斷當前環境為web還是cmd
277
		#回傳結果:
278
		#$result,"web"或"cmd"
279
		if(csInformation::getEnv()=="web"){
280
 
281
			#設置執行失敗
282
			$result["status"]="false";
283
 
284
			#設置執行錯誤訊息
285
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
286
 
287
			#回傳結果
288
			return $result;
289
 
290
			}#if end
291
 
292
		#如果沒有參數
293
		if(func_num_args()==0){
294
 
295
			#設置執行失敗
296
			$result["status"]="false";
297
 
298
			#設置執行錯誤訊息
299
			$result["error"]="函式".$result["function"]."需要參數";
300
 
301
			#回傳結果
302
			return $result;
303
 
304
			}#if end
305
 
306
		#取得參數
307
		$result["argu"]=$conf;
308
 
309
		#如果 $conf 不為陣列
310
		if(gettype($conf)!="array"){
311
 
312
			#設置執行失敗
313
			$result["status"]="false";
314
 
315
			#設置執行錯誤訊息
316
			$result["error"][]="\$conf變數須為陣列形態";
317
 
318
			#如果傳入的參數為 null
319
			if($conf==null){
320
 
321
				#設置執行錯誤訊息
322
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
323
 
324
				}#if end
325
 
326
			#回傳結果
327
			return $result;
328
 
329
			}#if end
330
 
331
		#檢查參數
332
		#函式說明:
333
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
334
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
335
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
336
		#$result["function"],當前執行的函式名稱.
337
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
338
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
339
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
340
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
341
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
342
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
343
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
344
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
345
		#必填寫的參數:
346
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
347
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
348
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
349
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("readVarName","fileArgu");
350
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
351
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
352
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
353
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
354
		#可以省略的參數:
355
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
356
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
357
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
358
		#$conf["skipableVariableCanNotBeEmpty"]=array();
359
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
360
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("conf","commentsArray","forceRewrite");
361
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
362
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string");
363
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
364
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".qbpwcf_tmp/cmd/getFromConf/conf.xml",array("請輸入變數 ".$conf["readVarName"]." 的內容"),"false");
365
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
366
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
367
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
368
		#參考資料來源:
369
		#array_keys=>http://php.net/manual/en/function.array-keys.php
370
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
371
		unset($conf["variableCheck::checkArguments"]);
372
 
373
		#如果檢查參數失敗
374
		if($checkArguments["status"]==="false"){
375
 
376
			#設置執行不正常
377
			$result["status"]="false";
378
 
379
			#設置執行錯誤
380
			$result["error"]=$checkArguments;
381
 
382
			#回傳結果
383
			return $result;
384
 
385
			}#if end
386
 
387
		#如果檢查參數不通過
388
		if($checkArguments["passed"]==="false"){
389
 
390
			#設置執行不正常
391
			$result["status"]="false";
392
 
393
			#設置執行錯誤
394
			$result["error"]=$checkArguments;
395
 
396
			#回傳結果
397
			return $result;
398
 
399
			}#if end
400
 
401
		#轉換路徑為絕對路徑
402
		#函式說明:
403
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
404
		#回傳結果:
405
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
406
		#$result["error"],錯誤訊息陣列.
407
		#$result["function"],函式名稱.
408
		#$result["content"],網址,若是在命令列執行,則為"null".
409
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
410
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
411
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
412
		#必填參數:
413
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
414
		$conf["csInformation::getInternetAddress"]["address"]=$conf["conf"];
415
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
416
		$conf["csInformation::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
417
		#可省略參數:
418
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
419
		$conf["csInformation::getInternetAddress"]["userDir"]="true";
420
		#備註:
421
		#在命令列執行,所得的路徑是錯誤的。
422
		$getInternetAddress=fileAccess::getInternetAddress($conf["csInformation::getInternetAddress"]);
423
		unset($conf["csInformation::getInternetAddress"]);
424
 
425
		#如果轉換位置失敗
426
		if($getInternetAddress["status"]==="false"){
427
 
428
			#設置執行不正常
429
			$result["status"]="false";
430
 
431
			#設置執行錯誤
432
			$result["error"]=$getInternetAddress;
433
 
434
			#回傳結果
435
			return $result;
436
 
437
			}#if end
438
 
439
		#取得轉換好的設定檔絕對位置
440
		$conf["conf"]=$getInternetAddress["fileSystemAbsoulutePosition"];
441
 
442
		#函式說明:檢查多個檔案與資料夾是否存在.
443
		#回傳的結果:
444
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
445
		#$result["error"],錯誤訊息陣列.
446
		#$resutl["function"],當前執行的函式名稱.
447
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
448
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
449
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
450
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
451
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
452
		#必填參數:
453
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
454
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["conf"]);
455
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
456
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
457
		#可省略參數
458
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
459
		#$conf["disableWebSearch"]="false";
460
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
461
		#$conf["userDir"]="true";
462
		#參考資料來源:
463
		#http://php.net/manual/en/function.file-exists.php
464
		#http://php.net/manual/en/control-structures.foreach.php
465
		#備註:
466
		#函式file_exists檢查的路徑為檔案系統的路徑
467
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
468
		unset($conf["fileAccess::checkMultiFileExist"]);
469
 
470
		#如果檢查設定檔是否存在失敗
471
		if($checkMultiFileExist["status"]==="false"){
472
 
473
			#設置執行不正常
474
			$result["status"]="false";
475
 
476
			#設置執行錯誤
477
			$result["error"]=$checkMultiFileExist;
478
 
479
			#回傳結果
480
			return $result;
481
 
482
			}#if end
483
 
484
		#如果設定檔不存在
485
		if($checkMultiFileExist["allExist"]==="false"){
486
 
487
			#建立設定檔的路徑
488
			#函式說明:
489
			#確保路徑存在.
490
			#回傳的結果:
491
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
492
			#$result["error"],錯誤訊息陣列.
493
			#$resutl["function"],當前執行的函式名稱.
494
			#$result["path"],建立好的路徑字串.
495
			#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
496
			#必填參數:
497
			#$conf["path"],要檢查的路徑
498
			$conf["fileAccess::validatePath"]["path"]=$conf["conf"];
499
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
500
			$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
501
			#可省略參數:
502
			#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
503
			$conf["fileAccess::validatePath"]["haveFileName"]="true";
504
			#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
505
			#$conf["dirPermission"]="";
506
			$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
507
			unset($conf["fileAccess::validatePath"]);
508
 
509
			#如果確保設定檔路徑失敗
510
			if($validatePath["status"]==="false"){
511
 
512
				#設置執行不正常
513
				$result["status"]="false";
514
 
515
				#設置執行錯誤
516
				$result["error"]=$validatePath;
517
 
518
				#回傳結果
519
				return $result;
520
 
521
				}#if end
522
 
523
			#建立設定檔
524
			#函式說明:
525
			#建立空的xml檔案
526
			#回傳結果:
527
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
528
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
529
			#$result["function"],當前執行的函式名稱.
530
			#$result["content"],xml檔案的路徑.
531
			#必填參數:
532
			#$conf["xmlPosition"],字串,xml檔案的位置.
533
			$conf["xml::createEmptyXml"]["xmlPosition"]=$conf["conf"];
534
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
535
			$conf["xml::createEmptyXml"]["fileArgu"]=$conf["fileArgu"];
536
			#參考資料:
537
			#simplexmlelement=>http://php.net/manual/en/simplexmlelement.asxml.php
538
			$createEmptyXml=xml::createEmptyXml($conf["xml::createEmptyXml"]);
539
			unset($conf["xml::createEmptyXml"]);
540
 
541
			#如果建立設定檔失敗
542
			if($createEmptyXml["status"]=="false"){
543
 
544
				#設置執行不正常
545
				$result["status"]="false";
546
 
547
				#設置執行錯誤
548
				$result["error"]=$createEmptyXml;
549
 
550
				#回傳結果
551
				return $result;
552
 
553
				}#if end
554
 
555
			#讀取要寫入到設定檔的變數
556
			#函式說明:
557
			#讀取標準I/O的一行輸入.並提供提示說明.
558
			#回傳的結果:
559
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
560
			#$result["error"],錯誤訊息.
561
			#$result["function"],當前執行的函式名稱.
562
			#$result["content"],取得的輸入內容.
563
			#必填參數:
564
			#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
565
			$conf["cmd::readLine"]["commentsArray"]=$conf["commentsArray"];
566
			#可省略參數:
567
			#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
568
			#$conf["newLineBreak"]="false";
569
			$readLine=cmd::readLine($conf["cmd::readLine"]);
570
			unset($conf["cmd::readLine"]);
571
 
572
			#如果讀取字串失敗
573
			if($readLine["status"]==="false"){
574
 
575
				#設置執行不正常
576
				$result["status"]="false";
577
 
578
				#設置執行錯誤
579
				$result["error"]=$readLine;
580
 
581
				#回傳結果
582
				return $result;
583
 
584
				}#if end
585
 
586
			#取的新的設定值
587
			$confVal=$readLine["content"];
588
 
589
			#過濾 $conf["tag"][$i] 的 「::」 字元
590
			#函式說明:
591
			#處理字串避免網頁出錯
592
			#回傳的結果:
593
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
594
			#$result["function"],當前執行的函式.
595
			#$result["content"],爲處理好的字串.
596
			#$result["error"],錯誤訊息陣列.
597
			#必填參數:
598
			$conf["stringProcess::correctCharacter"]["stringIn"]=$conf["readVarName"];#爲要處理的字串
599
			#可省略參數:
600
			$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("<",">","=","//","'","$","%","&","|","/*","*","#","\"",":");#爲被選擇要處理的字串/字元,須爲陣列值。
601
				#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
602
				#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
603
			#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
604
			$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
605
			unset($conf["stringProcess::correctCharacter"]);
606
 
607
			#如果修正標籤名稱失敗
608
			if($correctCharacter["status"]==="false"){
609
 
610
				#設置執行不正常
611
				$result["status"]="false";
612
 
613
				#設置執行錯誤
614
				$result["error"]=$correctCharacter;
615
 
616
				#回傳結果
617
				return $result;
618
 
619
				}#if end
620
 
621
			#取得修正好的tag名稱
622
			$conf["readVarName"]=$correctCharacter["content"];
623
 
624
			#將設定值內容寫入到設定檔案裡面
625
			#函式說明:
626
			#在目標層級新增標籤與內容
627
			#回傳結果:
628
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
629
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
630
			#$result["function"],當前執行的函式名稱.
631
			#必填參數:
632
			#$conf["xmlPosition"],字串,xml檔案的位置.
633
			$conf["xml::addTag"]["xmlPosition"]=$conf["conf"];
634
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
635
			$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
636
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
637
			$conf["xml::addTag"]["tag"]=array($conf["readVarName"]);
638
			#$conf["tagValue"],字串,目標標籤的內容要放什麼.
639
			$conf["xml::addTag"]["tagValue"]=$confVal;
640
			#參考資料:
641
			#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
642
			$addTag=xml::addTag($conf["xml::addTag"]);
643
			unset($conf["xml::addTag"]);
644
 
645
			#如果新增tag失敗
646
			if($addTag["status"]==="false"){
647
 
648
				#設置執行不正常
649
				$result["status"]="false";
650
 
651
				#設置執行錯誤
652
				$result["error"]=$addTag;
653
 
654
				#回傳結果
655
				return $result;
656
 
657
				}#if end
658
 
659
			}#if end
660
 
661
		#讀取設定檔的內容
662
		#函式說明:
663
		#取得xml特定標籤的內容
664
		#回傳結果:
665
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
666
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
667
		#$result["warning"],警告訊息陣列.
668
		#$result["function"],當前執行的函式名稱.
669
		#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.
670
		#$result["content"],xml物件的標籤內容.
671
		#必填參數:
672
		#$conf["xmlPosition"],字串,xml檔案的位置.
673
		$conf["xml::getContent"]["xmlPosition"]=$conf["conf"];
674
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
675
		$conf["xml::getContent"]["fileArgu"]=$conf["fileArgu"];
676
		#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
677
		$conf["xml::getContent"]["tag"]=array($conf["readVarName"]);
678
		$getContent=xml::getTagInfo($conf["xml::getContent"]);
679
		unset($conf["xml::getContent"]);
680
 
681
		#如果取得tag資訊失敗
682
		if($getContent["status"]==="false"){
683
 
684
			#如果是讀取時出錯
685
			if($getContent["error"]["error"][0]==="讀取xml檔案失敗!"){
686
 
687
				#判斷是否為檔案不完整所導致的錯誤
688
				#函式說明:
689
				#檢查多個字串裡面是否沒有多個任何篩選字存在
690
				#回傳的結果:
691
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
692
				#$result["function"],當前執行的函式
693
				#$result["error"],函式錯誤訊息,若爲""則表示沒有錯誤
694
				#$result["filtered"],該字串是否為要過濾掉的識別陣列,"true"為要過濾掉的;"false"為不用過濾掉的
695
				#必填參數:
696
				$conf["search::filterMutiString"]["inputStr"]=array($getContent["error"]["error"][1]->message);#要過濾的字串陣列
697
				$conf["search::filterMutiString"]["filterWord"]=array("Opening and ending tag mismatch:","Premature end of data in tag","Couldn't find end of Start Tag","expected");#要過濾的字串不能含有該陣列元素之一
698
				$filterMutiString=search::filterMutiString($conf["search::filterMutiString"]);
699
				unset($conf["search::filterMutiString"]);
700
 
701
				#如果尋找前置關鍵字失敗
702
				if($filterMutiString["status"]==="false"){
703
 
704
					#設置執行不正常
705
					$result["status"]="false";
706
 
707
					#設置執行錯誤
708
					$result["error"]=$filterMutiString;
709
 
710
					#回傳結果
711
					return $result;
712
 
713
					}#if end
714
 
715
				#如果有找到前置關鍵字
716
				if($filterMutiString["filtered"][0]==="true"){
717
 
718
					#移除該xml檔案
719
					#函式說明:
720
					#移除檔案
721
					#回傳的結果:
722
					#$result["status"],"true"代表移除成功,"false"代表移除失敗.
723
					#$result["error"],錯誤訊息陣列
724
					#$result["warning"],警告訊息陣列
725
					#$result["function"],當前執行的函式名稱
726
					#必填參數:
727
					#$conf["fileAddress"],字串,要移除檔案的位置.
728
					$conf["fileAccess::delFile"]["fileAddress"]=$conf["conf"];
729
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
730
					$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
731
					#可省略參數:
732
					#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
733
					#$conf["commentsArray"]=array("");
734
					$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
735
					unset($conf["fileAccess::delFile"]);
736
 
737
					#如果移除檔案失敗
738
					if($delFile["status"]==="false"){
739
 
740
						#設置執行不正常
741
						$result["status"]="false";
742
 
743
						#設置執行錯誤
744
						$result["error"]=$delFile;
745
 
746
						#回傳結果
747
						return $result;
748
 
749
						}#if end
750
 
751
					#遞迴取得xml檔案特定標籤的內容
752
					/*
753
					#函式說明:
754
					#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
755
					#回傳結果:
756
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
757
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
758
					#$result["function"],當前執行的函式名稱.
759
					#$result["argu"],使用的參數.
760
					#$result["content"],設定值內容.
761
					#必填參數:
762
					#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
763
					$conf["readVarName"]="";
764
					#可省略參數:
765
					#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
766
					#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
767
					#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
768
					#$conf["fileArgu"]=__FILE__;
769
					#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
770
					#$conf["commentsArray"]=array();
771
					#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要,預設為"false".
772
					#$conf["forceRewrite"]="";
773
					*/
774
					return cmd::getFromConf($conf=$result["argu"]);
775
 
776
					}#if end
777
 
778
				}#if end
779
 
780
			#設置執行不正常
781
			$result["status"]="false";
782
 
783
			#設置執行錯誤
784
			$result["error"]=$getContent;
785
 
786
			#回傳結果
787
			return $result;
788
 
789
			}#if end
790
 
791
		#如果要取得的tag不存在
792
		if($getContent["tagExist"]==="false"){
793
 
794
			#讀取要寫入到設定檔的變數
795
			#函式說明:
796
			#讀取標準I/O的一行輸入.並提供提示說明.
797
			#回傳的結果:
798
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
799
			#$result["error"],錯誤訊息.
800
			#$result["function"],當前執行的函式名稱.
801
			#$result["content"],取得的輸入內容.
802
			#必填參數:
803
			#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
804
			$conf["cmd::readLine"]["commentsArray"]=$conf["commentsArray"];
805
			#可省略參數:
806
			#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
807
			#$conf["newLineBreak"]="false";
808
			$readLine=cmd::readLine($conf["cmd::readLine"]);
809
			unset($conf["cmd::readLine"]);
810
 
811
			#如果讀取字串失敗
812
			if($readLine["status"]==="false"){
813
 
814
				#設置執行不正常
815
				$result["status"]="false";
816
 
817
				#設置執行錯誤
818
				$result["error"]=$readLine;
819
 
820
				#回傳結果
821
				return $result;
822
 
823
				}#if end
824
 
825
			#取的新的設定值
826
			$confVal=$readLine["content"];
827
 
828
			#將設定值內容寫入到設定檔案裡面
829
			#函式說明:
830
			#在目標層級新增標籤與內容
831
			#回傳結果:
832
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
833
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
834
			#$result["function"],當前執行的函式名稱.
835
			#必填參數:
836
			#$conf["xmlPosition"],字串,xml檔案的位置.
837
			$conf["xml::addTag"]["xmlPosition"]=$conf["conf"];
838
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
839
			$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
840
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
841
			$conf["xml::addTag"]["tag"]=array($conf["readVarName"]);
842
			#$conf["tagValue"],字串,目標標籤的內容要放什麼.
843
			$conf["xml::addTag"]["tagValue"]=$confVal;
844
			#參考資料:
845
			#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
846
			$addTag=xml::addTag($conf["xml::addTag"]);
847
			unset($conf["xml::addTag"]);
848
 
849
			#如果新增tag失敗
850
			if($addTag["status"]==="false"){
851
 
852
				#設置執行不正常
853
				$result["status"]="false";
854
 
855
				#設置執行錯誤
856
				$result["error"]=$addTag;
857
 
858
				#回傳結果
859
				return $result;
860
 
861
				}#if end
862
 
863
			#讀取設定檔的內容
864
			#函式說明:
865
			#取得xml特定標籤的內容
866
			#回傳結果:
867
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
868
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
869
			#$result["warning"],警告訊息陣列.
870
			#$result["function"],當前執行的函式名稱.
871
			#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.
872
			#$result["content"],xml物件的標籤內容.
873
			#必填參數:
874
			#$conf["xmlPosition"],字串,xml檔案的位置.
875
			$conf["xml::getContent"]["xmlPosition"]=$conf["conf"];
876
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
877
			$conf["xml::getContent"]["fileArgu"]=$conf["fileArgu"];
878
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
879
			$conf["xml::getContent"]["tag"]=array($conf["readVarName"]);
880
			$getContent=xml::getTagInfo($conf["xml::getContent"]);
881
			unset($conf["xml::getContent"]);
882
 
883
			#如果取得tag資訊失敗
884
			if($getContent["status"]==="false"){
885
 
886
				#設置執行不正常
887
				$result["status"]="false";
888
 
889
				#設置執行錯誤
890
				$result["error"]=$getContent;
891
 
892
				#回傳結果
893
				return $result;
894
 
895
				}#if end
896
 
897
			#如果要取得的tag不存在
898
			if($getContent["tagExist"]==="false"){
899
 
900
				#設置執行不正常
901
				$result["status"]="false";
902
 
903
				#設置執行錯誤
904
				$result["error"]=$getContent;
905
 
906
				#回傳結果
907
				return $result;
908
 
909
				}#if end
910
 
911
			}#if end
912
 
913
		#如果要強制覆寫設定值
914
		if($conf["forceRewrite"]==="true"){
915
 
916
			#讀取要寫入到設定檔的變數
917
			#函式說明:
918
			#讀取標準I/O的一行輸入.並提供提示說明.
919
			#回傳的結果:
920
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
921
			#$result["error"],錯誤訊息.
922
			#$result["function"],當前執行的函式名稱.
923
			#$result["content"],取得的輸入內容.
924
			#必填參數:
925
			#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
926
			$conf["cmd::readLine"]["commentsArray"]=$conf["commentsArray"];
927
			#可省略參數:
928
			#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
929
			#$conf["newLineBreak"]="false";
930
			$readLine=cmd::readLine($conf["cmd::readLine"]);
931
			unset($conf["cmd::readLine"]);
932
 
933
			#如果讀取字串失敗
934
			if($readLine["status"]==="false"){
935
 
936
				#設置執行不正常
937
				$result["status"]="false";
938
 
939
				#設置執行錯誤
940
				$result["error"]=$readLine;
941
 
942
				#回傳結果
943
				return $result;
944
 
945
				}#if end
946
 
947
			#取的新的設定值
948
			$confVal=$readLine["content"];
949
 
950
			#將設定值內容寫入到設定檔案裡面
951
			#函式說明:
952
			#在目標層級新增標籤與內容
953
			#回傳結果:
954
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
955
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
956
			#$result["function"],當前執行的函式名稱.
957
			#必填參數:
958
			#$conf["xmlPosition"],字串,xml檔案的位置.
959
			$conf["xml::addTag"]["xmlPosition"]=$conf["conf"];
960
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
961
			$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
962
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
963
			$conf["xml::addTag"]["tag"]=array($conf["readVarName"]);
964
			#$conf["tagValue"],字串,目標標籤的內容要放什麼.
965
			$conf["xml::addTag"]["tagValue"]=$confVal;
966
			#參考資料:
967
			#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
968
			$addTag=xml::updateTag($conf["xml::addTag"]);
969
			unset($conf["xml::addTag"]);
970
 
971
			#如果新增tag失敗
972
			if($addTag["status"]==="false"){
973
 
974
				#設置執行不正常
975
				$result["status"]="false";
976
 
977
				#設置執行錯誤
978
				$result["error"]=$addTag;
979
 
980
				#回傳結果
981
				return $result;
982
 
983
				}#if end
984
 
985
			#讀取設定檔的內容
986
			#函式說明:
987
			#取得xml特定標籤的內容
988
			#回傳結果:
989
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
990
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
991
			#$result["warning"],警告訊息陣列.
992
			#$result["function"],當前執行的函式名稱.
993
			#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.
994
			#$result["content"],xml物件的標籤內容.
995
			#必填參數:
996
			#$conf["xmlPosition"],字串,xml檔案的位置.
997
			$conf["xml::getContent"]["xmlPosition"]=$conf["conf"];
998
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
999
			$conf["xml::getContent"]["fileArgu"]=$conf["fileArgu"];
1000
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
1001
			$conf["xml::getContent"]["tag"]=array($conf["readVarName"]);
1002
			$getContent=xml::getTagInfo($conf["xml::getContent"]);
1003
			unset($conf["xml::getContent"]);
1004
 
1005
			#如果取得tag資訊失敗
1006
			if($getContent["status"]=="false"){
1007
 
1008
				#設置執行不正常
1009
				$result["status"]="false";
1010
 
1011
				#設置執行錯誤
1012
				$result["error"]=$getContent;
1013
 
1014
				#回傳結果
1015
				return $result;
1016
 
1017
				}#if end
1018
 
1019
			#如果要取得的tag不存在
1020
			if($getContent["tagExist"]=="false"){
1021
 
1022
				#設置執行不正常
1023
				$result["status"]="false";
1024
 
1025
				#設置執行錯誤
1026
				$result["error"]=$getContent;
1027
 
1028
				#回傳結果
1029
				return $result;
1030
 
1031
				}#if end
1032
 
1033
			}#if end
1034
 
1035
		#設置讀取到的設定值
1036
		$result["content"]=$getContent["content"];
1037
 
1038
		#設置執行正常
1039
		$result["status"]="true";
1040
 
1041
		#回傳結果
1042
		return $result;
1043
 
1044
		}#function getFromConf end
1045
 
1046
	/*
1047
	#函式說明:
1048
	#將資料夾打包成tar.gz檔案
1049
	#回傳的結果:
1050
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1051
	#$result["error"],錯誤訊息.
1052
	#$result["function"],當前執行的函式名稱.
1053
	#$result["storePlace"],檔案輸出後的位置與名稱.
1054
	#必填參數:
1055
	#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1056
	$conf["commentsArray"]=array("正在打包");
1057
	#$conf["compressedFolder"],字串,要打包的資料夾位置
1058
	$conf["compressedFolder"]="";
1059
	#$conf["createdTarGzFile"],字串,打包好的檔案要放在哪裡,副檔名「.tar.gz」會自動加上.
1060
	$conf["createdTarGzFile"]="";
1061
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1062
	$conf["fileArgu"]=__FILE__;
1063
	#可省略參數:
1064
	#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
1065
	#$conf["newLineBreak"]="false";
1066
	#參考資料:
1067
	#無.
1068
	#備註:
1069
	#產生的壓縮檔內的路徑是從根目錄開始的.
1070
	#移到fileAccess類別會比較恰當
1071
	*/
1072
	public static function makeTarGzFile(&$conf){
1073
 
1074
		#初始化要回傳的內容
1075
		$result=array();
1076
 
1077
		#取得當前函式的名稱
1078
		$result["function"]=__FUNCTION__;
1079
 
1080
		#如果 $conf 不為陣列
1081
		if(gettype($conf)!="array"){
1082
 
1083
			#設置執行失敗
1084
			$result["status"]="false";
1085
 
1086
			#設置執行錯誤訊息
1087
			$result["error"][]="\$conf變數須為陣列形態";
1088
 
1089
			#如果傳入的參數為 null
1090
			if($conf==null){
1091
 
1092
				#設置執行錯誤訊息
1093
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
1094
 
1095
				}#if end
1096
 
1097
			#回傳結果
1098
			return $result;
1099
 
1100
			}#if end
1101
 
1102
		#檢查參數
1103
		#函式說明:
1104
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
1105
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1106
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1107
		#$result["function"],當前執行的函式名稱.
1108
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1109
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1110
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1111
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1112
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1113
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1114
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1115
		#必填寫的參數:
1116
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1117
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1118
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1119
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("commentsArray","compressedFolder","createdTarGzFile","fileArgu");
1120
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
1121
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string","string");
1122
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1123
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1124
		#可以省略的參數:
1125
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1126
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1127
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1128
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("newLineBreak");
1129
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1130
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
1131
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1132
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
1133
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1134
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
1135
		#參考資料來源:
1136
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1137
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1138
		unset($conf["variableCheck::checkArguments"]);
1139
 
1140
		#如果檢查失敗
1141
		if($checkResult["status"]=="false"){
1142
 
1143
			#設置錯誤狀態
1144
			$result["status"]="false";
1145
 
1146
			#設置錯誤提示
1147
			$result["error"]=$checkResult;
1148
 
1149
			#回傳結果
1150
			return $result;
1151
 
1152
			}#if end
1153
 
1154
		#如果檢查不通過
1155
		if($checkResult["passed"]=="false"){
1156
 
1157
			#設置錯誤狀態
1158
			$result["status"]="false";
1159
 
1160
			#設置錯誤提示
1161
			$result["error"]=$checkResult;
1162
 
1163
			#回傳結果
1164
			return $result;
1165
 
1166
			}#if end
1167
 
1168
		#如果 $conf["breakNewLine"] 沒有設置
1169
		if(!isset($conf["breakNewLine"])){
1170
 
1171
			# 將 $conf["breakNewLine"] 設為 "true"
1172
			$conf["breakNewLine"]="true";
1173
 
1174
			}#if end
1175
 
1176
		#針對$commensArray的每個元素
1177
		foreach($conf["commentsArray"] as $comment){
1178
 
1179
			#印出描述
1180
			echo $comment;
1181
 
1182
			#如果 $conf["breakNewLine"] 等於 "true"
1183
			if($conf["breakNewLine"]=="true"){
1184
 
1185
				#印出斷行符號
1186
				echo "\n";
1187
 
1188
				}#if end
1189
 
1190
			}#foreach end
1191
 
1192
		#取得當前的工作目錄
1193
		$workingDir=$_SERVER["PWD"];
1194
 
1195
		#檢查 $conf["createdTarGzFile"] 的開頭是否為 "/"
1196
		#函式說明:
1197
		#取得字首一樣的字串,並回傳其字串。
1198
		#回傳的結果:
1199
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
1200
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
1201
		#$result["function"],當前執行的函式名稱.
1202
		#$result["error"],錯誤訊息陣列.
1203
		#$result["returnString"],爲符合字首條件的字串內容.
1204
		#必填參數:
1205
		$conf["search"]["getMeetConditionsString"]["checkString"]=$conf["createdTarGzFile"];#要檢查的字串
1206
		$conf["search"]["getMeetConditionsString"]["frontWord"]="/";#用來檢查字首應該要有什麼字串
1207
		#用到的函式:
1208
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
1209
		$serachResult=search::getMeetConditionsString($conf["search"]["getMeetConditionsString"]);
1210
		unset($conf["search"]["getMeetConditionsString"]);
1211
 
1212
		#如果 $serachResult["status"] 等於 "false"
1213
		if($serachResult["status"]=="false"){
1214
 
1215
			#設置執行錯誤識別
1216
			$result["status"]="false";
1217
 
1218
			#取得錯誤訊息
1219
			$result["error"]=$serachResult;
1220
 
1221
			#回傳結果
1222
			return $result;
1223
 
1224
			}#if end
1225
 
1226
		#如果 $serachResult["founded"] 等於 "false"
1227
		if($serachResult["founded"]=="false"){
1228
 
1229
			#那就代表 $conf["createdTarGzFile"] 不是從根目錄開始的路徑位置
1230
			$conf["createdTarGzFile"]=$workingDir."/".$conf["createdTarGzFile"];
1231
 
1232
			}#if end
1233
 
1234
		#檢查 $conf["compressedFolder"] 的開頭是否為 "/"
1235
		#函式說明:
1236
		#取得字首一樣的字串,並回傳其字串。
1237
		#回傳的結果:
1238
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
1239
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
1240
		#$result["function"],當前執行的函式名稱.
1241
		#$result["error"],錯誤訊息陣列.
1242
		#$result["returnString"],爲符合字首條件的字串內容.
1243
		#必填參數:
1244
		$conf["search"]["getMeetConditionsString"]["checkString"]=$conf["compressedFolder"];#要檢查的字串
1245
		$conf["search"]["getMeetConditionsString"]["frontWord"]="/";#用來檢查字首應該要有什麼字串
1246
		#用到的函式:
1247
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
1248
		$serachResult=search::getMeetConditionsString($conf["search"]["getMeetConditionsString"]);
1249
		unset($conf["search"]["getMeetConditionsString"]);
1250
 
1251
		#如果 $serachResult["status"] 等於 "false"
1252
		if($serachResult["status"]=="false"){
1253
 
1254
			#設置執行錯誤識別
1255
			$result["status"]="false";
1256
 
1257
			#取得錯誤訊息
1258
			$result["error"]=$serachResult;
1259
 
1260
			#回傳結果
1261
			return $result;
1262
 
1263
			}#if end
1264
 
1265
		#如果 $serachResult["founded"] 等於 "false"
1266
		if($serachResult["founded"]=="false"){
1267
 
1268
			#那就代表 $conf["compressedFolder"] 不是從根目錄開始的路徑位置
1269
			$conf["compressedFolder"]=$workingDir."/".$conf["compressedFolder"];
1270
 
1271
			}#if end
1272
 
1273
		#為 $conf["createdTarGzFile"] 加上 .tar 的副檔名
1274
		$conf["createdTarGzFile"]=$conf["createdTarGzFile"].".tar";
1275
 
1276
		#函式說明:
1277
		#呼叫shell執行系統命令,並取得回傳的內容.
1278
		#回傳結果:
1279
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1280
		#$result["error"],錯誤訊息陣列.
1281
		#$result["function"],當前執行的函數名稱.
1282
		#$result["argu"],使用的參數.
1283
		#$result["cmd"],執行的指令內容.
1284
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
1285
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
1286
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
1287
		#$result["running"],是否還在執行.
1288
		#$result["pid"],pid.
1289
		#$result["statusCode"],執行結束後的代碼.
1290
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
1291
		#必填參數:
1292
		#$conf["command"],字串,要執行的指令.
1293
		$conf["external::callShell"]["command"]="tar";
1294
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1295
		$conf["external::callShell"]["fileArgu"]=__FILE__;
1296
		#可省略參數:
1297
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1298
		$conf["external::callShell"]["argu"]=array("-cvf",$conf["createdTarGzFile"],$conf["compressedFolder"]);
1299
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1300
		#$conf["arguIsAddr"]=array();
1301
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1302
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1303
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1304
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1305
		#$conf["enablePrintDescription"]="true";
1306
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
1307
		#$conf["printDescription"]="";
1308
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
1309
		$conf["external::callShell"]["escapeshellarg"]="true";
1310
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
1311
		#$conf["thereIsShellVar"]=array();
1312
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
1313
		#$conf["username"]="";
1314
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1315
		#$conf["password"]="";
1316
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
1317
		#$conf["useScript"]="";
1318
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
1319
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1320
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
1321
		#$conf["inBackGround"]="";
1322
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
1323
		#$conf["getErr"]="false";
1324
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
1325
		#$conf["doNotRun"]="false";
1326
		#參考資料:
1327
		#exec=>http://php.net/manual/en/function.exec.php
1328
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1329
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1330
		#備註:
1331
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
1332
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
1333
		$callShell=external::callShell($conf["external::callShell"]);
1334
		unset($conf["external::callShell"]);
1335
 
1336
		#如果執行外部程式失敗
1337
		if($callShell["status"]=="false"){
1338
 
1339
			#設置執行錯誤識別
1340
			$result["status"]="false";
1341
 
1342
			#取得錯誤訊息
1343
			$result["error"]=$callShell;
1344
 
1345
			#回傳結果
1346
			return $result;
1347
 
1348
			}#if end
1349
 
1350
		#取得要清除的中介資料
1351
		$deletedTarFile=$conf["createdTarGzFile"];
1352
 
1353
		#取得要壓縮的檔案路徑名稱
1354
		$conf["compressedFolder"]=$conf["createdTarGzFile"];
1355
 
1356
		#為 $conf["createdTarGzFile"] 加上 .gz 的副檔名
1357
		$conf["createdTarGzFile"]=$conf["createdTarGzFile"].".gz";
1358
 
1359
		#壓縮 tar 檔案
1360
		#函式說明:
1361
		#呼叫shell執行系統命令,並取得回傳的內容.
1362
		#回傳結果:
1363
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1364
		#$result["error"],錯誤訊息陣列.
1365
		#$result["function"],當前執行的函數名稱.
1366
		#$result["argu"],使用的參數.
1367
		#$result["cmd"],執行的指令內容.
1368
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
1369
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
1370
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
1371
		#$result["running"],是否還在執行.
1372
		#$result["pid"],pid.
1373
		#$result["statusCode"],執行結束後的代碼.
1374
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
1375
		#必填參數:
1376
		#$conf["command"],字串,要執行的指令.
1377
		$conf["external::callShell"]["command"]="gzip";
1378
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1379
		$conf["external::callShell"]["fileArgu"]=__FILE__;
1380
		#可省略參數:
1381
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1382
		$conf["external::callShell"]["argu"]=array("-cv",$conf["compressedFolder"],">>",$conf["createdTarGzFile"]);
1383
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1384
		#$conf["arguIsAddr"]=array();
1385
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1386
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1387
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1388
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1389
		#$conf["enablePrintDescription"]="true";
1390
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
1391
		#$conf["printDescription"]="";
1392
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
1393
		$conf["external::callShell"]["escapeshellarg"]="true";
1394
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
1395
		#$conf["thereIsShellVar"]=array();
1396
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
1397
		#$conf["username"]="";
1398
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1399
		#$conf["password"]="";
1400
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
1401
		#$conf["useScript"]="";
1402
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
1403
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1404
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
1405
		#$conf["inBackGround"]="";
1406
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
1407
		#$conf["getErr"]="false";
1408
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
1409
		#$conf["doNotRun"]="false";
1410
		#參考資料:
1411
		#exec=>http://php.net/manual/en/function.exec.php
1412
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1413
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1414
		#備註:
1415
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
1416
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
1417
		$callShell=external::callShell($conf["external::callShell"]);
1418
		unset($conf["external::callShell"]);
1419
 
1420
		#如果執行外部程式失敗
1421
		if($callShell["status"]=="false"){
1422
 
1423
			#設置執行錯誤識別
1424
			$result["status"]="false";
1425
 
1426
			#取得錯誤訊息
1427
			$result["error"]=$callShell;
1428
 
1429
			#回傳結果
1430
			return $result;
1431
 
1432
			}#if end
1433
 
1434
		#檢查 $conf["createdTarGzFile"] 的開頭是否為 "/"
1435
		#函式說明:
1436
		#取得字首一樣的字串,並回傳其字串。
1437
		#回傳的結果:
1438
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
1439
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
1440
		#$result["function"],當前執行的函式名稱.
1441
		#$result["error"],錯誤訊息陣列.
1442
		#$result["returnString"],爲符合字首條件的字串內容.
1443
		#必填參數:
1444
		$conf["search"]["getMeetConditionsString"]["checkString"]=$conf["createdTarGzFile"];#要檢查的字串
1445
		$conf["search"]["getMeetConditionsString"]["frontWord"]="/";#用來檢查字首應該要有什麼字串
1446
		#用到的函式:
1447
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
1448
		$serachResult=search::getMeetConditionsString($conf["search"]["getMeetConditionsString"]);
1449
		unset($conf["search"]["getMeetConditionsString"]);
1450
 
1451
		#如果 $serachResult["status"] 等於 "false"
1452
		if($serachResult["status"]=="false"){
1453
 
1454
			#設置執行錯誤識別
1455
			$result["status"]="false";
1456
 
1457
			#取得錯誤訊息
1458
			$result["error"]=$serachResult;
1459
 
1460
			#回傳結果
1461
			return $result;
1462
 
1463
			}#if end
1464
 
1465
		#如果 $serachResult["founded"] 等於 "false"
1466
		if($serachResult["founded"]=="false"){
1467
 
1468
			#那就代表 $conf["createdTarGzFile"] 不是從根目錄開始的路徑位置
1469
			$conf["createdTarGzFile"]=$workingDir."/".$conf["createdTarGzFile"];
1470
 
1471
			}#if end
1472
 
1473
		#儲存輸出檔案的位置
1474
		$result["storePlace"]=$conf["createdTarGzFile"];
1475
 
1476
		#函式說明:
1477
		#移除檔案
1478
		#回傳的結果:
1479
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
1480
		#$result["error"],錯誤訊息陣列
1481
		#$result["warning"],警告訊息陣列
1482
		#$result["function"],當前執行的函式名稱
1483
		#必填參數:
1484
		$conf["fileAccess::delFile"]["fileAddress"]=$deletedTarFile;#要移除檔案的位置
1485
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1486
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
1487
		$del=fileAccess::delFile($conf["fileAccess::delFile"]);
1488
		unset($conf["fileAccess::delFile"]);
1489
 
1490
		#如果 $del["status"] 等於 "false"
1491
		#亦即移除檔案失敗
1492
		if($del["status"]=="false"){
1493
 
1494
			#設置執行錯誤識別
1495
			$result["status"]="false";
1496
 
1497
			#取得錯誤訊息
1498
			$result["error"]=$del;
1499
 
1500
			#回傳結果
1501
			return $result;
1502
 
1503
			}#if end
1504
 
1505
		#執行到這邊可能沒有錯誤了
1506
 
1507
		#設置執行成功
1508
		$result["status"]="true";
1509
 
1510
		#回傳結果
1511
		return $result;
1512
 
1513
		}#function makeTarGzFile end
1514
 
1515
	/*
1516
	#函式說明:
1517
	#將資料夾打包成.zst檔案
1518
	#回傳的結果:
1519
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1520
	#$result["error"],錯誤訊息.
1521
	#$result["function"],當前執行的函式名稱.
1522
	#$result["storePlace"],檔案輸出後的位置與名稱.
1523
	#必填參數:	
1524
	#$conf["target"],字串,要打包的檔案.
1525
	$conf["target"]="";
1526
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1527
	$conf["fileArgu"]=__FILE__;
1528
	#可省略參數:
1529
	#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1530
	$conf["commentsArray"]=array("正透過zstd壓縮");
1531
	#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
1532
	#$conf["newLineBreak"]="false";
1533
	#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.
1534
	#$conf["path"]="./";
1535
	#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.
1536
	#$conf["delAfterSuc"]="false";
1537
	#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.
1538
	#$conf["overwrite"]="true";
1539
	#參考資料:
1540
	#無.
1541
	#備註:
1542
	#無.
1543
	*/
1544
	public static function makeZstFile(&$conf){
1545
 
1546
		#初始化要回傳的內容
1547
		$result=array();
1548
 
1549
		#取得當前函式的名稱
1550
		$result["function"]=__FUNCTION__;
1551
 
1552
		#如果 $conf 不為陣列
1553
		if(gettype($conf)!="array"){
1554
 
1555
			#設置執行失敗
1556
			$result["status"]="false";
1557
 
1558
			#設置執行錯誤訊息
1559
			$result["error"][]="\$conf變數須為陣列形態";
1560
 
1561
			#如果傳入的參數為 null
1562
			if($conf==null){
1563
 
1564
				#設置執行錯誤訊息
1565
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
1566
 
1567
				}#if end
1568
 
1569
			#回傳結果
1570
			return $result;
1571
 
1572
			}#if end
1573
 
1574
		#檢查參數
1575
		#函式說明:
1576
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
1577
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1578
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1579
		#$result["function"],當前執行的函式名稱.
1580
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1581
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1582
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1583
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1584
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1585
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1586
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1587
		#必填寫的參數:
1588
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1589
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1590
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1591
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("target","fileArgu");
1592
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
1593
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
1594
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1595
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1596
		#可以省略的參數:
1597
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1598
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1599
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1600
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","newLineBreak","path","delAfterSuc","overwrite");
1601
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1602
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string","string");
1603
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1604
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true","./","false","false");
1605
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1606
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
1607
		#參考資料來源:
1608
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1609
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1610
		unset($conf["variableCheck::checkArguments"]);
1611
 
1612
		#如果檢查失敗
1613
		if($checkResult["status"]=="false"){
1614
 
1615
			#設置錯誤狀態
1616
			$result["status"]="false";
1617
 
1618
			#設置錯誤提示
1619
			$result["error"]=$checkResult;
1620
 
1621
			#回傳結果
1622
			return $result;
1623
 
1624
			}#if end
1625
 
1626
		#如果檢查不通過
1627
		if($checkResult["passed"]=="false"){
1628
 
1629
			#設置錯誤狀態
1630
			$result["status"]="false";
1631
 
1632
			#設置錯誤提示
1633
			$result["error"]=$checkResult;
1634
 
1635
			#回傳結果
1636
			return $result;
1637
 
1638
			}#if end
1639
 
1640
		#如果 $conf["breakNewLine"] 沒有設置
1641
		if(!isset($conf["breakNewLine"])){
1642
 
1643
			# 將 $conf["breakNewLine"] 設為 "true"
1644
			$conf["breakNewLine"]="true";
1645
 
1646
			}#if end
1647
 
1648
		#針對$commensArray的每個元素
1649
		foreach($conf["commentsArray"] as $comment){
1650
 
1651
			#印出描述
1652
			echo $comment;
1653
 
1654
			#如果 $conf["breakNewLine"] 等於 "true"
1655
			if($conf["breakNewLine"]=="true"){
1656
 
1657
				#印出斷行符號
1658
				echo PHP_EOL;
1659
 
1660
				}#if end
1661
 
1662
			}#foreach end
1663
 
1664
		#初始化儲存要壓縮的檔案名稱與位置
1665
		$inputFile=$conf["target"];
1666
 
1667
		#初始化原始要產生的壓縮檔案位置名稱
1668
		$result["storePlace"]=$conf["target"].".zst";
1669
 
1670
		#如果path不為"/"結束
1671
		if($conf["path"][strlen($conf["path"])-1]!=="/"){
1672
 
1673
			#串接 "/" 到結尾
1674
			$conf["path"]=$conf["path"]."/";
1675
 
1676
			}#if end
1677
 
1678
		#設置產生的檔案位置與名稱
1679
		$result["storePlace"]=$conf["path"].$result["storePlace"];
1680
 
1681
		#設置原始的檔案位置與名稱
1682
		$inputFile=$conf["path"].$inputFile;
1683
 
1684
		#確認檔案有存在
1685
		#函式說明:
1686
		#檢查多個檔案與資料夾是否存在.
1687
		#回傳的結果:
1688
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1689
		#$result["error"],錯誤訊息陣列.
1690
		#$resutl["function"],當前執行的涵式名稱.
1691
		#$result["argu"],使用的參數.
1692
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1693
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1694
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1695
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
1696
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1697
		#必填參數:
1698
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1699
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($result["storePlace"]);
1700
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1701
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
1702
		#可省略參數:
1703
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1704
		#$conf["disableWebSearch"]="false";
1705
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1706
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
1707
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1708
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
1709
		#參考資料來源:
1710
		#http://php.net/manual/en/function.file-exists.php
1711
		#http://php.net/manual/en/control-structures.foreach.php
1712
		#備註:
1713
		#函數file_exists檢查的路徑為檔案系統的路徑
1714
		#$result["varName"][$i]結果未實作
1715
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1716
		unset($conf["fileAccess::checkMultiFileExist"]);
1717
 
1718
		#如果失敗
1719
		if($checkMultiFileExist["status"]==="false"){
1720
 
1721
			#設置執行錯誤識別
1722
			$result["status"]="false";
1723
 
1724
			#取得錯誤訊息
1725
			$result["error"]=$checkMultiFileExist;
1726
 
1727
			#回傳結果
1728
			return $result;
1729
 
1730
			}#if end
1731
 
1732
		#如果壓縮檔已經存在
1733
		if($checkMultiFileExist["allExist"]==="true"){
1734
 
1735
			#如果不要覆蓋既有的檔案
1736
			if($conf["overwrite"]==="false"){
1737
 
1738
				#設置執行錯誤識別
1739
				$result["status"]="false";
1740
 
1741
				#取得錯誤訊息
1742
				$result["error"][]="zst壓縮檔已經存在";
1743
 
1744
				#回傳結果
1745
				return $result;
1746
 
1747
				}#if end
1748
 
1749
			#反之
1750
			else{
1751
 
1752
				#移除已經存在的zst壓縮檔
1753
				#函式說明:
1754
				#移除檔案
1755
				#回傳結果:
1756
				#$result["status"],"true"代表移除成功,"false"代表移除失敗.
1757
				#$result["error"],錯誤訊息陣列.
1758
				#$result["warning"],警告訊息陣列.
1759
				#$result["function"],當前執行的函數名稱.
1760
				#$result["argu"],當前函式使用的參數.
1761
				#必填參數:
1762
				#$conf["fileAddress"],字串,要移除檔案的位置.
1763
				$conf["fileAccess::delFile"]["fileAddress"]=$result["storePlace"];
1764
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1765
				$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
1766
				#可省略參數:
1767
				#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1768
				#$conf["commentsArray"]=array("");
1769
				#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
1770
				#$conf["allowDelSymlink"]="true";
1771
				#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
1772
				#$conf["allowDelFolder"]="true";
1773
				#參考資料:
1774
				#無.
1775
				#備註:
1776
				#無.
1777
				$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
1778
				unset($conf["fileAccess::delFile"]);
1779
 
1780
				#如果執行失敗
1781
				if($delFile["status"]==="false"){
1782
 
1783
					#設置執行錯誤識別
1784
					$result["status"]="false";
1785
 
1786
					#取得錯誤訊息
1787
					$result["error"]=$delFile;
1788
 
1789
					#回傳結果
1790
					return $result;
1791
 
1792
					}#if end
1793
 
1794
				}#else end
1795
 
1796
			}#if end
1797
 
1798
		#函式說明:
1799
		#呼叫shell執行系統命令,並取得回傳的內容.
1800
		#回傳結果:
1801
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1802
		#$result["error"],錯誤訊息陣列.
1803
		#$result["function"],當前執行的函數名稱.
1804
		#$result["argu"],使用的參數.
1805
		#$result["cmd"],執行的指令內容.
1806
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
1807
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
1808
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
1809
		#$result["running"],是否還在執行.
1810
		#$result["pid"],pid.
1811
		#$result["statusCode"],執行結束後的代碼.
1812
		#必填參數:
1813
		#$conf["command"],字串,要執行的指令與.
1814
		$conf["external::callShell"]["command"]="cd";
1815
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1816
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
1817
		#可省略參數:
1818
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1819
		$conf["external::callShell"]["argu"]=array($conf["path"],";","zstd",$conf["target"]);
1820
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1821
		$conf["external::callShell"]["arguIsAddr"]=array("true","false","false","false");
1822
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"".
1823
		#$conf["external::callShell"]["plainArgu"]=array("false","true","true","false");
1824
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1825
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1826
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1827
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1828
		#$conf["enablePrintDescription"]="true";
1829
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
1830
		#$conf["printDescription"]="";
1831
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
1832
		$conf["external::callShell"]["escapeshellarg"]="true";
1833
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
1834
		#$conf["username"]="";
1835
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1836
		#$conf["password"]="";
1837
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
1838
		#$conf["useScript"]="";
1839
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
1840
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1841
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
1842
		#$conf["inBackGround"]="";
1843
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
1844
		#$conf["getErr"]="false";
1845
		#備註:
1846
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
1847
		#參考資料:
1848
		#exec=>http://php.net/manual/en/function.exec.php
1849
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1850
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1851
		$callShell=external::callShell($conf["external::callShell"]);
1852
		unset($conf["external::callShell"]);
1853
 
1854
		#如果執行外部程式失敗
1855
		if($callShell["status"]==="false"){
1856
 
1857
			#設置執行錯誤識別
1858
			$result["status"]="false";
1859
 
1860
			#取得錯誤訊息
1861
			$result["error"]=$callShell;
1862
 
1863
			#回傳結果
1864
			return $result;
1865
 
1866
			}#if end
1867
 
1868
		#確認檔案有存在
1869
		#函式說明:
1870
		#檢查多個檔案與資料夾是否存在.
1871
		#回傳的結果:
1872
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1873
		#$result["error"],錯誤訊息陣列.
1874
		#$resutl["function"],當前執行的涵式名稱.
1875
		#$result["argu"],使用的參數.
1876
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1877
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1878
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1879
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
1880
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1881
		#必填參數:
1882
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1883
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($result["storePlace"]);
1884
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1885
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
1886
		#可省略參數:
1887
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1888
		#$conf["disableWebSearch"]="false";
1889
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1890
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
1891
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1892
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
1893
		#參考資料來源:
1894
		#http://php.net/manual/en/function.file-exists.php
1895
		#http://php.net/manual/en/control-structures.foreach.php
1896
		#備註:
1897
		#函數file_exists檢查的路徑為檔案系統的路徑
1898
		#$result["varName"][$i]結果未實作
1899
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1900
		unset($conf["fileAccess::checkMultiFileExist"]);
1901
 
1902
		#如果失敗
1903
		if($checkMultiFileExist["status"]==="false"){
1904
 
1905
			#設置執行錯誤識別
1906
			$result["status"]="false";
1907
 
1908
			#取得錯誤訊息
1909
			$result["error"]=$checkMultiFileExist;
1910
 
1911
			#回傳結果
1912
			return $result;
1913
 
1914
			}#if end
1915
 
1916
		#如果壓縮檔產生失敗
1917
		if($checkMultiFileExist["allExist"]==="false"){
1918
 
1919
			#設置執行錯誤識別
1920
			$result["status"]="false";
1921
 
1922
			#取得錯誤訊息
1923
			$result["error"]=$checkMultiFileExist;
1924
 
1925
			#回傳結果
1926
			return $result;
1927
 
1928
			}#if end
1929
 
1930
		#如果要移除原始檔案
1931
		if($conf["delAfterSuc"]==="true"){
1932
 
1933
			#函式說明:
1934
			#移除檔案
1935
			#回傳結果:
1936
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
1937
			#$result["error"],錯誤訊息陣列
1938
			#$result["warning"],警告訊息陣列
1939
			#$result["function"],當前執行的函數名稱
1940
			#必填參數:
1941
			#$conf["fileAddress"],字串,要移除檔案的位置.
1942
			$conf["fileAccess::delFile"]["fileAddress"]=$inputFile;
1943
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1944
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
1945
			#可省略參數:
1946
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1947
			#$conf["commentsArray"]=array("");
1948
			#備註:
1949
			#無.
1950
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
1951
			unset($conf["fileAccess::delFile"]);
1952
 
1953
			#如果失敗
1954
			if($delFile["status"]==="false"){
1955
 
1956
				#設置執行錯誤識別
1957
				$result["status"]="false";
1958
 
1959
				#取得錯誤訊息
1960
				$result["error"]=$delFile;
1961
 
1962
				#回傳結果
1963
				return $result;
1964
 
1965
				}#if end
1966
 
1967
			}#if end
1968
 
1969
		#設置執行正常
1970
		$result["status"]="true";
1971
 
1972
		#回傳結果
1973
		return $result;
1974
 
1975
		}#function makeZstFile end
1976
 
1977
	/*
1978
	#函式說明:
1979
	#將資料夾打包成.tar檔案
1980
	#回傳的結果:
1981
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1982
	#$result["error"],錯誤訊息.
1983
	#$result["function"],當前執行的函式名稱.
1984
	#$result["storePlace"],檔案輸出後的位置與名稱.
1985
	#必填參數:
1986
	#$conf["target"],字串,要打包的檔案.
1987
	$conf["target"]="";
1988
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1989
	$conf["fileArgu"]=__FILE__;
1990
	#可省略參數:
1991
	#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1992
	$conf["commentsArray"]=array("正透過tar打包");
1993
	#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
1994
	#$conf["newLineBreak"]="false";
1995
	#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.
1996
	#$conf["path"]="./";
1997
	#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.
1998
	#$conf["delAfterSuc"]="false";
1999
	#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.
2000
	#$conf["overwrite"]="true";
2001
	#參考資料:
2002
	#無.
2003
	#備註:
2004
	#無.
2005
	*/
2006
	public static function makeTarFile(&$conf){
2007
 
2008
		#初始化要回傳的內容
2009
		$result=array();
2010
 
2011
		#取得當前函式的名稱
2012
		$result["function"]=__FUNCTION__;
2013
 
2014
		#如果 $conf 不為陣列
2015
		if(gettype($conf)!="array"){
2016
 
2017
			#設置執行失敗
2018
			$result["status"]="false";
2019
 
2020
			#設置執行錯誤訊息
2021
			$result["error"][]="\$conf變數須為陣列形態";
2022
 
2023
			#如果傳入的參數為 null
2024
			if($conf==null){
2025
 
2026
				#設置執行錯誤訊息
2027
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
2028
 
2029
				}#if end
2030
 
2031
			#回傳結果
2032
			return $result;
2033
 
2034
			}#if end
2035
 
2036
		#檢查參數
2037
		#函式說明:
2038
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
2039
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2040
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2041
		#$result["function"],當前執行的函式名稱.
2042
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2043
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2044
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2045
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2046
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2047
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2048
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2049
		#必填寫的參數:
2050
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2051
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2052
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2053
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("target","fileArgu");
2054
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
2055
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2056
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2057
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2058
		#可以省略的參數:
2059
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2060
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2061
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2062
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","newLineBreak","path","delAfterSuc","overwrite");
2063
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2064
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string","string");
2065
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2066
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true","./","false","false");
2067
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2068
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
2069
		#參考資料來源:
2070
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2071
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2072
		unset($conf["variableCheck::checkArguments"]);
2073
 
2074
		#如果檢查失敗
2075
		if($checkResult["status"]=="false"){
2076
 
2077
			#設置錯誤狀態
2078
			$result["status"]="false";
2079
 
2080
			#設置錯誤提示
2081
			$result["error"]=$checkResult;
2082
 
2083
			#回傳結果
2084
			return $result;
2085
 
2086
			}#if end
2087
 
2088
		#如果檢查不通過
2089
		if($checkResult["passed"]=="false"){
2090
 
2091
			#設置錯誤狀態
2092
			$result["status"]="false";
2093
 
2094
			#設置錯誤提示
2095
			$result["error"]=$checkResult;
2096
 
2097
			#回傳結果
2098
			return $result;
2099
 
2100
			}#if end
2101
 
2102
		#如果 $conf["breakNewLine"] 沒有設置
2103
		if(!isset($conf["breakNewLine"])){
2104
 
2105
			# 將 $conf["breakNewLine"] 設為 "true"
2106
			$conf["breakNewLine"]="true";
2107
 
2108
			}#if end
2109
 
2110
		#如果需要輸出提示
2111
		if(isset($conf["commentsArray"])){
2112
 
2113
			#針對$commensArray的每個元素
2114
			foreach($conf["commentsArray"] as $comment){
2115
 
2116
				#印出描述
2117
				echo $comment;
2118
 
2119
				#如果 $conf["breakNewLine"] 等於 "true"
2120
				if($conf["breakNewLine"]=="true"){
2121
 
2122
					#印出斷行符號
2123
					echo PHP_EOL;
2124
 
2125
					}#if end
2126
 
2127
				}#foreach end
2128
 
2129
			}#if end
2130
 
2131
		#初始化儲存要壓縮的檔案名稱與位置
2132
		$inputFile=$conf["target"];
2133
 
2134
		#初始化原始要產生的壓縮檔案位置名稱
2135
		$result["storePlace"]=$conf["target"].".tar";
2136
 
2137
		#如果路徑不是 "./" 也不是 "../"
2138
		if($conf["path"]!=="./" && $conf["path"]!=="../"){
2139
 
2140
			#檔案位置與名稱前面加上"/"
2141
			$result["storePlace"]="/".$result["storePlace"];
2142
 
2143
			#檔案位置與名稱前面加上"/"
2144
			$inputFile="/".$inputFile;
2145
 
2146
			}#if end
2147
 
2148
		#設置產生的檔案位置與名稱
2149
		$result["storePlace"]=$conf["path"].$result["storePlace"];
2150
 
2151
		#設置原始的檔案位置與名稱
2152
		$inputFile=$conf["path"].$inputFile;
2153
 
2154
		#確認檔案有存在
2155
		#函式說明:
2156
		#檢查多個檔案與資料夾是否存在.
2157
		#回傳的結果:
2158
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2159
		#$result["error"],錯誤訊息陣列.
2160
		#$resutl["function"],當前執行的涵式名稱.
2161
		#$result["argu"],使用的參數.
2162
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
2163
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
2164
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
2165
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
2166
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2167
		#必填參數:
2168
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
2169
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($result["storePlace"]);
2170
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2171
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
2172
		#可省略參數:
2173
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
2174
		#$conf["disableWebSearch"]="false";
2175
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
2176
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
2177
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
2178
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
2179
		#參考資料來源:
2180
		#http://php.net/manual/en/function.file-exists.php
2181
		#http://php.net/manual/en/control-structures.foreach.php
2182
		#備註:
2183
		#函數file_exists檢查的路徑為檔案系統的路徑
2184
		#$result["varName"][$i]結果未實作
2185
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
2186
		unset($conf["fileAccess::checkMultiFileExist"]);
2187
 
2188
		#如果失敗
2189
		if($checkMultiFileExist["status"]==="false"){
2190
 
2191
			#設置執行錯誤識別
2192
			$result["status"]="false";
2193
 
2194
			#取得錯誤訊息
2195
			$result["error"]=$checkMultiFileExist;
2196
 
2197
			#回傳結果
2198
			return $result;
2199
 
2200
			}#if end
2201
 
2202
		#如果壓縮檔已經存在
2203
		if($checkMultiFileExist["allExist"]==="true"){
2204
 
2205
			#如果不要覆蓋既有的檔案
2206
			if($conf["overwrite"]==="false"){
2207
 
2208
				#設置執行錯誤識別
2209
				$result["status"]="false";
2210
 
2211
				#取得錯誤訊息
2212
				$result["error"][]="tar檔已經存在";
2213
 
2214
				#回傳結果
2215
				return $result;
2216
 
2217
				}#if end
2218
 
2219
			#反之
2220
			else{
2221
 
2222
				#移除已經存在的zst壓縮檔
2223
				#函式說明:
2224
				#移除檔案
2225
				#回傳結果:
2226
				#$result["status"],"true"代表移除成功,"false"代表移除失敗.
2227
				#$result["error"],錯誤訊息陣列.
2228
				#$result["warning"],警告訊息陣列.
2229
				#$result["function"],當前執行的函數名稱.
2230
				#$result["argu"],當前函式使用的參數.
2231
				#必填參數:
2232
				#$conf["fileAddress"],字串,要移除檔案的位置.
2233
				$conf["fileAccess::delFile"]["fileAddress"]=$result["storePlace"];
2234
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
2235
				$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
2236
				#可省略參數:
2237
				#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
2238
				#$conf["commentsArray"]=array("");
2239
				#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
2240
				#$conf["allowDelSymlink"]="true";
2241
				#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
2242
				#$conf["allowDelFolder"]="true";
2243
				#參考資料:
2244
				#無.
2245
				#備註:
2246
				#無.
2247
				$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
2248
				unset($conf["fileAccess::delFile"]);
2249
 
2250
				#如果執行失敗
2251
				if($delFile["status"]==="false"){
2252
 
2253
					#設置執行錯誤識別
2254
					$result["status"]="false";
2255
 
2256
					#取得錯誤訊息
2257
					$result["error"]=$delFile;
2258
 
2259
					#回傳結果
2260
					return $result;
2261
 
2262
					}#if end
2263
 
2264
				}#else end
2265
 
2266
			}#if end
2267
 
2268
		#函式說明:
2269
		#呼叫shell執行系統命令,並取得回傳的內容.
2270
		#回傳結果:
2271
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2272
		#$result["error"],錯誤訊息陣列.
2273
		#$result["function"],當前執行的函數名稱.
2274
		#$result["argu"],使用的參數.
2275
		#$result["cmd"],執行的指令內容.
2276
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
2277
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
2278
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
2279
		#$result["running"],是否還在執行.
2280
		#$result["pid"],pid.
2281
		#$result["statusCode"],執行結束後的代碼.
2282
		#必填參數:
2283
		#$conf["command"],字串,要執行的指令與.
2284
		$conf["external::callShell"]["command"]="cd";
2285
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2286
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
2287
		#可省略參數:
2288
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
2289
		$conf["external::callShell"]["argu"]=array($conf["path"],";","tar","-c","-v","-f",$conf["target"].".tar",$conf["target"]);
2290
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
2291
		$conf["external::callShell"]["arguIsAddr"]=array("true","false","false","false","false","false","false","false");
2292
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"".
2293
		#$conf["external::callShell"]["plainArgu"]=array("false","true","true","false");
2294
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
2295
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
2296
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
2297
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2298
		#$conf["enablePrintDescription"]="true";
2299
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
2300
		#$conf["printDescription"]="";
2301
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
2302
		$conf["external::callShell"]["escapeshellarg"]="true";
2303
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
2304
		#$conf["username"]="";
2305
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2306
		#$conf["password"]="";
2307
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
2308
		#$conf["useScript"]="";
2309
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
2310
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
2311
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
2312
		#$conf["inBackGround"]="";
2313
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
2314
		#$conf["getErr"]="false";
2315
		#備註:
2316
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
2317
		#參考資料:
2318
		#exec=>http://php.net/manual/en/function.exec.php
2319
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2320
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2321
		$callShell=external::callShell($conf["external::callShell"]);
2322
		unset($conf["external::callShell"]);
2323
 
2324
		#如果執行外部程式失敗
2325
		if($callShell["status"]==="false"){
2326
 
2327
			#設置執行錯誤識別
2328
			$result["status"]="false";
2329
 
2330
			#取得錯誤訊息
2331
			$result["error"]=$callShell;
2332
 
2333
			#回傳結果
2334
			return $result;
2335
 
2336
			}#if end
2337
 
2338
		#確認檔案有存在
2339
		#函式說明:
2340
		#檢查多個檔案與資料夾是否存在.
2341
		#回傳的結果:
2342
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2343
		#$result["error"],錯誤訊息陣列.
2344
		#$resutl["function"],當前執行的涵式名稱.
2345
		#$result["argu"],使用的參數.
2346
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
2347
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
2348
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
2349
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
2350
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2351
		#必填參數:
2352
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
2353
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($result["storePlace"]);
2354
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2355
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
2356
		#可省略參數:
2357
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
2358
		#$conf["disableWebSearch"]="false";
2359
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
2360
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
2361
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
2362
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
2363
		#參考資料來源:
2364
		#http://php.net/manual/en/function.file-exists.php
2365
		#http://php.net/manual/en/control-structures.foreach.php
2366
		#備註:
2367
		#函數file_exists檢查的路徑為檔案系統的路徑
2368
		#$result["varName"][$i]結果未實作
2369
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
2370
		unset($conf["fileAccess::checkMultiFileExist"]);
2371
 
2372
		#如果失敗
2373
		if($checkMultiFileExist["status"]==="false"){
2374
 
2375
			#設置執行錯誤識別
2376
			$result["status"]="false";
2377
 
2378
			#取得錯誤訊息
2379
			$result["error"]=$checkMultiFileExist;
2380
 
2381
			#回傳結果
2382
			return $result;
2383
 
2384
			}#if end
2385
 
2386
		#如果壓縮檔產生失敗
2387
		if($checkMultiFileExist["allExist"]==="false"){
2388
 
2389
			#設置執行錯誤識別
2390
			$result["status"]="false";
2391
 
2392
			#取得錯誤訊息
2393
			$result["error"]=$checkMultiFileExist;
2394
 
2395
			#回傳結果
2396
			return $result;
2397
 
2398
			}#if end
2399
 
2400
		#如果要移除原始檔案
2401
		if($conf["delAfterSuc"]==="true"){
2402
 
2403
			#函式說明:
2404
			#移除檔案
2405
			#回傳結果:
2406
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
2407
			#$result["error"],錯誤訊息陣列
2408
			#$result["warning"],警告訊息陣列
2409
			#$result["function"],當前執行的函數名稱
2410
			#必填參數:
2411
			#$conf["fileAddress"],字串,要移除檔案的位置.
2412
			$conf["fileAccess::delFile"]["fileAddress"]=$inputFile;
2413
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
2414
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
2415
			#可省略參數:
2416
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
2417
			#$conf["commentsArray"]=array("");
2418
			#備註:
2419
			#無.
2420
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
2421
			unset($conf["fileAccess::delFile"]);
2422
 
2423
			#如果失敗
2424
			if($delFile["status"]==="false"){
2425
 
2426
				#設置執行錯誤識別
2427
				$result["status"]="false";
2428
 
2429
				#取得錯誤訊息
2430
				$result["error"]=$delFile;
2431
 
2432
				#回傳結果
2433
				return $result;
2434
 
2435
				}#if end
2436
 
2437
			}#if end
2438
 
2439
		#設置執行正常
2440
		$result["status"]="true";
2441
 
2442
		#回傳結果
2443
		return $result;
2444
 
2445
		}#function makeTarFile end
2446
 
2447
	/*
2448
	#函式說明:
2449
	#將資料夾打包成.tar.zst檔案
2450
	#回傳的結果:
2451
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2452
	#$result["error"],錯誤訊息.
2453
	#$result["function"],當前執行的函式名稱.
2454
	#$result["storePlace"],檔案輸出後的位置與名稱.
2455
	#必填參數:
2456
	#$conf["target"],字串,要打包的檔案.
2457
	$conf["target"]="";
2458
	#可省略參數:
2459
	#$conf["commentsArrayForTar"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述,預設為array("正產生 tar 檔案");
2460
	#$conf["commentsArrayForTar"]=array("正產生 tar 檔案");
2461
	#$conf["commentsArrayForZst"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述,預設為array("正產生 zst 檔案");
2462
	#$conf["commentsArrayForZst"]=array("正產生 zst 檔案");
2463
	#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
2464
	#$conf["newLineBreak"]="false";
2465
	#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.
2466
	#$conf["path"]="./";
2467
	#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.
2468
	#$conf["delAfterSuc"]="false";
2469
	#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.
2470
	#$conf["overwrite"]="true";
2471
	#參考資料:
2472
	#無.
2473
	#備註:
2474
	#無.
2475
	*/
2476
	public static function makeTarZstFile(&$conf){
2477
 
2478
		#初始化要回傳的結果
2479
		$result=array();
2480
 
2481
		#取得當前執行的函數名稱
2482
		$result["function"]=__FUNCTION__;
2483
 
2484
		#如果沒有參數
2485
		if(func_num_args()==0){
2486
 
2487
			#設置執行失敗
2488
			$result["status"]="false";
2489
 
2490
			#設置執行錯誤訊息
2491
			$result["error"]="函數".$result["function"]."需要參數";
2492
 
2493
			#回傳結果
2494
			return $result;
2495
 
2496
			}#if end
2497
 
2498
		#取得參數
2499
		$result["argu"]=$conf;
2500
 
2501
		#如果 $conf 不為陣列
2502
		if(gettype($conf)!=="array"){
2503
 
2504
			#設置執行失敗
2505
			$result["status"]="false";
2506
 
2507
			#設置執行錯誤訊息
2508
			$result["error"][]="\$conf變數須為陣列形態";
2509
 
2510
			#如果傳入的參數為 null
2511
			if(is_null($conf)){
2512
 
2513
				#設置執行錯誤訊息
2514
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2515
 
2516
				}#if end
2517
 
2518
			#回傳結果
2519
			return $result;
2520
 
2521
			}#if end
2522
 
2523
		#函式說明:
2524
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2525
		#回傳結果:
2526
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2527
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2528
		#$result["simpleError"],簡單表示的錯誤訊息.
2529
		#$result["function"],當前執行的函式名稱.
2530
		#$result["argu"],設置給予的參數.
2531
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2532
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2533
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2534
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
2535
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
2536
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2537
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2538
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2539
		#必填參數:
2540
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2541
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2542
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2543
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2544
		#可省略參數:
2545
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2546
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("target");
2547
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
2548
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
2549
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
2550
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2551
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
2552
		#$conf["canNotBeEmpty"]=array();
2553
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
2554
		#$conf["canBeEmpty"]=array();
2555
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2556
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2557
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2558
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArrayForTar","commentsArrayForZst","newLineBreak","path","delAfterSuc","overwrite");
2559
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2560
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","string","string","string","string");
2561
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2562
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"true","./","false","false");
2563
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
2564
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
2565
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
2566
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";
2567
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2568
		#$conf["arrayCountEqualCheck"][]=array();
2569
		#參考資料:
2570
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2571
		#備註:
2572
		#無.
2573
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2574
		unset($conf["variableCheck::checkArguments"]);
2575
 
2576
		#如果 $checkArguments["status"] 等於 "false"
2577
		if($checkArguments["status"]==="false"){
2578
 
2579
			#設置執行錯誤識別
2580
			$result["status"]="false";
2581
 
2582
			#取得錯誤訊息
2583
			$result["error"]=$checkArguments;
2584
 
2585
			#回傳結果
2586
			return $result;
2587
 
2588
			}#if end
2589
 
2590
		#如果 $checkArguments["passed"] 等於 "false"
2591
		if($checkArguments["passed"]==="false"){
2592
 
2593
			#設置執行錯誤識別
2594
			$result["status"]="false";
2595
 
2596
			#取得錯誤訊息
2597
			$result["error"]=$checkArguments;
2598
 
2599
			#回傳結果
2600
			return $result;
2601
 
2602
			}#if end
2603
 
2604
		#函式說明:
2605
		#將資料夾打包成.tar檔案
2606
		#回傳的結果:
2607
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2608
		#$result["error"],錯誤訊息.
2609
		#$result["function"],當前執行的函式名稱.
2610
		#$result["storePlace"],檔案輸出後的位置與名稱.
2611
		#必填參數:
2612
		#$conf["target"],字串,要打包的檔案.
2613
		$conf["cmd::makeTarFile"]["target"]=$conf["target"];
2614
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
2615
		$conf["cmd::makeTarFile"]["fileArgu"]=__FILE__;
2616
		#可省略參數:
2617
 
2618
		#如果有設置 $conf["commentsArrayForTar"]
2619
		if(isset($conf["commentsArrayForTar"])){
2620
 
2621
			#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
2622
			$conf["cmd::makeTarFile"]["commentsArray"]=$conf["commentsArrayForTar"];
2623
 
2624
			}#if end
2625
 
2626
		#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
2627
		$conf["cmd::makeTarFile"]["newLineBreak"]=$conf["newLineBreak"];
2628
		#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.
2629
		$conf["cmd::makeTarFile"]["path"]=$conf["path"];
2630
		#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.
2631
		$conf["cmd::makeTarFile"]["delAfterSuc"]=$conf["delAfterSuc"];
2632
		#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.
2633
		$conf["cmd::makeTarFile"]["overwrite"]=$conf["overwrite"];
2634
		#參考資料:
2635
		#無.
2636
		#備註:
2637
		#無.
2638
		$makeTarFile=cmd::makeTarFile($conf["cmd::makeTarFile"]);
2639
		unset($conf["cmd::makeTarFile"]);
2640
 
2641
		#如果 $makeTarFile["status"] 等於 "false"
2642
		if($makeTarFile["status"]==="false"){
2643
 
2644
			#設置執行錯誤識別
2645
			$result["status"]="false";
2646
 
2647
			#取得錯誤訊息
2648
			$result["error"]=$makeTarFile;
2649
 
2650
			#回傳結果
2651
			return $result;
2652
 
2653
			}#if end
2654
 
2655
		#函式說明:
2656
		#將資料夾打包成.zst檔案
2657
		#回傳的結果:
2658
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2659
		#$result["error"],錯誤訊息.
2660
		#$result["function"],當前執行的函式名稱.
2661
		#$result["storePlace"],檔案輸出後的位置與名稱.
2662
		#必填參數:
2663
		#$conf["target"],字串,要打包的檔案.
2664
		$conf["cmd::makeZstFile"]["target"]=$conf["target"].".tar";
2665
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
2666
		$conf["cmd::makeZstFile"]["fileArgu"]=__FILE__;
2667
		#可省略參數:
2668
 
2669
		#如果有設置 $conf["commentsArrayForZst"]
2670
		if(isset($conf["commentsArrayForZst"])){
2671
 
2672
			#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
2673
			$conf["cmd::makeZstFile"]["commentsArray"]=$conf["commentsArrayForZst"];
2674
 
2675
			}#if end
2676
 
2677
		#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
2678
		$conf["cmd::makeZstFile"]["newLineBreak"]=$conf["newLineBreak"];
2679
		#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.
2680
		$conf["cmd::makeZstFile"]["path"]=$conf["path"];
2681
		#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.
2682
		$conf["cmd::makeZstFile"]["delAfterSuc"]=$conf["delAfterSuc"];
2683
		#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.
2684
		$conf["cmd::makeZstFile"]["overwrite"]=$conf["overwrite"];
2685
		#參考資料:
2686
		#無.
2687
		#備註:
2688
		#無.
2689
		$makeZstFile=cmd::makeZstFile($conf["cmd::makeZstFile"]);
2690
		unset($conf["cmd::makeZstFile"]);
2691
 
2692
		#如果 $makeZstFile["status"] 等於 "false"
2693
		if($makeZstFile["status"]==="false"){
2694
 
2695
			#設置執行錯誤識別
2696
			$result["status"]="false";
2697
 
2698
			#取得錯誤訊息
2699
			$result["error"]=$makeZstFile;
2700
 
2701
			#回傳結果
2702
			return $result;
2703
 
2704
			}#if end
2705
 
2706
		#取得壓縮好的檔案路徑與名稱
2707
		$result["content"]=$makeZstFile["storePlace"];
2708
 
2709
		#設置執行正常
2710
		$result["status"]="true";
2711
 
2712
		#回傳結果
2713
		return $result;
2714
 
2715
		}#function makeTarZstFile end
2716
 
2717
	/*
2718
	#函式說明:
2719
	#移動檔案並重新命名,過程會提供提示說明.
2720
	#回傳的結果:
2721
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2722
	#$result["error"],錯誤訊息.
2723
	#$result["function"],當前執行的函式名稱.
2724
	#必填參數:
2725
	#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
2726
	$conf["commentsArray"]=array("正在移動");
2727
	#$conf["movedFilePositionAndName"],字串,為想要移動的檔案位置與名稱.
2728
	$conf["movedFilePositionAndName"]="";
2729
	#$conf["movedTargetFileAndName"],字串,要移動到的位置與新檔案名稱.
2730
	$conf["movedTargetFileAndName"]="";
2731
	#可省略參數:
2732
	#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
2733
	#$conf["newLineBreak"]="false";
2734
	#參考資料:
2735
	#rename函式用法
2736
	#http://php.net/manual/en/function.rename.php
2737
	#備註:
2738
	#無.
2739
	*/
2740
	public static function mv($conf){
2741
 
2742
		#初始化要回傳的內容
2743
		$result=array();
2744
 
2745
		#取得當前函式的名稱
2746
		$result["function"]=__FUNCTION__;
2747
 
2748
		#如果 $conf 不為陣列
2749
		if(gettype($conf)!="array"){
2750
 
2751
			#設置執行失敗
2752
			$result["status"]="false";
2753
 
2754
			#設置執行錯誤訊息
2755
			$result["error"][]="\$conf變數須為陣列形態";
2756
 
2757
			#如果傳入的參數為 null
2758
			if($conf==null){
2759
 
2760
				#設置執行錯誤訊息
2761
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
2762
 
2763
				}#if end
2764
 
2765
			#回傳結果
2766
			return $result;
2767
 
2768
			}#if end
2769
 
2770
		#函式說明:
2771
		#函式說明:
2772
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
2773
		#回傳的結果:
2774
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2775
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2776
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2777
		#必填寫的參數:
2778
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
2779
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("commentsArray","movedFilePositionAndName","movedTargetFileAndName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
2780
		#可以省略的參數:
2781
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("array","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
2782
		#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
2783
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
2784
		unset($conf["variableCheck"]["isexistMuti"]);
2785
 
2786
		#如果 $checkResult["status"] 等於 "false"
2787
		if($checkResult["status"]==="false"){
2788
 
2789
			#設置執行錯誤識別
2790
			$result["status"]="false";
2791
 
2792
			#取得錯誤訊息
2793
			$result["error"]=$checkResult;
2794
 
2795
			#回傳結果
2796
			return $result;
2797
 
2798
			}#if end
2799
 
2800
		#如果 $checkResult["passed"] 等於 "false"
2801
		if($checkResult["passed"]==="false"){
2802
 
2803
			#設置執行錯誤識別
2804
			$result["status"]="false";
2805
 
2806
			#取得錯誤訊息
2807
			$result["error"]=$checkResult;
2808
 
2809
			#回傳結果
2810
			return $result;
2811
 
2812
			}#if end
2813
 
2814
		#如果 $conf["breakNewLine"] 沒有設置
2815
		if(!isset($conf["breakNewLine"])){
2816
 
2817
			# 將 $conf["breakNewLine"] 設為 "true"
2818
			$conf["breakNewLine"]="true";
2819
 
2820
			}#if end
2821
 
2822
		#針對$commensArray的每個元素
2823
		foreach($conf["commentsArray"] as $comment){
2824
 
2825
			#印出描述
2826
			echo $comment;
2827
 
2828
			#如果 $conf["breakNewLine"] 等於 "true"
2829
			if($conf["breakNewLine"]==="true"){
2830
 
2831
				#印出斷行符號
2832
				echo "\n";
2833
 
2834
				}#if end
2835
 
2836
			}#foreach end
2837
 
2838
		#重新命名檔案
2839
		#回傳結果為 TRUE 的話
2840
		if(rename($conf["movedFilePositionAndName"],$conf["movedTargetFileAndName"])==TRUE){
2841
 
2842
			#代表檔案移動、重新命名成功
2843
 
2844
			#設置執行正常
2845
			$result["status"]="true";
2846
 
2847
			#回傳結果
2848
			return $result;
2849
 
2850
			}#if end
2851
 
2852
		#反之代表移動、重新命名失敗
2853
		else{
2854
 
2855
			#設置執行失敗
2856
			$result["status"]="false";
2857
 
2858
			#設置錯誤訊息
2859
			$result["error"][]="移動、重新命名失敗";
2860
 
2861
			#回傳結果
2862
			return $result;
2863
 
2864
			}#else end
2865
 
2866
		#執行到這邊代表不正常
2867
 
2868
		#設置執行失敗
2869
		$result["status"]="false";
2870
 
2871
		#設置錯誤訊息
2872
		$result["error"][]="不應該出現的例外";
2873
 
2874
		#回傳結果
2875
		return $result;
2876
 
2877
		}#function mv end
2878
 
2879
	/*
2880
	#函式說明:
2881
	#檢查是否為相對路徑,並將之轉換為絕對路徑
2882
	#回傳的結果:
2883
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2884
	#$result["function"],當前執行的函式名稱.
2885
	#$result["error"],錯誤訊息.
2886
	#$result["absolutePath"],轉換好的路徑檔案字串.
2887
	#必填參數:
2888
	#$conf["checkedPath"],字串,要檢查是不是絕對路徑的路徑檔案字串.
2889
	$conf["checkedPath"]="";
2890
	#可省略參數:
2891
	#無.
2892
	#參考資料:
2893
	#無.
2894
	#備註:
2895
	#無.
2896
	*/
2897
	public static function changeToAbsolutePath($conf){
2898
 
2899
		#初始化要回傳的內容
2900
		$result=array();
2901
 
2902
		#取得當前函式的名稱
2903
		$result["function"]=__FUNCTION__;
2904
 
2905
		#如果 $conf 不為陣列
2906
		if(gettype($conf)!="array"){
2907
 
2908
			#設置執行失敗
2909
			$result["status"]="false";
2910
 
2911
			#設置執行錯誤訊息
2912
			$result["error"][]="\$conf變數須為陣列形態";
2913
 
2914
			#如果傳入的參數為 null
2915
			if($conf==null){
2916
 
2917
				#設置執行錯誤訊息
2918
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
2919
 
2920
				}#if end
2921
 
2922
			#回傳結果
2923
			return $result;
2924
 
2925
			}#if end
2926
 
2927
		#函式說明:
2928
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
2929
		#回傳的結果:
2930
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2931
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2932
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2933
		#必填寫的參數:
2934
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
2935
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("checkedPath");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
2936
		#可以省略的參數:
2937
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
2938
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
2939
		#備註:
2940
		#功能與checkExistAndType函式相同
2941
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
2942
		unset($conf["variableCheck"]["isexistMuti"]);
2943
 
2944
		#如果 $checkResult["status"] 等於 "false"
2945
		if($checkResult["status"]=="false"){
2946
 
2947
			#設置執行錯誤識別
2948
			$result["status"]="false";
2949
 
2950
			#取得錯誤訊息
2951
			$result["error"]=$checkResult;
2952
 
2953
			#回傳結果
2954
			return $result;
2955
 
2956
			}#if end
2957
 
2958
		#如果 $checkResult["passed"] 等於 "false"
2959
		if($checkResult["passed"]=="false"){
2960
 
2961
			#設置執行錯誤識別
2962
			$result["status"]="false";
2963
 
2964
			#取得錯誤訊息
2965
			$result["error"]=$checkResult;
2966
 
2967
			#回傳結果
2968
			return $result;
2969
 
2970
			}#if end
2971
 
2972
		#取得當前的工作目錄
2973
		$workingDir=$_SERVER["PWD"];
2974
 
2975
		#檢查 $conf["checkedPath"] 的開頭是否為 "/"
2976
		#函式說明:
2977
		#取得字首一樣的字串,並回傳其字串。
2978
		#回傳的結果:
2979
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
2980
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
2981
		#$result["function"],當前執行的函式名稱.
2982
		#$result["error"],錯誤訊息陣列.
2983
		#$result["returnString"],爲符合字首條件的字串內容。
2984
		#必填參數:
2985
		$conf["search"]["getMeetConditionsString"]["checkString"]=$conf["checkedPath"];#要檢查的字串
2986
		$conf["search"]["getMeetConditionsString"]["frontWord"]="/";#用來檢查字首應該要有什麼字串
2987
		#用到的函式:
2988
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
2989
		$serachResult=search::getMeetConditionsString($conf["search"]["getMeetConditionsString"]);
2990
		unset($conf["search"]["getMeetConditionsString"]);
2991
 
2992
		#如果執行search::getMeetConditionsString失敗
2993
		if($serachResult["status"]=="false"){
2994
 
2995
			#設置執行錯誤識別
2996
			$result["status"]="false";
2997
 
2998
			#取得錯誤訊息
2999
			$result["error"]=$serachResult;
3000
 
3001
			#回傳結果
3002
			return $result;
3003
 
3004
			}#if end
3005
 
3006
		#如果 $serachResult["founded"] 等於 "false"
3007
		if($serachResult["founded"]=="false"){
3008
 
3009
			#那就代表 $conf["checkedPath"] 不是從根目錄開始的路徑位置
3010
			$conf["checkedPath"]=$workingDir."/".$conf["checkedPath"];
3011
 
3012
			}#if end
3013
 
3014
		#執行到這邊算是執行成功
3015
 
3016
		#設置執行成功的識別
3017
		$result["status"]="true";
3018
 
3019
		#設置轉換好的檔案目錄絕對路徑字串
3020
		$result["absolutePath"]=$conf["checkedPath"];
3021
 
3022
		#回傳結果
3023
		return $result;
3024
 
3025
		}#function changeToAbsolutePath end
3026
 
3027
	/*
3028
	#函式說明:
3029
	#檢查多個路徑字串是否為相對路徑,並將之轉換為絕對路徑
3030
	#回傳的結果:
3031
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3032
	#$result["error"],錯誤訊息.
3033
	#$result["function"],當前執行的函式名稱.
3034
	#$result["absolutePath"][$i],為轉換好的第$i+1個路徑檔案陣列字串.
3035
	#必填參數:
3036
	#$conf["checkedPathArray"],字串陣列,要檢查是不是絕對路徑的路徑檔案字串陣列.
3037
	$conf["checkedPathArray"]=array("");
3038
	#可省略參數:
3039
	#無.
3040
	#參考資料:
3041
	#無.
3042
	#備註:
3043
	#無.
3044
	*/
3045
	public static function changeMultiToAbsolutePath($conf){
3046
 
3047
		#初始化要回傳的內容
3048
		$result=array();
3049
 
3050
		#取得當前執行的函式名稱
3051
		$result["function"]=__FUNCTION__;
3052
 
3053
		#如果 $conf 不為陣列
3054
		if(gettype($conf)!="array"){
3055
 
3056
			#設置執行失敗
3057
			$result["status"]="false";
3058
 
3059
			#設置執行錯誤訊息
3060
			$result["error"][]="\$conf變數須為陣列形態";
3061
 
3062
			#如果傳入的參數為 null
3063
			if($conf==null){
3064
 
3065
				#設置執行錯誤訊息
3066
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
3067
 
3068
				}#if end
3069
 
3070
			#回傳結果
3071
			return $result;
3072
 
3073
			}#if end
3074
 
3075
		#函式說明:
3076
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
3077
		#回傳的結果:
3078
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3079
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3080
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3081
		#必填寫的參數:
3082
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
3083
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("checkedPathArray");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
3084
		#可以省略的參數:
3085
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3086
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
3087
		#備註:
3088
		#功能與checkExistAndType函式相同
3089
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
3090
		unset($conf["variableCheck"]["isexistMuti"]);
3091
 
3092
		#如果 $checkResult["status"] 等於 "false"
3093
		if($checkResult["status"]=="false"){
3094
 
3095
			#設置執行錯誤識別
3096
			$result["status"]="false";
3097
 
3098
			#取得錯誤訊息
3099
			$result["error"]=$checkResult;
3100
 
3101
			#回傳結果
3102
			return $result;
3103
 
3104
			}#if end
3105
 
3106
		#如果 $checkResult["passed"] 等於 "false"
3107
		if($checkResult["passed"]=="fssle"){
3108
 
3109
			#設置執行錯誤識別
3110
			$result["status"]="false";
3111
 
3112
			#取得錯誤訊息
3113
			$result["error"]=$checkResult;
3114
 
3115
			#回傳結果
3116
			return $result;
3117
 
3118
			}#if end
3119
 
3120
		#有幾個 $conf["checkedPathArray"] 就執行幾次
3121
		for($i=0;$i<count($conf["checkedPathArray"]);$i++){
3122
 
3123
			#函式說明:
3124
			#檢查是否為相對路徑,並將之轉換為絕對路徑
3125
			#回傳的結果:
3126
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3127
			#$result["error"],錯誤訊息.
3128
			#$result["absolutePath"],轉換好的路徑檔案字串.
3129
			#必填參數:
3130
			#$conf["checkedPath"],字串,要檢查是不是絕對路徑的路徑檔案字串.
3131
			$conf["cmd"]["changeToAbsolutePath"]["checkedPath"]=$conf["checkedPathArray"][$i];
3132
			$processedPath=cmd::changeToAbsolutePath($conf["cmd"]["changeToAbsolutePath"]);
3133
			unset($conf["cmd"]["changeToAbsolutePath"]);
3134
 
3135
			#如果 cmd::changeToAbsolutePath 執行失敗
3136
			if($processedPath["status"]=="false"){
3137
 
3138
				#設置執行錯誤識別
3139
				$result["status"]="false";
3140
 
3141
				#取得錯誤訊息
3142
				$result["error"]=$processedPath;
3143
 
3144
				#回傳結果
3145
				return $result;
3146
 
3147
				}#if end
3148
 
3149
			#設置轉換好的檔案目錄絕對路徑字串
3150
			$result["absolutePath"][$i]=$processedPath["absolutePath"];
3151
 
3152
			}#for end
3153
 
3154
		#執行到這邊算是執行成功
3155
 
3156
		#設置執行成功的識別
3157
		$result["status"]="true";
3158
 
3159
		#回傳結果
3160
		return $result;
3161
 
3162
		}#function changeMultiToAbsolutePath end
3163
 
3164
	/*
3165
	#函式說明:
3166
	#將資料夾打包成iso檔
3167
	#回傳的結果:
3168
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3169
	#$result["error"],錯誤訊息.
3170
	#$result["function"],當前執行的函式名稱.
3171
	#$result["storePlace"],檔案輸出後的位置與名稱.
3172
	#$result["execStr"],建立iso檔時所使用的系統呼叫指令內容字串.
3173
	#必填參數:
3174
	#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
3175
	$conf["commentsArray"]=array("正在製作iso檔");
3176
	#$conf["targetInRoot"],字串陣列,要放在iso檔根目錄底下的多個檔案位置,array("*")代表目錄底下的所有檔案目錄.
3177
	$conf["targetInRoot"]=array("");
3178
	#$conf["createdIsoFile"],字串,打包好的檔案要放在哪裡,副檔名「.iso」會自動加上.
3179
	$conf["createdIsoFile"]="";
3180
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3181
	$conf["fileArgu"]=__FILE__;
3182
	#可省略參數:
3183
	#$conf["folderInRoot"],字串陣列,要放在iso檔根目錄底下的資料夾
3184
	#$conf["folderInRoot"]=array();
3185
	#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
3186
	#$conf["newLineBreak"]="false";
3187
	#參考資料:
3188
	#無.
3189
	#備註:
3190
	#無.
3191
	*/
3192
	public static function packetToISO(&$conf){
3193
 
3194
		#初始化要回傳的內容
3195
		$result=array();
3196
 
3197
		#取得當前函式的名稱
3198
		$result["function"]=__FUNCTION__;
3199
 
3200
		#如果 $conf 不為陣列
3201
		if(gettype($conf)!="array"){
3202
 
3203
			#設置執行失敗
3204
			$result["status"]="false";
3205
 
3206
			#設置執行錯誤訊息
3207
			$result["error"][]="\$conf變數須為陣列形態";
3208
 
3209
			#如果傳入的參數為 null
3210
			if($conf==null){
3211
 
3212
				#設置執行錯誤訊息
3213
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
3214
 
3215
				}#if end
3216
 
3217
			#回傳結果
3218
			return $result;
3219
 
3220
			}#if end
3221
 
3222
		#檢查參數
3223
		#函式說明:
3224
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
3225
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3226
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3227
		#$result["function"],當前執行的函式名稱.
3228
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3229
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3230
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3231
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3232
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3233
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3234
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3235
		#必填寫的參數:
3236
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3237
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3238
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3239
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("commentsArray","targetInRoot","createdIsoFile","fileArgu");
3240
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3241
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","string","string");
3242
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3243
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3244
		#可以省略的參數:
3245
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3246
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3247
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3248
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("folderInRoot","newLineBreak");
3249
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3250
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
3251
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3252
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true");
3253
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3254
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3255
		#參考資料來源:
3256
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3257
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3258
		unset($conf["variableCheck::checkArguments"]);
3259
 
3260
		#如果檢查失敗
3261
		if($checkResult["status"]=="false"){
3262
 
3263
			#設置錯誤狀態
3264
			$result["status"]="false";
3265
 
3266
			#設置錯誤提示
3267
			$result["error"]=$checkResult;
3268
 
3269
			#回傳結果
3270
			return $result;
3271
 
3272
			}#if end
3273
 
3274
		#如果檢查不通過
3275
		if($checkResult["passed"]=="false"){
3276
 
3277
			#設置錯誤狀態
3278
			$result["status"]="false";
3279
 
3280
			#設置錯誤提示
3281
			$result["error"]=$checkResult;
3282
 
3283
			#回傳結果
3284
			return $result;
3285
 
3286
			}#if end
3287
 
3288
		#取得當前的工作目錄
3289
		$workingDir=$_SERVER["PWD"];
3290
 
3291
		#針對$commensArray的每個元素
3292
		foreach($conf["commentsArray"] as $comment){
3293
 
3294
			#印出描述
3295
			echo $comment;
3296
 
3297
			#如果 $conf["newLineBreak"] 等於 "true"
3298
			if($conf["newLineBreak"]=="true"){
3299
 
3300
				#印出斷行符號
3301
				echo "\n";
3302
 
3303
				}#if end
3304
 
3305
			}#foreach end
3306
 
3307
		#將 $conf["createdIsoFile"] 轉換為絕對路徑
3308
		#函式說明:
3309
		#檢查是否為相對路徑,並將之轉換為絕對路徑
3310
		#回傳的結果:
3311
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3312
		#$result["error"],錯誤訊息.
3313
		#$result["absolutePath"],轉換好的路徑檔案字串.
3314
		#必填參數:
3315
		#$conf["cmd"]["changeToAbsolutePath"]["checkedPath"],"字串",要檢查是不是絕對路徑的路徑檔案字串.
3316
		$conf["cmd"]["changeToAbsolutePath"]["checkedPath"]=$conf["createdIsoFile"];
3317
		$processedCreatedIsoFileStr=cmd::changeToAbsolutePath($conf["cmd"]["changeToAbsolutePath"]);
3318
		unset($conf["cmd"]["changeToAbsolutePath"]);
3319
 
3320
		#如果轉換為絕對路徑失敗
3321
		if($processedCreatedIsoFileStr["status"]=="false"){
3322
 
3323
			#設置執行錯誤識別
3324
			$result["status"]="false";
3325
 
3326
			#取得錯誤訊息
3327
			$result["error"]=$processedCreatedIsoFileStr;
3328
 
3329
			#回傳結果
3330
			return $result;
3331
 
3332
			}#if end
3333
 
3334
		#取得絕對路徑
3335
		$conf["createdIsoFile"]=$processedCreatedIsoFileStr["absolutePath"];
3336
 
3337
		#初始化用來儲存要放進iso檔裡面的各個檔案目錄
3338
		$targetInRootArray=array();
3339
 
3340
		#針對 $conf["compresseeTarget"] 中每個元素
3341
		foreach($conf["targetInRoot"] as $targetInRoot){
3342
 
3343
			#將給個 $conf["compresseeTarget"] 轉換為絕對路徑
3344
			#函式說明:
3345
			#檢查是否為將相對路徑,並將之轉換為絕對路徑
3346
			#回傳的結果:
3347
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3348
			#$result["error"],錯誤訊息.
3349
			#$result["absolutePath"],轉換好的路徑檔案字串.
3350
			#必填參數:
3351
			#$conf["checkedPath"],"字串",要檢查是不是絕對路徑的路徑檔案字串.
3352
			$conf["cmd"]["changeToAbsolutePath"]["checkedPath"]=$targetInRoot;
3353
			$AbsolutePath=cmd::changeToAbsolutePath($conf["cmd"]["changeToAbsolutePath"]);
3354
			unset($conf["cmd"]["changeToAbsolutePath"]);
3355
 
3356
			#如果轉換為絕對路徑失敗
3357
			if($AbsolutePath["status"]=="false"){
3358
 
3359
				#設置執行錯誤識別
3360
				$result["status"]="false";
3361
 
3362
				#取得錯誤訊息
3363
				$result["error"]=$AbsolutePath;
3364
 
3365
				#回傳結果
3366
				return $result;
3367
 
3368
				}#if end
3369
 
3370
			#取得絕對路徑
3371
			$targetInRootArray[]=$AbsolutePath["absolutePath"];
3372
 
3373
			}#foreach end
3374
 
3375
		#取得轉換為絕對路徑的檔案目錄字串陣列
3376
		$conf["targetInRoot"]=$targetInRootArray;
3377
 
3378
		#初始化用來儲存要放進iso檔根目錄裡面的各個以空格分隔的檔案字串
3379
		$isoContentString="";
3380
 
3381
		#檢查每個 $conf["targetInRoot"] 檔案 是否存在
3382
		#函式說明:檢查多個檔案與資料夾是否存在.
3383
		#回傳的結果:
3384
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3385
		#$result["error"],錯誤訊息陣列.
3386
		#$resutl["function"],當前執行的函式名稱.
3387
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3388
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
3389
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
3390
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3391
		#必填參數:
3392
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
3393
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["targetInRoot"];
3394
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3395
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3396
		#可省略參數
3397
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3398
		#$conf["disableWebSearch"]="false";
3399
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3400
		#$conf["userDir"]="true";
3401
		#參考資料來源:
3402
		#http://php.net/manual/en/function.file-exists.php
3403
		#http://php.net/manual/en/control-structures.foreach.php
3404
		#備註:
3405
		#函式file_exists檢查的路徑為檔案系統的路徑
3406
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
3407
		unset($conf["fileAccess::checkMultiFileExist"]);
3408
 
3409
		#如果檢查檔案是否存在失敗
3410
		if($checkMultiFileExist["status"]=="false"){
3411
 
3412
			#設置執行錯誤識別
3413
			$result["status"]="false";
3414
 
3415
			#取得錯誤訊息
3416
			$result["error"]=$checkMultiFileExist;
3417
 
3418
			#回傳結果
3419
			return $result;
3420
 
3421
			}#if end
3422
 
3423
		#如果沒有每個檔案都存在
3424
		if($checkMultiFileExist["allExist"]=="false"){
3425
 
3426
			#設置執行錯誤識別
3427
			$result["status"]="false";
3428
 
3429
			#取得錯誤訊息
3430
			$result["error"]=$checkMultiFileExist;
3431
 
3432
			#回傳結果
3433
			return $result;
3434
 
3435
			}#if end
3436
 
3437
		#將 $conf["targetInRoot"] 轉換為以空格分隔的字串
3438
		for($i=0;$i<count($conf["targetInRoot"]);$i++){
3439
 
3440
			#如果是第一筆
3441
			if($i==0){
3442
 
3443
				#串接第一個 $isoContent 字串
3444
				$isoContentString=$isoContentString."\"".$conf["targetInRoot"][$i]."\"";
3445
 
3446
				}#if end
3447
 
3448
			#反之不是第一筆
3449
			else{
3450
 
3451
				#串接每個 $isoContent 字串
3452
				$isoContentString=$isoContentString." \"".$conf["targetInRoot"][$i]."\"";
3453
 
3454
				}#else end
3455
 
3456
			}#for end
3457
 
3458
		#取得要放進iso檔根目錄底下以空格分隔的檔案目錄字串
3459
		$conf["targetInRoot"]=$isoContentString;
3460
 
3461
		#將多個目錄的路徑轉換為絕對路徑
3462
		#函式說明:
3463
		#檢查多個路徑字串是否為相對路徑,並將之轉換為絕對路徑
3464
		#回傳的結果:
3465
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3466
		#$result["error"],錯誤訊息.
3467
		#$result["absolutePath"][$i],為轉換好的第$i+1個路徑檔案陣列字串.
3468
		#必填參數:
3469
		#$conf["cmd"]["changeMultiToAbsolutePath"]["checkedPathArray"],字串陣列,要檢查是不是絕對路徑的路徑檔案字串陣列.
3470
		$conf["cmd"]["changeMultiToAbsolutePath"]["checkedPathArray"]=$conf["folderInRoot"];
3471
		$processedFolderPath=cmd::changeMultiToAbsolutePath($conf["cmd"]["changeMultiToAbsolutePath"]);
3472
		unset($conf["cmd"]["changeMultiToAbsolutePath"]);
3473
 
3474
		#如果將多個目錄的路徑轉換成絕對路徑失敗
3475
		if($processedFolderPath["status"]=="false"){
3476
 
3477
			#設置執行錯誤識別
3478
			$result["status"]="false";
3479
 
3480
			#取得錯誤訊息
3481
			$result["error"]=$processedFolderPath;
3482
 
3483
			#回傳結果
3484
			return $result;
3485
 
3486
			}#if end
3487
 
3488
		#檢查每個 $processedFolderPath["absolutePath"] 目錄是否存在
3489
		#函式說明:檢查多個檔案與資料夾是否存在.
3490
		#回傳的結果:
3491
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3492
		#$result["error"],錯誤訊息陣列.
3493
		#$resutl["function"],當前執行的函式名稱.
3494
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3495
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
3496
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
3497
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3498
		#必填參數:
3499
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
3500
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$processedFolderPath["absolutePath"];
3501
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3502
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3503
		#可省略參數
3504
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3505
		#$conf["disableWebSearch"]="false";
3506
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3507
		#$conf["userDir"]="true";
3508
		#參考資料來源:
3509
		#http://php.net/manual/en/function.file-exists.php
3510
		#http://php.net/manual/en/control-structures.foreach.php
3511
		#備註:
3512
		#函式file_exists檢查的路徑為檔案系統的路徑
3513
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
3514
		unset($conf["fileAccess::checkMultiFileExist"]);
3515
 
3516
		#如果檢查檔案是否存在失敗
3517
		if($checkMultiFileExist["status"]=="false"){
3518
 
3519
			#設置執行錯誤識別
3520
			$result["status"]="false";
3521
 
3522
			#取得錯誤訊息
3523
			$result["error"]=$checkMultiFileExist;
3524
 
3525
			#回傳結果
3526
			return $result;
3527
 
3528
			}#if end
3529
 
3530
		#如果沒有每個檔案都存在
3531
		if($checkMultiFileExist["allExist"]=="false"){
3532
 
3533
			#設置執行錯誤識別
3534
			$result["status"]="false";
3535
 
3536
			#取得錯誤訊息
3537
			$result["error"]=$checkMultiFileExist;
3538
 
3539
			#回傳結果
3540
			return $result;
3541
 
3542
			}#if end
3543
 
3544
		#初始化儲存 -graft-point  後面接的字串
3545
		$graftPointStr="";
3546
 
3547
		#針對每個處理過的目錄路徑
3548
		for($i=0;$i<count($processedFolderPath["absolutePath"]);$i++){
3549
 
3550
			#如果是第一筆
3551
			if($i==0){
3552
 
3553
				$graftPointStr="-graft-point \"".$conf["folderInRoot"][$i]."\"=\"".$processedFolderPath["absolutePath"][$i]."\"";
3554
 
3555
				}#if end
3556
 
3557
			#反之不是第一筆
3558
			else{
3559
 
3560
				#將之變成 -graft-point inputDir=dirNameInISO 的格式
3561
				$graftPointStr=$graftPointStr." \"".$conf["folderInRoot"][$i]."\"=\"".$processedFolderPath["absolutePath"][$i]."\"";
3562
 
3563
				}#else end
3564
 
3565
			}#for end
3566
 
3567
		#執行的系統命令字串
3568
		#$result["execStr"]="genisoimage -iso-level 4 -J -L -R ".$graftPointStr." ".$conf["targetInRoot"]." > \"".$conf["createdIsoFile"].".iso\"");
3569
		#$result["execStr"]="      ".." ".." > \"".\"";
3570
 
3571
		#函式說明:
3572
		#呼叫shell執行系統命令,並取得回傳的內容.
3573
		#回傳結果:
3574
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3575
		#$result["error"],錯誤訊息陣列.
3576
		#$result["function"],當前執行的函數名稱.
3577
		#$result["argu"],使用的參數.
3578
		#$result["cmd"],執行的指令內容.
3579
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3580
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
3581
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
3582
		#$result["running"],是否還在執行.
3583
		#$result["pid"],pid.
3584
		#$result["statusCode"],執行結束後的代碼.
3585
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
3586
		#必填參數:
3587
		#$conf["command"],字串,要執行的指令.
3588
		$conf["external::callShell"]["command"]="genisoimage";
3589
		#$conf["fileArgu"],字串,變數__FILE__的內容.
3590
		$conf["external::callShell"]["fileArgu"]=__FILE__;
3591
		#可省略參數:
3592
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3593
		$conf["external::callShell"]["argu"]=array("-iso-level","4","-J","-L","-R","-joliet-long",$graftPointStr,$conf["targetInRoot"],">",$conf["createdIsoFile"].".iso");
3594
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
3595
		#$conf["arguIsAddr"]=array();
3596
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
3597
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
3598
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
3599
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3600
		#$conf["enablePrintDescription"]="true";
3601
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
3602
		#$conf["printDescription"]="";
3603
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
3604
		$conf["external::callShell"]["escapeshellarg"]="true";
3605
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
3606
		#$conf["thereIsShellVar"]=array();
3607
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
3608
		#$conf["username"]="";
3609
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
3610
		#$conf["password"]="";
3611
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
3612
		#$conf["useScript"]="";
3613
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
3614
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3615
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
3616
		#$conf["inBackGround"]="";
3617
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
3618
		#$conf["getErr"]="false";
3619
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
3620
		#$conf["doNotRun"]="false";
3621
		#參考資料:
3622
		#exec=>http://php.net/manual/en/function.exec.php
3623
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3624
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3625
		#備註:
3626
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3627
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3628
		$callShell=external::callShell($conf["external::callShell"]);
3629
		unset($conf["external::callShell"]);
3630
 
3631
		#如果產出iso檔失敗
3632
		if($callShell["status"]=="false"){
3633
 
3634
			#設置執行錯誤識別
3635
			$result["status"]="false";
3636
 
3637
			#取得錯誤訊息
3638
			$result["error"]=$callShell;
3639
 
3640
			#回傳結果
3641
			return $result;
3642
 
3643
			}#if end
3644
 
3645
		#執行到這邊算是執行成功
3646
 
3647
		#設置執行成功的識別
3648
		$result["status"]="true";
3649
 
3650
		#設置輸出的iso檔路徑
3651
		$result["storePlace"]=$conf["createdIsoFile"].".iso";
3652
 
3653
		#回傳結果
3654
		return $result;
3655
 
3656
		}#function packetToISO end
3657
 
3658
	/*
3659
	#函式說明:
3660
	#轉換攝氏溫度爲華氏溫度
3661
	#回傳的結果:
3662
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3663
	#$result["error"],錯誤訊息.
3664
	#$result["function"],當前執行的函式名稱.
3665
	#$result["C"],華氏溫度
3666
	#必填參數:
3667
	#$conf["temperatur"]="";#輸入的溫度,結尾必須加上C代表攝氏,F代表華氏
3668
	#可省略參數:
3669
	#$conf["useC"]="true";#輸入內容是否使用單位C、F,如果要則設爲"true";反之不使用。
3670
	#$conf["useF"]="true";#輸出內容是否使用單位C、F,如果要則設爲"true";反之不使用。
3671
	#$conf["points"]="1";#要算到小數點後第幾位,並且四捨五入,預設是不限定小數點位數。
3672
	#參考資料:
3673
	#無.
3674
	#備註:
3675
	#原始公式:F = 9C / 5 + 32
3676
	*/
3677
	public static function transferTemperature($conf){
3678
 
3679
		#初始化要回傳的內容
3680
		$result=array();
3681
 
3682
		#取得當前函式的名稱
3683
		$result["function"]=__FUNCTION__;
3684
 
3685
		#如果 $conf 不為陣列
3686
		if(gettype($conf)!="array"){
3687
 
3688
			#設置執行失敗
3689
			$result["status"]="false";
3690
 
3691
			#設置執行錯誤訊息
3692
			$result["error"][]="\$conf變數須為陣列形態";
3693
 
3694
			#如果傳入的參數為 null
3695
			if($conf==null){
3696
 
3697
				#設置執行錯誤訊息
3698
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
3699
 
3700
				}#if end
3701
 
3702
			#回傳結果
3703
			return $result;
3704
 
3705
			}#if end
3706
 
3707
		#函式說明:
3708
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
3709
		#回傳的結果:
3710
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3711
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3712
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3713
		#必填寫的參數:
3714
		$conf["variableCheck"]["isexistMuti"]["varInput"]=#conf;#要檢查的陣列變數
3715
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("temperatur");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
3716
		#可以省略的參數:
3717
		#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3718
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
3719
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
3720
		unset($conf["variableCheck"]["isexistMuti"]);
3721
 
3722
		#如果 $checkResult["status"] 等於 "false"
3723
		if($checkResult["status"]=="false"){
3724
 
3725
			#設置執行錯誤識別
3726
			$result["status"]="false";
3727
 
3728
			#取得錯誤訊息
3729
			$result["error"]=$checkResult;
3730
 
3731
			#回傳結果
3732
			return $result;
3733
 
3734
			}#if end
3735
 
3736
		#如果 $checkResult["passed"] 等於 "false"
3737
		if($checkResult["passed"]=="false"){
3738
 
3739
			#設置執行錯誤識別
3740
			$result["status"]="false";
3741
 
3742
			#取得錯誤訊息
3743
			$result["error"]=$checkResult;
3744
 
3745
			#回傳結果
3746
			return $result;
3747
 
3748
			}#if end
3749
 
3750
		#判斷輸入是華氏溫度還是攝氏溫度
3751
 
3752
		#將字串內容分割成一個字一個元素
3753
		$spiltedStr=str_split($conf["temperature"]);
3754
 
3755
		#將輸入的C或F踢除,以便進行計算
3756
		#函式說明:
3757
		#處理字串避免網頁出錯
3758
		#回傳的結果:
3759
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3760
		#$result["function"],當前執行的函式.
3761
		#$result["content"],爲處理好的字串.
3762
		#$result["error"],錯誤訊息陣列.
3763
		#必填參數:
3764
		$conf["stringProcess"]["correctCharacter"]["stringIn"]=$conf["temperature"];#爲要處理的字串
3765
		#可省略參數:
3766
		$conf["selectedCharacter"]=array("C","F");#爲被選擇要處理的字串/字元,須爲陣列值。
3767
			#若不設定則預設爲要將這些字串作替換("<" ">" ";" "=" "//" "'" "$" "%" "&" "|" "#" "/*" "*\/")。
3768
		#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
3769
		$temperature=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
3770
		unset($conf["stringProcess"]["correctCharacter"]);
3771
 
3772
		#如果剔除C或F失敗
3773
		if($temperature["status"]=="false"){
3774
 
3775
			#設置執行錯誤識別
3776
			$result["status"]="false";
3777
 
3778
			#取得錯誤訊息
3779
			$result["error"]=$temperature;
3780
 
3781
			#回傳結果
3782
			return $result;
3783
 
3784
			}#if end
3785
 
3786
		#如果輸入是攝氏溫度
3787
		if($spiltedStr[count($spiltedStr)-1]=="C"){
3788
 
3789
			#計算華氏溫度
3790
 
3791
			#如果不爲0度
3792
			if($temperature["content"]!=0){
3793
 
3794
				#求算華氏溫度
3795
				$F=9*$temperature["content"]/5+32;
3796
 
3797
				#如果有設定 $conf["points"]
3798
				if(isset($conf["points"])){
3799
 
3800
					#設定要顯示的小數點位數
3801
					$F=round($F,$conf["points"]);
3802
 
3803
					}#if end
3804
 
3805
				#如果 $conf["useF"] 有設置
3806
				if(isset($conf["useF"])){
3807
 
3808
					#如果 $conf["useF"] 爲 "true"
3809
					if($conf["useF"]=="true"){
3810
 
3811
						#加上F
3812
						$F=$F."F";
3813
 
3814
						}#if end
3815
 
3816
					}#if end
3817
 
3818
				#回傳結果
3819
				return $F;
3820
 
3821
				}#if end
3822
 
3823
			#如果爲0度
3824
			if($temperature["content"]==0){
3825
 
3826
				#華氏溫度爲32
3827
				$F=32;
3828
 
3829
				#如果有設定 $conf["points"]
3830
				if(isset($conf["points"])){
3831
 
3832
					#設定要顯示的小數點位數
3833
					$F=round($F,$conf["points"]);
3834
 
3835
					}#if end
3836
 
3837
				#如果 $conf["useF"] 有設置
3838
				if(isset($conf["useF"])){
3839
 
3840
					#如果 $conf["useF"] 爲 "true"
3841
					if($conf["useF"]=="true"){
3842
 
3843
						#加上F
3844
						$F=$F."F";
3845
 
3846
						}#if end
3847
 
3848
					}#if end
3849
 
3850
				#回傳結果
3851
				return $F;
3852
 
3853
				}#else end
3854
 
3855
			}#if end
3856
 
3857
		#如果輸入是華氏溫度
3858
		if($spiltedStr[count($spiltedStr)-1]=="F"){
3859
 
3860
			#計算攝氏溫度
3861
			$C=($temperature["content"]-32)*5/9;
3862
 
3863
			#如果有設定 $conf["points"]
3864
			if(isset($conf["points"])){
3865
 
3866
				#設定要顯示的小數點位數
3867
				$C=round($C,$conf["points"]);
3868
 
3869
				}#if end
3870
 
3871
			#如果 $conf["useC"] 有設置
3872
			if(isset($conf["useC"])){
3873
 
3874
				#如果 $conf["useC"] 爲 "true"
3875
				if($conf["useC"]=="true"){
3876
 
3877
					#加上C
3878
					$C=$C."C";
3879
 
3880
					}#if end
3881
 
3882
				}#if end
3883
 
3884
			#設置執行成功
3885
			$result["status"]="true";
3886
 
3887
			#設置轉換好的攝氏溫度
3888
			$result["C"]=$C;;
3889
 
3890
			#回傳結果
3891
			return $result;
3892
 
3893
			}#if end
3894
 
3895
		#設置執行失敗
3896
		$result["status"]="false";
3897
 
3898
		#設置錯誤訊息
3899
		$result["error"][]="請在結尾加上C或F來代表攝氏或華氏溫度";
3900
 
3901
		#回傳結果
3902
		return $result;
3903
 
3904
		}#function transferCtoF
3905
 
3906
	/*
3907
	#函式說明:
3908
	#印出多行文字,結尾自動換行.
3909
	#回傳的結果:
3910
	#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
3911
	#$result["function"],當前執行的函式名稱.
3912
	#$result["error"],錯誤訊息陣列.
3913
	#必填參數:
3914
	#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
3915
	$conf["outputStringArray"]=array("");
3916
	#可省略參數:
3917
	#無.
3918
	#參考資料:
3919
	#無.
3920
	#備註:
3921
	#無.
3922
	*/
3923
	public static function echoMultiLine($conf){
3924
 
3925
		#初始化要回傳的內容
3926
		$result=array();
3927
 
3928
		#取得當前函式的名稱
3929
		$result["function"]=__FUNCTION__;
3930
 
3931
		#如果 $conf 不為陣列
3932
		if(gettype($conf)!="array"){
3933
 
3934
			#設置執行失敗
3935
			$result["status"]="false";
3936
 
3937
			#設置執行錯誤訊息
3938
			$result["error"][]="\$conf變數須為陣列形態";
3939
 
3940
			#如果傳入的參數為 null
3941
			if($conf==null){
3942
 
3943
				#設置執行錯誤訊息
3944
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
3945
 
3946
				}#if end
3947
 
3948
			#回傳結果
3949
			return $result;
3950
 
3951
			}#if end
3952
 
3953
		#檢查參數
3954
		#函式說明:
3955
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
3956
		#回傳的結果:
3957
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3958
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3959
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3960
		#必填寫的參數:
3961
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
3962
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("outputStringArray");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
3963
		#可以省略的參數:
3964
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3965
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
3966
		#備註:
3967
		#功能與checkExistAndType函式相同
3968
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
3969
		unset($conf["variableCheck"]["isexistMuti"]);
3970
 
3971
		#如果 $checkResult["status"] 等於 "false"
3972
		if($checkResult["status"]=="false"){
3973
 
3974
			#設置執行錯誤識別
3975
			$result["status"]="false";
3976
 
3977
			#取得錯誤訊息
3978
			$result["error"]=$checkResult;
3979
 
3980
			#回傳結果
3981
			return $result;
3982
 
3983
			}#if end
3984
 
3985
		#如果 $checkResult["passed"] 等於 "false"
3986
		if($checkResult["passed"]=="false"){
3987
 
3988
			#設置執行錯誤識別
3989
			$result["status"]="false";
3990
 
3991
			#取得錯誤訊息
3992
			$result["error"]=$checkResult;
3993
 
3994
			#回傳結果
3995
			return $result;
3996
 
3997
			}#if end
3998
 
3999
		#$conf["outputStringArray"]有幾個元素就執行幾次
4000
		for($i=0;$i<count($conf["outputStringArray"]);$i++){
4001
 
4002
			#引出該行字,並換行
4003
			echo $conf["outputStringArray"][$i].PHP_EOL;
4004
 
4005
			}#for end
4006
 
4007
		#執行到這邊代表執行正常
4008
		$result["status"]="true";
4009
 
4010
		#回傳結果
4011
		return $result;
4012
 
4013
		}#function echoMultiLine end
4014
 
4015
	/*
4016
	#函式說明:
4017
	#用shell檢查檔案是否存在,可以指定查詢時用的身份.
4018
	#回傳的結果:
4019
	#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
4020
	#$result["function"],當前執行的函式名稱.
4021
	#$result["error"],錯誤訊息陣列.
66 liveuser 4022
	#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案,"?"代表沒有執行指令.
4023
	#$result["cmdStr"],查詢檔案是否存在的指令與參數字串.
4024
	#$result["escapedCmdArray"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
3 liveuser 4025
	#必填參數:
4026
	#$conf["fileName"],字串,要檢查的檔案名稱.
4027
	$conf["fileName"]="";
4028
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
4029
	$conf["fileArgu"]=__FILE__;
4030
	#可省略參數:
4031
	#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.
4032
	#$conf["username"]="";
4033
	#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.
4034
	#$conf["password"]="";
66 liveuser 4035
	#$conf["getCmdOnly"],字串,若不要執行指令,只要取得要執行的指令,則設置為"true";反之為預設值"false".
4036
	#$conf["getCmdOnly"]="";
3 liveuser 4037
	#參考資料:
4038
	#無.
4039
	#備註:
4040
	#僅能在命令列環境下執行.
4041
	*/
4042
	public static function checkFileExist(&$conf){
4043
 
4044
		#初始化要回傳的結果
4045
		$result=array();
4046
 
4047
		#取得當前執行的函式
4048
		$result["function"]=__FUNCTION__;
4049
 
4050
		#如果 $conf 不為陣列
4051
		if(gettype($conf)!="array"){
4052
 
4053
			#設置執行失敗
4054
			$result["status"]="false";
4055
 
4056
			#設置執行錯誤訊息
4057
			$result["error"][]="\$conf變數須為陣列形態";
4058
 
4059
			#如果傳入的參數為 null
4060
			if($conf==null){
4061
 
4062
				#設置執行錯誤訊息
4063
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
4064
 
4065
				}#if end
4066
 
4067
			#回傳結果
4068
			return $result;
4069
 
4070
			}#if end
4071
 
4072
		#函式說明:
4073
		#判斷當前環境為web還是cmd
4074
		#回傳結果:
4075
		#$result,"web"或"cmd"
4076
		if(csInformation::getEnv()==="web"){
4077
 
4078
			#設置執行失敗
4079
			$result["status"]="false";
4080
 
4081
			#設置執行錯誤訊息
4082
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
4083
 
4084
			#回傳結果
4085
			return $result;
4086
 
4087
			}#if end
4088
 
4089
		#檢查參數
4090
		#函式說明:
4091
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
4092
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4093
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4094
		#$result["function"],當前執行的函式名稱.
4095
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4096
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4097
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4098
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4099
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4100
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4101
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4102
		#必填寫的參數:
4103
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4104
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4105
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4106
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileName","fileArgu");
4107
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
4108
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
4109
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4110
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4111
		#可以省略的參數:
4112
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
4113
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
4114
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
66 liveuser 4115
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","getCmdOnly");
3 liveuser 4116
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
66 liveuser 4117
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
3 liveuser 4118
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
66 liveuser 4119
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,"false");
3 liveuser 4120
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4121
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
4122
		#參考資料來源:
4123
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4124
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4125
		unset($conf["variableCheck::checkArguments"]);
4126
 
4127
		#如果檢查失敗
66 liveuser 4128
		if($checkResult["status"]==="false"){
3 liveuser 4129
 
4130
			#設置錯誤狀態
4131
			$result["status"]="false";
4132
 
4133
			#設置錯誤提示
4134
			$result["error"]=$checkResult;
4135
 
4136
			#回傳結果
4137
			return $result;
4138
 
4139
			}#if end
4140
 
4141
		#如果檢查不通過
66 liveuser 4142
		if($checkResult["passed"]==="false"){
3 liveuser 4143
 
4144
			#設置錯誤狀態
4145
			$result["status"]="false";
4146
 
4147
			#設置錯誤提示
4148
			$result["error"]=$checkResult;
4149
 
4150
			#回傳結果
4151
			return $result;
4152
 
4153
			}#if end
4154
 
4155
		#初始化儲存檢查檔案是否存在的腳本
4156
		$cmd="";
4157
 
4158
		#設定要檢查的檔案
4159
		$cmd=$cmd."target=".\escapeshellarg($conf["fileName"]).";";
4160
 
4161
		#判斷檔案是否存在並印出 $target found 或 $target not found
4162
		#$cmd=$cmd."if [ -e \${target} ]; then echo \${target} found ; else echo \${target} not found; fi;";
4163
 
4164
		#執行腳本
4165
		#函式說明:
4166
		#呼叫shell執行系統命令,並取得回傳的內容.
4167
		#回傳的結果:
4168
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4169
		#$result["error"],錯誤訊息陣列.
4170
		#$result["function"],當前執行的函式名稱.
4171
		#$result["cmd"],執行的指令內容.
66 liveuser 4172
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3 liveuser 4173
		#$result["output"],爲執行完二元碼後的輸出陣列.
66 liveuser 4174
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
4175
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
3 liveuser 4176
		#必填參數
4177
		#$conf["command"],字串,要執行的指令與.
4178
		$conf["external::callShell"]["command"]=$cmd;
4179
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4180
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
4181
		#可省略參數:
4182
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
66 liveuser 4183
		#$conf["external::callShell"]["argu"]=array("if","[","-e","\${target}","]",";","then","echo","\${target}","found",";","else","echo","\${target}","not founnd",";","fi",";");
4184
		$conf["external::callShell"]["argu"]=array("if","[","-e","\${target}","]",";","then","echo","found",";","else","echo","not founnd",";","fi",";");
3 liveuser 4185
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
4186
		#$conf["enablePrintDescription"]="true";
4187
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
4188
		#$conf["printDescription"]="";
4189
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
4190
		$conf["external::callShell"]["escapeshellarg"]="false";
4191
 
4192
		#如果有 $conf["username"]
4193
		if(isset($conf["username"])){
4194
 
4195
			#如果不是以運行php的使用者角色來檢查檔案是否存在
4196
			if($conf["username"]!==$_SERVER["LOGNAME"]){
4197
 
4198
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
4199
				$conf["external::callShell"]["username"]=$conf["username"];
4200
 
4201
				}#if end
4202
 
4203
			}#if end
4204
 
4205
		#如果有 $conf["password"]
4206
		if(isset($conf["password"])){
4207
 
4208
			#如果不是以運行php的使用者角色來檢查檔案是否存在
4209
			if($conf["username"]!==$_SERVER["LOGNAME"]){
4210
 
4211
				#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
4212
				$conf["external::callShell"]["password"]=$conf["password"];
4213
 
4214
				}#if end
4215
 
4216
			}#if end
66 liveuser 4217
 
4218
		#如果不要運行指令,只要取得要執行的指令
4219
		if($conf["getCmdOnly"]==="true"){
3 liveuser 4220
 
66 liveuser 4221
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
4222
			$conf["external::callShell"]["doNotRun"]="false";
4223
 
4224
			}#if end
4225
 
3 liveuser 4226
		#備註:
4227
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
4228
		#參考資料:
4229
		#exec=>http://php.net/manual/en/function.exec.php
4230
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
4231
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4232
		$callShell=external::callShell($conf["external::callShell"]);
4233
		unset($conf["external::callShell"]);
4234
 
4235
		#如果執行腳本失敗
66 liveuser 4236
		if($callShell["status"]==="false"){
3 liveuser 4237
 
4238
			#設置錯誤識別
4239
			$result["status"]="false";
4240
 
4241
			#設置錯誤提示
4242
			$result["error"]=$callShell;
4243
 
4244
			#回傳結果
4245
			return $result;
4246
 
4247
			}#if end
66 liveuser 4248
 
4249
		#儲存要執行的指令
4250
		$result["cmdStr"]=$callShell["cmd"];
4251
 
4252
		#用陣列儲存的指令與參數資訊
4253
		$result["escapedCmdArray"]=$callShell["noEscaped"];
3 liveuser 4254
 
66 liveuser 4255
		#如果不要運行指令,只要取得要執行的指令
4256
		if($conf["getCmdOnly"]==="true"){
4257
 
4258
			#設置執行正常的識別
4259
			$result["status"]="true";
4260
 
4261
			#因為沒有執行指令,所以設置為"?"
4262
			$result["founded"]="?";
4263
 
4264
			#回傳結果
4265
			return $result;
4266
 
4267
			}#if end
4268
 
3 liveuser 4269
		#如果有找到檔案
66 liveuser 4270
		if($callShell["output"][0]==="found"){
3 liveuser 4271
 
4272
			#設置執行正常的識別
4273
			$result["status"]="true";
4274
 
4275
			#設置有找到檔案
4276
			$result["founded"]="true";
4277
 
4278
			#回傳結果
4279
			return $result;
4280
 
4281
			}#if end
4282
 
66 liveuser 4283
		#如果沒有找到檔案
4284
		else if($callShell["output"][0]==="not found"){
3 liveuser 4285
 
4286
			#設置執行正常的識別
4287
			$result["status"]="true";
4288
 
4289
			#設置有找到檔案
4290
			$result["founded"]="false";
4291
 
4292
			#回傳結果
4293
			return $result;
4294
 
4295
			}#if end
4296
 
4297
		#設置錯誤識別
4298
		$result["status"]="false";
4299
 
4300
		#設置錯誤提示
4301
		$result["error"]=$callShell;
4302
 
4303
		#回傳結果
4304
		return $result;
4305
 
4306
		}#function checkFileExist Exist
4307
 
4308
	/*
4309
	#函式說明:
4310
	#透過lsblk指令的輸出取得已經掛載的blk.
4311
	#回傳結果:
4312
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4313
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
4314
	#$result["function"],當前執行的函式名稱.
4315
	#$result["content"],lsblk的輸出內容.
4316
	#必填參數:
4317
	#$conf["fileArgu"],字串,變數__FILE__的內容.
4318
	$conf["fileArgu"]=__FILE__;
4319
	#可省略參數:
4320
	#無.
4321
	#參考資料:
4322
	#無.
4323
	#備註:
4324
	#無.
4325
	*/
4326
	public static function lsblk(&$conf=array()){
4327
 
4328
		#初始化要回傳的結果
4329
		$result=array();
4330
 
4331
		#取得當前執行的函式名稱
4332
		$result["function"]=__FUNCTION__;
4333
 
4334
		#取得參數
4335
		$result["argu"]=$conf;
4336
 
4337
		#如果 $conf 不為陣列
4338
		if(gettype($conf)!="array"){
4339
 
4340
			#設置執行失敗
4341
			$result["status"]="false";
4342
 
4343
			#設置執行錯誤訊息
4344
			$result["error"][]="\$conf變數須為陣列形態";
4345
 
4346
			#如果傳入的參數為 null
4347
			if($conf==null){
4348
 
4349
				#設置執行錯誤訊息
4350
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
4351
 
4352
				}#if end
4353
 
4354
			#回傳結果
4355
			return $result;
4356
 
4357
			}#if end
4358
 
4359
		#檢查參數
4360
		#函式說明:
4361
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
4362
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4363
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4364
		#$result["function"],當前執行的函式名稱.
4365
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4366
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4367
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4368
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4369
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4370
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4371
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4372
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4373
		#必填寫的參數:
4374
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4375
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4376
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4377
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
4378
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
4379
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4380
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4381
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4382
		#可以省略的參數:
4383
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4384
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
4385
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
4386
		#$conf["canNotBeEmpty"]=array();
4387
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
4388
		#$conf["canBeEmpty"]=array();
4389
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
4390
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4391
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4392
		#$conf["skipableVariableName"]=array();
4393
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
4394
		#$conf["skipableVariableType"]=array();
4395
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4396
		#$conf["skipableVarDefaultValue"]=array("");
4397
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4398
		#$conf["arrayCountEqualCheck"][]=array();
4399
		#參考資料來源:
4400
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4401
		#建議:
4402
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
4403
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4404
		unset($conf["variableCheck::checkArguments"]);
4405
 
4406
		#如果檢查參數失敗
4407
		if($checkArguments["status"]==="false"){
4408
 
4409
			#設置執行失敗
4410
			$result["status"]="false";
4411
 
4412
			#設置執行錯誤訊息
4413
			$result["error"]=$checkArguments;
4414
 
4415
			#回傳結果
4416
			return $result;
4417
 
4418
			}#if end
4419
 
4420
		#如果檢查參數不通過
4421
		if($checkArguments["passed"]==="false"){
4422
 
4423
			#設置執行失敗
4424
			$result["status"]="false";
4425
 
4426
			#設置執行錯誤訊息
4427
			$result["error"]=$checkArguments;
4428
 
4429
			#回傳結果
4430
			return $result;
4431
 
4432
			}#if end
4433
 
4434
		#執行 lsblk 指令
4435
		#函式說明:
4436
		#呼叫shell執行系統命令,並取得回傳的內容.
4437
		#回傳的結果:
4438
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4439
		#$result["error"],錯誤訊息陣列.
4440
		#$result["function"],當前執行的函式名稱.
4441
		#$result["cmd"],執行的指令內容.
4442
		#$result["output"],爲執行完二元碼後的輸出陣列.
4443
		#必填參數
4444
		#$conf["command"],字串,要執行的指令與.
4445
		$conf["external::callShell"]["command"]="lsblk";
4446
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
4447
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
4448
		#可省略參數:
4449
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
4450
		$conf["external::callShell"]["argu"]=array("--output","NAME,SIZE");
4451
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
4452
		#$conf["enablePrintDescription"]="true";
4453
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
4454
		#$conf["printDescription"]="";
4455
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
4456
		$conf["external::callShell"]["escapeshellarg"]="true";
4457
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
4458
		#$conf["username"]="";
4459
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
4460
		#$conf["password"]="";
4461
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
4462
		#$conf["useScript"]="";
4463
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
4464
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
4465
		#備註:
4466
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
4467
		#參考資料:
4468
		#exec=>http://php.net/manual/en/function.exec.php
4469
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
4470
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4471
		$callShell=external::callShell($conf["external::callShell"]);
4472
		unset($conf["external::callShell"]);
4473
 
4474
		#如果執行 lsblk 指令失敗
4475
		if($callShell["status"]=="false"){
4476
 
4477
			#設置執行失敗
4478
			$result["status"]="false";
4479
 
4480
			#設置執行錯誤訊息
4481
			$result["error"]=$callShell;
4482
 
4483
			#回傳結果
4484
			return $result;
4485
 
4486
			}#if end
4487
 
4488
		#初始化用儲存欄位名稱的變數
4489
		$colName=array();
4490
 
4491
		#針對每個欄位
4492
		foreach($callShell["output"] as $lineNum=>$lineStr){
4493
 
4494
			#如果是標題列
4495
			if($lineNum==0){
4496
 
4497
				#分割 $lineStr 以便取得欄位名稱
4498
				#函式說明:
4499
				#將固定格式的字串分開,並回傳分開的結果。
4500
				#回傳結果:
4501
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4502
				#$result["error"],錯誤訊息陣列
4503
				#$result["function"],當前執行的函式名稱.
4504
				#$result["oriStr"],要分割的原始字串內容
4505
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4506
				#$result["dataCounts"],爲總共分成幾段
4507
				#必填參數:
4508
				$conf["stringProcess::spiltString"]["stringIn"]=$lineStr;#要處理的字串。
4509
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
4510
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4511
				unset($conf["stringProcess::spiltString"]);
4512
 
4513
				#如果分割字串失敗
4514
				if($spiltString["status"]=="false"){
4515
 
4516
					#設置執行失敗
4517
					$result["status"]="false";
4518
 
4519
					#設置執行錯誤訊息
4520
					$result["error"]=$spiltString;
4521
 
4522
					#回傳結果
4523
					return $result;
4524
 
4525
					}#if end
4526
 
4527
				#針對每個欄位名稱
4528
				for($i=0;$i<$spiltString["dataCounts"];$i++){
4529
 
4530
					#儲存每個欄位名稱
4531
					$colName[]=$spiltString["dataArray"][$i];
4532
 
4533
					}#for end
4534
 
4535
				#跳過
4536
				continue;
4537
 
4538
				}#if end
4539
 
4540
			#反之不是標題列
4541
			else{
4542
 
4543
				#將開頭的 "| " 剔除
4544
				#函式說明:
4545
				#將字串特定關鍵字與其前面的內容剔除
4546
				#回傳結果:
4547
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4548
				#$result["error"],錯誤訊息陣列.
4549
				#$result["warning"],警告訊息鎮列.
4550
				#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4551
				#$result["function"],當前執行的函式名稱.
4552
				#$result["oriStr"],要處理的原始字串內容.
4553
				#$result["content"],處理好的的字串內容.
4554
				#必填參數:
4555
				$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$lineStr;#要處理的字串.
4556
				$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="│ ";#特定字串.
4557
				$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
4558
				unset($conf["stringProcess::delStrBeforeKeyWord"]);
4559
 
4560
				#如果處理字串失敗
4561
				if($delStrBeforeKeyWord["status"]==="false"){
4562
 
4563
					#設置執行失敗
4564
					$result["status"]="false";
4565
 
4566
					#設置執行錯誤訊息
4567
					$result["error"]=$delStrBeforeKeyWord;
4568
 
4569
					#回傳結果
4570
					return $result;
4571
 
4572
					}#if end
4573
 
4574
				#如果含有要處理的關鍵字
4575
				if($delStrBeforeKeyWord["founded"]==="true"){
4576
 
4577
					#取得處理好的字串
4578
					$lineStr=$delStrBeforeKeyWord["content"];
4579
 
4580
					}#if end
4581
 
4582
				#分割 $lineStr 以便取得欄位名稱
4583
				#函式說明:
4584
				#將固定格式的字串分開,並回傳分開的結果。
4585
				#回傳結果:
4586
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4587
				#$result["error"],錯誤訊息陣列
4588
				#$result["function"],當前執行的函式名稱.
4589
				#$result["oriStr"],要分割的原始字串內容
4590
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4591
				#$result["dataCounts"],爲總共分成幾段
4592
				#必填參數:
4593
				$conf["stringProcess::spiltString"]["stringIn"]=$lineStr;#要處理的字串。
4594
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
4595
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4596
				unset($conf["stringProcess::spiltString"]);
4597
 
4598
				#如果分割字串失敗
4599
				if($spiltString["status"]=="false"){
4600
 
4601
					#設置執行失敗
4602
					$result["status"]="false";
4603
 
4604
					#設置執行錯誤訊息
4605
					$result["error"]=$spiltString;
4606
 
4607
					#回傳結果
4608
					return $result;
4609
 
4610
					}#if end
4611
 
4612
				#針對每個欄位名稱
4613
				for($i=0;$i<$spiltString["dataCounts"];$i++){
4614
 
4615
					#如果是NAME欄位
4616
					if($colName[$i]=="NAME"){
4617
 
4618
						#將開頭的 "├─" 剃除
4619
						#函式說明:
4620
						#將字串特定關鍵字與其前面的內容剔除
4621
						#回傳結果:
4622
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4623
						#$result["error"],錯誤訊息陣列.
4624
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4625
						#$result["function"],當前執行的函式名稱.
4626
						#$result["oriStr"],要處理的原始字串內容.
4627
						#$result["content"],處理好的的字串內容.
4628
						#必填參數:
4629
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$spiltString["dataArray"][$i];#要處理的字串.
4630
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="|-";#特定字串.
4631
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
4632
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
4633
 
4634
						#如果移除關鍵字前面的內容失敗
4635
						if($delStrBeforeKeyWord["status"]=="false"){
4636
 
4637
							#設置執行失敗
4638
							$result["status"]="false";
4639
 
4640
							#設置執行錯誤訊息
4641
							$result["error"]=$delStrBeforeKeyWord;
4642
 
4643
							#回傳結果
4644
							return $result;
4645
 
4646
							}#if end
4647
 
4648
						#如果有找到關鍵字
4649
						if($delStrBeforeKeyWord["founded"]=="true"){
4650
 
4651
							#取得移除開頭關鍵字後的內容
4652
							$spiltString["dataArray"][$i]=$delStrBeforeKeyWord["content"];
4653
 
4654
							#儲存欄位的真正內容
4655
							#$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["oriStr"];
4656
 
4657
							#儲存欄位的真正內容
4658
							$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["content"];
4659
 
4660
							}#if end
4661
 
4662
						#反之
4663
						else{
4664
 
4665
							#將開頭的 "└─" 剃除
4666
							#函式說明:
4667
							#將字串特定關鍵字與其前面的內容剔除
4668
							#回傳結果:
4669
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4670
							#$result["error"],錯誤訊息陣列.
4671
							#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4672
							#$result["function"],當前執行的函式名稱.
4673
							#$result["oriStr"],要處理的原始字串內容.
4674
							#$result["content"],處理好的的字串內容.
4675
							#必填參數:
4676
							$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$spiltString["dataArray"][$i];#要處理的字串.
4677
							$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="`-";#特定字串.
4678
							$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
4679
							unset($conf["stringProcess::delStrBeforeKeyWord"]);
4680
 
4681
							#如果移除關鍵字前面的內容失敗
4682
							if($delStrBeforeKeyWord["status"]=="false"){
4683
 
4684
								#設置執行失敗
4685
								$result["status"]="false";
4686
 
4687
								#設置執行錯誤訊息
4688
								$result["error"]=$delStrBeforeKeyWord;
4689
 
4690
								#回傳結果
4691
								return $result;
4692
 
4693
								}#if end
4694
 
4695
							#取得移除開頭關鍵字後的內容
4696
							$spiltString["dataArray"][$i]=$delStrBeforeKeyWord["content"];
4697
 
4698
							#儲存欄位的真正內容
4699
							#$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["oriStr"];
4700
 
4701
							#儲存欄位的真正內容
4702
							$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["content"];
4703
 
4704
							}#else end
4705
 
4706
						#將名稱當中的 "-" 置換為 "/"
4707
						#函式說明:
4708
						#處理字串避免網頁出錯
4709
						#回傳的結果:
4710
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4711
						#$result["function"],當前執行的函式.
4712
						#$result["content"],爲處理好的字串.
4713
						#$result["error"],錯誤訊息陣列.
4714
						#必填參數:
4715
						$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][$i];#爲要處理的字串
4716
						#可省略參數:
4717
						$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("-");#爲被選擇要處理的字串/字元,須爲陣列值。
4718
							#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
4719
							#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
4720
						$conf["stringProcess::correctCharacter"]["changeTo"]=array("/");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
4721
						$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
4722
						unset($conf["stringProcess::correctCharacter"]);
4723
 
4724
						#如果轉換NAME失敗
4725
						if($correctCharacter["status"]=="false"){
4726
 
4727
							#設置執行失敗
4728
							$result["status"]="false";
4729
 
4730
							#設置執行錯誤訊息
4731
							$result["error"]=$correctCharacter;
4732
 
4733
							#回傳結果
4734
							return $result;
4735
 
4736
							}#if end
4737
 
4738
						#取得轉換好的 NAME
4739
						$spiltString["dataArray"][$i]=$correctCharacter["content"];
4740
 
4741
						#補上 "/dev/"
4742
						$spiltString["dataArray"][$i]="/dev/".$spiltString["dataArray"][$i];
4743
 
4744
						}#if end
4745
 
4746
					#儲存每個欄位名稱
4747
					$result["content"][$colName[$i]][]=$spiltString["dataArray"][$i];
4748
 
4749
					}#for end
4750
 
4751
				}#else end
4752
 
4753
			}#foreach end
4754
 
4755
		#lsblk 的 PKNAME 與 MOUNTPOINT 與 vendor 與 WWN 資訊要個別取得,因為可能是空值
4756
		$othersCol=array("PKNAME","MOUNTPOINT","vendor","WWN","SERIAL");
4757
 
4758
		#新增的欄位,可以得知blk是什麼類型
4759
		$othersCol[]="TYPE";
4760
 
4761
		#每個要各別取得的欄位資訊內容
4762
		foreach($othersCol as $colName){
4763
 
4764
			#執行 lsblk 指令
4765
			#函式說明:
4766
			#呼叫shell執行系統命令,並取得回傳的內容.
4767
			#回傳的結果:
4768
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4769
			#$result["error"],錯誤訊息陣列.
4770
			#$result["function"],當前執行的函式名稱.
4771
			#$result["cmd"],執行的指令內容.
4772
			#$result["output"],爲執行完二元碼後的輸出陣列.
4773
			#必填參數
4774
			#$conf["command"],字串,要執行的指令與.
4775
			$conf["external::callShell"]["command"]="lsblk";
4776
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
4777
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
4778
			#可省略參數:
4779
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
4780
			$conf["external::callShell"]["argu"]=array("--output",$colName);
4781
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
4782
			#$conf["enablePrintDescription"]="true";
4783
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
4784
			#$conf["printDescription"]="";
4785
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
4786
			$conf["external::callShell"]["escapeshellarg"]="true";
4787
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
4788
			#$conf["username"]="";
4789
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
4790
			#$conf["password"]="";
4791
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
4792
			#$conf["useScript"]="";
4793
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
4794
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
4795
			#備註:
4796
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
4797
			#參考資料:
4798
			#exec=>http://php.net/manual/en/function.exec.php
4799
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
4800
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4801
			$callShell=external::callShell($conf["external::callShell"]);
4802
			unset($conf["external::callShell"]);
4803
 
4804
			#如果執行 lsblk 指令失敗
4805
			if($callShell["status"]=="false"){
4806
 
4807
				#設置執行失敗
4808
				$result["status"]="false";
4809
 
4810
				#設置執行錯誤訊息
4811
				$result["error"]=$callShell;
4812
 
4813
				#回傳結果
4814
				return $result;
4815
 
4816
				}#if end
4817
 
4818
			#針對每列輸出
4819
			foreach($callShell["output"] as $index=>$colStr){
4820
 
4821
				#如果索引為0
4822
				if($index==0){
4823
 
4824
					#跳到下一次迴圈
4825
					continue;
4826
 
4827
					}#if end
4828
 
4829
				#分割 $lineStr 以便取得欄位名稱
4830
				#函式說明:
4831
				#將固定格式的字串分開,並回傳分開的結果。
4832
				#回傳結果:
4833
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4834
				#$result["error"],錯誤訊息陣列
4835
				#$result["function"],當前執行的函式名稱.
4836
				#$result["oriStr"],要分割的原始字串內容
4837
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4838
				#$result["dataCounts"],爲總共分成幾段
4839
				#必填參數:
4840
				$conf["stringProcess::spiltString"]["stringIn"]=$colStr;#要處理的字串。
4841
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
4842
				#可省略參數:
4843
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4844
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="true";
4845
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4846
				unset($conf["stringProcess::spiltString"]);
4847
 
4848
				#如果分割字串失敗
4849
				if($spiltString["status"]=="false"){
4850
 
4851
					#設置執行失敗
4852
					$result["status"]="false";
4853
 
4854
					#設置執行錯誤訊息
4855
					$result["error"]=$spiltString;
4856
 
4857
					#回傳結果
4858
					return $result;
4859
 
4860
					}#if end
4861
 
4862
				#針對每個欄位名稱
4863
				for($i=0;$i<$spiltString["dataCounts"];$i++){
4864
 
4865
					#儲存每個欄位名稱
4866
					$result["content"][$colName][]=$spiltString["dataArray"][$i];
4867
 
4868
					}#for end
4869
 
4870
				}#foreach end
4871
 
4872
			}#foreach end
4873
 
4874
		#修正 NAME 欄位的名稱,如果是 TYPE 是 LVM
4875
		foreach($result["content"]["TYPE"] as $key=>$type){
4876
 
4877
			#如果 type 是 LVM
4878
			if($type==="lvm"){
4879
 
4880
				#暫存當前的 key
4881
				$curKey=$key;
4882
 
4883
				#如果往前找有 TYPE
4884
				while(isset($result["content"]["TYPE"][--$curKey])){
4885
 
4886
					#如果是 "part"
4887
					if($result["content"]["TYPE"][$curKey]==="part"){
4888
 
4889
						#將名稱當中的 "/dev" 置換為 "NAME"
4890
						#函式說明:
4891
						#處理字串避免網頁出錯
4892
						#回傳的結果:
4893
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4894
						#$result["function"],當前執行的函式.
4895
						#$result["content"],爲處理好的字串.
4896
						#$result["error"],錯誤訊息陣列.
4897
						#必填參數:
4898
						$conf["stringProcess::correctCharacter"]["stringIn"]=$result["content"]["NAME"][$key];#爲要處理的字串
4899
						#可省略參數:
4900
						$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("/dev");#爲被選擇要處理的字串/字元,須爲陣列值。
4901
							#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
4902
							#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
4903
						$conf["stringProcess::correctCharacter"]["changeTo"]=array($result["content"]["NAME"][$curKey]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
4904
						$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
4905
						unset($conf["stringProcess::correctCharacter"]);
4906
 
4907
						#如果轉換NAME失敗
4908
						if($correctCharacter["status"]=="false"){
4909
 
4910
							#設置執行失敗
4911
							$result["status"]="false";
4912
 
4913
							#設置執行錯誤訊息
4914
							$result["error"]=$correctCharacter;
4915
 
4916
							#回傳結果
4917
							return $result;
4918
 
4919
							}#if end
4920
 
4921
						#取得轉換好的 NAME
4922
						$result["content"]["NAME"][$key]=$correctCharacter["content"];
4923
 
4924
						#結束該 NAME 的修正
4925
						continue 2;
4926
 
4927
						}#if end
4928
 
4929
					}#while end
4930
 
4931
				#找不到歸屬的 PART
4932
 
4933
				#設置執行失敗
4934
				$result["status"]="false";
4935
 
4936
				#設置執行錯誤訊息
4937
				$result["error"]="找不到 ".$result["content"]["MOUNTPOINT"][$key]." 歸屬的分割區名稱";
4938
 
4939
				#回傳結果
4940
				return $result;
4941
 
4942
				}#if end
4943
 
4944
			}#foreach end
4945
 
4946
		#設置執行正常
4947
		$result["status"]="true";
4948
 
4949
		#回傳結果
4950
		return $result;
4951
 
4952
		}#function lsblk end
4953
 
4954
	/*
4955
	#函式說明:
4956
	#嘗試掛載儲存裝置
4957
	#回傳結果:
4958
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4959
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
4960
	#$result["warning"],警告訊息陣列.
4961
	#$result["function"],當前執行的函式名稱.
4962
	#$result["content"],lsblk的輸出內容.
4963
	#必填參數:
4964
	#$conf["device"],陣列,想要掛載的裝置勢別資訊,當塞選到只剩下一個儲存裝置時,將會掛載之.
4965
	$conf["device"]=array("");
4966
	#$conf["partNo"],字串,分割區號碼.
4967
	$conf["partNo"]="";
4968
	#$conf["mountPoint"],字串,想要掛載到哪邊.
4969
	$conf["mountPoint"]="";
4970
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
4971
	$conf["fileArgu"]=__FILE__;
4972
	#可省略參數:
4973
	#$conf["createMountPoint"],字串,當掛載點不存在時是否要建立其目錄與路徑,"true"代表要,"false"代表不要,預設為"false".
4974
	#$conf["createMountPoint"]="";
4975
	#參考資料:
4976
	#無.
4977
	#備註:
4978
	#無.
4979
	*/
4980
	public static function mountDev(&$conf){
4981
 
4982
		#初始化要回傳的結果
4983
		$result=array();
4984
 
4985
		#取得當前執行的函式名稱
4986
		$result["function"]=__FUNCTION__;
4987
 
4988
		#如果沒有參數
4989
		if(func_num_args()==0){
4990
 
4991
			#設置執行失敗
4992
			$result["status"]="false";
4993
 
4994
			#設置執行錯誤訊息
4995
			$result["error"]="函式".$result["function"]."需要參數";
4996
 
4997
			#回傳結果
4998
			return $result;
4999
 
5000
			}#if end
5001
 
5002
		#函式說明:
5003
		#判斷當前環境為web還是cmd
5004
		#回傳結果:
5005
		#$result,"web"或"cmd"
5006
		if(csInformation::getEnv()=="web"){
5007
 
5008
			#設置執行失敗
5009
			$result["status"]="false";
5010
 
5011
			#設置執行錯誤訊息
5012
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
5013
 
5014
			#回傳結果
5015
			return $result;
5016
 
5017
			}#if end
5018
 
5019
		#取得參數
5020
		$result["argu"]=$conf;
5021
 
5022
		#如果 $conf 不為陣列
5023
		if(gettype($conf)!="array"){
5024
 
5025
			#設置執行失敗
5026
			$result["status"]="false";
5027
 
5028
			#設置執行錯誤訊息
5029
			$result["error"][]="\$conf變數須為陣列形態";
5030
 
5031
			#如果傳入的參數為 null
5032
			if($conf==null){
5033
 
5034
				#設置執行錯誤訊息
5035
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
5036
 
5037
				}#if end
5038
 
5039
			#回傳結果
5040
			return $result;
5041
 
5042
			}#if end
5043
 
5044
		#檢查參數
5045
		#函式說明:
5046
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
5047
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5048
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5049
		#$result["function"],當前執行的函式名稱.
5050
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5051
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5052
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5053
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5054
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5055
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5056
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5057
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5058
		#必填寫的參數:
5059
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5060
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5061
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5062
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("device","partNo","mountPoint","fileArgu");
5063
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
5064
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string","string");
5065
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5066
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5067
		#可以省略的參數:
5068
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5069
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5070
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5071
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5072
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5073
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("createMountPoint");
5074
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5075
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
5076
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5077
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
5078
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5079
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("styleName","styleValue");
5080
		#參考資料來源:
5081
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5082
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5083
		unset($conf["variableCheck::checkArguments"]);
5084
 
5085
		#如果檢查參數失敗
5086
		if($checkArguments["status"]=="false"){
5087
 
5088
			#設置執行失敗
5089
			$result["status"]="false";
5090
 
5091
			#設置執行錯誤
5092
			$result["error"]=$checkArguments;
5093
 
5094
			#回傳結果
5095
			return $result;
5096
 
5097
			}#if end
5098
 
5099
		#如果檢查參數不通過
5100
		if($checkArguments["passed"]=="false"){
5101
 
5102
			#設置執行失敗
5103
			$result["status"]="false";
5104
 
5105
			#設置執行錯誤
5106
			$result["error"]=$checkArguments;
5107
 
5108
			#回傳結果
5109
			return $result;
5110
 
5111
			}#if end
5112
 
5113
		#函式說明:
5114
		#透過lsblk指令的輸出取得已經掛載的blk.
5115
		#回傳結果:
5116
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5117
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5118
		#$result["function"],當前執行的函式名稱.
5119
		#$result["content"],lsblk的輸出內容.
5120
		#必填參數:
5121
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5122
		$conf["cmd::lsblk"]["fileArgu"]=__FILE__;
5123
		#可省略參數:
5124
		#無.
5125
		#備註:
5126
		#完整解析NAME的規則目前找不到.
5127
		$lsblk=cmd::lsblk($conf["cmd::lsblk"]);
5128
		unset($conf["cmd::lsblk"]);
5129
 
5130
		#如果取得儲存裝置列表失敗
5131
		if($lsblk["status"]=="false"){
5132
 
5133
			#設置執行失敗
5134
			$result["status"]="false";
5135
 
5136
			#設置執行錯誤訊息
5137
			$result["error"]=$lsblk;
5138
 
5139
			#回傳結果
5140
			return $result;
5141
 
5142
			}#if end
5143
 
5144
		#初始化儲存符合條件的儲存裝置
5145
		$targetDevice=$lsblk["content"];
5146
 
5147
		#初始化暫存符合條件的儲存裝置
5148
		$newDevArray=array();
5149
 
5150
		#初始化儲存符合條件的裝置索引
5151
		$devNo=array();
5152
 
5153
		#依據每個篩選條件
5154
		foreach($conf["device"] as $fillter){
5155
 
5156
			#依據列表上的每個裝置屬性
5157
			foreach($targetDevice as $des => $devArray){
5158
 
5159
				#依據列表上的每個裝置
5160
				foreach($devArray as $devIndex =>$devInfo){
5161
 
5162
					#如果該裝置的資訊跟篩選條件一樣
5163
					if($devInfo===$fillter){
5164
 
5165
						#取得裝置的索引
5166
						$devNo[]=$devIndex;
5167
 
5168
						}#if end
5169
 
5170
					}#foreach end
5171
 
5172
				}#foreach end
5173
 
5174
			#如果存在 $devNo
5175
			if(count($devNo)>0){
5176
 
5177
				#依據每個符合條件的no
5178
				#更新target device
5179
				foreach($devNo as $no){
5180
 
5181
					#依據每個屬性
5182
					foreach($targetDevice as $attr=>$devArray){
5183
 
5184
						#依據每個裝置
5185
						foreach($devArray as $devIndex=>$devInfo){
5186
 
5187
							#如果是符合條件的裝置
5188
							if($devIndex==$no){
5189
 
5190
								#儲存之
5191
								$newDevArray[$attr][$devIndex]=$targetDevice[$attr][$devIndex];
5192
 
5193
								}#if end
5194
 
5195
							}#foreach end
5196
 
5197
						}#foreach end
5198
 
5199
					}#foreach end
5200
 
5201
				#清空要保留的裝置索引
5202
				$devNo=array();
5203
 
5204
				#如果有符合條件的裝置
5205
				if(isset($newDevArray["NAME"])){
5206
 
5207
					#更新可能的儲存裝置列表
5208
					$targetDevice=$newDevArray;
5209
 
5210
					}#if end
5211
 
5212
				}#if end
5213
 
5214
			}#foreach end
5215
 
5216
		#如果篩選完後的結果大於一個
5217
		if(count($targetDevice["NAME"])>1){
5218
 
5219
			#代表給與的篩選條件不足無法取得切確的裝置
5220
 
5221
			#設置執行錯誤訊息
5222
			$result["error"][]="沒有符合條件的裝置可以掛載";
5223
 
5224
			#設置執行失敗
5225
			$result["status"]="false";
5226
 
5227
			#回傳結果
5228
			return $result;
5229
 
5230
			}#if end
5231
 
5232
		#初始化儲存裝置的分隔區名稱
5233
		$diskName="";
5234
 
5235
		#初始化儲存裝置的掛載點
5236
		$mountPoint="";
5237
 
5238
		#取得裝置的名稱
5239
		foreach($targetDevice["NAME"] as $dn){
5240
 
5241
			#取得儲存裝置的分隔區名稱
5242
			$diskName=$dn;
5243
 
5244
			}#foreach end
5245
 
5246
		#初始化沒有找到分割區
5247
		$foundPart="false";
5248
 
5249
		#依據每個分割區的 NAME
5250
		foreach($lsblk["content"]["NAME"] as $devIndex=>$devInfo){
5251
 
5252
			#尋找有無分割區 $diskName.$conf["partNo"]
5253
			if($devInfo===$diskName.$conf["partNo"]){
5254
 
5255
				#取得儲存裝置的NAME
5256
				$diskName=$devInfo;
5257
 
5258
				#取得儲存裝置的掛載點
5259
				$mountPoint=$lsblk["content"]["MOUNTPOINT"][$devIndex];
5260
 
5261
				#設置有找到分割區
5262
				$foundPart="true";
5263
 
5264
				}#if end
5265
 
5266
			}#foreach end
5267
 
5268
		#如果沒有找到分割區
5269
		if($foundPart==="false"){
5270
 
5271
			#設置執行錯誤訊息
5272
			$result["error"][]="裝置的分割區「".$diskName."」不存在";
5273
 
5274
			#設置執行失敗
5275
			$result["status"]="false";
5276
 
5277
			#回傳結果
5278
			return $result;
5279
 
5280
			}#if end
5281
 
5282
		#取得root密碼
5283
		#函式說明:
5284
		#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
5285
		#回傳結果:
5286
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5287
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5288
		#$result["function"],當前執行的函式名稱.
5289
		#$result["content"],設定值內容.
5290
		#必填參數:
5291
		#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
5292
		$conf["cmd::getFromConf"]["readVarName"]="root-passwds";
5293
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5294
		$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];
5295
		#可省略參數:
5296
		#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
5297
		#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
5298
		#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
5299
		$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");
5300
		#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
5301
		#$conf["forceRewrite"]="";
5302
		$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
5303
		unset($conf["cmd::getFromConf"]);
5304
 
5305
		#如果取得 root 密碼失敗
5306
		if($getFromConf["status"]=="false"){
5307
 
5308
			#設置執行錯誤訊息
5309
			$result["error"]=$getFromConf;
5310
 
5311
			#設置執行失敗
5312
			$result["status"]="false";
5313
 
5314
			#回傳結果
5315
			return $result;
5316
 
5317
			}#if end
5318
 
5319
		#驗證密碼是否正確
5320
		#函式說明:
5321
		#驗證Linux使用者的密碼是否正確.
5322
		#回傳結果:
5323
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5324
		#$result["function"],當前執行的函式名稱.
5325
		#$result["error"],錯誤訊息陣列.
5326
		#$result["warninig"],警告訊息陣列.
5327
		#$result["valid"],是否為存在的使用者且密碼正確.
5328
		#必填參數:
5329
		#$conf["username"],字串,要驗證的使用者名稱.
5330
		$conf["authenticate::validUser"]["username"]="root";
5331
		#$conf["password"],字串,用於驗證使用者的密碼.
5332
		$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
5333
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5334
		$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
5335
		#備註:
5336
		#僅能在命令列環境下運行.
5337
		$validUser=authenticate::validUser($conf["authenticate::validUser"]);
5338
		unset($conf["authenticate::validUser"]);
5339
 
5340
		#如果驗證使用者失敗
5341
		if($validUser["status"]=="false"){
5342
 
5343
			#設置執行錯誤訊息
5344
			$result["error"]=$validUser;
5345
 
5346
			#設置執行失敗
5347
			$result["status"]="false";
5348
 
5349
			#回傳結果
5350
			return $result;
5351
 
5352
			}#if end
5353
 
5354
		#如果root密碼不正確
5355
		while($validUser["valid"]==="false"){
5356
 
5357
			#取得root密碼
5358
			#函式說明:
5359
			#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
5360
			#回傳結果:
5361
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5362
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
5363
			#$result["function"],當前執行的函式名稱.
5364
			#$result["content"],設定值內容.
5365
			#必填參數:
5366
			#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
5367
			$conf["cmd::getFromConf"]["readVarName"]="root-passwds";
5368
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5369
			$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];
5370
			#可省略參數:
5371
			#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
5372
			#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
5373
			#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
5374
			$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");
5375
			#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
5376
			$conf["cmd::getFromConf"]["forceRewrite"]="true";
5377
			$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
5378
			unset($conf["cmd::getFromConf"]);
5379
 
5380
			#如果取得 root 密碼失敗
5381
			if($getFromConf["status"]=="false"){
5382
 
5383
				#設置執行錯誤訊息
5384
				$result["error"]=$getFromConf;
5385
 
5386
				#設置執行失敗
5387
				$result["status"]="false";
5388
 
5389
				#回傳結果
5390
				return $result;
5391
 
5392
				}#if end
5393
 
5394
			#驗證密碼是否正確
5395
			#函式說明:
5396
			#驗證Linux使用者的密碼是否正確.
5397
			#回傳結果:
5398
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5399
			#$result["function"],當前執行的函式名稱.
5400
			#$result["error"],錯誤訊息陣列.
5401
			#$result["warninig"],警告訊息陣列.
5402
			#$result["valid"],是否為存在的使用者且密碼正確.
5403
			#必填參數:
5404
			#$conf["username"],字串,要驗證的使用者名稱.
5405
			$conf["authenticate::validUser"]["username"]="root";
5406
			#$conf["password"],字串,用於驗證使用者的密碼.
5407
			$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
5408
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5409
			$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
5410
			#備註:
5411
			#僅能在命令列環境下運行.
5412
			$validUser=authenticate::validUser($conf["authenticate::validUser"]);
5413
			unset($conf["authenticate::validUser"]);
5414
 
5415
			#如果驗證使用者失敗
5416
			if($validUser["status"]=="false"){
5417
 
5418
				#設置執行錯誤訊息
5419
				$result["error"]=$validUser;
5420
 
5421
				#設置執行失敗
5422
				$result["status"]="false";
5423
 
5424
				#回傳結果
5425
				return $result;
5426
 
5427
				}#if end
5428
 
5429
			}#if end
5430
 
5431
		#取得root密碼
5432
		$rootPasswd=$getFromConf["content"];
5433
 
5434
		#取得 $conf["mountPoint"] 的絕對位置
5435
		#函式說明:
5436
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
5437
		#回傳結果:
5438
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5439
		#$result["error"],錯誤訊息陣列.
5440
		#$result["function"],函式名稱.
5441
		#$result["content"],網址,若是在命令列執行,則為"null".
5442
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
5443
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
5444
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
5445
		#必填參數:
5446
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
5447
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["mountPoint"];
5448
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
5449
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
5450
		#可省略參數:
5451
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5452
		#$conf["fileAccess::getInternetAddress"]["userDir"]="true";
5453
		#備註:
5454
		#在命令列執行,所得的路徑是錯誤的。
5455
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
5456
		unset($conf["fileAccess::getInternetAddress"]);
5457
 
5458
		#如果取得路徑資訊失敗
5459
		if($getInternetAddress["status"]=="false"){
5460
 
5461
			#設置執行錯誤訊息
5462
			$result["error"]=$getInternetAddress;
5463
 
5464
			#設置執行失敗
5465
			$result["status"]="false";
5466
 
5467
			#回傳結果
5468
			return $result;
5469
 
5470
			}#if end
5471
 
5472
		#取得掛載點的絕對路徑
5473
		$conf["mountPoint"]=$getInternetAddress["fileSystemAbsoulutePosition"];
5474
 
5475
		#檢查掛載點是否存在
5476
		#函式說明:檢查多個檔案與資料夾是否存在.
5477
		#回傳的結果:
5478
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5479
		#$result["error"],錯誤訊息陣列.
5480
		#$resutl["function"],當前執行的函式名稱.
5481
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5482
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5483
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5484
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
5485
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5486
		#必填參數:
5487
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
5488
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["mountPoint"]);
5489
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5490
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5491
		#可省略參數
5492
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5493
		#$conf["disableWebSearch"]="false";
5494
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5495
		#$conf["userDir"]="true";
5496
		#參考資料來源:
5497
		#http://php.net/manual/en/function.file-exists.php
5498
		#http://php.net/manual/en/control-structures.foreach.php
5499
		#備註:
5500
		#函式file_exists檢查的路徑為檔案系統的路徑
5501
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5502
		unset($conf["fileAccess::checkMultiFileExist"]);
5503
 
5504
		#如果檢查掛載點失敗
5505
		if($checkMultiFileExist["status"]=="false"){
5506
 
5507
			#設置執行錯誤訊息
5508
			$result["error"]=$checkMultiFileExist;
5509
 
5510
			#設置執行失敗
5511
			$result["status"]="false";
5512
 
5513
			#回傳結果
5514
			return $result;
5515
 
5516
			}#if end
5517
 
5518
		#如果掛載點不存在
5519
		if($checkMultiFileExist["allExist"]=="false"){
5520
 
5521
			#如果有設定建立不存在的掛載點
5522
			if($conf["createMountPoint"]=="true"){
5523
 
5524
				#函式說明:
5525
				#確保路徑存在.
5526
				#回傳的結果:
5527
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5528
				#$result["error"],錯誤訊息陣列.
5529
				#$resutl["function"],當前執行的函式名稱.
5530
				#$result["path"],建立好的路徑字串.
5531
				#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
5532
				#必填參數:
5533
				#$conf["path"],要檢查的路徑
5534
				$conf["fileAccess::validatePath"]["path"]=$conf["mountPoint"];
5535
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5536
				$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
5537
				#可省略參數:
5538
				#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
5539
				#$conf["haveFileName"]="false";
5540
				#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
5541
				#$conf["dirPermission"]="";
5542
				$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
5543
				unset($conf["fileAccess::validatePath"]);
5544
 
5545
				#如果確保路徑失敗
5546
				if($validatePath["status"]=="false"){
5547
 
5548
					#設置執行錯誤訊息
5549
					$result["error"]=$validatePath;
5550
 
5551
					#設置執行失敗
5552
					$result["status"]="false";
5553
 
5554
					#回傳結果
5555
					return $result;
5556
 
5557
					}#if end
5558
 
5559
				#設置已經建立不存在的掛點點
5560
				$result["warning"][]="已經建立不存在的掛載點「".$conf["mountPoint"]."」";
5561
 
5562
				}#if end
5563
 
5564
			#反之
5565
			else{
5566
 
5567
				#設置執行錯誤訊息
5568
				$result["error"]=$checkMultiFileExist;
5569
 
5570
				#設置掛載點不存在的錯誤訊息
5571
				$result["error"][]="掛載點「".$conf["mountPoint"]."」不存在";
5572
 
5573
				#設置執行失敗
5574
				$result["status"]="false";
5575
 
5576
				#回傳結果
5577
				return $result;
5578
 
5579
				}#else end
5580
 
5581
			}#if end
5582
 
5583
		#如果儲存裝置已經掛載在其他地方了
5584
		if($mountPoint!="" && $mountPoint!=$conf["mountPoint"]){
5585
 
5586
			#卸載儲存裝置
5587
			#函式說明:
5588
			#呼叫shell執行系統命令,並取得回傳的內容.
5589
			#回傳的結果:
5590
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5591
			#$result["error"],錯誤訊息陣列.
5592
			#$result["function"],當前執行的函式名稱.
5593
			#$result["cmd"],執行的指令內容.
5594
			#$result["output"],爲執行完二元碼後的輸出陣列.
5595
			#必填參數
5596
			#$conf["command"],字串,要執行的指令與.
5597
			$conf["external::callShell"]["command"]="umount";
5598
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
5599
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5600
			#可省略參數:
5601
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5602
			$conf["external::callShell"]["argu"]=array($diskName);
5603
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5604
			#$conf["enablePrintDescription"]="true";
5605
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
5606
			#$conf["printDescription"]="";
5607
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
5608
			$conf["external::callShell"]["escapeshellarg"]="true";
5609
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
5610
			$conf["external::callShell"]["username"]="root";
5611
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
5612
			$conf["external::callShell"]["password"]=$rootPasswd;
5613
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
5614
			#$conf["useScript"]="";
5615
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
5616
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
5617
			#備註:
5618
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
5619
			#參考資料:
5620
			#exec=>http://php.net/manual/en/function.exec.php
5621
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
5622
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
5623
			$callShell=external::callShell($conf["external::callShell"]);
5624
			unset($conf["external::callShell"]);
5625
 
5626
			#如果卸載儲存裝置失敗
5627
			if($callShell["status"]=="false"){
5628
 
5629
				#設置執行錯誤訊息
5630
				$result["error"]=$callShell;
5631
 
5632
				#設置執行失敗
5633
				$result["status"]="false";
5634
 
5635
				#回傳結果
5636
				return $result;
5637
 
5638
				}#if end
5639
 
5640
			}#if
5641
 
5642
		#反之已經掛載在正確的地方了
5643
		else if($mountPoint==$conf["mountPoint"]){
5644
 
5645
			#設置執行警告訊息
5646
			$result["warning"][]="裝置「".$diskName."」已經掛載在「".$conf["mountPoint"]."」了";
5647
 
5648
			#設置執行正常
5649
			$result["status"]="true";
5650
 
5651
			#回傳結果
5652
			return $result;
5653
 
5654
			}#if end
5655
 
5656
		#掛載儲存裝置
5657
		#函式說明:
5658
		#呼叫shell執行系統命令,並取得回傳的內容.
5659
		#回傳的結果:
5660
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5661
		#$result["error"],錯誤訊息陣列.
5662
		#$result["function"],當前執行的函式名稱.
5663
		#$result["cmd"],執行的指令內容.
5664
		#$result["output"],爲執行完二元碼後的輸出陣列.
5665
		#必填參數
5666
		#$conf["command"],字串,要執行的指令與.
5667
		$conf["external::callShell"]["command"]="mount";
5668
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
5669
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5670
		#可省略參數:
5671
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5672
		$conf["external::callShell"]["argu"]=array($diskName,$conf["mountPoint"]);
5673
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5674
		#$conf["enablePrintDescription"]="true";
5675
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
5676
		#$conf["printDescription"]="";
5677
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
5678
		$conf["external::callShell"]["escapeshellarg"]="true";
5679
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
5680
		$conf["external::callShell"]["username"]="root";
5681
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
5682
		$conf["external::callShell"]["password"]=$rootPasswd;
5683
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
5684
		#$conf["useScript"]="";
5685
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
5686
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
5687
		#備註:
5688
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
5689
		#參考資料:
5690
		#exec=>http://php.net/manual/en/function.exec.php
5691
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
5692
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
5693
		$callShell=external::callShell($conf["external::callShell"]);
5694
		unset($conf["external::callShell"]);
5695
 
5696
		#如果掛載行動硬碟失敗
5697
		if($callShell["status"]=="false"){
5698
 
5699
			#設置執行錯誤訊息
5700
			$result["error"]=$callShell;
5701
 
5702
			#設置執行失敗
5703
			$result["status"]="false";
5704
 
5705
			#回傳結果
5706
			return $result;
5707
 
5708
			}#if end
5709
 
5710
		#設置執行正常
5711
		$result["status"]="true";
5712
 
5713
		#回傳結果
5714
		return $result;
5715
 
5716
		}#function mountDev end
5717
 
5718
	/*
5719
	#函式說明:
5720
	#卸載儲存裝置
5721
	#回傳結果:
5722
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5723
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5724
	#$result["warning"],警告訊息陣列.
5725
	#$result["function"],當前執行的函式名稱.
5726
	#$result["content"],lsblk的輸出內容.
5727
	#必填參數:
5728
	#$conf["device"],陣列,想要卸載的裝置勢別資訊,當塞選到只剩下一個儲存裝置時,將會掛載之.
5729
	$conf["device"]=array("");
5730
	#$conf["partNo"],字串,分割區號碼.
5731
	$conf["partNo"]="";
5732
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5733
	$conf["fileArgu"]=__FILE__;
5734
	#可省略參數:
5735
	#無.
5736
	#參考資料:
5737
	#無.
5738
	#備註:
5739
	#無.
5740
	*/
5741
	public static function umountDev(&$conf){
5742
 
5743
		#初始化要回傳的結果
5744
		$result=array();
5745
 
5746
		#取得當前執行的函式名稱
5747
		$result["function"]=__FUNCTION__;
5748
 
5749
		#如果沒有參數
5750
		if(func_num_args()==0){
5751
 
5752
			#設置執行失敗
5753
			$result["status"]="false";
5754
 
5755
			#設置執行錯誤訊息
5756
			$result["error"]="函式".$result["function"]."需要參數";
5757
 
5758
			#回傳結果
5759
			return $result;
5760
 
5761
			}#if end
5762
 
5763
		#函式說明:
5764
		#判斷當前環境為web還是cmd
5765
		#回傳結果:
5766
		#$result,"web"或"cmd"
5767
		if(csInformation::getEnv()=="web"){
5768
 
5769
			#設置執行失敗
5770
			$result["status"]="false";
5771
 
5772
			#設置執行錯誤訊息
5773
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
5774
 
5775
			#回傳結果
5776
			return $result;
5777
 
5778
			}#if end
5779
 
5780
		#取得參數
5781
		$result["argu"]=$conf;
5782
 
5783
		#如果 $conf 不為陣列
5784
		if(gettype($conf)!="array"){
5785
 
5786
			#設置執行失敗
5787
			$result["status"]="false";
5788
 
5789
			#設置執行錯誤訊息
5790
			$result["error"][]="\$conf變數須為陣列形態";
5791
 
5792
			#如果傳入的參數為 null
5793
			if($conf==null){
5794
 
5795
				#設置執行錯誤訊息
5796
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
5797
 
5798
				}#if end
5799
 
5800
			#回傳結果
5801
			return $result;
5802
 
5803
			}#if end
5804
 
5805
		#檢查參數
5806
		#函式說明:
5807
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
5808
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5809
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5810
		#$result["function"],當前執行的函式名稱.
5811
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5812
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5813
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5814
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5815
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5816
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5817
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5818
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5819
		#必填寫的參數:
5820
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5821
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5822
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5823
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("device","partNo","fileArgu");
5824
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
5825
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
5826
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5827
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5828
		#可以省略的參數:
5829
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5830
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5831
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5832
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5833
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5834
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array();
5835
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5836
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
5837
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5838
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__);
5839
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5840
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("styleName","styleValue");
5841
		#參考資料來源:
5842
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5843
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5844
		unset($conf["variableCheck::checkArguments"]);
5845
 
5846
		#如果檢查參數失敗
5847
		if($checkArguments["status"]=="false"){
5848
 
5849
			#設置執行失敗
5850
			$result["status"]="false";
5851
 
5852
			#設置執行錯誤
5853
			$result["error"]=$checkArguments;
5854
 
5855
			#回傳結果
5856
			return $result;
5857
 
5858
			}#if end
5859
 
5860
		#如果檢查參數不通過
5861
		if($checkArguments["passed"]=="false"){
5862
 
5863
			#設置執行失敗
5864
			$result["status"]="false";
5865
 
5866
			#設置執行錯誤
5867
			$result["error"]=$checkArguments;
5868
 
5869
			#回傳結果
5870
			return $result;
5871
 
5872
			}#if end
5873
 
5874
		#函式說明:
5875
		#透過lsblk指令的輸出取得已經掛載的blk.
5876
		#回傳結果:
5877
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5878
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5879
		#$result["function"],當前執行的函式名稱.
5880
		#$result["content"],lsblk的輸出內容.
5881
		#必填參數:
5882
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5883
		$conf["cmd::lsblk"]["fileArgu"]=$conf["fileArgu"];
5884
		#可省略參數:
5885
		#無.
5886
		$lsblk=cmd::lsblk($conf["cmd::lsblk"]);
5887
		unset($conf["cmd::lsblk"]);
5888
 
5889
		#如果取得儲存裝置列表失敗
5890
		if($lsblk["status"]=="false"){
5891
 
5892
			#設置執行失敗
5893
			$result["status"]="false";
5894
 
5895
			#設置執行錯誤訊息
5896
			$result["error"]=$lsblk;
5897
 
5898
			#回傳結果
5899
			return $result;
5900
 
5901
			}#if end
5902
 
5903
		#初始化儲存符合條件的儲存裝置
5904
		$targetDevice=$lsblk["content"];
5905
 
5906
		#初始化暫存符合條件的儲存裝置
5907
		$newDevArray=array();
5908
 
5909
		#初始化儲存符合條件的裝置索引
5910
		$devNo=array();
5911
 
5912
		#依據每個篩選條件
5913
		foreach($conf["device"] as $fillter){
5914
 
5915
			#依據列表上的每個裝置屬性
5916
			foreach($targetDevice as $des => $devArray){
5917
 
5918
				#依據列表上的每個裝置
5919
				foreach($devArray as $devIndex =>$devInfo){
5920
 
5921
					#如果該裝置的資訊跟篩選條件一樣
5922
					if($devInfo===$fillter){
5923
 
5924
						#取得裝置的索引
5925
						$devNo[]=$devIndex;
5926
 
5927
						}#if end
5928
 
5929
					}#foreach end
5930
 
5931
				}#foreach end
5932
 
5933
			#如果存在 $devNo
5934
			if(count($devNo)>0){
5935
 
5936
				#依據每個符合條件的no
5937
				#更新target device
5938
				foreach($devNo as $no){
5939
 
5940
					#依據每個屬性
5941
					foreach($targetDevice as $attr=>$devArray){
5942
 
5943
						#依據每個裝置
5944
						foreach($devArray as $devIndex=>$devInfo){
5945
 
5946
							#如果是符合條件的裝置
5947
							if($devIndex==$no){
5948
 
5949
								#儲存之
5950
								$newDevArray[$attr][$devIndex]=$targetDevice[$attr][$devIndex];
5951
 
5952
								}#if end
5953
 
5954
							}#foreach end
5955
 
5956
						}#foreach end
5957
 
5958
					}#foreach end
5959
 
5960
				#清空要保留的裝置索引
5961
				$devNo=array();
5962
 
5963
				#如果有符合條件的裝置
5964
				if(isset($newDevArray["NAME"])){
5965
 
5966
					#更新可能的儲存裝置列表
5967
					$targetDevice=$newDevArray;
5968
 
5969
					}#if end
5970
 
5971
				}#if end
5972
 
5973
			}#foreach end
5974
 
5975
		#如果篩選完後的結果大於一個
5976
		if(count($targetDevice["NAME"])>1){
5977
 
5978
			#代表給與的篩選條件不足無法取得切確的裝置
5979
 
5980
			#設置執行錯誤訊息
5981
			$result["error"][]="沒有符合條件的裝置可以卸載";
5982
 
5983
			#設置執行失敗
5984
			$result["status"]="false";
5985
 
5986
			#回傳結果
5987
			return $result;
5988
 
5989
			}#if end
5990
 
5991
		#初始化儲存裝置的分隔區名稱
5992
		$diskName="";
5993
 
5994
		#初始化儲存裝置的掛載點
5995
		$mountPoint="";
5996
 
5997
		#取得裝置的名稱
5998
		foreach($targetDevice["NAME"] as $dn){
5999
 
6000
			#取得儲存裝置的分隔區名稱
6001
			$diskName=$dn;
6002
 
6003
			}#foreach end
6004
 
6005
		#初始化沒有找到分割區
6006
		$foundPart="false";
6007
 
6008
		#依據每個分割區的 NAME
6009
		foreach($lsblk["content"]["NAME"] as $devIndex=>$devInfo){
6010
 
6011
			#尋找有無分割區 $diskName.$conf["partNo"]
6012
			if($devInfo===$diskName.$conf["partNo"]){
6013
 
6014
				#取得儲存裝置的NAME
6015
				$diskName=$devInfo;
6016
 
6017
				#取得儲存裝置的掛載點
6018
				$mountPoint=$lsblk["content"]["MOUNTPOINT"][$devIndex];
6019
 
6020
				#設置有找到分割區
6021
				$foundPart="true";
6022
 
6023
				}#if end
6024
 
6025
			}#foreach end
6026
 
6027
		#如果沒有找到分割區
6028
		if($foundPart==="false"){
6029
 
6030
			#設置執行錯誤訊息
6031
			$result["error"][]="裝置的分割區「".$diskName."」不存在";
6032
 
6033
			#設置執行失敗
6034
			$result["status"]="false";
6035
 
6036
			#回傳結果
6037
			return $result;
6038
 
6039
			}#if end
6040
 
6041
		#如果要被卸載的分割區沒有被掛載
6042
		if($mountPoint==""){
6043
 
6044
			#設置執行錯誤訊息
6045
			$result["error"][]="裝置的分割區「".$diskName."」並未被掛載";
6046
 
6047
			#設置執行失敗
6048
			$result["status"]="false";
6049
 
6050
			#回傳結果
6051
			return $result;
6052
 
6053
			}#if end
6054
 
6055
		#取得root密碼
6056
		#函式說明:
6057
		#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
6058
		#回傳結果:
6059
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6060
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6061
		#$result["function"],當前執行的函式名稱.
6062
		#$result["content"],設定值內容.
6063
		#必填參數:
6064
		#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
6065
		$conf["cmd::getFromConf"]["readVarName"]="root-passwds";
6066
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6067
		$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];
6068
		#可省略參數:
6069
		#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
6070
		#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
6071
		#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
6072
		$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");
6073
		#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
6074
		#$conf["forceRewrite"]="";
6075
		$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
6076
		unset($conf["cmd::getFromConf"]);
6077
 
6078
		#如果取得 root 密碼失敗
6079
		if($getFromConf["status"]=="false"){
6080
 
6081
			#設置執行錯誤訊息
6082
			$result["error"]=$getFromConf;
6083
 
6084
			#設置執行失敗
6085
			$result["status"]="false";
6086
 
6087
			#回傳結果
6088
			return $result;
6089
 
6090
			}#if end
6091
 
6092
		#驗證密碼是否正確
6093
		#函式說明:
6094
		#驗證Linux使用者的密碼是否正確.
6095
		#回傳結果:
6096
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6097
		#$result["function"],當前執行的函式名稱.
6098
		#$result["error"],錯誤訊息陣列.
6099
		#$result["warninig"],警告訊息陣列.
6100
		#$result["valid"],是否為存在的使用者且密碼正確.
6101
		#必填參數:
6102
		#$conf["username"],字串,要驗證的使用者名稱.
6103
		$conf["authenticate::validUser"]["username"]="root";
6104
		#$conf["password"],字串,用於驗證使用者的密碼.
6105
		$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
6106
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6107
		$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
6108
		#備註:
6109
		#僅能在命令列環境下運行.
6110
		$validUser=authenticate::validUser($conf["authenticate::validUser"]);
6111
		unset($conf["authenticate::validUser"]);
6112
 
6113
		#如果驗證使用者失敗
6114
		if($validUser["status"]=="false"){
6115
 
6116
			#設置執行錯誤訊息
6117
			$result["error"]=$validUser;
6118
 
6119
			#設置執行失敗
6120
			$result["status"]="false";
6121
 
6122
			#回傳結果
6123
			return $result;
6124
 
6125
			}#if end
6126
 
6127
		#如果root密碼不正確
6128
		while($validUser["valid"]=="false"){
6129
 
6130
			#取得root密碼
6131
			#函式說明:
6132
			#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
6133
			#回傳結果:
6134
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6135
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
6136
			#$result["function"],當前執行的函式名稱.
6137
			#$result["content"],設定值內容.
6138
			#必填參數:
6139
			#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
6140
			$conf["cmd::getFromConf"]["readVarName"]="root-passwds";
6141
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6142
			$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];
6143
			#可省略參數:
6144
			#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
6145
			#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
6146
			#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
6147
			$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");
6148
			#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
6149
			$conf["cmd::getFromConf"]["forceRewrite"]="true";
6150
			$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
6151
			unset($conf["cmd::getFromConf"]);
6152
 
6153
			#如果取得 root 密碼失敗
6154
			if($getFromConf["status"]=="false"){
6155
 
6156
				#設置執行錯誤訊息
6157
				$result["error"]=$getFromConf;
6158
 
6159
				#設置執行失敗
6160
				$result["status"]="false";
6161
 
6162
				#回傳結果
6163
				return $result;
6164
 
6165
				}#if end
6166
 
6167
			#驗證密碼是否正確
6168
			#函式說明:
6169
			#驗證Linux使用者的密碼是否正確.
6170
			#回傳結果:
6171
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6172
			#$result["function"],當前執行的函式名稱.
6173
			#$result["error"],錯誤訊息陣列.
6174
			#$result["warninig"],警告訊息陣列.
6175
			#$result["valid"],是否為存在的使用者且密碼正確.
6176
			#必填參數:
6177
			#$conf["username"],字串,要驗證的使用者名稱.
6178
			$conf["authenticate::validUser"]["username"]="root";
6179
			#$conf["password"],字串,用於驗證使用者的密碼.
6180
			$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
6181
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6182
			$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
6183
			#備註:
6184
			#僅能在命令列環境下運行.
6185
			$validUser=authenticate::validUser($conf["authenticate::validUser"]);
6186
			unset($conf["authenticate::validUser"]);
6187
 
6188
			#如果驗證使用者失敗
6189
			if($validUser["status"]=="false"){
6190
 
6191
				#設置執行錯誤訊息
6192
				$result["error"]=$validUser;
6193
 
6194
				#設置執行失敗
6195
				$result["status"]="false";
6196
 
6197
				#回傳結果
6198
				return $result;
6199
 
6200
				}#if end
6201
 
6202
			}#if end
6203
 
6204
		#取得root密碼
6205
		$rootPasswd=$getFromConf["content"];
6206
 
6207
		#卸載儲存裝置
6208
		#函式說明:
6209
		#呼叫shell執行系統命令,並取得回傳的內容.
6210
		#回傳的結果:
6211
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6212
		#$result["error"],錯誤訊息陣列.
6213
		#$result["function"],當前執行的函式名稱.
6214
		#$result["cmd"],執行的指令內容.
6215
		#$result["output"],爲執行完二元碼後的輸出陣列.
6216
		#必填參數
6217
		#$conf["command"],字串,要執行的指令與.
6218
		$conf["external::callShell"]["command"]="umount";
6219
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6220
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
6221
		#可省略參數:
6222
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
6223
		$conf["external::callShell"]["argu"]=array($diskName);
6224
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
6225
		#$conf["enablePrintDescription"]="true";
6226
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
6227
		#$conf["printDescription"]="";
6228
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
6229
		#$conf["escapeshellarg"]="false";
6230
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
6231
		$conf["external::callShell"]["username"]="root";
6232
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
6233
		$conf["external::callShell"]["password"]=$rootPasswd;
6234
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
6235
		#$conf["useScript"]="";
6236
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
6237
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
6238
		#備註:
6239
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
6240
		#參考資料:
6241
		#exec=>http://php.net/manual/en/function.exec.php
6242
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
6243
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
6244
		$callShell=external::callShell($conf["external::callShell"]);
6245
		unset($conf["external::callShell"]);
6246
 
6247
		#如果卸載儲存裝置失敗
6248
		if($callShell["status"]=="false"){
6249
 
6250
			#設置執行錯誤訊息
6251
			$result["error"]=$callShell;
6252
 
6253
			#設置執行失敗
6254
			$result["status"]="false";
6255
 
6256
			#回傳結果
6257
			return $result;
6258
 
6259
			}#if end
6260
 
6261
		#設置執行正常
6262
		$result["status"]="true";
6263
 
6264
		#回傳結果
6265
		return $result;
6266
 
6267
		}#function umountDev end
6268
 
6269
	/*
6270
	#函式說明:
6271
	#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確
6272
	#回傳結果:
6273
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6274
	#$result["function"],當前執行的函式名稱.
6275
	#$result["error"],錯誤訊息陣列.
6276
	#$result["content"],帳戶密碼.
6277
	#必填參數:
6278
	#$conf["fileArgu"],字串,__FILE__的內容.
6279
	$conf["fileArgu"]=__FILE__;
6280
	#可省略參數:
6281
	#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".
6282
	#$conf["password"]="";
6283
	#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.
6284
	#$conf["username"]="";
6285
	#參考資料:
6286
	#無.
6287
	#備註:
6288
	#無.
6289
	*/
6290
	public static function validRootPasswd(&$conf=array()){
6291
 
6292
		#初始化要回傳的結果
6293
		$result=array();
6294
 
6295
		#取得當前執行的函式名稱
6296
		$result["function"]=__FUNCTION__;
6297
 
6298
		#如果沒有參數
6299
		if(func_num_args()==0){
6300
 
6301
			#設置執行失敗
6302
			$result["status"]="false";
6303
 
6304
			#設置執行錯誤訊息
6305
			$result["error"]="函式".$result["function"]."需要參數";
6306
 
6307
			#回傳結果
6308
			return $result;
6309
 
6310
			}#if end
6311
 
6312
		#函式說明:
6313
		#判斷當前環境為web還是cmd
6314
		#回傳結果:
6315
		#$result,"web"或"cmd"
6316
		if(csInformation::getEnv()==="web"){
6317
 
6318
			#設置執行失敗
6319
			$result["status"]="false";
6320
 
6321
			#設置執行錯誤訊息
6322
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
6323
 
6324
			#回傳結果
6325
			return $result;
6326
 
6327
			}#if end
6328
 
6329
		#取得參數
6330
		$result["argu"]=$conf;
6331
 
6332
		#如果 $conf 不為陣列
6333
		if(gettype($conf)!=="array"){
6334
 
6335
			#設置執行失敗
6336
			$result["status"]="false";
6337
 
6338
			#設置執行錯誤訊息
6339
			$result["error"][]="\$conf變數須為陣列形態";
6340
 
6341
			#如果傳入的參數為 null
6342
			if($conf===null){
6343
 
6344
				#設置執行錯誤訊息
6345
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
6346
 
6347
				}#if end
6348
 
6349
			#回傳結果
6350
			return $result;
6351
 
6352
			}#if end
6353
 
6354
		#檢查參數
6355
		#函式說明:
6356
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
6357
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6358
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6359
		#$result["function"],當前執行的函式名稱.
6360
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6361
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6362
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6363
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6364
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6365
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6366
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6367
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6368
		#必填寫的參數:
6369
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6370
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6371
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6372
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
6373
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
6374
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6375
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6376
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6377
		#可以省略的參數:
6378
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6379
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6380
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列
6381
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("password");
6382
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列
6383
		$conf["variableCheck::checkArguments"]["canBeEmpty"]=array("password");
6384
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6385
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6386
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6387
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("password","username");
6388
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6389
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
6390
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6391
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("rootPasswd","root");
6392
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6393
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
6394
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
6395
		#參考資料來源:
6396
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6397
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6398
		unset($conf["variableCheck::checkArguments"]);
6399
 
6400
		#如果檢查參數失敗
6401
		if($checkArguments["status"]=="false"){
6402
 
6403
			#設置執行不正常
6404
			$result["status"]="false";
6405
 
6406
			#設置執行錯誤
6407
			$result["error"]=$checkArguments;
6408
 
6409
			#回傳結果
6410
			return $result;
6411
 
6412
			}#if end
6413
 
6414
		#如果檢查參數不通過
6415
		if($checkArguments["passed"]=="false"){
6416
 
6417
			#設置執行不正常
6418
			$result["status"]="false";
6419
 
6420
			#設置執行錯誤
6421
			$result["error"]=$checkArguments;
6422
 
6423
			#回傳結果
6424
			return $result;
6425
 
6426
			}#if end
6427
 
6428
		#驗證root帳號的密碼
6429
		#函式說明:
6430
		#驗證Linux使用者的密碼是否正確.
6431
		#回傳結果:
6432
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6433
		#$result["function"],當前執行的函式名稱.
6434
		#$result["error"],錯誤訊息陣列.
6435
		#$result["warninig"],警告訊息陣列.
6436
		#$result["valid"],是否為存在的使用者且密碼正確.
6437
		#必填參數:
6438
		#$conf["username"],字串,要驗證的使用者名稱.
6439
		$conf["authenticate::validUser"]["username"]=$conf["username"];
6440
		#$conf["password"],字串,用於驗證使用者的密碼.
6441
		$conf["authenticate::validUser"]["password"]=$conf["password"];
6442
		#$conf["fileArgu"],字串,__FILE__的內容.
6443
		$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
6444
		#備註:
6445
		#僅能在命令列環境下運行.
6446
		$validUser=authenticate::validUser($conf["authenticate::validUser"]);
6447
		unset($conf["authenticate::validUser"]);
6448
 
6449
		#如果認證root密碼失敗
6450
		if($validUser["status"]==="false"){
6451
 
6452
			#設置執行不正常
6453
			$result["status"]="false";
6454
 
6455
			#設置執行錯誤
6456
			$result["error"]=$validUser;
6457
 
6458
			#回傳結果
6459
			return $result;
6460
 
6461
			}#if end
6462
 
6463
		#如果驗證使用者不通過
6464
		if($validUser["valid"]==="false"){
6465
 
6466
			#請使用者輸入帳戶的密碼
6467
			#函式說明:
6468
			#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
6469
			#回傳結果:
6470
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6471
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
6472
			#$result["function"],當前執行的函式名稱.
6473
			#$result["content"],設定值內容.
6474
			#必填參數:
6475
			#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
6476
			$conf["cmd::getFromConf"]["readVarName"]="cmd::valid".$conf["username"]."Passwd";
6477
			#可省略參數:
6478
			#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
6479
			#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
6480
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6481
			#$conf["fileArgu"]=__FILE__;
6482
			#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
6483
			$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入".$conf["username"]."帳戶的密碼:");
6484
			#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
6485
			$conf["cmd::getFromConf"]["forceRewrite"]="true";
6486
			$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
6487
			unset($conf["cmd::getFromConf"]);
6488
 
6489
			#如果輸入root密碼失敗
6490
			if($getFromConf["status"]==="false"){
6491
 
6492
				#設置執行不正常
6493
				$result["status"]="false";
6494
 
6495
				#設置執行錯誤
6496
				$result["error"]=$getFromConf;
6497
 
6498
				#回傳結果
6499
				return $result;
6500
 
6501
				}#if end
6502
 
6503
			#驗證帳號的密碼
6504
			#函式說明:
6505
			#驗證Linux使用者的密碼是否正確.
6506
			#回傳結果:
6507
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6508
			#$result["function"],當前執行的函式名稱.
6509
			#$result["error"],錯誤訊息陣列.
6510
			#$result["warninig"],警告訊息陣列.
6511
			#$result["valid"],是否為存在的使用者且密碼正確.
6512
			#必填參數:
6513
			#$conf["username"],字串,要驗證的使用者名稱.
6514
			$conf["authenticate::validUser"]["username"]=$conf["username"];
6515
			#$conf["password"],字串,用於驗證使用者的密碼.
6516
			$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
6517
			#$conf["fileArgu"],字串,__FILE__的內容.
6518
			$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
6519
			#備註:
6520
			#僅能在命令列環境下運行.
6521
			$validUser=authenticate::validUser($conf["authenticate::validUser"]);
6522
			unset($conf["authenticate::validUser"]);
6523
 
6524
			#如果認證root密碼失敗
6525
			if($validUser["status"]==="false"){
6526
 
6527
				#設置執行不正常
6528
				$result["status"]="false";
6529
 
6530
				#設置執行錯誤
6531
				$result["error"]=$validUser;
6532
 
6533
				#回傳結果
6534
				return $result;
6535
 
6536
				}#if end
6537
 
6538
			#如果認證密碼不正確
6539
			while($validUser["valid"]==="false"){
6540
 
6541
				#請使用者輸入root帳戶的密碼
6542
				#函式說明:
6543
				#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
6544
				#回傳結果:
6545
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6546
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
6547
				#$result["function"],當前執行的函式名稱.
6548
				#$result["content"],設定值內容.
6549
				#必填參數:
6550
				#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
6551
				$conf["cmd::getFromConf"]["readVarName"]="cmd::valid".$conf["username"]."Passwd";
6552
				#可省略參數:
6553
				#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
6554
				#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
6555
				#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6556
				#$conf["fileArgu"]=__FILE__;
6557
				#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
6558
				$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入".$conf["username"]."帳戶的密碼:");
6559
				#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
6560
				$conf["cmd::getFromConf"]["forceRewrite"]="true";
6561
				$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
6562
				unset($conf["cmd::getFromConf"]);
6563
 
6564
				#如果輸入root密碼失敗
6565
				if($getFromConf["status"]==="false"){
6566
 
6567
					#設置執行不正常
6568
					$result["status"]="false";
6569
 
6570
					#設置執行錯誤
6571
					$result["error"]=$getFromConf;
6572
 
6573
					#回傳結果
6574
					return $result;
6575
 
6576
					}#if end
6577
 
6578
				#驗證密碼是否正確
6579
				#函式說明:
6580
				#驗證Linux使用者的密碼是否正確.
6581
				#回傳結果:
6582
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6583
				#$result["function"],當前執行的函式名稱.
6584
				#$result["error"],錯誤訊息陣列.
6585
				#$result["warninig"],警告訊息陣列.
6586
				#$result["valid"],是否為存在的使用者且密碼正確.
6587
				#必填參數:
6588
				#$conf["username"],字串,要驗證的使用者名稱.
6589
				$conf["authenticate::validUser"]["username"]=$conf["username"];
6590
				#$conf["password"],字串,用於驗證使用者的密碼.
6591
				$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
6592
				#$conf["fileArgu"],字串,__FILE__的內容.
6593
				$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
6594
				#備註:
6595
				#僅能在命令列環境下運行.
6596
				$validUser=authenticate::validUser($conf["authenticate::validUser"]);
6597
				unset($conf["authenticate::validUser"]);
6598
 
6599
				#如果認證帳戶失敗
6600
				if($validUser["status"]==="false"){
6601
 
6602
					#設置執行不正常
6603
					$result["status"]="false";
6604
 
6605
					#設置執行錯誤
6606
					$result["error"]=$validUser;
6607
 
6608
					#回傳結果
6609
					return $result;
6610
 
6611
					}#if end
6612
 
6613
				#如果帳戶認證的密碼正確
6614
				if($validUser["valid"]==="true"){
6615
 
6616
					#更新認證用的密碼
6617
					$conf["password"]=$getFromConf["content"];
6618
 
6619
					#跳出while
6620
					break;
6621
 
6622
					}#if end
6623
 
6624
				}#while end
6625
 
6626
			}#if end
6627
 
6628
		#如果沒有從設定檔取得的密碼
6629
		if(!isset($getFromConf["content"])){
6630
 
6631
			#代表一開始設定的密碼就是正確的
6632
			$result["content"]=$conf["password"];
6633
 
6634
			}#if end
6635
 
6636
		#反之設定檔中的密碼才是正確的
6637
		else{
6638
 
6639
			#取得正確的密碼
6640
			$result["content"]=$getFromConf["content"];
6641
 
6642
			}#else end
6643
 
6644
		#設置執行正常
6645
		$result["status"]="true";
6646
 
6647
		#回傳結果
6648
		return $result;
6649
 
6650
		}#function validRootPasswd end
6651
 
6652
	/*
6653
	#函式說明:
6654
	#取得檔案的內容並以列為單位搜尋多個關鍵字.
6655
	#回傳結果:
6656
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6657
	#$result["error"],錯誤訊息.
6658
	#$result["function"],當前執行的函式名稱.
6659
	#$result["content"],取得讀取到的檔案內容.
6660
	#$result["founded"],每個關鍵字串尋找的結果,"true"代表有找到,"false"代表沒有找到.
6661
	#$result["foundedLine"],每個找到的關鍵字是在第幾列找到的,key值與$result["founded"]的key值一樣.
6662
	#$result["foundedAll"],是否每個關鍵字串都有找到,"true"代表有,"false"代表沒有.
6663
	#必填參數:
6664
	#$conf["file"],字串,檔案的位置與名稱.
6665
	$conf["file"]="";
6666
	#$conf["keyStr"],陣列字串,要搜尋每列有哪些關鍵字串.
6667
	$conf["keyStr"]=array();
6668
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6669
	$conf["fileArgu"]=__FILE__;
6670
	#可省略參數:
6671
	#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
6672
	#$conf["username"]="";
6673
	#$conf["password"],字串,使用者對應的密碼,預設不使用.
6674
	#$conf["password"]="";
6675
	#$conf["tempDir"],字串,暫存資料的目錄位置,預設為".cmd/checkFileKeyStrLBL".
6676
	#$conf["tempDir"]="";
6677
	#參考資料:
6678
	#無.
6679
	#備註:
6680
	#僅能在命令列環境下運行
6681
	*/
6682
	public static function checkFileKeyStrLBL(&$conf){
6683
 
6684
		#初始化要回傳的結果
6685
		$result=array();
6686
 
6687
		#取得當前執行的函式名稱
6688
		$result["function"]=__FUNCTION__;
6689
 
6690
		#如果沒有參數
6691
		if(func_num_args()==0){
6692
 
6693
			#設置執行失敗
6694
			$result["status"]="false";
6695
 
6696
			#設置執行錯誤訊息
6697
			$result["error"]="函式".$result["function"]."需要參數";
6698
 
6699
			#回傳結果
6700
			return $result;
6701
 
6702
			}#if end
6703
 
6704
		#函式說明:
6705
		#判斷當前環境為web還是cmd
6706
		#回傳結果:
6707
		#$result,"web"或"cmd"
6708
		if(csInformation::getEnv()==="web"){
6709
 
6710
			#設置執行失敗
6711
			$result["status"]="false";
6712
 
6713
			#設置執行錯誤訊息
6714
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
6715
 
6716
			#回傳結果
6717
			return $result;
6718
 
6719
			}#if end
6720
 
6721
		#取得參數
6722
		$result["argu"]=$conf;
6723
 
6724
		#如果 $conf 不為陣列
6725
		if(gettype($conf)!=="array"){
6726
 
6727
			#設置執行失敗
6728
			$result["status"]="false";
6729
 
6730
			#設置執行錯誤訊息
6731
			$result["error"][]="\$conf變數須為陣列形態";
6732
 
6733
			#如果傳入的參數為 null
6734
			if(is_null($conf)){
6735
 
6736
				#設置執行錯誤訊息
6737
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
6738
 
6739
				}#if end
6740
 
6741
			#回傳結果
6742
			return $result;
6743
 
6744
			}#if end
6745
 
6746
		#檢查參數
6747
		#函式說明:
6748
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
6749
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6750
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6751
		#$result["function"],當前執行的函式名稱.
6752
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6753
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6754
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6755
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6756
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6757
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6758
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6759
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6760
		#必填寫的參數:
6761
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6762
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6763
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6764
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","keyStr","fileArgu");
6765
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
6766
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
6767
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6768
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6769
		#可以省略的參數:
6770
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6771
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6772
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
6773
		#$conf["canNotBeEmpty"]=array();
6774
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
6775
		#$conf["canBeEmpty"]=array();
6776
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
6777
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6778
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6779
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","tempDir");
6780
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6781
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
6782
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6783
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,".cmd/checkFileKeyStrLBL");
6784
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6785
		#$conf["arrayCountEqualCheck"][]=array();
6786
		#參考資料來源:
6787
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6788
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6789
		unset($conf["variableCheck::checkArguments"]);
6790
 
6791
		#如果參數檢查失敗
6792
		if($checkArguments["status"]==="false"){
6793
 
6794
			#設置執行不正常
6795
			$result["status"]="false";
6796
 
6797
			#設置執行錯誤
6798
			$result["error"]=$checkArguments;
6799
 
6800
			#回傳結果
6801
			return $result;
6802
 
6803
			}#if end
6804
 
6805
		#如果參數檢查不通過
6806
		if($checkArguments["passed"]==="false"){
6807
 
6808
			#設置執行不正常
6809
			$result["status"]="false";
6810
 
6811
			#設置執行錯誤
6812
			$result["error"]=$checkArguments;
6813
 
6814
			#回傳結果
6815
			return $result;
6816
 
6817
			}#if end
6818
 
6819
		#函式說明:
6820
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
6821
		#回傳結果:
6822
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6823
		#$result["error"],錯誤訊息陣列.
6824
		#$result["function"],函式名稱.
6825
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
6826
		#必填參數:
6827
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
6828
		$conf["fileAccess::getRelativePath"]["path"]=array($conf["tempDir"]);
6829
		#$conf["fileArgu"],字串,當前路徑.
6830
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
6831
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
6832
		unset($conf["fileAccess::getRelativePath"]);
6833
 
6834
		#如果轉換路徑失敗
6835
		if($getRelativePath["status"]==="false"){
6836
 
6837
			#設置執行不正常
6838
			$result["status"]="false";
6839
 
6840
			#設置執行錯誤
6841
			$result["error"]=$getRelativePath;
6842
 
6843
			#回傳結果
6844
			return $result;
6845
 
6846
			}#if end
6847
 
6848
		#取得暫存目錄的相對路徑
6849
		$conf["tempDir"]=$getRelativePath["content"][0];
6850
 
6851
		#如果有設置密碼且使用者不為 $_SERVER["LOGNAME"]
6852
		if(isset($conf["password"]) && $conf["username"]!==$_SERVER["LOGNAME"]){
6853
 
6854
			#驗證使用者與密碼
6855
			#函式說明:
6856
			#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確
6857
			#回傳結果:
6858
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6859
			#$result["function"],當前執行的函式名稱.
6860
			#$result["error"],錯誤訊息陣列.
6861
			#$result["content"],帳戶密碼.
6862
			#必填參數:
6863
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6864
			$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];
6865
			#可省略參數:
6866
			#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".
6867
			$conf["cmd::validRootPasswd"]["password"]=$conf["password"];
6868
			#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.
6869
			$conf["cmd::validRootPasswd"]["username"]=$conf["username"];
6870
			$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);
6871
			unset($conf["cmd::validRootPasswd"]);
6872
 
6873
			#如果認證失敗
6874
			if($validRootPasswd["status"]==="false"){
6875
 
6876
				#設置執行不正常
6877
				$result["status"]="false";
6878
 
6879
				#設置執行錯誤
6880
				$result["error"]=$validRootPasswd;
6881
 
6882
				#回傳結果
6883
				return $result;
6884
 
6885
				}#if end
6886
 
6887
			}#if end
6888
 
6889
		#確認檔案是否存在
6890
		#函式說明:
6891
		#用shell檢查檔案是否存在,可以指定查詢時用的身份.
6892
		#回傳的結果:
6893
		#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
6894
		#$result["function"],當前執行的函式名稱.
6895
		#$result["error"],錯誤訊息陣列.
6896
		#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案.
6897
		#必填參數:
6898
		#$conf["fileName"],字串,要檢查的檔案名稱.
6899
		$conf["cmd::checkFileExist"]["fileName"]=$conf["file"];
6900
		#可省略參數:
6901
		#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.
6902
		$conf["cmd::checkFileExist"]["username"]=$conf["username"];
6903
 
6904
		#如果有設置 $conf["password"]
6905
		if(isset($conf["password"])){
6906
 
6907
			#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.
6908
			$conf["cmd::checkFileExist"]["password"]=$conf["password"];
6909
 
6910
			}#if end
6911
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6912
		$conf["cmd::checkFileExist"]["fileArgu"]=$conf["fileArgu"];
6913
		#備註:
6914
		#該函式若使用可省略參數,則無法在web環境下運行
6915
		$checkFileExist=cmd::checkFileExist($conf["cmd::checkFileExist"]);
6916
		unset($conf["cmd::checkFileExist"]);
6917
 
6918
		#如果檢查檔案是否存在失敗
6919
		if($checkFileExist["status"]==="false"){
6920
 
6921
			#設置執行不正常
6922
			$result["status"]="false";
6923
 
6924
			#設置執行錯誤
6925
			$result["error"]=$checkFileExist;
6926
 
6927
			#回傳結果
6928
			return $result;
6929
 
6930
			}#if end
6931
 
6932
		#如果檔案不存在
6933
		if($checkFileExist["founded"]==="false"){
6934
 
6935
			#設置執行不正常
6936
			$result["status"]="false";
6937
 
6938
			#設置執行錯誤
6939
			$result["error"]=$checkFileExist;
6940
 
6941
			#回傳結果
6942
			return $result;
6943
 
6944
			}#if end
6945
 
6946
		#建立暫存目錄
6947
		#函式說明:
6948
		#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
6949
		#回傳的結果:
6950
		#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
6951
		#$result["error"],錯誤訊息陣列.
6952
		#$result["function"],當前執行的函式名稱.
6953
		#$result["content"],建立的目錄路徑.
6954
		#必填參數:
6955
		#$conf["dirPositionAndName"]="";#新建的位置與名稱
6956
		$conf["fileAccess::createNewFolder"]["dirPositionAndName"]=$conf["tempDir"];
6957
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6958
		$conf["fileAccess::createNewFolder"]["fileArgu"]=$conf["fileArgu"];
6959
		#可省略參數:
6960
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
6961
		#$conf["dirPermission"]="";
6962
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,預設為"false"不取消,若要取消該功能請設為"true".
6963
		#$conf["disableWebSearch"]="false";
6964
		#備註:
6965
		#同 function createFolderAfterCheck.
6966
		$createNewFolder=fileAccess::createNewFolder($conf["fileAccess::createNewFolder"]);
6967
		unset($conf["fileAccess::createNewFolder"]);
6968
 
6969
		#如果建立暫存資料夾失敗
6970
		if($createNewFolder["status"]==="false"){
6971
 
6972
			#設置執行不正常
6973
			$result["status"]="false";
6974
 
6975
			#設置執行錯誤
6976
			$result["error"]=$createNewFolder;
6977
 
6978
			#回傳結果
6979
			return $result;
6980
 
6981
			}#if end
6982
 
6983
		#取得轉換好的暫存目錄
6984
		$conf["tempDir"]=$createNewFolder["content"];
6985
 
6986
		#建立暫存檔案的名稱
6987
		#函式說明:
6988
		#建立以圖片(PNG格式)呈現的驗證碼.
6989
		#回傳的解果:
6990
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
6991
		#$result["error"],錯誤訊息.
6992
		#$result["function"],檔前執行的函式名稱.
6993
		#$result["randNumberWord"],傳驗證碼的內容.
6994
		#$result["imgAddress"],圖片的位置與名稱.
6995
		#必填參數:
6996
		#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
6997
		$conf["authenticate::validationCode"]["imgAddressAndName"]="no used!";
6998
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6999
		$conf["authenticate::validationCode"]["fileArgu"]=$conf["fileArgu"];
7000
		#可省略參數:
7001
		#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
7002
		#$conf["num"]="8";
7003
		#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
7004
		$conf["authenticate::validationCode"]["disableImg"]="true";
7005
		#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
7006
		#$conf["imgToData"]="true";
7007
		$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
7008
		unset($conf["authenticate::validationCode"]);
7009
 
7010
		#如果產生亂數名稱失敗
7011
		if($validationCode["status"]==="false"){
7012
 
7013
			#設置執行不正常
7014
			$result["status"]="false";
7015
 
7016
			#設置執行錯誤
7017
			$result["error"]=$validationCode;
7018
 
7019
			#回傳結果
7020
			return $result;
7021
 
7022
			}#if end
7023
 
7024
		#取得暫存檔案名稱
7025
		$tempFname=$validationCode["randNumberWord"];
7026
 
7027
		#取得暫存檔案的路徑於名稱
7028
		$tempFileFullPath=$conf["tempDir"]."/".$tempFname;
7029
 
7030
		#複製檔案到暫存區塊,並設定權限為當前使用者可以讀取.
7031
		#函式說明:
7032
		#呼叫shell執行系統命令,並取得回傳的內容.
7033
		#回傳的結果:
7034
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7035
		#$result["error"],錯誤訊息陣列.
7036
		#$result["function"],當前執行的函式名稱.
7037
		#$result["cmd"],執行的指令內容.
7038
		#$result["output"],爲執行完二元碼後的輸出陣列.
7039
		#必填參數
7040
		#$conf["command"],字串,要執行的指令與.
7041
		$conf["external::callShell"]["command"]="cp";
7042
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7043
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
7044
		#可省略參數:
7045
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7046
		$conf["external::callShell"]["argu"]=array($conf["file"],$tempFileFullPath,";","chown",$conf["username"].":".$conf["username"],";","chmod","777",$tempFileFullPath);
7047
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7048
		#$conf["enablePrintDescription"]="true";
7049
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7050
		#$conf["printDescription"]="";
7051
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
7052
		$conf["external::callShell"]["escapeshellarg"]="true";
7053
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
7054
		#$conf["username"]="";
7055
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
7056
		#$conf["password"]="";
7057
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
7058
		#$conf["useScript"]="";
7059
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
7060
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
7061
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
7062
		#$conf["inBackGround"]="";
7063
		#備註:
7064
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
7065
		#參考資料:
7066
		#exec=>http://php.net/manual/en/function.exec.php
7067
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7068
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7069
		$callShell=external::callShell($conf["external::callShell"]);
7070
		unset($conf["external::callShell"]);
7071
 
7072
		#如果複製httpd設定檔失敗
7073
		if($callShell["status"]==="false"){
7074
 
7075
			#設置執行不正常
7076
			$result["status"]="false";
7077
 
7078
			#設置執行錯誤
7079
			$result["error"]=$callShell;
7080
 
7081
			#回傳結果
7082
			return $result;
7083
 
7084
			}#if end
7085
 
7086
		#讀取httpd設定檔內容
7087
		#函式說明:
7088
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
7089
		#回傳的變數說明:
7090
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
7091
		#$result["error"],錯誤訊息提示.
7092
		#$result["warning"],警告訊息.
7093
		#$result["function"],當前執行的函式名稱.
7094
		#$result["fileContent"],爲檔案的內容陣列.
7095
		#$result["lineCount"],爲檔案內容總共的行數.
7096
		#$result["fullContent"],為檔案的完整內容.
7097
		#必填參數:
7098
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
7099
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$tempFileFullPath;
7100
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7101
		$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
7102
		#參考資料:
7103
		#file(),取得檔案內容的行數.
7104
		#file=>http:#php.net/manual/en/function.file.php
7105
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
7106
		#filesize=>http://php.net/manual/en/function.filesize.php
7107
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
7108
		unset($conf["fileAccess::getFileContent"]);
7109
 
7110
		#如果取得檔案內容失敗
7111
		if($getFileContent["status"]==="false"){
7112
 
7113
			#設置執行不正常
7114
			$result["status"]="false";
7115
 
7116
			#設置執行錯誤
7117
			$result["error"]=$getFileContent;
7118
 
7119
			#回傳結果
7120
			return $result;
7121
 
7122
			}#if end
7123
 
7124
		#移除暫存檔案
7125
		#函式說明:
7126
		#移除檔案
7127
		#回傳的結果:
7128
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7129
		#$result["error"],錯誤訊息陣列
7130
		#$result["warning"],警告訊息陣列
7131
		#$result["function"],當前執行的函式名稱
7132
		#必填參數:
7133
		#$conf["fileAddress"],字串,要移除檔案的位置.
7134
		$conf["fileAccess::delFile"]["fileAddress"]=$tempFileFullPath;
7135
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7136
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
7137
		#可省略參數:
7138
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7139
		#$conf["commentsArray"]=array("");
7140
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
7141
		unset($conf["fileAccess::delFile"]);
7142
 
7143
		#如果移除暫存檔案失敗
7144
		if($delFile["status"]==="false"){
7145
 
7146
			#設置執行不正常
7147
			$result["status"]="false";
7148
 
7149
			#設置執行錯誤
7150
			$result["error"]=$delFile;
7151
 
7152
			#回傳結果
7153
			return $result;
7154
 
7155
			}#if end
7156
 
7157
		#有幾個關鍵字串列就執行幾次
7158
		foreach($conf["keyStr"] as $index => $keyWordStr){
7159
 
7160
			#判斷有無關鍵字存在
7161
			#函式說明:
7162
			#檢查多個字串中的每個字串是否有多個關鍵字
7163
			#回傳的結果:
7164
			#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
7165
			#$result["function"],當前執行的函式名稱.
7166
			#$result["error"],錯誤訊息.
7167
			#$result["foundedTrueKey"],結果為"true"的元素key陣列。
7168
			#$result["foundedFalseKey"],結果為"false"的元素key陣列。
7169
			#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
7170
			#必填參數:
7171
			$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array($keyWordStr);#想要搜尋的關鍵字
7172
			$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$getFileContent["fileContent"];#要被搜尋的字串內容陣列
7173
			#可省略參數:
7174
			$conf["search::findManyKeyWordsFromManyString"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
7175
			$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
7176
			unset($conf["search::findManyKeyWordsFromManyString"]);
7177
 
7178
			#如果尋找關鍵字失敗
7179
			if($findManyKeyWordsFromManyString["status"]==="false"){
7180
 
7181
				#設置執行不正常
7182
				$result["status"]="false";
7183
 
7184
				#設置執行錯誤
7185
				$result["error"]=$findManyKeyWordsFromManyString;
7186
 
7187
				#回傳結果
7188
				return $result;
7189
 
7190
				}#if end
7191
 
7192
			#如果尋找到關鍵字串
7193
			if(isset($findManyKeyWordsFromManyString["foundedTrueKey"])){
7194
 
7195
				#設置有找到關鍵字串
7196
				$result["founded"][$index]="true";
7197
 
7198
				#用 foreach 取得無法得知的 key
7199
				foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $foundedLine=>$value){
7200
 
7201
					#設置找到的關鍵字串所在列數
7202
					$result["foundedLine"][$index]=$foundedLine;
7203
 
7204
					}#foreach end
7205
 
7206
				}#if end
7207
 
7208
			#反之沒有找到關鍵字串
7209
			else{
7210
 
7211
				#設置有找到關鍵字串
7212
				$result["founded"][$index]="false";
7213
 
7214
				#設置沒有找到每各關鍵字串
7215
				$result["foundedAll"]="false";
7216
 
7217
				}#else end
7218
 
7219
			}#foreach end
7220
 
7221
		#如果不存在 $result["foundedAll"]
7222
		if(!isset($result["foundedAll"])){
7223
 
7224
			#代表所有關鍵字串都有找到
7225
			$result["foundedAll"]="true";
7226
 
7227
			}#if end
7228
 
7229
		#取得讀取到的檔案內容
7230
		$result["content"]=$getFileContent["fileContent"];
7231
 
7232
		#設置執行正常
7233
		$result["status"]="true";
7234
 
7235
		#回傳結果
7236
		return $result;
7237
 
7238
		}#function checkFileKeyStrLBL end
7239
 
7240
	/*
7241
	#函式說明:
7242
	#複製檔案、資料夾.
7243
	#回傳結果:
7244
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7245
	#$result["error"],錯誤訊息.
7246
	#$result["function"],當前執行的函式名稱.
7247
	#$result["content"],複製好的檔案路徑與名稱.
7248
	#必填參數:
7249
	#$conf["file"],字串,檔案的位置與名稱.
7250
	$conf["file"]="";
7251
	#$conf["to"],字串,檔案要複製到哪裡.
7252
	$conf["to"]="";
7253
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
7254
	$conf["fileArgu"]=__FILE__;
7255
	#可省略參數:
7256
	#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
7257
	#$conf["username"]="";
7258
	#$conf["password"],字串,使用者對應的密碼,預設不使用.
7259
	#$conf["password"]="";
7260
	#參考資料:
7261
	#無.
7262
	#備註:
7263
	#僅能在命令列環境下運行
7264
	*/
7265
	public static function cp(&$conf){
7266
 
7267
		#初始化要回傳的結果
7268
		$result=array();
7269
 
7270
		#取得當前執行的函式名稱
7271
		$result["function"]=__FUNCTION__;
7272
 
7273
		#如果沒有參數
7274
		if(func_num_args()==0){
7275
 
7276
			#設置執行失敗
7277
			$result["status"]="false";
7278
 
7279
			#設置執行錯誤訊息
7280
			$result["error"]="函式".$result["function"]."需要參數";
7281
 
7282
			#回傳結果
7283
			return $result;
7284
 
7285
			}#if end
7286
 
7287
		#函式說明:
7288
		#判斷當前環境為web還是cmd
7289
		#回傳結果:
7290
		#$result,"web"或"cmd"
7291
		if(csInformation::getEnv()==="web"){
7292
 
7293
			#設置執行失敗
7294
			$result["status"]="false";
7295
 
7296
			#設置執行錯誤訊息
7297
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
7298
 
7299
			#回傳結果
7300
			return $result;
7301
 
7302
			}#if end
7303
 
7304
		#取得參數
7305
		$result["argu"]=$conf;
7306
 
7307
		#如果 $conf 不為陣列
7308
		if(gettype($conf)!=="array"){
7309
 
7310
			#設置執行失敗
7311
			$result["status"]="false";
7312
 
7313
			#設置執行錯誤訊息
7314
			$result["error"][]="\$conf變數須為陣列形態";
7315
 
7316
			#如果傳入的參數為 null
7317
			if($conf===null){
7318
 
7319
				#設置執行錯誤訊息
7320
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
7321
 
7322
				}#if end
7323
 
7324
			#回傳結果
7325
			return $result;
7326
 
7327
			}#if end
7328
 
7329
		#檢查參數
7330
		#函式說明:
7331
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
7332
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7333
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7334
		#$result["function"],當前執行的函式名稱.
7335
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7336
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7337
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7338
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7339
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7340
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7341
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7342
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7343
		#必填寫的參數:
7344
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7345
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7346
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7347
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","to","fileArgu");
7348
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
7349
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
7350
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7351
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7352
		#可以省略的參數:
7353
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7354
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7355
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
7356
		#$conf["canNotBeEmpty"]=array();
7357
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
7358
		#$conf["canBeEmpty"]=array();
7359
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
7360
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7361
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7362
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password");
7363
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7364
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
7365
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7366
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null);
7367
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7368
		#$conf["arrayCountEqualCheck"][]=array();
7369
		#參考資料來源:
7370
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7371
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7372
		unset($conf["variableCheck::checkArguments"]);
7373
 
7374
		#如果參數檢查失敗
7375
		if($checkArguments["status"]==="false"){
7376
 
7377
			#設置執行不正常
7378
			$result["status"]="false";
7379
 
7380
			#設置執行錯誤
7381
			$result["error"]=$checkArguments;
7382
 
7383
			#回傳結果
7384
			return $result;
7385
 
7386
			}#if end
7387
 
7388
		#如果參數檢查不通過
7389
		if($checkArguments["passed"]==="false"){
7390
 
7391
			#設置執行不正常
7392
			$result["status"]="false";
7393
 
7394
			#設置執行錯誤
7395
			$result["error"]=$checkArguments;
7396
 
7397
			#回傳結果
7398
			return $result;
7399
 
7400
			}#if end
7401
 
7402
		#初始化驗證過的使用者密碼
7403
		$validPasswd="";
7404
 
7405
		#如果不是以運行php的使用者角色來複製檔案
7406
		if($conf["username"]!==$_SERVER["LOGNAME"]){
7407
 
7408
			#驗證帳戶與密碼是否正確
7409
			#函式說明:
7410
			#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確
7411
			#回傳結果:
7412
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7413
			#$result["function"],當前執行的函式名稱.
7414
			#$result["error"],錯誤訊息陣列.
7415
			#$result["content"],帳戶密碼.
7416
			#必填參數:
7417
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7418
			$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];
7419
			#可省略參數:
7420
 
7421
			#如果有設置密碼
7422
			if(isset($conf["password"])){
7423
 
7424
				#設定驗證用的密碼
7425
				#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".
7426
				$conf["cmd::validRootPasswd"]["password"]=$conf["password"];
7427
 
7428
				}#if end
7429
 
7430
			#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.
7431
			$conf["cmd::validRootPasswd"]["username"]=$conf["username"];
7432
 
7433
			$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);
7434
			unset($conf["cmd::validRootPasswd"]);
7435
 
7436
			#如果驗證帳號密碼失敗
7437
			if($validRootPasswd["status"]==="false"){
7438
 
7439
				#設置執行不正常
7440
				$result["status"]="false";
7441
 
7442
				#設置執行錯誤
7443
				$result["error"]=$validRootPasswd;
7444
 
7445
				#回傳結果
7446
				return $result;
7447
 
7448
				}#if end
7449
 
7450
			#取得驗證過的使用者密碼
7451
			$validPasswd=$validRootPasswd["content"];
7452
 
7453
			}#if end
7454
 
7455
		#檢查要複製的檔案是否存在
7456
		#函式說明:
7457
		#用shell檢查檔案是否存在,可以指定查詢時用的身份.
7458
		#回傳的結果:
7459
		#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
7460
		#$result["function"],當前執行的函式名稱.
7461
		#$result["error"],錯誤訊息陣列.
7462
		#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案.
7463
		#必填參數:
7464
		#$conf["fileName"],字串,要檢查的檔案名稱.
7465
		$conf["cmd::checkFileExist"]["fileName"]=$conf["file"];
7466
		#可省略參數:
7467
		#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.
7468
		$conf["cmd::checkFileExist"]["username"]=$conf["username"];
7469
		#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.
7470
		$conf["cmd::checkFileExist"]["password"]=$validPasswd;
7471
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
7472
		$conf["cmd::checkFileExist"]["fileArgu"]=$conf["fileArgu"];
7473
		#備註:
7474
		#該函式若使用可省略參數,則無法在web環境下運行
7475
		$checkFileExist=cmd::checkFileExist($conf["cmd::checkFileExist"]);
7476
		unset($conf["cmd::checkFileExist"]);
7477
 
7478
		#如果檢查檔案是否存在失敗
7479
		if($checkFileExist["status"]==="false"){
7480
 
7481
			#設置執行不正常
7482
			$result["status"]="false";
7483
 
7484
			#設置執行錯誤
7485
			$result["error"]=$checkFileExist;
7486
 
7487
			#回傳結果
7488
			return $result;
7489
 
7490
			}#if end
7491
 
7492
		#如果要複製的檔案不存在
7493
		if($checkFileExist["founded"]==="false"){
7494
 
7495
			#設置執行不正常
7496
			$result["status"]="false";
7497
 
7498
			#設置執行錯誤
7499
			$result["error"]=$checkFileExist;
7500
 
7501
			#設置要複製的檔案不存在
7502
			$result["error"][]="檔案「".$conf["file"]."」不存在,或沒有權限接觸.";
7503
 
7504
			#回傳結果
7505
			return $result;
7506
 
7507
			}#if end
7508
 
7509
		#函式說明:
7510
		#呼叫shell依序執行系統命令,並取得回傳的內容.
7511
		#回傳結果:
7512
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7513
		#$result["error"],錯誤訊息陣列.
7514
		#$result["function"],當前執行的函數名稱.	
7515
		#$result["content"],爲執行完每個指令後的回傳結果.
7516
		#$result["cmd"],執行的指令內容,若"sameShell"參數為"true",則會有該數值.
7517
		#$result["output"],執行後得到的輸出,若"sameShell"參數為"true",則會有該數值.
7518
		#必填參數:
7519
		#$conf["command"],字串陣列,要執行的指令.
7520
		$conf["external::callShellMulti"]["command"]=array("/bin/cp","chown","chmod");
7521
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
7522
		$conf["external::callShellMulti"]["fileArgu"]=$conf["fileArgu"];
7523
		#可省略參數:
7524
		#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
7525
		$conf["external::callShellMulti"]["argu"]=array(array("-rvf",$conf["file"],$conf["to"]),array($conf["username"].":".$conf["username"],$conf["to"]),array("770",$conf["to"]));
7526
		#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
7527
		#$conf["enablePrintDescription"]=array("false");
7528
		#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
7529
		#$conf["printDescription"]=array("");
7530
		#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
7531
		$conf["external::callShell"]["escapeshellarg"]=array("true");
7532
		#$conf["username"],陣列字串,每個指令要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
7533
		$conf["external::callShell"]["username"]=$conf["username"];
7534
		#$conf["password"],陣列字串,每個指令與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
7535
		$conf["external::callShell"]["password"]=$validPasswd;
7536
		#$conf["useScript"],字串,每個指令的執行是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
7537
		#$conf["useScript"]="";
7538
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
7539
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
7540
		#$conf["inBackGround"],字串,每個指令的執行是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用";"區隔的多個指令將會出錯.
7541
		#$conf["inBackGround"]="";
7542
		#$conf["sameShell"],字串,"true"代表每個指令都在同空shell環境下執行,亦即會繼承變數、位置等資訊;預設為"false"代表要在個別獨立的shell環境下執行.
7543
		$conf["external::callShellMulti"]["sameShell"]="true";
7544
		#參考資料:
7545
		#exec=>http://php.net/manual/en/function.exec.php
7546
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7547
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7548
		#備註:
7549
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7550
		$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);
7551
		unset($conf["external::callShellMulti"]);
7552
 
7553
		#如果複製檔案失敗
7554
		if($callShellMulti["status"]==="false"){
7555
 
7556
			#設置執行不正常
7557
			$result["status"]="false";
7558
 
7559
			#設置執行錯誤
7560
			$result["error"]=$callShellMulti;
7561
 
7562
			#回傳結果
7563
			return $result;
7564
 
7565
			}#if end
7566
 
7567
		#設置複製好的檔案位置與名稱
7568
		$result["content"]=$conf["to"];
7569
 
7570
		#設置執行正常
7571
		$result["status"]="true";
7572
 
7573
		#回傳結果
7574
		return $result;
7575
 
7576
		}#function cp end
7577
 
7578
	/*
7579
	#函式說明:
7580
	#取得檔案內容
7581
	#回傳內容
7582
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7583
	#$result["error"],錯誤訊息.
7584
	#$result["function"],當前執行的函式名稱.
7585
	#$result["content"],檔案的內容.
7586
	#必填參數:
7587
	#$conf["file"],字串,想要取得內容的檔案位置.
7588
	$conf["file"]="";
7589
	#$conf["fileArgu"],字串,當前檔案的位置,亦即__FILE__.
7590
	$conf["fileArgu"]=__FILE__;
7591
	#可省略參數:
7592
	#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
7593
	#$conf["username"]="";
7594
	#$conf["password"],字串,使用者對應的密碼,預設不使用.
7595
	#$conf["password"]="";
7596
	#參考資料:
7597
	#無.
7598
	#備註:
7599
	#僅能在命令列環境下運行
7600
	*/
7601
	public static function getFileContent(&$conf){
7602
 
7603
		#初始化要回傳的結果
7604
		$result=array();
7605
 
7606
		#取得當前執行的函式名稱
7607
		$result["function"]=__FUNCTION__;
7608
 
7609
		#如果沒有參數
7610
		if(func_num_args()==0){
7611
 
7612
			#設置執行失敗
7613
			$result["status"]="false";
7614
 
7615
			#設置執行錯誤訊息
7616
			$result["error"]="函式".$result["function"]."需要參數";
7617
 
7618
			#回傳結果
7619
			return $result;
7620
 
7621
			}#if end
7622
 
7623
		#函式說明:
7624
		#判斷當前環境為web還是cmd
7625
		#回傳結果:
7626
		#$result,"web"或"cmd"
7627
		if(csInformation::getEnv()==="web"){
7628
 
7629
			#設置執行失敗
7630
			$result["status"]="false";
7631
 
7632
			#設置執行錯誤訊息
7633
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
7634
 
7635
			#回傳結果
7636
			return $result;
7637
 
7638
			}#if end
7639
 
7640
		#取得參數
7641
		$result["argu"]=$conf;
7642
 
7643
		#如果 $conf 不為陣列
7644
		if(gettype($conf)!=="array"){
7645
 
7646
			#設置執行失敗
7647
			$result["status"]="false";
7648
 
7649
			#設置執行錯誤訊息
7650
			$result["error"][]="\$conf變數須為陣列形態";
7651
 
7652
			#如果傳入的參數為 null
7653
			if($conf===null){
7654
 
7655
				#設置執行錯誤訊息
7656
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
7657
 
7658
				}#if end
7659
 
7660
			#回傳結果
7661
			return $result;
7662
 
7663
			}#if end
7664
 
7665
		#檢查參數
7666
		#函式說明:
7667
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
7668
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7669
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7670
		#$result["function"],當前執行的函式名稱.
7671
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7672
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7673
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7674
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7675
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7676
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7677
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7678
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7679
		#必填寫的參數:
7680
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7681
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7682
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7683
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
7684
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
7685
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7686
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7687
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7688
		#可以省略的參數:
7689
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7690
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7691
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
7692
		#$conf["canNotBeEmpty"]=array();
7693
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
7694
		#$conf["canBeEmpty"]=array();
7695
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
7696
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("username","password");
7697
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7698
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password");
7699
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7700
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
7701
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7702
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null);
7703
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7704
		#$conf["arrayCountEqualCheck"][]=array();
7705
		#參考資料來源:
7706
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7707
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7708
		unset($conf["variableCheck::checkArguments"]);
7709
 
7710
		#如果檢查參數失敗
7711
		if($checkArguments["status"]==="false"){
7712
 
7713
			#設置執行不正常
7714
			$result["status"]="false";
7715
 
7716
			#設置執行錯誤
7717
			$result["error"]=$checkArguments;
7718
 
7719
			#回傳結果
7720
			return $result;
7721
 
7722
			}#if end
7723
 
7724
		#如果參數檢查不通過
7725
		if($checkArguments["passed"]==="false"){
7726
 
7727
			#設置執行不正常
7728
			$result["status"]="false";
7729
 
7730
			#設置執行錯誤
7731
			$result["error"]=$checkArguments;
7732
 
7733
			#回傳結果
7734
			return $result;
7735
 
7736
			}#if end
7737
 
7738
		#初始化認證後的密碼
7739
		$password="";
7740
 
7741
		#如果不是用執行php的使用者來執行
7742
		if($conf["username"]!==$_SERVER["LOGNAME"]){
7743
 
7744
			#驗證帳號密碼
7745
			#函式說明:
7746
			#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確
7747
			#回傳結果:
7748
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7749
			#$result["function"],當前執行的函式名稱.
7750
			#$result["error"],錯誤訊息陣列.
7751
			#$result["content"],帳戶密碼.
7752
			#必填參數:
7753
			$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];
7754
			#可省略參數:
7755
 
7756
			#如果有設定 $conf["password"]
7757
			if(isset($conf["password"])){
7758
 
7759
				#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".
7760
				$conf["cmd::validRootPasswd"]["password"]=$conf["password"];
7761
 
7762
				}#if end
7763
 
7764
			#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.
7765
			$conf["cmd::validRootPasswd"]["username"]=$conf["username"];
7766
			$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);
7767
			unset($conf["cmd::validRootPasswd"]);
7768
 
7769
			#如果檢查帳戶失敗
7770
			if($validRootPasswd["status"]==="false"){
7771
 
7772
				#設置執行不正常
7773
				$result["status"]="false";
7774
 
7775
				#設置執行錯誤
7776
				$result["error"]=$validRootPasswd;
7777
 
7778
				#回傳結果
7779
				return $result;
7780
 
7781
				}#if end
7782
 
7783
			#取得認證使用者後的密碼
7784
			$password=$validRootPasswd["content"];
7785
 
7786
			}#if end
7787
 
7788
		#反之
7789
		else{
7790
 
7791
			#密碼設為空字串
7792
			$password="";
7793
 
7794
			}#else end
7795
 
7796
		#建立暫存的目錄與命名暫存檔案名稱
7797
		#函式說明:
7798
		#建立暫存目錄與回傳暫存檔案名稱路徑
7799
		#回傳結果:
7800
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7801
		#$result["error"],錯誤訊息.
7802
		#$result["function"],當前執行的函式名稱.
7803
		#$result["content"],暫存檔案的路徑與名稱.
7804
		#必填參數:
7805
		#無
7806
		#可省略參數:
7807
		#$conf["tempDir"],字串,暫存目錄的名稱,預設為.fileAccess/createTempFile
7808
		#$conf["tempDIr"]="";
7809
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
7810
		$conf["fileAccess::createTempFile"]["fileArgu"]=$conf["fileArgu"];
7811
		#$conf["createPath"],字串,是否僅要建立目錄,"true"代表要,"false"代表不要,預設為"true".
7812
		#$conf["createPath"]="";
7813
		#$conf["createFile"],字串,是否要在暫存路徑建立好後建立暫存檔案,"true"代表要,"false"代表不用,預設為"true".
7814
		$conf["fileAccess::createTempFile"]["createFile"]="false";
7815
		$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
7816
		unset($conf["fileAccess::createTempFile"]);
7817
 
7818
		#若建立暫存目錄取得暫存檔案名稱失敗
7819
		if($createTempFile["status"]==="false"){
7820
 
7821
			#設置執行不正常
7822
			$result["status"]="false";
7823
 
7824
			#設置執行錯誤
7825
			$result["error"]=$createTempFile;
7826
 
7827
			#回傳結果
7828
			return $result;
7829
 
7830
			}#if end
7831
 
7832
		#複製檔案到目的地
7833
		#函式說明:
7834
		#複製檔案
7835
		#回傳結果:
7836
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7837
		#$result["error"],錯誤訊息.
7838
		#$result["function"],當前執行的函式名稱.
7839
		#$result["content"],複製好的檔案路徑與名稱.
7840
		#必填參數:
7841
		#$conf["file"],字串,檔案的位置與名稱.
7842
		$conf["cmd::cp"]["file"]=$conf["file"];
7843
		#$conf["to"],字串,檔案要複製到哪裡.
7844
		$conf["cmd::cp"]["to"]=$createTempFile["content"];
7845
		#可省略參數:
7846
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
7847
		$conf["cmd::cp"]["username"]=$conf["username"];
7848
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
7849
		$conf["cmd::cp"]["password"]=$password;
7850
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
7851
		$conf["cmd::cp"]["fileArgu"]=$conf["fileArgu"];
7852
		$cp=cmd::cp($conf["cmd::cp"]);
7853
		unset($conf["cmd::cp"]);
7854
 
7855
		#如果複製檔案失敗
7856
		if($cp["status"]==="false"){
7857
 
7858
			#設置執行不正常
7859
			$result["status"]="false";
7860
 
7861
			#設置執行錯誤
7862
			$result["error"]=$createTempFile;
7863
 
7864
			#回傳結果
7865
			return $result;
7866
 
7867
			}#if end
7868
 
7869
		#讀取檔案的內容
7870
		#函式說明:
7871
		#呼叫shell執行系統命令,並取得回傳的內容.
7872
		#回傳的結果:
7873
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7874
		#$result["error"],錯誤訊息陣列.
7875
		#$result["function"],當前執行的函式名稱.
7876
		#$result["cmd"],執行的指令內容.
7877
		#$result["output"],爲執行完二元碼後的輸出陣列.
7878
		#必填參數
7879
		#$conf["command"],字串,要執行的指令與.
7880
		$conf["external::callShell"]["command"]="cat";
7881
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7882
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
7883
		#可省略參數:
7884
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7885
		$conf["external::callShell"]["argu"]=array($cp["content"]);
7886
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7887
		#$conf["enablePrintDescription"]="true";
7888
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7889
		#$conf["printDescription"]="";
7890
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
7891
		$conf["external::callShell"]["escapeshellarg"]="true";
7892
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
7893
		$conf["external::callShell"]["username"]=$conf["username"];
7894
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
7895
		$conf["external::callShell"]["password"]=$password;
7896
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
7897
		#$conf["useScript"]="";
7898
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
7899
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
7900
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
7901
		#$conf["inBackGround"]="";
7902
		#備註:
7903
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
7904
		#參考資料:
7905
		#exec=>http://php.net/manual/en/function.exec.php
7906
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7907
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7908
		$callShell=external::callShell($conf["external::callShell"]);
7909
		unset($conf["external::callShell"]);
7910
 
7911
		#如果取得檔案內容失敗
7912
		if($callShell["status"]==="false"){
7913
 
7914
			#設置執行不正常
7915
			$result["status"]="false";
7916
 
7917
			#設置執行錯誤
7918
			$result["error"]=$callShell;
7919
 
7920
			#回傳結果
7921
			return $result;
7922
 
7923
			}#if end
7924
 
7925
		#移除暫存檔案
7926
		#函式說明:
7927
		#移除檔案
7928
		#回傳的結果:
7929
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7930
		#$result["error"],錯誤訊息陣列
7931
		#$result["warning"],警告訊息陣列
7932
		#$result["function"],當前執行的函式名稱
7933
		#必填參數:
7934
		#$conf["fileAddress"],字串,要移除檔案的位置.
7935
		$conf["fileAccess::delFile"]["fileAddress"]=$cp["content"];
7936
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7937
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
7938
		#可省略參數:
7939
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7940
		#$conf["commentsArray"]=array("");
7941
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
7942
		unset($conf["fileAccess::delFile"]);
7943
 
7944
		#如果移除暫存檔案失敗
7945
		if($delFile["status"]==="false"){
7946
 
7947
			#設置執行不正常
7948
			$result["status"]="false";
7949
 
7950
			#設置執行錯誤
7951
			$result["error"]=$delFile;
7952
 
7953
			#回傳結果
7954
			return $result;
7955
 
7956
			}#if end
7957
 
7958
		#取得檔案內容
7959
		$result["content"]=$callShell["output"];
7960
 
7961
		#設置執行正常
7962
		$result["status"]="true";
7963
 
7964
		#回傳結果
7965
		return $result;
7966
 
7967
		}#function getFileContent end
7968
 
7969
	/*
7970
	#函式說明:
7971
	#新增文字內容到檔案裡面
7972
	#回傳結果:
7973
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7974
	#$result["error"],錯誤訊息.
7975
	#$result["function"],當前執行的函式名稱.
7976
	#$result["content"],新增好後的檔案內容.
7977
	#必填參數:
7978
	#$conf["file"],字串,檔案的位置與名稱.
7979
	$conf["file"]="";
7980
	#$conf["addStr"],陣列字串,要新增的字串內容.
7981
	$conf["addStr"]=array();
7982
	#可省略參數:
7983
	#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
7984
	#$conf["username"]="";
7985
	#$conf["password"],字串,使用者對應的密碼,預設為"password".
7986
	#$conf["password"]="";
7987
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
7988
	#$conf["fileArgu"]=__FILE__;
7989
	#參考資料:
7990
	#無.
7991
	#備註:
7992
	#無.
7993
	*/
7994
	public static function addTextToFile(&$conf){
7995
 
7996
		#初始化要回傳的結果
7997
		$result=array();
7998
 
7999
		#取得當前執行的函式名稱
8000
		$result["function"]=__FUNCTION__;
8001
 
8002
		#如果沒有參數
8003
		if(func_num_args()==0){
8004
 
8005
			#設置執行失敗
8006
			$result["status"]="false";
8007
 
8008
			#設置執行錯誤訊息
8009
			$result["error"]="函式".$result["function"]."需要參數";
8010
 
8011
			#回傳結果
8012
			return $result;
8013
 
8014
			}#if end
8015
 
8016
		#函式說明:
8017
		#判斷當前環境為web還是cmd
8018
		#回傳結果:
8019
		#$result,"web"或"cmd"
8020
		if(csInformation::getEnv()==="web"){
8021
 
8022
			#設置執行失敗
8023
			$result["status"]="false";
8024
 
8025
			#設置執行錯誤訊息
8026
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
8027
 
8028
			#回傳結果
8029
			return $result;
8030
 
8031
			}#if end
8032
 
8033
		#取得參數
8034
		$result["argu"]=$conf;
8035
 
8036
		#如果 $conf 不為陣列
8037
		if(gettype($conf)!=="array"){
8038
 
8039
			#設置執行失敗
8040
			$result["status"]="false";
8041
 
8042
			#設置執行錯誤訊息
8043
			$result["error"][]="\$conf變數須為陣列形態";
8044
 
8045
			#如果傳入的參數為 null
8046
			if($conf===null){
8047
 
8048
				#設置執行錯誤訊息
8049
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
8050
 
8051
				}#if end
8052
 
8053
			#回傳結果
8054
			return $result;
8055
 
8056
			}#if end
8057
 
8058
		#檢查參數
8059
		#函式說明:
8060
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
8061
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8062
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8063
		#$result["function"],當前執行的函式名稱.
8064
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8065
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8066
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8067
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8068
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8069
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8070
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8071
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8072
		#必填寫的參數:
8073
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8074
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8075
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8076
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","addStr");
8077
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8078
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
8079
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8080
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8081
		#可以省略的參數:
8082
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8083
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8084
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8085
		#$conf["canNotBeEmpty"]=array();
8086
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8087
		#$conf["canBeEmpty"]=array();
8088
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8089
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8090
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8091
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","fileArgu");
8092
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8093
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
8094
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8095
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],"password",__FILE__);
8096
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8097
		#$conf["arrayCountEqualCheck"][]=array();
8098
		#參考資料來源:
8099
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8100
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8101
		unset($conf["variableCheck::checkArguments"]);
8102
 
8103
		#如果參數檢查失敗
8104
		if($checkArguments["status"]==="false"){
8105
 
8106
			#設置執行不正常
8107
			$result["status"]="false";
8108
 
8109
			#設置執行錯誤
8110
			$result["error"]=$checkArguments;
8111
 
8112
			#回傳結果
8113
			return $result;
8114
 
8115
			}#if end
8116
 
8117
		#如果參數檢查不通過
8118
		if($checkArguments["passed"]==="false"){
8119
 
8120
			#設置執行不正常
8121
			$result["status"]="false";
8122
 
8123
			#設置執行錯誤
8124
			$result["error"]=$checkArguments;
8125
 
8126
			#回傳結果
8127
			return $result;
8128
 
8129
			}#if end
8130
 
8131
		#驗證使用者與密碼
8132
		#函式說明:
8133
		#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確
8134
		#回傳結果:
8135
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8136
		#$result["function"],當前執行的函式名稱.
8137
		#$result["error"],錯誤訊息陣列.
8138
		#$result["content"],帳戶密碼.
8139
		#必填參數:
8140
		$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];
8141
		#可省略參數:
8142
		#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".
8143
		$conf["cmd::validRootPasswd"]["password"]=$conf["password"];
8144
		#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.
8145
		$conf["cmd::validRootPasswd"]["username"]=$conf["username"];
8146
		$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);
8147
		unset($conf["cmd::validRootPasswd"]);
8148
 
8149
		#如果認證失敗
8150
		if($validRootPasswd["status"]==="false"){
8151
 
8152
			#設置執行不正常
8153
			$result["status"]="false";
8154
 
8155
			#設置執行錯誤
8156
			$result["error"]=$validRootPasswd;
8157
 
8158
			#回傳結果
8159
			return $result;
8160
 
8161
			}#if end
8162
 
8163
		#取得正確的密碼
8164
		$conf["password"]=$validRootPasswd["content"];
8165
 
8166
		#確認檔案是否存在
8167
		#函式說明:
8168
		#用shell檢查檔案是否存在,可以指定查詢時用的身份.
8169
		#回傳的結果:
8170
		#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
8171
		#$result["function"],當前執行的函式名稱.
8172
		#$result["error"],錯誤訊息陣列.
8173
		#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案.
8174
		#必填參數:
8175
		#$conf["fileName"],字串,要檢查的檔案名稱.
8176
		$conf["cmd::checkFileExist"]["fileName"]=$conf["file"];
8177
		#可省略參數:
8178
		#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.
8179
		$conf["cmd::checkFileExist"]["username"]=$conf["username"];
8180
		#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.
8181
		$conf["cmd::checkFileExist"]["password"]=$conf["password"];
8182
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
8183
		$conf["cmd::checkFileExist"]["fileArgu"]=$conf["fileArgu"];
8184
		#備註:
8185
		#該函式若使用可省略參數,則無法在web環境下運行
8186
		$checkFileExist=cmd::checkFileExist($conf["cmd::checkFileExist"]);
8187
		unset($conf["cmd::checkFileExist"]);
8188
 
8189
		#如果檢查檔案是否存在失敗
8190
		if($checkFileExist["status"]==="false"){
8191
 
8192
			#設置執行不正常
8193
			$result["status"]="false";
8194
 
8195
			#設置執行錯誤
8196
			$result["error"]=$checkFileExist;
8197
 
8198
			#回傳結果
8199
			return $result;
8200
 
8201
			}#if end
8202
 
8203
		#如果檔案不存在
8204
		if($checkFileExist["founded"]==="false"){
8205
 
8206
			#設置執行不正常
8207
			$result["status"]="false";
8208
 
8209
			#設置執行錯誤
8210
			$result["error"]=$checkFileExist;
8211
 
8212
			#回傳結果
8213
			return $result;
8214
 
8215
			}#if end
8216
 
8217
		#有幾列內容就執行幾次
8218
		foreach($conf["addStr"] as $inputText){
8219
 
8220
			#組合增加檔案內容的語法
8221
			#複製檔案到暫存區塊,並設定權限為當前使用者可以讀取.
8222
			#函式說明:
8223
			#呼叫shell執行系統命令,並取得回傳的內容.
8224
			#回傳的結果:
8225
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8226
			#$result["error"],錯誤訊息陣列.
8227
			#$result["function"],當前執行的函式名稱.
8228
			#$result["cmd"],執行的指令內容.
8229
			#$result["output"],爲執行完二元碼後的輸出陣列.
8230
			#必填參數
8231
			#$conf["command"],字串,要執行的指令與.
8232
			$conf["external::callShell"]["command"]="echo";
8233
			#$conf["fileArgu"],字串,變數__FILE__的內容.
8234
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
8235
			#可省略參數:
8236
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8237
			$conf["external::callShell"]["argu"]=array($inputText,">>",$conf["file"]);
8238
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8239
			#$conf["enablePrintDescription"]="true";
8240
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
8241
			#$conf["printDescription"]="";
8242
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
8243
			$conf["external::callShell"]["escapeshellarg"]="true";
8244
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8245
			$conf["external::callShell"]["username"]=$conf["username"];
8246
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8247
			$conf["external::callShell"]["password"]=$conf["password"];
8248
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
8249
			#$conf["useScript"]="";
8250
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
8251
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8252
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8253
			#$conf["inBackGround"]="";
8254
			#備註:
8255
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8256
			#參考資料:
8257
			#exec=>http://php.net/manual/en/function.exec.php
8258
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8259
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8260
			$callShell=external::callShell($conf["external::callShell"]);
8261
			unset($conf["external::callShell"]);
8262
 
8263
			#如果執行增加檔案內容的語法失敗
8264
			if($callShell["status"]==="false"){
8265
 
8266
				#設置執行不正常
8267
				$result["status"]="false";
8268
 
8269
				#設置執行錯誤
8270
				$result["error"]=$callShell;
8271
 
8272
				#回傳結果
8273
				return $result;
8274
 
8275
				}#if end
8276
 
8277
			}#foreach end
8278
 
8279
		#取得新增內容後的檔案內容
8280
		#函式說明:
8281
		#取得檔案內容
8282
		#回傳內容
8283
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8284
		#$result["error"],錯誤訊息.
8285
		#$result["function"],當前執行的函式名稱.
8286
		#$result["content"],檔案的內容.
8287
		#必填參數:
8288
		#$conf["file"],字串,想要取得內容的檔案位置.
8289
		$conf["cmd::getFileContent"]["file"]=$conf["file"];
8290
		#$conf["fileArgu"],字串,當前檔案的位置,亦即__FILE__.
8291
		$conf["cmd::getFileContent"]["fileArgu"]=$conf["fileArgu"];
8292
		#可省略參數:
8293
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
8294
		$conf["cmd::getFileContent"]["username"]=$conf["username"];
8295
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
8296
		$conf["cmd::getFileContent"]["password"]=$conf["password"];
8297
		$getFileContent=cmd::getFileContent($conf["cmd::getFileContent"]);
8298
		unset($conf["cmd::getFileContent"]);
8299
 
8300
		#如果取得設定檔內容失敗
8301
		if($getFileContent["status"]==="false"){
8302
 
8303
			#設置執行不正常
8304
			$result["status"]="false";
8305
 
8306
			#設置執行錯誤
8307
			$result["error"]=$getFileContent;
8308
 
8309
			#回傳結果
8310
			return $result;
8311
 
8312
			}#if end
8313
 
8314
		#新增完資料後的檔案內容
8315
		$result["content"]=$getFileContent["content"];
8316
 
8317
		#設置執行正常
8318
		$result["status"]="true";
8319
 
8320
		#回傳內容
8321
		return $result;
8322
 
8323
		}#function addContentToFile
8324
 
8325
	/*
8326
	#函式說明:
8327
	#檢查指令的輸出是否含有關鍵字
8328
	#回傳結果:
8329
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8330
	#$result["error"],錯誤訊息.
8331
	#$result["function"],當前執行的函式名稱.
8332
	#$result["argu"],使用的參數.
8333
	#$result["grepCmd"],截取關鍵字的指令.
8334
	#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
8335
	#$result["content"],關鍵字所在列的輸出.
8336
	#$result["count"],輸出的列數.
8337
	#必填參數:
8338
	#$conf["cmd"],字串,要執行的指令.
8339
	$conf["cmd"]="";
8340
	#$conf["keyWord"],字串,要檢查是否有關鍵字.
8341
	$conf["keyWord"]="";
8342
	#$conf["fileArgu"],字串,變數__FILE__的內容.
8343
	$conf["fileArgu"]=__FILE__;
8344
	#可省略參數:
8345
	#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
8346
	#$conf["binPath"]="";
8347
	#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
8348
	#$conf["argu"]=array("");
8349
	#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
8350
	#$conf["excludeGrep"]="false";
8351
	#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8352
	#$conf["username"]="";
8353
	#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8354
	#$conf["password"]="";
8355
	#參考資料:
8356
	#無.
8357
	#備註:
8358
	#無.
8359
	*/
8360
	public static function searchOutPut(&$conf){
8361
 
8362
		#初始化要回傳的結果
8363
		$result=array();
8364
 
8365
		#取得當前執行的函式名稱
8366
		$result["function"]=__FUNCTION__;
8367
 
8368
		#如果沒有參數
8369
		if(func_num_args()==0){
8370
 
8371
			#設置執行失敗
8372
			$result["status"]="false";
8373
 
8374
			#設置執行錯誤訊息
8375
			$result["error"]="函式".$result["function"]."需要參數";
8376
 
8377
			#回傳結果
8378
			return $result;
8379
 
8380
			}#if end
8381
 
8382
		#函式說明:
8383
		#判斷當前環境為web還是cmd
8384
		#回傳結果:
8385
		#$result,"web"或"cmd"
8386
		if(csInformation::getEnv()==="web"){
8387
 
8388
			#設置執行失敗
8389
			$result["status"]="false";
8390
 
8391
			#設置執行錯誤訊息
8392
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
8393
 
8394
			#回傳結果
8395
			return $result;
8396
 
8397
			}#if end
8398
 
8399
		#取得參數
8400
		$result["argu"]=$conf;
8401
 
8402
		#如果 $conf 不為陣列
8403
		if(gettype($conf)!=="array"){
8404
 
8405
			#設置執行失敗
8406
			$result["status"]="false";
8407
 
8408
			#設置執行錯誤訊息
8409
			$result["error"][]="\$conf變數須為陣列形態";
8410
 
8411
			#如果傳入的參數為 null
8412
			if($conf===null){
8413
 
8414
				#設置執行錯誤訊息
8415
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
8416
 
8417
				}#if end
8418
 
8419
			#回傳結果
8420
			return $result;
8421
 
8422
			}#if end
8423
 
8424
		#檢查參數
8425
		#函式說明:
8426
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
8427
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8428
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8429
		#$result["function"],當前執行的函式名稱.
8430
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8431
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8432
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8433
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8434
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8435
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8436
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8437
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8438
		#必填寫的參數:
8439
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8440
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8441
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8442
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmd","keyWord","fileArgu");
8443
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8444
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
8445
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8446
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8447
		#可以省略的參數:
8448
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8449
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8450
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8451
		#$conf["canNotBeEmpty"]=array();
8452
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8453
		#$conf["canBeEmpty"]=array();
8454
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8455
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8456
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8457
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("binPath","argu","excludeGrep","username","password");
8458
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8459
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string","string","string");
8460
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8461
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false","root",null);
8462
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8463
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("netType","netCard");
8464
		#參考資料來源:
8465
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8466
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8467
		unset($conf["variableCheck::checkArguments"]);
8468
 
8469
		#如果參數檢查失敗
8470
		if($checkArguments["status"]==="false"){
8471
 
8472
			#設置執行不正常
8473
			$result["status"]="false";
8474
 
8475
			#設置執行錯誤
8476
			$result["error"]=$checkArguments;
8477
 
8478
			#回傳結果
8479
			return $result;
8480
 
8481
			}#if end
8482
 
8483
		#如果參數檢查不通過
8484
		if($checkArguments["passed"]==="false"){
8485
 
8486
			#設置執行不正常
8487
			$result["status"]="false";
8488
 
8489
			#設置執行錯誤
8490
			$result["error"]=$checkArguments;
8491
 
8492
			#回傳結果
8493
			return $result;
8494
 
8495
			}#if end
8496
 
8497
		#檢查指令 $conf["cmd"] 是否存在
8498
		#函式說明:
8499
		#檢查指令是否存在
8500
		#回傳結果:
8501
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8502
		#$result["error"],錯誤訊息.
8503
		#$result["function"],當前執行的函式名稱.
8504
		#$result["argu"],使用的參數.
8505
		#$result["content"],新增好後的檔案內容.
8506
		#必填參數:
8507
		#$conf["cmd"],"字串",要查詢的指令.
8508
		$conf["self::checkCmdExist"]["cmd"]=$conf["cmd"];
8509
		#可省略參數:
8510
 
8511
		#如果有設置 $conf["binPath"]
8512
		if(isset($conf["binPath"])){
8513
 
8514
			#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
8515
			$conf["self::checkCmdExist"]["binPath"]=$conf["binPath"];
8516
 
8517
			}#if end
8518
 
8519
		$checkCmdExist=self::checkCmdExist($conf["self::checkCmdExist"]);
8520
		unset($conf["self::checkCmdExist"]);
8521
 
8522
		#如果檢查指令是否存在失敗
8523
		if($checkCmdExist["status"]==="false"){
8524
 
8525
			#設置執行不正常
8526
			$result["status"]="false";
8527
 
8528
			#設置執行錯誤
8529
			$result["error"]=$checkCmdExist;
8530
 
8531
			#回傳結果
8532
			return $result;
8533
 
8534
			}#if end
8535
 
8536
		#如果指令不存在
8537
		if($checkCmdExist["founded"]==="false"){
8538
 
8539
			#設置執行不正常
8540
			$result["status"]="false";
8541
 
8542
			#設置執行錯誤
8543
			$result["error"]=$checkCmdExist;
8544
 
8545
			#回傳結果
8546
			return $result;
8547
 
8548
			}#if end
8549
 
8550
		#執行指令並檢查輸出的內容是否有關鍵字
8551
		#函式說明:
8552
		#呼叫shell執行系統命令,並取得回傳的內容.
8553
		#回傳的結果:
8554
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8555
		#$result["error"],錯誤訊息陣列.
8556
		#$result["function"],當前執行的函式名稱.
8557
		#$result["cmd"],執行的指令內容.
8558
		#$result["output"],爲執行完二元碼後的輸出陣列.
8559
		#必填參數
8560
		#$conf["command"],字串,要執行的指令與.
8561
		$conf["checkCmdExist::callShell"]["command"]=$conf["cmd"];
8562
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8563
		$conf["checkCmdExist::callShell"]["fileArgu"]=$conf["fileArgu"];
8564
		#可省略參數:
8565
 
8566
		#如果有設置 $conf["argu"]
8567
		if(isset($conf["argu"])){
8568
 
8569
			#串接將結果導向給後面指令處理的符號
8570
			$conf["argu"][]="|";
8571
 
8572
			#串接截取關鍵字的參數
8573
			$conf["argu"][]="grep";
8574
 
8575
			#串接要截取的關鍵字
8576
			$conf["argu"][]=$conf["keyWord"];
8577
 
8578
			}#if end
8579
 
8580
		#反之
8581
		else{
8582
 
8583
			#設置截取關鍵字的參數
8584
			$conf["argu"]=array("|","grep",$conf["keyWord"]);
8585
 
8586
			}#else end
8587
 
8588
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8589
		$conf["checkCmdExist::callShell"]["argu"]=$conf["argu"];
8590
 
8591
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8592
		#$conf["enablePrintDescription"]="true";
8593
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
8594
		#$conf["printDescription"]="";
8595
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
8596
		$conf["checkCmdExist::callShell"]["escapeshellarg"]="true";
8597
 
8598
		#如果有設置 $conf["username"]
8599
		if(isset($conf["username"])){
8600
 
8601
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8602
			$conf["checkCmdExist::callShell"]["username"]=$conf["username"];
8603
 
8604
			}#if end
8605
 
8606
		#如果有設置 $conf["password"]
8607
		if(isset($conf["password"])){
8608
 
8609
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8610
			$conf["checkCmdExist::callShell"]["password"]=$conf["password"];				
8611
 
8612
			}#if end
8613
 
8614
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
8615
		#$conf["useScript"]="";
8616
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
8617
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8618
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8619
		#$conf["inBackGround"]="";
8620
		#備註:
8621
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8622
		#參考資料:
8623
		#exec=>http://php.net/manual/en/function.exec.php
8624
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8625
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8626
		$callShell=external::callShell($conf["checkCmdExist::callShell"]);
8627
		unset($conf["checkCmdExist::callShell"]);
8628
 
8629
		#取得截取關鍵字的指令
8630
		$result["grepCmd"]=$callShell["cmd"];
8631
 
8632
		#如果執行指令失敗
8633
		if($callShell["status"]==="false"){
8634
 
8635
			#如果有紀錄輸出
8636
			if(isset($callShell["output"])){
8637
 
8638
				#取得搜尋的輸出
8639
				$result["content"]=$callShell["output"];
8640
 
8641
				#如果等於空陣列
8642
				if($callShell["output"]===array()){
8643
 
8644
					#設置執行正常
8645
					$result["status"]="true";
8646
 
8647
					#設置找不到關鍵字
8648
					$result["founded"]="false";
8649
 
8650
					#回傳結果
8651
					return $result;
8652
 
8653
					}#if end
8654
 
8655
				}#if end
8656
 
8657
			#沒有輸出
8658
			else{
8659
 
8660
				#設置執行不正常
8661
				$result["status"]="false";
8662
 
8663
				#設置執行錯誤
8664
				$result["error"]=$callShell;
8665
 
8666
				#回傳結果
8667
				return $result;
8668
 
8669
				}#else end
8670
 
8671
			}#if end
8672
 
8673
		#如果有輸出
8674
		if(isset($callShell["output"])){
8675
 
8676
			#初始化新的輸出
8677
			$newOutput=array();
8678
 
8679
			#如果有設置要排除 "| grep ".$conf["keyWord"] 關鍵字
8680
			if($conf["excludeGrep"]==="true"){
8681
 
8682
				#設置不需要的關鍵字串A
8683
				$notNeedKeyWordA="grep ";
8684
 
8685
				#設置不需要的關鍵字串B
8686
				$notNeedKeyWordB=$conf["keyWord"];
8687
 
8688
				#針對每一列輸出
8689
				foreach($callShell["output"] as $line){
8690
 
8691
					#如果含有要排除的關鍵字
8692
					if(strpos($line,$notNeedKeyWordA)!==false && strpos($line,$notNeedKeyWordB)!==false){
8693
 
8694
						#繼續到下一個迴圈
8695
						continue;
8696
 
8697
						}#if end
8698
 
8699
					#記錄輸出
8700
					$newOutput[]=$line;
8701
 
8702
					}#foreach end
8703
 
8704
				#取得新的輸出
8705
				$callShell["output"]=$newOutput;
8706
 
8707
				}#if end
8708
 
8709
			#取得搜尋的輸出
8710
			$result["content"]=$callShell["output"];
8711
 
8712
			#取得搜尋結果的輸出行數
8713
			$result["count"]=count($result["content"]);
8714
 
8715
			#如果等於空陣列
8716
			if($callShell["output"]===array()){
8717
 
8718
				#設置執行正常
8719
				$result["status"]="true";
8720
 
8721
				#設置找不到關鍵字
8722
				$result["founded"]="false";
8723
 
8724
				#回傳結果
8725
				return $result;
8726
 
8727
				}#if end
8728
 
8729
			#如果有輸出內容
8730
			else if(count($callShell["output"])>0){
8731
 
8732
				#設置執行正常
8733
				$result["status"]="true";
8734
 
8735
				#設置有找到關鍵字
8736
				$result["founded"]="true";
8737
 
8738
				#回傳結果
8739
				return $result;
8740
 
8741
				}#if end
8742
 
8743
			}#if end
8744
 
8745
		#沒有輸出
8746
		else{
8747
 
8748
			#設置執行不正常
8749
			$result["status"]="false";
8750
 
8751
			#設置執行錯誤
8752
			$result["error"]=$callShell;
8753
 
8754
			#回傳結果
8755
			return $result;
8756
 
8757
			}#else end
8758
 
8759
		}#function searchOutPut end
8760
 
8761
	/*
8762
	#函式說明:
8763
	#檢查指令是否存在
8764
	#回傳結果:
8765
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8766
	#$result["error"],錯誤訊息.
8767
	#$result["function"],當前執行的函式名稱.
8768
	#$result["argu"],使用的參數.
8769
	#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
8770
	#$result["cmdFullPath"],指令的絕對路徑.
8771
	#必填參數:
8772
	#$conf["cmd"],"字串",要查詢的指令.
8773
	$conf["cmd"]="";
8774
	#可省略參數:
8775
	#無.
8776
	#參考資料:
8777
	#無.
8778
	#備註:
8779
	#無.
8780
	*/
8781
	public static function checkCmdExist(&$conf){
8782
 
8783
		#初始化要回傳的結果
8784
		$result=array();
8785
 
8786
		#取得當前執行的函式名稱
8787
		$result["function"]=__FUNCTION__;
8788
 
8789
		#如果沒有參數
8790
		if(func_num_args()==0){
8791
 
8792
			#設置執行失敗
8793
			$result["status"]="false";
8794
 
8795
			#設置執行錯誤訊息
8796
			$result["error"]="函式".$result["function"]."需要參數";
8797
 
8798
			#回傳結果
8799
			return $result;
8800
 
8801
			}#if end
8802
 
8803
		#取得參數
8804
		$result["argu"]=$conf;
8805
 
8806
		#如果 $conf 不為陣列
8807
		if(gettype($conf)!=="array"){
8808
 
8809
			#設置執行失敗
8810
			$result["status"]="false";
8811
 
8812
			#設置執行錯誤訊息
8813
			$result["error"][]="\$conf變數須為陣列形態";
8814
 
8815
			#如果傳入的參數為 null
8816
			if($conf===null){
8817
 
8818
				#設置執行錯誤訊息
8819
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
8820
 
8821
				}#if end
8822
 
8823
			#回傳結果
8824
			return $result;
8825
 
8826
			}#if end
8827
 
8828
		#檢查參數
8829
		#函式說明:
8830
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
8831
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8832
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8833
		#$result["function"],當前執行的函式名稱.
8834
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8835
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8836
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8837
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8838
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8839
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8840
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8841
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8842
		#必填寫的參數:
8843
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8844
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8845
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8846
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmd");
8847
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8848
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
8849
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8850
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8851
		#可以省略的參數:
8852
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8853
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8854
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8855
		#$conf["canNotBeEmpty"]=array();
8856
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8857
		#$conf["canBeEmpty"]=array();
8858
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8859
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8860
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8861
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("binPath");
8862
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8863
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
8864
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8865
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/bin");
8866
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8867
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("netType","netCard");
8868
		#參考資料來源:
8869
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8870
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8871
		unset($conf["variableCheck::checkArguments"]);
8872
 
8873
		#如果參數檢查失敗
8874
		if($checkArguments["status"]==="false"){
8875
 
8876
			#設置執行不正常
8877
			$result["status"]="false";
8878
 
8879
			#設置執行錯誤
8880
			$result["error"]=$checkArguments;
8881
 
8882
			#回傳結果
8883
			return $result;
8884
 
8885
			}#if end
8886
 
8887
		#如果參數檢查不通過
8888
		if($checkArguments["passed"]==="false"){
8889
 
8890
			#設置執行不正常
8891
			$result["status"]="false";
8892
 
8893
			#設置執行錯誤
8894
			$result["error"]=$checkArguments;
8895
 
8896
			#回傳結果
8897
			return $result;
8898
 
8899
			}#if end
8900
 
8901
		#初始化輸出
8902
		$output=array();
8903
 
8904
		#取得 PATH
8905
		exec("echo \$PATH",$output,$status);
8906
 
8907
		#如果執行失敗
8908
		if($status!==0){
8909
 
8910
			#設置執行失敗
8911
			$result["status"]="false";
8912
 
8913
			#設置執行錯誤訊息
8914
			$result["error"]="取得系統環境變數 PATH 失敗";
8915
 
8916
			#回傳結果
8917
			return $result;
8918
 
8919
			}#if end
8920
 
8921
		#取得 PATH 設定 
8922
		$PATHS=$output[0];
8923
 
8924
		#函式說明:
8925
		#將固定格式的字串分開,並回傳分開的結果.
8926
		#回傳結果:
8927
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8928
		#$result["error"],錯誤訊息陣列
8929
		#$result["function"],當前執行的函數名稱.
8930
		#$result["argu"],使用的參數.
8931
		#$result["oriStr"],要分割的原始字串內容
8932
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8933
		#$result["dataCounts"],爲總共分成幾段
8934
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
8935
		#必填參數:
8936
		#$conf["stringIn"],字串,要處理的字串.
8937
		$conf["stringProcess::spiltString"]["stringIn"]=$PATHS;
8938
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
8939
		$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
8940
		#可省略參數:
8941
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
8942
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
8943
		#參考資料:
8944
		#無.
8945
		#備註:
8946
		#無.
8947
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8948
		unset($conf["stringProcess::spiltString"]);
8949
 
8950
		#如果分割字串失敗
8951
		if($spiltString["status"]==="false"){
8952
 
8953
			#設置執行失敗
8954
			$result["status"]="false";
8955
 
8956
			#設置執行錯誤訊息
8957
			$result["error"]="取得系統環境變數 PATH 失敗";
8958
 
8959
			#回傳結果
8960
			return $result;
8961
 
8962
			}#if end
8963
 
8964
		#取得PATH字串陣列
8965
		$PATHS=$spiltString["dataArray"];
8966
 
8967
		#預設沒有找到程式
8968
		$cmdFound=false;
8969
 
8970
		#針對每個 $PATHS
8971
		foreach($PATHS as $path){
8972
 
8973
			#要運行的指令
8974
			$cmd="targetToCheck='".$path."/".$conf["cmd"]."';".PHP_EOL."if [ -f \${targetToCheck} ]; then".PHP_EOL."exit;".PHP_EOL."else".PHP_EOL."exit 1;".PHP_EOL."fi";
8975
 
8976
			#初始化輸出
8977
			$output=array();
8978
 
8979
			#執行指令
8980
			exec($cmd,$output,$status);
8981
 
8982
			#如果執行正常
8983
			if($status===0){
8984
 
8985
				#代表有找到程式
8986
				$cmdFound=true;
8987
 
8988
				#設置完整的程式路徑
8989
				$result["cmdFullPath"]=$path."/".$conf["cmd"];
8990
 
8991
				#跳離 foreach
8992
				break;
8993
 
8994
				}#if end
8995
 
8996
			}#foreach end
8997
 
8998
		#設置找到指令
8999
		$result["founded"]=$cmdFound;
9000
 
9001
		#設置執行正常
9002
		$result["status"]="true";
9003
 
9004
		#回傳結果
9005
		return $result;
9006
 
9007
		}#function checkCmdExist end
9008
 
9009
	/*
9010
	#函式說明:
9011
	#掃port的程式
9012
	#回傳結果:
9013
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9014
	#$result["error"],錯誤訊息.
9015
	#$result["function"],當前執行的函式名稱.
9016
	#$result["argu"],使用的參數.
9017
	#$result["content"],掃好可能可以使用的port資訊.
9018
	#必填參數
9019
	#$conf["fileArgu"],字串,變數__FILE__的內容.
9020
	$conf["fileArgu"]=__FILE__;
9021
	#可省略參數:
9022
	#$conf["target"],字串,要掃描的主機,預設為"127.0.0.1",
9023
	#$conf["target"]="127.0.0.1";
9024
	#$conf["-Pn"],字串,是否要啟用避免ping不到就會掃port失敗的功能,預設為"false".
9025
	#$conf["-Pn"]="false";
9026
	#參考資料:
9027
	#無.
9028
	#備註:
9029
	#無.
9030
	*/
9031
	public static function nmap(&$conf=array()){
9032
 
9033
		#初始化要回傳的結果
9034
		$result=array();
9035
 
9036
		#取得當前執行的函式名稱
9037
		$result["function"]=__FUNCTION__;
9038
 
9039
		#函式說明:
9040
		#判斷當前環境為web還是cmd
9041
		#回傳結果:
9042
		#$result,"web"或"cmd"
9043
		if(csInformation::getEnv()==="web"){
9044
 
9045
			#設置執行失敗
9046
			$result["status"]="false";
9047
 
9048
			#設置執行錯誤訊息
9049
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
9050
 
9051
			#回傳結果
9052
			return $result;
9053
 
9054
			}#if end
9055
 
9056
		#取得參數
9057
		$result["argu"]=$conf;
9058
 
9059
		#如果 $conf 不為陣列
9060
		if(gettype($conf)!="array"){
9061
 
9062
			#設置執行失敗
9063
			$result["status"]="false";
9064
 
9065
			#設置執行錯誤訊息
9066
			$result["error"][]="\$conf變數須為陣列形態";
9067
 
9068
			#如果傳入的參數為 null
9069
			if($conf==null){
9070
 
9071
				#設置執行錯誤訊息
9072
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
9073
 
9074
				}#if end
9075
 
9076
			#回傳結果
9077
			return $result;
9078
 
9079
			}#if end
9080
 
9081
		#檢查參數
9082
		#函式說明:
9083
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
9084
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9085
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9086
		#$result["function"],當前執行的函式名稱.
9087
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9088
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9089
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9090
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
9091
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
9092
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9093
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9094
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9095
		#必填寫的參數:
9096
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9097
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9098
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9099
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
9100
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
9101
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
9102
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9103
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9104
		#可以省略的參數:
9105
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
9106
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9107
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
9108
		#$conf["canNotBeEmpty"]=array();
9109
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
9110
		#$conf["canBeEmpty"]=array();
9111
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
9112
		#$conf["skipableVariableCanNotBeEmpty"]=array();
9113
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9114
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("target","-Pn");
9115
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
9116
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
9117
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9118
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("127.0.0.1","false");
9119
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9120
		#$conf["arrayCountEqualCheck"][]=array();
9121
		#參考資料來源:
9122
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9123
		#建議:
9124
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
9125
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9126
		unset($conf["variableCheck::checkArguments"]);
9127
 
9128
		#如果檢查參數失敗
9129
		if($checkArguments["status"]==="false"){
9130
 
9131
			#設置執行失敗
9132
			$result["status"]="false";
9133
 
9134
			#設置執行錯誤訊息
9135
			$result["error"]=$checkArguments;
9136
 
9137
			#回傳結果
9138
			return $result;
9139
 
9140
			}#if end
9141
 
9142
		#如果檢查參數不通過
9143
		if($checkArguments["passed"]==="false"){
9144
 
9145
			#設置執行失敗
9146
			$result["status"]="false";
9147
 
9148
			#設置執行錯誤訊息
9149
			$result["error"]=$checkArguments;
9150
 
9151
			#回傳結果
9152
			return $result;
9153
 
9154
			}#if end
9155
 
9156
		#檢查有無指令nmap存在
9157
		#函式說明:
9158
		#檢查指令是否存在
9159
		#回傳結果:
9160
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9161
		#$result["error"],錯誤訊息.
9162
		#$result["function"],當前執行的函式名稱.
9163
		#$result["argu"],使用的參數.
9164
		#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
9165
		#必填參數:
9166
		#$conf["cmd"],"字串",要查詢的指令.
9167
		$conf["self::checkCmdExist"]["cmd"]="nmap";
9168
		#可省略參數:
9169
		#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
9170
		#$conf["binPath"]="";
9171
		$checkCmdExist=self::checkCmdExist($conf["self::checkCmdExist"]);
9172
		unset($conf["self::checkCmdExist"]);
9173
 
9174
		#如果檢查指令 nmap 失敗
9175
		if($checkCmdExist["status"]==="false"){
9176
 
9177
			#設置執行失敗
9178
			$result["status"]="false";
9179
 
9180
			#設置執行錯誤訊息
9181
			$result["error"]=$checkCmdExist;
9182
 
9183
			#回傳結果
9184
			return $result;
9185
 
9186
			}#if end
9187
 
9188
		#如果指令 nmap 不存在
9189
		if($checkCmdExist["founded"]==="false"){
9190
 
9191
			#設置執行失敗
9192
			$result["status"]="false";
9193
 
9194
			#設置執行錯誤訊息
9195
			$result["error"]=$checkCmdExist;
9196
 
9197
			#回傳結果
9198
			return $result;
9199
 
9200
			}#if end
9201
 
9202
		#用 namp 指令掃 port
9203
		#函式說明:
9204
		#呼叫shell執行系統命令,並取得回傳的內容.
9205
		#回傳的結果:
9206
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9207
		#$result["error"],錯誤訊息陣列.
9208
		#$result["function"],當前執行的函式名稱.
9209
		#$result["cmd"],執行的指令內容.
9210
		#$result["output"],爲執行完二元碼後的輸出陣列.
9211
		#必填參數
9212
		#$conf["command"],字串,要執行的指令與.
9213
		$conf["external::callShell"]["command"]="nmap";
9214
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9215
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
9216
		#可省略參數:
9217
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9218
		$conf["external::callShell"]["argu"]=array($conf["target"]);
9219
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9220
		#$conf["enablePrintDescription"]="true";
9221
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
9222
		#$conf["printDescription"]="";
9223
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
9224
		$conf["external::callShell"]["escapeshellarg"]="true";
9225
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9226
		#$conf["username"]="";
9227
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9228
		#$conf["password"]="";
9229
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
9230
		#$conf["useScript"]="";
9231
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
9232
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9233
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9234
		#$conf["inBackGround"]="";
9235
		#備註:
9236
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9237
		#參考資料:
9238
		#exec=>http://php.net/manual/en/function.exec.php
9239
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9240
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9241
		$callShell=external::callShell($conf["external::callShell"]);
9242
		unset($conf["external::callShell"]);
9243
 
9244
		#如果掃port失敗
9245
		if($callShell["status"]==="false"){
9246
 
9247
			#設置執行失敗
9248
			$result["status"]="false";
9249
 
9250
			#設置執行錯誤訊息
9251
			$result["error"]=$checkCmdExist;
9252
 
9253
			#回傳結果
9254
			return $result;
9255
 
9256
			}#if end
9257
 
9258
		#初始化儲存新的指令輸出
9259
		$output=array();
9260
 
9261
		#針對每行輸出
9262
		foreach($callShell["output"] as $line){
9263
 
9264
			#如果不是空白行
9265
			if(trim($line)!==""){
9266
 
9267
				#記錄該行
9268
				$output[]=$line;
9269
 
9270
				}#if 
9271
 
9272
			}#foreach end
9273
 
9274
		#取代成沒有空白行的輸出
9275
		$callShell["output"]=$output;
9276
 
9277
		#如果輸出列數大於4
9278
		if(count($callShell["output"])>=4){
9279
 
9280
			#如果第4列有關鍵字 "PORT     STATE SERVICE"
9281
			#函式說明:
9282
			#檢查字串裡面有無指定的關鍵字
9283
			#回傳的結果:
9284
			#$result["status"],"true"代表執行成功,"false"代表執行失敗。
9285
			#$result["error"],錯誤訊息
9286
			#$result["function"],當前執行的函式名稱.
9287
			#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
9288
			#$result["keyWordCount"],找到的關鍵字數量.
9289
			#必填參數:
9290
			$conf["search::findKeyWord"]["keyWord"]="PORT";#想要搜尋的關鍵字
9291
			$conf["search::findKeyWord"]["string"]=$callShell["output"][4];#要被搜尋的字串內容
9292
			#可省略參數:
9293
			#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
9294
			$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
9295
			unset($conf["search::findKeyWord"]);
9296
 
9297
			#如果搜尋失敗
9298
			if($findKeyWord["status"]==="false"){
9299
 
9300
				#設置執行失敗
9301
				$result["status"]="false";
9302
 
9303
				#設置執行錯誤訊息
9304
				$result["error"]=$findKeyWord;
9305
 
9306
				#回傳結果
9307
				return $result;
9308
 
9309
				}#if end
9310
 
9311
			#如果找不到關鍵字
9312
			if($findKeyWord["founded"]==="false"){
9313
 
9314
				#設置執行失敗
9315
				$result["status"]="false";
9316
 
9317
				#設置執行錯誤訊息
9318
				$result["error"]=$findKeyWord;
9319
 
9320
				#回傳結果
9321
				return $result;
9322
 
9323
				}#if end
9324
 
9325
			#nmap輸出範例例輸出
9326
			/*
9327
			Starting Nmap 7.12 ( https://nmap.org ) at 2016-08-30 18:18 CST
9328
			Nmap scan report for 2.2.2.2
9329
			Host is up (0.00048s latency).
9330
			Not shown: 994 filtered ports
9331
			PORT     STATE SERVICE
9332
			80/tcp   open  http
9333
			513/tcp  open  login
9334
			514/tcp  open  shell
9335
			8000/tcp open  http-alt
9336
			8080/tcp open  http-proxy
9337
			8100/tcp open  xprint-server
9338
			Nmap done: 1 IP address (1 host up) scanned in 17.29 seconds
9339
			*/
9340
 
9341
			#初始化使用中的port
9342
			$result["content"]=array();
9343
 
9344
			#從第七列開始抓port資料到倒數第二列
9345
			for($i=5;$i<count($callShell["output"])-1;$i++){
9346
 
9347
				#用「/」去分割
9348
				#函式說明:
9349
				#將固定格式的字串分開,並回傳分開的結果。
9350
				#回傳結果:
9351
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9352
				#$result["error"],錯誤訊息陣列
9353
				#$result["function"],當前執行的函式名稱.
9354
				#$result["oriStr"],要分割的原始字串內容
9355
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9356
				#$result["dataCounts"],爲總共分成幾段
9357
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9358
				#必填參數:
9359
				$conf["stringProcess::spiltString"]["stringIn"]=$callShell["output"][$i];#要處理的字串。
9360
				$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
9361
				#可省略參數:
9362
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9363
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
9364
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
9365
				unset($conf["stringProcess::spiltString"]);
9366
 
9367
				#如果分割字串失敗
9368
				if($spiltString["status"]==="false"){
9369
 
9370
					#設置執行失敗
9371
					$result["status"]="false";
9372
 
9373
					#設置執行錯誤訊息
9374
					$result["error"]=$spiltString;
9375
 
9376
					#回傳結果
9377
					return $result;
9378
 
9379
					}#if end
9380
 
9381
				#如果沒有分割用的符號
9382
				if($spiltString["found"]==="false"){
9383
 
9384
					#設置執行失敗
9385
					$result["status"]="false";
9386
 
9387
					#設置執行錯誤訊息
9388
					$result["error"]=$spiltString;
9389
 
9390
					#回傳結果
9391
					return $result;
9392
 
9393
					}#if end
9394
 
9395
				#取得使用中的port
9396
				$result["content"][]=$spiltString["dataArray"][0];
9397
 
9398
				}#for end
9399
 
9400
			}#if end
9401
 
9402
		#反之代表主機可能不接受ping,且未使用 -Pn 參數.
9403
		else if($conf["-Pn"]==="false"){
9404
 
9405
			#取得計有的參數
9406
			$params=$conf;
9407
 
9408
			#設置用-Pn參數
9409
			$parmas["-Pn"]="true";
9410
 
9411
			#呼叫自己
9412
			return self::nmap($params);
9413
 
9414
			}#else end
9415
 
9416
		#反之
9417
		else{
9418
 
9419
			#設置執行不正常
9420
			$result["status"]="false";
9421
 
9422
			#設置錯誤訊息
9423
			$result["error"][]="無法取得port的使用狀況";
9424
 
9425
			#回傳結果
9426
			return $result;
9427
 
9428
			}#else end
9429
 
9430
		#設置執行正常
9431
		$result["status"]="true";
9432
 
9433
		#回傳結果
9434
		return $result;
9435
 
9436
		}#function nmap end
9437
 
9438
	/*
9439
	#函式說明:
9440
	#fedora的nmcli指令,取得所有網路連線設定的資訊.
9441
	#回傳結果:
9442
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9443
	#$result["error"],錯誤訊息.
9444
	#$result["function"],當前執行的函式名稱.
9445
	#$result["argu"],使用的參數.
9446
	#$result["content"],連線資訊.有DEVICE,TYPE,UUID,NAME.
9447
	#必填參數
9448
	#$conf["fileArgu"],字串,__FILE__的內容.
9449
	$conf["fileArgu"]=__FILE__;
9450
	#可省略參數:
9451
	#無.
9452
	#參考資料:
9453
	#無.
9454
	#備註:
9455
	#僅能在命令列環境下執行.
9456
	*/
9457
	public static function nmcli_list(&$conf){
9458
 
9459
		#初始化要回傳的結果
9460
		$result=array();
9461
 
9462
		#取得當前執行的函式名稱
9463
		$result["function"]=__FUNCTION__;
9464
 
9465
		#如果沒有參數
9466
		if(func_num_args()==0){
9467
 
9468
			#設置執行失敗
9469
			$result["status"]="false";
9470
 
9471
			#設置執行錯誤訊息
9472
			$result["error"]="函式".$result["function"]."需要參數";
9473
 
9474
			#回傳結果
9475
			return $result;
9476
 
9477
			}#if end
9478
 
9479
		#函式說明:
9480
		#判斷當前環境為web還是cmd
9481
		#回傳結果:
9482
		#$result,"web"或"cmd"
9483
		if(csInformation::getEnv()==="web"){
9484
 
9485
			#設置執行失敗
9486
			$result["status"]="false";
9487
 
9488
			#設置執行錯誤訊息
9489
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
9490
 
9491
			#回傳結果
9492
			return $result;
9493
 
9494
			}#if end
9495
 
9496
		#取得參數
9497
		$result["argu"]=$conf;
9498
 
9499
		#如果 $conf 不為陣列
9500
		if(gettype($conf)!=="array"){
9501
 
9502
			#設置執行失敗
9503
			$result["status"]="false";
9504
 
9505
			#設置執行錯誤訊息
9506
			$result["error"][]="\$conf變數須為陣列形態";
9507
 
9508
			#如果傳入的參數為 null
9509
			if($conf===null){
9510
 
9511
				#設置執行錯誤訊息
9512
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
9513
 
9514
				}#if end
9515
 
9516
			#回傳結果
9517
			return $result;
9518
 
9519
			}#if end
9520
 
9521
		#函式說明:
9522
		#檢查指令是否存在
9523
		#回傳結果:
9524
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9525
		#$result["error"],錯誤訊息.
9526
		#$result["function"],當前執行的函式名稱.
9527
		#$result["argu"],使用的參數.
9528
		#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
9529
		#必填參數:
9530
		#$conf["cmd"],"字串",要查詢的指令.
9531
		$conf["cmd::checkCmdExist"]["cmd"]="nmcli";
9532
		#可省略參數:
9533
		#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
9534
		#$conf["binPath"]="";
9535
		$checkCmdExist=$checkCmdExist=cmd::checkCmdExist($conf["cmd::checkCmdExist"]);
9536
		unset($conf["cmd::checkCmdExist"]);
9537
 
9538
		#如果執行失敗
9539
		if($checkCmdExist["status"]==="false"){
9540
 
9541
			#設置執行失敗
9542
			$result["status"]="false";
9543
 
9544
			#設置執行錯誤訊息
9545
			$result["error"]=$checkCmdExist;
9546
 
9547
			#回傳結果
9548
			return $result;
9549
 
9550
			}#if end
9551
 
9552
		#如果指令不存在
9553
		if($checkCmdExist["founded"]==="false"){
9554
 
9555
			#設置執行失敗
9556
			$result["status"]="false";
9557
 
9558
			#設置執行錯誤訊息
9559
			$result["error"]=$checkCmdExist;
9560
 
9561
			#回傳結果
9562
			return $result;
9563
 
9564
			}#if end
9565
 
9566
		#函式說明:
9567
		#呼叫shell執行系統命令,並取得回傳的內容.
9568
		#回傳的結果:
9569
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9570
		#$result["error"],錯誤訊息陣列.
9571
		#$result["function"],當前執行的函式名稱.
9572
		#$result["cmd"],執行的指令內容.
9573
		#$result["output"],爲執行完二元碼後的輸出陣列.
9574
		#必填參數
9575
		#$conf["command"],字串,要執行的指令與.
9576
		$conf["external::callShell"]["command"]="nmcli";
9577
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9578
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
9579
		#可省略參數:
9580
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9581
		$conf["external::callShell"]["argu"]=array("c");
9582
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9583
		#$conf["arguIsAddr"]=array();
9584
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9585
		#$conf["enablePrintDescription"]="true";
9586
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
9587
		#$conf["printDescription"]="";
9588
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
9589
		$conf["external::callShell"]["escapeshellarg"]="true";
9590
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9591
		#$conf["username"]="";
9592
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9593
		#$conf["password"]="";
9594
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9595
		#$conf["useScript"]="";
9596
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9597
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9598
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9599
		#$conf["inBackGround"]="";
9600
		#備註:
9601
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9602
		#參考資料:
9603
		#exec=>http://php.net/manual/en/function.exec.php
9604
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9605
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9606
		$callShell=external::callShell($conf["external::callShell"]);
9607
		unset($conf["external::callShell"]);
9608
 
9609
		#如果執行失敗
9610
		if($callShell["status"]==="false"){
9611
 
9612
			#設置執行失敗
9613
			$result["status"]="false";
9614
 
9615
			#設置執行錯誤訊息
9616
			$result["error"]=$callShell;
9617
 
9618
			#回傳結果
9619
			return $result;
9620
 
9621
			}#if end
9622
 
9623
		#取得輸出
9624
		$nmcliStrArray=&$callShell["output"];
9625
 
9626
		#初始化儲存欄位的名稱
9627
		$colName=array();
9628
 
9629
		#針對每個連線設定檔
9630
		foreach($nmcliStrArray as $index=>$cInfo){
9631
 
9632
			#範例輸出:
9633
			/*
9634
			NAME                       UUID                                  TYPE             DEVICE
9635
			br0                        0627f17d-f855-4dc7-b8fc-b0f893fe1a8d  bridge           br0
9636
			enp3s0                     2eca39a1-bacb-4fc2-aea8-eb2a990bf9af  802-3-ethernet   enp3s0
9637
			tap0                       4f16a556-7ff7-4c80-a97d-ba1a5a181fbc  tun              tap0
9638
			virbr0                     84afc773-5d55-48b9-b06b-d91385091ea7  bridge           virbr0
9639
			CHT8909                    820ec025-b1e5-45bc-b3c9-b14b6078f3f6  802-11-wireless  --
9640
			Coolbee Wifi ShoppingMall  67b5cd6d-2ebb-4f81-98ae-8cfba6979d58  802-11-wireless  --
9641
			bridge0 slave 1            86bca1ad-f984-47d0-833b-3ff3d8909f0a  802-3-ethernet   --
9642
			enp3s0                     e0c87421-5d6c-3197-909e-15a94d42b8fe  802-3-ethernet   --
9643
			*/
9644
 
9645
			#分割字串
9646
			#函式說明:
9647
			#將固定格式的字串分開,並回傳分開的結果。
9648
			#回傳結果:
9649
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9650
			#$result["error"],錯誤訊息陣列
9651
			#$result["function"],當前執行的函式名稱.
9652
			#$result["oriStr"],要分割的原始字串內容
9653
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9654
			#$result["dataCounts"],爲總共分成幾段
9655
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9656
			#必填參數:
9657
			$conf["stringProcess::spiltString"]["stringIn"]=$cInfo;#要處理的字串。
9658
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
9659
			#可省略參數:
9660
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9661
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
9662
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
9663
			unset($conf["stringProcess::spiltString"]);
9664
 
9665
			#如果分割失敗
9666
			if($spiltString["status"]==="false"){
9667
 
9668
				#設置執行失敗
9669
				$result["status"]="false";
9670
 
9671
				#設置執行錯誤訊息
9672
				$result["error"]=$spiltString;
9673
 
9674
				#回傳結果
9675
				return $result;
9676
 
9677
				}#if end
9678
 
9679
			#如果沒有找到分割用關鍵字" "
9680
			if($spiltString["found"]==="false"){
9681
 
9682
				#設置執行失敗
9683
				$result["status"]="false";
9684
 
9685
				#設置執行錯誤訊息
9686
				$result["error"]=$spiltString;
9687
 
9688
				#回傳結果
9689
				return $result;
9690
 
9691
				}#if end
9692
 
9693
			#如果是標題字串
9694
			if($index===0){
9695
 
9696
				#如果段數不等於4
9697
				if($spiltString["dataCounts"]!==4){
9698
 
9699
					#設置執行失敗
9700
					$result["status"]="false";
9701
 
9702
					#設置執行錯誤訊息
9703
					$result["error"]=$spiltString;
9704
 
9705
					#回傳結果
9706
					return $result;
9707
 
9708
					}#if end
9709
 
9710
				#有幾段就執行幾次
9711
				foreach($spiltString["dataArray"] as $cn){
9712
 
9713
					#串接欄位名稱
9714
					$colName[]=$cn;
9715
 
9716
					}#foreach end
9717
 
9718
				}#if end
9719
 
9720
			#反之
9721
			else{
9722
 
9723
				#如果段數小於4
9724
				if($spiltString["dataCounts"]<4){
9725
 
9726
					#設置執行失敗
9727
					$result["status"]="false";
9728
 
9729
					#設置執行錯誤訊息
9730
					$result["error"]=$spiltString;
9731
 
9732
					#回傳結果
9733
					return $result;
9734
 
9735
					}#if end
9736
 
9737
				#如果段數不等於4
9738
				if($spiltString["dataCounts"]!==4){
9739
 
9740
					#從後面開始擷取內容
9741
 
9742
					#暫存要儲存的key值
9743
					$count=4;
9744
 
9745
					#初始化暫存網路連線設定檔的陣列
9746
					$ni=array();
9747
 
9748
					#初始化迴圈起始的值
9749
					$i=$spiltString["dataCounts"]-1;
9750
 
9751
					#有幾段就執行幾次
9752
					for(;$i>$spiltString["dataCounts"]-4;$i--){
9753
 
9754
						#儲存欄位對應的內容
9755
						$ni[$colName[--$count]]=$spiltString["dataArray"][$i];
9756
 
9757
						}#for end
9758
 
9759
					#初始化暫存第一個欄位的名稱
9760
					$fc="";
9761
 
9762
					#剩下的段落為連線的名稱
9763
					for(;$i>=0;$i--){
9764
 
9765
						#如果不是最後一個
9766
						if($i!==0){
9767
 
9768
							#串接第一個欄位的內容
9769
							$fc=$spiltString["dataArray"][$i]." ".$fc;
9770
 
9771
							}#if end
9772
 
9773
						#反之
9774
						else{
9775
 
9776
							#串接第一個欄位的內容
9777
							$fc=$spiltString["dataArray"][$i];
9778
 
9779
							}#else end
9780
 
9781
						}#for end
9782
 
9783
					#取得第一個欄位的內容
9784
					$ni[$colName[--$count]]=$fc;
9785
 
9786
					#取得該連線設定檔的資訊
9787
					$result["content"][]=$ni;
9788
 
9789
					}#if end
9790
 
9791
				#如果剛好等於4段
9792
				if($spiltString["dataCounts"]===4){
9793
 
9794
					#有幾段就執行幾次
9795
					for($i=0;$i<$spiltString["dataCounts"];$i++){
9796
 
9797
						#儲存欄位對應的內容
9798
						$ni[$colName[$i]]=$spiltString["dataArray"][$i];
9799
 
9800
						}#for end
9801
 
9802
					#取得該連線設定檔的資訊
9803
					$result["content"][]=$ni;
9804
 
9805
					}#if end
9806
 
9807
				}#if end
9808
 
9809
			}#foreach end
9810
 
9811
		#設置執行正常
9812
		$result["status"]="true";
9813
 
9814
		#回傳結果
9815
		return $result;
9816
 
9817
		}#function nmcli_list end
9818
 
9819
	/*
9820
	#函式說明:
9821
	#fedora的nmcli指令,重新連線指定的連線。
9822
	#回傳結果:
9823
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9824
	#$result["error"],錯誤訊息.
9825
	#$result["function"],當前執行的函式名稱.
9826
	#$result["argu"],使用的參數.
9827
	#$result["content"],連線資訊.有DEVICE,TYPE,UUID,NAME.
9828
	#必填參數
9829
	#$conf["fileArgu"],字串,__FILE__的內容.
9830
	$conf["fileArgu"]=__FILE__;
9831
	#$conf["name-uuid"],字串,"代表用來識別連線的名稱或UUID".
9832
	$conf["name-uuid"]="";
9833
	#可省略參數:
9834
	#無.
9835
	#參考資料:
9836
	#無.
9837
	#備註:
9838
	#僅能在命令列環境下執行.
9839
	*/	
9840
	public static function nmcli_reconnect($conf){
9841
 
9842
		#初始化要回傳的結果
9843
		$result=array();
9844
 
9845
		#取得當前執行的函式名稱
9846
		$result["function"]=__FUNCTION__;
9847
 
9848
		#如果沒有參數
9849
		if(func_num_args()==0){
9850
 
9851
			#設置執行失敗
9852
			$result["status"]="false";
9853
 
9854
			#設置執行錯誤訊息
9855
			$result["error"]="函式".$result["function"]."需要參數";
9856
 
9857
			#回傳結果
9858
			return $result;
9859
 
9860
			}#if end
9861
 
9862
		#取得參數
9863
		$result["argu"]=$conf;
9864
 
9865
		#如果 $conf 不為陣列
9866
		if(gettype($conf)!=="array"){
9867
 
9868
			#設置執行失敗
9869
			$result["status"]="false";
9870
 
9871
			#設置執行錯誤訊息
9872
			$result["error"][]="\$conf變數須為陣列形態";
9873
 
9874
			#如果傳入的參數為 null
9875
			if($conf===null){
9876
 
9877
				#設置執行錯誤訊息
9878
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
9879
 
9880
				}#if end
9881
 
9882
			#回傳結果
9883
			return $result;
9884
 
9885
			}#if end
9886
 
9887
		#檢查參數
9888
		#函式說明:
9889
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
9890
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9891
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9892
		#$result["function"],當前執行的函式名稱.
9893
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9894
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9895
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9896
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
9897
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
9898
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9899
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9900
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9901
		#必填寫的參數:
9902
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9903
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9904
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9905
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9906
		#可以省略的參數:
9907
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9908
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name-uuid");
9909
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
9910
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
9911
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
9912
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9913
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
9914
		#$conf["canNotBeEmpty"]=array();
9915
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
9916
		#$conf["canBeEmpty"]=array();
9917
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
9918
		#$conf["skipableVariableCanNotBeEmpty"]=array();
9919
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9920
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("echo");
9921
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
9922
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
9923
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9924
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
9925
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
9926
		#$conf["disallowAllSkipableVarIsEmpty"]="";
9927
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
9928
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
9929
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9930
		#$conf["arrayCountEqualCheck"][]=array();
9931
		#參考資料來源:
9932
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9933
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9934
		unset($conf["variableCheck::checkArguments"]);
9935
 
9936
		#若執行失敗
9937
		if($checkArguments["status"]==="false"){
9938
 
9939
			#設置執行失敗
9940
			$result["status"]="false";
9941
 
9942
			#設置執行錯誤訊息
9943
			$result["error"]=$checkArguments;
9944
 
9945
			#回傳結果
9946
			return $result;
9947
 
9948
			}#if end
9949
 
9950
		#若檢查不通過
9951
		if($checkArguments["passed"]==="false"){
9952
 
9953
			#設置執行失敗
9954
			$result["status"]="false";
9955
 
9956
			#設置執行錯誤訊息
9957
			$result["error"]=$checkArguments;
9958
 
9959
			#回傳結果
9960
			return $result;
9961
 
9962
			}#if end
9963
 
9964
 
9965
		#函式說明:
9966
		#呼叫shell執行系統命令,並取得回傳的內容.
9967
		#回傳的結果:
9968
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9969
		#$result["error"],錯誤訊息陣列.
9970
		#$result["function"],當前執行的函式名稱.
9971
		#$result["argu"],使用的參數.
9972
		#$result["cmd"],執行的指令內容.
9973
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9974
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9975
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9976
		#$result["running"],是否還在執行.
9977
		#$result["pid"],pid.
9978
		#$result["statusCode"],執行結束後的代碼.
9979
		#必填參數
9980
		#$conf["command"],字串,要執行的指令與.
9981
		$conf["external::callShell"]["command"]="nmcli";
9982
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9983
		$conf["external::callShell"]["fileArgu"]=__FILE__;		
9984
		#可省略參數:
9985
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9986
		$conf["external::callShell"]["argu"]=array("c","down",$conf["name-uuid"]);
9987
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9988
		#$conf["arguIsAddr"]=array();	
9989
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9990
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9991
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9992
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9993
		#$conf["enablePrintDescription"]="true";
9994
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9995
		#$conf["printDescription"]="";
9996
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
9997
		$conf["external::callShell"]["escapeshellarg"]="true";
9998
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9999
		#$conf["username"]="";
10000
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10001
		#$conf["password"]="";
10002
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10003
		#$conf["useScript"]="";
10004
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10005
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10006
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10007
		#$conf["inBackGround"]="";
10008
		#備註:
10009
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10010
		#參考資料:
10011
		#exec=>http://php.net/manual/en/function.exec.php
10012
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10013
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10014
		$callShell=external::callShell($conf["external::callShell"]);
10015
 
10016
		#如果執行失敗
10017
		if($callShell["status"]==="false" && $callShell["error"][0]!==10 && $callShell["error"][0]!==4){
10018
 
10019
			#設置執行失敗
10020
			$result["status"]="false";
10021
 
10022
			#設置執行錯誤訊息
10023
			$result["error"]=$callShell;
10024
 
10025
			#回傳結果
10026
			return $result;
10027
 
10028
			}#if end
10029
 
10030
		#函式說明:
10031
		#呼叫shell執行系統命令,並取得回傳的內容.
10032
		#回傳的結果:
10033
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10034
		#$result["error"],錯誤訊息陣列.
10035
		#$result["function"],當前執行的函式名稱.
10036
		#$result["argu"],使用的參數.
10037
		#$result["cmd"],執行的指令內容.
10038
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10039
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10040
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10041
		#$result["running"],是否還在執行.
10042
		#$result["pid"],pid.
10043
		#$result["statusCode"],執行結束後的代碼.
10044
		#必填參數
10045
		#$conf["command"],字串,要執行的指令與.
10046
		$conf["external::callShell"]["command"]="nmcli";
10047
		#$conf["fileArgu"],字串,變數__FILE__的內容.
10048
		$conf["external::callShell"]["fileArgu"]=__FILE__;		
10049
		#可省略參數:
10050
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
10051
		$conf["external::callShell"]["argu"]=array("c","up",$conf["name-uuid"]);
10052
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
10053
		#$conf["arguIsAddr"]=array();	
10054
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10055
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10056
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10057
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10058
		#$conf["enablePrintDescription"]="true";
10059
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10060
		#$conf["printDescription"]="";
10061
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
10062
		#$conf["escapeshellarg"]="false";
10063
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10064
		#$conf["username"]="";
10065
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10066
		#$conf["password"]="";
10067
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10068
		#$conf["useScript"]="";
10069
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10070
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10071
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10072
		#$conf["inBackGround"]="";
10073
		#備註:
10074
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10075
		#參考資料:
10076
		#exec=>http://php.net/manual/en/function.exec.php
10077
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10078
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10079
		$callShell=external::callShell($conf["external::callShell"]);
10080
 
10081
		#如果執行失敗
10082
		if($callShell["status"]==="false" && $callShell["error"][0]!==4){
10083
 
10084
			#設置執行失敗
10085
			$result["status"]="false";
10086
 
10087
			#設置執行錯誤訊息
10088
			$result["error"]=$callShell;
10089
 
10090
			#回傳結果
10091
			return $result;
10092
 
10093
			}#if end
10094
 
10095
		#設置執行正常
10096
		$result["status"]="true";
10097
 
10098
		#記錄執行結果
10099
		$result["content"]=$callShell;
10100
 
10101
		#回傳結果
10102
		return $result;
10103
 
10104
		}#function nmcli_reconnect end
10105
 
10106
	/*
10107
	#函式說明:
10108
	#抓取命令列的參數.
10109
	#回傳結果:
10110
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10111
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
10112
	#$result["function"],當前執行的函式名稱.
10113
	#$result["argu"],使用的參數陣列.
10114
	#$result["content"],要回傳的參數陣列.
10115
	#$result["count"],參數的數量.
10116
	#$result["_GET"],收到的 HTTP GET 參數陣列.
10117
	#$result["_POST"],收到的 HTTP POST 參數陣列.
10118
	#必填參數:
10119
	#無
10120
	#可省略參數:
10121
	#$conf["echo"],字串,"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
10122
	#$conf["echo"]="false";
10123
	#$conf["httpGetToArgu"],字串,"true"代表要將 http get 參數變成參數來取得,像是 $_GET["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.
10124
	#$conf["httpGetToArgu"]="false";
10125
	#$conf["httpPostToArgu"],字串,"true"代表要將 http post 參數變成參數來取得,像是 $_POST["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.
10126
	#$conf["httpPostToArgu"]="false";
48 liveuser 10127
	#$conf["arguEqual2http"],字串,預設為"false",代表命令列環境的參數依序為程式名稱本身、第n個參數,反之為"true",代表命令列的第一個參數為第n個參數,亦即沒有程式本身名稱的參數.
10128
	#$conf["arguEqual2http"]="false";
3 liveuser 10129
	#參考資料:
10130
	#無.
10131
	#備註:
10132
	#pipe要用''包住,才會被解析,例如'|'、'>'、'>>'.
10133
	*/
10134
	public static function getArgu(&$conf=array()){
10135
 
10136
		#初始化要回傳的結果
10137
		$result=array();
10138
 
10139
		#取得當前執行的函式名稱
10140
		$result["function"]=__FUNCTION__;
10141
 
10142
		#如果沒有參數
10143
		if(func_num_args()==0){
10144
 
10145
			#設置執行失敗
10146
			$result["status"]="false";
10147
 
10148
			#設置執行錯誤訊息
10149
			$result["error"]="函式".$result["function"]."需要參數";
10150
 
10151
			#回傳結果
10152
			return $result;
10153
 
10154
			}#if end
10155
 
10156
		#取得參數
10157
		$result["argu"]=$conf;
10158
 
10159
		#如果 $conf 不為陣列
10160
		if(gettype($conf)!=="array"){
10161
 
10162
			#設置執行失敗
10163
			$result["status"]="false";
10164
 
10165
			#設置執行錯誤訊息
10166
			$result["error"][]="\$conf變數須為陣列形態";
10167
 
10168
			#如果傳入的參數為 null
10169
			if($conf===null){
10170
 
10171
				#設置執行錯誤訊息
10172
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
10173
 
10174
				}#if end
10175
 
10176
			#回傳結果
10177
			return $result;
10178
 
10179
			}#if end
10180
 
10181
		#檢查參數
10182
		#函式說明:
10183
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
10184
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10185
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10186
		#$result["function"],當前執行的函式名稱.
10187
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10188
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10189
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10190
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
10191
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
10192
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10193
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10194
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10195
		#必填寫的參數:
10196
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10197
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10198
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10199
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10200
		#可以省略的參數:
10201
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10202
		#$conf["mustBeFilledVariableName"]=array();
10203
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
10204
		#$conf["mustBeFilledVariableType"]=array();
10205
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
10206
		#$conf["canBeEmptyString"]="false";
10207
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
10208
		#$conf["canNotBeEmpty"]=array();
10209
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
10210
		#$conf["canBeEmpty"]=array();
10211
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
10212
		#$conf["skipableVariableCanNotBeEmpty"]=array();
10213
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
48 liveuser 10214
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("echo","httpGetToArgu","httpPostToArgu","arguEqual2http");
3 liveuser 10215
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
48 liveuser 10216
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
3 liveuser 10217
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
48 liveuser 10218
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false","false");
3 liveuser 10219
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
10220
		#$conf["disallowAllSkipableVarIsEmpty"]="";
10221
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
10222
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
10223
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10224
		#$conf["arrayCountEqualCheck"][]=array();
10225
		#參考資料來源:
10226
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10227
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10228
		unset($conf["variableCheck::checkArguments"]);
10229
 
10230
		#若執行失敗
10231
		if($checkArguments["status"]==="false"){
10232
 
10233
			#設置執行失敗
10234
			$result["status"]="false";
10235
 
10236
			#設置執行錯誤訊息
10237
			$result["error"]=$checkArguments;
10238
 
10239
			#回傳結果
10240
			return $result;
10241
 
10242
			}#if end
10243
 
10244
		#若檢查不通過
10245
		if($checkArguments["passed"]==="false"){
10246
 
10247
			#設置執行失敗
10248
			$result["status"]="false";
10249
 
10250
			#設置執行錯誤訊息
10251
			$result["error"]=$checkArguments;
10252
 
10253
			#回傳結果
10254
			return $result;
10255
 
10256
			}#if end
10257
 
48 liveuser 10258
		#預設沒有參數
10259
		$result["content"]=array();
3 liveuser 10260
 
48 liveuser 10261
		#預設參數數量為0
10262
		$result["count"]=0;
3 liveuser 10263
 
48 liveuser 10264
		#如果有 $_SERVER["argv"]
10265
		if(isset($_SERVER["argv"])){
10266
 
10267
			#儲存參數
10268
			$result["content"]=$_SERVER["argv"];
10269
 
10270
			}#if end
10271
 
10272
		#如果有 $_SERVER["argc"]
10273
		if(isset($_SERVER["argc"])){
10274
 
10275
			#取得參數數量
10276
			$result["count"]=$_SERVER["argc"];
10277
 
10278
			}#if end
10279
 
10280
		#如果 arguEqual2http 為 "true" 且含有參數
10281
		if($conf["arguEqual2http"]==="true" && count($result["content"])>0 ){
10282
 
10283
			#移除命令列的第一個參數(程式名稱)
10284
			$array_shift=array_shift($result["content"]);
10285
 
10286
			#如果異常
10287
			if($array_shift===null){
10288
 
10289
				#設置執行失敗
10290
				$result["status"]="false";
3 liveuser 10291
 
48 liveuser 10292
				#設置執行錯誤訊息
10293
				$result["error"][]="shift first argu failed";
10294
 
10295
				#回傳結果
10296
				return $result;
10297
 
10298
				}#if end
10299
 
10300
			}#if end
10301
 
3 liveuser 10302
		#如果要將 http get 變成參數
10303
		if($conf["httpGetToArgu"]==="true"){
10304
 
10305
			#函式說明:
10306
			#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
10307
			#回傳結果:
10308
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
10309
			#$result["error"],錯誤訊息陣列.
10310
			#$resutl["function"],當前執行的函式名稱.
10311
			#$result["warning"],警告訊息陣列.
10312
			#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
10313
			#$result["lostVarName"],沒有皆收到的變數名稱陣列
10314
			#$result["inputDataContent"],所接收的參數陣列.
10315
			#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
10316
			#$result["inputDataCount"],從表單總共接收到幾個元素.
10317
			#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
10318
			#必填參數:
10319
			#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
10320
			$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="get";
10321
			#可省略參數:
10322
			#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
10323
			$conf["form::responseMultiInputDataSecurityEnhance"]["allowGet"]="true";
10324
			#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
10325
			#$conf["limitPrePage"]=array("");
10326
			#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
10327
			#$conf["transferLocation"]="";
10328
			#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
10329
			#$conf["ignore"]=array();
10330
			#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
10331
			#$conf["correctCharacter"]="false";
10332
			#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
10333
			#$conf["checkedVarName"]=array();
10334
			#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
10335
			#$conf["canBeEmptyString"]="false";
10336
			#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
10337
			#$conf["sessionNameArray"]=array();
10338
			#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
10339
			#$conf["unsetSessionArray"]=array();
10340
			#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.
10341
			#$conf["recaptcha_url"]="";
10342
			#參考資料:
10343
			#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
10344
			#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
10345
			#備註:
10346
			#表單變數的名稱若含有「.」,則會變成「-」。
10347
			$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);
10348
			unset($conf["form::responseMultiInputDataSecurityEnhance"]);
10349
 
10350
			#若執行失敗
10351
			if($responseMultiInputDataSecurityEnhance["status"]==="false"){
10352
 
10353
				#設置執行失敗
10354
				$result["status"]="false";
10355
 
10356
				#設置執行錯誤訊息
10357
				$result["error"]=$responseMultiInputDataSecurityEnhance;
10358
 
10359
				#回傳結果
10360
				return $result;
10361
 
10362
				}#if end
10363
 
10364
			#取得 GET 變數	
10365
			$result["_GET"]=$responseMultiInputDataSecurityEnhance["inputDataContent"];
10366
 
10367
			#函式說明:
10368
			#將多個一維陣列串聯起來,key從0開始排序.
10369
			#回傳的結果:
10370
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
10371
			#$result["error"],錯誤訊息陣列.
10372
			#$result["function"],當前執行的函數.
10373
			#$result["content"],合併好的一維陣列.
10374
			#必填參數
10375
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
10376
			$conf["arrays::mergeArray"]["inputArray"]=array($result["content"],$result["_GET"]);
10377
			#可省略參數:
10378
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
10379
			$conf["arrays::mergeArray"]["allowRepeat"]="false";
10380
			#參考資料:
10381
			#無.
10382
			#備註:
10383
			#無.
10384
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
10385
			unset($conf["arrays::mergeArray"]);
10386
 
10387
			#若執行失敗
10388
			if($mergeArray["status"]==="false"){
10389
 
10390
				#設置執行失敗
10391
				$result["status"]="false";
10392
 
10393
				#設置執行錯誤訊息
10394
				$result["error"]=$mergeArray;
10395
 
10396
				#回傳結果
10397
				return $result;
10398
 
10399
				}#if end
10400
 
10401
			#取得合併好的參數陣列
10402
			$result["content"]=$mergeArray["content"];
10403
 
10404
			#更新參數的數量
10405
			$result["count"]=count($result["content"]);
10406
 
10407
			}#if end
10408
 
10409
		#如果要將 http post 變成參數
10410
		if($conf["httpPostToArgu"]==="true"){
10411
 
10412
			#函式說明:
10413
			#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
10414
			#回傳結果:
10415
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
10416
			#$result["error"],錯誤訊息陣列.
10417
			#$resutl["function"],當前執行的函式名稱.
10418
			#$result["warning"],警告訊息陣列.
10419
			#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
10420
			#$result["lostVarName"],沒有皆收到的變數名稱陣列
10421
			#$result["inputDataContent"],所接收的參數陣列.
10422
			#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
10423
			#$result["inputDataCount"],從表單總共接收到幾個元素.
10424
			#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
10425
			#必填參數:
10426
			#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
10427
			$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="post";
10428
			#可省略參數:
10429
			#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
10430
			$conf["form::responseMultiInputDataSecurityEnhance"]["allowGet"]="true";
10431
			#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
10432
			#$conf["limitPrePage"]=array("");
10433
			#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
10434
			#$conf["transferLocation"]="";
10435
			#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
10436
			#$conf["ignore"]=array();
10437
			#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
10438
			#$conf["correctCharacter"]="false";
10439
			#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
10440
			#$conf["checkedVarName"]=array();
10441
			#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
10442
			#$conf["canBeEmptyString"]="false";
10443
			#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
10444
			#$conf["sessionNameArray"]=array();
10445
			#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
10446
			#$conf["unsetSessionArray"]=array();
10447
			#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.
10448
			#$conf["recaptcha_url"]="";
10449
			#參考資料:
10450
			#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
10451
			#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
10452
			#備註:
10453
			#表單變數的名稱若含有「.」,則會變成「-」。
10454
			$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);
10455
			unset($conf["form::responseMultiInputDataSecurityEnhance"]);
10456
 
10457
			#若執行失敗
10458
			if($responseMultiInputDataSecurityEnhance["status"]==="false"){
10459
 
10460
				#設置執行失敗
10461
				$result["status"]="false";
10462
 
10463
				#設置執行錯誤訊息
10464
				$result["error"]=$responseMultiInputDataSecurityEnhance;
10465
 
10466
				#回傳結果
10467
				return $result;
10468
 
10469
				}#if end
10470
 
10471
			#取得 POST 變數	
10472
			$result["_POST"]=$responseMultiInputDataSecurityEnhance["inputDataContent"];
10473
 
10474
			#函式說明:
10475
			#將多個一維陣列串聯起來,key從0開始排序.
10476
			#回傳的結果:
10477
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
10478
			#$result["error"],錯誤訊息陣列.
10479
			#$result["function"],當前執行的函數.
10480
			#$result["content"],合併好的一維陣列.
10481
			#必填參數
10482
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
10483
			$conf["arrays::mergeArray"]["inputArray"]=array($result["content"],$result["_POST"]);
10484
			#可省略參數:
10485
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
10486
			$conf["arrays::mergeArray"]["allowRepeat"]="false";
10487
			#參考資料:
10488
			#無.
10489
			#備註:
10490
			#無.
10491
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
10492
			unset($conf["arrays::mergeArray"]);
10493
 
10494
			#若執行失敗
10495
			if($mergeArray["status"]==="false"){
10496
 
10497
				#設置執行失敗
10498
				$result["status"]="false";
10499
 
10500
				#設置執行錯誤訊息
10501
				$result["error"]=$mergeArray;
10502
 
10503
				#回傳結果
10504
				return $result;
10505
 
10506
				}#if end
10507
 
10508
			#取得合併好的參數陣列
10509
			$result["content"]=$mergeArray["content"];
10510
 
10511
			#更新參數的數量
10512
			$result["count"]=count($result["content"]);
10513
 
10514
			}#if end
10515
 
10516
		#設置執行正常
10517
		$result["status"]="true";
10518
 
10519
		#如果要印出內容
10520
		if($conf["echo"]==="true"){
10521
 
10522
			#針對每個參數
10523
			foreach($result["content"] as $param){
10524
 
10525
				#印出來並換行
10526
				echo $param.PHP_EOL;
10527
 
10528
				}#foreach end
10529
 
10530
			}#if end
10531
 
10532
		#反之
10533
		else{
10534
 
10535
			#回傳結果
10536
			return $result;
10537
 
10538
			}#else end
10539
 
10540
		}#function getArgu end
10541
 
10542
	/*
10543
	#函式說明:
10544
	#解析參數.
10545
	#回傳結果:
10546
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10547
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
10548
	#$result["function"],當前執行的函式名稱.
10549
	#$result["content"],解析好的參數陣列.
10550
	#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
10551
	#$result["program"],字串,執行的程式名稱.
10552
	#必填參數:
10553
	#無.
10554
	#可省略參數:
10555
	#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
10556
	#$conf["helpFunc"]="help";
10557
	#$conf["parseFormVar"],解析表單變數(get\post),預設為"false"不使用;反之設置為"true".
10558
	#$conf["parseFormVar"]="false";
10559
	#參考資料:
10560
	#無.
10561
	#備註:
10562
	#僅能在命令列底下執行.
10563
	#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
10564
	*/
10565
	public static function parseArgu(&$conf){
10566
 
10567
		#初始化要回傳的結果
10568
		$result=array();
10569
 
10570
		#取得當前執行的函式名稱
10571
		$result["function"]=__FUNCTION__;
10572
 
10573
		#函式說明:
10574
		#判斷當前環境為web還是cmd
10575
		#回傳結果:
10576
		#$result,"web"或"cmd"
10577
		if(csInformation::getEnv()=="web"){
10578
 
10579
			#設置執行失敗
10580
			$result["status"]="false";
10581
 
10582
			#設置執行錯誤訊息
10583
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
10584
 
10585
			#回傳結果
10586
			return $result;
10587
 
10588
			}#if end
10589
 
10590
		#取得參數
10591
		$result["argu"]=$conf;
10592
 
10593
		#如果 $conf 不為陣列
10594
		if(gettype($conf)!=="array"){
10595
 
10596
			#設置執行失敗
10597
			$result["status"]="false";
10598
 
10599
			#設置執行錯誤訊息
10600
			$result["error"][]="\$conf變數須為陣列形態";
10601
 
10602
			#如果傳入的參數為 null
10603
			if($conf===null){
10604
 
10605
				#設置執行錯誤訊息
10606
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
10607
 
10608
				}#if end
10609
 
10610
			#回傳結果
10611
			return $result;
10612
 
10613
			}#if end
10614
 
10615
		#檢查參數
10616
		#函式說明:
10617
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
10618
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10619
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10620
		#$result["function"],當前執行的函式名稱.
10621
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10622
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10623
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10624
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
10625
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
10626
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10627
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10628
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10629
		#必填寫的參數:
10630
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10631
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10632
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10633
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10634
		#可以省略的參數:
10635
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10636
		#$conf["mustBeFilledVariableName"]=array();
10637
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
10638
		#$conf["mustBeFilledVariableType"]=array();
10639
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
10640
		#$conf["canBeEmptyString"]="false";
10641
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
10642
		#$conf["canNotBeEmpty"]=array();
10643
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
10644
		#$conf["canBeEmpty"]=array();
10645
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
10646
		#$conf["skipableVariableCanNotBeEmpty"]=array();
10647
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10648
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("helpFunc","parseFormVar");
10649
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
10650
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
10651
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10652
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false");
10653
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
10654
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
10655
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
10656
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
10657
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10658
		#$conf["arrayCountEqualCheck"][]=array();
10659
		#參考資料來源:
10660
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10661
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10662
		unset($conf["variableCheck::checkArguments"]);
10663
 
10664
		#若執行失敗
10665
		if($checkArguments["status"]==="false"){
10666
 
10667
			#設置執行失敗
10668
			$result["status"]="false";
10669
 
10670
			#設置執行錯誤訊息
10671
			$result["error"]=$checkArguments;
10672
 
10673
			#回傳結果
10674
			return $result;
10675
 
10676
			}#if end
10677
 
10678
		#若檢查不通過
10679
		if($checkArguments["passed"]==="false"){
10680
 
10681
			#設置執行失敗
10682
			$result["status"]="false";
10683
 
10684
			#設置執行錯誤訊息
10685
			$result["error"]=$checkArguments;
10686
 
10687
			#回傳結果
10688
			return $result;
10689
 
10690
			}#if end
10691
 
10692
		#函式說明:
10693
		#抓取命令列的參數.
10694
		#回傳結果:
10695
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10696
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10697
		#$result["function"],當前執行的函式名稱.
10698
		#$result["argu"],使用的參數陣列.
10699
		#$result["content"],要回傳的參數陣列.
10700
		#$result["count"],參數的數量.
10701
		#必填參數:
10702
		#無
10703
		#可省略參數:
10704
		#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
10705
		#$conf["echo"]="false";
10706
		$conf["cmd::getArgu"]=array();
10707
 
10708
		#如果要解析表單變數
10709
		if($conf["parseFormVar"]==="true"){
10710
 
10711
			#$conf["httpGetToArgu"],字串,"true"代表要將 http get 參數變成參數來取得,像是 $_GET["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.
10712
			$conf["cmd::getArgu"]["httpGetToArgu"]="true";
10713
			#$conf["httpPostToArgu"],字串,"true"代表要將 http post 參數變成參數來取得,像是 $_POST["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.
10714
			$conf["cmd::getArgu"]["httpPostToArgu"]="true";
10715
 
10716
			}#if end
10717
 
10718
		$getArgu=cmd::getArgu($conf["cmd::getArgu"]);
10719
		unset($conf["cmd::getArgu"]);
10720
 
10721
		#如果解析失敗
10722
		if($getArgu["status"]==="false"){
10723
 
10724
			#設置執行失敗
10725
			$result["status"]="false";
10726
 
10727
			#設置執行錯誤訊息
10728
			$result["error"]=$getArgu;
10729
 
10730
			#回傳結果
10731
			return $result;
10732
 
10733
			}#if end
10734
 
10735
		#若參數若不成對
10736
		if($getArgu["count"]%2===0){
10737
 
10738
			#如果有設置 help function
10739
			if(isset($conf["helpFunc"])){
10740
 
10741
				#若help函式是可以呼叫的
10742
				if(is_callable("\qbpwcf\\".$conf["helpFunc"])){
10743
 
10744
					#呼叫之
10745
					call_user_func("\qbpwcf\\".$conf["helpFunc"]);
10746
 
10747
					}#if end
10748
 
10749
				}#if end
10750
 
10751
			#設置執行失敗
10752
			$result["status"]="false";
10753
 
10754
			#設置執行錯誤訊息
10755
			$result["error"]=$getArgu;
10756
 
10757
			#設置執行錯誤訊息
10758
			$result["error"][]="參數不成對";
10759
 
10760
			#回傳結果
10761
			return $result;
10762
 
10763
			}#if end
10764
 
10765
		#取得執行的程式名稱
10766
		$result["program"]=$getArgu["content"][0];
10767
 
10768
		#移除第一個參數
10769
		unset($getArgu["content"][0]);
10770
 
10771
		#初始化抓到的參數
10772
		$result["content"]=array();
10773
 
10774
		#針對每個參數
10775
		for($i=1;$i<$getArgu["count"]-1;$i=$i+2){
10776
 
10777
			#如果不是 "-" 開頭的參數名稱
10778
			if(strpos($getArgu["content"][$i],"-")!==0){
10779
 
10780
				#設置執行失敗
10781
				$result["status"]="false";
10782
 
10783
				#設置執行錯誤訊息
10784
				$result["error"]=$getArgu;
10785
 
10786
				#設置執行錯誤訊息
10787
				$result["error"][]="參數名稱 \"".$getArgu["content"][$i]."\" 必須為 \"-\" 開頭";
10788
 
10789
				#回傳結果
10790
				return $result;
10791
 
10792
				}#if end
10793
 
10794
			#函式說明:
10795
			#移除字串開頭的特定內容
10796
			#回傳的接結果:
10797
			#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
10798
			#$result["error"],錯誤訊息陣列.
10799
			#$result["function"],當前執行的函式.
10800
			#$result["content"],處理好的字串.
10801
			#必填參數:
10802
			#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
10803
			$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$getArgu["content"][$i];
10804
			#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
10805
			$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]="-";
10806
			#可省略參數:
10807
			#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
10808
			$conf["stringProcess::delKeyWordsInStrHead"]["recursive"]="true";
10809
			$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
10810
			unset($conf["stringProcess::delKeyWordsInStrHead"]);
10811
 
10812
			#如果處理字串失敗
10813
			if($delKeyWordsInStrHead["status"]==="false"){
10814
 
10815
				#設置執行失敗
10816
				$result["status"]="false";
10817
 
10818
				#設置執行錯誤訊息
10819
				$result["error"]=$getArgu;
10820
 
10821
				#設置執行錯誤訊息
10822
				$result["error"][]="處理參數 \"".$getArgu["content"][$i]."\" 失敗";
10823
 
10824
				#回傳結果
10825
				return $result;
10826
 
10827
				}#if end
10828
 
10829
			#取得參數名稱
10830
			$paramName=$delKeyWordsInStrHead["content"];
10831
 
10832
			#如果下一個參數不存在
10833
			if(!isset($getArgu["content"][$i+1])){
10834
 
10835
				#設置執行失敗
10836
				$result["status"]="false";
10837
 
10838
				#設置執行錯誤訊息
10839
				$result["error"]=$getArgu;
10840
 
10841
				#設置執行錯誤訊息
10842
				$result["error"][]="參數 \"".$getArgu["content"][$i]."\" 對應的數值不存在";
10843
 
10844
				#回傳結果
10845
				return $result;
10846
 
10847
				}#if end
10848
 
10849
			#設置參數的數值
10850
			$result["content"][$paramName][]=$getArgu["content"][$i+1];
10851
 
10852
			}#foreach end
10853
 
10854
		#設置執行正常
10855
		$result["status"]="true";
10856
 
10857
		#回傳結果
10858
		return $result;
10859
 
10860
		}#function parseArgu end
10861
 
10862
	/*
10863
	#函式說明:
10864
	#將指令字串解析成陣列,方便給予 external::callShell 使用 
10865
	#回傳結果:
10866
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10867
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
10868
	#$result["function"],當前執行的函式名稱.
10869
	#$result["content"],解析好的指令陣列.
10870
	#$result["cmd"],解析好的指令名稱.
10871
	#$result["argus"],解析好的參數陣列.
10872
	#$result["argu"],所使用的參數.
10873
	#必填參數
10874
	#$conf["cmdStr"],字串,要解析的指令字串
10875
	$conf["cmdStr"]="";
10876
	#可省略參數:
10877
	#無.
10878
	#參考資料:
10879
	#無.
10880
	#備註:
10881
	#無.
10882
	*/
10883
	public static function parseCmdString(&$conf){
10884
 
10885
		#初始化要回傳的結果
10886
		$result=array();
10887
 
10888
		#取得當前執行的函式名稱
10889
		$result["function"]=__FUNCTION__;
10890
 
10891
		#如果沒有參數
10892
		if(func_num_args()==0){
10893
 
10894
			#設置執行失敗
10895
			$result["status"]="false";
10896
 
10897
			#設置執行錯誤訊息
10898
			$result["error"]="函式".$result["function"]."需要參數";
10899
 
10900
			#回傳結果
10901
			return $result;
10902
 
10903
			}#if end
10904
 
10905
		#取得參數
10906
		$result["argu"]=$conf;
10907
 
10908
		#如果 $conf 不為陣列
10909
		if(gettype($conf)!=="array"){
10910
 
10911
			#設置執行失敗
10912
			$result["status"]="false";
10913
 
10914
			#設置執行錯誤訊息
10915
			$result["error"][]="\$conf變數須為陣列形態";
10916
 
10917
			#如果傳入的參數為 null
10918
			if($conf===null){
10919
 
10920
				#設置執行錯誤訊息
10921
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
10922
 
10923
				}#if end
10924
 
10925
			#回傳結果
10926
			return $result;
10927
 
10928
			}#if end
10929
 
10930
		#檢查參數
10931
		#函式說明:
10932
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
10933
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10934
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10935
		#$result["function"],當前執行的函式名稱.
10936
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10937
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10938
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10939
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
10940
		#必填寫的參數:
10941
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10942
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10943
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10944
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmdStr");
10945
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
10946
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
10947
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10948
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10949
		#可以省略的參數:
10950
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
10951
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
10952
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10953
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","port","title","fullScreen","spicePassword");
10954
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
10955
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
10956
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10957
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,"false",null);
10958
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10959
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
10960
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10961
		unset($conf["variableCheck::checkArguments"]);
10962
 
10963
		#如果檢查參數失敗
10964
		if($checkResult["status"]=="false"){
10965
 
10966
			#設置執行失敗
10967
			$result["status"]="false";
10968
 
10969
			#設置執行錯誤
10970
			$result["error"]=$checkResult;
10971
 
10972
			#回傳結果
10973
			return $result;
10974
 
10975
			}#if end
10976
 
10977
		#如果檢查參數不通過
10978
		if($checkResult["passed"]=="false"){
10979
 
10980
			#設置執行失敗
10981
			$result["status"]="false";
10982
 
10983
			#設置執行錯誤
10984
			$result["error"]=$checkResult;
10985
 
10986
			#回傳結果
10987
			return $result;
10988
 
10989
			}#if end
10990
 
10991
		#函式說明:
10992
		#呼叫shell執行系統命令,並取得回傳的內容.
10993
		#回傳結果:
10994
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10995
		#$result["error"],錯誤訊息陣列.
10996
		#$result["function"],當前執行的函數名稱.
10997
		#$result["argu"],使用的參數.
10998
		#$result["cmd"],執行的指令內容.
10999
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11000
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11001
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11002
		#$result["running"],是否還在執行.
11003
		#$result["pid"],pid.
11004
		#$result["statusCode"],執行結束後的代碼.
11005
		#必填參數:
11006
		#$conf["command"],字串,要執行的指令.
11007
		$conf["external::callShell"]["command"]=escapeshellarg(pathinfo(__FILE__)["dirname"])."/../../bin/parse";
11008
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11009
		$conf["external::callShell"]["fileArgu"]=__FILE__;
11010
		#可省略參數:
11011
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11012
		$conf["external::callShell"]["argu"]=array($conf["cmdStr"]);
11013
		#$conf["external::callShell"]["argu"]=array("`cat",$createTempFile["content"]."`","parse","\${params}");
11014
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11015
		#$conf["arguIsAddr"]=array();
11016
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
11017
		#$conf["plainArgu"]=array();
11018
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
11019
		#$conf["useApostrophe"]=array();
11020
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11021
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11022
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11023
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11024
		#$conf["enablePrintDescription"]="true";
11025
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11026
		#$conf["printDescription"]=-"";
11027
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11028
		#$conf["external::callShell"]["escapeshellarg"]="true";
11029
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11030
		#$conf["thereIsShellVar"]=array();
11031
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11032
		#$conf["username"]="";
11033
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11034
		#$conf["password"]="";
11035
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11036
		#$conf["useScript"]="";
11037
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11038
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11039
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11040
		#$conf["inBackGround"]="";
11041
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11042
		#$conf["getErr"]="false";
11043
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11044
		#$conf["doNotRun"]="false";
11045
		#參考資料:
11046
		#exec=>http://php.net/manual/en/function.exec.php
11047
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11048
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11049
		#備註:
11050
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11051
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11052
		$callShell=external::callShell($conf["external::callShell"]);
11053
		unset($conf["external::callShell"]);
11054
 
11055
		#debug
11056
		#var_dump(__FUNCTION__,__LINE__,$callShell);
11057
 
11058
		#如果執行失敗
11059
		if($callShell["status"]==="false"){
11060
 
11061
			#設置執行失敗
11062
			$result["status"]="false";
11063
 
11064
			#設置錯誤訊息
11065
			$result["error"]=$callShell;
11066
 
11067
			#回傳結果
11068
			return $result;
11069
 
11070
			}#if end
11071
 
11072
		#設置執行正常
11073
		$result["status"]="true";
11074
 
11075
		#初始化解析得到的參數
11076
		$result["argus"]=array();
11077
 
11078
		#如果有輸出
11079
		if(isset($callShell["output"][0])){
11080
 
11081
			#如果輸出非 json
11082
			if(json_validate($callShell["output"][0])===false){
11083
 
11084
				#設置執行失敗
11085
				$result["status"]="false";
11086
 
11087
				#設置錯誤訊息
11088
				$result["error"]=$callShell;
11089
 
11090
				#回傳結果
11091
				return $result;
11092
 
11093
				}#if end
11094
 
11095
			#取得解析的結果
11096
			$parseResult=(array)(json_decode($callShell["output"][0]));
11097
 
11098
			}#if end
11099
 
11100
		#針對執行結果輸出的每個元素
11101
		foreach($parseResult as $index=>$str){
11102
 
11103
			#如果是第1個元素
11104
			if($index<1){
11105
 
11106
				#忽略,換下一個元素
11107
				continue;
11108
 
11109
				}#if end`
11110
 
11111
			#如果是第2個元素
11112
			if($index===1){
11113
 
11114
				#設置為解析成的指令
11115
				$result["cmd"]=$str;
11116
 
11117
				#設置為解析成連續的字串之一
11118
				$result["content"][]=$str;
11119
 
11120
				#下一個元素
11121
				continue;
11122
 
11123
				}#if end
11124
 
11125
			#取得參數
11126
			$result["argus"][]=$str;
11127
 
11128
			#設置為解析成連續的字串之一
11129
			$result["content"][]=$str;
11130
 
11131
			}#foreach end
11132
 
11133
		#回傳結果
11134
		return $result;
11135
 
11136
		}#function parseCmdString end
11137
 
11138
	/*
11139
	#函式說明:
11140
	#搜尋特定目錄底下或檔案是否有關鍵字存在,其行數為何.
11141
	#回傳結果:
11142
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11143
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
11144
	#$result["function"],當前執行的函式名稱.
11145
	#$result["argu"],所使用的參數.
11146
	#$result["folder"],搜尋的目標是否為資料夾,"true"為是;"false"為否.
11147
	#$result["content"],符合的列數與內容.
11148
	#$result["content"][$i]["AD"],關鍵字是在哪個檔案裡面.
11149
	#$result["content"][$i]["LN"],第$i+1個符合條件的列數.
11150
	#$result["content"][$i]["LC"],第$i+1個符合條件的列內容.
11151
	#必填參數
11152
	#$conf["target"],字串,要搜尋的路徑或檔案名稱.
11153
	$conf["target"]="";
11154
	#$conf["fileArgu"],字串,__FILE__的內容.
11155
	$conf["fileArgu"]=__FILE__;
11156
	#$conf["keyWord"],字串,關鍵字.
11157
	$conf["keyWord"]="";
11158
	#可省略參數:
11159
	#無.
11160
	#參考資料:
11161
	#無.
11162
	#備註:
11163
	#無.
11164
	*/
11165
	public static function searchFileContent(&$conf=array()){
11166
 
11167
		#初始化要回傳的結果
11168
		$result=array();
11169
 
11170
		#取得當前執行的函式名稱
11171
		$result["function"]=__FUNCTION__;
11172
 
11173
		#如果沒有參數
11174
		if(func_num_args()==0){
11175
 
11176
			#設置執行失敗
11177
			$result["status"]="false";
11178
 
11179
			#設置執行錯誤訊息
11180
			$result["error"]="函式".$result["function"]."需要參數";
11181
 
11182
			#回傳結果
11183
			return $result;
11184
 
11185
			}#if end
11186
 
11187
		#函式說明:
11188
		#判斷當前環境為web還是cmd
11189
		#回傳結果:
11190
		#$result,"web"或"cmd"
11191
		if(csInformation::getEnv()==="web"){
11192
 
11193
			#設置執行失敗
11194
			$result["status"]="false";
11195
 
11196
			#設置執行錯誤訊息
11197
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
11198
 
11199
			#回傳結果
11200
			return $result;
11201
 
11202
			}#if end
11203
 
11204
		#取得參數
11205
		$result["argu"]=$conf;
11206
 
11207
		#如果 $conf 不為陣列
11208
		if(gettype($conf)!=="array"){
11209
 
11210
			#設置執行失敗
11211
			$result["status"]="false";
11212
 
11213
			#設置執行錯誤訊息
11214
			$result["error"][]="\$conf變數須為陣列形態";
11215
 
11216
			#如果傳入的參數為 null
11217
			if($conf===null){
11218
 
11219
				#設置執行錯誤訊息
11220
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
11221
 
11222
				}#if end
11223
 
11224
			#回傳結果
11225
			return $result;
11226
 
11227
			}#if end
11228
 
11229
		#檢查參數
11230
		#函式說明:
11231
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
11232
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11233
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11234
		#$result["function"],當前執行的函式名稱.
11235
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11236
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11237
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11238
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
11239
		#必填寫的參數:
11240
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11241
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11242
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11243
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("target","keyWord","fileArgu");
11244
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
11245
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
11246
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11247
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11248
		#可以省略的參數:
11249
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
11250
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11251
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11252
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","port","title","fullScreen","spicePassword");
11253
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
11254
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
11255
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11256
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,"false",null);
11257
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11258
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
11259
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11260
		unset($conf["variableCheck::checkArguments"]);
11261
 
11262
		#如果檢查參數失敗
11263
		if($checkResult["status"]=="false"){
11264
 
11265
			#設置執行失敗
11266
			$result["status"]="false";
11267
 
11268
			#設置執行錯誤
11269
			$result["error"]=$checkResult;
11270
 
11271
			#回傳結果
11272
			return $result;
11273
 
11274
			}#if end
11275
 
11276
		#如果檢查參數不通過
11277
		if($checkResult["passed"]=="false"){
11278
 
11279
			#設置執行失敗
11280
			$result["status"]="false";
11281
 
11282
			#設置執行錯誤
11283
			$result["error"]=$checkResult;
11284
 
11285
			#回傳結果
11286
			return $result;
11287
 
11288
			}#if end
11289
 
11290
		#轉換檔案路徑為相對於當前位置的路徑
11291
		#函式說明:
11292
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
11293
		#回傳結果:
11294
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
11295
		#$result["error"],錯誤訊息陣列.
11296
		#$result["function"],函式名稱.
11297
		#$result["content"],網址,若是在命令列執行,則為"null".
11298
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
11299
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
11300
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
11301
		#必填參數:
11302
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
11303
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["target"];
11304
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
11305
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
11306
		#可省略參數:
11307
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
11308
		#$conf["userDir"]="true";
11309
		#備註:
11310
		#在命令列執行,所得的路徑是錯誤的。
11311
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
11312
		unset($conf["fileAccess::getInternetAddress"]);
11313
 
11314
		#如果解析檔案位置失敗
11315
		if($getInternetAddress["status"]==="false"){
11316
 
11317
			#設置執行失敗
11318
			$result["status"]="false";
11319
 
11320
			#設置執行錯誤
11321
			$result["error"]=$getInternetAddress;
11322
 
11323
			#回傳結果
11324
			return $result;
11325
 
11326
			}#if end
11327
 
11328
		#取得檔案的相對位置
11329
		$fileRelativeAddr=$getInternetAddress["fileSystemRelativePosition"];
11330
 
11331
		#取得檔案的絕對位置
11332
		$fileAbsolute=$getInternetAddress["fileSystemAbsoulutePosition"];
11333
 
11334
		#函式說明:
11335
		#呼叫shell執行系統命令,並取得回傳的內容.
11336
		#回傳的結果:
11337
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11338
		#$result["error"],錯誤訊息陣列.
11339
		#$result["function"],當前執行的函式名稱.
11340
		#$result["cmd"],執行的指令內容.
11341
		#$result["output"],爲執行完二元碼後的輸出陣列.
11342
		#$result["pid"],pid
11343
		#必填參數
11344
		#$conf["command"],字串,要執行的指令與.
11345
		#$conf["external::callShell"]["command"]="grep -asnr \"".$conf["keyWord"]."\" \"".$conf["target"]."\"";
11346
		$conf["external::callShell"]["command"]="grep";
11347
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11348
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
11349
		#可省略參數:
11350
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11351
		$conf["external::callShell"]["argu"]=array("-asnr",$conf["keyWord"],$fileRelativeAddr);
11352
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11353
		#$conf["arguIsAddr"]=array();
11354
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11355
		$conf["external::callShell"]["enablePrintDescription"]="true";
11356
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
11357
		#$conf["printDescription"]="";
11358
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
11359
		#$conf["escapeshellarg"]="false";
11360
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11361
		#$conf["username"]="";
11362
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11363
		#$conf["password"]="";
11364
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11365
		#$conf["useScript"]="";
11366
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11367
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11368
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11369
		#$conf["inBackGround"]="";
11370
		#備註:
11371
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11372
		#參考資料:
11373
		#exec=>http://php.net/manual/en/function.exec.php
11374
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11375
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11376
		$callShell=external::callShell($conf["external::callShell"]);
11377
		unset($conf["external::callShell"]);
11378
 
11379
		#如果執行cmd失敗
11380
		if($callShell["status"]==="false"){
11381
 
11382
			#設置執行失敗
11383
			$result["status"]="false";
11384
 
11385
			#設置執行錯誤
11386
			$result["error"]=$callShell;
11387
 
11388
			#回傳結果
11389
			return $result;
11390
 
11391
			}#if end
11392
 
11393
		#取得搜尋結果
11394
		$output=$callShell["output"];
11395
 
11396
		#判斷是檔案還是目錄
11397
		$folder=is_dir($fileRelativeAddr);
11398
 
11399
		#記錄搜尋的目標是檔案
11400
		$result["folder"]=$folder;
11401
 
11402
		#如果是檔案
11403
		if(!$folder){
11404
 
11405
			#針對每行結果
11406
			foreach($output as $LC){
11407
 
11408
				#用":"分割
11409
				#函式說明:
11410
				#將固定格式的字串分開,並回傳分開的結果。
11411
				#回傳結果:
11412
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11413
				#$result["error"],錯誤訊息陣列
11414
				#$result["function"],當前執行的函式名稱.
11415
				#$result["oriStr"],要分割的原始字串內容
11416
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
11417
				#$result["dataCounts"],爲總共分成幾段
11418
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
11419
				#必填參數:
11420
				$conf["stringProcess::spiltString"]["stringIn"]=$LC;#要處理的字串。
11421
				$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#爲以哪個符號作爲分割
11422
				#可省略參數:
11423
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
11424
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
11425
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
11426
				unset($conf["stringProcess::spiltString"]);
11427
 
11428
				#如果分割字串失敗
11429
				if($spiltString["status"]==="false"){
11430
 
11431
					#設置執行失敗
11432
					$result["status"]="false";
11433
 
11434
					#設置執行錯誤
11435
					$result["error"]=$spiltString;
11436
 
11437
					#回傳結果
11438
					return $result;
11439
 
11440
					}#if end
11441
 
11442
				#如果沒有分割用的關鍵字
11443
				if($spiltString["found"]==="false"){
11444
 
11445
					#設置執行失敗
11446
					$result["status"]="false";
11447
 
11448
					#設置執行錯誤
11449
					$result["error"]=$spiltString;
11450
 
11451
					#回傳結果
11452
					return $result;
11453
 
11454
					}#if end
11455
 
11456
				#記錄該行行數
11457
				$lineN=$spiltString["dataArray"][0];
11458
 
11459
				#解析內容
11460
				#函式說明:
11461
				#將字串特定關鍵字與其前面的內容剔除
11462
				#回傳結果:
11463
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11464
				#$result["error"],錯誤訊息陣列.
11465
				#$result["warning"],警告訊息鎮列.
11466
				#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11467
				#$result["function"],當前執行的函式名稱.
11468
				#$result["oriStr"],要處理的原始字串內容.
11469
				#$result["content"],處理好的的字串內容.
11470
				#必填參數:
11471
				$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$LC;#要處理的字串.
11472
				$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$lineN.":";#特定字串.
11473
				$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
11474
				unset($conf["stringProcess::delStrBeforeKeyWord"]);
11475
 
11476
				#如果處理字串失敗
11477
				if($delStrBeforeKeyWord["status"]==="false"){
11478
 
11479
					#設置執行失敗
11480
					$result["status"]="false";
11481
 
11482
					#設置執行錯誤
11483
					$result["error"]=$delStrBeforeKeyWord;
11484
 
11485
					#回傳結果
11486
					return $result;
11487
 
11488
					}#if end
11489
 
11490
				#如果關鍵字找不到
11491
				if($delStrBeforeKeyWord["founded"]==="false"){
11492
 
11493
					#設置執行失敗
11494
					$result["status"]="false";
11495
 
11496
					#設置執行錯誤
11497
					$result["error"]=$delStrBeforeKeyWord;
11498
 
11499
					#回傳結果
11500
					return $result;
11501
 
11502
					}#if end
11503
 
11504
				#記錄該行內容
11505
				$lineContent=$delStrBeforeKeyWord["content"];
11506
 
11507
				#記錄搜尋到的內容
11508
				$result["content"][]=array("LN"=>$lineN,"LC"=>$lineContent);
11509
 
11510
				}#foreach end
11511
 
11512
			}#if end
11513
 
11514
		#反之是目錄
11515
		else{
11516
 
11517
			#針對每行結果
11518
			foreach($output as $LC){
11519
 
11520
				#用":"分割
11521
				#函式說明:
11522
				#將固定格式的字串分開,並回傳分開的結果。
11523
				#回傳結果:
11524
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11525
				#$result["error"],錯誤訊息陣列
11526
				#$result["function"],當前執行的函式名稱.
11527
				#$result["oriStr"],要分割的原始字串內容
11528
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
11529
				#$result["dataCounts"],爲總共分成幾段
11530
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
11531
				#必填參數:
11532
				$conf["stringProcess::spiltString"]["stringIn"]=$LC;#要處理的字串。
11533
				$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#爲以哪個符號作爲分割
11534
				#可省略參數:
11535
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
11536
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
11537
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
11538
				unset($conf["stringProcess::spiltString"]);
11539
 
11540
				#如果分割字串失敗
11541
				if($spiltString["status"]==="false"){
11542
 
11543
					#設置執行失敗
11544
					$result["status"]="false";
11545
 
11546
					#設置執行錯誤
11547
					$result["error"]=$spiltString;
11548
 
11549
					#回傳結果
11550
					return $result;
11551
 
11552
					}#if end
11553
 
11554
				#如果沒有分割用的關鍵字
11555
				if($spiltString["found"]==="false"){
11556
 
11557
					#如果開頭有 "Binary file "
11558
					#函式說明:
11559
					#取得符合特定字首與字尾的字串
11560
					#回傳的結果:
11561
					#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
11562
					#$result["function"],當前執行的函式名稱.
11563
					#$result["error"],錯誤訊息陣列.
11564
					#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
11565
					#$result["returnString"],爲符合字首條件的字串內容。
11566
					#必填參數:
11567
					#$conf["checkString"],字串,要檢查的字串.
11568
					$conf["search::getMeetConditionsString"]["checkString"]=$LC;
11569
					#可省略參數:
11570
					#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
11571
					$conf["search::getMeetConditionsString"]["frontWord"]="Binary file ";
11572
					#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
11573
					$conf["tailWord"]=" matches";
11574
					#參考資料:
11575
					#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
11576
					$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
11577
					unset($conf["search::getMeetConditionsString"]);
11578
 
11579
					#如果找關鍵字失敗
11580
					if($getMeetConditionsString["status"]==="false"){
11581
 
11582
						#設置執行失敗
11583
						$result["status"]="false";
11584
 
11585
						#設置執行錯誤
11586
						$result["error"]=$getMeetConditionsString;
11587
 
11588
						#回傳結果
11589
						return $result;
11590
 
11591
						}#if end
11592
 
11593
					#如果找不到關鍵字
11594
					if($getMeetConditionsString["founded"]==="false"){
11595
 
11596
						#設置執行失敗
11597
						$result["status"]="false";
11598
 
11599
						#設置執行錯誤
11600
						$result["error"]=$getMeetConditionsString;
11601
 
11602
						#回傳結果
11603
						return $result;
11604
 
11605
						}#if end
11606
 
11607
					#忽略該筆紀錄
11608
					continue;
11609
 
11610
					}#if end
11611
 
11612
				#記錄該行所屬檔案路徑與名稱
11613
				$fileAddr=$spiltString["dataArray"][0];
11614
 
11615
				#記錄該行行數
11616
				$lineN=$spiltString["dataArray"][1];
11617
 
11618
				#解析內容
11619
				#函式說明:
11620
				#將字串特定關鍵字與其前面的內容剔除
11621
				#回傳結果:
11622
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11623
				#$result["error"],錯誤訊息陣列.
11624
				#$result["warning"],警告訊息鎮列.
11625
				#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11626
				#$result["function"],當前執行的函式名稱.
11627
				#$result["oriStr"],要處理的原始字串內容.
11628
				#$result["content"],處理好的的字串內容.
11629
				#必填參數:
11630
				$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$LC;#要處理的字串.
11631
				$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$fileAddr.":".$lineN.":";#特定字串.
11632
				$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
11633
				unset($conf["stringProcess::delStrBeforeKeyWord"]);
11634
 
11635
				#如果處理字串失敗
11636
				if($delStrBeforeKeyWord["status"]==="false"){
11637
 
11638
					#設置執行失敗
11639
					$result["status"]="false";
11640
 
11641
					#設置執行錯誤
11642
					$result["error"]=$delStrBeforeKeyWord;
11643
 
11644
					#回傳結果
11645
					return $result;
11646
 
11647
					}#if end
11648
 
11649
				#如果關鍵字找不到
11650
				if($delStrBeforeKeyWord["founded"]==="false"){
11651
 
11652
					#設置執行失敗
11653
					$result["status"]="false";
11654
 
11655
					#設置執行錯誤
11656
					$result["error"]=$delStrBeforeKeyWord;
11657
 
11658
					#回傳結果
11659
					return $result;
11660
 
11661
					}#if end
11662
 
11663
				#記錄該行內容
11664
				$lineContent=$delStrBeforeKeyWord["content"];
11665
 
11666
				#記錄搜尋到的內容
11667
				$result["content"][]=array("AD"=>$fileAddr,"LN"=>$lineN,"LC"=>$lineContent);
11668
 
11669
				}#foreach end
11670
 
11671
			}#else end
11672
 
11673
		#設置執行正常
11674
		$result["status"]="true";
11675
 
11676
		#回傳結果
11677
		return $result;
11678
 
11679
		}#function searchFileContent end
11680
 
11681
	/*
11682
	#函式說明:
11683
	#透過"df -h"取得伺服器上的磁碟空間用量
11684
	#回傳結果
11685
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11686
	#$result["error"],錯誤訊息陣列.
11687
	#$result["function"],當前執行的函式名稱.
11688
	#$result["argu"],使用的參數
11689
	#$result["content"],磁碟空間用量.
11690
	#$result["oriOutput"],原始輸出的逐行內容.
11691
	#必填參數:
11692
	#$conf["fileArgu"],字串,__FILE__的內容.
11693
	$conf["fileArgu"]=__FILE__;
11694
	#可省略參數:
11695
	#無.
11696
	#參考資料:
11697
	#無.
11698
	#備註:
11699
	#無.
11700
	*/
11701
	public static function getStorageUsage(&$conf=array()){
11702
 
11703
		#初始化要回傳的結果
11704
		$result=array();
11705
 
11706
		#取得當前執行的函式名稱
11707
		$result["function"]=__FUNCTION__;
11708
 
11709
		#如果沒有參數
11710
		if(func_num_args()==0){
11711
 
11712
			#設置執行失敗
11713
			$result["status"]="false";
11714
 
11715
			#設置執行錯誤訊息
11716
			$result["error"]="函式".$result["function"]."需要參數";
11717
 
11718
			#回傳結果
11719
			return $result;
11720
 
11721
			}#if end
11722
 
11723
		#取得參數
11724
		$result["argu"]=$conf;
11725
 
11726
		#如果 $conf 不為陣列
11727
		if(gettype($conf)!=="array"){
11728
 
11729
			#設置執行失敗
11730
			$result["status"]="false";
11731
 
11732
			#設置執行錯誤訊息
11733
			$result["error"][]="\$conf變數須為陣列形態";
11734
 
11735
			#如果傳入的參數為 null
11736
			if($conf===null){
11737
 
11738
				#設置執行錯誤訊息
11739
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
11740
 
11741
				}#if end
11742
 
11743
			#回傳結果
11744
			return $result;
11745
 
11746
			}#if end
11747
 
11748
		#檢查參數
11749
		#函式說明:
11750
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
11751
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11752
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11753
		#$result["function"],當前執行的函式名稱.
11754
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11755
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11756
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11757
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11758
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11759
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11760
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11761
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11762
		#必填寫的參數:
11763
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11764
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11765
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11766
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
11767
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11768
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
11769
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11770
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11771
		#可以省略的參數:
11772
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11773
		#$conf["canBeEmptyString"]="false";
11774
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11775
		#$conf["canNotBeEmpty"]=array();
11776
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11777
		#$conf["canBeEmpty"]=array();
11778
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11779
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11780
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11781
		#$conf["skipableVariableName"]=array();
11782
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
11783
		#$conf["skipableVariableType"]=array();
11784
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11785
		#$conf["skipableVarDefaultValue"]=array("");
11786
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11787
		#$conf["arrayCountEqualCheck"][]=array();
11788
		#參考資料來源:
11789
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11790
		#建議:
11791
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11792
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11793
		unset($conf["variableCheck::checkArguments"]);
11794
 
11795
		#如果檢查參數失敗
11796
		if($checkArguments["status"]==="false"){
11797
 
11798
			#設置執行失敗
11799
			$result["status"]="false";
11800
 
11801
			#設置執行錯誤
11802
			$result["error"]=$checkArguments;
11803
 
11804
			#回傳結果
11805
			return $result;
11806
 
11807
			}#if end
11808
 
11809
		#如果檢查參數不通過
11810
		if($checkArguments["status"]==="false"){
11811
 
11812
			#設置執行失敗
11813
			$result["status"]="false";
11814
 
11815
			#設置執行錯誤
11816
			$result["error"]=$checkArguments;
11817
 
11818
			#回傳結果
11819
			return $result;
11820
 
11821
			}#if end
11822
 
11823
		#用 "df -h" 取得分割區使用狀況
11824
		#函式說明:
11825
		#呼叫shell執行系統命令,並取得回傳的內容.
11826
		#回傳的結果:
11827
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11828
		#$result["error"],錯誤訊息陣列.
11829
		#$result["function"],當前執行的函式名稱.
11830
		#$result["cmd"],執行的指令內容.
11831
		#$result["output"],爲執行完二元碼後的輸出陣列.
11832
		#$result["pid"],pid
11833
		#必填參數
11834
		#$conf["command"],字串,要執行的指令與.
11835
		$conf["external::callShell"]["command"]="df";
11836
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11837
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
11838
		#可省略參數:
11839
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11840
		$conf["external::callShell"]["argu"]=array("-h");
11841
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11842
		#$conf["arguIsAddr"]=array();
11843
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11844
		#$conf["enablePrintDescription"]="true";
11845
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
11846
		#$conf["printDescription"]="";
11847
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
11848
		$conf["external::callShell"]["escapeshellarg"]="true";
11849
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11850
		#$conf["username"]="";
11851
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11852
		#$conf["password"]="";
11853
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11854
		#$conf["useScript"]="";
11855
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11856
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11857
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11858
		#$conf["inBackGround"]="";
11859
		#備註:
11860
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11861
		#參考資料:
11862
		#exec=>http://php.net/manual/en/function.exec.php
11863
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11864
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11865
		$callShell=external::callShell($conf["external::callShell"]);
11866
		unset($conf["external::callShell"]);
11867
 
11868
		#如果執行失敗
11869
		if($callShell["status"]==="false"){
11870
 
11871
			#設置執行失敗
11872
			$result["status"]="false";
11873
 
11874
			#設置執行錯誤
11875
			$result["error"]=$callShell;
11876
 
11877
			#回傳結果
11878
			return $result;
11879
 
11880
			}#if end
11881
 
11882
		#取的原始的輸出
11883
		$result["oriOutput"]=$callShell["output"];
11884
 
11885
		#針對每個結果
11886
		foreach($callShell["output"] as $lineN=>$dfOutput){
11887
 
11888
			#範例輸出
11889
			/*
11890
			Filesystem               Size  Used Avail Use% Mounted on
11891
			devtmpfs                 1.5G     0  1.5G   0% /dev
11892
			tmpfs                    1.5G  388K  1.5G   1% /dev/shm
11893
			tmpfs                    1.5G  1.6M  1.5G   1% /run
11894
			tmpfs                    1.5G     0  1.5G   0% /sys/fs/cgroup
11895
			/dev/mapper/fedora-root   50G   29G   19G  61% /
11896
			tmpfs                    1.5G  160K  1.5G   1% /tmp
11897
			/dev/vda1                477M  162M  286M  37% /boot
11898
			/dev/mapper/fedora-home   47G  7.5G   37G  17% /home
11899
			tmpfs                    295M   28K  295M   1% /run/user/42
11900
			tmpfs                    295M   18M  278M   6% /run/user/1000
11901
			*/
11902
 
11903
			#如果是標題列
11904
			if($lineN===0){
11905
 
11906
				#分割標題欄位
11907
				#函式說明:
11908
				#將固定格式的字串分開,並回傳分開的結果。
11909
				#回傳結果:
11910
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11911
				#$result["error"],錯誤訊息陣列
11912
				#$result["function"],當前執行的函式名稱.
11913
				#$result["oriStr"],要分割的原始字串內容
11914
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
11915
				#$result["dataCounts"],爲總共分成幾段
11916
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
11917
				#必填參數:
11918
				$conf["stringProcess::spiltString"]["stringIn"]=$dfOutput;#要處理的字串。
11919
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
11920
				#可省略參數:
11921
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
11922
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
11923
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
11924
				unset($conf["stringProcess::spiltString"]);
11925
 
11926
				#如果分割字串失敗
11927
				if($spiltString["status"]==="false"){
11928
 
11929
					#設置執行失敗
11930
					$result["status"]="false";
11931
 
11932
					#設置執行錯誤
11933
					$result["error"]=$callShell;
11934
 
11935
					#回傳結果
11936
					return $result;
11937
 
11938
					}#if end
11939
 
11940
				#如果分割字串失敗
11941
				if($spiltString["found"]==="false"){
11942
 
11943
					#設置執行失敗
11944
					$result["status"]="false";
11945
 
11946
					#設置執行錯誤
11947
					$result["error"]=$callShell;
11948
 
11949
					#回傳結果
11950
					return $result;
11951
 
11952
					}#if end
11953
 
11954
				#針對每個分割好的內容
11955
				for($i=0;$i<$spiltString["dataCounts"];$i++){
11956
 
11957
					#如果後面還有
11958
					if(isset($spiltString["dataArray"][$i+1])){
11959
 
11960
						#如果當前跟後一個是 "Mounted" 跟 "on"
11961
						if($spiltString["dataArray"][$i+1]==="Mounted" && $spiltString["dataArray"][$i+1]==="on"){
11962
 
11963
							#取得 "Mounted on" 標題
11964
							$title[]=$spiltString["dataArray"][$i]." ".$spiltString["dataArray"][$i+1];
11965
 
11966
							#跳出迴圈
11967
							break;
11968
 
11969
							}#if end
11970
 
11971
						}#if end
11972
 
11973
					#取得標題列
11974
					$title[]=$spiltString["dataArray"][$i];
11975
 
11976
					}#for end
11977
 
11978
				}#if end
11979
 
11980
			#反之是內容列
11981
			else{
11982
 
11983
				#函式說明:
11984
				#將固定格式的字串分開,並回傳分開的結果。
11985
				#回傳結果:
11986
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11987
				#$result["error"],錯誤訊息陣列
11988
				#$result["function"],當前執行的函式名稱.
11989
				#$result["oriStr"],要分割的原始字串內容
11990
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
11991
				#$result["dataCounts"],爲總共分成幾段
11992
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
11993
				#必填參數:
11994
				$conf["stringProcess::spiltString"]["stringIn"]=$dfOutput;#要處理的字串。
11995
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
11996
				#可省略參數:
11997
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
11998
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
11999
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
12000
				unset($conf["stringProcess::spiltString"]);
12001
 
12002
				#如果分割字串失敗
12003
				if($spiltString["status"]==="false"){
12004
 
12005
					#設置執行失敗
12006
					$result["status"]="false";
12007
 
12008
					#設置執行錯誤
12009
					$result["error"]=$callShell;
12010
 
12011
					#回傳結果
12012
					return $result;
12013
 
12014
					}#if end
12015
 
12016
				#如果分割字串失敗
12017
				if($spiltString["found"]==="false"){
12018
 
12019
					#設置執行失敗
12020
					$result["status"]="false";
12021
 
12022
					#設置執行錯誤
12023
					$result["error"]=$callShell;
12024
 
12025
					#回傳結果
12026
					return $result;
12027
 
12028
					}#if end
12029
 
12030
				#初始化暫存的陣列
12031
				$tempArray=array();
12032
 
12033
				#針對每個分割好的內容
12034
				for($i=0;$i<$spiltString["dataCounts"];$i++){
12035
 
12036
					#加上欄位的內容(用名稱為key)
12037
					$tempArray=$tempArray+array($title[$i]=>$spiltString["dataArray"][$i]);
12038
 
12039
					}#for end
12040
 
12041
				#儲存內容
12042
				$result["content"][]=$tempArray;
12043
 
12044
				}#else end
12045
 
12046
			}#foreach end
12047
 
12048
		#設置執行正常
12049
		$result["status"]="true";
12050
 
12051
		#回傳結果
12052
		return $result;
12053
 
12054
		}#function getStorageUsage end
12055
 
12056
	/*
12057
	#函式說明:
12058
	#檢查與取得net interface的資訊
12059
	#回傳結果
12060
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12061
	#$result["error"],錯誤訊息陣列.
12062
	#$result["function"],當前執行的函式名稱.
12063
	#$result["cmd"],使用的command.
12064
	#$result["argu"],使用的參數.
12065
	#$result["founded"],是否有找到目標網路界面,"true"代表有,"false"代表沒有.
12066
	#$result["content"],原始輸出的逐行內容.
12067
	#必填參數:
12068
	#$conf["netInterface"],字串,網路界面的名稱.
12069
	$conf["netInterface"]="";
12070
	#$conf["fileArgu"],字串,__FILE__的內容.
12071
	$conf["fileArgu"]=__FILE__;
12072
	#可省略參數:
12073
	#無.
12074
	#參考資料:
12075
	#無.
12076
	#備註:
12077
	#無.
12078
	*/
12079
	public static function getNetDevInfo(&$conf=array()){
12080
 
12081
		#初始化要回傳的結果
12082
		$result=array();
12083
 
12084
		#取得當前執行的函式名稱
12085
		$result["function"]=__FUNCTION__;
12086
 
12087
		#如果沒有參數
12088
		if(func_num_args()==0){
12089
 
12090
			#設置執行失敗
12091
			$result["status"]="false";
12092
 
12093
			#設置執行錯誤訊息
12094
			$result["error"]="函式".$result["function"]."需要參數";
12095
 
12096
			#回傳結果
12097
			return $result;
12098
 
12099
			}#if end
12100
 
12101
		#取得參數
12102
		$result["argu"]=$conf;
12103
 
12104
		#如果 $conf 不為陣列
12105
		if(gettype($conf)!=="array"){
12106
 
12107
			#設置執行失敗
12108
			$result["status"]="false";
12109
 
12110
			#設置執行錯誤訊息
12111
			$result["error"][]="\$conf變數須為陣列形態";
12112
 
12113
			#如果傳入的參數為 null
12114
			if($conf===null){
12115
 
12116
				#設置執行錯誤訊息
12117
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
12118
 
12119
				}#if end
12120
 
12121
			#回傳結果
12122
			return $result;
12123
 
12124
			}#if end
12125
 
12126
		#檢查參數
12127
		#函式說明:
12128
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
12129
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12130
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12131
		#$result["function"],當前執行的函式名稱.
12132
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12133
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12134
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12135
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12136
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12137
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12138
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12139
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12140
		#必填寫的參數:
12141
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12142
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12143
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12144
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("netInterface","fileArgu");
12145
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12146
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12147
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12148
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12149
		#可以省略的參數:
12150
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12151
		#$conf["canBeEmptyString"]="false";
12152
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12153
		#$conf["canNotBeEmpty"]=array();
12154
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12155
		#$conf["canBeEmpty"]=array();
12156
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12157
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12158
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12159
		#$conf["skipableVariableName"]=array();
12160
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
12161
		#$conf["skipableVariableType"]=array();
12162
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12163
		#$conf["skipableVarDefaultValue"]=array("");
12164
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12165
		#$conf["arrayCountEqualCheck"][]=array();
12166
		#參考資料來源:
12167
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12168
		#建議:
12169
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
12170
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12171
		unset($conf["variableCheck::checkArguments"]);
12172
 
12173
		#如果檢查參數失敗
12174
		if($checkArguments["status"]==="false"){
12175
 
12176
			#設置執行失敗
12177
			$result["status"]="false";
12178
 
12179
			#設置執行錯誤
12180
			$result["error"]=$checkArguments;
12181
 
12182
			#回傳結果
12183
			return $result;
12184
 
12185
			}#if end
12186
 
12187
		#如果檢查參數不通過
12188
		if($checkArguments["status"]==="false"){
12189
 
12190
			#設置執行失敗
12191
			$result["status"]="false";
12192
 
12193
			#設置執行錯誤
12194
			$result["error"]=$checkArguments;
12195
 
12196
			#回傳結果
12197
			return $result;
12198
 
12199
			}#if end
12200
 
12201
		#函式說明:
12202
		#呼叫shell執行系統命令,並取得回傳的內容.
12203
		#回傳的結果:
12204
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12205
		#$result["error"],錯誤訊息陣列.
12206
		#$result["function"],當前執行的函式名稱.
12207
		#$result["cmd"],執行的指令內容.
12208
		#$result["output"],爲執行完二元碼後的輸出陣列.
12209
		#$result["pid"],pid
12210
		#必填參數
12211
		#$conf["command"],字串,要執行的指令與.
12212
		$conf["external::callShell"]["command"]="ifconfig";
12213
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12214
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12215
		#可省略參數:
12216
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12217
		#$conf["argu"]=array("");
12218
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12219
		#$conf["arguIsAddr"]=array();
12220
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12221
		#$conf["enablePrintDescription"]="true";
12222
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12223
		#$conf["printDescription"]="";
12224
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12225
		$conf["external::callShell"]["escapeshellarg"]="true";
12226
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12227
		#$conf["username"]="";
12228
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12229
		#$conf["password"]="";
12230
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12231
		#$conf["useScript"]="";
12232
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12233
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12234
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12235
		#$conf["inBackGround"]="";
12236
		#備註:
12237
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12238
		#參考資料:
12239
		#exec=>http://php.net/manual/en/function.exec.php
12240
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12241
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12242
		$callShell=external::callShell($conf["external::callShell"]);
12243
		unset($conf["external::callShell"]);
12244
 
12245
		#如果執行cmd失敗
12246
		if($callShell["status"]==="false"){
12247
 
12248
			#設置執行失敗
12249
			$result["status"]="false";
12250
 
12251
			#設置執行錯誤訊息
12252
			$result["error"]=$callShell;
12253
 
12254
			#回傳結果
12255
			return $result;
12256
 
12257
			}#if end
12258
 
12259
		#取得執行的cmd
12260
		$result["cmd"]=$callShell["cmd"];
12261
 
12262
		#取得cmd的輸出
12263
		$result["content"]=$callShell["output"];
12264
 
12265
		#font keyword
12266
		$keyword=$conf["netInterface"].": ";
12267
 
12268
		#函式說明:
12269
		#取得多個符合特定字首與字尾的字串.
12270
		#回傳的結果:
12271
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
12272
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
12273
		#$result["function"],當前執行的函式名稱.
12274
		#$result["returnString"],爲符合字首條件的字串陣列內容。
12275
		#必填參數:
12276
		#$conf["checkString"],陣列字串,要檢查的字串們.
12277
		$conf["search::getMeetConditionsStringMulti"]["checkString"]=$result["content"];#要檢查的字串陣列
12278
		#可省略參數:
12279
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
12280
		$conf["search::getMeetConditionsStringMulti"]["frontWord"]=$keyword;
12281
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
12282
		#$conf["tailWord"]="";
12283
		#參考資料:
12284
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
12285
		$getMeetConditionsStringMulti=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
12286
		unset($conf["search::getMeetConditionsStringMulti"]);
12287
 
12288
		#如果尋找過程出錯
12289
		if($getMeetConditionsStringMulti["status"]==="false"){
12290
 
12291
			#設置執行失敗
12292
			$result["status"]="false";
12293
 
12294
			#設置執行錯誤訊息
12295
			$result["error"]=$getMeetConditionsStringMulti;
12296
 
12297
			#回傳結果
12298
			return $result;
12299
 
12300
			}#if end
12301
 
12302
		#設置查網路界面的結果
12303
		$result["founded"]=$getMeetConditionsStringMulti["founded"];
12304
 
12305
		#設置執行正常
12306
		$result["status"]="true";
12307
 
12308
		#回傳結果
12309
		return $result;
12310
 
12311
		}#function getNetDevInfo end
12312
 
12313
	/*
12314
	#函式說明:
12315
	#檢查當前目錄是否在svn版本之下
12316
	#回傳結果:
12317
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12318
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
12319
	#$result["function"],當前執行的函式名稱.
12320
	#$result["warning"],警告訊息陣列.
12321
	#$result["content"]["issvnworkdir"],當前目錄是否處於svn版本控制之下,"ture"代表是,"false"代表不是.
12322
	#$result["content"]["account"],連線到repo的帳戶.
12323
	#$result["content"]["repo"],連線到的repo.
12324
	#必填參數:
12325
	#$conf["fileArgu"],字串,變數__FILE__的內容.
12326
	$conf["fileArgu"]=__FILE__;
12327
	#可省略參數:
12328
	#無.
12329
	#參考資料:
12330
	#無.
12331
	#備註:
12332
	#無.
12333
	*/
12334
	public static function issvnworkdir(&$conf=array()){
12335
 
12336
		#初始化要回傳的結果
12337
		$result=array();
12338
 
12339
		#取得當前執行的函式名稱
12340
		$result["function"]=__FUNCTION__;
12341
 
12342
		#函式說明:
12343
		#判斷當前環境為web還是cmd
12344
		#回傳結果:
12345
		#$result,"web"或"cmd"
12346
		if(csInformation::getEnv()=="web"){
12347
 
12348
			#設置執行失敗
12349
			$result["status"]="false";
12350
 
12351
			#設置執行錯誤訊息
12352
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
12353
 
12354
			#回傳結果
12355
			return $result;
12356
 
12357
			}#if end
12358
 
12359
		#如果沒有參數
12360
		if(func_num_args()==0){
12361
 
12362
			#設置執行失敗
12363
			$result["status"]="false";
12364
 
12365
			#設置執行錯誤訊息
12366
			$result["error"]="函式".$result["function"]."需要參數";
12367
 
12368
			#回傳結果
12369
			return $result;
12370
 
12371
			}#if end
12372
 
12373
		#取得參數
12374
		$result["argu"]=$conf;
12375
 
12376
		#如果 $conf 不為陣列
12377
		if(gettype($conf)!=="array"){
12378
 
12379
			#設置執行失敗
12380
			$result["status"]="false";
12381
 
12382
			#設置執行錯誤訊息
12383
			$result["error"][]="\$conf變數須為陣列形態";
12384
 
12385
			#如果傳入的參數為 null
12386
			if($conf===null){
12387
 
12388
				#設置執行錯誤訊息
12389
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
12390
 
12391
				}#if end
12392
 
12393
			#回傳結果
12394
			return $result;
12395
 
12396
			}#if end
12397
 
12398
		#檢查參數
12399
		#函式說明:
12400
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
12401
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12402
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12403
		#$result["function"],當前執行的函式名稱.
12404
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12405
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12406
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12407
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12408
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12409
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12410
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12411
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12412
		#必填寫的參數:
12413
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12414
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12415
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12416
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12417
		#可以省略的參數:
12418
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12419
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
12420
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12421
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
12422
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12423
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12424
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12425
		#$conf["canNotBeEmpty"]=array();
12426
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12427
		#$conf["canBeEmpty"]=array();
12428
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12429
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12430
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12431
		#$conf["skipableVariableName"]=array();
12432
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
12433
		#$conf["skipableVariableType"]=array();
12434
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12435
		#$conf["skipableVarDefaultValue"]=array("");
12436
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12437
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12438
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12439
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12440
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12441
		#$conf["arrayCountEqualCheck"][]=array();
12442
		#參考資料來源:
12443
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12444
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12445
		unset($conf["variableCheck::checkArguments"]);
12446
 
12447
		#如果檢查參數失敗
12448
		if($checkArguments["status"]==="false"){
12449
 
12450
			#設置執行失敗
12451
			$result["status"]="false";
12452
 
12453
			#設置錯誤訊息
12454
			$result["error"]=$callShell;
12455
 
12456
			#回傳結果
12457
			return $result;
12458
 
12459
			}#if end
12460
 
12461
		#若檢查參數不通過
12462
		if($checkArguments["passed"]==="false"){
12463
 
12464
			#設置執行失敗
12465
			$result["status"]="false";
12466
 
12467
			#設置錯誤訊息
12468
			$result["error"]=$callShell;
12469
 
12470
			#回傳結果
12471
			return $result;
12472
 
12473
			}#if end
12474
 
12475
		#執行svn info指令
12476
		#函式說明:
12477
		#呼叫shell執行系統命令,並取得回傳的內容.
12478
		#回傳的結果:
12479
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12480
		#$result["error"],錯誤訊息陣列.
12481
		#$result["function"],當前執行的函式名稱.
12482
		#$result["argu"],使用的參數.
12483
		#$result["cmd"],執行的指令內容.
12484
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12485
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12486
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12487
		#$result["running"],是否還在執行.
12488
		#$result["pid"],pid
12489
		#必填參數
12490
		#$conf["command"],字串,要執行的指令與.
12491
		$conf["external::callShell"]["command"]="svn";
12492
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12493
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12494
		#可省略參數:
12495
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12496
		$conf["external::callShell"]["argu"]=array("info");
12497
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12498
		#$conf["arguIsAddr"]=array();
12499
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12500
		#$conf["enablePrintDescription"]="true";
12501
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12502
		#$conf["printDescription"]="";
12503
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12504
		$conf["external::callShell"]["escapeshellarg"]="true";
12505
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12506
		#$conf["username"]="";
12507
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12508
		#$conf["password"]="";
12509
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12510
		#$conf["useScript"]="";
12511
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12512
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12513
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12514
		#$conf["inBackGround"]="";
12515
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
12516
		$conf["external::callShell"]["getErr"]="true";
12517
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
12518
		#$conf["doNotRun"]="false";
12519
		#備註:
12520
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12521
		#參考資料:
12522
		#exec=>http://php.net/manual/en/function.exec.php
12523
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12524
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12525
		$callShell=external::callShell($conf["external::callShell"]);
12526
		unset($conf["external::callShell"]);
12527
 
12528
		#如果執行指令失敗
12529
		if($callShell["status"]==="false"){
12530
 
12531
			#設置執行正常
12532
			$result["status"]="true";
12533
 
12534
			#設置警告訊息
12535
			$result["warning"]=$callShell;
12536
 
12537
			#設置警告訊息
12538
			$result["warning"][]="當前目錄「".$_SERVER["PWD"]."」不是svn工作目錄";
12539
 
12540
			#設置當前目錄不是svn目錄
12541
			$result["content"]["issvnworkdir"]="false";
12542
 
12543
			#回傳結果
12544
			return $result;
12545
 
12546
			}#if end
12547
 
12548
		#從svn的URL找到使用的帳號
12549
		foreach($callShell["output"] as $line){
12550
 
12551
			#如果找到有 "URL: svn+ssh://" 的關鍵字列
12552
			if(strpos($line,'Repository Root: svn+ssh://')!==false){
12553
 
12554
				#取得帳字元結尾位置
12555
				$acTail=strpos($line,'@');
12556
 
12557
				#取得帳號
12558
				$result["content"]["account"]=substr($line,strlen('Repository Root: svn+ssh://'),$acTail-strlen('Repository Root: svn+ssh://'));
12559
 
12560
				#取得svn repo位址
12561
				$result["content"]["repo"]=substr($line,$acTail+1);
12562
 
12563
				#跳出foreach
12564
				break;
12565
 
12566
				}#if ned
12567
 
12568
			}#foreach end
12569
 
12570
		#設置當前目錄是svn目錄
12571
		$result["content"]["issvnworkdir"]="true";
12572
 
12573
		#設置執行正常
12574
		$result["status"]="true";
12575
 
12576
		#回傳結果
12577
		return $result;
12578
 
12579
		}#function issvnworkdir end
12580
 
12581
	/*
12582
	#函式說明:
12583
	#執行svn status指令
12584
	#回傳結果:
12585
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12586
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
12587
	#$result["function"],當前執行的函式名稱.
12588
	#$result["content"]["ori"],指令輸出的原始結果陣列.
12589
	#$result["content"]["status"][$i]["status"],第$i+1個目標的狀態.
12590
	#$result["content"]["status"][$i]["target"],第$i+1個目標的路徑與名稱.
12591
	#$result["content"]["status"][$i]["is_dir"],第$i+1個目標是否為目錄,"true"代表是,"false"代表不是.
12592
	#必填參數:
12593
	#$conf["fileArgu"],字串,變數__FILE__的內容.
12594
	$conf["fileArgu"]=__FILE__;
12595
	#可省略參數:
12596
	#$conf["target"],字串,要檢查status的目標.
12597
	#$conf["target"]="";
12598
	#參考資料:
12599
	#無.
12600
	#備註:
12601
	#範例輸出->svn: warning: W155010: The node '.../usr/lib64' was not found.
12602
	*/
12603
	public static function svnsta(&$conf=array()){
12604
 
12605
		#初始化要回傳的結果
12606
		$result=array();
12607
 
12608
		#取得當前執行的函式名稱
12609
		$result["function"]=__FUNCTION__;
12610
 
12611
		#函式說明:
12612
		#判斷當前環境為web還是cmd
12613
		#回傳結果:
12614
		#$result,"web"或"cmd"
12615
		if(csInformation::getEnv()=="web"){
12616
 
12617
			#設置執行失敗
12618
			$result["status"]="false";
12619
 
12620
			#設置執行錯誤訊息
12621
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
12622
 
12623
			#回傳結果
12624
			return $result;
12625
 
12626
			}#if end
12627
 
12628
		#檢查參數
12629
		#函式說明:
12630
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
12631
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12632
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12633
		#$result["function"],當前執行的函式名稱.
12634
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12635
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12636
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12637
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12638
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12639
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12640
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12641
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12642
		#必填寫的參數:
12643
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12644
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12645
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12646
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12647
		#可以省略的參數:
12648
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12649
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
12650
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12651
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
12652
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12653
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12654
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12655
		#$conf["canNotBeEmpty"]=array();
12656
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12657
		#$conf["canBeEmpty"]=array();
12658
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12659
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("target");
12660
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12661
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("target");
12662
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
12663
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12664
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12665
		#$conf["skipableVarDefaultValue"]=array("");
12666
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12667
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12668
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12669
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12670
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12671
		#$conf["arrayCountEqualCheck"][]=array();
12672
		#參考資料來源:
12673
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12674
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12675
		unset($conf["variableCheck::checkArguments"]);
12676
 
12677
		#如果檢查參數失敗
12678
		if($checkArguments["status"]==="false"){
12679
 
12680
			#設置執行失敗
12681
			$result["status"]="false";
12682
 
12683
			#設置錯誤訊息
12684
			$result["error"]=$checkArguments;
12685
 
12686
			#回傳結果
12687
			return $result;
12688
 
12689
			}#if end
12690
 
12691
		#若檢查參數不通過
12692
		if($checkArguments["passed"]==="false"){
12693
 
12694
			#設置執行失敗
12695
			$result["status"]="false";
12696
 
12697
			#設置錯誤訊息
12698
			$result["error"]=$checkArguments;
12699
 
12700
			#回傳結果
12701
			return $result;
12702
 
12703
			}#if end
12704
 
12705
		#函式說明:
12706
		#檢查當前目錄是否在svn版本之下
12707
		#回傳結果:
12708
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12709
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12710
		#$result["function"],當前執行的函式名稱.
12711
		#$result["warning"],警告訊息陣列.
12712
		#$result["content"]["issvnworkdir"],當前目錄是否處於svn版本控制之下,"ture"代表是,"false"代表不是.
12713
		#$result["content"]["account"],連線到repo的帳戶.
12714
		#$result["content"]["repo"],連線到的repo.
12715
		#必填參數:
12716
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12717
		$conf["cmd::issvnworkdir"]["fileArgu"]=$conf["fileArgu"];
12718
		#可省略參數:
12719
		#無.
12720
		$issvnworkdir=cmd::issvnworkdir($conf["cmd::issvnworkdir"]);
12721
		unset($conf["cmd::issvnworkdir"]);
12722
 
12723
		#如果檢查當前目錄是否在svn版本控制下失敗
12724
		if($issvnworkdir["status"]==="false"){
12725
 
12726
			#設置執行失敗
12727
			$result["status"]="false";
12728
 
12729
			#設置錯誤訊息
12730
			$result["error"]=$issvnworkdir;
12731
 
12732
			#回傳結果
12733
			return $result;
12734
 
12735
			}#if end
12736
 
12737
		#如果當前目錄不是svn工作目錄
12738
		if($issvnworkdir["content"]["issvnworkdir"]==="false"){
12739
 
12740
			#設置執行正常
12741
			$result["status"]="false";
12742
 
12743
			#設置錯誤訊息
12744
			$result["error"]=$issvnworkdir;
12745
 
12746
			#回傳結果
12747
			return $result;
12748
 
12749
			}#if end
12750
 
12751
		#設置要執行的指令
12752
		$cmd="svn";
12753
 
12754
		#初始化給 svn 指令的參數
12755
		$arguForSvn=array("status");
12756
 
12757
		#如果有設置要檢查的目標
12758
		if(isset($conf["target"])){
12759
 
12760
			#加上目標的參數
12761
			$arguForSvn[]=$conf["target"];
12762
 
12763
			}#if end
12764
 
12765
		#執行svn status指令
12766
		#函式說明:
12767
		#呼叫shell執行系統命令,並取得回傳的內容.
12768
		#回傳的結果:
12769
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12770
		#$result["error"],錯誤訊息陣列.
12771
		#$result["function"],當前執行的函式名稱.
12772
		#$result["argu"],使用的參數.
12773
		#$result["cmd"],執行的指令內容.
12774
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12775
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12776
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12777
		#$result["running"],是否還在執行.
12778
		#$result["pid"],pid
12779
		#必填參數
12780
		#$conf["command"],字串,要執行的指令與.
12781
		$conf["external::callShell"]["command"]="svn";
12782
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12783
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12784
		#可省略參數:
12785
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12786
		$conf["external::callShell"]["argu"]=$arguForSvn;
12787
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12788
		#$conf["arguIsAddr"]=array();
12789
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12790
		#$conf["enablePrintDescription"]="true";
12791
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12792
		#$conf["printDescription"]="";
12793
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12794
		$conf["external::callShell"]["escapeshellarg"]="true";
12795
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12796
		#$conf["username"]="";
12797
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12798
		#$conf["password"]="";
12799
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12800
		#$conf["useScript"]="";
12801
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12802
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12803
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12804
		#$conf["inBackGround"]="";
12805
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
12806
		$conf["external::callShell"]["getErr"]="true";
12807
		#備註:
12808
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12809
		#參考資料:
12810
		#exec=>http://php.net/manual/en/function.exec.php
12811
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12812
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12813
		$callShell=external::callShell($conf["external::callShell"]);
12814
		unset($conf["external::callShell"]);
12815
 
12816
		#如果執行指令失敗
12817
		if($callShell["status"]==="false"){
12818
 
12819
			#設置執行正常
12820
			$result["status"]="false";
12821
 
12822
			#設置警告訊息
12823
			$result["error"]=$callShell;
12824
 
12825
			#回傳結果
12826
			return $result;
12827
 
12828
			}#if end
12829
 
12830
		#取得指令輸出的結果
12831
		$result["content"]["ori"]=$callShell["output"];
12832
 
12833
		#如果不等於空陣列
12834
		if($result["content"]["ori"]!==array()){
12835
 
12836
			#未進入版本控制的軟連結到目錄,會出現類似以下警告訊息.
12837
			#svn: warning: W155010: The node '.../usr/lib64' was not found
12838
 
12839
			#如果遇到沒有進入版本控制的軟連結
12840
			if( strpos($result["content"]["ori"][0]," W155010: ")!==false && strpos($result["content"]["ori"][0]," The node ")!==false && strpos($result["content"]["ori"][0]," was not found")!==false ){
12841
 
12842
				#設置該目標的 狀態(status), 路徑與名稱(target), 是否為目錄(is_dir).
12843
				$result["content"]["status"][]=array(
12844
					"status"=>"?",
12845
					"target"=>$conf["target"],
12846
					"is_dir"=>"false"
12847
					);
12848
 
12849
				}#if end
12850
 
12851
			#反之
12852
			else{
12853
 
12854
				#針對每一列
12855
				foreach($result["content"]["ori"] as $line){
12856
 
12857
					#取得檔案的 status 與名稱
12858
					sscanf($line,"%s %s",$sta,$fi);
12859
 
12860
					#設置該目標的 狀態(status), 路徑與名稱(target), 是否為目錄(is_dir).
12861
					$result["content"]["status"][]=array(
12862
						"status"=>$sta,
12863
						"target"=>$fi,
12864
						"is_dir"=>is_file($fi)?"false":"true"
12865
						);
12866
 
12867
					}#foreach end
12868
 
12869
				}#else end
12870
 
12871
			}#if end
12872
 
12873
		#設置執行正常
12874
		$result["status"]="true";
12875
 
12876
		#回傳結果
12877
		return $result;
12878
 
12879
		}#function svn status end
12880
 
12881
	/*
12882
	#函式說明:
12883
	#提供方便進行svn commit的工具
12884
	#回傳結果:
12885
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12886
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
12887
	#$result["function"],當前執行的函式名稱.
12888
	#$result["content"],commit完得到的結果.
12889
	#$result["content"]["content"],執行完svn ci得到的終端輸出.
12890
	#$result["content"]["cmd"],實際執行的指令.
12891
	#$result["content"]["status"],svn指令回傳的代碼,0代表正常結束.
12892
	#必填參數:
12893
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12894
	$conf["fileArgu"]=__FILE__;
12895
	#可省略參數:
12896
	#$conf["author"],字串,作者資訊,若無則預設為"-- Power by QBPWCF"
12897
	#$conf["author"]="";
12898
	#參考資料:
12899
	#sscanf指定讀到特定字符才結束=>http://stackoverflow.com/questions/2854488/reading-a-string-with-spaces-with-sscanf
12900
	#參考資料:
12901
	#無.
12902
	#備註:
41 liveuser 12903
	#註解輸入 "update Release Note & rpm spec file" 會導致解析錯誤.
3 liveuser 12904
	*/
12905
	public static function svnci(&$conf=array()){
12906
 
12907
		#初始化要回傳的結果
12908
		$result=array();
12909
 
12910
		#取得當前執行的函式名稱
12911
		$result["function"]=__FUNCTION__;
12912
 
12913
		#函式說明:
12914
		#判斷當前環境為web還是cmd
12915
		#回傳結果:
12916
		#$result,"web"或"cmd"
12917
		if(csInformation::getEnv()=="web"){
12918
 
12919
			#設置執行失敗
12920
			$result["status"]="false";
12921
 
12922
			#設置執行錯誤訊息
12923
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
12924
 
12925
			#回傳結果
12926
			return $result;
12927
 
12928
			}#if end
12929
 
12930
		#函式說明:
12931
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
12932
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12933
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12934
		#$result["function"],當前執行的函式名稱.
12935
		#$result["argu"],設置給予的參數.
12936
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12937
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12938
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12939
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12940
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12941
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12942
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12943
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12944
		#必填寫的參數:
12945
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12946
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12947
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12948
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12949
		#可以省略的參數:
12950
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12951
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
12952
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12953
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
12954
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12955
		#$conf["canBeEmptyString"]="false";
12956
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12957
		#$conf["canNotBeEmpty"]=array();
12958
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12959
		#$conf["canBeEmpty"]=array();
12960
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12961
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12962
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12963
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("author");
12964
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
12965
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12966
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12967
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("-- Power by QBPWCF");
12968
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12969
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12970
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12971
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12972
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12973
		#$conf["arrayCountEqualCheck"][]=array();
12974
		#參考資料來源:
12975
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12976
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12977
		unset($conf["variableCheck::checkArguments"]);
12978
 
12979
		#如果檢查參數失敗
12980
		if($checkArguments["status"]==="false"){
12981
 
12982
			#設置執行失敗
12983
			$result["status"]="false";
12984
 
12985
			#設置執行錯誤
12986
			$result["error"]=$checkArguments;
12987
 
12988
			#回傳結果
12989
			return $result;
12990
 
12991
			}#if end
12992
 
12993
		#如果檢查參數不通過
12994
		if($checkArguments["status"]==="false"){
12995
 
12996
			#設置執行失敗
12997
			$result["status"]="false";
12998
 
12999
			#設置執行錯誤
13000
			$result["error"]=$checkArguments;
13001
 
13002
			#回傳結果
13003
			return $result;
13004
 
13005
			}#if end
13006
 
13007
		#函式說明:
13008
		#抓取命令列的參數.
13009
		#回傳結果:
13010
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13011
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13012
		#$result["function"],當前執行的函式名稱.
13013
		#$result["argu"],使用的參數陣列.
13014
		#$result["content"],要回傳的參數陣列.
13015
		#$result["count"],參數的數量.
13016
		#必填參數:
13017
		#無
13018
		#可省略參數:
13019
		#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
13020
		#$conf["echo"]="false";
13021
		$conf["cmd::getArgu"]=array();
13022
		$getArgu=cmd::getArgu($conf["cmd::getArgu"]);
13023
		unset($conf["cmd::getArgu"]);
13024
 
13025
		#如果取得參數失敗
13026
		if($getArgu["status"]==="false")
13027
		{
13028
 
13029
			#設置執行失敗
13030
			$result["status"]="false";
13031
 
13032
			#設置執行錯誤
13033
			$result["error"]=$getArgu;
13034
 
13035
			#回傳結果
13036
			return $result;
13037
 
13038
		}#if end
13039
 
13040
		#如果有第一個參數
13041
		if(isset($getArgu["content"][1]))
13042
		{
13043
			#如果是 "-h" 跟 "--help"
13044
			if($getArgu["content"][1]==="-h" || $getArgu["content"][1]==="--help")
13045
			{
13046
				#提示用法
13047
				echo "usage: ".basename($_SERVER["PHP_SELF"])." [--ssh-port=ssh connect port] [--ssh-key=ssh prive key] ".PHP_EOL;
13048
				echo "--ssh-port, 代表ssh連線的port.".PHP_EOL;
13049
				echo "--ssh-key, 代表ssh連線所要使用的私有金鑰.".PHP_EOL;
13050
				exit;
13051
 
13052
			}#if end
13053
 
13054
		}#if end
13055
 
13056
		#解析參數
13057
		#函式說明:
13058
		#解析參數.
13059
		#回傳結果:
13060
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13061
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13062
		#$result["function"],當前執行的函式名稱.
13063
		#$result["content"],解析好的參數陣列.
13064
		#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
13065
		#$result["program"],字串,執行的程式名稱.
13066
		#必填參數:
13067
		#無
13068
		#可省略參數:
13069
		#無
13070
		#備註:
13071
		#僅能在命令列底下執行.
13072
		#建議:
13073
		#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["content"]["a"]["b"][$i]=$value .
13074
		$conf["cmd::parseArgu"]=array();
13075
		$parseArgu=cmd::parseArgu($conf["cmd::parseArgu"]);
13076
		unset($conf["cmd::parseArgu"]);
13077
 
13078
		#如果解析參數失敗
13079
		if($parseArgu["status"]==="false"){
13080
 
13081
			#設置執行失敗
13082
			$result["status"]="false";
13083
 
13084
			#設置執行錯誤
13085
			$result["error"]=$parseArgu;
13086
 
13087
			#回傳結果
13088
			return $result;
13089
 
13090
			}#if end
13091
 
13092
		#初始化 ssh 設定的字串
13093
		$sshOption="--config-option=config:tunnels:ssh=ssh";
13094
 
13095
		#如果有設定ssh port的參數
13096
		if(isset($parseArgu["content"]["ssh-port"])){
13097
 
13098
			#如果有第一個參數
13099
			if(isset($parseArgu["content"]["ssh-port"][0])){
13100
 
13101
				#設置 ssh 的 port
13102
				$sshOption=$sshOption." -p ".$parseArgu["content"]["ssh-port"][0];
13103
 
13104
				}#if end
13105
 
13106
			}#if end
13107
 
13108
		#如果有設定ssh key的參數
13109
		if(isset($parseArgu["content"]["ssh-key"])){
13110
 
13111
			#如果有第一個參數
13112
			if(isset($parseArgu["content"]["ssh-key"][0])){
13113
 
13114
				#設置 ssh 的 port
13115
				$sshOption=$sshOption." -i ".$parseArgu["content"]["ssh-key"][0];
13116
 
13117
				}#if end
13118
 
13119
			}#if end
13120
 
13121
		#函式說明:
13122
		#檢查當前目錄是否在svn版本之下
13123
		#回傳結果:
13124
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13125
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13126
		#$result["function"],當前執行的函式名稱.
13127
		#$result["warning"],警告訊息陣列.
13128
		#$result["content"]["issvnworkdir"],當前目錄是否處於svn版本控制之下,"ture"代表是,"false"代表不是.
13129
		#$result["content"]["account"],連線到repo的帳戶.
13130
		#$result["content"]["repo"],連線到的repo.
13131
		#必填參數:
13132
		#$conf["fileArgu"],字串,變數__FILE__的內容.
13133
		$conf["cmd::issvnworkdir"]["fileArgu"]=$conf["fileArgu"];
13134
		#可省略參數:
13135
		#無.
13136
		$issvnworkdir=cmd::issvnworkdir($conf["cmd::issvnworkdir"]);
13137
		unset($conf["cmd::issvnworkdir"]);
13138
 
13139
		#如果出錯
13140
		if($issvnworkdir["status"]==="false"){
13141
 
13142
			#設置執行失敗
13143
			$result["status"]="false";
13144
 
13145
			#設置執行錯誤
13146
			$result["error"]=$issvnworkdir;
13147
 
13148
			#回傳結果
13149
			return $result;
13150
 
13151
			}#if end
13152
 
13153
		#如果不在版本控制目錄底下
13154
		if($issvnworkdir["content"]["issvnworkdir"]==="false"){
13155
 
13156
			#設置執行失敗
13157
			$result["status"]="false";
13158
 
13159
			#設置執行錯誤
13160
			$result["error"]=$issvnworkdir;
13161
 
13162
			#回傳結果
13163
			return $result;
13164
 
13165
			}#if end
13166
 
13167
		#取得使用的svn+ssh帳號
13168
		$account=$issvnworkdir["content"]["account"];
13169
 
13170
		#取得svn的repo
13171
		$repo=$issvnworkdir["content"]["repo"];
13172
 
13173
		#預設存放 svn 賬號密碼的 xml 檔案位置
13174
		$defaultSvnAcctXml=pathinfo(__FILE__)["dirname"]."/../../../etc/qbpwcf/qbpwcf.conf.xml";
13175
 
13176
		#預設存放 svn 賬號密碼的 local xml 檔案位置
13177
		$defaultLocalSvnAcctXml=$defaultSvnAcctXml;
13178
 
13179
		#預設存放 svn 賬號密碼的 xml 檔案可能位置
13180
		$svnAcctXmlArray=array($defaultSvnAcctXml);
13181
 
13182
		#如果存在 include path
13183
		if(get_include_path()!==false){
13184
 
13185
			#函式說明:
13186
			#將固定格式的字串分開,並回傳分開的結果.
13187
			#回傳結果:
13188
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13189
			#$result["error"],錯誤訊息陣列
13190
			#$result["function"],當前執行的函數名稱.
13191
			#$result["argu"],使用的參數.
13192
			#$result["oriStr"],要分割的原始字串內容
13193
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13194
			#$result["dataCounts"],爲總共分成幾段
13195
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13196
			#必填參數:
13197
			#$conf["stringIn"],字串,要處理的字串.
13198
			$conf["stringProcess::spiltString"]["stringIn"]=get_include_path();
13199
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
13200
			$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
13201
			#可省略參數:
13202
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13203
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13204
			#參考資料:
13205
			#無.
13206
			#備註:
13207
			#無.
13208
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13209
			unset($conf["stringProcess::spiltString"]);
13210
 
13211
			#如果執行失敗
13212
			if($spiltString["status"]==="false"){
13213
 
13214
				#設置執行失敗
13215
				$result["status"]="false";
13216
 
13217
				#設置執行錯誤
13218
				$result["error"]=$spiltString;
13219
 
13220
				#回傳結果
13221
				return $result;
13222
 
13223
				}#if end
13224
 
13225
			#如果沒有符合的分割符號
13226
			if($spiltString["found"]==="false"){
13227
 
13228
				#設置執行失敗
13229
				$result["status"]="false";
13230
 
13231
				#設置執行錯誤
13232
				$result["error"]=$spiltString;
13233
 
13234
				#回傳結果
13235
				return $result;
13236
 
13237
				}#if end
13238
 
13239
			#如果沒有切割出東西
13240
			if($spiltString["dataCounts"]<1){
13241
 
13242
				#設置執行失敗
13243
				$result["status"]="false";
13244
 
13245
				#設置執行錯誤
13246
				$result["error"]=$spiltString;
13247
 
13248
				#回傳結果
13249
				return $result;
13250
 
13251
				}#if end
13252
 
13253
			#如果 first php include path 不為 "/" 結尾
13254
			if($spiltString["dataArray"][0][strlen($spiltString["dataArray"][0])-1]!=="/"){
13255
 
13256
				#開頭加上 "/"
13257
				$defaultLocalSvnAcctXml="/".$defaultLocalSvnAcctXml;
13258
 
13259
				}#if end
13260
 
13261
			#增加 存放帳號密碼的xml檔案 位置
13262
			$svnAcctXmlArray[]=$spiltString["dataArray"][0].$defaultLocalSvnAcctXml;
13263
 
13264
			}#if end
13265
 
13266
		#針對每個可能的 存放帳號密碼的xml檔案 位置
13267
		foreach($svnAcctXmlArray as $index=>$svnAcctXml){
13268
 
13269
			#如果存放帳號密碼的xml檔案不存在
13270
			if(!file_exists($svnAcctXml)){
13271
 
13272
				#如果是最後一個xml檔案了
13273
				if($index===count($svnAcctXmlArray)-1){
13274
 
13275
					#設置執行失敗
13276
					$result["status"]="false";
13277
 
13278
					#設置執行錯誤
13279
					$result["error"]="存放帳號密碼的xml檔案(".$svnAcctXml.")不存在";
13280
 
13281
					#回傳結果
13282
					return $result;
13283
 
13284
 
13285
					}#if end
13286
 
13287
				}#if end
13288
 
13289
			#反之檔案存在
13290
			else {
13291
 
13292
				#更新要使用的 存放帳號密碼的xml檔案
13293
				$defaultSvnAcctXml=$svnAcctXml;
13294
 
13295
				#跳出 foreach
13296
				break;
13297
 
13298
				}#else end
13299
 
13300
			}#foreach end
13301
 
13302
		#初始化要使用的svn+ssh帳號
13303
		$password="";
13304
 
13305
		#取得qbpwcf設定檔案的內容
13306
		#檢查是否有svn的URL上帳號對應的密碼是否存在
13307
		#函式說明:
13308
		#取得xml特定標籤的內容
13309
		#回傳結果:
13310
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13311
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13312
		#$result["warning"],警告訊息陣列.
13313
		#$result["function"],當前執行的函式名稱.
13314
		#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.
13315
		#$result["content"],xml物件的標籤內容.
13316
		#$result["tag"],修正名稱格式後取得目標標籤內容的階層陣列.
13317
		#必填參數:
13318
		#$conf["xmlPosition"],字串,xml檔案的位置.
13319
		$conf["xml::getTagInfo"]["xmlPosition"]=$defaultSvnAcctXml;
13320
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13321
		$conf["xml::getTagInfo"]["fileArgu"]=$conf["fileArgu"];
13322
		#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13323
		$conf["xml::getTagInfo"]["tag"]=array("qbpwcf","cmd","svnci","conf");
13324
		$getTagInfo=xml::getTagInfo($conf["xml::getTagInfo"]);
13325
		unset($conf["xml::getTagInfo"]);
13326
 
13327
		#如果讀取xml檔案失敗
13328
		if($getTagInfo["status"]==="false"){
13329
 
13330
			#設置執行失敗
13331
			$result["status"]="false";
13332
 
13333
			#設置執行錯誤
13334
			$result["error"]=$getTagInfo;
13335
 
13336
			#回傳結果
13337
			return $result;
13338
 
13339
			}#if end
13340
 
13341
		#如果標籤不存在
13342
		if($getTagInfo["tagExist"]==="false"){
13343
 
13344
			#函式說明:
13345
			#在目標層級新增標籤與內容
13346
			#回傳結果:
13347
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13348
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
13349
			#$result["function"],當前執行的函式名稱.
13350
			#必填參數:
13351
			#$conf["xmlPosition"],字串,xml檔案的位置.
13352
			$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13353
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13354
			$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13355
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13356
			$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","account");
13357
			#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13358
			$conf["xml::addTag"]["tagValue"]=$account;
13359
			#參考資料:
13360
			#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13361
			$addTag=xml::addTag($conf["xml::addTag"]);
13362
			unset($conf["xml::addTag"]);
13363
 
13364
			#如果讀取新增標籤檔案失敗
13365
			if($addTag["status"]==="false"){
13366
 
13367
				#設置執行失敗
13368
				$result["status"]="false";
13369
 
13370
				#設置執行錯誤
13371
				$result["error"]=$addTag;
13372
 
13373
				#回傳結果
13374
				return $result;
13375
 
13376
				}#if end
13377
 
13378
			#函式說明:
13379
			#在目標層級新增標籤與內容
13380
			#回傳結果:
13381
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13382
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
13383
			#$result["function"],當前執行的函式名稱.
13384
			#必填參數:
13385
			#$conf["xmlPosition"],字串,xml檔案的位置.
13386
			$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13387
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13388
			$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13389
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13390
			$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","password");
13391
			#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13392
			$conf["xml::addTag"]["tagValue"]=$password;
13393
			#參考資料:
13394
			#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13395
			$addTag=xml::addTag($conf["xml::addTag"]);
13396
			unset($conf["xml::addTag"]);
13397
 
13398
			#如果讀取新增標籤檔案失敗
13399
			if($addTag["status"]==="false"){
13400
 
13401
				#設置執行失敗
13402
				$result["status"]="false";
13403
 
13404
				#設置執行錯誤
13405
				$result["error"]=$addTag;
13406
 
13407
				#回傳結果
13408
				return $result;
13409
 
13410
				}#if end
13411
 
13412
			#函式說明:
13413
			#在目標層級新增標籤與內容
13414
			#回傳結果:
13415
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13416
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
13417
			#$result["function"],當前執行的函式名稱.
13418
			#必填參數:
13419
			#$conf["xmlPosition"],字串,xml檔案的位置.
13420
			$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13421
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13422
			$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13423
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13424
			$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","repo");
13425
			#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13426
			$conf["xml::addTag"]["tagValue"]=$repo;
13427
			#參考資料:
13428
			#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13429
			$addTag=xml::addTag($conf["xml::addTag"]);
13430
			unset($conf["xml::addTag"]);
13431
 
13432
			#如果讀取新增標籤檔案失敗
13433
			if($addTag["status"]==="false"){
13434
 
13435
				#設置執行失敗
13436
				$result["status"]="false";
13437
 
13438
				#設置執行錯誤
13439
				$result["error"]=$addTag;
13440
 
13441
				#回傳結果
13442
				return $result;
13443
 
13444
				}#if end
13445
 
13446
			#取得qbpwcf設定檔案的內容
13447
			#檢查是否有svn的URL上帳號對應的密碼是否存在
13448
			#函式說明:
13449
			#取得xml特定標籤的內容
13450
			#回傳結果:
13451
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13452
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
13453
			#$result["warning"],警告訊息陣列.
13454
			#$result["function"],當前執行的函式名稱.
13455
			#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.
13456
			#$result["content"],xml物件的標籤內容.
13457
			#$result["tag"],修正名稱格式後取得目標標籤內容的階層陣列.
13458
			#必填參數:
13459
			#$conf["xmlPosition"],字串,xml檔案的位置.
13460
			$conf["xml::getTagInfo"]["xmlPosition"]=$defaultSvnAcctXml;
13461
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13462
			$conf["xml::getTagInfo"]["fileArgu"]=$conf["fileArgu"];
13463
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13464
			$conf["xml::getTagInfo"]["tag"]=array("qbpwcf","cmd","svnci","conf");
13465
			$getTagInfo=xml::getTagInfo($conf["xml::getTagInfo"]);
13466
			unset($conf["xml::getTagInfo"]);
13467
 
13468
			#如果讀取xml檔案失敗
13469
			if($getTagInfo["status"]==="false"){
13470
 
13471
				#設置執行失敗
13472
				$result["status"]="false";
13473
 
13474
				#設置執行錯誤
13475
				$result["error"]=$getTagInfo;
13476
 
13477
				#回傳結果
13478
				return $result;
13479
 
13480
				}#if end
13481
 
13482
			#如果標籤不存在
13483
			if($getTagInfo["tagExist"]==="false"){
13484
 
13485
				#設置執行失敗
13486
				$result["status"]="false";
13487
 
13488
				#設置執行錯誤
13489
				$result["error"]=$getTagInfo;
13490
 
13491
				$result["error"][]="應該存在的tag並不存在";
13492
 
13493
				#回傳結果
13494
				return $result;
13495
 
13496
				}#if end
13497
 
13498
			}#if end
13499
 
13500
		#如果只有一筆資料
13501
		$dataCount=count($getTagInfo["content"]->account);
13502
 
13503
		#針對每個記錄
13504
		for($i=0;$i<$dataCount;$i++){
13505
 
13506
			#如果 帳號 跟 repo 有對上
13507
			if(
13508
				(string)$getTagInfo["content"]->account[$i]===$account &&
13509
				(string)$getTagInfo["content"]->repo[$i]===$repo
13510
				){
13511
 
13512
				#提示有找到既有的帳號與repo
13513
				echo "找到既有的帳號與repo".PHP_EOL;
13514
 
13515
				#取得密碼的形態
13516
				$storedPass=(string)($getTagInfo["content"]->password[$i]);
13517
 
13518
				#初始化密碼不ok
13519
				$passIsOk=false;
13520
 
13521
				#無窮迴圈直到密碼對了
13522
				while(!$passIsOk){
13523
 
13524
					#測試密碼是否正確
13525
					#用 svn ls 來驗證".PHP_EOL;
13526
 
13527
					#函式說明:
13528
					#呼叫shell執行系統命令,並取得回傳的內容.
13529
					#回傳的結果:
13530
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13531
					#$result["error"],錯誤訊息陣列.
13532
					#$result["function"],當前執行的函式名稱.
13533
					#$result["argu"],使用的參數.
13534
					#$result["cmd"],執行的指令內容.
13535
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13536
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13537
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13538
					#$result["running"],是否還在執行.
13539
					#$result["pid"],pid
13540
					#必填參數
13541
					#$conf["command"],字串,要執行的指令與.
13542
					$conf["external::callShel"]["command"]="echo";
13543
					#$conf["fileArgu"],字串,變數__FILE__的內容.
13544
					$conf["external::callShel"]["fileArgu"]=$conf["fileArgu"];
13545
					#可省略參數:
13546
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13547
					$conf["external::callShel"]["argu"]=array("\"".$storedPass."\"","|","sshpass","-v","svn","ls",$sshOption);
13548
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13549
					#$conf["arguIsAddr"]=array();
13550
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
13551
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
13552
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
13553
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13554
					#$conf["enablePrintDescription"]="true";
13555
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13556
					#$conf["printDescription"]="";
13557
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13558
					$conf["external::callShel"]["escapeshellarg"]="true";
13559
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13560
					#$conf["username"]="";
13561
					#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13562
					#$conf["password"]="";
13563
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13564
					#$conf["useScript"]="";
13565
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13566
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13567
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13568
					#$conf["inBackGround"]="";
13569
					#備註:
13570
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13571
					#參考資料:
13572
					#exec=>http://php.net/manual/en/function.exec.php
13573
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13574
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13575
					$callShell=external::callShell($conf["external::callShel"]);
13576
					unset($conf["external::callShel"]);
13577
 
13578
					#如果執行失敗
13579
					if($callShell["status"]==="false"){
13580
 
13581
						#如果不是密碼錯誤
13582
						if($callShell["error"][0]!==5){
13583
 
13584
							#設置執行失敗
13585
							$result["status"]="false";
13586
 
13587
							#設置執行錯誤
13588
							$result["error"]=$callShell;
13589
 
13590
							#回傳結果
13591
							return $result;
13592
 
13593
							}#if end
13594
 
13595
						#提示輸入密碼
13596
						#函式說明:
13597
						#讀取標準I/O的一行輸入.並提供提示說明.
13598
						#回傳的結果:
13599
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13600
						#$result["error"],錯誤訊息.
13601
						#$result["function"],當前執行的函式名稱.
13602
						#$result["content"],取得的輸入內容.
13603
						#必填參數:
13604
						#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
13605
						$conf["cmd::readLine"]["commentsArray"]=array("請輸入帳號(".$account.")對應的密碼");
13606
						#可省略參數:
13607
						#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
13608
						#$conf["newLineBreak"]="false";
13609
						$readLine=cmd::readLine($conf["cmd::readLine"]);
13610
						unset($conf["cmd::readLine"]);
13611
 
13612
						#如果執行失敗
13613
						if($readLine["status"]==="false"){
13614
 
13615
							#設置執行失敗
13616
							$result["status"]="false";
13617
 
13618
							#設置執行錯誤
13619
							$result["error"]=$readLine;
13620
 
13621
							#回傳結果
13622
							return $result;
13623
 
13624
							}#if end
13625
 
13626
						#取得輸入的密碼
13627
						$untestPass=$readLine["content"];
13628
 
13629
						#密碼正確,儲存密碼
13630
						#函式說明:
13631
						#更新xml標籤的內容.
13632
						#回傳結果:
13633
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13634
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
13635
						#$result["function"],當前執行的函式名稱.
13636
						#必填參數:
13637
						#$conf["xmlPosition"],字串,xml檔案的位置.
13638
						$conf["xml::updateTag"]["xmlPosition"]=$defaultSvnAcctXml;
13639
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13640
						$conf["xml::updateTag"]["fileArgu"]=$conf["fileArgu"];
13641
						#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13642
						$conf["xml::updateTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","password");
13643
						#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13644
						$conf["xml::updateTag"]["tagValue"]=$untestPass;
13645
						#參考資料:
13646
						#replacechild=>http://php.net/manual/en/domnode.replacechild.php
13647
						#loadxml=>http://php.net/manual/en/domdocument.loadxml.php
13648
						#update xml node value=>http://stackoverflow.com/questions/4748014/updating-xml-node-with-php
13649
						#備註:
13650
						#若有多個同名的tag,則只會對於第一個tag進行操作.
13651
						$updateTag=xml::updateTag($conf["xml::updateTag"]);
13652
						unset($conf["xml::updateTag"]);
13653
 
13654
						#如果更新檔案失敗
13655
						if($updateTag["status"]==="false"){
13656
 
13657
							#設置執行失敗
13658
							$result["status"]="false";
13659
 
13660
							#設置執行錯誤
13661
							$result["error"]=$updateTag;
13662
 
13663
							#回傳結果
13664
							return $result;
13665
 
13666
							}#if end
13667
 
13668
						#儲存密碼
13669
						echo "已更新svn密碼".PHP_EOL;
13670
 
13671
						#取得正確的 svn 密碼
13672
						$storedPass=$untestPass;
13673
 
13674
						}#if end
13675
 
13676
					#反之
13677
					else{
13678
 
13679
						#設置密碼正確
13680
						$passIsOk=true;
13681
 
13682
						#儲存密碼
13683
						echo "svn密碼正確".PHP_EOL;
13684
 
13685
						#跳出 while for
13686
						break 2;
13687
 
13688
						}#else end
13689
 
13690
					}#while end
13691
 
13692
				}#if end
13693
 
13694
			#如果已經是最後一筆帳號、密碼、repo對不上
13695
			else if($i===$dataCount-1)
13696
			{
13697
				#提示有找到既有的帳號與repo
13698
				echo "既有的帳號與repo都不符合".PHP_EOL;
13699
 
13700
				#提示輸入密碼
13701
				#函式說明:
13702
				#讀取標準I/O的一行輸入.並提供提示說明.
13703
				#回傳的結果:
13704
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13705
				#$result["error"],錯誤訊息.
13706
				#$result["function"],當前執行的函式名稱.
13707
				#$result["content"],取得的輸入內容.
13708
				#必填參數:
13709
				#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
13710
				$conf["cmd::readLine"]["commentsArray"]=array("請輸入帳號(".$account.")對應的密碼");
13711
				#可省略參數:
13712
				#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
13713
				#$conf["newLineBreak"]="false";
13714
				$readLine=cmd::readLine($conf["cmd::readLine"]);
13715
				unset($conf["cmd::readLine"]);
13716
 
13717
				#如果執行失敗
13718
				if($readLine["status"]==="false"){
13719
 
13720
					#設置執行失敗
13721
					$result["status"]="false";
13722
 
13723
					#設置執行錯誤
13724
					$result["error"]=$readLine;
13725
 
13726
					#回傳結果
13727
					return $result;
13728
 
13729
					}#if end
13730
 
13731
				#取得輸入的密碼
13732
				$untestPass=$readLine["content"];
13733
 
13734
				#初始化密碼不ok
13735
				$passIsOk=false;
13736
 
13737
				#無窮迴圈直到密碼對了
13738
				while(!$passIsOk){
13739
 
13740
					#測試密碼是否正確
13741
					#用 svn ls 來驗證".PHP_EOL;
13742
 
13743
					#函式說明:
13744
					#呼叫shell執行系統命令,並取得回傳的內容.
13745
					#回傳的結果:
13746
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13747
					#$result["error"],錯誤訊息陣列.
13748
					#$result["function"],當前執行的函式名稱.
13749
					#$result["argu"],使用的參數.
13750
					#$result["cmd"],執行的指令內容.
13751
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13752
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13753
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13754
					#$result["running"],是否還在執行.
13755
					#$result["pid"],pid
13756
					#必填參數
13757
					#$conf["command"],字串,要執行的指令與.
13758
					$conf["external::callShel"]["command"]="echo";
13759
					#$conf["fileArgu"],字串,變數__FILE__的內容.
13760
					$conf["external::callShel"]["fileArgu"]=$conf["fileArgu"];
13761
					#可省略參數:
13762
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13763
					#$conf["external::callShel"]["argu"]=array("\"".$untestPass."\"","|","sshpass","-v","svn","ls",$sshOption);
13764
					$conf["external::callShel"]["argu"]=array($untestPass,"|","sshpass","-v","svn","ls",$sshOption);
13765
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13766
					#$conf["arguIsAddr"]=array();
13767
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
13768
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
13769
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
13770
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13771
					#$conf["enablePrintDescription"]="true";
13772
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13773
					#$conf["printDescription"]="";
13774
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13775
					$conf["external::callShel"]["escapeshellarg"]="true";
13776
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13777
					#$conf["username"]="";
13778
					#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13779
					#$conf["password"]="";
13780
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13781
					#$conf["useScript"]="";
13782
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13783
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13784
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13785
					#$conf["inBackGround"]="";
13786
					#備註:
13787
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13788
					#參考資料:
13789
					#exec=>http://php.net/manual/en/function.exec.php
13790
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13791
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13792
					$callShell=external::callShell($conf["external::callShel"]);
13793
					unset($conf["external::callShel"]);
13794
 
13795
					#如果執行失敗
13796
					if($callShell["status"]==="false"){
13797
 
13798
						#如果不是密碼錯誤
13799
						if($callShell["error"][0]!==5){
13800
 
13801
							#設置執行失敗
13802
							$result["status"]="false";
13803
 
13804
							#設置執行錯誤
13805
							$result["error"]=$callShell;
13806
 
13807
							#回傳結果
13808
							return $result;
13809
 
13810
							}#if end
13811
 
13812
						#提示輸入密碼
13813
						#函式說明:
13814
						#讀取標準I/O的一行輸入.並提供提示說明.
13815
						#回傳的結果:
13816
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13817
						#$result["error"],錯誤訊息.
13818
						#$result["function"],當前執行的函式名稱.
13819
						#$result["content"],取得的輸入內容.
13820
						#必填參數:
13821
						#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
13822
						$conf["cmd::readLine"]["commentsArray"]=array("請輸入帳號(".$account.")對應的密碼");
13823
						#可省略參數:
13824
						#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
13825
						#$conf["newLineBreak"]="false";
13826
						$readLine=cmd::readLine($conf["cmd::readLine"]);
13827
						unset($conf["cmd::readLine"]);
13828
 
13829
						#如果執行失敗
13830
						if($readLine["status"]==="false"){
13831
 
13832
							#設置執行失敗
13833
							$result["status"]="false";
13834
 
13835
							#設置執行錯誤
13836
							$result["error"]=$readLine;
13837
 
13838
							#回傳結果
13839
							return $result;
13840
 
13841
							}#if end
13842
 
13843
						#取得輸入的密碼
13844
						$untestPass=$readLine["content"];
13845
 
13846
						}#if end
13847
 
13848
					#反之
13849
					else{
13850
 
13851
						#設置密碼正確
13852
						$passIsOk=true;
13853
 
13854
						#儲存密碼
13855
						echo "svn密碼正確".PHP_EOL;
13856
 
13857
						#取得正確的 svn 密碼
13858
						$untestPass;
13859
 
13860
						#儲存密碼
13861
						echo "新增 svn帳號、密碼、repo".PHP_EOL;
13862
 
13863
						#函式說明:
13864
						#在目標層級新增標籤與內容
13865
						#回傳結果:
13866
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13867
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
13868
						#$result["function"],當前執行的函式名稱.
13869
						#必填參數:
13870
						#$conf["xmlPosition"],字串,xml檔案的位置.
13871
						$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13872
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13873
						$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13874
						#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13875
						$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","account");
13876
						#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13877
						$conf["xml::addTag"]["tagValue"]=$account;
13878
						#參考資料:
13879
						#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13880
						$addTag=xml::addTag($conf["xml::addTag"]);
13881
						unset($conf["xml::addTag"]);
13882
 
13883
						#如果讀取新增標籤檔案失敗
13884
						if($addTag["status"]==="false"){
13885
 
13886
							#設置執行失敗
13887
							$result["status"]="false";
13888
 
13889
							#設置執行錯誤
13890
							$result["error"]=$addTag;
13891
 
13892
							#回傳結果
13893
							return $result;
13894
 
13895
							}#if end
13896
 
13897
						#函式說明:
13898
						#在目標層級新增標籤與內容
13899
						#回傳結果:
13900
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13901
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
13902
						#$result["function"],當前執行的函式名稱.
13903
						#必填參數:
13904
						#$conf["xmlPosition"],字串,xml檔案的位置.
13905
						$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13906
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13907
						$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13908
						#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13909
						$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","password");
13910
						#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13911
						$conf["xml::addTag"]["tagValue"]=$untestPass;
13912
						#參考資料:
13913
						#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13914
						$addTag=xml::addTag($conf["xml::addTag"]);
13915
						unset($conf["xml::addTag"]);
13916
 
13917
						#如果讀取新增標籤檔案失敗
13918
						if($addTag["status"]==="false"){
13919
 
13920
							#設置執行失敗
13921
							$result["status"]="false";
13922
 
13923
							#設置執行錯誤
13924
							$result["error"]=$addTag;
13925
 
13926
							#回傳結果
13927
							return $result;
13928
 
13929
							}#if end
13930
 
13931
						#函式說明:
13932
						#在目標層級新增標籤與內容
13933
						#回傳結果:
13934
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13935
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
13936
						#$result["function"],當前執行的函式名稱.
13937
						#必填參數:
13938
						#$conf["xmlPosition"],字串,xml檔案的位置.
13939
						$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13940
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13941
						$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13942
						#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13943
						$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","repo");
13944
						#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13945
						$conf["xml::addTag"]["tagValue"]=$repo;
13946
						#參考資料:
13947
						#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13948
						$addTag=xml::addTag($conf["xml::addTag"]);
13949
						unset($conf["xml::addTag"]);
13950
 
13951
						#如果讀取新增標籤檔案失敗
13952
						if($addTag["status"]==="false"){
13953
 
13954
							#設置執行失敗
13955
							$result["status"]="false";
13956
 
13957
							#設置執行錯誤
13958
							$result["error"]=$addTag;
13959
 
13960
							#回傳結果
13961
							return $result;
13962
 
13963
							}#if end
13964
 
13965
						#取得qbpwcf設定檔案的內容
13966
						#檢查是否有svn的URL上帳號對應的密碼是否存在
13967
						#函式說明:
13968
						#取得xml特定標籤的內容
13969
						#回傳結果:
13970
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13971
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
13972
						#$result["warning"],警告訊息陣列.
13973
						#$result["function"],當前執行的函式名稱.
13974
						#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.
13975
						#$result["content"],xml物件的標籤內容.
13976
						#$result["tag"],修正名稱格式後取得目標標籤內容的階層陣列.
13977
						#必填參數:
13978
						#$conf["xmlPosition"],字串,xml檔案的位置.
13979
						$conf["xml::getTagInfo"]["xmlPosition"]=$defaultSvnAcctXml;
13980
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13981
						$conf["xml::getTagInfo"]["fileArgu"]=$conf["fileArgu"];
13982
						#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13983
						$conf["xml::getTagInfo"]["tag"]=array("qbpwcf","cmd","svnci","conf");
13984
						$getTagInfo=xml::getTagInfo($conf["xml::getTagInfo"]);
13985
						unset($conf["xml::getTagInfo"]);
13986
 
13987
						#如果讀取xml檔案失敗
13988
						if($getTagInfo["status"]==="false"){
13989
 
13990
							#設置執行失敗
13991
							$result["status"]="false";
13992
 
13993
							#設置執行錯誤
13994
							$result["error"]=$getTagInfo;
13995
 
13996
							#回傳結果
13997
							return $result;
13998
 
13999
							}#if end
14000
 
14001
						#如果標籤不存在
14002
						if($getTagInfo["tagExist"]==="false"){
14003
 
14004
							#設置執行失敗
14005
							$result["status"]="false";
14006
 
14007
							#設置執行錯誤
14008
							$result["error"]=$getTagInfo;
14009
 
14010
							$result["error"][]="應該存在的tag並不存在";
14011
 
14012
							#回傳結果
14013
							return $result;
14014
 
14015
							}#if end
14016
 
14017
						#取得正確的 svn 密碼
14018
						$storedPass=$untestPass;
14019
 
14020
						}#else end
14021
 
14022
					}#if end
14023
 
14024
				}#if end
14025
 
14026
			}#for end
14027
 
14028
		#初始化要commit的檔案清單
14029
		$filesToCommit=array();
14030
 
14031
		#初始化要加到版本控制的檔案清單
14032
		$fileAdded=array();
14033
 
14034
		#初始化要移除的檔案
14035
		$fileShouldBeDeleted=array();
14036
 
14037
		#初始化紀錄複製的清單
14038
		$copyList=array();
14039
 
14040
		#當檔案未指定時
14041
		while(true){
14042
 
14043
			#提示輸入要commit的檔案
14044
			echo
14045
				"請輸入要commit的檔案名稱:".PHP_EOL.
14046
				"若要結束輸入請輸入'quit'".PHP_EOL.
14047
				"若要顯示本機目錄的list請輸入'lls sourcePath'".PHP_EOL.
14048
				"若要顯示svn上的list請輸入'rls targetPath'".PHP_EOL.
14049
				"若要檢視commit清單請輸入'ls'".PHP_EOL.
14050
				"若要取消目標的commit請輸入'unci sourcePath/file'".PHP_EOL.
14051
				"若要看相對於repo的差異請輸入'status'".PHP_EOL.
14052
				"若要看檔案相對於repo的差異請輸入'diff sourcePath/file'".PHP_EOL.
14053
				"若要看檔案相對於repo的特定版本差異請輸入'diff 版本號 sourcePath/file'".PHP_EOL.
14054
				"若要將status為「?」的檔案加到svn版本控制,請輸入'add sourcePath/file'".PHP_EOL.
14055
				"若要檢視本次commit新增到版本控制的檔案目錄清單,請輸入'ls add'".PHP_EOL.
14056
				"若要移除檔案則請輸入'del targetPath/file'".PHP_EOL.
14057
				"若要取消移除檔案則請輸入'undel targetPath/file'".PHP_EOL.
14058
				"若要檢視要移除的檔案清單請輸入'ls del'".PHP_EOL.
14059
				"若要複製路徑請輸入'cp sourcePath/file targetPath/file'".PHP_EOL.
14060
				"若要顯示複製的清單請輸入 'ls cp'".PHP_EOL.
14061
				"若要查詢目錄或檔案的歷史commit記錄,請輸入 'log sourcePath/file'".PHP_EOL.
14062
				"若要復原檔案目錄的變更為svn上的最新版本,請輸入 'revert targetPath/file'".PHP_EOL.
14063
				"若要更新請輸入 'update' ".PHP_EOL;
14064
 
14065
			#接收輸入
14066
			$input=trim(fgets(STDIN));
14067
 
14068
			#判斷輸入的內容
14069
			switch($input){
14070
 
14071
				#如果是 "quit"
14072
				case "quit":
14073
 
14074
					#如果沒有要commit的目標
14075
					if(count($filesToCommit)===0){
14076
 
14077
						#提示沒有要commit的目標
14078
						echo "沒有要commit的目標!".PHP_EOL;
14079
 
14080
						#等待使用者輸入要commit的目標
14081
						continue 2;
14082
 
14083
						}#if end
14084
 
14085
					#則代表結束輸入
14086
					break 2;
14087
 
14088
				#如果是 "ls"
14089
				case "ls":
14090
 
14091
					#針對每一列
14092
					foreach($filesToCommit as $lineNo=>$lineContent){
14093
 
14094
						#印出要上傳的檔案清單
14095
						echo "[".$lineNo."] ".$lineContent.PHP_EOL;
14096
 
14097
						}#foreach end
14098
 
14099
					#繼續輸入要commit的檔案名稱
14100
					continue 2;
14101
 
14102
				#如果是 "lls"
14103
				case "lls":
14104
 
14105
					#運行 ls
14106
					#函式說明:
14107
					#呼叫shell執行系統命令,並取得回傳的內容.
14108
					#回傳的結果:
14109
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14110
					#$result["error"],錯誤訊息陣列.
14111
					#$result["function"],當前執行的函式名稱.
14112
					#$result["argu"],使用的參數.
14113
					#$result["cmd"],執行的指令內容.
14114
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14115
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14116
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14117
					#$result["running"],是否還在執行.
14118
					#$result["pid"],pid.
14119
					#$result["statusCode"],執行結束後的代碼.
14120
					#必填參數
14121
					#$conf["command"],字串,要執行的指令與.
14122
					$conf["external::callShell"]["command"]="ls";
14123
					#$conf["fileArgu"],字串,變數__FILE__的內容.
14124
					$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
14125
					#可省略參數:
14126
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14127
					$conf["external::callShell"]["argu"]=array("-alh");
14128
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
14129
					#$conf["arguIsAddr"]=array();
14130
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14131
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14132
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14133
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14134
					#$conf["enablePrintDescription"]="true";
14135
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14136
					#$conf["printDescription"]="";
14137
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14138
					$conf["external::callShell"]["escapeshellarg"]="true";
14139
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14140
					#$conf["username"]="";
14141
					#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14142
					#$conf["password"]="";
14143
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14144
					#$conf["useScript"]="";
14145
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14146
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14147
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14148
					#$conf["inBackGround"]="";
14149
					#備註:
14150
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14151
					#參考資料:
14152
					#exec=>http://php.net/manual/en/function.exec.php
14153
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14154
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14155
					$callShell=external::callShell($conf["external::callShell"]);
14156
					unset($conf["external::callShell"]);
14157
 
14158
					#如果執行失敗
14159
					if($callShell["status"]==="false"){
14160
 
14161
						#設置執行失敗
14162
						$result["status"]="false";
14163
 
14164
						#設置執行錯誤
14165
						$result["error"]=$callShell;
14166
 
14167
						#回傳結果
14168
						return $result;
14169
 
14170
						}#if end
14171
 
14172
					#印出執行的 cmd
14173
					echo "執行的指令:".$callShell["cmd"].PHP_EOL;
14174
 
14175
					#印出執行後的回傳代碼
14176
					echo "status:".$callShell["statusCode"].PHP_EOL;
14177
 
14178
					#印出執行的結果
14179
					echo "本機當前路徑的檔案目錄清單:".PHP_EOL;
14180
 
14181
					#函式說明:
14182
					#顯示多行文字.
14183
					#回傳的結果:
14184
					#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
14185
					#$result["error"],錯誤訊息陣列.
14186
					#$result["function"],當前執行的函式名稱.
14187
					#$result["content"],語法.
14188
					#必填參數:
14189
					#$conf["string"],字串陣列,要放置的內容.
14190
					$conf["text::multiLine"]["string"]=$callShell["output"];
14191
					#可省略參數:
14192
					#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
14193
					#$conf["class"]="";
14194
					#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".
14195
					#$conf["type"]="EOL";
14196
					$multiLine=text::multiLine($conf["text::multiLine"]);
14197
					unset($conf["text::multiLine"]);
14198
 
14199
					#如過執行失敗
14200
					if($multiLine["status"]==="false"){
14201
 
14202
						#設置執行失敗
14203
						$result["status"]="false";
14204
 
14205
						#設置執行錯誤
14206
						$result["error"]=$multiLine;
14207
 
14208
						#回傳結果
14209
						return $result;
14210
 
14211
						}#if end
14212
 
14213
					#印出結果
14214
					echo $multiLine["content"];
14215
 
14216
					#繼續輸入要commit的檔案名稱
14217
					continue 2;
14218
 
14219
				#如果是 rls
14220
				case "rls":
14221
 
14222
					#運行svn ls
14223
					#函式說明:
14224
					#呼叫shell執行系統命令,並取得回傳的內容.
14225
					#回傳的結果:
14226
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14227
					#$result["error"],錯誤訊息陣列.
14228
					#$result["function"],當前執行的函式名稱.
14229
					#$result["argu"],使用的參數.
14230
					#$result["cmd"],執行的指令內容.
14231
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14232
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14233
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14234
					#$result["running"],是否還在執行.
14235
					#$result["pid"],pid
14236
					#$result["statusCode"],執行結束後的代碼.
14237
					#必填參數:
14238
					#$conf["command"],字串,要執行的指令與.
14239
					$conf["external::callShell"]["command"]="echo";
14240
					#$conf["fileArgu"],字串,變數__FILE__的內容.
14241
					$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
14242
					#可省略參數:
14243
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14244
					$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","ls",$sshOption);
14245
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
14246
					#$conf["arguIsAddr"]=array();
14247
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14248
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14249
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14250
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14251
					#$conf["enablePrintDescription"]="true";
14252
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14253
					#$conf["printDescription"]="";
14254
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14255
					$conf["external::callShell"]["escapeshellarg"]="true";
14256
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14257
					#$conf["username"]="";
14258
					#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14259
					#$conf["password"]="";
14260
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14261
					#$conf["useScript"]="";
14262
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14263
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14264
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14265
					#$conf["inBackGround"]="";
14266
					#備註:
14267
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14268
					#參考資料:
14269
					#exec=>http://php.net/manual/en/function.exec.php
14270
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14271
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14272
					$callShell=external::callShell($conf["external::callShell"]);
14273
					unset($conf["external::callShell"]);
14274
 
14275
					#如果運行失敗
14276
					if($callShell["status"]==="false")
14277
					{
14278
						#設置執行失敗
14279
						$result["status"]="false";
14280
 
14281
						#設置執行錯誤
14282
						$result["error"]=$callShell;
14283
 
14284
						#回傳結果
14285
						return $result;
14286
 
14287
					}#if end
14288
 
14289
					#印出執行的cmd
14290
					echo "cmd:".$callShell["cmd"].PHP_EOL;
14291
 
14292
					#印出執行後的回傳代碼
14293
					echo "status:".$callShell["statusCode"].PHP_EOL;
14294
 
14295
					#印出執行的結果
14296
					echo "repo當前路徑的檔案目錄清單:".PHP_EOL;
14297
 
14298
					#函式說明:
14299
					#顯示多行文字.
14300
					#回傳的結果:
14301
					#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
14302
					#$result["error"],錯誤訊息陣列.
14303
					#$result["function"],當前執行的函式名稱.
14304
					#$result["content"],語法.
14305
					#必填參數:
14306
					#$conf["string"],字串陣列,要放置的內容.
14307
					$conf["text::multiLine"]["string"]=$callShell["output"];
14308
					#可省略參數:
14309
					#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
14310
					#$conf["class"]="";
14311
					#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".
14312
					#$conf["type"]="EOL";
14313
					$multiLine=text::multiLine($conf["text::multiLine"]);
14314
					unset($conf["text::multiLine"]);
14315
 
14316
					#如過執行失敗
14317
					if($multiLine["status"]==="false"){
14318
 
14319
						#設置執行失敗
14320
						$result["status"]="false";
14321
 
14322
						#設置執行錯誤
14323
						$result["error"]=$multiLine;
14324
 
14325
						#回傳結果
14326
						return $result;
14327
 
14328
						}#if end
14329
 
14330
					#印出結果
14331
					echo $multiLine["content"];
14332
 
14333
					#繼續輸入要commit的檔案名稱
14334
					continue 2;
14335
 
14336
				#如果是 "status"
14337
				case "status":
14338
 
14339
					#取得當前目錄相對於repo的差異
14340
					#函式說明:
14341
					#執行svn status指令
14342
					#回傳結果:
14343
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14344
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
14345
					#$result["function"],當前執行的函式名稱.
14346
					#$result["content"]["ori"],指令輸出的原始結果陣列.
14347
					#$result["content"]["status"][$i]["status"],第$i+1個目標的狀態.
14348
					#$result["content"]["status"][$i]["target"],第$i+1個目標的路徑與名稱.
14349
					#$result["content"]["status"][$i]["is_dir"],第$i+1個目標是否為目錄,"true"代表是,"false"代表不是.
14350
					#必填參數:
14351
					#$conf["fileArgu"],字串,變數__FILE__的內容.
14352
					$conf["cmd::svnsta"]["fileArgu"]=$conf["fileArgu"];
14353
					#可省略參數:
14354
					#$conf["target"],字串,要檢查status的目標.
14355
					#$conf["target"]="";
14356
					$svnsta=cmd::svnsta($conf["cmd::svnsta"]);
14357
					unset($conf["cmd::svnsta"]);
14358
 
14359
					#如果執行失敗
14360
					if($svnsta["status"]==="false"){
14361
 
14362
						#設置執行失敗
14363
						$result["status"]="false";
14364
 
14365
						#設置執行錯誤
14366
						$result["error"]=$svnsta;
14367
 
14368
						#回傳結果
14369
						return $result;
14370
 
14371
						}#if end
14372
 
14373
					#印出相對於repo的差異
14374
 
14375
					#針對每列輸出
14376
					foreach($svnsta["content"]["ori"] as $line){
14377
 
14378
						#印出內容
14379
						echo $line.PHP_EOL;
14380
 
14381
						}#foreach end
14382
 
14383
					#繼續輸入要commit的檔案名稱
14384
					continue 2;
14385
 
14386
				#如果是 "update"
14387
				case "update":
14388
 
14389
					#運行 svn update
14390
					#函式說明:
14391
					#呼叫shell執行系統命令,並取得回傳的內容.
14392
					#回傳的結果:
14393
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14394
					#$result["error"],錯誤訊息陣列.
14395
					#$result["function"],當前執行的函式名稱.
14396
					#$result["argu"],使用的參數.
14397
					#$result["cmd"],執行的指令內容.
14398
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14399
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14400
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14401
					#$result["running"],是否還在執行.
14402
					#$result["pid"],pid
14403
					#$result["statusCode"],執行結束後的代碼.
14404
					#必填參數:
14405
					#$conf["command"],字串,要執行的指令與.
14406
					$conf["external::callShell"]["command"]="echo";
14407
					#$conf["fileArgu"],字串,變數__FILE__的內容.
14408
					$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
14409
					#可省略參數:
14410
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14411
					$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","update",$sshOption);
14412
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
14413
					#$conf["arguIsAddr"]=array();
14414
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14415
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14416
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14417
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14418
					#$conf["enablePrintDescription"]="true";
14419
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14420
					#$conf["printDescription"]="";
14421
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14422
					$conf["external::callShell"]["escapeshellarg"]="true";
14423
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14424
					#$conf["username"]="";
14425
					#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14426
					#$conf["password"]="";
14427
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14428
					#$conf["useScript"]="";
14429
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14430
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14431
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14432
					#$conf["inBackGround"]="";
14433
					#備註:
14434
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14435
					#參考資料:
14436
					#exec=>http://php.net/manual/en/function.exec.php
14437
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14438
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14439
					$callShell=external::callShell($conf["external::callShell"]);
14440
					unset($conf["external::callShell"]);
14441
 
14442
					#如果運行失敗
14443
					if($callShell["status"]==="false")
14444
					{
14445
						#設置執行失敗
14446
						$result["status"]="false";
14447
 
14448
						#設置執行錯誤
14449
						$result["error"]=$callShell;
14450
 
14451
						#回傳結果
14452
						return $result;
14453
 
14454
					}#if end
14455
 
14456
					#印出執行的cmd
14457
					echo "cmd:".$callShell["cmd"].PHP_EOL;
14458
 
14459
					#印出執行後的回傳代碼
14460
					echo "status:".$callShell["statusCode"].PHP_EOL;
14461
 
14462
					#印出執行的結果
14463
					echo "已經更新到最新版本".PHP_EOL;
14464
 
14465
					#函式說明:
14466
					#顯示多行文字.
14467
					#回傳的結果:
14468
					#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
14469
					#$result["error"],錯誤訊息陣列.
14470
					#$result["function"],當前執行的函式名稱.
14471
					#$result["content"],語法.
14472
					#必填參數:
14473
					#$conf["string"],字串陣列,要放置的內容.
14474
					$conf["text::multiLine"]["string"]=$callShell["output"];
14475
					#可省略參數:
14476
					#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
14477
					#$conf["class"]="";
14478
					#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".
14479
					#$conf["type"]="EOL";
14480
					$multiLine=text::multiLine($conf["text::multiLine"]);
14481
					unset($conf["text::multiLine"]);
14482
 
14483
					#如過執行失敗
14484
					if($multiLine["status"]==="false"){
14485
 
14486
						#設置執行失敗
14487
						$result["status"]="false";
14488
 
14489
						#設置執行錯誤
14490
						$result["error"]=$multiLine;
14491
 
14492
						#回傳結果
14493
						return $result;
14494
 
14495
						}#if end
14496
 
14497
					#印出結果
14498
					echo $multiLine["content"];
14499
 
14500
					#繼續輸入要commit的檔案名稱
14501
					continue 2;
14502
 
14503
				#如果是 "ls del"
14504
				case "ls del":
14505
 
14506
					#印出本次commit要移除的目標
14507
					#函式說明:
14508
					#將陣列字串處理成一個個"[index] 元素內容"的格式,且[index]的寬度會依造陣列的長度而固定。
14509
					#回傳結果:
14510
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14511
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
14512
					#$result["function"],當前執行的函式名稱.
14513
					#$result["content"],處理好的陣列.
14514
					#必填參數:
14515
					#$conf["inputArray"],陣列字串,要轉換陣列.
14516
					$conf["arrays::toPrintableIndex"]["inputArray"]=$fileShouldBeDeleted;
14517
					#可省略參數:
14518
					#$conf["newLine"],字串,組合的內容是否要加換行符號,"true"代表要,"false"代表不要,預設為"ture".
14519
					#$conf["newLine"]="false";
14520
					#$conf["print"],字串,是否要直接印出來,"true"代表要,"false"代表不要,預設為"false".
14521
					$conf["arrays::toPrintableIndex"]["print"]="true";
14522
					$toPrintableIndex=arrays::toPrintableIndex($conf["arrays::toPrintableIndex"]);
14523
					unset($conf["arrays::toPrintableIndex"]);
14524
 
14525
					#如果處理錯誤
14526
					if($toPrintableIndex["status"]==="false"){
14527
 
14528
						#設置錯誤訊息
14529
						$result["error"]=$toPrintableIndex;
14530
 
14531
						#設置執行失敗
14532
						$result["status"]="false";
14533
 
14534
						#回傳結果
14535
						return $result;
14536
 
14537
						}#if end
14538
 
14539
					#繼續讓使用者輸入要commit的檔案
14540
					continue 2;
14541
 
14542
				#如果是 "ls add"
14543
				case "ls add":
14544
 
14545
					#印出本次要新增到版本控制的檔案清單
14546
					#函式說明:
14547
					#將陣列字串處理成一個個"[index] 元素內容"的格式,且[index]的寬度會依造陣列的長度而固定。
14548
					#回傳結果:
14549
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14550
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
14551
					#$result["function"],當前執行的函式名稱.
14552
					#$result["content"],處理好的陣列.
14553
					#必填參數:
14554
					#$conf["inputArray"],陣列字串,要轉換陣列.
14555
					$conf["arrays::toPrintableIndex"]["inputArray"]=$fileAdded;
14556
					#可省略參數:
14557
					#$conf["newLine"],字串,組合的內容是否要加換行符號,"true"代表要,"false"代表不要,預設為"ture".
14558
					#$conf["newLine"]="false";
14559
					#$conf["print"],字串,是否要直接印出來,"true"代表要,"false"代表不要,預設為"false".
14560
					$conf["arrays::toPrintableIndex"]["print"]="true";
14561
					$toPrintableIndex=arrays::toPrintableIndex($conf["arrays::toPrintableIndex"]);
14562
					unset($conf["arrays::toPrintableIndex"]);
14563
 
14564
					#如果處理錯誤
14565
					if($toPrintableIndex["status"]==="false"){
14566
 
14567
						#設置錯誤訊息
14568
						$result["error"]=$toPrintableIndex;
14569
 
14570
						#設置執行失敗
14571
						$result["status"]="false";
14572
 
14573
						#回傳結果
14574
						return $result;
14575
 
14576
						}#if end
14577
 
14578
					#繼續讓使用者輸入要commit的檔案
14579
					continue 2;
14580
 
14581
				#如果是 "ls cp"
14582
				case "ls cp":
14583
 
14584
					#取得本次要新增到版本控制的複製檔案清單長度
14585
					$fileCopiedCountLength=strlen(count($copyList));
14586
 
14587
					#初始化暫存要印出來的元素陣列
14588
					$tp=array();
14589
 
14590
					#有幾個本次要複製的版本控制的檔案就執行幾次
14591
					foreach($copyList as $index=>$copiedFN){
14592
 
14593
						#如果列數長度加3小於要移除檔案之計數長度
14594
						while(strlen($index)<$fileCopiedCountLength){
14595
 
14596
							#在前面加上空格
14597
							$index=" ".$index;
14598
 
14599
							}#if end
14600
 
14601
						#儲存元素內容
14602
						$tp[]="copy from ".$copiedFN["from"]." to ".$copiedFN["to"];
14603
 
14604
						}#foreach end
14605
 
14606
					#印出本次要新增到版本控制的複製檔案清單
14607
					#函式說明:
14608
					#將陣列字串處理成一個個"[index] 元素內容"的格式,且[index]的寬度會依造陣列的長度而固定。
14609
					#回傳結果:
14610
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14611
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
14612
					#$result["function"],當前執行的函式名稱.
14613
					#$result["content"],處理好的陣列.
14614
					#必填參數:
14615
					#$conf["inputArray"],陣列字串,要轉換陣列.
14616
					$conf["arrays::toPrintableIndex"]["inputArray"]=$tp;
14617
					#可省略參數:
14618
					#$conf["newLine"],字串,組合的內容是否要加換行符號,"true"代表要,"false"代表不要,預設為"ture".
14619
					#$conf["newLine"]="false";
14620
					#$conf["print"],字串,是否要直接印出來,"true"代表要,"false"代表不要,預設為"false".
14621
					$conf["arrays::toPrintableIndex"]["print"]="true";
14622
					$toPrintableIndex=arrays::toPrintableIndex($conf["arrays::toPrintableIndex"]);
14623
					unset($conf["arrays::toPrintableIndex"]);
14624
 
14625
					#如果處理錯誤
14626
					if($toPrintableIndex["status"]==="false"){
14627
 
14628
						#設置錯誤訊息
14629
						$result["error"]=$toPrintableIndex;
14630
 
14631
						#設置執行失敗
14632
						$result["status"]="false";
14633
 
14634
						#回傳結果
14635
						return $result;
14636
 
14637
						}#if end
14638
 
14639
					#繼續讓使用者輸入要commit的檔案
14640
					continue 2;
14641
 
14642
				#如果是其他數值
14643
				default:
14644
 
14645
					#不做事
14646
 
14647
				}#switch end
14648
 
14649
			#函式說明:
14650
			#將字串進行解析,變成多個參數.
14651
			#回傳結果:
14652
			#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
14653
			#$result["function"],當前執行的函式內容.
14654
			#$result["error"],錯誤訊息陣列.
14655
			#$result["content"],參數陣列.
14656
			#$result["count"],總共有幾個參數.
14657
			#必填參數:
14658
			#$conf["input"],字串,要解析成參數的字串.
14659
			$conf["stringProcess::parse"]["input"]=$input;
14660
			#可省略參數:
14661
			#無.
14662
			#參考資料:
14663
			#無.
14664
			#備註:
14665
			#無.
14666
			$parse=stringProcess::parse($conf["stringProcess::parse"]);
14667
			unset($conf["stringProcess::parse"]);
14668
 
14669
			#如果處理錯誤
14670
			if($parse["status"]==="false"){
14671
 
14672
				#debug
14673
				#var_dump(__FUNCITON__,__LINE__,$parse);
14674
 
14675
				#如果是 bash 語法錯誤
14676
				if($parse["error"][0]==="bash syntax error"){
14677
 
14678
					#提示錯誤訊息
14679
					echo $parse["error"][0].PHP_EOL;
14680
 
14681
					#提示錯誤訊息
14682
					echo $parse["error"][1]["content"][0]["error"];
14683
 
14684
					#debug
14685
					#var_dump($parse);
14686
 
14687
					#繼續讓使用者輸入要commit的檔案
14688
					continue;
14689
 
14690
					}#if end
14691
 
14692
				#設置錯誤訊息
14693
				$result["error"]=$parse;
14694
 
14695
				#設置執行失敗
14696
				$result["status"]="false";
14697
 
14698
				#回傳結果
14699
				return $result;
14700
 
14701
				}#if end
14702
 
14703
			#取得參數內容
14704
			$argv=$parse["content"];
14705
 
14706
			#取得參數數目
14707
			$argc=count($argv);
14708
 
14709
			#依照參數的數量
14710
			switch($argc){
14711
 
14712
				#如果參數數量為3
14713
				case 3:
14714
 
14715
					#判斷 $argv[0] 的內容
14716
					switch($argv[0])
14717
					{
14718
						#如果是 cp
14719
						case "cp":
14720
 
14721
							#函式說明:
14722
							#清除字串的「"」或「'」符號.
14723
							#回傳結果:
14724
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
14725
							#$result["function"],當前執行的函式內容.
14726
							#$result["error"],錯誤訊息陣列.
14727
							#$result["content"],剔除「"」或「'」符號後的字串.
14728
							#必填參數:
14729
							#$conf["str"],字串,要處理的字串.
14730
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
14731
							#可省略參數:
14732
							#無.
14733
							#參考資料:
14734
							#無.
14735
							#備註:
14736
							#無.
14737
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
14738
							unset($conf["stringProcess::clearStrSymbol"]);
14739
 
14740
							#如果失敗
14741
							if($clearStrSymbol["status"]==="false"){
14742
 
14743
								#設置執行失敗
14744
								$result["status"]="false";
14745
 
14746
								#設置執行失敗訊息
14747
								$result["error"]=$clearStrSymbol;
14748
 
14749
								#回傳結果
14750
								return $result;
14751
 
14752
								}#if end	
14753
 
14754
							#如果第二個參數代表的複製來源不存在
14755
							if(!file_exists($clearStrSymbol["content"])){
14756
 
14757
								#提示複製的來源檔案並不存在
14758
								echo "要複製的檔案「".$clearStrSymbol["content"]."」不存在!".PHP_EOL;
14759
 
14760
								#讓使用者繼續輸入要commit的項目
14761
								#continue 2;
14762
								break 2;
14763
 
14764
								}#if end
14765
 
14766
							#函式說明:
14767
							#清除字串的「"」或「'」符號.
14768
							#回傳結果:
14769
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
14770
							#$result["function"],當前執行的函式內容.
14771
							#$result["error"],錯誤訊息陣列.
14772
							#$result["content"],剔除「"」或「'」符號後的字串.
14773
							#必填參數:
14774
							#$conf["str"],字串,要處理的字串.
14775
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[2];	
14776
							#可省略參數:
14777
							#無.
14778
							#參考資料:
14779
							#無.
14780
							#備註:
14781
							#無.
14782
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
14783
							unset($conf["stringProcess::clearStrSymbol"]);
14784
 
14785
							#如果失敗
14786
							if($clearStrSymbol["status"]==="false"){
14787
 
14788
								#設置執行失敗
14789
								$result["status"]="false";
14790
 
14791
								#設置執行失敗訊息
14792
								$result["error"]=$clearStrSymbol;
14793
 
14794
								#回傳結果
14795
								return $result;
14796
 
14797
								}#if end
14798
 
14799
							#如果第三個參數代表的複製目的已經存在
14800
							if(file_exists($clearStrSymbol["content"])){
14801
 
14802
								#若不是目錄
14803
								if(!is_dir($clearStrSymbol["content"])){
14804
 
14805
									#提示複製的目的已經存在
14806
									echo "要複製到的目的檔案「".$argv[2]."」已存在!".PHP_EOL;
14807
 
14808
									#讓使用者繼續輸入要commit的項目
14809
									break 2;
14810
 
14811
									}#if end								
14812
 
14813
								#反之代表目的地是目錄
14814
								else{
14815
 
14816
									#檢查目錄是否在版本控制中
14817
 
14818
									#函式說明:
14819
									#呼叫shell執行系統命令,並取得回傳的內容.
14820
									#回傳結果:
14821
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14822
									#$result["error"],錯誤訊息陣列.
14823
									#$result["function"],當前執行的函數名稱.
14824
									#$result["argu"],使用的參數.
14825
									#$result["cmd"],執行的指令內容.
14826
									#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14827
									#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14828
									#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14829
									#$result["running"],是否還在執行.
14830
									#$result["pid"],pid.
14831
									#$result["statusCode"],執行結束後的代碼.
14832
									#必填參數:
14833
									#$conf["command"],字串,要執行的指令與.
14834
									$conf["external::callShell"]["command"]="svn";
14835
									#$conf["fileArgu"],字串,變數__FILE__的內容.
14836
									$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
14837
									#可省略參數:
14838
									#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14839
									$conf["external::callShell"]["argu"]=array("status",$argv[2]);
14840
									#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
14841
									#$conf["arguIsAddr"]=array();
14842
									#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
14843
									#$conf["plainArgu"]=array();
14844
									#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
14845
									#$conf["useApostrophe"]=array();
14846
									#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14847
									#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14848
									#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14849
									#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14850
									#$conf["enablePrintDescription"]="true";
14851
									#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14852
									#$conf["printDescription"]="";
14853
									#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
14854
									$conf["external::callShell"]["escapeshellarg"]="true";
14855
									#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
14856
									#$conf["thereIsShellVar"]=array();
14857
									#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14858
									#$conf["username"]="";
14859
									#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14860
									#$conf["password"]="";
14861
									#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14862
									#$conf["useScript"]="";
14863
									#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14864
									#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14865
									#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14866
									#$conf["inBackGround"]="";
14867
									#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
14868
									#$conf["getErr"]="false";
14869
									#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
14870
									#$conf["doNotRun"]="false";
14871
									#參考資料:
14872
									#exec=>http://php.net/manual/en/function.exec.php
14873
									#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14874
									#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14875
									#備註:
14876
									#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14877
									$callShell=external::callShell($conf["external::callShell"]);
14878
									unset($conf["external::callShell"]);
14879
 
14880
									#如果運行失敗
14881
									if($callShell["status"]==="false")
14882
									{
14883
										#設置執行失敗
14884
										$result["status"]="false";
14885
 
14886
										#設置執行錯誤
14887
										$result["error"]=$callShell;
14888
 
14889
										#回傳結果
14890
										return $result;
14891
 
14892
									}#if end
14893
 
14894
									#印出執行的cmd
14895
									echo "cmd:".$callShell["cmd"].PHP_EOL;
14896
 
14897
									#印出執行後的回傳代碼
14898
									echo "status:".$callShell["statusCode"].PHP_EOL;
14899
 
14900
									#如果不等於空陣列
14901
									if($callShell["output"]!==array()){
14902
 
14903
										#取得檔案的 status 與名稱
14904
										sscanf($callShell["output"][0],"%s %s",$sta,$fi);
14905
 
14906
										#如果狀態等於 ?
14907
										if($sta==="?"){
14908
 
14909
											#提示新增檔案到版本控制失敗
14910
											echo "目的地目錄「".$argv[2]."」不在版本控制裡面,因此無法複製過去".PHP_EOL;
14911
 
14912
											#繼續讓使用者輸入要commit的檔案
14913
											#continue 2;
14914
											break;
14915
 
14916
											}#if end
14917
 
14918
										}#if end
14919
 
14920
									#提示複製過去的目標的目的已經存在
14921
									echo "要複製的「".$argv[1]."」會放到「".$argv[2]."」目錄底下!".PHP_EOL;
14922
 
14923
									}#else end
14924
 
14925
								}#if end
14926
 
14927
							#函式說明:
14928
							#呼叫shell執行系統命令,並取得回傳的內容.
14929
							#回傳結果:
14930
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14931
							#$result["error"],錯誤訊息陣列.
14932
							#$result["function"],當前執行的函數名稱.
14933
							#$result["argu"],使用的參數.
14934
							#$result["cmd"],執行的指令內容.
14935
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14936
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14937
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14938
							#$result["running"],是否還在執行.
14939
							#$result["pid"],pid.
14940
							#$result["statusCode"],執行結束後的代碼.
14941
							#必填參數:
14942
							#$conf["command"],字串,要執行的指令與.
14943
							$conf["external::callShell"]["command"]="svn";
14944
							#$conf["fileArgu"],字串,變數__FILE__的內容.
14945
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
14946
							#可省略參數:
14947
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14948
							$conf["external::callShell"]["argu"]=array("status",$argv[1]);
14949
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
14950
							#$conf["arguIsAddr"]=array();
14951
							#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
14952
							#$conf["plainArgu"]=array();
14953
							#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
14954
							#$conf["useApostrophe"]=array();
14955
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14956
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14957
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14958
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14959
							#$conf["enablePrintDescription"]="true";
14960
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14961
							#$conf["printDescription"]="";
14962
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
14963
							$conf["external::callShell"]["escapeshellarg"]="true";
14964
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
14965
							#$conf["thereIsShellVar"]=array();
14966
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14967
							#$conf["username"]="";
14968
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14969
							#$conf["password"]="";
14970
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14971
							#$conf["useScript"]="";
14972
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14973
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14974
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14975
							#$conf["inBackGround"]="";
14976
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
14977
							#$conf["getErr"]="false";
14978
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
14979
							#$conf["doNotRun"]="false";
14980
							#參考資料:
14981
							#exec=>http://php.net/manual/en/function.exec.php
14982
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14983
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14984
							#備註:
14985
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14986
							$callShell=external::callShell($conf["external::callShell"]);
14987
							unset($conf["external::callShell"]);
14988
 
14989
							#如果運行失敗
14990
							if($callShell["status"]==="false")
14991
							{
14992
								#設置執行失敗
14993
								$result["status"]="false";
14994
 
14995
								#設置執行錯誤
14996
								$result["error"]=$callShell;
14997
 
14998
								#回傳結果
14999
								return $result;
15000
 
15001
							}#if end
15002
 
15003
							#印出執行的cmd
15004
							echo "cmd:".$callShell["cmd"].PHP_EOL;
15005
 
15006
							#印出執行後的回傳代碼
15007
							echo "status:".$callShell["statusCode"].PHP_EOL;
15008
 
15009
							#如果不等於空陣列
15010
							if($callShell["output"]!==array()){
15011
 
15012
								#取得檔案的 status 與名稱
15013
								sscanf($callShell["output"][0],"%s %s",$sta,$fi);
15014
 
15015
								#如果狀態等於 ?
15016
								if($sta==="?"){
15017
 
15018
									#提示新增檔案到版本控制失敗
15019
									#函式說明:
15020
									#清除字串的「"」或「'」符號.
15021
									#回傳結果:
15022
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15023
									#$result["function"],當前執行的函式內容.
15024
									#$result["error"],錯誤訊息陣列.
15025
									#$result["content"],剔除「"」或「'」符號後的字串.
15026
									#必填參數:
15027
									#$conf["str"],字串,要處理的字串.
15028
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15029
									#可省略參數:
15030
									#無.
15031
									#參考資料:
15032
									#無.
15033
									#備註:
15034
									#無.
15035
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15036
									unset($conf["stringProcess::clearStrSymbol"]);
15037
 
15038
									#如果運行失敗
15039
									if($clearStrSymbol["status"]==="false")
15040
									{
15041
										#設置執行失敗
15042
										$result["status"]="false";
15043
 
15044
										#設置執行失敗訊息
15045
										$result["error"]=$clearStrSymbol;
15046
 
15047
										#回傳結果
15048
										return $result;
15049
 
15050
									}#if end
15051
 
15052
									echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法複製".PHP_EOL;
15053
 
15054
									#繼續讓使用者輸入要commit的檔案
15055
									break 2;
15056
 
15057
									}#if end
15058
 
15059
								}#if end
15060
 
15061
							#如果要複製的來源與目的地有存在於本次commit要新增的項目
15062
							if(in_array($argv[2],$filesToCommit)){
15063
 
15064
								#提示不能複製本次要commit的內容
15065
								echo "不能複製本次要commit的內容".PHP_EOL;
15066
 
15067
								#讓使用者繼續輸入要commit的項目
15068
								break 2;
15069
 
15070
								}#if end
15071
 
15072
							#執行 svn cpoy 的指令
15073
							#函式說明:
15074
							#呼叫shell執行系統命令,並取得回傳的內容.
15075
							#回傳結果:
15076
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15077
							#$result["error"],錯誤訊息陣列.
15078
							#$result["function"],當前執行的函數名稱.
15079
							#$result["argu"],使用的參數.
15080
							#$result["cmd"],執行的指令內容.
15081
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15082
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15083
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15084
							#$result["running"],是否還在執行.
15085
							#$result["pid"],pid.
15086
							#$result["statusCode"],執行結束後的代碼.
15087
							#必填參數:
15088
							#$conf["command"],字串,要執行的指令與.
15089
							$conf["external::callShell"]["command"]="svn";
15090
							#$conf["fileArgu"],字串,變數__FILE__的內容.
15091
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
15092
							#可省略參數:
15093
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15094
							$conf["external::callShell"]["argu"]=array("copy",$argv[1],$argv[2]);
15095
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15096
							#$conf["arguIsAddr"]=array();
15097
							#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
15098
							#$conf["plainArgu"]=array();
15099
							#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
15100
							#$conf["useApostrophe"]=array();
15101
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15102
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15103
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15104
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15105
							#$conf["enablePrintDescription"]="true";
15106
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15107
							#$conf["printDescription"]="";
15108
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
15109
							$conf["external::callShell"]["escapeshellarg"]="true";
15110
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
15111
							#$conf["thereIsShellVar"]=array();
15112
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15113
							#$conf["username"]="";
15114
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15115
							#$conf["password"]="";
15116
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15117
							#$conf["useScript"]="";
15118
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15119
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15120
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15121
							#$conf["inBackGround"]="";
15122
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15123
							#$conf["getErr"]="false";
15124
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
15125
							#$conf["doNotRun"]="false";
15126
							#參考資料:
15127
							#exec=>http://php.net/manual/en/function.exec.php
15128
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15129
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15130
							#備註:
15131
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15132
							$callShell=external::callShell($conf["external::callShell"]);
15133
							unset($conf["external::callShell"]);
15134
 
15135
							#如果運行失敗
15136
							if($callShell["status"]==="false")
15137
							{
15138
								#設置執行失敗
15139
								$result["status"]="false";
15140
 
15141
								#設置執行錯誤
15142
								$result["error"]=$callShell;
15143
 
15144
								#回傳結果
15145
								return $result;
15146
 
15147
							}#if end
15148
 
15149
							#印出執行的cmd
15150
							echo "cmd:".$callShell["cmd"].PHP_EOL;
15151
 
15152
							#印出執行後的回傳代碼
15153
							echo "status:".$callShell["statusCode"].PHP_EOL;
15154
 
15155
							#針對每列輸出
15156
							foreach($callShell["output"] as $line){
15157
 
15158
								#印出內容
15159
								echo $line.PHP_EOL;
15160
 
15161
								}#foreach end
15162
 
15163
							#設置 $argv[2] 為本次要commit的目錄檔案
15164
 
15165
							#紀錄複製的來源與目標
15166
							$copyList[]=array("from"=>$argv[1],"to"=>$argv[2]);
15167
 
15168
							#記錄要commit的新增檔案
15169
							$filesToCommit[]=$argv[2];
15170
 
15171
							#記錄本次要新增的檔案
15172
							$fileAdded[]=$argv[2];
15173
 
15174
							#讓使用者繼續輸入要commit的項目
15175
							break 2;
15176
 
15177
						#如果是 diff
15178
						case "diff":
15179
 
15180
							#跳出 switch
15181
							break;
15182
 
15183
						default:
15184
 
15185
					}#switch end
15186
 
15187
				#如果參數數量為2
15188
				case 2:
15189
 
15190
					#判斷 $argv[0] 的內容
15191
					switch($argv[0]){
15192
 
15193
						#如果第一個參數為 "diff"
15194
						case "diff":
15195
 
15196
							#函式說明:
15197
							#清除字串的「"」或「'」符號.
15198
							#回傳結果:
15199
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15200
							#$result["function"],當前執行的函式內容.
15201
							#$result["error"],錯誤訊息陣列.
15202
							#$result["content"],剔除「"」或「'」符號後的字串.
15203
							#必填參數:
15204
							#$conf["str"],字串,要處理的字串.
15205
							$conf["str"]="";
15206
							#可省略參數:
15207
							#無.
15208
							#參考資料:
15209
							#無.
15210
							#備註:
15211
							#無.
15212
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15213
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15214
							unset($conf["stringProcess::clearStrSymbol"]);	
15215
 
15216
							#如果運行失敗
42 liveuser 15217
							if($clearStrSymbol["status"]==="false"){
15218
 
3 liveuser 15219
								#設置執行失敗
15220
								$result["status"]="false";
15221
 
15222
								#設置執行失敗訊息
15223
								$result["error"]=$clearStrSymbol;
15224
 
15225
								#回傳結果
15226
								return $result;
15227
 
42 liveuser 15228
								}#if end
3 liveuser 15229
 
15230
							#如果存在第二個參數的檔案
15231
							if(file_exists($clearStrSymbol["content"])){
15232
 
15233
								#執行command
15234
								#函式說明:
15235
								#呼叫shell執行系統命令,並取得回傳的內容.
15236
								#回傳結果:
15237
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15238
								#$result["error"],錯誤訊息陣列.
15239
								#$result["function"],當前執行的函數名稱.
15240
								#$result["argu"],使用的參數.
15241
								#$result["cmd"],執行的指令內容.
15242
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15243
								#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15244
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15245
								#$result["running"],是否還在執行.
15246
								#$result["pid"],pid.
15247
								#$result["statusCode"],執行結束後的代碼.
15248
								#必填參數:
15249
								#$conf["command"],字串,要執行的指令與.
15250
								$conf["external::callShell"]["command"]="svn";
15251
								#$conf["fileArgu"],字串,變數__FILE__的內容.
15252
								$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
15253
								#可省略參數:
15254
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15255
								$conf["external::callShell"]["argu"]=array("diff",$argv[1]);
15256
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15257
								#$conf["arguIsAddr"]=array();
15258
								#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
15259
								#$conf["plainArgu"]=array();
15260
								#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
15261
								#$conf["useApostrophe"]=array();
15262
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15263
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15264
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15265
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15266
								#$conf["enablePrintDescription"]="true";
15267
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15268
								#$conf["printDescription"]="";
15269
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
15270
								$conf["external::callShell"]["escapeshellarg"]="true";
15271
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
15272
								#$conf["thereIsShellVar"]=array();
15273
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15274
								#$conf["username"]="";
15275
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15276
								#$conf["password"]="";
15277
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15278
								#$conf["useScript"]="";
15279
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15280
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15281
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15282
								#$conf["inBackGround"]="";
15283
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15284
								#$conf["getErr"]="false";
15285
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
15286
								#$conf["doNotRun"]="false";
15287
								#參考資料:
15288
								#exec=>http://php.net/manual/en/function.exec.php
15289
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15290
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15291
								#備註:
15292
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15293
								$callShell=external::callShell($conf["external::callShell"]);
15294
								unset($conf["external::callShell"]);
15295
 
15296
								#如果運行失敗
42 liveuser 15297
								if($callShell["status"]==="false"){
15298
 
3 liveuser 15299
									#設置執行失敗
15300
									$result["status"]="false";
15301
 
15302
									#設置執行錯誤
15303
									$result["error"]=$callShell;
15304
 
15305
									#回傳結果
15306
									return $result;
15307
 
42 liveuser 15308
									}#if end
3 liveuser 15309
 
15310
								#印出執行的cmd
15311
								echo "cmd:".$callShell["cmd"].PHP_EOL;
15312
 
15313
								#印出執行後的回傳代碼
15314
								echo "status:".$callShell["statusCode"].PHP_EOL;
15315
 
15316
								#針對每列輸出
15317
								foreach($callShell["output"] as $line){
15318
 
15319
									#印出內容
15320
									echo $line.PHP_EOL;
15321
 
15322
									}#foreach end
15323
 
15324
								#清空output
15325
								unset($output);
15326
 
15327
								#繼續讓使用者輸入要commit的檔案
15328
								break 2;
15329
 
15330
								}#if end
15331
 
15332
							#反之
15333
							else{
15334
 
15335
								#提示錯誤
15336
								echo "檔案「".$clearStrSymbol["content"]."」不存在".PHP_EOL;
15337
 
15338
								#繼續讓使用者輸入要commit的檔案
15339
								break 2;
15340
 
15341
								}#else end
15342
 
15343
							#跳出switch
15344
							break;
15345
 
15346
						#如果第一個參數為 "add"
15347
						#針對軟連結也ok?
15348
						case "add":
15349
 
15350
							#函式說明:
15351
							#清除字串的「"」或「'」符號.
15352
							#回傳結果:
15353
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15354
							#$result["function"],當前執行的函式內容.
15355
							#$result["error"],錯誤訊息陣列.
15356
							#$result["content"],剔除「"」或「'」符號後的字串.
15357
							#必填參數:
15358
							#$conf["str"],字串,要處理的字串.
15359
							$conf["stringProcess::clearStrSymbol"]["str"]="$argv[1]";
15360
							#可省略參數:
15361
							#無.
15362
							#參考資料:
15363
							#無.
15364
							#備註:
15365
							#無.
15366
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15367
 
15368
							#如果運行失敗
15369
							if($clearStrSymbol["status"]==="false")
15370
							{
15371
								#設置執行失敗
15372
								$result["status"]="false";
15373
 
15374
								#設置執行失敗訊息
15375
								$result["error"]=$clearStrSymbol;
15376
 
15377
								#回傳結果
15378
								return $result;
15379
 
15380
							}#if end
15381
 
15382
							#若第二個參數的名稱檔案存在
15383
							if(file_exists($clearStrSymbol["content"])){
15384
 
15385
								#若該檔案存在於要新增檔案的清單中
15386
								if(in_array($argv[1],$fileAdded)){
15387
 
15388
									#函式說明:
15389
									#清除字串的「"」或「'」符號.
15390
									#回傳結果:
15391
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15392
									#$result["function"],當前執行的函式內容.
15393
									#$result["error"],錯誤訊息陣列.
15394
									#$result["content"],剔除「"」或「'」符號後的字串.
15395
									#必填參數:
15396
									#$conf["str"],字串,要處理的字串.
15397
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15398
									#可省略參數:
15399
									#無.
15400
									#參考資料:
15401
									#無.
15402
									#備註:
15403
									#無.
15404
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15405
									unset($conf["stringProcess::clearStrSymbol"]);
15406
 
15407
									#如果運行失敗
15408
									if($clearStrSymbol["status"]==="false")
15409
									{
15410
										#設置執行失敗
15411
										$result["status"]="false";
15412
 
15413
										#設置執行失敗訊息
15414
										$result["error"]=$clearStrSymbol;
15415
 
15416
										#回傳結果
15417
										return $result;
15418
 
15419
									}#if end
15420
 
15421
									#提示要該檔案已經在移除的清單了
15422
									echo "檔案「".$clearStrSymbol["content"]."」已經在要新增的清單裡面了".PHP_EOL;
15423
 
15424
									#繼續讓使用者輸入要commit的檔案
15425
									break 2;
15426
 
15427
									}#if end
15428
 
15429
								#函式說明:
15430
								#呼叫shell執行系統命令,並取得回傳的內容.
15431
								#回傳的結果:
15432
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15433
								#$result["error"],錯誤訊息陣列.
15434
								#$result["function"],當前執行的函式名稱.
15435
								#$result["argu"],使用的參數.
15436
								#$result["cmd"],執行的指令內容.
15437
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15438
								#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15439
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15440
								#$result["running"],是否還在執行.
15441
								#$result["pid"],pid.
15442
								#$result["statusCode"],執行結束後的代碼.
15443
								#必填參數:
15444
								#$conf["command"],字串,要執行的指令與.
15445
								$conf["external::callShell"]["command"]="svn";
15446
								#$conf["fileArgu"],字串,變數__FILE__的內容.
15447
								$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
15448
								#可省略參數:
15449
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15450
								$conf["external::callShell"]["argu"]=array("add",$argv[1]);
15451
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15452
								#$conf["arguIsAddr"]=array();
15453
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15454
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15455
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15456
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15457
								#$conf["enablePrintDescription"]="true";
15458
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15459
								#$conf["printDescription"]="";
15460
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
15461
								$conf["external::callShell"]["escapeshellarg"]="true";
15462
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15463
								#$conf["username"]="";
15464
								#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15465
								#$conf["password"]="";
15466
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15467
								#$conf["useScript"]="";
15468
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15469
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15470
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15471
								#$conf["inBackGround"]="";
15472
								#備註:
15473
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15474
								#參考資料:
15475
								#exec=>http://php.net/manual/en/function.exec.php
15476
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15477
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15478
								$callShell=external::callShell($conf["external::callShell"]);
15479
								unset($conf["external::callShell"]);
15480
 
15481
								#如果執行失敗
15482
								if($callShell["status"]==="false"){
15483
 
15484
									#設置執行失敗
15485
									$result["status"]="false";
15486
 
15487
									#設置執行錯誤
15488
									$result["error"]=$callShell;
15489
 
15490
									#回傳結果
15491
									return $result;
15492
 
15493
									}#if end
15494
 
15495
								#印出執行的cmd
15496
								echo "cmd:".$callShell["cmd"].PHP_EOL;
15497
 
15498
								#印出執行後的回傳代碼
15499
								echo "status:".$callShell["statusCode"].PHP_EOL;
15500
 
15501
								#針對每列輸出
15502
								foreach($callShell["output"] as $line){
15503
 
15504
									#印出內容
15505
									echo $line.PHP_EOL;
15506
 
15507
									}#foreach end
15508
 
15509
								#如果新增檔案到版本控制成功
15510
								if($callShell["statusCode"]===0){
15511
 
15512
									#記錄要commit的新增檔案
15513
									$filesToCommit[]=$argv[1];
15514
 
15515
									#記錄本次要新增的檔案
15516
									$fileAdded[]=$argv[1];
15517
 
15518
									#函式說明:
15519
									#清除字串的「"」或「'」符號.
15520
									#回傳結果:
15521
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15522
									#$result["function"],當前執行的函式內容.
15523
									#$result["error"],錯誤訊息陣列.
15524
									#$result["content"],剔除「"」或「'」符號後的字串.
15525
									#必填參數:
15526
									#$conf["str"],字串,要處理的字串.
15527
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15528
									#可省略參數:
15529
									#無.
15530
									#參考資料:
15531
									#無.
15532
									#備註:
15533
									#無.									
15534
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15535
									unset($conf["stringProcess::clearStrSymbol"]);
15536
 
15537
									#如果執行失敗
15538
									if($clearStrSymbol["status"]==="false"){
15539
 
15540
										#設置執行失敗
15541
										$result["status"]="false";
15542
 
15543
										#設置執行失敗訊息
15544
										$result["error"]=$clearStrSymbol;
15545
 
15546
										#回傳結果
15547
										return $result;
15548
 
15549
										}#if end
15550
 
15551
									#提示已經新增
15552
									echo "已新增檔案「".$clearStrSymbol["content"]."」到版本控制".PHP_EOL;
15553
 
15554
									}#if end
15555
 
15556
								#反之新增檔案到版本控制失敗
15557
								else{
15558
 
15559
									#函式說明:
15560
									#清除字串的「"」或「'」符號.
15561
									#回傳結果:
15562
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15563
									#$result["function"],當前執行的函式內容.
15564
									#$result["error"],錯誤訊息陣列.
15565
									#$result["content"],剔除「"」或「'」符號後的字串.
15566
									#必填參數:
15567
									#$conf["str"],字串,要處理的字串.
15568
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15569
									#可省略參數:
15570
									#無.
15571
									#參考資料:
15572
									#無.
15573
									#備註:
15574
									#無									
15575
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15576
									unset($conf["stringProcess::clearStrSymbol"]);
15577
 
15578
									#如果執行失敗
15579
									if($clearStrSymbol["status"]==="false"){
15580
 
15581
										#設置執行失敗
15582
										$result["status"]="false";
15583
 
15584
										#設置執行失敗訊息
15585
										$result["error"]=$clearStrSymbol;
15586
 
15587
										#回傳結果
15588
										return $result;
15589
 
15590
										}#if end
15591
 
15592
									#提示新增檔案到版本控制失敗
15593
									echo "新增檔案「".$clearStrSymbol["content"]."」到版本控制失敗".PHP_EOL;
15594
 
15595
									}#else end
15596
 
15597
								#繼續讓使用者輸入要commit的檔案
15598
								break 2;
15599
 
15600
								}#if end
15601
 
15602
							#跳出switch
15603
							break;
15604
 
15605
						#如果第一個參數為 "del"
15606
						case "del":
15607
 
15608
							#函式說明:
15609
							#清除字串的「"」或「'」符號.
15610
							#回傳結果:
15611
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15612
							#$result["function"],當前執行的函式內容.
15613
							#$result["error"],錯誤訊息陣列.
15614
							#$result["content"],剔除「"」或「'」符號後的字串.
15615
							#必填參數:
15616
							#$conf["str"],字串,要處理的字串.
15617
							$conf["str"]="";
15618
							#可省略參數:
15619
							#無.
15620
							#參考資料:
15621
							#無.
15622
							#備註:
15623
							#無.
15624
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15625
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15626
							unset($conf["stringProcess::clearStrSymbol"]);
15627
 
15628
							#如果執行失敗
15629
							if($clearStrSymbol["status"]==="false"){
15630
 
15631
								#設置執行失敗
15632
								$result["status"]="false";
15633
 
15634
								#設置執行失敗訊息
15635
								$result["error"]=$clearStrSymbol;
15636
 
15637
								#回傳結果
15638
								return $result;
15639
 
15640
								}#if end
15641
 
15642
							#函式說明:
15643
							#檢查多個檔案與資料夾是否存在.
15644
							#回傳的結果:
15645
							#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
15646
							#$result["error"],錯誤訊息陣列.
15647
							#$resutl["function"],當前執行的涵式名稱.
15648
							#$result["argu"],使用的參數.
15649
							#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
15650
							#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
15651
							#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
15652
							#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
15653
							#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
15654
							#必填參數:
15655
							#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
15656
							$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($clearStrSymbol["content"]);
15657
							#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15658
							$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
15659
							#可省略參數:
15660
							#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
15661
							#$conf["disableWebSearch"]="false";
15662
							#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
15663
							#$conf["userDir"]="true";
15664
							#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
15665
							$conf["fileAccess::checkMultiFileExist"]["web"]="false";
15666
							#參考資料:
15667
							#http://php.net/manual/en/function.file-exists.php
15668
							#http://php.net/manual/en/control-structures.foreach.php
15669
							#備註:
15670
							#函數file_exists檢查的路徑為檔案系統的路徑
15671
							#$result["varName"][$i]結果未實作
15672
							$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
15673
							unset($conf["fileAccess::checkMultiFileExist"]);
15674
 
15675
							#如果執行失敗
15676
							if($checkMultiFileExist["status"]==="false"){
15677
 
15678
								#設置執行失敗
15679
								$result["status"]="false";
15680
 
15681
								#設置執行失敗訊息
15682
								$result["error"]=$checkMultiFileExist;
15683
 
15684
								#回傳結果
15685
								return $result;
15686
 
15687
								}#if end
15688
 
15689
							#如果檔案不存在
15690
							if($checkMultiFileExist["allExist"]==="false"){
15691
 
15692
								#函式說明:
15693
								#清除字串的「"」或「'」符號.
15694
								#回傳結果:
15695
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15696
								#$result["function"],當前執行的函式內容.
15697
								#$result["error"],錯誤訊息陣列.
15698
								#$result["content"],剔除「"」或「'」符號後的字串.
15699
								#必填參數:
15700
								#$conf["str"],字串,要處理的字串.
15701
								$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15702
								#可省略參數:
15703
								#無.
15704
								#參考資料:
15705
								#無.
15706
								#備註:
15707
								#無.								
15708
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15709
								unset($conf["stringProcess::clearStrSymbol"]);
15710
 
15711
								#如果運行失敗
15712
								if($clearStrSymbol["status"]==="false")
15713
								{
15714
									#設置執行失敗
15715
									$result["status"]="false";
15716
 
15717
									#設置執行失敗訊息
15718
									$result["error"]=$clearStrSymbol;
15719
 
15720
									#回傳結果
15721
									return $result;
15722
 
15723
								}#if end
15724
 
15725
								#提示新增檔案到版本控制失敗
15726
								echo "檔案「".$clearStrSymbol["content"]."」不存在".PHP_EOL;
15727
 
15728
								#繼續讓使用者輸入要commit的檔案
15729
								break 2;
15730
 
15731
								}#if end
15732
 
15733
							#若第二個參數的名稱檔案存在
15734
							else{
15735
 
15736
								#如果要移除的檔案是本次要新增的版本控制的檔案
15737
								if(in_array($argv[1],$fileAdded)){
15738
 
15739
									#提示要新增到版本控制的檔案不能在本次commit移除
15740
									echo "檔案「".$clearStrSymbol["content"]."」不能在本次commit移除".PHP_EOL;
15741
 
15742
									#繼續讓使用者輸入要commit的檔案
15743
									break 2;
15744
 
15745
									}#if end
15746
 
15747
								#如果該檔案已經是要移除的了
15748
								if(in_array($argv[1],$fileShouldBeDeleted)){
15749
 
15750
									#提示要該檔案已經在移除的清單了
15751
									echo "檔案「".$clearStrSymbol["content"]."」已經在移除的清單裡面了".PHP_EOL;
15752
 
15753
									#繼續讓使用者輸入要commit的檔案
15754
									break 2;
15755
 
15756
									}#if end
15757
 
15758
								#檢查要移除的檔案是否在版本控制中
15759
								#函式說明:
15760
								#呼叫shell執行系統命令,並取得回傳的內容.
15761
								#回傳結果:
15762
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15763
								#$result["error"],錯誤訊息陣列.
15764
								#$result["function"],當前執行的函數名稱.
15765
								#$result["argu"],使用的參數.
15766
								#$result["cmd"],執行的指令內容.
15767
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15768
								#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15769
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15770
								#$result["running"],是否還在執行.
15771
								#$result["pid"],pid.
15772
								#$result["statusCode"],執行結束後的代碼.
15773
								#必填參數:
15774
								#$conf["command"],字串,要執行的指令與.
15775
								$conf["external::callShell"]["command"]="svn";
15776
								#$conf["fileArgu"],字串,變數__FILE__的內容.
15777
								$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
15778
								#可省略參數:
15779
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15780
								$conf["external::callShell"]["argu"]=array("status",$argv[1]);
15781
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15782
								#$conf["arguIsAddr"]=array();
15783
								#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
15784
								#$conf["plainArgu"]=array();
15785
								#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
15786
								#$conf["useApostrophe"]=array();
15787
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15788
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15789
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15790
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15791
								#$conf["enablePrintDescription"]="true";
15792
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15793
								#$conf["printDescription"]="";
15794
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
15795
								$conf["external::callShell"]["escapeshellarg"]="true";
15796
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
15797
								#$conf["thereIsShellVar"]=array();
15798
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15799
								#$conf["username"]="";
15800
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15801
								#$conf["password"]="";
15802
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15803
								#$conf["useScript"]="";
15804
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15805
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15806
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15807
								#$conf["inBackGround"]="";
15808
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15809
								#$conf["getErr"]="false";
15810
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
15811
								#$conf["doNotRun"]="false";
15812
								#參考資料:
15813
								#exec=>http://php.net/manual/en/function.exec.php
15814
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15815
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15816
								#備註:
15817
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15818
								$callShell=external::callShell($conf["external::callShell"]);
15819
								unset($conf["external::callShell"]);
15820
 
15821
								#如果運行失敗
15822
								if($callShell["status"]==="false")
15823
								{
15824
									#設置執行失敗
15825
									$result["status"]="false";
15826
 
15827
									#設置執行錯誤
15828
									$result["error"]=$callShell;
15829
 
15830
									#回傳結果
15831
									return $result;
15832
 
15833
								}#if end
15834
 
15835
								#印出執行的cmd
15836
								echo "cmd:".$callShell["cmd"].PHP_EOL;
15837
 
15838
								#印出執行後的回傳代碼
15839
								echo "status:".$callShell["statusCode"].PHP_EOL;
15840
 
15841
								#debug
15842
								#var_dump(__LINE__,$callShell["output"]);
15843
 
15844
								#如果不等於空陣列
15845
								if($callShell["output"]!==array()){
15846
 
15847
									#取得檔案的 status 與名稱
15848
									sscanf($callShell["output"][0],"%s %s",$sta,$fi);
15849
 
15850
									#如果狀態等於 ?
15851
									if($sta==="?"){
15852
 
15853
 
15854
										#函式說明:
15855
										#清除字串的「"」或「'」符號.
15856
										#回傳結果:
15857
										#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15858
										#$result["function"],當前執行的函式內容.
15859
										#$result["error"],錯誤訊息陣列.
15860
										#$result["content"],剔除「"」或「'」符號後的字串.
15861
										#必填參數:
15862
										#$conf["str"],字串,要處理的字串.
15863
										$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15864
										#可省略參數:
15865
										#無.
15866
										#參考資料:
15867
										#無.
15868
										#備註:
15869
										#無.
15870
										$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15871
										unset($conf["stringProcess::clearStrSymbol"]);	
15872
 
15873
										#如果運行失敗
15874
										if($clearStrSymbol["status"]==="false")
15875
										{
15876
											#設置執行失敗
15877
											$result["status"]="false";
15878
 
15879
											#設置執行失敗訊息
15880
											$result["error"]=$clearStrSymbol;
15881
 
15882
											#回傳結果
15883
											return $result;
15884
 
15885
										}#if end
15886
 
15887
										#提示新增檔案到版本控制失敗
15888
										echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法移除之".PHP_EOL;
15889
 
15890
										#繼續讓使用者輸入要commit的檔案
15891
										break 2;
15892
 
15893
										}#if end
15894
 
15895
									}#if end
15896
 
15897
								#取得要移除的檔案
15898
								$fileShouldBeDeleted[]=$argv[1];
15899
 
15900
								#記錄要commit的檔案
15901
								$filesToCommit[]=$argv[1];
15902
 
15903
								#繼續讓使用者輸入要commit的檔案
15904
								#continue 2;
15905
								break 2;
15906
 
15907
								}#if end
15908
 
15909
							#繼續讓使用者輸入要commit的檔案
15910
							break 2;
15911
 
15912
						#如果第一個參數是 "undel"
15913
						case "undel":
15914
 
15915
							#如果該檔案是在要移除的清單裡面
15916
							if(in_array($argv[1],$fileShouldBeDeleted)){
15917
 
15918
								#依據每個要commit的目標
15919
								foreach($filesToCommit as $index=>$target){
15920
 
15921
									#如果是 $argv[1]
15922
									if($target===$argv[1]){
15923
 
15924
										#移除之
15925
										unset($filesToCommit[$index]);
15926
 
15927
										}#if end
15928
 
15929
									}#foreach
15930
 
15931
								#依據每個要移除的目標
15932
								foreach($fileShouldBeDeleted as $index=>$target){
15933
 
15934
									#如果是 $argv[1]
15935
									if($target===$argv[1]){
15936
 
15937
										#移除之
15938
										unset($fileShouldBeDeleted[$index]);
15939
 
15940
										}#if end
15941
 
15942
									}#foreach
15943
 
15944
								#函式說明:
15945
								#清除字串的「"」或「'」符號.
15946
								#回傳結果:
15947
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15948
								#$result["function"],當前執行的函式內容.
15949
								#$result["error"],錯誤訊息陣列.
15950
								#$result["content"],剔除「"」或「'」符號後的字串.
15951
								#必填參數:
15952
								#$conf["str"],字串,要處理的字串.
15953
								$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15954
								#可省略參數:
15955
								#無.
15956
								#參考資料:
15957
								#無.
15958
								#備註:
15959
								#無.								
15960
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15961
								unset($conf["stringProcess::clearStrSymbol"]);
15962
 
15963
								#如果運行失敗
15964
								if($clearStrSymbol["status"]==="false")
15965
								{
15966
									#設置執行失敗
15967
									$result["status"]="false";
15968
 
15969
									#設置執行失敗訊息
15970
									$result["error"]=$clearStrSymbol;
15971
 
15972
									#回傳結果
15973
									return $result;
15974
 
15975
								}#if end
15976
 
15977
								#提示目已經取消移除
15978
								echo "檔案「".$clearStrSymbol["content"]."」已不在要移除的清單裡面了".PHP_EOL;
15979
 
15980
								#繼續讓使用者輸入要commit的檔案
15981
								break 2;
15982
 
15983
								}#if end
15984
 
15985
							#函式說明:
15986
							#清除字串的「"」或「'」符號.
15987
							#回傳結果:
15988
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15989
							#$result["function"],當前執行的函式內容.
15990
							#$result["error"],錯誤訊息陣列.
15991
							#$result["content"],剔除「"」或「'」符號後的字串.
15992
							#必填參數:
15993
							#$conf["str"],字串,要處理的字串.
15994
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15995
							#可省略參數:
15996
							#無.
15997
							#參考資料:
15998
							#無.
15999
							#備註:
16000
							#無.							
16001
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16002
							unset($conf["stringProcess::clearStrSymbol"]);
16003
 
16004
							#如果運行失敗
16005
							if($clearStrSymbol["status"]==="false")
16006
							{
16007
								#設置執行失敗
16008
								$result["status"]="false";
16009
 
16010
								#設置執行失敗訊息
16011
								$result["error"]=$clearStrSymbol;
16012
 
16013
								#回傳結果
16014
								return $result;
16015
 
16016
							}#if end
16017
 
16018
							#提示目標沒有在要移除的清單裡面
16019
							echo "檔案「".$clearStrSymbol["content"]."」不在要移除的清單裡面".PHP_EOL;
16020
 
16021
							#繼續讓使用者輸入要commit的檔案
16022
							break 2;
16023
 
16024
						#如果第一個參數是 "unci"
16025
						case "unci":
16026
 
16027
							#如果該檔案是在要commit的清單裡面
16028
							if(in_array($argv[1],$filesToCommit)){
16029
 
16030
								#依據每個要commit的目標
16031
								foreach($filesToCommit as $index=>$target){
16032
 
16033
									#如果是 $argv[1]
16034
									if($target===$argv[1]){
16035
 
16036
										#移除之
16037
										unset($filesToCommit[$index]);
16038
 
16039
										}#if end
16040
 
16041
									}#foreach
16042
 
16043
								#依據每個要移除的目標
16044
								foreach($fileShouldBeDeleted as $index=>$target){
16045
 
16046
									#如果是 $argv[1]
16047
									if($target===$argv[1]){
16048
 
16049
										#移除之
16050
										unset($fileShouldBeDeleted[$index]);
16051
 
16052
										}#if end
16053
 
16054
									}#foreach
16055
 
16056
								#依據每個要新增的目標
16057
								foreach($fileAdded as $index=>$target){
16058
 
16059
									#如果是 $argv[1]
16060
									if($target===$argv[1]){
16061
 
16062
										#函式說明:
16063
										#呼叫shell執行系統命令,並取得回傳的內容.
16064
										#回傳結果:
16065
										#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16066
										#$result["error"],錯誤訊息陣列.
16067
										#$result["function"],當前執行的函數名稱.
16068
										#$result["argu"],使用的參數.
16069
										#$result["cmd"],執行的指令內容.
16070
										#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16071
										#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16072
										#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16073
										#$result["running"],是否還在執行.
16074
										#$result["pid"],pid.
16075
										#$result["statusCode"],執行結束後的代碼.
16076
										#必填參數:
16077
										#$conf["command"],字串,要執行的指令與.
16078
										$conf["external::callShell"]["command"]="svn";
16079
										#$conf["fileArgu"],字串,變數__FILE__的內容.
16080
										$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16081
										#可省略參數:
16082
										#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16083
										$conf["external::callShell"]["argu"]=array("revert","--depth","infinity",$argv[1]);
16084
										#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16085
										#$conf["arguIsAddr"]=array();
16086
										#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16087
										#$conf["plainArgu"]=array();
16088
										#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16089
										#$conf["useApostrophe"]=array();
16090
										#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16091
										#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16092
										#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16093
										#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16094
										#$conf["enablePrintDescription"]="true";
16095
										#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16096
										#$conf["printDescription"]="";
16097
										#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16098
										$conf["external::callShell"]["escapeshellarg"]="true";
16099
										#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16100
										#$conf["thereIsShellVar"]=array();
16101
										#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16102
										#$conf["username"]="";
16103
										#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16104
										#$conf["password"]="";
16105
										#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16106
										#$conf["useScript"]="";
16107
										#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16108
										#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16109
										#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16110
										#$conf["inBackGround"]="";
16111
										#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16112
										#$conf["getErr"]="false";
16113
										#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16114
										#$conf["doNotRun"]="false";
16115
										#參考資料:
16116
										#exec=>http://php.net/manual/en/function.exec.php
16117
										#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16118
										#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16119
										#備註:
16120
										#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16121
										$callShell=external::callShell($conf["external::callShell"]);
16122
										unset($conf["external::callShell"]);
16123
 
16124
										#如果運行失敗
16125
										if($callShell["status"]==="false")
16126
										{
16127
											#設置執行失敗
16128
											$result["status"]="false";
16129
 
16130
											#設置執行錯誤
16131
											$result["error"]=$callShell;
16132
 
16133
											#回傳結果
16134
											return $result;
16135
 
16136
										}#if end
16137
 
16138
										#印出執行的cmd
16139
										echo "cmd:".$callShell["cmd"].PHP_EOL;
16140
 
16141
										#印出執行後的回傳代碼
16142
										echo "status:".$callShell["statusCode"].PHP_EOL;
16143
 
16144
										#移除之
16145
										unset($fileAdded[$index]);
16146
 
16147
										}#if end
16148
 
16149
									}#foreach
16150
 
16151
								#函式說明:
16152
								#清除字串的「"」或「'」符號.
16153
								#回傳結果:
16154
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16155
								#$result["function"],當前執行的函式內容.
16156
								#$result["error"],錯誤訊息陣列.
16157
								#$result["content"],剔除「"」或「'」符號後的字串.
16158
								#必填參數:
16159
								#$conf["str"],字串,要處理的字串.
16160
								$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16161
								#可省略參數:
16162
								#無.
16163
								#參考資料:
16164
								#無.
16165
								#備註:
16166
								#無.
16167
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16168
								unset($conf["stringProcess::clearStrSymbol"]);
16169
 
16170
								#如果運行失敗
16171
								if($clearStrSymbol["status"]==="false")
16172
								{
16173
									#設置執行失敗
16174
									$result["status"]="false";
16175
 
16176
									#設置執行失敗訊息
16177
									$result["error"]=$clearStrSymbol;
16178
 
16179
									#回傳結果
16180
									return $result;
16181
 
16182
								}#if end
16183
 
16184
								#提示目已經取消移除
16185
								echo "檔案「".$clearStrSymbol["content"]."」已不在要commit的清單裡面了".PHP_EOL;
16186
 
16187
								}#if end
16188
 
16189
							#反之
16190
							else{
16191
 
16192
								#函式說明:
16193
								#清除字串的「"」或「'」符號.
16194
								#回傳結果:
16195
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16196
								#$result["function"],當前執行的函式內容.
16197
								#$result["error"],錯誤訊息陣列.
16198
								#$result["content"],剔除「"」或「'」符號後的字串.
16199
								#必填參數:
16200
								#$conf["str"],字串,要處理的字串.
16201
								$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16202
								#可省略參數:
16203
								#無.
16204
								#參考資料:
16205
								#無.
16206
								#備註:
16207
								#無.
16208
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16209
								unset($conf["stringProcess::clearStrSymbol"]);
16210
 
16211
								#如果運行失敗
16212
								if($clearStrSymbol["status"]==="false")
16213
								{
16214
									#設置執行失敗
16215
									$result["status"]="false";
16216
 
16217
									#設置執行失敗訊息
16218
									$result["error"]=$clearStrSymbol;
16219
 
16220
									#回傳結果
16221
									return $result;
16222
 
16223
								}#if end
16224
 
16225
								#提示目標沒有在要移除的清單裡面
16226
								echo "檔案「".$clearStrSymbol["content"]."」不在要commit的清單裡面".PHP_EOL;
16227
 
16228
								}#else end
16229
 
16230
							#繼續讓使用者輸入要commit的檔案
16231
							#continue 2;
16232
							break 2;
16233
 
16234
						#如果第一個參數為 "log"
16235
						case "log":
16236
 
16237
							#函式說明:
16238
							#清除字串的「"」或「'」符號.
16239
							#回傳結果:
16240
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16241
							#$result["function"],當前執行的函式內容.
16242
							#$result["error"],錯誤訊息陣列.
16243
							#$result["content"],剔除「"」或「'」符號後的字串.
16244
							#必填參數:
16245
							#$conf["str"],字串,要處理的字串.
16246
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16247
							#可省略參數:
16248
							#無.
16249
							#參考資料:
16250
							#無.
16251
							#備註:
66 liveuser 16252
							#無.
3 liveuser 16253
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16254
							unset($conf["stringProcess::clearStrSymbol"]);
16255
 
16256
							#如果運行失敗
66 liveuser 16257
							if($clearStrSymbol["status"]==="false"){
16258
 
3 liveuser 16259
								#設置執行失敗
16260
								$result["status"]="false";
16261
 
16262
								#設置執行失敗訊息
16263
								$result["error"]=$clearStrSymbol;
16264
 
16265
								#回傳結果
16266
								return $result;
16267
 
66 liveuser 16268
								}#if end
3 liveuser 16269
 
16270
							#如果檔案不存在
16271
							if(!file_exists($clearStrSymbol["content"])){
16272
 
16273
								#提示檔案不存在
16274
								echo "要查詢commmit記錄的檔案「".$clearStrSymbol["content"]."」並不存在".PHP_EOL;
16275
 
16276
								#繼續讓使用者輸入要commit的檔案
16277
								break 2;
16278
 
16279
								}#if end
16280
 
16281
							#檢查要查commit記錄的檔案是否在版本控制中
16282
 
16283
							#函式說明:
16284
							#呼叫shell執行系統命令,並取得回傳的內容.
16285
							#回傳結果:
16286
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16287
							#$result["error"],錯誤訊息陣列.
16288
							#$result["function"],當前執行的函數名稱.
16289
							#$result["argu"],使用的參數.
16290
							#$result["cmd"],執行的指令內容.
16291
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16292
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16293
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16294
							#$result["running"],是否還在執行.
16295
							#$result["pid"],pid.
16296
							#$result["statusCode"],執行結束後的代碼.
16297
							#必填參數:
16298
							#$conf["command"],字串,要執行的指令與.
16299
							$conf["external::callShell"]["command"]="svn";
16300
							#$conf["fileArgu"],字串,變數__FILE__的內容.
16301
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16302
							#可省略參數:
16303
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16304
							$conf["external::callShell"]["argu"]=array("status",$argv[1]);
16305
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16306
							#$conf["arguIsAddr"]=array();
16307
							#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16308
							#$conf["plainArgu"]=array();
16309
							#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16310
							#$conf["useApostrophe"]=array();
16311
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16312
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16313
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16314
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16315
							#$conf["enablePrintDescription"]="true";
16316
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16317
							#$conf["printDescription"]="";
16318
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16319
							$conf["external::callShell"]["escapeshellarg"]="true";
16320
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16321
							#$conf["thereIsShellVar"]=array();
16322
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16323
							#$conf["username"]="";
16324
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16325
							#$conf["password"]="";
16326
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16327
							#$conf["useScript"]="";
16328
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16329
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16330
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16331
							#$conf["inBackGround"]="";
16332
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16333
							#$conf["getErr"]="false";
16334
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16335
							#$conf["doNotRun"]="false";
16336
							#參考資料:
16337
							#exec=>http://php.net/manual/en/function.exec.php
16338
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16339
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16340
							#備註:
16341
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16342
							$callShell=external::callShell($conf["external::callShell"]);
16343
							unset($conf["external::callShell"]);
16344
 
16345
							#如果運行失敗
16346
							if($callShell["status"]==="false")
16347
							{
16348
								#設置執行失敗
16349
								$result["status"]="false";
16350
 
16351
								#設置執行錯誤
16352
								$result["error"]=$callShell;
16353
 
16354
								#回傳結果
16355
								return $result;
16356
 
16357
							}#if end
16358
 
16359
							#印出執行的cmd
16360
							echo "cmd:".$callShell["cmd"].PHP_EOL;
16361
 
16362
							#印出執行後的回傳代碼
16363
							echo "status:".$callShell["statusCode"].PHP_EOL;
16364
 
16365
							#如果不等於空陣列
16366
							if($callShell["output"]!==array()){
16367
 
16368
								#取得檔案的 status 與名稱
16369
								sscanf($callShell["output"][0],"%s %s",$sta,$fi);
16370
 
16371
								#如果狀態等於 ?
16372
								if($sta==="?"){
16373
 
16374
									#函式說明:
16375
									#清除字串的「"」或「'」符號.
16376
									#回傳結果:
16377
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16378
									#$result["function"],當前執行的函式內容.
16379
									#$result["error"],錯誤訊息陣列.
16380
									#$result["content"],剔除「"」或「'」符號後的字串.
16381
									#必填參數:
16382
									#$conf["str"],字串,要處理的字串.
16383
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16384
									#可省略參數:
16385
									#無.
16386
									#參考資料:
16387
									#無.
16388
									#備註:
16389
									#無.
16390
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16391
									unset($conf["stringProcess::clearStrSymbol"]);
16392
 
16393
									#如果運行失敗
16394
									if($clearStrSymbol["status"]==="false")
16395
									{
16396
										#設置執行失敗
16397
										$result["status"]="false";
16398
 
16399
										#設置執行失敗訊息
16400
										$result["error"]=$clearStrSymbol;
16401
 
16402
										#回傳結果
16403
										return $result;
16404
 
16405
									}#if end
16406
 
16407
									#提示新增檔案到版本控制失敗
16408
									echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法查詢commit記錄".PHP_EOL;
16409
 
16410
									#繼續讓使用者輸入要commit的檔案
16411
									break 2;
16412
 
16413
									}#if end
16414
 
16415
								}#if end
16416
 
16417
							#運行svn status
16418
							#函式說明:
16419
							#呼叫shell執行系統命令,並取得回傳的內容.
16420
							#回傳的結果:
16421
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16422
							#$result["error"],錯誤訊息陣列.
16423
							#$result["function"],當前執行的函式名稱.
16424
							#$result["argu"],使用的參數.
16425
							#$result["cmd"],執行的指令內容.
16426
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16427
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16428
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16429
							#$result["running"],是否還在執行.
16430
							#$result["pid"],pid
16431
							#$result["statusCode"],執行結束後的代碼.
16432
							#必填參數:
16433
							#$conf["command"],字串,要執行的指令與.
16434
							$conf["external::callShell"]["command"]="echo";
16435
							#$conf["fileArgu"],字串,變數__FILE__的內容.
16436
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16437
							#可省略參數:
16438
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16439
							$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","log",$argv[1],$sshOption);
16440
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16441
							#$conf["arguIsAddr"]=array();
16442
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16443
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16444
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16445
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16446
							#$conf["enablePrintDescription"]="true";
16447
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16448
							#$conf["printDescription"]="";
16449
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
16450
							$conf["external::callShell"]["escapeshellarg"]="true";
16451
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16452
							#$conf["username"]="";
16453
							#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16454
							#$conf["password"]="";
16455
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16456
							#$conf["useScript"]="";
16457
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16458
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16459
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16460
							#$conf["inBackGround"]="";
16461
							#備註:
16462
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16463
							#參考資料:
16464
							#exec=>http://php.net/manual/en/function.exec.php
16465
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16466
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16467
							$callShell=external::callShell($conf["external::callShell"]);
16468
							unset($conf["external::callShell"]);
16469
 
16470
							#如果運行失敗
16471
							if($callShell["status"]==="false"){
16472
 
16473
								#設置執行失敗
16474
								$result["status"]="false";
16475
 
16476
								#設置執行錯誤
16477
								$result["error"]=$callShell;
16478
 
16479
								#回傳結果
16480
								return $result;
16481
 
16482
								}#if end
16483
 
16484
							#印出執行的cmd
16485
							echo "cmd:".$callShell["cmd"].PHP_EOL;
16486
 
16487
							#印出執行後的回傳代碼
16488
							echo "status:".$callShell["statusCode"].PHP_EOL;
16489
 
16490
							#初始化儲存版號的陣列
16491
							$rversion=array();
16492
 
16493
							#初始化儲存版本註解的陣列
16494
							$vlog=array();
16495
 
16496
							#依照每列輸出
16497
							foreach($callShell["output"] as $index=>$line){
16498
 
16499
								#如果不是第一列
16500
								if($index>0){
16501
 
16502
									#初始化註解的列數
16503
									$logLines=0;
16504
 
16505
									#如果前一列是 "------------------------------------------------------------------------" 且 當前列第一個字為"r" 且 當前列含有3個 "|" 且下一列為 ""
16506
									if($callShell["output"][$index-1]==="------------------------------------------------------------------------" && strpos($line,"r")===0 && substr_count($line,"|")===3 && $callShell["output"][$index+1]==="" ){
16507
 
16508
										#截取該行的版本號
16509
										$spiltedLine=explode(" ",$line);
16510
 
16511
										#取得該行的版本號
16512
										$version=substr($spiltedLine[0],1);
16513
 
16514
										#儲存版號
16515
										$rversion[]=$version;
16516
 
16517
										#取得註解的行數
16518
										$logLines=$spiltedLine[count($spiltedLine)-2];
16519
 
16520
										}#if end
16521
 
16522
									#如果有註解列數
16523
									for($i=0;$i<$logLines;$i++){
16524
 
16525
										#取得註解列的ley
16526
										$key=$index+1+($i+1);
16527
 
16528
										#取得該版本的該列註解
16529
										$vlog[$rversion[count($rversion)-1]][]=$callShell["output"][$key];
16530
 
16531
										}#for end
16532
 
16533
									}#if end
16534
 
16535
								#印出內容
16536
								echo $line.PHP_EOL;
16537
 
16538
								}#foreach end
16539
 
16540
							#提示版號清單
16541
							echo "版號清單:".PHP_EOL;
16542
 
16543
							#有幾個版號就執行幾次
16544
							foreach($rversion as $version){
16545
 
16546
								#提示版號
16547
								echo "版號: ".$version." 的註解".PHP_EOL;
16548
 
16549
								#該版號有幾列註解就執行幾次
16550
								foreach($vlog[$version] as $vlLine){
16551
 
16552
									#印出該版commit時的註解
16553
									echo $vlLine.PHP_EOL;
16554
 
16555
									}#foreach end
16556
 
16557
								}#foeach end
16558
 
16559
							#換行
16560
							echo PHP_EOL;
16561
 
16562
							#繼續讓使用者輸入要commit的檔案
16563
							break 2;
16564
 
16565
						#如果第一個參數為 "revert"
16566
						case "revert":
16567
 
16568
							#檢查要還原的檔案是否在版本控制之中
16569
 
16570
							#函式說明:
16571
							#呼叫shell執行系統命令,並取得回傳的內容.
16572
							#回傳結果:
16573
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16574
							#$result["error"],錯誤訊息陣列.
16575
							#$result["function"],當前執行的函數名稱.
16576
							#$result["argu"],使用的參數.
16577
							#$result["cmd"],執行的指令內容.
16578
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16579
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16580
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16581
							#$result["running"],是否還在執行.
16582
							#$result["pid"],pid.
16583
							#$result["statusCode"],執行結束後的代碼.
16584
							#必填參數:
16585
							#$conf["command"],字串,要執行的指令與.
16586
							$conf["external::callShell"]["command"]="svn";
16587
							#$conf["fileArgu"],字串,變數__FILE__的內容.
16588
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16589
							#可省略參數:
16590
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16591
							$conf["external::callShell"]["argu"]=array("status",$argv[1]);
16592
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16593
							#$conf["arguIsAddr"]=array();
16594
							#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16595
							#$conf["plainArgu"]=array();
16596
							#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16597
							#$conf["useApostrophe"]=array();
16598
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16599
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16600
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16601
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16602
							#$conf["enablePrintDescription"]="true";
16603
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16604
							#$conf["printDescription"]="";
16605
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16606
							$conf["external::callShell"]["escapeshellarg"]="true";
16607
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16608
							#$conf["thereIsShellVar"]=array();
16609
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16610
							#$conf["username"]="";
16611
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16612
							#$conf["password"]="";
16613
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16614
							#$conf["useScript"]="";
16615
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16616
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16617
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16618
							#$conf["inBackGround"]="";
16619
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16620
							#$conf["getErr"]="false";
16621
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16622
							#$conf["doNotRun"]="false";
16623
							#參考資料:
16624
							#exec=>http://php.net/manual/en/function.exec.php
16625
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16626
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16627
							#備註:
16628
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16629
							$callShell=external::callShell($conf["external::callShell"]);
16630
							unset($conf["external::callShell"]);
16631
 
16632
							#如果運行失敗
16633
							if($callShell["status"]==="false")
16634
							{
16635
								#設置執行失敗
16636
								$result["status"]="false";
16637
 
16638
								#設置執行錯誤
16639
								$result["error"]=$callShell;
16640
 
16641
								#回傳結果
16642
								return $result;
16643
 
16644
							}#if end
16645
 
16646
							#印出執行的cmd
16647
							echo "cmd:".$callShell["cmd"].PHP_EOL;
16648
 
16649
							#印出執行後的回傳代碼
16650
							echo "status:".$callShell["statusCode"].PHP_EOL;
16651
 
16652
							#如果不等於空陣列
16653
							if($callShell["output"]!==array()){
16654
 
16655
								#取得檔案的 status 與名稱
16656
								sscanf($callShell["output"][0],"%s %s",$sta,$fi);
16657
 
16658
								#如果狀態等於 ?
16659
								if($sta==="?"){
16660
 
16661
									#函式說明:
16662
									#清除字串的「"」或「'」符號.
16663
									#回傳結果:
16664
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16665
									#$result["function"],當前執行的函式內容.
16666
									#$result["error"],錯誤訊息陣列.
16667
									#$result["content"],剔除「"」或「'」符號後的字串.
16668
									#必填參數:
16669
									#$conf["str"],字串,要處理的字串.
16670
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16671
									#可省略參數:
16672
									#無.
16673
									#參考資料:
16674
									#無.
16675
									#備註:
16676
									#無.
16677
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16678
									unset($conf["stringProcess::clearStrSymbol"]);
16679
 
16680
									#如果運行失敗
16681
									if($clearStrSymbol["status"]==="false")
16682
									{
16683
										#設置執行失敗
16684
										$result["status"]="false";
16685
 
16686
										#設置執行失敗訊息
16687
										$result["error"]=$clearStrSymbol;
16688
 
16689
										#回傳結果
16690
										return $result;
16691
 
16692
									}#if end
16693
 
16694
									#提示不在版本控制裡面
16695
									echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法還原".PHP_EOL;
16696
 
16697
									#繼續讓使用者輸入要commit的檔案
16698
									break 2;
16699
 
16700
									}#if end
16701
 
16702
								#如果狀態等於 ""
16703
								else if($sta===""){
16704
 
16705
									#函式說明:
16706
									#清除字串的「"」或「'」符號.
16707
									#回傳結果:
16708
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16709
									#$result["function"],當前執行的函式內容.
16710
									#$result["error"],錯誤訊息陣列.
16711
									#$result["content"],剔除「"」或「'」符號後的字串.
16712
									#必填參數:
16713
									#$conf["str"],字串,要處理的字串.
16714
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16715
									#可省略參數:
16716
									#無.
16717
									#參考資料:
16718
									#無.
16719
									#備註:
16720
									#無.
16721
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16722
									unset($conf["stringProcess::clearStrSymbol"]);
16723
 
16724
									#如果運行失敗
16725
									if($clearStrSymbol["status"]==="false")
16726
									{
16727
										#設置執行失敗
16728
										$result["status"]="false";
16729
 
16730
										#設置執行失敗訊息
16731
										$result["error"]=$clearStrSymbol;
16732
 
16733
										#回傳結果
16734
										return $result;
16735
 
16736
									}#if end
16737
 
16738
									#提示新增檔案到版本控制失敗
16739
									echo "檔案「".$clearStrSymbol["content"]."」跟當前svn版本無差異".PHP_EOL;
16740
 
16741
									#繼續讓使用者輸入要commit的檔案
16742
									break 2;
16743
 
16744
									}#if end
16745
 
16746
								#反之等於其他狀態,則代表可以 revert
16747
								else{
16748
 
16749
									#函式說明:
16750
									#呼叫shell執行系統命令,並取得回傳的內容.
16751
									#回傳結果:
16752
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16753
									#$result["error"],錯誤訊息陣列.
16754
									#$result["function"],當前執行的函數名稱.
16755
									#$result["argu"],使用的參數.
16756
									#$result["cmd"],執行的指令內容.
16757
									#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16758
									#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16759
									#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16760
									#$result["running"],是否還在執行.
16761
									#$result["pid"],pid.
16762
									#$result["statusCode"],執行結束後的代碼.
16763
									#必填參數:
16764
									#$conf["command"],字串,要執行的指令與.
16765
									$conf["external::callShell"]["command"]="svn";
16766
									#$conf["fileArgu"],字串,變數__FILE__的內容.
16767
									$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16768
									#可省略參數:
16769
									#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16770
									$conf["external::callShell"]["argu"]=array("revert","--depth","infinity",$argv[1]);
16771
									#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16772
									#$conf["arguIsAddr"]=array();
16773
									#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16774
									#$conf["plainArgu"]=array();
16775
									#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16776
									#$conf["useApostrophe"]=array();
16777
									#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16778
									#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16779
									#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16780
									#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16781
									#$conf["enablePrintDescription"]="true";
16782
									#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16783
									#$conf["printDescription"]="";
16784
									#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16785
									$conf["external::callShell"]["escapeshellarg"]="true";
16786
									#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16787
									#$conf["thereIsShellVar"]=array();
16788
									#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16789
									#$conf["username"]="";
16790
									#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16791
									#$conf["password"]="";
16792
									#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16793
									#$conf["useScript"]="";
16794
									#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16795
									#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16796
									#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16797
									#$conf["inBackGround"]="";
16798
									#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16799
									#$conf["getErr"]="false";
16800
									#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16801
									#$conf["doNotRun"]="false";
16802
									#參考資料:
16803
									#exec=>http://php.net/manual/en/function.exec.php
16804
									#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16805
									#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16806
									#備註:
16807
									#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16808
									$callShell=external::callShell($conf["external::callShell"]);
16809
									unset($conf["external::callShell"]);
16810
 
16811
									#如果運行失敗
16812
									if($callShell["status"]==="false")
16813
									{
16814
										#設置執行失敗
16815
										$result["status"]="false";
16816
 
16817
										#設置執行錯誤
16818
										$result["error"]=$callShell;
16819
 
16820
										#回傳結果
16821
										return $result;
16822
 
16823
									}#if end
16824
 
16825
									#印出執行的cmd
16826
									echo "cmd:".$callShell["cmd"].PHP_EOL;
16827
 
16828
									#印出執行後的回傳代碼
16829
									echo "status:".$callShell["statusCode"].PHP_EOL;
16830
 
16831
									#如果運行正常
16832
									if($callShell["statusCode"]===0){
16833
 
16834
										#如果該檔案是被rm指令刪除的
16835
										if($sta==="!"){
16836
 
16837
											#函式說明:
16838
											#清除字串的「"」或「'」符號.
16839
											#回傳結果:
16840
											#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16841
											#$result["function"],當前執行的函式內容.
16842
											#$result["error"],錯誤訊息陣列.
16843
											#$result["content"],剔除「"」或「'」符號後的字串.
16844
											#必填參數:
16845
											#$conf["str"],字串,要處理的字串.
16846
											$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16847
											#可省略參數:
16848
											#無.
16849
											#參考資料:
16850
											#無.
16851
											#備註:
16852
											#無.
16853
											$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16854
											unset($conf["stringProcess::clearStrSymbol"]);
16855
 
16856
											#如果運行失敗
16857
											if($clearStrSymbol["status"]==="false")
16858
											{
16859
												#設置執行失敗
16860
												$result["status"]="false";
16861
 
16862
												#設置執行失敗訊息
16863
												$result["error"]=$clearStrSymbol;
16864
 
16865
												#回傳結果
16866
												return $result;
16867
 
16868
											}#if end
16869
 
16870
											#提示已經還原變更了
16871
											echo "已還原被移除的「".$clearStrSymbol["content"]."」".PHP_EOL;
16872
 
16873
											#繼續讓使用者輸入要commit的檔案
16874
											break 2;
16875
 
16876
											}#if end
16877
 
16878
										#如果該檔案是要新增版本控制
16879
										else if($sta==="A"){
16880
 
16881
											#如果 $argv[1] 在本次的 commit 清單裡面
16882
											if(in_array($argv[1],$filesToCommit)){
16883
 
16884
												#依據每個要commit的目標
16885
												foreach($filesToCommit as $index=>$target){
16886
 
16887
													#如果是 $argv[1]
16888
													if($target===$argv[1]){
16889
 
16890
														#移除之
16891
														unset($filesToCommit[$index]);
16892
 
16893
														}#if end
16894
 
16895
													}#foreach
16896
 
16897
												#依據每個要新增到版本控制的目標
16898
												foreach($fileAdded as $index=>$target){
16899
 
16900
													#如果是 $argv[1]
16901
													if($target===$argv[1]){
16902
 
16903
														#移除之
16904
														unset($fileAdded[$index]);
16905
 
16906
														}#if end
16907
 
16908
													}#foreach
16909
 
16910
												}#if end
16911
 
16912
											#函式說明:
16913
											#清除字串的「"」或「'」符號.
16914
											#回傳結果:
16915
											#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16916
											#$result["function"],當前執行的函式內容.
16917
											#$result["error"],錯誤訊息陣列.
16918
											#$result["content"],剔除「"」或「'」符號後的字串.
16919
											#必填參數:
16920
											#$conf["str"],字串,要處理的字串.
16921
											$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16922
											#可省略參數:
16923
											#無.
16924
											#參考資料:
16925
											#無.
16926
											#備註:
16927
											#無.
16928
											$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16929
											unset($conf["stringProcess::clearStrSymbol"]);
16930
 
16931
											#如果運行失敗
16932
											if($clearStrSymbol["status"]==="false")
16933
											{
16934
												#設置執行失敗
16935
												$result["status"]="false";
16936
 
16937
												#設置執行失敗訊息
16938
												$result["error"]=$clearStrSymbol;
16939
 
16940
												#回傳結果
16941
												return $result;
16942
 
16943
											}#if end
16944
 
16945
											#提示已經還原變更了
16946
											echo "已取消新增「".$clearStrSymbol["content"]."」到版本控制".PHP_EOL;
16947
 
16948
											#初始化儲存暫存的複製清單
16949
											$tempCpList=array();
16950
 
16951
											#針對每個複製的清單
16952
											foreach($copyList as $index=>$info){
16953
 
16954
												#如果還原的目標不是被複製出來的
16955
												if($info["to"]!==$argv[1]){
16956
 
16957
													#儲存複製資訊
16958
													$tempCpList[]=$info;
16959
 
16960
													}#if end
16961
 
16962
												}#foreach end
16963
 
16964
											#更新複製清單
16965
											$copyList=$tempCpList;
16966
 
16967
											#繼續讓使用者輸入要commit的檔案
16968
											#continue 2;
16969
											break 2;
16970
 
16971
											}#if end
16972
 
16973
										#如果該檔案原本是被移除版本控制
16974
										else if($sta==="D"){
16975
 
16976
											#如果 $argv[1] 在本次的 commit 清單裡面
16977
											if(in_array($argv[1],$filesToCommit)){
16978
 
16979
												#依據每個要commit的目標
16980
												foreach($filesToCommit as $index=>$target){
16981
 
16982
													#如果是 $argv[1]
16983
													if($target===$argv[1]){
16984
 
16985
														#移除之
16986
														unset($filesToCommit[$index]);
16987
 
16988
														}#if end
16989
 
16990
													}#foreach
16991
 
16992
												#依據每個要移除的目標
16993
												foreach($fileShouldBeDeleted as $index=>$target){
16994
 
16995
													#如果是 $argv[1]
16996
													if($target===$argv[1]){
16997
 
16998
														#移除之
16999
														unset($fileShouldBeDeleted[$index]);
17000
 
17001
														}#if end
17002
 
17003
													}#foreach
17004
 
17005
												}#if end
17006
 
17007
											#函式說明:
17008
											#清除字串的「"」或「'」符號.
17009
											#回傳結果:
17010
											#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17011
											#$result["function"],當前執行的函式內容.
17012
											#$result["error"],錯誤訊息陣列.
17013
											#$result["content"],剔除「"」或「'」符號後的字串.
17014
											#必填參數:
17015
											#$conf["str"],字串,要處理的字串.
17016
											$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
17017
											#可省略參數:
17018
											#無.
17019
											#參考資料:
17020
											#無.
17021
											#備註:
17022
											#無.
17023
											$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17024
											unset($conf["stringProcess::clearStrSymbol"]);
17025
 
17026
											#如果運行失敗
17027
											if($clearStrSymbol["status"]==="false")
17028
											{
17029
												#設置執行失敗
17030
												$result["status"]="false";
17031
 
17032
												#設置執行失敗訊息
17033
												$result["error"]=$clearStrSymbol;
17034
 
17035
												#回傳結果
17036
												return $result;
17037
 
17038
											}#if end
17039
 
17040
											#提示已經還原變更了
17041
											echo "已還原被移除版本控制的「".$clearStrSymbol["content"]."」".PHP_EOL;
17042
 
17043
											#繼續讓使用者輸入要commit的檔案
17044
											break 2;
17045
 
17046
											}#if end
17047
 
17048
										#如果該檔案是被修改過內容的
17049
										else if($sta==="M"){
17050
 
17051
											#如果 $argv[1] 在本次的 commit 清單裡面
17052
											if(in_array($argv[1],$filesToCommit)){
17053
 
17054
												#依據每個要commit的目標
17055
												foreach($filesToCommit as $index=>$target){
17056
 
17057
													#如果是 $argv[1]
17058
													if($target===$argv[1]){
17059
 
17060
														#移除之
17061
														unset($filesToCommit[$index]);
17062
 
17063
														}#if end
17064
 
17065
													}#foreach
17066
 
17067
												}#if end
17068
 
17069
											#函式說明:
17070
											#清除字串的「"」或「'」符號.
17071
											#回傳結果:
17072
											#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17073
											#$result["function"],當前執行的函式內容.
17074
											#$result["error"],錯誤訊息陣列.
17075
											#$result["content"],剔除「"」或「'」符號後的字串.
17076
											#必填參數:
17077
											#$conf["str"],字串,要處理的字串.
17078
											$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
17079
											#可省略參數:
17080
											#無.
17081
											#參考資料:
17082
											#無.
17083
											#備註:
17084
											#無.
17085
											$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17086
											unset($conf["stringProcess::clearStrSymbol"]);
17087
 
17088
											#如果運行失敗
17089
											if($clearStrSymbol["status"]==="false")
17090
											{
17091
												#設置執行失敗
17092
												$result["status"]="false";
17093
 
17094
												#設置執行失敗訊息
17095
												$result["error"]=$clearStrSymbol;
17096
 
17097
												#回傳結果
17098
												return $result;
17099
 
17100
											}#if end
17101
 
17102
											#提示已經還原變更了
17103
											echo "已還原「".$clearStrSymbol["content"]."」的修改".PHP_EOL;
17104
 
17105
											#繼續讓使用者輸入要commit的檔案
17106
											break 2;
17107
 
17108
											}#if end
17109
 
17110
										}#if end
17111
 
17112
									}#else end
17113
 
17114
								}#if end
17115
 
17116
							#反之
17117
							else{
17118
 
17119
								#函式說明:
17120
								#清除字串的「"」或「'」符號.
17121
								#回傳結果:
17122
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17123
								#$result["function"],當前執行的函式內容.
17124
								#$result["error"],錯誤訊息陣列.
17125
								#$result["content"],剔除「"」或「'」符號後的字串.
17126
								#必填參數:
17127
								#$conf["str"],字串,要處理的字串.
17128
								$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
17129
								#可省略參數:
17130
								#無.
17131
								#參考資料:
17132
								#無.
17133
								#備註:
17134
								#無.								
17135
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17136
								unset($conf["stringProcess::clearStrSymbol"]);
17137
 
17138
								#如果運行失敗
17139
								if($clearStrSymbol["status"]==="false")
17140
								{
17141
									#設置執行失敗
17142
									$result["status"]="false";
17143
 
17144
									#設置執行失敗訊息
17145
									$result["error"]=$clearStrSymbol;
17146
 
17147
									#回傳結果
17148
									return $result;
17149
 
17150
								}#if end
17151
 
17152
								#提示已經還原變更了
17153
								echo "目標「".$clearStrSymbol."」跟svn上的版本並無不同,或並不存在".PHP_EOL;
17154
 
17155
								#繼續讓使用者輸入要commit的檔案
17156
								break 2;
17157
 
17158
								}#else end
17159
 
17160
							#跳出switch
17161
							break;
17162
 
17163
						#如果是 "lls"
17164
						case "lls":
17165
 
17166
							#函式說明:
17167
							#清除字串的「"」或「'」符號.
17168
							#回傳結果:
17169
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17170
							#$result["function"],當前執行的函式內容.
17171
							#$result["error"],錯誤訊息陣列.
17172
							#$result["content"],剔除「"」或「'」符號後的字串.
17173
							#必填參數:
17174
							#$conf["str"],字串,要處理的字串.
17175
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
17176
							#可省略參數:
17177
							#無.
17178
							#參考資料:
17179
							#無.
17180
							#備註:
17181
							#無.							
17182
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17183
							unset($conf["stringProcess::clearStrSymbol"]);
17184
 
17185
							#如果運行失敗
17186
							if($clearStrSymbol["status"]==="false")
17187
							{
17188
								#設置執行失敗
17189
								$result["status"]="false";
17190
 
17191
								#設置執行失敗訊息
17192
								$result["error"]=$clearStrSymbol;
17193
 
17194
								#回傳結果
17195
								return $result;
17196
 
17197
							}#if end
17198
 
17199
							#如果檔案不存在
17200
							if(!file_exists($clearStrSymbol["content"])){
17201
 
17202
								#提示檔案不存在
17203
								echo "要檢視的本機目錄檔案「".$clearStrSymbol["content"]."」並不存在".PHP_EOL;
17204
 
17205
								#繼續讓使用者輸入要commit的檔案
17206
								break 2;
17207
 
17208
								}#if end
17209
 
17210
							#運行 ls
17211
							#函式說明:
17212
							#呼叫shell執行系統命令,並取得回傳的內容.
17213
							#回傳結果:
17214
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17215
							#$result["error"],錯誤訊息陣列.
17216
							#$result["function"],當前執行的函數名稱.
17217
							#$result["argu"],使用的參數.
17218
							#$result["cmd"],執行的指令內容.
17219
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17220
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17221
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17222
							#$result["running"],是否還在執行.
17223
							#$result["pid"],pid.
17224
							#$result["statusCode"],執行結束後的代碼.
17225
							#必填參數:
17226
							#$conf["command"],字串,要執行的指令與.
17227
							$conf["external::callShell"]["command"]="ls";
17228
							#$conf["fileArgu"],字串,變數__FILE__的內容.
17229
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17230
							#可省略參數:
17231
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17232
							$conf["external::callShell"]["argu"]=array("-alh",$argv[1]);
17233
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17234
							#$conf["arguIsAddr"]=array();
17235
							#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17236
							#$conf["plainArgu"]=array();
17237
							#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17238
							#$conf["useApostrophe"]=array();
17239
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17240
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17241
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17242
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17243
							#$conf["enablePrintDescription"]="true";
17244
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17245
							#$conf["printDescription"]="";
17246
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17247
							#$conf["escapeshellarg"]="false";
17248
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17249
							#$conf["thereIsShellVar"]=array();
17250
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17251
							#$conf["username"]="";
17252
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17253
							#$conf["password"]="";
17254
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17255
							#$conf["useScript"]="";
17256
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17257
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17258
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17259
							#$conf["inBackGround"]="";
17260
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17261
							#$conf["getErr"]="false";
17262
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17263
							#$conf["doNotRun"]="false";
17264
							#參考資料:
17265
							#exec=>http://php.net/manual/en/function.exec.php
17266
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17267
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17268
							#備註:
17269
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17270
							$callShell=external::callShell($conf["external::callShell"]);
17271
							unset($conf["external::callShell"]);
17272
 
17273
							#如果執行失敗
17274
							if($callShell["status"]==="false"){
17275
 
17276
								#設置執行失敗
17277
								$result["status"]="false";
17278
 
17279
								#設置執行錯誤
17280
								$result["error"]=$callShell;
17281
 
17282
								#回傳結果
17283
								return $result;
17284
 
17285
								}#if end
17286
 
17287
							#印出執行的 cmd
17288
							echo "執行的指令:".$callShell["cmd"].PHP_EOL;
17289
 
17290
							#印出執行後的回傳代碼
17291
							echo "status:".$callShell["statusCode"].PHP_EOL;
17292
 
17293
							#印出執行的結果
17294
							echo "本機路徑 ".$argv[1]." 底下的檔案目錄清單:".PHP_EOL;
17295
 
17296
							#函式說明:
17297
							#顯示多行文字.
17298
							#回傳的結果:
17299
							#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
17300
							#$result["error"],錯誤訊息陣列.
17301
							#$result["function"],當前執行的函式名稱.
17302
							#$result["content"],語法.
17303
							#必填參數:
17304
							#$conf["string"],字串陣列,要放置的內容.
17305
							$conf["text::multiLine"]["string"]=$callShell["output"];
17306
							#可省略參數:
17307
							#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
17308
							#$conf["class"]="";
17309
							#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".
17310
							#$conf["type"]="EOL";
17311
							$multiLine=text::multiLine($conf["text::multiLine"]);
17312
							unset($conf["text::multiLine"]);
17313
 
17314
							#如過執行失敗
17315
							if($multiLine["status"]==="false"){
17316
 
17317
								#設置執行失敗
17318
								$result["status"]="false";
17319
 
17320
								#設置執行錯誤
17321
								$result["error"]=$multiLine;
17322
 
17323
								#回傳結果
17324
								return $result;
17325
 
17326
								}#if end
17327
 
17328
							#印出結果
17329
							echo $multiLine["content"];
17330
 
17331
							#繼續讓使用者輸入要commit的檔案
17332
							break 2;
17333
 
17334
						#如果是 "rls"
17335
						case "rls":
17336
 
17337
							#運行 svn ls
17338
							#函式說明:
17339
							#呼叫shell執行系統命令,並取得回傳的內容.
17340
							#回傳的結果:
17341
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17342
							#$result["error"],錯誤訊息陣列.
17343
							#$result["function"],當前執行的函式名稱.
17344
							#$result["argu"],使用的參數.
17345
							#$result["cmd"],執行的指令內容.
17346
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17347
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17348
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17349
							#$result["running"],是否還在執行.
17350
							#$result["pid"],pid.
17351
							#$result["statusCode"],執行結束後的代碼.
17352
							#必填參數:
17353
							#$conf["command"],字串,要執行的指令與.
17354
							$conf["external::callShell"]["command"]="echo";
17355
							#$conf["fileArgu"],字串,變數__FILE__的內容.
17356
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17357
							#可省略參數:
17358
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17359
							$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","ls",$argv[1],$sshOption);
17360
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17361
							#$conf["arguIsAddr"]=array();
17362
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17363
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17364
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17365
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17366
							#$conf["enablePrintDescription"]="true";
17367
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17368
							#$conf["printDescription"]="";
17369
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
17370
							$conf["external::callShell"]["escapeshellarg"]="true";
17371
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17372
							#$conf["username"]="";
17373
							#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17374
							#$conf["password"]="";
17375
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17376
							#$conf["useScript"]="";
17377
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17378
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17379
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17380
							#$conf["inBackGround"]="";
17381
							#備註:
17382
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17383
							#參考資料:
17384
							#exec=>http://php.net/manual/en/function.exec.php
17385
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17386
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17387
							$callShell=external::callShell($conf["external::callShell"]);
17388
							unset($conf["external::callShell"]);
17389
 
17390
							#如果執行失敗
17391
							if($callShell["status"]==="false"){
17392
 
17393
								#設置執行失敗
17394
								$result["status"]="false";
17395
 
17396
								#設置執行錯誤
17397
								$result["error"]=$callShell;
17398
 
17399
								#回傳結果
17400
								return $result;
17401
 
17402
								}#if end
17403
 
17404
							#印出執行的 cmd
17405
							echo "執行的指令:".$callShell["cmd"].PHP_EOL;
17406
 
17407
							#印出執行後的回傳代碼
17408
							echo "status:".$callShell["statusCode"].PHP_EOL;
17409
 
17410
							#印出執行的結果
17411
							echo "repo路徑 ".$argv[1]." 底下的檔案目錄清單:".PHP_EOL;
17412
 
17413
							#函式說明:
17414
							#顯示多行文字.
17415
							#回傳的結果:
17416
							#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
17417
							#$result["error"],錯誤訊息陣列.
17418
							#$result["function"],當前執行的函式名稱.
17419
							#$result["content"],語法.
17420
							#必填參數:
17421
							#$conf["string"],字串陣列,要放置的內容.
17422
							$conf["text::multiLine"]["string"]=$callShell["output"];
17423
							#可省略參數:
17424
							#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
17425
							#$conf["class"]="";
17426
							#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".
17427
							#$conf["type"]="EOL";
17428
							$multiLine=text::multiLine($conf["text::multiLine"]);
17429
							unset($conf["text::multiLine"]);
17430
 
17431
							#如過執行失敗
17432
							if($multiLine["status"]==="false"){
17433
 
17434
								#設置執行失敗
17435
								$result["status"]="false";
17436
 
17437
								#設置執行錯誤
17438
								$result["error"]=$multiLine;
17439
 
17440
								#回傳結果
17441
								return $result;
17442
 
17443
								}#if end
17444
 
17445
							#印出結果
17446
							echo $multiLine["content"];
17447
 
17448
							#繼續讓使用者輸入要commit的檔案
17449
							#continue 2;
17450
							break 2;
17451
 
17452
						#其他內容
17453
						default:
17454
 
17455
							#函式說明:
17456
							#清除字串的「"」或「'」符號.
17457
							#回傳結果:
17458
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17459
							#$result["function"],當前執行的函式內容.
17460
							#$result["error"],錯誤訊息陣列.
17461
							#$result["content"],剔除「"」或「'」符號後的字串.
17462
							#必填參數:
17463
							#$conf["str"],字串,要處理的字串.
17464
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];
17465
							#可省略參數:
17466
							#無.
17467
							#參考資料:
17468
							#無.
17469
							#備註:
17470
							#無.
17471
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17472
							unset($conf["stringProcess::clearStrSymbol"]);
17473
 
17474
							#如過執行失敗
17475
							if($clearStrSymbol["status"]==="false"){
17476
 
17477
								#設置執行失敗
17478
								$result["status"]="false";
17479
 
17480
								#設置執行失敗訊息
17481
								$result["error"]=$clearStrSymbol;
17482
 
17483
								#回傳結果
17484
								return $result;
17485
 
17486
								}#if end
17487
 
17488
							#提示命令 $argv[1] 不存在
17489
							echo "命令 「".$clearStrSymbol["content"]."」 不存在".PHP_EOL;
17490
 
17491
							#繼續讓使用者輸入要commit的檔案
17492
							break 2;
17493
 
17494
						}#switch end
17495
 
17496
					#提示不正常
17497
					echo "Oops somethine go wrong. Input is ".print_r($argv,true).PHP_EOL;
17498
 
17499
					#繼續輸入要commit的檔案名稱
17500
					break;
17501
 
17502
				#如果參數數量為1
17503
				case 1:
17504
 
17505
					#剔除開頭與結尾的「'」或「""」
17506
					#函式說明:
17507
					#清除字串的「"」或「'」符號.
17508
					#回傳結果:
17509
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17510
					#$result["function"],當前執行的函式內容.
17511
					#$result["error"],錯誤訊息陣列.
17512
					#$result["content"],剔除「"」或「'」符號後的字串.
17513
					#必填參數:
17514
					#$conf["str"],字串,要處理的字串.
17515
					$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];
17516
					#可省略參數:
17517
					#無.
17518
					#參考資料:
17519
					#無.
17520
					#備註:
17521
					#無.
17522
					$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17523
					unset($conf["stringProcess::clearStrSymbol"]);
17524
 
17525
					#如果執行失敗
17526
					if($clearStrSymbol["status"]==="false"){
17527
 
17528
						#設置執行失敗
17529
						$result["status"]="false";
17530
 
17531
						#設置執行失敗訊息
17532
						$result["error"]=$clearStrSymbol;
17533
 
17534
						#回傳結果
17535
						return $result;
17536
 
17537
						}#if end
17538
 
17539
					#提示檢查檔案是否存在
17540
					echo "檢查檔案 ".$clearStrSymbol["content"]." 是否存在".PHP_EOL;
17541
 
17542
					#函式說明:
17543
					#檢查多個檔案與資料夾是否存在.
17544
					#回傳的結果:
17545
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
17546
					#$result["error"],錯誤訊息陣列.
17547
					#$resutl["function"],當前執行的涵式名稱.
17548
					#$result["argu"],使用的參數.
17549
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
17550
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
17551
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
17552
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
17553
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
17554
					#必填參數:
17555
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
17556
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($clearStrSymbol["content"]);
17557
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17558
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
17559
					#可省略參數:
17560
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
17561
					#$conf["disableWebSearch"]="false";
17562
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
17563
					#$conf["fileAccess::checkMultiFileExist"]["userDir"]="true";
17564
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
17565
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
17566
					#參考資料:
17567
					#http://php.net/manual/en/function.file-exists.php
17568
					#http://php.net/manual/en/control-structures.foreach.php
17569
					#備註:
17570
					#函數file_exists檢查的路徑為檔案系統的路徑
17571
					#$result["varName"][$i]結果未實作
17572
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
17573
					unset($conf["fileAccess::checkMultiFileExist"]);
17574
 
17575
					#如果執行失敗
17576
					if($checkMultiFileExist["status"]==="false"){
17577
 
17578
						#設置執行失敗
17579
						$result["status"]="false";
17580
 
17581
						#設置執行失敗訊息
17582
						$result["error"]=$checkMultiFileExist;
17583
 
17584
						#回傳結果
17585
						return $result;
17586
 
17587
						}#if end
17588
 
17589
					#如果檔案不存在
17590
					if($checkMultiFileExist["allExist"]==="false"){
17591
 
17592
						#提示檔案不存在
17593
						echo "檔案".$clearStrSymbol["content"]."不存在".PHP_EOL;
17594
 
17595
						#繼續輸入要commit的檔案名稱
17596
						break;
17597
 
17598
						}#if end
17599
 
17600
					#檢查檔案 $input 是否處於版本控制中
17601
 
17602
					#函式說明:
17603
					#執行svn status指令
17604
					#回傳結果:
17605
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17606
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
17607
					#$result["function"],當前執行的函式名稱.
17608
					#$result["content"]["ori"],指令輸出的原始結果陣列.
17609
					#$result["content"]["status"][$i]["status"],第$i+1個目標的狀態.
17610
					#$result["content"]["status"][$i]["target"],第$i+1個目標的路徑與名稱.
17611
					#$result["content"]["status"][$i]["is_dir"],第$i+1個目標是否為目錄,"true"代表是,"false"代表不是.
17612
					#必填參數:
17613
					#$conf["fileArgu"],字串,變數__FILE__的內容.
17614
					$conf["cmd::svnsta"]["fileArgu"]=__FILE__;
17615
					#可省略參數:
17616
					#$conf["target"],字串,要檢查status的目標.
17617
					$conf["cmd::svnsta"]["target"]=$input;
17618
					#參考資料:
17619
					#無.
17620
					#備註:
17621
					#無.
17622
					$svnsta=cmd::svnsta($conf["cmd::svnsta"]);
17623
					unset($conf["cmd::svnsta"]);
17624
 
17625
					#如果執行失敗
17626
					if($svnsta["status"]==="false"){
17627
 
17628
						#設置執行失敗
17629
						$result["status"]="false";
17630
 
17631
						#設置執行失敗訊息
17632
						$result["error"]=$svnsta;
17633
 
17634
						#回傳結果
17635
						return $result;
17636
 
17637
						}#if end
17638
 
17639
					#var_dump(__LINE__,$svnsta);
17640
 
17641
					#如果沒有版本控制記錄
17642
					if($svnsta["content"]["status"][0]["status"]==="?"){
17643
 
17644
						#函式說明:
17645
						#呼叫shell執行系統命令,並取得回傳的內容.
17646
						#回傳結果:
17647
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17648
						#$result["error"],錯誤訊息陣列.
17649
						#$result["function"],當前執行的函數名稱.
17650
						#$result["argu"],使用的參數.
17651
						#$result["cmd"],執行的指令內容.
17652
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17653
						#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17654
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17655
						#$result["running"],是否還在執行.
17656
						#$result["pid"],pid.
17657
						#$result["statusCode"],執行結束後的代碼.
17658
						#必填參數:
17659
						#$conf["command"],字串,要執行的指令與.
17660
						$conf["external::callShell"]["command"]="svn";
17661
						#$conf["fileArgu"],字串,變數__FILE__的內容.
17662
						$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17663
						#可省略參數:
17664
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17665
						$conf["external::callShell"]["argu"]=array("add",$argv[0]);
17666
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17667
						#$conf["arguIsAddr"]=array();
17668
						#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17669
						#$conf["plainArgu"]=array();
17670
						#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17671
						#$conf["useApostrophe"]=array();
17672
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17673
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17674
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17675
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17676
						#$conf["enablePrintDescription"]="true";
17677
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17678
						#$conf["printDescription"]="";
17679
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17680
						$conf["external::callShell"]["escapeshellarg"]="true";
17681
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17682
						#$conf["thereIsShellVar"]=array();
17683
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17684
						#$conf["username"]="";
17685
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17686
						#$conf["password"]="";
17687
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17688
						#$conf["useScript"]="";
17689
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17690
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17691
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17692
						#$conf["inBackGround"]="";
17693
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17694
						#$conf["getErr"]="false";
17695
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17696
						#$conf["doNotRun"]="false";
17697
						#參考資料:
17698
						#exec=>http://php.net/manual/en/function.exec.php
17699
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17700
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17701
						#備註:
17702
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17703
						$callShell=external::callShell($conf["external::callShell"]);
17704
						unset($conf["external::callShell"]);
17705
 
17706
						#如果執行失敗
17707
						if($callShell["status"]==="false"){
17708
 
17709
							#設置執行失敗
17710
							$result["status"]="false";
17711
 
17712
							#設置執行失敗訊息
17713
							$result["error"]=$callShell;
17714
 
17715
							#回傳結果
17716
							return $result;
17717
 
17718
							}#if end
17719
 
17720
						#印出執行的cmd
17721
						echo "cmd:".$callShell["cmd"].PHP_EOL;
17722
 
17723
						#印出執行後的回傳代碼
17724
						echo "status:".$callShell["statusCode"].PHP_EOL;
17725
 
17726
						#針對每列輸出
17727
						foreach($callShell["output"] as $line){
17728
 
17729
							#印出內容
17730
							echo $line.PHP_EOL;
17731
 
17732
							}#foreach end
17733
 
17734
						#清空output
17735
						unset($output);
17736
 
17737
						#如果新增檔案到版本控制成功
17738
						if($callShell["statusCode"]===0){
17739
 
17740
							#記錄要commit的新增檔案
17741
							$filesToCommit[]=$argv[0];
17742
 
17743
							#記錄本次要新增的檔案
17744
							$fileAdded[]=$argv[0];
17745
 
17746
							#函式說明:
17747
							#清除字串的「"」或「'」符號.
17748
							#回傳結果:
17749
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17750
							#$result["function"],當前執行的函式內容.
17751
							#$result["error"],錯誤訊息陣列.
17752
							#$result["content"],剔除「"」或「'」符號後的字串.
17753
							#必填參數:
17754
							#$conf["str"],字串,要處理的字串.
17755
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];
17756
							#可省略參數:
17757
							#無.
17758
							#參考資料:
17759
							#無.
17760
							#備註:
17761
							#無.
17762
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17763
							unset($conf["stringProcess::clearStrSymbol"]);
17764
 
17765
							#如果執行失敗
17766
							if($clearStrSymbol["status"]==="false"){
17767
 
17768
								#設置執行失敗
17769
								$result["status"]="false";
17770
 
17771
								#設置執行失敗訊息
17772
								$result["error"]=$clearStrSymbol;
17773
 
17774
								#回傳結果
17775
								return $result;
17776
 
17777
								}#if end
17778
 
17779
							#提示已經新增
17780
							echo "已新增檔案「".$clearStrSymbol["content"]."」到版本控制".PHP_EOL;
17781
 
17782
							#繼續讓使用者輸入要commit的檔案
17783
							break;
17784
 
17785
							}#if end
17786
 
17787
						#反之
17788
						else{
17789
 
17790
							#提示新增檔案到版本控制失敗
17791
							echo "新增檔案「".$argv[0]."」到版本控制失敗(".$callShell["statusCode"].")".PHP_EOL;
17792
 
17793
							#繼續讓使用者輸入要commit的檔案
17794
							break;
17795
 
17796
							}#else end
17797
 
17798
						}#if end
17799
 
17800
					#反之有異動過
17801
					else if( $svnsta["content"]["status"][0]["status"]==="M" || $svnsta["content"]["status"][0]["status"]==="A" ){
17802
 
17803
						#如果有在commit清單裡面了
17804
						if(in_array($argv[0],$filesToCommit)){
17805
 
17806
							#提示新增檔案到版本控制失敗
17807
							echo "檔案「".$argv[0]."」的異動已記錄(".$callShell["statusCode"].")".PHP_EOL;
17808
 
17809
							#繼續讓使用者輸入要commit的檔案
17810
							break;
17811
 
17812
							}#if end
17813
 
17814
						#記錄要commit的新增檔案
17815
						$filesToCommit[]=$argv[0];
17816
 
17817
						#記錄本次要新增的檔案
17818
						$fileAdded[]=$argv[0];
17819
 
17820
						#函式說明:
17821
						#清除字串的「"」或「'」符號.
17822
						#回傳結果:
17823
						#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17824
						#$result["function"],當前執行的函式內容.
17825
						#$result["error"],錯誤訊息陣列.
17826
						#$result["content"],剔除「"」或「'」符號後的字串.
17827
						#必填參數:
17828
						#$conf["str"],字串,要處理的字串.
17829
						$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];
17830
						#可省略參數:
17831
						#無.
17832
						#參考資料:
17833
						#無.
17834
						#備註:
17835
						#無.
17836
						$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17837
						unset($conf["stringProcess::clearStrSymbol"]);
17838
 
17839
						#如果執行失敗
17840
						if($clearStrSymbol["status"]==="false"){
17841
 
17842
							#設置執行失敗
17843
							$result["status"]="false";
17844
 
17845
							#設置執行失敗訊息
17846
							$result["error"]=$clearStrSymbol;
17847
 
17848
							#回傳結果
17849
							return $result;
17850
 
17851
							}#if end
17852
 
17853
						#提示已經新增
17854
						echo "已將檔案「".$clearStrSymbol["content"]."」的異動加到版本控制".PHP_EOL;
17855
 
17856
						#繼續讓使用者輸入要commit的檔案
17857
						break;
17858
 
17859
						}#if end
17860
 
17861
					#反之
17862
					else{
17863
 
17864
						#提示node無異動,所以無法加入為commit的清單
17865
						echo "檔案「".$argv[0]."」無異動".PHP_EOL;
17866
 
17867
						#繼續讓使用者輸入要commit的檔案
17868
						break;
17869
 
17870
						}#else end
17871
 
17872
					#繼續輸入要commit的檔案名稱
17873
					break;
17874
 
17875
				#如果參數數量為0
17876
				case 0:
17877
 
17878
					#繼續輸入要commit的檔案名稱
17879
					break;
17880
 
17881
				#其他結果
17882
				default:
17883
 
17884
					#判斷第一個參數
17885
					switch($argv[0]){
17886
 
17887
						#如果是 "cp"
17888
						case "cp":
17889
 
17890
							#檢查要複製到的目標
17891
							#函式說明:
17892
							#清除字串的「"」或「'」符號.
17893
							#回傳結果:
17894
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17895
							#$result["function"],當前執行的函式內容.
17896
							#$result["error"],錯誤訊息陣列.
17897
							#$result["content"],剔除「"」或「'」符號後的字串.
17898
							#必填參數:
17899
							#$conf["str"],字串,要處理的字串.
17900
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[$argc-1];
17901
							#可省略參數:
17902
							#無.
17903
							#參考資料:
17904
							#無.
17905
							#備註:
17906
							#無.
17907
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17908
							unset($conf["stringProcess::clearStrSymbol"]);
17909
 
17910
							#如果執行失敗
17911
							if($clearStrSymbol["status"]==="false"){
17912
 
17913
								#設置執行失敗
17914
								$result["status"]="false";
17915
 
17916
								#設置執行失敗訊息
17917
								$result["error"]=$clearStrSymbol;
17918
 
17919
								#回傳結果
17920
								return $result;
17921
 
17922
								}#if end
17923
 
17924
							#如果最後一個參數代表的複製目的已經存在
17925
							if(file_exists($clearStrSymbol["content"])){
17926
 
17927
								#不是目錄
17928
								if(!is_dir($clearStrSymbol["content"])){
17929
 
17930
									#提示複製的目的已經存在
17931
									echo "要複製到的目的檔案「".$argv[$argc-1]."」已存在!".PHP_EOL;
17932
 
17933
									#讓使用者繼續輸入要commit的項目
17934
									break 2;
17935
 
17936
									}#if end
17937
 
17938
								#反之代表目的地是目錄
17939
								else{
17940
 
17941
									#檢查目錄是否在版本控制中
17942
 
17943
									#函式說明:
17944
									#呼叫shell執行系統命令,並取得回傳的內容.
17945
									#回傳結果:
17946
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17947
									#$result["error"],錯誤訊息陣列.
17948
									#$result["function"],當前執行的函數名稱.
17949
									#$result["argu"],使用的參數.
17950
									#$result["cmd"],執行的指令內容.
17951
									#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17952
									#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17953
									#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17954
									#$result["running"],是否還在執行.
17955
									#$result["pid"],pid.
17956
									#$result["statusCode"],執行結束後的代碼.
17957
									#必填參數:
17958
									#$conf["command"],字串,要執行的指令與.
17959
									$conf["external::callShell"]["command"]="svn";
17960
									#$conf["fileArgu"],字串,變數__FILE__的內容.
17961
									$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17962
									#可省略參數:
17963
									#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17964
									$conf["external::callShell"]["argu"]=array("status",$argv[$argc-1]);
17965
									#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17966
									#$conf["arguIsAddr"]=array();
17967
									#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17968
									#$conf["plainArgu"]=array();
17969
									#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17970
									#$conf["useApostrophe"]=array();
17971
									#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17972
									#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17973
									#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17974
									#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17975
									#$conf["enablePrintDescription"]="true";
17976
									#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17977
									#$conf["printDescription"]="";
17978
									#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17979
									$conf["external::callShell"]["escapeshellarg"]="true";
17980
									#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17981
									#$conf["thereIsShellVar"]=array();
17982
									#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17983
									#$conf["username"]="";
17984
									#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17985
									#$conf["password"]="";
17986
									#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17987
									#$conf["useScript"]="";
17988
									#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17989
									#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17990
									#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17991
									#$conf["inBackGround"]="";
17992
									#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17993
									#$conf["getErr"]="false";
17994
									#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17995
									#$conf["doNotRun"]="false";
17996
									#參考資料:
17997
									#exec=>http://php.net/manual/en/function.exec.php
17998
									#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17999
									#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
18000
									#備註:
18001
									#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
18002
									$callShell=external::callShell($conf["external::callShell"]);
18003
									unset($conf["external::callShell"]);
18004
 
18005
									#如果執行失敗
18006
									if($callShell["status"]==="false"){
18007
 
18008
										#設置執行失敗
18009
										$result["status"]="false";
18010
 
18011
										#設置執行失敗訊息
18012
										$result["error"]=$callShell;
18013
 
18014
										#回傳結果
18015
										return $result;
18016
 
18017
										}#if end
18018
 
18019
									#印出執行的cmd
18020
									echo "cmd:".$callShell["cmd"].PHP_EOL;
18021
 
18022
									#印出執行後的回傳代碼
18023
									echo "status:".$callShell["statusCode"].PHP_EOL;
18024
 
18025
									#如果不等於空陣列
18026
									if($callShell["output"]!==array()){
18027
 
18028
										#取得檔案的 status 與名稱
18029
										sscanf($callShell["output"][0],"%s %s",$sta,$fi);
18030
 
18031
										#如果狀態等於 ?
18032
										if($sta==="?"){
18033
 
18034
											#提示新增檔案到版本控制失敗
18035
											echo "目的地目錄「".$argv[$argc-1]."」不在版本控制裡面,因此無法複製過去".PHP_EOL;
18036
 
18037
											#繼續讓使用者輸入要commit的檔案
18038
											break 2;
18039
 
18040
											}#if end
18041
 
18042
										}#if end
18043
 
18044
									#提示複製過去的目標的目的已經存在
18045
									echo "要複製的清單會放到「".$argv[$argc-1]."」目錄底下!".PHP_EOL;
18046
 
18047
									}#else end
18048
 
18049
								}#if end
18050
 
18051
							#扣掉頭尾剩下幾個參數就執行幾次
18052
							for($i=1;$i<$argc-1;$i++){
18053
 
18054
								#要複製的目標路徑與名稱
18055
								$source=$argv[$i];
18056
 
18057
								#要複製的目標名稱
18058
								$sourceFileName=$source;
18059
 
18060
								#debug
18061
								echo "Trying copy 「".$sourceFileName."」 to 「".$argv[$argc-1]."」".PHP_EOL;
18062
 
18063
								#如果複製來源含有 '/'
18064
								while($slashPos=strpos($sourceFileName,'/')){
18065
 
18066
									#取得 '/' 後面的內容
18067
									$sourceFileName=substr($sourceFileName,$slashPos);
18068
 
18069
									}#while end
18070
 
18071
								#複製過去的新位置與名稱
18072
								$target=$argv[$argc-1].$sourceFileName;
18073
 
18074
								#要檢查複製過去的目標是否已經存在
18075
								if(file_exists($target)){
18076
 
18077
									echo "要複製到的目標「".$target."」已經存在,略過".PHP_EOL;
18078
 
18079
									#跳過已經存在的目標
18080
									continue;
18081
 
18082
									}#if end
18083
 
18084
								#函式說明:
18085
								#呼叫shell執行系統命令,並取得回傳的內容.
18086
								#回傳結果:
18087
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18088
								#$result["error"],錯誤訊息陣列.
18089
								#$result["function"],當前執行的函數名稱.
18090
								#$result["argu"],使用的參數.
18091
								#$result["cmd"],執行的指令內容.
18092
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
18093
								#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
18094
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
18095
								#$result["running"],是否還在執行.
18096
								#$result["pid"],pid.
18097
								#$result["statusCode"],執行結束後的代碼.
18098
								#必填參數:
18099
								#$conf["command"],字串,要執行的指令與.
18100
								$conf["external::callShell"]["command"]="svn";
18101
								#$conf["fileArgu"],字串,變數__FILE__的內容.
18102
								$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
18103
								#可省略參數:
18104
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
18105
								$conf["external::callShell"]["argu"]=array("status",$argv[$i]);
18106
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
18107
								#$conf["arguIsAddr"]=array();
18108
								#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
18109
								#$conf["plainArgu"]=array();
18110
								#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
18111
								#$conf["useApostrophe"]=array();
18112
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
18113
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
18114
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
18115
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
18116
								#$conf["enablePrintDescription"]="true";
18117
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
18118
								#$conf["printDescription"]="";
18119
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
18120
								$conf["external::callShell"]["escapeshellarg"]="true";
18121
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
18122
								#$conf["thereIsShellVar"]=array();
18123
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
18124
								#$conf["username"]="";
18125
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
18126
								#$conf["password"]="";
18127
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
18128
								#$conf["useScript"]="";
18129
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
18130
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
18131
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
18132
								#$conf["inBackGround"]="";
18133
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
18134
								#$conf["getErr"]="false";
18135
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
18136
								#$conf["doNotRun"]="false";
18137
								#參考資料:
18138
								#exec=>http://php.net/manual/en/function.exec.php
18139
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
18140
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
18141
								#備註:
18142
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
18143
								$callShell=external::callShell($conf["external::callShell"]);
18144
								unset($conf["external::callShell"]);
18145
 
18146
								#如果執行失敗
18147
								if($callShell["status"]==="false"){
18148
 
18149
									#設置執行失敗
18150
									$result["status"]="false";
18151
 
18152
									#設置執行失敗訊息
18153
									$result["error"]=$callShell;
18154
 
18155
									#回傳結果
18156
									return $result;
18157
 
18158
									}#if end
18159
 
18160
								#印出執行的cmd
18161
								echo "cmd:".$callShell["cmd"].PHP_EOL;
18162
 
18163
								#印出執行後的回傳代碼
18164
								echo "status:".$callShell["statusCode"].PHP_EOL;
18165
 
18166
								#如果不等於空陣列
18167
								if($callShell["output"]!==array()){
18168
 
18169
									#取得檔案的 status 與名稱
18170
									sscanf($callShell["output"][0],"%s %s",$sta,$fi);
18171
 
18172
									#如果狀態等於 ?
18173
									if($sta==="?"){
18174
 
18175
										#提示新增檔案到版本控制失敗
18176
										#函式說明:
18177
										#清除字串的「"」或「'」符號.
18178
										#回傳結果:
18179
										#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
18180
										#$result["function"],當前執行的函式內容.
18181
										#$result["error"],錯誤訊息陣列.
18182
										#$result["content"],剔除「"」或「'」符號後的字串.
18183
										#必填參數:
18184
										#$conf["str"],字串,要處理的字串.
18185
										$conf["stringProcess::clearStrSymbol"]["str"]=$source;
18186
										#可省略參數:
18187
										#無.
18188
										#參考資料:
18189
										#無.
18190
										#備註:
18191
										#無.
18192
										$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
18193
										unset($conf["stringProcess::clearStrSymbol"]);
18194
 
18195
										#如果執行失敗
18196
										if($clearStrSymbol["status"]==="false"){
18197
 
18198
											#設置執行失敗
18199
											$result["status"]="false";
18200
 
18201
											#設置執行失敗訊息
18202
											$result["error"]=$clearStrSymbol;
18203
 
18204
											#回傳結果
18205
											return $result;
18206
 
18207
											}#if end
18208
 
18209
										echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法複製".PHP_EOL;
18210
 
18211
										#繼續讓使用者輸入要commit的檔案
18212
										break 3;
18213
 
18214
										}#if end
18215
 
18216
									}#if end
18217
 
18218
								#如果要複製的來源與目的地有存在於本次commit要新增的項目
18219
								if(in_array($source,$filesToCommit) && in_array($target,$filesToCommit)){
18220
 
18221
									#提示不能複製本次要commit的內容
18222
									echo "不能複製本次要commit的內容".PHP_EOL;
18223
 
18224
									#檢查下一個要複製的項目
18225
									continue;
18226
 
18227
									}#if end
18228
 
18229
								#運行 svn cpoy 的指令
18230
								#函式說明:
18231
								#呼叫shell執行系統命令,並取得回傳的內容.
18232
								#回傳結果:
18233
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18234
								#$result["error"],錯誤訊息陣列.
18235
								#$result["function"],當前執行的函數名稱.
18236
								#$result["argu"],使用的參數.
18237
								#$result["cmd"],執行的指令內容.
18238
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
18239
								#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
18240
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
18241
								#$result["running"],是否還在執行.
18242
								#$result["pid"],pid.
18243
								#$result["statusCode"],執行結束後的代碼.
18244
								#必填參數:
18245
								#$conf["command"],字串,要執行的指令與.
18246
								$conf["external::callShell"]["command"]="svn";
18247
								#$conf["fileArgu"],字串,變數__FILE__的內容.
18248
								$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
18249
								#可省略參數:
18250
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
18251
								$conf["external::callShell"]["argu"]=array("copy",$source,$argv[$argc-1]);
18252
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
18253
								#$conf["arguIsAddr"]=array();
18254
								#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
18255
								#$conf["plainArgu"]=array();
18256
								#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
18257
								#$conf["useApostrophe"]=array();
18258
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
18259
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
18260
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
18261
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
18262
								#$conf["enablePrintDescription"]="true";
18263
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
18264
								#$conf["printDescription"]="";
18265
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
18266
								$conf["external::callShell"]["escapeshellarg"]="true";
18267
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
18268
								#$conf["thereIsShellVar"]=array();
18269
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
18270
								#$conf["username"]="";
18271
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
18272
								#$conf["password"]="";
18273
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
18274
								#$conf["useScript"]="";
18275
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
18276
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
18277
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
18278
								#$conf["inBackGround"]="";
18279
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
18280
								#$conf["getErr"]="false";
18281
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
18282
								#$conf["doNotRun"]="false";
18283
								#參考資料:
18284
								#exec=>http://php.net/manual/en/function.exec.php
18285
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
18286
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
18287
								#備註:
18288
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
18289
								$callShell=external::callShell($conf["external::callShell"]);
18290
								unset($conf["external::callShell"]);
18291
 
18292
								#如果執行失敗
18293
								if($callShell["status"]==="false"){
18294
 
18295
									#設置執行失敗
18296
									$result["status"]="false";
18297
 
18298
									#設置執行失敗訊息
18299
									$result["error"]=$callShell;
18300
 
18301
									#回傳結果
18302
									return $result;
18303
 
18304
									}#if end
18305
 
18306
								#印出執行的cmd
18307
								echo "cmd:".$callShell["cmd"].PHP_EOL;
18308
 
18309
								#印出執行後的回傳代碼
18310
								echo "status:".$callShell["statusCode"].PHP_EOL;
18311
 
18312
								#針對每列輸出
18313
								foreach($callShell["output"] as $line){
18314
 
18315
									#印出內容
18316
									echo $line.PHP_EOL;
18317
 
18318
									}#foreach end
18319
 
18320
								#紀錄複製的來源與目標
18321
								$copyList[]=array("from"=>$source,"to"=>$target);
18322
 
18323
								#記錄要commit的新增檔案
18324
								$filesToCommit[]=$target;
18325
 
18326
								#記錄本次要新增的檔案
18327
								$fileAdded[]=$target;
18328
 
18329
								}#for end
18330
 
18331
							#讓使用者繼續輸入要commit的項目
18332
							break 2;
18333
 
18334
						}#switch end
18335
 
18336
					#提示參數數量不對
18337
					echo "參數數量(".$argc.")不對".PHP_EOL;
18338
 
18339
					#提示輸入的參數
18340
					foreach($argv as $no=>$p){
18341
 
18342
						#印出參數
18343
						echo "參數".$no.":".$p.PHP_EOL;
18344
 
18345
						}#foreach end
18346
 
18347
					#繼續輸入要commit的檔案名稱
18348
					break;
18349
 
18350
				}#switch end
18351
 
18352
			}#while end
18353
 
18354
		#提示輸入註解
18355
		$commentNoteText=
18356
			"請輸入註解:".PHP_EOL.
18357
			"若要結束輸入請輸入'quit'".PHP_EOL.
18358
			"若要顯示所有註解的內容請輸入'show log'".PHP_EOL.
18359
			"跳到下一列請輸入'+line'".PHP_EOL.
18360
			"跳到上一列請輸入'-line'".PHP_EOL.
18361
			"跳到檔案開頭請輸入'head'".PHP_EOL.
18362
			"跳到檔案結尾請輸入'tail'".PHP_EOL.
18363
			"跳到指定的列請輸入'to 列號'".PHP_EOL.
18364
			"若要移除指定列的註解請輸入'del 列號'".PHP_EOL.
18365
			"若要檢視commit清單請輸入'ls'".PHP_EOL.
18366
			"若要看檔案相對於repo的差異請輸入 'diff fileName'".PHP_EOL.
18367
			"若要檢視本次commit新增到版本控制的檔案目錄清單,請輸入'ls add'".PHP_EOL.
18368
			"若要檢視要移除的檔案清單請輸入'ls del'".PHP_EOL.
18369
			"若要顯示複製的清單請輸入 'ls cp'".PHP_EOL;
18370
 
18371
		#初始化註解的列陣列
18372
		$comment=array($conf["author"].PHP_EOL);
18373
 
18374
		#初始化目前指到註解那邊的pointer
18375
		$pointer=1;
18376
 
18377
		#無窮迴圈
18378
		while(true){
18379
 
18380
			#印出提示
18381
			echo $commentNoteText;
18382
 
18383
			#接收使用者的輸入
18384
			$input=trim(fgets(STDIN));
18385
 
18386
			#判斷輸入
18387
			switch($input){
18388
 
18389
				#如果輸入為 "quit"
18390
				case "quit":
18391
 
18392
					#跳出 while
18393
					break 2;
18394
 
18395
				#如果輸入為 "-line"
18396
				case "-line":
18397
 
18398
					#如果不存在上一列
18399
					if(!isset($comment[$pointer-1])){
18400
 
18401
						#提示已經是第一列了
18402
						echo "已經是檔案開頭了".PHP_EOL;
18403
 
18404
						}#if end
18405
 
18406
					#反之
18407
					else{
18408
 
18409
						#指標減1
18410
						$pointer--;
18411
 
18412
						#印出這一列的內容
18413
						echo "這一列的內容為:".$comment[$pointer].PHP_EOL;
18414
 
18415
						}#else end
18416
 
18417
					#等待下個commit的註解
18418
					break;
18419
 
18420
				#如果輸入為 "+line"
18421
				case "+line":
18422
 
18423
					#如果不存在下一列
18424
					if(!isset($comment[$pointer+1])){
18425
 
18426
						#提示已經是最後一列了
18427
						echo "已經是最後一列了".PHP_EOL;
18428
 
18429
						}#if end
18430
 
18431
					#反之
18432
					else{
18433
 
18434
						#指標加1
18435
						$pointer++;
18436
 
18437
						#印出這一列的內容
18438
						echo "這一列的內容為:".$comment[$pointer].PHP_EOL;
18439
 
18440
						}#else ened
18441
 
18442
					#等待下個commit的註解
18443
					break;
18444
 
18445
				#如果是 "head"
18446
				case "head":
18447
 
18448
					#設置pointer到開頭
18449
					$pointer=0;
18450
 
18451
					#如果存在第一列
18452
					if(isset($comment[$pointer])){
18453
 
18454
						#印出第一列的內容
18455
						echo "第一列的內容為:".$comment[$pointer].PHP_EOL;
18456
 
18457
						}#if end
18458
 
18459
					#等待下個commit的註解
18460
					break;
18461
 
18462
				#如果是 "tail"
18463
				case "tail":
18464
 
18465
					#設置pointer到最尾端
18466
					$pointer=count($comment);
18467
 
18468
					#如果存在最後一列
18469
					if(isset($comment[$pointer-1])){
18470
 
18471
						#印出最後一列的內容
18472
						echo "最後一列的內容為:".$comment[$pointer-1].PHP_EOL;
18473
 
18474
						}#if end
18475
 
18476
					#等待下個commit的註解
18477
					break;
18478
 
18479
				#如果是 "show log"
18480
				case "show log":
18481
 
18482
					#取得列數
18483
					$lineCount=$pointer+1;
18484
 
18485
					#取得列數長度
18486
					$numberLenth=strlen((string)$lineCount);
18487
 
18488
					#初始化識別是否已經顯示pointer
18489
					$showPointer=false;
18490
 
18491
					#有幾列就執行幾次
18492
					foreach($comment as $lineNum=>$lineContent){
18493
 
18494
						#如果該列號長度小於列數長度
18495
						while(strlen($lineNum)<$numberLenth){
18496
 
18497
							#在前面加上空白
18498
							$lineNum=" ".$lineNum;
18499
 
18500
							}#while end
18501
 
18502
						#列號
18503
						$lineNo="[".$lineNum."] ";
18504
 
18505
						#如果是當前列
18506
						if(intval($lineNum)===intval($pointer)){
18507
 
18508
							#顯示目前正在複寫該列內容
18509
							$lineNo=">> ".$lineNo;
18510
 
18511
							#設置已經顯示poniter
18512
							$showPointer=true;
18513
 
18514
							}#if end
18515
 
18516
						#印出列號與列內容
18517
						echo $lineNo.$lineContent;
18518
 
18519
						}#foreach end
18520
 
18521
					#如果尚未顯示pointer
18522
					if(!$showPointer){
18523
 
18524
						#列號等於$pointer
18525
						$lineNo=$pointer;
18526
 
18527
						#如果該列號長度小於列數長度
18528
						while(strlen($lineNo)<$numberLenth){
18529
 
18530
							#在前面加上空白
18531
							$lineNo=" ".$lineNo;
18532
 
18533
							}#while end
18534
 
18535
						#列號
18536
						$lineNo="[".$lineNo."] ";
18537
 
18538
						#印出當前列
18539
						echo ">> ".$lineNo.PHP_EOL;
18540
 
18541
						}#if end
18542
 
18543
					#等待下個commit的註解
18544
					break;
18545
 
18546
				#如果是 "ls"
18547
				case "ls":
18548
 
18549
					#針對每一列
18550
					foreach($filesToCommit as $lineNo=>$lineContent){
18551
 
18552
						#印出要上傳的檔案清單
18553
						echo "[".$lineNo."] ".$lineContent.PHP_EOL;
18554
 
18555
						}#foreach end
18556
 
18557
					#等待下個commit的註解
18558
					break;
18559
 
18560
				#如果是 "ls del"
18561
				case "ls del":
18562
 
18563
					#取得要移除檔案之計數長度
18564
					$fileShouldBeDeletedCountLength=strlen(count($fileShouldBeDeleted));
18565
 
18566
					#針對每個要移除的檔案
18567
					foreach($fileShouldBeDeleted as $index=>$delFile){
18568
 
18569
						#如果列數長度加3小於要移除檔案之計數長度
18570
						while(strlen($index)+3<$fileShouldBeDeletedCountLength){
18571
 
18572
							#在前面加上空格
18573
							$index=" ".$index;
18574
 
18575
							}#if end
18576
 
18577
						#印出內容
18578
						echo "[".$index."] ".$delFile.PHP_EOL;
18579
 
18580
						}#foreach end
18581
 
18582
				#如果是 "ls add"
18583
				case "ls add":
18584
 
18585
					#取得本次要新增到版本控制的檔案清單長度
18586
					$fileAddedCountLength=strlen(count($fileAdded));
18587
 
18588
					#有幾個本次要新增的版本控制的檔案就執行幾次
18589
					foreach($fileAdded as $index=>$addedFN){
18590
 
18591
						#如果列數長度加3小於要移除檔案之計數長度
18592
						while(strlen($index)+3<$fileAddedCountLength){
18593
 
18594
							#在前面加上空格
18595
							$index=" ".$index;
18596
 
18597
							}#if end
18598
 
18599
						#印出內容
18600
						echo "[".$index."] ".$addedFN.PHP_EOL;
18601
 
18602
						}#foreach end
18603
 
18604
					#等待下個commit的註解
18605
					break;
18606
 
18607
				#如果是 "ls cp"
18608
				case "ls cp":
18609
 
18610
					#取得本次要新增到版本控制的複製檔案清單長度
18611
					$fileCopiedCountLength=strlen(count($copyList));
18612
 
18613
					#有幾個本次要複製的版本控制的檔案就執行幾次
18614
					foreach($copyList as $index=>$copiedFN){
18615
 
18616
						#如果列數長度加3小於要移除檔案之計數長度
18617
						while(strlen($index)+3<$fileCopiedCountLength){
18618
 
18619
							#在前面加上空格
18620
							$index=" ".$index;
18621
 
18622
							}#if end
18623
 
18624
						#印出內容
18625
						echo "[".$index."] copy from ".$copiedFN["from"]." to ".$copiedFN["to"].PHP_EOL;
18626
 
18627
						}#foreach end
18628
 
18629
					#等待下個commit的註解
18630
					break;
18631
 
18632
				#視為註解
18633
				default:
18634
 
18635
					#如果存在 $fileName
18636
					if(isset($fileName)){
18637
 
18638
						#移除之
18639
						unset($fileName);
18640
 
18641
						}#if end
18642
 
18643
					#函式說明:
18644
					#將字串進行解析,變成多個參數.
18645
					#回傳結果:
18646
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
18647
					#$result["function"],當前執行的函式內容.
18648
					#$result["error"],錯誤訊息陣列.
18649
					#$result["content"],參數陣列.
18650
					#$result["count"],總共有幾個參數.
18651
					#必填參數:
18652
					#$conf["input"],字串,要解析成參數的字串.
18653
					$conf["stringProcess::parse"]["input"]=$input;
18654
					#建議:
18655
					#改用cmd::getArgu構成的command去parse字串
18656
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
18657
					unset($conf["stringProcess::parse"]);
18658
 
18659
					#如果處理錯誤
18660
					if($parse["status"]==="false"){
18661
 
18662
						#如果是 bash 語法錯誤
18663
						if($parse["error"][0]==="bash syntax error"){
18664
 
18665
							#提示錯誤訊息
18666
							echo $parse["error"][0].PHP_EOL;
18667
 
18668
							#提示錯誤訊息
18669
							echo $parse["error"][1]["content"][0]["error"];
18670
 
18671
							#debug
18672
							#var_dump($parse);
18673
 
18674
							#等待下個commit的註解
18675
							break;
18676
 
18677
							}#if end
18678
 
18679
						#設置錯誤訊息
18680
						$result["error"]=$parse;
18681
 
18682
						#設置執行失敗
18683
						$result["status"]="false";
18684
 
18685
						#回傳結果
18686
						return $result;
18687
 
18688
						}#if end
18689
 
18690
					#取得參數數量
18691
					$argc=$parse["count"];
18692
 
18693
					#取得參數陣列
18694
					$param=$parse["content"];
18695
 
18696
					#依照參數的數量
18697
					switch($argc){
18698
 
18699
						#兩個參數
18700
						case "2":
18701
 
18702
							#如果第一個字串為 "diff" ,第二個字串代表要比較的目標檔案.
18703
							if($param[0]==="diff"){
18704
 
18705
								#更新目標檔案名稱
18706
								#函式說明:
18707
								#清除字串的「"」或「'」符號.
18708
								#回傳結果:
18709
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
18710
								#$result["function"],當前執行的函式內容.
18711
								#$result["error"],錯誤訊息陣列.
18712
								#$result["content"],剔除「"」或「'」符號後的字串.
18713
								#必填參數:
18714
								#$conf["str"],字串,要處理的字串.
18715
								#$conf["str"]="";
18716
								#可省略參數:
18717
								#無.
18718
								#參考資料:
18719
								#無.
18720
								#備註:
18721
								#無.
18722
								$conf["stringProcess::clearStrSymbol"]["str"]=$param[1];
18723
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
18724
								unset($conf["stringProcess::clearStrSymbol"]);
18725
 
18726
								#如果parse字串失敗
18727
								if($clearStrSymbol["status"]==="false"){
18728
 
18729
									#設置執行失敗
18730
									$result["status"]="false";
18731
 
18732
									#設置錯誤訊息
18733
									$result["error"]=$clearStrSymbol;
18734
 
18735
									#回傳結果
18736
									return $result;
18737
 
18738
									}#if end
18739
 
18740
								#如果目標檔案存在
18741
								if(file_exists($clearStrSymbol["content"])){
18742
 
18743
									#函式說明:
18744
									#呼叫shell執行系統命令,並取得回傳的內容.
18745
									#回傳結果:
18746
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18747
									#$result["error"],錯誤訊息陣列.
18748
									#$result["function"],當前執行的函數名稱.
18749
									#$result["argu"],使用的參數.
18750
									#$result["cmd"],執行的指令內容.
18751
									#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
18752
									#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
18753
									#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
18754
									#$result["running"],是否還在執行.
18755
									#$result["pid"],pid.
18756
									#$result["statusCode"],執行結束後的代碼.
18757
									#必填參數:
18758
									#$conf["command"],字串,要執行的指令與.
18759
									$conf["external::callShell"]["command"]="svn";
18760
									#$conf["fileArgu"],字串,變數__FILE__的內容.
18761
									$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
18762
									#可省略參數:
18763
									#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
18764
									$conf["external::callShell"]["argu"]=array("diff",$param[1]);
18765
									#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
18766
									#$conf["arguIsAddr"]=array();
18767
									#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
18768
									#$conf["plainArgu"]=array();
18769
									#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
18770
									#$conf["useApostrophe"]=array();
18771
									#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
18772
									#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
18773
									#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
18774
									#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
18775
									#$conf["enablePrintDescription"]="true";
18776
									#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
18777
									#$conf["printDescription"]="";
18778
									#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
18779
									$conf["external::callShell"]["escapeshellarg"]="true";
18780
									#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
18781
									#$conf["thereIsShellVar"]=array();
18782
									#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
18783
									#$conf["username"]="";
18784
									#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
18785
									#$conf["password"]="";
18786
									#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
18787
									#$conf["useScript"]="";
18788
									#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
18789
									#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
18790
									#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
18791
									#$conf["inBackGround"]="";
18792
									#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
18793
									#$conf["getErr"]="false";
18794
									#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
18795
									#$conf["doNotRun"]="false";
18796
									#參考資料:
18797
									#exec=>http://php.net/manual/en/function.exec.php
18798
									#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
18799
									#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
18800
									#備註:
18801
									#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
18802
									$callShell=external::callShell($conf["external::callShell"]);
18803
									unset($conf["external::callShell"]);
18804
 
18805
									#如果執行失敗
18806
									if($callShell["status"]==="false"){
18807
 
18808
										#設置執行失敗
18809
										$result["status"]="false";
18810
 
18811
										#設置執行失敗訊息
18812
										$result["error"]=$callShell;
18813
 
18814
										#回傳結果
18815
										return $result;
18816
 
18817
										}#if end
18818
 
18819
									#印出執行的cmd
18820
									echo "cmd:".$callShell["cmd"].PHP_EOL;
18821
 
18822
									#印出執行後的回傳代碼
18823
									echo "status:".$callShell["statusCode"].PHP_EOL;
18824
 
18825
									#針對每列輸出
18826
									foreach($callShell["output"] as $line){
18827
 
18828
										#印出內容
18829
										echo $line.PHP_EOL;
18830
 
18831
										}#foreach end
18832
 
18833
									}#if end
18834
 
18835
								#反之代表目標檔案不存在
18836
								else{
18837
 
18838
									#題書目標檔案不存在
18839
									echo "目標檔案「".$clearStrSymbol["content"]."」不存在!".PHP_EOL;
18840
 
18841
									}#else end
18842
 
18843
								#繼續讓使用者輸入註解
18844
								continue 3;
18845
 
18846
								}#if end
18847
 
18848
							#如果第一個字串為 "to" ,第二個字串代表要去的列(整數)
18849
							else if($param[0]==="to" && is_int(intval($param[1]))){
18850
 
18851
								#如果目標列存在
18852
								if(isset($comment[$param[1]])){
18853
 
18854
									#設置pointer
18855
									$pointer=$param[1];
18856
 
18857
									#提示目標列的內容
18858
									echo "這一列的內容為:".$comment[$pointer].PHP_EOL;
18859
 
18860
									#繼續讓使用者輸入註解
18861
									continue 3;
18862
 
18863
									}#if end
18864
 
18865
								#反之
18866
								else{
18867
 
18868
									#提示目標列不存在
18869
									echo "目標列(".$param[1].")不存在".PHP_EOL;
18870
 
18871
									#繼續讓使用者輸入註解
18872
									continue 3;
18873
 
18874
									}#else end
18875
 
18876
								}#if end
18877
 
18878
							#如果第一個字串為 "del" ,第二個字串代表要去的列(整數)
18879
							else if($param[0]==="del" && is_int(intval($param[1]))){
18880
 
18881
								#debug
18882
								echo "移除註解列".PHP_EOL;
18883
 
18884
								#如果目標列存在
18885
								if(isset($comment[$param[1]])){
18886
 
18887
									#提示目標列的內容
18888
									echo "移除列「".$param[1]."」的內容「".trim($comment[$param[1]])."」".PHP_EOL;
18889
 
18890
									#移除目標列
18891
									unset($comment[$param[1]]);
18892
 
18893
									#如果被移除的列號大於1
18894
									if($param[1]>0){
18895
 
18896
										#設置pointer為被移除列減1
18897
										$pointer=$param[1]-1;
18898
 
18899
										}#if end
18900
 
18901
									#暫存排序好的註解陣列
18902
									$tempCA=array();
18903
 
18904
									#依據每列註解
18905
									foreach($comment as $lineVal){
18906
 
18907
										#取得註解列的內容
18908
										$tempCA[]=$lineVal;
18909
 
18910
										}#foreach end
18911
 
18912
									#取得重新排序好的註解陣列
18913
									$comment=$tempCA;
18914
 
18915
									#提示目標列的內容
18916
									echo "這一列的內容為:".$comment[$pointer].PHP_EOL;
18917
 
18918
									#繼續讓使用者輸入註解
18919
									continue 3;
18920
 
18921
									}#if end
18922
 
18923
								#反之
18924
								else{
18925
 
18926
									#提示目標列不存在
18927
									echo "目標列(".$param[1].")不存在".PHP_EOL;
18928
 
18929
									#繼續讓使用者輸入註解
18930
									continue 3;
18931
 
18932
									}#else end
18933
 
18934
								}#if end
18935
 
18936
							#跳出switch
18937
							break;
18938
 
18939
						#0個參數
18940
						case "0":
18941
 
18942
							#繼續讓使用者輸入註解
18943
							continue 3;
18944
 
18945
						#其他參數數量
18946
						default:
18947
 
18948
							#寫入換行跟輸入的內容
18949
							$comment[$pointer]=escapeshellarg($input).PHP_EOL;
18950
 
18951
							#指標+1
18952
							$pointer++;
18953
 
18954
							#印出上一列的內容
18955
							echo "上一列的內容為:".$comment[$pointer-1].PHP_EOL;
18956
 
18957
							#繼續讓使用者輸入註解
18958
							continue 3;
18959
 
18960
						}#switch end
18961
 
18962
					#寫入換行跟輸入的內容
18963
					$comment[$pointer]=escapeshellarg($input).PHP_EOL;
18964
 
18965
					#指標+1
18966
					$pointer++;
18967
 
18968
					#印出上一列的內容
18969
					echo "上一列的內容為:".$comment[$pointer-1].PHP_EOL;
18970
 
18971
					#繼續讓使用者輸入註解
18972
					continue 2;
18973
 
18974
				}#switch end
18975
 
18976
			}#while end
18977
 
18978
		#如果有要移除的檔案
18979
		if(count($fileShouldBeDeleted)>0){
18980
 
18981
			#針對每個要移除的檔案
18982
			foreach($fileShouldBeDeleted as $delFile){
18983
 
18984
				#函式說明:
18985
				#呼叫shell執行系統命令,並取得回傳的內容.
18986
				#回傳結果:
18987
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18988
				#$result["error"],錯誤訊息陣列.
18989
				#$result["function"],當前執行的函數名稱.
18990
				#$result["argu"],使用的參數.
18991
				#$result["cmd"],執行的指令內容.
18992
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
18993
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
18994
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
18995
				#$result["running"],是否還在執行.
18996
				#$result["pid"],pid.
18997
				#$result["statusCode"],執行結束後的代碼.
18998
				#必填參數:
18999
				#$conf["command"],字串,要執行的指令與.
19000
				$conf["external::callShell"]["command"]="svn";
19001
				#$conf["fileArgu"],字串,變數__FILE__的內容.
19002
				$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
19003
				#可省略參數:
19004
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
19005
				$conf["external::callShell"]["argu"]=array("--force","del",$delFile);
19006
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
19007
				#$conf["arguIsAddr"]=array();
19008
				#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
19009
				#$conf["plainArgu"]=array();
19010
				#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
19011
				#$conf["useApostrophe"]=array();
19012
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
19013
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
19014
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
19015
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
19016
				#$conf["enablePrintDescription"]="true";
19017
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
19018
				#$conf["printDescription"]="";
19019
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
19020
				$conf["external::callShell"]["escapeshellarg"]="true";
19021
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
19022
				#$conf["thereIsShellVar"]=array();
19023
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
19024
				#$conf["username"]="";
19025
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
19026
				#$conf["password"]="";
19027
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
19028
				#$conf["useScript"]="";
19029
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
19030
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
19031
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
19032
				#$conf["inBackGround"]="";
19033
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
19034
				#$conf["getErr"]="false";
19035
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
19036
				#$conf["doNotRun"]="false";
19037
				#參考資料:
19038
				#exec=>http://php.net/manual/en/function.exec.php
19039
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
19040
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
19041
				#備註:
19042
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
19043
				$callShell=external::callShell($conf["external::callShell"]);
19044
				unset($conf["external::callShell"]);
19045
 
19046
				#如果執行失敗
19047
				if($callShell["status"]==="false"){
19048
 
19049
					#設置執行失敗
19050
					$result["status"]="false";
19051
 
19052
					#設置執行失敗訊息
19053
					$result["error"]=$callShell;
19054
 
19055
					#回傳結果
19056
					return $result;
19057
 
19058
					}#if end
19059
 
19060
				#印出執行的cmd
19061
				echo "cmd:".$callShell["cmd"].PHP_EOL;
19062
 
19063
				#印出執行後的回傳代碼
19064
				echo "status:".$callShell["statusCode"].PHP_EOL;
19065
 
19066
				}#foreach end
19067
 
19068
			}#if end
19069
 
19070
		#函式說明:
19071
		#建立暫存目錄與回傳暫存檔案名稱路徑 
19072
		#回傳結果:
19073
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19074
		#$result["error"],錯誤訊息.
19075
		#$result["function"],當前執行的函數名稱.
19076
		#$result["content"],暫存檔案的路徑與名稱.
19077
		#必填參數:
19078
		#無.
19079
		#可省略參數:
19080
		#無.
19081
		#參考資料:
19082
		#無.
19083
		#備註:
19084
		#無.
37 liveuser 19085
		$conf["conffileAccess::createTempFile"]=array();
19086
		$createTempFile=fileAccess::createTempFile($conf["conffileAccess::createTempFile"]);
19087
		unset($conf["conffileAccess::createTempFile"]);
3 liveuser 19088
 
19089
		#如果執行失敗
19090
		if($createTempFile["status"]==="false"){
19091
 
19092
			#設置執行失敗
19093
			$result["status"]="false";
19094
 
19095
			#設置執行失敗訊息
19096
			$result["error"]=$createTempFile;
19097
 
19098
			#回傳結果
19099
			return $result;
19100
 
19101
			}#if end
19102
 
19103
		#指定 commit log file
19104
		$commitLogFile=$createTempFile["content"];
19105
 
19106
		#函式說明:
19107
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
19108
		#回傳的結果:
19109
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19110
		#$result["function"],當前執行的function名稱
19111
		#$result["error"],錯誤訊息陣列.
19112
		#$result["content"],處理好的字串.
19113
		#$result["argu"],使用的參數.
19114
		#必填參數:
19115
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
19116
		$conf["arrays::arrayToString"]["inputArray"]=$comment;
19117
		#可省略參數:
19118
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
19119
		$conf["arrays::arrayToString"]["spiltSymbol"]=PHP_EOL;
19120
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
19121
		$conf["arrays::arrayToString"]["skipEnd"]="true";
19122
		#參考資料:
19123
		#無.
19124
		#備註:
19125
		#無.
19126
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
19127
		unset($conf["arrays::arrayToString"]);
19128
 
19129
		#如果執行失敗
19130
		if($arrayToString["status"]==="false"){
19131
 
19132
			#設置執行失敗
19133
			$result["status"]="false";
19134
 
19135
			#設置執行失敗訊息
19136
			$result["error"]=$arrayToString;
19137
 
19138
			#回傳結果
19139
			return $result;
19140
 
19141
			}#if end
19142
 
19143
		#取得註解字串
19144
		$commentStr=$arrayToString["content"];
19145
 
19146
		#函式說明:
19147
		#將字串寫入到檔案
19148
		#回傳結果:
19149
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
19150
		#$result["error"],錯誤訊息陣列.
19151
		#$result["function"],當前執行的函數名稱.
19152
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
19153
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
19154
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
19155
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
19156
		#$result["argu"],使用的參數.
19157
		#必填參數:
19158
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
19159
		$conf["fileAcceess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
19160
		#可省略參數:
19161
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
19162
		$conf["fileAcceess::writeTextIntoFile"]["fileName"]=$commitLogFile;
19163
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
19164
		$conf["fileAcceess::writeTextIntoFile"]["inputString"]=$commentStr;
19165
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
19166
		#$conf["writeMethod"]="a";
19167
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
19168
		#$conf["checkRepeat"]="";
19169
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
19170
		#$conf["filenameExtensionStartPoint"]="";
19171
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
19172
		#$conf["repeatNameRule"]="";
19173
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
19174
		$conf["fileAcceess::writeTextIntoFile"]["web"]="false";
19175
		#參考資料:
19176
		#無.
19177
		#備註:
19178
		#無.
19179
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAcceess::writeTextIntoFile"]);
19180
		unset($conf["fileAcceess::writeTextIntoFile"]);
19181
 
19182
		#如果執行失敗
19183
		if($writeTextIntoFile["status"]==="false"){
19184
 
19185
			#設置執行失敗
19186
			$result["status"]="false";
19187
 
19188
			#設置執行失敗訊息
19189
			$result["error"]=$writeTextIntoFile;
19190
 
19191
			#回傳結果
19192
			return $result;
19193
 
19194
			}#if end
19195
 
19196
		#函式說明:
19197
		#將多個一維陣列串聯起來,key從0開始排序.
19198
		#回傳的結果:
19199
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
19200
		#$result["error"],錯誤訊息陣列.
19201
		#$result["function"],當前執行的函式.
19202
		#$result["content"],合併好的一維陣列.
19203
		#必填參數:
19204
		#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
19205
		$conf["arrays::mergeArray"]["inputArray"]=array(array($storedPass,"|","sshpass","-v","svn","commit","-F",$commitLogFile),$filesToCommit,array($sshOption));
19206
		#可省略參數:
19207
		#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
19208
		#$conf["allowRepeat"]="true";
19209
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
19210
		unset($conf["arrays::mergeArray"]);
19211
 
19212
		#如果建立新陣列失敗
19213
		if($mergeArray["status"]==="false"){
19214
 
19215
			#設置執行錯誤
19216
			$result["error"]=$mergeArray;
19217
 
19218
			#設置執行不正常
19219
			$result["status"]="false";
19220
 
19221
			#回傳結果
19222
			return $result;
19223
 
19224
			}#if end
19225
 
19226
		#函式說明:
19227
		#呼叫shell執行系統命令,並取得回傳的內容.
19228
		#回傳的結果:
19229
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19230
		#$result["error"],錯誤訊息陣列.
19231
		#$result["function"],當前執行的函式名稱.
19232
		#$result["argu"],使用的參數.
19233
		#$result["cmd"],執行的指令內容.
19234
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
19235
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
19236
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
19237
		#$result["running"],是否還在執行.
19238
		#$result["pid"],pid
19239
		#$result["statusCode"],執行結束後的代碼.
19240
		#必填參數:
19241
		#$conf["command"],字串,要執行的指令與.
19242
		$conf["external::callShell"]["command"]="echo";
19243
		#$conf["fileArgu"],字串,變數__FILE__的內容.
19244
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
19245
		#可省略參數:
19246
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
19247
		$conf["external::callShell"]["argu"]=$mergeArray["content"];
19248
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
19249
		#$conf["arguIsAddr"]=array();
19250
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
19251
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
19252
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
19253
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
19254
		#$conf["enablePrintDescription"]="true";
19255
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
19256
		#$conf["printDescription"]="";
19257
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
19258
		$conf["external::callShell"]["escapeshellarg"]="true";
19259
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
19260
		#$conf["username"]="";
19261
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
19262
		#$conf["password"]="";
19263
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
19264
		#$conf["useScript"]="";
19265
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
19266
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
19267
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
19268
		#$conf["inBackGround"]="";
19269
		#備註:
19270
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
19271
		#參考資料:
19272
		#exec=>http://php.net/manual/en/function.exec.php
19273
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
19274
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
19275
		$callShell=external::callShell($conf["external::callShell"]);
19276
		unset($conf["external::callShell"]);
19277
 
19278
		#紀錄 commit 的指令
19279
		$result["content"]["cmd"]=$callShell["cmd"];
19280
 
19281
		#紀錄 commit 的註解
19282
		$result["content"]["commit"]=$commentStr;
19283
 
19284
		#移除commit用的註解檔案
19285
		#函式說明:
19286
		#移除檔案
19287
		#回傳結果:
19288
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
19289
		#$result["error"],錯誤訊息陣列
19290
		#$result["warning"],警告訊息陣列
19291
		#$result["function"],當前執行的函數名稱
19292
		#必填參數:
19293
		#$conf["fileAddress"],字串,要移除檔案的位置.
19294
		$conf["fileAccess::delFile"]["fileAddress"]=$commitLogFile;
19295
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
19296
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
19297
		#可省略參數:
19298
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
19299
		#$conf["commentsArray"]=array("");
19300
		#參考資料:
19301
		#無.
19302
		#備註:
19303
		#無.
19304
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
19305
		unset($conf["fileAccess::delFile"]);
19306
 
19307
		#如果移除暫存檔案失敗
19308
		if($delFile["status"]==="false"){
19309
 
19310
			#設置執行錯誤
19311
			$result["error"]=$delFile;
19312
 
19313
			#設置執行不正常
19314
			$result["status"]="false";
19315
 
19316
			#回傳結果
19317
			return $result;
19318
 
19319
			}#if end
19320
 
19321
		#紀錄 commit 的結果
19322
		$result["content"]["content"]=$callShell["output"];
19323
 
19324
		#如果svn指令的輸出為空
19325
		if($result["content"]["content"]===array()){
19326
 
19327
			#給予可能是被svn server拒絕的提示
19328
			$result["content"]["content"][]="未commit,請檢查要commit的檔案是否與repo上的檔案沒有差異。";
19329
 
19330
			}#if end
19331
 
19332
		#記錄 commit 執行後的回傳代碼
19333
		$result["content"]["status"]=$callShell["statusCode"];
19334
 
19335
		#設置執行正常
19336
		$result["status"]="true";
19337
 
19338
		#回傳結果
19339
		return $result;
19340
 
19341
		}#function svnci end
19342
 
19343
	/*
19344
	#函式說明:
19345
	#顯示網路連線的資訊.
19346
	#回傳結果:
19347
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19348
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
19349
	#$result["function"],當前執行的函式名稱.
19350
	#$result["cmd"],實際執行的指令.
19351
	#$result["content"],執行完ip link show得到的終端輸出.
19352
	#$result["content"][$i],第$i+1個網路設備資訊陣列
19353
	#$result["content"][$i]["devName"],第$i+1個網路設備的名稱.
19354
	#$result["content"][$i]["deviceFlags"][$flag],第$i+1個網路設備擁有$flag屬性.
19355
	#$result["content"][$i]["mac"],第$i+1個網路設備的mac.
19356
	#$result["content"][$i]["brd"],第$i+1個網路設備的廣播位置.
19357
	#$result["content"][$i]["deviceAttr"]["mtu"],$i+1個網路設備的mtu(Maximum Transmission Unit;最大傳輸單元)屬性數值.
19358
	#$result["content"][$i]["deviceAttr"]["qdisc"],$i+1個網路設備的qdisc(queueing disciplines;佇列規則)屬性數值.
19359
	#$result["content"][$i]["deviceAttr"]["state"],$i+1個網路設備的state(UP:啟用;DOWN:停用)屬性數值.
19360
	#$result["content"][$i]["deviceAttr"]["mode"],$i+1個網路設備的mode屬性數值.
19361
	#$result["content"][$i]["deviceAttr"]["group"],$i+1個網路設備的group屬性數值.
19362
	#$result["content"][$i]["deviceAttr"]["qlen"],$i+1個網路設備的qlen(The length of the transmission queue)屬性數值.
19363
	#$result["content"][$i]["deviceAttr"]["master"],$i+1個網路設備的master(歸屬於哪個網路設備)屬性數值.
19364
	#必填參數:
19365
	#$conf["fileArgu"],字串,變數__FILE__的內容.
19366
	$conf["fileArgu"]=__FILE__;
19367
	#可省略參數:
19368
	#$conf["linkName"],字串,要檢視的連線名稱,若省略則會顯示所有的網路設備資訊
19369
	#$conf["linkName"]="";
19370
	#參考資料:
19371
	#LOWER_UP=>http://www.linuxforums.org/forum/networking/155196-what-does-lower_up-state-mean.html
19372
	#備註:
19373
	#需要ip link show指令能夠運作.
19374
	*/
19375
	public static function ipLinkShow(&$conf=array()){
19376
 
19377
		#初始化要回傳的結果
19378
		$result=array();
19379
 
19380
		#取得當前執行的函式名稱
19381
		$result["function"]=__FUNCTION__;
19382
 
19383
		#取得參數
19384
		$result["argu"]=$conf;
19385
 
19386
		#如果 $conf 不為陣列
19387
		if(gettype($conf)!="array"){
19388
 
19389
			#設置執行失敗
19390
			$result["status"]="false";
19391
 
19392
			#設置執行錯誤訊息
19393
			$result["error"][]="\$conf變數須為陣列形態";
19394
 
19395
			#如果傳入的參數為 null
19396
			if($conf==null){
19397
 
19398
				#設置執行錯誤訊息
19399
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
19400
 
19401
				}#if end
19402
 
19403
			#回傳結果
19404
			return $result;
19405
 
19406
			}#if end
19407
 
19408
		#檢查參數
19409
		#函式說明:
19410
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
19411
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19412
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
19413
		#$result["function"],當前執行的函式名稱.
19414
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
19415
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
19416
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
19417
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
19418
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
19419
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
19420
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
19421
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
19422
		#必填寫的參數:
19423
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
19424
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
19425
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
19426
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
19427
		#可以省略的參數:
19428
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
19429
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
19430
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
19431
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
19432
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
19433
		#$conf["canBeEmptyString"]="false";
19434
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
19435
		#$conf["canNotBeEmpty"]=array();
19436
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
19437
		#$conf["canBeEmpty"]=array();
19438
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
19439
		#$conf["skipableVariableCanNotBeEmpty"]=array();
19440
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
19441
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("linkName");
19442
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
19443
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
19444
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
19445
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");
19446
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
19447
		#$conf["disallowAllSkipableVarIsEmpty"]="";
19448
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
19449
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
19450
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
19451
		#$conf["arrayCountEqualCheck"][]=array();
19452
		#參考資料來源:
19453
		#array_keys=>http://php.net/manual/en/function.array-keys.php
19454
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
19455
		unset($conf["variableCheck::checkArguments"]);
19456
 
19457
		#如果檢查參數失敗
19458
		if($checkArguments["status"]==="false"){
19459
 
19460
			#設置執行失敗
19461
			$result["status"]="false";
19462
 
19463
			#設置執行錯誤訊息
19464
			$result["error"]=$checkArguments;
19465
 
19466
			#回傳結果
19467
			return $result;
19468
 
19469
			}#if end
19470
 
19471
		#如果檢查參數不通過
19472
		if($checkArguments["passed"]==="false"){
19473
 
19474
			#設置執行失敗
19475
			$result["status"]="false";
19476
 
19477
			#設置執行錯誤訊息
19478
			$result["error"]=$checkArguments;
19479
 
19480
			#回傳結果
19481
			return $result;
19482
 
19483
			}#if end
19484
 
19485
		#執行 ip link show 指令
19486
		#函式說明:
19487
		#呼叫shell執行系統命令,並取得回傳的內容.
19488
		#回傳的結果:
19489
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19490
		#$result["error"],錯誤訊息陣列.
19491
		#$result["function"],當前執行的函式名稱.
19492
		#$result["cmd"],執行的指令內容.
19493
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
19494
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
19495
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
19496
		#$result["running"],是否還在執行.
19497
		#$result["pid"],pid
19498
		#必填參數:
19499
		#$conf["command"],字串,要執行的指令與.
19500
		$conf["external::callShell"]["command"]="ip";
19501
		#$conf["fileArgu"],字串,變數__FILE__的內容.
19502
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
19503
		#可省略參數:
19504
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
19505
		$conf["external::callShell"]["argu"]=array("link","show",$conf["linkName"]);
19506
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
19507
		#$conf["arguIsAddr"]=array();
19508
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
19509
		#$conf["enablePrintDescription"]="true";
19510
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
19511
		#$conf["printDescription"]="";
19512
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
19513
		$conf["external::callShell"]["escapeshellarg"]="true";
19514
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
19515
		#$conf["external::callShell"]["username"]="root";
19516
		#$conf["password"],字串,root使用者的密碼,預設不使用密碼,該參數不適用於apache環境.
19517
		#$conf["external::callShell"]["password"]="";
19518
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
19519
		#$conf["useScript"]="";
19520
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
19521
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
19522
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
19523
		#$conf["inBackGround"]="";
19524
		#備註:
19525
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
19526
		#參考資料:
19527
		#exec=>http://php.net/manual/en/function.exec.php
19528
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
19529
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
19530
		$callShell=external::callShell($conf["external::callShell"]);
19531
		unset($conf["external::callShell"]);
19532
 
19533
		#如果運行 ip link show 指令失敗
19534
		if($callShell["status"]==="false"){
19535
 
19536
			#設置執行失敗
19537
			$result["status"]="false";
19538
 
19539
			#設置執行錯誤訊息
19540
			$result["error"]=$callShell;
19541
 
19542
			#回傳結果
19543
			return $result;
19544
 
19545
			}#if end
19546
 
19547
		#如果輸出的列數不為偶數
19548
		if(count($callShell["output"])%2!==0){
19549
 
19550
			#設置執行失敗
19551
			$result["status"]="false";
19552
 
19553
			#設置執行錯誤訊息
19554
			$result["error"][]="輸出列數不正常";
19555
 
19556
			#回傳結果
19557
			return $result;
19558
 
19559
			}#if end
19560
 
19561
		#初始化用來判斷奇偶數的變數
19562
		$odd_even=0;
19563
 
19564
		#初始化用來計數第幾個網路設備的索引
19565
		$index=0;
19566
 
19567
		#初始化用來暫存網路設備的資訊
19568
		$info=array();
19569
 
19570
		#解析回傳的內容
19571
		foreach($callShell["output"] as $lineNo => $lineContent){
19572
 
19573
			#取得是否為奇偶數
19574
			$odd_even=($odd_even+1)%2;
19575
 
19576
			#如果是奇數列
19577
			if($odd_even===1){
19578
 
19579
				#1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
19580
 
19581
				#用 ": " 分割
19582
				#函式說明:
19583
				#將固定格式的字串分開,並回傳分開的結果。
19584
				#回傳結果:
19585
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19586
				#$result["error"],錯誤訊息陣列
19587
				#$result["function"],當前執行的函式名稱.
19588
				#$result["oriStr"],要分割的原始字串內容
19589
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
19590
				#$result["dataCounts"],爲總共分成幾段
19591
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
19592
				#必填參數:
19593
				$conf["stringProcess::spiltString"]["stringIn"]=$lineContent;#要處理的字串。
19594
				$conf["stringProcess::spiltString"]["spiltSymbol"]=": ";#爲以哪個符號作爲分割
19595
				#可省略參數:
19596
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
19597
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
19598
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
19599
				unset($conf["stringProcess::spiltString"]);
19600
 
19601
				#如果分割字串失敗
19602
				if($spiltString["status"]==="false"){
19603
 
19604
					#設置執行失敗
19605
					$result["status"]="false";
19606
 
19607
					#設置執行錯誤訊息
19608
					$result["error"]=$spiltString;
19609
 
19610
					#回傳結果
19611
					return $result;
19612
 
19613
					}#if end
19614
 
19615
				#如果分割字串的關鍵字不存在
19616
				if($spiltString["found"]==="false"){
19617
 
19618
					#設置執行失敗
19619
					$result["status"]="false";
19620
 
19621
					#設置執行錯誤訊息
19622
					$result["error"]=$spiltString;
19623
 
19624
					#回傳結果
19625
					return $result;
19626
 
19627
					}#if end
19628
 
19629
				#如果分割出來小於兩段
19630
				if($spiltString["dataCounts"]<2){
19631
 
19632
					#設置執行失敗
19633
					$result["status"]="false";
19634
 
19635
					#設置執行錯誤訊息
19636
					$result["error"]=$spiltString;
19637
 
19638
					#回傳結果
19639
					return $result;
19640
 
19641
					}#if end
19642
 
19643
				#取得網路設備索引
19644
				$index=$spiltString["dataArray"][0]-1;
19645
 
19646
				#取得網路設備名稱
19647
				$devName=$spiltString["dataArray"][1];
19648
 
19649
				#記錄網路設備名稱
19650
				$info["devName"]=$devName;
19651
 
19652
				#初始化剩下的字串
19653
				$unParseStr="";
19654
 
19655
				#將剩下的傳接起來
19656
				for($i=2;$i<$spiltString["dataCounts"];$i++){
19657
 
19658
					#串接字串
19659
					$unParseStr=$unParseStr.$spiltString["dataArray"][$i];
19660
 
19661
					}#for end
19662
 
19663
				#<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
19664
 
19665
				#用 " " 分割
19666
				#函式說明:
19667
				#將固定格式的字串分開,並回傳分開的結果。
19668
				#回傳結果:
19669
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19670
				#$result["error"],錯誤訊息陣列
19671
				#$result["function"],當前執行的函式名稱.
19672
				#$result["oriStr"],要分割的原始字串內容
19673
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
19674
				#$result["dataCounts"],爲總共分成幾段
19675
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
19676
				#必填參數:
19677
				$conf["stringProcess::spiltString"]["stringIn"]=$unParseStr;#要處理的字串。
19678
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
19679
				#可省略參數:
19680
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
19681
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
19682
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
19683
				unset($conf["stringProcess::spiltString"]);
19684
 
19685
				#如果分割字串失敗
19686
				if($spiltString["status"]==="false"){
19687
 
19688
					#設置執行失敗
19689
					$result["status"]="false";
19690
 
19691
					#設置執行錯誤訊息
19692
					$result["error"]=$spiltString;
19693
 
19694
					#回傳結果
19695
					return $result;
19696
 
19697
					}#if end
19698
 
19699
				#如果分割字串的關鍵字不存在
19700
				if($spiltString["found"]==="false"){
19701
 
19702
					#設置執行失敗
19703
					$result["status"]="false";
19704
 
19705
					#設置執行錯誤訊息
19706
					$result["error"]=$spiltString;
19707
 
19708
					#回傳結果
19709
					return $result;
19710
 
19711
					}#if end
19712
 
19713
				#如果分割出來小於1段
19714
				if($spiltString["dataCounts"]<1){
19715
 
19716
					#設置執行失敗
19717
					$result["status"]="false";
19718
 
19719
					#設置執行錯誤訊息
19720
					$result["error"]=$spiltString;
19721
 
19722
					#回傳結果
19723
					return $result;
19724
 
19725
					}#if end
19726
 
19727
				#<LOOPBACK,UP,LOWER_UP>
19728
 
19729
				#剔除開頭的"<"跟結尾的">"
19730
				#函式說明:
19731
				#處理字串避免網頁出錯
19732
				#回傳的結果:
19733
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19734
				#$result["function"],當前執行的函式.
19735
				#$result["content"],爲處理好的字串.
19736
				#$result["error"],錯誤訊息陣列.
19737
				#必填參數:
19738
				$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][0];#爲要處理的字串
19739
				#可省略參數:
19740
				$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("<",">");#爲被選擇要處理的字串/字元,須爲陣列值。
19741
					#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
19742
					#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
19743
				#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
19744
				$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
19745
				unset($conf["stringProcess::correctCharacter"]);
19746
 
19747
				#如果過濾 "<" ">" 失敗
19748
				if($correctCharacter["status"]==="false"){
19749
 
19750
					#設置執行失敗
19751
					$result["status"]="false";
19752
 
19753
					#設置執行錯誤訊息
19754
					$result["error"]=$correctCharacter;
19755
 
19756
					#回傳結果
19757
					return $result;
19758
 
19759
					}#if end
19760
 
19761
				#取得網路實體層的資訊
19762
				$lowLevelStr=$correctCharacter["content"];
19763
 
19764
				#LOOPBACK,UP,LOWER_UP
19765
 
19766
				#用 "," 分割
19767
				#函式說明:
19768
				#將固定格式的字串分開,並回傳分開的結果。
19769
				#回傳結果:
19770
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19771
				#$result["error"],錯誤訊息陣列
19772
				#$result["function"],當前執行的函式名稱.
19773
				#$result["oriStr"],要分割的原始字串內容
19774
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
19775
				#$result["dataCounts"],爲總共分成幾段
19776
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
19777
				#必填參數:
19778
				$conf["stringProcess::spiltString"]["stringIn"]=$lowLevelStr;#要處理的字串。
19779
				$conf["stringProcess::spiltString"]["spiltSymbol"]=",";#爲以哪個符號作爲分割
19780
				#可省略參數:
19781
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
19782
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
19783
				$lowLevelStr=stringProcess::spiltString($conf["stringProcess::spiltString"]);
19784
				unset($conf["stringProcess::spiltString"]);
19785
 
19786
				#如果分割字串失敗
19787
				if($lowLevelStr["status"]==="false"){
19788
 
19789
					#設置執行失敗
19790
					$result["status"]="false";
19791
 
19792
					#設置執行錯誤訊息
19793
					$result["error"]=$lowLevelStr;
19794
 
19795
					#回傳結果
19796
					return $result;
19797
 
19798
					}#if end
19799
 
19800
				#如果分割字串的關鍵字不存在
19801
				if($lowLevelStr["found"]==="false"){
19802
 
19803
					#設置執行失敗
19804
					$result["status"]="false";
19805
 
19806
					#設置執行錯誤訊息
19807
					$result["error"]=$lowLevelStr;
19808
 
19809
					#回傳結果
19810
					return $result;
19811
 
19812
					}#if end
19813
 
19814
				#如果分割出來小於1段
19815
				if($lowLevelStr["dataCounts"]<1){
19816
 
19817
					#設置執行失敗
19818
					$result["status"]="false";
19819
 
19820
					#設置執行錯誤訊息
19821
					$result["error"]=$lowLevelStr;
19822
 
19823
					#回傳結果
19824
					return $result;
19825
 
19826
					}#if end
19827
 
19828
				#有幾個 device flag 就執行幾次
19829
				for($i=0;$i<count($lowLevelStr["dataArray"]);$i++){
19830
 
19831
					#設置名為 $lowLevelStr["dataArray"] 的 device flags 為 "true"
19832
					$info["deviceFlags"][$lowLevelStr["dataArray"][$i]]="true";
19833
 
19834
					}#for end
19835
 
19836
				#string array: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
19837
 
19838
				#$spiltString 有幾個元素
19839
				for($i=1;$i<$spiltString["dataCounts"];$i=$i+2){
19840
 
19841
					#取得設備的屬性與值
19842
					$info["deviceAttr"][$spiltString["dataArray"][$i]]=$spiltString["dataArray"][$i+1];
19843
 
19844
					}#for end
19845
 
19846
				}#if end
19847
 
19848
			#反之是偶數列
19849
			else{
19850
 
19851
				#    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
19852
				#用 " " 分割
19853
				#函式說明:
19854
				#將固定格式的字串分開,並回傳分開的結果。
19855
				#回傳結果:
19856
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19857
				#$result["error"],錯誤訊息陣列
19858
				#$result["function"],當前執行的函式名稱.
19859
				#$result["oriStr"],要分割的原始字串內容
19860
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
19861
				#$result["dataCounts"],爲總共分成幾段
19862
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
19863
				#必填參數:
19864
				$conf["stringProcess::spiltString"]["stringIn"]=$lineContent;#要處理的字串。
19865
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
19866
				#可省略參數:
19867
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
19868
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
19869
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
19870
				unset($conf["stringProcess::spiltString"]);
19871
 
19872
				#如果分割字串失敗
19873
				if($spiltString["status"]==="false"){
19874
 
19875
					#設置執行失敗
19876
					$result["status"]="false";
19877
 
19878
					#設置執行錯誤訊息
19879
					$result["error"]=$spiltString;
19880
 
19881
					#回傳結果
19882
					return $result;
19883
 
19884
					}#if end
19885
 
19886
				#如果分割字串的關鍵字不存在
19887
				if($spiltString["found"]==="false"){
19888
 
19889
					#設置執行失敗
19890
					$result["status"]="false";
19891
 
19892
					#設置執行錯誤訊息
19893
					$result["error"]=$spiltString;
19894
 
19895
					#回傳結果
19896
					return $result;
19897
 
19898
					}#if end
19899
 
19900
				#如果分割出來小於1段
19901
				if($spiltString["dataCounts"]!==4){
19902
 
19903
					#設置執行失敗
19904
					$result["status"]="false";
19905
 
19906
					#設置執行錯誤訊息
19907
					$result["error"]=$spiltString;
19908
 
19909
					#回傳結果
19910
					return $result;
19911
 
19912
					}#if end
19913
 
19914
				#取得 mac
19915
				$info["mac"]=$spiltString["dataArray"][1];
19916
 
19917
				#取得廣播位置
19918
				$info["brd"]=$spiltString["dataArray"][3];
19919
 
19920
				#記錄網路設備資訊
19921
				$result["content"][$index]=$info;
19922
 
19923
				#重設 $info 為空陣列
19924
				$info=array();
19925
 
19926
				}#else end
19927
 
19928
			}#foreach end
19929
 
19930
		#設置取得的網路設備資訊
19931
		#$result["content"]=$callShell["output"];
19932
 
19933
		#設置執行正常
19934
		$result["status"]="true";
19935
 
19936
		#回傳結果
19937
		return $result;
19938
 
19939
		}#function ipLinkShow end
19940
 
19941
	/*
19942
	#函式說明:
19943
	#顯示網路連線的IP相關資訊.
19944
	#回傳結果:
19945
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19946
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
19947
	#$result["function"],當前執行的函式名稱.
19948
	#$result["cmd"],實際執行的指令.
19949
	#$result["content"],陣列,每個可能的ip地址.
19950
	#必填參數:
19951
	#$conf["fileArgu"],字串,變數__FILE__的內容.
19952
	$conf["fileArgu"]=__FILE__;
19953
	#$conf["linkName"],字串,要檢視的網路界面名稱,若省略則會顯示所有的網路設備的ip地址相關資訊
19954
	$conf["linkName"]="";
19955
	#可省略參數:
19956
	#無.
19957
	#參考資料:
19958
	#無.
19959
	#備註:
19960
	#無.
19961
	*/
19962
	public static function ipAddrShow(&$conf){
19963
 
19964
		#初始化要回傳的結果
19965
		$result=array();
19966
 
19967
		#取得當前執行的函式名稱
19968
		$result["function"]=__FUNCTION__;
19969
 
19970
		#取得參數
19971
		$result["argu"]=$conf;
19972
 
19973
		#如果 $conf 不為陣列
19974
		if(gettype($conf)!="array"){
19975
 
19976
			#設置執行失敗
19977
			$result["status"]="false";
19978
 
19979
			#設置執行錯誤訊息
19980
			$result["error"][]="\$conf變數須為陣列形態";
19981
 
19982
			#如果傳入的參數為 null
19983
			if($conf==null){
19984
 
19985
				#設置執行錯誤訊息
19986
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
19987
 
19988
				}#if end
19989
 
19990
			#回傳結果
19991
			return $result;
19992
 
19993
			}#if end
19994
 
19995
		#檢查參數
19996
		#函式說明:
19997
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
19998
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19999
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
20000
		#$result["function"],當前執行的函式名稱.
20001
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
20002
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
20003
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
20004
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
20005
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
20006
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
20007
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
20008
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
20009
		#必填寫的參數:
20010
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
20011
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
20012
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
20013
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
20014
		#可以省略的參數:
20015
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
20016
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkName");
20017
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
20018
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
20019
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
20020
		#$conf["canBeEmptyString"]="false";
20021
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
20022
		#$conf["canNotBeEmpty"]=array();
20023
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
20024
		#$conf["canBeEmpty"]=array();
20025
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
20026
		#$conf["skipableVariableCanNotBeEmpty"]=array();
20027
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
20028
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("linkName");
20029
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
20030
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
20031
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
20032
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");
20033
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
20034
		#$conf["disallowAllSkipableVarIsEmpty"]="";
20035
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
20036
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
20037
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
20038
		#$conf["arrayCountEqualCheck"][]=array();
20039
		#參考資料來源:
20040
		#array_keys=>http://php.net/manual/en/function.array-keys.php
20041
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
20042
		unset($conf["variableCheck::checkArguments"]);
20043
 
20044
		#如果檢查參數失敗
20045
		if($checkArguments["status"]==="false"){
20046
 
20047
			#設置執行失敗
20048
			$result["status"]="false";
20049
 
20050
			#設置執行錯誤訊息
20051
			$result["error"]=$checkArguments;
20052
 
20053
			#回傳結果
20054
			return $result;
20055
 
20056
			}#if end
20057
 
20058
		#如果檢查參數不通過
20059
		if($checkArguments["passed"]==="false"){
20060
 
20061
			#設置執行失敗
20062
			$result["status"]="false";
20063
 
20064
			#設置執行錯誤訊息
20065
			$result["error"]=$checkArguments;
20066
 
20067
			#回傳結果
20068
			return $result;
20069
 
20070
			}#if end
20071
 
20072
		/*
20073
		#輸出參考
20074
		3: ens2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
20075
		    link/ether 52:54:11:12:35:02 brd ff:ff:ff:ff:ff:ff
20076
		    altname enp3s2
20077
		    altname enx525411123502
20078
		    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute ens2
20079
		       valid_lft 74728sec preferred_lft 74728sec
20080
		    inet6 fec0::5054:11ff:fe12:3502/64 scope site dynamic noprefixroute 
20081
		       valid_lft 86029sec preferred_lft 14029sec
20082
		    inet6 fe80::5054:11ff:fe12:3502/64 scope link noprefixroute 
20083
		       valid_lft forever preferred_lft forever
20084
		*/
20085
 
20086
		#函式說明:
20087
		#呼叫shell執行系統命令,並取得回傳的內容.
20088
		#回傳結果:
20089
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20090
		#$result["error"],錯誤訊息陣列.
20091
		#$result["function"],當前執行的函數名稱.
20092
		#$result["argu"],使用的參數.
20093
		#$result["cmd"],執行的指令內容.
20094
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
20095
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
20096
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
20097
		#$result["running"],是否還在執行.
20098
		#$result["pid"],pid.
20099
		#$result["statusCode"],執行結束後的代碼.
20100
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
20101
		#必填參數:
20102
		#$conf["command"],字串,要執行的指令.
20103
		$conf["external::callShell"]["command"]="ip";
20104
		#$conf["fileArgu"],字串,變數__FILE__的內容.
20105
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
20106
		#可省略參數:
20107
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
20108
		$conf["external::callShell"]["argu"]=array("addr","show",$conf["linkName"]);
20109
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
20110
		#$conf["arguIsAddr"]=array();
20111
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
20112
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
20113
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
20114
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
20115
		#$conf["enablePrintDescription"]="true";
20116
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
20117
		#$conf["printDescription"]="";
20118
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
20119
		$conf["external::callShell"]["escapeshellarg"]="true";
20120
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
20121
		#$conf["thereIsShellVar"]=array();
20122
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
20123
		#$conf["username"]="";
20124
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
20125
		#$conf["password"]="";
20126
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
20127
		#$conf["useScript"]="";
20128
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
20129
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
20130
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
20131
		#$conf["inBackGround"]="";
20132
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
20133
		#$conf["getErr"]="false";
20134
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
20135
		#$conf["doNotRun"]="false";
20136
		#參考資料:
20137
		#exec=>http://php.net/manual/en/function.exec.php
20138
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
20139
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
20140
		#備註:
20141
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
20142
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
20143
		$callShell=external::callShell($conf["external::callShell"]);
20144
		unset($conf["external::callShell"]);
20145
 
20146
		#如果檢查參數失敗
20147
		if($callShell["status"]==="false"){
20148
 
20149
			#設置執行失敗
20150
			$result["status"]="false";
20151
 
20152
			#設置執行錯誤訊息
20153
			$result["error"]=$callShell;
20154
 
20155
			#回傳結果
20156
			return $result;
20157
 
20158
			}#if end
20159
 
20160
		#ip addr show [Network Interface name]
20161
		#$callShell["output"];
20162
 
20163
		#函式說明:
20164
		#尋找多個字串中是否含有符合多個格式之一的內容,且回傳解析好的變數數值.
20165
		#回傳結果:
20166
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20167
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
20168
		#$result["function"],當前執行的函式名稱.
20169
		#$result["argu"],所使用的參數.
20170
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
20171
		#$result["content"],陣列,key為lineNo者為inputs參數的索引;key為content者為符合的資訊,若為n個${*},則當found為"true"時,就會回傳n個元素.
20172
		#必填參數:
20173
		#$conf["inputs"],字串陣列,要檢查的字串集合.
20174
		$conf["search::getMatchFormatsStrings"]["inputs"]=$callShell["output"];
20175
		#$conf["format"],格式字串陣列,要尋找的可能格式字串集合.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.
20176
		$conf["search::getMatchFormatsStrings"]["formats"]=array("\${*}inet \${*}/\${*} \${*}","\${*}inet6 \${*}/\${*} \${*}");
20177
		#可省略參數:
20178
		#無.
20179
		#參考資料:
20180
		#無.
20181
		#備註:
20182
		#無.
20183
		$getMatchFormatsStrings=search::getMatchFormatsStrings($conf["search::getMatchFormatsStrings"]);
20184
		unset($conf["search::getMatchFormatsStrings"]);
20185
 
20186
		#如果執行出錯
20187
		if($getMatchFormatsStrings["status"]==="false"){
20188
 
20189
			#設置執行失敗
20190
			$result["status"]="false";
20191
 
20192
			#設置執行錯誤訊息
20193
			$result["error"]=$getMatchFormatsStrings;
20194
 
20195
			#回傳結果
20196
			return $result;
20197
 
20198
			}#if end
20199
 
20200
		#如果沒有ip的關鍵字
20201
		if($getMatchFormatsStrings["found"]==="false"){
20202
 
20203
			#設置執行失敗
20204
			$result["status"]="false";
20205
 
20206
			#設置執行錯誤訊息
20207
			$result["error"]=$getMatchFormatsStrings;
20208
 
20209
			#回傳結果
20210
			return $result;
20211
 
20212
			}#if end
20213
 
20214
		#初始化儲存ip地址的陣列
20215
		$result["content"]=array();
20216
 
20217
		#針對每個符合的行結果
20218
		foreach($getMatchFormatsStrings["content"] as $ipInfo){
20219
 
20220
			#var_dump(__LINE__,$ipInfo);
20221
 
20222
			#針對每個ip資訊
20223
			foreach($ipInfo["content"] as $ip){
20224
 
20225
				#儲存 ip 地址
20226
				$result["content"][]=$ip[1]."/".$ip[2];
20227
 
20228
				}#foreach end
20229
 
20230
			}#foreach end
20231
 
20232
		#設置執行正常
20233
		$result["status"]="true";
20234
 
20235
		#回傳結果
20236
		return $result;
20237
 
20238
		}#function ipAddrShow end
20239
 
20240
	/*
20241
	#函式說明:
20242
	#建立腳本檔案.
20243
	#回傳結果:
20244
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20245
	#$result["error"],錯誤訊息陣列.
20246
	#$result["function"],當前執行的函數名稱.
20247
	#$result["content"],腳本檔案的位置與名稱.
20248
	#必填參數:
20249
	#$conf["cmd"],要執行的指令字串陣列.
20250
	#$conf["cmd"]=array();
20251
	#可省略參數:
20252
	#$conf["params"],要執行對應指令所屬的參數字串陣列.
20253
	#$conf["params"]=array(array());
20254
	#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.
20255
	#$conf["excuteBy"]="";
20256
	#$conf["fileName"],字串,指定要輸出的檔案名稱.
20257
	#$conf["fileName"]="";
20258
	#參考資料:
20259
	#無.
20260
	#備註:
20261
	#無.
20262
	*/
20263
	public static function createBatch(&$conf){
20264
 
20265
		#初始化要回傳的結果
20266
		$result=array();
20267
 
20268
		#取得當前執行的函數名稱
20269
		$result["function"]=__FUNCTION__;
20270
 
20271
		#如果沒有參數
20272
		if(func_num_args()==0){
20273
 
20274
			#設置執行失敗
20275
			$result["status"]="false";
20276
 
20277
			#設置執行錯誤訊息
20278
			$result["error"]="函數".$result["function"]."需要參數";
20279
 
20280
			#回傳結果
20281
			return $result;
20282
 
20283
			}#if end
20284
 
20285
		#取得參數
20286
		$result["argu"]=$conf;
20287
 
20288
		#如果 $conf 不為陣列
20289
		if(gettype($conf)!=="array"){
20290
 
20291
			#設置執行失敗
20292
			$result["status"]="false";
20293
 
20294
			#設置執行錯誤訊息
20295
			$result["error"][]="\$conf變數須為陣列形態";
20296
 
20297
			#如果傳入的參數為 null
20298
			if(is_null($conf)){
20299
 
20300
				#設置執行錯誤訊息
20301
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
20302
 
20303
				}#if end
20304
 
20305
			#回傳結果
20306
			return $result;
20307
 
20308
			}#if end
20309
 
20310
		#函式說明:
20311
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
20312
		#回傳結果:
20313
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20314
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
20315
		#$result["simpleError"],簡單表示的錯誤訊息.
20316
		#$result["function"],當前執行的函式名稱.
20317
		#$result["argu"],設置給予的參數.
20318
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
20319
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
20320
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
20321
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
20322
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
20323
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
20324
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
20325
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
20326
		#必填參數:
20327
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
20328
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
20329
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
20330
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
20331
		#可省略參數:
20332
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
20333
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmd");
20334
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
20335
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
20336
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
20337
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
20338
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
20339
		#$conf["canNotBeEmpty"]=array();
20340
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
20341
		#$conf["canBeEmpty"]=array();
20342
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
20343
		#$conf["skipableVariableCanNotBeEmpty"]=array();
20344
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
20345
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("params","excuteBy","fileName");
20346
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
20347
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
20348
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
20349
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null);
20350
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
20351
		#$conf["disallowAllSkipableVarIsEmpty"]="";
20352
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
20353
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
20354
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
20355
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cmd","params");
20356
		#參考資料:
20357
		#array_keys=>http://php.net/manual/en/function.array-keys.php
20358
		#備註:
20359
		#無.
20360
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
20361
		unset($conf["variableCheck::checkArguments"]);
20362
 
20363
		#如果執行失敗
20364
		if($callShell["status"]==="false"){
20365
 
20366
			#設置執行失敗
20367
			$result["status"]="false";
20368
 
20369
			#設置執行錯誤訊息
20370
			$result["error"]=$checkArguments;
20371
 
20372
			#回傳結果
20373
			return $result;
20374
 
20375
			}#if end
20376
 
20377
		#如果未通過檢查
20378
		if($callShell["passed"]==="false"){
20379
 
20380
			#設置執行失敗
20381
			$result["status"]="false";
20382
 
20383
			#設置執行錯誤訊息
20384
			$result["error"]=$checkArguments;
20385
 
20386
			#回傳結果
20387
			return $result;
20388
 
20389
			}#if end
20390
 
20391
		#初始化要執行的執行字串陣列
20392
		$multiLineCmdStr="";
20393
 
20394
		#如果有設定 $conf["excuteBy"]
20395
		if(isset($conf["excuteBy"])){
20396
 
20397
			#檢查 $conf["excuteBy"] 是否存在
20398
			#函式說明:
20399
			#檢查指令是否存在
20400
			#回傳結果:
20401
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20402
			#$result["error"],錯誤訊息.
20403
			#$result["function"],當前執行的函式名稱.
20404
			#$result["argu"],使用的參數.
20405
			#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
20406
			#$result["cmdFullPath"],指令的絕對路徑.
20407
			#必填參數:
20408
			#$conf["cmd"],"字串",要查詢的指令.
20409
			$conf["cmd::checkCmdExist"]["cmd"]=$conf["excuteBy"];			
20410
			#可省略參數:
20411
			#無.
20412
			#參考資料:
20413
			#無.
20414
			#備註:
20415
			#無.
20416
			$checkCmdExist=cmd::checkCmdExist($conf["cmd::checkCmdExist"]);
20417
			unset($conf["cmd::checkCmdExist"]);
20418
 
20419
			#若執行失敗
20420
			if($checkCmdExist["status"]==="false"){
20421
 
20422
				#設置執行失敗
20423
				$result["status"]="false";
20424
 
20425
				#設置執行錯誤訊息
20426
				$result["error"]=$checkCmdExist;
20427
 
20428
				#回傳結果
20429
				return $result;
20430
 
20431
				}#if end
20432
 
20433
			#若指令不存在
20434
			if($checkCmdExist["founded"]==="false"){
20435
 
20436
				#設置執行失敗
20437
				$result["status"]="false";
20438
 
20439
				#設置執行錯誤訊息
20440
				$result["error"]=$checkCmdExist;
20441
 
20442
				#回傳結果
20443
				return $result;
20444
 
20445
				}#if end
20446
 
20447
			#設置要透過哪個程式執行
20448
			$multiLineCmdStr=$multiLineCmdStr."#!".$checkCmdExist["cmdFullPath"].PHP_EOL;
20449
 
20450
			}#if end
20451
 
20452
		#針對每行指令
20453
		foreach($conf["cmd"] as $index=>$cmd){
20454
 
20455
			#函式說明:
20456
			#呼叫shell執行系統命令,並取得回傳的內容.
20457
			#回傳結果:
20458
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20459
			#$result["error"],錯誤訊息陣列.
20460
			#$result["function"],當前執行的函數名稱.
20461
			#$result["argu"],使用的參數.
20462
			#$result["cmd"],執行的指令內容.
20463
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
20464
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
20465
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
20466
			#$result["running"],是否還在執行.
20467
			#$result["pid"],pid.
20468
			#$result["statusCode"],執行結束後的代碼.
20469
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
20470
			#必填參數:
20471
			#$conf["command"],字串,要執行的指令.
20472
			$conf["external::callShell"]["command"]=$cmd;
20473
			#$conf["fileArgu"],字串,變數__FILE__的內容.
20474
			$conf["external::callShell"]["fileArgu"]=__FILE__;
20475
			#可省略參數:
20476
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
20477
			$conf["external::callShell"]["argu"]=$conf["params"][$index];
20478
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
20479
			#$conf["arguIsAddr"]=array();
20480
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
20481
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
20482
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
20483
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
20484
			#$conf["enablePrintDescription"]="true";
20485
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
20486
			#$conf["printDescription"]="";
20487
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
20488
			$conf["external::callShell"]["escapeshellarg"]="true";
20489
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
20490
			#$conf["thereIsShellVar"]=array();
20491
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
20492
			#$conf["username"]="";
20493
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
20494
			#$conf["password"]="";
20495
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
20496
			#$conf["useScript"]="";
20497
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
20498
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
20499
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
20500
			#$conf["inBackGround"]="";
20501
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
20502
			#$conf["getErr"]="false";
20503
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
20504
			$conf["external::callShell"]["doNotRun"]="true";
20505
			#參考資料:
20506
			#exec=>http://php.net/manual/en/function.exec.php
20507
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
20508
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
20509
			#備註:
20510
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
20511
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
20512
			$callShell=external::callShell($conf["external::callShell"]);
20513
			unset($conf["external::callShell"]);
20514
 
20515
			#如果分割字串失敗
20516
			if($callShell["status"]==="false"){
20517
 
20518
				#設置執行失敗
20519
				$result["status"]="false";
20520
 
20521
				#設置執行錯誤訊息
20522
				$result["error"]=$callShell;
20523
 
20524
				#回傳結果
20525
				return $result;
20526
 
20527
				}#if end
20528
 
20529
			#儲存要執行的指令字串
20530
			$multiLineCmdStr=$multiLineCmdStr.$callShell["cmd"].PHP_EOL;
20531
 
20532
			}#foreach end
20533
 
20534
		#函式說明:
20535
		#將字串寫入到檔案
20536
		#回傳結果:
20537
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
20538
		#$result["error"],錯誤訊息陣列.
20539
		#$result["function"],當前執行的函數名稱.
20540
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
20541
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
20542
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
20543
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
20544
		#$result["argu"],使用的參數.
20545
		#必填參數:
20546
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
20547
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
20548
		#可省略參數:
20549
 
20550
		#如果有設置 fileName
20551
		if(isset($conf["fileName"])){
20552
 
20553
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
20554
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$conf["fileName"];
20555
 
20556
			}#if end
20557
 
20558
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
20559
		$conf["fileAccess::writeTextIntoFile"]["inputString"]=$multiLineCmdStr;
20560
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
20561
		#$conf["writeMethod"]="a";
20562
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
20563
		#$conf["checkRepeat"]="";
20564
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
20565
		#$conf["filenameExtensionStartPoint"]="";
20566
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
20567
		#$conf["repeatNameRule"]="";
20568
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
20569
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
20570
		#參考資料:
20571
		#無.
20572
		#備註:
20573
		#無.
20574
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
20575
		unset($conf["fileAccess::writeTextIntoFile"]);
20576
 
20577
		#如果執行失敗
20578
		if($writeTextIntoFile["status"]==="false"){
20579
 
20580
			#設置執行失敗
20581
			$result["status"]="false";
20582
 
20583
			#設置執行錯誤訊息
20584
			$result["error"]=$callShell;
20585
 
20586
			#回傳結果
20587
			return $result;
20588
 
20589
			}#if end
20590
 
20591
		#設置 腳本檔案 的位置與名稱
20592
		$result["content"]=$writeTextIntoFile["fileInfo"]["createdFilePathAndName"];
20593
 
20594
		#設置執行正常
20595
		$result["status"]="true";
20596
 
20597
		#回傳結果
20598
		return $result;
20599
 
20600
		}#function createBatch end
20601
 
20602
	/*
20603
	#函式說明:
20604
	#export svn 上的檔案目錄,進行打包放到遠端伺服器上並進行安裝或更新的動作.
20605
	#回傳結果:
20606
	#無.
20607
	#必填參數:
20608
	#無.
20609
	#可省略參數:
20610
	#無.
20611
	#參考資料:
20612
	#無.
20613
	#備註:
20614
	#用戶端上需要有安裝php,openssh-clients,subversion(svn),openssh-askpass,zstd套件.
20615
	#網站伺服器端需要有安裝openssh-server,zstd套件.
20616
	#待測試
20617
	#建議將svn預先輸入密碼的功能分離出來
20618
	*/
20619
	public static function packetFromSvnToRemoteServer(){
20620
 
20621
		#歡迎
20622
		echo "Welcome to ".basename($_SERVER["SCRIPT_FILENAME"])."~".PHP_EOL;
20623
 
20624
		#取得參數
20625
		$params=$_SERVER["argv"];
20626
 
20627
		#如果有第一個參數
20628
		if(isset($params[1])){
20629
 
20630
			//初始化檢查與設定用的conf變數
20631
			$conf=array();
20632
			$conf["newConfFile"]["name"]="要產生的設定檔名稱";
20633
			$conf["newConfFile"]["val"]="";
20634
			$conf["svnAccount"]["name"]="svn+ssh所用的帳戶名稱";
20635
			$conf["svnAccount"]["val"]="";
20636
			$conf["svnPass"]["name"]="svn+ssh所用的帳戶密碼";
20637
			$conf["svnPass"]["val"]="";
20638
			$conf["svnSshPrivateKey"]["name"]="svn+ssh所用賬戶對應的 ssh private key";
20639
			$conf["svnSshPrivateKey"]["val"]="";
20640
			$conf["svnUrl"]["name"]="svn+ssh的完整路徑,例如「svn+ssh://sshAccount@dns/usr/local/projects/projectsName/branch/1.XX.XX」";
20641
			$conf["svnUrl"]["val"]="";
20642
			$conf["svnPort"]["name"]="svn+ssh所使用網址對應的port,若要使用22以外的數值請指定.";
20643
			$conf["svnPort"]["val"]="";
20644
			$conf["src"]["name"]="export後存在本機上的名稱,預設爲 svn+ssh完整路徑的最後一層目錄名稱";
20645
			$conf["src"]["val"]="basename(\$svnUrl)";
20646
			$conf["date"]["name"]="打包時間的產生方式,預設爲 gmdate('YmdHis')";
20647
			$conf["date"]["val"]="gmdate('YmdHis')";
20648
			$conf["target"]["name"]="要打包的目錄,預設爲 export後存在本機上的名稱-打包時間";
20649
			$conf["target"]["val"]="\$src.\"-\".\$date";
20650
			$conf["exclude"]["name"]="要排除的目錄或檔案";
20651
			$conf["exclude"]["val"]=array("");
20652
			$conf["targetRoot"]["name"]="網頁要放置的位置";
20653
			$conf["targetRoot"]["val"]="/var/www/html";
20654
			$conf["sshServerDns"]["name"]="網站Server的dns或ip";
20655
			$conf["sshServerDns"]["val"]="";
20656
			$conf["sshServerPort"]["name"]="連線到網站Server的ssh port";
20657
			$conf["sshServerPort"]["val"]="";
20658
			$conf["sshServerAccount"]["name"]="連線到網站Server的ssh acccount";
20659
			$conf["sshServerAccount"]["val"]="";
20660
			$conf["sshServerPassword"]["name"]="連線到網站Server的ssh password";
20661
			$conf["sshServerPassword"]["val"]="";
20662
			$conf["sshServerPrivateKey"]["name"]="連線到網站Server的ssh private key";
20663
			$conf["sshServerPrivateKey"]["val"]="";
20664
			$conf["serverHtmlManageAccount"]["name"]="網站Server上可以搬移網頁檔案的帳戶";
20665
			$conf["serverHtmlManageAccount"]["val"]="";
20666
			$conf["serverHtmlManagePassword"]["name"]="網站Server上可以搬移網頁檔案的賬戶密碼";
20667
			$conf["serverHtmlManagePassword"]["val"]="";
20668
 
20669
			#取得參數1
20670
			$param=&$params[1];
20671
 
20672
			#判斷參數
20673
			switch($param){
20674
 
20675
				#如果參數爲 "--create-conf"
20676
				case "--create-conf":
20677
 
20678
					#提示建立設定檔
20679
					echo "建立新設定檔...".PHP_EOL;
20680
 
20681
					#依據每個設定檔
20682
					foreach($conf as $varInPhp=>$info){
20683
 
20684
						#提示輸入參數
20685
						echo "請輸入參數 ".$info["name"].":".PHP_EOL;
20686
 
20687
						#如果 $info["val"] 不為空字串
20688
						if($info["val"]!==""){
20689
 
20690
							#如果是 "exclude" 的設定
20691
							if($varInPhp==="exclude"){
20692
 
20693
								#提示檢視用法的參數
20694
								echo "輸入 -h 或 --help 顯示本說明".PHP_EOL;
20695
 
20696
								#提示顯示要移除的目錄
20697
								echo "輸入 ls 來顯示要剔除的路徑或檔案清單".PHP_EOL;
20698
 
20699
								#提示輸入路徑與檔案來新增要剔除的目標
20700
								echo "輸入路徑或檔案名稱來新增要剔除的目標".PHP_EOL;
20701
 
20702
								#提示移除剔除清單的方式
20703
								echo "輸入 \"del 排除項目的編號\" 將項目移除".PHP_EOL;
20704
 
20705
								#提示留空的預設數值
20706
								echo "留空則爲預設的:".PHP_EOL;
20707
 
20708
								#針對每個要剔除的對象
20709
								foreach($info["val"] as $rmNo=>$rmVal){
20710
 
20711
									#印出編號與數值內容
20712
									echo "[".$rmNo."]=>".$rmVal.PHP_EOL;
20713
 
20714
									}#foreach end
20715
 
20716
								}#if end
20717
 
20718
							#反之
20719
							else{
20720
 
20721
								#提示留空的預設數值
20722
								echo "留空則爲預設的「".$info["val"]."".PHP_EOL."」";
20723
 
20724
								}#else end
20725
 
20726
							}#if end
20727
 
20728
						#無窮迴圈
20729
						while(true){
20730
 
20731
							#取得列輸入
20732
							$input=trim(fgets(STDIN));
20733
 
20734
							#有預設數值則允許爲空字串
20735
							if($info["val"]!==""){
20736
 
20737
								#如果是 "exclude" 的設定
20738
								if($varInPhp==="exclude"){
20739
 
20740
									#判斷輸入的內容
20741
									switch($input){
20742
 
20743
										#如果是 ""
20744
										case "":
20745
 
20746
											#取得要移除的清單
20747
											$conf[$varInPhp]["val"]=$info["val"];
20748
 
20749
											#結束輸入
20750
											break 2;
20751
 
20752
										#如果是 "ls"
20753
										case "ls":
20754
 
20755
											#提示要移除的目錄或檔案
20756
											echo "要剔除的路徑或檔案清單如下:".PHP_EOL;
20757
 
20758
											#針對每個要剔除的對象
20759
											foreach($info["val"] as $rmNo=>$rmVal){
20760
 
20761
												#印出編號與數值內容
20762
												echo "[".$rmNo."]=>".$rmVal.PHP_EOL;
20763
 
20764
												}#foreach end
20765
 
20766
											#繼續輸入
20767
											continue 2;
20768
 
20769
										#如果是 "-h"
20770
										case "-h":
20771
 
20772
										#如果是 "--help"
20773
										case "--help":
20774
 
20775
										#其他內容
20776
										default:
20777
 
20778
											#解析輸入字串
20779
											sscanf($input,'%s %d',$p1,$p2);
20780
 
20781
											#如果第一個字是 "del"
20782
											if($p1==="del"){
20783
 
20784
												#檢查$p2是否為數字
20785
												if(is_integer($p2)){
20786
 
20787
													#如果要移除的目標存在
20788
													if(isset($info["val"][$p2])){
20789
 
20790
														#移除之
20791
														unset($info["val"][$p2]);
20792
 
20793
														#重新排序
20794
 
20795
														#初始化暫存的陣列
20796
														$tmp=array();
20797
 
20798
														#針對每個要剔除的對象
20799
														foreach($info["val"] as $rmNo=>$rmVal){
20800
 
20801
															#印出編號與數值內容
20802
															$tmp[]=$rmVal;
20803
 
20804
															}#foreach end
20805
 
20806
														#取得重新排序好的陣列
20807
														$info["val"]=$tmp;
20808
 
20809
														}#if end
20810
 
20811
													}#if end
20812
 
20813
												}#if end
20814
 
20815
											#反之
20816
											else{
20817
 
20818
												#取得新的排除項目
20819
												$info["val"][]=$p1;
20820
 
20821
												}#else end
20822
 
20823
											#提示檢視用法的參數
20824
											echo "輸入 -h 或 --help 顯示本說明".PHP_EOL;
20825
 
20826
											#提示顯示要移除的目錄
20827
											echo "輸入 ls 來顯示要剔除的路徑或檔案清單".PHP_EOL;
20828
 
20829
											#提示輸入路徑與檔案來新增要剔除的目標
20830
											echo "輸入路徑或檔案名稱來新增要剔除的目標".PHP_EOL;
20831
 
20832
											#提示移除剔除清單的方式
20833
											echo "輸入 \"del 排除項目的編號\" 將項目移除".PHP_EOL;
20834
 
20835
											#提示留空代表結束輸入
20836
											echo "留空代表結束輸入".PHP_EOL;
20837
 
20838
											#繼續輸入
20839
											continue 2;
20840
 
20841
										}#switch end
20842
 
20843
									}#if end
20844
 
20845
								#反之
20846
								else{
20847
 
20848
									#若輸入不為空
20849
									if($input!==""){
20850
 
20851
										#取得輸入的內容
20852
										$conf[$varInPhp]["val"]=$input;
20853
 
20854
										}#if end
20855
 
20856
									}#else end
20857
 
20858
								#跳出while
20859
								break;
20860
 
20861
								}#if end
20862
 
20863
							#無預設數值,輸入不爲空才允許.
20864
							else{
20865
 
20866
								#若輸入不為空字串
20867
								if($input!==""){
20868
 
20869
									#取得輸入內容
20870
									$conf[$varInPhp]["val"]=$input;
20871
 
20872
									#跳出while
20873
									break;
20874
 
20875
									}#if end
20876
 
20877
								}#else end
20878
 
20879
							#提示輸入參數
20880
							echo "請輸入參數 ".$info["name"].":".PHP_EOL;
20881
 
20882
							#如果輸入不為空字串
20883
							if($info["val"]!==""){
20884
 
20885
								#提示留空的預設內容
20886
								echo "留空則爲預設的「".$info["val"]."」".PHP_EOL;
20887
 
20888
								}#if end
20889
 
20890
							}#while end
20891
 
20892
						}#foreach end
20893
 
20894
					#寫設定檔
20895
 
20896
					#取得新設定檔的名稱
20897
					$ncn=$conf["newConfFile"]["val"];
20898
 
20899
					#卸除新設定檔的變數陣列
20900
					unset($conf["newConfFile"]);
20901
 
20902
					#初始化新設定檔的內容
20903
					$ncc="";
20904
 
20905
					#針對每個conf
20906
					foreach($conf as $varInPhp=>$info){
20907
 
20908
						#如果是陣列
20909
						if(is_array($info["val"])){
20910
 
20911
							#寫入初始化為陣列
20912
							$ncc=$ncc."\$".$varInPhp."=array();".PHP_EOL;
20913
 
20914
							#針對每個元素
20915
							foreach($info["val"] as $key=>$val){
20916
 
20917
								#寫入元素內容
20918
								$ncc=$ncc."\$".$varInPhp."[".$key."]=".$val.";".PHP_EOL;
20919
 
20920
								}#foreach end
20921
 
20922
							}#if end
20923
 
20924
						#反之
20925
						else{
20926
 
20927
							#如果數值內容有 "$" 或 "gmdate(" 或 'date(' 或 'time()' 或 'mktime(' 或 'gmmktime('
20928
							if(strpos($info["val"],'$')!==false || strpos($info["val"],'gmdate(')!==false || strpos($info["val"],'date(')!==false || strpos($info["val"],'time()')!==false || strpos($info["val"],'mktime(')!==false || strpos($info["val"],'gmmktime(')!==false || $varInPhp==="serverHtmlManagePassword"){
20929
 
20930
								#直接寫入
20931
								$ncc=$ncc."\$".$varInPhp."=".$info["val"].";".PHP_EOL;
20932
 
20933
								}#if end
20934
 
20935
							#反之
20936
							else{
20937
 
20938
								#加上""再寫入
20939
								$ncc=$ncc."\$".$varInPhp."=\"".$info["val"]."\";".PHP_EOL;
20940
 
20941
								}#else end
20942
 
20943
							}#else end
20944
 
20945
						}#foreach end
20946
 
20947
					#函式說明:
20948
					#將字串寫入到檔案
20949
					#回傳結果:
20950
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
20951
					#$result["error"],錯誤訊息陣列.
20952
					#$result["function"],當前執行的函數名稱.
20953
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
20954
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
20955
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
20956
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
20957
					#$result["argu"],使用的參數.
20958
					#必填參數:
20959
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
20960
					$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
20961
					#可省略參數:
20962
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
20963
					$conf["fileAccess::writeTextIntoFile"]["fileName"]=$ncn;
20964
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
20965
					$conf["fileAccess::writeTextIntoFile"]["inputString"]=$ncc;
20966
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
20967
					#$conf["writeMethod"]="a";
20968
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
20969
					#$conf["checkRepeat"]="";
20970
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
20971
					#$conf["filenameExtensionStartPoint"]="";
20972
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
20973
					#$conf["repeatNameRule"]="";
20974
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
20975
					$conf["fileAccess::writeTextIntoFile"]["web"]="false";
20976
					#參考資料:
20977
					#無.
20978
					#備註:
20979
					#無.
20980
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
20981
					unset($conf["fileAccess::writeTextIntoFile"]);
20982
 
20983
					#如果執行失敗
20984
					if($writeTextIntoFile["status"]==="false"){
20985
 
20986
						#設置執行失敗
20987
						$result["status"]="false";
20988
 
20989
						#設置執行錯誤訊息
20990
						$result["error"]=$writeTextIntoFile;
20991
 
20992
						#回傳結果
20993
						return $result;
20994
 
20995
						}#if end
20996
 
20997
					#提示建立設定檔案完成
20998
					echo "設定檔「".$ncn."」建立完成".PHP_EOL;
20999
 
21000
					#程式執行結束
21001
					exit;
21002
 
21003
				#其他則視爲要include進來的conf檔案
21004
				default:
21005
 
21006
					#如果設定檔案不存在
21007
					if(!file_exists($param)){
21008
 
21009
						#提示設定檔不存在或沒有權限讀取
21010
						echo "設定檔「".$param."」不存在,或沒有權限讀取".PHP_EOL;
21011
 
21012
						#提示建立新設定檔案的方式
21013
						echo "如果要建立新設定檔請用「--create-conf」參數".PHP_EOL;
21014
 
21015
						#結束程式
21016
						exit;
21017
 
21018
						}#if end
21019
 
21020
					#反之
21021
					else{
21022
 
21023
						#匯入設定檔案
21024
						include($param);
21025
 
21026
						#針對每個設定變數
21027
						foreach($conf as $varInPhp=>$info){
21028
 
21029
							#如果變數key為newConfFile
21030
							if($varInPhp==="newConfFile"){
21031
 
21032
								#則跳過
21033
								continue;
21034
 
21035
								}#if end
21036
 
21037
							#如果設定變數不存在
21038
							if(!isset($$varInPhp)){
21039
 
21040
								#提示設定變數未設置
21041
								echo "設定檔的 ".$info["name"]." 參數未設置!".PHP_EOL;
21042
 
21043
								#結束程式
21044
								exit;
21045
 
21046
								}#if end
21047
 
21048
							}#foreach end
21049
 
21050
						}#else end
21051
 
21052
				}#switch end
21053
 
21054
			}#if end
21055
 
21056
		#反之
21057
		else{
21058
 
21059
			#提示參數用法
21060
			echo "參數用法:".PHP_EOL;
21061
 
21062
			#提示建立新設定檔案的參數
21063
			echo "php ".$_SERVER["PHP_SELF"]." --create-conf 建立新設定檔".PHP_EOL;
21064
 
21065
			#提示使用設定檔進行包code與部署到遠端網頁伺服器的動作
21066
			echo "php ".$_SERVER["PHP_SELF"]." php_conf_file 依據 php_conf_file 進行包 code 到網站伺服器的動作".PHP_EOL;
21067
 
21068
			#結束程式
21069
			exit;
21070
 
21071
			}#else end
21072
 
21073
		#確保儲存要包的目錄不存在.
21074
		#函式說明:
21075
		#呼叫shell執行系統命令,並取得回傳的內容.
21076
		#回傳結果:
21077
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21078
		#$result["error"],錯誤訊息陣列.
21079
		#$result["function"],當前執行的函數名稱.
21080
		#$result["argu"],使用的參數.
21081
		#$result["cmd"],執行的指令內容.
21082
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21083
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21084
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21085
		#$result["running"],是否還在執行.
21086
		#$result["pid"],pid.
21087
		#$result["statusCode"],執行結束後的代碼.
21088
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21089
		#必填參數:
21090
		#$conf["command"],字串,要執行的指令.
21091
		$conf["external::callShell"]["command"]="rm";
21092
		#$conf["fileArgu"],字串,變數__FILE__的內容.
21093
		$conf["external::callShell"]["fileArgu"]=__FILE__;
21094
		#可省略參數:
21095
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21096
		$conf["external::callShell"]["argu"]=array("-rf",$src);
21097
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21098
		#$conf["arguIsAddr"]=array();
21099
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21100
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21101
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21102
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21103
		#$conf["enablePrintDescription"]="true";
21104
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21105
		#$conf["printDescription"]="";
21106
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21107
		$conf["external::callShell"]["escapeshellarg"]="true";
21108
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21109
		#$conf["thereIsShellVar"]=array();
21110
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21111
		#$conf["username"]="";
21112
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21113
		#$conf["password"]="";
21114
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21115
		#$conf["useScript"]="";
21116
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21117
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
21118
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
21119
		#$conf["inBackGround"]="";
21120
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
21121
		#$conf["getErr"]="false";
21122
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
21123
		#$conf["doNotRun"]="false";
21124
		#參考資料:
21125
		#exec=>http://php.net/manual/en/function.exec.php
21126
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
21127
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
21128
		#備註:
21129
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
21130
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
21131
		$callShell=external::callShell($conf["external::callShell"]);
21132
		unset($conf["external::callShell"]);
21133
 
21134
		#如果執行失敗
21135
		if($callShell["status"]==="false"){
21136
 
21137
			#設置執行失敗
21138
			$result["status"]="false";
21139
 
21140
			#設置執行錯誤訊息
21141
			$result["error"]=$callShell;
21142
 
21143
			#回傳結果
21144
			return $result;
21145
 
21146
			}#if end
21147
 
21148
		#初始化要是給 callShellHelper 的指令與參數陣列
21149
		$paramsToCallShellHelper=array();
21150
 
21151
		#如果 $svnPass 有數值
21152
		if($svnPass!==""){
21153
 
21154
			#設置要使用 ssh 密碼
21155
			$paramsToCallShellHelper[]="sshpass";
21156
 
21157
			#設置密碼參數
21158
			$paramsToCallShellHelper[]="-p";
21159
 
21160
			#設置密碼
21161
			$paramsToCallShellHelper[]=$svnPass;
21162
 
21163
			}#if end
21164
 
21165
		#設置要使用 svn
21166
		$paramsToCallShellHelper[]="svn";
21167
 
21168
		#設置要 export
21169
		$paramsToCallShellHelper[]="export";
21170
 
21171
		#設置 svn+ssh 的路徑
21172
		$paramsToCallShellHelper[]=$svnUrl;
21173
 
21174
		#初始化給svn+ssh使用的ssh參數
21175
		$sshOptionsForSvn=array();
21176
 
21177
		#如果有指定 svnSshPrivateKey
21178
		if($svnSshPrivateKey!==""){
21179
 
21180
			#如果 給svn+ssh使用的ssh參數 預設為空
21181
			if($sshOptionsForSvn===array()){
21182
 
21183
				#設置要指定 ssh 參數. 
21184
				$sshOptionsForSvn[]="--config-option=config:tunnels:ssh=ssh";
21185
 
21186
				}#if end
21187
 
21188
			#設置 private key 的參數.
21189
			$sshOptionsForSvn[]="-i";
21190
 
21191
			#設置 private key 的路徑與名稱.
21192
			$sshOptionsForSvn[]=$svnSshPrivateKey;
21193
 
21194
			}#if end
21195
 
21196
		#如果有指定 svnPort
21197
		if($svnPort!==""){
21198
 
21199
			#如果 給svn+ssh使用的ssh參數 預設為空
21200
			if($sshOptionsForSvn===array()){
21201
 
21202
				#設置要指定 ssh 參數. 
21203
				$sshOptionsForSvn[]="--config-option=config:tunnels:ssh=ssh";
21204
 
21205
				}#if end
21206
 
21207
			#設置 port 的參數.
21208
			$sshOptionsForSvn[]="-p";
21209
 
21210
			#設置 port.
21211
			$sshOptionsForSvn[]=$svnPort;
21212
 
21213
			}#if end
21214
 
21215
		#Merge $paramsToCallShellHelper 跟 $sshOptionsForSvn
21216
		#函式說明:
21217
		#將多個一維陣列串聯起來,key從0開始排序.
21218
		#回傳的結果:
21219
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
21220
		#$result["error"],錯誤訊息陣列.
21221
		#$result["function"],當前執行的函數.
21222
		#$result["content"],合併好的一維陣列.
21223
		#必填參數
21224
		#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
21225
		$conf["arrays::mergeArray"]["inputArray"]=array($paramsToCallShellHelper,$sshOptionsForSvn);
21226
		#可省略參數:
21227
		#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
21228
		#$conf["allowRepeat"]="true";
21229
		#參考資料:
21230
		#無.
21231
		#備註:
21232
		#無.
21233
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
21234
		unset($conf["arrays::mergeArray"]);
21235
 
21236
		#如果執行失敗
21237
		if($mergeArray["status"]==="false"){
21238
 
21239
			#設置執行失敗
21240
			$result["status"]="false";
21241
 
21242
			#設置執行錯誤訊息
21243
			$result["error"]=$mergeArray;
21244
 
21245
			#回傳結果
21246
			return $result;
21247
 
21248
			}#if end
21249
 
21250
		#函式說明:
21251
		#解析指令與參數,回傳指令與參數給 callShell 函式使用.
21252
		#回傳結果:
21253
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21254
		#$result["error"],錯誤訊息陣列.
21255
		#$result["function"],當前執行的函數名稱.
21256
		#$result["argu"],使用的參數.
21257
		#$result["cmd"],執行的指令名稱.
21258
		#$result["params"],執行指令伴隨的參數.
21259
		#必填參數:
21260
		#$conf["cmdArray"],字串陣列,要執行的指令字串.
21261
		$conf["external::callShellHelper"]["cmdArray"]=$mergeArray["content"];
21262
		#可省略參數:
21263
		#無.
21264
		#參考資料:
21265
		#array_shift=>https://www.php.net/manual/en/function.array-shift.php
21266
		#備註:
21267
		#無.
21268
		$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
21269
		unset($conf["external::callShellHelper"]);
21270
 
21271
		#如果執行失敗
21272
		if($callShellHelper["status"]==="false"){
21273
 
21274
			#設置執行失敗
21275
			$result["status"]="false";
21276
 
21277
			#設置執行錯誤訊息
21278
			$result["error"]=$callShellHelper;
21279
 
21280
			#回傳結果
21281
			return $result;
21282
 
21283
			}#if end
21284
 
21285
		#輸出位於 $svnUrl 上的svn code,使用的密碼為 $svnPass
21286
		#函式說明:
21287
		#呼叫shell執行系統命令,並取得回傳的內容.
21288
		#回傳結果:
21289
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21290
		#$result["error"],錯誤訊息陣列.
21291
		#$result["function"],當前執行的函數名稱.
21292
		#$result["argu"],使用的參數.
21293
		#$result["cmd"],執行的指令內容.
21294
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21295
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21296
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21297
		#$result["running"],是否還在執行.
21298
		#$result["pid"],pid.
21299
		#$result["statusCode"],執行結束後的代碼.
21300
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21301
		#必填參數:
21302
		#$conf["command"],字串,要執行的指令.
21303
		$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
21304
		#$conf["fileArgu"],字串,變數__FILE__的內容.
21305
		$conf["external::callShell"]["fileArgu"]=__FILE__;
21306
		#可省略參數:
21307
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21308
		$conf["external::callShell"]["argu"]=$callShellHelper["params"];
21309
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21310
		#$conf["arguIsAddr"]=array();
21311
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21312
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21313
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21314
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21315
		#$conf["enablePrintDescription"]="true";
21316
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21317
		#$conf["printDescription"]="";
21318
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21319
		$conf["external::callShell"]["escapeshellarg"]="true";
21320
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21321
		#$conf["thereIsShellVar"]=array();
21322
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21323
		#$conf["username"]="";
21324
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21325
		#$conf["password"]="";
21326
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21327
		#$conf["useScript"]="";
21328
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21329
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
21330
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
21331
		#$conf["inBackGround"]="";
21332
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
21333
		#$conf["getErr"]="false";
21334
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
21335
		#$conf["doNotRun"]="false";
21336
		#參考資料:
21337
		#exec=>http://php.net/manual/en/function.exec.php
21338
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
21339
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
21340
		#備註:
21341
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
21342
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
21343
		$callShell=external::callShell($conf["external::callShell"]);
21344
		unset($conf["external::callShell"]);
21345
 
21346
		#如果執行失敗
21347
		if($callShell["status"]==="false"){
21348
 
21349
			#設置執行失敗
21350
			$result["status"]="false";
21351
 
21352
			#設置執行錯誤訊息
21353
			$result["error"]=$callShell;
21354
 
21355
			#回傳結果
21356
			return $result;
21357
 
21358
			}#if end
21359
 
21360
		#複製要包的版本
21361
		#函式說明:
21362
		#呼叫shell執行系統命令,並取得回傳的內容.
21363
		#回傳結果:
21364
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21365
		#$result["error"],錯誤訊息陣列.
21366
		#$result["function"],當前執行的函數名稱.
21367
		#$result["argu"],使用的參數.
21368
		#$result["cmd"],執行的指令內容.
21369
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21370
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21371
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21372
		#$result["running"],是否還在執行.
21373
		#$result["pid"],pid.
21374
		#$result["statusCode"],執行結束後的代碼.
21375
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21376
		#必填參數:
21377
		#$conf["command"],字串,要執行的指令.
21378
		$conf["external::callShell"]["command"]="cp";
21379
		#$conf["fileArgu"],字串,變數__FILE__的內容.
21380
		$conf["external::callShell"]["fileArgu"]=__FILE__;
21381
		#可省略參數:
21382
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21383
		$conf["external::callShell"]["argu"]=array("-R","-v",$src,$target);
21384
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21385
		#$conf["arguIsAddr"]=array();
21386
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21387
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21388
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21389
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21390
		#$conf["enablePrintDescription"]="true";
21391
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21392
		#$conf["printDescription"]="";
21393
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21394
		$conf["external::callShell"]["escapeshellarg"]="true";
21395
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21396
		#$conf["thereIsShellVar"]=array();
21397
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21398
		#$conf["username"]="";
21399
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21400
		#$conf["password"]="";
21401
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21402
		#$conf["useScript"]="";
21403
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21404
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
21405
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
21406
		#$conf["inBackGround"]="";
21407
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
21408
		#$conf["getErr"]="false";
21409
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
21410
		#$conf["doNotRun"]="false";
21411
		#參考資料:
21412
		#exec=>http://php.net/manual/en/function.exec.php
21413
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
21414
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
21415
		#備註:
21416
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
21417
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
21418
		$callShell=external::callShell($conf["external::callShell"]);
21419
		unset($conf["external::callShell"]);
21420
 
21421
		#如果執行失敗
21422
		if($callShell["status"]==="false"){
21423
 
21424
			#設置執行失敗
21425
			$result["status"]="false";
21426
 
21427
			#設置執行錯誤訊息
21428
			$result["error"]=$callShell;
21429
 
21430
			#回傳結果
21431
			return $result;
21432
 
21433
			}#if end
21434
 
21435
		#設置複製到網頁Server前要移除的檔案(不覆蓋到Server上既有的檔案)
21436
 
21437
		#移除不需要包出去的目錄
21438
 
21439
		#初始化暫存剔除的指令
21440
		$rm=array();
21441
 
21442
		#針對每個要剔除的目標
21443
		foreach($exclude as $delPorF){
21444
 
21445
			#函式說明:
21446
			#呼叫shell執行系統命令,並取得回傳的內容.
21447
			#回傳結果:
21448
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21449
			#$result["error"],錯誤訊息陣列.
21450
			#$result["function"],當前執行的函數名稱.
21451
			#$result["argu"],使用的參數.
21452
			#$result["cmd"],執行的指令內容.
21453
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21454
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21455
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21456
			#$result["running"],是否還在執行.
21457
			#$result["pid"],pid.
21458
			#$result["statusCode"],執行結束後的代碼.
21459
			#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21460
			#必填參數:
21461
			#$conf["command"],字串,要執行的指令.
21462
			$conf["external::callShell"]["command"]="rm";
21463
			#$conf["fileArgu"],字串,變數__FILE__的內容.
21464
			$conf["external::callShell"]["fileArgu"]=__FILE__;
21465
			#可省略參數:
21466
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21467
			$conf["external::callShell"]["argu"]=array("-rf","-v",$target,$target."/".$delPorF);
21468
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21469
			#$conf["arguIsAddr"]=array();
21470
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21471
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21472
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21473
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21474
			#$conf["enablePrintDescription"]="true";
21475
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21476
			#$conf["printDescription"]="";
21477
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21478
			$conf["external::callShell"]["escapeshellarg"]="true";
21479
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21480
			#$conf["thereIsShellVar"]=array();
21481
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21482
			#$conf["username"]="";
21483
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21484
			#$conf["password"]="";
21485
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21486
			#$conf["useScript"]="";
21487
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21488
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
21489
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
21490
			#$conf["inBackGround"]="";
21491
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
21492
			#$conf["getErr"]="false";
21493
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
21494
			#$conf["doNotRun"]="false";
21495
			#參考資料:
21496
			#exec=>http://php.net/manual/en/function.exec.php
21497
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
21498
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
21499
			#備註:
21500
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
21501
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
21502
			$callShell=external::callShell($conf["external::callShell"]);
21503
			unset($conf["external::callShell"]);
21504
 
21505
			#如果執行失敗
21506
			if($callShell["status"]==="false"){
21507
 
21508
				#設置執行失敗
21509
				$result["status"]="false";
21510
 
21511
				#設置執行錯誤訊息
21512
				$result["error"]=$callShell;
21513
 
21514
				#回傳結果
21515
				return $result;
21516
 
21517
				}#if end
21518
 
21519
			}#foreach end
21520
 
21521
		#打包目標 $target 成 $target.'tar.xz'
21522
		#函式說明:
21523
		#將資料夾打包成.tar.zst檔案
21524
		#回傳的結果:
21525
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21526
		#$result["error"],錯誤訊息.
21527
		#$result["function"],當前執行的函式名稱.
21528
		#$result["storePlace"],檔案輸出後的位置與名稱.
21529
		#必填參數:
21530
		#$conf["target"],字串,要打包的檔案.
21531
		$conf["cmd::makeTarZstFile"]["target"]=$target;
21532
		#可省略參數:
21533
		#$conf["commentsArrayForTar"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述,預設為array("正產生 tar 檔案");
21534
		#$conf["commentsArrayForTar"]=array("正產生 tar 檔案");
21535
		#$conf["commentsArrayForZst"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述,預設為array("正產生 zst 檔案");
21536
		#$conf["commentsArrayForZst"]=array("正產生 zst 檔案");
21537
		#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
21538
		#$conf["newLineBreak"]="false";
21539
		#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.
21540
		#$conf["path"]="./";
21541
		#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.
21542
		#$conf["delAfterSuc"]="false";
21543
		#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.
21544
		#$conf["overwrite"]="true";
21545
		#參考資料:
21546
		#無.
21547
		#備註:
21548
		#無.
21549
		$makeTarZstFile=cmd::makeTarZstFile($conf["cmd::makeTarZstFile"]);
21550
		unset($conf["cmd::makeTarZstFile"]);
21551
 
21552
		#如果執行失敗
21553
		if($makeTarZstFile["status"]==="false"){
21554
 
21555
			#設置執行失敗
21556
			$result["status"]="false";
21557
 
21558
			#設置執行錯誤訊息
21559
			$result["error"]=$callShell;
21560
 
21561
			#回傳結果
21562
			return $result;
21563
 
21564
			}#if end
21565
 
21566
		#建立將打包好的壓縮檔放到 Server 的腳本
21567
		#建立temp目錄
21568
		#進入 temp 目錄
21569
		#把包好的程式放到伺服器端
21570
 
21571
		#函式說明:
21572
		#建立腳本檔案.
21573
		#回傳結果:
21574
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21575
		#$result["error"],錯誤訊息陣列.
21576
		#$result["function"],當前執行的函數名稱.
21577
		#$result["content"],腳本檔案的位置與名稱.
21578
		#必填參數:
21579
		#$conf["cmd"],要執行的指令字串陣列.
21580
		$conf["cmd::createBatch"]["cmd"]=array("mkdir","cd","put");
21581
		#可省略參數:
21582
		#$conf["params"],要執行對應指令所屬的參數字串陣列.
21583
		$conf["cmd::createBatch"]["params"]=array(array("temp"),array("temp"),array($makeTarZstFile["content"]));
21584
		#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.
21585
		$conf["cmd::createBatch"]["excuteBy"]="bash";
21586
		#$conf["fileName"],字串,指定要輸出的檔案名稱.
21587
		#$conf["fileName"]="";
21588
		#參考資料:
21589
		#無.
21590
		#備註:
21591
		#無.
21592
		$createBatch=cmd::createBatch($conf["cmd::createBatch"]);
21593
		unset($conf["cmd::createBatch"]);
21594
 
21595
		#如果執行失敗
21596
		if($createBatch["status"]==="false"){
21597
 
21598
			#設置執行失敗
21599
			$result["status"]="false";
21600
 
21601
			#設置執行錯誤訊息
21602
			$result["error"]=$callShell;
21603
 
21604
			#回傳結果
21605
			return $result;
21606
 
21607
			}#if end
21608
 
21609
		#取得腳本
21610
		$batchFile=$createBatch["content"];
21611
 
21612
		#初始化給 sftp 使用的指令跟參數
21613
		$paramsForSshServer=array();
21614
 
21615
		#如果有指定 $sshServerPassword
21616
		if($sshServerPassword!==""){
21617
 
21618
			#使用 sshpass 指令
21619
			$paramsForSshServer[]="sshpass";
21620
 
21621
			#設置要指定密碼
21622
			$paramsForSshServer[]="-p";
21623
 
21624
			#設置要使用的密碼
21625
			$paramsForSshServer[]=$sshServerPassword;
21626
 
21627
			}#if end
21628
 
21629
		#設置使用 sftp 指令
21630
		$paramsForSshServer[]="sftp";
21631
 
21632
		#如果 $sshServerPort 不為空
21633
		if($sshServerPort!==""){
21634
 
21635
			#設置要指定 port 
21636
			$paramsForSshServer[]="-P";
21637
 
21638
			#設置 port
21639
			$paramsForSshServer[]=$sshServerPort;
21640
 
21641
			}#if end
21642
 
21643
		#如果 sshServerPrivateKey 不為空
21644
		if($sshServerPrivateKey!==""){
21645
 
21646
			#設置要指定 ssh private key
21647
			$paramsForSshServer[]="-i";
21648
 
21649
			#設置 ssh private key
21650
			$paramsForSshServer[]=$sshServerPrivateKey;
21651
 
21652
			}#if end
21653
 
21654
		#設置 sftp 的url以及要使用的賬號
21655
		$paramsForSshServer[]=$sshServerAccount."@".$sshServerDns;
21656
 
21657
		#設置要倒入腳本
21658
		$paramsForSshServer[]="<";
21659
 
21660
		#設置要倒入的腳本
21661
		$paramsForSshServer[]=$batchFile;
21662
 
21663
		#函式說明:
21664
		#解析指令與參數,回傳指令與參數給 callShell 函式使用.
21665
		#回傳結果:
21666
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21667
		#$result["error"],錯誤訊息陣列.
21668
		#$result["function"],當前執行的函數名稱.
21669
		#$result["argu"],使用的參數.
21670
		#$result["cmd"],執行的指令名稱.
21671
		#$result["params"],執行指令伴隨的參數.
21672
		#必填參數:
21673
		#$conf["cmdArray"],字串陣列,要執行的指令字串.
21674
		$conf["external::callShellHelper"]["cmdArray"]=$paramsForSshServer;
21675
		#可省略參數:
21676
		#無.
21677
		#參考資料:
21678
		#array_shift=>https://www.php.net/manual/en/function.array-shift.php
21679
		#備註:
21680
		#無.
21681
		$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
21682
		unset($conf["external::callShellHelper"]);
21683
 
21684
		#如果執行失敗
21685
		if($callShellHelper["status"]==="false"){
21686
 
21687
			#設置執行失敗
21688
			$result["status"]="false";
21689
 
21690
			#設置執行錯誤訊息
21691
			$result["error"]=$callShellHelper;
21692
 
21693
			#回傳結果
21694
			return $result;
21695
 
21696
			}#if end
21697
 
21698
		#輸出位於 $svnUrl 上的svn code,使用的密碼為 $svnPass
21699
		#函式說明:
21700
		#呼叫shell執行系統命令,並取得回傳的內容.
21701
		#回傳結果:
21702
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21703
		#$result["error"],錯誤訊息陣列.
21704
		#$result["function"],當前執行的函數名稱.
21705
		#$result["argu"],使用的參數.
21706
		#$result["cmd"],執行的指令內容.
21707
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21708
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21709
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21710
		#$result["running"],是否還在執行.
21711
		#$result["pid"],pid.
21712
		#$result["statusCode"],執行結束後的代碼.
21713
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21714
		#必填參數:
21715
		#$conf["command"],字串,要執行的指令.
21716
		$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
21717
		#$conf["fileArgu"],字串,變數__FILE__的內容.
21718
		$conf["external::callShell"]["fileArgu"]=__FILE__;
21719
		#可省略參數:
21720
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21721
		$conf["external::callShell"]["argu"]=$callShellHelper["params"];
21722
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21723
		#$conf["arguIsAddr"]=array();
21724
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21725
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21726
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21727
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21728
		#$conf["enablePrintDescription"]="true";
21729
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21730
		#$conf["printDescription"]="";
21731
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21732
		$conf["external::callShell"]["escapeshellarg"]="true";
21733
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21734
		#$conf["thereIsShellVar"]=array();
21735
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21736
		#$conf["username"]="";
21737
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21738
		#$conf["password"]="";
21739
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21740
		#$conf["useScript"]="";
21741
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21742
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
21743
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
21744
		#$conf["inBackGround"]="";
21745
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
21746
		#$conf["getErr"]="false";
21747
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
21748
		#$conf["doNotRun"]="false";
21749
		#參考資料:
21750
		#exec=>http://php.net/manual/en/function.exec.php
21751
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
21752
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
21753
		#備註:
21754
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
21755
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
21756
		$callShell=external::callShell($conf["external::callShell"]);
21757
		unset($conf["external::callShell"]);
21758
 
21759
		#如果執行失敗
21760
		if($callShell["status"]==="false"){
21761
 
21762
			#設置執行失敗
21763
			$result["status"]="false";
21764
 
21765
			#設置執行錯誤訊息
21766
			$result["error"]=$callShell;
21767
 
21768
			#回傳結果
21769
			return $result;
21770
 
21771
			}#if end
21772
 
21773
		/*
21774
		建立連線到Server要做的cmd
21775
		1.將打包好的檔案解壓縮
21776
		2.複製解好的檔案目錄到目標位置
21777
		3.移除安裝過程產生的檔案
21778
		*/
21779
		/*
21780
		#進入temp目錄
21781
		#解壓縮程式壓縮檔
21782
		#解壓縮 tar 檔
21783
		#用網頁管理者賬戶 $serverHtmlManageAccount 的身份與密碼 $serverHtmlManagePassword 執行將網頁檔案目錄 $target 底下的內容放到對的位置 $targetRoot, 變更目標位置 $targetRoot 的擁有着為 apache.apache ,且權限為755.
21784
		#移除暫存的網頁路徑
21785
		#移除網頁tar檔
21786
		#移除網頁xz檔
21787
		*/
21788
		#函式說明:
21789
		#建立腳本檔案.
21790
		#回傳結果:
21791
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21792
		#$result["error"],錯誤訊息陣列.
21793
		#$result["function"],當前執行的函數名稱.
21794
		#$result["content"],腳本檔案的位置與名稱.
21795
		#必填參數:
21796
		#$conf["cmd"],要執行的指令字串陣列.
21797
		$conf["cmd::createBatch"]["cmd"]=array("cd","zstd","tar","echo","rm","rm","rm");
21798
		#可省略參數:
21799
		#$conf["params"],要執行對應指令所屬的參數字串陣列.
21800
		$conf["cmd::createBatch"]["params"]=array(array("temp"),array("-d",$target."tar.zst"),array("-xvf",$target."tar"),array($serverHtmlManagePassword,"|","su",$serverHtmlManageAccount,"-c"," ' cp -R --force ".$target."/. ".$targetRoot.";chown -R apache:apache ".$targetRoot.";chmod 755 -R ".$targetRoot.";'"),array("-rf",$target),array($target."tar"),array($target."tar.xz"));
21801
		#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.
21802
		$conf["cmd::createBatch"]["excuteBy"]="bash";
21803
		#$conf["fileName"],字串,指定要輸出的檔案名稱.
21804
		#$conf["fileName"]="";
21805
		#參考資料:
21806
		#無.
21807
		#備註:
21808
		#無.
21809
		$createBatch=cmd::createBatch($conf["cmd::createBatch"]);
21810
		unset($conf["cmd::createBatch"]);
21811
 
21812
		#如果執行失敗
21813
		if($createBatch["status"]==="false"){
21814
 
21815
			#設置執行失敗
21816
			$result["status"]="false";
21817
 
21818
			#設置執行錯誤訊息
21819
			$result["error"]=$createBatch;
21820
 
21821
			#回傳結果
21822
			return $result;
21823
 
21824
			}#if end
21825
 
21826
		#取得腳本檔案名稱
21827
		$batchFile=$createBatch["content"];
21828
 
21829
		#初始化給 ssh 使用的指令跟參數
21830
		$paramsForSshServer=array();
21831
 
21832
		#如果有指定 $sshServerPassword
21833
		if($sshServerPassword!==""){
21834
 
21835
			#使用 sshpass 指令
21836
			$paramsForSshServer[]="sshpass";
21837
 
21838
			#設置要指定密碼
21839
			$paramsForSshServer[]="-p";
21840
 
21841
			#設置要使用的密碼
21842
			$paramsForSshServer[]=$sshServerPassword;
21843
 
21844
			}#if end
21845
 
21846
		#設置使用 sftp 指令
21847
		$paramsForSshServer[]="ssh";
21848
 
21849
		#如果 $sshServerPort 不為空
21850
		if($sshServerPort!==""){
21851
 
21852
			#設置要指定 port 
21853
			$paramsForSshServer[]="-p";
21854
 
21855
			#設置 port
21856
			$paramsForSshServer[]=$sshServerPort;
21857
 
21858
			}#if end
21859
 
21860
		#如果 sshServerPrivateKey 不為空
21861
		if($sshServerPrivateKey!==""){
21862
 
21863
			#設置要指定 ssh private key
21864
			$paramsForSshServer[]="-i";
21865
 
21866
			#設置 ssh private key
21867
			$paramsForSshServer[]=$sshServerPrivateKey;
21868
 
21869
			}#if end
21870
 
21871
		#設置 sftp 的url以及要使用的賬號
21872
		$paramsForSshServer[]=$sshServerAccount."@".$sshServerDns;
21873
 
21874
		#設置要倒入腳本
21875
		$paramsForSshServer[]="<";
21876
 
21877
		#設置要倒入的腳本
21878
		$paramsForSshServer[]=$batchFile;
21879
 
21880
		#函式說明:
21881
		#解析指令與參數,回傳指令與參數給 callShell 函式使用.
21882
		#回傳結果:
21883
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21884
		#$result["error"],錯誤訊息陣列.
21885
		#$result["function"],當前執行的函數名稱.
21886
		#$result["argu"],使用的參數.
21887
		#$result["cmd"],執行的指令名稱.
21888
		#$result["params"],執行指令伴隨的參數.
21889
		#必填參數:
21890
		#$conf["cmdArray"],字串陣列,要執行的指令字串.
21891
		$conf["external::callShellHelper"]["cmdArray"]=$paramsForSshServer;
21892
		#可省略參數:
21893
		#無.
21894
		#參考資料:
21895
		#array_shift=>https://www.php.net/manual/en/function.array-shift.php
21896
		#備註:
21897
		#無.
21898
		$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
21899
		unset($conf["external::callShellHelper"]);
21900
 
21901
		#如果執行失敗
21902
		if($callShellHelper["status"]==="false"){
21903
 
21904
			#設置執行失敗
21905
			$result["status"]="false";
21906
 
21907
			#設置執行錯誤訊息
21908
			$result["error"]=$callShellHelper;
21909
 
21910
			#回傳結果
21911
			return $result;
21912
 
21913
			}#if end
21914
 
21915
		#連線到遠端將檔案解壓縮放到指定的目錄
21916
		#函式說明:
21917
		#呼叫shell執行系統命令,並取得回傳的內容.
21918
		#回傳結果:
21919
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21920
		#$result["error"],錯誤訊息陣列.
21921
		#$result["function"],當前執行的函數名稱.
21922
		#$result["argu"],使用的參數.
21923
		#$result["cmd"],執行的指令內容.
21924
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21925
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21926
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21927
		#$result["running"],是否還在執行.
21928
		#$result["pid"],pid.
21929
		#$result["statusCode"],執行結束後的代碼.
21930
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21931
		#必填參數:
21932
		#$conf["command"],字串,要執行的指令.
21933
		$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
21934
		#$conf["fileArgu"],字串,變數__FILE__的內容.
21935
		$conf["external::callShell"]["fileArgu"]=__FILE__;
21936
		#可省略參數:
21937
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21938
		$conf["external::callShell"]["argu"]=$callShellHelper["params"];
21939
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21940
		#$conf["arguIsAddr"]=array();
21941
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21942
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21943
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21944
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21945
		#$conf["enablePrintDescription"]="true";
21946
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21947
		#$conf["printDescription"]="";
21948
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21949
		$conf["external::callShell"]["escapeshellarg"]="true";
21950
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21951
		#$conf["thereIsShellVar"]=array();
21952
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21953
		#$conf["username"]="";
21954
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21955
		#$conf["password"]="";
21956
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21957
		#$conf["useScript"]="";
21958
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21959
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
21960
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
21961
		#$conf["inBackGround"]="";
21962
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
21963
		#$conf["getErr"]="false";
21964
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
21965
		#$conf["doNotRun"]="false";
21966
		#參考資料:
21967
		#exec=>http://php.net/manual/en/function.exec.php
21968
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
21969
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
21970
		#備註:
21971
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
21972
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
21973
		$callShell=external::callShell($conf["external::callShell"]);
21974
		unset($conf["external::callShell"]);
21975
 
21976
		#如果執行失敗
21977
		if($callShell["status"]==="false"){
21978
 
21979
			#設置執行失敗
21980
			$result["status"]="false";
21981
 
21982
			#設置執行錯誤訊息
21983
			$result["error"]=$callShell;
21984
 
21985
			#回傳結果
21986
			return $result;
21987
 
21988
			}#if end
21989
 
21990
		#建立移除本機上檔案的腳本
21991
		/*
21992
		#移除包code的目錄
21993
		#移除含有時間標識包code的暫存目錄
21994
		#移除包code的壓縮檔
21995
		#移除用不到的batch檔案
21996
		*/
21997
		#函式說明:
21998
		#建立腳本檔案.
21999
		#回傳結果:
22000
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22001
		#$result["error"],錯誤訊息陣列.
22002
		#$result["function"],當前執行的函數名稱.
22003
		#$result["content"],腳本檔案的位置與名稱.
22004
		#必填參數:
22005
		#$conf["cmd"],要執行的指令字串陣列.
22006
		$conf["cmd::createBatch"]["cmd"]=array("rm","rm","rm","rm");
22007
		#可省略參數:
22008
		#$conf["params"],要執行對應指令所屬的參數字串陣列.
22009
		$conf["cmd::createBatch"]["params"]=array(array("-rf",$src),array("-rf",$target),array("-rf",$target."tar.xz"),array($batchFile));
22010
		#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.
22011
		$conf["cmd::createBatch"]["excuteBy"]="bash";
22012
		#$conf["fileName"],字串,指定要輸出的檔案名稱.
22013
		#$conf["fileName"]="";
22014
		#參考資料:
22015
		#無.
22016
		#備註:
22017
		#無.
22018
		$createBatch=cmd::createBatch($conf["cmd::createBatch"]);
22019
		unset($conf["cmd::createBatch"]);
22020
 
22021
		#如果執行失敗
22022
		if($createBatch["status"]==="false"){
22023
 
22024
			#設置執行失敗
22025
			$result["status"]="false";
22026
 
22027
			#設置執行錯誤訊息
22028
			$result["error"]=$createBatch;
22029
 
22030
			#回傳結果
22031
			return $result;
22032
 
22033
			}#if end
22034
 
22035
		#運行腳本檔案
22036
		#函式說明:
22037
		#呼叫shell執行編譯過的2元碼程式或具備執行權限的檔案後回傳的結果
22038
		#回傳結果:
22039
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22040
		#$result["function"],正在執行的函式
22041
		#$result["error"],錯誤訊息陣列.
22042
		#$result["error"]["returnCode"],錯誤代碼.
22043
		#$result["output"],爲執行完二元碼後的輸出陣列.
22044
		#$result["escapedCmd"],實際執行的指令.
22045
		#必填參數:
22046
		$conf["exeFileAddress"]=$createBatch["content"];#可執行檔的位置與名稱
22047
		#可省略參數:
22048
		#$conf["arguments"]="";#要給執行檔的參數
22049
		#參考資料:
22050
		#http://php.net/manual/en/function.exec.php
22051
		#備註:
22052
		#無.
22053
		$execByteCode=external::execByteCode($conf);
22054
		unset($conf);
22055
 
22056
		#如果執行失敗
22057
		if($execByteCode["status"]==="false"){
22058
 
22059
			#設置執行失敗
22060
			$result["status"]="false";
22061
 
22062
			#設置執行錯誤訊息
22063
			$result["error"]=$execByteCode;
22064
 
22065
			#回傳結果
22066
			return $result;
22067
 
22068
			}#if end
22069
 
22070
		}#function packetFromSvnToRemoteServer end
22071
 
22072
	/*
22073
	#函式說明:
22074
	#輸出標準錯誤
22075
	#回傳結果:
22076
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22077
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
22078
	#$result["function"],當前執行的函式名稱.
22079
	#必填參數:
22080
	#$conf["errors"],字串陣列,要輸出的標準錯誤訊息.
22081
	#$conf["errors"]=array();
22082
	#可省略參數:
22083
	#$conf["forceEOL"],字串,是否要強制每個元素結尾都要有PHP_EOL,"false"代表不要;預設為"true"代表要.
22084
	#$conf["forceEOL"]="true";
22085
	#參考資料
22086
	#http://php.net/manual/en/features.commandline.io-streams.php
22087
	#備註:
22088
	#無.
22089
	*/
22090
	public static function outputStdErr(&$conf=array()){
22091
 
22092
		#初始化要回傳的結果
22093
		$result=array();
22094
 
22095
		#取得當前執行的函式名稱
22096
		$result["function"]=__FUNCTION__;
22097
 
22098
		#如果沒有參數
22099
		if(func_num_args()==0){
22100
 
22101
			#設置執行失敗
22102
			$result["status"]="false";
22103
 
22104
			#設置執行錯誤訊息
22105
			$result["error"]="函式".$result["function"]."需要參數";
22106
 
22107
			#回傳結果
22108
			return $result;
22109
 
22110
			}#if end
22111
 
22112
		#函式說明:
22113
		#判斷當前環境為web還是cmd
22114
		#回傳結果:
22115
		#$result,"web"或"cmd"
22116
		if(csInformation::getEnv()==="web"){
22117
 
22118
			#設置執行失敗
22119
			$result["status"]="false";
22120
 
22121
			#設置執行錯誤訊息
22122
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
22123
 
22124
			#回傳結果
22125
			return $result;
22126
 
22127
			}#if end
22128
 
22129
		#取得參數
22130
		$result["argu"]=$conf;
22131
 
22132
		#如果 $conf 不為陣列
22133
		if(gettype($conf)!=="array"){
22134
 
22135
			#設置執行失敗
22136
			$result["status"]="false";
22137
 
22138
			#設置執行錯誤訊息
22139
			$result["error"][]="\$conf變數須為陣列形態";
22140
 
22141
			#如果傳入的參數為 null
22142
			if($conf===null){
22143
 
22144
				#設置執行錯誤訊息
22145
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
22146
 
22147
				}#if end
22148
 
22149
			#回傳結果
22150
			return $result;
22151
 
22152
			}#if end
22153
 
22154
		#檢查參數
22155
		#函式說明:
22156
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
22157
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22158
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
22159
		#$result["function"],當前執行的函式名稱.
22160
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
22161
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
22162
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
22163
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
22164
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
22165
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
22166
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
22167
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
22168
		#必填寫的參數:
22169
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
22170
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
22171
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
22172
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("errors");
22173
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
22174
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
22175
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
22176
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
22177
		#可以省略的參數:
22178
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
22179
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
22180
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
22181
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("forceEOL");
22182
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
22183
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("forceEOL");
22184
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
22185
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
22186
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
22187
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
22188
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
22189
		#$conf["arrayCountEqualCheck"][]=array();
22190
		#參考資料來源:
22191
		#array_keys=>http://php.net/manual/en/function.array-keys.php
22192
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
22193
		unset($conf["variableCheck::checkArguments"]);
22194
 
22195
		#如果檢查失敗
22196
		if($checkArguments["status"]=="false"){
22197
 
22198
			#設置錯誤識別
22199
			$result["status"]="false";
22200
 
22201
			#設置錯誤訊息
22202
			$result["error"]=$checkArguments;
22203
 
22204
			#回傳結果
22205
			return $result;
22206
 
22207
			}#if end
22208
 
22209
		#如果檢查不通過
22210
		if($checkArguments["passed"]=="false"){
22211
 
22212
			#設置錯誤識別
22213
			$result["status"]="false";
22214
 
22215
			#設置錯誤訊息
22216
			$result["error"]=$checkArguments;
22217
 
22218
			#回傳結果
22219
			return $result;
22220
 
22221
			}#if end
22222
 
22223
		#開啟錯誤輸出的界面
22224
		$stderr = fopen('php://stderr', 'w');
22225
 
22226
		#針對每個錯誤列
22227
		foreach($conf["errors"] as $error){
22228
 
22229
			#取得換行符號的長度
22230
			$EOLlength=strlen(PHP_EOL);
22231
 
22232
			#如果強制要每個元素用PHP_EOL
22233
			if($conf["forceEOL"]==="true")
22234
			{
22235
				#取得該行錯誤的長度
22236
				$errlength=strlen($error);
22237
 
22238
				#如果結尾無PHP_EOL
22239
				if(strpos($error,PHP_EOL)!==($errlength-$EOLlength+1)){
22240
 
22241
					#加上PHP_EOL
22242
					$error=$error.PHP_EOL;
22243
 
22244
					}#if end
22245
 
22246
				}#if end
22247
 
22248
			#輸出錯誤
22249
			fwrite($stderr,$error);
22250
 
22251
			}#foreach end
22252
 
22253
		}#fucntion outputStdErr end
22254
 
22255
	/*
22256
	#函式說明:
22257
	#用find指令尋找檔案
22258
	#回傳結果:
22259
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22260
	#$result["error"],錯誤訊息.
22261
	#$result["function"],當前執行的函式名稱.
22262
	#$result["argu"],所使用的參數.
22263
	#$result["found"],是否有找到符合的檔案,"true"代表有;"false"代表沒有.
22264
	#$result["content"],找到的檔案陣列.
22265
	#必填參數:
22266
	#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
22267
	$conf["keyWord"]="";
22268
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
22269
	$conf["fileArgu"]=$conf["fileArgu"];
22270
	#可省略參數:
22271
	#$conf["path"],字串,搜尋的路徑,預設為"/".
22272
	#$conf["path"]="/";
22273
	#$conf["fileOnly"],字串,"true"代表只要找檔案,"false"代表.
22274
	#$conf["fileOnly"]="";
22275
	#參考資料:
22276
	#http://php.net/manual/en/function.glob.php
22277
	#備註:
22278
	#無.
22279
	*/
22280
	public static function find(&$conf=array()){
22281
 
22282
		#初始化要回傳的結果
22283
		$result=array();
22284
 
22285
		#取得當前執行的函式名稱
22286
		$result["function"]=__FUNCTION__;
22287
 
22288
		#如果沒有參數
22289
		if(func_num_args()==0){
22290
 
22291
			#設置執行失敗
22292
			$result["status"]="false";
22293
 
22294
			#設置執行錯誤訊息
22295
			$result["error"]="函式".$result["function"]."需要參數";
22296
 
22297
			#回傳結果
22298
			return $result;
22299
 
22300
			}#if end
22301
 
22302
		#取得參數
22303
		$result["argu"]=$conf;
22304
 
22305
		#如果 $conf 不為陣列
22306
		if(gettype($conf)!=="array"){
22307
 
22308
			#設置執行失敗
22309
			$result["status"]="false";
22310
 
22311
			#設置執行錯誤訊息
22312
			$result["error"][]="\$conf變數須為陣列形態";
22313
 
22314
			#如果傳入的參數為 null
22315
			if($conf===null){
22316
 
22317
				#設置執行錯誤訊息
22318
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
22319
 
22320
				}#if end
22321
 
22322
			#回傳結果
22323
			return $result;
22324
 
22325
			}#if end
22326
 
22327
		#函式說明:
22328
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
22329
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22330
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
22331
		#$result["function"],當前執行的函式名稱.
22332
		#$result["argu"],設置給予的參數.
22333
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
22334
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
22335
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
22336
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
22337
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
22338
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
22339
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
22340
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
22341
		#必填寫的參數:
22342
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
22343
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
22344
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
22345
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
22346
		#可以省略的參數:
22347
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
22348
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","keyWord");
22349
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
22350
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
22351
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
22352
		#$conf["canBeEmptyString"]="false";
22353
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
22354
		#$conf["canNotBeEmpty"]=array();
22355
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
22356
		#$conf["canBeEmpty"]=array();
22357
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
22358
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","fileOnly");
22359
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
22360
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","fileOnly");
22361
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
22362
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
22363
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
22364
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/","false");
22365
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
22366
		#$conf["disallowAllSkipableVarIsEmpty"]="";
22367
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
22368
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
22369
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
22370
		#$conf["arrayCountEqualCheck"][]=array();
22371
		#參考資料來源:
22372
		#array_keys=>http://php.net/manual/en/function.array-keys.php
22373
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
22374
		unset($conf["variableCheck::checkArguments"]);
22375
 
22376
		#如果檢查參數失敗
22377
		if($checkArguments["status"]==="false"){
22378
 
22379
			#設置執行失敗
22380
			$result["status"]="false";
22381
 
22382
			#設置錯誤訊息
22383
			$result["error"]=$checkArguments;
22384
 
22385
			#回傳結果
22386
			return $result;
22387
 
22388
			}#if end
22389
 
22390
		#如果檢查參數失敗
22391
		if($checkArguments["passed"]==="false"){
22392
 
22393
			#設置執行失敗
22394
			$result["status"]="false";
22395
 
22396
			#設置錯誤訊息
22397
			$result["error"]=$checkArguments;
22398
 
22399
			#回傳結果
22400
			return $result;
22401
 
22402
			}#if end
22403
 
22404
		#初始化參數
22405
		$params=array();
22406
 
22407
		#設置搜尋路徑
22408
		$params[]=$conf["path"];
22409
 
22410
		#如果只要搜尋檔案
22411
		if($conf["fileOnly"]==="true"){
22412
 
22413
			#設置類型
22414
			$params[]="-type";
22415
 
22416
			#設置為檔案
22417
			$params[]="f";
22418
 
22419
			}#if end
22420
 
22421
		#設置搜尋的關鍵字
22422
		$params[]="-name";
22423
 
22424
		#設置搜尋的關鍵字參數
22425
		$params[]=$conf["keyWord"];
22426
 
22427
		#初始化是否為路徑的參數
22428
		$arguIsAddr=array();
22429
 
22430
		#針對每個參數
22431
		foreach($params as $no=>$val){
22432
 
22433
			#如果是第一個
22434
			if($no===0){
22435
 
22436
				#設置為路徑
22437
				$arguIsAddr[]="true";
22438
 
22439
				}#if end
22440
 
22441
			#反之
22442
			else{
22443
 
22444
				#設置不為路徑
22445
				$arguIsAddr[]="false";
22446
 
22447
				}#else end
22448
 
22449
			}#foreach end
22450
 
22451
		#函式說明:
22452
		#呼叫shell執行系統命令,並取得回傳的內容.
22453
		#回傳的結果:
22454
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22455
		#$result["error"],錯誤訊息陣列.
22456
		#$result["function"],當前執行的函式名稱.
22457
		#$result["argu"],使用的參數.
22458
		#$result["cmd"],執行的指令內容.
22459
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
22460
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
22461
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
22462
		#$result["running"],是否還在執行.
22463
		#$result["pid"],pid
22464
		#必填參數:
22465
		#$conf["command"],字串,要執行的指令與.
22466
		$conf["external::callShell"]["command"]="find";
22467
		#$conf["fileArgu"],字串,變數__FILE__的內容.
22468
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
22469
		#可省略參數:
22470
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
22471
		$conf["external::callShell"]["argu"]=$params;
22472
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
22473
		$conf["external::callShell"]["arguIsAddr"]=$arguIsAddr;
22474
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
22475
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
22476
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
22477
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
22478
		#$conf["enablePrintDescription"]="true";
22479
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
22480
		#$conf["printDescription"]="";
22481
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
22482
		$conf["external::callShell"]["escapeshellarg"]="true";
22483
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
22484
		#$conf["username"]="";
22485
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
22486
		#$conf["password"]="";
22487
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
22488
		#$conf["useScript"]="";
22489
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
22490
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
22491
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
22492
		#$conf["inBackGround"]="";
22493
		#備註:
22494
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
22495
		#參考資料:
22496
		#exec=>http://php.net/manual/en/function.exec.php
22497
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
22498
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
22499
		$callShell=external::callShell($conf["external::callShell"]);
22500
		unset($conf["external::callShell"]);
22501
 
22502
		#如果執行失敗
22503
		if($callShell["status"]==="false"){
22504
 
22505
			#設置執行失敗
22506
			$result["status"]="false";
22507
 
22508
			#設置錯誤訊息
22509
			$result["error"]=$callShell;
22510
 
22511
			#回傳結果
22512
			return $result;
22513
 
22514
			}#if end
22515
 
22516
		#初始化沒有找到
22517
		$result["found"]="false";
22518
 
22519
		#如果有找到符合的項目
22520
		if(count($callShell["output"])>0){
22521
 
22522
			#設置有找到
22523
			$result["found"]="true";
22524
 
22525
			}#if end
22526
 
22527
		#設置取得的檔案
22528
		$result["content"]=$callShell["output"];
22529
 
22530
		#設置執行正常
22531
		$result["status"]="true";
22532
 
22533
		#回傳結果
22534
		return $result;
22535
 
22536
		}#function find end
22537
 
22538
	/*
22539
	#函式說明:
22540
	#檢查 httpd 與 postfix/smtpd 的 log 與 named 的 log 與 sshd 的 log 把惡意連線的 IP 用防火牆阻阻擋
22541
	#回傳結果:
22542
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22543
	#$result["error"],錯誤訊息.
22544
	#$result["function"],當前執行的函式名稱.
22545
	#$result["argu"],所使用的參數.
22546
	#$result["content"],阻擋IP的結果或有問題的IP資訊清單.
22547
	#$result["reason"][$ip],特定ip被阻擋的資訊.
22548
	#必填參數:
22549
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
22550
	$conf["fileArgu"]=__FILE__;
22551
	#可省略參數:
22552
	#$conf["excludeIp"],字串陣列,白名單ip陣列.
22553
	#$conf["excludeIp"]=array();
22554
	#$conf["logPath"],字串,httpd的log位置,預設為 "/var/log/httpd"
22555
	#$conf["logPath"]="";
22556
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
22557
	#$conf["username"]="";
22558
	#$conf["password"],字串,root使用者的密碼,
22559
	#$conf["password"]="";
22560
	#$conf["getIplistOnly"],字串,是否不阻擋IP只取得有問題的IP,預設為"false",要阻擋IP;"true"代表只取得有問題的IP.
22561
	#$conf["getIplistOnly"]="false";
22562
	#$conf["dynamic"],字串,是否要動態的阻擋不要永久阻擋,是為"true";反之為"false",預設為"true".
22563
	#$conf["dynamic"]="true"
22564
	#參考資料:
22565
	#無.
22566
	#備註:
22567
	#無.
22568
	*/
22569
	public static function blockAcctackIp(&$conf){
22570
 
22571
		#初始化要回傳的結果
22572
		$result=array();
22573
 
22574
		#取得當前執行的函式名稱
22575
		$result["function"]=__FUNCTION__;
22576
 
22577
		#取得參數
22578
		$result["argu"]=$conf;
22579
 
22580
		#如果 $conf 不為陣列
22581
		if(gettype($conf)!=="array"){
22582
 
22583
			#設置執行失敗
22584
			$result["status"]="false";
22585
 
22586
			#設置執行錯誤訊息
22587
			$result["error"][]="\$conf變數須為陣列形態";
22588
 
22589
			#如果傳入的參數為 null
22590
			if(is_null($conf)){
22591
 
22592
				#設置執行錯誤訊息
22593
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
22594
 
22595
				}#if end
22596
 
22597
			#回傳結果
22598
			return $result;
22599
 
22600
			}#if end
22601
 
22602
		#函式說明:
22603
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
22604
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22605
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
22606
		#$result["function"],當前執行的函式名稱.
22607
		#$result["argu"],設置給予的參數.
22608
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
22609
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
22610
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
22611
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
22612
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
22613
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
22614
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
22615
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
22616
		#必填寫的參數:
22617
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
22618
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
22619
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
22620
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
22621
		#可以省略的參數:
22622
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
22623
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
22624
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
22625
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
22626
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
22627
		#$conf["canBeEmptyString"]="false";
22628
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
22629
		#$conf["canNotBeEmpty"]=array();
22630
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
22631
		#$conf["canBeEmpty"]=array();
22632
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
22633
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath","getIplistOnly","dynamic");
22634
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
22635
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("excludeIp","logPath","username","password","getIplistOnly","dynamic");
22636
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
22637
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string","string","string");
22638
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
22639
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array(),"/var/log/httpd","root",null,"false","true");
22640
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
22641
		#$conf["disallowAllSkipableVarIsEmpty"]="";
22642
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
22643
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
22644
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
22645
		#$conf["arrayCountEqualCheck"][]=array();
22646
		#參考資料來源:
22647
		#array_keys=>http://php.net/manual/en/function.array-keys.php
22648
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
22649
		unset($conf["variableCheck::checkArguments"]);
22650
 
22651
		#如果檢查參數失敗
22652
		if($checkArguments["status"]==="false"){
22653
 
22654
			#設置執行失敗
22655
			$result["status"]="false";
22656
 
22657
			#設置錯誤訊息
22658
			$result["error"]=$checkArguments;
22659
 
22660
			#回傳結果
22661
			return $result;
22662
 
22663
			}#if end
22664
 
22665
		#如果檢查參數失敗
22666
		if($checkArguments["passed"]==="false"){
22667
 
22668
			#設置執行失敗
22669
			$result["status"]="false";
22670
 
22671
			#設置錯誤訊息
22672
			$result["error"]=$checkArguments;
22673
 
22674
			#回傳結果
22675
			return $result;
22676
 
22677
			}#if end
22678
 
22679
		#取得 http 存取記錄的 log
22680
		#函式說明:
22681
		#檢查指令的輸出是否含有關鍵字
22682
		#回傳結果:
22683
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22684
		#$result["error"],錯誤訊息.
22685
		#$result["function"],當前執行的函式名稱.
22686
		#$result["argu"],使用的參數.
22687
		#$result["grepCmd"],截取關鍵字的指令.
22688
		#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
22689
		#$result["content"],關鍵字所在列的輸出.
22690
		#$result["count"],輸出的列數.
22691
		#必填參數:
22692
		#$conf["cmd"],字串,要執行的指令.
22693
		$conf["cmd::searchOutPut"]["cmd"]="cat";
22694
		#$conf["keyWord"],字串,要檢查是否有關鍵字.
22695
		$conf["cmd::searchOutPut"]["keyWord"]=" 404 ";
22696
		#$conf["fileArgu"],字串,變數__FILE__的內容.
22697
		$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
22698
		#可省略參數:
22699
		#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
22700
		#$conf["binPath"]="";
22701
		#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
22702
		$conf["cmd::searchOutPut"]["argu"]=array($conf["logPath"]."/access_log");
22703
		#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
22704
		#$conf["excludeGrep"]="false";
22705
 
22706
		#如果有設置 username
22707
		if(isset($conf["username"])){
22708
 
22709
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
22710
			$conf["cmd::searchOutPut"]["username"]=$conf["username"];
22711
 
22712
			}#if end
22713
 
22714
		#如果有設置 password
22715
		if(isset($conf["password"])){
22716
 
22717
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
22718
			$conf["cmd::searchOutPut"]["password"]=$conf["password"];
22719
 
22720
			}#if end
22721
 
22722
		$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
22723
		unset($conf["cmd::searchOutPut"]);
22724
 
22725
		#如果執行失敗
22726
		if($searchOutPut["status"]==="false"){
22727
 
22728
			#設置執行失敗
22729
			$result["status"]="false";
22730
 
22731
			#設置錯誤訊息
22732
			$result["error"]=$searchOutPut;
22733
 
22734
			#回傳結果
22735
			return $result;
22736
 
22737
			}#if end
22738
 
22739
		#如果不是只抓清單
22740
		if($conf["getIplistOnly"]==="false"){
22741
 
22742
			#清空 access_log
22743
			#函式說明:
22744
			#將檔案內容清空
22745
			#回傳結果:
22746
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
22747
			#$result["error"],錯誤訊息陣列
22748
			#必填參數:
22749
			#$conf["fileAddr"],字串,要清空的檔案位置與名稱.
22750
			$conf["fileAccess::emptyFile"]["fileAddr"]=$conf["logPath"]."/access_log";
22751
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
22752
			$conf["fileAccess::emptyFile"]["fileArgu"]=$conf["fileArgu"];
22753
			#可省略參數:
22754
			#可省略參數:
22755
			#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
22756
			$conf["fileAccess::emptyFile"]["web"]="false";
22757
			$emptyFile=fileAccess::emptyFile($conf["fileAccess::emptyFile"]);
22758
			unset($conf["fileAccess::emptyFile"]);
22759
 
22760
			#如果執行失敗
22761
			if($emptyFile["status"]==="false"){
22762
 
22763
				#設置執行失敗
22764
				$result["status"]="false";
22765
 
22766
				#設置錯誤訊息
22767
				$result["error"]=$emptyFile;
22768
 
22769
				#回傳結果
22770
				return $result;
22771
 
22772
				}#if end
22773
 
22774
			}#if end
22775
 
22776
		#過濾掉對於含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.  	
22777
		#函式說明:
22778
		#檢查多個字串中的每個字串是否有多個關鍵字
22779
		#回傳的結果:
22780
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
22781
		#$result["function"],當前執行的函式名稱.
22782
		#$result["error"],錯誤訊息.
22783
		#$result["argu"],使用的參數.
22784
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列.
22785
		#$result["foundedKeyWords"].找到的關鍵字.
22786
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列.
22787
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
22788
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
22789
		#必填參數:
22790
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(".css",".js","favicon.ico",".jpg",".png");#想要搜尋的關鍵字
22791
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$searchOutPut["content"];#要被搜尋的字串內容陣列
22792
		#可省略參數:
22793
		#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
22794
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
22795
		unset($conf["search::findManyKeyWordsFromManyString"]);
22796
 
22797
		#如果執行出錯
22798
		if($findManyKeyWordsFromManyString["status"]==="false"){
22799
 
22800
			#設置執行失敗
22801
			$result["status"]="false";
22802
 
22803
			#設置錯誤訊息
22804
			$result["error"]=$findManyKeyWordsFromManyString;
22805
 
22806
			#回傳結果
22807
			return $result;
22808
 
22809
			}#if end
22810
 
22811
		#取得不含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.
22812
		$searchOutPut["content"]=$findManyKeyWordsFromManyString["foundedFalseKey"];	
22813
 
22814
		#更新計數
22815
		$searchOutPut["count"]=count($searchOutPut["content"]);
22816
 
22817
		#用空格分割字串
22818
		#函式說明:
22819
		#將多個固定格式的字串分開,並回傳分開的結果
22820
		#回傳的參數:
22821
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
22822
		#$result["error"],錯誤訊息陣列.
22823
		#$result["function"],當前執行的函式名稱.
22824
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
22825
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
22826
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
22827
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
22828
		#必填參數:
22829
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
22830
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];
22831
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
22832
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";
22833
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
22834
		unset($conf["stringProcess::spiltMutiString"]);
22835
 
22836
		#如果分割失敗
22837
		if($spiltMutiString["status"]==="false"){
22838
 
22839
			#設置執行失敗
22840
			$result["status"]="false";
22841
 
22842
			#設置錯誤訊息
22843
			$result["error"]=$spiltMutiString;
22844
 
22845
			#回傳結果
22846
			return $result;
22847
 
22848
			}#if end
22849
 
22850
		#初始化儲存有問題IP的陣列
22851
		$ips=array();
22852
 
22853
		#初始化儲存可能有問題的IP陣列
22854
		$ips_byIp=array();
22855
 
22856
		#針對每行內容
22857
		for($i=0;$i<$searchOutPut["count"];$i++){
22858
 
22859
			#如果沒有分割出來的內容
22860
			if($spiltMutiString["spiltString"][$i]["dataCounts"]===0){
22861
 
22862
				#換下一個
22863
				continue;
22864
 
22865
				}#if end
22866
 
22867
			#有問題的資訊
22868
			$info=array();
22869
 
22870
			#設置問題對應的log行內容
22871
			$info["log"]=$spiltMutiString["spiltString"][$i]["oriStr"];
22872
 
22873
			#設置問題時間點
22874
			$info["time"]=$spiltMutiString["spiltString"][$i]["dataArray"][3];
22875
 
22876
			#記錄有問題的ip
22877
			$info["ip"]=$spiltMutiString["spiltString"][$i]["dataArray"][0];
22878
 
22879
			#取得可能有問題的IP位置資訊
22880
			$ips_byIp[$spiltMutiString["spiltString"][$i]["dataArray"][0]][]=$info;
22881
 
22882
 
22883
			}#for end
22884
 
22885
		#針對每個可能有問題的IP
22886
		foreach($ips_byIp as $ip => $infos){
22887
 
22888
			#計數 ip 於同時間前來的計數
22889
			$ipSameTimeCount=0;
22890
 
22891
			#用來存放來存取的同一時間
22892
			$ipSameTime="";
22893
 
22894
			#看來拜訪的時間點
22895
			foreach($infos as $info){
22896
 
22897
				#如果是初次
22898
				if($ipSameTime===""){
22899
 
22900
					#記錄時間點
22901
					$ipSameTime=$info["time"];
22902
 
22903
					#同時間點計數加1
22904
					$ipSameTimeCount++;
22905
 
22906
					}#if end
22907
 
22908
				#反之如果時間點相同
22909
				else if($ipSameTime===$info["time"]){
22910
 
22911
					#同時間點計數加1
22912
					$ipSameTimeCount++;
22913
 
22914
					}#if end
22915
 
22916
				#反之時間點不相同
22917
				else{
22918
 
22919
					#記錄時間點
22920
					$ipSameTime=$info["time"];
22921
 
22922
					#同時間點計數重設為1
22923
					$ipSameTimeCount=1;
22924
 
22925
					}#else end
22926
 
22927
				#如果同時間的計數達到3
22928
				if($ipSameTimeCount===3){
22929
 
22930
					#取得有問題的IP
22931
					$ips[]=$info;
22932
 
22933
					#換檢查下一個IP
22934
					continue 2;
22935
 
22936
					}#if end
22937
 
22938
				}#foreach end
22939
 
22940
			}#foreach end
22941
 
22942
		#取得 https 存取記錄的 log
22943
		#函式說明:
22944
		#檢查指令的輸出是否含有關鍵字
22945
		#回傳結果:
22946
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22947
		#$result["error"],錯誤訊息.
22948
		#$result["function"],當前執行的函式名稱.
22949
		#$result["argu"],使用的參數.
22950
		#$result["grepCmd"],截取關鍵字的指令.
22951
		#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
22952
		#$result["content"],關鍵字所在列的輸出.
22953
		#$result["count"],輸出的列數.
22954
		#必填參數:
22955
		#$conf["cmd"],字串,要執行的指令.
22956
		$conf["cmd::searchOutPut"]["cmd"]="cat";
22957
		#$conf["keyWord"],字串,要檢查是否有關鍵字.
22958
		$conf["cmd::searchOutPut"]["keyWord"]=" 404 ";
22959
		#$conf["fileArgu"],字串,變數__FILE__的內容.
22960
		$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
22961
		#可省略參數:
22962
		#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
22963
		#$conf["binPath"]="";
22964
		#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
22965
		$conf["cmd::searchOutPut"]["argu"]=array($conf["logPath"]."/ssl_access_log");
22966
		#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
22967
		#$conf["excludeGrep"]="false";
22968
 
22969
		#如果有設置 username
22970
		if(isset($conf["username"])){
22971
 
22972
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
22973
			$conf["cmd::searchOutPut"]["username"]=$conf["username"];
22974
 
22975
			}#if end
22976
 
22977
		#如果有設置 password
22978
		if(isset($conf["password"])){
22979
 
22980
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
22981
			$conf["cmd::searchOutPut"]["password"]=$conf["password"];
22982
 
22983
			}#if end
22984
 
22985
		$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
22986
		unset($conf["cmd::searchOutPut"]);
22987
 
22988
		#如果執行失敗
22989
		if($searchOutPut["status"]==="false"){
22990
 
22991
			#設置執行失敗
22992
			$result["status"]="false";
22993
 
22994
			#設置錯誤訊息
22995
			$result["error"]=$searchOutPut;
22996
 
22997
			#回傳結果
22998
			return $result;
22999
 
23000
			}#if end
23001
 
23002
		#如果不是只抓清單
23003
		if($conf["getIplistOnly"]==="false"){
23004
 
23005
			#清空 ssl_access_log
23006
			#函式說明:
23007
			#將檔案內容清空
23008
			#回傳結果:
23009
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
23010
			#$result["error"],錯誤訊息陣列
23011
			#必填參數:
23012
			#$conf["fileAddr"],字串,要清空的檔案位置與名稱.
23013
			$conf["fileAccess::emptyFile"]["fileAddr"]=$conf["logPath"]."/ssl_access_log";
23014
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
23015
			$conf["fileAccess::emptyFile"]["fileArgu"]=$conf["fileArgu"];
23016
			#可省略參數:
23017
			#無
23018
			$emptyFile=fileAccess::emptyFile($conf["fileAccess::emptyFile"]);
23019
			unset($conf["fileAccess::emptyFile"]);
23020
 
23021
			#如果執行失敗
23022
			if($emptyFile["status"]==="false"){
23023
 
23024
				#設置執行失敗
23025
				$result["status"]="false";
23026
 
23027
				#設置錯誤訊息
23028
				$result["error"]=$emptyFile;
23029
 
23030
				#回傳結果
23031
				return $result;
23032
 
23033
				}#if end
23034
 
23035
			}#if end
23036
 
23037
		#過濾掉對於含有 ".css",".js","favicon.ico",".jpg",".png" 關鍵字串的結果.  	
23038
		#函式說明:
23039
		#檢查多個字串中的每個字串是否有多個關鍵字
23040
		#回傳的結果:
23041
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
23042
		#$result["function"],當前執行的函式名稱.
23043
		#$result["error"],錯誤訊息.
23044
		#$result["argu"],使用的參數.
23045
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列.
23046
		#$result["foundedKeyWords"].找到的關鍵字.
23047
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列.
23048
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
23049
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
23050
		#必填參數:
23051
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(".css",".js","favicon.ico",".jpg",".png");#想要搜尋的關鍵字
23052
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$searchOutPut["content"];#要被搜尋的字串內容陣列
23053
		#可省略參數:
23054
		#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
23055
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
23056
		unset($conf["search::findManyKeyWordsFromManyString"]);
23057
 
23058
		#如果執行出錯
23059
		if($findManyKeyWordsFromManyString["status"]==="false"){
23060
 
23061
			#設置執行失敗
23062
			$result["status"]="false";
23063
 
23064
			#設置錯誤訊息
23065
			$result["error"]=$findManyKeyWordsFromManyString;
23066
 
23067
			#回傳結果
23068
			return $result;
23069
 
23070
			}#if end
23071
 
23072
		#取得不含有 ".css",".js","favicon.ico",".jpg",".png" 關鍵字串的結果.
23073
		$searchOutPut["content"]=$findManyKeyWordsFromManyString["foundedFalseKey"];	
23074
 
23075
		#更新計數
23076
		$searchOutPut["count"]=count($searchOutPut["content"]);
23077
 
23078
		#用空格分割字串
23079
		#函式說明:
23080
		#將多個固定格式的字串分開,並回傳分開的結果
23081
		#回傳的參數:
23082
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
23083
		#$result["error"],錯誤訊息陣列.
23084
		#$result["function"],當前執行的函式名稱.
23085
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
23086
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
23087
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
23088
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
23089
		#必填參數:
23090
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
23091
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];
23092
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
23093
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";
23094
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
23095
		unset($conf["stringProcess::spiltMutiString"]);
23096
 
23097
		#如果分割失敗
23098
		if($spiltMutiString["status"]==="false"){
23099
 
23100
			#設置執行失敗
23101
			$result["status"]="false";
23102
 
23103
			#設置錯誤訊息
23104
			$result["error"]=$spiltMutiString;
23105
 
23106
			#回傳結果
23107
			return $result;
23108
 
23109
			}#if end
23110
 
23111
		#初始化儲存有問題IP的陣列
23112
		$ips_https=array();
23113
 
23114
		#初始化儲存可能有問題的IP陣列
23115
		$ips_byIp_https=array();
23116
 
23117
		#針對每行內容
23118
		for($i=0;$i<$searchOutPut["count"];$i++){
23119
 
23120
			#如果沒有分割出來的內容
23121
			if($spiltMutiString["spiltString"][$i]["dataCounts"]===0){
23122
 
23123
				#換下一個
23124
				continue;
23125
 
23126
				}#if end
23127
 
23128
			#有問題的資訊
23129
			$info=array();
23130
 
23131
			#設置問題對應的log行內容
23132
			$info["log"]=$spiltMutiString["spiltString"][$i]["oriStr"];
23133
 
23134
			#設置問題時間點
23135
			$info["time"]=$spiltMutiString["spiltString"][$i]["dataArray"][3];
23136
 
23137
			#記錄有問題的ip
23138
			$info["ip"]=$spiltMutiString["spiltString"][$i]["dataArray"][0];
23139
 
23140
			#取得可能有問題的IP位置,key為[ip][int]
23141
			$ips_byIp_https[$spiltMutiString["spiltString"][$i]["dataArray"][0]][]=$info;
23142
 
23143
			}#for end
23144
 
23145
		#針對每個可能有問題的IP
23146
		foreach($ips_byIp_https as $infos){
23147
 
23148
			#計數 ip 於同時間前來的計數
23149
			$ipSameTimeCount=0;
23150
 
23151
			#用來存放來存取的同一時間
23152
			$ipSameTime="";
23153
 
23154
			#看來拜訪的時間點
23155
			foreach($infos as $info){
23156
 
23157
				#如果是初次
23158
				if($ipSameTime===""){
23159
 
23160
					#記錄時間點
23161
					$ipSameTime=$info["time"];
23162
 
23163
					#同時間點計數加1
23164
					$ipSameTimeCount++;
23165
 
23166
					}#if end
23167
 
23168
				#反之如果時間點相同
23169
				else if($ipSameTime===$info["time"]){
23170
 
23171
					#同時間點計數加1
23172
					$ipSameTimeCount++;
23173
 
23174
					}#if end
23175
 
23176
				#反之時間點不相同
23177
				else{
23178
 
23179
					#記錄時間點
23180
					$ipSameTime=$info["time"];
23181
 
23182
					#同時間點計數重設為1
23183
					$ipSameTimeCount=1;
23184
 
23185
					}#else end
23186
 
23187
				#如果同時間的計數達到3
23188
				if($ipSameTimeCount===3){
23189
 
23190
					#取得有問題的IP
23191
					$ips_https[]=$info;
23192
 
23193
					#換檢查下一個IP
23194
					continue 2;
23195
 
23196
					}#if end
23197
 
23198
				}#foreach end
23199
 
23200
			}#foreach end
23201
 
23202
		#透過 journalctl -a -e | grep "postfix/smtps/smtpd" | grep " connect from unknown" 來取得 IP
23203
		#函式說明:
23204
		#呼叫shell執行系統命令,並取得回傳的內容.
23205
		#回傳的結果:
23206
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23207
		#$result["error"],錯誤訊息陣列.
23208
		#$result["function"],當前執行的函式名稱.
23209
		#$result["argu"],使用的參數.
23210
		#$result["cmd"],執行的指令內容.
23211
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
23212
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
23213
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
23214
		#$result["running"],是否還在執行.
23215
		#$result["pid"],pid.
23216
		#$result["statusCode"],執行結束後的代碼.
23217
		#必填參數:
23218
		#$conf["command"],字串,要執行的指令與.
23219
		$conf["external::callShell"]["command"]="journalctl";
23220
		#$conf["fileArgu"],字串,變數__FILE__的內容.
23221
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
23222
		#可省略參數:
23223
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
23224
		$conf["external::callShell"]["argu"]=array("-a","-e","|","grep","postfix/smtps/smtpd","|","grep"," connect from unknown");
23225
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
23226
		#$conf["arguIsAddr"]=array();	
23227
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
23228
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
23229
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
23230
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
23231
		#$conf["enablePrintDescription"]="true";
23232
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
23233
		#$conf["printDescription"]="";
23234
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
23235
		$conf["external::callShell"]["escapeshellarg"]="true";
23236
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
23237
		#$conf["username"]="";
23238
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
23239
		#$conf["password"]="";
23240
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
23241
		#$conf["useScript"]="";
23242
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
23243
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
23244
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
23245
		#$conf["inBackGround"]="";
23246
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
23247
		#$conf["getErr"]="false";
23248
		#備註:
23249
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
23250
		#參考資料:
23251
		#exec=>http://php.net/manual/en/function.exec.php
23252
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
23253
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
23254
		$callShell=external::callShell($conf["external::callShell"]);
23255
		unset($conf["external::callShell"]);
23256
 
23257
		#如果執行失敗
23258
		if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){
23259
 
23260
			#設置執行失敗
23261
			$result["status"]="false";
23262
 
23263
			#設置錯誤訊息
23264
			$result["error"]=$callShell;
23265
 
23266
			#回傳結果
23267
			return $result;
23268
 
23269
			}#if end
23270
 
23271
		#儲存有問題的smtp IP
23272
		$ips_smtp=array();
23273
 
23274
		#狀態碼不為1才執行	
23275
		if($callShell["statusCode"]!==1){	
23276
 
23277
			#截取出的格式
23278
			#Aug 08 18:05:51 www.qbpwcf.org postfix/smtpd[27933]: connect from unknown[185.234.219.62]
23279
			#Aug 08 18:14:29 www.qbpwcf.org postfix/smtpd[16133]: connect from unknown[185.234.219.62]
23280
			#Aug 08 18:23:12 www.qbpwcf.org postfix/smtpd[11623]: connect from unknown[185.234.219.62]
23281
			#Apr 04 15:11:16 mail.qbpwcf.org postfix/smtps/smtpd[10145]: connect from unknown[212.70.149.72]
23282
			#Apr 04 15:58:01 mail.qbpwcf.org postfix/smtps/smtpd[12382]: connect from unknown[212.70.149.72]
23283
			#Mar 09 13:44:00 qbpwcf.org postfix/smtpd[1058247]: connect from unknown[194.48.251.15]
23284
			#Mar 09 13:44:01 qbpwcf.org postfix/smtpd[1058247]: disconnect from unknown[194.48.251.15] ehlo=1 auth=0/1 quit=1 commands=2/3
23285
 
23286
			#分割字串
23287
			#函式說明:
23288
			#將多個固定格式的字串分開,並回傳分開的結果
23289
			#回傳的參數:
23290
			#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
23291
			#$result["error"],錯誤訊息陣列.
23292
			#$result["function"],當前執行的函式名稱.
23293
			#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
23294
			#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
23295
			#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
23296
			#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
23297
			#必填參數:
23298
			#$conf["stringIn"],字串陣列,要處理的字串陣列.
23299
			$conf["stringProcess::spiltMutiString"]["stringIn"]=$callShell["output"];
23300
			#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
23301
			$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";
23302
			$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
23303
			unset($conf["stringProcess::spiltMutiString"]);
23304
 
23305
			#如果分割失敗
23306
			if($spiltMutiString["status"]==="false"){
23307
 
23308
				#設置執行失敗
23309
				$result["status"]="false";
23310
 
23311
				#設置錯誤訊息
23312
				$result["error"]=$spiltMutiString;
23313
 
23314
				#回傳結果
23315
				return $result;
23316
 
23317
				}#if end	
23318
 
23319
			#初始化記錄每行log的時間點
23320
			$occurTime=array();	
23321
 
23322
			#根據每筆記錄
23323
			foreach($spiltMutiString["spiltString"] as $index => $splitStr){
23324
 
23325
				#儲存時間
23326
				$occurTime[$index]=$spiltMutiString["spiltString"][$index]["dataArray"][0]." ".$spiltMutiString["spiltString"][$index]["dataArray"][1]." ".$spiltMutiString["spiltString"][$index]["dataArray"][2];
23327
 
23328
				}#foreach end	
23329
 
23330
			#第一次分割的關鍵字
23331
			$splitKeyWord=" connect from unknown[";
23332
 
23333
			#分割字串
23334
			#函式說明:
23335
			#將多個固定格式的字串分開,並回傳分開的結果
23336
			#回傳的參數:
23337
			#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
23338
			#$result["error"],錯誤訊息陣列.
23339
			#$result["function"],當前執行的函式名稱.
23340
			#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
23341
			#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
23342
			#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
23343
			#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
23344
			#必填參數:
23345
			#$conf["stringIn"],字串陣列,要處理的字串陣列.
23346
			$conf["stringProcess::spiltMutiString"]["stringIn"]=$callShell["output"];
23347
			#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
23348
			$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$splitKeyWord;
23349
			$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
23350
			unset($conf["stringProcess::spiltMutiString"]);
23351
 
23352
			#如果分割失敗
23353
			if($spiltMutiString["status"]==="false"){
23354
 
23355
				#設置執行失敗
23356
				$result["status"]="false";
23357
 
23358
				#設置錯誤訊息
23359
				$result["error"]=$spiltMutiString;
23360
 
23361
				#回傳結果
23362
				return $result;
23363
 
23364
				}#if end
23365
 
23366
			#儲存尚未處理好的字串
23367
			$unProcessedStr=array();
23368
 
23369
			#初始化儲存log行資訊的變數
23370
			$oriLog=array();
23371
 
23372
			#根據每筆記錄
23373
			foreach($spiltMutiString["spiltString"] as $index => $splitStr){
23374
 
23375
				#儲存原始的log行內容
23376
				$oriLog[$index]=$spiltMutiString["spiltString"][$index ]["oriStr"];
23377
 
23378
				#取得所需的字串
23379
				$unProcessedStr[]=$splitStr["dataArray"][1];
23380
 
23381
				}#foreach end
23382
 
23383
			#第二次分割的關鍵字
23384
			$splitKeyWord="]";
23385
 
23386
			#分割字串
23387
			#函式說明:
23388
			#將多個固定格式的字串分開,並回傳分開的結果
23389
			#回傳的參數:
23390
			#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
23391
			#$result["error"],錯誤訊息陣列.
23392
			#$result["function"],當前執行的函式名稱.
23393
			#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
23394
			#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
23395
			#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
23396
			#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
23397
			#必填參數:
23398
			#$conf["stringIn"],字串陣列,要處理的字串陣列.
23399
			$conf["stringProcess::spiltMutiString"]["stringIn"]=$unProcessedStr;
23400
			#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
23401
			$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$splitKeyWord;
23402
			$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
23403
			unset($conf["stringProcess::spiltMutiString"]);
23404
 
23405
			#如果分割失敗
23406
			if($spiltMutiString["status"]==="false"){
23407
 
23408
				#設置執行失敗
23409
				$result["status"]="false";
23410
 
23411
				#設置錯誤訊息
23412
				$result["error"]=$spiltMutiString;
23413
 
23414
				#回傳結果
23415
				return $result;
23416
 
23417
				}#if end
23418
 
23419
			#根據每筆記錄
23420
			foreach($spiltMutiString["spiltString"] as $index => $splitStr){
23421
 
23422
				#有問題的資訊
23423
				$info=array();
23424
 
23425
				#設置問題對應的log行內容
23426
				$info["log"]=$oriLog[$index];
23427
 
23428
				#設置問題時間點
23429
				$info["time"]=$occurTime[$index];
23430
 
23431
				#記錄有問題的ip
23432
				$info["ip"]=$splitStr["dataArray"][0];
23433
 
23434
				#取得所需的有問題的IP
23435
				$ips_smtp[]=$info;
23436
 
23437
				}#foreach end
23438
 
23439
			}#if end
23440
 
23441
		#透過 journalctl -e | grep named | grep " client " 來取得 IP
23442
		#函式說明:
23443
		#呼叫shell執行系統命令,並取得回傳的內容.
23444
		#回傳的結果:
23445
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23446
		#$result["error"],錯誤訊息陣列.
23447
		#$result["function"],當前執行的函式名稱.
23448
		#$result["argu"],使用的參數.
23449
		#$result["cmd"],執行的指令內容.
23450
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
23451
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
23452
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
23453
		#$result["running"],是否還在執行.
23454
		#$result["pid"],pid.
23455
		#$result["statusCode"],執行結束後的代碼.
23456
		#必填參數:
23457
		#$conf["command"],字串,要執行的指令與.
23458
		$conf["external::callShell"]["command"]="journalctl";
23459
		#$conf["fileArgu"],字串,變數__FILE__的內容.
23460
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
23461
		#可省略參數:
23462
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
23463
		$conf["external::callShell"]["argu"]=array("-a","-e","|","grep"," named","|","grep"," client ");
23464
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
23465
		#$conf["arguIsAddr"]=array();	
23466
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
23467
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
23468
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
23469
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
23470
		#$conf["enablePrintDescription"]="true";
23471
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
23472
		#$conf["printDescription"]="";
23473
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
23474
		$conf["external::callShell"]["escapeshellarg"]="true";
23475
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
23476
		#$conf["username"]="";
23477
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
23478
		#$conf["password"]="";
23479
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
23480
		#$conf["useScript"]="";
23481
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
23482
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
23483
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
23484
		#$conf["inBackGround"]="";
23485
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
23486
		#$conf["getErr"]="false";
23487
		#備註:
23488
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
23489
		#參考資料:
23490
		#exec=>http://php.net/manual/en/function.exec.php
23491
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
23492
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
23493
		$callShell=external::callShell($conf["external::callShell"]);
23494
		unset($conf["external::callShell"]);
23495
 
23496
		#如果執行失敗
23497
		if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){
23498
 
23499
			#設置執行失敗
23500
			$result["status"]="false";
23501
 
23502
			#設置錯誤訊息
23503
			$result["error"]=$callShell;
23504
 
23505
			#回傳結果
23506
			return $result;
23507
 
23508
			}#if end
23509
 
23510
		#記錄攻擊者的IP
23511
		$attacker_ips_namd=array();	
23512
 
23513
		#狀態碼不為1才執行	
23514
		if($callShell["statusCode"]!==1){		
23515
 
23516
			#截取出的格式
23517
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23518
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23519
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23520
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23521
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23522
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23523
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23524
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23525
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f77180297c0 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23526
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23527
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23528
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23529
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23530
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23531
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f770c077bf0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23532
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f770c077bf0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23533
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23534
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f77180297c0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23535
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23536
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f77180297c0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23537
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23538
			#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23539
			#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23540
			#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
23541
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#40052 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
23542
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#48628 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
23543
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#52460 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
23544
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#60457 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
23545
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#10213 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
23546
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#44377 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
23547
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#4481 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
23548
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#53061 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
23549
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#31654 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
23550
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc802a410 61.220.11.198#57701 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
23551
 
23552
			#第一次分割的關鍵字
23553
			$splitKeyWord="#";
23554
 
23555
			#分割字串
23556
			#函式說明:
23557
			#將多個固定格式的字串分開,並回傳分開的結果
23558
			#回傳的參數:
23559
			#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
23560
			#$result["error"],錯誤訊息陣列.
23561
			#$result["function"],當前執行的函式名稱.
23562
			#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
23563
			#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
23564
			#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
23565
			#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
23566
			#必填參數:
23567
			#$conf["stringIn"],字串陣列,要處理的字串陣列.
23568
			$conf["stringProcess::spiltMutiString"]["stringIn"]=$callShell["output"];
23569
			#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
23570
			$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$splitKeyWord;
23571
			$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
23572
			unset($conf["stringProcess::spiltMutiString"]);
23573
 
23574
			#如果分割失敗
23575
			if($spiltMutiString["status"]==="false"){
23576
 
23577
				#設置執行失敗
23578
				$result["status"]="false";
23579
 
23580
				#設置錯誤訊息
23581
				$result["error"]=$spiltMutiString;
23582
 
23583
				#回傳結果
23584
				return $result;
23585
 
23586
				}#if end
23587
 
23588
			#儲存未處理的dns查詢字串
23589
			$quertString=array();
23590
 
23591
			#儲存尚未處理好的字串
23592
			$unProcessedStr=array();
23593
 
23594
			#初始化儲存原始log行內容
23595
			$oriLog=array();
23596
 
23597
			#根據每筆記錄
23598
			foreach($spiltMutiString["spiltString"] as $index => $splitStr){
23599
 
23600
				#如果切割出來小於兩段
23601
				if($splitStr["dataCounts"]<2){
23602
 
23603
					#換下一筆資料
23604
					continue;
23605
 
23606
					}#if end
23607
 
23608
				#取得原始log行內容
23609
				$oriLog[]=$splitStr["oriStr"];
23610
 
23611
				#取得所需的字串
23612
				$unProcessedStr[]=$splitStr["dataArray"][0];
23613
 
23614
				#儲存查詢的dns字串
23615
				$quertString[]=$splitStr["dataArray"][1];
23616
 
23617
				}#foreach end
23618
 
23619
			#第二次分割的關鍵字
23620
			$splitKeyWord=" ";
23621
 
23622
			#分割字串
23623
			#函式說明:
23624
			#將多個固定格式的字串分開,並回傳分開的結果
23625
			#回傳的參數:
23626
			#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
23627
			#$result["error"],錯誤訊息陣列.
23628
			#$result["function"],當前執行的函式名稱.
23629
			#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
23630
			#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
23631
			#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
23632
			#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
23633
			#必填參數:
23634
			#$conf["stringIn"],字串陣列,要處理的字串陣列.
23635
			$conf["stringProcess::spiltMutiString"]["stringIn"]=$unProcessedStr;
23636
			#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
23637
			$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$splitKeyWord;
23638
			$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
23639
			unset($conf["stringProcess::spiltMutiString"]);
23640
 
23641
			#如果分割失敗
23642
			if($spiltMutiString["status"]==="false"){
23643
 
23644
				#設置執行失敗
23645
				$result["status"]="false";
23646
 
23647
				#設置錯誤訊息
23648
				$result["error"]=$spiltMutiString;
23649
 
23650
				#回傳結果
23651
				return $result;
23652
 
23653
				}#if end
23654
 
23655
			#儲存有問題的IP
23656
			$ips_named=array();
23657
 
23658
			#根據每筆記錄
23659
			foreach($spiltMutiString["spiltString"] as $index => $splitStr){
23660
 
23661
				#取得所需的可能有問題的IP
23662
				$ips_named[]=array("ip"=>$splitStr["dataArray"][$splitStr["dataCounts"]-1],"time"=>$splitStr["dataArray"][2],"log"=>$oriLog[$index]);
23663
 
23664
				}#foreach end
23665
 
23666
			#第三次分割的關鍵字
23667
			$splitKeyWord=" ";
23668
 
23669
			#分割字串
23670
			#函式說明:
23671
			#將多個固定格式的字串分開,並回傳分開的結果
23672
			#回傳的參數:
23673
			#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
23674
			#$result["error"],錯誤訊息陣列.
23675
			#$result["function"],當前執行的函式名稱.
23676
			#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
23677
			#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
23678
			#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
23679
			#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
23680
			#必填參數:
23681
			#$conf["stringIn"],字串陣列,要處理的字串陣列.
23682
			$conf["stringProcess::spiltMutiString"]["stringIn"]=$quertString;
23683
			#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
23684
			$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$splitKeyWord;
23685
			$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
23686
			unset($conf["stringProcess::spiltMutiString"]);
23687
 
23688
			#如果分割失敗
23689
			if($spiltMutiString["status"]==="false"){
23690
 
23691
				#設置執行失敗
23692
				$result["status"]="false";
23693
 
23694
				#設置錯誤訊息
23695
				$result["error"]=$spiltMutiString;
23696
 
23697
				#回傳結果
23698
				return $result;
23699
 
23700
				}#if end
23701
 
23702
			#根據每筆記錄
23703
			foreach($spiltMutiString["spiltString"] as $index=>$splitStr){
23704
 
23705
				#取得所需的可能有問題IP所查詢的dns
23706
				$ips_named[$index]["dns"]=$splitStr["dataArray"][$splitStr["dataCounts"]-2];
23707
 
23708
				}#foreach end
23709
 
23710
			#初始化記錄時間點
23711
			$time=0;
23712
 
23713
			#初始化記錄當前ip
23714
			$ip="";
23715
 
23716
			#初始化記錄當前查詢的dns
23717
			$dns="";
23718
 
23719
			#初始化記錄同時間,ip重複的次數.
23720
			$count=0;
23721
 
23722
			#針對每筆資料
23723
			for($i=0;$i<count($ips_named);$i++){
23724
 
23725
				#如果時間點不同
23726
				if($ips_named[$i]["time"]!==$time){
23727
 
23728
					#初始化記錄時間點
23729
					$time=$ips_named[$i]["time"];
23730
 
23731
					#初始化記錄當前ip
23732
					$ip=$ips_named[$i]["ip"];
23733
 
23734
					#初始化記錄當前的dns
23735
					$dns=$ips_named[$i]["dns"];
23736
 
23737
					#初始化記錄同時間,ip重複的次數.
23738
					$count=1;
23739
 
23740
					}#if end
23741
 
23742
				#反之時間點相同且,但ip不同
23743
				else if($ips_named[$i]["ip"]!==$ip){
23744
 
23745
					#初始化記錄時間點
23746
					$time=$ips_named[$i]["time"];
23747
 
23748
					#初始化記錄當前ip
23749
					$ip=$ips_named[$i]["ip"];
23750
 
23751
					#初始化記錄當前的dns
23752
					$dns=$ips_named[$i]["dns"];
23753
 
23754
					#初始化記錄同時間,ip重複的次數.
23755
					$count=1;				
23756
 
23757
					}#if end
23758
 
23759
				#反之時間點相同,但dns不同
23760
				else if($ips_named[$i]["dns"]!==$dns){
23761
 
23762
					#初始化記錄時間點
23763
					$time=$ips_named[$i]["time"];
23764
 
23765
					#初始化記錄當前ip
23766
					$ip=$ips_named[$i]["ip"];
23767
 
23768
					#初始化記錄當前的dns
23769
					$dns=$ips_named[$i]["dns"];
23770
 
23771
					#初始化記錄同時間,ip重複的次數.
23772
					$count=1;	
23773
 
23774
					}#if end
23775
 
23776
				#反之時間點與IP與dns皆相同
23777
				else{
23778
 
23779
					#計數+1
23780
					$count++;
23781
 
23782
					#如果計數5次
23783
					if($count===5){
23784
 
23785
						#若該IP是已經重複
23786
						if(in_array($ips_named[$i]["ip"],$attacker_ips_namd)){
23787
 
23788
							#跳過
23789
							continue;
23790
 
23791
							}#if end
23792
 
23793
						#反之是新IP
23794
						else{
23795
 
23796
							#記錄起來
23797
							$attacker_ips_namd[]=$ips_named[$i];
23798
 
23799
							}#else end
23800
 
23801
						}#if end
23802
 
23803
					}#else end
23804
 
23805
				}#for end
23806
 
23807
			}#if end
23808
 
23809
		#透過 journalctl -a -e | grep dovecot | grep failed 來取得 IP
23810
		#函式說明:
23811
		#呼叫shell執行系統命令,並取得回傳的內容.
23812
		#回傳的結果:
23813
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23814
		#$result["error"],錯誤訊息陣列.
23815
		#$result["function"],當前執行的函式名稱.
23816
		#$result["argu"],使用的參數.
23817
		#$result["cmd"],執行的指令內容.
23818
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
23819
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
23820
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
23821
		#$result["running"],是否還在執行.
23822
		#$result["pid"],pid.
23823
		#$result["statusCode"],執行結束後的代碼.
23824
		#必填參數:
23825
		#$conf["command"],字串,要執行的指令與.
23826
		$conf["external::callShell"]["command"]="journalctl";
23827
		#$conf["fileArgu"],字串,變數__FILE__的內容.
23828
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
23829
		#可省略參數:
23830
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
23831
		$conf["external::callShell"]["argu"]=array("-a","-e","|","grep","dovecot","|","grep","failed");
23832
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
23833
		#$conf["arguIsAddr"]=array();	
23834
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
23835
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
23836
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
23837
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
23838
		#$conf["enablePrintDescription"]="true";
23839
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
23840
		#$conf["printDescription"]="";
23841
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
23842
		$conf["external::callShell"]["escapeshellarg"]="true";
23843
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
23844
		#$conf["username"]="";
23845
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
23846
		#$conf["password"]="";
23847
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
23848
		#$conf["useScript"]="";
23849
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
23850
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
23851
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
23852
		#$conf["inBackGround"]="";
23853
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
23854
		#$conf["getErr"]="false";
23855
		#備註:
23856
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
23857
		#參考資料:
23858
		#exec=>http://php.net/manual/en/function.exec.php
23859
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
23860
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
23861
		$callShell=external::callShell($conf["external::callShell"]);
23862
		unset($conf["external::callShell"]);
23863
 
23864
		#如果執行失敗
23865
		if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){
23866
 
23867
			#設置執行失敗
23868
			$result["status"]="false";
23869
 
23870
			#設置錯誤訊息
23871
			$result["error"]=$callShell;
23872
 
23873
			#回傳結果
23874
			return $result;
23875
 
23876
			}#if end
23877
 
23878
		#記錄攻擊者的IP
23879
		$attacker_ips_imap=array();
23880
 
23881
		/* $callShell["output"] 範例截取結果
23882
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MxQuPu+73xpliNc9>
23883
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hH8xPu+7dBtliNc9>
23884
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<nmI0Pu+7zhtliNc9>
23885
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<1GU2Pu+7NBhliNc9>
23886
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0Io5Pu+7sRhliNc9>
23887
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zbQ+Pu+7rhlliNc9>
23888
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0P5APu+7/BlliNc9>
23889
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<gKRDPu+7XhpliNc9>
23890
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<4hNHPu+77hpliNc9>
23891
		Feb 23 00:25:00 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<belIPu+7bBtliNc9>
23892
		Feb 23 00:25:00 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<VhRLPu+7xBtliNc9>
23893
		Feb 23 00:46:19 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<loiMiu+7cxhliNc9>
23894
		Feb 23 00:46:19 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<RNCQiu+7/xhliNc9>
23895
		Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NWCTiu+7PBlliNc9>
23896
		Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<2tiViu+7hBlliNc9>
23897
		Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<w6Sbiu+7/xlliNc9>
23898
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SkWkiu+7gBtliNc9>
23899
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<bGCmiu+7qBtliNc9>
23900
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0E+oiu+76RtliNc9>
23901
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<FBGriu+7UhhliNc9>
23902
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<AeSsiu+7iBhliNc9>
23903
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<gpSuiu+70hhliNc9>
23904
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zYfITPC7RBlliNc9>
23905
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<GULMTPC7zhlliNc9>
23906
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3jjOTPC7CBpliNc9>
23907
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vhHQTPC7UBpliNc9>
23908
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vArTTPC7rxpliNc9>
23909
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hDTXTPC7GhtliNc9>
23910
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<c6vZTPC7SRtliNc9>
23911
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<rQzcTPC7jBtliNc9>
23912
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<LSffTPC78htliNc9>
23913
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<XLThTPC7KBhliNc9>
23914
		Feb 23 01:40:40 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<tZfjTPC7dxhliNc9>
23915
		Feb 23 03:27:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<i3bIyfG7AxtliNc9>
23916
		Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0sLVyfG7uxtliNc9>
23917
		Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<BJXZyfG7BhhliNc9>
23918
		Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<xK3cyfG7SxhliNc9>
23919
		Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<q43gyfG7aRhliNc9>
23920
		Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Oj3syfG7FBlliNc9>
23921
		Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SF7uyfG7RhlliNc9>
23922
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<IM/wyfG7ZRlliNc9>
23923
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<pXv1yfG7vBlliNc9>
23924
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8ub4yfG7/xlliNc9>
23925
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<H0j7yfG7NRpliNc9>
23926
		Feb 23 06:10:07 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Zw6FEPS7WxhliNc9>
23927
		Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vmKTEPS7cRpliNc9>
23928
		Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SkOXEPS7BxtliNc9>
23929
		Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<H42bEPS7WRtliNc9>
23930
		Feb 23 06:10:09 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<jFqoEPS7SRhliNc9>
23931
		Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<TNy4EPS7DhpliNc9>
23932
		Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JYW7EPS7mBpliNc9>
23933
		Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=</Ve+EPS76hpliNc9>
23934
		Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<StLGEPS7qhtliNc9>
23935
		Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<7RnLEPS7DBhliNc9>
23936
		Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<6xTOEPS7eBhliNc9>
23937
		Feb 23 06:29:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<YHy0VfS7uBhliNc9>
23938
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<WLW4VfS7fxlliNc9>
23939
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<lM66VfS73BlliNc9>
23940
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Q4K9VfS7NxpliNc9>
23941
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JiLBVfS7rRpliNc9>
23942
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<DETIVfS7qxtliNc9>
23943
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<UlLLVfS7GhhliNc9>
23944
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<safNVfS7txhliNc9>
23945
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<M/DQVfS7LxlliNc9>
23946
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<+zPTVfS7eRlliNc9>
23947
		Feb 23 06:29:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<dxXWVfS72hlliNc9>
23948
		Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<S0pci/S7SxhliNc9>
23949
		Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zThji/S78RhliNc9>
23950
		Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8PJoi/S7ixlliNc9>
23951
		Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Qkhui/S7PBpliNc9>
23952
		Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SXVzi/S7hhtliNc9>
23953
		Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=</X55i/S7uhhliNc9>
23954
		Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MHJ9i/S74hlliNc9>
23955
		Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<RBWBi/S7pRpliNc9>
23956
		Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NJeGi/S7yhtliNc9>
23957
		Feb 23 06:44:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<QsaMi/S7rxhliNc9>
23958
		Feb 23 06:44:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8fiPi/S7uBlliNc9>
23959
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<dt04yPS7KBlliNc9>
23960
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<ZMI9yPS7WxpliNc9>
23961
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<nTVAyPS7ARtliNc9>
23962
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<wj1CyPS7lxtliNc9>
23963
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<u7RFyPS7YRhliNc9>
23964
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<tpBLyPS7ZhlliNc9>
23965
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<CRdOyPS7wxlliNc9>
23966
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<v9NQyPS7JxpliNc9>
23967
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<81lUyPS73hpliNc9>
23968
		Feb 23 07:01:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<PCZXyPS7TRtliNc9>
23969
		Feb 23 07:01:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<VnNZyPS7qxtliNc9>
23970
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<op+l9vS7ZxhliNc9>
23971
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<aBCr9vS7CBlliNc9>
23972
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0sOt9vS7dRlliNc9>
23973
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NFaw9vS7xhlliNc9>
23974
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<QS609vS7SRpliNc9>
23975
		Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<4FW79vS76htliNc9>
23976
		Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Fxu+9vS7gBhliNc9>
23977
		Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3djA9vS75RhliNc9>
23978
		Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hgzE9vS7mxlliNc9>
23979
		Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<J8TG9vS7GBpliNc9>
23980
		Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<t87I9vS7mBpliNc9>
23981
		Feb 23 07:29:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<1xBILPW7MRtliNc9>
23982
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<IXZNLPW79htliNc9>
23983
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<6OdPLPW7chhliNc9>
23984
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<M5BSLPW78hhliNc9>
23985
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Nv9VLPW7UxlliNc9>
23986
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<foJbLPW7KRpliNc9>
23987
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<EoVeLPW7nxpliNc9>
23988
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<DwNhLPW7JRtliNc9>
23989
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<mKhkLPW7ohtliNc9>
23990
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3nhnLPW7/htliNc9>
23991
		Feb 23 07:29:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<e+lpLPW7XRhliNc9>
23992
		Feb 23 07:44:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<KtTtYfW7dBhliNc9>
23993
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MLTxYfW77BhliNc9>
23994
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<9GL0YfW7KBlliNc9>
23995
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JNT2YfW7fRlliNc9>
23996
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8Zv5YfW72RlliNc9>
23997
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<lbv/YfW73BpliNc9>
23998
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<5zsCYvW7EBtliNc9>
23999
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<aE8EYvW7bRtliNc9>
24000
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<LEIHYvW75RtliNc9>
24001
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<rLsJYvW7MRhliNc9>
24002
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<9oMMYvW7ihhliNc9>
24003
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<x7SUl/W7mBpliNc9>
24004
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<k1KZl/W73xtliNc9>
24005
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Veabl/W7PxhliNc9>
24006
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Yamel/W7sxhliNc9>
24007
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<wpGil/W7OBlliNc9>
24008
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<+VCol/W7aBpliNc9>
24009
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<TMaql/W7zhpliNc9>
24010
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<KnKtl/W7GBtliNc9>
24011
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Lkixl/W7ixtliNc9>
24012
		Feb 23 07:59:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8bWzl/W7ARhliNc9>
24013
		Feb 23 07:59:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<70q2l/W7PBhliNc9>
24014
		*/
24015
 
24016
		#針對每列輸出
24017
		foreach($callShell["output"] as $line){
24018
 
24019
			#用 " " 區分內容
24020
			#函式說明:
24021
			#將固定格式的字串分開,並回傳分開的結果。
24022
			#回傳結果:
24023
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24024
			#$result["error"],錯誤訊息陣列
24025
			#$result["function"],當前執行的函式名稱.
24026
			#$result["argu"],使用的參數.
24027
			#$result["oriStr"],要分割的原始字串內容
24028
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
24029
			#$result["dataCounts"],爲總共分成幾段
24030
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
24031
			#必填參數:
24032
			#$conf["stringIn"],字串,要處理的字串.
24033
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
24034
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
24035
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
24036
			#可省略參數:
24037
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
24038
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
24039
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
24040
			unset($conf["stringProcess::spiltString"]);
24041
 
24042
			#如果分割失敗
24043
			if($spiltString["status"]==="false"){
24044
 
24045
				#設置執行失敗
24046
				$result["status"]="false";
24047
 
24048
				#設置錯誤訊息
24049
				$result["error"]=$spiltString;
24050
 
24051
				#回傳結果
24052
				return $result;
24053
 
24054
				}#if end
24055
 
24056
			#取得時間
24057
			$time=$spiltString["dataArray"][2];
24058
 
24059
			#用 "rip=" 切割
24060
			#函式說明:
24061
			#將固定格式的字串分開,並回傳分開的結果。
24062
			#回傳結果:
24063
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24064
			#$result["error"],錯誤訊息陣列
24065
			#$result["function"],當前執行的函式名稱.
24066
			#$result["argu"],使用的參數.
24067
			#$result["oriStr"],要分割的原始字串內容
24068
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
24069
			#$result["dataCounts"],爲總共分成幾段
24070
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
24071
			#必填參數:
24072
			#$conf["stringIn"],字串,要處理的字串.
24073
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
24074
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
24075
			$conf["stringProcess::spiltString"]["spiltSymbol"]="rip=";
24076
			#可省略參數:
24077
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
24078
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
24079
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
24080
			unset($conf["stringProcess::spiltString"]);
24081
 
24082
			#如果分割失敗
24083
			if($spiltString["status"]==="false"){
24084
 
24085
				#設置執行失敗
24086
				$result["status"]="false";
24087
 
24088
				#設置錯誤訊息
24089
				$result["error"]=$spiltString;
24090
 
24091
				#回傳結果
24092
				return $result;
24093
 
24094
				}#if end 
24095
 
24096
			#如果不存在 client ip 字串
24097
			if(!isset($spiltString["dataArray"][1])){
24098
 
24099
				#跳過
24100
				continue;
24101
 
24102
				}#if end
24103
 
24104
			#取得含有 client IP 的字串
24105
			$clientIpStr=$spiltString["dataArray"][1];
24106
 
24107
			#用 "," 切割
24108
			#函式說明:
24109
			#將固定格式的字串分開,並回傳分開的結果。
24110
			#回傳結果:
24111
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24112
			#$result["error"],錯誤訊息陣列
24113
			#$result["function"],當前執行的函式名稱.
24114
			#$result["argu"],使用的參數.
24115
			#$result["oriStr"],要分割的原始字串內容
24116
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
24117
			#$result["dataCounts"],爲總共分成幾段
24118
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
24119
			#必填參數:
24120
			#$conf["stringIn"],字串,要處理的字串.
24121
			$conf["stringProcess::spiltString"]["stringIn"]=$clientIpStr;
24122
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
24123
			$conf["stringProcess::spiltString"]["spiltSymbol"]=",";
24124
			#可省略參數:
24125
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
24126
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
24127
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
24128
			unset($conf["stringProcess::spiltString"]);
24129
 
24130
			#如果分割失敗
24131
			if($spiltString["status"]==="false"){
24132
 
24133
				#設置執行失敗
24134
				$result["status"]="false";
24135
 
24136
				#設置錯誤訊息
24137
				$result["error"]=$spiltString;
24138
 
24139
				#回傳結果
24140
				return $result;
24141
 
24142
				}#if end
24143
 
24144
			#取得來源ip
24145
			$clientIp=$spiltString["dataArray"][0];
24146
 
24147
			#如果計數不存在
24148
			if(!isset($attacker_ips_imap[$time][$clientIp])){
24149
 
24150
				#初始計數為1
24151
				$attacker_ips_imap[$time][$clientIp]=1;
24152
 
24153
				#記錄log行內容
24154
				$attacker_ips_imap[$time]["log"]=$line;
24155
 
24156
				}#if end
24157
 
24158
			#反之
24159
			else{
24160
 
24161
				#計數加1
24162
				$attacker_ips_imap[$time][$clientIp]++;
24163
 
24164
				}#else end
24165
 
24166
			}#foreach end
24167
 
24168
		#存放真正有問題的imap ip清單
24169
		$ips_imap=array();
24170
 
24171
		#針對每個時間點
24172
		foreach($attacker_ips_imap as $time=>$times){
24173
 
24174
			#針對每個列管的ip
24175
			foreach($times as $ip => $count){
24176
 
24177
				#如果是log
24178
				if($ip==="log"){
24179
 
24180
					#跳過
24181
					continue;
24182
 
24183
					}#if end
24184
 
24185
				#如果累積次數達到3
24186
				if($count>=3){
24187
 
24188
					#儲存有問題ip的資訊
24189
					$info=array();
24190
 
24191
					#記錄 ip
24192
					$info["ip"]=$ip;
24193
 
24194
					#記錄該行 log 內容
24195
					$info["log"]=$attacker_ips_imap[$time]["log"];
24196
 
24197
					#記錄時間
24198
					$info["time"]=$time;
24199
 
24200
					#記錄有問題的imap ip清單
24201
					$ips_imap[]=$info;
24202
 
24203
					}#if end
24204
 
24205
				}#foreach end
24206
 
24207
			}#foreach end
24208
 
24209
		#記錄ssh攻擊者的IP
24210
		$attacker_ips_ssh=array();
24211
 
24212
		#透過 journalctl -a -e | grep sshd | grep failed 來取得 ssh 攻擊者的 IP
24213
		#函式說明:
24214
		#呼叫shell執行系統命令,並取得回傳的內容.
24215
		#回傳的結果:
24216
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24217
		#$result["error"],錯誤訊息陣列.
24218
		#$result["function"],當前執行的函式名稱.
24219
		#$result["argu"],使用的參數.
24220
		#$result["cmd"],執行的指令內容.
24221
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
24222
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
24223
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
24224
		#$result["running"],是否還在執行.
24225
		#$result["pid"],pid.
24226
		#$result["statusCode"],執行結束後的代碼.
24227
		#必填參數:
24228
		#$conf["command"],字串,要執行的指令與.
24229
		$conf["external::callShell"]["command"]="journalctl";
24230
		#$conf["fileArgu"],字串,變數__FILE__的內容.
24231
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
24232
		#可省略參數:
24233
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
24234
		$conf["external::callShell"]["argu"]=array("-a","-e","|","grep","sshd","|","grep","failed");
24235
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
24236
		#$conf["arguIsAddr"]=array();	
24237
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
24238
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
24239
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
24240
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
24241
		#$conf["enablePrintDescription"]="true";
24242
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
24243
		#$conf["printDescription"]="";
24244
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
24245
		$conf["external::callShell"]["escapeshellarg"]="true";
24246
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
24247
		#$conf["username"]="";
24248
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
24249
		#$conf["password"]="";
24250
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
24251
		#$conf["useScript"]="";
24252
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
24253
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
24254
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
24255
		#$conf["inBackGround"]="";
24256
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
24257
		#$conf["getErr"]="false";
24258
		#備註:
24259
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
24260
		#參考資料:
24261
		#exec=>http://php.net/manual/en/function.exec.php
24262
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
24263
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
24264
		$callShell=external::callShell($conf["external::callShell"]);
24265
		unset($conf["external::callShell"]);
24266
 
24267
		#如果執行失敗
24268
		if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){
24269
 
24270
			#設置執行失敗
24271
			$result["status"]="false";
24272
 
24273
			#設置錯誤訊息
24274
			$result["error"]=$callShell;
24275
 
24276
			#回傳結果
24277
			return $result;
24278
 
24279
			}#if end
24280
 
24281
		/*
24282
		得到的範例輸出
24283
		Apr 03 07:35:05 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858888]: USER_LOGIN pid=2858888 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="(unknown)" exe="/usr/sbin/sshd" hostname=? addr=81.30.179.11 terminal=ssh res=failed'
24284
		Apr 03 07:35:07 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858891]: USER_AUTH pid=2858891 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'
24285
		Apr 03 07:35:09 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858891]: USER_AUTH pid=2858891 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'
24286
		Apr 03 07:35:12 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858891]: USER_AUTH pid=2858891 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'
24287
		Apr 03 07:35:14 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858891]: USER_LOGIN pid=2858891 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="root" exe="/usr/sbin/sshd" hostname=? addr=49.88.112.77 terminal=ssh res=failed'
24288
		Apr 03 07:35:22 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858896]: USER_AUTH pid=2858896 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'
24289
		Apr 03 07:35:23 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858901]: USER_AUTH pid=2858901 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="bot" exe="/usr/sbin/sshd" hostname=103.149.27.65 addr=103.149.27.65 terminal=ssh res=failed'
24290
		Apr 03 07:35:23 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858899]: USER_AUTH pid=2858899 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="insserver" exe="/usr/sbin/sshd" hostname=129.146.81.43 addr=129.146.81.43 terminal=ssh res=failed'
24291
		Apr 03 07:35:24 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858896]: USER_AUTH pid=2858896 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'
24292
		Apr 03 07:35:25 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858901]: USER_LOGIN pid=2858901 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="(unknown)" exe="/usr/sbin/sshd" hostname=? addr=103.149.27.65 terminal=ssh res=failed'
24293
		Apr 03 07:35:25 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858899]: USER_LOGIN pid=2858899 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="(unknown)" exe="/usr/sbin/sshd" hostname=? addr=129.146.81.43 terminal=ssh res=failed'
24294
		Apr 03 07:35:27 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858896]: USER_AUTH pid=2858896 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=49.88.112.77 addr=49.88.112.77 terminal=ssh res=failed'
24295
		Apr 03 07:35:29 ip-172-31-46-128.ap-southeast-1.compute.internal audit[2858896]: USER_LOGIN pid=2858896 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="root" exe="/usr/sbin/sshd" hostname=? addr=49.88.112.77 terminal=ssh res=failed'
24296
		Mar 07 12:14:24 mail.qbpwcf.org sshd[3253686]: error: connect_to 127.0.0.1 port 5950: failed.
24297
		*/	
24298
 
24299
		#針對每列輸出
24300
		foreach($callShell["output"] as $line){
24301
 
24302
			#用 "addr=" 區分內容
24303
			#函式說明:
24304
			#將固定格式的字串分開,並回傳分開的結果。
24305
			#回傳結果:
24306
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24307
			#$result["error"],錯誤訊息陣列
24308
			#$result["function"],當前執行的函式名稱.
24309
			#$result["argu"],使用的參數.
24310
			#$result["oriStr"],要分割的原始字串內容
24311
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
24312
			#$result["dataCounts"],爲總共分成幾段
24313
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
24314
			#必填參數:
24315
			#$conf["stringIn"],字串,要處理的字串.
24316
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
24317
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
24318
			$conf["stringProcess::spiltString"]["spiltSymbol"]="addr=";
24319
			#可省略參數:
24320
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
24321
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
24322
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
24323
			unset($conf["stringProcess::spiltString"]);
24324
 
24325
			#如果分割失敗
24326
			if($spiltString["status"]==="false"){
24327
 
24328
				#設置執行失敗
24329
				$result["status"]="false";
24330
 
24331
				#設置錯誤訊息
24332
				$result["error"]=$spiltString;
24333
 
24334
				#回傳結果
24335
				return $result;
24336
 
24337
				}#if end
24338
 
24339
			#如果沒有找到分割用的關鍵字
24340
			if($spiltString["found"]==="false"){
24341
 
24342
				#設置執行失敗
24343
				$result["status"]="true";
24344
 
24345
				#設置警告訊息
24346
				$result["warning"][]=$spiltString;
24347
 
24348
				#跳過
24349
				continue;
24350
 
24351
				}#if end
24352
 
24353
			#取得IP位址開頭的字串	
24354
			$ipStr=$spiltString["dataArray"][1];
24355
 
24356
			#用 " " 區分內容
24357
			#函式說明:
24358
			#將固定格式的字串分開,並回傳分開的結果。
24359
			#回傳結果:
24360
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24361
			#$result["error"],錯誤訊息陣列
24362
			#$result["function"],當前執行的函式名稱.
24363
			#$result["argu"],使用的參數.
24364
			#$result["oriStr"],要分割的原始字串內容
24365
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
24366
			#$result["dataCounts"],爲總共分成幾段
24367
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
24368
			#必填參數:
24369
			#$conf["stringIn"],字串,要處理的字串.
24370
			$conf["stringProcess::spiltString"]["stringIn"]=$ipStr;
24371
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
24372
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
24373
			#可省略參數:
24374
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
24375
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
24376
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
24377
			unset($conf["stringProcess::spiltString"]);
24378
 
24379
			#如果分割失敗
24380
			if($spiltString["status"]==="false"){
24381
 
24382
				#設置執行失敗
24383
				$result["status"]="false";
24384
 
24385
				#設置錯誤訊息
24386
				$result["error"]=$spiltString;
24387
 
24388
				#回傳結果
24389
				return $result;
24390
 
24391
				}#if end
24392
 
24393
			#如果沒有找到分割用的關鍵字
24394
			if($spiltString["found"]==="false"){
24395
 
24396
				#設置執行失敗
24397
				$result["status"]="false";
24398
 
24399
				#設置錯誤訊息
24400
				$result["error"]=$spiltString;
24401
 
24402
				#回傳結果
24403
				return $result;
24404
 
24405
				}#if end
24406
 
24407
			#取得IP位址	
24408
			$ip=$spiltString["dataArray"][0];
24409
 
24410
			#用 " " 區分內容
24411
			#函式說明:
24412
			#將固定格式的字串分開,並回傳分開的結果。
24413
			#回傳結果:
24414
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24415
			#$result["error"],錯誤訊息陣列
24416
			#$result["function"],當前執行的函式名稱.
24417
			#$result["argu"],使用的參數.
24418
			#$result["oriStr"],要分割的原始字串內容
24419
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
24420
			#$result["dataCounts"],爲總共分成幾段
24421
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
24422
			#必填參數:
24423
			#$conf["stringIn"],字串,要處理的字串.
24424
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
24425
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
24426
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
24427
			#可省略參數:
24428
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
24429
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
24430
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
24431
			unset($conf["stringProcess::spiltString"]);
24432
 
24433
			#如果分割失敗
24434
			if($spiltString["status"]==="false"){
24435
 
24436
				#設置執行失敗
24437
				$result["status"]="false";
24438
 
24439
				#設置錯誤訊息
24440
				$result["error"]=$spiltString;
24441
 
24442
				#回傳結果
24443
				return $result;
24444
 
24445
				}#if end
24446
 
24447
			#如果沒有找到分割用的關鍵字
24448
			if($spiltString["found"]==="false"){
24449
 
24450
				#設置執行失敗
24451
				$result["status"]="false";
24452
 
24453
				#設置錯誤訊息
24454
				$result["error"]=$spiltString;
24455
 
24456
				#回傳結果
24457
				return $result;
24458
 
24459
				}#if end
24460
 
24461
			#取得含有秒數的時間點	
24462
			$timeWithSec=$spiltString["dataArray"][2];	
24463
 
24464
			#用 ":" 區分內容
24465
			#函式說明:
24466
			#將固定格式的字串分開,並回傳分開的結果。
24467
			#回傳結果:
24468
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24469
			#$result["error"],錯誤訊息陣列
24470
			#$result["function"],當前執行的函式名稱.
24471
			#$result["argu"],使用的參數.
24472
			#$result["oriStr"],要分割的原始字串內容
24473
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
24474
			#$result["dataCounts"],爲總共分成幾段
24475
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
24476
			#必填參數:
24477
			#$conf["stringIn"],字串,要處理的字串.
24478
			$conf["stringProcess::spiltString"]["stringIn"]=$timeWithSec;
24479
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
24480
			$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
24481
			#可省略參數:
24482
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
24483
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
24484
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
24485
			unset($conf["stringProcess::spiltString"]);
24486
 
24487
			#如果分割失敗
24488
			if($spiltString["status"]==="false"){
24489
 
24490
				#設置執行失敗
24491
				$result["status"]="false";
24492
 
24493
				#設置錯誤訊息
24494
				$result["error"]=$spiltString;
24495
 
24496
				#回傳結果
24497
				return $result;
24498
 
24499
				}#if end
24500
 
24501
			#如果沒有找到分割用的關鍵字
24502
			if($spiltString["found"]==="false"){
24503
 
24504
				#設置執行失敗
24505
				$result["status"]="false";
24506
 
24507
				#設置錯誤訊息
24508
				$result["error"]=$spiltString;
24509
 
24510
				#回傳結果
24511
				return $result;
24512
 
24513
				}#if end	
24514
 
24515
			#時間包含到分鐘的字串
24516
			$timeWithMin=$spiltString["dataArray"][0].":".$spiltString["dataArray"][1];
24517
 
24518
			#如果該時間分對應的ip不存在
24519
			if(!isset($attacker_ips_ssh[$timeWithMin][$ip])){
24520
 
24521
				#初始化為1次
24522
				$attacker_ips_ssh[$timeWithMin][$ip]["count"]=1;	
24523
 
24524
				#記錄內容
24525
				$attacker_ips_ssh[$timeWithMin][$ip]["line"][]=$line;
24526
 
24527
				}#if end	
24528
 
24529
			#反之
24530
			else{
24531
				#計數+1
24532
				$attacker_ips_ssh[$timeWithMin][$ip]["count"]++;
24533
 
24534
				#記錄內容
24535
				$attacker_ips_ssh[$timeWithMin][$ip]["line"][]=$line;
24536
 
24537
				}#else end
24538
 
24539
			}#foreach end
24540
 
24541
		#透過 journalctl -a -e | grep sshd | grep 'Invalid user ' | grep ' from ' 來取得 ssh 攻擊者的 IP
24542
		#函式說明:
24543
		#呼叫shell執行系統命令,並取得回傳的內容.
24544
		#回傳的結果:
24545
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24546
		#$result["error"],錯誤訊息陣列.
24547
		#$result["function"],當前執行的函式名稱.
24548
		#$result["argu"],使用的參數.
24549
		#$result["cmd"],執行的指令內容.
24550
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
24551
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
24552
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
24553
		#$result["running"],是否還在執行.
24554
		#$result["pid"],pid.
24555
		#$result["statusCode"],執行結束後的代碼.
24556
		#必填參數:
24557
		#$conf["command"],字串,要執行的指令與.
24558
		$conf["external::callShell"]["command"]="journalctl";
24559
		#$conf["fileArgu"],字串,變數__FILE__的內容.
24560
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
24561
		#可省略參數:
24562
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
24563
		$conf["external::callShell"]["argu"]=array("-a","-e","|","grep","sshd","|","grep","Invalid user","|","grep"," from ");
24564
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
24565
		#$conf["arguIsAddr"]=array();	
24566
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
24567
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
24568
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
24569
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
24570
		#$conf["enablePrintDescription"]="true";
24571
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
24572
		#$conf["printDescription"]="";
24573
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
24574
		$conf["external::callShell"]["escapeshellarg"]="true";
24575
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
24576
		#$conf["username"]="";
24577
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
24578
		#$conf["password"]="";
24579
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
24580
		#$conf["useScript"]="";
24581
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
24582
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
24583
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
24584
		#$conf["inBackGround"]="";
24585
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
24586
		#$conf["getErr"]="false";
24587
		#備註:
24588
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
24589
		#參考資料:
24590
		#exec=>http://php.net/manual/en/function.exec.php
24591
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
24592
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
24593
		$callShell=external::callShell($conf["external::callShell"]);
24594
		unset($conf["external::callShell"]);
24595
 
24596
		#如果執行失敗
24597
		if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){
24598
 
24599
			#設置執行失敗
24600
			$result["status"]="false";
24601
 
24602
			#設置錯誤訊息
24603
			$result["error"]=$callShell;
24604
 
24605
			#回傳結果
24606
			return $result;
24607
 
24608
			}#if end
24609
 
24610
		#得到的範例輸出
24611
		#Dec 22 15:51:48 mail.qbpwcf.org sshd[3518693]: Invalid user xl from 159.89.131.172 port 44458
24612
 
24613
		#debug
24614
		#var_dump(__LINE__,$callShell["output"]);
24615
 
24616
		#針對每列輸出
24617
		foreach($callShell["output"] as $line){
24618
 
24619
			#備份原始的內容
24620
			$ori_line=$line;
24621
 
24622
			#移除多餘的資訊
24623
			#函式說明:
24624
			#將字串特定關鍵字與其前面的內容剔除
24625
			#回傳結果:
24626
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24627
			#$result["error"],錯誤訊息陣列.
24628
			#$result["warning"],警告訊息鎮列.
24629
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
24630
			#$result["function"],當前執行的函數名稱.
24631
			#$result["argu"],使用的參數.
24632
			#$result["oriStr"],要處理的原始字串內容.
24633
			#$result["content"],處理好的的字串內容.	
24634
			#必填參數:
24635
			#$conf["stringIn"],字串,要處理的字串.
24636
			$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$line;
24637
			#$conf["keyWord"],字串,特定字串.
24638
			$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" Invalid user ";
24639
			#可省略參數:
24640
			#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
24641
			#$conf["recursive"]="true";
24642
			#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則回改回傳該內容.
24643
			#$conf["lastResult"]=$delStrBeforeKeyWord;
24644
			#參考資料:
24645
			#無.
24646
			#備註:
24647
			#無.
24648
			$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
24649
			unset($conf["stringProcess::delStrBeforeKeyWord"]);
24650
 
24651
			#debug
24652
			#var_dump(__LINE__,$delStrBeforeKeyWord);
24653
 
24654
			#如果執行失敗
24655
			if($delStrBeforeKeyWord["status"]==="false"){
24656
 
24657
				#設置執行失敗
24658
				$result["status"]="false";
24659
 
24660
				#設置錯誤訊息
24661
				$result["error"]=$delStrBeforeKeyWord;
24662
 
24663
				#回傳結果
24664
				return $result;
24665
 
24666
				}#if end
24667
 
24668
			#如果沒有理應存在內容
24669
			if($delStrBeforeKeyWord["founded"]==="false"){
24670
 
24671
				#設置執行失敗
24672
				$result["status"]="false";
24673
 
24674
				#設置錯誤訊息
24675
				$result["error"]=$delStrBeforeKeyWord;
24676
 
24677
				#回傳結果
24678
				return $result;
24679
 
24680
				}#if end
24681
 
24682
			#取得需要的部分
24683
			$line=$delStrBeforeKeyWord["content"];
24684
 
24685
			#解析 ip
24686
			#函式說明:
24687
			#將字串進行解析,取得兩個關鍵字中間的內容.
24688
			#回傳結果:
24689
			#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
24690
			#$result["function"],當前執行的函式內容.
24691
			#$result["error"],錯誤訊息陣列.
24692
			#$result["content"],取得的內容.
24693
			#$result["oriStr"],原始的內容.
24694
			#$result["found"],是否有找到符合條件的內容.
24695
			#必填參數:
24696
			#$conf["input"],字串,要處理的字串.
24697
			$conf["stringProcess::getContentBetweenKeyWord"]["input"]=$line;
24698
			#$conf["startKeyWord"],字串,開頭的關鍵字.
24699
			$conf["stringProcess::getContentBetweenKeyWord"]["startKeyWord"]=" from ";
24700
			#$conf["endKeyWord"],字串,結束的關鍵字.
24701
			$conf["stringProcess::getContentBetweenKeyWord"]["endKeyWord"]=" port ";
24702
			#可省略參數:
24703
			#無.
24704
			#參考資料:
24705
			#無.
24706
			#備註:
24707
			#無.
24708
			$getContentBetweenKeyWord=stringProcess::getContentBetweenKeyWord($conf["stringProcess::getContentBetweenKeyWord"]);
24709
			unset($conf["stringProcess::getContentBetweenKeyWord"]);
24710
 
24711
			#如果執行失敗
24712
			if($getContentBetweenKeyWord["status"]==="false"){
24713
 
24714
				#設置執行失敗
24715
				$result["status"]="false";
24716
 
24717
				#設置錯誤訊息
24718
				$result["error"]=$getContentBetweenKeyWord;
24719
 
24720
				#回傳結果
24721
				return $result;
24722
 
24723
				}#if end
24724
 
24725
			#如果沒有有該有的關鍵字
24726
			if($getContentBetweenKeyWord["found"]==="false"){
24727
 
24728
				#設置執行失敗
24729
				$result["status"]="false";
24730
 
24731
				#設置錯誤訊息
24732
				$result["error"]=$getContentBetweenKeyWord;
24733
 
24734
				#回傳結果
24735
				return $result;
24736
 
24737
				}#if end
24738
 
24739
			#取得ip
24740
			$ip=$getContentBetweenKeyWord["content"];	
24741
 
24742
			#解析time
24743
			#用 " " 區分內容
24744
			#函式說明:
24745
			#將固定格式的字串分開,並回傳分開的結果。
24746
			#回傳結果:
24747
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24748
			#$result["error"],錯誤訊息陣列
24749
			#$result["function"],當前執行的函式名稱.
24750
			#$result["argu"],使用的參數.
24751
			#$result["oriStr"],要分割的原始字串內容
24752
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
24753
			#$result["dataCounts"],爲總共分成幾段
24754
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
24755
			#必填參數:
24756
			#$conf["stringIn"],字串,要處理的字串.
24757
			$conf["stringProcess::spiltString"]["stringIn"]=$ori_line;
24758
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
24759
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
24760
			#可省略參數:
24761
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
24762
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
24763
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
24764
			unset($conf["stringProcess::spiltString"]);
24765
 
24766
			#如果分割失敗
24767
			if($spiltString["status"]==="false"){
24768
 
24769
				#設置執行失敗
24770
				$result["status"]="false";
24771
 
24772
				#設置錯誤訊息
24773
				$result["error"]=$spiltString;
24774
 
24775
				#回傳結果
24776
				return $result;
24777
 
24778
				}#if end
24779
 
24780
			#如果沒有找到分割用的關鍵字
24781
			if($spiltString["found"]==="false"){
24782
 
24783
				#設置執行失敗
24784
				$result["status"]="false";
24785
 
24786
				#設置錯誤訊息
24787
				$result["error"]=$spiltString;
24788
 
24789
				#回傳結果
24790
				return $result;
24791
 
24792
				}#if end
24793
 
24794
			#取得含有秒數的時間點
24795
			$timeWithSec=$spiltString["dataArray"][2];
24796
 
24797
			#用 ":" 區分內容
24798
			#函式說明:
24799
			#將固定格式的字串分開,並回傳分開的結果。
24800
			#回傳結果:
24801
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24802
			#$result["error"],錯誤訊息陣列
24803
			#$result["function"],當前執行的函式名稱.
24804
			#$result["argu"],使用的參數.
24805
			#$result["oriStr"],要分割的原始字串內容
24806
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
24807
			#$result["dataCounts"],爲總共分成幾段
24808
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
24809
			#必填參數:
24810
			#$conf["stringIn"],字串,要處理的字串.
24811
			$conf["stringProcess::spiltString"]["stringIn"]=$timeWithSec;
24812
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
24813
			$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
24814
			#可省略參數:
24815
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
24816
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
24817
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
24818
			unset($conf["stringProcess::spiltString"]);
24819
 
24820
			#如果分割失敗
24821
			if($spiltString["status"]==="false"){
24822
 
24823
				#設置執行失敗
24824
				$result["status"]="false";
24825
 
24826
				#設置錯誤訊息
24827
				$result["error"]=$spiltString;
24828
 
24829
				#回傳結果
24830
				return $result;
24831
 
24832
				}#if end
24833
 
24834
			#如果沒有找到分割用的關鍵字
24835
			if($spiltString["found"]==="false"){
24836
 
24837
				#設置執行失敗
24838
				$result["status"]="false";
24839
 
24840
				#設置錯誤訊息
24841
				$result["error"]=$spiltString;
24842
 
24843
				#回傳結果
24844
				return $result;
24845
 
24846
				}#if end	
24847
 
24848
			#時間包含到分鐘的字串
24849
			$timeWithMin=$spiltString["dataArray"][0].":".$spiltString["dataArray"][1];
24850
 
24851
			#如果該時間分對應的ip不存在
24852
			if(!isset($attacker_ips_ssh[$timeWithMin][$ip])){
24853
 
24854
				#初始化為1次
24855
				$attacker_ips_ssh[$timeWithMin][$ip]["count"]=1;
24856
 
24857
				#記錄內容
24858
				$attacker_ips_ssh[$timeWithMin][$ip]["line"][]=$ori_line;
24859
 
24860
				}#if end	
24861
 
24862
			#反之
24863
			else{
24864
 
24865
				#計數+1
24866
				$attacker_ips_ssh[$timeWithMin][$ip]["count"]++;
24867
 
24868
				#記錄內容
24869
				$attacker_ips_ssh[$timeWithMin][$ip]["line"][]=$ori_line;
24870
 
24871
				}#else end
24872
 
24873
			}#foreach end
24874
 
24875
		#存放真正有問題的imap ip清單
24876
		$ips_ssh=array();
24877
 
24878
		#針對每個時間點
24879
		foreach($attacker_ips_ssh as $times){
24880
 
24881
			#針對每個列管的ip
24882
			foreach($times as $ip => $info){
24883
 
24884
				#取得計數
24885
				$count=$info["count"];
24886
 
24887
				#取得該行
24888
				$ori_line=$info["line"];
24889
 
24890
				#如果累積次數達到3
24891
				if($count>=3){
24892
 
24893
					#儲存該行log
24894
					$info["log"]=$ori_line;
24895
 
24896
					#儲存ip
24897
					$info["ip"]=$ip;
24898
 
24899
					#記錄有問題的imap ip清單
24900
					$ips_ssh[]=$info;
24901
 
24902
					}#if end
24903
 
24904
				}#foreach end
24905
 
24906
			}#foreach end
24907
 
24908
		#合併取得的有問題IP集合
24909
		#$ips,$ips_https,$ips_smtp,$ips_imap,$attacker_ips_namd,ips_ssh
24910
 
24911
		#函式說明:
24912
		#將多個一維陣列串聯起來,key從0開始排序.
24913
		#回傳的結果:
24914
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
24915
		#$result["error"],錯誤訊息陣列.
24916
		#$result["function"],當前執行的函式.
24917
		#$result["content"],合併好的一維陣列.
24918
		#必填參數:
24919
		#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
24920
		$conf["arrays::mergeArray"]["inputArray"]=array($ips,$ips_https,$ips_smtp,$attacker_ips_namd,$ips_imap,$ips_ssh);
24921
		#可省略參數:
24922
		#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
24923
		$conf["arrays::mergeArray"]["allowRepeat"]="false";
24924
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
24925
		unset($conf["arrays::mergeArray"]);
24926
 
24927
		#如果分割失敗
24928
		if($mergeArray["status"]==="false"){
24929
 
24930
			#設置執行失敗
24931
			$result["status"]="false";
24932
 
24933
			#設置錯誤訊息
24934
			$result["error"]=$mergeArray;
24935
 
24936
			#回傳結果
24937
			return $result;
24938
 
24939
			}#if end
24940
 
24941
		#取得不重複的IP
24942
		$ips=$mergeArray["content"];
24943
 
24944
		#取得防火牆的IP block清單
24945
		#cmd:firewall-cmd --list-rich-rule
24946
 
24947
		#函式說明:
24948
		#檢查指令的輸出是否含有關鍵字
24949
		#回傳結果:
24950
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24951
		#$result["error"],錯誤訊息.
24952
		#$result["function"],當前執行的函式名稱.
24953
		#$result["argu"],使用的參數.
24954
		#$result["grepCmd"],截取關鍵字的指令.
24955
		#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
24956
		#$result["content"],關鍵字所在列的輸出.
24957
		#必填參數:
24958
		#$conf["cmd"],字串,要執行的指令.
24959
		$conf["cmd::searchOutPut"]["cmd"]="firewall-cmd";
24960
		#$conf["keyWord"],字串,要檢查是否有關鍵字.
24961
		$conf["cmd::searchOutPut"]["keyWord"]=" reject";
24962
		#$conf["fileArgu"],字串,變數__FILE__的內容.
24963
		$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
24964
		#可省略參數:
24965
		#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
24966
		#$conf["binPath"]="";
24967
		#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
24968
		$conf["cmd::searchOutPut"]["argu"]=array("--list-rich-rule");
24969
		#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
24970
		#$conf["excludeGrep"]="false";
24971
 
24972
		#如果有設置 username
24973
		if(isset($conf["username"])){
24974
 
24975
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
24976
			$conf["cmd::searchOutPut"]["username"]=$conf["username"];
24977
 
24978
			}#if end
24979
 
24980
		#如果有設置 password
24981
		if(isset($conf["password"])){
24982
 
24983
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
24984
			$conf["cmd::searchOutPut"]["password"]=$conf["password"];
24985
 
24986
			}#if end
24987
 
24988
		$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
24989
		unset($conf["cmd::searchOutPut"]);
24990
 
24991
		#如果執行失敗
24992
		if($searchOutPut["status"]==="false"){
24993
 
24994
			#設置執行失敗
24995
			$result["status"]="false";
24996
 
24997
			#設置錯誤訊息
24998
			$result["error"]=$searchOutPut;
24999
 
25000
			#回傳結果
25001
			return $result;
25002
 
25003
			}#if end
25004
 
25005
		#初始化儲存已封鎖IP的陣列
25006
		$ips_blocked=array();	
25007
 
25008
		#如果有找到關鍵字 " reject"
25009
		if($searchOutPut["founded"]==="true"){
25010
 
25011
			#用 " 來分割每列字串
25012
			#函式說明:
25013
			#將多個固定格式的字串分開,並回傳分開的結果
25014
			#回傳的參數:
25015
			#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
25016
			#$result["error"],錯誤訊息陣列.
25017
			#$result["function"],當前執行的函式名稱.
25018
			#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
25019
			#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
25020
			#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
25021
			#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
25022
			#必填參數:
25023
			#$conf["stringIn"],字串陣列,要處理的字串陣列.
25024
			$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];
25025
			#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
25026
			$conf["stringProcess::spiltMutiString"]["spiltSymbol"]="\"";
25027
			$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
25028
			unset($conf["stringProcess::spiltMutiString"]);
25029
 
25030
			#如果分割失敗
25031
			if($spiltMutiString["status"]==="false"){
25032
 
25033
				#設置執行失敗
25034
				$result["status"]="false";
25035
 
25036
				#設置錯誤訊息
25037
				$result["error"]=$spiltMutiString;
25038
 
25039
				#回傳結果
25040
				return $result;
25041
 
25042
				}#if end
25043
 
25044
			#針對每行分割出來的內容
25045
			for($i=0;$i<$searchOutPut["count"];$i++){
25046
 
25047
				#如果不存在 IP
25048
				if(!isset($spiltMutiString["spiltString"][$i]["dataArray"][3])){
25049
 
25050
					#跳過
25051
					continue;
25052
 
25053
					}#if end
25054
 
25055
				#取得封鎖的IP位置
25056
				$ips_blocked[]=$spiltMutiString["spiltString"][$i]["dataArray"][3];
25057
 
25058
				}#for end
25059
 
25060
			}#if end
25061
 
25062
		#儲存有問題的IP資訊陣列
25063
		#$ips;	
25064
 
25065
		#儲存已封鎖IP的陣列
25066
		#$ips_blocked;
25067
 
25068
		#初始化要封鎖的ip資訊
25069
		$ips_to_block=array();
25070
 
25071
		#留下未阻擋的有問題IP
25072
 
25073
		#針對每個有問題的ip資訊
25074
		foreach($ips as $info){
25075
 
25076
			#函式說明:
25077
			#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
25078
			#回傳結果:
25079
			#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
25080
			#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
25081
			#$result["error"],錯誤訊息
25082
			#$result["function"],當前執行的函數名稱
25083
			#$result["argv"],使用的參數
25084
			#$result["equalVarName"],相等的變數名稱或key.
25085
			#$result["equalVarValue"],相等的變數數值內容.
25086
			#必填參數:
25087
			#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
25088
			$conf["search::getEqualVar"]["conditionElement"]=$info["ip"];
25089
			#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
25090
			$conf["search::getEqualVar"]["compareElements"]=$ips_blocked;
25091
			#可省略參數:
25092
			#無.
25093
			#參考資料:
25094
			#無.
25095
			#備註:
25096
			#無.
25097
			$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
25098
			unset($conf["search::getEqualVar"]);
25099
 
25100
			#如果執行失敗
25101
			if($getEqualVar["status"]==="false"){
25102
 
25103
				#設置執行失敗
25104
				$result["status"]="false";
25105
 
25106
				#設置錯誤訊息
25107
				$result["error"]=$getEqualVar;
25108
 
25109
				#回傳結果
25110
				return $result;
25111
 
25112
				}#if end
25113
 
25114
			#如果ip尚未被封鎖
25115
			if($getEqualVar["founded"]==="false"){
25116
 
25117
				#儲存要封鎖的ip資訊
25118
				$ips_to_block[]=$info;
25119
 
25120
				}#if end
25121
 
25122
			}#foreach end
25123
 
25124
		#如果沒有未阻擋的有問題 IP
25125
		if(count($ips_to_block)===0){
25126
 
25127
			#設置執行成功
25128
			$result["status"]="true";
25129
 
25130
			#回傳結果
25131
			return $result;
25132
 
25133
			}#if end
25134
 
25135
		#如果要阻擋IP
25136
		if($conf["getIplistOnly"]==="false"){
25137
 
25138
			#針對每個有問題的IP資訊
25139
			foreach($ips_to_block as $info){
25140
 
25141
				#檢查該ip是否在白名單裡面
25142
				#函式說明:
25143
				#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
25144
				#回傳結果:
25145
				#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
25146
				#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
25147
				#$result["error"],錯誤訊息
25148
				#$result["function"],當前執行的函數名稱
25149
				#$result["argv"],使用的參數
25150
				#$result["equalVarName"],相等的變數名稱或key.
25151
				#$result["equalVarValue"],相等的變數數值內容.
25152
				#必填參數:
25153
				$conf["search::getEqualVar"]["conditionElement"]=$info["ip"];#條件元素,要等於的元素內容.
25154
				$conf["search::getEqualVar"]["compareElements"]=$conf["excludeIp"];#要比對的陣列變數內容.
25155
				#可省略參數:
25156
				#無.
25157
				#備註:
25158
				#無.
25159
				$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
25160
				unset($conf["search::getEqualVar"]);
25161
 
25162
				#如果執行失敗
25163
				if($getEqualVar["status"]==="false")
25164
				{
25165
					#設置執行失敗
25166
					$result["status"]="false";
25167
 
25168
					#設置錯誤訊息
25169
					$result["error"]=$getEqualVar;
25170
 
25171
					#回傳結果
25172
					return $result;
25173
 
25174
				}#if end
25175
 
25176
				#如果在白名單ip裡面
25177
				if($getEqualVar["founded"]==="true")
25178
				{
25179
 
25180
					#跳過該ip
25181
					continue;
25182
 
25183
				}#if end
25184
 
25185
				#如果不是要動態阻擋
25186
				if($conf["dynamic"]==="false"){
25187
 
25188
					#函式說明:
25189
					#呼叫shell依序執行系統命令,並取得回傳的內容.
25190
					#回傳的結果:
25191
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25192
					#$result["error"],錯誤訊息陣列.
25193
					#$result["function"],當前執行的函式名稱.
25194
					#$result["cmd"],執行的指令內容.
25195
					#$result["output"],爲執行完每個指令後的輸出陣列.
25196
					#必填參數:
25197
					#$conf["command"],字串陣列,要執行的指令.
25198
					$conf["external::callShellMulti"]["command"]=array("echo");
25199
					#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
25200
					$conf["external::callShellMulti"]["fileArgu"]=$conf["fileArgu"];		
25201
					#可省略參數:
25202
					#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
25203
					$conf["external::callShellMulti"]["argu"]=array(array($info["ip"],"|","block_ip.sh"));
25204
					#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25205
					#$conf["enablePrintDescription"]=array("false");
25206
					#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25207
					#$conf["printDescription"]=array("");
25208
					#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25209
					$conf["external::callShellMulti"]["escapeshellarg"]=array("true");
25210
 
25211
					#如果有設置 username
25212
					if(isset($conf["username"])){
25213
 
25214
						#$conf["username"],陣列字串,每個指令要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
25215
						$conf["external::callShellMulti"]["username"]=array($conf["username"]);
25216
 
25217
						}#if end
25218
 
25219
					#如果有設置 password
25220
					if(isset($conf["password"])){
25221
 
25222
						#$conf["password"],陣列字串,每個指令與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
25223
						$conf["external::callShellMulti"]["password"]=array($conf["password"]);
25224
 
25225
						}#if end
25226
 
25227
					#$conf["useScript"],字串,每個指令的執行是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
25228
					#$conf["useScript"]="";
25229
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
25230
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
25231
					#$conf["inBackGround"],字串,每個指令的執行是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用";"區隔的多個指令將會出錯.
25232
					#$conf["inBackGround"]="";
25233
					#備註:
25234
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
25235
					#參考資料:
25236
					#exec=>http://php.net/manual/en/function.exec.php
25237
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
25238
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php	
25239
					$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);
25240
					unset($conf["external::callShellMulti"]);
25241
 
25242
					#如果執行失敗
25243
					if($callShellMulti["status"]==="false"){
25244
 
25245
						#設置執行失敗
25246
						$result["status"]="false";
25247
 
25248
						#設置錯誤訊息
25249
						$result["error"]=$callShellMulti;
25250
 
25251
						#回傳結果
25252
						return $result;
25253
 
25254
						}#if end
25255
 
25256
					}#if end
25257
 
25258
				#反之是要動態阻擋
25259
				else{
25260
 
25261
					#函式說明:
25262
					#呼叫shell依序執行系統命令,並取得回傳的內容.
25263
					#回傳的結果:
25264
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25265
					#$result["error"],錯誤訊息陣列.
25266
					#$result["function"],當前執行的函式名稱.
25267
					#$result["cmd"],執行的指令內容.
25268
					#$result["output"],爲執行完每個指令後的輸出陣列.
25269
					#必填參數:
25270
					#$conf["command"],字串陣列,要執行的指令.
25271
					$conf["external::callShellMulti"]["command"]=array("echo");
25272
					#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
25273
					$conf["external::callShellMulti"]["fileArgu"]=$conf["fileArgu"];		
25274
					#可省略參數:
25275
					#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
25276
					$conf["external::callShellMulti"]["argu"]=array(array($info["ip"],"|","block_ip_tmp.sh"));
25277
					#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25278
					#$conf["enablePrintDescription"]=array("false");
25279
					#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25280
					#$conf["printDescription"]=array("");
25281
					#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25282
					$conf["external::callShellMulti"]["escapeshellarg"]=array("true");
25283
 
25284
					#如果有設置 username
25285
					if(isset($conf["username"])){
25286
 
25287
						#$conf["username"],陣列字串,每個指令要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
25288
						$conf["external::callShellMulti"]["username"]=array($conf["username"]);
25289
 
25290
						}#if end
25291
 
25292
					#如果有設置 password
25293
					if(isset($conf["password"])){
25294
 
25295
						#$conf["password"],陣列字串,每個指令與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
25296
						$conf["external::callShellMulti"]["password"]=array($conf["password"]);
25297
 
25298
						}#if end
25299
 
25300
					#$conf["useScript"],字串,每個指令的執行是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
25301
					#$conf["useScript"]="";
25302
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
25303
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
25304
					#$conf["inBackGround"],字串,每個指令的執行是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用";"區隔的多個指令將會出錯.
25305
					#$conf["inBackGround"]="";
25306
					#備註:
25307
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
25308
					#參考資料:
25309
					#exec=>http://php.net/manual/en/function.exec.php
25310
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
25311
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php	
25312
					$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);
25313
					unset($conf["external::callShellMulti"]);
25314
 
25315
					}#else end
25316
 
25317
				#如果執行失敗
25318
				if($callShellMulti["status"]==="false"){
25319
 
25320
					#設置執行失敗
25321
					$result["status"]="false";
25322
 
25323
					#設置錯誤訊息
25324
					$result["error"]=$callShellMulti;
25325
 
25326
					#回傳結果
25327
					return $result;
25328
 
25329
					}#if end
25330
 
25331
				#取得每次執行的結果
25332
				$result["content"][]=$callShellMulti;
25333
 
25334
				#儲存特定ip被阻擋的資訊
25335
				$result["reason"][$info["ip"]]=$info;
25336
 
25337
				}#foreach end
25338
 
25339
			}#if end
25340
 
25341
		#反之
25342
		else{
25343
 
25344
			#取得有問題的IP資訊清單
25345
			$result["content"]=$ips_to_block;
25346
 
25347
			}#else end
25348
 
25349
		#設置執行正常
25350
		$result["status"]="true";
25351
 
25352
		#回傳結果
25353
		return $result;
25354
 
25355
		}#function blockAcctackIp end
25356
 
25357
	/*
25358
	#函式說明:
25359
	#執行 systemd 程序來管理服務.
25360
	#回傳結果:
25361
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25362
	#$result["error"],錯誤訊息.
25363
	#$result["function"],當前執行的函式名稱.
25364
	#$result["argu"],所使用的參數.
25365
	#$result["content"],執行的結果.
25366
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
25367
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
25368
	#必填參數:
25369
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
25370
	$conf["fileArgu"]=__FILE__;
25371
	#$conf["name"],字串,服務名稱.
25372
	$conf["name"]="";
25373
	#可省略參數:
25374
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
25375
	#$conf["operation"]="";
25376
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
25377
	#$conf["username"]="";
25378
	#$conf["password"],字串,使用者的密碼,預設不使用.
25379
	#$conf["password"]="";
25380
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
25381
	#$conf["daemonReload"]="true";
25382
	#參考資料:
25383
	#無.
25384
	#備註:
25385
	#無.
25386
	*/
25387
	public static function systemd(&$conf){
25388
 
25389
		#初始化要回傳的結果
25390
		$result=array();
25391
 
25392
		#取得當前執行的函式名稱
25393
		$result["function"]=__FUNCTION__;
25394
 
25395
		#取得參數
25396
		$result["argu"]=$conf;
25397
 
25398
		#如果 $conf 不為陣列
25399
		if(gettype($conf)!=="array"){
25400
 
25401
			#設置執行失敗
25402
			$result["status"]="false";
25403
 
25404
			#設置執行錯誤訊息
25405
			$result["error"][]="\$conf變數須為陣列形態";
25406
 
25407
			#如果傳入的參數為 null
25408
			if(is_null($conf)){
25409
 
25410
				#設置執行錯誤訊息
25411
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
25412
 
25413
				}#if end
25414
 
25415
			#回傳結果
25416
			return $result;
25417
 
25418
			}#if end
25419
 
25420
		#函式說明:
25421
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
25422
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25423
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
25424
		#$result["function"],當前執行的函式名稱.
25425
		#$result["argu"],設置給予的參數.
25426
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
25427
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
25428
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
25429
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
25430
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
25431
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
25432
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
25433
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
25434
		#必填寫的參數:
25435
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
25436
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
25437
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
25438
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
25439
		#可以省略的參數:
25440
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
25441
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name");
25442
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
25443
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
25444
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
25445
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
25446
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
25447
		#$conf["canNotBeEmpty"]=array();
25448
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
25449
		#$conf["canBeEmpty"]=array();
25450
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
25451
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath");
25452
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
25453
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("operation","username","password","daemonReload");
25454
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
25455
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
25456
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
25457
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("list","root",null,"false");
25458
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
25459
		#$conf["disallowAllSkipableVarIsEmpty"]="";
25460
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
25461
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
25462
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
25463
		#$conf["arrayCountEqualCheck"][]=array();
25464
		#參考資料來源:
25465
		#array_keys=>http://php.net/manual/en/function.array-keys.php
25466
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
25467
		unset($conf["variableCheck::checkArguments"]);
25468
 
25469
		#如果檢查參數失敗
25470
		if($checkArguments["status"]==="false"){
25471
 
25472
			#設置執行失敗
25473
			$result["status"]="false";
25474
 
25475
			#設置錯誤訊息
25476
			$result["error"]=$checkArguments;
25477
 
25478
			#回傳結果
25479
			return $result;
25480
 
25481
			}#if end
25482
 
25483
		#如果檢查參數失敗
25484
		if($checkArguments["passed"]==="false"){
25485
 
25486
			#設置執行失敗
25487
			$result["status"]="false";
25488
 
25489
			#設置錯誤訊息
25490
			$result["error"]=$checkArguments;
25491
 
25492
			#回傳結果
25493
			return $result;
25494
 
25495
			}#if end
25496
 
25497
		#如果要 reload daemon
25498
		if($conf["daemonReload"]==="true"){
25499
 
25500
			#函式說明:
25501
			#呼叫shell執行系統命令,並取得回傳的內容.
25502
			#回傳的結果:
25503
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25504
			#$result["error"],錯誤訊息陣列.
25505
			#$result["function"],當前執行的函式名稱.
25506
			#$result["argu"],使用的參數.
25507
			#$result["cmd"],執行的指令內容.
25508
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
25509
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
25510
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
25511
			#$result["running"],是否還在執行.
25512
			#$result["pid"],pid.
25513
			#$result["statusCode"],執行結束後的代碼.
25514
			#必填參數:
25515
			#$conf["command"],字串,要執行的指令與.
25516
			$conf["external::callShell"]["command"]="systemctl";
25517
			#$conf["fileArgu"],字串,變數__FILE__的內容.
25518
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
25519
			#可省略參數:
25520
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
25521
			$conf["external::callShell"]["argu"]=array("daemon-reload");
25522
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
25523
			#$conf["arguIsAddr"]=array();	
25524
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
25525
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
25526
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
25527
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
25528
			#$conf["enablePrintDescription"]="true";
25529
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
25530
			#$conf["printDescription"]="";
25531
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
25532
			$conf["external::callShell"]["escapeshellarg"]="true";
25533
 
25534
			#如果有設置 $conf["username"]
25535
			if(isset($conf["username"])){
25536
 
25537
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
25538
				$conf["external::callShell"]["username"]=$conf["username"];
25539
 
25540
				}#if end		
25541
 
25542
			#如果有設置 $conf["password"]
25543
			if(isset($conf["password"])){
25544
 
25545
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
25546
				$conf["external::callShell"]["password"]=$conf["password"];
25547
 
25548
				}#if end
25549
 
25550
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
25551
			#$conf["useScript"]="";
25552
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
25553
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
25554
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
25555
			#$conf["inBackGround"]="";
25556
			#備註:
25557
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
25558
			#參考資料:
25559
			#exec=>http://php.net/manual/en/function.exec.php
25560
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
25561
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
25562
			$callShell=external::callShell($conf["external::callShell"]);
25563
			unset($conf["external::callShell"]);
25564
 
25565
			#如果運行失敗
25566
			if($callShell["status"]==="false"){
25567
 
25568
				#設置執行失敗
25569
				$result["status"]="false";
25570
 
25571
				#設置錯誤訊息
25572
				$result["error"]=$callShell;
25573
 
25574
				#回傳結果
25575
				return $result;
25576
 
25577
 
25578
				}#if end
25579
 
25580
			#取得運行結果
25581
			$result["content"]=$callShell["output"];
25582
 
25583
			#設置執行成功
25584
			$result["status"]="true";
25585
 
25586
			#回傳結果
25587
			return $result;
25588
 
25589
			}#if end
25590
 
25591
		#判斷 $conf["operation"]
25592
		switch($conf["operation"]){
25593
 
25594
			#如果是 list
25595
			case "list":
25596
 
25597
				#函式說明:
25598
				#呼叫shell執行系統命令,並取得回傳的內容.
25599
				#回傳的結果:
25600
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25601
				#$result["error"],錯誤訊息陣列.
25602
				#$result["function"],當前執行的函式名稱.
25603
				#$result["argu"],使用的參數.
25604
				#$result["cmd"],執行的指令內容.
25605
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
25606
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
25607
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
25608
				#$result["running"],是否還在執行.
25609
				#$result["pid"],pid.
25610
				#$result["statusCode"],執行結束後的代碼.
25611
				#必填參數:
25612
				#$conf["command"],字串,要執行的指令與.
25613
				$conf["external::callShell"]["command"]="systemctl";
25614
				#$conf["fileArgu"],字串,變數__FILE__的內容.
25615
				$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
25616
				#可省略參數:
25617
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
25618
				#$conf["external::callShell"]["argu"]=array("2>&1");
25619
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
25620
				#$conf["arguIsAddr"]=array();	
25621
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
25622
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
25623
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
25624
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
25625
				#$conf["enablePrintDescription"]="true";
25626
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
25627
				#$conf["printDescription"]="";
25628
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
25629
				$conf["external::callShell"]["escapeshellarg"]="true";
25630
 
25631
				#如果有設置 $conf["username"]
25632
				if(isset($conf["username"])){
25633
 
25634
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
25635
					$conf["external::callShell"]["username"]=$conf["username"];
25636
 
25637
					}#if end		
25638
 
25639
				#如果有設置 $conf["password"]
25640
				if(isset($conf["password"])){
25641
 
25642
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
25643
					$conf["external::callShell"]["password"]=$conf["password"];
25644
 
25645
					}#if end
25646
 
25647
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
25648
				#$conf["useScript"]="";
25649
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
25650
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
25651
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
25652
				#$conf["inBackGround"]="";
25653
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
25654
				$conf["external::callShell"]["getErr"]="true";
25655
				#備註:
25656
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
25657
				#參考資料:
25658
				#exec=>http://php.net/manual/en/function.exec.php
25659
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
25660
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
25661
				$callShell=external::callShell($conf["external::callShell"]);
25662
				unset($conf["external::callShell"]);
25663
 
25664
				#如果運行失敗
25665
				if($callShell["status"]==="false"){
25666
 
25667
					#設置執行失敗
25668
					$result["status"]="false";
25669
 
25670
					#設置錯誤訊息
25671
					$result["error"]=$callShell;
25672
 
25673
					#回傳結果
25674
					return $result;
25675
 
25676
 
25677
					}#if end
25678
 
25679
				#取得運行結果
25680
				$result["content"]=$callShell["output"];
25681
 
25682
				#設置執行成功
25683
				$result["status"]="true";
25684
 
25685
				#回傳結果
25686
				return $result;
25687
 
25688
				#跳出 switch
25689
				break;
25690
 
25691
			#其他操作
25692
			case "enable":
25693
			case "disable":
25694
			case "start":
25695
			case "stop":
25696
			case "restart":
25697
			case "status":
25698
 
25699
				#函式說明:
25700
				#呼叫shell執行系統命令,並取得回傳的內容.
25701
				#回傳的結果:
25702
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25703
				#$result["error"],錯誤訊息陣列.
25704
				#$result["function"],當前執行的函式名稱.
25705
				#$result["argu"],使用的參數.
25706
				#$result["cmd"],執行的指令內容.
25707
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
25708
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
25709
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
25710
				#$result["running"],是否還在執行.
25711
				#$result["pid"],pid.
25712
				#$result["statusCode"],執行結束後的代碼.
25713
				#必填參數:
25714
				#$conf["command"],字串,要執行的指令與.
25715
				$conf["external::callShell"]["command"]="systemctl";
25716
				#$conf["fileArgu"],字串,變數__FILE__的內容.
25717
				$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
25718
				#可省略參數:
25719
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
25720
				$conf["external::callShell"]["argu"]=array($conf["operation"],$conf["name"]);
25721
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
25722
				#$conf["arguIsAddr"]=array();	
25723
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
25724
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
25725
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
25726
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
25727
				#$conf["enablePrintDescription"]="true";
25728
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
25729
				#$conf["printDescription"]="";
25730
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
25731
				$conf["external::callShell"]["escapeshellarg"]="true";
25732
 
25733
				#如果有設置 $conf["username"]
25734
				if(isset($conf["username"])){
25735
 
25736
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
25737
					$conf["external::callShell"]["username"]=$conf["username"];
25738
 
25739
					}#if end
25740
 
25741
				#如果有設置 $conf["password"]
25742
				if(isset($conf["password"])){
25743
 
25744
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
25745
					$conf["external::callShell"]["password"]=$conf["password"];
25746
 
25747
					}#if end
25748
 
25749
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
25750
				#$conf["useScript"]="";
25751
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
25752
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
25753
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
25754
				#$conf["inBackGround"]="";
25755
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
25756
				$conf["external::callShell"]["getErr"]="true";
25757
				#備註:
25758
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
25759
				#參考資料:
25760
				#exec=>http://php.net/manual/en/function.exec.php
25761
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
25762
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
25763
				$callShell=external::callShell($conf["external::callShell"]);
25764
				unset($conf["external::callShell"]);
25765
 
25766
				#如果運行失敗
25767
				if($callShell["status"]==="false"){
25768
 
25769
					if($callShell["statusCode"]!==1 && $callShell["statusCode"]!==3){
25770
 
25771
						#設置執行失敗
25772
						$result["status"]="false";
25773
 
25774
						#設置錯誤訊息
25775
						$result["error"]=$callShell;
25776
 
25777
						#回傳結果
25778
						return $result;
25779
 
25780
						}#if end
25781
 
25782
					}#if end
25783
 
25784
				#取得運行結果
25785
				$result["content"]=$callShell["output"];
25786
 
25787
				#如果運作參數是 "status" 
25788
				if($conf["operation"]==="status"){
25789
 
25790
					#"Active: inactive (dead)"
25791
					#"Active: active (running)"
25792
					#"Active: failed"
25793
					#"service; enabled; "
25794
					#"service; disabled; "
25795
					#函式說明:
25796
					#檢查多個字串中的每個字串是否有多個關鍵字
25797
					#回傳的結果:
25798
					#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
25799
					#$result["function"],當前執行的函式名稱.
25800
					#$result["error"],錯誤訊息.
25801
					#$result["foundedTrueKey"],結果為"true"的元素key陣列。
25802
					#$result["foundedTrueKeyWords"],有找到的關鍵字陣列.
25803
					#$result["foundedFalseKey"],結果為"false"的元素key陣列。
25804
					#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
25805
					#必填參數:
25806
					$keyWordToFind=$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("Active: inactive (dead)","Active: active (running)","service; enabled;","service; disabled;","Active: failed","Active: deactivating");#想要搜尋的關鍵字
25807
					$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$result["content"];#要被搜尋的字串內容陣列
25808
					#可省略參數:
25809
					#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
25810
					$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
25811
					unset($conf["search::findManyKeyWordsFromManyString"]);
25812
 
25813
					#如果執行失敗
25814
					if($findManyKeyWordsFromManyString["status"]==="false"){
25815
 
25816
						#設置執行失敗
25817
						$result["status"]="false";
25818
 
25819
						#設置錯誤訊息
25820
						$result["error"]=$findManyKeyWordsFromManyString;
25821
 
25822
						#回傳結果
25823
						return $result;
25824
 
25825
						}#if end
25826
 
25827
					#服務狀態的計數
25828
					$serverStaCount=count($findManyKeyWordsFromManyString["foundedTrueKey"]);
25829
 
25830
					#如果沒有剛好取得服務的兩個狀態
25831
					if($serverStaCount!==2){
25832
 
25833
						#設置執行失敗
25834
						$result["status"]="false";
25835
 
25836
						#提示錯誤
25837
						$result["error"][]="取得啟動狀態與啟用狀態失敗";
25838
 
25839
						#設置錯誤訊息
25840
						$result["error"][]=$findManyKeyWordsFromManyString;
25841
 
25842
						#回傳結果
25843
						return $result;
25844
 
25845
						}#if end
25846
 
25847
					#針對每個服務狀態
25848
					foreach($findManyKeyWordsFromManyString["foundedKeyWords"] as $statusDesc){
25849
 
25850
						#判斷服務狀態
25851
						switch($statusDesc){
25852
 
25853
							#未啟動
25854
							case "Active: inactive (dead)":
25855
							case "Active: failed":
25856
							case "Active: deactivating":
25857
 
25858
								#設置未啟動的識別
25859
								$result["content"]["srerviceInfo"]["on"]="false";
25860
 
25861
								#跳出 switch
25862
								break;
25863
 
25864
							#啟動
25865
							case "Active: active (running)":
25866
 
25867
								#設置啟動的識別
25868
								$result["content"]["srerviceInfo"]["on"]="true";
25869
 
75 liveuser 25870
								#跳出 switch
3 liveuser 25871
								break;
25872
 
75 liveuser 25873
							#啟用,開機自動啟動
3 liveuser 25874
							case "service; enabled;":
25875
 
25876
								#設置啟動的識別
25877
								$result["content"]["srerviceInfo"]["auto"]="true";
25878
 
25879
								#跳出 switch
25880
								break;
25881
 
25882
							#未啟用,開機不啟動
25883
							case "service; disabled;":
25884
 
25885
								#設置啟動的識別
25886
								$result["content"]["srerviceInfo"]["auto"]="false";
25887
 
25888
								#跳出 switch
25889
								break;
25890
 
25891
							#無法判斷的服務狀態
25892
							default:
25893
 
25894
								#設置執行失敗
25895
								$result["status"]="false";
25896
 
25897
								#提示錯誤
25898
								$result["error"][]="無法識別的內容「".$statusDesc."」";
25899
 
25900
								#設置錯誤訊息
25901
								$result["error"][]=$findManyKeyWordsFromManyString;
25902
 
25903
								#回傳結果
25904
								return $result;
25905
 
75 liveuser 25906
							}#switch end
3 liveuser 25907
 
25908
						}#for end
25909
 
25910
					}#if end
25911
 
25912
				#設置執行成功
25913
				$result["status"]="true";
25914
 
25915
				#回傳結果
25916
				return $result;
25917
 
25918
				#跳出 switch
25919
				break;
25920
 
25921
			#不允許的操作
25922
			default :
25923
 
25924
				#設置執行失敗識別
25925
				$result["status"]="false";
25926
 
25927
				#設置錯誤訊息
25928
				$result["error"][]="operatio \"".$conf["operation"]."\" is not allowed.";
25929
 
25930
				#回傳結果
25931
				return $result;
25932
 
25933
			}#switch end
25934
 
25935
		}#function systemd end
25936
 
25937
	/*
25938
	#函式說明:
25939
	#執行 systemd 程序來確保服務是運行中.
25940
	#回傳結果:
25941
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25942
	#$result["error"],錯誤訊息.
25943
	#$result["function"],當前執行的函式名稱.
25944
	#$result["argu"],所使用的參數.
25945
	#$result["content"],執行的結果.
25946
	#必填參數:
25947
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
25948
	$conf["fileArgu"]=__FILE__;
25949
	#$conf["name"],字串,服務名稱.
25950
	$conf["name"]="";
25951
	#可省略參數:
25952
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
25953
	#$conf["username"]="";
25954
	#$conf["password"],字串,使用者的密碼,預設不使用.
25955
	#$conf["password"]="";
25956
	#$conf["checkListen"],陣列,用來判斷服務是否有正確啟動的條件,一個元素代表,其中要有一個socket info符合之,若元素的key為"ip",則其數值為[ipv4/ipv6]:port:protocol(tcp/udp);若元素的key為"addr",則其數值為unix domain socket 的位置與名稱;若元素的key為"name",則其數值為程序名稱.
25957
	#$conf["checkListen"]=array(array("ip"=>169.254.1.1:443/tcp,"addr"=>/usr/lib/qbpwcf/qbpwcf-usock.sock,"name"=>"addr"),"name"=>"httpd");
25958
	#$conf["interval"],字串,檢查沒問題後,要多少秒後再檢查一次,預設為30秒,亦即"30".
25959
	#$conf["interval"]="30";
25960
	#$conf["reportOnly"],字串,"true"代表不「啟動/重新啟動」服務,只是輸出訊息表示服務有正常或需要處理;預設為"false"代表直接「啟動/重新啟動」.
25961
	#$conf["reportOnly"]="true";
25962
	#$conf["verbose"],字串,預設為"false",若為"true"則會印出過程訊息.
25963
	#$conf["verbose"]="true";
25964
	#$conf["onlyWhenEnable"],字串,預設為"true",代表若服務為enable才會將其變成運行中;反之為"false".
25965
	#$conf["onlyWhenEnable"]="false";
25966
	#參考資料:
25967
	#無.
25968
	#備註:
25969
	#無.
25970
	*/
25971
	public static function keepServiceUp(&$conf){
25972
 
25973
		#初始化要回傳的結果
25974
		$result=array();
25975
 
25976
		#取得當前執行的函式名稱
25977
		$result["function"]=__FUNCTION__;
25978
 
25979
		#取得參數
25980
		$result["argu"]=$conf;
25981
 
25982
		#如果 $conf 不為陣列
25983
		if(gettype($conf)!=="array"){
25984
 
25985
			#設置執行失敗
25986
			$result["status"]="false";
25987
 
25988
			#設置執行錯誤訊息
25989
			$result["error"][]="\$conf變數須為陣列形態";
25990
 
25991
			#如果傳入的參數為 null
25992
			if(is_null($conf)){
25993
 
25994
				#設置執行錯誤訊息
25995
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
25996
 
25997
				}#if end
25998
 
25999
			#回傳結果
26000
			return $result;
26001
 
26002
			}#if end
26003
 
26004
		#函式說明:
26005
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
26006
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26007
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
26008
		#$result["function"],當前執行的函式名稱.
26009
		#$result["argu"],設置給予的參數.
26010
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
26011
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
26012
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
26013
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
26014
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
26015
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
26016
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
26017
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
26018
		#必填寫的參數:
26019
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
26020
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
26021
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
26022
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
26023
		#可以省略的參數:
26024
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
26025
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name");
26026
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
26027
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
26028
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
26029
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
26030
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
26031
		#$conf["canNotBeEmpty"]=array();
26032
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
26033
		#$conf["canBeEmpty"]=array();
26034
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
26035
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath");
26036
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
26037
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","checkListen","interval","reportOnly","verbose","onlyWhenEnable");
26038
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
26039
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","string","string","string","string");
26040
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
26041
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("root",null,null,"30","false","false","true");
26042
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
26043
		#$conf["disallowAllSkipableVarIsEmpty"]="";
26044
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
26045
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
26046
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
26047
		#$conf["arrayCountEqualCheck"][]=array();
26048
		#參考資料來源:
26049
		#array_keys=>http://php.net/manual/en/function.array-keys.php
26050
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
26051
		unset($conf["variableCheck::checkArguments"]);
26052
 
26053
		#如果檢查參數失敗
26054
		if($checkArguments["status"]==="false"){
26055
 
26056
			#設置執行失敗
26057
			$result["status"]="false";
26058
 
26059
			#設置錯誤訊息
26060
			$result["error"]=$checkArguments;
26061
 
26062
			#回傳結果
26063
			return $result;
26064
 
26065
			}#if end
26066
 
26067
		#如果檢查參數失敗
26068
		if($checkArguments["passed"]==="false"){
26069
 
26070
			#設置執行失敗
26071
			$result["status"]="false";
26072
 
26073
			#設置錯誤訊息
26074
			$result["error"]=$checkArguments;
26075
 
26076
			#回傳結果
26077
			return $result;
26078
 
26079
			}#if end
26080
 
26081
		#無窮迴圈
26082
		while(true){
26083
 
26084
			#如果有啟用 verbose
26085
			if($conf["verbose"]==="true"){
26086
 
26087
				#提示正在檢查
26088
				echo "start checking...".PHP_EOL;
26089
 
26090
				}#if end
26091
 
26092
			#查詢服務啟動沒
26093
			#函式說明:
26094
			#執行 systemd 程序來管理服務.
26095
			#回傳結果:
26096
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26097
			#$result["error"],錯誤訊息.
26098
			#$result["function"],當前執行的函式名稱.
26099
			#$result["argu"],所使用的參數.
26100
			#$result["content"],執行的結果.
26101
			#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
26102
			#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
26103
			#必填參數:
26104
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
26105
			$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
26106
			#$conf["name"],字串,服務名稱.
26107
			$conf["cmd::systemd"]["name"]=$conf["name"];
26108
			#可省略參數:
26109
			#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
26110
			$conf["cmd::systemd"]["operation"]="status";
26111
			#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
26112
			#$conf["cmd::systemd"]["username"]="";
26113
 
26114
			#如果有設定密碼
26115
			if(isset($conf["password"])){
26116
 
26117
				#$conf["password"],字串,使用者的密碼,預設不使用.
26118
				$conf["cmd::systemd"]["password"]=$conf["password"];
26119
 
26120
				}#if end
26121
 
26122
			$systemd=cmd::systemd($conf["cmd::systemd"]);
26123
			unset($conf["cmd::systemd"]);
26124
 
26125
			#若運行出錯
26126
			if($systemd["status"]==="false"){
26127
 
26128
				#設置執行失敗
26129
				$result["status"]="false";
26130
 
26131
				#設置錯誤訊息
26132
				$result["error"]=$systemd;
26133
 
26134
				#回傳結果
26135
				return $result;
26136
 
26137
				}#if end
26138
 
26139
			#如果只處理有設置enable的服務
26140
			if($conf["onlyWhenEnable"]==="true"){
26141
 
26142
				#如果服務沒有 enable
26143
				if($systemd["content"]["srerviceInfo"]["auto"]==="false"){
26144
 
26145
					#過30秒再檢查一次
26146
					sleep($conf["interval"]);
26147
 
26148
					#下一輪
26149
					continue;
26150
 
26151
					}#if end
26152
 
26153
				}#if end
26154
 
26155
			#如果服務沒啟動
26156
			if($systemd["content"]["srerviceInfo"]["on"]==="false"){
26157
 
26158
				#如果 verbose 為 "true"
26159
				if($conf["verbose"]==="true"){
26160
 
26161
					#印出提示
26162
					echo "service ".$conf["name"]." down.".PHP_EOL;
26163
 
26164
					}#if end
26165
 
26166
				#如果只要 Report
26167
				if($conf["reportOnly"]==="true"){
26168
 
26169
					#輸出
26170
					echo "service ".$conf["name"]." need to start!";
26171
 
26172
					#下一輪
26173
					continue;
26174
 
26175
					}#if end
26176
 
26177
				#啟動服務
26178
				#函式說明:
26179
				#執行 systemd 程序來管理服務.
26180
				#回傳結果:
26181
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26182
				#$result["error"],錯誤訊息.
26183
				#$result["function"],當前執行的函式名稱.
26184
				#$result["argu"],所使用的參數.
26185
				#$result["content"],執行的結果.
26186
				#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
26187
				#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
26188
				#必填參數:
26189
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
26190
				$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
26191
				#$conf["name"],字串,服務名稱.
26192
				$conf["cmd::systemd"]["name"]=$conf["name"];
26193
				#可省略參數:
26194
				#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
26195
				$conf["cmd::systemd"]["operation"]="start";
26196
				#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
26197
				#$conf["username"]="";
26198
				#$conf["password"],字串,使用者的密碼,預設不使用.
26199
				#$conf["password"]="";
26200
				$systemd=cmd::systemd($conf["cmd::systemd"]);
26201
				unset($conf["cmd::systemd"]);
26202
 
26203
				#若運行出錯
26204
				if($systemd["status"]==="false"){
26205
 
26206
					#設置執行失敗
26207
					$result["status"]="false";
26208
 
26209
					#設置錯誤訊息
26210
					$result["error"]=$systemd;
26211
 
26212
					#回傳結果
26213
					return $result;
26214
 
26215
					}#if end
26216
 
26217
				#如果 verbose 為 "true"
26218
				if($conf["verbose"]==="true"){
26219
 
26220
					#印出提示
26221
					echo "service ".$conf["name"]." started.".PHP_EOL;
26222
 
26223
					}#if end
26224
 
26225
				#下一輪
26226
				continue;
26227
 
26228
				}#if end
26229
 
26230
			#如果有啟用 verbose
26231
			if($conf["verbose"]==="true"){
26232
 
26233
				#提示正在檢查
26234
				echo "service seems up.".PHP_EOL;
26235
 
26236
				}#if end
26237
 
26238
			#如果有指定 checkListen陣列
26239
			if(isset($conf["checkListen"])){
26240
 
26241
				#如果有指定 socket info 的條件
26242
				if(count($conf["checkListen"])>0){
26243
 
26244
					#如果有啟用 verbose
26245
					if($conf["verbose"]==="true"){
26246
 
26247
						#提示正在檢查
26248
						echo "need check socket info.".PHP_EOL;
26249
 
26250
						}#if end
26251
 
26252
					#針對每個 socket 的 infos
26253
					foreach($conf["checkListen"] as $checkListen){
26254
 
26255
						#如果有啟用 verbose
26256
						if($conf["verbose"]==="true"){
26257
 
26258
							#提示正在檢查
26259
							echo "parse socket condition...".PHP_EOL;
26260
 
26261
							}#if end
26262
 
26263
						#函式說明:
26264
						#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
26265
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26266
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
26267
						#$result["function"],當前執行的函式名稱.
26268
						#$result["argu"],設置給予的參數.
26269
						#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
26270
						#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
26271
						#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
26272
						#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
26273
						#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
26274
						#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
26275
						#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
26276
						#$result["notNeedVar"],字串陣列,多餘的參數名稱.
26277
						#必填寫的參數:
26278
						#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
26279
						$conf["variableCheck::checkArguments"]["varInput"]=&$checkListen;
26280
						#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
26281
						$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
26282
						#可以省略的參數:
26283
						#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
26284
						#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name");
26285
						#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
26286
						#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
26287
						#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
26288
						#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
26289
						#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
26290
						#$conf["canNotBeEmpty"]=array();
26291
						#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
26292
						#$conf["canBeEmpty"]=array();
26293
						#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
26294
						$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("ip","addr","name");
26295
						#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
26296
						$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("ip","addr","name");
26297
						#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
26298
						$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
26299
						#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
26300
						$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null);
26301
						#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
26302
						$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
26303
						#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
26304
						$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";
26305
						#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
26306
						#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
26307
						#參考資料來源:
26308
						#array_keys=>http://php.net/manual/en/function.array-keys.php
26309
						$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
26310
						unset($conf["variableCheck::checkArguments"]);
26311
 
26312
						#如果檢查參數失敗
26313
						if($checkArguments["status"]==="false"){
26314
 
26315
							#設置執行失敗
26316
							$result["status"]="false";
26317
 
26318
							#設置錯誤訊息
26319
							$result["error"]=$checkArguments;
26320
 
26321
							#回傳結果
26322
							return $result;
26323
 
26324
							}#if end
26325
 
26326
						#如果檢查參數失敗
26327
						if($checkArguments["passed"]==="false"){
26328
 
26329
							#設置執行失敗
26330
							$result["status"]="false";
26331
 
26332
							#設置錯誤訊息
26333
							$result["error"]=$checkArguments;
26334
 
26335
							#回傳結果
26336
							return $result;
26337
 
26338
							}#if end
26339
 
26340
						#debug
26341
						#echo "check arguments ok!".PHP_EOL;
26342
 
26343
						#初始化找到的 socket 資訊
26344
						$foundSocketInfo=array();
26345
 
26346
						#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
26347
						#回傳結果:
26348
						#$result["status"],"true"代表執行正常;"false"代表執行不正常.
26349
						#$result["error"],錯誤訊息陣列.
26350
						#$result["function"],當前執行的函式名稱.
26351
						#$result["argu"],使用的參數.
26352
						#必填參數:
26353
						#$conf["fileArgu"],字串,變數__FILE__的內容.
26354
						$conf["sock::execAnyCmdbyQBPWCFunixSocket"]["fileArgu"]=$conf["fileArgu"];
26355
						#$conf["command"],字串,要執行的指令名稱.
26356
						$conf["sock::execAnyCmdbyQBPWCFunixSocket"]["command"]="ss";
26357
						#可省略參數:
26358
						#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
26359
						#$conf["sock"]=qbpwcf_usock_path;
26360
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
26361
						$conf["sock::execAnyCmdbyQBPWCFunixSocket"]["argu"]=array("-n","-p","-O","-l");
26362
						#參考資料:
26363
						#無.
26364
						#備註:
26365
						#無.
26366
						$execAnyCmdbyQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdbyQBPWCFunixSocket"]);
26367
						unset($conf["sock::execAnyCmdbyQBPWCFunixSocket"]);
26368
 
26369
						#如果執行失敗
26370
						if($execAnyCmdbyQBPWCFunixSocket["status"]==="false"){
26371
 
26372
							#設置執行失敗
26373
							$result["status"]="false";
26374
 
26375
							#設置錯誤訊息
26376
							$result["error"]=$execAnyCmdbyQBPWCFunixSocket;
26377
 
26378
							#回傳結果
26379
							return $result;
26380
 
26381
							}#if end
26382
 
26383
						#debug
26384
						#var_dump($execAnyCmdbyQBPWCFunixSocket["content"]);	
26385
 
26386
						#函式說明:
26387
						#解析 ss 指令的輸出
26388
						#回傳結果:
26389
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26390
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
26391
						#$result["function"],當前執行的函式名稱.
26392
						#$result["argu"],使用的參數.
26393
						#$result["columns"],解析好的欄位名稱陣列.
26394
						#$result["content"],解析好的內容陣列.
26395
						#必填參數:
26396
						#$conf["input"],字串陣列,要解析的內容,包含header.
26397
						$conf["parser::ss"]["input"]=$execAnyCmdbyQBPWCFunixSocket["content"];
26398
						#可省略參數:
26399
						#無.
26400
						#參考資料:
26401
						#無.
26402
						#備註:
26403
						#無.
26404
						$ss=parser::ss($conf["parser::ss"]);
26405
						unset($conf["parser::ss"]);
26406
 
26407
						#如果執行失敗
26408
						if($ss["status"]==="false"){
26409
 
26410
							#設置執行失敗
26411
							$result["status"]="false";
26412
 
26413
							#設置錯誤訊息
26414
							$result["error"]=$ss;
26415
 
26416
							#回傳結果
26417
							return $result;
26418
 
26419
							}#if end
26420
 
26421
						#debug
26422
						#var_dump($ss);	
26423
 
26424
						#如果沒有 Netid 欄位
26425
						if(!isset($ss["content"]["Netid"])){
26426
 
26427
							#設置執行失敗
26428
							$result["status"]="false";
26429
 
26430
							#設置錯誤訊息
26431
							$result["error"][]="Netid column data not found";
26432
 
26433
							#設置錯誤訊息
26434
							$result["error"][]=$ss;
26435
 
26436
							#回傳結果
26437
							return $result;
26438
 
26439
							}#if end
26440
 
26441
						#如果有ip條件
26442
						if(isset($checkListen["ip"])){
26443
 
26444
							#取得ip條件
26445
							$listenInfo=$checkListen["ip"];
26446
 
26447
							#函式說明:
26448
							#將固定格式的字串分開,並回傳分開的結果.
26449
							#回傳結果:
26450
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26451
							#$result["error"],錯誤訊息陣列
26452
							#$result["function"],當前執行的函數名稱.
26453
							#$result["argu"],使用的參數.
26454
							#$result["oriStr"],要分割的原始字串內容
26455
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
26456
							#$result["dataCounts"],爲總共分成幾段
26457
							#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
26458
							#必填參數:
26459
							#$conf["stringIn"],字串,要處理的字串.
26460
							$conf["stringProcess::spiltString"]["stringIn"]=$listenInfo;
26461
							#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
26462
							$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
26463
							#可省略參數:
26464
							#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
26465
							$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
26466
							#參考資料:
26467
							#無.
26468
							#備註:
26469
							#無.
26470
							$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
26471
							unset($conf["stringProcess::spiltString"]);
26472
 
26473
							#如果執行失敗
26474
							if($spiltString["status"]==="false"){
26475
 
26476
								#設置執行失敗
26477
								$result["status"]="false";
26478
 
26479
								#設置錯誤訊息
26480
								$result["error"]=$spiltString;
26481
 
26482
								#回傳結果
26483
								return $result;
26484
 
26485
								}#if end
26486
 
26487
							#如果沒有分割用的關鍵字
26488
							if($spiltString["found"]==="false"){
26489
 
26490
								#設置執行失敗
26491
								$result["status"]="false";
26492
 
26493
								#設置錯誤訊息
26494
								$result["error"]=$spiltString;
26495
 
26496
								#回傳結果
26497
								return $result;
26498
 
26499
								}#if end
26500
 
26501
							#如果沒有切成兩段	
26502
							if($spiltString["dataCounts"]!==2){
26503
 
26504
								#設置執行失敗
26505
								$result["status"]="false";
26506
 
26507
								#設置錯誤訊息
26508
								$result["error"]=$spiltString;
26509
 
26510
								#回傳結果
26511
								return $result;
26512
 
26513
								}#if end
26514
 
26515
							#取得 listen ip
26516
							$ip=$spiltString["dataArray"][0];
26517
 
26518
							#函式說明:
26519
							#將固定格式的字串分開,並回傳分開的結果.
26520
							#回傳結果:
26521
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26522
							#$result["error"],錯誤訊息陣列
26523
							#$result["function"],當前執行的函數名稱.
26524
							#$result["argu"],使用的參數.
26525
							#$result["oriStr"],要分割的原始字串內容
26526
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
26527
							#$result["dataCounts"],爲總共分成幾段
26528
							#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
26529
							#必填參數:
26530
							#$conf["stringIn"],字串,要處理的字串.
26531
							$conf["stringProcess::spiltString"]["stringIn"]=$spiltString["dataArray"][1];
26532
							#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
26533
							$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
26534
							#可省略參數:
26535
							#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
26536
							$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
26537
							#參考資料:
26538
							#無.
26539
							#備註:
26540
							#無.
26541
							$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
26542
							unset($conf["stringProcess::spiltString"]);
26543
 
26544
							#如果執行失敗
26545
							if($spiltString["status"]==="false"){
26546
 
26547
								#設置執行失敗
26548
								$result["status"]="false";
26549
 
26550
								#設置錯誤訊息
26551
								$result["error"]=$spiltString;
26552
 
26553
								#回傳結果
26554
								return $result;
26555
 
26556
								}#if end
26557
 
26558
							#如果沒有分割用的關鍵字
26559
							if($spiltString["found"]==="false"){
26560
 
26561
								#設置執行失敗
26562
								$result["status"]="false";
26563
 
26564
								#設置錯誤訊息
26565
								$result["error"]=$spiltString;
26566
 
26567
								#回傳結果
26568
								return $result;
26569
 
26570
								}#if end
26571
 
26572
							#如果沒有切成兩段	
26573
							if($spiltString["dataCounts"]!==2){
26574
 
26575
								#設置執行失敗
26576
								$result["status"]="false";
26577
 
26578
								#設置錯誤訊息
26579
								$result["error"]=$spiltString;
26580
 
26581
								#回傳結果
26582
								return $result;
26583
 
26584
								}#if end
26585
 
26586
							#取得 listen port
26587
							$port=$spiltString["dataArray"][0];
26588
 
26589
							#取得 listen protocol
26590
							$protocol=$spiltString["dataArray"][1];
26591
 
26592
							#如果 verbose 為 "true"
26593
							if($conf["verbose"]==="true"){
26594
 
26595
								#印出提示
26596
								echo "check ip=".$ip." of service ".$conf["name"].PHP_EOL;
26597
 
26598
								#印出提示
26599
								echo "check port=".$port." of service ".$conf["name"].PHP_EOL;
26600
 
26601
								#印出提示
26602
								echo "check protocol=".$protocol." of service ".$conf["name"].PHP_EOL;
26603
 
26604
								}#if end
26605
 
26606
							#如果 protocol 不是 tcp 也不是 udp
26607
							if($protocol!=="tcp" && $protocol!=="udp"){
26608
 
26609
								#設置執行失敗
26610
								$result["status"]="false";
26611
 
26612
								#設置錯誤訊息
26613
								$result["error"][]="protocol should be tcp or udp";
26614
 
26615
								#設置錯誤訊息
26616
								$result["error"][]=$spiltString;
26617
 
26618
								#回傳結果
26619
								return $result;
26620
 
26621
								}#if end
26622
 
26623
							#如果沒有 "Local Address:Port" 欄位
26624
							if(!isset($ss["content"]["Local Address:Port"])){
26625
 
26626
								#設置執行失敗
26627
								$result["status"]="false";
26628
 
26629
								#設置錯誤訊息
26630
								$result["error"][]="Local Address:Port column data not found";
26631
 
26632
								#設置錯誤訊息
26633
								$result["error"][]=$ss;
26634
 
26635
								#回傳結果
26636
								return $result;
26637
 
26638
								}#if end
26639
 
26640
							#預設沒有通過檢查
26641
							$pass="false";
26642
 
26643
							#要搜尋的ip
26644
							$ips=array();
26645
 
26646
							#要搜尋的ip關鍵字
26647
							$ips[]=$ip;
26648
 
26649
							#如果不是 ipv6,亦即為ipv4.
26650
							if(strpos($ip,":")!==false){
26651
 
26652
								#函式說明:
26653
								#將ipv4轉換成ipv6
26654
								#回傳結果:
26655
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26656
								#$result["error"],錯誤訊息陣列.
26657
								#$result["function"],當前執行的函式名稱.
26658
								#$result["content"],取得的回應內容.
26659
								#$result["argu"],使用的參數.
26660
								#必填參數:
26661
								#$conf["ipv4"],字串,人可讀的ipv4字串.
26662
								$Conf["csInformation::ipv4toipv6"]["ipv4"]=$ip;
26663
								#可省略參數:
26664
								#無.
26665
								#參考資料:
26666
								#http://benjr.tw/17314
26667
								#https://www.ultratools.com/tools/ipv4toipv6
26668
								#備註:
26669
								#無.
26670
								$ipv4toipv6=csInformation::ipv4toipv6($Conf["csInformation::ipv4toipv6"]);
26671
								unset($Conf["csInformation::ipv4toipv6"]);
26672
 
26673
								#如果執行失敗
26674
								if($ipv4toipv6["status"]==="false"){
26675
 
26676
									#設置執行失敗
26677
									$result["status"]="false";
26678
 
26679
									#設置錯誤訊息
26680
									$result["error"]=$ipv4toipv6;
26681
 
26682
									#回傳結果
26683
									return $result;
26684
 
26685
									}#if end
26686
 
26687
								#要搜尋的ipv6關鍵字
26688
								$ips[]=$ipv4toipv6["content"];
26689
 
26690
								}#if end
26691
 
26692
							#針對每筆資料
26693
							foreach($ss["content"]["Local Address:Port"] as $index => $localAddrPort){
26694
 
26695
								#尋找符合的 Local Address
26696
								#函式說明:
26697
								#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
26698
								#回傳結果:
26699
								#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
26700
								#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
26701
								#$result["error"],錯誤訊息
26702
								#$result["function"],當前執行的函數名稱
26703
								#$result["argv"],使用的參數
26704
								#$result["equalVarName"],相等的變數名稱或key.
26705
								#$result["equalVarValue"],相等的變數數值內容.
26706
								#必填參數:
26707
								#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
26708
								$conf["search::getEqualVar"]["conditionElement"]=$localAddrPort["addr"];
26709
								#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
26710
								$conf["search::getEqualVar"]["compareElements"]=$ips;
26711
								#可省略參數:
26712
								#無.
26713
								#參考資料:
26714
								#無.
26715
								#備註:
26716
								#無.
26717
								$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
26718
								unset($conf["search::getEqualVar"]);
26719
 
26720
								#如果執行失敗
26721
								if($getEqualVar["status"]==="false"){
26722
 
26723
									#設置執行失敗
26724
									$result["status"]="false";
26725
 
26726
									#設置錯誤訊息
26727
									$result["error"]=$getEqualVar;
26728
 
26729
									#回傳結果
26730
									return $result;
26731
 
26732
									}#if end
26733
 
26734
								#如果無找到同 addr 的資料
26735
								if($getEqualVar["founded"]==="fasle"){
26736
 
26737
									#下一輪
26738
									continue;
26739
 
26740
									}#if end
26741
 
26742
								#尋找符合的 Port
26743
								#函式說明:
26744
								#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
26745
								#回傳結果:
26746
								#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
26747
								#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
26748
								#$result["error"],錯誤訊息
26749
								#$result["function"],當前執行的函數名稱
26750
								#$result["argv"],使用的參數
26751
								#$result["equalVarName"],相等的變數名稱或key.
26752
								#$result["equalVarValue"],相等的變數數值內容.
26753
								#必填參數:
26754
								#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
26755
								$conf["search::getEqualVar"]["conditionElement"]=$localAddrPort["port"];
26756
								#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
26757
								$conf["search::getEqualVar"]["compareElements"]=array($port);
26758
								#可省略參數:
26759
								#無.
26760
								#參考資料:
26761
								#無.
26762
								#備註:
26763
								#無.
26764
								$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
26765
								unset($conf["search::getEqualVar"]);
26766
 
26767
								#如果執行失敗
26768
								if($getEqualVar["status"]==="false"){
26769
 
26770
									#設置執行失敗
26771
									$result["status"]="false";
26772
 
26773
									#設置錯誤訊息
26774
									$result["error"]=$getEqualVar;
26775
 
26776
									#回傳結果
26777
									return $result;
26778
 
26779
									}#if end
26780
 
26781
								#如果無找到同 port 的資料
26782
								if($getEqualVar["founded"]==="fasle"){
26783
 
26784
									#下一輪
26785
									continue;
26786
 
26787
									}#if end
26788
 
26789
								#執行到這邊代表有找到同 ip:port 的資料
26790
 
26791
								#若 protocol 正確
26792
								if($ss["content"]["Netid"][$index]===$protocol){
26793
 
26794
									#設置通過檢查
26795
									$pass="true";
26796
 
26797
									}#if end
26798
 
26799
								}#foreach end
26800
 
26801
							#如果沒有符合的 ip:port
26802
							if($pass==="false"){
26803
 
26804
								#提示問題
26805
								echo "service ".$conf["name"]." ip and port not match!".PHP_EOL;
26806
 
26807
								#如果 verbose 為 "true"
26808
								if($conf["verbose"]==="true"){
26809
 
26810
									#提示搜尋過的內容
26811
									echo "searched socket list:".PHP_EOL;
26812
									var_dump($ss["content"]["Local Address:Port"]);
26813
 
26814
									}#if end
26815
 
26816
								#如果只要 Report
26817
								if($conf["reportOnly"]==="true"){
26818
 
26819
									#輸出
26820
									echo "service ".$conf["name"]." need to restart!".PHP_EOL;
26821
 
26822
									#下一輪
26823
									continue;
26824
 
26825
									}#if end
26826
 
26827
								#啟動服務
26828
								#函式說明:
26829
								#執行 systemd 程序來管理服務.
26830
								#回傳結果:
26831
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26832
								#$result["error"],錯誤訊息.
26833
								#$result["function"],當前執行的函式名稱.
26834
								#$result["argu"],所使用的參數.
26835
								#$result["content"],執行的結果.
26836
								#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
26837
								#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
26838
								#必填參數:
26839
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
26840
								$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
26841
								#$conf["name"],字串,服務名稱.
26842
								$conf["cmd::systemd"]["name"]=$conf["name"];
26843
								#可省略參數:
26844
								#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
26845
								$conf["cmd::systemd"]["operation"]="start";
26846
								#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
26847
								#$conf["username"]="";
26848
								#$conf["password"],字串,使用者的密碼,預設不使用.
26849
								#$conf["password"]="";
26850
								$systemd=cmd::systemd($conf["cmd::systemd"]);
26851
								unset($conf["cmd::systemd"]);
26852
 
26853
								#若運行出錯
26854
								if($systemd["status"]==="false"){
26855
 
26856
									#設置執行失敗
26857
									$result["status"]="false";
26858
 
26859
									#設置錯誤訊息
26860
									$result["error"]=$systemd;
26861
 
26862
									#回傳結果
26863
									return $result;
26864
 
26865
									}#if end
26866
 
26867
								#下一輪
26868
								continue;
26869
 
26870
								}#if end
26871
 
26872
							}#if end, ip condition end
26873
 
26874
						#如果有指定 addr
26875
						if(isset($checkListen["addr"])){
26876
 
26877
							#取得addr資訊
26878
							$listenInfo=$checkListen["addr"];
26879
 
26880
							#如果沒有 "Local Address:Port" 欄位
26881
							if(!isset($ss["content"]["Local Address:Port"])){
26882
 
26883
								#設置執行失敗
26884
								$result["status"]="false";
26885
 
26886
								#設置錯誤訊息
26887
								$result["error"][]="Local Address:Port column data not found";
26888
 
26889
								#設置錯誤訊息
26890
								$result["error"][]=$ss;
26891
 
26892
								#回傳結果
26893
								return $result;
26894
 
26895
								}#if end
26896
 
26897
							#預設沒有通過檢查
26898
							$pass="false";
26899
 
26900
							#初始化關鍵字
26901
							$keyWord=array();
26902
 
26903
							#新增關鍵字  unix socket domain
26904
							$keyWord[]=$listenInfo;
26905
 
26906
							#針對每筆資料
26907
							foreach($ss["content"]["Local Address:Port"] as $index => $localAddrPort){
26908
 
26909
								#如果是字串
26910
								if(gettype($localAddrPort)==="string"){
26911
 
26912
									#置換成陣列
26913
									$localAddrPort=array($localAddrPort);
26914
 
26915
									}#if end
26916
 
26917
								#尋找符合的 Local Address:Port
26918
								#函式說明:
26919
								#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
26920
								#回傳結果:
26921
								#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
26922
								#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
26923
								#$result["error"],錯誤訊息
26924
								#$result["function"],當前執行的函數名稱
26925
								#$result["argv"],使用的參數
26926
								#$result["equalVarName"],相等的變數名稱或key.
26927
								#$result["equalVarValue"],相等的變數數值內容.
26928
								#必填參數:
26929
								#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
26930
								$conf["search::getEqualVar"]["conditionElement"]=$localAddrPort;
26931
								#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
26932
								$conf["search::getEqualVar"]["compareElements"]=$keyWord;
26933
								#可省略參數:
26934
								#無.
26935
								#參考資料:
26936
								#無.
26937
								#備註:
26938
								#無.
26939
								$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
26940
								unset($conf["search::getEqualVar"]);
26941
 
26942
								#如果執行失敗
26943
								if($getEqualVar["status"]==="false"){
26944
 
26945
									#設置執行失敗
26946
									$result["status"]="false";
26947
 
26948
									#設置錯誤訊息
26949
									$result["error"]=$getEqualVar;
26950
 
26951
									#回傳結果
26952
									return $result;
26953
 
26954
									}#if end
26955
 
26956
								#如果有找到同 unix domain socket 的資料
26957
								if($getEqualVar["founded"]==="true"){
26958
 
26959
									#初始化 剩下要搜尋的 socket list 資訊
26960
									$new_ss["content"]=array();
26961
 
26962
									#針對每個欄位
26963
									foreach($ss["columns"] as $columnName){
26964
 
26965
										#取得欄位對應的資料內容
26966
										$new_ss["content"][$columnName][]=$ss["content"][$columnName][$index];
26967
 
26968
										}#foreach end
26969
 
26970
									#更新要搜尋的 socket list 資訊
26971
									$ss["content"]=$new_ss["content"];
26972
 
26973
									#設置通過檢查
26974
									$pass="true";
26975
 
26976
									}#if end
26977
 
26978
								}#foreach end
26979
 
26980
							#如果沒有符合的 unix domain socket
26981
							if($pass==="false"){
26982
 
26983
								#提示問題
26984
								echo "service ".$conf["name"]." unix domain socket not match!".PHP_EOL;
26985
 
26986
								#如果 verbose 為 "true"
26987
								if($conf["verbose"]==="true"){
26988
 
26989
									#提示搜尋過的內容
26990
									echo "searched socket list:".PHP_EOL;
26991
									var_dump($ss["content"]["Local Address:Port"]);
26992
 
26993
									}#if end
26994
 
26995
								#如果只要 Report
26996
								if($conf["reportOnly"]==="true"){
26997
 
26998
									#輸出
26999
									echo "service ".$conf["name"]." need to restart!".PHP_EOL;
27000
 
27001
									#下一輪
27002
									continue;
27003
 
27004
									}#if end
27005
 
27006
								#啟動服務
27007
								#函式說明:
27008
								#執行 systemd 程序來管理服務.
27009
								#回傳結果:
27010
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27011
								#$result["error"],錯誤訊息.
27012
								#$result["function"],當前執行的函式名稱.
27013
								#$result["argu"],所使用的參數.
27014
								#$result["content"],執行的結果.
27015
								#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
27016
								#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
27017
								#必填參數:
27018
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27019
								$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
27020
								#$conf["name"],字串,服務名稱.
27021
								$conf["cmd::systemd"]["name"]=$conf["name"];
27022
								#可省略參數:
27023
								#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
27024
								$conf["cmd::systemd"]["operation"]="start";
27025
								#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
27026
								#$conf["username"]="";
27027
								#$conf["password"],字串,使用者的密碼,預設不使用.
27028
								#$conf["password"]="";
27029
								$systemd=cmd::systemd($conf["cmd::systemd"]);
27030
								unset($conf["cmd::systemd"]);
27031
 
27032
								#若運行出錯
27033
								if($systemd["status"]==="false"){
27034
 
27035
									#設置執行失敗
27036
									$result["status"]="false";
27037
 
27038
									#設置錯誤訊息
27039
									$result["error"]=$systemd;
27040
 
27041
									#回傳結果
27042
									return $result;
27043
 
27044
									}#if end
27045
 
27046
								#下一輪
27047
								continue;
27048
 
27049
								}#if end
27050
 
27051
							}#if end
27052
 
27053
						#如果有指定 name
27054
						if(isset($checkListen["name"])){
27055
 
27056
							#取得name資訊
27057
							$listenInfo=$checkListen["name"];
27058
 
27059
							#如果沒有 "Process" 欄位
27060
							if(!isset($ss["content"]["Process"])){
27061
 
27062
								#設置執行失敗
27063
								$result["status"]="false";
27064
 
27065
								#設置錯誤訊息
27066
								$result["error"][]="Process column data not found";
27067
 
27068
								#設置錯誤訊息
27069
								$result["error"][]=$ss;
27070
 
27071
								#回傳結果
27072
								return $result;
27073
 
27074
								}#if end
27075
 
27076
							#預設沒有通過檢查
27077
							$pass="false";
27078
 
27079
							#針對每筆資料
27080
							foreach($ss["content"]["Process"] as $index => $Process){
27081
 
27082
								#尋找符合的 Process
27083
								#函式說明:
27084
								#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
27085
								#回傳結果:
27086
								#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
27087
								#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
27088
								#$result["error"],錯誤訊息
27089
								#$result["function"],當前執行的函數名稱
27090
								#$result["argv"],使用的參數
27091
								#$result["equalVarName"],相等的變數名稱或key.
27092
								#$result["equalVarValue"],相等的變數數值內容.
27093
								#必填參數:
27094
								#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
27095
								$conf["search::getEqualVar"]["conditionElement"]=$listenInfo;
27096
								#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
27097
								$conf["search::getEqualVar"]["compareElements"]=$Process;
27098
								#可省略參數:
27099
								#無.
27100
								#參考資料:
27101
								#無.
27102
								#備註:
27103
								#無.
27104
								$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
27105
								unset($conf["search::getEqualVar"]);
27106
 
27107
								#如果執行失敗
27108
								if($getEqualVar["status"]==="false"){
27109
 
27110
									#設置執行失敗
27111
									$result["status"]="false";
27112
 
27113
									#設置錯誤訊息
27114
									$result["error"]=$getEqualVar;
27115
 
27116
									#回傳結果
27117
									return $result;
27118
 
27119
									}#if end
27120
 
27121
								#如果有找到同 Process 的資料
27122
								if($getEqualVar["founded"]==="true"){
27123
 
27124
									#設置通過檢查
27125
									$pass="true";
27126
 
27127
									}#if end
27128
 
27129
								}#foreach end
27130
 
27131
							#如果沒有符合的 process program name
27132
							if($pass==="false"){
27133
 
27134
								#提示問題
27135
								echo "service ".$conf["name"]." process program name not match!".PHP_EOL;
27136
 
27137
								#如果只要 Report
27138
								if($conf["reportOnly"]==="true"){
27139
 
27140
									#輸出
27141
									echo "service ".$conf["name"]." need to restart!".PHP_EOL;;
27142
 
27143
									#下一輪
27144
									continue;
27145
 
27146
									}#if end
27147
 
27148
								#啟動服務
27149
								#函式說明:
27150
								#執行 systemd 程序來管理服務.
27151
								#回傳結果:
27152
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27153
								#$result["error"],錯誤訊息.
27154
								#$result["function"],當前執行的函式名稱.
27155
								#$result["argu"],所使用的參數.
27156
								#$result["content"],執行的結果.
27157
								#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
27158
								#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
27159
								#必填參數:
27160
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27161
								$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
27162
								#$conf["name"],字串,服務名稱.
27163
								$conf["cmd::systemd"]["name"]=$conf["name"];
27164
								#可省略參數:
27165
								#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
27166
								$conf["cmd::systemd"]["operation"]="start";
27167
								#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
27168
								#$conf["username"]="";
27169
								#$conf["password"],字串,使用者的密碼,預設不使用.
27170
								#$conf["password"]="";
27171
								$systemd=cmd::systemd($conf["cmd::systemd"]);
27172
								unset($conf["cmd::systemd"]);
27173
 
27174
								#若運行出錯
27175
								if($systemd["status"]==="false"){
27176
 
27177
									#設置執行失敗
27178
									$result["status"]="false";
27179
 
27180
									#設置錯誤訊息
27181
									$result["error"]=$systemd;
27182
 
27183
									#回傳結果
27184
									return $result;
27185
 
27186
									}#if end
27187
 
27188
								#下一輪
27189
								continue;
27190
 
27191
								}#if end
27192
 
27193
							}#if end
27194
 
27195
						#如果有 verbose
27196
						if($conf["verbose"]==="true"){
27197
 
27198
							#提示什麼條件檢查通過
27199
							echo " condition "; 
27200
 
27201
							#針對每個條件
27202
							foreach($checkListen as $name => $value){
27203
 
27204
								#印出條件
27205
								echo $name." = ".$value;
27206
 
27207
								}#for end
27208
 
27209
							#印出結果
27210
							echo " passed".PHP_EOL;
27211
 
27212
							}#if end
27213
 
27214
						}#foreach end
27215
 
27216
					}#if end
27217
 
27218
				}#if end			
27219
 
27220
			#過30秒再檢查一次
27221
			sleep($conf["interval"]);
27222
 
27223
			#下一輪
27224
			continue;
27225
 
27226
			}#while end
27227
 
27228
		}#function keepServiceUp end
27229
 
27230
	/*
27231
	#函式說明:
27232
	#將要執行的程式變成透過 systemd 來運行.
27233
	#回傳結果:
27234
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27235
	#$result["error"],錯誤訊息.
27236
	#$result["function"],當前執行的函式名稱.
27237
	#$result["argu"],所使用的參數.
27238
	#$result["content"],執行的結果.
27239
	#必填參數:
27240
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
27241
	$conf["fileArgu"]=__FILE__;
27242
	#$conf["name"],字串,服務名稱,實際產生的system名稱會加上".service".
27243
	$conf["name"]="";
27244
	#$conf["cmd"],字串,要執行的指令.
27245
	$conf["cmd"]="";
27246
	#可省略參數:
27247
	#$conf["params"],字串陣列,指令要使用的參數.
27248
	#$conf["params"]=array("");
27249
	#$conf["enable"],字串,預設為"true",代表該服務為enable.
27250
	#$conf["enable"]="true";
27251
	#$conf["startNow"],字串,預設為"true",代表該服務要立刻執行.
27252
	#$conf["startNow"]="true";
27253
	#參考資料:
27254
	#無.
27255
	#備註:
27256
	#無.
27257
	*/
27258
	public static function registerService(&$conf){
27259
 
27260
		#初始化要回傳的結果
27261
		$result=array();
27262
 
27263
		#取得當前執行的函式名稱
27264
		$result["function"]=__FUNCTION__;
27265
 
27266
		#取得參數
27267
		$result["argu"]=$conf;
27268
 
27269
		#如果 $conf 不為陣列
27270
		if(gettype($conf)!=="array"){
27271
 
27272
			#設置執行失敗
27273
			$result["status"]="false";
27274
 
27275
			#設置執行錯誤訊息
27276
			$result["error"][]="\$conf變數須為陣列形態";
27277
 
27278
			#如果傳入的參數為 null
27279
			if(is_null($conf)){
27280
 
27281
				#設置執行錯誤訊息
27282
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
27283
 
27284
				}#if end
27285
 
27286
			#回傳結果
27287
			return $result;
27288
 
27289
			}#if end
27290
 
27291
		#函式說明:
27292
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
27293
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27294
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
27295
		#$result["function"],當前執行的函式名稱.
27296
		#$result["argu"],設置給予的參數.
27297
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
27298
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
27299
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
27300
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
27301
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
27302
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
27303
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
27304
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
27305
		#必填寫的參數:
27306
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
27307
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
27308
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
27309
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
27310
		#可以省略的參數:
27311
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
27312
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name","cmd");
27313
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
27314
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
27315
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
27316
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
27317
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
27318
		#$conf["canNotBeEmpty"]=array();
27319
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
27320
		#$conf["canBeEmpty"]=array();
27321
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
27322
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("params","enable","startNow","description");
27323
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
27324
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("params","enable","startNow","description");
27325
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
27326
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string");
27327
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$c)onf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
27328
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true","true","service description.");
27329
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
27330
		#$conf["disallowAllSkipableVarIsEmpty"]="";
27331
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
27332
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
27333
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
27334
		#$conf["arrayCountEqualCheck"][]=array();
27335
		#參考資料來源:
27336
		#array_keys=>http://php.net/manual/en/function.array-keys.php
27337
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
27338
		unset($conf["variableCheck::checkArguments"]);
27339
 
27340
		#如果檢查參數失敗
27341
		if($checkArguments["status"]==="false"){
27342
 
27343
			#設置執行失敗
27344
			$result["status"]="false";
27345
 
27346
			#設置錯誤訊息
27347
			$result["error"]=$checkArguments;
27348
 
27349
			#回傳結果
27350
			return $result;
27351
 
27352
			}#if end
27353
 
27354
		#如果檢查參數失敗
27355
		if($checkArguments["passed"]==="false"){
27356
 
27357
			#設置執行失敗
27358
			$result["status"]="false";
27359
 
27360
			#設置錯誤訊息
27361
			$result["error"]=$checkArguments;
27362
 
27363
			#回傳結果
27364
			return $result;
27365
 
27366
			}#if end
27367
 
27368
		#初始化要寫入到服務檔案的內容陣列
27369
		$serviceFileContent=array();
27370
 
27371
		#服務的 Unit 識別
27372
		$serviceFileContent[]="[Unit]";
27373
 
27374
		#服務的描述
27375
		$serviceFileContent[]="Description= ".$conf["description"];
27376
 
27377
		#空一行
27378
		$serviceFileContent[]="";
27379
 
27380
		#網路連線後才執行該服務
27381
		$serviceFileContent[]="After=network-pre.target dbus.service network.target network.service httpd.service";
27382
 
27383
		#空一行
27384
		$serviceFileContent[]="";
27385
 
27386
		#服務的 Service 識別
27387
		$serviceFileContent[]="[Service]";
27388
 
27389
		#服務類型
27390
		$serviceFileContent[]="Type=simple";
27391
 
27392
		#用root身份執行
27393
		$serviceFileContent[]="User=root";
27394
 
27395
		#函式說明:
27396
		#呼叫shell執行系統命令,並取得回傳的內容.
27397
		#回傳結果:
27398
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27399
		#$result["error"],錯誤訊息陣列.
27400
		#$result["function"],當前執行的函數名稱.
27401
		#$result["argu"],使用的參數.
27402
		#$result["cmd"],執行的指令內容.
27403
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
27404
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
27405
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
27406
		#$result["running"],是否還在執行.
27407
		#$result["pid"],pid.
27408
		#$result["statusCode"],執行結束後的代碼.
27409
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
27410
		#必填參數:
27411
		#$conf["command"],字串,要執行的指令.
27412
		$conf["external::callShell"]["command"]=$conf["cmd"];
27413
		#$conf["fileArgu"],字串,變數__FILE__的內容.
27414
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
27415
		#可省略參數:
27416
 
27417
		#如果有參數
27418
		if(isset($conf["params"])){
27419
 
27420
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
27421
			$conf["external::callShell"]["argu"]=$conf["params"];
27422
 
27423
			}#if end
27424
 
27425
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
27426
		#$conf["arguIsAddr"]=array();
27427
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
27428
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
27429
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
27430
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
27431
		#$conf["enablePrintDescription"]="true";
27432
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
27433
		#$conf["printDescription"]="";
27434
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
27435
		$conf["external::callShell"]["escapeshellarg"]="true";
27436
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
27437
		#$conf["thereIsShellVar"]=array();
27438
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
27439
		#$conf["username"]="";
27440
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
27441
		#$conf["password"]="";
27442
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
27443
		#$conf["useScript"]="";
27444
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
27445
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
27446
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
27447
		#$conf["inBackGround"]="";
27448
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
27449
		#$conf["getErr"]="false";
27450
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
27451
		$conf["external::callShell"]["doNotRun"]="true";
27452
		#參考資料:
27453
		#exec=>http://php.net/manual/en/function.exec.php
27454
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
27455
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
27456
		#備註:
27457
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
27458
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
27459
		$callShell=external::callShell($conf["external::callShell"]);
27460
		unset($conf["external::callShell"]);
27461
 
27462
		#如果檢查參數失敗
27463
		if($callShell["status"]==="false"){
27464
 
27465
			#設置執行失敗
27466
			$result["status"]="false";
27467
 
27468
			#設置錯誤訊息
27469
			$result["error"]=$callShell;
27470
 
27471
			#回傳結果
27472
			return $result;
27473
 
27474
			}#if end
27475
 
27476
		#組合完整指令字串
27477
		#函式說明:
27478
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
27479
		#回傳的結果:
27480
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27481
		#$result["function"],當前執行的function名稱
27482
		#$result["error"],錯誤訊息陣列.
27483
		#$result["content"],處理好的字串.
27484
		#$result["argu"],使用的參數.
27485
		#必填參數:
27486
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
27487
		$conf["arrays::arrayToString"]["inputArray"]=$callShell["escape"]["array"];
27488
		#可省略參數:
27489
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
27490
		$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
27491
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
27492
		$conf["arrays::arrayToString"]["skipEnd"]="true";
27493
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
27494
		#$conf["spiltSymbolAtStart"]="";
27495
		#參考資料:
27496
		#無.
27497
		#備註:
27498
		#無.
27499
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
27500
		unset($conf["arrays::arrayToString"]);
27501
 
27502
		#如果轉換成字串失敗
27503
		if($arrayToString["status"]==="false"){
27504
 
27505
			#設置執行失敗
27506
			$result["status"]="false";
27507
 
27508
			#設置錯誤訊息
27509
			$result["error"]=$arrayToString;
27510
 
27511
			#回傳結果
27512
			return $result;
27513
 
27514
			}#if end
27515
 
27516
		#完整指令
27517
		$fullCmd=$arrayToString["content"];
27518
 
27519
		#要執行的程式與參數
27520
		$serviceFileContent[]="ExecStart=".$fullCmd;
27521
 
27522
		#重新執行的程式與參數
27523
		$serviceFileContent[]="ExecReload=killall ".$conf["cmd"]."; sleep 10; ".$fullCmd;
27524
 
27525
		#執行失敗後,會再次嘗試執行
27526
		$serviceFileContent[]="Restart=on-failure";
27527
 
27528
		#沒有timeout
27529
		$serviceFileContent[]="TimeoutSec=infinity";
27530
 
27531
		#空一行
27532
		$serviceFileContent[]="";
27533
 
27534
		#服務的 Install 識別
27535
		$serviceFileContent[]="[Install]";
27536
 
27537
		#預設為 multi-user.target
27538
		$serviceFileContent[]="WantedBy=multi-user.target";
27539
 
27540
		#建立 service 檔案 
27541
		#函式說明:
27542
		#將多行字串寫入到檔案
27543
		#回傳結果:
27544
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
27545
		#$result["error"],錯誤訊息陣列.
27546
		#$result["function"],當前執行函數的名稱.
27547
		#必填參數:
27548
		#$conf["fileName"],字串,爲要編輯的檔案名稱
27549
		$conf["fileAccess::writeMultiLine"]["fileName"]="/etc/systemd/system/".$conf["name"].".service";
27550
		#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
27551
		$conf["fileAccess::writeMultiLine"]["inputString"]=$serviceFileContent;
27552
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27553
		$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
27554
		#可省略參數:
27555
		#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
27556
		#參考資料:
27557
		#無.
27558
		#備註:
27559
		#無.
27560
		$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
27561
		unset($conf["fileAccess::writeMultiLine"]);
27562
 
27563
		#如果建立服務檔案失敗
27564
		if($writeMultiLine["status"]==="false"){
27565
 
27566
			#設置執行失敗
27567
			$result["status"]="false";
27568
 
27569
			#設置錯誤訊息
27570
			$result["error"]=$writeMultiLine;
27571
 
27572
			#回傳結果
27573
			return $result;
27574
 
27575
			}#if end
27576
 
27577
		#如果要 enable 服務
27578
		if($conf["enable"]==="true"){
27579
 
27580
			#啟用服務
27581
			#函式說明:
27582
			#呼叫shell執行系統命令,並取得回傳的內容.
27583
			#回傳結果:
27584
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27585
			#$result["error"],錯誤訊息陣列.
27586
			#$result["function"],當前執行的函數名稱.
27587
			#$result["argu"],使用的參數.
27588
			#$result["cmd"],執行的指令內容.
27589
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
27590
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
27591
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
27592
			#$result["running"],是否還在執行.
27593
			#$result["pid"],pid.
27594
			#$result["statusCode"],執行結束後的代碼.
27595
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
27596
			#必填參數:
27597
			#$conf["command"],字串,要執行的指令.
27598
			$conf["external::callShell"]["command"]="systemctl";
27599
			#$conf["fileArgu"],字串,變數__FILE__的內容.
27600
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
27601
			#可省略參數:
27602
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
27603
			$conf["external::callShell"]["argu"]=array("enable",$conf["name"].".service");
27604
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
27605
			#$conf["arguIsAddr"]=array();
27606
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
27607
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
27608
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
27609
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
27610
			#$conf["enablePrintDescription"]="true";
27611
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
27612
			#$conf["printDescription"]="";
27613
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
27614
			$conf["external::callShell"]["escapeshellarg"]="true";
27615
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
27616
			#$conf["thereIsShellVar"]=array();
27617
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
27618
			#$conf["username"]="";
27619
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
27620
			#$conf["password"]="";
27621
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
27622
			#$conf["useScript"]="";
27623
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
27624
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
27625
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
27626
			#$conf["inBackGround"]="";
27627
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
27628
			#$conf["getErr"]="false";
27629
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
27630
			#$conf["doNotRun"]="false";
27631
			#參考資料:
27632
			#exec=>http://php.net/manual/en/function.exec.php
27633
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
27634
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
27635
			#備註:
27636
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
27637
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
27638
			$callShell=external::callShell($conf["external::callShell"]);
27639
			unset($conf["external::callShell"]);
27640
 
27641
			#如果執行失敗
27642
			if($callShell["status"]==="false"){
27643
 
27644
				#設置執行失敗
27645
				$result["status"]="false";
27646
 
27647
				#設置錯誤訊息
27648
				$result["error"]=$callShell;
27649
 
27650
				#回傳結果
27651
				return $result;
27652
 
27653
				}#if end
27654
 
27655
			}#if end
27656
 
27657
		#如果要馬上 start 服務
27658
		if($conf["startNow"]){
27659
 
27660
			#啟動服務
27661
			#函式說明:
27662
			#呼叫shell執行系統命令,並取得回傳的內容.
27663
			#回傳結果:
27664
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27665
			#$result["error"],錯誤訊息陣列.
27666
			#$result["function"],當前執行的函數名稱.
27667
			#$result["argu"],使用的參數.
27668
			#$result["cmd"],執行的指令內容.
27669
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
27670
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
27671
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
27672
			#$result["running"],是否還在執行.
27673
			#$result["pid"],pid.
27674
			#$result["statusCode"],執行結束後的代碼.
27675
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
27676
			#必填參數:
27677
			#$conf["command"],字串,要執行的指令.
27678
			$conf["external::callShell"]["command"]="systemctl";
27679
			#$conf["fileArgu"],字串,變數__FILE__的內容.
27680
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
27681
			#可省略參數:
27682
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
27683
			$conf["external::callShell"]["argu"]=array("start",$conf["name"].".service");
27684
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
27685
			#$conf["arguIsAddr"]=array();
27686
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
27687
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
27688
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
27689
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
27690
			#$conf["enablePrintDescription"]="true";
27691
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
27692
			#$conf["printDescription"]="";
27693
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
27694
			$conf["external::callShell"]["escapeshellarg"]="true";
27695
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
27696
			#$conf["thereIsShellVar"]=array();
27697
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
27698
			#$conf["username"]="";
27699
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
27700
			#$conf["password"]="";
27701
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
27702
			#$conf["useScript"]="";
27703
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
27704
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
27705
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
27706
			#$conf["inBackGround"]="";
27707
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
27708
			#$conf["getErr"]="false";
27709
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
27710
			#$conf["doNotRun"]="false";
27711
			#參考資料:
27712
			#exec=>http://php.net/manual/en/function.exec.php
27713
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
27714
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
27715
			#備註:
27716
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
27717
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
27718
			$callShell=external::callShell($conf["external::callShell"]);
27719
			unset($conf["external::callShell"]);
27720
 
27721
			#如果執行失敗
27722
			if($callShell["status"]==="false"){
27723
 
27724
				#設置執行失敗
27725
				$result["status"]="false";
27726
 
27727
				#設置錯誤訊息
27728
				$result["error"]=$callShell;
27729
 
27730
				#回傳結果
27731
				return $result;
27732
 
27733
				}#if end
27734
 
27735
			}#if end
27736
 
27737
		#設置執行正常
27738
		$result["status"]="true";
27739
 
27740
		#回傳結果
27741
		return $result;
27742
 
27743
		}#function registerService end
27744
 
27745
	/*
27746
	#函式說明:
27747
	#透過 ping -c 3 -I [ppp0/網路界面名稱] 1.1.1.1 ,來判斷是否該界面有跟外部連線。
27748
	#回傳結果:
27749
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27750
	#$result["error"],錯誤訊息.
27751
	#$result["function"],當前執行的函式名稱.
27752
	#$result["argu"],所使用的參數.
27753
	#$result["content"],執行的結果.
27754
	#必填參數:
27755
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27756
	$conf["fileArgu"]=__FILE__;
27757
	#$conf["interface"],字串,網路界面名稱.
27758
	$conf["interface"]="";
27759
	#可省略參數:
27760
	#$conf["pingTarget"],"字串",要ping的目標,預設為"1.1.1.1".
27761
	#$conf["pingTarget"]="";
27762
	#參考資料:
27763
	#無.
27764
	#備註:
27765
	#無.
27766
	*/
27767
	public static function pingOutsideTest(&$conf){
27768
 
27769
		#初始化要回傳的結果
27770
		$result=array();
27771
 
27772
		#取得當前執行的函式名稱
27773
		$result["function"]=__FUNCTION__;
27774
 
27775
		#取得參數
27776
		$result["argu"]=$conf;
27777
 
27778
		#如果 $conf 不為陣列
27779
		if(gettype($conf)!=="array"){
27780
 
27781
			#設置執行失敗
27782
			$result["status"]="false";
27783
 
27784
			#設置執行錯誤訊息
27785
			$result["error"][]="\$conf變數須為陣列形態";
27786
 
27787
			#如果傳入的參數為 null
27788
			if(is_null($conf)){
27789
 
27790
				#設置執行錯誤訊息
27791
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
27792
 
27793
				}#if end
27794
 
27795
			#回傳結果
27796
			return $result;
27797
 
27798
			}#if end
27799
 
27800
		#函式說明:
27801
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
27802
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27803
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
27804
		#$result["function"],當前執行的函式名稱.
27805
		#$result["argu"],設置給予的參數.
27806
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
27807
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
27808
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
27809
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
27810
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
27811
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
27812
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
27813
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
27814
		#必填寫的參數:
27815
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
27816
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
27817
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
27818
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
27819
		#可以省略的參數:
27820
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
27821
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","interface");
27822
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
27823
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
27824
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
27825
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
27826
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
27827
		#$conf["canNotBeEmpty"]=array();
27828
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
27829
		#$conf["canBeEmpty"]=array();
27830
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
27831
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath");
27832
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
27833
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pingTarget");
27834
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
27835
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
27836
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
27837
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("1.1.1.1");
27838
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
27839
		#$conf["disallowAllSkipableVarIsEmpty"]="";
27840
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
27841
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
27842
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
27843
		#$conf["arrayCountEqualCheck"][]=array();
27844
		#參考資料來源:
27845
		#array_keys=>http://php.net/manual/en/function.array-keys.php
27846
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
27847
		unset($conf["variableCheck::checkArguments"]);
27848
 
27849
		#如果檢查參數失敗
27850
		if($checkArguments["status"]==="false"){
27851
 
27852
			#設置執行失敗
27853
			$result["status"]="false";
27854
 
27855
			#設置錯誤訊息
27856
			$result["error"]=$checkArguments;
27857
 
27858
			#回傳結果
27859
			return $result;
27860
 
27861
			}#if end
27862
 
27863
		#如果檢查參數失敗
27864
		if($checkArguments["passed"]==="false"){
27865
 
27866
			#設置執行失敗
27867
			$result["status"]="false";
27868
 
27869
			#設置錯誤訊息
27870
			$result["error"]=$checkArguments;
27871
 
27872
			#回傳結果
27873
			return $result;
27874
 
27875
			}#if end
27876
 
27877
		#函式說明:
27878
		#呼叫shell執行系統命令,並取得回傳的內容.
27879
		#回傳的結果:
27880
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27881
		#$result["error"],錯誤訊息陣列.
27882
		#$result["function"],當前執行的函式名稱.
27883
		#$result["argu"],使用的參數.
27884
		#$result["cmd"],執行的指令內容.
27885
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
27886
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
27887
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
27888
		#$result["running"],是否還在執行.
27889
		#$result["pid"],pid.
27890
		#$result["statusCode"],執行結束後的代碼.
27891
		#必填參數
27892
		#$conf["command"],字串,要執行的指令與.
27893
		$conf["external::callShell"]["command"]="ping";
27894
		#$conf["fileArgu"],字串,變數__FILE__的內容.
27895
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
27896
		#可省略參數:
27897
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
27898
		$conf["external::callShell"]["argu"]=array("-c","3","-I",$conf["interface"],$conf["pingTarget"]);
27899
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
27900
		#$conf["arguIsAddr"]=array();	
27901
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
27902
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
27903
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
27904
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
27905
		#$conf["enablePrintDescription"]="true";
27906
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
27907
		#$conf["printDescription"]="";
27908
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
27909
		$conf["external::callShell"]["escapeshellarg"]="true";
27910
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
27911
		$conf["external::callShell"]["username"]="root";
27912
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
27913
		#$conf["password"]="";
27914
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
27915
		#$conf["useScript"]="";
27916
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
27917
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
27918
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
27919
		#$conf["inBackGround"]="";
27920
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
27921
		$conf["external::callShell"]["getErr"]="true";
27922
		#備註:
27923
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
27924
		#參考資料:
27925
		#exec=>http://php.net/manual/en/function.exec.php
27926
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
27927
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
27928
		$callShell=external::callShell($conf["external::callShell"]);
27929
		unset($conf["external::callShell"]);
27930
 
27931
		#如果運行失敗
27932
		if($callShell["status"]==="false"){
27933
 
27934
			#設置執行失敗
27935
			$result["status"]="false";
27936
 
27937
			#設置錯誤訊息
27938
			$result["error"]=$callShell;
27939
 
27940
			#回傳結果
27941
			return $result;
27942
 
27943
 
27944
			}#if end
27945
 
27946
		#取得運行結果
27947
		$result["content"]=$callShell["output"];
27948
 
27949
		#設置執行成功
27950
		$result["status"]="true";
27951
 
27952
		#回傳結果
27953
		return $result;
27954
 
27955
		}#function pingOutsideTest end
27956
 
27957
	/*
27958
	#函式說明:
27959
	#變更word press網站的所有資訊為新的 domain name.
27960
	#回傳結果:
27961
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27962
	#$result["error"],錯誤訊息.
27963
	#$result["function"],當前執行的函式名稱.
27964
	#$result["argu"],所使用的參數.
27965
	#$result["content"],執行的結果.
27966
	#必填參數:
27967
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27968
	$conf["fileArgu"]=__FILE__;
27969
	#$conf["oldDomain"],字串,舊的domain名稱.
27970
	$conf["oldDomain"]="";
27971
	#$conf["newDomain"],字串,新的domain名稱.
27972
	$conf["newDomain"]="";
27973
	#可省略參數:
27974
	#$conf["wpConfig"],字串,wp-cofnig.php的位置與名稱,預設為"/var/www/html/wordpress/wp-config.php".
27975
	#$conf["wpConfig"]="/var/www/html/wordpress/wp-config.php";
27976
	#參考資料:
27977
	#無.
27978
	#備註:
27979
	#建構中...
27980
	*/
27981
	public static function changeWordPressDomain(&$conf){
27982
 
27983
		#初始化要回傳的結果
27984
		$result=array();
27985
 
27986
		#取得當前執行的函式名稱
27987
		$result["function"]=__FUNCTION__;
27988
 
27989
		#取得參數
27990
		$result["argu"]=$conf;
27991
 
27992
		#如果 $conf 不為陣列
27993
		if(gettype($conf)!=="array"){
27994
 
27995
			#設置執行失敗
27996
			$result["status"]="false";
27997
 
27998
			#設置執行錯誤訊息
27999
			$result["error"][]="\$conf變數須為陣列形態";
28000
 
28001
			#如果傳入的參數為 null
28002
			if(is_null($conf)){
28003
 
28004
				#設置執行錯誤訊息
28005
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
28006
 
28007
				}#if end
28008
 
28009
			#回傳結果
28010
			return $result;
28011
 
28012
			}#if end
28013
 
28014
		#函式說明:
28015
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
28016
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28017
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
28018
		#$result["function"],當前執行的函式名稱.
28019
		#$result["argu"],設置給予的參數.
28020
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
28021
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
28022
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
28023
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
28024
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
28025
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
28026
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
28027
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
28028
		#必填寫的參數:
28029
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
28030
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
28031
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
28032
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
28033
		#可以省略的參數:
28034
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
28035
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","oldDomain","newDomain");
28036
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
28037
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
28038
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
28039
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
28040
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
28041
		#$conf["canNotBeEmpty"]=array();
28042
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
28043
		#$conf["canBeEmpty"]=array();
28044
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
28045
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("wpConfig");
28046
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
28047
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wpConfig");
28048
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
28049
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
28050
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
28051
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/var/www/html/wordpress/wp-config.php");
28052
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
28053
		#$conf["disallowAllSkipableVarIsEmpty"]="";
28054
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
28055
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
28056
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
28057
		#$conf["arrayCountEqualCheck"][]=array();
28058
		#參考資料來源:
28059
		#array_keys=>http://php.net/manual/en/function.array-keys.php
28060
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
28061
		unset($conf["variableCheck::checkArguments"]);
28062
 
28063
		#如果檢查參數失敗
28064
		if($checkArguments["status"]==="false"){
28065
 
28066
			#設置執行失敗
28067
			$result["status"]="false";
28068
 
28069
			#設置錯誤訊息
28070
			$result["error"]=$checkArguments;
28071
 
28072
			#回傳結果
28073
			return $result;
28074
 
28075
			}#if end
28076
 
28077
		#如果檢查參數失敗
28078
		if($checkArguments["passed"]==="false"){
28079
 
28080
			#設置執行失敗
28081
			$result["status"]="false";
28082
 
28083
			#設置錯誤訊息
28084
			$result["error"]=$checkArguments;
28085
 
28086
			#回傳結果
28087
			return $result;
28088
 
28089
			}#if end	
28090
 
28091
		#要尋找的db參數
28092
		$dbParams=array("DB_NAME","DB_USER","DB_PASSWORD","DB_HOST");	
28093
 
28094
		#函式說明:
28095
		#解析PHP檔案裡面的變數.
28096
		#回傳結果:
28097
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28098
		#$result["error"],錯誤訊息.
28099
		#$result["function"],當前執行的函式名稱.
28100
		#$result["argu"],所使用的參數.	
28101
		#$result["content"],找到的變數內容陣列.
28102
		#$result["content"]["value"],依找到變數順序的數值.
28103
		#$result["content"]["struc"],依找到變數順序的階層結構.
28104
		#$result["content"]["direct],變數名稱對應的數值內容.
28105
		#必填參數:
28106
		#$conf["file"],字串,檔案的路徑與名稱.
28107
		$conf["fileAccess::parseVaraiableInPHPfile"]["file"]=$conf["wpConfig"];
28108
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
28109
		$conf["fileAccess::parseVaraiableInPHPfile"]["fileArgu"]=$conf["fileArgu"];
28110
		#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
28111
		$conf["fileAccess::parseVaraiableInPHPfile"]["varName"]=$dbParams;
28112
		#可省略參數:
28113
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
28114
		#$conf["web"]="true";
28115
		#參考資料:
28116
		#https://www.php.net/manual/en/function.parse-str.php
28117
		$parseVaraiableInPHPfile=fileAccess::parseVaraiableInPHPfile($conf["fileAccess::parseVaraiableInPHPfile"]);
28118
		unset($conf["fileAccess::parseVaraiableInPHPfile"]);
28119
 
28120
		#如果解析 php 變數失敗
28121
		if($parseVaraiableInPHPfile["status"]==="false"){
28122
 
28123
			#設置執行失敗
28124
			$result["status"]="false";
28125
 
28126
			#設置錯誤訊息
28127
			$result["error"]=$parseVaraiableInPHPfile;
28128
 
28129
			#回傳結果
28130
			return $result;
28131
 
28132
			}#if end
28133
 
28134
		#針對每個要尋找的資料庫連線變數
28135
		foreach($dbParams as $varName){
28136
 
28137
			#如果要尋找的資料庫參數不存在
28138
			if(!isset($parseVaraiableInPHPfile["content"]["direct"][$varName])){
28139
 
28140
				#設置執行失敗
28141
				$result["status"]="false";
28142
 
28143
				#設置錯誤訊息
28144
				$result["error"]=$parseVaraiableInPHPfile;
28145
 
28146
				#回傳結果
28147
				return $result;
28148
 
28149
				}#if end
28150
 
28151
			#設置變數名稱
28152
			$$varName=$parseVaraiableInPHPfile["content"]["direct"][$varName];
28153
 
28154
			}#foreach end
28155
 
28156
		#update wp_options table start
28157
 
28158
		#函式說明:
28159
		#一次取得資料庫、表的資料
28160
		#回傳的結果
28161
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
28162
		#$result["error"],錯誤訊息陣列。
28163
		#$result["function"],當前執行的漢書名稱.
28164
		#$result["argu"],使用的參數.
28165
		#$result["dataColumnName"],抓取的資料欄位名稱陣列.
28166
			#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
28167
		#$result["dataContent"],爲資料的內容。
28168
		#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
28169
			#$dataSetNum 爲第$dataSetNum+1筆資料
28170
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
28171
		#$result["dataCount"],爲取得的資料筆數。
28172
		#$result["sql"],執行的sql字串.
28173
		#必填參數:
28174
		#$conf["dbAddress"],字串,爲dbServer的位置。
28175
		$conf["db::fastGetDbData"]["dbAddress"]=$DB_HOST;
28176
		#$conf["dbAccount"],字串,爲登入dbServer的帳號。
28177
		$conf["db::fastGetDbData"]["dbAccount"]=$DB_USER;
28178
		#$conf["dbName"],字串,爲要存取的資料庫名稱
28179
		$conf["db::fastGetDbData"]["dbName"]=$DB_NAME;
28180
		#$conf["tableName"],字串,爲要存取的資料表名稱
28181
		$conf["db::fastGetDbData"]["tableName"]="wp_options";
28182
		#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.
28183
		$conf["db::fastGetDbData"]["columnYouWant"]=array("*");
28184
		#可省略參數:
28185
		#$conf["dbPassword"],字串,爲要存取dbServer的密碼.
28186
		$conf["db::fastGetDbData"]["dbPassword"]=$DB_PASSWORD;
28187
		#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
28188
		#$conf["dbPort"]="";
28189
		#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
28190
		#$conf["WhereColumnName"]=array("");
28191
		#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
28192
		#$conf["WhereColumnValue"]=array("");
28193
		#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
28194
		#$conf["WhereColumnCombine"]=array("");
28195
		#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
28196
		#$conf["WhereColumnOperator"]=array("");
28197
		#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
28198
		#$conf["WhereColumnAndOr"]=array("");
28199
		#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
28200
		#$conf["whereIn"]=array(array("colName",array("a","b","c")));
28201
		#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
28202
		#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
28203
		#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
28204
		#$conf["orderItem"]="";
28205
		#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
28206
		#$conf["ascORdesc"]="";
28207
		#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
28208
		#$conf["numberStart"]="0";
28209
		#$conf["numLimit"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
28210
		#$conf["numLimit"]="30";
28211
		#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
28212
		#$conf["groupBy"]=array("");
28213
		$fastGetDbData=db::fastGetDbData($conf["db::fastGetDbData"]);
28214
		unset($conf["db::fastGetDbData"]);
28215
 
28216
		#如果查詢失敗
28217
		if($fastGetDbData["status"]==="false"){
28218
 
28219
			#設置執行失敗
28220
			$result["status"]="false";
28221
 
28222
			#設置錯誤訊息
28223
			$result["error"]=$fastGetDbData;
28224
 
28225
			#回傳結果
28226
			return $result;
28227
 
28228
			}#if end
28229
 
28230
		#針對每筆資料
28231
		foreach($fastGetDbData["dataContent"]["option_value"] as $index=>$value){
28232
 
28233
			#遇到空字串
28234
			if($value===""){
28235
 
28236
				#跳過
28237
				continue;
28238
 
28239
				}#if end
28240
 
28241
			#函式說明:
28242
			#處理字串避免網頁出錯
28243
			#回傳的結果:
28244
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28245
			#$result["function"],當前執行的函式.
28246
			#$result["content"],爲處理好的字串.
28247
			#$result["error"],錯誤訊息陣列.
28248
			#$result["argu"],使用的參數. 
28249
			#必填參數:
28250
			$conf["stringProcess::correctCharacter"]["stringIn"]=$value;#爲要處理的字串
28251
			#可省略參數:
28252
			$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array($conf["oldDomain"]);#爲被選擇要處理的字串/字元,須爲陣列值。
28253
				#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
28254
				#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
28255
			$conf["stringProcess::correctCharacter"]["changeTo"]=array($conf["newDomain"]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
28256
			#備註:
28257
			#無.
28258
			$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
28259
			unset($conf["stringProcess::correctCharacter"]);
28260
 
28261
			#如果查詢失敗
28262
			if($correctCharacter["status"]==="false"){
28263
 
28264
				#設置執行失敗
28265
				$result["status"]="false";
28266
 
28267
				#設置錯誤訊息
28268
				$result["error"]=$correctCharacter;
28269
 
28270
				#回傳結果
28271
				return $result;
28272
 
28273
				}#if end
28274
 
28275
			#取得處理好的內容
28276
			$value=$correctCharacter["content"];
28277
 
28278
			#函式說明:	
28279
			#更新資料表裏面的資料
28280
			#回傳的結果:	
28281
			#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
28282
			#$result["error"],錯誤訊息
28283
			#$result["function"],當前執行的函式名稱
28284
			#$result["sql"],執行的sql語法.
28285
			#必填參數:
28286
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
28287
			$conf["db::updateDataTableContent"]["fileArgu"]=$conf["fileArgu"];
28288
			#$conf["dbAddress"],字串,爲mysql-Server的位置
28289
			$conf["db::updateDataTableContent"]["dbAddress"]=$DB_HOST;
28290
			#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
28291
			$conf["db::updateDataTableContent"]["dbAccount"]=$DB_USER;
28292
			#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
28293
			$conf["db::updateDataTableContent"]["selectedDataBaseName"]=$DB_NAME;
28294
			#$conf["tableName"],字串,要修改的資料表名稱
28295
			$conf["db::updateDataTableContent"]["tableName"]="wp_options";
28296
			#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值
28297
			$conf["db::updateDataTableContent"]["whereColumn"]=array("option_id");
28298
			#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值
28299
			$conf["db::updateDataTableContent"]["whereValue"]=array($fastGetDbData["dataContent"]["option_id"][$index]);
28300
			#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列
28301
			$conf["db::updateDataTableContent"]["tableColumnName"]=array("option_value");
28302
			#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值
28303
			$conf["db::updateDataTableContent"]["updateDataValue"]=array($value);
28304
			#可省略參數:
28305
			#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
28306
			$conf["db::updateDataTableContent"]["dbPassword"]=$DB_PASSWORD;
28307
			#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
28308
			#$conf["dbPort"]=$dbPort;
28309
			$updateDataTableContent=db::updateDataTableContent($conf["db::updateDataTableContent"]);
28310
			unset($conf["db::updateDataTableContent"]);
28311
 
28312
			#如果更新失敗
28313
			if($updateDataTableContent["status"]==="false"){
28314
 
28315
				#設置執行失敗
28316
				$result["status"]="false";
28317
 
28318
				#設置錯誤訊息
28319
				$result["error"]=$updateDataTableContent;
28320
 
28321
				#回傳結果
28322
				return $result;
28323
 
28324
				}#if end
28325
 
28326
			}#foreach end
28327
 
28328
		#update wp_options table end
28329
 
28330
		#update wp_posts table post_content col start
28331
 
28332
		#函式說明:
28333
		#一次取得資料庫、表的資料
28334
		#回傳的結果
28335
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
28336
		#$result["error"],錯誤訊息陣列。
28337
		#$result["function"],當前執行的漢書名稱.
28338
		#$result["argu"],使用的參數.
28339
		#$result["dataColumnName"],抓取的資料欄位名稱陣列.
28340
			#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
28341
		#$result["dataContent"],爲資料的內容。
28342
		#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
28343
			#$dataSetNum 爲第$dataSetNum+1筆資料
28344
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
28345
		#$result["dataCount"],爲取得的資料筆數。
28346
		#$result["sql"],執行的sql字串.
28347
		#必填參數:
28348
		#$conf["dbAddress"],字串,爲dbServer的位置。
28349
		$conf["db::fastGetDbData"]["dbAddress"]=$DB_HOST;
28350
		#$conf["dbAccount"],字串,爲登入dbServer的帳號。
28351
		$conf["db::fastGetDbData"]["dbAccount"]=$DB_USER;
28352
		#$conf["dbName"],字串,爲要存取的資料庫名稱
28353
		$conf["db::fastGetDbData"]["dbName"]=$DB_NAME;
28354
		#$conf["tableName"],字串,爲要存取的資料表名稱
28355
		$conf["db::fastGetDbData"]["tableName"]="wp_posts";
28356
		#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.
28357
		$conf["db::fastGetDbData"]["columnYouWant"]=array("*");
28358
		#可省略參數:
28359
		#$conf["dbPassword"],字串,爲要存取dbServer的密碼.
28360
		$conf["db::fastGetDbData"]["dbPassword"]=$DB_PASSWORD;
28361
		#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
28362
		#$conf["dbPort"]="";
28363
		#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
28364
		#$conf["WhereColumnName"]=array("");
28365
		#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
28366
		#$conf["WhereColumnValue"]=array("");
28367
		#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
28368
		#$conf["WhereColumnCombine"]=array("");
28369
		#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
28370
		#$conf["WhereColumnOperator"]=array("");
28371
		#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
28372
		#$conf["WhereColumnAndOr"]=array("");
28373
		#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
28374
		#$conf["whereIn"]=array(array("colName",array("a","b","c")));
28375
		#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
28376
		#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
28377
		#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
28378
		#$conf["orderItem"]="";
28379
		#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
28380
		#$conf["ascORdesc"]="";
28381
		#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
28382
		#$conf["numberStart"]="0";
28383
		#$conf["numLimit"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
28384
		#$conf["numLimit"]="30";
28385
		#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
28386
		#$conf["groupBy"]=array("");
28387
		$fastGetDbData=db::fastGetDbData($conf["db::fastGetDbData"]);
28388
		unset($conf["db::fastGetDbData"]);
28389
 
28390
		#如果查詢失敗
28391
		if($fastGetDbData["status"]==="false"){
28392
 
28393
			#設置執行失敗
28394
			$result["status"]="false";
28395
 
28396
			#設置錯誤訊息
28397
			$result["error"]=$fastGetDbData;
28398
 
28399
			#回傳結果
28400
			return $result;
28401
 
28402
			}#if end
28403
 
28404
		#針對每筆資料
28405
		foreach($fastGetDbData["dataContent"]["post_content"] as $index=>$value){
28406
 
28407
			#函式說明:
28408
			#處理字串避免網頁出錯
28409
			#回傳的結果:
28410
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28411
			#$result["function"],當前執行的函式.
28412
			#$result["content"],爲處理好的字串.
28413
			#$result["error"],錯誤訊息陣列.
28414
			#$result["argu"],使用的參數. 
28415
			#必填參數:
28416
			$conf["stringProcess::correctCharacter"]["stringIn"]=$value;#爲要處理的字串
28417
			#可省略參數:
28418
			$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array($conf["oldDomain"]);#爲被選擇要處理的字串/字元,須爲陣列值。
28419
				#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
28420
				#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
28421
			$conf["stringProcess::correctCharacter"]["changeTo"]=array($conf["newDomain"]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
28422
			#備註:
28423
			#無.
28424
			$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
28425
			unset($conf["stringProcess::correctCharacter"]);
28426
 
28427
			#如果查詢失敗
28428
			if($correctCharacter["status"]==="false"){
28429
 
28430
				#設置執行失敗
28431
				$result["status"]="false";
28432
 
28433
				#設置錯誤訊息
28434
				$result["error"]=$correctCharacter;
28435
 
28436
				#回傳結果
28437
				return $result;
28438
 
28439
				}#if end
28440
 
28441
			#取得處理好的內容
28442
			$value=$correctCharacter["content"];
28443
 
28444
			#函式說明:	
28445
			#更新資料表裏面的資料
28446
			#回傳的結果:	
28447
			#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
28448
			#$result["error"],錯誤訊息
28449
			#$result["function"],當前執行的函式名稱
28450
			#$result["sql"],執行的sql語法.
28451
			#必填參數:
28452
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
28453
			$conf["db::updateDataTableContent"]["fileArgu"]=$conf["fileArgu"];
28454
			#$conf["dbAddress"],字串,爲mysql-Server的位置
28455
			$conf["db::updateDataTableContent"]["dbAddress"]=$DB_HOST;
28456
			#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
28457
			$conf["db::updateDataTableContent"]["dbAccount"]=$DB_USER;
28458
			#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
28459
			$conf["db::updateDataTableContent"]["selectedDataBaseName"]=$DB_NAME;
28460
			#$conf["tableName"],字串,要修改的資料表名稱
28461
			$conf["db::updateDataTableContent"]["tableName"]="wp_posts";
28462
			#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值
28463
			$conf["db::updateDataTableContent"]["whereColumn"]=array("id");
28464
			#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值
28465
			$conf["db::updateDataTableContent"]["whereValue"]=array($fastGetDbData["dataContent"]["id"][$index]);
28466
			#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列
28467
			$conf["db::updateDataTableContent"]["tableColumnName"]=array("post_content");
28468
			#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值
28469
			$conf["db::updateDataTableContent"]["updateDataValue"]=array($value);
28470
			#可省略參數:
28471
			#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
28472
			$conf["db::updateDataTableContent"]["dbPassword"]=$DB_PASSWORD;
28473
			#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
28474
			#$conf["dbPort"]=$dbPort;
28475
			$updateDataTableContent=db::updateDataTableContent($conf["db::updateDataTableContent"]);
28476
			unset($conf["db::updateDataTableContent"]);
28477
 
28478
			#如果更新失敗
28479
			if($updateDataTableContent["status"]==="false"){
28480
 
28481
				#設置執行失敗
28482
				$result["status"]="false";
28483
 
28484
				#設置錯誤訊息
28485
				$result["error"]=$updateDataTableContent;
28486
 
28487
				#回傳結果
28488
				return $result;
28489
 
28490
				}#if end
28491
 
28492
			}#foreach end
28493
 
28494
		#update wp_posts table post_content col end
28495
 
28496
		#update wp_posts table guid col start
28497
 
28498
		#函式說明:
28499
		#一次取得資料庫、表的資料
28500
		#回傳的結果
28501
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
28502
		#$result["error"],錯誤訊息陣列。
28503
		#$result["function"],當前執行的漢書名稱.
28504
		#$result["argu"],使用的參數.
28505
		#$result["dataColumnName"],抓取的資料欄位名稱陣列.
28506
			#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
28507
		#$result["dataContent"],爲資料的內容。
28508
		#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
28509
			#$dataSetNum 爲第$dataSetNum+1筆資料
28510
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
28511
		#$result["dataCount"],爲取得的資料筆數。
28512
		#$result["sql"],執行的sql字串.
28513
		#必填參數:
28514
		#$conf["dbAddress"],字串,爲dbServer的位置。
28515
		$conf["db::fastGetDbData"]["dbAddress"]=$DB_HOST;
28516
		#$conf["dbAccount"],字串,爲登入dbServer的帳號。
28517
		$conf["db::fastGetDbData"]["dbAccount"]=$DB_USER;
28518
		#$conf["dbName"],字串,爲要存取的資料庫名稱
28519
		$conf["db::fastGetDbData"]["dbName"]=$DB_NAME;
28520
		#$conf["tableName"],字串,爲要存取的資料表名稱
28521
		$conf["db::fastGetDbData"]["tableName"]="wp_posts";
28522
		#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.
28523
		$conf["db::fastGetDbData"]["columnYouWant"]=array("*");
28524
		#可省略參數:
28525
		#$conf["dbPassword"],字串,爲要存取dbServer的密碼.
28526
		$conf["db::fastGetDbData"]["dbPassword"]=$DB_PASSWORD;
28527
		#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
28528
		#$conf["dbPort"]="";
28529
		#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
28530
		#$conf["WhereColumnName"]=array("");
28531
		#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
28532
		#$conf["WhereColumnValue"]=array("");
28533
		#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
28534
		#$conf["WhereColumnCombine"]=array("");
28535
		#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
28536
		#$conf["WhereColumnOperator"]=array("");
28537
		#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
28538
		#$conf["WhereColumnAndOr"]=array("");
28539
		#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
28540
		#$conf["whereIn"]=array(array("colName",array("a","b","c")));
28541
		#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
28542
		#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
28543
		#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
28544
		#$conf["orderItem"]="";
28545
		#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
28546
		#$conf["ascORdesc"]="";
28547
		#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
28548
		#$conf["numberStart"]="0";
28549
		#$conf["numLimit"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
28550
		#$conf["numLimit"]="30";
28551
		#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
28552
		#$conf["groupBy"]=array("");
28553
		$fastGetDbData=db::fastGetDbData($conf["db::fastGetDbData"]);
28554
		unset($conf["db::fastGetDbData"]);
28555
 
28556
		#如果查詢失敗
28557
		if($fastGetDbData["status"]==="false"){
28558
 
28559
			#設置執行失敗
28560
			$result["status"]="false";
28561
 
28562
			#設置錯誤訊息
28563
			$result["error"]=$fastGetDbData;
28564
 
28565
			#回傳結果
28566
			return $result;
28567
 
28568
			}#if end
28569
 
28570
		#針對每筆資料
28571
		foreach($fastGetDbData["dataContent"]["guid"] as $index=>$value){
28572
 
28573
			#函式說明:
28574
			#處理字串避免網頁出錯
28575
			#回傳的結果:
28576
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28577
			#$result["function"],當前執行的函式.
28578
			#$result["content"],爲處理好的字串.
28579
			#$result["error"],錯誤訊息陣列.
28580
			#$result["argu"],使用的參數. 
28581
			#必填參數:
28582
			$conf["stringProcess::correctCharacter"]["stringIn"]=$value;#爲要處理的字串
28583
			#可省略參數:
28584
			$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array($conf["oldDomain"]);#爲被選擇要處理的字串/字元,須爲陣列值。
28585
				#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
28586
				#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
28587
			$conf["stringProcess::correctCharacter"]["changeTo"]=array($conf["newDomain"]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
28588
			#備註:
28589
			#無.
28590
			$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
28591
			unset($conf["stringProcess::correctCharacter"]);
28592
 
28593
			#如果查詢失敗
28594
			if($correctCharacter["status"]==="false"){
28595
 
28596
				#設置執行失敗
28597
				$result["status"]="false";
28598
 
28599
				#設置錯誤訊息
28600
				$result["error"]=$correctCharacter;
28601
 
28602
				#回傳結果
28603
				return $result;
28604
 
28605
				}#if end
28606
 
28607
			#取得處理好的內容
28608
			$value=$correctCharacter["content"];
28609
 
28610
			#函式說明:	
28611
			#更新資料表裏面的資料
28612
			#回傳的結果:	
28613
			#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
28614
			#$result["error"],錯誤訊息
28615
			#$result["function"],當前執行的函式名稱
28616
			#$result["sql"],執行的sql語法.
28617
			#必填參數:
28618
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
28619
			$conf["db::updateDataTableContent"]["fileArgu"]=$conf["fileArgu"];
28620
			#$conf["dbAddress"],字串,爲mysql-Server的位置
28621
			$conf["db::updateDataTableContent"]["dbAddress"]=$DB_HOST;
28622
			#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
28623
			$conf["db::updateDataTableContent"]["dbAccount"]=$DB_USER;
28624
			#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
28625
			$conf["db::updateDataTableContent"]["selectedDataBaseName"]=$DB_NAME;
28626
			#$conf["tableName"],字串,要修改的資料表名稱
28627
			$conf["db::updateDataTableContent"]["tableName"]="wp_posts";
28628
			#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值
28629
			$conf["db::updateDataTableContent"]["whereColumn"]=array("id");
28630
			#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值
28631
			$conf["db::updateDataTableContent"]["whereValue"]=array($fastGetDbData["dataContent"]["id"][$index]);
28632
			#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列
28633
			$conf["db::updateDataTableContent"]["tableColumnName"]=array("guid");
28634
			#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值
28635
			$conf["db::updateDataTableContent"]["updateDataValue"]=array($value);
28636
			#可省略參數:
28637
			#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
28638
			$conf["db::updateDataTableContent"]["dbPassword"]=$DB_PASSWORD;
28639
			#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
28640
			#$conf["dbPort"]=$dbPort;
28641
			$updateDataTableContent=db::updateDataTableContent($conf["db::updateDataTableContent"]);
28642
			unset($conf["db::updateDataTableContent"]);
28643
 
28644
			#如果更新失敗
28645
			if($updateDataTableContent["status"]==="false"){
28646
 
28647
				#設置執行失敗
28648
				$result["status"]="false";
28649
 
28650
				#設置錯誤訊息
28651
				$result["error"]=$updateDataTableContent;
28652
 
28653
				#回傳結果
28654
				return $result;
28655
 
28656
				}#if end
28657
 
28658
			}#foreach end
28659
 
28660
		#update wp_posts table guid col end
28661
 
28662
		#設置執行正常
28663
		$result["status"]="true";
28664
 
28665
		#回傳結果
28666
		return $reuslt;
28667
 
28668
		}#functino changeWordPressDomain
28669
 
28670
	/*
28671
	#函式說明:
28672
	#使用 linux 的 groups 指令來查詢使用者所屬的群組清單.
28673
	#回傳結果:
28674
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28675
	#$result["error"],錯誤訊息.
28676
	#$result["function"],當前執行的函式名稱.
28677
	#$result["cmd"],執行的指令.
28678
	#必填參數:
28679
	#無.
28680
	#可省略參數:
28681
	#$conf["user"],字串,要查詢的user,若不指定則為查詢當前使用者.
28682
	$conf["user"]="";
28683
	#參考資料:
28684
	#無.
28685
	#備註:
28686
	#無.
28687
	*/
28688
	public static function getUserGroups(&$conf){
28689
 
28690
		#初始化要回傳的結果
28691
		$result=array();
28692
 
28693
		#取得當前執行的函數名稱
28694
		$result["function"]=__FUNCTION__;
28695
 
28696
		#如果沒有參數
28697
		if(func_num_args()==0){
28698
 
28699
			#設置執行失敗
28700
			$result["status"]="false";
28701
 
28702
			#設置執行錯誤訊息
28703
			$result["error"]="函數".$result["function"]."需要參數";
28704
 
28705
			#回傳結果
28706
			return $result;
28707
 
28708
			}#if end
28709
 
28710
		#取得參數
28711
		$result["argu"]=$conf;
28712
 
28713
		#如果 $conf 不為陣列
28714
		if(gettype($conf)!=="array"){
28715
 
28716
			#設置執行失敗
28717
			$result["status"]="false";
28718
 
28719
			#設置執行錯誤訊息
28720
			$result["error"][]="\$conf變數須為陣列形態";
28721
 
28722
			#如果傳入的參數為 null
28723
			if(is_null($conf)){
28724
 
28725
				#設置執行錯誤訊息
28726
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
28727
 
28728
				}#if end
28729
 
28730
			#回傳結果
28731
			return $result;
28732
 
28733
			}#if end
28734
 
28735
		#函式說明:
28736
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
28737
		#回傳結果:
28738
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28739
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
28740
		#$result["function"],當前執行的函式名稱.
28741
		#$result["argu"],設置給予的參數.
28742
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
28743
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
28744
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
28745
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
28746
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
28747
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
28748
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
28749
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
28750
		#必填參數:
28751
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
28752
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
28753
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
28754
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
28755
		#可省略參數:
28756
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
28757
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("owner","target");
28758
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
28759
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
28760
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
28761
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
28762
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
28763
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
28764
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
28765
		#$conf["canBeEmpty"]=array();
28766
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
28767
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("user");
28768
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
28769
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("user");
28770
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
28771
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
28772
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
28773
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
28774
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
28775
		#$conf["disallowAllSkipableVarIsEmpty"]="";
28776
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
28777
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
28778
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
28779
		#$conf["arrayCountEqualCheck"][]=array();
28780
		#參考資料:
28781
		#array_keys=>http://php.net/manual/en/function.array-keys.php
28782
		#備註:
28783
		#無.
28784
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
28785
		unset($conf["variableCheck::checkArguments"]);
28786
 
28787
		#如果執行失敗
28788
		if($checkArguments["status"]==="false"){
28789
 
28790
			#設置執行失敗
28791
			$result["status"]="false";
28792
 
28793
			#設置錯誤訊息
28794
			$result["error"]=$checkArguments;
28795
 
28796
			#回傳結果
28797
			return $result;
28798
 
28799
			}#if end
28800
 
28801
		#如果檢查不通過
28802
		if($checkArguments["passed"]==="false"){
28803
 
28804
			#設置執行失敗
28805
			$result["status"]="false";
28806
 
28807
			#設置錯誤訊息
28808
			$result["error"]=$checkArguments;
28809
 
28810
			#回傳結果
28811
			return $result;
28812
 
28813
			}#if end
28814
 
28815
		#如果沒有指定 user
28816
		if(!isset($conf["users"])){
28817
 
28818
			#函式說明:
28819
			#取得用戶端的資訊,並依據需要寫入到資料表裡面
28820
			#回傳的結果:
28821
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
28822
			#$result["error"],錯誤訊息.
28823
			#$result["function"],檔前執行的函數名稱.
28824
			#$result["mode"],當前的模式是"cmd"還是"web".
28825
			#$result["userBrowserType"],爲使用者的瀏覽器資訊
28826
			#$result["userIp"],爲使用者的IP
28827
			#$result["serverIp"],為伺服器的IP
28828
			#$result["server_name"],伺服器的 domain name
28829
			#$result["scheme"],通訊協定
28830
			#$result["serverPort"],伺服器給對外下載網頁的port
28831
			#$result["requestUri"],爲使用者要求的網址/php檔案.
28832
			#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
28833
			#$result["clientRequestIP"],用戶端要求的ip與port
28834
			#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
28835
			#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
28836
			#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
28837
			#$result["header"],接收到的 header 陣列.
28838
			#$result["body"],接收到的 body 字串.
28839
			#必填參數:
28840
			#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
28841
			$conf["csInformation::getConnectionInfo"]["getAccount"]="true";
28842
			#可省略參數:
28843
			#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
28844
			#$conf["accountVar"]=$_SESSION["username"];
28845
			#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
28846
			#$conf["saveToDb"]="true";
28847
			#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
28848
			#$conf["dbAddress"]=$dbAddress;
28849
			#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
28850
			#$conf["dbAccount"]=$dbAccount;
28851
			#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
28852
			#$conf["dbName"]=$dbName;
28853
			#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
28854
			#$conf["tableName"]="visitorInfo";
28855
			#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
28856
			#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
28857
			#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
28858
			#$conf["dbPassword"]=$dbPassword;
28859
			#參考資料:
28860
			#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
28861
			#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
28862
			#備註:
28863
			#無.
28864
			$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
28865
			unset($conf["csInformation::getConnectionInfo"]);
28866
 
28867
			#如果執行失敗
28868
			if($getConnectionInfo["status"]==="false"){
28869
 
28870
				#設置執行失敗
28871
				$result["status"]="false";
28872
 
28873
				#設置錯誤訊息
28874
				$result["error"]=$getConnectionInfo;
28875
 
28876
				#回傳結果
28877
				return $result;
28878
 
28879
				}#if end
28880
 
28881
			#設置預設使用者為自己
28882
			$conf["users"]=$getConnectionInfo["phpUser"];
28883
 
28884
			}#if end
28885
 
28886
		#函式說明:
28887
		#呼叫shell執行系統命令,並取得回傳的內容.
28888
		#回傳結果:
28889
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28890
		#$result["error"],錯誤訊息陣列.
28891
		#$result["function"],當前執行的函數名稱.
28892
		#$result["argu"],使用的參數.
28893
		#$result["cmd"],執行的指令內容.
28894
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
28895
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
28896
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
28897
		#$result["running"],是否還在執行.
28898
		#$result["pid"],pid.
28899
		#$result["statusCode"],執行結束後的代碼.
28900
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
28901
		#必填參數:
28902
		#$conf["command"],字串,要執行的指令.
28903
		$conf["external::callShell"]["command"]="groups";
28904
		#$conf["fileArgu"],字串,變數__FILE__的內容.
28905
		$conf["external::callShell"]["fileArgu"]=__FILE__;
28906
		#可省略參數:
28907
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
28908
		$conf["external::callShell"]["argu"]=array($conf["user"]);
28909
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
28910
		#$conf["arguIsAddr"]=array();
28911
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
28912
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
28913
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
28914
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
28915
		#$conf["enablePrintDescription"]="true";
28916
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
28917
		#$conf["printDescription"]="";
28918
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
28919
		#$conf["escapeshellarg"]="false";
28920
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
28921
		#$conf["thereIsShellVar"]=array();
28922
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
28923
		#$conf["username"]="";
28924
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
28925
		#$conf["password"]="";
28926
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
28927
		#$conf["useScript"]="";
28928
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
28929
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
28930
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
28931
		#$conf["inBackGround"]="";
28932
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
28933
		#$conf["getErr"]="false";
28934
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
28935
		#$conf["doNotRun"]="false";
28936
		#參考資料:
28937
		#exec=>http://php.net/manual/en/function.exec.php
28938
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
28939
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
28940
		#備註:
28941
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
28942
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
28943
		$callShell=external::callShell($conf["external::callShell"]);
28944
		unset($conf["external::callShell"]);
28945
 
28946
		#如果執行失敗
28947
		if($callShell["status"]==="false"){
28948
 
28949
			#設置執行失敗
28950
			$result["status"]="false";
28951
 
28952
			#設置錯誤訊息
28953
			$result["error"]=$callShell;
28954
 
28955
			#回傳結果
28956
			return $result;
28957
 
28958
			}#if end
28959
 
28960
		#取得群組清單
28961
		#函式說明:
28962
		#將字串特定關鍵字與其前面的內容剔除
28963
		#回傳結果:
28964
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28965
		#$result["error"],錯誤訊息陣列.
28966
		#$result["warning"],警告訊息鎮列.
28967
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
28968
		#$result["function"],當前執行的函數名稱.
28969
		#$result["argu"],使用的參數.
28970
		#$result["oriStr"],要處理的原始字串內容.
28971
		#$result["content"],處理好的的字串內容.	
28972
		#必填參數:
28973
		#$conf["stringIn"],字串,要處理的字串.
28974
		$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$callShell["output"][0];
28975
		#$conf["keyWord"],字串,特定字串.
28976
		$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" : ";
28977
		#可省略參數:
28978
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
28979
		#$conf["recursive"]="true";
28980
		#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
28981
		#$conf["lastResult"]=$delStrBeforeKeyWord;
28982
		#參考資料:
28983
		#無.
28984
		#備註:
28985
		#無.
28986
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
28987
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
28988
 
28989
		#如果執行失敗
28990
		if($delStrBeforeKeyWord["status"]==="false"){
28991
 
28992
			#設置執行失敗
28993
			$result["status"]="false";
28994
 
28995
			#設置錯誤訊息
28996
			$result["error"]=$delStrBeforeKeyWord;
28997
 
28998
			#回傳結果
28999
			return $result;
29000
 
29001
			}#if end
29002
 
29003
		#如果沒有該有的關鍵字
29004
		if($delStrBeforeKeyWord["founded"]==="false"){
29005
 
29006
			#設置執行失敗
29007
			$result["status"]="false";
29008
 
29009
			#設置錯誤訊息
29010
			$result["error"]=$delStrBeforeKeyWord;
29011
 
29012
			#回傳結果
29013
			return $result;
29014
 
29015
			}#if end	
29016
 
29017
		#函式說明:
29018
		#將固定格式的字串分開,並回傳分開的結果.
29019
		#回傳結果:
29020
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29021
		#$result["error"],錯誤訊息陣列
29022
		#$result["function"],當前執行的函數名稱.
29023
		#$result["argu"],使用的參數.
29024
		#$result["oriStr"],要分割的原始字串內容
29025
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
29026
		#$result["dataCounts"],爲總共分成幾段
29027
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
29028
		#必填參數:
29029
		#$conf["stringIn"],字串,要處理的字串.
29030
		$conf["stringProcess::spiltString"]["stringIn"]=$delStrBeforeKeyWord["content"];
29031
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
29032
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
29033
		#可省略參數:
29034
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
29035
		#$conf["allowEmptyStr"]="false";
29036
		#參考資料:
29037
		#無.
29038
		#備註:
29039
		#無.
29040
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
29041
		unset($conf["stringProcess::spiltString"]);
29042
 
29043
		#如果執行失敗
29044
		if($spiltString["status"]==="false"){
29045
 
29046
			#設置執行失敗
29047
			$result["status"]="false";
29048
 
29049
			#設置錯誤訊息
29050
			$result["error"]=$spiltString;
29051
 
29052
			#回傳結果
29053
			return $result;
29054
 
29055
			}#if end
29056
 
29057
		#如果沒有結果
29058
		if($spiltString["dataCounts"]===0){
29059
 
29060
			#設置執行失敗
29061
			$result["status"]="false";
29062
 
29063
			#設置錯誤訊息
29064
			$result["error"]=$spiltString;
29065
 
29066
			#回傳結果
29067
			return $result;
29068
 
29069
			}#if end
29070
 
29071
		#設置結果
29072
		$result["content"]=$spiltString["dataArray"];
29073
 
29074
		#設置執行正常
29075
		$result["status"]="true";
29076
 
29077
		#回傳結果
29078
		return $reuslt;
29079
 
29080
		}#function getUserGroups end
29081
 
29082
	/*
29083
	#函式說明:
29084
	#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
29085
	#回傳結果:
29086
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29087
	#$result["error"],錯誤訊息.
29088
	#$result["function"],當前執行的函式名稱.
29089
	#$result["cmd"],執行的指令.
29090
	#必填參數:
29091
	#$conf["owner"],字串,要變哪個使用者擁有.
29092
	$conf["owner"]="";
29093
	#$conf["target"],字串,需要變更擁有者、 群組的目標.
29094
	$conf["target"]="";
29095
	#可省略參數:
29096
	#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
29097
	$conf["group"]="";
29098
	#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
29099
	#$conf["recursive"]="true";
29100
	#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
29101
	#$conf["excludeSelf"]="true";
29102
	#參考資料:
29103
	#無.
29104
	#備註:
29105
	#無.
29106
	*/
29107
	public static function chown(&$conf){
29108
 
29109
		#初始化要回傳的結果
29110
		$result=array();
29111
 
29112
		#取得當前執行的函數名稱
29113
		$result["function"]=__FUNCTION__;
29114
 
29115
		#如果沒有參數
29116
		if(func_num_args()==0){
29117
 
29118
			#設置執行失敗
29119
			$result["status"]="false";
29120
 
29121
			#設置執行錯誤訊息
29122
			$result["error"]="函數".$result["function"]."需要參數";
29123
 
29124
			#回傳結果
29125
			return $result;
29126
 
29127
			}#if end
29128
 
29129
		#取得參數
29130
		$result["argu"]=$conf;
29131
 
29132
		#如果 $conf 不為陣列
29133
		if(gettype($conf)!=="array"){
29134
 
29135
			#設置執行失敗
29136
			$result["status"]="false";
29137
 
29138
			#設置執行錯誤訊息
29139
			$result["error"][]="\$conf變數須為陣列形態";
29140
 
29141
			#如果傳入的參數為 null
29142
			if(is_null($conf)){
29143
 
29144
				#設置執行錯誤訊息
29145
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
29146
 
29147
				}#if end
29148
 
29149
			#回傳結果
29150
			return $result;
29151
 
29152
			}#if end
29153
 
29154
		#函式說明:
29155
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
29156
		#回傳結果:
29157
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29158
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
29159
		#$result["function"],當前執行的函式名稱.
29160
		#$result["argu"],設置給予的參數.
29161
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
29162
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
29163
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
29164
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
29165
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
29166
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
29167
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
29168
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
29169
		#必填參數:
29170
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
29171
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
29172
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
29173
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
29174
		#可省略參數:
29175
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
29176
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("owner","target");
29177
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
29178
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
29179
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
29180
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
29181
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
29182
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
29183
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
29184
		#$conf["canBeEmpty"]=array();
29185
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
29186
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("group","recursive","excludeSelf");
29187
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
29188
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("group","recursive","excludeSelf");
29189
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
29190
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
29191
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
29192
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"owner\"]","false","false");
29193
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
29194
		#$conf["disallowAllSkipableVarIsEmpty"]="";
29195
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
29196
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
29197
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
29198
		#$conf["arrayCountEqualCheck"][]=array();
29199
		#參考資料:
29200
		#array_keys=>http://php.net/manual/en/function.array-keys.php
29201
		#備註:
29202
		#無.
29203
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
29204
		unset($conf["variableCheck::checkArguments"]);
29205
 
29206
		#如果執行失敗
29207
		if($checkArguments["status"]==="false"){
29208
 
29209
			#設置執行失敗
29210
			$result["status"]="false";
29211
 
29212
			#設置錯誤訊息
29213
			$result["error"]=$checkArguments;
29214
 
29215
			#回傳結果
29216
			return $result;
29217
 
29218
			}#if end
29219
 
29220
		#如果檢查不通過
29221
		if($checkArguments["passed"]==="false"){
29222
 
29223
			#設置執行失敗
29224
			$result["status"]="false";
29225
 
29226
			#設置錯誤訊息
29227
			$result["error"]=$checkArguments;
29228
 
29229
			#回傳結果
29230
			return $result;
29231
 
29232
			}#if end
29233
 
29234
		#確認 $conf["target"] 存在
29235
		#函式說明:
29236
		#檢查多個檔案與資料夾是否存在.
29237
		#回傳的結果:
29238
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
29239
		#$result["error"],錯誤訊息陣列.
29240
		#$resutl["function"],當前執行的涵式名稱.
29241
		#$result["argu"],使用的參數.
29242
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
29243
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
29244
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
29245
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
29246
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
29247
		#必填參數:
29248
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
29249
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["target"]);
29250
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
29251
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
29252
		#可省略參數:
29253
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
29254
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
29255
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
29256
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
29257
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
29258
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
29259
		#參考資料:
29260
		#http://php.net/manual/en/function.file-exists.php
29261
		#http://php.net/manual/en/control-structures.foreach.php
29262
		#備註:
29263
		#函數file_exists檢查的路徑為檔案系統的路徑
29264
		#$result["varName"][$i]結果未實作
29265
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
29266
		unset($conf["fileAccess::checkMultiFileExist"]);
29267
 
29268
		#如果執行失敗
29269
		if($checkMultiFileExist["status"]==="false"){
29270
 
29271
			#設置執行失敗
29272
			$result["status"]="false";
29273
 
29274
			#設置錯誤訊息
29275
			$result["error"]=$checkMultiFileExist;
29276
 
29277
			#回傳結果
29278
			return $result;
29279
 
29280
			}#if end
29281
 
29282
		#如果 target 不存在
29283
		if($checkMultiFileExist["allExist"]==="false"){
29284
 
29285
			#設置執行失敗
29286
			$result["status"]="false";
29287
 
29288
			#設置錯誤訊息
29289
			$result["error"]=$checkMultiFileExist;
29290
 
29291
			#回傳結果
29292
			return $result;
29293
 
29294
			}#if end
29295
 
29296
		#初始化給 chown 的參數
29297
		$paramsForChown=array($conf["owner"].":".$conf["group"]);
29298
 
29299
		#如果底下的內容也要一起做設定
29300
		if($conf["recursive"]==="true"){
29301
 
29302
			#加上 -R 參數
29303
			$paramsForChown[]="-R";
29304
 
29305
			#取得目標資訊
29306
			#函式說明:
29307
			#取得節點的資訊.
29308
			#回傳結果:
29309
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
29310
			#$result["error"],錯誤訊息陣列.
29311
			#$result["function"],函數名稱. 
29312
			#$result["content"],檔案資訊陣列.
29313
			#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.	
29314
			#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
29315
			#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
29316
			#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
29317
			#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
29318
			#$result["content"]["ownerName"],檔案擁有着資訊.
29319
			#$result["content"]["groupName"],檔案所屬擁有着資訊.
29320
			#$result["content"]["size"],檔案大小.
29321
			#$result["content"]["modifyDate"],檔案變更年月日.
29322
			#$result["content"]["modifyTime"],檔案變更時分秒.
29323
			#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
29324
			#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
29325
			#必填參數:
29326
			#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
29327
			$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;
29328
			#$conf["file"],字串,要查看擁有者資訊的檔案.
29329
			$conf["fileAccess::fileInfo"]["file"]=$conf["target"];
29330
			#可省略參數:
29331
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
29332
			$conf["fileAccess::fileInfo"]["web"]="false";
29333
			#參考資料:
29334
			#fileowner=>http://php.net/manual/en/function.fileowner.php
29335
			#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
29336
			#備註:
29337
			#無.
29338
			$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
29339
			unset($conf["fileAccess::fileInfo"]);
29340
 
29341
			#如果執行失敗
29342
			if($fileInfo["status"]==="false"){
29343
 
29344
				#設置執行失敗
29345
				$result["status"]="false";
29346
 
29347
				#設置錯誤訊息
29348
				$result["error"]=$fileInfo;
29349
 
29350
				#回傳結果
29351
				return $result;
29352
 
29353
				}#if end
29354
 
29355
			#如果目標是資料夾
29356
			if($fileInfo["content"]["is_folder"]==="true"){
29357
 
29358
				#如果要排除目標資料夾或軟連結之類的
29359
				if($conf["excludeSelf"]==="true"){
29360
 
29361
					#函式說明:
29362
					#開啟特定目錄,取得底下的檔案路徑清單.
29363
					#回傳結果:
29364
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29365
					#$result["error"],錯誤訊息.
29366
					#$result["function"],當前執行的函數名稱.
29367
					#$result["argu"],所使用的參數.	
29368
					#$result["content"],讀取到的內容陣列.
29369
					#$result["content"][$i],第$i+1個結果.
29370
					#$result["content"][$i]["name"],第$i+1個名稱.
29371
					#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.		
29372
					#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
29373
					#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
29374
					#必填參數:
29375
					#$conf["path"],字串,要取得檔案資訊的所屬路徑.
29376
					$conf["fileAccess::listInfo"]["path"]=$conf["target"];
29377
					#可省略參數:
29378
					#無.
29379
					#參考資料
29380
					#無.
29381
					#備註:
29382
					#無.
29383
					$listInfo=fileAccess::listInfo($conf["fileAccess::listInfo"]);
29384
					unset($conf["fileAccess::listInfo"]);
29385
 
29386
					#如果執行失敗
29387
					if($listInfo["status"]==="false"){
29388
 
29389
						#設置執行失敗
29390
						$result["status"]="false";
29391
 
29392
						#設置錯誤訊息
29393
						$result["error"]=$listInfo;
29394
 
29395
						#回傳結果
29396
						return $result;
29397
 
29398
						}#if end
29399
 
29400
					#針對每個目標
29401
					foreach($listInfo["content"] as $fileInfo){
29402
 
29403
						#忽略當前目錄與上層目錄
29404
						if($fileInfo["content"]["name"]==="." || $fileInfo["content"]["name"]===".."){
29405
 
29406
							#跳過
29407
							continue;
29408
 
29409
							}#if end
29410
 
29411
						#函式說明:
29412
						#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
29413
						#回傳結果:
29414
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29415
						#$result["error"],錯誤訊息.
29416
						#$result["function"],當前執行的函式名稱.
29417
						#$result["cmd"],執行的指令.
29418
						#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.
29419
						#必填參數:
29420
						#$conf["owner"],字串,要變哪個使用者擁有.
29421
						$conf["cmd::chown"]["owner"]=$conf["owner"];
29422
						#$conf["target"],字串,需要變更擁有者、 群組的目標.
29423
						$conf["cmd::chown"]["target"]=$conf["target"]."/".$fileInfo["content"]["name"];
29424
						#可省略參數:
29425
						#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
29426
						$conf["cmd::chown"]["group"]=$conf["group"];
29427
						#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
29428
						$conf["cmd::chown"]["recursive"]="true";
29429
						#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
29430
						#$conf["excludeSelf"]="true";
29431
						#參考資料:
29432
						#無.
29433
						#備註:
29434
						#無.
29435
						$chown=cmd::chown($conf["cmd::chown"]);
29436
						unset($conf["cmd::chown"]);
29437
 
29438
						#如果執行失敗
29439
						if($chown["status"]==="false"){
29440
 
29441
							#設置執行失敗
29442
							$result["status"]="false";
29443
 
29444
							#設置錯誤訊息
29445
							$result["error"]=$chown;
29446
 
29447
							#回傳結果
29448
							return $result;
29449
 
29450
							}#if end
29451
 
29452
						#記錄結果
29453
						$result["content"][]=$chown;
29454
 
29455
						}#foreach end
29456
 
29457
					#設置執行正常
29458
					$result["status"]="true";
29459
 
29460
					#回傳結果
29461
					return $result;
29462
 
29463
					}#if end
29464
 
29465
				#執行到這邊代表不用對底下內容做異動
29466
 
29467
				}#if end
29468
 
29469
			#執行到這邊代表目標不是目錄
29470
 
29471
			}#if end
29472
 
29473
		#取得目標資訊
29474
		#函式說明:
29475
		#取得節點的資訊.
29476
		#回傳結果:
29477
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
29478
		#$result["error"],錯誤訊息陣列.
29479
		#$result["function"],函數名稱. 
29480
		#$result["content"],檔案資訊陣列.
29481
		#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.	
29482
		#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
29483
		#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
29484
		#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
29485
		#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
29486
		#$result["content"]["ownerName"],檔案擁有着資訊.
29487
		#$result["content"]["groupName"],檔案所屬擁有着資訊.
29488
		#$result["content"]["size"],檔案大小.
29489
		#$result["content"]["modifyDate"],檔案變更年月日.
29490
		#$result["content"]["modifyTime"],檔案變更時分秒.
29491
		#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
29492
		#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
29493
		#必填參數:
29494
		#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
29495
		$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;
29496
		#$conf["file"],字串,要查看擁有者資訊的檔案.
29497
		$conf["fileAccess::fileInfo"]["file"]=$conf["target"];
29498
		#可省略參數:
29499
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
29500
		$conf["fileAccess::fileInfo"]["web"]="false";
29501
		#參考資料:
29502
		#fileowner=>http://php.net/manual/en/function.fileowner.php
29503
		#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
29504
		#備註:
29505
		#無.
29506
		$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
29507
		unset($conf["fileAccess::fileInfo"]);
29508
 
29509
		#如果執行失敗
29510
		if($fileInfo["status"]==="false"){
29511
 
29512
			#設置執行失敗
29513
			$result["status"]="false";
29514
 
29515
			#設置錯誤訊息
29516
			$result["error"]=$fileInfo;
29517
 
29518
			#回傳結果
29519
			return $result;
29520
 
29521
			}#if end
29522
 
29523
		#函式說明:
29524
		#取得用戶端的資訊,並依據需要寫入到資料表裡面
29525
		#回傳的結果:
29526
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
29527
		#$result["error"],錯誤訊息.
29528
		#$result["function"],檔前執行的函數名稱.
29529
		#$result["mode"],當前的模式是"cmd"還是"web".
29530
		#$result["userBrowserType"],爲使用者的瀏覽器資訊
29531
		#$result["userIp"],爲使用者的IP
29532
		#$result["serverIp"],為伺服器的IP
29533
		#$result["server_name"],伺服器的 domain name
29534
		#$result["scheme"],通訊協定
29535
		#$result["serverPort"],伺服器給對外下載網頁的port
29536
		#$result["requestUri"],爲使用者要求的網址/php檔案.
29537
		#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
29538
		#$result["clientRequestIP"],用戶端要求的ip與port
29539
		#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
29540
		#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
29541
		#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
29542
		#$result["header"],接收到的 header 陣列.
29543
		#$result["body"],接收到的 body 字串.
29544
		#必填參數:
29545
		#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
29546
		$conf["csInformation::getConnectionInfo"]["getAccount"]="true";
29547
		#可省略參數:
29548
		#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
29549
		#$conf["accountVar"]=$_SESSION["username"];
29550
		#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
29551
		#$conf["saveToDb"]="true";
29552
		#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
29553
		#$conf["dbAddress"]=$dbAddress;
29554
		#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
29555
		#$conf["dbAccount"]=$dbAccount;
29556
		#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
29557
		#$conf["dbName"]=$dbName;
29558
		#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
29559
		#$conf["tableName"]="visitorInfo";
29560
		#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
29561
		#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
29562
		#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
29563
		#$conf["dbPassword"]=$dbPassword;
29564
		#參考資料:
29565
		#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
29566
		#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
29567
		#備註:
29568
		#無.
29569
		$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
29570
		unset($conf["csInformation::getConnectionInfo"]);
29571
 
29572
		#如果執行失敗
29573
		if($getConnectionInfo["status"]==="false"){
29574
 
29575
			#設置執行失敗
29576
			$result["status"]="false";
29577
 
29578
			#設置錯誤訊息
29579
			$result["error"]=$getConnectionInfo;
29580
 
29581
			#回傳結果
29582
			return $result;
29583
 
29584
			}#if end
29585
 
29586
		#初始化 chown 指令
29587
		$chown="chown";
29588
 
29589
		#debug
29590
		#var_dump(__LINE__,$getConnectionInfo);
29591
 
29592
		#如果不是root賬戶在運行
29593
		if($getConnectionInfo["phpUserType"]!=="intrinsic"){
29594
 
29595
			#如果不是擁有者的檔案/目錄 或是要變成自己以外的擁有者
29596
			if($getConnectionInfo["phpUser"]!==$fileInfo["content"]["ownerName"] || $getConnectionInfo["phpUser"]!==$conf["owner"]){
29597
 
29598
				#如果是wheel成員
29599
				if($getConnectionInfo["phpUserType"]==="wheel"){
29600
 
29601
					#代表要 sudo 在前
29602
					$chown="sudo";
29603
 
29604
					#函式說明:
29605
					#將多個多維陣列串聯起來,key從0開始排序.
29606
					#回傳的結果:
29607
					#$result["status"],"true"表執行正常,"false"代表執行不正常.
29608
					#$result["error"],錯誤訊息陣列.
29609
					#$result["function"],當前執行的函數.
29610
					#$result["argu"],使用的參數.
29611
					#$result["content"],合併好的一維陣列.
29612
					#必填參數
29613
					#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
29614
					$conf["arrays::mergeMultiDimensionArray"]["inputArray"]=array(array("chown"),$paramsForChown);
29615
					#可省略參數:
29616
					#$conf["allowRepeat"],字串,預設為"false",不允許重複的結果;反之為"true".
29617
					$conf["arrays::mergeMultiDimensionArray"]["allowRepeat"]="true";
29618
					#$conf["equalKeyStruc"],字串陣列,若 allowRepeat 參數為 "false", 這該參數生效.該參數為用來判斷每個陣列的哪個鍵值路徑底下的數值相同時要進行取代,後者會取代前者.
29619
					#$conf["equalKeyStruc"]=array();
29620
					#參考資料:
29621
					#無.
29622
					#備註:
29623
					#無.
29624
					$mergeMultiDimensionArray=arrays::mergeMultiDimensionArray($conf["arrays::mergeMultiDimensionArray"]);
29625
					unset($conf["arrays::mergeMultiDimensionArray"]);
29626
 
29627
					#如果執行失敗
29628
					if($mergeMultiDimensionArray["status"]==="false"){
29629
 
29630
						#設置執行失敗
29631
						$result["status"]="false";
29632
 
29633
						#設置錯誤訊息
29634
						$result["error"]=$mergeMultiDimensionArray;
29635
 
29636
						#回傳結果
29637
						return $result;
29638
 
29639
						}#if end
29640
 
29641
					#chown 在後
29642
					$paramsForChown=$mergeMultiDimensionArray["content"];
29643
 
29644
					}#if end
29645
 
29646
				#反之
29647
				else{
29648
 
29649
					#設置執行失敗
29650
					$result["status"]="false";
29651
 
29652
					#設置錯誤訊息
29653
					$result["error"][]="你沒有權限變更 ".$conf["target"]." 的  file mode bits";
29654
 
29655
					#設置錯誤訊息
29656
					$result["error"][]=$getConnectionInfo;
29657
 
29658
					#回傳結果
29659
					return $result;
29660
 
29661
					}#else end
29662
 
29663
				}#if end
29664
 
29665
			}#if end
29666
 
29667
		#加上要變更的目標
29668
		$paramsForChown[]=$conf["target"];
29669
 
29670
		#函式說明:
29671
		#呼叫shell執行系統命令,並取得回傳的內容.
29672
		#回傳結果:
29673
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29674
		#$result["error"],錯誤訊息陣列.
29675
		#$result["function"],當前執行的函數名稱.
29676
		#$result["argu"],使用的參數.
29677
		#$result["cmd"],執行的指令內容.
29678
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
29679
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
29680
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
29681
		#$result["running"],是否還在執行.
29682
		#$result["pid"],pid.
29683
		#$result["statusCode"],執行結束後的代碼.
29684
		#必填參數:
29685
		#$conf["command"],字串,要執行的指令.
29686
		$conf["external::callShell"]["command"]=$chown;
29687
		#$conf["fileArgu"],字串,變數__FILE__的內容.
29688
		$conf["external::callShell"]["fileArgu"]=__FILE__;
29689
		#可省略參數:
29690
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
29691
		$conf["external::callShell"]["argu"]=$paramsForChown;
29692
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
29693
		#$conf["arguIsAddr"]=array();
29694
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
29695
		#$conf["plainArgu"]=array();
29696
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
29697
		#$conf["useApostrophe"]=array();
29698
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
29699
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
29700
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
29701
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
29702
		#$conf["enablePrintDescription"]="true";
29703
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
29704
		#$conf["printDescription"]="";
29705
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
29706
		$conf["external::callShell"]["escapeshellarg"]="true";
29707
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
29708
		#$conf["thereIsShellVar"]=array();
29709
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
29710
		#$conf["username"]="";
29711
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
29712
		#$conf["password"]="";
29713
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
29714
		#$conf["useScript"]="";
29715
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
29716
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
29717
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
29718
		#$conf["inBackGround"]="";
29719
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
29720
		#$conf["getErr"]="false";
29721
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
29722
		#$conf["doNotRun"]="false";
29723
		#參考資料:
29724
		#exec=>http://php.net/manual/en/function.exec.php
29725
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
29726
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
29727
		#備註:
29728
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
29729
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
29730
		$callShell=external::callShell($conf["external::callShell"]);
29731
		unset($conf["external::callShell"]);
29732
 
29733
		#如果執行失敗
29734
		if($callShell["status"]==="false"){
29735
 
29736
			#設置執行失敗
29737
			$result["status"]="false";
29738
 
29739
			#設置錯誤訊息
29740
			$result["error"]=$callShell;
29741
 
29742
			#回傳結果
29743
			return $result;
29744
 
29745
			}#if end
29746
 
29747
		#設置執行的指令
29748
		$result["cmd"]=$callShell["cmd"];
29749
 
29750
		#設置執行正常
29751
		$result["status"]="true";
29752
 
29753
		#回傳結果
29754
		return $result;
29755
 
29756
		}#functino chown end
29757
 
29758
	/*
29759
	#函式說明:
29760
	#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
29761
	#回傳結果:
29762
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29763
	#$result["error"],錯誤訊息.
29764
	#$result["function"],當前執行的函式名稱.
29765
	#$result["cmd"],執行的指令.
29766
	#必填參數:
29767
	#$conf["mode"],字串,要變成什麼權限.
29768
	$conf["mode"]="";
29769
	#$conf["target"],字串,需要變更權限的目標.
29770
	$conf["target"]="";
29771
	#可省略參數:
29772
	#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
29773
	#$conf["recursive"]="true";
29774
	#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
29775
	#$conf["excludeSelf"]="true";
29776
	#參考資料:
29777
	#無.
29778
	#備註:
29779
	#無.
29780
	*/
29781
	public static function chmod(&$conf){
29782
 
29783
		#初始化要回傳的結果
29784
		$result=array();
29785
 
29786
		#取得當前執行的函數名稱
29787
		$result["function"]=__FUNCTION__;
29788
 
29789
		#如果沒有參數
29790
		if(func_num_args()==0){
29791
 
29792
			#設置執行失敗
29793
			$result["status"]="false";
29794
 
29795
			#設置執行錯誤訊息
29796
			$result["error"]="函數".$result["function"]."需要參數";
29797
 
29798
			#回傳結果
29799
			return $result;
29800
 
29801
			}#if end
29802
 
29803
		#取得參數
29804
		$result["argu"]=$conf;
29805
 
29806
		#如果 $conf 不為陣列
29807
		if(gettype($conf)!=="array"){
29808
 
29809
			#設置執行失敗
29810
			$result["status"]="false";
29811
 
29812
			#設置執行錯誤訊息
29813
			$result["error"][]="\$conf變數須為陣列形態";
29814
 
29815
			#如果傳入的參數為 null
29816
			if(is_null($conf)){
29817
 
29818
				#設置執行錯誤訊息
29819
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
29820
 
29821
				}#if end
29822
 
29823
			#回傳結果
29824
			return $result;
29825
 
29826
			}#if end
29827
 
29828
		#函式說明:
29829
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
29830
		#回傳結果:
29831
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29832
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
29833
		#$result["function"],當前執行的函式名稱.
29834
		#$result["argu"],設置給予的參數.
29835
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
29836
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
29837
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
29838
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
29839
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
29840
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
29841
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
29842
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
29843
		#必填參數:
29844
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
29845
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
29846
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
29847
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
29848
		#可省略參數:
29849
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
29850
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode","target");
29851
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
29852
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
29853
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
29854
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
29855
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
29856
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
29857
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
29858
		#$conf["canBeEmpty"]=array();
29859
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
29860
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("recursive","excludeSelf");
29861
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
29862
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive","excludeSelf");
29863
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
29864
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
29865
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
29866
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
29867
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
29868
		#$conf["disallowAllSkipableVarIsEmpty"]="";
29869
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
29870
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
29871
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
29872
		#$conf["arrayCountEqualCheck"][]=array();
29873
		#參考資料:
29874
		#array_keys=>http://php.net/manual/en/function.array-keys.php
29875
		#備註:
29876
		#無.
29877
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
29878
		unset($conf["variableCheck::checkArguments"]);
29879
 
29880
		#如果執行失敗
29881
		if($checkArguments["status"]==="false"){
29882
 
29883
			#設置執行失敗
29884
			$result["status"]="false";
29885
 
29886
			#設置錯誤訊息
29887
			$result["error"]=$checkArguments;
29888
 
29889
			#回傳結果
29890
			return $result;
29891
 
29892
			}#if end
29893
 
29894
		#如果檢查不通過
29895
		if($checkArguments["passed"]==="false"){
29896
 
29897
			#設置執行失敗
29898
			$result["status"]="false";
29899
 
29900
			#設置錯誤訊息
29901
			$result["error"]=$checkArguments;
29902
 
29903
			#回傳結果
29904
			return $result;
29905
 
29906
			}#if end
29907
 
29908
		#確認 $conf["target"] 存在
29909
		#函式說明:
29910
		#檢查多個檔案與資料夾是否存在.
29911
		#回傳的結果:
29912
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
29913
		#$result["error"],錯誤訊息陣列.
29914
		#$resutl["function"],當前執行的涵式名稱.
29915
		#$result["argu"],使用的參數.
29916
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
29917
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
29918
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
29919
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
29920
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
29921
		#必填參數:
29922
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
29923
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["target"]);
29924
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
29925
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
29926
		#可省略參數:
29927
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
29928
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
29929
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
29930
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
29931
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
29932
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
29933
		#參考資料:
29934
		#http://php.net/manual/en/function.file-exists.php
29935
		#http://php.net/manual/en/control-structures.foreach.php
29936
		#備註:
29937
		#函數file_exists檢查的路徑為檔案系統的路徑
29938
		#$result["varName"][$i]結果未實作
29939
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
29940
		unset($conf["fileAccess::checkMultiFileExist"]);
29941
 
29942
		#如果執行失敗
29943
		if($checkMultiFileExist["status"]==="false"){
29944
 
29945
			#設置執行失敗
29946
			$result["status"]="false";
29947
 
29948
			#設置錯誤訊息
29949
			$result["error"]=$checkMultiFileExist;
29950
 
29951
			#回傳結果
29952
			return $result;
29953
 
29954
			}#if end
29955
 
29956
		#如果 target 不存在
29957
		if($checkMultiFileExist["allExist"]==="false"){
29958
 
29959
			#設置執行失敗
29960
			$result["status"]="false";
29961
 
29962
			#設置錯誤訊息
29963
			$result["error"]=$checkMultiFileExist;
29964
 
29965
			#回傳結果
29966
			return $result;
29967
 
29968
			}#if end
29969
 
29970
		#初始化給 chmod 的參數
29971
		$paramsForChmod=array($conf["mode"]);
29972
 
29973
		#如果底下的內容也要一起做設定
29974
		if($conf["recursive"]==="true"){
29975
 
29976
			#加上 -R 參數
29977
			$paramsForChmod[]="-R";
29978
 
29979
			#取得目標資訊
29980
			#函式說明:
29981
			#取得節點的資訊.
29982
			#回傳結果:
29983
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
29984
			#$result["error"],錯誤訊息陣列.
29985
			#$result["function"],函數名稱. 
29986
			#$result["content"],檔案資訊陣列.
29987
			#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.	
29988
			#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
29989
			#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
29990
			#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
29991
			#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
29992
			#$result["content"]["ownerName"],檔案擁有着資訊.
29993
			#$result["content"]["groupName"],檔案所屬擁有着資訊.
29994
			#$result["content"]["size"],檔案大小.
29995
			#$result["content"]["modifyDate"],檔案變更年月日.
29996
			#$result["content"]["modifyTime"],檔案變更時分秒.
29997
			#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
29998
			#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
29999
			#必填參數:
30000
			#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
30001
			$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;
30002
			#$conf["file"],字串,要查看擁有者資訊的檔案.
30003
			$conf["fileAccess::fileInfo"]["file"]=$conf["target"];
30004
			#可省略參數:
30005
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
30006
			$conf["fileAccess::fileInfo"]["web"]="false";
30007
			#參考資料:
30008
			#fileowner=>http://php.net/manual/en/function.fileowner.php
30009
			#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
30010
			#備註:
30011
			#無.
30012
			$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
30013
			unset($conf["fileAccess::fileInfo"]);
30014
 
30015
			#如果執行失敗
30016
			if($fileInfo["status"]==="false"){
30017
 
30018
				#設置執行失敗
30019
				$result["status"]="false";
30020
 
30021
				#設置錯誤訊息
30022
				$result["error"]=$fileInfo;
30023
 
30024
				#回傳結果
30025
				return $result;
30026
 
30027
				}#if end
30028
 
30029
			#如果目標是資料夾
30030
			if($fileInfo["content"]["is_folder"]==="true"){
30031
 
30032
				#如果要排除目標資料夾或軟連結之類的
30033
				if($conf["excludeSelf"]==="true"){
30034
 
30035
					#函式說明:
30036
					#開啟特定目錄,取得底下的檔案路徑清單.
30037
					#回傳結果:
30038
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30039
					#$result["error"],錯誤訊息.
30040
					#$result["function"],當前執行的函數名稱.
30041
					#$result["argu"],所使用的參數.	
30042
					#$result["content"],讀取到的內容陣列.
30043
					#$result["content"][$i],第$i+1個結果.
30044
					#$result["content"][$i]["name"],第$i+1個名稱.
30045
					#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.		
30046
					#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
30047
					#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
30048
					#必填參數:
30049
					#$conf["path"],字串,要取得檔案資訊的所屬路徑.
30050
					$conf["fileAccess::listInfo"]["path"]=$conf["target"];
30051
					#可省略參數:
30052
					#無.
30053
					#參考資料
30054
					#無.
30055
					#備註:
30056
					#無.
30057
					$listInfo=fileAccess::listInfo($conf["fileAccess::listInfo"]);
30058
					unset($conf["fileAccess::listInfo"]);
30059
 
30060
					#如果執行失敗
30061
					if($listInfo["status"]==="false"){
30062
 
30063
						#設置執行失敗
30064
						$result["status"]="false";
30065
 
30066
						#設置錯誤訊息
30067
						$result["error"]=$listInfo;
30068
 
30069
						#回傳結果
30070
						return $result;
30071
 
30072
						}#if end
30073
 
30074
					#如果底下有資料
30075
					if(!empty($listInfo["content"])){
30076
 
30077
						#針對每個目標
30078
						foreach($listInfo["content"] as $fileInfo){
30079
 
30080
							#忽略當前目錄與上層目錄
30081
							if($fileInfo["name"]==="." || $fileInfo["name"]===".."){
30082
 
30083
								#跳過
30084
								continue;
30085
 
30086
								}#if end
30087
 
30088
							#函式說明:
30089
							#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
30090
							#回傳結果:
30091
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30092
							#$result["error"],錯誤訊息.
30093
							#$result["function"],當前執行的函式名稱.
30094
							#必填參數:
30095
							#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
30096
							$conf["fileAccess::chmod"]["mode"]=$conf["mode"];
30097
							#$conf["target"],字串,需要變更權限的目標.
30098
							$conf["fileAccess::chmod"]["target"]=$conf["target"]."/".$fileInfo["name"];
30099
							#可省略參數:
30100
							#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
30101
							$conf["fileAccess::chmod"]["recursive"]="true";
30102
							#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
30103
							#$conf["excludeSelf"]="true";
30104
							#參考資料:
30105
							#無.
30106
							#備註:
30107
							#無.
30108
							$chmod=cmd::chmod($conf["fileAccess::chmod"]);
30109
							unset($conf["fileAccess::chmod"]);
30110
 
30111
							#如果執行失敗
30112
							if($chmod["status"]==="false"){
30113
 
30114
								#設置執行失敗
30115
								$result["status"]="false";
30116
 
30117
								#設置錯誤訊息
30118
								$result["error"]=$chmod;
30119
 
30120
								#回傳結果
30121
								return $result;
30122
 
30123
								}#if end
30124
 
30125
							#記錄結果
30126
							$result["content"][]=$chmod;
30127
 
30128
							}#foreach end
30129
 
30130
						}#if end
30131
 
30132
					#設置執行正常
30133
					$result["status"]="true";
30134
 
30135
					#回傳結果
30136
					return $result;
30137
 
30138
					}#if end
30139
 
30140
				#執行到這邊代表不用對底下內容做異動
30141
 
30142
				}#if end
30143
 
30144
			#執行到這邊代表目標不是目錄
30145
 
30146
			}#if end
30147
 
30148
		#函式說明:
30149
		#取得用戶端的資訊,並依據需要寫入到資料表裡面
30150
		#回傳的結果:
30151
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
30152
		#$result["error"],錯誤訊息.
30153
		#$result["function"],檔前執行的函數名稱.
30154
		#$result["mode"],當前的模式是"cmd"還是"web".
30155
		#$result["userBrowserType"],爲使用者的瀏覽器資訊
30156
		#$result["userIp"],爲使用者的IP
30157
		#$result["serverIp"],為伺服器的IP
30158
		#$result["server_name"],伺服器的 domain name
30159
		#$result["scheme"],通訊協定
30160
		#$result["serverPort"],伺服器給對外下載網頁的port
30161
		#$result["requestUri"],爲使用者要求的網址/php檔案.
30162
		#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
30163
		#$result["clientRequestIP"],用戶端要求的ip與port
30164
		#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
30165
		#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
30166
		#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
30167
		#$result["header"],接收到的 header 陣列.
30168
		#$result["body"],接收到的 body 字串.
30169
		#必填參數:
30170
		#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
30171
		$conf["csInformation::getConnectionInfo"]["getAccount"]="true";
30172
		#可省略參數:
30173
		#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
30174
		#$conf["accountVar"]=$_SESSION["username"];
30175
		#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
30176
		#$conf["saveToDb"]="true";
30177
		#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
30178
		#$conf["dbAddress"]=$dbAddress;
30179
		#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
30180
		#$conf["dbAccount"]=$dbAccount;
30181
		#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
30182
		#$conf["dbName"]=$dbName;
30183
		#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
30184
		#$conf["tableName"]="visitorInfo";
30185
		#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
30186
		#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
30187
		#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
30188
		#$conf["dbPassword"]=$dbPassword;
30189
		#參考資料:
30190
		#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
30191
		#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
30192
		#備註:
30193
		#無.
30194
		$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
30195
		unset($conf["csInformation::getConnectionInfo"]);
30196
 
30197
		#如果執行失敗
30198
		if($getConnectionInfo["status"]==="false"){
30199
 
30200
			#設置執行失敗
30201
			$result["status"]="false";
30202
 
30203
			#設置錯誤訊息
30204
			$result["error"]=$getConnectionInfo;
30205
 
30206
			#回傳結果
30207
			return $result;
30208
 
30209
			}#if end
30210
 
30211
		#取得目標資訊
30212
		#函式說明:
30213
		#取得節點的資訊.
30214
		#回傳結果:
30215
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
30216
		#$result["error"],錯誤訊息陣列.
30217
		#$result["function"],函數名稱. 
30218
		#$result["content"],檔案資訊陣列.
30219
		#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.	
30220
		#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
30221
		#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
30222
		#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
30223
		#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
30224
		#$result["content"]["ownerName"],檔案擁有着資訊.
30225
		#$result["content"]["groupName"],檔案所屬擁有着資訊.
30226
		#$result["content"]["size"],檔案大小.
30227
		#$result["content"]["modifyDate"],檔案變更年月日.
30228
		#$result["content"]["modifyTime"],檔案變更時分秒.
30229
		#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
30230
		#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
30231
		#必填參數:
30232
		#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
30233
		$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;
30234
		#$conf["file"],字串,要查看擁有者資訊的檔案.
30235
		$conf["fileAccess::fileInfo"]["file"]=$conf["target"];
30236
		#可省略參數:
30237
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
30238
		$conf["fileAccess::fileInfo"]["web"]="false";
30239
		#參考資料:
30240
		#fileowner=>http://php.net/manual/en/function.fileowner.php
30241
		#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
30242
		#備註:
30243
		#無.
30244
		$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
30245
		unset($conf["fileAccess::fileInfo"]);
30246
 
30247
		#如果執行失敗
30248
		if($fileInfo["status"]==="false"){
30249
 
30250
			#設置執行失敗
30251
			$result["status"]="false";
30252
 
30253
			#設置錯誤訊息
30254
			$result["error"]=$fileInfo;
30255
 
30256
			#回傳結果
30257
			return $result;
30258
 
30259
			}#if end
30260
 
30261
		/*
30262
		#debug
30263
		$fsock=fopen("/tmp/test.log","w");
30264
		fwrite($fsock,$getConnectionInfo["phpUser"]);
30265
		fwrite($fsock,$fileInfo["content"]["ownerName"]);
30266
		*/
30267
 
30268
		#初始化 chmod 指令
30269
		$chmod="chmod";
30270
 
30271
		#如果不是root賬戶在運行
30272
		if($getConnectionInfo["phpUserType"]!=="intrinsic"){
30273
 
30274
			#如果不是擁有者的檔案/目錄
30275
			if($getConnectionInfo["phpUser"]!==$fileInfo["content"]["ownerName"]){
30276
 
30277
				#如果是wheel成員
30278
				if($getConnectionInfo["phpUserType"]==="wheel"){
30279
 
30280
					#代表要 sudo 在前
30281
					$chmod="sudo";
30282
 
30283
					#函式說明:
30284
					#將多個多維陣列串聯起來,key從0開始排序.
30285
					#回傳的結果:
30286
					#$result["status"],"true"表執行正常,"false"代表執行不正常.
30287
					#$result["error"],錯誤訊息陣列.
30288
					#$result["function"],當前執行的函數.
30289
					#$result["argu"],使用的參數.
30290
					#$result["content"],合併好的一維陣列.
30291
					#必填參數
30292
					#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
30293
					$conf["arrays::mergeMultiDimensionArray"]["inputArray"]=array(array("chmod"),$paramsForChmod);
30294
					#可省略參數:
30295
					#$conf["allowRepeat"],字串,預設為"false",不允許重複的結果;反之為"true".
30296
					$conf["arrays::mergeMultiDimensionArray"]["allowRepeat"]="true";
30297
					#$conf["equalKeyStruc"],字串陣列,若 allowRepeat 參數為 "false", 這該參數生效.該參數為用來判斷每個陣列的哪個鍵值路徑底下的數值相同時要進行取代,後者會取代前者.
30298
					#$conf["equalKeyStruc"]=array();
30299
					#參考資料:
30300
					#無.
30301
					#備註:
30302
					#無.
30303
					$mergeMultiDimensionArray=arrays::mergeMultiDimensionArray($conf["arrays::mergeMultiDimensionArray"]);
30304
					unset($conf["arrays::mergeMultiDimensionArray"]);
30305
 
30306
					#如果執行失敗
30307
					if($mergeMultiDimensionArray["status"]==="false"){
30308
 
30309
						#設置執行失敗
30310
						$result["status"]="false";
30311
 
30312
						#設置錯誤訊息
30313
						$result["error"]=$mergeMultiDimensionArray;
30314
 
30315
						#回傳結果
30316
						return $result;
30317
 
30318
						}#if end
30319
 
30320
					#chmod 在後
30321
					$paramsForChmod=$mergeMultiDimensionArray["content"];
30322
 
30323
					}#if end
30324
 
30325
				#反之
30326
				else{
30327
 
30328
					#設置執行失敗
30329
					$result["status"]="false";
30330
 
30331
					#設置錯誤訊息
30332
					$result["error"][]="你沒有權限變更 ".$conf["target"]." 的  file mode bits";
30333
 
30334
					#設置錯誤訊息
30335
					$result["error"][]=$getConnectionInfo;
30336
 
30337
					#設置錯誤訊息
30338
					$result["error"][]=$fileInfo["content"];
30339
 
30340
					#回傳結果
30341
					return $result;
30342
 
30343
					}#else end
30344
 
30345
				}#if end
30346
 
30347
			}#if end
30348
 
30349
		#加上要變更的目標
30350
		$paramsForChmod[]=$conf["target"];
30351
 
30352
		#函式說明:
30353
		#呼叫shell執行系統命令,並取得回傳的內容.
30354
		#回傳結果:
30355
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30356
		#$result["error"],錯誤訊息陣列.
30357
		#$result["function"],當前執行的函數名稱.
30358
		#$result["argu"],使用的參數.
30359
		#$result["cmd"],執行的指令內容.
30360
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
30361
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
30362
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
30363
		#$result["running"],是否還在執行.
30364
		#$result["pid"],pid.
30365
		#$result["statusCode"],執行結束後的代碼.
30366
		#必填參數:
30367
		#$conf["command"],字串,要執行的指令.
30368
		$conf["external::callShell"]["command"]=$chmod;
30369
		#$conf["fileArgu"],字串,變數__FILE__的內容.
30370
		$conf["external::callShell"]["fileArgu"]=__FILE__;
30371
		#可省略參數:
30372
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
30373
		$conf["external::callShell"]["argu"]=$paramsForChmod;
30374
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
30375
		#$conf["arguIsAddr"]=array();
30376
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
30377
		#$conf["plainArgu"]=array();
30378
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
30379
		#$conf["useApostrophe"]=array();
30380
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
30381
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
30382
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
30383
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
30384
		#$conf["enablePrintDescription"]="true";
30385
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
30386
		#$conf["printDescription"]="";
30387
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
30388
		$conf["external::callShell"]["escapeshellarg"]="true";
30389
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
30390
		#$conf["thereIsShellVar"]=array();
30391
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
30392
		#$conf["username"]="";
30393
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
30394
		#$conf["password"]="";
30395
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
30396
		#$conf["useScript"]="";
30397
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
30398
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
30399
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
30400
		#$conf["inBackGround"]="";
30401
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
30402
		#$conf["getErr"]="false";
30403
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
30404
		#$conf["doNotRun"]="false";
30405
		#參考資料:
30406
		#exec=>http://php.net/manual/en/function.exec.php
30407
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
30408
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
30409
		#備註:
30410
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
30411
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
30412
		$callShell=external::callShell($conf["external::callShell"]);
30413
		unset($conf["external::callShell"]);
30414
 
30415
		#如果執行失敗
30416
		if($callShell["status"]==="false"){
30417
 
30418
			#設置執行失敗
30419
			$result["status"]="false";
30420
 
30421
			#設置錯誤訊息
30422
			$result["error"]=$callShell;
30423
 
30424
			#回傳結果
30425
			return $result;
30426
 
30427
			}#if end
30428
 
30429
		#設置執行的指令
30430
		$result["cmd"]=$callShell["cmd"];
30431
 
30432
		#設置執行正常
30433
		$result["status"]="true";
30434
 
30435
		#回傳結果
30436
		return $result;
30437
 
30438
		}#function chmod end
30439
 
30440
	/*
30441
	#函式說明:
30442
	#使用 linux 的 uuid 指令來產生 uuid 字串
30443
	#回傳結果:
30444
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30445
	#$result["error"],錯誤訊息.
30446
	#$result["function"],當前執行的函式名稱.
30447
	#$result["content"],uuid.
30448
	#必填參數:
30449
	#無.
30450
	#可省略參數:
30451
	#無.
30452
	#參考資料:
30453
	#無.
30454
	#備註:
30455
	#無.
30456
	*/
30457
	public static function uuid(){
30458
 
30459
		#初始化要回傳的結果
30460
		$result=array();
30461
 
30462
		#取得當前執行的函數名稱
30463
		$result["function"]=__FUNCTION__;
30464
 
30465
		#函式說明:
30466
		#呼叫shell執行系統命令,並取得回傳的內容.
30467
		#回傳結果:
30468
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30469
		#$result["error"],錯誤訊息陣列.
30470
		#$result["function"],當前執行的函數名稱.
30471
		#$result["argu"],使用的參數.
30472
		#$result["cmd"],執行的指令內容.
30473
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
30474
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
30475
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
30476
		#$result["running"],是否還在執行.
30477
		#$result["pid"],pid.
30478
		#$result["statusCode"],執行結束後的代碼.
30479
		#必填參數:
30480
		#$conf["command"],字串,要執行的指令.
30481
		$conf["external::callShell"]["command"]="uuid";
30482
		#$conf["fileArgu"],字串,變數__FILE__的內容.
30483
		$conf["external::callShell"]["fileArgu"]=__FILE__;
30484
		#可省略參數:
30485
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
30486
		#$conf["argu"]=array("");
30487
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
30488
		#$conf["arguIsAddr"]=array();
30489
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
30490
		#$conf["plainArgu"]=array();
30491
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
30492
		#$conf["useApostrophe"]=array();
30493
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
30494
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
30495
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
30496
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
30497
		#$conf["enablePrintDescription"]="true";
30498
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
30499
		#$conf["printDescription"]="";
30500
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
30501
		$conf["external::callShell"]["escapeshellarg"]="true";
30502
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
30503
		#$conf["thereIsShellVar"]=array();
30504
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
30505
		#$conf["username"]="";
30506
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
30507
		#$conf["password"]="";
30508
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
30509
		#$conf["useScript"]="";
30510
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
30511
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
30512
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
30513
		#$conf["inBackGround"]="";
30514
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
30515
		#$conf["getErr"]="false";
30516
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
30517
		#$conf["doNotRun"]="false";
30518
		#參考資料:
30519
		#exec=>http://php.net/manual/en/function.exec.php
30520
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
30521
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
30522
		#備註:
30523
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
30524
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
30525
		$callShell=external::callShell($conf["external::callShell"]);
30526
		unset($conf["external::callShell"]);
30527
 
30528
		#如果執行失敗
30529
		if($callShell["status"]==="false"){
30530
 
30531
			#設置執行失敗
30532
			$result["status"]="false";
30533
 
30534
			#設置錯誤訊息
30535
			$result["error"]=$callShell;
30536
 
30537
			#回傳結果
30538
			return $result;
30539
 
30540
			}#if end
30541
 
30542
		#如果沒有預期的 uuid 結果
30543
		if(!isset($callShell["output"][0])){
30544
 
30545
			#設置執行失敗
30546
			$result["status"]="false";
30547
 
30548
			#設置錯誤訊息
30549
			$result["error"][]="沒有預期的 uuid 輸出";
30550
 
30551
			#設置錯誤訊息
30552
			$result["error"][]=$callShell;
30553
 
30554
			#回傳結果
30555
			return $result;
30556
 
30557
			}#if end
30558
 
30559
		#取得結果	
30560
		$result["content"]=$callShell["output"][0];
30561
 
30562
		#設置執行正常
30563
		$result["status"]="true";
30564
 
30565
		#回傳結果
30566
		return $result;
30567
 
30568
		}#function uuid end
30569
 
30570
	/*
30571
	#函式說明:
30572
	#將 freeplane 軟體支持的 mm 格式檔案跨平台.
30573
	#回傳結果:
30574
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30575
	#$result["error"],錯誤訊息.
30576
	#$result["function"],當前執行的函式名稱.
30577
	#$result["content"],調整過後的檔案內容simple xml object,若有需要取得純文字的xml內容,可用 echo 來實現.
30578
	#必填參數:
30579
	#$conf["mmFile"],字串,mm檔案的位置與名稱.
30580
	$conf["mmFile"]="";
30581
	#可省略參數:
30582
	#$conf["imgFolder"],字串,圖片存放的相對路徑字串,預設為"Pictures".
30583
	#$conf["imgFolder"]="Pictures";
30584
	#$conf["output"],字串,更新過後的 mm 檔案位置與名稱,預設為原檔案名稱加上"-1",變成"fileName-1.mm".
30585
	#$conf["output"]="";
30586
	#參考資料:
30587
	#https://www.php.net/manual/en/simplexmlelement.children.php
30588
	#https://www.php.net/manual/en/simplexmlelement.getname.php
30589
	#https://www.php.net/manual/en/simplexmlelement.tostring.php
30590
	#備註:
30591
	#無.
30592
	*/
30593
	public static function msPortable(&$conf){
30594
 
30595
		#初始化要回傳的結果
30596
		$result=array();
30597
 
30598
		#取得當前執行的函數名稱
30599
		$result["function"]=__FUNCTION__;
30600
 
30601
		#如果沒有參數
30602
		if(func_num_args()==0){
30603
 
30604
			#設置執行失敗
30605
			$result["status"]="false";
30606
 
30607
			#設置執行錯誤訊息
30608
			$result["error"]="函數".$result["function"]."需要參數";
30609
 
30610
			#回傳結果
30611
			return $result;
30612
 
30613
			}#if end
30614
 
30615
		#取得參數
30616
		$result["argu"]=$conf;
30617
 
30618
		#如果 $conf 不為陣列
30619
		if(gettype($conf)!=="array"){
30620
 
30621
			#設置執行失敗
30622
			$result["status"]="false";
30623
 
30624
			#設置執行錯誤訊息
30625
			$result["error"][]="\$conf變數須為陣列形態";
30626
 
30627
			#如果傳入的參數為 null
30628
			if(is_null($conf)){
30629
 
30630
				#設置執行錯誤訊息
30631
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
30632
 
30633
				}#if end
30634
 
30635
			#回傳結果
30636
			return $result;
30637
 
30638
			}#if end
30639
 
30640
		#函式說明:
30641
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
30642
		#回傳結果:
30643
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30644
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
30645
		#$result["function"],當前執行的函式名稱.
30646
		#$result["argu"],設置給予的參數.
30647
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
30648
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
30649
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
30650
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
30651
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
30652
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
30653
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
30654
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
30655
		#必填參數:
30656
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
30657
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
30658
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
30659
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
30660
		#可省略參數:
30661
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
30662
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mmFile");
30663
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
30664
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
30665
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
30666
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
30667
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
30668
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
30669
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
30670
		#$conf["canBeEmpty"]=array();
30671
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
30672
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("imgFolder","output");
30673
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
30674
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("imgFolder","output");
30675
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
30676
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
30677
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
30678
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("Pictures",null);
30679
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
30680
		#$conf["disallowAllSkipableVarIsEmpty"]="";
30681
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
30682
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
30683
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
30684
		#$conf["arrayCountEqualCheck"][]=array();
30685
		#參考資料:
30686
		#array_keys=>http://php.net/manual/en/function.array-keys.php
30687
		#備註:
30688
		#無.
30689
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
30690
		unset($conf["variableCheck::checkArguments"]);
30691
 
30692
		#如果執行失敗
30693
		if($checkArguments["status"]==="false"){
30694
 
30695
			#設置執行失敗
30696
			$result["status"]="false";
30697
 
30698
			#設置錯誤訊息
30699
			$result["error"]=$checkArguments;
30700
 
30701
			#回傳結果
30702
			return $result;
30703
 
30704
			}#if end
30705
 
30706
		#如果檢查不通過
30707
		if($checkArguments["passed"]==="false"){
30708
 
30709
			#設置執行失敗
30710
			$result["status"]="false";
30711
 
30712
			#設置錯誤訊息
30713
			$result["error"]=$checkArguments;
30714
 
30715
			#回傳結果
30716
			return $result;
30717
 
30718
			}#if end
30719
 
30720
		#如果沒有設置輸出的檔案位置與名稱
30721
		if(!isset($conf["output"])){
30722
 
30723
			#函式說明:
30724
			#將字串特定關鍵字與其後面的內容剔除
30725
			#回傳結果:
30726
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30727
			#$result["error"],錯誤訊息陣列.
30728
			#$result["warning"],警告訊息鎮列.
30729
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
30730
			#$result["function"],當前執行的函數名稱.
30731
			#$result["oriStr"],要處理的原始字串內容.
30732
			#$result["content"],處理好的的字串內容.
30733
			#$result["argu"],使用的參數.
30734
			#必填參數:
30735
			#$conf["stringIn"],字串,要處理的字串.
30736
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$conf["mmFile"];
30737
			#$conf["keyWord"],字串,特定字串.
30738
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".mm";
30739
			#可省略參數:
30740
			#無.
30741
			#參考資料:
30742
			#無.
30743
			#備註:
30744
			#無.
30745
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
30746
			unset($conf["stringProcess::delStrAfterKeyWord"]);
30747
 
30748
			#如果執行失敗
30749
			if($delStrAfterKeyWord["status"]==="false"){
30750
 
30751
				#設置執行失敗
30752
				$result["status"]="false";
30753
 
30754
				#設置錯誤訊息
30755
				$result["error"]=$delStrAfterKeyWord;
30756
 
30757
				#回傳結果
30758
				return $result;
30759
 
30760
				}#if end
30761
 
30762
			#如果沒有符合的關鍵字 ".mm"
30763
			if($delStrAfterKeyWord["founded"]==="false"){
30764
 
30765
				#設置執行失敗
30766
				$result["status"]="false";
30767
 
30768
				#設置錯誤訊息
30769
				$result["error"]=$delStrAfterKeyWord;
30770
 
30771
				#回傳結果
30772
				return $result;
30773
 
30774
				}#if end
30775
 
30776
			#設置預設的輸出檔案路徑與名稱
30777
			$conf["output"]=$delStrAfterKeyWord["content"]."-1.mm";
30778
 
30779
			}#if end
30780
 
30781
		#確認 $conf["target"] 存在
30782
		#函式說明:
30783
		#檢查多個檔案與資料夾是否存在.
30784
		#回傳的結果:
30785
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
30786
		#$result["error"],錯誤訊息陣列.
30787
		#$resutl["function"],當前執行的涵式名稱.
30788
		#$result["argu"],使用的參數.
30789
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
30790
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
30791
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
30792
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
30793
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
30794
		#必填參數:
30795
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
30796
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["mmFile"]);
30797
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
30798
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
30799
		#可省略參數:
30800
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
30801
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
30802
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
30803
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
30804
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
30805
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
30806
		#參考資料:
30807
		#http://php.net/manual/en/function.file-exists.php
30808
		#http://php.net/manual/en/control-structures.foreach.php
30809
		#備註:
30810
		#函數file_exists檢查的路徑為檔案系統的路徑
30811
		#$result["varName"][$i]結果未實作
30812
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
30813
		unset($conf["fileAccess::checkMultiFileExist"]);
30814
 
30815
		#如果執行失敗
30816
		if($checkMultiFileExist["status"]==="false"){
30817
 
30818
			#設置執行失敗
30819
			$result["status"]="false";
30820
 
30821
			#設置錯誤訊息
30822
			$result["error"]=$checkMultiFileExist;
30823
 
30824
			#回傳結果
30825
			return $result;
30826
 
30827
			}#if end
30828
 
30829
		#如果 target 不存在
30830
		if($checkMultiFileExist["allExist"]==="false"){
30831
 
30832
			#設置執行失敗
30833
			$result["status"]="false";
30834
 
30835
			#設置錯誤訊息
30836
			$result["error"]=$checkMultiFileExist;
30837
 
30838
			#回傳結果
30839
			return $result;
30840
 
30841
			}#if end
30842
 
30843
		#函式說明:
30844
		#讀取xml檔案,儲存所有標籤的內容,目前尚不能讀取屬性的資訊
30845
		#回傳結果:
30846
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30847
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
30848
		#$result["function"],當前執行的函式名稱.
30849
		#$result["founded"],是否有抓到xml檔案,"true"代表有抓到,"false"代表沒有抓到.
30850
		#$result["content"],xml的物件內容.
30851
		#$result["argu"],所使用的參數.
30852
		#必填參數:
30853
		#$conf["xmlPosition"],字串,xml檔案的位置.
30854
		$conf["xml::getContent"]["xmlPosition"]=$conf["mmFile"];
30855
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
30856
		$conf["xml::getContent"]["fileArgu"]=__FILE__;
30857
		#可省略參數:
30858
		#無.
30859
		#參考資料來源:
30860
		#XML範例檔=>http://msdn.microsoft.com/zh-tw/library/bb387025.aspx
30861
		#simplexml-load-file=>http://php.net/manual/en/function.simplexml-load-file.php
30862
		#取得xml檔案內容的示範=>http://php.net/manual/en/simplexml.examples-basic.php
30863
		#啟用處理xml的錯誤處理=>http://php.net/manual/en/function.libxml-use-internal-errors.php
30864
		#取得處理xml的錯誤訊息=>http://php.net/manual/en/function.libxml-get-errors.php
30865
		#備註:
30866
		#無.
30867
		$getContent=xml::getContent($conf["xml::getContent"]);
30868
		unset($conf["xml::getContent"]);
30869
 
30870
		#如果執行失敗
30871
		if($getContent["status"]==="false"){
30872
 
30873
			#設置執行失敗
30874
			$result["status"]="false";
30875
 
30876
			#設置錯誤訊息
30877
			$result["error"]=$getContent;
30878
 
30879
			#回傳結果
30880
			return $result;
30881
 
30882
			}#if end
30883
 
30884
		#如果xml檔案不存在
30885
		if($getContent["founded"]==="false"){
30886
 
30887
			#設置執行失敗
30888
			$result["status"]="false";
30889
 
30890
			#設置錯誤訊息
30891
			$result["error"]=$getContent;
30892
 
30893
			#回傳結果
30894
			return $result;
30895
 
30896
			}#if end
30897
 
30898
		#初始化要解析的 simeple xml object
30899
		$searchArray=array(&$getContent["content"]);
30900
 
30901
		#有幾個要解析的 simeple xml object 就執行幾次
30902
		for($i=0;$i<count($searchArray);$i++){
30903
 
30904
			#初始化基準點
30905
			$base=&$searchArray[$i];
30906
 
30907
			#如果存在node子階層
30908
			if(isset($base->node)){
30909
 
30910
				#針對每個同名的node階層
30911
				for($j=0;$j<count($base->node);$j++){
30912
 
30913
					#取得階層的位置
30914
					$tempLayer=&($base->node)[$j];
30915
 
30916
					#如果下一層有 hook
30917
					if(isset($tempLayer->hook)){
30918
 
30919
						#針對底下的屬性
30920
						foreach($tempLayer->hook->attributes() as $attrName => $attrValue){
30921
 
30922
							#如果有指定 URI
30923
							if($attrName==="URI" && $attrValue!==""){
30924
 
30925
								#更新 URI 位置
30926
								$tempLayer->hook->attributes()->$attrName=$conf["imgFolder"]."/".basename($attrValue);
30927
 
30928
								#設置 SIZE 為 1.0
30929
								$tempLayer->hook->attributes()->SIZE="1.0";
30930
 
30931
								}#if end
30932
 
30933
							}#foreach end
30934
 
30935
						}#if end
30936
 
30937
					#保存待處理的 simple xml object
30938
					$searchArray[]=&$tempLayer;
30939
 
30940
					}#for end
30941
 
30942
				}#if end
30943
 
30944
			}#for end		
30945
 
30946
		#取得更新後的 simple xml object
30947
		$result["content"]=$getContent["content"];
30948
 
30949
		#建立新 mm 檔案
30950
		#函式說明:
30951
		#將字串寫入到檔案
30952
		#回傳結果:
30953
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
30954
		#$result["error"],錯誤訊息陣列.
30955
		#$result["function"],當前執行的函數名稱.
30956
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
30957
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
30958
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
30959
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
30960
		#$result["argu"],使用的參數.
30961
		#必填參數:
30962
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
30963
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
30964
		#可省略參數:
30965
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
30966
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$conf["output"];
30967
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
30968
		$conf["fileAccess::writeTextIntoFile"]["inputString"]=$getContent["content"]->asXML();
30969
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
30970
		#$conf["writeMethod"]="a";
30971
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
30972
		#$conf["checkRepeat"]="";
30973
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
30974
		#$conf["filenameExtensionStartPoint"]="";
30975
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
30976
		#$conf["repeatNameRule"]="";
30977
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
30978
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
30979
		#參考資料:
30980
		#無.
30981
		#備註:
30982
		#無.
30983
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
30984
		unset($conf["fileAccess::writeTextIntoFile"]);
30985
 
30986
		#如果執行失敗
30987
		if($writeTextIntoFile["status"]==="false"){
30988
 
30989
			#設置執行失敗
30990
			$result["status"]="false";
30991
 
30992
			#設置錯誤訊息
30993
			$result["error"]=$writeTextIntoFile;
30994
 
30995
			#回傳結果
30996
			return $result;
30997
 
30998
			}#if end
30999
 
31000
		#設置執行正常
31001
		$result["status"]="true";
31002
 
31003
		#回傳結果
31004
		return $result;
31005
 
31006
		}#function msPortable end
31007
 
31008
	/*
31009
	#函式說明:
31010
	#使用 linux 的 rsync 指令來進行備份檔案.
31011
	#回傳結果:
31012
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31013
	#$result["error"],錯誤訊息.
31014
	#$result["function"],當前執行的函式名稱.
31015
	#$result["cmd"],執行的指令.
31016
	#必填參數:
31017
	#$conf["source"],字串,需要進行備份的目錄或檔案
31018
	$conf["source"]="";
31019
	#$conf["target"],字串,備份到哪個地方或檔案
31020
	$conf["target"]="";
31021
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
31022
	$conf["fileArgu"]=__FILE__;
31023
	#可省略參數:
31024
	#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要複製,預設為"false".
31025
	#$conf["recursive"]="true";
31026
	#$conf["exclude"],字串陣列,每個元素代表要排除的項目,預設不指定.
31027
	#$conf["exclude"]=array();
31028
	#$conf["excludeFileType"],字串陣列,每個元素代表要排除的副檔名,預設不指定.
31029
	#$conf["excludeFileType"]=array();
31030
	#$conf["bandWidthLimit"],字串,代表頻寬上限,單為可為K、M、G等,預設不指定.
31031
	#$conf["bandWidthLimit"]="";
31032
	#$conf["newFileOnly"],字串,是否只複製比較新的檔案,預設為"true"代表要;反之為"false".
31033
	#$conf["newFileOnly"]="true";
31034
	#$conf["appendMode"],字串,是否用append的方式複製,適用於檔案內同位置內容一樣的檔案,預設值"false"代表不要;反之為"true".
31035
	#$conf["appendMode"]="true";
31036
	#參考資料:
31037
	#無
31038
	#備註:
31039
	#無.
31040
	*/
31041
	public static function rsync(&$conf){
31042
 
31043
		#初始化要回傳的結果
31044
		$result=array();
31045
 
31046
		#取得當前執行的函數名稱
31047
		$result["function"]=__FUNCTION__;
31048
 
31049
		#如果沒有參數
31050
		if(func_num_args()==0){
31051
 
31052
			#設置執行失敗
31053
			$result["status"]="false";
31054
 
31055
			#設置執行錯誤訊息
31056
			$result["error"]="函數".$result["function"]."需要參數";
31057
 
31058
			#回傳結果
31059
			return $result;
31060
 
31061
			}#if end
31062
 
31063
		#取得參數
31064
		$result["argu"]=$conf;
31065
 
31066
		#如果 $conf 不為陣列
31067
		if(gettype($conf)!=="array"){
31068
 
31069
			#設置執行失敗
31070
			$result["status"]="false";
31071
 
31072
			#設置執行錯誤訊息
31073
			$result["error"][]="\$conf變數須為陣列形態";
31074
 
31075
			#如果傳入的參數為 null
31076
			if(is_null($conf)){
31077
 
31078
				#設置執行錯誤訊息
31079
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
31080
 
31081
				}#if end
31082
 
31083
			#回傳結果
31084
			return $result;
31085
 
31086
			}#if end
31087
 
31088
		#函式說明:
31089
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
31090
		#回傳結果:
31091
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31092
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
31093
		#$result["function"],當前執行的函式名稱.
31094
		#$result["argu"],設置給予的參數.
31095
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
31096
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
31097
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
31098
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
31099
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
31100
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
31101
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
31102
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
31103
		#必填參數:
31104
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
31105
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
31106
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
31107
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
31108
		#可省略參數:
31109
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
31110
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("source","target","fileArgu");
31111
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
31112
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
31113
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
31114
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
31115
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
31116
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
31117
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
31118
		#$conf["canBeEmpty"]=array();
31119
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
31120
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("recursive","exclude","excludeFileType","bandWidthLimit","newFileOnly","appendMode");
31121
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
31122
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive","exclude","excludeFileType","bandWidthLimit","newFileOnly","appendMode");
31123
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
31124
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","array","string","string","string");
31125
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
31126
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,null,null,"false","false");
31127
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
31128
		#$conf["disallowAllSkipableVarIsEmpty"]="";
31129
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
31130
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
31131
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
31132
		#$conf["arrayCountEqualCheck"][]=array();
31133
		#參考資料:
31134
		#array_keys=>http://php.net/manual/en/function.array-keys.php
31135
		#備註:
31136
		#無.
31137
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
31138
		unset($conf["variableCheck::checkArguments"]);
31139
 
31140
		#如果執行失敗
31141
		if($checkArguments["status"]==="false"){
31142
 
31143
			#設置執行失敗
31144
			$result["status"]="false";
31145
 
31146
			#設置錯誤訊息
31147
			$result["error"]=$checkArguments;
31148
 
31149
			#回傳結果
31150
			return $result;
31151
 
31152
			}#if end
31153
 
31154
		#如果檢查不通過
31155
		if($checkArguments["passed"]==="false"){
31156
 
31157
			#設置執行失敗
31158
			$result["status"]="false";
31159
 
31160
			#設置錯誤訊息
31161
			$result["error"]=$checkArguments;
31162
 
31163
			#回傳結果
31164
			return $result;
31165
 
31166
			}#if end
31167
 
31168
		#確認 $conf["source"] 存在
31169
		#函式說明:
31170
		#檢查多個檔案與資料夾是否存在.
31171
		#回傳的結果:
31172
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
31173
		#$result["error"],錯誤訊息陣列.
31174
		#$resutl["function"],當前執行的涵式名稱.
31175
		#$result["argu"],使用的參數.
31176
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
31177
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
31178
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
31179
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
31180
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
31181
		#必填參數:
31182
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
31183
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["source"]);
31184
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
31185
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
31186
		#可省略參數:
31187
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
31188
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
31189
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
31190
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
31191
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
31192
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
31193
		#參考資料:
31194
		#http://php.net/manual/en/function.file-exists.php
31195
		#http://php.net/manual/en/control-structures.foreach.php
31196
		#備註:
31197
		#函數file_exists檢查的路徑為檔案系統的路徑
31198
		#$result["varName"][$i]結果未實作
31199
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
31200
		unset($conf["fileAccess::checkMultiFileExist"]);
31201
 
31202
		#如果執行失敗
31203
		if($checkMultiFileExist["status"]==="false"){
31204
 
31205
			#設置執行失敗
31206
			$result["status"]="false";
31207
 
31208
			#設置錯誤訊息
31209
			$result["error"]=$checkMultiFileExist;
31210
 
31211
			#回傳結果
31212
			return $result;
31213
 
31214
			}#if end
31215
 
31216
		#如果 source 不存在
31217
		if($checkMultiFileExist["allExist"]==="false"){
31218
 
31219
			#設置執行失敗
31220
			$result["status"]="false";
31221
 
31222
			#設置錯誤訊息
31223
			$result["error"]=$checkMultiFileExist;
31224
 
31225
			#回傳結果
31226
			return $result;
31227
 
31228
			}#if end
31229
 
31230
		#如果要複製的目標不為 "/" 結尾
31231
		#函式說明:
31232
		#取得符合特定字首與字尾的字串
31233
		#回傳結果:
31234
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
31235
		#$result["function"],當前執行的函數名稱.
31236
		#$result["error"],錯誤訊息陣列.
31237
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
31238
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
31239
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
31240
		#$result["argu"],使用的參數.
31241
		#必填參數:
31242
		#$conf["checkString"],字串,要檢查的字串.
31243
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["source"];
31244
		#可省略參數:
31245
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
31246
		#$conf["frontWord"]="";
31247
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
31248
		$conf["search::getMeetConditionsString"]["tailWord"]="/";
31249
		#參考資料:
31250
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
31251
		#備註:
31252
		#無.
31253
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
31254
		unset($conf["search::getMeetConditionsString"]);
31255
 
31256
		#如果執行失敗
31257
		if($getMeetConditionsString["status"]==="false"){
31258
 
31259
			#設置執行失敗
31260
			$result["status"]="false";
31261
 
31262
			#設置錯誤訊息
31263
			$result["error"]=$getMeetConditionsString;
31264
 
31265
			#回傳結果
31266
			return $result;
31267
 
31268
			}#if end
31269
 
31270
		#如果不是"/"結尾
31271
		if($getMeetConditionsString["founded"]==="false"){
31272
 
31273
			#來源不是資料夾
31274
			$sourceIsFolder="false";
31275
 
31276
			#取得來源目錄或檔案的資訊
31277
			#函式說明:
31278
			#取得節點的資訊.
31279
			#回傳結果:
31280
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
31281
			#$result["error"],錯誤訊息陣列.
31282
			#$result["function"],函數名稱. 
31283
			#$result["content"],檔案資訊陣列.
31284
			#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.	
31285
			#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
31286
			#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
31287
			#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
31288
			#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
31289
			#$result["content"]["ownerName"],檔案擁有着資訊.
31290
			#$result["content"]["groupName"],檔案所屬擁有着資訊.
31291
			#$result["content"]["size"],檔案大小.
31292
			#$result["content"]["modifyDate"],檔案變更年月日.
31293
			#$result["content"]["modifyTime"],檔案變更時分秒.
31294
			#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
31295
			#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
31296
			#必填參數:
31297
			#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
31298
			$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
31299
			#$conf["file"],字串,要查看擁有者資訊的檔案.
31300
			$conf["fileAccess::fileInfo"]["file"]=$conf["source"];
31301
			#可省略參數:
31302
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
31303
			$conf["fileAccess::fileInfo"]["web"]="false";
31304
			#參考資料:
31305
			#fileowner=>http://php.net/manual/en/function.fileowner.php
31306
			#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
31307
			#備註:
31308
			$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
31309
			unset($conf["fileAccess::fileInfo"]);
31310
 
31311
			#如果執行失敗
31312
			if($fileInfo["status"]==="false"){
31313
 
31314
				#設置執行失敗
31315
				$result["status"]="false";
31316
 
31317
				#設置錯誤訊息
31318
				$result["error"]=$fileInfo;
31319
 
31320
				#回傳結果
31321
				return $result;
31322
 
31323
				}#if end
31324
 
31325
			#如果要複製的目標為目錄
31326
			if($fileInfo["content"]["is_folder"]==="true"){
31327
 
31328
				#來源是資料夾
31329
				$sourceIsFolder="true";
31330
 
31331
				#結尾加上"/"
31332
				$conf["source"]=$conf["source"]."/";
31333
 
31334
				}#if end
31335
 
31336
			}#if end
31337
 
31338
		#反之來源為資料夾
31339
		else{
31340
 
31341
			#來源是資料夾
31342
			$sourceIsFolder="true";
31343
 
31344
			}#else end
31345
 
31346
		#函式說明:
31347
		#取得符合特定字首與字尾的字串
31348
		#回傳結果:
31349
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
31350
		#$result["function"],當前執行的函數名稱.
31351
		#$result["error"],錯誤訊息陣列.
31352
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
31353
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
31354
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
31355
		#$result["argu"],使用的參數.
31356
		#必填參數:
31357
		#$conf["checkString"],字串,要檢查的字串.
31358
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["target"];
31359
		#可省略參數:
31360
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
31361
		#$conf["frontWord"]="";
31362
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
31363
		$conf["search::getMeetConditionsString"]["tailWord"]="/";
31364
		#參考資料:
31365
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
31366
		#備註:
31367
		#無.
31368
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
31369
		unset($conf["search::getMeetConditionsString"]);
31370
 
31371
		#如果執行失敗
31372
		if($getMeetConditionsString["status"]==="false"){
31373
 
31374
			#設置執行失敗
31375
			$result["status"]="false";
31376
 
31377
			#設置錯誤訊息
31378
			$result["error"]=$getMeetConditionsString;
31379
 
31380
			#回傳結果
31381
			return $result;
31382
 
31383
			}#if end
31384
 
31385
		#如果不是 "/" 結尾
31386
		if($getMeetConditionsString["founded"]==="false"){
31387
 
31388
			#檢查要複製到的目標所屬路徑是否存在
31389
			#函式說明:
31390
			#檢查路徑是否存在.
31391
			#回傳結果:
31392
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
31393
			#$result["error"],錯誤訊息陣列.
31394
			#$resutl["function"],當前執行的涵式名稱.
31395
			#$result["argu"],使用的參數.
31396
			#$result["found"],路徑是否存在,"true"代表存在,"false"代表不存在.
31397
			#$result["content"],每個階層路徑的檢查結果,每個元素有檢查的路徑"path"跟是否有存在或可存取的識別"found".
31398
			#必填參數:
31399
			#$conf["path"],要檢查的路徑
31400
			$conf["fileAccess::checkPathExist"]["path"]=$conf["target"];
31401
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
31402
			$conf["fileAccess::checkPathExist"]["fileArgu"]=$conf["fileArgu"];
31403
			#可省略參數:
31404
			#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
31405
			#$conf["fileAccess::checkPathExist"]["haveFileName"]="true";
31406
			#參考資料:
31407
			#無.
31408
			#備註:
31409
			#無.
31410
			$checkPathExist=fileAccess::checkPathExist($conf["fileAccess::checkPathExist"]);
31411
			unset($conf["fileAccess::checkPathExist"]);
31412
 
31413
			#如果執行失敗
31414
			if($checkPathExist["status"]==="false"){
31415
 
31416
				#設置執行失敗
31417
				$result["status"]="false";
31418
 
31419
				#設置錯誤訊息
31420
				$result["error"]=$checkPathExist;
31421
 
31422
				#回傳結果
31423
				return $result;
31424
 
31425
				}#if end
31426
 
31427
			#目的不是資料夾
31428
			$targetIsFolder="false";
31429
 
31430
			#如果路徑都存在
31431
			if($checkPathExist["found"]==="true"){
31432
 
31433
				#取得目標檔案的資訊
31434
				#函式說明:
31435
				#取得節點的資訊.
31436
				#回傳結果:
31437
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
31438
				#$result["error"],錯誤訊息陣列.
31439
				#$result["function"],函數名稱. 
31440
				#$result["content"],檔案資訊陣列.
31441
				#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.	
31442
				#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
31443
				#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
31444
				#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
31445
				#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
31446
				#$result["content"]["ownerName"],檔案擁有着資訊.
31447
				#$result["content"]["groupName"],檔案所屬擁有着資訊.
31448
				#$result["content"]["size"],檔案大小.
31449
				#$result["content"]["modifyDate"],檔案變更年月日.
31450
				#$result["content"]["modifyTime"],檔案變更時分秒.
31451
				#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
31452
				#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
31453
				#必填參數:
31454
				#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
31455
				$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
31456
				#$conf["file"],字串,要查看擁有者資訊的檔案.
31457
				$conf["fileAccess::fileInfo"]["file"]=$conf["target"];
31458
				#可省略參數:
31459
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
31460
				$conf["fileAccess::fileInfo"]["web"]="false";
31461
				#參考資料:
31462
				#fileowner=>http://php.net/manual/en/function.fileowner.php
31463
				#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
31464
				#備註:
31465
				$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
31466
				unset($conf["fileAccess::fileInfo"]);
31467
 
31468
				#如果執行失敗
31469
				if($fileInfo["status"]==="false"){
31470
 
31471
					#設置執行失敗
31472
					$result["status"]="false";
31473
 
31474
					#設置錯誤訊息
31475
					$result["error"]=$fileInfo;
31476
 
31477
					#回傳結果
31478
					return $result;
31479
 
31480
					}#if end
31481
 
31482
				#如果要複製到的目標為目錄
31483
				if($fileInfo["content"]["is_folder"]==="true"){
31484
 
31485
					#目的是資料夾
31486
					$targetIsFolder="true";
31487
 
31488
					#結尾加上"/"
31489
					$conf["target"]=$conf["target"]."/";
31490
 
31491
					}#if end
31492
 
31493
				}#if end
31494
 
31495
			}#if end
31496
 
31497
		#反之
31498
		else{
31499
 
31500
			#目的是資料夾
31501
			$targetIsFolder="true";
31502
 
31503
			}#else end
31504
 
31505
		#如果來源跟目標不同為檔案為目錄
31506
		if($sourceIsFolder!==$targetIsFolder){
31507
 
31508
			#設置執行失敗
31509
			$result["status"]="false";
31510
 
31511
			#設置錯誤訊息
31512
			$result["error"][]="複製的來源與目標須同樣為目錄或檔案";
31513
 
31514
			#回傳結果
31515
			return $result;
31516
 
31517
			}#if end
31518
 
31519
		#初始化給 rsync 的參數
31520
		$params_for_rsync=array("-v","--progress","--links");
31521
 
31522
		#如果目錄底下的內容也要複製
31523
		if($conf["recursive"]==="true"){
31524
 
31525
			#設置目錄底下的內容也要複製
31526
			$params_for_rsync[]="-r";
31527
 
31528
			}#if end
31529
 
31530
		#如果有設置頻寬限制
31531
		if(isset($conf["bandWidthLimit"])){
31532
 
31533
			#設置頻寬限制參數
31534
			$params_for_rsync[]="--bwlimit";
31535
 
31536
			#設置頻寬限制參數數值
31537
			$params_for_rsync[]=$conf["bandWidthLimit"];
31538
 
31539
			}#if end
31540
 
31541
		#如果有設置只要複製比較新的檔案
31542
		if($conf["newFileOnly"]==="true"){
31543
 
31544
			#設置只要複製比較新的檔案
31545
			$params_for_rsync[]="--update";
31546
 
31547
			}#if end
31548
 
31549
		#如果要用append的方法
31550
		if($conf["appendMode"]==="true"){
31551
 
31552
			#設置要用append的方法
31553
			$params_for_rsync[]="--append";
31554
 
31555
			}#if end
31556
 
31557
		#如果有排除特定檔案或目錄
31558
		if(isset($conf["exclude"])){
31559
 
31560
			#針對每個要排除的檔案或目錄
31561
			foreach($conf["exclude"] as $excludeSource){
31562
 
31563
				#設置要排除的檔案或目錄
31564
				$params_for_rsync[]="--exclude=".$excludeSource;
31565
 
31566
				}#foreach end
31567
 
31568
			}#if end
31569
 
31570
		#如果有排除特定檔案類型
31571
		if(isset($conf["excludeFileType"])){
31572
 
31573
			#針對每個要排除的檔案類型
31574
			foreach($conf["excludeFileType"] as $excludeSource){
31575
 
31576
				#設置要排除的檔案類型
31577
				$params_for_rsync[]="--exclude=\"*.".$excludeSource."\"";
31578
 
31579
				}#foreach end
31580
 
31581
			}#if end
31582
 
31583
		#如果要複製的目標不是 ./ 開頭
31584
		#函式說明:
31585
		#取得符合特定字首與字尾的字串
31586
		#回傳結果:
31587
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
31588
		#$result["function"],當前執行的函數名稱.
31589
		#$result["error"],錯誤訊息陣列.
31590
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
31591
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
31592
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
31593
		#$result["argu"],使用的參數.
31594
		#必填參數:
31595
		#$conf["checkString"],字串,要檢查的字串.
31596
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["source"];
31597
		#可省略參數:
31598
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
31599
		$conf["search::getMeetConditionsString"]["frontWord"]="./";
31600
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
31601
		#$conf["tailWord"]="";
31602
		#參考資料:
31603
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
31604
		#備註:
31605
		#無.
31606
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
31607
		unset($conf["search::getMeetConditionsString"]);
31608
 
31609
		#如果執行失敗
31610
		if($getMeetConditionsString["status"]==="false"){
31611
 
31612
			#設置執行失敗
31613
			$result["status"]="false";
31614
 
31615
			#設置錯誤訊息
31616
			$result["error"]=$getMeetConditionsString;
31617
 
31618
			#回傳結果
31619
			return $result;
31620
 
31621
			}#if end
31622
 
31623
		#如果沒有符合
31624
		if($getMeetConditionsString["founded"]==="false"){
31625
 
31626
			#如果要複製的目標不是 / 開頭
31627
			#函式說明:
31628
			#取得符合特定字首與字尾的字串
31629
			#回傳結果:
31630
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
31631
			#$result["function"],當前執行的函數名稱.
31632
			#$result["error"],錯誤訊息陣列.
31633
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
31634
			#$result["content"],符合條件的字串,去掉字首字尾後的結果.
31635
			#$result["returnString"],爲符合字首字、尾條件的字串內容。
31636
			#$result["argu"],使用的參數.
31637
			#必填參數:
31638
			#$conf["checkString"],字串,要檢查的字串.
31639
			$conf["search::getMeetConditionsString"]["checkString"]=$conf["source"];
31640
			#可省略參數:
31641
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
31642
			$conf["search::getMeetConditionsString"]["frontWord"]="/";
31643
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
31644
			#$conf["tailWord"]="";
31645
			#參考資料:
31646
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
31647
			#備註:
31648
			#無.
31649
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
31650
			unset($conf["search::getMeetConditionsString"]);
31651
 
31652
			#如果執行失敗
31653
			if($getMeetConditionsString["status"]==="false"){
31654
 
31655
				#設置執行失敗
31656
				$result["status"]="false";
31657
 
31658
				#設置錯誤訊息
31659
				$result["error"]=$getMeetConditionsString;
31660
 
31661
				#回傳結果
31662
				return $result;
31663
 
31664
				}#if end
31665
 
31666
			#如果沒有符合
31667
			if($getMeetConditionsString["founded"]==="false"){
31668
 
31669
				#加上 "./" 變成絕對位置,避免"::"被視為其他含義
31670
				$conf["source"]="./".$conf["source"];
31671
 
31672
				}#if end
31673
 
31674
			}#if end
31675
 
31676
		#設置要複製的目標
31677
		$params_for_rsync[]=$conf["source"];
31678
 
31679
		#如果要複製的目標不是 ./ 開頭
31680
		#函式說明:
31681
		#取得符合特定字首與字尾的字串
31682
		#回傳結果:
31683
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
31684
		#$result["function"],當前執行的函數名稱.
31685
		#$result["error"],錯誤訊息陣列.
31686
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
31687
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
31688
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
31689
		#$result["argu"],使用的參數.
31690
		#必填參數:
31691
		#$conf["checkString"],字串,要檢查的字串.
31692
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["target"];
31693
		#可省略參數:
31694
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
31695
		$conf["search::getMeetConditionsString"]["frontWord"]="./";
31696
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
31697
		#$conf["tailWord"]="";
31698
		#參考資料:
31699
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
31700
		#備註:
31701
		#無.
31702
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
31703
		unset($conf["search::getMeetConditionsString"]);
31704
 
31705
		#如果執行失敗
31706
		if($getMeetConditionsString["status"]==="false"){
31707
 
31708
			#設置執行失敗
31709
			$result["status"]="false";
31710
 
31711
			#設置錯誤訊息
31712
			$result["error"]=$getMeetConditionsString;
31713
 
31714
			#回傳結果
31715
			return $result;
31716
 
31717
			}#if end
31718
 
31719
		#如果沒有符合
31720
		if($getMeetConditionsString["founded"]==="false"){
31721
 
31722
			#如果要複製的目標不是 / 開頭
31723
			#函式說明:
31724
			#取得符合特定字首與字尾的字串
31725
			#回傳結果:
31726
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
31727
			#$result["function"],當前執行的函數名稱.
31728
			#$result["error"],錯誤訊息陣列.
31729
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
31730
			#$result["content"],符合條件的字串,去掉字首字尾後的結果.
31731
			#$result["returnString"],爲符合字首字、尾條件的字串內容。
31732
			#$result["argu"],使用的參數.
31733
			#必填參數:
31734
			#$conf["checkString"],字串,要檢查的字串.
31735
			$conf["search::getMeetConditionsString"]["checkString"]=$conf["target"];
31736
			#可省略參數:
31737
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
31738
			$conf["search::getMeetConditionsString"]["frontWord"]="/";
31739
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
31740
			#$conf["tailWord"]="";
31741
			#參考資料:
31742
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
31743
			#備註:
31744
			#無.
31745
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
31746
			unset($conf["search::getMeetConditionsString"]);
31747
 
31748
			#如果執行失敗
31749
			if($getMeetConditionsString["status"]==="false"){
31750
 
31751
				#設置執行失敗
31752
				$result["status"]="false";
31753
 
31754
				#設置錯誤訊息
31755
				$result["error"]=$getMeetConditionsString;
31756
 
31757
				#回傳結果
31758
				return $result;
31759
 
31760
				}#if end
31761
 
31762
			#如果沒有符合
31763
			if($getMeetConditionsString["founded"]==="false"){
31764
 
31765
				#加上 "./" 變成絕對位置,避免"::"被視為其他含義
31766
				$conf["target"]="./".$conf["target"];
31767
 
31768
				}#if end
31769
 
31770
			}#if end
31771
 
31772
		#設置要備份到的位置或檔案名稱
31773
		$params_for_rsync[]=$conf["target"];
31774
 
31775
		#執行rsync指令
31776
		#函式說明:
31777
		#呼叫shell執行系統命令,並取得回傳的內容.
31778
		#回傳結果:
31779
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31780
		#$result["error"],錯誤訊息陣列.
31781
		#$result["function"],當前執行的函數名稱.
31782
		#$result["argu"],使用的參數.
31783
		#$result["cmd"],執行的指令內容.
31784
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
31785
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
31786
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
31787
		#$result["running"],是否還在執行.
31788
		#$result["pid"],pid.
31789
		#$result["statusCode"],執行結束後的代碼.
31790
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
31791
		#必填參數:
31792
		#$conf["command"],字串,要執行的指令.
31793
		$conf["external::callShell"]["command"]="rsync";
31794
		#$conf["fileArgu"],字串,變數__FILE__的內容.
31795
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
31796
		#可省略參數:
31797
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
31798
		$conf["external::callShell"]["argu"]=$params_for_rsync;
31799
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
31800
		#$conf["arguIsAddr"]=array();
31801
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
31802
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
31803
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
31804
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
31805
		#$conf["enablePrintDescription"]="true";
31806
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
31807
		#$conf["printDescription"]="";
31808
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
31809
		$conf["external::callShell"]["escapeshellarg"]="true";
31810
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
31811
		#$conf["thereIsShellVar"]=array();
31812
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
31813
		#$conf["username"]="";
31814
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
31815
		#$conf["password"]="";
31816
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
31817
		#$conf["useScript"]="";
31818
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
31819
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
31820
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
31821
		#$conf["inBackGround"]="";
31822
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
31823
		#$conf["getErr"]="false";
31824
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
31825
		#$conf["doNotRun"]="false";
31826
		#參考資料:
31827
		#exec=>http://php.net/manual/en/function.exec.php
31828
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
31829
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
31830
		#備註:
31831
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
31832
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
31833
		$callShell=external::callShell($conf["external::callShell"]);
31834
		unset($conf["external::callShell"]);
31835
 
31836
		#如果執行失敗
31837
		if($callShell["status"]==="false"){
31838
 
31839
			#設置執行失敗
31840
			$result["status"]="false";
31841
 
31842
			#設置錯誤訊息
31843
			$result["error"]=$callShell;
31844
 
31845
			#回傳結果
31846
			return $result;
31847
 
31848
			}#if end
31849
 
31850
		#設置執行正常
31851
		$result["status"]="true";
31852
 
31853
		#設置執行完的回應
31854
		$result["content"]=$callShell["output"];
31855
 
31856
		#回傳結果
31857
		return $result;
31858
 
31859
		}#function rsync end
31860
 
31861
	/*
31862
	#函式說明:
31863
	#使用 linux 的 httpd 指令來取得 vhost 資訊.
31864
	#回傳結果:
31865
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31866
	#$result["error"],錯誤訊息.
31867
	#$result["function"],當前執行的函式名稱.
31868
	#$result["content"],得到的結果陣列,每個元素可能會含有的key有ServerName、DocumentRoot、ServerAlias,其中DocumentRoot的數值會是用""包起來的路徑.
31869
	#必填參數:
31870
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
31871
	$conf["fileArgu"]=__FILE__;
31872
	#可省略參數:
31873
	#$conf["defaultConfig"],字串,httpd預設的設定檔位置,預設為"/etc/httpd/conf/http.conf".
31874
	#$conf["defaultConfig"]="";
31875
	#參考資料:
31876
	#無
31877
	#備註:
31878
	#無.
31879
	*/
31880
	public static function httpdGetVhostInfo(&$conf){
31881
 
31882
		#初始化要回傳的結果
31883
		$result=array();
31884
 
31885
		#取得當前執行的函數名稱
31886
		$result["function"]=__FUNCTION__;
31887
 
31888
		#如果沒有參數
31889
		if(func_num_args()==0){
31890
 
31891
			#設置執行失敗
31892
			$result["status"]="false";
31893
 
31894
			#設置執行錯誤訊息
31895
			$result["error"]="函數".$result["function"]."需要參數";
31896
 
31897
			#回傳結果
31898
			return $result;
31899
 
31900
			}#if end
31901
 
31902
		#取得參數
31903
		$result["argu"]=$conf;
31904
 
31905
		#如果 $conf 不為陣列
31906
		if(gettype($conf)!=="array"){
31907
 
31908
			#設置執行失敗
31909
			$result["status"]="false";
31910
 
31911
			#設置執行錯誤訊息
31912
			$result["error"][]="\$conf變數須為陣列形態";
31913
 
31914
			#如果傳入的參數為 null
31915
			if(is_null($conf)){
31916
 
31917
				#設置執行錯誤訊息
31918
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
31919
 
31920
				}#if end
31921
 
31922
			#回傳結果
31923
			return $result;
31924
 
31925
			}#if end
31926
 
31927
		#函式說明:
31928
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
31929
		#回傳結果:
31930
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31931
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
31932
		#$result["function"],當前執行的函式名稱.
31933
		#$result["argu"],設置給予的參數.
31934
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
31935
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
31936
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
31937
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
31938
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
31939
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
31940
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
31941
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
31942
		#必填參數:
31943
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
31944
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
31945
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
31946
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
31947
		#可省略參數:
31948
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
31949
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
31950
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
31951
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
31952
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
31953
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
31954
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
31955
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
31956
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
31957
		#$conf["canBeEmpty"]=array();
31958
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
31959
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("defaultConfig");
31960
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
31961
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("defaultConfig");
31962
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
31963
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
31964
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
31965
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/etc/httpd/conf/httpd.conf");
31966
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
31967
		#$conf["disallowAllSkipableVarIsEmpty"]="";
31968
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
31969
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
31970
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
31971
		#$conf["arrayCountEqualCheck"][]=array();
31972
		#參考資料:
31973
		#array_keys=>http://php.net/manual/en/function.array-keys.php
31974
		#備註:
31975
		#無.
31976
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
31977
		unset($conf["variableCheck::checkArguments"]);
31978
 
31979
		#如果執行失敗
31980
		if($checkArguments["status"]==="false"){
31981
 
31982
			#設置執行失敗
31983
			$result["status"]="false";
31984
 
31985
			#設置錯誤訊息
31986
			$result["error"]=$checkArguments;
31987
 
31988
			#回傳結果
31989
			return $result;
31990
 
31991
			}#if end
31992
 
31993
		#如果檢查不通過
31994
		if($checkArguments["passed"]==="false"){
31995
 
31996
			#設置執行失敗
31997
			$result["status"]="false";
31998
 
31999
			#設置錯誤訊息
32000
			$result["error"]=$checkArguments;
32001
 
32002
			#回傳結果
32003
			return $result;
32004
 
32005
			}#if end
32006
 
32007
		#取得設定檔的內容
32008
		#函式說明:
32009
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
32010
		#回傳的變數說明:
32011
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
32012
		#$result["error"],錯誤訊息提示.
32013
		#$result["warning"],警告訊息.
32014
		#$result["function"],當前執行的函數名稱.
32015
		#$result["fileContent"],爲檔案的內容陣列.
32016
		#$result["lineCount"],爲檔案內容總共的行數.
32017
		#$result["fullContent"],為檔案的完整內容.
32018
		#$result["base64data"],為檔案的base64內容.
32019
		#$result["mimeType"],為檔案的mime type.
32020
		#必填參數:
32021
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
32022
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["defaultConfig"];
32023
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
32024
		$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
32025
		#可省略參數:
32026
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
32027
		#$conf["web"]="true";
32028
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
32029
		#$conf["createIfnotExist"]="false";
32030
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
32031
		$conf["fileAccess::getFileContent"]["autoDeleteSpaceOnEachLineStart"]="true";
32032
		#參考資料:
32033
		#file(),取得檔案內容的行數.
32034
		#file=>http:#php.net/manual/en/function.file.php
32035
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
32036
		#filesize=>http://php.net/manual/en/function.filesize.php
32037
		#參考資料:
32038
		#無.
32039
		#備註:
32040
		#無.
32041
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
32042
		unset($conf["fileAccess::getFileContent"]);
32043
 
32044
		#如果執行失敗
32045
		if($getFileContent["status"]==="false"){
32046
 
32047
			#設置執行失敗
32048
			$result["status"]="false";
32049
 
32050
			#設置錯誤訊息
32051
			$result["error"]=$getFileContent;
32052
 
32053
			#回傳結果
32054
			return $result;
32055
 
32056
			}#if end
32057
 
32058
		#取得 default Listen Add、port - start
32059
 
32060
		/*
32061
		#ipv4+port
32062
		Listen 12.34.56.78:80
32063
		*/
32064
 
32065
		/*
32066
		#port only
32067
		Listen 80
32068
		*/
32069
 
32070
		#函式說明:
32071
		#取得符合多個特定字首與字尾之一的字串們
32072
		#回傳結果:
32073
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
32074
		#$result["function"],當前執行的函數名稱.
32075
		#$result["error"],錯誤訊息陣列.
32076
		#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
32077
		#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.
32078
		#$result["argu"],使用的參數.
32079
		#必填參數:
32080
		#$conf["checkString"],陣列字串,要檢查的陣列字串.
32081
		$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];
32082
		#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.
32083
		$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"Listen "),array("front"=>"DocumentRoot "));
32084
		#可省略參數:
32085
		#無.
32086
		#參考資料:
32087
		#無.
32088
		#備註:
32089
		#無.
32090
		$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);
32091
		unset($conf["search::getMeetMultiConditionsStrings"]);
32092
 
32093
		#如果執行失敗
32094
		if($getMeetMultiConditionsStrings["status"]==="false"){
32095
 
32096
			#設置執行失敗
32097
			$result["status"]="false";
32098
 
32099
			#設置錯誤訊息
32100
			$result["error"]=$getMeetMultiConditionsStrings;
32101
 
32102
			#回傳結果
32103
			return $result;
32104
 
32105
			}#if end
32106
 
32107
		#如果沒有需要的關鍵字存在
32108
		if($getMeetMultiConditionsStrings["found"]==="false"){
32109
 
32110
			#設置執行失敗
32111
			$result["status"]="false";
32112
 
32113
			#設置錯誤訊息
32114
			$result["error"]=$getMeetMultiConditionsStrings;
32115
 
32116
			#回傳結果
32117
			return $result;
32118
 
32119
			}#if end
32120
 
32121
		#解析 Listen and port and Document string
32122
 
32123
		#針對每個 section
32124
		foreach($getMeetMultiConditionsStrings["content"] as $section){
32125
 
32126
			#取得區段名稱
32127
			$name=$section["meetConditions"]["front"];
32128
 
32129
			#取得設定檔中該行的內容
32130
			$lineDef=$section["oriStr"];
32131
 
32132
			#取得設定檔中該行定義的數值
32133
			$lineVal=$section["content"];
32134
 
32135
			#判斷是哪個區段名稱
32136
			switch($name){
32137
 
32138
				#如果是 Listen 區段
32139
				case "Listen ":
32140
 
32141
					#函式說明:
32142
					#將固定格式的字串分開,並回傳分開的結果.
32143
					#回傳結果:
32144
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32145
					#$result["error"],錯誤訊息陣列
32146
					#$result["function"],當前執行的函數名稱.
32147
					#$result["argu"],使用的參數.
32148
					#$result["oriStr"],要分割的原始字串內容
32149
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
32150
					#$result["dataCounts"],爲總共分成幾段
32151
					#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
32152
					#必填參數:
32153
					#$conf["stringIn"],字串,要處理的字串.
32154
					$conf["stringProcess::spiltString"]["stringIn"]=$lineVal;
32155
					#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
32156
					$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
32157
					#可省略參數:
32158
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
32159
					#$conf["allowEmptyStr"]="false";
32160
					#參考資料:
32161
					#無.
32162
					#備註:
32163
					#無.
32164
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
32165
					unset($conf["stringProcess::spiltString"]);
32166
 
32167
					#如果執行失敗
32168
					if($spiltString["status"]==="false"){
32169
 
32170
						#設置執行失敗
32171
						$result["status"]="false";
32172
 
32173
						#設置錯誤訊息
32174
						$result["error"]=$spiltString;
32175
 
32176
						#回傳結果
32177
						return $result;
32178
 
32179
						}#if end
32180
 
32181
					#如果沒有需要的關鍵字存在
32182
					if($spiltString["found"]==="false"){
32183
 
32184
						#代表只有設定 port
32185
 
32186
						#如果沒有 port 存在
32187
						if(!isset($spiltString["dataArray"][0])){
32188
 
32189
							#設置執行失敗
32190
							$result["status"]="false";
32191
 
32192
							#設置錯誤訊息
32193
							$result["error"][]="main configuration of httpd seems not right!";
32194
 
32195
							#設置錯誤訊息
32196
							$result["error"][]=$spiltString;
32197
 
32198
							#回傳結果
32199
							return $result;
32200
 
32201
							}#if end
32202
 
32203
						#確認是否為 只有 listen port
32204
						#函式說明:
32205
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
32206
						#回傳結果:
32207
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32208
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
32209
						#$result["function"],當前執行的函式名稱.
32210
						#$result["argu"],所使用的參數.
32211
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
32212
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
32213
						#必填參數:
32214
						#$conf["input"],字串,要檢查的字串.
32215
						$conf["search::findSpecifyStrFormat"]["input"]=$spiltString["dataArray"][0];
32216
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.
32217
						$conf["search::findSpecifyStrFormat"]["format"]="\${*}";
32218
						#可省略參數:
32219
						#無.
32220
						#參考資料:
32221
						#無.
32222
						#備註:
32223
						#無.
32224
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
32225
						unset($conf["search::findSpecifyStrFormat"]);
32226
 
32227
						#若執行失敗
32228
						if($findSpecifyStrFormat["status"]==="false"){
32229
 
32230
							#設置執行失敗
32231
							$result["status"]="false";
32232
 
32233
							#設置錯誤訊息
32234
							$result["error"]=$findSpecifyStrFormat;
32235
 
32236
							#回傳結果
32237
							return $result;
32238
 
32239
							}#if end
32240
 
32241
						#若符合格式
32242
						if($findSpecifyStrFormat["found"]==="true"){
32243
 
32244
							#設置預設ip
32245
							$defaultIp="*";
32246
 
32247
							#設置預設 port
32248
							$defaultPort=$findSpecifyStrFormat["content"][0];
32249
 
32250
							}#if end
32251
 
32252
						}#if end
32253
 
32254
					#反之如果分成兩段
32255
					else if($spiltString["dataCounts"]===2){
32256
 
32257
						#判斷是否為IPv4+port
32258
						#函式說明:
32259
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
32260
						#回傳結果:
32261
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32262
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
32263
						#$result["function"],當前執行的函式名稱.
32264
						#$result["argu"],所使用的參數.
32265
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
32266
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
32267
						#必填參數:
32268
						#$conf["input"],字串,要檢查的字串.
32269
						$conf["search::findSpecifyStrFormat"]["input"]=$spiltString["dataArray"][1];
32270
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.
32271
						$conf["search::findSpecifyStrFormat"]["format"]="\${*}.\${*}.\${*}.\${*}:\${*}";
32272
						#可省略參數:
32273
						#無.
32274
						#參考資料:
32275
						#無.
32276
						#備註:
32277
						#無.
32278
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
32279
						unset($conf["search::findSpecifyStrFormat"]);
32280
 
32281
						#若執行失敗
32282
						if($findSpecifyStrFormat["status"]==="false"){
32283
 
32284
							#設置執行失敗
32285
							$result["status"]="false";
32286
 
32287
							#設置錯誤訊息
32288
							$result["error"]=$findSpecifyStrFormat;
32289
 
32290
							#回傳結果
32291
							return $result;
32292
 
32293
							}#if end
32294
 
32295
						#若符合格式
32296
						if($findSpecifyStrFormat["found"]==="true"){
32297
 
32298
							#設置預設的listen ip
32299
							$defaultIp=$findSpecifyStrFormat[0].".".$findSpecifyStrFormat[1].".".$findSpecifyStrFormat[2].".".$findSpecifyStrFormat[3];
32300
 
32301
							#設置預設的listen port
32302
							$defaultPort=$findSpecifyStrFormat[4];
32303
 
32304
							}#if end
32305
 
32306
						#反之非 ipv4+port 的格式
32307
						else{
32308
 
32309
							#確認是否為 ipv6 + port
32310
							#函式說明:
32311
							#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
32312
							#回傳結果:
32313
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32314
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
32315
							#$result["function"],當前執行的函式名稱.
32316
							#$result["argu"],所使用的參數.
32317
							#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
32318
							#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
32319
							#必填參數:
32320
							#$conf["input"],字串,要檢查的字串.
32321
							$conf["search::findSpecifyStrFormat"]["input"]=$spiltString["dataArray"][1];
32322
							#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.
32323
							$conf["search::findSpecifyStrFormat"]["format"]="\${*}:\${*}";
32324
							#可省略參數:
32325
							#無.
32326
							#參考資料:
32327
							#無.
32328
							#備註:
32329
							#無.
32330
							$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
32331
							unset($conf["search::findSpecifyStrFormat"]);
32332
 
32333
							#若執行失敗
32334
							if($findSpecifyStrFormat["status"]==="false"){
32335
 
32336
								#設置執行失敗
32337
								$result["status"]="false";
32338
 
32339
								#設置錯誤訊息
32340
								$result["error"]=$findSpecifyStrFormat;
32341
 
32342
								#回傳結果
32343
								return $result;
32344
 
32345
								}#if end
32346
 
32347
							#若符合格式
32348
							if($findSpecifyStrFormat["found"]==="true"){
32349
 
32350
								#設置預設ip
32351
								$defaultIp=$findSpecifyStrFormat["content"][0];
32352
 
32353
								#設置預設 port
32354
								$defaultPort=$findSpecifyStrFormat["content"][1];
32355
 
32356
								}#if end
32357
 
32358
							#反之,格式錯誤
32359
							else{
32360
 
32361
								#設置執行失敗
32362
								$result["status"]="false";
32363
 
32364
								#設置錯誤訊息
32365
								$result["error"][]="main configuration of httpd seems not right!";
32366
 
32367
								#設置錯誤訊息
32368
								$result["error"][]=$findSpecifyStrFormat;
32369
 
32370
								#回傳結果
32371
								return $result;
32372
 
32373
								}#else end
32374
 
32375
							}#else end
32376
 
32377
						}#if end
32378
 
32379
					#反之
32380
					else{
32381
 
32382
						#設置執行失敗
32383
						$result["status"]="false";
32384
 
32385
						#設置錯誤訊息
32386
						$result["error"][]="main configuration of httpd seems not right!";
32387
 
32388
						#設置錯誤訊息
32389
						$result["error"][]=$findSpecifyStrFormat;
32390
 
32391
						#回傳結果
32392
						return $result;
32393
 
32394
						}#else end
32395
 
32396
					#跳出  switch
32397
					break;
32398
 
32399
				#如果是 DocumentRoot 區段
32400
				case "DocumentRoot ":
32401
 
32402
					#函式說明:
32403
					#將固定格式的字串分開,並回傳分開的結果.
32404
					#回傳結果:
32405
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32406
					#$result["error"],錯誤訊息陣列
32407
					#$result["function"],當前執行的函數名稱.
32408
					#$result["argu"],使用的參數.
32409
					#$result["oriStr"],要分割的原始字串內容
32410
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
32411
					#$result["dataCounts"],爲總共分成幾段
32412
					#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
32413
					#必填參數:
32414
					#$conf["stringIn"],字串,要處理的字串.
32415
					$conf["stringProcess::spiltString"]["stringIn"]=$lineDef;
32416
					#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
32417
					$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
32418
					#可省略參數:
32419
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
32420
					#$conf["allowEmptyStr"]="false";
32421
					#參考資料:
32422
					#無.
32423
					#備註:
32424
					#無.
32425
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
32426
					unset($conf["stringProcess::spiltString"]);
32427
 
32428
					#如果執行失敗
32429
					if($spiltString["status"]==="false"){
32430
 
32431
						#設置執行失敗
32432
						$result["status"]="false";
32433
 
32434
						#設置錯誤訊息
32435
						$result["error"]=$spiltString;
32436
 
32437
						#回傳結果
32438
						return $result;
32439
 
32440
						}#if end
32441
 
32442
					#如果沒有關鍵字存在
32443
					if($spiltString["found"]==="false"){
32444
 
32445
						#設置執行失敗
32446
						$result["status"]="false";
32447
 
32448
						#設置錯誤訊息
32449
						$result["error"]=$spiltString;
32450
 
32451
						#回傳結果
32452
						return $result;
32453
 
32454
						}#if end
32455
 
32456
					#如果沒有剛好切割成兩段
32457
					if($spiltString["dataCounts"]!==2){
32458
 
32459
						#設置執行失敗
32460
						$result["status"]="false";
32461
 
32462
						#設置錯誤訊息
32463
						$result["error"]=$spiltString;
32464
 
32465
						#回傳結果
32466
						return $result;
32467
 
32468
						}#if end
32469
 
32470
					#取得預設的 document root
32471
					eval("\$documentRoot=".$spiltString["dataArray"][1].";");
32472
 
32473
					#另存一分預設的 document root
32474
					$defaultDocumentRoot=$documentRoot;
32475
 
32476
					#跳出  switch
32477
					break;
32478
 
32479
				#其他不支援的區段
32480
				default:
32481
 
32482
					#設置執行失敗
32483
					$result["status"]="false";
32484
 
32485
					#設置錯誤訊息
32486
					$result["error"][]="unsupported section:".$getMeetMultiConditionsStrings["content"][0]["meetConditions"]["front"];
32487
 
32488
					#設置錯誤訊息
32489
					$result["error"][]=$getMeetMultiConditionsStrings;
32490
 
32491
					#回傳結果
32492
					return $result;
32493
 
32494
				}#switch end
32495
 
32496
			}#foreach end
32497
 
32498
		#取得 defaut Listen Add、port - end
32499
 
32500
		#取得 ServerName、ServerAlias、DocumentRoot - start
32501
 
32502
		#函式說明:
32503
		#取得符合多個特定字首與字尾之一的字串們
32504
		#回傳結果:
32505
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
32506
		#$result["function"],當前執行的函數名稱.
32507
		#$result["error"],錯誤訊息陣列.
32508
		#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
32509
		#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.
32510
		#$result["argu"],使用的參數.
32511
		#必填參數:
32512
		#$conf["checkString"],陣列字串,要檢查的陣列字串.
32513
		$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];
32514
		#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.
32515
		$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"ServerName"),array("front"=>"DocumentRoot"),array("front"=>"ServerAlias"));
32516
		#可省略參數:
32517
		#無.
32518
		#參考資料:
32519
		#無.
32520
		#備註:
32521
		#無.
32522
		$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);
32523
		unset($conf["search::getMeetMultiConditionsStrings"]);
32524
 
32525
		#如果執行失敗
32526
		if($getMeetMultiConditionsStrings["status"]==="false"){
32527
 
32528
			#設置執行失敗
32529
			$result["status"]="false";
32530
 
32531
			#設置錯誤訊息
32532
			$result["error"]=$getMeetMultiConditionsStrings;
32533
 
32534
			#回傳結果
32535
			return $result;
32536
 
32537
			}#if end
32538
 
32539
		#如果沒有需要的關鍵字存在
32540
		if($getMeetMultiConditionsStrings["found"]==="false"){
32541
 
32542
			#設置執行失敗
32543
			$result["status"]="false";
32544
 
32545
			#設置錯誤訊息
32546
			$result["error"]=$getMeetMultiConditionsStrings;
32547
 
32548
			#回傳結果
32549
			return $result;
32550
 
32551
			}#if end
32552
 
32553
		#如果預設的ip跟port跟document root有缺少任何一個
32554
		if( !isset($defaultIp) || !isset($defaultPort) || !isset($defaultDocumentRoot) ){
32555
 
32556
			#設置執行失敗
32557
			$result["status"]="false";
32558
 
32559
			#設置錯誤訊息
32560
			$result["error"][]="main configuration of httpd seems not right!";
32561
 
32562
			#設置錯誤訊息
32563
			$result["error"][]=$findSpecifyStrFormat;
32564
 
32565
			#回傳結果
32566
			return $result;
32567
 
32568
			}#if end
32569
 
32570
		#初始化vhost的資訊
32571
		$vhostInfo=array("ip"=>$defaultIp,"port"=>$defaultPort,"DocumentRoot"=>$defaultDocumentRoot);
32572
 
32573
		#針對每個找到的結果
32574
		foreach($getMeetMultiConditionsStrings["content"] as $found){
32575
 
32576
			#取得符合的關鍵字/屬性名稱
32577
			$attrName=$found["meetConditions"]["front"];
32578
 
32579
			#取得屬性的數值
32580
			$attrValue=$found["content"];
32581
 
32582
			#移除屬性數值前面的空白
32583
			#函式說明:
32584
			#將字串特定關鍵字與其前面的內容剔除
32585
			#回傳結果:
32586
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32587
			#$result["error"],錯誤訊息陣列.
32588
			#$result["warning"],警告訊息鎮列.
32589
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
32590
			#$result["function"],當前執行的函數名稱.
32591
			#$result["argu"],使用的參數.
32592
			#$result["oriStr"],要處理的原始字串內容.
32593
			#$result["content"],處理好的的字串內容.	
32594
			#必填參數:
32595
			#$conf["stringIn"],字串,要處理的字串.
32596
			$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$attrValue;
32597
			#$conf["keyWord"],字串,特定字串.
32598
			$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
32599
			#可省略參數:
32600
			#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
32601
			$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
32602
			#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
32603
			#$conf["lastResult"]=$delStrBeforeKeyWord;
32604
			#參考資料:
32605
			#無.
32606
			#備註:
32607
			#無.
32608
			$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
32609
			unset($conf["stringProcess::delStrBeforeKeyWord"]);
32610
 
32611
			#如果執行失敗
32612
			if($delStrBeforeKeyWord["status"]==="false"){
32613
 
32614
				#設置執行失敗
32615
				$result["status"]="false";
32616
 
32617
				#設置錯誤訊息
32618
				$result["error"]=$delStrBeforeKeyWord;
32619
 
32620
				#回傳結果
32621
				return $result;
32622
 
32623
				}#if end
32624
 
32625
			#如果不存在開頭的空白
32626
			if($delStrBeforeKeyWord["founded"]==="false"){
32627
 
32628
				#設置執行失敗
32629
				$result["status"]="false";
32630
 
32631
				#設置錯誤訊息
32632
				$result["error"]=$delStrBeforeKeyWord;
32633
 
32634
				#回傳結果
32635
				return $result;
32636
 
32637
				}#if end
32638
 
32639
			#取得移除開頭空格後的屬性數值
32640
			$attrValue=$delStrBeforeKeyWord["content"];
32641
 
32642
			#如果是 server
32643
			if($attrName==="ServerName"){
32644
 
32645
				#判斷 ServerName 的結尾是否為 ":".$port,並移除之.
32646
				#函式說明:
32647
				#將字串特定關鍵字與其後面的內容剔除
32648
				#回傳結果:
32649
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32650
				#$result["error"],錯誤訊息陣列.
32651
				#$result["warning"],警告訊息鎮列.
32652
				#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
32653
				#$result["function"],當前執行的函數名稱.
32654
				#$result["oriStr"],要處理的原始字串內容.
32655
				#$result["content"],處理好的的字串內容.
32656
				#$result["deleted"],被移除的內容.
32657
				#$result["argu"],使用的參數.
32658
				#必填參數:
32659
				#$conf["stringIn"],字串,要處理的字串.
32660
				$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$attrValue;
32661
				#$conf["keyWord"],字串,特定字串.
32662
				$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";
32663
				#可省略參數:
32664
				#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
32665
				#$conf["deleteLastRepeatedOne"]="";
32666
				#參考資料:
32667
				#無.
32668
				#備註:
32669
				#無.
32670
				$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
32671
				unset($conf["stringProcess::delStrAfterKeyWord"]);
32672
 
32673
				#如果執行失敗
32674
				if($delStrAfterKeyWord["status"]==="false"){
32675
 
32676
					#設置執行失敗
32677
					$result["status"]="false";
32678
 
32679
					#設置錯誤訊息
32680
					$result["error"]=$delStrAfterKeyWord;
32681
 
32682
					#回傳結果
32683
					return $result;
32684
 
32685
					}#if end
32686
 
32687
				#如果有符合的關鍵字
32688
				if($delStrAfterKeyWord["founded"]==="true"){
32689
 
32690
					#取得處理好的內容
32691
					$attrValue=$delStrAfterKeyWord["content"];
32692
 
32693
					#更新 port
32694
					$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);
32695
 
32696
					}#if end
32697
 
32698
				}#if end
32699
 
32700
			#如果是 DocumentRoot 的設定
32701
			if($attrName==="DocumentRoot"){
32702
 
32703
				#設置其數值為沒有雙引號的內容
32704
				eval("\$attrValue=".$attrValue.";");
32705
 
32706
				}#if end
32707
 
32708
			#設置 vhost 資訊
32709
			$vhostInfo[$attrName]=$attrValue;
32710
 
32711
			}#foreach end
32712
 
32713
		#儲存解析出來的 vhost 資訊到要回傳的結果
32714
		$result["content"][]=$vhostInfo;
32715
 
32716
		#取得 ServerName、ServerAlias、DocumentRoot - end
32717
 
32718
		#函式說明:
32719
		#呼叫shell執行系統命令,並取得回傳的內容.
32720
		#回傳結果:
32721
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32722
		#$result["error"],錯誤訊息陣列.
32723
		#$result["function"],當前執行的函數名稱.
32724
		#$result["argu"],使用的參數.
32725
		#$result["cmd"],執行的指令內容.
32726
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
32727
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
32728
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
32729
		#$result["running"],是否還在執行.
32730
		#$result["pid"],pid.
32731
		#$result["statusCode"],執行結束後的代碼.
32732
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
32733
		#必填參數:
32734
		#$conf["command"],字串,要執行的指令.
32735
		$conf["external::callShell"]["command"]="httpd";
32736
		#$conf["fileArgu"],字串,變數__FILE__的內容.
32737
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
32738
		#可省略參數:
32739
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
32740
		$conf["external::callShell"]["argu"]=array("-T","-D","DUMP_VHOSTS");
32741
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
32742
		#$conf["arguIsAddr"]=array();
32743
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
32744
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
32745
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
32746
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
32747
		#$conf["enablePrintDescription"]="true";
32748
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
32749
		#$conf["printDescription"]="";
32750
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
32751
		#$conf["escapeshellarg"]="false";
32752
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
32753
		#$conf["thereIsShellVar"]=array();
32754
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
32755
		#$conf["username"]="";
32756
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
32757
		#$conf["password"]="";
32758
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
32759
		#$conf["useScript"]="";
32760
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
32761
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
32762
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
32763
		#$conf["inBackGround"]="";
32764
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
32765
		#$conf["getErr"]="false";
32766
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
32767
		#$conf["doNotRun"]="false";
32768
		#參考資料:
32769
		#exec=>http://php.net/manual/en/function.exec.php
32770
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
32771
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
32772
		#備註:
32773
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
32774
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
32775
		$callShell=external::callShell($conf["external::callShell"]);
32776
		unset($conf["external::callShell"]);
32777
 
32778
		#如果檢查不通過
32779
		if($callShell["status"]==="false"){
32780
 
32781
			#設置執行失敗
32782
			$result["status"]="false";
32783
 
32784
			#設置錯誤訊息
32785
			$result["error"]=$callShell;
32786
 
32787
			#回傳結果
32788
			return $result;
32789
 
32790
			}#if end
32791
 
32792
		/*
32793
		輸出範例
32794
		VirtualHost configuration:
32795
		169.254.1.1:80         latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:1)
32796
		169.254.1.1:443        is a NameVirtualHost
32797
		        default server mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)
32798
		        port 443 namevhost mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)
32799
		                alias www.qbpwcf.org
32800
		                alias qbpwcf.org
32801
		        port 443 namevhost aesopower-svn-free.qbpwcf.org (/etc/httpd/conf.d/aesopower-svn-free.qbpwcf.org.conf:1)
32802
		        port 443 namevhost www.amaztik.com (/etc/httpd/conf.d/amaztik.conf:1)
32803
		        port 443 namevhost bei-jiao24.qbpwcf.org (/etc/httpd/conf.d/bei-jiao24.conf:1)
32804
		        port 443 namevhost egg-roll.qbpwcf.org (/etc/httpd/conf.d/egg-roll.qbpwcf.org.conf:1)
32805
		        port 443 namevhost freedomainandssl.cloudns.asia (/etc/httpd/conf.d/freeDomainAndSSL.conf:1)
32806
		        port 443 namevhost grgralisa-free.qbpwcf.org (/etc/httpd/conf.d/grgralisa-free.qbpwcf.org.conf:1)
32807
		        port 443 namevhost iuqi-free.qbpwcf.org (/etc/httpd/conf.d/iuqi-free.qbpwcf.org.conf:1)
32808
		        port 443 namevhost ajo-free.qbpwcf.org (/etc/httpd/conf.d/proxy-ajo-free.qbpwcf.org.conf:1)
32809
		        port 443 namevhost dlsite.qbpwcf.org (/etc/httpd/conf.d/proxy-dlsite.qbpwcf.org.conf:1)
32810
		        port 443 namevhost iuqi.qbpwcf.org (/etc/httpd/conf.d/proxy-iuqi.qbpwcf.org.conf:1)
32811
		        port 443 namevhost viivatw-free.qbpwcf.org (/etc/httpd/conf.d/proxy-viivatw-free.qbpwcf.org.conf:1)
32812
		        port 443 namevhost ws.qbpwcf.org (/etc/httpd/conf.d/proxy-ws.qbpwcf.org.conf:1)
32813
		                alias sock-ws.qbpwcf.org
32814
		        port 443 namevhost latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:13)
32815
		                alias sock-latest.qbpwcf.org
32816
		        port 443 namevhost sock.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-sock.conf:1)
32817
		        port 443 namevhost svn.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-svn.conf:1)
32818
		        port 443 namevhost sock.freedomainandssl.cloudns.asia (/etc/httpd/conf.d/sock.freeDomainAndSSL.conf:1)
32819
		        port 443 namevhost yao-lan-lesa-free.qbpwcf.org (/etc/httpd/conf.d/yao-lan-lesa-free.qbpwcf.org.conf:1)
32820
		*/
32821
 
32822
		#輸出陣列
32823
		#$callShell["output"];
32824
 
32825
		#初始化搭配的ip與port
32826
		$ipAndPort="";
32827
 
32828
		#針對每行輸出
32829
		for($line=0;$line<count($callShell["output"]);$line++){
32830
 
32831
			#若是第一行
32832
			if($line===0){
32833
 
32834
				#若第一行輸出有錯
32835
				if($callShell["output"][$line]!=="VirtualHost configuration:"){
32836
 
32837
					#設置執行失敗
32838
					$result["status"]="false";
32839
 
32840
					#設置錯誤訊息
32841
					$result["error"]=$callShell["output"];
32842
 
32843
					#設置錯誤訊息
32844
					$result["error"][]="output of VirtualHost configuration seems not right!";
32845
 
32846
					#回傳結果
32847
					return $result;
32848
 
32849
					}#if end
32850
 
32851
				}#if end
32852
 
32853
			#反之
32854
			else{
32855
 
32856
				#函式說明:
32857
				#取得符合特定字首與字尾的字串
32858
				#回傳結果:
32859
				#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
32860
				#$result["function"],當前執行的函數名稱.
32861
				#$result["error"],錯誤訊息陣列.
32862
				#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
32863
				#$result["content"],符合條件的字串,去掉字首字尾後的結果.
32864
				#$result["returnString"],爲符合字首字、尾條件的字串內容。
32865
				#$result["argu"],使用的參數.
32866
				#必填參數:
32867
				#$conf["checkString"],字串,要檢查的字串.
32868
				$conf["search::getMeetConditionsString"]["checkString"]=$callShell["output"][$line];
32869
				#可省略參數:
32870
				#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
32871
				$conf["search::getMeetConditionsString"]["frontWord"]=" ";
32872
				#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
32873
				#$conf["tailWord"]="";
32874
				#參考資料:
32875
				#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
32876
				#備註:
32877
				#無.
32878
				$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
32879
				unset($conf["search::getMeetConditionsString"]);
32880
 
32881
				#如果執行失敗
32882
				if($getMeetConditionsString["status"]==="false"){
32883
 
32884
					#設置執行失敗
32885
					$result["status"]="false";
32886
 
32887
					#設置錯誤訊息
32888
					$result["error"]=$callShell["output"];
32889
 
32890
					#回傳結果
32891
					return $result;
32892
 
32893
					}#if end
32894
 
32895
				#如果該行為空白開頭
32896
				if($getMeetConditionsString["founded"]==="true"){
32897
 
32898
					#若無搭配的ip跟port
32899
					if($ipAndPort===""){
32900
 
32901
						#設置執行失敗
32902
						$result["status"]="false";
32903
 
32904
						#設置錯誤訊息
32905
						$result["error"]=$callShell["output"];
32906
 
32907
						#設置錯誤訊息
32908
						$result["error"][]="output of VirtualHost configuration seems not right!";
32909
 
32910
						#回傳結果
32911
						return $result;
32912
 
32913
						}#if end
32914
 
32915
					#執行到這邊代表輸出為以下格式
32916
					/*
32917
					        default server mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)
32918
					        port 443 namevhost mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)
32919
					                alias www.qbpwcf.org
32920
					                alias qbpwcf.org
32921
					        port 443 namevhost aesopower-svn-free.qbpwcf.org (/etc/httpd/conf.d/aesopower-svn-free.qbpwcf.org.conf:1)
32922
					        port 443 namevhost www.amaztik.com (/etc/httpd/conf.d/amaztik.conf:1)
32923
					        port 443 namevhost bei-jiao24.qbpwcf.org (/etc/httpd/conf.d/bei-jiao24.conf:1)
32924
					        port 443 namevhost egg-roll.qbpwcf.org (/etc/httpd/conf.d/egg-roll.qbpwcf.org.conf:1)
32925
					        port 443 namevhost freedomainandssl.cloudns.asia (/etc/httpd/conf.d/freeDomainAndSSL.conf:1)
32926
					        port 443 namevhost grgralisa-free.qbpwcf.org (/etc/httpd/conf.d/grgralisa-free.qbpwcf.org.conf:1)
32927
					        port 443 namevhost iuqi-free.qbpwcf.org (/etc/httpd/conf.d/iuqi-free.qbpwcf.org.conf:1)
32928
					        port 443 namevhost ajo-free.qbpwcf.org (/etc/httpd/conf.d/proxy-ajo-free.qbpwcf.org.conf:1)
32929
					        port 443 namevhost dlsite.qbpwcf.org (/etc/httpd/conf.d/proxy-dlsite.qbpwcf.org.conf:1)
32930
					        port 443 namevhost iuqi.qbpwcf.org (/etc/httpd/conf.d/proxy-iuqi.qbpwcf.org.conf:1)
32931
					        port 443 namevhost viivatw-free.qbpwcf.org (/etc/httpd/conf.d/proxy-viivatw-free.qbpwcf.org.conf:1)
32932
					        port 443 namevhost ws.qbpwcf.org (/etc/httpd/conf.d/proxy-ws.qbpwcf.org.conf:1)
32933
					                alias sock-ws.qbpwcf.org
32934
					        port 443 namevhost latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:13)
32935
					                alias sock-latest.qbpwcf.org
32936
					        port 443 namevhost sock.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-sock.conf:1)
32937
					        port 443 namevhost svn.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-svn.conf:1)
32938
					        port 443 namevhost sock.freedomainandssl.cloudns.asia (/etc/httpd/conf.d/sock.freeDomainAndSSL.conf:1)
32939
					        port 443 namevhost yao-lan-lesa-free.qbpwcf.org (/etc/httpd/conf.d/yao-lan-lesa-free.qbpwcf.org.conf:1)
32940
					*/
32941
 
32942
					#嘗試移除 "(" 前面的內容
32943
					#函式說明:
32944
					#將字串特定關鍵字與其前面的內容剔除
32945
					#回傳結果:
32946
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32947
					#$result["error"],錯誤訊息陣列.
32948
					#$result["warning"],警告訊息鎮列.
32949
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
32950
					#$result["function"],當前執行的函數名稱.
32951
					#$result["argu"],使用的參數.
32952
					#$result["oriStr"],要處理的原始字串內容.
32953
					#$result["content"],處理好的的字串內容.	
32954
					#必填參數:
32955
					#$conf["stringIn"],字串,要處理的字串.
32956
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$callShell["output"][$line];
32957
					#$conf["keyWord"],字串,特定字串.
32958
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="(";
32959
					#可省略參數:
32960
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
32961
					#$conf["recursive"]="true";
32962
					#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
32963
					#$conf["lastResult"]=$delStrBeforeKeyWord;
32964
					#參考資料:
32965
					#無.
32966
					#備註:
32967
					#無.
32968
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
32969
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
32970
 
32971
					#如果執行失敗
32972
					if($delStrBeforeKeyWord["status"]==="false"){
32973
 
32974
						#設置執行失敗
32975
						$result["status"]="false";
32976
 
32977
						#設置錯誤訊息
32978
						$result["error"]=$delStrBeforeKeyWord;
32979
 
32980
						#回傳結果
32981
						return $result;
32982
 
32983
						}#if end
32984
 
32985
					#如果應該要存在的關鍵字存在
32986
					if($delStrBeforeKeyWord["founded"]==="true"){
32987
 
32988
						#嘗試移除 ")" 後面的內容
32989
						#函式說明:
32990
						#將字串特定關鍵字與其後面的內容剔除
32991
						#回傳結果:
32992
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32993
						#$result["error"],錯誤訊息陣列.
32994
						#$result["warning"],警告訊息鎮列.
32995
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
32996
						#$result["function"],當前執行的函數名稱.
32997
						#$result["oriStr"],要處理的原始字串內容.
32998
						#$result["content"],處理好的的字串內容.
32999
						#$result["argu"],使用的參數.
33000
						#必填參數:
33001
						#$conf["stringIn"],字串,要處理的字串.
33002
						$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
33003
						#$conf["keyWord"],字串,特定字串.
33004
						$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=")";
33005
						#可省略參數:
33006
						#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33007
						#$conf["deleteLastRepeatedOne"]="";
33008
						#參考資料:
33009
						#無.
33010
						#備註:
33011
						#無.
33012
						$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33013
						unset($conf["stringProcess::delStrAfterKeyWord"]);
33014
 
33015
						#如果執行失敗
33016
						if($delStrAfterKeyWord["status"]==="false"){
33017
 
33018
							#設置執行失敗
33019
							$result["status"]="false";
33020
 
33021
							#設置錯誤訊息
33022
							$result["error"]=$delStrAfterKeyWord;
33023
 
33024
							#回傳結果
33025
							return $result;
33026
 
33027
							}#if end
33028
 
33029
						#如果無找到 ")"
33030
						if($delStrAfterKeyWord["founded"]==="false"){
33031
 
33032
							#設置執行失敗
33033
							$result["status"]="false";
33034
 
33035
							#設置錯誤訊息
33036
							$result["error"]=$delStrAfterKeyWord;
33037
 
33038
							#回傳結果
33039
							return $result;
33040
 
33041
							}#if end
33042
 
33043
						#嘗試移除":number"
33044
						#函式說明:
33045
						#將字串特定關鍵字與其後面的內容剔除
33046
						#回傳結果:
33047
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33048
						#$result["error"],錯誤訊息陣列.
33049
						#$result["warning"],警告訊息鎮列.
33050
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33051
						#$result["function"],當前執行的函數名稱.
33052
						#$result["oriStr"],要處理的原始字串內容.
33053
						#$result["content"],處理好的的字串內容.
33054
						#$result["argu"],使用的參數.
33055
						#必填參數:
33056
						#$conf["stringIn"],字串,要處理的字串.
33057
						$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrAfterKeyWord["content"];
33058
						#$conf["keyWord"],字串,特定字串.
33059
						$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";
33060
						#可省略參數:
33061
						#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33062
						$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="true";
33063
						#參考資料:
33064
						#無.
33065
						#備註:
33066
						#無.
33067
						$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33068
						unset($conf["stringProcess::delStrAfterKeyWord"]);
33069
 
33070
						#如果執行失敗
33071
						if($delStrAfterKeyWord["status"]==="false"){
33072
 
33073
							#設置執行失敗
33074
							$result["status"]="false";
33075
 
33076
							#設置錯誤訊息
33077
							$result["error"]=$delStrAfterKeyWord;
33078
 
33079
							#回傳結果
33080
							return $result;
33081
 
33082
							}#if end
33083
 
33084
						#取得 vhost 設定檔案的位置
33085
						$vhostFile=$delStrAfterKeyWord["content"];
33086
 
33087
						#取得設定檔的內容
33088
						#函式說明:
33089
						#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
33090
						#回傳的變數說明:
33091
						#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
33092
						#$result["error"],錯誤訊息提示.
33093
						#$result["warning"],警告訊息.
33094
						#$result["function"],當前執行的函數名稱.
33095
						#$result["fileContent"],爲檔案的內容陣列.
33096
						#$result["lineCount"],爲檔案內容總共的行數.
33097
						#$result["fullContent"],為檔案的完整內容.
33098
						#$result["base64data"],為檔案的base64內容.
33099
						#$result["mimeType"],為檔案的mime type.
33100
						#必填參數:
33101
						#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
33102
						$conf["fileAccess::getFileContent"]["filePositionAndName"]=$vhostFile;
33103
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
33104
						$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
33105
						#可省略參數:
33106
						#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
33107
						#$conf["web"]="true";
33108
						#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
33109
						#$conf["createIfnotExist"]="false";
33110
						#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
33111
						$conf["fileAccess::getFileContent"]["autoDeleteSpaceOnEachLineStart"]="true";
33112
						#參考資料:
33113
						#file(),取得檔案內容的行數.
33114
						#file=>http:#php.net/manual/en/function.file.php
33115
						#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
33116
						#filesize=>http://php.net/manual/en/function.filesize.php
33117
						#參考資料:
33118
						#無.
33119
						#備註:
33120
						#無.
33121
						$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
33122
						unset($conf["fileAccess::getFileContent"]);
33123
 
33124
						#如果執行失敗
33125
						if($getFileContent["status"]==="false"){
33126
 
33127
							#設置執行失敗
33128
							$result["status"]="false";
33129
 
33130
							#設置錯誤訊息
33131
							$result["error"]=$getFileContent;
33132
 
33133
							#回傳結果
33134
							return $result;
33135
 
33136
							}#if end
33137
 
33138
						#符合條件的內容範例
33139
						/*
33140
						DocumentRoot "/var/www/html/qbpwcf"
33141
						ServerName mobile.qbpwcf.org:443
33142
						ServerAlias www.qbpwcf.org
33143
						ServerAlias qbpwcf.org
33144
						*/
33145
 
33146
						#取得 ServerName、ServerAlias、DocumentRoot - start
33147
 
33148
						#函式說明:
33149
						#取得符合多個特定字首與字尾之一的字串們
33150
						#回傳結果:
33151
						#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
33152
						#$result["function"],當前執行的函數名稱.
33153
						#$result["error"],錯誤訊息陣列.
33154
						#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
33155
						#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.
33156
						#$result["argu"],使用的參數.
33157
						#必填參數:
33158
						#$conf["checkString"],陣列字串,要檢查的陣列字串.
33159
						$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];
33160
						#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.
33161
						$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"ServerName"),array("front"=>"DocumentRoot"),array("front"=>"ServerAlias"));
33162
						#可省略參數:
33163
						#無.
33164
						#參考資料:
33165
						#無.
33166
						#備註:
33167
						#無.
33168
						$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);
33169
						unset($conf["search::getMeetMultiConditionsStrings"]);
33170
 
33171
						#如果執行失敗
33172
						if($getMeetMultiConditionsStrings["status"]==="false"){
33173
 
33174
							#設置執行失敗
33175
							$result["status"]="false";
33176
 
33177
							#設置錯誤訊息
33178
							$result["error"]=$getMeetMultiConditionsStrings;
33179
 
33180
							#回傳結果
33181
							return $result;
33182
 
33183
							}#if end
33184
 
33185
						#如果沒有需要的關鍵字存在
33186
						if($getMeetMultiConditionsStrings["found"]==="false"){
33187
 
33188
							#設置執行失敗
33189
							$result["status"]="false";
33190
 
33191
							#設置錯誤訊息
33192
							$result["error"]=$getMeetMultiConditionsStrings;
33193
 
33194
							#回傳結果
33195
							return $result;
33196
 
33197
							}#if end
33198
 
33199
						#初始化vhost的資訊
33200
						$vhostInfo=array("ip"=>$ip,"port"=>$port);
33201
 
33202
						#針對每個找到的結果
33203
						foreach($getMeetMultiConditionsStrings["content"] as $found){
33204
 
33205
							#取得符合的關鍵字/屬性名稱
33206
							$attrName=$found["meetConditions"]["front"];
33207
 
33208
							#取得屬性的數值
33209
							$attrValue=$found["content"];
33210
 
33211
							#移除屬性數值前面的空白
33212
							#函式說明:
33213
							#將字串特定關鍵字與其前面的內容剔除
33214
							#回傳結果:
33215
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33216
							#$result["error"],錯誤訊息陣列.
33217
							#$result["warning"],警告訊息鎮列.
33218
							#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33219
							#$result["function"],當前執行的函數名稱.
33220
							#$result["argu"],使用的參數.
33221
							#$result["oriStr"],要處理的原始字串內容.
33222
							#$result["content"],處理好的的字串內容.	
33223
							#必填參數:
33224
							#$conf["stringIn"],字串,要處理的字串.
33225
							$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$attrValue;
33226
							#$conf["keyWord"],字串,特定字串.
33227
							$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
33228
							#可省略參數:
33229
							#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
33230
							$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
33231
							#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
33232
							#$conf["lastResult"]=$delStrBeforeKeyWord;
33233
							#參考資料:
33234
							#無.
33235
							#備註:
33236
							#無.
33237
							$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
33238
							unset($conf["stringProcess::delStrBeforeKeyWord"]);
33239
 
33240
							#如果執行失敗
33241
							if($delStrBeforeKeyWord["status"]==="false"){
33242
 
33243
								#設置執行失敗
33244
								$result["status"]="false";
33245
 
33246
								#設置錯誤訊息
33247
								$result["error"]=$delStrBeforeKeyWord;
33248
 
33249
								#回傳結果
33250
								return $result;
33251
 
33252
								}#if end
33253
 
33254
							#如果不存在開頭的空白
33255
							if($delStrBeforeKeyWord["founded"]==="false"){
33256
 
33257
								#設置執行失敗
33258
								$result["status"]="false";
33259
 
33260
								#設置錯誤訊息
33261
								$result["error"]=$delStrBeforeKeyWord;
33262
 
33263
								#回傳結果
33264
								return $result;
33265
 
33266
								}#if end
33267
 
33268
							#取得移除開頭空格後的屬性數值
33269
							$attrValue=$delStrBeforeKeyWord["content"];
33270
 
33271
							#如果是 server
33272
							if($attrName==="ServerName"){
33273
 
33274
								#判斷 ServerName 的結尾是否為 ":".$port,並移除之.
33275
								#函式說明:
33276
								#將字串特定關鍵字與其後面的內容剔除
33277
								#回傳結果:
33278
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33279
								#$result["error"],錯誤訊息陣列.
33280
								#$result["warning"],警告訊息鎮列.
33281
								#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33282
								#$result["function"],當前執行的函數名稱.
33283
								#$result["oriStr"],要處理的原始字串內容.
33284
								#$result["content"],處理好的的字串內容.
33285
								#$result["deleted"],被移除的內容.
33286
								#$result["argu"],使用的參數.
33287
								#必填參數:
33288
								#$conf["stringIn"],字串,要處理的字串.
33289
								$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$attrValue;
33290
								#$conf["keyWord"],字串,特定字串.
33291
								$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";
33292
								#可省略參數:
33293
								#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33294
								#$conf["deleteLastRepeatedOne"]="";
33295
								#參考資料:
33296
								#無.
33297
								#備註:
33298
								#無.
33299
								$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33300
								unset($conf["stringProcess::delStrAfterKeyWord"]);
33301
 
33302
								#如果執行失敗
33303
								if($delStrAfterKeyWord["status"]==="false"){
33304
 
33305
									#設置執行失敗
33306
									$result["status"]="false";
33307
 
33308
									#設置錯誤訊息
33309
									$result["error"]=$delStrAfterKeyWord;
33310
 
33311
									#回傳結果
33312
									return $result;
33313
 
33314
									}#if end
33315
 
33316
								#如果有符合的關鍵字
33317
								if($delStrAfterKeyWord["founded"]==="true"){
33318
 
33319
									#取得處理好的內容
33320
									$attrValue=$delStrAfterKeyWord["content"];
33321
 
33322
									#更新 port
33323
									$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);
33324
 
33325
									}#if end
33326
 
33327
								}#if end
33328
 
33329
							#設置 vhost 資訊
33330
							$vhostInfo[$attrName]=$attrValue;
33331
 
33332
							}#foreach end
33333
 
33334
						#如果沒有 document 存在
33335
						if(!isset($vhostInfo["DocumentRoot"])){
33336
 
33337
							#給予預設的 document root
33338
							$vhostInfo["DocumentRoot"]=$defaultDocumentRoot;
33339
 
33340
							}#if end
33341
 
33342
						#儲存解析出來的 vhost 資訊到要回傳的結果
33343
						$result["content"][]=$vhostInfo;
33344
 
33345
						#取得 ServerName、ServerAlias、DocumentRoot - end
33346
 
33347
						}#if end
33348
 
33349
					}#if end
33350
 
33351
				#反之為 Listen 的 addr & port info
33352
				else{
33353
 
33354
					/*
33355
					輸出範例
33356
					169.254.1.1:80         latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:1)
33357
					169.254.1.1:443        is a NameVirtualHost
33358
					*/
33359
 
33360
					#函式說明:
33361
					#將字串特定關鍵字與其後面的內容剔除
33362
					#回傳結果:
33363
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33364
					#$result["error"],錯誤訊息陣列.
33365
					#$result["warning"],警告訊息鎮列.
33366
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33367
					#$result["function"],當前執行的函數名稱.
33368
					#$result["oriStr"],要處理的原始字串內容.
33369
					#$result["content"],處理好的的字串內容.
33370
					#$result["argu"],使用的參數.
33371
					#必填參數:
33372
					#$conf["stringIn"],字串,要處理的字串.
33373
					$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$callShell["output"][$line];
33374
					#$conf["keyWord"],字串,特定字串.
33375
					$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=" ";
33376
					#可省略參數:
33377
					#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33378
					#$conf["deleteLastRepeatedOne"]="";
33379
					#參考資料:
33380
					#無.
33381
					#備註:
33382
					#無.
33383
					$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33384
					unset($conf["stringProcess::delStrAfterKeyWord"]);
33385
 
33386
					#如果執行失敗
33387
					if($delStrAfterKeyWord["status"]==="false"){
33388
 
33389
						#設置執行失敗
33390
						$result["status"]="false";
33391
 
33392
						#設置錯誤訊息
33393
						$result["error"]=$delStrAfterKeyWord;
33394
 
33395
						#回傳結果
33396
						return $result;
33397
 
33398
						}#if end
33399
 
33400
					#如果應該要存在的關鍵字不存在
33401
					if($delStrAfterKeyWord["founded"]==="false"){
33402
 
33403
						#設置執行失敗
33404
						$result["status"]="false";
33405
 
33406
						#設置錯誤訊息
33407
						$result["error"]=$delStrAfterKeyWord;
33408
 
33409
						#回傳結果
33410
						return $result;
33411
 
33412
						}#if end
33413
 
33414
					#取得IP跟Port
33415
					$listenAddrAndPort=$delStrAfterKeyWord["content"];
33416
 
33417
					#函式說明:
33418
					#將固定格式的字串分開,並回傳分開的結果.
33419
					#回傳結果:
33420
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33421
					#$result["error"],錯誤訊息陣列
33422
					#$result["function"],當前執行的函數名稱.
33423
					#$result["argu"],使用的參數.
33424
					#$result["oriStr"],要分割的原始字串內容
33425
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
33426
					#$result["dataCounts"],爲總共分成幾段
33427
					#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
33428
					#必填參數:
33429
					#$conf["stringIn"],字串,要處理的字串.
33430
					$conf["stringProcess::spiltString"]["stringIn"]=$listenAddrAndPort;
33431
					#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
33432
					$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
33433
					#可省略參數:
33434
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
33435
					#$conf["allowEmptyStr"]="false";
33436
					#參考資料:
33437
					#無.
33438
					#備註:
33439
					#無.
33440
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
33441
					unset($conf["stringProcess::spiltString"]);
33442
 
33443
					#如果執行失敗
33444
					if($spiltString["status"]==="false"){
33445
 
33446
						#設置執行失敗
33447
						$result["status"]="false";
33448
 
33449
						#設置錯誤訊息
33450
						$result["error"]=$spiltString;
33451
 
33452
						#回傳結果
33453
						return $result;
33454
 
33455
						}#if end
33456
 
33457
					#如果應該要存在的關鍵字不存在
33458
					if($spiltString["found"]==="false"){
33459
 
33460
						#設置執行失敗
33461
						$result["status"]="false";
33462
 
33463
						#設置錯誤訊息
33464
						$result["error"]=$spiltString;
33465
 
33466
						#回傳結果
33467
						return $result;
33468
 
33469
						}#if end
33470
 
33471
					#如果不是切成兩段
33472
					if($spiltString["dataCounts"]!==2){
33473
 
33474
						#設置執行失敗
33475
						$result["status"]="false";
33476
 
33477
						#設置錯誤訊息
33478
						$result["error"]=$spiltString;
33479
 
33480
						#回傳結果
33481
						return $result;
33482
 
33483
						}#if end
33484
 
33485
					#更新 ip and port 變數
33486
					$ipAndPort=$spiltString["oriStr"];
33487
 
33488
					#更新 ip
33489
					$ip=$spiltString["dataArray"][0];
33490
 
33491
					#更新 port
33492
					$port=$spiltString["dataArray"][1];
33493
 
33494
					#嘗試移除 "(" 前面的內容
33495
					#函式說明:
33496
					#將字串特定關鍵字與其前面的內容剔除
33497
					#回傳結果:
33498
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33499
					#$result["error"],錯誤訊息陣列.
33500
					#$result["warning"],警告訊息鎮列.
33501
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33502
					#$result["function"],當前執行的函數名稱.
33503
					#$result["argu"],使用的參數.
33504
					#$result["oriStr"],要處理的原始字串內容.
33505
					#$result["content"],處理好的的字串內容.	
33506
					#必填參數:
33507
					#$conf["stringIn"],字串,要處理的字串.
33508
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$callShell["output"][$line];
33509
					#$conf["keyWord"],字串,特定字串.
33510
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="(";
33511
					#可省略參數:
33512
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
33513
					#$conf["recursive"]="true";
33514
					#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
33515
					#$conf["lastResult"]=$delStrBeforeKeyWord;
33516
					#參考資料:
33517
					#無.
33518
					#備註:
33519
					#無.
33520
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
33521
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
33522
 
33523
					#如果執行失敗
33524
					if($delStrBeforeKeyWord["status"]==="false"){
33525
 
33526
						#設置執行失敗
33527
						$result["status"]="false";
33528
 
33529
						#設置錯誤訊息
33530
						$result["error"]=$delStrBeforeKeyWord;
33531
 
33532
						#回傳結果
33533
						return $result;
33534
 
33535
						}#if end
33536
 
33537
					#如果應該要存在的關鍵字存在
33538
					if($delStrBeforeKeyWord["founded"]==="true"){
33539
 
33540
						#嘗試移除 ")" 後面的內容
33541
						#函式說明:
33542
						#將字串特定關鍵字與其後面的內容剔除
33543
						#回傳結果:
33544
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33545
						#$result["error"],錯誤訊息陣列.
33546
						#$result["warning"],警告訊息鎮列.
33547
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33548
						#$result["function"],當前執行的函數名稱.
33549
						#$result["oriStr"],要處理的原始字串內容.
33550
						#$result["content"],處理好的的字串內容.
33551
						#$result["argu"],使用的參數.
33552
						#必填參數:
33553
						#$conf["stringIn"],字串,要處理的字串.
33554
						$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
33555
						#$conf["keyWord"],字串,特定字串.
33556
						$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=")";
33557
						#可省略參數:
33558
						#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33559
						#$conf["deleteLastRepeatedOne"]="";
33560
						#參考資料:
33561
						#無.
33562
						#備註:
33563
						#無.
33564
						$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33565
						unset($conf["stringProcess::delStrAfterKeyWord"]);
33566
 
33567
						#如果執行失敗
33568
						if($delStrAfterKeyWord["status"]==="false"){
33569
 
33570
							#設置執行失敗
33571
							$result["status"]="false";
33572
 
33573
							#設置錯誤訊息
33574
							$result["error"]=$delStrAfterKeyWord;
33575
 
33576
							#回傳結果
33577
							return $result;
33578
 
33579
							}#if end
33580
 
33581
						#如果無找到 ")"
33582
						if($delStrAfterKeyWord["founded"]==="false"){
33583
 
33584
							#設置執行失敗
33585
							$result["status"]="false";
33586
 
33587
							#設置錯誤訊息
33588
							$result["error"]=$delStrAfterKeyWord;
33589
 
33590
							#回傳結果
33591
							return $result;
33592
 
33593
							}#if end
33594
 
33595
						#嘗試移除":number"
33596
						#函式說明:
33597
						#將字串特定關鍵字與其後面的內容剔除
33598
						#回傳結果:
33599
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33600
						#$result["error"],錯誤訊息陣列.
33601
						#$result["warning"],警告訊息鎮列.
33602
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33603
						#$result["function"],當前執行的函數名稱.
33604
						#$result["oriStr"],要處理的原始字串內容.
33605
						#$result["content"],處理好的的字串內容.
33606
						#$result["argu"],使用的參數.
33607
						#必填參數:
33608
						#$conf["stringIn"],字串,要處理的字串.
33609
						$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrAfterKeyWord["content"];
33610
						#$conf["keyWord"],字串,特定字串.
33611
						$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";
33612
						#可省略參數:
33613
						#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33614
						$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="true";
33615
						#參考資料:
33616
						#無.
33617
						#備註:
33618
						#無.
33619
						$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33620
						unset($conf["stringProcess::delStrAfterKeyWord"]);
33621
 
33622
						#如果執行失敗
33623
						if($delStrAfterKeyWord["status"]==="false"){
33624
 
33625
							#設置執行失敗
33626
							$result["status"]="false";
33627
 
33628
							#設置錯誤訊息
33629
							$result["error"]=$delStrAfterKeyWord;
33630
 
33631
							#回傳結果
33632
							return $result;
33633
 
33634
							}#if end
33635
 
33636
						#取得 vhost 設定檔案的位置
33637
						$vhostFile=$delStrAfterKeyWord["content"];
33638
 
33639
						#取得設定檔的內容
33640
						#函式說明:
33641
						#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
33642
						#回傳的變數說明:
33643
						#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
33644
						#$result["error"],錯誤訊息提示.
33645
						#$result["warning"],警告訊息.
33646
						#$result["function"],當前執行的函數名稱.
33647
						#$result["fileContent"],爲檔案的內容陣列.
33648
						#$result["lineCount"],爲檔案內容總共的行數.
33649
						#$result["fullContent"],為檔案的完整內容.
33650
						#$result["base64data"],為檔案的base64內容.
33651
						#$result["mimeType"],為檔案的mime type.
33652
						#必填參數:
33653
						#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
33654
						$conf["fileAccess::getFileContent"]["filePositionAndName"]=$vhostFile;
33655
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
33656
						$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
33657
						#可省略參數:
33658
						#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
33659
						#$conf["web"]="true";
33660
						#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
33661
						#$conf["createIfnotExist"]="false";
33662
						#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
33663
						$conf["fileAccess::getFileContent"]["autoDeleteSpaceOnEachLineStart"]="true";
33664
						#參考資料:
33665
						#file(),取得檔案內容的行數.
33666
						#file=>http:#php.net/manual/en/function.file.php
33667
						#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
33668
						#filesize=>http://php.net/manual/en/function.filesize.php
33669
						#參考資料:
33670
						#無.
33671
						#備註:
33672
						#無.
33673
						$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
33674
						unset($conf["fileAccess::getFileContent"]);
33675
 
33676
						#如果執行失敗
33677
						if($getFileContent["status"]==="false"){
33678
 
33679
							#設置執行失敗
33680
							$result["status"]="false";
33681
 
33682
							#設置錯誤訊息
33683
							$result["error"]=$getFileContent;
33684
 
33685
							#回傳結果
33686
							return $result;
33687
 
33688
							}#if end
33689
 
33690
						#符合條件的內容範例
33691
						/*
33692
						DocumentRoot "/var/www/html/qbpwcf"
33693
						ServerName mobile.qbpwcf.org:443
33694
						ServerAlias www.qbpwcf.org
33695
						ServerAlias qbpwcf.org
33696
						*/
33697
 
33698
						#取得 ServerName、ServerAlias、DocumentRoot - start
33699
 
33700
						#函式說明:
33701
						#取得符合多個特定字首與字尾之一的字串們
33702
						#回傳結果:
33703
						#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
33704
						#$result["function"],當前執行的函數名稱.
33705
						#$result["error"],錯誤訊息陣列.
33706
						#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
33707
						#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.
33708
						#$result["argu"],使用的參數.
33709
						#必填參數:
33710
						#$conf["checkString"],陣列字串,要檢查的陣列字串.
33711
						$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];
33712
						#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.
33713
						$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"ServerName"),array("front"=>"DocumentRoot"),array("front"=>"ServerAlias"));
33714
						#可省略參數:
33715
						#無.
33716
						#參考資料:
33717
						#無.
33718
						#備註:
33719
						#無.
33720
						$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);
33721
						unset($conf["search::getMeetMultiConditionsStrings"]);
33722
 
33723
						#如果執行失敗
33724
						if($getMeetMultiConditionsStrings["status"]==="false"){
33725
 
33726
							#設置執行失敗
33727
							$result["status"]="false";
33728
 
33729
							#設置錯誤訊息
33730
							$result["error"]=$getMeetMultiConditionsStrings;
33731
 
33732
							#回傳結果
33733
							return $result;
33734
 
33735
							}#if end
33736
 
33737
						#如果沒有需要的關鍵字存在
33738
						if($getMeetMultiConditionsStrings["found"]==="false"){
33739
 
33740
							#設置執行失敗
33741
							$result["status"]="false";
33742
 
33743
							#設置錯誤訊息
33744
							$result["error"]=$getMeetMultiConditionsStrings;
33745
 
33746
							#回傳結果
33747
							return $result;
33748
 
33749
							}#if end
33750
 
33751
						#初始化vhost的資訊
33752
						$vhostInfo=array("ip"=>$defaultIp,"port"=>$defaultPort,"DocumentRoot"=>$defaultDocumentRoot);
33753
 
33754
						#針對每個找到的結果
33755
						foreach($getMeetMultiConditionsStrings["content"] as $found){
33756
 
33757
							#取得符合的關鍵字/屬性名稱
33758
							$attrName=$found["meetConditions"]["front"];
33759
 
33760
							#取得屬性的數值
33761
							$attrValue=$found["content"];
33762
 
33763
							#移除屬性數值前面的空白
33764
							#函式說明:
33765
							#將字串特定關鍵字與其前面的內容剔除
33766
							#回傳結果:
33767
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33768
							#$result["error"],錯誤訊息陣列.
33769
							#$result["warning"],警告訊息鎮列.
33770
							#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33771
							#$result["function"],當前執行的函數名稱.
33772
							#$result["argu"],使用的參數.
33773
							#$result["oriStr"],要處理的原始字串內容.
33774
							#$result["content"],處理好的的字串內容.	
33775
							#必填參數:
33776
							#$conf["stringIn"],字串,要處理的字串.
33777
							$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$attrValue;
33778
							#$conf["keyWord"],字串,特定字串.
33779
							$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
33780
							#可省略參數:
33781
							#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
33782
							$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
33783
							#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
33784
							#$conf["lastResult"]=$delStrBeforeKeyWord;
33785
							#參考資料:
33786
							#無.
33787
							#備註:
33788
							#無.
33789
							$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
33790
							unset($conf["stringProcess::delStrBeforeKeyWord"]);
33791
 
33792
							#如果執行失敗
33793
							if($delStrBeforeKeyWord["status"]==="false"){
33794
 
33795
								#設置執行失敗
33796
								$result["status"]="false";
33797
 
33798
								#設置錯誤訊息
33799
								$result["error"]=$delStrBeforeKeyWord;
33800
 
33801
								#回傳結果
33802
								return $result;
33803
 
33804
								}#if end
33805
 
33806
							#如果不存在開頭的空白
33807
							if($delStrBeforeKeyWord["founded"]==="false"){
33808
 
33809
								#設置執行失敗
33810
								$result["status"]="false";
33811
 
33812
								#設置錯誤訊息
33813
								$result["error"]=$delStrBeforeKeyWord;
33814
 
33815
								#回傳結果
33816
								return $result;
33817
 
33818
								}#if end
33819
 
33820
							#取得移除開頭空格後的屬性數值
33821
							$attrValue=$delStrBeforeKeyWord["content"];
33822
 
33823
							#如果是 ServerName 定義行
33824
							if($attrName="ServerName"){
33825
 
33826
								#判斷 ServerName 的結尾是否為 ":".$port,並移除之.
33827
								#函式說明:
33828
								#將字串特定關鍵字與其後面的內容剔除
33829
								#回傳結果:
33830
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33831
								#$result["error"],錯誤訊息陣列.
33832
								#$result["warning"],警告訊息鎮列.
33833
								#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33834
								#$result["function"],當前執行的函數名稱.
33835
								#$result["oriStr"],要處理的原始字串內容.
33836
								#$result["content"],處理好的的字串內容.
33837
								#$result["deleted"],被移除的內容.
33838
								#$result["argu"],使用的參數.
33839
								#必填參數:
33840
								#$conf["stringIn"],字串,要處理的字串.
33841
								$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$attrValue;
33842
								#$conf["keyWord"],字串,特定字串.
33843
								$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";
33844
								#可省略參數:
33845
								#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33846
								#$conf["deleteLastRepeatedOne"]="";
33847
								#參考資料:
33848
								#無.
33849
								#備註:
33850
								#無.
33851
								$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33852
								unset($conf["stringProcess::delStrAfterKeyWord"]);
33853
 
33854
								#如果執行失敗
33855
								if($delStrAfterKeyWord["status"]==="false"){
33856
 
33857
									#設置執行失敗
33858
									$result["status"]="false";
33859
 
33860
									#設置錯誤訊息
33861
									$result["error"]=$delStrAfterKeyWord;
33862
 
33863
									#回傳結果
33864
									return $result;
33865
 
33866
									}#if end
33867
 
33868
								#如果有符合的關鍵字
33869
								if($delStrAfterKeyWord["founded"]==="true"){
33870
 
33871
									#取得處理好的內容
33872
									$attrValue=$delStrAfterKeyWord["content"];
33873
 
33874
									#更新 port
33875
									$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);
33876
 
33877
									}#if end
33878
 
33879
								#更新 port
33880
								$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);
33881
 
33882
								}#if end
33883
 
33884
							#設置 vhost 資訊
33885
							$vhostInfo[$attrName]=$attrValue;
33886
 
33887
							}#foreach end
33888
 
33889
						#如果沒有 document 存在
33890
						if(!isset($vhostInfo["DocumentRoot"])){
33891
 
33892
							#給予預設的 document root
33893
							$vhostInfo["DocumentRoot"]=$defaultDocumentRoot;
33894
 
33895
							}#if end
33896
 
33897
						#儲存解析出來的 vhost 資訊到要回傳的結果
33898
						$result["content"][]=$vhostInfo;
33899
 
33900
						#取得 ServerName、ServerAlias、DocumentRoot - end
33901
 
33902
						}#if end
33903
 
33904
					}#else end
33905
 
33906
				}#else end
33907
 
33908
			}#if end
33909
 
33910
		#剔除重複的vhost內容
33911
		#函式說明:
33912
		#將陣列中重複的元素剔除
33913
		#回傳的結果:
33914
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
33915
		#$result["error"],錯誤訊息陣列.
33916
		#$result["function"],當前執行的函數.
33917
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
33918
		#$result["content"],合併好的陣列.
33919
		#必填參數
33920
		#$conf["inputArray"],陣列,要合併的陣列變數.
33921
		$conf["arrays::unique"]["inputArray"]=$result["content"];
33922
		#可省略參數:
33923
		#無.
33924
		#參考資料:
33925
		#無.
33926
		#備註:
33927
		#無.
33928
		$unique=arrays::unique($conf["arrays::unique"]);
33929
		unset($conf["arrays::unique"]);
33930
 
33931
		#debug
33932
		#var_dump(__LINE__,$unique);
33933
 
33934
		#如果執行失敗
33935
		if($unique["status"]==="false"){
33936
 
33937
			#設置執行失敗
33938
			$result["status"]="false";
33939
 
33940
			#設置錯誤訊息
33941
			$result["error"]=$unique;
33942
 
33943
			#回傳結果
33944
			return $result;
33945
 
33946
			}#if end
33947
 
33948
		#取得不重複的vhost內容
33949
		$result["content"]=$unique["content"];
33950
 
33951
		#如果沒有vhost的解析結果
33952
		if(!isset($result["content"])){
33953
 
33954
			#設置錯誤訊息
33955
			$result["error"][]="No vhost setting found";
33956
 
33957
			#設置執行失敗
33958
			$result["status"]="false";
33959
 
33960
			#回傳結果
33961
			return $result;
33962
 
33963
			}#if end
33964
 
33965
		#設置執行正常
33966
		$result["status"]="true";
33967
 
33968
		#回傳結果
33969
		return $result;	
33970
 
33971
		}#function httpdGetVhostInfo end
33972
 
33973
	/*
33974
	#函式說明:
33975
	#產生 rpmspec 檔案內容的程式.
33976
	#回傳結果:
33977
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33978
	#$result["error"],錯誤訊息.
33979
	#$result["function"],當前執行的函式名稱.
33980
	#$result["content"],得到的rpm spec檔案內容字串.
33981
	#必填參數:
33982
	#$conf["name"],字串,要產生的package名稱.
33983
	#$conf["name"]="";
33984
	#$conf["version"],字串,版本號,不可含有"-".
33985
	#$conf["version"]="";
33986
	#$conf["summary"],字串,package的簡述.
33987
	#$conf["summary"]="";
33988
	#$conf["desc"],字串,package的完整描述.
33989
	#$conf["desc"]="";
33990
	#可省略參數:
33991
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
33992
	#$conf["fileArgu"]=__FILE__;
33993
	#$conf["release"],字串,發行版次。初始值一般都應該是 "1%{?dist}" ,每次新發行同版本軟體的軟體包就遞增一個數字。若上游發行新的版本,就對應修改 Version 標籤,然後把 Release >發行版次重設回 1
33994
	#$conf["release"]="";	
33995
	#$conf["license"],字串,版權宣告,預設為 "GPL-3.0-or-later" .
33996
	#$conf["license"]="";
33997
	#$conf["projectUrl"],字串,該package所屬專案的官方網址,預設為"https://%{name}.qbpwcf.org".
33998
	#$conf["projectUrl"]="";
33999
	#$conf["sourceFileUrl"],字串,原始碼檔案的下載位置,預設為"https://%{name}.qbpwcf.org/%{name}-%{version}.tar.zst"
34000
	#$conf["sourceFileUrl"]="";
34001
	#$conf["preRequiredPacakge"],字串陣列,編譯與安裝該package要有哪些package預先安裝好.預設不設定,亦即沒有須要必備的package.
34002
	#$conf["preRequiredPacakge"]=array();
34003
	#$conf["arch"],字串,package對應的處理器架構,例如 "aarch64","x86_64" 等,預設為 "noarch"(不指定處理器架構),亦即為通用的package.
34004
	#$conf["arch"]="";
34005
	#$conf["configure"],字串,編譯前是否需要運行 configure 檔案來進行設定,預設為"true"代表要;反之為"false".
34006
	#$conf["configure"]="";
34007
	#$conf["build"],字串,是否需要進行編譯的動作,預設為 "false" 代表不用;反之為 "true".
34008
	#$conf["build"]="";
34009
	#可省略參數:
34010
	#無.
34011
	#參考資料:
34012
	#無
34013
	#備註:
34014
	#建構中...
34015
	*/
34016
	public static function createRPMspec(&$conf){
34017
 
34018
		}#function createRPMspec end
34019
 
34020
	}#class cmd end
34021
 
34022
?>